How the AI decides what ship type to build

How the AI decides what ship type to build; support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

How the AI decides what ship type to build

Post by DCER » Tue Feb 24, 2009 9:24 am

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...
Last edited by DCER on Tue Feb 24, 2009 9:31 am, edited 1 time in total.

User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER » Tue Feb 24, 2009 9:30 am

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.

Dr_Breen
Commodore
Commodore
Posts: 889
Joined: Wed Apr 30, 2008 2:00 am
Location: Zurich, Switzerland
Contact:

Post by Dr_Breen » Thu Feb 26, 2009 6:35 am

so we can get the AI to build less TT's (i once met an AI fleet of 112 TT's and i destroyed them all witha cloaked battleship)
of course TT's are needed but not that many of them, it should rather build a few more battleships
Public BotF / EF2 Teamspeak 3 Server: 83.169.13.55

User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER » Thu Feb 26, 2009 6:47 am

Yes, you could. Download latest dev version of UE, it'll allow editing these lists when you open trek.exe

User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron » Sat Mar 07, 2009 9:13 pm

This looks very interesting.
Many thanks, DCER :)
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.

User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 5831
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.
Contact:

Post by thunderchero » Thu Mar 12, 2009 10:42 am

Weirdness wrote:A question are slots 6-8 used for things like outposts, starbases, alien, minors?
ship types
0=scout
1=destroyer
2=cruiser
3=strike
4=command
5=colony
6=outpost
7=starbase
8=alien
9=troop

this was by memory but think it is right :wink:

thunderchero

User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 703
Joined: Sun Apr 27, 2008 2:00 am

Re: How the AI decides what ship type to build

Post by Spocks-cuddly-tribble » Sun Mar 11, 2012 7:20 am

Trying to understand more about the selection of the AI tasks lead me back to this great work by DCER.

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


:arrow: "Lower Level" Ship Type Index Bug Fix

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
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

Post Reply

Return to “How the AI decides what ship type to build”

Who is online

Users browsing this forum: No registered users and 1 guest