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: 755
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)
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: 755
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 » Thu Dec 05, 2019 3:24 pm

Code: Select all

0x50464 change 00 0F 84 -> 02 0F 85

0x50654 change 72 80 FB 12 -> 70 80 FB 00

0x5065E change (9bytes) 80 FB 1F 0F 85 FC FB FF FF -> 80 7C 24 71 0B 75 13 90 90


-asm:
00451060            cmp     byte ptr [esp+73h], 0  -> 2   // if one per empire...
00451065            jz      loc_451251             -> jnz // ... skip

00451251            mov     bl, [esp+72h]      -> esp+70h // if home system...
00451255            cmp     bl, 12h            -> 0       // ... requirement skip

0045125E   807C24 71 0B   CMP BYTE [ESP+71], 0B // if no dilithium requirement...
00451263   75 13          JNZ SHORT 451278      // ... skip dilithium check
00451265   90 90          NOP
Note that the AI will greatly appreciate shipyards in bldset.bin for its extra starting systems! :wink:



Auto-correct bldset.bin OPTION (extra systems must possess all building requirements)

Code: Select all

0x50464 change 00 0F 84 -> 02 0F 85

0x50651 change (0x1C bytes) to -> 0F B7 84 24 64 01 00 00 E8 02 2C 0A 00 85 C0 0F 85 FD FB FF FF E9 00 FE FF FF 90 90 90

0xF327D change A0 2A 2B 5A 00 -> 66 8B 45 4C 90

-asm-- Additions:
00451251   0FB78424 64010000   MOVZX EAX,[ESP+164]  // system ID
00451259   E8 022C0A00         CALL 4F3E60          // Building Restrictions Player
0045125E   85C0                TEST EAX,EAX
00451260  ^0F85 FDFBFFFF       JNZ 00450E63         // OK add Building
00451266  ^E9 00FEFFFF         JMP 0045106B         // not OK skip
0045126B   90 90 90            NOP

sub_4F3E60 Building Restrictions Player -> share with AI fix

004F3E7D   66:8B45 4C      MOV AX,WORD[EBP+4C]  // owner race Id 
004F3E81   90              NOP
Application example: In BotF 1.0.2 for the romulan starting levels 3+ the 'Aquaculture Center' could be added to the bldset.bin entries without worrying about system restrictions of the extra systems. Note that the home systems themselfes still remain uncontrolled!




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)”

Who is online

Users browsing this forum: No registered users