+ def unset_surroundings(self):
+ self._stencil = None
+ 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
+