parameters: ()
docstring: examines known planets, collects various colonization data, to be later used to send colony fleets
docstring_summary: examines known planets, collects various colonization data, to be later used to send colony fleets
docstring_tokens: examines known planets collects various colonization data to be later used to send colony fleets
function: def get_colony_fleets():
      """examines known planets, collects various colonization data, to be later used to send colony fleets"""
      universe = fo.getUniverse()
      empire = fo.getEmpire()
  
      colonization_timer.start("Identify Existing colony/outpost targets")
      colony_targeted_planet_ids = FleetUtilsAI.get_targeted_planet_ids(universe.planetIDs, MissionType.COLONISATION)
      all_colony_targeted_system_ids = PlanetUtilsAI.get_systems(colony_targeted_planet_ids)
      colony_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.COLONISATION)
      num_colony_fleets = len(FleetUtilsAI.extract_fleet_ids_without_mission_types(colony_fleet_ids))
  
      outpost_targeted_planet_ids = FleetUtilsAI.get_targeted_planet_ids(universe.planetIDs, MissionType.OUTPOST)
      outpost_targeted_planet_ids.extend(
          FleetUtilsAI.get_targeted_planet_ids(universe.planetIDs, MissionType.ORBITAL_OUTPOST)
      )
      all_outpost_targeted_system_ids = PlanetUtilsAI.get_systems(outpost_targeted_planet_ids)
      outpost_fleet_ids = FleetUtilsAI.get_empire_fleet_ids_by_role(MissionType.OUTPOST)
      num_outpost_fleets = len(FleetUtilsAI.extract_fleet_ids_without_mission_types(outpost_fleet_ids))
  
      debug("Colony Targeted SystemIDs: %s" % all_colony_targeted_system_ids)
      debug("Colony Targeted PlanetIDs: %s" % colony_targeted_planet_ids)
      debug(colony_fleet_ids and "Colony Fleet IDs: %s" % colony_fleet_ids or "Available Colony Fleets: 0")
      debug("Colony Fleets Without Missions: %s" % num_colony_fleets)
      debug("")
      debug("Outpost Targeted SystemIDs: %s" % all_outpost_targeted_system_ids)
      debug("Outpost Targeted PlanetIDs: %s" % outpost_targeted_planet_ids)
      debug(outpost_fleet_ids and "Outpost Fleet IDs: %s" % outpost_fleet_ids or "Available Outpost Fleets: 0")
      debug("Outpost Fleets Without Missions: %s" % num_outpost_fleets)
      debug("")
  
      # export targeted systems for other AI modules
      AIstate.colonyTargetedSystemIDs = all_colony_targeted_system_ids
      AIstate.outpostTargetedSystemIDs = all_outpost_targeted_system_ids
  
      colonization_timer.start("Identify colony base targets")
      # keys are sets of ints; data is doubles
      available_pp = {tuple(el.key()): el.data() for el in empire.planetsWithAvailablePP}
  
      avail_pp_by_sys = {}
      for p_set in available_pp:
          avail_pp_by_sys.update([(sys_id, available_pp[p_set]) for sys_id in set(PlanetUtilsAI.get_systems(p_set))])
  
      evaluated_colony_planet_ids = list(
          get_unowned_empty_planets().union(get_empire_outposts()) - set(colony_targeted_planet_ids)
      )  # places for possible colonyBase
  
      aistate = get_aistate()
      outpost_base_manager = aistate.orbital_colonization_manager
  
      for pid in evaluated_colony_planet_ids:  # TODO: reorganize
          planet = universe.getPlanet(pid)
          if not planet:
              continue
          sys_id = planet.systemID
          for pid2 in get_colonized_planets_in_system(sys_id):
              planet2 = universe.getPlanet(pid2)
              if not (planet2 and can_build_colony_for_species(planet2.speciesName)):
                  continue
              if planet.unowned:
                  outpost_base_manager.create_new_plan(pid, pid2)
  
      colonization_timer.start("Initiate outpost base construction")
  
      reserved_outpost_base_targets = outpost_base_manager.get_targets()
      debug("Current qualifyingOutpostBaseTargets: %s" % reserved_outpost_base_targets)
      outpost_base_manager.build_bases()
      colonization_timer.start("Evaluate Primary Colony Opportunities")
  
      evaluated_outpost_planet_ids = list(
          get_unowned_empty_planets()
          - set(outpost_targeted_planet_ids)
          - set(colony_targeted_planet_ids)
          - set(reserved_outpost_base_targets)
      )
  
      evaluated_colony_planets = assign_colonisation_values(evaluated_colony_planet_ids, MissionType.COLONISATION, None)
      colonization_timer.stop("Evaluate %d Primary Colony Opportunities" % (len(evaluated_colony_planet_ids)))
      colonization_timer.start("Evaluate All Colony Opportunities")
      _all_colony_opportunities.clear()
      _all_colony_opportunities.update(
          assign_colonisation_values(evaluated_colony_planet_ids, MissionType.COLONISATION, None, [], True)
      )
      colonization_timer.start("Evaluate Outpost Opportunities")
  
      sorted_planets = list(evaluated_colony_planets.items())
      sorted_planets.sort(key=itemgetter(1), reverse=True)
  
      _print_colony_candidate_table(sorted_planets, show_detail=False)
  
      sorted_planets = [(planet_id, score[:2]) for planet_id, score in sorted_planets if score[0] > 0]
      # export planets for other AI modules
      aistate.colonisablePlanetIDs.clear()
      aistate.colonisablePlanetIDs.update(sorted_planets)
  
      evaluated_outpost_planets = assign_colonisation_values(evaluated_outpost_planet_ids, MissionType.OUTPOST, None)
      # if outposted planet would be in supply range, let outpost value be best of outpost value or colonization value
      for pid in set(evaluated_outpost_planets).intersection(evaluated_colony_planets):
          if get_planet_supply(pid, -99) >= 0:
              evaluated_outpost_planets[pid] = (
                  max(evaluated_colony_planets[pid][0], evaluated_outpost_planets[pid][0]),
                  "",
              )
  
      colonization_timer.stop()
  
      sorted_outposts = list(evaluated_outpost_planets.items())
      sorted_outposts.sort(key=itemgetter(1), reverse=True)
  
      _print_outpost_candidate_table(sorted_outposts)
  
      sorted_outposts = [(planet_id, score[:2]) for planet_id, score in sorted_outposts if score[0] > 0]
      # export outposts for other AI modules
      aistate.colonisableOutpostIDs.clear()
      aistate.colonisableOutpostIDs.update(sorted_outposts)
      colonization_timer.stop_print_and_clear()
function_tokens: def get_colony_fleets ( ) : universe = fo . getUniverse ( ) empire = fo . getEmpire ( ) colonization_timer . start ( "Identify Existing colony/outpost targets" ) colony_targeted_planet_ids = FleetUtilsAI . get_targeted_planet_ids ( universe . planetIDs , MissionType . COLONISATION ) all_colony_targeted_system_ids = PlanetUtilsAI . get_systems ( colony_targeted_planet_ids ) colony_fleet_ids = FleetUtilsAI . get_empire_fleet_ids_by_role ( MissionType . COLONISATION ) num_colony_fleets = len ( FleetUtilsAI . extract_fleet_ids_without_mission_types ( colony_fleet_ids ) ) outpost_targeted_planet_ids = FleetUtilsAI . get_targeted_planet_ids ( universe . planetIDs , MissionType . OUTPOST ) outpost_targeted_planet_ids . extend ( FleetUtilsAI . get_targeted_planet_ids ( universe . planetIDs , MissionType . ORBITAL_OUTPOST ) ) all_outpost_targeted_system_ids = PlanetUtilsAI . get_systems ( outpost_targeted_planet_ids ) outpost_fleet_ids = FleetUtilsAI . get_empire_fleet_ids_by_role ( MissionType . OUTPOST ) num_outpost_fleets = len ( FleetUtilsAI . extract_fleet_ids_without_mission_types ( outpost_fleet_ids ) ) debug ( "Colony Targeted SystemIDs: %s" % all_colony_targeted_system_ids ) debug ( "Colony Targeted PlanetIDs: %s" % colony_targeted_planet_ids ) debug ( colony_fleet_ids and "Colony Fleet IDs: %s" % colony_fleet_ids or "Available Colony Fleets: 0" ) debug ( "Colony Fleets Without Missions: %s" % num_colony_fleets ) debug ( "" ) debug ( "Outpost Targeted SystemIDs: %s" % all_outpost_targeted_system_ids ) debug ( "Outpost Targeted PlanetIDs: %s" % outpost_targeted_planet_ids ) debug ( outpost_fleet_ids and "Outpost Fleet IDs: %s" % outpost_fleet_ids or "Available Outpost Fleets: 0" ) debug ( "Outpost Fleets Without Missions: %s" % num_outpost_fleets ) debug ( "" ) # export targeted systems for other AI modules AIstate . colonyTargetedSystemIDs = all_colony_targeted_system_ids AIstate . outpostTargetedSystemIDs = all_outpost_targeted_system_ids colonization_timer . start ( "Identify colony base targets" ) # keys are sets of ints; data is doubles available_pp = { tuple ( el . key ( ) ) : el . data ( ) for el in empire . planetsWithAvailablePP } avail_pp_by_sys = { } for p_set in available_pp : avail_pp_by_sys . update ( [ ( sys_id , available_pp [ p_set ] ) for sys_id in set ( PlanetUtilsAI . get_systems ( p_set ) ) ] ) evaluated_colony_planet_ids = list ( get_unowned_empty_planets ( ) . union ( get_empire_outposts ( ) ) - set ( colony_targeted_planet_ids ) ) # places for possible colonyBase aistate = get_aistate ( ) outpost_base_manager = aistate . orbital_colonization_manager for pid in evaluated_colony_planet_ids : # TODO: reorganize planet = universe . getPlanet ( pid ) if not planet : continue sys_id = planet . systemID for pid2 in get_colonized_planets_in_system ( sys_id ) : planet2 = universe . getPlanet ( pid2 ) if not ( planet2 and can_build_colony_for_species ( planet2 . speciesName ) ) : continue if planet . unowned : outpost_base_manager . create_new_plan ( pid , pid2 ) colonization_timer . start ( "Initiate outpost base construction" ) reserved_outpost_base_targets = outpost_base_manager . get_targets ( ) debug ( "Current qualifyingOutpostBaseTargets: %s" % reserved_outpost_base_targets ) outpost_base_manager . build_bases ( ) colonization_timer . start ( "Evaluate Primary Colony Opportunities" ) evaluated_outpost_planet_ids = list ( get_unowned_empty_planets ( ) - set ( outpost_targeted_planet_ids ) - set ( colony_targeted_planet_ids ) - set ( reserved_outpost_base_targets ) ) evaluated_colony_planets = assign_colonisation_values ( evaluated_colony_planet_ids , MissionType . COLONISATION , None ) colonization_timer . stop ( "Evaluate %d Primary Colony Opportunities" % ( len ( evaluated_colony_planet_ids ) ) ) colonization_timer . start ( "Evaluate All Colony Opportunities" ) _all_colony_opportunities . clear ( ) _all_colony_opportunities . update ( assign_colonisation_values ( evaluated_colony_planet_ids , MissionType . COLONISATION , None , [ ] , True ) ) colonization_timer . start ( "Evaluate Outpost Opportunities" ) sorted_planets = list ( evaluated_colony_planets . items ( ) ) sorted_planets . sort ( key = itemgetter ( 1 ) , reverse = True ) _print_colony_candidate_table ( sorted_planets , show_detail = False ) sorted_planets = [ ( planet_id , score [ : 2 ] ) for planet_id , score in sorted_planets if score [ 0 ] > 0 ] # export planets for other AI modules aistate . colonisablePlanetIDs . clear ( ) aistate . colonisablePlanetIDs . update ( sorted_planets ) evaluated_outpost_planets = assign_colonisation_values ( evaluated_outpost_planet_ids , MissionType . OUTPOST , None ) # if outposted planet would be in supply range, let outpost value be best of outpost value or colonization value for pid in set ( evaluated_outpost_planets ) . intersection ( evaluated_colony_planets ) : if get_planet_supply ( pid , - 99 ) >= 0 : evaluated_outpost_planets [ pid ] = ( max ( evaluated_colony_planets [ pid ] [ 0 ] , evaluated_outpost_planets [ pid ] [ 0 ] ) , "" , ) colonization_timer . stop ( ) sorted_outposts = list ( evaluated_outpost_planets . items ( ) ) sorted_outposts . sort ( key = itemgetter ( 1 ) , reverse = True ) _print_outpost_candidate_table ( sorted_outposts ) sorted_outposts = [ ( planet_id , score [ : 2 ] ) for planet_id , score in sorted_outposts if score [ 0 ] > 0 ] # export outposts for other AI modules aistate . colonisableOutpostIDs . clear ( ) aistate . colonisableOutpostIDs . update ( sorted_outposts ) colonization_timer . stop_print_and_clear ( )