本文整理匯總了Python中FleetUtilsAI.extractFleetIDsWithoutMissionTypes方法的典型用法代碼示例。如果您正苦於以下問題:Python FleetUtilsAI.extractFleetIDsWithoutMissionTypes方法的具體用法?Python FleetUtilsAI.extractFleetIDsWithoutMissionTypes怎麽用?Python FleetUtilsAI.extractFleetIDsWithoutMissionTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FleetUtilsAI
的用法示例。
在下文中一共展示了FleetUtilsAI.extractFleetIDsWithoutMissionTypes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getInvasionFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def getInvasionFleets():
"get invasion fleets"
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
AIstate.invasionFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs)
# get supplyable planets
universe = fo.getUniverse()
empire = fo.getEmpire()
empireID = empire.empireID
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
# get competitor planets
exploredSystemIDs = empire.exploredSystemIDs
exploredPlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(exploredSystemIDs)
allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(exploredPlanetIDs)
# print "All Owned and Populated PlanetIDs: " + str(allOwnedPlanetIDs)
empireOwnedPlanetIDs = PlanetUtilsAI.getOwnedPlanetsByEmpire(universe.planetIDs, empireID)
# print "Empire Owned PlanetIDs: " + str(empireOwnedPlanetIDs)
competitorPlanetIDs = list(set(allOwnedPlanetIDs) - set(empireOwnedPlanetIDs))
print "Competitor PlanetIDs: " + str(competitorPlanetIDs)
print ""
print "Invasion Targeted SystemIDs: " + str(AIstate.invasionTargetedSystemIDs)
invasionTargetedPlanetIDs = getInvasionTargetedPlanetIDs(universe.planetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, empireID)
allInvasionTargetedSystemIDs = PlanetUtilsAI.getSystems(invasionTargetedPlanetIDs)
# export invasion targeted systems for other AI modules
AIstate.invasionTargetedSystemIDs = allInvasionTargetedSystemIDs
print "Invasion Targeted PlanetIDs: " + str(invasionTargetedPlanetIDs)
invasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
if not invasionFleetIDs:
print "Available Invasion Fleets: 0"
else:
print "Invasion FleetIDs: " + str(FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION))
numInvasionFleets = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(invasionFleetIDs))
print "Invasion Fleets Without Missions: " + str(numInvasionFleets)
evaluatedPlanetIDs = list(set(competitorPlanetIDs) - set(invasionTargetedPlanetIDs))
# print "Evaluated PlanetIDs: " + str(evaluatedPlanetIDs)
evaluatedPlanets = assignInvasionValues(evaluatedPlanetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, fleetSupplyablePlanetIDs, empire)
sortedPlanets = evaluatedPlanets.items()
sortedPlanets.sort(lambda x, y: cmp(x[1], y[1]), reverse=True)
print ""
print "Invadable planetIDs:"
for evaluationPair in sortedPlanets:
print " ID|Score: " + str(evaluationPair)
# export opponent planets for other AI modules
AIstate.opponentPlanetIDs = sortedPlanets
示例2: getColonyFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def getColonyFleets():
# get colony fleets
allColonyFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_COLONISATION)
AIstate.colonyFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allColonyFleetIDs)
# get supplyable systems
empire = fo.getEmpire()
universe = fo.getUniverse()
capitalID = empire.capitalID
homeworld = universe.getPlanet(capitalID)
speciesName = homeworld.speciesName
species = fo.getSpecies(speciesName)
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
print " fleetSupplyablePlanetIDs:" + str(fleetSupplyablePlanetIDs)
# get planets
systemIDs = foAI.foAIstate.getExplorableSystems(AIExplorableSystemType.EXPLORABLE_SYSTEM_EXPLORED)
planetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(systemIDs)
removeAlreadyOwnedPlanetIDs(planetIDs, AIFleetMissionType.FLEET_MISSION_COLONISATION)
removeAlreadyOwnedPlanetIDs(planetIDs, AIFleetMissionType.FLEET_MISSION_OUTPOST)
evaluatedPlanets = assignColonisationValues(planetIDs, AIFleetMissionType.FLEET_MISSION_COLONISATION, fleetSupplyablePlanetIDs, species, empire)
removeLowValuePlanets(evaluatedPlanets)
sortedPlanets = evaluatedPlanets.items()
sortedPlanets.sort(lambda x, y: cmp(x[1], y[1]), reverse=True)
print "Colonisable planets:"
for evaluationPair in sortedPlanets:
print " ID|Score: " + str(evaluationPair)
print ""
# export planets for other AI modules
AIstate.colonisablePlanetIDs = sortedPlanets
# get outpost fleets
allOutpostFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_OUTPOST)
AIstate.outpostFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allOutpostFleetIDs)
evaluatedOutposts = assignColonisationValues(planetIDs, AIFleetMissionType.FLEET_MISSION_OUTPOST, fleetSupplyablePlanetIDs, species, empire)
removeLowValuePlanets(evaluatedOutposts)
sortedOutposts = evaluatedOutposts.items()
sortedOutposts.sort(lambda x, y: cmp(x[1], y[1]), reverse=True)
print "Colonisable outposts:"
for evaluationPair in sortedOutposts:
print " ID|Score: " + str(evaluationPair)
print ""
# export outposts for other AI modules
AIstate.colonisableOutpostIDs = sortedOutposts
示例3: calculateColonisationPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateColonisationPriority():
"calculates the demand for colony ships by colonisable planets"
global allottedColonyTargets
totalPP=fo.getEmpire().productionPoints
colonyCost=120*(1+ 0.06*len( list(AIstate.popCtrIDs) ))
turnsToBuild=8#TODO: check for susp anim pods, build time 10
allottedPortion = [0.4, 0.5][ random.choice([0, 1]) ] #fo.empireID() % 2
if ( foAI.foAIstate.getPriority(EnumsAI.AIPriorityType.PRIORITY_PRODUCTION_COLONISATION)
> 2 * foAI.foAIstate.getPriority(EnumsAI.AIPriorityType.PRIORITY_PRODUCTION_MILITARY)):
allottedPortion *= 1.5
#allottedColonyTargets = 1+ int(fo.currentTurn()/50)
allottedColonyTargets = 1 + int( totalPP*turnsToBuild*allottedPortion/colonyCost)
numColonisablePlanetIDs = len( [ pid for (pid, (score, specName) ) in foAI.foAIstate.colonisablePlanetIDs if score > 60 ][:allottedColonyTargets+2] )
if (numColonisablePlanetIDs == 0): return 1
colonyshipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_COLONISATION)
numColonyships = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(colonyshipIDs))
colonisationPriority = 121 * (1+numColonisablePlanetIDs - numColonyships) / (numColonisablePlanetIDs+1)
# print ""
# print "Number of Colony Ships : " + str(numColonyships)
# print "Number of Colonisable planets : " + str(numColonisablePlanetIDs)
# print "Priority for colony ships : " + str(colonisationPriority)
if colonisationPriority < 1: return 1
return colonisationPriority
示例4: assignInvasionFleetsToInvade
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def assignInvasionFleetsToInvade():
# assign fleet targets to invadable planets
invasionFleetIDs = AIstate.invasionFleetIDs
sendInvasionFleets(invasionFleetIDs, AIstate.invasionTargets, AIFleetMissionType.FLEET_MISSION_INVASION)
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
for fid in FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs):
thisMission = foAI.foAIstate.getAIFleetMission(fid)
thisMission.checkMergers(context="Post-send consolidation of unassigned troops")
示例5: calculateMilitaryPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateMilitaryPriority():
"calculates the demand for military ships by military targeted systems"
numMilitaryTargetedSystemIDs = len(AIstate.militaryTargetedSystemIDs)
militaryShipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_MILITARY)
numMilitaryShips = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(militaryShipIDs))
# build one more military ship than military targeted systems
militaryPriority = 100 * ((numMilitaryTargetedSystemIDs +2) - numMilitaryShips) / (numMilitaryTargetedSystemIDs + 1)
# print ""
# print "Number of Military Ships Without Missions: " + str(numMilitaryShips)
# print "Number of Military Targeted Systems: " + str(numMilitaryTargetedSystemIDs)
# print "Priority for Military Ships: " + str(militaryPriority)
if militaryPriority < 0: return 0
return militaryPriority
示例6: calculateInvasionPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateInvasionPriority():
"calculates the demand for troop ships by opponent planets"
numOpponentPlanetIDs = len(AIstate.opponentPlanetIDs)
if numOpponentPlanetIDs == 0: return 0
troopShipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
numTroopShips = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(troopShipIDs))
invasionPriority = 105 * (numOpponentPlanetIDs - numTroopShips) / numOpponentPlanetIDs
print ""
print "Number of Troop Ships : " + str(numTroopShips)
print "Number of Opponent Planets: " + str(numOpponentPlanetIDs)
print "Priority for Troop Ships : " + str(invasionPriority)
if invasionPriority < 0: return 0
return invasionPriority
示例7: calculateColonisationPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateColonisationPriority():
"calculates the demand for colony ships by colonisable planets"
numColonisablePlanetIDs = len(foAI.foAIstate.colonisablePlanetIDs)
if (numColonisablePlanetIDs == 0): return 0
colonyshipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_COLONISATION)
numColonyships = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(colonyshipIDs))
colonisationPriority = 101 * (numColonisablePlanetIDs - numColonyships) / numColonisablePlanetIDs
# print ""
# print "Number of Colony Ships : " + str(numColonyships)
# print "Number of Colonisable planets : " + str(numColonisablePlanetIDs)
# print "Priority for colony ships : " + str(colonisationPriority)
if colonisationPriority < 0: return 0
return colonisationPriority
示例8: calculateOutpostPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateOutpostPriority():
"calculates the demand for outpost ships by colonisable planets"
numOutpostPlanetIDs = len(foAI.foAIstate.colonisableOutpostIDs)
completedTechs = getCompletedTechs()
if numOutpostPlanetIDs == 0 or not 'CON_ENV_ENCAPSUL' in completedTechs:
return 0
outpostShipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_OUTPOST)
numOutpostShips = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(outpostShipIDs))
outpostPriority = 102 * (numOutpostPlanetIDs - numOutpostShips) / numOutpostPlanetIDs
# print ""
# print "Number of Outpost Ships : " + str(numOutpostShips)
# print "Number of Colonisable outposts: " + str(numOutpostPlanetIDs)
print "Priority for outpost ships : " + str(outpostPriority)
if outpostPriority < 0: return 0
return outpostPriority
示例9: sendMilitaryFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def sendMilitaryFleets(militaryFleetIDs, evaluatedSystems, missionType):
"sends a list of military fleets to a list of system_value_pairs"
if len(militaryFleetIDs) == 0:
return
allMilitaryFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_MILITARY)
AIstate.militaryFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allMilitaryFleetIDs)
targets = []
for systemID_value_pair in evaluatedSystems: # evaluatedSystems is a dictionary
targets.extend(int(systemID_value_pair[1]) * [systemID_value_pair[0]])
# currentFleetSizes= dict ( [ (fleetID, len( universe.getFleet(fleetID).shipIDs) ) for fleetID in allMilitaryFleetIDs ] )
# newFleetSizes= dict ( [ (fleetID, len( universe.getFleet(fleetID).shipIDs) ) for fleetID in AIstate.militaryFleetIDs ] )
if len(targets) == 0:
return
if True:
for fleetID in militaryFleetIDs:
systemID = choice(targets)
aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, systemID)
aiFleetMission = foAI.foAIstate.getAIFleetMission(fleetID)
aiFleetMission.addAITarget(missionType, aiTarget)
return
else:
i = 0
for systemID_value_pair in evaluatedSystems: # evaluatedSystems is a dictionary
if i >= len(militaryFleetIDs):
return
fleetID = militaryFleetIDs[i]
systemID = systemID_value_pair[0]
aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, systemID)
aiFleetMission = foAI.foAIstate.getAIFleetMission(fleetID)
aiFleetMission.addAITarget(missionType, aiTarget)
i = i + 1
return
示例10: calculateOutpostPriority
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def calculateOutpostPriority():
"calculates the demand for outpost ships by colonisable planets"
baseOutpostCost=80
numOutpostPlanetIDs = len(foAI.foAIstate.colonisableOutpostIDs)
numOutpostPlanetIDs = len( [ pid for (pid, (score, specName) ) in foAI.foAIstate.colonisableOutpostIDs if score > 1.0*baseOutpostCost/3.0 ][:allottedColonyTargets] )
completedTechs = ResearchAI.getCompletedTechs()
if numOutpostPlanetIDs == 0 or not 'CON_ENV_ENCAPSUL' in completedTechs:
return 0
outpostShipIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_OUTPOST)
numOutpostShips = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(outpostShipIDs))
outpostPriority = 102 * (numOutpostPlanetIDs - numOutpostShips) / numOutpostPlanetIDs
# print ""
# print "Number of Outpost Ships : " + str(numOutpostShips)
# print "Number of Colonisable outposts: " + str(numOutpostPlanetIDs)
print "Priority for outpost ships : " + str(outpostPriority)
if outpostPriority < 1: return 1
return outpostPriority
示例11: assignInvasionFleetsToInvade
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def assignInvasionFleetsToInvade():
# assign fleet targets to invadable planets
universe = fo.getUniverse()
empire = fo.getEmpire()
empireID = empire.empireID
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
allTroopBaseFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_ORBITAL_INVASION)
availTroopBaseFleetIDs = set(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allTroopBaseFleetIDs))
for fid in list(availTroopBaseFleetIDs):
if fid not in availTroopBaseFleetIDs:
continue
fleet = universe.getFleet(fid)
if not fleet:
continue
sysID = fleet.systemID
system = universe.getSystem(sysID)
availPlanets = set(system.planetIDs).intersection(set( foAI.foAIstate.qualifyingTroopBaseTargets.keys()))
print "Considering Base Troopers in %s, found planets %s and regtistered targets %s with status %s"%(system.name, list(system.planetIDs), availPlanets,
[(pid, foAI.foAIstate.qualifyingTroopBaseTargets[pid]) for pid in availPlanets])
targets = [pid for pid in availPlanets if foAI.foAIstate.qualifyingTroopBaseTargets[pid][1] != -1 ]
if not targets:
print "Error found no valid target for troop base in system %s (%d)"%(system.name, sysID)
continue
status=foAI.foAIstate.systemStatus.get( sysID, {} )
local_base_troops = set(status.get('myfleets', [])).intersection(availTroopBaseFleetIDs)
troop_pod_tally = 0
for fid2 in local_base_troops:
troop_pod_tally += FleetUtilsAI.countPartsFleetwide(fid2, ["GT_TROOP_POD"])
targetID=-1
bestScore=-1
target_troops = 0
#
for pid, rating in assignInvasionValues(targets, EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION, fleetSupplyablePlanetIDs, empire).items():
p_score, p_troops = rating
if p_score>bestScore:
if p_troops >= 2*troop_pod_tally:
pass
#continue
bestScore = p_score
targetID = pid
target_troops = p_troops
if targetID != -1:
local_base_troops.discard(fid)
foundFleets = []
podsNeeded= math.ceil( (target_troops - 2*(FleetUtilsAI.countPartsFleetwide(fid, ["GT_TROOP_POD"]))+0.05)/2.0)
foundStats={}
minStats= {'rating':0, 'troopPods':podsNeeded}
targetStats={'rating':10,'troopPods':podsNeeded}
theseFleets = FleetUtilsAI.getFleetsForMission(1, targetStats , minStats, foundStats, "", systemsToCheck=[sysID], systemsChecked=[], fleetPoolSet=local_base_troops, fleetList=foundFleets, verbose=False)
for fid2 in foundFleets:
FleetUtilsAI.mergeFleetAintoB(fid2, fid)
availTroopBaseFleetIDs.discard(fid2)
availTroopBaseFleetIDs.discard(fid)
foAI.foAIstate.qualifyingTroopBaseTargets[targetID][1] = -1 #TODO: should probably delete
aiTarget = AITarget.AITarget(EnumsAI.AITargetType.TARGET_PLANET, targetID)
aiFleetMission = foAI.foAIstate.getAIFleetMission(fid)
aiFleetMission.addAITarget(EnumsAI.AIFleetMissionType.FLEET_MISSION_ORBITAL_INVASION, aiTarget)
invasionFleetIDs = AIstate.invasionFleetIDs
sendInvasionFleets(invasionFleetIDs, AIstate.invasionTargets, EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION)
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION)
for fid in FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs):
thisMission = foAI.foAIstate.getAIFleetMission(fid)
thisMission.checkMergers(context="Post-send consolidation of unassigned troops")
示例12: getInvasionFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def getInvasionFleets():
"get invasion fleets"
times=[]
tasks = []
times.append( time() )
tasks.append("init")
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION)
AIstate.invasionFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs)
# get supplyable planets
universe = fo.getUniverse()
empire = fo.getEmpire()
empireID = empire.empireID
capitalID = PlanetUtilsAI.getCapital()
#capitalID = empire.capitalID
homeworld=None
if capitalID:
homeworld = universe.getPlanet(capitalID)
if homeworld:
homeSystemID = homeworld.systemID
else:
speciesName = ""
homeworldName=" no remaining homeworld "
homeSystemID = -1
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
primeInvadableSystemIDs = set(ColonisationAI.annexableSystemIDs)
primeInvadablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(primeInvadableSystemIDs)
# get competitor planets
exploredSystemIDs = empire.exploredSystemIDs
exploredPlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(exploredSystemIDs)
visibleSystemIDs = foAI.foAIstate.visInteriorSystemIDs.keys() + foAI.foAIstate. visBorderSystemIDs.keys()
visiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(visibleSystemIDs)
if homeSystemID != -1:
accessibleSystemIDs = [sysID for sysID in visibleSystemIDs if (sysID != -1 ) and universe.systemsConnected(sysID, homeSystemID, empireID) ]
else:
print "Invasion Warning: this empire has no identifiable homeworld, will therefor treat all visible planets as accessible."
accessibleSystemIDs = visibleSystemIDs #TODO: check if any troop ships still owned, use their system as home system
acessiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(accessibleSystemIDs)
print "Accessible Systems: " + str(PlanetUtilsAI.sysNameIDs(accessibleSystemIDs))
print
#allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(exploredPlanetIDs)
allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(acessiblePlanetIDs)#need these for unpopulated outposts
# print "All Owned and Populated PlanetIDs: " + str(allOwnedPlanetIDs)
allPopulatedPlanets=PlanetUtilsAI.getPopulatedPlanetIDs(acessiblePlanetIDs)#need this for natives
print "All Visible and accessible Populated PlanetIDs (including this empire's): " + str(PlanetUtilsAI.planetNameIDs(allPopulatedPlanets))
print
print "Prime Invadable Target Systems: " + str(PlanetUtilsAI.sysNameIDs(primeInvadableSystemIDs))
print
empireOwnedPlanetIDs = PlanetUtilsAI.getOwnedPlanetsByEmpire(universe.planetIDs, empireID)
# print "Empire Owned PlanetIDs: " + str(empireOwnedPlanetIDs)
invadablePlanetIDs = set(primeInvadablePlanetIDs).intersection(set(allOwnedPlanetIDs).union(allPopulatedPlanets) - set(empireOwnedPlanetIDs))
print "Prime Invadable PlanetIDs: " + str(PlanetUtilsAI.planetNameIDs(invadablePlanetIDs))
print ""
print "Current Invasion Targeted SystemIDs: " + str(PlanetUtilsAI.sysNameIDs(AIstate.invasionTargetedSystemIDs))
invasionTargetedPlanetIDs = getInvasionTargetedPlanetIDs(universe.planetIDs, EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION, empireID)
invasionTargetedPlanetIDs.extend( getInvasionTargetedPlanetIDs(universe.planetIDs, EnumsAI.AIFleetMissionType.FLEET_MISSION_ORBITAL_INVASION, empireID))
allInvasionTargetedSystemIDs = set(PlanetUtilsAI.getSystems(invasionTargetedPlanetIDs))
print "Current Invasion Targeted PlanetIDs: " + str(PlanetUtilsAI.planetNameIDs(invasionTargetedPlanetIDs))
invasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION)
if not invasionFleetIDs:
print "Available Invasion Fleets: 0"
else:
print "Invasion FleetIDs: " + str(FleetUtilsAI.getEmpireFleetIDsByRole(EnumsAI.AIFleetMissionType.FLEET_MISSION_INVASION))
numInvasionFleets = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(invasionFleetIDs))
print "Invasion Fleets Without Missions: " + str(numInvasionFleets)
times.append( time() )
tasks.append( "gathering initial info" )
availablePP = {}
for el in empire.planetsWithAvailablePP: #keys are sets of ints; data is doubles
avail_pp = el.data()
for pid in el.key():
availablePP[pid] = avail_pp
if len (invadablePlanetIDs) > 0:
#print "Evaluating Troop Bases (SpaceInvaders) for %s"%(invadablePlanetIDs)
pass
for pid in invadablePlanetIDs: #TODO: reorganize
planet = universe.getPlanet(pid)
if not planet:
continue
sysID = planet.systemID
sysPartialVisTurn = dictFromMap(universe.getVisibilityTurnsMap(planet.systemID, empireID)).get(fo.visibility.partial, -9999)
planetPartialVisTurn = dictFromMap(universe.getVisibilityTurnsMap(pid, empireID)).get(fo.visibility.partial, -9999)
if (planetPartialVisTurn < sysPartialVisTurn):
#print "rejecting %s due to stealth"%planet.name
#.........這裏部分代碼省略.........
示例13: assignMilitaryFleetsToSystems
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def assignMilitaryFleetsToSystems(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.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_ORBITAL_DEFENSE)
unassignedBaseDefenseIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(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.getAIFleetMission(fleetID)
aiFleetMission.clearAIFleetOrders()
aiFleetMission.clearAITargets( (aiFleetMission.getAIMissionTypes() + [-1])[0] )
missionType = AIFleetMissionType.FLEET_MISSION_ORBITAL_DEFENSE
aiFleetMission.addAITarget( missionType , aiTarget)
allMilitaryFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_MILITARY)
AIstate.militaryFleetIDs = allMilitaryFleetIDs
if allMilitaryFleetIDs == []:
MilitaryAllocations = []
return
availMilFleetIDs = list( FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allMilitaryFleetIDs) )
mil_needing_repair_ids, availMilFleetIDs = avail_mil_needing_repair(availMilFleetIDs)
availMilRating = sum( map(lambda x: foAI.foAIstate.getRating(x).get('overall', 0), availMilFleetIDs ) )
under_repair_mil_rating = sum( map(lambda x: foAI.foAIstate.getRating(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.getRating(x).get('overall', 0), availMilFleetIDs ) )
theseAllocations = allocations
remainingMilRating = availMilRating
#send_for_repair(mil_needing_repair_ids) #currently, let get taken care of by AIFleetMission.generateAIFleetOrders()
# 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.getFleetsForMission(1, {'rating':alloc}, {'rating':minalloc}, foundStats, "", systemsToCheck=[sysID], systemsChecked=[],
fleetPoolSet=availMilFleetIDs, fleetList=foundFleets, verbose=False)
except:
continue
if theseFleets == []:
if foundFleets==[] or not ( FleetUtilsAI.statsMeetReqs( 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.rateFleet(x), foundFleets ) )
ratings = map(foAI.foAIstate.getRating, 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.getAIFleetMission(fleetID)
aiFleetMission.clearAIFleetOrders()
aiFleetMission.clearAITargets( (aiFleetMission.getAIMissionTypes() + [-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.addAITarget( missionType , aiTarget)
aiFleetMission.generateAIFleetOrders()
if not doingMain:
foAI.foAIstate.misc.setdefault('ReassignedFleetMissions', []).append(aiFleetMission)
if doingMain:
print "---------------------------------"
示例14: getInvasionFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def getInvasionFleets():
"get invasion fleets"
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
AIstate.invasionFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs)
# get supplyable planets
universe = fo.getUniverse()
empire = fo.getEmpire()
empireID = empire.empireID
capitalID = PlanetUtilsAI.getCapital()
#capitalID = empire.capitalID
homeworld=None
if capitalID:
homeworld = universe.getPlanet(capitalID)
if homeworld:
homeSystemID = homeworld.systemID
else:
speciesName = ""
homeworldName=" no remaining homeworld "
homeSystemID = -1
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
primeInvadableSystemIDs = set(ColonisationAI.annexableSystemIDs)
primeInvadablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(primeInvadableSystemIDs)
# get competitor planets
exploredSystemIDs = empire.exploredSystemIDs
exploredPlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(exploredSystemIDs)
visibleSystemIDs = foAI.foAIstate.visInteriorSystemIDs.keys() + foAI.foAIstate. visBorderSystemIDs.keys()
visiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(visibleSystemIDs)
accessibleSystemIDs = [sysID for sysID in visibleSystemIDs if universe.systemsConnected(sysID, homeSystemID, empireID) ]
acessiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(accessibleSystemIDs)
#allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(exploredPlanetIDs)
allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(acessiblePlanetIDs)
# print "All Owned and Populated PlanetIDs: " + str(allOwnedPlanetIDs)
allPopulatedPlanets=PlanetUtilsAI.getPopulatedPlanetIDs(acessiblePlanetIDs)
print "All Visible and accessible Populated PlanetIDs (including this empire's): " + str(PlanetUtilsAI.planetNameIDs(allPopulatedPlanets))
empireOwnedPlanetIDs = PlanetUtilsAI.getOwnedPlanetsByEmpire(universe.planetIDs, empireID)
# print "Empire Owned PlanetIDs: " + str(empireOwnedPlanetIDs)
invadablePlanetIDs = set(primeInvadablePlanetIDs).intersection(set(allPopulatedPlanets) - set(empireOwnedPlanetIDs))
print "Prime Invadable PlanetIDs: " + str(PlanetUtilsAI.planetNameIDs(invadablePlanetIDs))
print ""
print "Current Invasion Targeted SystemIDs: " + str(PlanetUtilsAI.sysNameIDs(AIstate.invasionTargetedSystemIDs))
invasionTargetedPlanetIDs = getInvasionTargetedPlanetIDs(universe.planetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, empireID)
allInvasionTargetedSystemIDs = PlanetUtilsAI.getSystems(invasionTargetedPlanetIDs)
# export invasion targeted systems for other AI modules
AIstate.invasionTargetedSystemIDs = allInvasionTargetedSystemIDs
print "Current Invasion Targeted PlanetIDs: " + str(PlanetUtilsAI.planetNameIDs(invasionTargetedPlanetIDs))
invasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
if not invasionFleetIDs:
print "Available Invasion Fleets: 0"
else:
print "Invasion FleetIDs: " + str(FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION))
numInvasionFleets = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(invasionFleetIDs))
print "Invasion Fleets Without Missions: " + str(numInvasionFleets)
evaluatedPlanetIDs = list(set(invadablePlanetIDs) - set(invasionTargetedPlanetIDs))
print "Evaluating potential invasions, PlanetIDs: " + str(evaluatedPlanetIDs)
evaluatedPlanets = assignInvasionValues(evaluatedPlanetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, fleetSupplyablePlanetIDs, empire)
sortedPlanets = [(pid, pscore, ptroops) for (pid, (pscore, ptroops)) in evaluatedPlanets.items() ]
sortedPlanets.sort(lambda x, y: cmp(x[1], y[1]), reverse=True)
sortedPlanets = [(pid, pscore%10000, ptroops) for (pid, pscore, ptroops) in sortedPlanets ]
print ""
if sortedPlanets:
print "Invadable planets\nIDs, ID | Score | Name | Race | Troops"
for pid, pscore, ptroops in sortedPlanets:
planet = universe.getPlanet(pid)
if planet:
print "%6d | %6d | %16s | %16s | %d"%(pid, pscore, planet.name, planet.speciesName, ptroops)
else:
print "%6d | %6d | Error: invalid planet ID"%(pid, pscore)
else:
print "No Invadable planets identified"
# export opponent planets for other AI modules
AIstate.opponentPlanetIDs = [pid for pid, pscore, trp in sortedPlanets]
AIstate.invasionTargets = sortedPlanets
示例15: getInvasionFleets
# 需要導入模塊: import FleetUtilsAI [as 別名]
# 或者: from FleetUtilsAI import extractFleetIDsWithoutMissionTypes [as 別名]
def getInvasionFleets():
"get invasion fleets"
allInvasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
AIstate.invasionFleetIDs = FleetUtilsAI.extractFleetIDsWithoutMissionTypes(allInvasionFleetIDs)
# get supplyable planets
universe = fo.getUniverse()
empire = fo.getEmpire()
empireID = empire.empireID
capitalID = PlanetUtilsAI.getCapital()
#capitalID = empire.capitalID
homeworld=None
if capitalID:
homeworld = universe.getPlanet(capitalID)
if homeworld:
homeSystemID = homeworld.systemID
else:
speciesName = ""
homeworldName=" no remaining homeworld "
homeSystemID = -1
fleetSupplyableSystemIDs = empire.fleetSupplyableSystemIDs
fleetSupplyablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(fleetSupplyableSystemIDs)
primeInvadableSystemIDs1 = set([])
primeInvadableSystemIDs = set([])
print "Current Fleet Supplyable Systems: ", sysNameIDs(empire.fleetSupplyableSystemIDs)
for sysID in empire.fleetSupplyableSystemIDs:
primeInvadableSystemIDs.add(sysID)
for nID in universe.getImmediateNeighbors(sysID, empireID):
primeInvadableSystemIDs.add(nID)
primeInvadableSystemIDs1.add(nID)
primeInvadableSystemIDs1.difference_update(empire.fleetSupplyableSystemIDs)
print "First Ring of invadable systems: ", sysNameIDs(primeInvadableSystemIDs1)
if empire.getTechStatus("CON_ORBITAL_CON") == fo.techStatus.complete:
primeInvadableSystemIDs2 = set([])
for sysID in list(primeInvadableSystemIDs1):
for nID in universe.getImmediateNeighbors(sysID, empireID):
primeInvadableSystemIDs2.add(nID)
primeInvadableSystemIDs2.difference_update(primeInvadableSystemIDs)
print "Second Ring of invadable systems: ", sysNameIDs(primeInvadableSystemIDs2)
primeInvadableSystemIDs.update(primeInvadableSystemIDs2)
primeInvadableSystemIDs3 = set([])
if foAI.foAIstate.aggression > 1:
for sysID in list(primeInvadableSystemIDs2):
for nID in universe.getImmediateNeighbors(sysID, empireID):
primeInvadableSystemIDs3.add(nID)
primeInvadableSystemIDs3.difference_update(primeInvadableSystemIDs)
print "Third Ring of invadable systems: ", sysNameIDs(primeInvadableSystemIDs3)
primeInvadableSystemIDs.update(primeInvadableSystemIDs3)
primeInvadablePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(primeInvadableSystemIDs)
# get competitor planets
exploredSystemIDs = empire.exploredSystemIDs
exploredPlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(exploredSystemIDs)
visibleSystemIDs = foAI.foAIstate.visInteriorSystemIDs.keys() + foAI.foAIstate. visBorderSystemIDs.keys()
visiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(visibleSystemIDs)
accessibleSystemIDs = [sysID for sysID in visibleSystemIDs if universe.systemsConnected(sysID, homeSystemID, empireID) ]
acessiblePlanetIDs = PlanetUtilsAI.getPlanetsInSystemsIDs(accessibleSystemIDs)
#allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(exploredPlanetIDs)
allOwnedPlanetIDs = PlanetUtilsAI.getAllOwnedPlanetIDs(acessiblePlanetIDs)
# print "All Owned and Populated PlanetIDs: " + str(allOwnedPlanetIDs)
allPopulatedPlanets=PlanetUtilsAI.getPopulatedPlanetIDs(acessiblePlanetIDs)
print "All Visible and accessible Populated PlanetIDs (including this empire's): " + str(planetNameIDs(allPopulatedPlanets))
empireOwnedPlanetIDs = PlanetUtilsAI.getOwnedPlanetsByEmpire(universe.planetIDs, empireID)
# print "Empire Owned PlanetIDs: " + str(empireOwnedPlanetIDs)
invadablePlanetIDs = set(primeInvadablePlanetIDs).intersection(set(allPopulatedPlanets) - set(empireOwnedPlanetIDs))
print "Prime Invadable PlanetIDs: " + str(planetNameIDs(invadablePlanetIDs))
print ""
print "Invasion Targeted SystemIDs: " + str(sysNameIDs(AIstate.invasionTargetedSystemIDs))
invasionTargetedPlanetIDs = getInvasionTargetedPlanetIDs(universe.planetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, empireID)
allInvasionTargetedSystemIDs = PlanetUtilsAI.getSystems(invasionTargetedPlanetIDs)
# export invasion targeted systems for other AI modules
AIstate.invasionTargetedSystemIDs = allInvasionTargetedSystemIDs
print "Invasion Targeted PlanetIDs: " + str(planetNameIDs(invasionTargetedPlanetIDs))
invasionFleetIDs = FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION)
if not invasionFleetIDs:
print "Available Invasion Fleets: 0"
else:
print "Invasion FleetIDs: " + str(FleetUtilsAI.getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_INVASION))
numInvasionFleets = len(FleetUtilsAI.extractFleetIDsWithoutMissionTypes(invasionFleetIDs))
print "Invasion Fleets Without Missions: " + str(numInvasionFleets)
evaluatedPlanetIDs = list(set(invadablePlanetIDs) - set(invasionTargetedPlanetIDs))
print "Evaluating potential invasions, PlanetIDs: " + str(evaluatedPlanetIDs)
evaluatedPlanets = assignInvasionValues(evaluatedPlanetIDs, AIFleetMissionType.FLEET_MISSION_INVASION, fleetSupplyablePlanetIDs, empire)
sortedPlanets = [(pid, pscore, ptroops) for (pid, (pscore, ptroops)) in evaluatedPlanets.items() ]
#.........這裏部分代碼省略.........