本文整理汇总了Python中horizons.messaging.SettlementRangeChanged.broadcast方法的典型用法代码示例。如果您正苦于以下问题:Python SettlementRangeChanged.broadcast方法的具体用法?Python SettlementRangeChanged.broadcast怎么用?Python SettlementRangeChanged.broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.messaging.SettlementRangeChanged
的用法示例。
在下文中一共展示了SettlementRangeChanged.broadcast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_settlement
# 需要导入模块: from horizons.messaging import SettlementRangeChanged [as 别名]
# 或者: from horizons.messaging.SettlementRangeChanged import broadcast [as 别名]
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)
示例2: assign_settlement
# 需要导入模块: from horizons.messaging import SettlementRangeChanged [as 别名]
# 或者: from horizons.messaging.SettlementRangeChanged import broadcast [as 别名]
def assign_settlement(self, position, radius, settlement):
"""Assigns the settlement property to tiles within the circle defined by \
position and radius.
@param position: Rect
@param radius:
@param settlement:
"""
settlement_coords_changed = []
for coords in position.get_radius_coordinates(radius, include_self=True):
if coords not in self.ground_map:
continue
tile = self.ground_map[coords]
if tile.settlement is not None:
continue
tile.settlement = settlement
settlement.ground_map[coords] = tile
settlement_coords_changed.append(coords)
building = tile.object
# In theory fish deposits should never be on the island but this has been
# possible since they were turned into a 2x2 building. Since they are never
# entirely on the island then it is easiest to just make it impossible to own
# fish deposits.
if building is None or building.id == BUILDINGS.FISH_DEPOSIT:
continue
# Assign the entire building to the first settlement that covers some of it.
assert building.settlement is None or building.settlement is settlement
for building_coords in building.position.tuple_iter():
building_tile = self.ground_map[building_coords]
if building_tile.settlement is not settlement:
assert building_tile.settlement is None
building_tile.settlement = settlement
settlement.ground_map[building_coords] = building_tile
settlement_coords_changed.append(building_coords)
building.settlement = settlement
building.owner = settlement.owner
settlement.add_building(building)
if not settlement_coords_changed:
return
flat_land_set = self.terrain_cache.cache[TerrainRequirement.LAND][(1, 1)]
settlement_tiles_changed = []
for coords in settlement_coords_changed:
settlement_tiles_changed.append(self.ground_map[coords])
Minimap.update(coords)
if coords in flat_land_set:
self.available_flat_land -= 1
self.available_land_cache.remove_area(settlement_coords_changed)
self._register_change()
if self.terrain_cache:
settlement.buildability_cache.modify_area(settlement_coords_changed)
SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
示例3: assign_settlement
# 需要导入模块: from horizons.messaging import SettlementRangeChanged [as 别名]
# 或者: from horizons.messaging.SettlementRangeChanged import broadcast [as 别名]
def assign_settlement(self, position, radius, settlement):
"""Assigns the settlement property to tiles within the circle defined by \
position and radius.
@param position: Rect
@param radius:
@param settlement:
"""
settlement_tiles_changed = []
for coord in position.get_radius_coordinates(radius, include_self=True):
tile = self.get_tile_tuple(coord)
if tile is not None:
if tile.settlement == settlement:
continue
if tile.settlement is None:
tile.settlement = settlement
settlement.ground_map[coord] = tile
Minimap.update(coord)
self._register_change(coord[0], coord[1])
settlement_tiles_changed.append(tile)
# notify all AI players when land ownership changes
for player in self.session.world.players:
if hasattr(player, "on_settlement_expansion"):
player.on_settlement_expansion(settlement, coord)
building = tile.object
# found a new building, that is now in settlement radius
# assign buildings on tiles to settlement
if (
building is not None and building.settlement is None and building.island == self
): # don't steal from other islands
building.settlement = settlement
building.owner = settlement.owner
settlement.add_building(building)
if settlement_tiles_changed:
SettlementRangeChanged.broadcast(settlement, settlement_tiles_changed)
示例4: remove_settlement
# 需要导入模块: from horizons.messaging import SettlementRangeChanged [as 别名]
# 或者: from horizons.messaging.SettlementRangeChanged import broadcast [as 别名]
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)