X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new%2Fplomrogue%2Fthings.py;h=0e47cc0b6cd6df06fb4f83e6df8b5b856a232456;hb=b65fcff5e5499f5c3c57f0c4d8f205643be5ebb7;hp=db37a04bd11e09d14c912ae79e4aee0f5b05623e;hpb=14d027c893d5576d54a86db2168f5b43dd5f9773;p=plomrogue2-experiments diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index db37a04..0e47cc0 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -113,27 +113,29 @@ class ThingAnimate(Thing): def move_on_dijkstra_map(self, own_pos, targets): visible_map = self.get_visible_map() - dijkstra_map = Map(visible_map.size) + dijkstra_map = Map(visible_map.size, + start_indented=visible_map.start_indented) n_max = 256 dijkstra_map.terrain = [n_max for i in range(dijkstra_map.size_i)] for target in targets: dijkstra_map[target] = 0 shrunk = True + get_neighbors = self.game.map_geometry.get_neighbors while shrunk: shrunk = False for pos in dijkstra_map: if visible_map[pos] != '.': continue - neighbors = self.game.map_geometry.get_neighbors((YX(0,0), pos), - dijkstra_map.size) + neighbors = get_neighbors((YX(0,0), pos), dijkstra_map.size, + dijkstra_map.start_indented) for direction in neighbors: big_yx, small_yx = neighbors[direction] if big_yx == YX(0,0) and \ dijkstra_map[small_yx] < dijkstra_map[pos] - 1: dijkstra_map[pos] = dijkstra_map[small_yx] + 1 shrunk = True - neighbors = self.game.map_geometry.get_neighbors((YX(0,0), own_pos), - dijkstra_map.size) + get_neighbors((YX(0,0), own_pos), dijkstra_map.size, + dijkstra_map.start_indented) n = n_max target_direction = None for direction in sorted(neighbors.keys()): @@ -246,7 +248,7 @@ class ThingAnimate(Thing): def unset_surroundings(self): self._stencil = None - self._surrounding_map = None + self._surroundings = None @property def view_offset(self): @@ -254,27 +256,22 @@ class ThingAnimate(Thing): self.position, self._radius) - def get_surrounding_map(self): - if self._surrounding_map is not None: - return self._surrounding_map - self._surrounding_map = Map(size=YX(self._radius*2+1, self._radius*2+1)) - for pos in self._surrounding_map: - correct = self.game.map_geometry.correct_double_coordinate - big_yx, small_yx = correct(self.game.map_size, (0,0), - pos + self.view_offset) - map_ = self.game.get_map(big_yx, False) - if map_ is None: - map_ = Map(size=self.game.map_size) - self._surrounding_map[pos] = map_[small_yx] - return self._surrounding_map + @property + def surroundings(self): + if self._surroundings is not None: + return self._surroundings + s = self.game.map_geometry.get_view(self.game.map_size, + self.game.get_map, + self._radius, self.view_offset) + self._surroundings = s + return self._surroundings def get_stencil(self): if self._stencil is not None: return self._stencil - surrounding_map = self.get_surrounding_map() - m = Map(surrounding_map.size, ' ') - for pos in surrounding_map: - if surrounding_map[pos] in {'.', '~'}: + m = Map(self.surroundings.size, ' ', self.surroundings.start_indented) + for pos in self.surroundings: + if self.surroundings[pos] in {'.', '~'}: m[pos] = '.' fov_center = YX((m.size.y) // 2, m.size.x // 2) self._stencil = FovMapHex(m, fov_center) @@ -282,10 +279,10 @@ class ThingAnimate(Thing): def get_visible_map(self): stencil = self.get_stencil() - m = Map(self.get_surrounding_map().size, ' ') + m = Map(self.surroundings.size, ' ') for pos in m: if stencil[pos] == '.': - m[pos] = self._surrounding_map[pos] + m[pos] = self.surroundings[pos] return m def get_visible_things(self):