From: Christian Heller Date: Sat, 27 Apr 2019 20:01:16 +0000 (+0200) Subject: Only contact with player's radius creates new maps. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/static/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=adbbe8b5526c6d9ae05ca646a5d6da2f347d93c8;p=plomrogue2-experiments Only contact with player's radius creates new maps. --- diff --git a/new/plomrogue/commands.py b/new/plomrogue/commands.py index 2d9ecb6..bd740b7 100644 --- a/new/plomrogue/commands.py +++ b/new/plomrogue/commands.py @@ -20,7 +20,7 @@ cmd_MAP_SIZE.argtypes = 'yx_tuple:pos' def cmd_MAP(game, map_pos): """Ensure (possibly empty/'?'-filled) map at position map_pos.""" - game.world.ensure_map(map_pos) + game.world.get_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 7bf958f..669fae3 100755 --- a/new/plomrogue/game.py +++ b/new/plomrogue/game.py @@ -79,10 +79,16 @@ class World(WorldBase): return 0 return self.things[-1].id_ + 1 - 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 get_map(self, map_pos, create_unfound=True): + if not (map_pos in self.maps and + self.maps[map_pos].size == self.map_size): + if create_unfound: + self.maps[map_pos] = self.game.map_type(self.map_size) + for pos in self.maps[map_pos]: + self.maps[map_pos][pos] = '~' + else: + return None + return self.maps[map_pos] def proceed_to_next_player_turn(self): """Run game world turns until player can decide their next step. @@ -138,23 +144,9 @@ class World(WorldBase): self.turn = 0 self.maps = {} self.map_size = yx - 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: - for pos in map_: - map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x')) - else: - for pos in map_: - map_[pos] = '~' + map_ = self.get_map(YX(0,0)) + for pos in map_: + map_[pos] = self.rand.choice(('.', '.', '.', '.', 'x')) player = add_thing_at_random('human') self.player_id = player.id_ add_thing_at_random('monster') diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index 1b3a46d..ed3b547 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -8,11 +8,11 @@ class ThingBase: def __init__(self, world, id_=None, position=(YX(0,0), YX(0,0))): self.world = world - self.position = position if id_ is None: self.id_ = self.world.new_thing_id() else: self.id_ = id_ + self.position = position @property def position(self): @@ -42,6 +42,7 @@ class Thing(ThingBase): def __init__(self, *args, **kwargs): self.inventory = [] + self._radius = 8 super().__init__(*args, **kwargs) def proceed(self): @@ -52,6 +53,28 @@ class Thing(ThingBase): for t_id in self.inventory: t = self.world.get_thing(t_id) t.position = self.position + if not self.id_ == self.world.player_id: + return + edge_left = self.position[1].x - self._radius + edge_right = self.position[1].x + self._radius + edge_up = self.position[1].y - self._radius + edge_down = self.position[1].y + self._radius + if edge_left < 0: + self.world.get_map(self.position[0] - YX(1,-1)) + self.world.get_map(self.position[0] - YX(0,-1)) + self.world.get_map(self.position[0] - YX(-1,-1)) + if edge_right >= self.world.map_size.x: + self.world.get_map(self.position[0] + YX(1,1)) + self.world.get_map(self.position[0] + YX(0,1)) + self.world.get_map(self.position[0] + YX(-1,1)) + if edge_up < 0: + self.world.get_map(self.position[0] - YX(-1,1)) + self.world.get_map(self.position[0] - YX(-1,0)) + self.world.get_map(self.position[0] - YX(-1,-1)) + if edge_down >= self.world.map_size.y: + self.world.get_map(self.position[0] + YX(1,1)) + self.world.get_map(self.position[0] + YX(1,0)) + self.world.get_map(self.position[0] + YX(1,-1)) @@ -72,7 +95,6 @@ class ThingAnimate(Thing): super().__init__(*args, **kwargs) self.set_task('WAIT') self._last_task_result = None - self._radius = 8 self.unset_surroundings() def move_on_dijkstra_map(self, own_pos, targets): @@ -250,7 +272,10 @@ class ThingAnimate(Thing): big_x, small_x = pan_and_scan(size.x, pos.x, offset.x) big_yx = YX(big_y, big_x) small_yx = YX(small_y, small_x) - self._surrounding_map[pos] = self.world.maps[big_yx][small_yx] + map_ = self.world.get_map(big_yx, False) + if map_ is None: + map_ = self.world.game.map_type(size=self.world.map_size) + self._surrounding_map[pos] = map_[small_yx] return self._surrounding_map def get_stencil(self):