本文整理汇总了Python中InvasionAI.get_invasion_targeted_planet_ids方法的典型用法代码示例。如果您正苦于以下问题:Python InvasionAI.get_invasion_targeted_planet_ids方法的具体用法?Python InvasionAI.get_invasion_targeted_planet_ids怎么用?Python InvasionAI.get_invasion_targeted_planet_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvasionAI
的用法示例。
在下文中一共展示了InvasionAI.get_invasion_targeted_planet_ids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_retarget_invasion
# 需要导入模块: import InvasionAI [as 别名]
# 或者: from InvasionAI import get_invasion_targeted_planet_ids [as 别名]
def _check_retarget_invasion(self):
"""checks if an invasion mission should be retargeted"""
universe = fo.getUniverse()
empire_id = fo.empireID()
fleet_id = self.fleet.id
fleet = universe.getFleet(fleet_id)
if fleet.systemID == INVALID_ID:
# next_loc = fleet.nextSystemID
return # TODO: still check
system = universe.getSystem(fleet.systemID)
if not system:
return
orders = self.orders
last_sys_target = INVALID_ID
if orders:
last_sys_target = orders[-1].target.id
if last_sys_target == fleet.systemID:
return # TODO: check for best local target
open_targets = []
already_targeted = InvasionAI.get_invasion_targeted_planet_ids(system.planetIDs, MissionType.INVASION)
aistate = get_aistate()
for pid in system.planetIDs:
if pid in already_targeted or (pid in aistate.qualifyingTroopBaseTargets):
continue
planet = universe.getPlanet(pid)
if planet.unowned or (planet.owner == empire_id):
continue
if (planet.initialMeterValue(fo.meterType.shield)) <= 0:
open_targets.append(pid)
if not open_targets:
return
troops_in_fleet = FleetUtilsAI.count_troops_in_fleet(fleet_id)
target_id = INVALID_ID
best_score = -1
target_troops = 0
#
for pid, rating in InvasionAI.assign_invasion_values(open_targets).items():
p_score, p_troops = rating
if p_score > best_score:
if p_troops >= troops_in_fleet:
continue
best_score = p_score
target_id = pid
target_troops = p_troops
if target_id == INVALID_ID:
return
debug("\t Splitting and retargetting fleet %d" % fleet_id)
new_fleets = FleetUtilsAI.split_fleet(fleet_id)
self.clear_target() # TODO: clear from foAIstate
self.clear_fleet_orders()
troops_needed = max(0, target_troops - FleetUtilsAI.count_troops_in_fleet(fleet_id))
min_stats = {'rating': 0, 'troopCapacity': troops_needed}
target_stats = {'rating': 10, 'troopCapacity': troops_needed}
found_fleets = []
# TODO check if next statement does not mutate any global states and can be removed
_ = FleetUtilsAI.get_fleets_for_mission(target_stats, min_stats, {}, starting_system=fleet.systemID, # noqa: F841
fleet_pool_set=set(new_fleets), fleet_list=found_fleets)
for fid in found_fleets:
FleetUtilsAI.merge_fleet_a_into_b(fid, fleet_id)
target = TargetPlanet(target_id)
self.set_target(MissionType.INVASION, target)
self.generate_fleet_orders()
示例2: _check_retarget_invasion
# 需要导入模块: import InvasionAI [as 别名]
# 或者: from InvasionAI import get_invasion_targeted_planet_ids [as 别名]
def _check_retarget_invasion(self):
"""checks if an invasion mission should be retargeted"""
universe = fo.getUniverse()
empire = fo.getEmpire()
empire_id = fo.empireID()
fleet_id = self.fleet.id
fleet = universe.getFleet(fleet_id)
if fleet.systemID == -1:
# next_loc = fleet.nextSystemID
return # TODO: still check
system = universe.getSystem(fleet.systemID)
if not system:
return
orders = self.orders
last_sys_target = -1
if orders:
last_sys_target = orders[-1].target.id
if last_sys_target == fleet.systemID:
return # TODO: check for best local target
open_targets = []
already_targeted = InvasionAI.get_invasion_targeted_planet_ids(system.planetIDs, MissionType.INVASION)
for pid in system.planetIDs:
if pid in already_targeted or (pid in foAI.foAIstate.qualifyingTroopBaseTargets):
continue
planet = universe.getPlanet(pid)
if planet.unowned or (planet.owner == empire_id):
continue
if (planet.currentMeterValue(fo.meterType.shield)) <= 0:
open_targets.append(pid)
if not open_targets:
return
troops_in_fleet = FleetUtilsAI.count_troops_in_fleet(fleet_id)
target_id = -1
best_score = -1
target_troops = 0
#
for pid, rating in InvasionAI.assign_invasion_values(open_targets, empire).items():
p_score, p_troops = rating
if p_score > best_score:
if p_troops >= troops_in_fleet:
continue
best_score = p_score
target_id = pid
target_troops = p_troops
if target_id == -1:
return
print "\t AIFleetMission._check_retarget_invasion: splitting and retargetting fleet %d" % fleet_id
new_fleets = FleetUtilsAI.split_fleet(fleet_id)
self.clear_target() # TODO: clear from foAIstate
self.clear_fleet_orders()
# pods_needed = max(0, math.ceil((target_troops - 2 * (FleetUtilsAI.count_parts_fleetwide(fleet_id, ["GT_TROOP_POD"])) + 0.05) / 2.0))
troops_needed = max(0, target_troops - FleetUtilsAI.count_troops_in_fleet(fleet_id))
found_stats = {}
min_stats = {'rating': 0, 'troopCapacity': troops_needed}
target_stats = {'rating': 10, 'troopCapacity': troops_needed}
found_fleets = []
# TODO check if next statement does not mutate any global states and can be removed
_ = FleetUtilsAI.get_fleets_for_mission(1, target_stats, min_stats, found_stats, "",
systems_to_check=[fleet.systemID], systems_checked=[],
fleet_pool_set=set(new_fleets), fleet_list=found_fleets,
verbose=False)
for fid in found_fleets:
FleetUtilsAI.merge_fleet_a_into_b(fid, fleet_id)
target = Planet(target_id)
self.add_target(MissionType.INVASION, target)
self.generate_fleet_orders()