Planet Growth Values ; habit.bin

Planet GrowthValues ; habit.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

Planet Growth Values ; habit.bin

Post by Gowron »

This posting used to be part of a relatively long thread about population growth, but it containes the complete information about how planets affect growth :)

Be warned, this topic is kinda technical ;)


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


Good news, I've found the constants that are controlling the growth rates in trek.exe and can now give a more precise algorithm for the growth rate calculation.
The not-so-good news is that it's a bit more complicated since there are several constants involved, and not everything is linear.

I'll call the constants p, q, r, s, t, u, v, w.
p is not used in the calculations, but that seems to be a bug (see below).

All of the following values are stored in trek.exe.

p
start position: 0x0017db84
size: 8 bytes (double)
default value: 0.1
meaning: unknown/unused (probably meant to be the barrier multiplier for small planets)
I tried changing this value from 0.1 to 2000.0, but it didn't seem to have any effect.

q
start position: 0x0017db8c
size: 8 bytes (double)
default value: 0.1
meaning: quadratic multiplier for growth rates, barrier value for small planets
warning: increasing this value will lower the max. accuracy of growth rates (see below)

r
start position: 0x0017db94
size: 8 bytes (double)
default value: 0.001
meaning: linear multiplier for growth rates

s
start position: 0x0017db9c
size: 8 bytes (double)
default value: 1.5
meaning: growth rate multiplier for large planets

t
start position: 0x0017dba4
size: 8 bytes (double)
default value: 0.4
meaning: barrier value for large planets

u
start position: 0x0017dbac
size: 8 bytes (double)
default value: 0.2
meaning: barrier value for medium planets

v
start position: 0x0017dbb4
size: 8 bytes (double)
default value: 0.5
meaning: growth rate multiplier for small planets

w
start position: 0x0017dbbc
size: 4 bytes (float)
default value: 10.0
meaning: global multiplier







Growth Rate Calculation Step by Step

1. Determine planet class and atmosphere type and get the corresponding habitability value from habit.bin.
If the habitability value is undefined, then the planet 's growth rate is now set to the substitute value (see below) according to the planet's size, and then proceed to step 6. Else, proceed to step 2.

2. If the planet is part of a minor race starting system, multiply the habitability value by the minor race growth value from race.rst. Cut the result at the decimal point. If the cut result is zero, then the planet 's growth rate is now set to 0.0 (and in that case all further calculations are skipped). If that's not the case or if the planet is not part of a minor race starting system, proceed to step 3.

3. If the planet is large, multiply the result from step 2 by s. If the planet is small, multiply by v instead. Proceed to step 4.

4. Determine the planet's growth rate via the following formula:
[growth rate] = [max. population] * r * q * [result from step 3] * 10.0%
Proceed to step 5.

5. If the result from step 4 is lower than the barrier value (see below), it is replaced by the substitute value (see below). In any case, proceed to step 6.

6. Multiply by w.
Cut the result at the decimal point.
Then multiply by q.
(thus, all possible growth rates are multiples of q; this is how q affects the max. accuracy)


It is possible that the barrier value for small planets was originally meant to be p, and it was accidentally replaced by q. Since the default values for p and q are the same, maybe no one noticed the bug since it does not have any effect in the default setup.


Substitute Values

The substitute value also depends on the planet's size.

For small planets, it's
0.1

For medium planets, it's
0.2

For large planets, it's
0.4
Last edited by Gowron on Sat Sep 27, 2008 4:58 pm, edited 2 times in total.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Habitability Values

Post by Gowron »

habit.bin
14 groups, each group consists of 8 bytes

1st byte: planet class
2nd byte: atmosphere type
3rd byte: habitability value for Cardassians
4th byte: habitability value for Humans
5th byte: habitability value for Ferengi
6th byte: habitability value for Klingons
7th byte: habitability value for Romulans
8th byte: habitability value for minors or unoccupied systems

The 4th and 8th values are always the same by default.
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron »

Update:

After looking through the assembler code, the algorithm (which had been the result of testing , not code analysis) seems to be exactly what the game is doing, with the multiplications in step 3 and 4 not necessarily being performed in that order.


The check within step 2 (which can lead to all further calculations being skipped) is located in trek.exe at position 0xB7476.
Assembler code:

Code: Select all

85FF           // test edi, edi
0F843C010000   // je 004B81BA
To disable the test, just overwrite those 8 bytes with "90"s :)



The substitute values are each composed of two parts, which are read separately, stored in a row and then loaded into the FPU as a whole.

Substitute Value for small planets (position 0xB75D4):

Code: Select all

BE9A999999    // mov esi, 9999999A
BF9999B93F    // mov edi, 3FB99999
Substitute Value for medium planets (position 0xB763B):

Code: Select all

B99A999999    // mov ecx, 9999999A
BB9999C93F    // mov ebx, 3FC99999
Substitute Value for large planets (position 0xB767E):

Code: Select all

B89A999999    // mov eax, 9999999A
BA9999D93F    // mov edx, 3FD99999
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Planet Growth Values ; habit.bin

Post by Tethys »

So I found out recently that habit.bin works by loading in the base values of each DEFINED planet + atmosphere type from this file!

If there is no associated planet + atmosphere combination in habit.bin, the "barrier value" is used instead (such as if you make a M class planet with methane atmosphere ie combination 06 0B). Since this is not a defined combination, it defaults to the hard coded values.

Furthermore, at least one entry can be added to habit.bin and I am about to test more entries to verify if the file is dynamic or static. Sorry Flocke... UE needs access to habit.bin to adjust growth percentages/per race if at all possible. I will update this post with further information regarding extension of the habit.bin file.

Update: A second additional entry is added and the values are working in game. BotF supports dynamic file size in this regard? I was worried about 70h bin size and

Code: Select all

4B8245 	0E0	 89 4C 24 74		mov     [esp+74h], ecx
but right now it seems to be working without any modifications. Update: I added 2 more entries, total entries = 18. Skipped testing entry 17, test to last entry. Initial testing shows no issues. Seems like we can create custom growth rates for non-vanilla planets (M-class with greenhouse = 06 terran + 0B methane) for additional options, unique planets, double growth percentage for Large M class super earths (06 terran + 0C thin oxygen), stuff like that.

Footnote: Editing out the 03 08 gas giant entry does not seem to affect the game or cause crashes, but more testing should be done (as with all things BotF)
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Planet Growth Values ; habit.bin

Post by Spocks-cuddly-tribble »

Tethys wrote: Mon Oct 09, 2023 12:34 pmhabit.bin works by loading in the base values of each DEFINED planet + atmosphere type from this file! (...) BotF supports dynamic file size in this regard
Correct, the topic is a bit abstract explained. My related post to assist Dafedz with his new planet type: viewtopic.php?p=28094&hili#p28094
Gowron wrote: Thu May 01, 2008 4:15 pmDetermine planet class and atmosphere type and get the corresponding habitability value from habit.bin.
If the habitability value is undefined, then the planet 's growth rate is now set to the substitute value (see below) according to the planet's size
Last edited by Spocks-cuddly-tribble on Wed Oct 11, 2023 2:09 pm, edited 1 time 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
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Planet Growth Values ; habit.bin

Post by Tethys »

Spocks-cuddly-tribble wrote: Tue Oct 10, 2023 1:09 pm
Gowron wrote: Thu May 01, 2008 4:15 pmDetermine planet class and atmosphere type and get the corresponding habitability value from habit.bin.
If the habitability value is undefined, then the planet 's growth rate is now set to the substitute value (see below) according to the planet's size
I have found, at least in the case of GALM, that uninhabitable gas giants their "barrier values" are being calculated into the systems growth rates.

I have found a solution, to setting all the gas planets to Large planets and rerouting the jump here:

Code: Select all

004B827C 0E0 77 24                   ja      short loc_4B82A2 ; 75 24 ignore barrier value
This calculates the value from the bin file instead of the barrier value for large planets, but is highly untested and might lead to issues down the road? Not sure, I will need to test it (I suspect that if a Large planet has an incalculable growth rate i.e. no entry in habit.bin, things might break). I may settle for 0.1 if I cannot get 0.0 to work

Furthermore, the discrepancies in the growth rates 'seem' to be due to the varying habitability values in the bin file. I have set all majors (except Borg) to the same habitability value as well as the neutral/minor/unpopulated rate entry value per planet/atmosphere type. The result was uniform growth percentage display for planets without much variation for race. The growth rates were pretty accurate.
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Planet Growth Multi Fix for habit.bin

Post by Spocks-cuddly-tribble »

There is three fixes / fix-corrections to do (see below multi patch):
Tethys wrote: Tue Oct 10, 2023 6:24 pmuninhabitable gas giants their "barrier values" are being calculated into the systems growth rates.
The "zero growth rate minor planets fix" by Gowron causes this bug :!:
minor_race_zero_growth_rate_fix.patch
(413 Bytes) Downloaded 18 times
Remove patch from trek.exe and delete in database, unless you want uninhabitable gas giants increasing systems growth rates with substitute values. :idea:

Tethys wrote: Mon Oct 09, 2023 12:34 pmEditing out the 03 08 gas giant entry does not seem to affect the game
Vanilla reads the zero values from the gas giant habit.bin entry to prevent this bug caused by the "zero growth rate minor planets fix".
My new multi fix checks the planspac.bin pop value, so you can remove or ignore uninhabitable gas giants in habit.bin. :wink:

Tethys wrote: Tue Oct 10, 2023 6:24 pmdiscrepancies in the growth rates 'seem' to be due to the varying habitability values in the bin file.
Growth rates of uninhabited systems read the 6th (shared minor) value in habit.bin. My new multi-fix reads the player empire. :wink:
Federation and minor habit.bin values are always the same by default so you only see the discrepancies playing other empires in vanilla. :idea:


Most min/max limits in BotF use at least two codes for the same value: The compare value (Barrier) and the replacement for outliers (Substitute).
Gowron wrote: Thu May 01, 2008 4:15 pm0x0017db84 unused (probably meant to be the barrier multiplier for small planets) it was accidentally replaced.
Since the default values for p and q are the same, maybe no one noticed the bug since it does not have any effect in the default setup.
New patch also fixes this pointer for 'growth barrier for small planets' at 4B80F9 fcomp ds:57FD8C -> 57FD84.

Planet_Growth_Multi_Fix.patch
(1.1 KiB) Downloaded 21 times
ASM Notes:
► Show Spoiler
And there is also bugs in the vanilla habit.bin file. E.g. Cardassians love arctic planets and dislike M-class (should be +desert/volcanic -arctic). :???:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Planet Growth Multi Fix for habit.bin

Post by Tethys »

Spocks-cuddly-tribble wrote: Wed Oct 11, 2023 2:29 pm There is three fixes / fix-corrections to do (see below multi patch):

...

And there is also bugs in the vanilla habit.bin file. E.g. Cardassians love arctic planets and dislike M-class (should be +desert/volcanic -arctic). :???:
Thanks for this. And in GALM, this is no issue, because I have replaced Arctic planets to be Desert AND Arctic because arctic are desert, just very cold. Also, Cardassia is minor at this point. I used the hot desert ani for them.

Note: There is at least one minor that is receiving a growth rate percentage boost. I believe it was the Edo (replaced by Bajorans, further replaced by T'Lani per EDO GOD redirection > cmp 06). I am searching the forums now for clues. My search yielded little. I will have to investigate, because their M class is about 1.5% above the standard M class percentage. 13% growth for a minor is insane, though it would make the perfect Tribble system :lol:
Discrepancy.png
Discrepancy.png (219.77 KiB) Viewed 756 times
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Planet Growth Multi Fix for habit.bin

Post by Spocks-cuddly-tribble »

Tethys wrote: Wed Oct 11, 2023 4:50 pmat least one minor is receiving a growth rate percentage boost. I believe it was the Edo. I am searching the forums now for clues. My search yielded little.
Which topic could it be...:?: :???: Minor races use the growth multiplier from race.rst (see first post). The vanilla EDO value is quite high: :idea: :wink:
Gowron wrote: Thu May 01, 2008 4:15 pmIf the planet is part of a minor race starting system, multiply the habitability value by the minor race growth value from race.rst.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2392
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: Planet Growth Values ; habit.bin

Post by Tethys »

Spocks-cuddly-tribble wrote: Wed Oct 11, 2023 6:40 pmThe vanilla EDO value is quite high: :idea: :wink:
But the value is also shared for non-Edo systems ie. free systems (unless your previously posted mod patch changes this?). I am quite aware the Edo value is high, and I am currently looking for said value in 45157C (setup_civstart) to no avail. Something you have labeled "start pop mod" ? It was none of the topics, no code at least.

Looking up I see there are dead race bitmasks, could this possibly be something else? One case it saves some alien info, the other case does not, but they both end up at 451506 setting some morale, starting pop, and race.rst pop values.

Do I assume that, putting the Edo population value down would also decrease their growth rate? I suspect it some habitability value being calculated solely for Edo race (cmp 12h). But I cannot find the cmp 12h. The workaround might have to do for now (setting M class > K class). Reason I believe it's habitability is that I changed the Jungle planet to operate more like Oceanic (+chance to be pre-terraformed?) so now that effect is applied to Marginal type planets instead. I have not tested if terraforming one of their planets changes the percentage but I assume that it does,; it appears they have default non-terraformed growth rates?
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
Post Reply

Return to “Planet GrowthValues ; habit.bin”