Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
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