- self._surrounding_map = None
- self._surroundings_offset = None
-
- def must_fix_indentation(self):
- return self._radius % 2 != self.position[1].y % 2
-
- def get_surroundings_offset(self):
- if self._surroundings_offset is not None:
- return self._surroundings_offset
- add_line = self.must_fix_indentation()
- offset = YX(self.position[1].y - self._radius - int(add_line),
- self.position[1].x - self._radius)
- self._surroundings_offset = offset
- return self._surroundings_offset
-
- def get_surrounding_map(self):
- if self._surrounding_map is not None:
- return self._surrounding_map
-
- def pan_and_scan(size_of_axis, pos, offset):
- big_pos = 0
- small_pos = pos + offset
- if small_pos < 0:
- big_pos = -1
- small_pos = size_of_axis + small_pos
- elif small_pos >= size_of_axis:
- big_pos = 1
- small_pos = small_pos - size_of_axis
- return big_pos, small_pos
-
- add_line = self.must_fix_indentation()
- self._surrounding_map = self.world.game.\
- map_type(size=YX(self._radius*2+1+int(add_line),
- self._radius*2+1))
- size = self.world.map_size
- offset = self.get_surroundings_offset()
- for pos in self._surrounding_map:
- big_y, small_y = pan_and_scan(size.y, pos.y, offset.y)
- 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)
- 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
+ self._surroundings = None
+
+ @property
+ def view_offset(self):
+ return self.game.map_geometry.get_view_offset(self.game.map_size,
+ self.position,
+ self._radius)
+
+ @property
+ def surroundings(self):
+ if self._surroundings is not None:
+ return self._surroundings
+ s, close_maps = self.\
+ game.map_geometry.get_view_and_seen_maps(self.game.map_size,
+ self.game.get_map,
+ self._radius,
+ self.view_offset)
+ self.close_maps = close_maps
+ self._surroundings = s
+ return self._surroundings