def print_resources_priority(): """Calculate top resource priority.""" universe = fo.getUniverse() empire = fo.getEmpire() empire_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire( universe.planetIDs) debug("Resource Priorities:") resource_priorities = {} aistate = get_aistate() for priority_type in get_priority_resource_types(): resource_priorities[priority_type] = aistate.get_priority( priority_type) sorted_priorities = sorted(resource_priorities.items(), key=itemgetter(1), reverse=True) top_priority = -1 for evaluation_priority, evaluation_score in sorted_priorities: if top_priority < 0: top_priority = evaluation_priority debug(" %s: %.2f", evaluation_priority, evaluation_score) # what is the focus of available resource centers? debug("") warnings = {} foci_table = Table( Text("Planet"), Text("Size"), Text("Type"), Text("Focus"), Text("Species"), Text("Pop"), table_name="Planetary Foci Overview Turn %d" % fo.currentTurn(), ) for pid in empire_planet_ids: planet = universe.getPlanet(pid) population = planet.currentMeterValue(fo.meterType.population) max_population = planet.currentMeterValue( fo.meterType.targetPopulation) if max_population < 1 and population > 0: warnings[planet.name] = (population, max_population) foci_table.add_row( planet, planet.size, planet.type, "_".join(str(planet.focus).split("_")[1:])[:8], planet.speciesName, "%.1f/%.1f" % (population, max_population), ) foci_table.print_table(info) debug( "Empire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n", empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research), ) for name, (cp, mp) in warnings.items(): warning( "Population Warning! -- %s has unsustainable current pop %d -- target %d", name, cp, mp)
def print_resources_priority(): """Calculate top resource priority.""" universe = fo.getUniverse() empire = fo.getEmpire() empire_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire( universe.planetIDs) print "Resource Priorities:" resource_priorities = {} for priority_type in get_priority_resource_types(): resource_priorities[priority_type] = foAI.foAIstate.get_priority( priority_type) sorted_priorities = resource_priorities.items() sorted_priorities.sort(lambda x, y: cmp(x[1], y[1]), reverse=True) top_priority = -1 for evaluation_priority, evaluation_score in sorted_priorities: if top_priority < 0: top_priority = evaluation_priority print " %s: %.2f" % (evaluation_priority, evaluation_score) # what is the focus of available resource centers? print warnings = {} foci_table = Table([ Text('Planet'), Text('Size'), Text('Type'), Text('Focus'), Text('Species'), Text('Pop') ], table_name="Planetary Foci Overview Turn %d" % fo.currentTurn()) for pid in empire_planet_ids: planet = universe.getPlanet(pid) population = planet.currentMeterValue(fo.meterType.population) max_population = planet.currentMeterValue( fo.meterType.targetPopulation) if max_population < 1 and population > 0: warnings[planet.name] = (population, max_population) foci_table.add_row([ planet, planet.size, planet.type, "_".join(str(planet.focus).split("_")[1:])[:8], planet.speciesName, "%.1f/%.1f" % (population, max_population) ]) foci_table.print_table() print "Empire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % ( empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) for name, (cp, mp) in warnings.iteritems(): print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % ( name, cp, mp)
def print_resources_priority(): """calculate top resource priority""" universe = fo.getUniverse() empire = fo.getEmpire() empirePlanetIDs = PlanetUtilsAI.get_owned_planets_by_empire( universe.planetIDs) print "Resource Management:" print print "Resource Priorities:" resourcePriorities = {} for priorityType in get_priority_resource_types(): resourcePriorities[priorityType] = foAI.foAIstate.get_priority( priorityType) sortedPriorities = resourcePriorities.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 " ResourcePriority |Score: %s | %s " % ( AIPriorityTypeNames.name(evaluationPair[0]), evaluationPair[1]) # what is the focus of available resource centers? print warnings = {} print "Planet Resources Foci:" for planetID in empirePlanetIDs: planet = universe.getPlanet(planetID) planetPopulation = planet.currentMeterValue(fo.meterType.population) maxPop = planet.currentMeterValue(fo.meterType.targetPopulation) if maxPop < 1 and planetPopulation > 0: warnings[planet.name] = (planetPopulation, maxPop) statusStr = " ID: " + str(planetID) + " Name: % 18s -- % 6s % 8s " % ( str(planet.name), str(planet.size), str(planet.type)) statusStr += " Focus: % 8s" % ("_".join( str(planet.focus).split("_")[1:])[:8]) + " Species: " + str( planet.speciesName) + " Pop: %2d/%2d" % (planetPopulation, maxPop) print statusStr print "\n\nEmpire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % ( empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) if warnings != {}: for pname in warnings: mp, cp = warnings[pname] print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % ( pname, cp, mp) print warnings.clear()
def print_resources_priority(): """Calculate top resource priority.""" universe = fo.getUniverse() empire = fo.getEmpire() empire_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire( universe.planetIDs) print "Resource Management:" print print "Resource Priorities:" resource_priorities = {} for priority_type in get_priority_resource_types(): resource_priorities[priority_type] = foAI.foAIstate.get_priority( priority_type) sorted_priorities = resource_priorities.items() sorted_priorities.sort(lambda x, y: cmp(x[1], y[1]), reverse=True) top_priority = -1 for evaluation_priority, evaluation_score in sorted_priorities: if top_priority < 0: top_priority = evaluation_priority print " ResourcePriority |Score: %s | %s " % ( evaluation_priority, evaluation_score) # what is the focus of available resource centers? print warnings = {} # TODO combine this with previous table to reduce report duplication? print "Planet Resources Foci:" for pid in empire_planet_ids: planet = universe.getPlanet(pid) population = planet.currentMeterValue(fo.meterType.population) max_population = planet.currentMeterValue( fo.meterType.targetPopulation) if max_population < 1 and population > 0: warnings[planet.name] = (population, max_population) print " ID: %d Name: % 18s -- % 6s % 8s Focus: % 8s Species: %s Pop: %2d/%2d" % ( pid, planet.name, planet.size, planet.type, "_".join( str(planet.focus).split("_")[1:])[:8], planet.speciesName, population, max_population) print "\n\nEmpire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % ( empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) if warnings != {}: for name in warnings: mp, cp = warnings[name] print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % ( name, cp, mp) print warnings.clear()
def print_resources_priority(): """Calculate top resource priority.""" universe = fo.getUniverse() empire = fo.getEmpire() empire_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire(universe.planetIDs) print "Resource Priorities:" resource_priorities = {} aistate = get_aistate() for priority_type in get_priority_resource_types(): resource_priorities[priority_type] = aistate.get_priority(priority_type) sorted_priorities = resource_priorities.items() sorted_priorities.sort(lambda x, y: cmp(x[1], y[1]), reverse=True) top_priority = -1 for evaluation_priority, evaluation_score in sorted_priorities: if top_priority < 0: top_priority = evaluation_priority print " %s: %.2f" % (evaluation_priority, evaluation_score) # what is the focus of available resource centers? print warnings = {} foci_table = Table([ Text('Planet'), Text('Size'), Text('Type'), Text('Focus'), Text('Species'), Text('Pop') ], table_name="Planetary Foci Overview Turn %d" % fo.currentTurn()) for pid in empire_planet_ids: planet = universe.getPlanet(pid) population = planet.currentMeterValue(fo.meterType.population) max_population = planet.currentMeterValue(fo.meterType.targetPopulation) if max_population < 1 and population > 0: warnings[planet.name] = (population, max_population) foci_table.add_row([ planet, planet.size, planet.type, "_".join(str(planet.focus).split("_")[1:])[:8], planet.speciesName, "%.1f/%.1f" % (population, max_population) ]) info(foci_table) print "Empire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % ( empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) for name, (cp, mp) in warnings.iteritems(): print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % (name, cp, mp)
def print_resources_priority(): """calculate top resource priority""" universe = fo.getUniverse() empire = fo.getEmpire() empirePlanetIDs = PlanetUtilsAI.get_owned_planets_by_empire(universe.planetIDs) print "Resource Management:" print print "Resource Priorities:" resourcePriorities = {} for priorityType in get_priority_resource_types(): resourcePriorities[priorityType] = foAI.foAIstate.get_priority(priorityType) sortedPriorities = resourcePriorities.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 " ResourcePriority |Score: %s | %s " % (AIPriorityTypeNames.name(evaluationPair[0]), evaluationPair[1]) # what is the focus of available resource centers? print warnings = {} print "Planet Resources Foci:" for planetID in empirePlanetIDs: planet = universe.getPlanet(planetID) planetPopulation = planet.currentMeterValue(fo.meterType.population) maxPop = planet.currentMeterValue(fo.meterType.targetPopulation) if maxPop < 1 and planetPopulation > 0: warnings[planet.name] = (planetPopulation, maxPop) statusStr = " ID: " + str(planetID) + " Name: % 18s -- % 6s % 8s " % (str(planet.name), str(planet.size), str(planet.type)) statusStr += " Focus: % 8s" % ("_".join(str(planet.focus).split("_")[1:])[:8]) + " Species: " + str(planet.speciesName) + " Pop: %2d/%2d" % (planetPopulation, maxPop) print statusStr print "\n\nEmpire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % (empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) if warnings != {}: for pname in warnings: mp, cp = warnings[pname] print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % (pname, cp, mp) print warnings.clear()
def print_resources_priority(): """Calculate top resource priority.""" universe = fo.getUniverse() empire = fo.getEmpire() empire_planet_ids = PlanetUtilsAI.get_owned_planets_by_empire(universe.planetIDs) print "Resource Management:" print print "Resource Priorities:" resource_priorities = {} for priority_type in get_priority_resource_types(): resource_priorities[priority_type] = foAI.foAIstate.get_priority(priority_type) sorted_priorities = resource_priorities.items() sorted_priorities.sort(lambda x, y: cmp(x[1], y[1]), reverse=True) top_priority = -1 for evaluation_priority, evaluation_score in sorted_priorities: if top_priority < 0: top_priority = evaluation_priority print " ResourcePriority |Score: %s | %s " % (evaluation_priority, evaluation_score) # what is the focus of available resource centers? print warnings = {} # TODO combine this with previous table to reduce report duplication? print "Planet Resources Foci:" for pid in empire_planet_ids: planet = universe.getPlanet(pid) population = planet.currentMeterValue(fo.meterType.population) max_population = planet.currentMeterValue(fo.meterType.targetPopulation) if max_population < 1 and population > 0: warnings[planet.name] = (population, max_population) print " ID: %d Name: % 18s -- % 6s % 8s Focus: % 8s Species: %s Pop: %2d/%2d" % (pid, planet.name, planet.size, planet.type, "_".join(str(planet.focus).split("_")[1:])[:8], planet.speciesName, population, max_population) print "\n\nEmpire Totals:\nPopulation: %5d \nProduction: %5d\nResearch: %5d\n" % (empire.population(), empire.productionPoints, empire.resourceProduction(fo.resourceType.research)) if warnings != {}: for name in warnings: mp, cp = warnings[name] print "Population Warning! -- %s has unsustainable current pop %d -- target %d" % (name, cp, mp) print warnings.clear()