home · contact · privacy
Change MAP command to ensuring map exists, not necessarily creating it.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 19:21:35 +0000 (21:21 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 19:21:35 +0000 (21:21 +0200)
new/plomrogue/commands.py
new/plomrogue/game.py

index c845ed1ce1dcc2135aad94b4696b768cb8ff86f4..2d9ecb6e1a2088aef39cb4449f00bc6c9446cfad 100644 (file)
@@ -19,8 +19,8 @@ def cmd_MAP_SIZE(game, size):
 cmd_MAP_SIZE.argtypes = 'yx_tuple:pos'
 
 def cmd_MAP(game, map_pos):
-    """Create new map at position map_pos and only of '?' cells."""
-    game.world.new_map(map_pos)
+    """Ensure (possibly empty/'?'-filled) map at position map_pos."""
+    game.world.ensure_map(map_pos)
 cmd_MAP.argtypes = 'yx_tuple'
 
 def cmd_THING_TYPE(game, i, type_):
index d1c9c665ffb18649f5819831ef2193e48a0b3cdf..7bf958f2a513714f99158475a0e3220d3db1530c 100755 (executable)
@@ -79,7 +79,9 @@ class World(WorldBase):
             return 0
         return self.things[-1].id_ + 1
 
-    def new_map(self, map_pos):
+    def ensure_map(self, map_pos):
+        if map_pos in self.maps and self.maps[map_pos].size == self.map_size:
+            return
         self.maps[map_pos] = self.game.map_type(self.map_size)
 
     def proceed_to_next_player_turn(self):
@@ -136,15 +138,15 @@ class World(WorldBase):
         self.turn = 0
         self.maps = {}
         self.map_size = yx
-        self.new_map(YX(0,0))
-        self.new_map(YX(0,1))
-        self.new_map(YX(1,1))
-        self.new_map(YX(1,0))
-        self.new_map(YX(1,-1))
-        self.new_map(YX(0,-1))
-        self.new_map(YX(-1,-1))
-        self.new_map(YX(-1,0))
-        self.new_map(YX(-1,1))
+        self.ensure_map(YX(0,0))
+        self.ensure_map(YX(0,1))
+        self.ensure_map(YX(1,1))
+        self.ensure_map(YX(1,0))
+        self.ensure_map(YX(1,-1))
+        self.ensure_map(YX(0,-1))
+        self.ensure_map(YX(-1,-1))
+        self.ensure_map(YX(-1,0))
+        self.ensure_map(YX(-1,1))
         for map_pos in self.maps:
             map_ = self.maps[map_pos]
             if YX(0,0) == map_pos: