本文整理匯總了Python中FleetUtilsAI.split_ship_from_fleet方法的典型用法代碼示例。如果您正苦於以下問題:Python FleetUtilsAI.split_ship_from_fleet方法的具體用法?Python FleetUtilsAI.split_ship_from_fleet怎麽用?Python FleetUtilsAI.split_ship_from_fleet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FleetUtilsAI
的用法示例。
在下文中一共展示了FleetUtilsAI.split_ship_from_fleet方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: issue_fleet_orders
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import split_ship_from_fleet [as 別名]
#.........這裏部分代碼省略.........
debug("Check if PROTECT_REGION mission with target %d is finished.", last_sys_target)
fleet_id = self.fleet.id
if clear_all:
if orders:
debug("Fleet %d has completed its mission; clearing all orders and targets." % self.fleet.id)
debug("Full set of orders were:")
for this_order in orders:
debug("\t\t %s" % this_order)
self.clear_fleet_orders()
self.clear_target()
if aistate.get_fleet_role(fleet_id) in (MissionType.MILITARY, MissionType.SECURE):
allocations = MilitaryAI.get_military_fleets(mil_fleets_ids=[fleet_id],
try_reset=False,
thisround="Fleet %d Reassignment" % fleet_id)
if allocations:
MilitaryAI.assign_military_fleets_to_systems(use_fleet_id_list=[fleet_id],
allocations=allocations)
else: # no orders
debug("No Current Orders")
else:
potential_threat = CombatRatingsAI.combine_ratings(
MilitaryAI.get_system_local_threat(last_sys_target),
MilitaryAI.get_system_neighbor_threat(last_sys_target)
)
threat_present = potential_threat > 0
debug("Fleet threat present? %s", threat_present)
target_system = universe.getSystem(last_sys_target)
if not threat_present and target_system:
for pid in target_system.planetIDs:
planet = universe.getPlanet(pid)
if (planet and
planet.owner != fo.empireID() and
planet.currentMeterValue(fo.meterType.maxDefense) > 0):
debug("Found local planetary threat: %s", planet)
threat_present = True
break
if not threat_present:
debug("No current threat in target system; releasing a portion of ships.")
# at least first stage of current task is done;
# release extra ships for potential other deployments
new_fleets = FleetUtilsAI.split_fleet(self.fleet.id)
if self.type == MissionType.PROTECT_REGION:
self.clear_fleet_orders()
self.clear_target()
new_fleets.append(self.fleet.id)
else:
debug("Threat remains in target system; Considering to release some ships.")
new_fleets = []
fleet_portion_to_remain = self._portion_of_fleet_needed_here()
if fleet_portion_to_remain > 1:
debug("Can not release fleet yet due to large threat.")
elif fleet_portion_to_remain > 0:
debug("Not all ships are needed here - considering releasing a few")
fleet_remaining_rating = CombatRatingsAI.get_fleet_rating(fleet_id)
fleet_min_rating = fleet_portion_to_remain * fleet_remaining_rating
debug("Starting rating: %.1f, Target rating: %.1f",
fleet_remaining_rating, fleet_min_rating)
allowance = CombatRatingsAI.rating_needed(fleet_remaining_rating, fleet_min_rating)
debug("May release ships with total rating of %.1f", allowance)
ship_ids = list(self.fleet.get_object().shipIDs)
for ship_id in ship_ids:
ship_rating = CombatRatingsAI.get_ship_rating(ship_id)
debug("Considering to release ship %d with rating %.1f", ship_id, ship_rating)
if ship_rating > allowance:
debug("Remaining rating insufficient. Not released.")
continue
debug("Splitting from fleet.")
new_fleet_id = FleetUtilsAI.split_ship_from_fleet(fleet_id, ship_id)
if assertion_fails(new_fleet_id and new_fleet_id != INVALID_ID):
break
new_fleets.append(new_fleet_id)
fleet_remaining_rating = CombatRatingsAI.rating_difference(
fleet_remaining_rating, ship_rating)
allowance = CombatRatingsAI.rating_difference(
fleet_remaining_rating, fleet_min_rating)
debug("Remaining fleet rating: %.1f - Allowance: %.1f",
fleet_remaining_rating, allowance)
if new_fleets:
aistate.get_fleet_role(fleet_id, force_new=True)
aistate.update_fleet_rating(fleet_id)
aistate.ensure_have_fleet_missions(new_fleets)
else:
debug("Planetary defenses are deemed sufficient. Release fleet.")
new_fleets = FleetUtilsAI.split_fleet(self.fleet.id)
new_military_fleets = []
for fleet_id in new_fleets:
if aistate.get_fleet_role(fleet_id) in COMBAT_MISSION_TYPES:
new_military_fleets.append(fleet_id)
allocations = []
if new_military_fleets:
allocations = MilitaryAI.get_military_fleets(
mil_fleets_ids=new_military_fleets,
try_reset=False,
thisround="Fleet Reassignment %s" % new_military_fleets
)
if allocations:
MilitaryAI.assign_military_fleets_to_systems(use_fleet_id_list=new_military_fleets,
allocations=allocations)