Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patterns

Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patterns; 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

Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patterns

Post by Gowron »

Welcome to my 3rd (and probably last) "four in one" topic :)
Time for some more funny facts about BotF ^^

Note: I'll use the abbreviation "sqrt" for the square root function, e.g.
sqrt(4) = 2




1. Population Growth

I'm not talking about the growth percentage (this has been covered before), but about the actual pop increase at the start of each turn. Although this seemed to be simple at first, it turned out to be one of the most complicated game mechanics, so I divide it into 5 sub-chapters.

Newly colonised systems will already grow during the turn they're colonised.

1.1 Starvation

If the system's food output is less than its population, then the population decreases. The formula does not look pretty, but neither nasty enough to scare a Klingon :P

[population loss] = 0.1 * sqrt ( [current population] * ( [current population] - [food output] ) )

The remaining population is always rounded UP.
This means that a system with a population of 9 or less cannot shrink any further by starvation.


1.2 The Effect of Unemployment

If a system has a food output equal to or greater than its current population, but does not have enough population-employing structures (farms, factories etc.) to employ more than 50% of its population, then it cannot grow by more than 1 population point per turn. This will overrule all calculations of sections 1.4 and 1.5.


1.3 The Effective Food Output

This is only needed for the formula in section 1.4.
"Normally", the effectice food output is just the system's food output.

The only exception is:
If the system's food output is greater than its maximum population capacity (not counting any planets that have yet to be terraformed), then the effective food output is equal to the maximum population capacity.

Note: The game will tell you something about "required food for maximum growth", displaying 2 times the system's current pop, but that's just plain nonsense.


1.4 The Growth Formula

The (exact) population increase of a system with a food output equal to or greater than its current population is given by

[population increase] = 0.5 * [growth rate] * ( [current population] + [effective food output] )

"Growth rate" is the system's "growth" value listed on the F1 screen. For example, if the screen displays "1.3%", then the growth rate is 0.013 (which is the same value, but without using the % sign).
However, if the growth rate is less than 0.01 (= 1%), then it is treated as 0.01 (= 1%).

But the result is most likely not an integer. If it's smaller than 1, then the system's population grows by one point. But if not, then the game has to decide whether it's "rounded" up or down. This leads to...


1.5 The Random Generator

The game creates a random value between 0 and 1. If the random value is greater than the internal decimal places of the (floating-point) pop increase, then the increase is rounded down. Else, it's rounded up.

This means, it you have an exact increase of, say, +3.375, then there's a 37.5% chance that the system grows by 4 pop points and a 62.5% chance that is grows by 3 pop points.

The random value is fully determined by the starting seed, i.e. saving and loading will lead to the same results, but starting a new game and doing exactly the same can lead to different results.


I've tested this by starting many identical games in a row and comparing the first-turn growth results:

Test 1
number of test games: 100
system: Ferenginar, starting population 20, growth rate 0.028, eff. food output 310
exact pop increase: +4.62
possible pop increases: +4 or +5
average observed pop increase: +4.68

Test 2
number of test games: 100
system: Cardassia, starting population 20, growth rate 0.027, eff. food output 345
exact pop increase: +4.9275
possible pop increases: +4 or +5
average observed pop increase: +4.93






2.1 Terraforming Costs (simple)

The required amount of work to terraform a planet is given by

[terraforming cost] = [planet's population capacity] * ( [planet type coefficient] + [planet atmosphere coefficient] )

The coefficients are:

Code: Select all

+ 8    for class P
+10    for class J
+ 7    for class G
+ 6    for class L
+ 4    for class O
  0    for class M
+12    for class Y

+ 1.5  for atmosphere "methane"
+ 1    for atmosphere "none"
- 1.5  for atmosphere "oxygen rich"
+ 1.25 for atmosphere "sulfuric"
- 1    for atmosphere "thin oxygen"

The result is cut at the decimal point.
A negative result or a 0 means that the planet does not need to be terraformed.

For more details, see the link in next section.


2.2 Terraforming Costs (advanced)

Click here:
viewtopic.php?f=159&t=60





3. Trade Goods

The benefit of "trade goods" is given by

[gained credits per turn] = sqrt ( [industry output] )

This value is then rounded UP and added to the system's cash output (which is also rounded up BEFORE the 2 values are added together).
The cash generated by trade goods is not influenced by any credits bonuses.

Trade goods are quite efficient if the system has no manned industry structures, giving sqrt(5) = +3 credits per turn (rounded up, of course, not exactly ^^). The more industry production, the greater the waste.

The output value for trade goods in edifice.bst (+1 by default) is meaningless. Changing it doesn't have any effect on the cash output.

Adjusting trade good output





4. Pattern for X-Ray Pulsars

Period length: 4 turns

Explanation:
0 means no effect on this square.
a means -2 scanning strength on this square.
b means -4 scanning strength on this square.
c means -8 scanning strength on this square.
d means -16 scanning strength on this square.
e means -32 scanning strength on this square.
f means -48 scanning strength on this square.


1st turn:

Code: Select all

00000
0ddd0
0ded0
0ddd0
00000

2nd turn:

Code: Select all

00000
00000
00d00
00000
00000

3rd turn:

Code: Select all

00000
0ddd0
0ded0
0ddd0
00000

4th turn:

Code: Select all

0ddd0
deeed
defed
deeed
0ddd0





5. Pattern for Radio Pulsars

Period length: 8 turns

Explanation:
0 means no effect on this square.
a means -2 scanning strength on this square.
b means -4 scanning strength on this square.
c means -8 scanning strength on this square.
d means -16 scanning strength on this square.
e means -32 scanning strength on this square.
f means -48 scanning strength on this square.

1st turn:

Code: Select all

000000000
000000000
000000000
000000000
abcde0000
abcd00000
0ab000000
0a0000000
2nd turn:

Code: Select all

000000000
000000000
000000000
000000000
0000e0000
000dd0000
00bcc0000
0aabb0000
000aa0000
3rd turn:

Code: Select all

000000000
000000000
000000000
000000000
0000e0000
0000dd000
0000ccb00
0000bbaa0
0000aa000
4th turn:

Code: Select all

000000000
000000000
000000000
000000000
0000edcba
00000dcba
000000ba0
0000000a0
000000000

5th turn:

Code: Select all

000000000
0000000a0
000000ba0
00000dcba
0000edcba
000000000
000000000
000000000
000000000

6th turn:

Code: Select all

0000aa000
0000bbaa0
0000ccb00
0000dd000
0000e0000
000000000
000000000
000000000
000000000

7th turn:

Code: Select all

 000aa0000
0aabb0000
00bcc0000
000dd0000
0000e0000
000000000
000000000
000000000
000000000

8th turn:

Code: Select all

 0a0000000
0ab000000
abcd00000
abcde0000
000000000
000000000
000000000
000000000
000000000
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
User avatar
The_Nighthawk
Lieutenant-Commander
Lieutenant-Commander
Posts: 149
Joined: Tue May 06, 2008 2:00 am
Location: Vancouver, BC Canada (GMT-8)
Contact:

Post by The_Nighthawk »

Just a comment on the application of section 1.4. To grow your colonies the fastest, you should be terraforming all the planets in a system asap, and then building farms to max out your food production first. You can grow your colony much faster this way.

For instance if you have a 2.0%, 250 max pop system with an actual pop of 60:

a) you're only producing enough food for your current next pop point (say 70), you will grow 0.5*.02*(60+70) or 1.3 pop next turn, pretty much what you'd expect.

b) you've managed to max out food at 250 (with all pop on farms and some special structures). Growth will be 0.5*.02*(60+250) or 3.1.

That's a big difference.
Playing BoP whenever the wife allows!
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 »

Spocks-cuddly-tribble wrote:Is there a way to influence the Starvation calculation in order to round DOWN remaining population?

(I hope that I'm not too heartless)
I did not find a way to do that, but you can make the game round the population to the nearest integer by replacing D9C9D9E0DEC9 with D9E0DEC9D9FC in trek.exe at position 0x42B11.
Note that this can bring a system's population down to a minimum of 5.

Alternatively, it should be possible to leave the rounding as it is and instead reduce the population by an additional point, which will, in most (but not all) cases, have the same result as reversing the rounding mode.
What would you prefer?


Now for the in-depth analysis...


UPDATE


a. Starvation Calculation

The actual implementation of starvation is equivalent to the formula I gave in the article above, but there are some redundant operations, as follows:

Code: Select all

pos.  -----hex------ ------------asm-------------
----------------------------------------------------------------
42AB8 DF4718         fild 16int[edi+18]            // load food output
42ABB DB8424C8000000 fild dword[esp+000000C8]      // load population
42AC2 DEF9           fdivp                         // divide food by pop
42AC4 668B4F1A       mov cx, word[edi+1A]
42AC8 668B5718       mov dx, word[edi+18]
42ACC D9E8           fld1                         
42ACE DEE1           fsubrp                        // subtract result from 1.0
42AD0 29D1           sub ecx, edx                 
42AD2 DD9C249C000000 fstp 64real[esp+0000009C]
42AD9 6685C9         test cx, cx
42ADC 0F8EF3000000   jle 004437D5
42AE2 DD84249C000000 fld 64real[esp+0000009C]
42AE9 DC0DD4885700   fmul 64real[005788D4]         // multiply by M1 [100.0]
42AEF D9FA           fsqrt                         // extract the square root
42AF1 DC0DDC885700   fmul 64real[005788DC]         // multiply by M2 [0.01]
42AF7 31D2           xor edx, edx                 
42AF9 8B4340         mov eax, dword[ebx+40]
42AFC 899424B8000000 mov dword[esp+000000B8], edx  // load population...
42B03 898424B4000000 mov dword[esp+000000B4], eax  // ...as 64-bit...
42B0A DFAC24B4000000 fild 64int[esp+000000B4]      // ...integer
42B11 D9C9           fxch                          // redundant!
42B13 D9E0           fchs                          // change sign
42B15 DEC9           fmulp                         // multiply by population
There are two multipliers involved, which I called M1 and M2.

M1
position: 0x1766D4
type: double
default value: 100.0

M2
position: 0x1766DC
type: double
default value: 0.01
warning: also used for population growth, see here


So the population loss by calculated this way:
[pop loss] = [pop] * M2 * sqrt( M1 * ( 1.0 - ( [food output] / [pop] ) ) )


The fxch operation at position 0x42B11 is not needed, because the two values are multiplied anyway, so it does not matter which one has its sign changed.

The sign change at position 0x42B13 can be overwritten with 9090 to reverse the effect of starvation (may not be very useful, but at least it's funny ^^).



b. Trade Goods Output Calculation (UPDATE)

This will be rather short:
The calculation consists of loading the current industry output and extracting its square root.

The square root operation (D9FA) is found at position 0x5FD1B and at position 0x6039C.
Changing D9FA to 9090 at both positions will result in trade goods generating credits equal to the system's current industry output. No more need for scrapping ships ;)


Edit: corrected position of square root operation for trade goods

Edit #2: updated trade goods section
Last edited by Gowron on Tue Oct 07, 2008 4:10 pm, edited 2 times in total.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.
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 »

Spocks-cuddly-tribble wrote:Reduction of starving population by an additional point fits, thanks. :)
This should work for you:

Go to position 0x42AE9.

Replace

Code: Select all

DC 0D D4 88 57 00 D9 FA DC 0D DC 88 57 00 31 D2 8B 43 40 89 94 24 B8 00 00 00 89 84 24 B4 00 00 00 DF AC 24 B4 00 00 00 D9 C9 D9 E0 DE C9
with

Code: Select all

DC 0D DC 88 57 00 D9 FA 31 D2 8B 43 40 89 94 24 B8 00 00 00 89 84 24 B4 00 00 00 DF AC 24 B4 00 00 00 DE C9 D9 E8 DE C1 90 90 90 90 D9 E0
Now you can starve your systems to death ^^
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: 1883
Joined: Sun Apr 27, 2008 2:00 am

Post by Spocks-cuddly-tribble »

Gowron wrote:b. Trade Goods Output Calculation (UPDATE)

This will be rather short:
The calculation consists of loading the current industry output and extracting its square root.

The square root operation (D9FA) is found at position 0x5FD1B and at position 0x6039C.
There is one more at 0x60309. It's for the forced trade goods in the case of "Credit Deficit" (loc_460E7B).

EDIT:

And one more at asm-46045A, same purpose.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
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 »

Population growth (resp. starvation) is controlled by subroutine 443610.
Here's the assembler code with comments from me.
(note that pop growth uses the same formula as I proposed in section 1, but it's implemented in a VERY intricate way)

Code: Select all

AUTO:00443610                 push    ebx
AUTO:00443611                 push    ecx
AUTO:00443612                 push    esi
AUTO:00443613                 push    edi
AUTO:00443614                 push    ebp
AUTO:00443615                 sub     esp, 0D8h
AUTO:0044361B                 mov     word ptr [esp+0D8h+var_4], ax
AUTO:00443623                 mov     esi, edx
AUTO:00443625                 mov     ecx, [esp+0D2h]
AUTO:0044362C                 sar     ecx, 10h
AUTO:0044362F                 imul    eax, ecx, 328h
AUTO:00443635                 mov     ebx, ds:st_systInfo
AUTO:0044363B                 mov     [esp+0D8h+RelSystDataOffs], eax
AUTO:00443642                 add     ebx, eax        ; data offset for current star system
AUTO:00443644                 lea     eax, ds:0[edx*4]
AUTO:0044364B                 sub     eax, edx
AUTO:0044364D                 shl     eax, 2
AUTO:00443650                 sub     eax, edx
AUTO:00443652                 mov     ebp, 0Ah
AUTO:00443657                 shl     eax, 3
AUTO:0044365A                 lea     edi, [ebx+240h]
AUTO:00443660                 mov     [esp+0D8h+var_18], eax
AUTO:00443667                 add     edi, eax
AUTO:00443669                 mov     eax, ecx
AUTO:0044366B                 xor     edx, edx
AUTO:0044366D                 call    GetSystemPpCap2 ; write 10*(star system population capacity) to eax
AUTO:00443672                 div     ebp             ; eax = star system population capacity
AUTO:00443674                 mov     ebp, eax        ; ebp = star system population capacity
AUTO:00443676                 mov     ax, [edi+14h]
AUTO:0044367A                 mov     [edi+18h], ax
AUTO:0044367E                 cmp     esi, 1
AUTO:00443681                 jnz     short loc_443689
AUTO:00443683                 cmp     byte ptr [ebx+4Ch], 23h ; check if system does not have an owner
AUTO:00443687                 jnz     short loc_443695

AUTO:00443689                 add     esp, 0D8h
AUTO:0044368F                 pop     ebp
AUTO:00443690                 pop     edi
AUTO:00443691                 pop     esi
AUTO:00443692                 pop     ecx
AUTO:00443693                 pop     ebx
AUTO:00443694                 retn
AUTO:00443695 ; ---------------------------------------------------------------------------

AUTO:00443695                 xor     eax, eax
AUTO:00443697                 mov     esi, esp        ; star system population capacity
AUTO:00443699                 mov     al, [ebx+4Ch]   ; controlling empire ID
AUTO:0044369C                 call    sub_4AED50
AUTO:004436A1                 cmp     dword ptr [ebx+40h], 0 ; check if current population is zero
AUTO:004436A5                 jz      loc_4437C2
AUTO:004436AB                 xor     eax, eax
AUTO:004436AD                 mov     ax, [edi+1Ah]   ; current population
AUTO:004436B1                 mov     [esp+0D8h+var_10], eax ; current population
AUTO:004436B8                 fild    word ptr [edi+18h] ; food output
AUTO:004436BB                 fild    [esp+0D8h+var_10] ; current population
AUTO:004436C2                 fdivp   st(1), st       ; divide food output by current population
AUTO:004436C4                 mov     cx, [edi+1Ah]   ; current population
AUTO:004436C8                 mov     dx, [edi+18h]   ; food output
AUTO:004436CC                 fld1
AUTO:004436CE                 fsubrp  st(1), st       ; subtract result of division from 1
AUTO:004436D0                 sub     ecx, edx        ; subtract food output from current population
AUTO:004436D2                 fstp    [esp+0D8h+var_3C]
AUTO:004436D9                 test    cx, cx
AUTO:004436DC                 jle     loc_4437D5      ; jump if food output is HIGHER than current population
AUTO:004436E2                 fld     [esp+0D8h+var_3C]
AUTO:004436E9                 fmul    ds:dbl_5788D4   ; 100.0
AUTO:004436EF                 fsqrt
AUTO:004436F1                 fmul    ds:PopGrowthMultpl ; 0.01
AUTO:004436F7                 xor     edx, edx
AUTO:004436F9                 mov     eax, [ebx+40h]
AUTO:004436FC                 mov     dword ptr [esp+0D8h+var_24+4], edx ; load current population...
AUTO:00443703                 mov     dword ptr [esp+0D8h+var_24], eax ; ... as 64-bit integer
AUTO:0044370A                 fild    [esp+0D8h+var_24]
AUTO:00443711                 fxch    st(1)
AUTO:00443713                 fchs
AUTO:00443715                 fmulp   st(1), st       ; population loss calculated
AUTO:00443717                 mov     dword ptr [ebx+320h], 0
AUTO:00443721                 call    RoundFloatTwds0 ; round population loss towards zero
AUTO:00443726                 fistp   [esp+0D8h+var_10] ; population loss
AUTO:0044372D                 mov     eax, [esp+0D8h+var_10] ; population loss
AUTO:00443734                 mov     [edi+4], ax     ; population loss
AUTO:00443738                 test    ax, ax          ; check if population loss is zero
AUTO:0044373B                 jz      loc_443689
AUTO:00443741                 mov     eax, 100h
AUTO:00443746                 call    sub_459230
AUTO:0044374B                 mov     esi, eax
AUTO:0044374D                 xor     ah, ah
AUTO:0044374F                 mov     al, [ebx+4Ch]
AUTO:00443752                 mov     cl, al
AUTO:00443754                 mov     [esi+4], ax
AUTO:00443758                 mov     al, 1
AUTO:0044375A                 shl     al, cl
AUTO:0044375C                 mov     edx, 78000h
AUTO:00443761                 mov     [esi+0Ch], al
AUTO:00443764                 mov     eax, esi
AUTO:00443766                 call    sub_4591C0
AUTO:0044376B                 mov     eax, [esi+20h]
AUTO:0044376E                 mov     edx, [esp+0D8h+var_4]
AUTO:00443775                 mov     [eax+8], dx
AUTO:00443779                 mov     edx, [edi+2]
AUTO:0044377C                 sar     edx, 10h
AUTO:0044377F                 mov     [eax+0Ch], edx
AUTO:00443782                 mov     eax, esi
AUTO:00443784                 call    sub_459370

AUTO:00443789                 mov     eax, [edi+2]
AUTO:0044378C                 mov     ecx, [ebx+40h]  ; current pop
AUTO:0044378F                 sar     eax, 10h        ; pop increase
AUTO:00443792                 add     eax, ecx        ; (current pop) + (pop increase)
AUTO:00443794                 cmp     eax, ebp        ; check if there is enough pop space for pop increase
AUTO:00443796                 jnb     loc_443A5C

AUTO:0044379C                 mov     [ebx+40h], eax  ; save new population number
AUTO:0044379F                 test    eax, eax        ; check if new population number is zero
AUTO:004437A1                 ja      loc_443689
AUTO:004437A7                 mov     eax, [esp+0D2h]
AUTO:004437AE                 sar     eax, 10h
AUTO:004437B1                 call    sub_440780
AUTO:004437B6                 add     esp, 0D8h
AUTO:004437BC                 pop     ebp
AUTO:004437BD                 pop     edi
AUTO:004437BE                 pop     esi
AUTO:004437BF                 pop     ecx
AUTO:004437C0                 pop     ebx
AUTO:004437C1                 retn
AUTO:004437C2 ; ---------------------------------------------------------------------------
AUTO:004437C2                 mov     eax, ecx
AUTO:004437C4                 call    sub_440780
AUTO:004437C9                 add     esp, 0D8h
AUTO:004437CF                 pop     ebp
AUTO:004437D0                 pop     edi
AUTO:004437D1                 pop     esi
AUTO:004437D2                 pop     ecx
AUTO:004437D3                 pop     ebx
AUTO:004437D4                 retn
AUTO:004437D5 ; ---------------------------------------------------------------------------
AUTO:004437D5                 mov     eax, [esp+0D8h+var_4]
AUTO:004437DC                 mov     [esp+0D8h+food_surplus], cx ; (-1)*(food surplus)
AUTO:004437E4                 mov     esi, ecx        ; (-1)*(food surplus)
AUTO:004437E6                 xor     edx, edx
AUTO:004437E8                 mov     ecx, [esp+0D8h+RelSystDataOffs]
AUTO:004437EF                 neg     esi             ; food surplus
AUTO:004437F1                 mov     [esp+0D8h+var_8], ax
AUTO:004437F9                 mov     [esp+0D8h+var_5C], edx ; 0
AUTO:004437FD                 mov     [esp+0D8h+food_surplus], si
AUTO:00443805                 mov     esi, ds:st_systInfo
AUTO:0044380B                 mov     [esp+0D8h+var_58], edx ; 0
AUTO:00443812                 add     esi, ecx        ; data offset for current star system
AUTO:00443814                 mov     eax, [esp+0D8h+var_18]
AUTO:0044381B                 lea     ecx, [esi+240h]
AUTO:00443821                 mov     dl, [esi+4Ch]   ; controlling empire ID
AUTO:00443824                 add     ecx, eax
AUTO:00443826                 cmp     dl, 23h
AUTO:00443829                 jz      short loc_443836 ; jump if current star system does not have an owner
AUTO:0044382B                 cmp     word ptr [esi+44h], 0FFFFh ; check if there is no inhabitant race ID
AUTO:00443830                 jnz     loc_443978

AUTO:00443836                 mov     eax, [esp+0D8h+var_5C]
AUTO:0044383A                 mov     [esp+0D8h+var_34], eax
AUTO:00443841                 mov     eax, [esp+0D8h+var_58]

AUTO:00443848                 mov     [esp+0D8h+var_30], eax
AUTO:0044384F                 mov     eax, [esp+0D8h+var_34]
AUTO:00443856                 mov     dword ptr [esp+0D8h+GrowthRate_x100], eax
AUTO:0044385D                 mov     eax, [esp+0D8h+var_30]
AUTO:00443864                 mov     dword ptr [esp+0D8h+GrowthRate_x100+4], eax
AUTO:0044386B                 mov     eax, [esp+0D2h]
AUTO:00443872                 mov     ecx, 0Ah
AUTO:00443877                 sar     eax, 10h        ; get star system ID
AUTO:0044387A                 xor     edx, edx
AUTO:0044387C                 call    GetSystemPpCap2 ; write 10*(star system population capacity) to eax
AUTO:00443881                 div     ecx             ; star system population capacity
AUTO:00443883                 mov     ecx, [ebx+40h]  ; current population
AUTO:00443886                 sub     eax, ecx        ; (pop capacity) - (current population)
AUTO:00443888                 mov     ecx, eax        ; (pop capacity) - (current population)
AUTO:0044388A                 mov     eax, [esp+0D8h+var_10+2]
AUTO:00443891                 sar     eax, 10h        ; food surplus
AUTO:00443894                 cmp     eax, ecx        ; check if food output is greater than pop capacity
AUTO:00443896                 jnb     loc_443A17

AUTO:0044389C                 xor     esi, esi
AUTO:0044389E                 mov     dword ptr [esp+0D8h+var_24], eax ; effective food surplus
AUTO:004438A5                 mov     dword ptr [esp+0D8h+var_24+4], esi ; 0
AUTO:004438AC                 mov     eax, [ebx+40h]
AUTO:004438AF                 fld     [esp+0D8h+GrowthRate_x100]
AUTO:004438B6                 fild    [esp+0D8h+var_24] ; load effective food surplus as 64-bit integer
AUTO:004438BD                 fmul    st, st(1)       ; result1 = 100 * (growth rate) * (eff. food surplus)
AUTO:004438BF                 add     eax, eax        ; 2 * (current population)
AUTO:004438C1                 mov     dword ptr [esp+0D8h+var_24+4], esi ; 0
AUTO:004438C8                 mov     dword ptr [esp+0D8h+var_24], eax ; 2 * (current population)
AUTO:004438CF                 fild    [esp+0D8h+var_24] ; load 2*(current population) as 64-bit integer
AUTO:004438D6                 fdivp   st(1), st       ; result2 = 0.5 * result1 / (current pop)
AUTO:004438D8                 mov     dword ptr [esp+0D8h+var_24+4], esi ; 0
AUTO:004438DF                 mov     eax, [ebx+40h]  ; current population
AUTO:004438E2                 faddp   st(1), st       ; result3 = result2 + 100*(growth rate)
AUTO:004438E4                 mov     dword ptr [esp+0D8h+var_24], eax ; current population
AUTO:004438EB                 fstp    [esp+0D8h+var_64] ; save result3
AUTO:004438EF                 fild    [esp+0D8h+var_24] ; current population
AUTO:004438F6                 fmul    [esp+0D8h+var_64] ; multiply result3 by current population
AUTO:004438FA                 fmul    ds:PopGrowthMultpl ; multiply by 0.01
AUTO:00443900                 fstp    [esp+0D8h+var_64] ; 0.5 * (growth rate) * ((eff. food output) + (current pop))
AUTO:00443904                 mov     esi, dword ptr [esp+0D8h+var_64+4]
AUTO:00443908                 push    esi
AUTO:00443909                 mov     eax, dword ptr [esp+0DCh+var_64]
AUTO:0044390D                 push    eax
AUTO:0044390E                 call    floor_          ; get integer part of pop increase
AUTO:00443913                 fsubr   [esp+0D8h+var_64] ; subtract integer part from pop increase to get fractional part
AUTO:00443917                 fstp    [esp+0D8h+var_4C] ; fractional part of pop increase
AUTO:0044391E                 fldz
AUTO:00443920                 fcomp   [esp+0D8h+var_4C] ; check if fractional part is not positive
AUTO:00443927                 fnstsw  ax
AUTO:00443929                 sahf
AUTO:0044392A                 jnb     short loc_443956 ; jump if fractional part is not positive
AUTO:0044392C                 mov     edx, 8C0h
AUTO:00443931                 mov     eax, offset a____SourceGame ; "..\\..\\source\\game\\solarapi.c"
AUTO:00443936                 call    random2
AUTO:0044393B                 fcomp   [esp+0D8h+var_4C] ; random decision for pop increase
AUTO:00443942                 fnstsw  ax
AUTO:00443944                 sahf
AUTO:00443945                 jnb     short loc_443956 ; jump if random part is zero
AUTO:00443947                 push    esi
AUTO:00443948                 mov     ecx, dword ptr [esp+0DCh+var_64]
AUTO:0044394C                 push    ecx
AUTO:0044394D                 call    ceil_           ; round pop increase up (random part == 1)
AUTO:00443952                 fstp    [esp+0D8h+var_64]

AUTO:00443956                 cmp     dword ptr [ebx+320h], 0
AUTO:0044395D                 jz      loc_443A1E
AUTO:00443963                 mov     word ptr [edi+4], 0
AUTO:00443969                 mov     dword ptr [ebx+320h], 0
AUTO:00443973                 jmp     loc_443789
AUTO:00443978 ; ---------------------------------------------------------------------------
AUTO:00443978                 mov     edx, [esi+40h]  ; current population
AUTO:0044397B                 cmp     edx, 0Ah
AUTO:0044397E                 jb      short loc_4439A1 ; jump if current population is less than 10
AUTO:00443980                 mov     eax, edx        ; current population
AUTO:00443982                 sar     edx, 1Fh
AUTO:00443985                 sub     eax, edx
AUTO:00443987                 sar     eax, 1          ; half population
AUTO:00443989                 mov     ecx, [ecx+0Eh]
AUTO:0044398C                 sar     ecx, 10h
AUTO:0044398F                 cmp     ecx, eax        ; unemployment check
AUTO:00443991                 jl      short loc_4439A1
AUTO:00443993                 xor     eax, eax
AUTO:00443995                 mov     [esp+0D8h+var_34], eax ; 0
AUTO:0044399C                 jmp     loc_443848
AUTO:004439A1 ; ---------------------------------------------------------------------------
AUTO:004439A1                 mov     eax, [esp+0CEh]
AUTO:004439A8                 xor     edx, edx
AUTO:004439AA                 sar     eax, 10h
AUTO:004439AD                 mov     dl, [esi+4Ch]
AUTO:004439B0                 call    sub_443540
AUTO:004439B5                 fstp    [esp+0D8h+var_44]
AUTO:004439BC                 fld1
AUTO:004439BE                 fcomp   [esp+0D8h+var_44]
AUTO:004439C5                 fnstsw  ax
AUTO:004439C7                 sahf
AUTO:004439C8                 jnb     short loc_443A00
AUTO:004439CA                 mov     eax, dword ptr [esp+0D8h+var_44]
AUTO:004439D1                 mov     [esp+0D8h+var_2C], eax
AUTO:004439D8                 mov     eax, dword ptr [esp+0D8h+var_44+4]
AUTO:004439DF                 mov     [esp+0D8h+var_28], eax

AUTO:004439E6                 mov     eax, [esp+0D8h+var_2C]
AUTO:004439ED                 mov     [esp+0D8h+var_34], eax
AUTO:004439F4                 mov     eax, [esp+0D8h+var_28]
AUTO:004439FB                 jmp     loc_443848
AUTO:00443A00 ; ---------------------------------------------------------------------------
AUTO:00443A00                 xor     ecx, ecx
AUTO:00443A02                 mov     esi, 3FF00000h
AUTO:00443A07                 mov     [esp+0D8h+var_2C], ecx
AUTO:00443A0E                 mov     [esp+0D8h+var_28], esi
AUTO:00443A15                 jmp     short loc_4439E6
AUTO:00443A17 ; ---------------------------------------------------------------------------
AUTO:00443A17                 mov     eax, ecx        ; set effective food surplus to ((pop cap) - (current pop))
AUTO:00443A19                 jmp     loc_44389C
AUTO:00443A1E ; ---------------------------------------------------------------------------
AUTO:00443A1E                 cmp     ebp, [ebx+40h]
AUTO:00443A21                 jbe     short loc_443A51 ; jump if pop cap is not greater than current pop
AUTO:00443A23                 fld     [esp+0D8h+var_64]
AUTO:00443A27                 call    RoundFloatTwds0
AUTO:00443A2C                 fistp   [esp+0D8h+var_1C] ; pop increase
AUTO:00443A33                 mov     edx, [esp+0D8h+var_1C] ; pop increase
AUTO:00443A3A                 cmp     edx, 1          ; check if pop increase is at least 1
AUTO:00443A3D                 jle     short loc_443A4A
AUTO:00443A3F                 mov     eax, edx        ; pop increase

AUTO:00443A41                 mov     [edi+4], ax     ; pop increase
AUTO:00443A45                 jmp     loc_443789
AUTO:00443A4A ; ---------------------------------------------------------------------------
AUTO:00443A4A                 mov     eax, 1          ; make pop increase 1 if it is less than 1
AUTO:00443A4F                 jmp     short loc_443A41
AUTO:00443A51 ; ---------------------------------------------------------------------------
AUTO:00443A51                 mov     word ptr [edi+4], 0 ; no pop increase
AUTO:00443A57                 jmp     loc_443789
AUTO:00443A5C ; ---------------------------------------------------------------------------
AUTO:00443A5C                 mov     eax, ebp        ; limit new pop by pop capacity
AUTO:00443A5E                 jmp     loc_44379C
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: 1883
Joined: Sun Apr 27, 2008 2:00 am

Food popup for max-growth fix

Post by Spocks-cuddly-tribble »

Gowron wrote:1. Population Growth

Note: The game will tell you something about "required food for maximum growth", displaying 2 times the system's current pop, but that's just plain nonsense.
:arrow: Food popup for max-growth fix (current pop*2 is wrong)

Code: Select all

trek.exe at 0x417E6 new code 0x17 bytes:

66 89 43 1A 66 8B 81 BC 00 00 00 B9 0A 00 00 00 F7 F1 EB 7E 90 90 90

sub_4423A0 asm changes:

004423E6     66:8943 1A          MOV [EBX+1A], AX    // store food consumption
004423EA     66:8B81 BC000000    MOV AX, [ECX+BC]   // system max population * 10
004423F1     B9 0A000000         MOV ECX, 0A    // divisor 10
004423F6     F7F1                DIV ECX
004423F8     EB 7E               JMP SHORT 442478 // goto set food for max growth
004423FA     909090              NOP
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
xDx
Commander
Commander
Posts: 299
Joined: Sat May 10, 2008 2:00 am
Location: East Coast, USA

Re: Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patt

Post by xDx »

Gowron wrote:

4. Pattern for X-Ray Pulsars

Period length: 4 turns

Explanation:
0 means no effect on this square.
a means -2 scanning strength on this square.
b means -4 scanning strength on this square.
c means -8 scanning strength on this square.
d means -16 scanning strength on this square.
e means -32 scanning strength on this square.
f means -48 scanning strength on this square.
5. Pattern for Radio Pulsars

Period length: 8 turns

Explanation:
0 means no effect on this square.
a means -2 scanning strength on this square.
b means -4 scanning strength on this square.
c means -8 scanning strength on this square.
d means -16 scanning strength on this square.
e means -32 scanning strength on this square.
f means -48 scanning strength on this square.
I am just curious so nobody needs to look into this if it hasn't been found already. Has the location been found for x-ray pulsars, radio pulsars, and nebulas that determine the decrease in scan strength? If it has been found could someone point me to the post as I have not been able to find any information on this. For example I am trying to make it so nebulas or pulsars decrease scan strength by 500 so a fleet can use them the way they were used in the series without having the galaxy cluttered with nebulas or pulsars. Again just curious.
"The only thing we have to fear is fear itself." -- FDR
User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 3194
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patt

Post by Flocke »

Spocks-cuddly-tribble wrote:Also this reminds me on the fog of war (or better unscanned sectors) scan-value fix requested by Flocke, so there is some synergy potential. :wink:
That was my request? :o
Have anotherone, when system population dies, (by starvation, events, bombardements, aliens) and you recolonize, buildings should still be there, that would be cool. Furthermore I remember german vanilla always crashed for me on recolonization but works on continue, dunno if that was fixed. :roll:
Spocks-cuddly-tribble wrote:1 - IIRC it's a very old request from the early days of the 1.0.3 project.
2 - I already considered it, but the time is probably better spend elsewhere.
3 - Upload a 1.0.2 savegame 1 turn before bug and I'll look into it when modifying system takeover code in order to keep main intel & minor special buildings.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Scanning Strength

Post by Spocks-cuddly-tribble »

xDx wrote:Has the location been found for x-ray pulsars, radio pulsars, and nebulas that determine the decrease in scan strength? ...For example I am trying to make it so nebulas or pulsars decrease scan strength by 500 so a fleet can use them the way they were used in the series without having the galaxy cluttered with nebulas or pulsars.
This should make you happy, albeit unfortunately, the actual sought code is still hiding (update of the AlienTFInfo for the broken minor ship limits fix).


Map scan base values for:

Code: Select all

0047CC04                 mov     ebx, 1   // ship without scanner
0047CAE9                 mov     ebx, 5   // ship scanner
0047D015                 mov     ebx, 0Ah // station(/scanner)
0047C9C5                 mov     ebx, 0Fh // star system(/scanner)
Anomaly effect base values:

Code: Select all

0047C94B                 sub     ebp, 8  // neutron star
0047C924                 sub     ebp, 40h // nebula (1 byte signed, see below)
0047C88D                 mov     ebx, 0FFFFFFE0h // black hole (-32)
0047C8D6                 mov     ebx, 0FFFFFFF0h // X-ray pulsar (-16)
00590F7C-00590FCB        -> 20 four byte values  // radio pulsar
This code supports nebula effects of 128 or more: (hex locations)

Code: Select all

0x7BD1E   8168 40 40000000   SUB DWORD [EAX+40], 40
0x7BD25   83C0 04            ADD EAX, 4
0x7BD28   9090               NOP
The area mechanisms are somewhat intricate, but the black hole is quite easy:

Code: Select all

0047C893                 mov     edx, 1  // black hole effect area, 0 = own sector only
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
xDx
Commander
Commander
Posts: 299
Joined: Sat May 10, 2008 2:00 am
Location: East Coast, USA

Re: Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patt

Post by xDx »

This makes me very happy. More than I asked for actually. :) Since I can change scan values of scanners I can live with a max value of 255 for nebulae :wink: Nice work SCT everything works perfectly. Many thanks.
"The only thing we have to fear is fear itself." -- FDR
Post Reply

Return to “Pop Growth, Terraforming Costs, Trade Goods, Pulsar Patterns”