Home Crush your enemies... and create an EMPIRE!!! Space Empires V -- BUY NOW!!!

User login

  • Create new account
  • Request new password

Navigation

  • news
    • archive
    • blogs
    • books
    • forums
    • recent posts
    • groups
  • image galleries
  • projects & downloads
  • search
  • create content
  • news aggregator

Search

Who's online

There are currently 1 user and 172 guests online.

Online users

  • GambitUK

Languages

  • English English
  • French French

Browse archives

« September 2008  
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Home » news » forums » Support & Feedback » Scenarios & Mods » SE:V MODs

AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Thu, 2007-05-03 12:46. SE:V MODs

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...

‹ Possible to restrict mounts to a range of kT? Slowing down game ›
» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Thu, 2007-05-03 12:56.

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.

» login or register to post comments
Mod Designer

Start changing things.

Submitted by Gideon on Thu, 2007-05-03 13:03.

Okay, so we know in rough terms how the AI knows how many components to add. Here is where the fun begins...

We want the AI to add a number of Crew Quarters and Life Support components based on the actual requirements of the design, and to adjust the ammount it adds based on the components' ability to meet those requirements (each component adds more points as its level goes up).

So...the AI first needs to know how many points it is going to require. This is the easiest change. Go in to Script_AI_GlobalSettings.txt, and start changing the number values in the lst_AI_Vehicle_Sizes_Num_Life_Support and lst_AI_Vehicle_Sizes_Num_Crew_Quarters lines. These values need to match what is required on the actual vehicle design, so Frigate becomes 50 each, while Organic Light Cruiser becomes 100 each. You can look these values up in the VehicleSizes.txt file in the SE5\Data directory.

Now, our frigate looks like:

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(50)
call lst_AI_Vehicle_Sizes_Num_Crew_Quarters.add(50)
call lst_AI_Vehicle_Sizes_Num_Engines.add(12)

Of course, this means that the AI will add 50 life support COMPONENTS and 50 crew quarters COMPONENTS. Not QUITE what we want here. Eye-wink

Next, we tell the AI how to determine how many it actually needs...

» login or register to post comments
Mod Designer

Changing the other half...

Submitted by Gideon on Thu, 2007-05-03 13:24.

So, the AI now knows how much it needs. Unfortunatly, it doesn't really understand that, and so is going to add a LOT more than it needs. We need the AI to be smarter about this.

Head back in to your Script_AI_DesignCreation.txt file, and go back down to where it says something like:

// 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...

I'm going to add it here, because I'm basically lazy. You could add it to the Get_Number_Of_Components_To_Add function if you wished, and that might make for cleaner code.

We will deal with Life Support first.

There is no way, that I know of, to look at the level of component the AI has. We just can't ask it "what is the highest level of X component you have". We CAN, however, ask it what its tech levels are. Since component level is directly related to tech levels, this is the next best thing.

By the way, I will be adding a bunch of variabls here. You need to declare new variables in each function you add them to (unless they are global, but that's not important for this example). Here are the variables I'm adding:

tech_id: long
tech_level: long
comp_level: long
comp_capacity: long
cap_requirement: long

I'll explain each of these as we go.

First, I add:

set tech_id := Sys_Get_Tech_ID(AI_TECH_AREA_MEDICAL_TREATMENT)
This gets us the tech_id (an internal number the AI uses) of the Medical Treatment tech, which governs Life Support (amung other things).

Now:
set tech_level := Sys_Get_Empire_Research_Tech_Level(sys_long_Player_ID, tech_id)
This tells us what level the current player (sys_long_Player_ID) has in a given tech (tech_id) as defined right above here.

Next:
set comp_level := Sys_Min_Long(tech_level, 6)
This tells us what level the component in question is. Literally, it says comp_level is set to tech_level (determined above) or the number 6, whichever is LESS. This is important, because Medical Treatment tech goes beyond level 6, but the Life Support component does not. So, if Medical Treatment is more than six, this lets the game "top out" the level of the Life Support component AT 6.

Next:

set comp_capacity := 100 + ((comp_level - 1) * 20)
This tells us the capacity for the component we are figuring out. This formula is taken directly from the Components.txt file, under the Life Support component. In that file it looks like this: 100 + (([%Level%] - 1) * 20)

Now, the AI knows what capacity its Life Support components have, based on the level of its life support components. Next comes determining how many we need. I use the following line:
set cap_requirement := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_LIFE_SUPPORT)
in place of:
set num_to_add := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_LIFE_SUPPORT)
as the Get_Number_Of_Components_To_Add function now just tells us the ammount of Life Support required, not the number of components (it's 50 for the frigate now).
Finally I use:
set num_to_add := Sys_Trunc((cap_requirement / comp_capacity) + 0.99)
To determine how many we need. This reads as: num_to_add is set to cap_requirement (how much we need) divided by comp_capacity (how much each component provides), plus 0.99, and then truncated.

Sys_Trunc cuts off all numbers after the decimal place, so 1.436246 becomes 1. However, if our component capacity is more than we require (100 life support, with frigate only needing 50) this creates a problem. The number added becomes 100 / 50, or 0.5, truncated to 0. So, we add 0.99 before we truncate (this is the equivilant of saying "round your result up". 0.5 becomes 1.49, which is then truncated to 1. This is important, because if the ship requires 1.436246 components, that means it needs MORE THAN ONE to fill its requirements. So, adding 0.99 makes this 2.426246, which is truncated to 2, which makes minimum requirements.

» login or register to post comments
Mod Designer

Final result...

Submitted by Gideon on Thu, 2007-05-03 13:29.

The final result of our work in Script_AI_DesignCreation.txt changes 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

To 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 tech_id := Sys_Get_Tech_ID(AI_TECH_AREA_MEDICAL_TREATMENT)
set tech_level := Sys_Get_Empire_Research_Tech_Level(sys_long_Player_ID, tech_id)
set comp_level := Sys_Min_Long(tech_level, 6)
set comp_capacity := 100 + ((comp_level - 1) * 20)
set cap_requirement := Get_Number_Of_Components_To_Add(design_id, AI_GEN_COMP_TYPE_LIFE_SUPPORT)
set num_to_add := Sys_Trunc((cap_requirement / comp_capacity) + 0.99)
set comp_enh_id := Sys_Get_Best_Comp_Enh_For_Component(sys_long_Player_ID, design_id, comp_id)
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 same method can be applied to Crew Quarters to achieve the same result. Just make sure you look up the right tech_id (AI_TECH_AREA_PSYCHOLOGY), you limit your component levels correctly (Sys_Min_Long(tech_level, 10)) and you use the correct formula from the Components.txt file (50 + ((comp_level - 1) * 50)).

Using the trick to look up a tech level, and then calculating the ability of a component based off of that level, can be used in several ways. I encourage you to experiment with it. For instance, I use it in a script for medical ships, to make them check their ability to cure a plague, before going off and attempting to cure it.

Good luck, and I hope this helped.

» login or register to post comments
largedarryl's picture

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by largedarryl on Thu, 2007-05-10 09:28.

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.

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Thu, 2007-05-10 14:54.

What you gather is correct. The stock AI wastes a lot of space on crew and life support late in the game.

Other things I've done, for instance, is specify that some races use Master Computers instead of Bridge/Crew/Life Support. Stock AI makes NO use of Master Computers at all, making the Computer Virus component effectivly pointless vs the AI.

I broke it down the way I did, to make it easier to "see" how the code works, and to make it a bit more flexible for me (though the actual code I used is a bit more efficient and in a different function). This way, I can more easily define new crew and life support requirements, expand or contract tech levels, etc.

I use different requirements for crew and life support than the stock game, and have expanded the life support componenet to all 49 levels of medical treatment with a different progression per level. I am also planning to expand crew quarters with the use of a new tech tree.

» login or register to post comments
largedarryl's picture

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by largedarryl on Thu, 2007-05-10 16:17.

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?

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Captain Kwok on Thu, 2007-05-10 21:11.

No. There are no script functions that return the ability amounts from components or facilities etc.

-----

Space Empires Depot | SE:V Balance Mod

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Thu, 2007-05-10 22:41.

Captain Kwok wrote:
No. There are no script functions that return the ability amounts from components or facilities etc.

-----

Space Empires Depot | SE:V Balance Mod

Boy, but that would make all our lives just that much easier.

» login or register to post comments
largedarryl's picture

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by largedarryl on Mon, 2007-05-14 13:26.

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?

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Mon, 2007-05-14 14:45.

largedarryl wrote:
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?

Here is what I did:

(BTW, I am at work, so I don't have my script in front of me to check, so this is a rough outline).

First, I added a global variable as to whether the AI uses Master Computers or not.

I set that AI to TRUE for the specific races that I want to use the Master Computer. I did this so that there is some difference between the feel of the races. Some use Automated ships, some use live crew. Knowing your enemy lets you decide between Toxic Injectors or Computer Viruses. I could also make whether each race uses the MC random at AI start, but for now its just set.

Then, I did a simple if then statement at the beginning of required components. Basically:

set comp_id := Master_Computer
If bool_Race_Uses_Master_Computer and (comp_id > 0) then
---Add the master computer component
else
---Add the Bridge/Life Support/Crew Quarters
endif

As for your second question, I don't think its possible to check for design errors. The game will not allow for the creation of the design if it violates the rules (AI cannot make ships without a Bridge or MC, for instance) but the scripting doesn't check for the presence or absence of those errors.

» login or register to post comments
largedarryl's picture

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by largedarryl on Mon, 2007-05-14 14:56.

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.

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Fyron on Mon, 2007-05-14 20:39.

Plan to post the results on the Wiki?


SpaceEmpires.net | Space Empires Wiki

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Tue, 2007-05-15 13:44.

largedarryl wrote:
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.

There is a minister called Enemy Analysis. Browsing throug the script files, you will find one dealing with Enemy Analysis. This script file is essentially empty. Theroetically this is where the AI functions to analyze enemy ship designs, tech, defenses, politics, Intel, general behaviour, etc would be located. These scripts, in turn, would be tied back in to the design, intel, politics, and construction scripts, creating a feedback loop between analysis, adaptation, and implementation.

Perhaps this is something that will be done in a patch some day, or perhaps this is an area where modders will have to contribute. Right now, I've got a LOT of fish to fry within the current scripting. I'm not even going to approach this section of the AI for a long time, if ever.

» login or register to post comments
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Gideon on Tue, 2007-05-15 13:44.

Fyron wrote:
Plan to post the results on the Wiki?


SpaceEmpires.net | Space Empires Wiki

Makes a note to go by the Wiki and figure out how to post in it...

» login or register to post comments
largedarryl's picture

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by largedarryl on Tue, 2007-05-15 16:13.

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.

» login or register to post comments
Captain Kwok's picture
Mod Designer

Re: AI ship design scripting workshop 1. Crew and life support.

Submitted by Captain Kwok on Tue, 2007-05-15 18:25.

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.

-----

Space Empires Depot | SE:V Balance Mod

» login or register to post comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Now on STEAM

Now on STEAM!Space Empires V via STEAMSpace Empires IV via STEAMSTEAM online by Valve Corporation

Popular content

Today's:

  • Ship Capture Issues
  • Space Empires V
  • Hows the current AI?
  • Space Empires V and VI: Expansions and the Future: Tell the Company What's on Your Wish List
  • SE5 Multimedia Pack

All time:

  • Space Empires V and VI: Expansions and the Future: Tell the Company What's on Your Wish List
  • Space Empires V
  • Gritty Galaxy Fleet Clash
  • Damn Dirty Bugs/Annoyances
  • Space Empires V: General Thoughts, Observations, and Suggestions

Last viewed:

  • Give ships to AI empire does not work
  • Bombardment Weaponss Whats the point???
  • Underground Satellites!
  • SE5_20060929-36.jpg
  • System Specs
(c) Strategy First, Inc. All rights reserved.