AI Script, planet max population capacity (or "Earth that was could no longer sustain our numbers, we were so many.") |
I was rather surprised to find out that the AI script has no system function to get the maximum population capcity for a planet. So, I made my own. I hope someone finds this useful.
First, I added these constants to Script_AI_GlobalConstants_General.txt:
AI_PLANET_SIZE_TINY: string := "Tiny"
AI_PLANET_SIZE_SMALL: string := "Small"
AI_PLANET_SIZE_MEDIUM: string := "Medium"
AI_PLANET_SIZE_LARGE: string := "Large"
AI_PLANET_SIZE_HUGE: string := "Huge"
AI_PLANET_SIZE_RING: string := "Ringworld"
AI_PLANET_SIZE_SPHERE: string := "Sphereworld"
AI_PLANET_POP_TINY: long := 500
AI_PLANET_POP_SMALL: long := 1000
AI_PLANET_POP_MEDIUM: long := 2000
AI_PLANET_POP_LARGE: long := 4000
AI_PLANET_POP_HUGE: long := 8000
AI_PLANET_POP_RING: long := 32000
AI_PLANET_POP_SPHERE: long := 64000
AI_PLANET_POP_TINY_DOMED: long := 125
AI_PLANET_POP_SMALL_DOMED: long := 250
AI_PLANET_POP_MEDIUM_DOMED: long := 500
AI_PLANET_POP_LARGE_DOMED: long := 1000
AI_PLANET_POP_HUGE_DOMED: long := 2000
AI_PLANET_POP_RING_DOMED: long := 8000
AI_PLANET_POP_SPHERE_DOMED: long := 16000
If you use non-default population maximums, or there are any non-default planet sizes in your game, then you should adjust the above constants accordingly.
Then all I had to do was add the following function to whatever script file I wanted to call it from:
//------------------------------------------------------------------------
// Planet_Max_Population
//------------------------------------------------------------------------
function Planet_Max_Population returns long
params
planet_id: long
vars
planet_size: string
is_domed: boolean
planet_max_pop: long
begin
set planet_size := Sys_Get_Planet_Size(planet_id)
set is_domed := Is_Colony_Domed(planet_id)
set planet_max_pop := 0
if is_domed then
case planet_size
AI_PLANET_SIZE_TINY:
set planet_max_pop := AI_PLANET_POP_TINY_DOMED
AI_PLANET_SIZE_SMALL:
set planet_max_pop := AI_PLANET_POP_SMALL_DOMED
AI_PLANET_SIZE_MEDIUM:
set planet_max_pop := AI_PLANET_POP_MEDIUM_DOMED
AI_PLANET_SIZE_LARGE:
set planet_max_pop := AI_PLANET_POP_LARGE_DOMED
AI_PLANET_SIZE_HUGE:
set planet_max_pop := AI_PLANET_POP_HUGE_DOMED
AI_PLANET_SIZE_RING:
set planet_max_pop := AI_PLANET_POP_RING_DOMED
AI_PLANET_SIZE_SPHERE:
set planet_max_pop := AI_PLANET_POP_SPHERE_DOMED
endcase
else
case planet_size
AI_PLANET_SIZE_TINY:
set planet_max_pop := AI_PLANET_POP_TINY
AI_PLANET_SIZE_SMALL:
set planet_max_pop := AI_PLANET_POP_SMALL
AI_PLANET_SIZE_MEDIUM:
set planet_max_pop := AI_PLANET_POP_MEDIUM
AI_PLANET_SIZE_LARGE:
set planet_max_pop := AI_PLANET_POP_LARGE
AI_PLANET_SIZE_HUGE:
set planet_max_pop := AI_PLANET_POP_HUGE
AI_PLANET_SIZE_RING:
set planet_max_pop := AI_PLANET_POP_RING
AI_PLANET_SIZE_SPHERE:
set planet_max_pop := AI_PLANET_POP_SPHERE
endcase
endif
return planet_max_pop
end
If you have any non-default planet sizes in your game, then you should make a new case entry for them. Be sure to add one for domed and one for not, and don't forget to have updated your list of constants.
When you feed this function the ID of a planet you want to know the max population of, it spits back the approriate number. The function Is_Colony_Domed() is explained in a previous blog entry. Note that if a planet does not have a colony on it, Is_Colony_Domed() returns FALSE (un-domed).
I've attached a .txt file with the above code, as the formatting will be better in it.
Good hunting!
---Permission is granted to duplicate, whole or in part, and/or modify any of the code here for any purposes that does not violate Malfador Machination's intellectual property rights. Credit to the author of the specific code here is not required.---
| Fichier attaché | Taille |
|---|---|
| PlanetMaxPop.txt | 3.4 Ko |



