X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=rogue_chat_curses.py;h=a58b842e70a46154341ea003f904d333f10b5972;hb=eb000b9ee11d2bf17ac3e70b62631c51bb24ee11;hp=07c8697fc71d160cf63d9f43914f2d1ed64d58ec;hpb=aaaa37601edeb1faa412780fee546e32bf92f4d2;p=plomrogue2 diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 07c8697..a58b842 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -29,7 +29,7 @@ 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', @@ -49,7 +49,7 @@ mode_helps = { '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': 'edit face', @@ -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' @@ -187,7 +186,9 @@ cmd_OTHER_WIPE.argtypes = '' def cmd_LOGIN_OK(game): game.tui.switch_mode('post_login_wait') game.tui.send('GET_GAMESTATE') - game.tui.log_msg('@ welcome') + game.tui.log_msg('@ welcome!') + game.tui.log_msg('@ hint: see top of terminal for how to get help.') + game.tui.log_msg('@ hint: enter study mode to understand your environment.') cmd_LOGIN_OK.argtypes = '' def cmd_ADMIN_OK(game): @@ -256,14 +257,14 @@ def cmd_MAP(game, geometry, size, content): map_geometry_class = globals()['MapGeometry' + geometry] game.map_geometry_new = map_geometry_class(size) game.map_content_new = content - if type(game.map_geometry) == MapGeometrySquare: + if type(game.map_geometry_new) == MapGeometrySquare: game.tui.movement_keys = { game.tui.keys['square_move_up']: 'UP', game.tui.keys['square_move_left']: 'LEFT', game.tui.keys['square_move_down']: 'DOWN', game.tui.keys['square_move_right']: 'RIGHT', } - elif type(game.map_geometry) == MapGeometryHex: + elif type(game.map_geometry_new) == MapGeometryHex: game.tui.movement_keys = { game.tui.keys['hex_move_upleft']: 'UPLEFT', game.tui.keys['hex_move_upright']: 'UPRIGHT', @@ -294,6 +295,8 @@ 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.energy = game.energy_new game.turn_complete = True if game.tui.mode.name == 'post_login_wait': game.tui.switch_mode('play') @@ -342,7 +345,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): @@ -361,6 +364,11 @@ def cmd_RANDOM_COLORS(game): game.tui.set_random_colors() cmd_RANDOM_COLORS.argtypes = '' +def cmd_STATS(game, bladder_pressure, energy): + game.bladder_pressure_new = bladder_pressure + game.energy_new = energy +cmd_STATS.argtypes = 'int:nonneg int' + class Game(GameBase): turn_complete = False tasks = {} @@ -400,6 +408,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_STATS) self.map_content = '' self.players_hat_chars = '' self.player_id = -1 @@ -503,7 +512,7 @@ class TUI: "command_thing", "take_thing", "drop_thing"] self.mode_play.available_actions = ["move", "teleport", "door", "consume", - "install", "wear", "spin"] + "install", "wear", "spin", "dance"] self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"] self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"] self.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type", @@ -514,7 +523,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"] @@ -556,6 +566,7 @@ class TUI: 'install': 'I', 'wear': 'W', 'spin': 'S', + 'dance': 'T', 'help': 'h', 'toggle_map_mode': 'L', 'toggle_tile_draw': 'm', @@ -649,11 +660,11 @@ 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 @@ -691,6 +702,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: @@ -699,17 +714,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'}: @@ -730,26 +734,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 =\ @@ -927,10 +946,10 @@ 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(): + stats = 'ENERGY: %s BLADDER: %s' % (self.game.energy, + self.game.bladder_pressure) + safe_addstr(0, self.window_width, stats) def draw_mode(): help = "hit [%s] for help" % self.keys['help'] @@ -1078,7 +1097,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() @@ -1126,6 +1145,7 @@ class TUI: 'door': 'open/close', 'consume': 'consume', 'spin': 'spin', + 'dance': 'dance', } action_tasks = { @@ -1139,6 +1159,7 @@ class TUI: 'command': 'COMMAND', 'consume': 'INTOXICATE', 'spin': 'SPIN', + 'dance': 'DANCE', } curses.curs_set(False) # hide cursor @@ -1250,8 +1271,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': @@ -1279,9 +1299,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_ == '': @@ -1313,6 +1332,8 @@ class TUI: self.send('TASK:WEAR') elif key == self.keys['spin'] and task_action_on('spin'): self.send('TASK:SPIN') + elif key == self.keys['dance'] and task_action_on('dance'): + self.send('TASK:DANCE') elif key == self.keys['teleport']: if self.game.player.position in self.game.portals: self.host = self.game.portals[self.game.player.position]