home · contact · privacy
If drunk, speak drunkenly.
[plomrogue2] / rogue_chat_curses.py
index 9519a95609a82ba0f9a0fd4f7d7bca95999f756e..65d5385ee2d20d17f5fb117a4ac82ea987163445 100755 (executable)
@@ -29,40 +29,40 @@ mode_helps = {
     'name_thing': {
         'short': 'name thing',
         'intro': '',
-        'long': 'Give name to/change name of thing here.'
+        'long': 'Give name to/change name of carried thing.'
     },
     'command_thing': {
-        'short': 'command thing',
+        'short': 'command',
         'intro': '',
         'long': 'Enter a command to the thing you carry.  Enter nothing to return to play mode.'
     },
     'take_thing': {
-        'short': 'take thing',
+        'short': 'take',
         'intro': 'Pick up a thing in reach by entering its index number.  Enter nothing to abort.',
         'long': 'You see a list of things which you could pick up.  Enter the target thing\'s index, or, to leave, nothing.'
     },
     'drop_thing': {
-        'short': 'drop thing',
+        'short': 'drop',
         'intro': 'Enter number of direction to which you want to drop thing.',
         'long': 'Drop currently carried thing by entering the target direction index.  Enter nothing to return to play mode..'
     },
     'admin_thing_protect': {
         'short': 'change thing protection',
         'intro': '@ enter thing protection character:',
-        'long': 'Change protection character for thing here.'
+        'long': 'Change protection character for carried thing.'
     },
     'enter_face': {
-        'short': 'enter your face',
+        'short': 'edit face',
         'intro': '@ enter face line (enter nothing to abort):',
         'long': 'Draw your face as ASCII art.  The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..'
     },
     'enter_hat': {
-        'short': 'enter your hat',
+        'short': 'edit hat',
         'intro': '@ enter hat line (enter nothing to abort):',
-        'long': 'Draw your hat as ASCII art.  The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..'
+        'long': 'Draw your face as ASCII art.  The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom.  Eat cookies to extend the ASCII characters available for drawing.'
     },
     'write': {
-        'short': 'change terrain',
+        'short': 'edit tile',
         'intro': '',
         'long': 'This mode allows you to change the map tile you currently stand on (if your world editing password authorizes you so).  Just enter any printable ASCII character to imprint it on the ground below you.'
     },
@@ -178,11 +178,11 @@ def cmd_TURN(game, n):
     game.turn_complete = False
 cmd_TURN.argtypes = 'int:nonneg'
 
-def cmd_PSEUDO_FOV_WIPE(game):
+def cmd_OTHER_WIPE(game):
     game.portals_new = {}
     game.annotations_new = {}
     game.things_new = []
-cmd_PSEUDO_FOV_WIPE.argtypes = ''
+cmd_OTHER_WIPE.argtypes = ''
 
 def cmd_LOGIN_OK(game):
     game.tui.switch_mode('post_login_wait')
@@ -342,7 +342,7 @@ def cmd_THING_INSTALLED(game, thing_id):
 cmd_THING_INSTALLED.argtypes = 'int:pos'
 
 def cmd_THING_CARRYING(game, thing_id, carried_id):
-    game.get_thing_temp(thing_id).carrying = game.get_thing(carried_id)
+    game.get_thing_temp(thing_id).carrying = game.get_thing_temp(carried_id)
 cmd_THING_CARRYING.argtypes = 'int:pos int:pos'
 
 def cmd_TERRAIN(game, terrain_char, terrain_desc):
@@ -377,7 +377,7 @@ class Game(GameBase):
         self.register_command(cmd_REPLY)
         self.register_command(cmd_PLAYER_ID)
         self.register_command(cmd_TURN)
-        self.register_command(cmd_PSEUDO_FOV_WIPE)
+        self.register_command(cmd_OTHER_WIPE)
         self.register_command(cmd_THING)
         self.register_command(cmd_THING_TYPE)
         self.register_command(cmd_THING_NAME)
@@ -514,7 +514,8 @@ class TUI:
         self.mode_control_tile_draw.available_actions = ["move_explorer",
                                                          "toggle_tile_draw"]
         self.mode_edit.available_modes = ["write", "annotate", "portal",
-                                          "name_thing", "enter_face", "enter_hat", "password",
+                                          "name_thing", "enter_face", "enter_hat",
+                                          "password",
                                           "chat", "study", "play", "admin_enter"]
         self.mode_edit.available_actions = ["move", "flatten", "install",
                                             "toggle_map_mode"]
@@ -582,6 +583,8 @@ class TUI:
         self.fov = ''
         self.flash = False
         self.map_lines = []
+        self.ascii_draw_stage = 0
+        self.full_ascii_draw = ''
         self.offset = YX(0,0)
         curses.wrapper(self.loop)
 
@@ -647,11 +650,18 @@ class TUI:
         elif self.mode.name == 'password':
             self.input_ = self.password
         elif self.mode.name == 'name_thing':
-            if hasattr(self.thing_selected, 'name'):
-                self.input_ = self.thing_selected.name
+            if hasattr(self.game.player.carrying, 'name'):
+                self.input_ = self.game.player.carrying.name
         elif self.mode.name == 'admin_thing_protect':
-            if hasattr(self.thing_selected, 'protection'):
-                self.input_ = self.thing_selected.protection
+            if hasattr(self.game.player.carrying, 'protection'):
+                self.input_ = self.game.player.carrying.protection
+        elif self.mode.name in {'enter_face', 'enter_hat'}:
+            start = self.ascii_draw_stage * 6
+            end = (self.ascii_draw_stage + 1) * 6
+            if self.mode.name == 'enter_face':
+                self.input_ = self.game.player.face[start:end]
+            elif self.mode.name == 'enter_hat':
+                self.input_ = self.game.player.hat[start:end]
 
     def send_tile_control_command(self):
         self.send('SET_TILE_CONTROL %s %s' %
@@ -682,6 +692,10 @@ class TUI:
            (not self.game.player.carrying or
             not self.game.player.carrying.commandable):
             return fail('not carrying anything commandable')
+        if mode_name == 'name_thing' and not self.game.player.carrying:
+            return fail('not carrying anything to re-name')
+        if mode_name == 'admin_thing_protect' and not self.game.player.carrying:
+            return fail('not carrying anything to protect')
         if mode_name == 'take_thing' and self.game.player.carrying:
             return fail('already carrying something')
         if mode_name == 'drop_thing' and not self.game.player.carrying:
@@ -690,17 +704,6 @@ class TUI:
             return fail('not wearing hat to edit', 'edit')
         if mode_name == 'admin_enter' and self.is_admin:
             mode_name = 'admin'
-        elif mode_name in {'name_thing', 'admin_thing_protect'}:
-            thing = None
-            for t in [t for t in self.game.things
-                      if t.position == self.game.player.position
-                      and t.id_ != self.game.player.id_]:
-                thing = t
-                break
-            if not thing:
-                return fail('not standing over thing', 'edit')
-            else:
-                self.thing_selected = thing
         self.mode = getattr(self, 'mode_' + mode_name)
         if self.mode.name in {'control_tile_draw', 'control_tile_type',
                               'control_pw_type'}:
@@ -721,26 +724,41 @@ class TUI:
                 self.log_msg('@ enter username')
         elif self.mode.name == 'take_thing':
             self.log_msg('Portable things in reach for pick-up:')
-            select_range = [self.game.player.position,
-                            self.game.player.position + YX(0,-1),
-                            self.game.player.position + YX(0, 1),
-                            self.game.player.position + YX(-1, 0),
-                            self.game.player.position + YX(1, 0)]
-            if type(self.game.map_geometry) == MapGeometryHex:
+            directed_moves = {
+                'HERE': YX(0, 0), 'LEFT': YX(0, -1), 'RIGHT': YX(0, 1)
+            }
+            if type(self.game.map_geometry) == MapGeometrySquare:
+                directed_moves['UP'] = YX(-1, 0)
+                directed_moves['DOWN'] = YX(1, 0)
+            elif type(self.game.map_geometry) == MapGeometryHex:
                 if self.game.player.position.y % 2:
-                    select_range += [self.game.player.position + YX(-1, 1),
-                                     self.game.player.position + YX(1, 1)]
+                    directed_moves['UPLEFT'] = YX(-1, 0)
+                    directed_moves['UPRIGHT'] = YX(-1, 1)
+                    directed_moves['DOWNLEFT'] = YX(1, 0)
+                    directed_moves['DOWNRIGHT'] = YX(1, 1)
                 else:
-                    select_range += [self.game.player.position + YX(-1, -1),
-                                     self.game.player.position + YX(1, -1)]
-            self.selectables = [t.id_ for t in self.game.things
-                                if t.portable and t.position in select_range]
+                    directed_moves['UPLEFT'] = YX(-1, -1)
+                    directed_moves['UPRIGHT'] = YX(-1, 0)
+                    directed_moves['DOWNLEFT'] = YX(1, -1)
+                    directed_moves['DOWNRIGHT'] = YX(1, 0)
+            select_range = {}
+            for direction in directed_moves:
+                move = directed_moves[direction]
+                select_range[direction] = self.game.player.position + move
+            self.selectables = []
+            directions = []
+            for direction in select_range:
+                for t in [t for t in self.game.things
+                          if t.portable and t.position == select_range[direction]]:
+                    self.selectables += [t.id_]
+                    directions += [direction]
             if len(self.selectables) == 0:
                 return fail('nothing to pick-up')
             else:
                 for i in range(len(self.selectables)):
                     t = self.game.get_thing(self.selectables[i])
-                    self.log_msg(str(i) + ': ' + self.get_thing_info(t))
+                    self.log_msg('%s %s: %s' % (i, directions[i],
+                                                self.get_thing_info(t)))
         elif self.mode.name == 'drop_thing':
             self.log_msg('Direction to drop thing to:')
             self.selectables =\
@@ -876,7 +894,8 @@ class TUI:
             if not self.mode.has_input_prompt:
                 self.input_lines = []
             else:
-                self.input_lines = msg_into_lines_of_width(input_prompt + self.input_,
+                self.input_lines = msg_into_lines_of_width(input_prompt
+                                                           + self.input_ + '█',
                                                            self.window_width)
 
         def move_explorer(direction):
@@ -1087,6 +1106,22 @@ class TUI:
             self.input_ = ''
             self.switch_mode('play')
 
+        def enter_ascii_art(command):
+            if len(self.input_) != 6:
+                self.log_msg('? wrong input length, must be 6; try again')
+                return
+            self.log_msg('  ' + self.input_)
+            self.full_ascii_draw += self.input_
+            self.ascii_draw_stage += 1
+            if self.ascii_draw_stage < 3:
+                self.restore_input_values()
+            else:
+                self.send('%s %s' % (command, quote(self.full_ascii_draw)))
+                self.full_ascii_draw = ""
+                self.ascii_draw_stage = 0
+                self.input_ = ""
+                self.switch_mode('edit')
+
         action_descriptions = {
             'move': 'move',
             'flatten': 'flatten surroundings',
@@ -1188,19 +1223,9 @@ class TUI:
                 self.send('LOGIN ' + quote(self.input_))
                 self.input_ = ""
             elif self.mode.name == 'enter_face' and key == '\n':
-                if len(self.input_) != 18:
-                    self.log_msg('? wrong input length, aborting')
-                else:
-                    self.send('PLAYER_FACE %s' % quote(self.input_))
-                self.input_ = ""
-                self.switch_mode('edit')
+                enter_ascii_art('PLAYER_FACE')
             elif self.mode.name == 'enter_hat' and key == '\n':
-                if len(self.input_) != 18:
-                    self.log_msg('? wrong input length, aborting')
-                else:
-                    self.send('PLAYER_HAT %s' % quote(self.input_))
-                self.input_ = ""
-                self.switch_mode('edit')
+                enter_ascii_art('PLAYER_HAT')
             elif self.mode.name == 'take_thing' and key == '\n':
                 pick_selectable('PICK_UP')
             elif self.mode.name == 'drop_thing' and key == '\n':
@@ -1234,8 +1259,7 @@ class TUI:
                 if len(self.input_) != 1:
                     self.log_msg('@ entered non-single-char, therefore aborted')
                 else:
-                    self.send('THING_PROTECTION %s %s' % (self.thing_selected.id_,
-                                                          quote(self.input_)))
+                    self.send('THING_PROTECTION %s' % (quote(self.input_)))
                     self.log_msg('@ sent new protection character for thing')
                 self.switch_mode('admin')
             elif self.mode.name == 'control_tile_type' and key == '\n':
@@ -1263,9 +1287,8 @@ class TUI:
             elif self.mode.name == 'name_thing' and key == '\n':
                 if self.input_ == '':
                     self.input_ = ' '
-                self.send('THING_NAME %s %s %s' % (self.thing_selected.id_,
-                                                   quote(self.input_),
-                                                   quote(self.password)))
+                self.send('THING_NAME %s %s' % (quote(self.input_),
+                                                quote(self.password)))
                 self.switch_mode('edit')
             elif self.mode.name == 'annotate' and key == '\n':
                 if self.input_ == '':