Domed colonies in the AI script (or "Is there air?!? You don't know!") |
A while back I found that I needed to detect whether a colony is domed. After sifting through the docs for a while, I realized that there is no way to directly check this. The function Sys_Is_Planet_Breathable() checks the planet against your Empire's primary race, but doesn't take in to account whether a colony is actually domed.
I created a script function that has since served me very well in many other script files. I thought I would post it here in case anyone wants to use or modify it themselves. I've also attached a .txt file with this information, as it might be hard to read here due to formatting.
First, I put this in the Script_AI_GlobalConstants_General.txt file:
AI_ATMOSPHERE_TYPE_NONE: string := "None"
AI_ATMOSPHERE_TYPE_OXYGEN: string := "Oxygen"
AI_ATMOSPHERE_TYPE_METHANE: string := "Methane"
AI_ATMOSPHERE_TYPE_HYDROGEN: string := "Hydrogen"
AI_ATMOSPHERE_TYPE_CARBON_DIOXIDE: string := "Carbon Dioxide"
AI_ATMOSPHERE_NUMBER_NONE: long := 1
AI_ATMOSPHERE_NUMBER_OXYGEN: long := 2
AI_ATMOSPHERE_NUMBER_METHANE: long := 3
AI_ATMOSPHERE_NUMBER_HYDROGEN: long := 4
AI_ATMOSPHERE_NUMBER_CARBON_DIOXIDE: long := 5
Next, I made the following function, which can be placed in other Script_AI files:
//------------------------------------------------------------------------
// Is_Colony_Domed
//------------------------------------------------------------------------
function Is_Colony_Domed returns boolean
params
planet_id: long
vars
is_domed: boolean
cargo_item_count: long
cargo_index: long
cargo_item_id: long
cargo_item_type: long
planet_atmosphere: long
population_atmo: string
atmosphere_number: long
begin
set is_domed := FALSE
set cargo_item_count := Sys_Get_Space_Object_Cargo_Item_Count(planet_id)
set planet_atmosphere := Sys_Get_Planet_Atmosphere_Type(planet_id)
if (cargo_item_count > 0) and (Sys_Get_Space_Object_Cargo_Item_Type_Count(planet_id, CARGO_ITEM_TYPE_POPULATION, "") > 0) then
set cargo_index := 0
loop
set cargo_index := cargo_index + 1
set cargo_item_id := Sys_Get_Space_Object_Cargo_Item_ID(planet_id, cargo_index)
set cargo_item_type := Sys_Get_Space_Object_Cargo_Item_Type(planet_id, cargo_item_id)
if (cargo_item_type = CARGO_ITEM_TYPE_POPULATION) then
set population_atmo := Sys_Get_Space_Object_Cargo_Item_Population_Atmosphere_Breathed(planet_id,cargo_item_id)
case population_atmo
AI_ATMOSPHERE_TYPE_NONE:
set atmosphere_number := AI_ATMOSPHERE_NUMBER_NONE
AI_ATMOSPHERE_TYPE_OXYGEN:
set atmosphere_number := AI_ATMOSPHERE_NUMBER_OXYGEN
AI_ATMOSPHERE_TYPE_METHANE:
set atmosphere_number := AI_ATMOSPHERE_NUMBER_METHANE
AI_ATMOSPHERE_TYPE_HYDROGEN:
set atmosphere_number := AI_ATMOSPHERE_NUMBER_HYDROGEN
AI_ATMOSPHERE_TYPE_CARBON_DIOXIDE:
set atmosphere_number := AI_ATMOSPHERE_NUMBER_CARBON_DIOXIDE
endcase
else
set atmosphere_number := 0
endif
if (atmosphere_number <> planet_atmosphere) and (atmosphere_number > 0) then
set is_domed := TRUE
endif
exitwhen (cargo_index >= cargo_item_count) or is_domed
endloop
endif
return is_domed
end
This goes through all the population on a planet, and checks what they breathe against the planet's atmosphere. If any one of the population does not breathe the planet's atmosphere, it returns TRUE. Otherwise, it returns FALSE.
Hope this helps.
EDIT: It should also be noted that if the planet has no population (no colony) then it returns FALSE (un-domed).
---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.---
| Attachment | Size |
|---|---|
| Is_Colony_Domed.txt | 2.94 KB |

Re: Domed colonies in the AI script (or "Is there air?!? You do
There's actually a built-in script function added in the latest patch, Sys_Is_Planet_Domed, that returns whether or not a planet is domed.




Re: Domed colonies in the AI script (or "Is there air?!? You do
This is exactly something I'll need if I'm to work on making the Pop Transport minister less brain-dead.
I find myself torn over doing this, because I am on a budget for home computer time (my wife wants some of my attention, heh) and I code all day at work. Perhaps you would be interested in turning the algorithm I worked out while waiting for compiles at work, into working code? I posted my thoughts in the main forum, including the algorithm outline. One of the big problems I can see is that I'll need to know a lot more about the system-supplied functions to be able to answer exactly the sort of question you have here.