aibldreq.bin , AI building behaviour

AI building behaviour (aibldreq.bin); support/discussion/questions

Moderator: thunderchero

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

aibldreq.bin , AI building behaviour

Post by Gowron »

Originally this was a reply to a very old topic where Joker had raised the question how the aibldreq.bin file worked.

--------------------------------------------------------------------
--------------------------------------------------------------------


I know I'm not topping the newest thread here, but "just because something's old doesn't mean you throw it away." (Geordi, "Relics") ;)


This file contains "AI Building Requirements" (hence the name). To prevent the AI from building a covert sensor array in that tiny pop 60 system that just can't make use of it, this file contains some minimum values that a system must provide for each building, before the AI can build it in that system.


In aibldreq.bin there are 77 data groups, each group contains the data for one building. Some buildings are left out (see below). Each group consists of 6 integer values (4 bytes per value), some of them are signed (see below).


1st value (not signed):
Building ID.
The file contains every building with an ID of 0x57 or less, except for shipyards and emergency morale programs. It does contain "Trade Goods".


2nd value (not signed):
Current population that the system must have before the AI can build the building there.


3rd value (not signed):
Maximum population that the system must provide before the AI can build the building there. Planets that have yet to be terraformed are not counted in.


4th value (signed):
Required enery for the building (quite obvious if you look at the values in the file). The AI is able to ignore this value, at least sometimes. At least 2 buildings don't have the correct value by default (Phoenix Facility and Obsidian Order).


5th value (signed):
Unknown.
If the value is set to +100 or less, the AI seems to be able to build the building everywhere (unless another restriction is not fulfilled, of course). If it's set to +101 or more, the building is not built at all.


6th value (signed):
Unknown.
This value does not seem to be used at all. By default, it's +1 for the labor camp, +2 for the forced labor farm and -10 for any other building. I gradually increased this value up to +1280 and also tried changing it to -256, with no effect at all.



As a "side effect" of the tests, I gained some insight into the building behaviour of the AI:
  • The AI will rush-buy most buildings. On the other hand systems will often just sit there producing nothing.
  • The AI ignores the "once per empire" restriction, instead the restriction is treated as "once per system". Thus, it can (and will) build multiple Great Halls or Genesis Labs, for example. And all of the buildings will have their full effects. To work around this, you could either restrict certain buildings to "home system only", or, if you're playing tech 5 and the respective building is already present in the AI player's home system, then you can use one of the two population-related values in aibldreq.bin and set it high enough that it can't be reached by any system.
  • The AI can build Isolinear Scanners without having to build Subspace Scanners or Listening Posts first.
  • Among the buildings that are available for a system (and included in aibldreq.bin), the AI will build the building with the lowest ID first, working its way down the list. When the ID 0x12 (trade goods) is reached, the system will explicitly build "trade goods" for one turn, then move on the next building. Other buildings (ID > 0x57) and shipyards can be built in-between when needed, also sometimes a system will just "have a break" and do nothing for one or more turns.
  • However, the AI will not build an Orbital Battery when it "reaches" the corresponding ID, instead the OB will just be ignored. The AI will, instead, build one OB per 50 millions of population (rounded down).
User avatar
DCER
Code Master
Code Master
Posts: 683
Joined: Sat Apr 26, 2008 2:00 am

Post by DCER »

Just to add some info...

Exactly 7 buildings have energy requirement set in aibldreq.bin that is different from the one in edifice.bst

Those are:

Phoenix Facility (10/30)
Trade Center (10/20)
Obsidian Order (200/300)
Harvesting Complex (10/50)
Research Think Tank (250/200)
Research Committee (100/130)
Science Academy (150/170)
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

aibldreq.bin (24 bytes per row / building)

Post by Spocks-cuddly-tribble »

The values 4 (required energy) and 6 (morale penalty marker?) are NOT used.


5th value = required % of the systems maximum population

Unterraformed planets do not count (cf. value 3), thus terraforming temporarily lowers the percentage.


Gowron wrote:The file contains every building with an ID of 0x57 or less, except for shipyards and emergency morale programs.
Looking at the code, the AI wants to build more shipyards (and ships) but missing entries in aibldreq.bin prevent this, except for special codes.

I just did a quick test with promising result (vanilla T8, ferengi AI, 30 turns unmodded vs. 30 turns yard entry in aibldreq.bin).
They built the yards and ships, many ships.... :wink:

Shipyards in aibldreq.bin also could be a key factor for AI expansion on larger maps, strategic base placement checks only medium range for opponents.

NOTE: Special codes for yard placement (if none within 3 sectors) can ignore aibldreq.bin and other requirements (like planet-types or dilithium).


Gowron wrote:the AI will not build an Orbital Battery when it "reaches" the corresponding ID, instead the OB will just be ignored. The AI will, instead, build one OB per 50 millions of population (rounded down).
Corresponding pop checks:

Code: Select all

 -> power up limit (danger check)
0040AF37                 cmp     edx, 32h
0040AF44                 mov     ebx, 32h

-> build limit
0040BB63                 cmp     edx, 32h
0040BB7A                 mov     eax, 32h
Last edited by Spocks-cuddly-tribble on Tue Jun 21, 2022 12:07 pm, edited 2 times in total.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Re: aibldreq.bin , AI building behaviour

Post by Peter1981 »

Thanks SCT -- the seems to be no limits to your hard work. Ive just added the shipyards to AIbldreq.bin and seems to work great. I used the following:-

Code: Select all

0f 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
15 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
34 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
36 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
37 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
57 00 00 00  32 00 00 00  64 00 00 00  19 00 00 00  14 00 00 00  f6 ff ff ff
As you can see the values I chose were
  • pop. req. = 50
    max. pop. req. = 100
    energy req. = 25
    % pop. req. = 20
:arrow: did you use similar values?
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: aibldreq.bin , AI building behaviour

Post by Spocks-cuddly-tribble »

Yes, this works. But note that the minor race shipyard makes no sense in aibldreq.bin, the same goes for modifying the energy values (unused, just ignore them).
Peter1981 wrote: :arrow: did you use similar values?
All values =1 for testing purpose to enable the AI to build shipyards earlier on new colonies for faster exploration & expansion (could be too fast for small maps). One could also try race specific values e.g. higher for xenophobic races.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

AI multiple One-per-Empire buildings fix & unpowered OBs fix

Post by Spocks-cuddly-tribble »

Gowron wrote: Thu May 01, 2008 4:57 pmThe AI ignores the "once per empire" restriction, instead the restriction is treated as "once per system". Thus, it can (and will) build multiple...

Code: Select all

NAME: AI multiple One-per-Empire buildings fix
DESC: Skips also output types trade goods & emergency morale program, in case they are mistakenly in aibldreq.bin.
AUTHOR: Spocks-cuddly-tribble
URL: https://www.armadafleetcommand.com/onscreen/botf/viewtopic.php?p=54784#p54784

>> 0xB2BF 24 66 8B 4E 08 66 83 F9 20 0F 83 98 00 00 00 B8 01 00 00 00 D3 E0 89 C1 23 4C 24 68 83 F9 01
<< 0xB2BF 12 8A 46 08 8B D1 E8 B6 FB 02 00 85 C0 0F 85 F9 FA FF FF 80 7C 24 72 04 74 05 80 7C 24 72 24

# 40BEBE   74 12           JE SHORT 40BED2      // skip One-per-empire check
# 40BEC0   8A46 08         MOV AL,[ESI+8]       // empire ID
# 40BEC3   8BD1            MOV EDX,ECX          // building ID
# 40BEC5   E8 B6FB0200     CALL 43BA80          // check_one_per_empire_buildings_eax1_there
# 40BECA   85C0            TEST EAX,EAX
# 40BECC  ^0F85 F9FAFFFF   JNZ 40B9CB           // skip is there
# 40BED2   807C24 72 04    CMP BYTE [ESP+72],4  // skip trade goods output type (AI placeholder building bug)
# 40BED7   74 05           JE SHORT 40BEDE
# 40BED9   807C24 72 24    CMP BYTE [ESP+72],24 // skip emergency morale program output type

Note in vanilla the bonus type 1F dilithium is blocked except for refineries (i.e. AI cannot build Singularity Plant or Mining Prison).

To skip buildings with negative morale penalties:

CMP word [ESP+82], 0 // extra morale
jl 40B9CB // skip


The AI Task (B) 'Build Wonder' was meant to handle one-per-empire structures. Here is how to disable it's unfinished code (might reduce unneeded AI calculations & building conflicts?):

Code: Select all

>> 0xD1E2 E8 09 F9 FF FF
<< 0xD1E2 90 90 90 90 90

# 40DDE2 call sub_40D6F0 AITaskB_Build_Wonder_special -> remove/nop

Code: Select all

NAME: AI power up all/more OBs when systems in danger (fix)
DESC: Works for vanilla default OBs on higher starting levels, but not always for acquired minors with excessive OBs.
AUTHOR: Spocks-cuddly-tribble
URL: https://www.armadafleetcommand.com/onscreen/botf/viewtopic.php?p=54784#p54784

>> 0xA339 32
<< 0xA339 0A
>> 0xA345 32
<< 0xA345 0A

# 40AF37                 cmp     edx, 32h        ; -> 0A (10dec)
# 40AF44                 mov     ebx, 32h        ; -> 0A (10dec)
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
Post Reply

Return to “AI building behaviour (aibldreq.bin)”