def print_production_queue(after_turn=False): """Print production queue content with relevant info in table format.""" universe = fo.getUniverse() s = "after" if after_turn else "before" title = "Production Queue Turn %d %s ProductionAI calls" % ( fo.currentTurn(), s) prod_queue_table = Table( Text("Object"), Text("Location"), Text("Quantity"), Text("Progress"), Text("Allocated PP"), Text("Turns left"), table_name=title, ) for element in fo.getEmpire().productionQueue: if element.buildType == EmpireProductionTypes.BT_SHIP: item = fo.getShipDesign(element.designID) elif element.buildType == EmpireProductionTypes.BT_BUILDING: item = fo.getBuildingType(element.name) else: continue cost = item.productionCost(fo.empireID(), element.locationID) prod_queue_table.add_row( element.name, universe.getPlanet(element.locationID), "%dx %d" % (element.remaining, element.blocksize), "%.1f / %.1f" % (element.progress * cost, cost), "%.1f" % element.allocation, "%d" % element.turnsLeft, ) prod_queue_table.print_table(info)
def inspect_ai_interface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder( list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] inspect( fo, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building), ) exit(1) # exit game to main menu no need to play anymore.
def inspect_FreeOrionAIInterface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder(list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] inspect( fo, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building), ) exit(1) # exit game to main menu no need to play anymore.
def generateProductionOrders(): "generate production orders" print "Production Queue Management:" empire = fo.getEmpire() totalPP = empire.productionPoints print "" print " Total Available Production Points: " + str(totalPP) totalPPSpent = fo.getEmpire().productionQueue.totalSpent print " Total Production Points Spent: " + str(totalPPSpent) wastedPP = totalPP - totalPPSpent print " Wasted Production Points: " + str(wastedPP) print "" print "Possible building types to build:" possibleBuildingTypes = empire.availableBuildingTypes for buildingTypeID in possibleBuildingTypes: buildingType = fo.getBuildingType(buildingTypeID) print " " + str(buildingType.name) + " cost:" + str(buildingType.productionCost) + " time:" + str(buildingType.productionTime) print "" print "Possible ship designs to build:" possibleShipDesigns = empire.availableShipDesigns for shipDesignID in possibleShipDesigns: shipDesign = fo.getShipDesign(shipDesignID) print " " + str(shipDesign.name(True)) + " cost:" + str(shipDesign.productionCost) + " time:" + str(shipDesign.productionTime) print "" print "Projects already in Production Queue:" productionQueue = empire.productionQueue for element in productionQueue: print " " + element.name + " turns:" + str(element.turnsLeft) + " PP:" + str(element.allocation) print "" # get the highest production priorities print "Production Queue Priorities:" productionPriorities = {} for priorityType in getAIPriorityProductionTypes(): productionPriorities[priorityType] = foAI.foAIstate.getPriority(priorityType) sortedPriorities = productionPriorities.items() sortedPriorities.sort(lambda x,y: cmp(x[1], y[1]), reverse=True) topPriority = -1 for evaluationPair in sortedPriorities: if topPriority < 0: topPriority = evaluationPair[0] print " ID|Score: " + str(evaluationPair) print " Top Production Queue Priority: " + str(topPriority) locationIDs = getAvailableBuildLocations(shipDesignID) if len(locationIDs) > 0 and wastedPP > 0: for shipDesignID in possibleShipDesigns: shipDesign = fo.getShipDesign(shipDesignID) explorationShipName = "SD_SCOUT" colonyShipName = "SD_COLONY_SHIP" outpostShipName = "SD_OUTPOST_SHIP" troopShipName = "SD_TROOP_SHIP" if topPriority == 6 and shipDesign.name(False) == explorationShipName: # exploration ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 7 and shipDesign.canColonize and shipDesign.name(False) == outpostShipName: # outpost ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 8 and shipDesign.canColonize and shipDesign.name(False) == colonyShipName: # colony ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 9 and shipDesign.canInvade and shipDesign.name(False) == troopShipName: # troop ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 10 and shipDesign.isArmed: # military ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif shipDesign.attack > 0: # military ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) print ""
def inspect_ai_interface(): capital_id = PlanetUtilsAI.get_capital() universe = fo.getUniverse() fleets_int_vector = universe.fleetIDs fleet = universe.getFleet(list(fleets_int_vector)[0]) ship = universe.getShip(list(universe.shipIDs)[0]) design = fo.getShipDesign(ship.designID) empire = fo.getEmpire() tech = fo.getTech('SHP_WEAPON_2_1') tech_spec = list(tech.unlockedItems)[0] part_id = list(empire.availableShipParts)[0] part_type = fo.getPartType(part_id) prod_queue = empire.productionQueue fo.issueEnqueueShipProductionOrder(list(empire.availableShipDesigns)[0], capital_id) research_queue = empire.researchQueue fo.issueEnqueueTechOrder('SHP_WEAPON_1_2', -1) planet = universe.getPlanet(capital_id) building = list(planet.buildingIDs)[0] color = empire.colour part_meters = ship.partMeters meter = planet.getMeter(fo.meterType.population) inspect( fo, instances=[ meter, part_meters, color, universe, fleet, planet, universe.getSystem(planet.systemID), ship, empire, design, tech, tech_spec, fo.getFieldType('FLD_ION_STORM'), fo.getBuildingType('BLD_SHIPYARD_BASE'), fo.getGalaxySetupData(), fo.getHullType('SH_XENTRONIUM'), fo.getPartType('SR_WEAPON_1_1'), fo.getSpecial('MODERATE_TECH_NATIVES_SPECIAL'), fo.getSpecies('SP_ABADDONI'), fo.getTech('SHP_WEAPON_4_1'), fo.diplomaticMessage(1, 2, fo.diplomaticMessageType.acceptPeaceProposal), fleets_int_vector, part_type, prod_queue, prod_queue.allocatedPP, prod_queue[0], research_queue, research_queue[0], empire.getSitRep(0), universe.getBuilding(building) ], classes_to_ignore=( 'IntSet', 'StringSet', 'IntIntMap', 'ShipSlotVec', 'VisibilityIntMap', 'IntDblMap', 'IntBoolMap', 'ItemSpecVec', 'PairIntInt_IntMap', 'IntSetSet', 'StringVec', 'IntPairVec', 'IntFltMap', 'MeterTypeStringPair', 'MeterTypeMeterMap', 'universeObject', # this item cannot be get from generate orders 'diplomaticStatusUpdate', ), path='AI' ) exit(1) # exit game to main menu no need to play anymore.
def turn_cost(self, planet: PlanetId) -> float: """ Returns production points then can be spent per turn for the building at the given planet. """ return fo.getBuildingType(self.value).perTurnCost( fo.empireID(), planet)
def production_time(self, planet: PlanetId) -> int: """ Returns minimum number of turns the building takes to finish at the given planet. """ return fo.getBuildingType(self.value).productionTime( fo.empireID(), planet)
def production_cost(self, planet: PlanetId) -> float: """ Returns overall production cost of the building at the given planet. """ return fo.getBuildingType(self.value).productionCost( fo.empireID(), planet)
def can_be_produced(self, planet: PlanetId) -> bool: """ Return whether the building can be produced at the given planet. """ return fo.getBuildingType(self.value).canBeProduced( fo.empireID(), planet)
def generateProductionOrders(): "generate production orders" print "Production Queue Management:" empire = fo.getEmpire() totalPP = empire.productionPoints print "" print " Total Available Production Points: " + str(totalPP) totalPPSpent = fo.getEmpire().productionQueue.totalSpent print " Total Production Points Spent: " + str(totalPPSpent) wastedPP = totalPP - totalPPSpent print " Wasted Production Points: " + str(wastedPP) print "" colonisablePlanetIDs = AIstate.colonisablePlanetIDs for element in colonisablePlanetIDs: print " Colonizable Planet ID, Score: " + str(element) colonyFleetIDs = getEmpireFleetIDsByRole(AIFleetMissionType.FLEET_MISSION_COLONISATION) for element in colonyFleetIDs: print " Colony Fleet ID: " + str(element) numColonyFleets = len(extractFleetIDsWithoutMissionTypes(colonyFleetIDs)) print " Number of Colony Fleets Without Missions: " + str(numColonyFleets) print "" print "Possible building types to build:" possibleBuildingTypes = empire.availableBuildingTypes for buildingTypeID in possibleBuildingTypes: buildingType = fo.getBuildingType(buildingTypeID) print " " + str(buildingType.name) + " cost:" + str(buildingType.productionCost) + " time:" + str(buildingType.productionTime) print "" print "Possible ship designs to build:" possibleShipDesigns = empire.availableShipDesigns for shipDesignID in possibleShipDesigns: shipDesign = fo.getShipDesign(shipDesignID) print " " + str(shipDesign.name(True)) + " cost:" + str(shipDesign.productionCost) + " time:" + str(shipDesign.productionTime) print "" print "Projects already in Production Queue:" productionQueue = empire.productionQueue for element in productionQueue: print " " + element.name + " turns:" + str(element.turnsLeft) + " PP:" + str(element.allocation) print "" # get the highest production priorities print "Production Queue Priorities:" productionPriorities = {} for priorityType in getAIPriorityProductionTypes(): productionPriorities[priorityType] = foAI.foAIstate.getPriority(priorityType) sortedPriorities = productionPriorities.items() sortedPriorities.sort(lambda x,y: cmp(x[1], y[1]), reverse=True) topPriority = -1 for evaluationPair in sortedPriorities: if topPriority < 0: topPriority = evaluationPair[0] print " ID|Score: " + str(evaluationPair) print " Top Production Queue Priority: " + str(topPriority) locationIDs = getAvailableBuildLocations(shipDesignID) if len(locationIDs) > 0 and wastedPP > 0: for shipDesignID in possibleShipDesigns: shipDesign = fo.getShipDesign(shipDesignID) explorationShipName = "Scout" colonyShipName = "Colony Ship" outpostShipName = "Outpost Ship" troopShipName = "Troop Ship" if topPriority == 5 and shipDesign.name(True) == explorationShipName: # exploration ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 6 and shipDesign.canColonize and shipDesign.name(True) == outpostShipName: # outpost ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 7 and shipDesign.canColonize and shipDesign.name(True) == colonyShipName: # colony ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 8 and shipDesign.name(True) == troopShipName: # troop ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif topPriority == 9 and shipDesign.isArmed: # military ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) elif shipDesign.attack > 0: # military ship print "" print "adding new ship to production queue: " + shipDesign.name(True) fo.issueEnqueueShipProductionOrder(shipDesignID, locationIDs[0]) print ""