From 15ad903f7da0dd35945f79ff26e4528378eaf31f Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Wed, 16 Dec 2020 21:23:39 +0100 Subject: [PATCH] Replace client TURN line with frequently updated toilet need stat. --- plomrogue/game.py | 11 +++++++---- rogue_chat.html | 18 ++++++++++-------- rogue_chat_curses.py | 17 +++++++++++------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/plomrogue/game.py b/plomrogue/game.py index d3ab1e7..5f91a11 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -136,9 +136,10 @@ class Game(GameBase): self.players_hat_chars = {} self.player_char_i = -1 self.admin_passwords = [] - self.send_gamestate_interval = datetime.timedelta(seconds=0.04) + self.send_gamestate_min_interval = datetime.timedelta(seconds=0.04) + self.send_gamestate_max_interval = datetime.timedelta(seconds=5) self.last_send_gamestate = datetime.datetime.now() -\ - self.send_gamestate_interval + self.send_gamestate_min_interval self.terrains = { '.': Terrain('.', 'floor'), 'X': Terrain('X', 'wall', blocks_light=True, blocks_sound=True, @@ -276,6 +277,7 @@ class Game(GameBase): player = self.get_player(c_id) self.io.send('PLAYERS_HAT_CHARS ' + quote(player.get_cookie_chars()), c_id) + self.io.send('BLADDER_PRESSURE %s' % player.need_for_toilet) if player.id_ in player_ids_send_fov: self.io.send('FOV %s' % quote(player.fov_stencil.terrain), c_id) self.io.send('MAP %s %s %s' % (self.get_map_geometry_shape(), @@ -387,12 +389,13 @@ class Game(GameBase): self.io.send('PLAY_ERROR ' + quote(str(e)), connection_id) # send gamestate if it makes sense at this point - if self.changed: + if self.changed or self.last_send_gamestate < \ + datetime.datetime.now() - self.send_gamestate_max_interval: self.turn += 1 # send_gamestate() can be rather expensive, due to among other reasons # re-calculating players' FOVs, so don't send it out too often if self.last_send_gamestate < \ - datetime.datetime.now() -self.send_gamestate_interval: + datetime.datetime.now() - self.send_gamestate_min_interval: n_changes = 0 for type_ in self.changed_tiles: n_changes += len(self.changed_tiles[type_]) diff --git a/rogue_chat.html b/rogue_chat.html index 212a1d6..291a98c 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -129,8 +129,8 @@ terminal rows: <input id="n_rows" type="number" step=4 min=24 value=24 /> </div> <script> "use strict"; -let websocket_location = "wss://plomlompom.com/rogue_chat/"; -//let websocket_location = "ws://localhost:8000/"; +//let websocket_location = "wss://plomlompom.com/rogue_chat/"; +let websocket_location = "ws://localhost:8000/"; let mode_helps = { 'play': { @@ -485,11 +485,12 @@ let server = { let tokens = parser.tokenize(event.data); if (tokens[0] === 'TURN') { game.turn_complete = false; - game.turn = parseInt(tokens[1]); } else if (tokens[0] === 'OTHER_WIPE') { game.portals_new = {}; explorer.annotations_new = {}; game.things_new = []; + } else if (tokens[0] === 'BLADDER_PRESSURE') { + game.bladder_pressure_new = parseInt(tokens[1]) } else if (tokens[0] === 'THING') { let t = game.get_thing_temp(tokens[4], true); t.position = parser.parse_yx(tokens[1]); @@ -546,6 +547,7 @@ let server = { game.things = game.things_new; game.player = game.things[game.player_id]; game.players_hat_chars = game.players_hat_chars_new; + game.bladder_pressure = game.bladder_pressure_new game.turn_complete = true; if (tui.mode.name == 'post_login_wait') { tui.switch_mode('play'); @@ -1210,10 +1212,8 @@ let tui = { } terminal.write(0, this.window_width, 'MODE: ' + this.mode.short_desc + ' â ' + help); }, - draw_turn_line: function(n) { - if (game.turn_complete) { - terminal.write(1, this.window_width, 'TURN: ' + game.turn); - } + draw_stats_line: function(n) { + terminal.write(1, this.window_width, 'BLADDER: ' + game.bladder_pressure); }, draw_history: function() { let log_display_lines = []; @@ -1328,7 +1328,7 @@ let tui = { this.draw_input(); } else { this.draw_map(); - this.draw_turn_line(); + this.draw_stats_line(); this.draw_mode_line(); if (this.mode.shows_info) { this.draw_info(); @@ -1368,6 +1368,8 @@ let game = { this.portals = {}; this.portals_new = {}; this.players_hat_chars = ""; + this.bladder_pressure = 0; + this.bladder_pressure_new = 0; }, get_thing_temp: function(id_, create_if_not_found=false) { if (id_ in game.things_new) { diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index ff55924..d469340 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -174,7 +174,6 @@ class PlomSocketClient(PlomSocket): pass # we assume socket will be known as dead by now def cmd_TURN(game, n): - game.turn = n game.turn_complete = False cmd_TURN.argtypes = 'int:nonneg' @@ -294,6 +293,7 @@ def cmd_GAME_STATE_COMPLETE(game): game.map_control_content = game.map_control_content_new game.player = game.get_thing(game.player_id) game.players_hat_chars = game.players_hat_chars_new + game.bladder_pressure = game.bladder_pressure_new game.turn_complete = True if game.tui.mode.name == 'post_login_wait': game.tui.switch_mode('play') @@ -361,6 +361,10 @@ def cmd_RANDOM_COLORS(game): game.tui.set_random_colors() cmd_RANDOM_COLORS.argtypes = '' +def cmd_BLADDER_PRESSURE(game, bladder_pressure): + game.bladder_pressure_new = bladder_pressure +cmd_BLADDER_PRESSURE.argtypes = 'int:nonneg' + class Game(GameBase): turn_complete = False tasks = {} @@ -400,6 +404,7 @@ class Game(GameBase): self.register_command(cmd_FOV) self.register_command(cmd_DEFAULT_COLORS) self.register_command(cmd_RANDOM_COLORS) + self.register_command(cmd_BLADDER_PRESSURE) self.map_content = '' self.players_hat_chars = '' self.player_id = -1 @@ -409,6 +414,8 @@ class Game(GameBase): self.portals_new = {} self.terrains = {} self.player = None + self.bladder_pressure_new = 0 + self.bladder_pressure = 0 def get_string_options(self, string_option_type): if string_option_type == 'map_geometry': @@ -936,10 +943,8 @@ class TUI: safe_addstr(y, self.window_width, self.input_lines[i]) y += 1 - def draw_turn(): - if not self.game.turn_complete: - return - safe_addstr(0, self.window_width, 'TURN: ' + str(self.game.turn)) + def draw_stats(): + safe_addstr(0, self.window_width, 'BLADDER: ' + str(self.game.bladder_pressure)) def draw_mode(): help = "hit [%s] for help" % self.keys['help'] @@ -1087,7 +1092,7 @@ class TUI: draw_history() draw_mode() if not self.mode.is_intro: - draw_turn() + draw_stats() draw_map() if self.show_help: draw_help() -- 2.30.2