Editing Mandatory Starting Buildings

Mandatory Starting Buildings (yard & refinery); 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

Editing Mandatory Starting Buildings

Post by Gowron »

If you start a new BotF game, your home system will always have a shipyard and a dilithium refinery (with fixed IDs), even if these buildings are not present in the respective bldset file.


The following code piece of code is only executed if no shipyard has been found yet in your home system:

Code: Select all

:00451190 668B842460010000        mov ax, word[esp+00000160]    // load empire ID
:00451198 31DB                    xor ebx, ebx
:0045119A E8E594FEFF              call 0043A684                 // write corresponding shipyard ID to eax 
:0045119F 6689C3                  mov bx, ax                    // shipyard ID
:004511A2 89DA                    mov edx, ebx                  // shipyard ID
:004511A4 89C8                    mov eax, ecx
:004511A6 E8454CFFFF              call 00445DF0                 // read building ID from edx and add building (shipyard)
:004511AB 89DA                    mov edx, ebx                  // shipyard ID
:004511AD 89C8                    mov eax, ecx
Subroutine 43A684 has a very simple structure, so it's easy to find (and edit) the shipyard IDs.

Now that the game has made sure you have a shipyard, it's about time to power it up and do the same for the refinery:

Code: Select all

:004511AF E87C44FFFF              call 00445630                 // power up shipyard
:004511B4 8B8C2462010000          mov ecx, dword[esp+00000162]
:004511BB BA06000000              mov edx, 00000006             // Dilithium Refinery ID
:004511C0 C1F910                  sar ecx, 10
:004511C3 C7400401000000          mov dword[eax+04], 00000001
:004511CA 89C8                    mov eax, ecx
:004511CC E89F45FFFF              call 00445770                 // read building ID from edx and check...
:004511D1 85C0                    test eax, eax                 // ... if building is already present
:004511D3 750C                    jne 004511E1                  // skip refinery creation if refinery is already present
:004511D5 BA06000000              mov edx, 00000006             // Dilithium Refinery ID
:004511DA 89C8                    mov eax, ecx
:004511DC E80F4CFFFF              call 00445DF0                 // read building ID from edx and add building (refinery)
---------
:004511E1 8B842462010000          mov eax, dword[esp+00000162]
:004511E8 BA06000000              mov edx, 00000006             // Dilithium Refinery ID
:004511ED C1F810                  sar eax, 10
:004511F0 E83B44FFFF              call 00445630                 // power up refinery
:004511F5 C7400401000000          mov dword[eax+04], 00000001
As you can see, this looks pretty straightforward. But subroutine 445630 ("power up") seems to be a troublemaker here. During testing, it did not accept IDs of buildings that were not shipyards or refineries (i.e. the game crashed). What DID work was to use the same building IDs for both the shipyard and refinery power up passes, thus reducing the number of mandatory buildings from 2 to 1. In this case, the "power up" subroutine is executed twice for the same structure, but that did not cause any problems.

As an example, this is the altered code I'm using for the next BoP update. It allows empires to start without a mandatory dilithium refinery:

Code: Select all

:004511D1 668B842460010000        mov ax, word[esp+00000160]    // load empire ID
:004511D9 E8A694FEFF              call 0043A684                 // write corresponding shipyard ID to eax
:004511DE 89C2                    mov edx, eax                  // shipyard ID
:004511E0 90                      nop
:004511E1 8B842462010000          mov eax, dword[esp+00000162] 
:004511E8 9090909090              nop
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Post by Spocks-cuddly-tribble »

A short note: This part is only for player (home-)systems.

loc_4510CD pop assignation for manned buildings (e.g. at 450A70 for manned energy depending on starting level)


AI handling - for all AI starting systems (loc_ 4513E6..)

45146C jnz -> jmp = no dilithium refineries for additional AI starting systems (not recommended, since AI cannot use phantom dilithium)
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

extra Starting Systems without Special Buildings Fix (OBs only is a Bug)

Post by Spocks-cuddly-tribble »

Code: Select all

NAME: extra Starting Systems without Special Buildings Fix (OBs only is a Bug) - UPDATED
DESC: Auto-corrects bldset.bin (home & extra starting systems must possess planet & dil requirements).
AUTHOR: Spocks-cuddly-tribble
URL: https://www.armadafleetcommand.com/onscreen/botf/viewtopic.php?p=50803#p50803

>> 0x5043E 8B 84 24 50 01 00 00 80 78 30 00 0F 84 14 FE FF FF 31 C0 89 E2 66 8B 84 24 1E 01 00 00 E8 50 F4 FF FF 80 7C 24 73 00 0F 84 E6 01 00 00
<< 0x5043E 33 C0 8B D4 66 8B 84 24 1E 01 00 00 E8 61 F4 FF FF 8B 84 24 50 01 00 00 80 7C 24 73 02 0F 85 F0 01 00 00 80 78 30 00 0F 84 F8 FD FF FF
>> 0x50654 72 80 FB 12 0F 84 0D FE FF FF 80 FB 1F 0F 85 FC FB FF FF 8B 84 24 50 01 00 00 F6 40 71 08
<< 0x50654 71 80 FB 08 74 1E 8A CB BB 01 00 00 00 D3 E3 85 58 70 90 90 90 90 90 90 90 90 90 90 90 90
Update prevents eg. wrong Aquaculture Center, Wind Turbines & Charge Collectors, but not wrong one-per-empire buildings eg. Genesis Lab!

Note that the AI will greatly appreciate shipyards in bldset.bin for its extra starting systems! :wink:

Just ignore BotF-patcher conflict warning when overwriting outdated patches.

ASM notes:
► Show Spoiler


Extra Starting Systems with lower starting tech than Home Worlds
DOT wrote:only home system starting with highest possible tech level and the other starting systems with lower tech level to simulate a step by step expanding
viewtopic.php?f=114&t=629#p24351


Player starting systems use 1 level lower bldset.bin entry than the home system (unless lowest level). The AI invoked its certificate of disability...

Code: Select all

0x501A4 change (0x1E bytes) -> 8D B4 24 34 01 00 00 8B 5E 1C 6B 53 44 50 8B 06 85 C0 74 09 8B 5B 04 4B 29 1E 90 90 90


00450DA4   8DB424 34010000    LEA ESI, [ESP+134]         // adr starting level
00450DAB   8B5E 1C            MOV EBX, [ESI+1C]          // adr systInfo
00450DAE   6B53 44 50         IMUL EDX, [EBX+44], 0x50   // race Id * 80
00450DB2   8B06               MOV EAX, [ESI]             // starting level
00450DB4   85C0               TEST EAX, EAX
00450DB6   74 09              JE 450DC1                  // skip if level 0
00450DB8   8B5B 04            MOV EBX, [EBX+4]           // load system type value; 1-AI/ 2-Player
00450DBB   4B                 DEC EBX                    // system type -1      
00450DBC   291E               SUB [ESI], EBX             // starting level -1 for extra starting systems player
00450DBE   90 90 90           NOP
NOTE: Can't be combined with option #11.c 'Additional Starting Pop for AI' from 'AI & Difficulty Level':
viewtopic.php?f=216&t=1805#p24589

Only a small drawback IMHO. Also make sure you don't miss:

Tech 1-5 Starting Population for Extra Starting Systems (broken feature fix)
viewtopic.php?f=117&t=57#p402
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 “Mandatory Starting Buildings (yard & refinery)”