From bc8966e5d8af45c551f7b2b42503b08609887475 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 27 Apr 2019 21:21:35 +0200
Subject: [PATCH] Change MAP command to ensuring map exists, not necessarily
 creating it.

---
 new/plomrogue/commands.py |  4 ++--
 new/plomrogue/game.py     | 22 ++++++++++++----------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/new/plomrogue/commands.py b/new/plomrogue/commands.py
index c845ed1..2d9ecb6 100644
--- a/new/plomrogue/commands.py
+++ b/new/plomrogue/commands.py
@@ -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_):
diff --git a/new/plomrogue/game.py b/new/plomrogue/game.py
index d1c9c66..7bf958f 100755
--- a/new/plomrogue/game.py
+++ b/new/plomrogue/game.py
@@ -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:
-- 
2.30.2