Raiding Percentages

Raiding Percentages; 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

Raiding Percentages

Post by Gowron » Sat Nov 15, 2008 1:11 pm

This topic explains how raiding percentage calculation can be modified.
"Raiding percentage" refers to the percentage that is displayed when a task force is given the order to raid nearby systems.

The displayed percentage is the sum of three values:
1. the empire-specific base value,
2. the crew experience bonus (major empires only),
3. the task force size bonus (major empires only).


1. Empire-specific base values

The base values are stored in trek.exe as 4-byte integers. They depend on the empire which performs the raid.

Cardassian Base Value
position: 0x18E324
default value: 10

Federation Base Value
position: 0x18E328
default value: 5

Ferengi Base Value
position: 0x18E32C
default value: 30

Klingon Base Value
position: 0x18E330
default value: 20

Romulan Base Value
position: 0x18E334
default value: 15

Minor Race Base Value
position: 0x18E338
default value: 40

The pointer to the base offset (where the whole 24-byte data group starts) is stored at 0x68BFF. It can be changed to something else (wherever you can free up some space in trek.exe) to avoid the collision with the colony values. EDIT: The actual pointer to the base offset for empires (20-byte data group at ds:590524) is at 0x68BE9. 0x68BFF just points to the minor base value (ds:590538).


2. Crew Experience Bonus

This bonus is only effective for ships with the AI role "destroyer". This role is determined at position 0x68BA2 (default value: 01 = destroyer) and can be changed to a different role. By alteration of the code, one can extend this bonus to more than one ship role.

The amount of bonus points per crew experience level is stored at position 0x68BA9 (default value: 10).


3. Task Force Size Bonus

Each ship in the raiding task force adds another bonus of 5%.
To calculate this, the task force size (stored in edi) is multiplied by 5 this way:

Code: Select all

position  hex    asm
0x68BE0 89F8   mov eax, edi  // eax = edi
0x68BE2 C1E702 shl edi, 02   // edi *= 4
0x68BE5 01C7   add edi, eax  // edi += eax
The content of eax is overwritten directly afterwards, so it's not important to keep the first step. Replacing all three steps by a multiplication statement allows any desired value for the bonus.
Last edited by Gowron on Tue Mar 24, 2009 6:43 pm, edited 1 time 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 » Sat Nov 15, 2008 1:41 pm

Spocks-cuddly-tribble wrote:
Gowron wrote:The amount of bonus points per crew experience level is stored at position 0x68BA9 (default value: 10).
You mean for every Exp. Level above "Green", right?
Yep, basically it's just a multiplication of the experience level (not the same as the number of pips) by 10.

Green = 0
(...)
Legendary = 4

That's a maximum experiene bonus of 40% (per ship).
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.

User avatar
Thunderchild
Ensign
Ensign
Posts: 28
Joined: Wed Apr 30, 2008 2:00 am

Post by Thunderchild » Thu Nov 20, 2008 6:25 pm

Is there a way to stop the raiding ships getting credits if the raided one has no more money and even in negative? I don't think its fun because you loose a game because your enemy is stealing thousands of credits while you haven't this money.

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

Post by Spocks-cuddly-tribble » Wed Dec 09, 2009 2:11 pm

Thunderchild wrote:Is there a way to stop the raiding ships getting credits if the raided one has no more money and even in negative?
This code will not prevent a "credit deficit" from happening, but it puts the stops on bizarre abuse:

:arrow: Raid fix wrt bankrupt empires

Code: Select all

trek.exe at 0x689D0
replace:
BA 01 00 00 00 31 C0 88 E9 8A 44 24 3C D3 E2 85 D0 0F 84
with:
0F B6 C5 69 C0 BC 01 00 00 05 30 1B 5B 00 83 38 01 0F 8C


at asm-4695D0:
movzx   eax, ch
imul    eax, 1BCh
add     eax, offset save_EmpsInfo+98h
cmp     dword ptr [eax], 1
jl      loc_46954D
So any empire which shows a credit deficit, before current turn raids, is protected from further thefts. It'd be more accurate to stop after the deficit causing raid, resp. zero credits, but I don't know where the raid-amounts register (i.e. operating credit pool) is stored.



:arrow: How to edit raiding defense structure - (default: Shield Generator)

In trek.exe at 0x68A08 is the building Output ID (default: 0x13-Shield per energy tech)

The value at 0x68A1F (0F) gets subtracted from the Task Force Raiding Percentage.
-> signed, max value 7F (without code altering)

NOTE energy requirement & output-strength in edifice.bst get ignored. But I didn't look into possible bugs like this.

At 0x6CCEE (0x14-Shield Generator) is the Building ID for the "hindered raid" message. This is not a check, it just reads the building name, regardless of presence.


Orbital Batteries & planetary Scanners also decrease the Raiding Percentage:
  • -1% per powered OB
  • -[edifice output * 3]% for Scanners
  • -20% for an Outpost/Starbase (at 0x68A06)


:arrow: Overflow Bug

As you probably know, systems (sectors) are raided (scanned) from top down, each line left to right i.e. in the following order:
  • 1 | 2 | 3
    4 | 5 | 6

    7 | 8 | 9
(with the Task Force located in sector 5)

The problem is that the effect of raiding defense structures (OBs, SH & Scanners) applies as well (& incremental !) to all following raiding targets, even from buildings located in invalid systems (your own or that of another empire if you have a treaty).

An example of the worst case scenario for SHs (assuming there is no overflow limit):

Say sector 9 is raiding target and sectors 1-8 are your own systems with a SH each. Now the enemy system 9 is protected by your own 8 SHs (vanilla 8*15) plus its own defense of course. :?

Overflow also corrupts "hindered raid" messages i.e. added to wrong systems or credits/OBs displayed twice instead of a valid message.



:arrow: raid messages - (0 credits = no message)

"%s hindered raid" -> lexicon entry 510 (see also above)

Displayed if there is either a Scanner (Output ID 0x1D-Scan range) or a SH (0x13). Both on the same system means a message corruption i.e. credits/OBs displayed twice instead. This is caused by code for the unused message %s and scanners hindered raid operations(509).

"All trade income from %s was seized." -> lexicon entry 499

Displayed if Production Queue is empty or an item is finished. Free minor systems display it always. I'm not sure if it affect the actual amounts.
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

Raiding Bugfixes

Post by Spocks-cuddly-tribble » Sat Feb 18, 2012 3:10 pm

As explained above, the massively flawed raiding code falsifies system defense values and therewith effective raiding percentages (after system defense), underlying system credit outputs, raiding amounts & messages and it disables the '% raiding' building bonus and a system blockade feature.



:arrow: '% raiding' Building Output Type Fix (empire wide bonus for all fleets)

Note that
  • when powering on/off displayed percentages will be updated next turn (just cosmetics, it's the same phenomenon as with the ground defense bonus)
  • as a side effect this fixes missing % raiding crew experience and task force size bonuses for minor races (with the minor base value loaded via empire pointer index 5)
  • this broken building bonus fix is technically independent from this topic

Code: Select all

1.) trek.exe at 0x39DD5 change 7 bytes to: 33 C9 89 4C 10 02 90

2.) at 0x68BBE new code 0x1B bytes:

0F B6 40 34 3C 05 72 04 B0 05 EB 0F 69 D0 BC 01 00 00 0F B7 92 92 1B 5B 00 03 EA

-asm changes:
0043A9D5   33C9         XOR ECX, ECX
0043A9D7   894C10 02    MOV [EAX+EDX+2], ECX  // clear empsInfo % raid area
0043A9DB   90           NOP

sub_469760:
004697BE     0FB640 34         MOVZX EAX, BYTE [EAX+34]  // TF owner
004697C2     3C 05             CMP AL, 5
004697C4     72 04             JB 4697CA
004697C6     B0 05             MOV AL, 5   // set minor index 5
004697C8     EB 0F             JMP 4697D9
004697CA     69D0 BC010000     IMUL EDX, EAX, 1BC
004697D0     0FB792 921B5B00   MOVZX EDX, WORD [EDX+5B1B92]  // empsInfo+0xFA
004697D7     03EA              ADD EBP, EDX
The following fixes 1-4 are to apply together.


1. Systems Defense Bug + Shiels Message Overflow Fix (sub_469470)

Code: Select all

trek.exe at 0x688B9 - 0x68B3C new code 0x284 bytes:

8B 40 0C C1 C0 10 89 44 24 3C 90 8D 41 FF 85 C0 0F 8C B2 00 00 00 89 C3 8D 42 FF 85 C0 0F 8C AC 00 00 00 89 44 24 18 E8 CB 43 FD FF 41 48 39 C1 0F 83 A0 00 00 00 E8 EC 43 FD FF 42 48 89 4C 24 08 39 C2 0F 83 9A 00 00 00 89 D0 8B 6C 24 08 89 44 24 1C 89 5C 24 10 39 EB 7F 5B 8B 44 24 18 8B 4C 24 1C 89 44 24 38 39 C8 7F 3A 8B 44 24 10 89 04 24 8B 44 24 38 89 44 24 04 89 E0 89 E2 E8 74 45 FD FF 89 C3 89 44 24 34 89 F8 E8 D7 16 01 00 85 C0 75 5A 8B 5C 24 38 43 8B 6C 24 1C 89 5C 24 38 39 EB 7E C6 8B 44 24 10 40 8B 54 24 08 89 44 24 10 39 D0 7E A5 83 C4 40 5D 5F 5E 59 5B C3 88 5C 24 3C E9 43 FF FF FF 31 C0 E9 47 FF FF FF 31 C0 E9 4D FF FF FF E8 1C 43 FD FF 8D 48 FF E9 53 FF FF FF E8 3F 43 FD FF 48 E9 5D FF FF FF 8B 43 0A C1 F8 10 83 F8 FF 74 9B 69 C0 28 03 00 00 8B 1D C8 36 5A 00 8A 4C 24 3C 01 C3 84 C9 74 1F 8A 6B 4C 80 FD 05 73 17 BA 01 00 00 00 31 C0 88 E9 8A 44 24 3C D3 E2 85 D0 0F 84 66 FF FF FF 0F BF 03 E8 A5 D2 FD FF 89 44 24 20 8B E8 8B 44 24 34 8B 40 06 C1 F8 10 83 F8 FF 74 03 83 C5 14 BA 13 00 00 00 0F BF 03 E8 EC BC FD FF 85 C0 74 08 B8 01 00 00 00 83 C5 0F 89 44 24 28 0F BF 03 E8 04 B6 FD FF 89 44 24 14 8D 14 40 03 EA 31 C0 31 D2 8A 43 4C 66 8B 57 34 39 D0 0F 84 05 FF FF FF 89 D1 31 C0 BA 01 00 00 00 8A 43 3F D3 E2 85 D0 0F 84 EF FE FF FF 66 83 7B 44 FF 0F 84 E4 FE FF FF 8A 43 4C 3C 05 72 14 3C 23 77 10 66 83 F9 05 72 0A 66 83 F9 23 0F 86 C9 FE FF FF 80 7B 4C 23 0F 85 BE 00 00 00 31 D2 31 C0 66 8B 57 34 66 8B 43 44 E8 E1 2B FD FF 85 C0 0F 85 A6 FE FF FF BA 48 0C 00 00 B8 84 A8 57 00 E8 3A E9 09 00 89 C2 B9 64 00 00 00 C1 FA 1F F7 F9 03 EA 2B F5 0F 8E A3 FE FF FF 8B 54 24 2C B8 00 03 00 00 E8 56 FB FE FF 89 C5 89 44 24 24 89 F0 90 90 8B 54 24 3E 50 8A 5B 4C 8B 4C 24 38 52 0F BF 07 8B 49 0A 50 C1 F9 10 8B 54 24 38 31 C0 8A 42 08 81 E3 FF 00 00 00 89 C2 89 E8 E8 5D 2E 00 00 8B 55 20 8B 44 24 28 8B 4C 24 30 89 42 3C 83 F9 05 7E 07 8B 44 24 20 89 42 38 83 7C 24 30 06 7E 0A 83 7C 24 14 00 74 03 D1 62

-asm changes:

004694B9   8B40 0C         MOV EAX, [EAX+C]
004694BC   C1C0 10         ROL EAX, 10
004694BF   894424 3C       MOV [ESP+3C], EAX
004694C3   90              NOP

004695F3   8BE8            MOV EBP, EAX

00469604   83C5 14         ADD EBP, 14

00469616   74 08           JE 469620  // clear shields marker fix

0046961D   83C5 0F         ADD EBP, 0F

00469633   03EA            ADD EBP, EDX

004696C2   03EA            ADD EBP,EDX  // system defense + random 0-99
004696C4   2BF5            SUB ESI, EBP 
004696C6  ^0F8E A3FEFFFF   JLE 46956F  // exit

004696E2   9090            NOP
004696E4   8B5424 3E       MOV EDX, [ESP+3E]  // TF sector ID

0046973B   D162 3C         SHL DWORD [EDX+3C], 1   // SH message fix
Note: The 'Raid fix wrt bankrupt empires' (see above) and previous changes to system defense have to be redone after this!

System defense values subtracted from the raiding percentage: (unchanged)

Code: Select all

004695F3   8BE8            MOV EBP, EAX   // active orbitals
00469604   83C5 14         ADD EBP, 14      // outpost/starbase
0046961D   83C5 0F         ADD EBP, 0F    // shield generator
00469630   8D1440       LEA EDX, [EAX+EAX*2]  // scanner output *3 (minor race bug)
004696B8   B9 64000000   MOV ECX, 64  // random system defense bonus 0-99
2. Stolen Credits Calculation Fix

Features:
  • corrected underlying system credit outputs including trade routes & trade goods, thus rich systems/races are more profitable than just populous but poor systems - assumed income of minor races is pop/4 (equal to the ferengi default 0.25) +16 credits per incoming trade route
  • stolen credits = ([system credit output * effective raiding percentage] / 256), effect limit at 256% raiding (after system defense) for the whole system credit output, albeit greater percentages are still useful when raiding more than one system
  • enabled broken 'system blockade' feature (task force sector) - skips benefit of all trade routes(outgoing & incoming) and trade goods(even the forced due to 'credit deficit') maximizing economic damage for system owner but with potentially lower raiding amounts


Code: Select all

trek.exe at 0x5EC48 - 0x5ED46 new code 0xFF bytes:

0F B7 5F 0E B8 28 03 00 00 0F AF D8 03 1D C8 36 5A 00 33 F6 89 77 4C 8D 2C 18 8B 53 40 85 D2 75 20 89 C8 E8 30 BF 0B 00 89 C1 85 C0 75 C8 8B 44 24 20 E8 51 97 FF FF 83 C4 28 5D 5F 5E 5A 59 5B C3 80 7B 4C 05 72 0E C1 EA 02 0F B6 45 E0 D0 E0 8D 2C C2 EB 2F 8B 03 66 3B 47 28 75 05 FE 45 F4 EB 13 80 BB 80 00 00 00 05 75 0A 8B 45 9C E8 55 10 00 00 8B F0 8B 03 33 D2 42 E8 09 2F FE FF 8B 6D 94 03 EE 8B 47 48 84 E4 74 07 83 E0 07 03 E8 EB 0E 0F AF E8 C1 ED 08 75 06 83 E0 03 8D 68 01 85 F6 74 09 3B EE 7C 0D 33 C0 89 47 28 80 7B 4C 05 73 40 90 90 31 C0 8A 43 4C 69 C0 BC 01 00 00 05 98 1A 5B 00 01 A8 B8 01 00 00 66 8B 59 04 66 83 FB 05 73 16 31 C0 66 89 D8 69 C0 BC 01 00 00 05 98 1A 5B 00 01 A8 98 00 00 00 89 6F 4C E9 2E FF FF FF 80 79 04 05 73 F2 80 7B 30 0A 74 CC

-code changes:

0045F848     0FB75F 0E       MOVZX EBX, WORD [EDI+E]  // system ID
0045F84C     B8 28030000     MOV EAX, 328
0045F851     0FAFD8          IMUL EBX, EAX
0045F854     031D C8365A00   ADD EBX, [5A36C8]  // systInfo
0045F85A     33F6            XOR ESI, ESI
0045F85C     8977 4C         MOV [EDI+4C], ESI
0045F85F     8D2C18          LEA EBP, [EAX+EBX]

0045F889   807B 4C 05          CMP BYTE [EBX+4C], 5
0045F88D   72 0E               JB 45F89D
0045F88F   C1EA 02             SHR EDX, 2   // pop/4
0045F892   0FB645 E0           MOVZX EAX, BYTE [EBP-20]  // systInfo+308
0045F896   D0E0                SHL AL, 1
0045F898   8D2CC2              LEA EBP, [EDX+EAX*8]  // + incoming trade routes *16
0045F89B   EB 2F               JMP 45F8CC
0045F89D   8B03                MOV EAX, [EBX]  // system ID
0045F89F   66:3B47 28          CMP AX, [EDI+28] // taskforce position system ID
0045F8A3   75 05               JNZ 45F8AA
0045F8A5   FE45 F4             INC BYTE [EBP-C]   // systInfo+31C system blockade marker
0045F8A8   EB 13               JMP 45F8BD
0045F8AA   80BB 80000000 05    CMP BYTE [EBX+80], 5  // trade goods ?
0045F8B1   75 0A               JNZ 45F8BD
0045F8B3   8B45 9C             MOV EAX, [EBP-64]  // systInfo+2C4 industry output
0045F8B6   E8 55100000         CALL 460910  // trade goods calculation
0045F8BB   8BF0                MOV ESI, EAX
0045F8BD   8B03                MOV EAX, [EBX]  // system ID
0045F8BF   33D2                XOR EDX, EDX
0045F8C1   42                  INC EDX
0045F8C2   E8 092FFEFF         CALL 4427D0  // system credits calculation (no trade goods)
0045F8C7   8B6D 94             MOV EBP, DWORD [EBP-6C]  // systInfo+2BC system credits
0045F8CA   03EE                ADD EBP, ESI
0045F8CC   8B47 48             MOV EAX, [EDI+48]  // taskforce raiding %
0045F8CF   84E4       TEST AH, AH    // effect limit 256 %
0045F8D1   74 07      JE 45F8DA
0045F8D3   83E0 07    AND EAX, 7    // random bonus 0-7 credits
0045F8D6   03E8       ADD EBP, EAX   // system credits + 0-7 random
0045F8D8   EB 0E      JMP 45F8E8
0045F8DA   0FAFE8              IMUL EBP, EAX
0045F8DD   C1ED 08             SHR EBP, 8  // divide by 256
0045F8E0   75 06               JNZ 45F8E8
0045F8E2   83E0 03             AND EAX, 3  // random 0-3
0045F8E5   8D68 01             LEA EBP, [EAX+1] // minimum 1-4 credits
0045F8E8   85F6                TEST ESI, ESI
0045F8EA   74 09               JE 45F8F5
0045F8EC   3BEE                CMP EBP, ESI
0045F8EE   7C 0D               JL 45F8FD
0045F8F0   33C0                XOR EAX, EAX
0045F8F2   8947 28             MOV [EDI+28], EAX  // 0 = trade goods message
0045F8F5   807B 4C 05          CMP BYTE [EBX+4C], 5
0045F8F9   73 40               JNB 45F93B
0045F8FB   9090                NOP

0045F93B   8079 04 05    CMP BYTE [ECX+4], 5
0045F93F  ^73 F2         JNB 45F933
0045F941   807B 30 0A    CMP BYTE [EBX+30], 0A
0045F945  ^74 CC         JE 45F913
2.b Option to set the effect limit to 128 % (advantage for attackers)

Code: Select all

after main fix in trek.exe at 0x5ECCF change 0x11 bytes to:

83 F8 7F 7E 06 83 E0 07 83 C0 7F 0F AF E8 C1 ED 07

0045F8CF   83F8 7F             CMP EAX, 7F  // effect limit 127 %
0045F8D2   7E 06               JLE 45F8DA
0045F8D4   83E0 07             AND EAX, 7  // random 0-7
0045F8D7   83C0 7F             ADD EAX, 7F  // limit 127 + 0-7 random

0045F8DD   C1ED 07    SHR EBP, 7    // divide by 128
3. Clear Blockade Marker Fix [systInfo+31C]

Code: Select all

trek.exe at 0x43C19 new code 0x10 bytes:

33 D2 89 93 1C 03 00 00 B2 C0 D3 E2 8B C3 90 90

-asm-
00444819     33D2             XOR EDX, EDX
0044481B     8993 1C030000    MOV [EBX+31C], EDX
00444821     B2 C0            MOV DL, C0
00444823     D3E2             SHL EDX, CL
00444825     8BC3             MOV EAX, EBX
00444827     9090             NOP
4. Raid Message Fixes (lexicon.dic entries 499, 500, 509 & 510; trade income, shield generator [and scanners])

First reset 0x6CCFB to 75 23 and lexicon.dic entry 510 back to default if changed.

Code: Select all

at 0x6CD3C change 90 13 -> 20 15

at 0x6CDEE & 0x6CF18 change BB 80 00 00 00 05 to -> 7D 28 00 90 90 90

-asm changes:
0046D939   8D8424 20150000  LEA EAX, [ESP+1520]

0046D9ED   837D 28 00       CMP DWORD [EBP+28], 0  // trade goods message
0046D9F1   909090           NOP

0046DB17   837D 28 00      CMP DWORD [EBP+28], 0  // trade goods message
0046DB1B   909090          NOP
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

Post Reply

Return to “Raiding Percentages”

Who is online

Users browsing this forum: No registered users