Each empire has a list of ship types to build for each agenda. Each list can contain up to 36 entries.
Valid agendas are (per the wording in trek.exe and checked indexes):
Normal Expansion (0)
Unopposed Expansion (1)
Normal Consolidation (2)
Defensive Consolidation (3)
Offensive Consolidation (4)
Cold War (5)
Defensive War (6)
Offensive War (7)
Jihad (8 )
The lists begin at 0x18A0C0 in trek.exe. The first one is for empire 0 (Cardassians) and agenda 0, next one is empire 0 agenda 1, and so on. All together the lists take up 12960 bytes.
Each entry contains ship type id (4 bytes (as read by botf - but only 2 bytes actually matter - botf shifts the bits) and another 4 bytes which have unknown function and are usually set to 0, but sometimes 1.
Let's say the AI is playing the Cardassians. At the begining their agenda is Normal expansion. One would expect Unopposed expansion, but that is not the case.
In vanilla trek.exe the first entries are:
Scout, Colony, Transport, Destroyer, Transporter, Destroyer, Colony, Transporter, Command Cruiser...
When the AI builds a ship it also runs through the list to pick the next ship type to build, the result is saved until the AI decides to build a ship. It then builds the one previously picked and picks the one for the next time again.
Now we start with a colony and a scout. AI goes through the list like this:
if the number of scouts < 1 build scout
else continue next item
if the number of colony ships < 1 build colony
else continue next item
if the number of transporters ships < 1 build transporter
else continue next item
if the number of destroyers < 1 build destroyer
else continue next item
if the number of transporters ships < 2 build transporter
else continue next item
and so on
So the first ship our Cardassians would build is a transporter.
When the next item is -1 (FFFF) or the end of the list is reached, the AI starts again from the begining of the list with the limits increased accordingly. So if the list contained only two Colony ships, a transporter and FFFF. The logic would look like this:
if the number of colony ships < 1 build colony
else continue next item
if the number of colony ships < 2 build colony
else continue next item
if the number of transporters ships < 1 build transporter
else continue next item
read FFFF (end of list) so start from begining
if the number of colony ships < 3 build colony
else continue next item
if the number of colony ships < 4 build colony
else continue next item
if the number of transporters ships < 2 build transporter
else continue next item
etc..
The forum keeps messing up the post so read on in next post...
How the AI decides what ship type to build
Moderator: thunderchero
How the AI decides what ship type to build
Last edited by DCER on Tue Feb 24, 2009 9:31 am, edited 1 time in total.
Now what if it encounters a ship type it can't build. Lets say the AI can't build the command cruiser and encounters it on the list. It will build a "lower level" equivalent and begin the list from the start (and not continue to next item). However unlike FFFF, it won't increase the limits. This means that if no ship is destroyed, the AI will keep building the lower equivalent until it can finally build the command cruiser and will then move on to the next item. The AI will normally not scrap it's surplus of ships unless it needs credits.
The "lower level" counter parts are (if ship type is unavailable move along the arrow):
Command Cruiser -> Cruiser -> Destroyer -> Scout -> skip
Strike Cruiser -> Cruiser -> Destroyer -> Scout -> skip
Colony -> skip
Transporter -> skip
This behaviour could be changed by modifying subroutine sub_40CB20.
Valid ship types are 0-5 and 9.
I couldn't figure out what the unknown value does if anything. Here's what it doesn't mean: stop here, new list start here, build more of this, skip this if not available
I couldn't discern any difference in AI behaviour when the unknown value is 0 or 1.
One fun thing you could do is to decide that one ship type not be available to any empire, you could use that to force the ai to build cruisers exclusively instead of making more colony ships etc. You would then have the number of colony ships etc. capped, while cruisers would not be limited in numbers. By modifying the relevant subroutine you could change the cruiser type to command cruiser and have those unlimited instead.
The "lower level" counter parts are (if ship type is unavailable move along the arrow):
Command Cruiser -> Cruiser -> Destroyer -> Scout -> skip
Strike Cruiser -> Cruiser -> Destroyer -> Scout -> skip
Colony -> skip
Transporter -> skip
This behaviour could be changed by modifying subroutine sub_40CB20.
Valid ship types are 0-5 and 9.
I couldn't figure out what the unknown value does if anything. Here's what it doesn't mean: stop here, new list start here, build more of this, skip this if not available
I couldn't discern any difference in AI behaviour when the unknown value is 0 or 1.
One fun thing you could do is to decide that one ship type not be available to any empire, you could use that to force the ai to build cruisers exclusively instead of making more colony ships etc. You would then have the number of colony ships etc. capped, while cruisers would not be limited in numbers. By modifying the relevant subroutine you could change the cruiser type to command cruiser and have those unlimited instead.
- thunderchero
- Site Administrator aka Fleet Admiral
- Posts: 6526
- Joined: Fri Apr 25, 2008 2:00 am
- Location: On a three month training mission, in command of the USS Valiant.
- Contact:
- Spocks-cuddly-tribble
- Code Master
- Posts: 873
- Joined: Sun Apr 27, 2008 2:00 am
Re: How the AI decides what ship type to build
Trying to understand more about the selection of the AI tasks lead me back to this great work by DCER.
"Lower Level" Ship Type Index Bug Fix
There's one more list following at 0x18D360 / asm-58F560 shared for all AI empires. It's used when potentially dangerous fleets (unfederated and not set to "evade") occupy ALL own systems with shipyards (i.e. if it's too late anyway).DCER wrote:The lists begin at 0x18A0C0 in trek.exe. The first one is for empire 0 (Cardassians) and agenda 0, next one is empire 0 agenda 1, and so on. All together the lists take up 12960 bytes.
The first entry with the second 4 bytes set to 1 marks the position to start read for list iterations. This means ship types set exclusively in entries above the marker limit the absolut number of those ship types.DCER wrote:Each entry contains ship type id (4 bytes (as read by botf - but only 2 bytes actually matter - botf shifts the bits) and another 4 bytes which have unknown function and are usually set to 0, but sometimes 1.
In fact it's just a simple bug wrt the internal ship type index values of unavailable i.e. replaced ship types. Means the AI still searchs for number of e.g. command ships and, since there are none, repeats building the lower level ships instead of reading the next entry.DCER wrote:Now what if it encounters a ship type it can't build. Lets say the AI can't build the command cruiser and encounters it on the list. It will build a "lower level" equivalent and begin the list from the start (and not continue to next item). However unlike FFFF, it won't increase the limits. This means that if no ship is destroyed, the AI will keep building the lower equivalent until it can finally build the command cruiser and will then move on to the next item.

Code: Select all
trek.exe at 0xBF59 change 89 C8 -> 8BFB
and at 0xC181 new code 0x44 bytes:
8B C7 90 C1 E0 02 BB 01 00 00 00 66 2B 1C 04 66 85 DB 7E 24 7E AB 31 D2 0F BF DB 89 14 04 8D 04 19 39 E8 77 41 8B C7 90 66 8B 7C 44 30 01 DF 01 D9 66 89 7C 44 30 EB 89 8B C7 90 83 3C 84 01 72 0B 8B C7 90
-asm code:
0040CB59 8BFB MOV EDI,EBX
at 0040CD81, 40CDA6, 0040CDB9 & 0040CDC2
8BC7 MOV EAX,EDI
90 NOP
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.