当前位置: 首页>>代码示例>>Python>>正文


Python ProductionBuilder.handle_lost_area方法代码示例

本文整理汇总了Python中horizons.ai.aiplayer.productionbuilder.ProductionBuilder.handle_lost_area方法的典型用法代码示例。如果您正苦于以下问题:Python ProductionBuilder.handle_lost_area方法的具体用法?Python ProductionBuilder.handle_lost_area怎么用?Python ProductionBuilder.handle_lost_area使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在horizons.ai.aiplayer.productionbuilder.ProductionBuilder的用法示例。


在下文中一共展示了ProductionBuilder.handle_lost_area方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SettlementManager

# 需要导入模块: from horizons.ai.aiplayer.productionbuilder import ProductionBuilder [as 别名]
# 或者: from horizons.ai.aiplayer.productionbuilder.ProductionBuilder import handle_lost_area [as 别名]

#.........这里部分代码省略.........
			if self._manual_upgrade(0, 1):
				self._set_taxes_and_permissions_prefix('early')
		elif self.get_resource_production(RES.BRICKS) > 1e-9 and not self.settlement.count_buildings(BUILDINGS.VILLAGE_SCHOOL):
			# if we just need the school then upgrade sailors manually
			free_boards = self.settlement.get_component(StorageComponent).inventory[RES.BOARDS]
			free_boards -= Entities.buildings[BUILDINGS.VILLAGE_SCHOOL].costs[RES.BOARDS]
			free_boards /= 2 # TODO: load this from upgrade resources
			if free_boards > 0:
				self._manual_upgrade(0, free_boards)
			self._set_taxes_and_permissions_prefix('no_school')
		elif self.settlement.count_buildings(BUILDINGS.VILLAGE_SCHOOL):
			if self.need_materials:
				self._set_taxes_and_permissions_prefix('school')
			else:
				self._set_taxes_and_permissions_prefix('final')

	def _end_general_tick(self):
		self.trade_manager.finalize_requests()
		self.trade_manager.organize_shipping()
		self.resource_manager.record_expected_exportable_production(self.owner.tick_interval)
		self.resource_manager.manager_buysell()
		self.resource_manager.finish_tick()

	def _add_goals(self, goals):
		"""Add the settlement's goals that can be activated to the goals list."""
		for goal in self._goals:
			if goal.can_be_activated:
				goal.update()
				goals.append(goal)

	def tick(self, goals):
		"""Refresh the settlement info and add its goals to the player's goal list."""
		if self.feeder_island:
			self._start_feeder_tick()
			self._add_goals(goals)
			self._end_feeder_tick()
		else:
			self._start_general_tick()
			self._add_goals(goals)
			self._end_general_tick()

	def add_building(self, building):
		"""Called when a new building is added to the settlement (the building already exists during the call)."""
		coords = building.position.origin.to_tuple()
		if coords in self.village_builder.plan:
			self.village_builder.add_building(building)
		else:
			self.production_builder.add_building(building)

	def remove_building(self, building):
		"""Called when a building is removed from the settlement (the building still exists during the call)."""
		coords = building.position.origin.to_tuple()
		if coords in self.village_builder.plan:
			self.village_builder.remove_building(building)
		else:
			self.production_builder.remove_building(building)

	def handle_lost_area(self, coords_list):
		"""
		Handle losing the potential land in the given coordinates list.

		Take the following actions:
		* remove the lost area from the village, production, and road areas
		* remove village sections with impossible main squares
		* remove all planned buildings that are now impossible from the village area
		* remove planned fields that are now impossible
		* remove fields that can no longer be serviced by a farm
		* TODO: if the village area takes too much of the total area then remove / reduce the remaining sections
		"""

		self.land_manager.handle_lost_area(coords_list)
		self.village_builder.handle_lost_area(coords_list)
		self.production_builder.handle_lost_area(coords_list)
		self.production_builder.handle_new_area() # some of the village area may have been repurposed as production area

		self.village_builder.display()
		self.production_builder.display()

	def handle_disaster(self, message):
		if issubclass(message.disaster_class, FireDisaster):
			position = message.building.position
			fire_station_radius = Entities.buildings[BUILDINGS.FIRE_STATION].radius
			handled = False

			for fire_station in self.settlement.buildings_by_id[BUILDINGS.FIRE_STATION]:
				if fire_station.position.distance(position) > fire_station_radius:
					continue
				# TODO: check whether the building and the fire station are connected by road
				self.log.info('%s ignoring %s at %s because %s should be able to handle it', self, message.disaster_class.__name__, message.building, fire_station)
				handled = True
				break

			if not handled:
				self.log.info('%s removing %s because of %s', self, message.building, message.disaster_class.__name__)
				Tear(message.building).execute(self.session)
		else:
			self.log.info('%s ignoring unknown disaster of type %s', self, message.disaster_class.__name__)

	def __str__(self):
		return '%s.SM(%s/%s)' % (self.owner, self.settlement.get_component(NamedComponent).name if hasattr(self, 'settlement') else 'unknown', self.worldid if hasattr(self, 'worldid') else 'none')
开发者ID:STEVEOO6,项目名称:unknown-horizons,代码行数:104,代码来源:settlementmanager.py


注:本文中的horizons.ai.aiplayer.productionbuilder.ProductionBuilder.handle_lost_area方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。