/
sususer
/
ColonyGEN
Обзор
Документация
Войти
/
sususer
/
ColonyGEN
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
core/simulation/rules.py
72 строки
2 KB
Chekr
f11
03 июн 2026, 13:53
03 июн 2026, 13:53
d260831
Код
Авторство
О чём код?
class RulesSystem: def __init__(self, game_map, simulation): self.map = game_map self.sim = simulation def get_available_buildings(self, x, y): tile = self.map.grid[y][x] if tile.building is not None: return [] if tile.type == "base": return [] if tile.type == "mountain": return ["mine"] if tile.type == "water": if self._has_non_water_neighbor(x, y): return ["bridge"] return [] return [ "generator", "mine", "researchstation", "wire", "road" ] def place_building(self, building, x, y): if not self.can_place(building.__class__, x, y): return False tile = self.map.grid[y][x] tile.building = building return True def can_place(self, building_class, x, y): if not self._in_bounds(x, y): return False tile = self.map.grid[y][x] if tile.type == "base": return False if tile.building is not None: return False name = building_class.__name__.lower() if tile.type == "mountain": return name == "mine" if tile.type == "water": return name == "bridge" and self._has_non_water_neighbor(x, y) if name == "road": return tile.type not in ("water", "mountain", "base") return True def _has_non_water_neighbor(self, x, y): for ny in range(max(0, y - 1), min(self.map.height, y + 2)): for nx in range(max(0, x - 1), min(self.map.width, x + 2)): if self.map.grid[ny][nx].type != "water": return True return False def _in_bounds(self, x, y): return 0 <= x < self.map.width and 0 <= y < self.map.height