AI ship design scripting workshop 1. Crew and life support. |
It had occured to me early on in my mod that the AI builds ships really poorly. Particularly in regards to crew and life support requirements.
For those that are script-inclined, this is what I came up with. This works, and can be tweaked to whatever values you feel are right.
First: Script_AI_GlobalSettings.txt
In here you will notice, right at the top, a long series of call functions, to various lists. Let me break it down for you:
lst_AI_Vehicle_Sizes_Name: The name of the ship class. Frigate, Organic Cruiser, etc. This is a string, or set of letters.
lst_AI_Vehicle_Sizes_AI_Size_Class: Whether it is a ship, carrier, colonizer, etc.
lst_AI_Vehicle_Sizes_Num_Life_Support: How much Life Support to put on the ship, as expressed by the NUMBER OF COMPONENTS.
lst_AI_Vehicle_Sizes_Num_Crew_Quarters: How much Crew Quarters to put on the ship, as expressed by the NUMBER OF COMPONENTS.
lst_AI_Vehicle_Sizes_Num_Engines: How many engines to put on the ship, as expressed by the NUMBER OF COMPONENTS.
These are in sets, so...
call lst_AI_Vehicle_Sizes_Name.add(AI_VEHICLE_SIZE_FRIGATE)
call lst_AI_Vehicle_Sizes_AI_Size_Class.add(AI_VEHICLE_SIZE_CLASS_SHIP)
call lst_AI_Vehicle_Sizes_Num_Life_Support.add(1)
call lst_AI_Vehicle_Sizes_Num_Crew_Quarters.add(1)
call lst_AI_Vehicle_Sizes_Num_Engines.add(12)
All counts as one set. The next set starts with the next call lst_AI_Vehicle_Sizes_Name, in this case adding AI_VEHICLE_SIZE_ORGANIC_FRIGATE.
You should note that the scripting sees Life Support and Crew Quarters requirements differently than we do. We see a number we need to fill, in this case 50 for each, it sees a number of COMPONENTS to add. The ammount each component gives is irrelevant to the AI.
The task, then, is to make the number each component adds RELEVANT to the AI, which then lets the AI guage how many it actually needs to put on.
Lets begin...

Re: AI ship design scripting workshop 1. Crew and life support.
So what I gather from this is that the stock ai places life support/crew quarters on a ship without checking the level of tech the ai currently has. So unless the ai refranes from researching medical treatment or psychology the entire game, they will design ships with way more life support/crew quarters then is needed.
I don't want to be rude, but why wouldn't the game designer(s) think to implement such a check for ship design. This actually sounds like an easy exploit (simply make a trade treaty with an ai and only research psychology and medical treatment so the ai will design ships with unneeded bloat)
I don't know if it would be less coding if you were to only check the tech level and simply take the number of original components to be added then dividing that number by the tech level, then rounding up.
by changing the num_to_add = sys_Trunc((Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_LIFE_SUPPORT)/AI_TECH_AREA_MEDICAL_TREATMENT)+.99)
This would save you adding excess code and using a majority of the original code anyway. I haven't really doublechecked my numbers, but I am pretty sure my math should work out to the same result that you want.

Re: AI ship design scripting workshop 1. Crew and life support.
Well your way of doing makes more sense, especially if you need to go back and make some changes. Mine was just a simple way of using the stock game and making it insert the correct amount of components.
I am fairly technical, but I get a little confused when I start going through large amounts of code (I'm actually a hardware guy). I am looking into modding the game, but I get tired of reading too much code trying to find what I want.
Is there no function that is able to extract the actual capacity from the component properties?

Re: AI ship design scripting workshop 1. Crew and life support.
No. There are no script functions that return the ability amounts from components or facilities etc.
-----

Re: AI ship design scripting workshop 1. Crew and life support.
When we get to this part of the script, we would probably want to run a check first that looks to add a central computer core. Basically a quick check that would see if the number of life support and crew quarters is more than 3. If that were true it could then skip then set the #_add_life_support and #_add_crew_quarters = 0. I haven't looked at the script in a ton of detail, but you might be able to add this to the point where it adds the bridge (granted the bridge is added before the life support and crew quarters), using an if else statement.
Another thought occured to me as well, is it possible to remove components in the script? Is it possible to check the design "errors" that are listed when the human is designing a ship?

Re: AI ship design scripting workshop 1. Crew and life support.
Thats exactly what i was thinking (BTW, I'm at work as well, thats why I make horrible references to code that is currently in the txt files).
I do like the idea of setting different races to use a master computer exclusively instead of a crew. Of course addding a seperate parameter for other races that would use both would also be nice (50/50 split would be pretty good to start with).
I also have ideas about checking for tech levels of enemies when choosing components. I doubt that this is possible, but if it is possible to check for enemy tech estimates to put more emphasis on different components (favor pd over more firepower or shields over armour)
Since I doubt that is possible, creating a seperate script for each race that would add more flavour to the game. Making certian races beeline a tech line and using that tech line for ship design.
Re: AI ship design scripting workshop 1. Crew and life support.

Re: AI ship design scripting workshop 1. Crew and life support.
Its nice to know that there is a place for some percieved "adaptation" by the ai, but last night when I looked at that file, ouch, the work needed to make that even usable would be astronomical. I think I will just stick to playing the game right now and maybe make some small tweaks in the future when a more complete ai has been done.
Right now the ai work isn't so much improving the ai, but making a majority of the ai code functional. Then you would need to implement these changes, followed by improving them. In the amount of time it takes me to figure that out, I'm sure several patches will come out that would force me to scrap my changes.
Keep up the good work with your mods.

Re: AI ship design scripting workshop 1. Crew and life support.
With respect to CQs and LSs, I used a similar process as outlined above. For each ship size I noted the amount of crew required for it, and knowing the progression in crew amounts for CQs and LSs in the mod, do a simple division to figure out the number to add.
Making the AI adaptable is very difficult, especially with respect to player designs and tactics. It's a bit easier with deciding what colony types are needed or things of that sort.
-----





Re: AI ship design scripting workshop 1. Crew and life support.
The AI desings each ship in the Script_AI_DesignCreation.txt file. Scrolling down it you find an area that looks like this:
// b. Add Life Support (Multiple)
set comp_id := Sys_Get_Component_With_Name(sys_long_Player_ID, AI_COMPONENT_LIFE_SUPPORT)
if (comp_id > 0) then
set comp_enh_id := Sys_Get_Best_Comp_Enh_For_Component(sys_long_Player_ID, design_id, comp_id)
set num_to_add := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_LIFE_SUPPORT)
call Add_Components_To_Vehicle_Design(design_id, comp_id, comp_enh_id, SHIP_SECTION_INNER_HULL, num_to_add, FALSE)
else
set bool_continue_design := FALSE
endif
// c. Add Crew Quarters (Multiple)
set comp_id := Sys_Get_Component_With_Name(sys_long_Player_ID, AI_COMPONENT_CREW_QUARTERS)
if (comp_id > 0) then
set comp_enh_id := Sys_Get_Best_Comp_Enh_For_Component(sys_long_Player_ID, design_id, comp_id)
set num_to_add := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_CREW_QUARTERS)
call Add_Components_To_Vehicle_Design(design_id, comp_id, comp_enh_id, SHIP_SECTION_INNER_HULL, num_to_add, FALSE)
else
set bool_continue_design := FALSE
endif
This is where the AI adds life support and crew quarters to the design it is creating. Looking at this, you can start to make some sense of it. set comp_id lets the AI know what componenet we are working with. set num_to_add calls a separate script named Get_Number_Of_Components_To_Add. call Add_Components_To_Vehicle_Design tells the AI to add these components to this design.
Since we care about how many of these it is adding, we should look up Get_Number_Of_Components_To_Add. Fortunatly, it is here in the same file.
In it, you can see an area that looks like this:
case (comp_type)
AI_GEN_COMP_TYPE_LIFE_SUPPORT:
return lst_AI_Vehicle_Sizes_Num_Life_Support.Get(index)
AI_GEN_COMP_TYPE_CREW_QUARTERS:
return lst_AI_Vehicle_Sizes_Num_Crew_Quarters.Get(index)
AI_GEN_COMP_TYPE_ENGINE:
return lst_AI_Vehicle_Sizes_Num_Engines.Get(index)
AI_GEN_COMP_TYPE_SMALL_ENGINE:
return lst_AI_Vehicle_Sizes_Num_Engines.Get(index)
AI_GEN_COMP_TYPE_GROUND_MOVEMENT:
return lst_AI_Vehicle_Sizes_Num_Engines.Get(index)
endcase
This means that for each of these cases, look up the associated variable, and return it to whatever called it.
So, we set num_to_add := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_CREW_QUARTERS). This looks in Get_Number_Of_Components_To_Add passing it the design_id (the ship we are designing) and the componenet we are looking for (AI_GEN_COMP_TYPE_CREW_QUARTERS). Get_Number_Of_Components_To_Add hunts through its case list (we won't go over the mechanics here) until it finds AI_GEN_COMP_TYPE_CREW_QUARTERS.
This case says to return lst_AI_Vehicle_Sizes_Num_Crew_Quarters.Get(index). Index can be thought of the ship class for now, and is determined off of the design_id. This variable is defined in the previous example as 1. So, it returns the number 1 in to num_to_add, which is then used by Add_Components_To_Vehicle_Design(design_id, comp_id, comp_enh_id, SHIP_SECTION_INNER_HULL, num_to_add, FALSE) to determine how many to add to the design.