From: Christian Heller Date: Fri, 20 Nov 2020 10:33:35 +0000 (+0100) Subject: Introduce spawn points. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/condition?a=commitdiff_plain;h=dbd7f497e0726b80f7df42c53ea7b4ee6a74a280;p=plomrogue2 Introduce spawn points. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 396b228..2903ca3 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -65,14 +65,20 @@ def cmd_ALL(game, msg, connection_id): c_id) cmd_ALL.argtypes = 'string' +def cmd_SPAWN_POINT(game, big_yx, little_yx): + if little_yx.y >= game.map_geometry.size.y or \ + little_yx.x >= game.map_geometry.size.x: + raise GameError('illegal spawn point') + game.spawn_point = big_yx, little_yx +cmd_SPAWN_POINT.argtypes = 'yx_tuple yx_tuple:nonneg' + def cmd_LOGIN(game, nick, connection_id): for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') if game.get_player(connection_id): raise GameError('cannot log in twice') t = game.thing_types['Player'](game) - t.position = (YX(0,0), - YX(game.map_geometry.size.y // 2, game.map_geometry.size.x // 2)) + t.position = game.spawn_point game.things += [t] # TODO refactor into Thing.__init__? t.player_char = game.get_next_player_char() game.sessions[connection_id] = { diff --git a/plomrogue/game.py b/plomrogue/game.py index d7be311..64ae689 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -123,6 +123,7 @@ class Game(GameBase): self.map_controls = {} self.map_control_passwords = {} self.annotations = {} + self.spawn_point = YX(0,0), YX(0,0) self.portals = {} self.player_chars = string.digits + string.ascii_letters self.player_char_i = -1 @@ -334,6 +335,8 @@ class Game(GameBase): t.position[1], t.type_, t.id_)) if hasattr(t, 'name'): write(f, 'THING_NAME %s %s' % (t.id_, quote(t.name))) + write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0], + self.spawn_point[1])) def get_map(self, big_yx, type_='normal'): if type_ == 'normal': @@ -352,6 +355,7 @@ class Game(GameBase): self.annotations = {} self.portals = {} self.admin_passwords = [] + self.spawn_point = YX(0,0), YX(0,0) self.map_geometry = map_geometry self.map_control_passwords = {'X': 'secret'} self.get_map(YX(0,0)) diff --git a/rogue_chat.py b/rogue_chat.py index 18fc91b..1f40913 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -9,7 +9,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES, cmd_THING_NAME, cmd_TERRAINS, cmd_ADMIN_PASSWORD, cmd_BECOME_ADMIN, cmd_SET_TILE_CONTROL, - cmd_SET_MAP_CONTROL_PASSWORD) + cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS) from plomrogue.things import Thing_Player, Thing_Item, Thing_Furniture @@ -44,6 +44,7 @@ game.register_command(cmd_ADMIN_PASSWORD) game.register_command(cmd_SET_TILE_CONTROL) game.register_command(cmd_SET_MAP_CONTROL_PASSWORD) game.register_command(cmd_BECOME_ADMIN) +game.register_command(cmd_SPAWN_POINT) game.register_task(Task_WAIT) game.register_task(Task_MOVE) game.register_task(Task_WRITE)