Difference between revisions of "User:The Silent One/colonisation code"

From FreeOrionWiki
Jump to: navigation, search
(New page: import foaiint # called once per turn def GenerateColonisationOrders(): foaiint.LogOutput("Generating Colonisation Orders") empire = foaiint.GetEmpire() empire_id = ...)
 
(pre Tag for code)
Line 1: Line 1:
import foaiint
+
<pre>import foaiint
  
 
# called once per turn
 
# called once per turn
Line 97: Line 97:
  
 
def GetEmpireStationaryFleetIDs: pass
 
def GetEmpireStationaryFleetIDs: pass
 +
</pre>

Revision as of 22:21, 2 January 2008

import foaiint

# called once per turn

def GenerateColonisationOrders():

    foaiint.LogOutput("Generating Colonisation Orders")

    

    empire = foaiint.GetEmpire()

    empire_id = foaiint.EmpireID()

    universe = foaiint.GetUniverse()

    
# --- Look for idle colony ships --- (Create a list with idle colony ships, if none are available, abort)
    

    colonyship_ids_list = GetEmpireStationaryFleetIDs(empire_id)

    foaiint.LogOutput("fleet_ids_list: " + str(fleet_ids_list))


    # erase all fleets from the list that have no colony ship
    while (i < colonyship_ids_list.len):

      # CODE if colonyship_ids_list[i] == colonyship:   # CODE (== colship)
        i = i+1
        continue  

      del colonyship_ids_list[i]
    
    # if there is no colony ship avaiable, the colonisation AI is done
    if colonyship_ids_list.len == 0: return


# --- Search for suitable planets ---
    # (1) Create a list with all known systems
    system_ids_list = [...]  # id-list of all explored systems

    # (1b) Create a planet list from the system list
    planet_list = []

    for i in range(0, system_ids_list.len):
      for j in range(0, system_ids_list[i].planetcount):            
        planet_list.append(system_ids_list[i].planet[j])

    # (2) Remove planets
    # ... with enemy ship presence (could also be done on system scale)
    # ... that are already colonized
    # ... that have a colony ship en route
    while (i < planet_list.len):
      if Enemy_Presence(planet_list[i]) or Colonised(planet_list[i]) or ColonyShipEnRoute(planet_list[i]):
        del planet_list[i]
        continue
        
      i = i+1

    # (3) Sort planet list with regard to their value
    for i in range(0, planet_list.len):
      planet_list[i].colonise_value == Colonise_Value(planet_list[i])
    # CODE: sort by colonise_value
    # planet_list.sort(key=planet_list.colonize_value)


# --- Send a colony ship ---

  # Send colony ships from idle list to the top planets on the pl value list
    for i in range(0, colonyship_ids_list.len):
      SendFleetToPlanet(colonyship_ids_list[i], planet_list[i])
      colonyship_ids_list[i].mission = "colonize"
      # Ships could be assigned to nearest planets
      # Ship mission should be set to 'Colonize'
      # On Arrival, a colony must be founded at the begin of the turn if ship mission is "colonize"


# --- Helper functions ---

# SendFleetToPlanet

def Enemy_Presence: pass

def Colonised(planet_list[i]): pass

def ColonyShipEnRoute(planet_list[i]): pass
  # get moving fleets
  # remove fleets without col ship or with colony ships that do not have mission
  # ... 'Colonize'
  # remove the remaining colships targets from the planet list

def Colonise_Value(planet_list[i]): pass
  # every planet is assigned a integer value (planet value)
  # see planet evaluation & exploration quotient
  # sort list by planet value

def GetEmpireStationaryFleetIDs: pass