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 » Sat Jan 09, 2010 9:14 am

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: 723
Joined: Sun Apr 27, 2008 2:00 am

Post by Spocks-cuddly-tribble » Sun Jan 31, 2010 3:14 pm

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

Post Reply

Return to “Mandatory Starting Buildings (yard & refinery)”

Who is online

Users browsing this forum: No registered users