1. Number of Planets
At the start of a new game, after stars have been generated, subroutine 4B4F70 is called - time for adding some planets
After a relatively uninteresting climate probability check, we enter a loop (for each star system):
Code: Select all
Offset hex code asm code
:004B5033 8BB4244C010000 mov esi, dword[esp+0000014C] // load current star system ID
:004B503A 8B1DC8365A00 mov ebx, dword[005A36C8]
:004B5040 01F3 add ebx, esi
:004B5042 668B4B44 mov cx, word[ebx+44] // determine controlling race (-1=none, 0=Card, 1=Fedr, 2=Ferg ...)
:004B5046 6685C9 test cx, cx
:004B5049 0F8CEB000000 jl 004B513A
Code: Select all
Offset hex code asm code
:004B513A 6800004040 push 40400000 // 3.0 (maybe a seed)
:004B513F E87C300500 call 005081C0 // generate a random value
:004B5144 E88B850600 call 0051D6D4 // round to integer
:004B5149 DB9C2450010000 fistp dword[esp+00000150] // store as integer
:004B5150 8B842450010000 mov eax, dword[esp+00000150]
:004B5157 668984245C010000 mov word[esp+0000015C], ax
:004B515F 8B94245A010000 mov edx, dword[esp+0000015A]
:004B5166 C1FA10 sar edx, 10
:004B5169 BE07000000 mov esi, 00000007 // [esi] = 7
:004B516E 89D0 mov eax, edx
:004B5170 C1FA1F sar edx, 1F
:004B5173 F7FE idiv esi // divide previously generated random integer value by [esi], store integer quotient in [eax] and remainder (between 0 and 6) in [edx]
:004B5175 8D4201 lea eax, dword[edx+01] // [eax] = [edx] + 1 (result is between 1 and 7)
:004B5178 E9FEFEFFFF jmp 004B507B
Code: Select all
:004B5175 8D4201 lea eax, dword[edx+01]
Code: Select all
:004B5175 8D4209 lea eax, dword[edx+09]
Note that clicking into a system with 10 (or more) planets will crash the game. However, for testing purpose it is possible to create a galaxy with some systems containing 10 planets and hover the mouse cursor over every star to view the number of planets, thus avoiding accidentially entering a system with 10 planets.
11 or more planets in a system reliably meant a CTD during testing.
2. Population Limits
The lower/upper limits of 80 and 400 are stored as 0x320 (= 800) and 0xFA0 (= 4000), respectively. This is why they were so hard to find. But now they're available, and even better, there are three different subroutines that do the work: subroutine 4B47B0 for free systems, subroutine 4B49C0 for minor race systems, and subroutine 4B4C20 for additional major empire starting systems. This is great, since it means these three types of systems can be modified separately
The game adds planets one by one until either the random number (see section 1) has been reached or the population capacity exceeds the upper limit (400 by default).
If the resulting system has a population capacity of less than the lower limit (80 resp. 130 by default), then the game tries to compensate that by adding more planets (if there aren't already 7 planets), and if that's still not enough, then the game (repeatedly) tries to replace planets with bigger ones, until there's enough population space (or until all planets are pop 140 class M planets ^^).
A warning in advance: Increasing the upper limit and the number of planets can lead to some planets not being displayed in the game, because there's only limited space for the planet animations. Gas Giants are the biggest troublemakers in this case, since they have big animations and a population capacity of zero.
Free Systems
Code: Select all
Offset hex code asm code
:004B48BD 817C244CA00F0000 cmp dword[esp+4C], 0FA // upper limit
----------
:004B4849 817C244C20030000 cmp dword[esp+4C], 00000320 // lower limit
----------
:004B485C 817C244C20030000 cmp dword[esp+4C], 00000320 // lower limit
----------
:004B492C 66837D6A07 cmp word[ebp+6A], 007 // maximum number of planets
Minor Race Systems
Code: Select all
Offset hex code asm code
:004B4B0B 817C244CA00F0000 cmp dword[esp+4C], 0FA // upper limit
----------
:004B4A43 817C244C14050000 cmp dword[esp+4C], 00000514 // lower limit
----------
:004B4A53 817C244C14050000 cmp dword[esp+4C], 00000514 // lower limit
----------
:004B4B7C 66837D6A07 cmp word[ebp+6A], 007 // maximum number of planets
Note that the population capacity of the home planet does not count.
Additional Major Empire Starting Systems
Code: Select all
Offset hex code asm code
:004B4D3D 817C244CA00F0000 cmp dword[esp+4C], 0FA // upper limit
----------
:004B4C6D 817C244C14050000 cmp dword[esp+4C], 00000514 // lower limit
----------
:004B4C7D 817C244C14050000 cmp dword[esp+4C], 00000514 // lower limit
----------
:004B4DFB 66837D6A07 cmp word[ebp+6A], 007 // maximum number of planets
Edit:
Class specification for the additional planet (default = 6 = terran):
Code: Select all
:004B4C9D B806000000 mov eax, 00000006
These "special planets" can be disabled by replacing
Code: Select all
:004B4C9B 753E jne 004B4CDB
Code: Select all
:004B4C9B EB3E jmp 004B4CDB