def remove_settlement(self, building): """Removes the settlement property from tiles within the radius of the given building""" settlement = building.settlement buildings_to_abandon, settlement_coords_to_change = Tear.additional_removals_after_tear(building) assert building not in buildings_to_abandon self.abandon_buildings(buildings_to_abandon) flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)] land_or_coast = self.terrain_cache.land_or_coast settlement_tiles_changed = [] clean_coords = set() for coords in settlement_coords_to_change: tile = self.ground_map[coords] tile.settlement = None building = tile.object if building is not None: settlement.remove_building(building) building.owner = None building.settlement = None if coords in land_or_coast: clean_coords.add(coords) settlement_tiles_changed.append(self.ground_map[coords]) del settlement.ground_map[coords] Minimap.update(coords) if coords in flat_land_set: self.available_flat_land += 1 self.available_land_cache.add_area(clean_coords) self._register_change() if self.terrain_cache: settlement.buildability_cache.modify_area(clean_coords) SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
def confirm_ranged_delete(self, building): buildings_to_destroy = len(Tear.additional_removals_after_tear(building)[0]) if buildings_to_destroy == 0: return True title = _("Destroy all buildings") msg = _("This will destroy all the buildings that fall outside of" " the settlement range.") msg += u"\n\n" msg += N_("%s additional building will be destroyed.", "%s additional buildings will be destroyed", buildings_to_destroy) % buildings_to_destroy return building.session.ingame_gui.show_popup(title, msg, show_cancel_button=True)
def remove_settlement(self, position, radius, settlement): """Removes the settlement property from tiles within the circle defined by \ position and radius. @param position: Rect @param radius: @param settlement: """ buildings_to_abandon, settlement_coords_to_change = Tear.destroyable_buildings(position, settlement) self.abandon_buildings(buildings_to_abandon) flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)] land_or_coast = self.terrain_cache.land_or_coast settlement_tiles_changed = [] clean_coords = set() for coords in settlement_coords_to_change: tile = self.ground_map[coords] tile.settlement = None building = tile.object if building is not None: settlement.remove_building(building) building.owner = None building.settlement = None if coords in land_or_coast: clean_coords.add(coords) settlement_tiles_changed.append(self.ground_map[coords]) del settlement.ground_map[coords] Minimap.update(coords) if coords in flat_land_set: self.available_flat_land += 1 self.available_land_cache.add_area(clean_coords) self._register_change() if self.terrain_cache: settlement.buildability_cache.modify_area(clean_coords) SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
def destruct_building(self): self.instance.session.ingame_gui.hide_menu() Tear(self.instance).execute(self.instance.session)
def remove(s, p): """ Place a couple of buildings and tear down one randomly, run a while afterwards. Called by test_removal with different parameters. """ settlement, island = settle(s) settlement.warehouse.get_component( StorageComponent).inventory.adjust_limit(sys.maxsize) # Plant trees for (x, y) in product(range(23, 38), repeat=2): if s.random.randint(0, 1) == 1: tree = Build(BUILDINGS.TREE, x, y, island, settlement=settlement)(p) assert tree tree.get_component(Producer).finish_production_now() jack = Build(BUILDINGS.LUMBERJACK, 25, 30, island, settlement=settlement)(p) assert jack jack = Build(BUILDINGS.LUMBERJACK, 35, 30, island, settlement=settlement)(p) assert jack # Throw some fish into the water for x in (25, 30, 35): school = Build(BUILDINGS.FISH_DEPOSIT, x, 18, s.world, ownerless=True)(None) assert school school.get_component(Producer).finish_production_now() fisherman = Build(BUILDINGS.FISHER, 25, 20, island, settlement=settlement)(p) assert fisherman fisherman = Build(BUILDINGS.FISHER, 35, 20, island, settlement=settlement)(p) assert fisherman # Some wild animals in the forest for (x_off, y_off) in product([-5, -4, 4, 5], repeat=2): x = 30 + x_off y = 30 + y_off animal = CreateUnit(island.worldid, UNITS.WILD_ANIMAL, x, y)(None) assert animal animal.get_component(Producer).finish_production_now() hunter = Build(BUILDINGS.HUNTER, 30, 35, island, settlement=settlement)(p) assert hunter # Build a farm assert Build(BUILDINGS.FARM, 26, 33, island, settlement=settlement)(p) assert Build(BUILDINGS.PASTURE, 22, 33, island, settlement=settlement)(p) assert Build(BUILDINGS.PASTURE, 26, 37, island, settlement=settlement)(p) # Build roads for (start, dest) in [(Point(27, 30), Point(30, 23)), (Point(32, 23), Point(35, 29)), (Point(25, 22), Point(30, 23)), (Point(32, 23), Point(35, 22)), (Point(30, 34), Point(32, 25)), (Point(26, 32), Point(27, 30))]: path = a_star_find_path(start.to_tuple(), dest.to_tuple(), island.path_nodes.nodes) assert path for (x, y) in path: Build(BUILDINGS.TRAIL, x, y, island, settlement=settlement)(p) s.run(seconds=before_ticks) # Tear down a random building that is not a trail or tree. target = [ b for b in settlement.buildings if b.id not in (BUILDINGS.TRAIL, BUILDINGS.TREE) ][tear_index] Tear(target)(p) s.run(seconds=after_ticks)
def handle_mine_empty(self, mine): Tear(mine).execute(self.session) self.land_manager.refresh_resource_deposits()
def abandon_buildings(self, buildings_list): """Abandon all buildings in the list @param buildings_list: buildings to abandon """ for building in buildings_list: Tear(building)(building.owner)
def destruct_building(self): self.instance.session.ingame_gui.hide_menu() if self.destruct_button.gui.isVisible(): self.destruct_button.hide_tooltip() Tear(self.instance).execute(self.instance.session)