+ 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][0] % 2
+
+ def get_surroundings_offset(self):
+ if self._surroundings_offset is not None:
+ return self._surroundings_offset
+ add_line = self.must_fix_indentation()
+ offset_y = self.position[1][0] - self._radius - int(add_line)
+ offset_x = self.position[1][1] - self._radius
+ self._surroundings_offset = (offset_y, offset_x)
+ 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=(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[0], pos[0], offset[0])
+ big_x, small_x = pan_and_scan(size[1], pos[1], offset[1])
+ big_yx = (big_y, big_x)
+ small_yx = (small_y, small_x)
+ self._surrounding_map[pos] = self.world.maps[big_yx][small_yx]
+ return self._surrounding_map
+