home · contact · privacy
In info view, show protection level.
[plomrogue2] / rogue_chat_curses.py
index 2dfbdd1b6b76772877ac47b9db7c04b4e199e919..99a7e88bc94b0f0bccf81c0bd3228335226765fe 100755 (executable)
@@ -51,6 +51,8 @@ class PlomSocketClient(PlomSocket):
             pass  # we assume socket will be known as dead by now
 
 def cmd_TURN(game, n):
+    game.info_db = {}
+    game.info_hints = []
     game.turn = n
     game.things = []
     game.portals = {}
@@ -124,7 +126,6 @@ def cmd_MAP_CONTROL(game, content):
 cmd_MAP_CONTROL.argtypes = 'string'
 
 def cmd_GAME_STATE_COMPLETE(game):
-    game.info_db = {}
     if game.tui.mode.name == 'post_login_wait':
         game.tui.switch_mode('play')
     if game.tui.mode.shows_info:
@@ -139,7 +140,7 @@ cmd_PORTAL.argtypes = 'yx_tuple:nonneg string'
 
 def cmd_PLAY_ERROR(game, msg):
     game.tui.log_msg('? ' + msg)
-    game.tui.flash()
+    game.tui.flash = True
     game.tui.do_refresh = True
 cmd_PLAY_ERROR.argtypes = 'string'
 
@@ -153,8 +154,13 @@ def cmd_ARGUMENT_ERROR(game, msg):
     game.tui.do_refresh = True
 cmd_ARGUMENT_ERROR.argtypes = 'string'
 
+def cmd_ANNOTATION_HINT(game, position):
+    game.info_hints += [position]
+cmd_ANNOTATION_HINT.argtypes = 'yx_tuple:nonneg'
+
 def cmd_ANNOTATION(game, position, msg):
     game.info_db[position] = msg
+    game.tui.restore_input_values()
     if game.tui.mode.shows_info:
         game.tui.do_refresh = True
 cmd_ANNOTATION.argtypes = 'yx_tuple:nonneg string'
@@ -196,6 +202,7 @@ class Game(GameBase):
         self.register_command(cmd_MAP_CONTROL)
         self.register_command(cmd_PORTAL)
         self.register_command(cmd_ANNOTATION)
+        self.register_command(cmd_ANNOTATION_HINT)
         self.register_command(cmd_GAME_STATE_COMPLETE)
         self.register_command(cmd_ARGUMENT_ERROR)
         self.register_command(cmd_GAME_ERROR)
@@ -205,6 +212,7 @@ class Game(GameBase):
         self.map_content = ''
         self.player_id = -1
         self.info_db = {}
+        self.info_hints = []
         self.portals = {}
         self.terrains = {}
 
@@ -291,11 +299,9 @@ class TUI:
         self.force_instant_connect = True
         self.input_lines = []
         self.fov = ''
+        self.flash = False
         curses.wrapper(self.loop)
 
-    def flash(self):
-        curses.flash()
-
     def connect(self):
 
         def handle_recv(msg):
@@ -368,6 +374,7 @@ class TUI:
         if self.mode.shows_info:
             player = self.game.get_thing(self.game.player_id)
             self.explorer = YX(player.position.y, player.position.x)
+            self.query_info()
         if self.mode.name == 'waiting_for_server':
             self.log_msg('@ waiting for server …')
         if self.mode.name == 'edit':
@@ -426,12 +433,12 @@ class TUI:
                                                            self.window_width)
 
         def move_explorer(direction):
-            target = self.game.map_geometry.move(self.explorer, direction)
+            target = self.game.map_geometry.move_yx(self.explorer, direction)
             if target:
                 self.explorer = target
                 self.query_info()
             else:
-                self.flash()
+                self.flash = True
 
         def draw_history():
             lines = []
@@ -456,6 +463,10 @@ class TUI:
                 if terrain_char in self.game.terrains:
                     terrain_desc = self.game.terrains[terrain_char]
                 info = 'TERRAIN: "%s" / %s\n' % (terrain_char, terrain_desc)
+                protection = self.game.map_control_content[pos_i]
+                if protection == '.':
+                    protection = 'unprotected'
+                info = 'PROTECTION: %s\n' % protection
                 for t in self.game.things:
                     if t.position == self.explorer:
                         info += 'THING: %s / %s' % (t.type_,
@@ -509,7 +520,10 @@ class TUI:
                 start = self.game.map_geometry.size.x * y
                 end = start + self.game.map_geometry.size.x
                 map_lines_split += [[c + ' ' for c in map_content[start:end]]]
-            if self.map_mode == 'terrain':
+            if self.map_mode == 'annotations':
+                for p in self.game.info_hints:
+                    map_lines_split[p.y][p.x] = 'A '
+            elif self.map_mode == 'terrain':
                 for p in self.game.portals.keys():
                     map_lines_split[p.y][p.x] = 'P '
                 used_positions = []
@@ -577,13 +591,12 @@ class TUI:
             elif self.mode == self.mode_study:
                 content += 'Available actions:\n'
                 content += '[%s] – move question mark\n' % ','.join(self.movement_keys)
-                content += '[%s] – toggle view between terrain, and password protection areas\n' % self.keys['toggle_map_mode']
+                content += '[%s] – toggle view between terrain, annotations, and password protection areas\n' % self.keys['toggle_map_mode']
                 content += '\n\nOther modes available from here:'
                 content += '[%s] – chat mode\n' % self.keys['switch_to_chat']
                 content += '[%s] – play mode\n' % self.keys['switch_to_play']
             elif self.mode == self.mode_chat:
                 content += '/nick NAME – re-name yourself to NAME\n'
-                #content += '/msg USER TEXT – send TEXT to USER\n'
                 content += '/%s or /play – switch to play mode\n' % self.keys['switch_to_play']
                 content += '/%s or /study – switch to study mode\n' % self.keys['switch_to_study']
             for i in range(self.size.y):
@@ -636,6 +649,9 @@ class TUI:
                 else:
                     self.send('PING')
                 last_ping = now
+            if self.flash:
+                curses.flash()
+                self.flash = False
             if self.do_refresh:
                 draw_screen()
                 self.do_refresh = False
@@ -716,6 +732,8 @@ class TUI:
                     self.switch_mode('play')
                 elif key == self.keys['toggle_map_mode']:
                     if self.map_mode == 'terrain':
+                        self.map_mode = 'annotations'
+                    elif self.map_mode == 'annotations':
                         self.map_mode = 'control'
                     else:
                         self.map_mode = 'terrain'
@@ -748,7 +766,7 @@ class TUI:
                         self.host = self.game.portals[player.position]
                         self.reconnect()
                     else:
-                        self.flash()
+                        self.flash = True
                         self.log_msg('? not standing on portal')
                 elif key in self.movement_keys and 'MOVE' in self.game.tasks:
                     self.send('TASK:MOVE ' + self.movement_keys[key])