From: Christian Heller Date: Sat, 27 Apr 2019 19:21:35 +0000 (+0200) Subject: Change MAP command to ensuring map exists, not necessarily creating it. X-Git-Url: https://plomlompom.com/repos/task?a=commitdiff_plain;h=bc8966e5d8af45c551f7b2b42503b08609887475;p=plomrogue2-experiments Change MAP command to ensuring map exists, not necessarily creating it. --- 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: