Economic and Military Score (Overflow Fix)

Economic and Military Score Overflow Fix; support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 723
Joined: Sun Apr 27, 2008 2:00 am

Economic and Military Score (Overflow Fix)

Post by Spocks-cuddly-tribble » Mon Nov 14, 2011 2:02 pm

Turner wrote:Botf seems to have a problem with the correct calculation of the score from an empire, if the cumulative value of these empire exceeds a specific threshold. If this happens, the calculation of the score begins again with zero.
This does affect:

- score percentages (intel screen - empire status)
- score graph (end game screen)
- endscore points after winning the match
- some espionage reports
- AI behavior



:arrow: Military Score (sub_44EE20)
Turner wrote:Value of the ships (without colony ships) + (Value of all stations * 0,3) + Value of all orbital batteries and shield generators
An excellent analysis, pretty accurate, except for the cumulated build cost of the stations, which gets divided by systems held; and OB & SH costs are divided by 2.

Code: Select all

-> stations
0044EF65                 div     ecx  // divide cumulated build cost of the stations by systems held

-> ships
loc_44F0A4            // add build cost if ship function is 0-4 or 9 = no colony ships

-> buildings
0044EFF6                 cmp     dl, 13h   // check building output ID -> SH
0044F0F3                 cmp     dl, 11h   // check building output ID -> OB
0044F011                 shr     eax, 1    // divide building costs by 2
Turner wrote:I've boosted the price for a sovereign up to 65535 and so I've needed only 21 of them to exceed the threshold... close by 1310500
Again pretty accurate, it's exactly 1310700 = 65535 (2 byte word/unsigned) * 20

Code: Select all

0044F035                 mov     ecx, 14h    // divide end result by 20
Consequently the simplest solution, without loss of data reliability for low tech games, would be a divisor adjustment to the prise of the cheapest of the above listed reference objects (default 250 = OB / SH build cost [500] / 2).


However, we can do even better. [empsInfo+1B4] already stores the cumulated build cost of war fleet (ship functions 0-4) i.e. the effective offensive firepower or military dangerousness of empires. :idea: Using this should help the AI to determine times for aggressive and/or demanding behavior (provided there is an actual ratio of build costs & fighting capacities of war ships).

Code: Select all

trek.exe at 0x4E288 new code 0xD bytes:

57 8B 9A B4 01 00 00 E9 A1 01 00 00 90

asm code:
0044EE88     57              PUSH EDI
0044EE89     8B9A B4010000   MOV EBX, [EDX+1B4] // empsInfo war fleet cost
0044EE8F     E9 A1010000     JMP 44F035 // goto end divisor at 0x4E436
0044EE94     90              NOP
-> cheapest reference object wrt the divisor is now the cheapest war ship (default 370 = build cost of romulan scout 1)
-> new game turn 1 empire status doesn't display military = 100% (matter of no importance)


Following code was meant to be used in the next ECM update:

Code: Select all

trek.exe at 0x4E288 new code 0x16 bytes:

57 8B 9A B4 01 00 00 8B C3 D1 E8 03 D8 C1 EB 09 E9 A5 01 00 00 90

asm code:
0044EE88     57              PUSH EDI
0044EE89     8B9A B4010000   MOV EBX, [EDX+1B4] // empsInfo war fleet cost
0044EE8F     8BC3            MOV EAX, EBX
0044EE91     D1E8            SHR EAX, 1   //  get 50% via div 2
0044EE93     03D8            ADD EBX, EAX   //  add 50% = *1.5
0044EE95     C1EB 09         SHR EBX, 9   //  *1.5 / 2^9 (512) = divide by 341.333
0044EE98     E9 A5010000     JMP 44F042  // skip end divisor, result already in bx
0044EE9D     90              NOP

:arrow: Economic Score (sub_44EC20)

Economic Score = [(total credits / 10) + (income * 10) + current food, industry, energy, research & intel output of all systems held] / 4

Code: Select all

0044EC62                 mov     ecx, 0Ah  // divisor for total credits from [empsInfo+98h]

0044EC73                 lea     eax, [edx*4]  // 4* income from [empsInfo+9C]
0044EC7A                 add     eax, edx   // 4* income + income = 5* income
0044EC7C                 add     eax, eax  // double (5* income) = 10* income

-systems held / read systInfo loop-
0044EC9E                 add     ecx, [eax+2ACh]  // Food output total after bonuses 
0044ECA6                 mov     esi, [eax+2C4h]  // Industry output total after bonuses
0044ECAC                 mov     bx, [eax+2B6h]  // Energy output total after bonuses
0044ECB3                 mov     ebp, [eax+2C8h]  // Research output total after bonuses
0044ECBB                 mov     ebx, [eax+2D8h]  // Intel output total after bonuses

0044ECD9                 shr     ecx, 2   // end divisor 2^2 = 4
Max result to prevent overflow -> 65535 (2 byte word/unsigned)

Needless to say that we, as well as the AI, really don't care about the totally unrelated food, energy, research and intel outputs. :?


As another example, here is how the issue was planned to be treated in the next ECM update:

Economic Score = [(total credits / 32) + income + (current + nominal -industry output of all systems held / 8 )] / 8

Code: Select all

trek.exe at 0x4E06A new code 0x72 bytes:

E8 05 90 90 89 C1 8B 53 04 90 90 90 90 90 90 90 90 90 90 90 03 CA 8B 46 50 E8 78 CE 0C 00 89 C2 85 C0 74 46 0F BF 02 69 D8 28 03 00 00 A1 C8 36 5A 00 01 D8 8B 98 C4 02 00 00 03 98 90 01 00 00 C1 EB 03 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 89 D0 01 F1 E8 D6 CA 0C 00 90 90 89 C2 01 D9 85 C0 75 BA 31 C0 8A 04 24 C1 E9 03

asm code changes:
0044EC69     C1E8 05           SHR EAX, 5 // total credits /2^5 = /32
0044EC6C     9090              NOP

0044EC73-44EC7D     90         NOP
0044EC7E     03CA              ADD ECX, EDX // income

0044EC9E     8B98 C4020000     MOV EBX, [EAX+2C4]  // current industry output
0044ECA4     0398 90010000     ADD EBX, [EAX+190]  // add nominal industry output
0044ECAA     C1EB 03           SHR EBX, 3   // divide by 2^3 = 8
0044ECAD-44ECC0    90          NOP

0044ECCA     9090              NOP

0044ECD9     C1E9 03           SHR ECX, 3  // divide end result by 2^3 = 8
I.e. sum of:
+ income / 8
+ total credits / 256
+ for all systems held [arithmetic average of current & nominal industry output] / 32

Income / Industry ratio = 4:1 (for ship scrap resp. trade goods 1:1 mods, this can be up to 1:1, of course)



:!: Warning :!:

Albeit the displayed economic & military percentages are based on the results of sub 44EC20 & 44EE20, they are biased (i.e. incorrect) due to some distracting influences. Therefore, it is to examine whether the approach of lower base values requires further adjustments.

Also note there is a mod independent bug when meeting an other empire before turn 3. In that case the empire status intel screen shows just question marks instead of the percentage.
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 723
Joined: Sun Apr 27, 2008 2:00 am

Total Score & Power Graph

Post by Spocks-cuddly-tribble » Mon Jul 23, 2012 12:35 pm

Based on the above explained economic and military scores, sub_506CA0 calculates the total score as follows:

[100 - (Turn Number / 10) + (economic score * 0.5) + (arithmetic average of the last 10 turn military scores * 0.25)]

* [84 +1 per higher resp -1 per lower opponent starting level] % (e.g. T1 vs. 4 * T5 = 100% resp T5 vs. 4 * T1 = 68%)

- [3.75 * difficulty level lower 5 aka impossible] % (e.g. simple -15% or * 0.85)

Code: Select all

00506CBB                 mov     edx, 64h // base value 100
00506CAD                 mov     ecx, 0Ah // divisor for turn number

multipliers for:
(8 byte floats)
ds:583298 economic score (0.5) at 0x181098
ds:5832A0 military score (0.25) at 0x1810A0
(4 byte float)
ds:5832A8 lower difficulty level penalty (3.75) at 0x1810A8
When lowering economic and military score to prevent overflows (via increasing of end divisors or altering of the calculations) just increase the corresponding multipliers by the same factor to keep the total score on the default level.

By default total credits and build costs of warships influence the total score by the same factor of /80 = /10 /4 *0.5 = /20 *0.25


Sub_44E810 stores up to 250 snapshots of increases of the total score (i.e. current score - starting score) as base for the power graph.

Two issues with the power graph: (not true for total score/famehall)

- total score & snapshots are loaded/stored as two byte values i.e. max score to prevent power graph overflow is 65535
- [empsInfo+1B4] (warfleet construction cost) is not set when BotF calculates the starting score, thus the above military score modification sets it too low, leading to a confused power graph

The last power graph snapshot value can be displayed via map ai data type F 'Game Statistics':
viewtopic.php?p=34204&sid=2772507a5febf ... 732#p34204

Tech score = sum of all tech levels + highest tech level + lowest tech level (i.e. they count twice)

- military, economic & tech score, store each the ranks and the top ranked empire ID
- like the military score, economic score stores the last 10 turn scores, but they don't seem to be used


Remaining Problem:

The score percentages of the empire status intel screen seem to be bugged. But solving this I leave to other afc members (what the hell are they lurking here for^^ :wink: ).

Code: Select all

sub_4BF0A0 -> sub_4BE528
004BE714                 mov     edx, 64h // percentage factor loaded as divisor into FPU
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

Post Reply

Return to “Economic and Military Score Overflow Fix”

Who is online

Users browsing this forum: No registered users