本文整理匯總了Python中FleetUtilsAI.stats_meet_reqs方法的典型用法代碼示例。如果您正苦於以下問題:Python FleetUtilsAI.stats_meet_reqs方法的具體用法?Python FleetUtilsAI.stats_meet_reqs怎麽用?Python FleetUtilsAI.stats_meet_reqs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FleetUtilsAI
的用法示例。
在下文中一共展示了FleetUtilsAI.stats_meet_reqs方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_invasion_fleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def send_invasion_fleets(fleet_ids, evaluated_planets, mission_type):
"""sends a list of invasion fleets to a list of planet_value_pairs"""
universe = fo.getUniverse()
invasion_fleet_pool = set(fleet_ids)
if not invasion_fleet_pool:
return
for planet_id, pscore, ptroops in evaluated_planets:
planet = universe.getPlanet(planet_id)
if not planet:
continue
sys_id = planet.systemID
found_fleets = []
found_stats = {}
min_stats = {'rating': 0, 'troopCapacity': ptroops}
target_stats = {'rating': 10, 'troopCapacity': ptroops+1}
these_fleets = FleetUtilsAI.get_fleets_for_mission(1, target_stats, min_stats, found_stats, "",
systems_to_check=[sys_id], systems_checked=[],
fleet_pool_set=invasion_fleet_pool, fleet_list=found_fleets,
verbose=False)
if not these_fleets:
if not FleetUtilsAI.stats_meet_reqs(found_stats, min_stats):
print "Insufficient invasion troop allocation for system %d ( %s ) -- requested %s , found %s" % (
sys_id, universe.getSystem(sys_id).name, min_stats, found_stats)
invasion_fleet_pool.update(found_fleets)
continue
else:
these_fleets = found_fleets
target = AITarget.AITarget(EnumsAI.TargetType.TARGET_PLANET, planet_id)
print "assigning invasion fleets %s to target %s" % (these_fleets, target)
for fleetID in these_fleets:
fleet_mission = foAI.foAIstate.get_fleet_mission(fleetID)
fleet_mission.clear_fleet_orders()
fleet_mission.clear_targets((fleet_mission.get_mission_types() + [-1])[0])
fleet_mission.add_target(mission_type, target)
示例2: send_invasion_fleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def send_invasion_fleets(fleet_ids, evaluated_planets, mission_type):
"""sends a list of invasion fleets to a list of planet_value_pairs"""
universe = fo.getUniverse()
invasion_fleet_pool = set(fleet_ids)
if not invasion_fleet_pool:
return
for planet_id, pscore, ptroops in evaluated_planets:
planet = universe.getPlanet(planet_id)
if not planet:
continue
sys_id = planet.systemID
found_fleets = []
found_stats = {}
min_stats = {'rating': 0, 'troopCapacity': ptroops}
target_stats = {'rating': 10, 'troopCapacity': ptroops+1}
these_fleets = FleetUtilsAI.get_fleets_for_mission(target_stats, min_stats, found_stats,
starting_system=sys_id, fleet_pool_set=invasion_fleet_pool,
fleet_list=found_fleets)
if not these_fleets:
if not FleetUtilsAI.stats_meet_reqs(found_stats, min_stats):
print "Insufficient invasion troop allocation for system %d ( %s ) -- requested %s , found %s" % (
sys_id, universe.getSystem(sys_id).name, min_stats, found_stats)
invasion_fleet_pool.update(found_fleets)
continue
else:
these_fleets = found_fleets
target = universe_object.Planet(planet_id)
print "assigning invasion fleets %s to target %s" % (these_fleets, target)
for fleetID in these_fleets:
fleet_mission = foAI.foAIstate.get_fleet_mission(fleetID)
fleet_mission.clear_fleet_orders()
fleet_mission.clear_target()
fleet_mission.set_target(mission_type, target)
示例3: send_invasion_fleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def send_invasion_fleets(fleet_ids, evaluated_planets, mission_type):
"""sends a list of invasion fleets to a list of planet_value_pairs"""
if not fleet_ids:
return
universe = fo.getUniverse()
invasion_fleet_pool = set(fleet_ids)
for planet_id, pscore, ptroops in evaluated_planets:
if pscore < MIN_INVASION_SCORE:
continue
planet = universe.getPlanet(planet_id)
if not planet:
continue
sys_id = planet.systemID
found_fleets = []
found_stats = {}
min_stats = {'rating': 0, 'troopCapacity': ptroops}
target_stats = {'rating': 10,
'troopCapacity': ptroops + _TROOPS_SAFETY_MARGIN,
'target_system': TargetSystem(sys_id)}
these_fleets = FleetUtilsAI.get_fleets_for_mission(target_stats, min_stats, found_stats,
starting_system=sys_id, fleet_pool_set=invasion_fleet_pool,
fleet_list=found_fleets)
if not these_fleets:
if not FleetUtilsAI.stats_meet_reqs(found_stats, min_stats):
debug("Insufficient invasion troop allocation for system %d ( %s ) -- requested %s , found %s" % (
sys_id, universe.getSystem(sys_id).name, min_stats, found_stats))
invasion_fleet_pool.update(found_fleets)
continue
else:
these_fleets = found_fleets
target = TargetPlanet(planet_id)
debug("assigning invasion fleets %s to target %s" % (these_fleets, target))
aistate = get_aistate()
for fleetID in these_fleets:
fleet_mission = aistate.get_fleet_mission(fleetID)
fleet_mission.clear_fleet_orders()
fleet_mission.clear_target()
fleet_mission.set_target(mission_type, target)
示例4: send_invasion_fleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def send_invasion_fleets(invasionFleetIDs, evaluatedPlanets, missionType):
"""sends a list of invasion fleets to a list of planet_value_pairs"""
universe=fo.getUniverse()
invasionPool = invasionFleetIDs[:] #need to make a copy
bestShip, bestDesign, buildChoices = ProductionAI.getBestShipInfo( EnumsAI.AIPriorityType.PRIORITY_PRODUCTION_INVASION)
if bestDesign:
troopsPerBestShip = 2*( list(bestDesign.parts).count("GT_TROOP_POD") )
else:
troopsPerBestShip=5 #may actually not have any troopers available, but this num will do for now
#sortedTargets=sorted( [ ( pscore-ptroops/2 , pID, pscore, ptroops) for pID, pscore, ptroops in evaluatedPlanets ] , reverse=True)
invasionPool=set(invasionPool)
for pID, pscore, ptroops in evaluatedPlanets: #
if not invasionPool: return
planet=universe.getPlanet(pID)
if not planet: continue
sysID = planet.systemID
foundFleets = []
podsNeeded= math.ceil( (ptroops+0.05)/2.0)
foundStats={}
minStats= {'rating':0, 'troopPods':podsNeeded}
targetStats={'rating':10,'troopPods':podsNeeded+1}
theseFleets = FleetUtilsAI.get_fleets_for_mission(1, targetStats , minStats, foundStats, "", systems_to_check=[sysID], systems_checked=[], fleet_pool_set=invasionPool, fleet_list=foundFleets, verbose=False)
if not theseFleets:
if not FleetUtilsAI.stats_meet_reqs(foundStats, minStats):
print "Insufficient invasion troop allocation for system %d ( %s ) -- requested %s , found %s"%(sysID, universe.getSystem(sysID).name, minStats, foundStats)
invasionPool.update( foundFleets )
continue
else:
theseFleets = foundFleets
aiTarget = AITarget.AITarget(EnumsAI.AITargetType.TARGET_PLANET, pID)
print "assigning invasion fleets %s to target %s"%(theseFleets, aiTarget)
for fleetID in theseFleets:
fleet=universe.getFleet(fleetID)
aiFleetMission = foAI.foAIstate.get_fleet_mission(fleetID)
aiFleetMission.clear_fleet_orders()
aiFleetMission.clear_targets( (aiFleetMission.get_mission_types() + [-1])[0] )
aiFleetMission.add_target(missionType, aiTarget)
示例5: assign_military_fleets_to_systems
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def assign_military_fleets_to_systems(use_fleet_id_list=None, allocations=None, round=1):
# assign military fleets to military theater systems
global military_allocations
universe = fo.getUniverse()
if allocations is None:
allocations = []
doing_main = (use_fleet_id_list is None)
if doing_main:
foAI.foAIstate.misc['ReassignedFleetMissions'] = []
base_defense_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.ORBITAL_DEFENSE)
unassigned_base_defense_ids = FleetUtilsAI.extract_fleet_ids_without_mission_types(base_defense_ids)
for fleet_id in unassigned_base_defense_ids:
fleet = universe.getFleet(fleet_id)
if not fleet:
continue
sys_id = fleet.systemID
target = universe_object.System(sys_id)
fleet_mission = foAI.foAIstate.get_fleet_mission(fleet_id)
fleet_mission.clear_fleet_orders()
fleet_mission.clear_target()
mission_type = MissionType.ORBITAL_DEFENSE
fleet_mission.add_target(mission_type, target)
all_military_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY)
if not all_military_fleet_ids:
military_allocations = []
return
avail_mil_fleet_ids = list(FleetUtilsAI.extract_fleet_ids_without_mission_types(all_military_fleet_ids))
mil_needing_repair_ids, avail_mil_fleet_ids = avail_mil_needing_repair(avail_mil_fleet_ids)
these_allocations = military_allocations
print "=================================================="
print "Assigning military fleets"
print "---------------------------------"
else:
avail_mil_fleet_ids = list(use_fleet_id_list)
mil_needing_repair_ids, avail_mil_fleet_ids = avail_mil_needing_repair(avail_mil_fleet_ids)
these_allocations = allocations
# send_for_repair(mil_needing_repair_ids) #currently, let get taken care of by AIFleetMission.generate_fleet_orders()
# get systems to defend
avail_mil_fleet_ids = set(avail_mil_fleet_ids)
for sys_id, alloc, minalloc, takeAny in these_allocations:
if not doing_main and not avail_mil_fleet_ids:
break
found_fleets = []
found_stats = {}
try:
these_fleets = FleetUtilsAI.get_fleets_for_mission(1, {'rating': alloc}, {'rating': minalloc}, found_stats, "", systems_to_check=[sys_id], systems_checked=[],
fleet_pool_set=avail_mil_fleet_ids, fleet_list=found_fleets, verbose=False)
except:
continue
if not these_fleets:
if not found_fleets or not (FleetUtilsAI.stats_meet_reqs(found_stats, {'rating': minalloc}) or takeAny):
if doing_main:
if verbose_mil_reporting:
print "NO available/suitable military allocation for system %d ( %s ) -- requested allocation %8d, found available rating %8d in fleets %s" % (sys_id, universe.getSystem(sys_id).name, minalloc, found_stats.get('rating', 0), found_fleets)
avail_mil_fleet_ids.update(found_fleets)
continue
else:
these_fleets = found_fleets
# rating = sum( map(lambda x: foAI.foAIstate.rate_fleet(x), foundFleets ) )
ratings = map(foAI.foAIstate.get_rating, found_fleets)
rating = sum([fr.get('attack', 0) for fr in ratings]) * sum([fr.get('health', 0) for fr in ratings])
if doing_main and verbose_mil_reporting:
if rating < minMilAllocations.get(sys_id, 0):
print "PARTIAL military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s" % (sys_id, universe.getSystem(sys_id).name, minalloc, rating, these_fleets)
else:
print "FULL MIN military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s" % (sys_id, universe.getSystem(sys_id).name, minMilAllocations.get(sys_id, 0), rating, these_fleets)
elif doing_main and verbose_mil_reporting:
print "FULL+ military allocation for system %d ( %s ) -- requested allocation %8d, got %8d with fleets %s" % (sys_id, universe.getSystem(sys_id).name, alloc, found_stats.get('rating', 0), these_fleets)
target = universe_object.System(sys_id)
for fleet_id in these_fleets:
fo.issueAggressionOrder(fleet_id, True)
fleet_mission = foAI.foAIstate.get_fleet_mission(fleet_id)
fleet_mission.clear_fleet_orders()
fleet_mission.clear_target()
if sys_id in list(set(AIstate.colonyTargetedSystemIDs + AIstate.outpostTargetedSystemIDs + AIstate.invasionTargetedSystemIDs + AIstate.blockadeTargetedSystemIDs)):
mission_type = MissionType.SECURE
else:
mission_type = MissionType.MILITARY
fleet_mission.add_target(mission_type, target)
fleet_mission.generate_fleet_orders()
if not doing_main:
foAI.foAIstate.misc.setdefault('ReassignedFleetMissions', []).append(fleet_mission)
if doing_main:
print "---------------------------------"
last_round = 3
last_round_name = "LastRound"
if round <= last_round:
# check if any fleets remain unassigned
all_military_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.MILITARY)
avail_mil_fleet_ids = list(FleetUtilsAI.extract_fleet_ids_without_mission_types(all_military_fleet_ids))
allocations = []
round += 1
thisround = "Extras Remaining Round %d" % round if round < last_round else last_round_name
if avail_mil_fleet_ids:
#.........這裏部分代碼省略.........
示例6: assign_military_fleets_to_systems
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import stats_meet_reqs [as 別名]
def assign_military_fleets_to_systems(useFleetIDList=None, allocations=None):
# assign military fleets to military theater systems
global MilitaryAllocations
universe = fo.getUniverse()
if allocations is None:
allocations = []
doingMain = (useFleetIDList is None)
if doingMain:
baseDefenseIDs = FleetUtilsAI.get_empire_fleet_ids_by_role(AIFleetMissionType.FLEET_MISSION_ORBITAL_DEFENSE)
unassignedBaseDefenseIDs = FleetUtilsAI.extract_fleet_ids_without_mission_types(baseDefenseIDs)
for fleetID in unassignedBaseDefenseIDs:
fleet = universe.getFleet(fleetID)
if not fleet:
continue
sysID = fleet.systemID
aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, sysID)
aiFleetMission = foAI.foAIstate.get_fleet_mission(fleetID)
aiFleetMission.clear_fleet_orders()
aiFleetMission.clear_targets( (aiFleetMission.get_mission_types() + [-1])[0] )
missionType = AIFleetMissionType.FLEET_MISSION_ORBITAL_DEFENSE
aiFleetMission.add_target( missionType , aiTarget)
allMilitaryFleetIDs = FleetUtilsAI.get_empire_fleet_ids_by_role(AIFleetMissionType.FLEET_MISSION_MILITARY)
AIstate.militaryFleetIDs = allMilitaryFleetIDs
if not allMilitaryFleetIDs:
MilitaryAllocations = []
return
availMilFleetIDs = list( FleetUtilsAI.extract_fleet_ids_without_mission_types(allMilitaryFleetIDs) )
mil_needing_repair_ids, availMilFleetIDs = avail_mil_needing_repair(availMilFleetIDs)
availMilRating = sum( map(lambda x: foAI.foAIstate.get_rating(x).get('overall', 0), availMilFleetIDs ) )
under_repair_mil_rating = sum( map(lambda x: foAI.foAIstate.get_rating(x).get('overall', 0), mil_needing_repair_ids ) )
theseAllocations = MilitaryAllocations
print "=================================================="
print "assigning military fleets"
print "---------------------------------"
else:
availMilFleetIDs = list( useFleetIDList )
mil_needing_repair_ids, availMilFleetIDs = avail_mil_needing_repair(availMilFleetIDs)
availMilRating = sum( map(lambda x: foAI.foAIstate.get_rating(x).get('overall', 0), availMilFleetIDs ) )
theseAllocations = allocations
remainingMilRating = availMilRating
#send_for_repair(mil_needing_repair_ids) #currently, let get taken care of by AIFleetMission.generate_fleet_orders()
# get systems to defend
availMilFleetIDs = set(availMilFleetIDs)
for sysID, alloc, minalloc, takeAny in theseAllocations:
if not doingMain and len(availMilFleetIDs)==0:
break
foundFleets = []
foundStats={}
try:
theseFleets = FleetUtilsAI.get_fleets_for_mission(1, {'rating':alloc}, {'rating':minalloc}, foundStats, "", systems_to_check=[sysID], systems_checked=[],
fleet_pool_set=availMilFleetIDs, fleet_list=foundFleets, verbose=False)
except:
continue
if not theseFleets:
if foundFleets==[] or not ( FleetUtilsAI.stats_meet_reqs( foundStats, {'rating':minalloc}) or takeAny):
if doingMain:
if verboseMilReporting:
print "NO available/suitable military allocation for system %d ( %s ) -- requested allocation %8d, found available rating %8d in fleets %s"%(sysID, universe.getSystem(sysID).name, minalloc, foundStats.get('rating', 0), foundFleets)
availMilFleetIDs.update(foundFleets)
continue
else:
theseFleets = foundFleets
#rating = sum( map(lambda x: foAI.foAIstate.rate_fleet(x), foundFleets ) )
ratings = map(foAI.foAIstate.get_rating, foundFleets )
rating = sum([fr.get('attack', 0) for fr in ratings]) * sum([fr.get('health', 0) for fr in ratings])
if doingMain and verboseMilReporting:
if rating < minMilAllocations.get(sysID, 0):
print "PARTIAL military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s"%(sysID, universe.getSystem(sysID).name, minalloc, rating, theseFleets)
else:
print "FULL MIN military allocation for system %d ( %s ) -- requested allocation %8d -- got %8d with fleets %s "%(sysID, universe.getSystem(sysID).name, minMilAllocations.get(sysID, 0) , rating, theseFleets)
elif doingMain and verboseMilReporting:
print "FULL+ military allocation for system %d ( %s ) -- requested allocation %8d, got %8d with fleets %s"%(sysID, universe.getSystem(sysID).name, alloc, foundStats.get('rating', 0), theseFleets)
aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, sysID)
for fleetID in theseFleets:
fleet=universe.getFleet(fleetID)
fo.issueAggressionOrder(fleetID, True)
aiFleetMission = foAI.foAIstate.get_fleet_mission(fleetID)
aiFleetMission.clear_fleet_orders()
aiFleetMission.clear_targets( (aiFleetMission.get_mission_types() + [-1])[0] )
if sysID in list(set(AIstate.colonyTargetedSystemIDs + AIstate.outpostTargetedSystemIDs + AIstate.invasionTargetedSystemIDs + AIstate.blockadeTargetedSystemIDs)):
missionType = AIFleetMissionType.FLEET_MISSION_SECURE
else:
missionType = AIFleetMissionType.FLEET_MISSION_MILITARY
aiFleetMission.add_target( missionType , aiTarget)
aiFleetMission.generate_fleet_orders()
if not doingMain:
foAI.foAIstate.misc.setdefault('ReassignedFleetMissions', []).append(aiFleetMission)
if doingMain:
print "---------------------------------"