def assignScoutsToExploreSystems(): # TODO: use Graph Theory to explore closest systems universe = fo.getUniverse() capitalSysID = PlanetUtilsAI.getCapitalSysID() # order fleets to explore #explorableSystemIDs = foAI.foAIstate.getExplorableSystems(AIExplorableSystemType.EXPLORABLE_SYSTEM_UNEXPLORED) explorableSystemIDs = list(borderUnexploredSystemIDs) if not explorableSystemIDs or (capitalSysID == -1): return expSystemsByDist = sorted( map( lambda x: ( universe.linearDistance(capitalSysID, x), x) , explorableSystemIDs ) ) print "Exploration system considering following system-distance pairs:\n %s"%("[ "+ ", ".join(["%3d : %5.1f"%(sys, dist) for dist, sys in expSystemsByDist]) +" ]") exploreList = [sysID for dist, sysID in expSystemsByDist ] alreadyCovered, availableScouts = getCurrentExplorationInfo() print "explorable sys IDs: %s"%exploreList print "already targeted: %s"%alreadyCovered if 'needsEmergencyExploration' not in dir(foAI.foAIstate): foAI.foAIstate.needsEmergencyExploration=[] needsCoverage= foAI.foAIstate.needsEmergencyExploration + [sysID for sysID in exploreList if sysID not in alreadyCovered ] # emergency coverage cane be due to invasion detection trouble, etc. print "needs coverage: %s"%needsCoverage print "available scouts & AIstate locs: %s"%(map( lambda x: (x, foAI.foAIstate.fleetStatus.get(x, {}).get('sysID', -1)), availableScouts) ) print "available scouts & universe locs: %s"%(map( lambda x: (x, universe.getFleet(x).systemID), availableScouts) ) if not needsCoverage or not availableScouts: return availableScouts = set(availableScouts) sentList=[] while (len(availableScouts) > 0 ) and ( len(needsCoverage) >0): thisSysID = needsCoverage.pop(0) if (foAI.foAIstate.systemStatus.setdefault(thisSysID, {}).setdefault('monsterThreat', 0) > 2000*(foAI.foAIstate.aggression) ) or (fo.currentTurn() <20 and foAI.foAIstate.systemStatus[thisSysID]['monsterThreat'] > 200): print "Skipping exploration of system %d due to Big Monster, threat %d"%(thisSysID, foAI.foAIstate.systemStatus[thisSysID]['monsterThreat']) continue foundFleets=[] thisFleetList = FleetUtilsAI.getFleetsForMission(nships=1, targetStats={}, minStats={}, curStats={}, species="", systemsToCheck=[thisSysID], systemsChecked=[], fleetPoolSet = availableScouts, fleetList=foundFleets, verbose=False) if thisFleetList==[]: print "seem to have run out of scouts while trying to cover sysID %d"%thisSysID break #must have ran out of scouts fleetID = thisFleetList[0] aiFleetMission = foAI.foAIstate.getAIFleetMission( fleetID ) aiTarget = AITarget.AITarget(AITargetType.TARGET_SYSTEM, thisSysID ) if len(MoveUtilsAI.canTravelToSystemAndReturnToResupply(fleetID, aiFleetMission.getLocationAITarget(), aiTarget, fo.empireID())) > 0: aiFleetMission.addAITarget(AIFleetMissionType.FLEET_MISSION_EXPLORATION, aiTarget) sentList.append(thisSysID) else: #system too far out, skip it, but can add scout back to available pool print "sysID %d too far out for fleet ( ID %d ) to readch"%(thisSysID, fleetID) availableScouts.update(thisFleetList) print "sent scouting fleets to sysIDs : %s"%sentList return # pylint: disable=pointless-string-statement """
def clean(self): "turn start AIstate cleanup" fleetsLostBySystem.clear() fleetsLostByID.clear() invasionTargets[:]=[] exploration_center = PlanetUtilsAI.getCapitalSysID() if exploration_center == -1: #a bad state probably from an old savegame exploration_center = self.origHomeSystemID ExplorationAI.graphFlags.clear() if fo.currentTurn() < 50: print "-------------------------------------------------" print "Border Exploration Update (relative to %s"%(PlanetUtilsAI.sysNameIDs([exploration_center, -1])[0]) print "-------------------------------------------------" if self.visBorderSystemIDs.keys() == [-1]: self.visBorderSystemIDs.clear() self.visBorderSystemIDs[exploration_center] = 1 for sysID in list(self.visBorderSystemIDs): if fo.currentTurn() < 50: print "Considering border system %s"%(PlanetUtilsAI.sysNameIDs([sysID, -1])[0]) ExplorationAI.followVisSystemConnections(sysID, exploration_center) newlyExplored = ExplorationAI.updateExploredSystems() nametags=[] universe = fo.getUniverse() for sysID in newlyExplored: newsys = universe.getSystem(sysID) nametags.append( "ID:%4d -- %20s"%(sysID, (newsys and newsys.name) or"name unknown" ) )# an explored system *should* always be able to be gotten if newlyExplored: print "-------------------------------------------------" print "newly explored systems: \n"+"\n".join(nametags) print "-------------------------------------------------" # cleanup fleet roles #self.updateFleetLocs() self.__cleanFleetRoles() self.__cleanAIFleetMissions(FleetUtilsAI.getEmpireFleetIDs()) print "Fleets lost by system: %s"%fleetsLostBySystem self.updateSystemStatus() ExplorationAI.updateScoutFleets() #should do this after clearing dead fleets, currently should be already done here