コード例 #1
0
ファイル: AIAbstractMission.py プロジェクト: Ablu/freeorion
    def getAnyAIMissionTypes(self):
        "return types of mission"

        if AIMissionType.FLEET_MISSION == self.getAIMissionType():
            return EnumsAI.getAIFleetMissionTypes()
        elif AIMissionType.EMPIRE_WAR_MISSION == self.getAIMissionType():
            return EnumsAI.getAIEmpireWarMissionTypes()

        return NotImplemented
コード例 #2
0
ファイル: AIstate.py プロジェクト: dbuksbaum/FreeOrion
    def __cleanExplorableSystems(self, startSystemID):
        "cleanup of all explorable systems"

        universe = fo.getUniverse()
        systemIDs = universe.systemIDs
        empireID = fo.empireID()
        empire = fo.getEmpire()

        for systemID in systemIDs:
            system = universe.getSystem(systemID)
            if not system: continue

            #print "system with id: " + str(systemID)

            if (empire.hasExploredSystem(systemID)):
                self.addExplorableSystem(AIExplorableSystemType.EXPLORABLE_SYSTEM_EXPLORED, systemID)
                self.removeExplorableSystem(AIExplorableSystemType.EXPLORABLE_SYSTEM_UNEXPLORED, systemID)
                #print "    has been explored"
                continue
            if (startSystemID == -1 or not universe.systemsConnected(systemID, startSystemID, empireID)):
                for explorableSystemsType in EnumsAI.getAIExplorableSystemTypes():
                    self.removeExplorableSystem(explorableSystemsType, systemID)
                #print "    is not connected to system with id: " + str(startSystemID)
                continue
            explorableSystemsType = self.getExplorableSystem(systemID)
            if (explorableSystemsType == AIExplorableSystemType.EXPLORABLE_SYSTEM_VISIBLE):
                #print "    is already explored system target"
                continue
            #print "    is now an unexplored system"
            self.addExplorableSystem(AIExplorableSystemType.EXPLORABLE_SYSTEM_UNEXPLORED, systemID)
コード例 #3
0
ファイル: AIstate.py プロジェクト: dbuksbaum/FreeOrion
    def __init__(self):
        "constructor"

        self.__missionsByType = {}
        for missionType in EnumsAI.getAIFleetMissionTypes():
            self.__missionsByType[missionType] = {}

        self.__aiMissionsByFleetID = {}

        self.__shipRoleByDesignID = {}
        self.__fleetRoleByID = {}
        self.__priorityByType = {}

        self.__explorableSystemByType = {}
        for explorableSystemsType in EnumsAI.getAIExplorableSystemTypes():
            self.__explorableSystemByType[explorableSystemsType] = {}
コード例 #4
0
ファイル: AIstate.py プロジェクト: e-h-j/freeorion
    def addFleetRole(self, fleetID, missionType):
        "adds a fleet ID/role pair"

        if not EnumsAI.checkValidity(missionType):
            return
        if fleetID in self.__fleetRoleByID:
            #print "Fleet ID " + str(fleetID) + " already exists."
            return
        else:
            self.__fleetRoleByID[fleetID] = missionType
コード例 #5
0
ファイル: AIstate.py プロジェクト: e-h-j/freeorion
    def addShipRole(self, shipDesignID, shipRole):
        "adds a ship designID/role pair"

        if not (shipRole in EnumsAI.getAIShipRolesTypes()):
            print "Invalid shipRole: " + str(shipRole)
            return
        elif shipDesignID in self.__shipRoleByDesignID:
            return
        else:
            self.__shipRoleByDesignID[shipDesignID] = shipRole
コード例 #6
0
ファイル: AIstate.py プロジェクト: dbuksbaum/FreeOrion
    def addExplorableSystem(self, explorableSystemsType, systemID):
        "add explorable system ID with type"

        if not (explorableSystemsType in EnumsAI.getAIExplorableSystemTypes()):
            return

        systems = self.__explorableSystemByType[explorableSystemsType]
        if systemID in systems:
            return
        systems[systemID] = systemID
コード例 #7
0
ファイル: AIstate.py プロジェクト: dbuksbaum/FreeOrion
    def getExplorableSystem(self, systemID):
        "determines system type from ID and returns it"

        for explorableSystemsType in EnumsAI.getAIExplorableSystemTypes():
            systems = self.getExplorableSystems(explorableSystemsType)
            if systemID in systems:
                return explorableSystemsType

        # print "SystemID " + str(systemID) + " not found."
        return AIExplorableSystemType.EXPLORABLE_SYSTEM_INVALID
コード例 #8
0
    def valid(self):
        """Returns if this object is valid."""
        if self.target_id is None or self.target_type is None or \
                not EnumsAI.check_validity(self.target_id):
            return False

        if TargetType.TARGET_EMPIRE == self.target_type:
            return self.target_id in fo.AllEmpireIDs()
        else:
            return self.target_obj is not None
コード例 #9
0
ファイル: AIstate.py プロジェクト: dbuksbaum/FreeOrion
    def addShipRole(self, shipDesignID, shipRole):
        "adds a ship name/role pair"

        if not (shipRole in EnumsAI.getAIShipRolesTypes()):
            print "Invalid shipRole: " + str(shipRole)
            return

        if shipDesignID in self.__shipRoleByDesignID:
            # print shipDesignID + " already exists."
            return

        self.__shipRoleByDesignID[shipDesignID] = shipRole
コード例 #10
0
ファイル: AITarget.py プロジェクト: e-h-j/freeorion
    def valid(self):
        "returns if this object is valid"

        if self.target_id == None or self.target_type == None or \
                EnumsAI.checkValidity(self.target_id) == False:
            return False

        if AITargetType.TARGET_EMPIRE == self.target_type:
            return self.target_id in fo.AllEmpireIDs()
        else:
            return None != self.target_obj

        return False
コード例 #11
0
ファイル: PriorityAI.py プロジェクト: raptor/freeorion
def calculateTopProductionQueuePriority():
    """calculates the top production queue priority"""
    productionQueuePriorities = {}
    for priorityType in EnumsAI.get_priority_production_types():
        productionQueuePriorities[priorityType] = foAI.foAIstate.get_priority(priorityType)

    sortedPriorities = productionQueuePriorities.items()
    sortedPriorities.sort(lambda x, y: cmp(x[1], y[1]), reverse=True)
    topProductionQueuePriority = -1
    for evaluationPair in sortedPriorities:
        if topProductionQueuePriority < 0:
            topProductionQueuePriority = evaluationPair[0]

    return topProductionQueuePriority
コード例 #12
0
ファイル: PriorityAI.py プロジェクト: freeqaz/freeorion
def calculateTopProductionQueuePriority():
    """calculates the top production queue priority"""
    productionQueuePriorities = {}
    for priorityType in EnumsAI.get_priority_production_types():
        productionQueuePriorities[priorityType] = foAI.foAIstate.get_priority(priorityType)

    sortedPriorities = productionQueuePriorities.items()
    sortedPriorities.sort(lambda x,y: cmp(x[1], y[1]), reverse=True)
    topProductionQueuePriority = -1
    for evaluationPair in sortedPriorities:
        if topProductionQueuePriority < 0:
            topProductionQueuePriority = evaluationPair[0]

    return topProductionQueuePriority
コード例 #13
0
ファイル: FleetUtilsAI.py プロジェクト: adesst/freeorion
def assessFleetRole(fleetID):
    "counts the number of ShipRoles in a fleet and returns a corresponding fleetRole"
    print ("assessing role of fleet with id " + str(fleetID))
    # TODO: one colony ship in fleet should mean it's a colony fleet

    universe = fo.getUniverse()

    shipRoles = {}
    for shipRole in EnumsAI.getAIShipRolesTypes():
        shipRoles[shipRole] = 0

    fleet = universe.getFleet(fleetID)
    if not fleet:
        print "couldn't get fleet with id " + str(fleetID)
        return AIShipRoleType.SHIP_ROLE_INVALID

    # count shipRoles
    for shipID in fleet.shipIDs:
        ship = universe.getShip(shipID)
        if ship.design:
            role = foAI.foAIstate.getShipRole(ship.design.id)
        else:
            role = AIShipRoleType.SHIP_ROLE_INVALID

        if role != AIShipRoleType.SHIP_ROLE_INVALID:
            shipRoles[role] = shipRoles[role] + 1

    # determine most common shipRole
    favouriteRole = AIShipRoleType.SHIP_ROLE_INVALID
    for shipRole in shipRoles:
        if shipRoles[shipRole] == max(shipRoles.values()):
            favouriteRole = shipRole

    # assign fleet role
    if favouriteRole == AIShipRoleType.SHIP_ROLE_CIVILIAN_EXPLORATION:
        return AIFleetMissionType.FLEET_MISSION_EXPLORATION
    if favouriteRole == AIShipRoleType.SHIP_ROLE_CIVILIAN_COLONISATION:
        return AIFleetMissionType.FLEET_MISSION_COLONISATION
    if favouriteRole == AIShipRoleType.SHIP_ROLE_CIVILIAN_OUTPOST:
        return AIFleetMissionType.FLEET_MISSION_OUTPOST
    if favouriteRole == AIShipRoleType.SHIP_ROLE_MILITARY_INVASION:
        return AIFleetMissionType.FLEET_MISSION_INVASION
    if favouriteRole == AIShipRoleType.SHIP_ROLE_MILITARY_ATTACK:
        return AIFleetMissionType.FLEET_MISSION_ATTACK
    if favouriteRole == AIShipRoleType.SHIP_ROLE_MILITARY:
        return AIFleetMissionType.FLEET_MISSION_MILITARY

    return AIShipRoleType.SHIP_ROLE_INVALID
コード例 #14
0
ファイル: AITarget.py プロジェクト: adesst/freeorion
    def isValid(self):
        "returns if this object is valid"

        if self.getTargetID() == None or self.getAITargetType() == None or EnumsAI.checkValidity(self.getTargetID()) == False:
            return False

        universe = fo.getUniverse()
        if AITargetType.TARGET_FLEET == self.getAITargetType():
            fleet = universe.getFleet(self.getTargetID())
            if fleet == None:
                return False
            return True

        elif AITargetType.TARGET_SYSTEM == self.getAITargetType():
            system = universe.getSystem(self.getTargetID())
            if system == None:
                return False
            return True

        elif AITargetType.TARGET_PLANET == self.getAITargetType():
            planet = universe.getPlanet(self.getTargetID())
            if planet == None:
                return False
            return True

        elif AITargetType.TARGET_BUILDING == self.getAITargetType():
            building = universe.getBuilding(self.getTargetID())
            if building == None:
                return False
            return True

        elif AITargetType.TARGET_EMPIRE == self.getAITargetType():
            empireIDs = fo.AllEmpireIDs()
            if (empireIDs == None) or (not self.getTargetID() in empireIDs):
                return False
            return True

        return False
コード例 #15
0
ファイル: AIFleetMission.py プロジェクト: oriongod/freeorion
 def __getAIFleetOrderFromAITarget(self, aiFleetMissionType, aiTarget):
     fleetAITarget = AITarget.AITarget(EnumsAI.AITargetType.TARGET_FLEET, self.getAITargetID())
     orderType = EnumsAI.getFleetOrderTypeForMission(aiFleetMissionType,  option=None)
     result = AIFleetOrder.AIFleetOrder(orderType, fleetAITarget, aiTarget)
     return result