home · contact · privacy
Introduce spawn points.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 20 Nov 2020 10:33:35 +0000 (11:33 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 20 Nov 2020 10:33:35 +0000 (11:33 +0100)
plomrogue/commands.py
plomrogue/game.py
rogue_chat.py

index 396b228879c1b3637e4b98acbeb78fe81b2bf2d3..2903ca3589832fcc92467dd542ee02833d02dcac 100644 (file)
@@ -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] = {
index d7be311f3d54dc02535fa1471c510d2e8db03263..64ae6898a9f9c11d56506d37f114d3e997585af0 100755 (executable)
@@ -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))
index 18fc91bf2b7a0f707b8b65640054ac1ecfb0ca27..1f40913eae7b4c11fc7baf3624470e221c72eab8 100755 (executable)
@@ -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)