當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。