home · contact · privacy
Enable selecting specific thing for pick-up.
[plomrogue2] / rogue_chat_curses.py
index be3c53f7226fcbecdb26cdacde5b99127da17d15..b098e0451456112f0e74508b6364417808cba73e 100755 (executable)
@@ -31,6 +31,10 @@ mode_helps = {
         'short': 'command thing',
         'long': 'Enter a command to the thing you carry.  Enter nothing to return to play mode.'
     },
+    'take_thing': {
+        'short': 'take thing',
+        'long': 'You see a list of things which you could pick up.  Enter the target thing\'s index, or, to leave, nothing.'
+    },
     'admin_thing_protect': {
         'short': 'change thing protection',
         'long': 'Change protection character for thing here.'
@@ -259,6 +263,7 @@ def cmd_TASKS(game, tasks_comma_separated):
     game.tasks = tasks_comma_separated.split(',')
     game.tui.mode_write.legal = 'WRITE' in game.tasks
     game.tui.mode_command_thing.legal = 'COMMAND' in game.tasks
+    game.tui.mode_take_thing.legal = 'PICK_UP' in game.tasks
 cmd_TASKS.argtypes = 'string'
 
 def cmd_THING_TYPE(game, thing_type, symbol_hint):
@@ -390,6 +395,7 @@ class TUI:
     mode_password = Mode('password', has_input_prompt=True)
     mode_name_thing = Mode('name_thing', has_input_prompt=True, shows_info=True)
     mode_command_thing = Mode('command_thing', has_input_prompt=True)
+    mode_take_thing = Mode('take_thing', has_input_prompt=True)
     is_admin = False
     tile_draw = False
 
@@ -397,8 +403,8 @@ class TUI:
         import os
         import json
         self.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
-                                          "command_thing"]
-        self.mode_play.available_actions = ["move", "take_thing", "drop_thing",
+                                          "command_thing", "take_thing"]
+        self.mode_play.available_actions = ["move", "drop_thing",
                                             "teleport", "door", "consume"]
         self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
         self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"]
@@ -441,7 +447,7 @@ class TUI:
             'switch_to_control_tile_type': 'Q',
             'switch_to_admin_thing_protect': 'T',
             'flatten': 'F',
-            'take_thing': 'z',
+            'switch_to_take_thing': 'z',
             'drop_thing': 'u',
             'teleport': 'p',
             'consume': 'C',
@@ -594,6 +600,17 @@ class TUI:
                 self.send('LOGIN ' + quote(self.login_name))
             else:
                 self.log_msg('@ enter username')
+        elif self.mode.name == 'take_thing':
+            self.log_msg('selectable things:')
+            player = self.game.get_thing(self.game.player_id)
+            selectables = [t for t in self.game.things
+                           if t != player and t.type_ != 'Player'
+                           and t.position == player.position]
+            if len(selectables) == 0:
+                self.log_msg('none')
+            else:
+                for t in selectables:
+                    self.log_msg(str(t.id_) + ' ' + self.get_thing_info(t))
         elif self.mode.name == 'command_thing':
             self.send('TASK:COMMAND ' + quote('HELP'))
         elif self.mode.name == 'admin_enter':
@@ -646,15 +663,10 @@ class TUI:
             info_to_cache += 'PROTECTION: %s\n' % protection
             for t in self.game.things:
                 if t.position == self.explorer:
+                    info_to_cache += 'THING: %s' % self.get_thing_info(t)
                     protection = t.protection
                     if protection == '.':
                         protection = 'none'
-                    info_to_cache += 'THING: %s / %s' %\
-                        (t.type_, self.game.thing_types[t.type_])
-                    if hasattr(t, 'thing_char'):
-                        info_to_cache += t.thing_char
-                    if hasattr(t, 'name'):
-                        info_to_cache += ' (%s)' % t.name
                     info_to_cache += ' / protection: %s\n' % protection
             if self.explorer in self.game.portals:
                 info_to_cache += 'PORTAL: ' +\
@@ -667,6 +679,15 @@ class TUI:
         self.info_cached = info_to_cache
         return self.info_cached
 
+    def get_thing_info(self, t):
+        info = '%s / %s' %\
+            (t.type_, self.game.thing_types[t.type_])
+        if hasattr(t, 'thing_char'):
+            info += t.thing_char
+        if hasattr(t, 'name'):
+            info += ' (%s)' % t.name
+        return info
+
     def loop(self, stdscr):
         import datetime
 
@@ -974,6 +995,13 @@ class TUI:
                 self.login_name = self.input_
                 self.send('LOGIN ' + quote(self.input_))
                 self.input_ = ""
+            elif self.mode.name == 'take_thing' and key == '\n':
+                if self.input_ == '':
+                    self.log_msg('@ aborted')
+                else:
+                    self.send('TASK:PICK_UP ' + quote(self.input_))
+                self.input_ = ''
+                self.switch_mode('play')
             elif self.mode.name == 'command_thing' and key == '\n':
                 if self.input_ == '':
                     self.log_msg('@ aborted')
@@ -1070,8 +1098,6 @@ class TUI:
             elif self.mode.name == 'play':
                 if self.mode.mode_switch_on_key(self, key):
                     continue
-                elif key == self.keys['take_thing'] and task_action_on('take_thing'):
-                    self.send('TASK:PICK_UP')
                 elif key == self.keys['drop_thing'] and task_action_on('drop_thing'):
                     self.send('TASK:DROP')
                 elif key == self.keys['door'] and task_action_on('door'):