AI & Difficulty Level

AI & Difficulty Level; support/discussion/questions

Moderator: thunderchero

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

AI & Difficulty Level

Post by Spocks-cuddly-tribble »

As we all know, the BotF AI indeed is far more artificial than intelligent, and I am afraid we cannot really make the AI smarter.

However, here are some nice examples of what can be done:
  • 1. AI Starting Credits on Hard & Impossible
    2. The AI Interval Credits Cheat
    3. AI Total Income Bonuses on Difficulty Level 2-4
    4. Adjusting AI Starting Credits
    5. Rebalancing AI Credits Income
    6. Adapting AI Trade Goods (to the AI building behaviour)
    7. Tuning AI Morale
    8. Disabling the system-specific Random Events for AI
    9. Determining AI control of Ships / Empires
    10. Protecting the AI from Neutron Stars
    11. Additional Starting Ships & Systems (+pop) for AI
    12. Modifying AI Terraforming Speed / Behavior
    13. Editing AI Fleet Buildup / Ship Upgradings
    14. Controlling the Amounts of AI Gifts, Offers & Demands
    15. Eliminating the Difficulty Level Bias in Minor Race Evolution
    16. Remaining to-do's (within the restrictions of the BotF AI coding)
Sections 1-3 describe the default AI cheats, 4+ modding options (12-15 have been covered before, but are listed for completeness).


EDIT: ---> List of further developments on the subject:

-> Adding Custom AI Research Bonuses
-> Speeding Up AI System Upgrades
-> Increasing the AI's offensive ground combat strength
-> Strengthening the AI Ships in Tactical Combat (via Accuracy/Defense Bonuses)





:arrow: 1. AI Starting Credits on Hard & Impossible (sub_451D44)


Based on the Tech 1-5 starting credits the AI gets a bonus of 50% on "hard" & 100% on "impossible":

Code: Select all

-> Hard (level 4):
451E2D                 lea     eax, ds:0[edx*4] // 4 * credits
451E34                 sub     eax, edx         // 3 * credits
451E36                 mov     edx, eax
451E38                 sar     edx, 1Fh
451E3B                 sub     eax, edx
451E3D                 sar     eax, 1           // 3/2 * credits
= starting credits approximately * 1.5 (rounded down)

-> Impossible (level 5):
451E6A                 add     ebp, ebp // double starting credits




:arrow: 2. The AI Interval Credits Cheat (broken feature -> savegame bug)


In sub_451D44 (see section 1) there is also a turn interval value set for a periodic task:

Code: Select all

451E4D                 mov     eax, 64h // hard
451E65                 mov     eax, 3Ch // impossible
Note the internal AI turn deviation of 2 turns e.g. for value 100(hard): player turns = 102, 202, 302

On said turns, sub_451E90 adds 20 times the current income, or a minimum of 1000, to credits for each AI empire:

Code: Select all

451EF5           imul    ecx, [edx+9Ch], 14h // income * 20

minimum bonus (1000 credits):
451E9A           mov     edi, 3E8h
451F02           cmp     ecx, 3E8h
Note the feature doesn't support savegames i.e. for re-loaded games it's gone!






:arrow: 3. AI Total Income Bonuses on Difficulty Level 2-4 (sub_43A434)


This is the AI core cheat in BotF, but since applied to the global income, it greatly imbalances AI vs. AI (cf. sections 5/6) & viewtopic.php?p=56614#p56614

To turn it off just change 75 to EB in trek.exe at 0x399DA.

Code: Select all

-> Easy (level 2): income bonus +50% (rounded down)
43A5FA                 shr     eax, 1
43A5FC                 add     ebp, eax
43A5FE                 mov     [esi], ebp

-> Normal (level 3):     +100% (double income)
43A611                 mov     eax, ebx
43A613                 add     [esi], eax
minimum bonus 100 credits:
43A60C                 cmp     ebx, 64h
43A61E                 mov     eax, 64h

-> Hard (level 4):       +200% (triple income)
43A631                 add     eax, eax
43A63D                 add     [esi], eax
minimum bonus 125 credits:
43A633                 cmp     eax, 7Dh
43A638                 mov     eax, 7Dh

-> Impossible (level 5): +400% (5x income) 
43A64B                 shl     eax, 2
43A65A                 add     [esi], eax
minimum bonus 175 credits:
43A64E                 cmp     eax, 0Afh
43A655                 mov     eax, 0AFh




:arrow: 4. Adjusting AI Starting Credits (sub_451D44)


Nobody in his senses would recommend e.g. more starting credits for a T4/5 klingon player in unmodded BotF. But, since the AI is unable to adapt empire specific advantages and AI vs. AI overall strength seems to be almost only determined by credits, for AI that's a horse of another color. This leads to...


4.1 Implementing Custom AI Starting Credits

The following modification still reads the 2nd 5 values of the Tech 1-5 starting pop & credits data-field for players and takes the unused 4th 5 values for the AI starting credits:

Code: Select all

trek.exe at 0x51199
replace: (26 bytes)
89 33 8B 00 89 43 18 80 FA 20 73 62 B8 01 00 00 00 D3 E0 8B 3D 50 2B 5A 00 89 C1
with:
B5 01 8A CA D2 E5 84 2D 28 2B 5A 00 75 03 8B 70 3C 89 33 8B 00 89 43 18 EB 6A 90


451D99     B5 01             MOV CH, 1
451D9B     8ACA              MOV CL, DL
451D9D     D2E5              SHL CH, CL
451D9F     842D 282B5A00     TEST [5A2B28], CH // if player
451DA5     75 03             JNZ SHORT 451DAA    // skip next
451DA7     8B70 3C           MOV ESI, [EAX+3C] // AI Starting Credits
451DAA     8933              MOV [EBX], ESI        // store credits at [empsInfo+98h]
451DAC     8B00              MOV EAX, [EAX]     // starting pop home systems
451DAE     8943 18           MOV [EBX+18], EAX  // store pop at [empsInfo+B0h]
451DB1     EB 6A             JMP SHORT 451E1D (load alienInfo for starID)
451DB3     90                NOP
4.2 Optimizing the AI difficulty bonus to Starting Credits

Code example for an adjustable bonus percentage per difficulty level above "simple":

Code: Select all

trek.exe at 0x511E7
replace: (25 bytes)
66 A1 44 2B 5A 00 48 66 3D 04 00 77 0C 25 FF FF 00 00 FF 24 85 30 1D 45 00
with:
A0 44 2B 5A 00 48 0F AF 03 6B C0 19 8B D0 C1 FA 1F 33 C9 B1 64 F7 F9 01 03


00451DE7     A0 442B5A00    MOV AL, [5A2B44] (difficulty level)
00451DEC     48             DEC EAX  // difficulty level -1
00451DED     0FAF03         IMUL EAX, [EBX] (AI starting credits)
00451DF0     6BC0 19        IMUL, EAX, 19h  //  % - Bonus
00451DF3     8BD0           MOV EDX, EAX
00451DF5     C1FA 1F        SAR EDX, 1F
00451DF8     33C9           XOR ECX, ECX
00451DFA     B1 64          MOV CL, 64
00451DFC     F7F9           IDIV ECX
00451DFE     0103           ADD [EBX], EAX // update AI empire credits
Bonus percentage in trek.exe at 0x511F2 default +25% (19h)

Note as a replacement for the feature from section 1 this also skips the bugged cheat from section 2.






:arrow: 5. Rebalancing AI Credits Income


As told above, the wide variations of the AI empires global income are a major imbalance factor in BotF, which gets even worse by the flawed AI building behavior / industry usage (see section 6). Responding to this issue, we can adapt the idea from section 4 and read for all AI majors (shared) a difficulty level dependant income multiplier instead of the race-specific income constants (see Credit Output - section 4).
That way, building bonuses & trade route mechanics still keep some diversity between the AI incomes, but we'll try to compensate this in section 6.


5.1 Altering the code (sub_4427D0)

Code: Select all

trek.exe at 0x41ECB
replace: (90 bytes)
8D 14 85 00 00 00 00 31 DB 8B 46 40 89 9C 24 30 02 00 00 89 84 24 2C 02 00 00 DD D9 E8 E8 AB 0D 00 DF BC 24 4C 02 00 00 DF AC 24 2C 02 00 00 D8 8A 58 FC 58 00 DD 9C 24 24 02 00 00 DF 45 44 D8 C9 DC 8C 24 24 02 00 00 8B 8C 24 4C 02 00 00 89 9C 24 50 02 00 00 89 8C 24 4C
with:
83 7E 04 01 75 08 66 A1 44 2B 5A 00 04 04 8D 14 85 00 00 00 00 33 DB 8B 46 40 89 9C 24 30 02 00 00 89 84 24 2C 02 00 00 DD D9 E8 DA AB 0D 00 DF BC 24 4C 02 00 00 DF AC 24 2C 02 00 00 D8 8A 94 9B 44 00 DD 9C 24 24 02 00 00 DF 45 44 D8 C9 DC 8C 24 24 02 00 00 89 9C 24 50


442ACB     837E 04 01         CMP [ESI+4], 1 // AI system ?
442ACF     75 08              JNZ SHORT 442AD9 // if not skip AI-values
442AD1     66:A1 442B5A00     MOV AX, [5A2B44] (difficulty_level)
442AD7     04 04              ADD AL, 4
442AD9     8D1485 00000000    LEA EDX, [EAX*4]
442AE0     33DB               XOR EBX, EBX
442AE2     8B46 40            MOV EAX, [ESI+40]
442AE5     899C24 30020000    MOV [ESP+230], EBX
442AEC     898424 2C020000    MOV [ESP+22C], EAX
442AF3     DDD9               FSTP ST(1)
442AF5     E8 DAAB0D00        CALL 51D6D4 (floating_point_rounding)
442AFA     DFBC24 4C020000    FISTP QWORD [ESP+24C]
442B01     DFAC24 2C020000    FILD QWORD [ESP+22C]
442B08     D88A 949B4400      FMUL DWORD [EDX+449B94] // new data field 449B94
442B0E     DD9C24 24020000    FSTP QWORD [ESP+224]
442B15     DF45 44            FILD WORD [EBP+44]
442B18     D8C9               FMUL ST, ST(1)
442B1A     DC8C24 24020000    FMUL QWORD [ESP+224]
442B21     899C24 50020000    MOV [ESP+250], EBX
The pointer to the base offset (where the whole new 40-byte data group starts, default asm-449B94) is stored at asm-442B0A. It can be changed to something else (wherever you can free up some space in trek.exe).


Old income multipliers data field (20 bytes ; 5 empires * 4 byte floats) at asm-58FC58 i.e. at 0x18da58

Change location -> 40 bytes needed (+20 bytes for 5 AI difficulty level multiplier afterwards)


5.2 Freeing-up code space in trek.exe (example for asm-449B94)

Disable [position2] Crew Experience thresholds (see Crew Experience):

Code: Select all

trek.exe at 0x48F76 replace:
40 3D 40 1F 00 00 7C 16
with:
44 FF 24 85 60 9B 44 00

449B74    mov   eax, [eax+44h]
449B77    jmp   off_449B60[eax*4]
5.3 Inserting the new float data field (5-player races + 5 AI difficulty level) * 4-bytes at asm-449B94:

Code: Select all

trek.exe at 0x48F94
replace: (40 bytes)
3D 88 13 00 00 7C 0C B8 03 00 00 00 FF 24 85 60 9B 44 00 3D DC 05 00 00 7C 0C B8 02 00 00 00 FF 24 85 60 9B 44 00 3D BC
with: 
9A 99 19 3E 66 66 66 3E 00 00 80 3E 33 33 33 3E CD CC 4C 3E CD CC 4C 3E 9A 99 99 3E CD CC CC 3E 9A 99 19 3F 00 00 80 3F
Income multiplier defaults (4 byte floats) -> Note the ultimate editor won't know the new location!

for the player empires card-rom (untouched vanilla values) at 0x48F94
0.15 / 0.225 / 0.25 / 0.175 / 0.2

AI for the difficulty levels 1-5 (shared by all AI empires) at 0x48FA8
0.2 / 0.3 / 0.4 / 0.6 / 1.0

Defaults of the new AI income modifiers apply the default bonuses from section 3 (you should turn this off now) with the romulan income being the base value.






:arrow: 6. Adapting AI Trade Goods (workaround for flawed AI building behaviour)


Very useful information on the AI building behaviour:

=> aibldreq.bin , AI building behaviour (don't forget to remove/disable trade goods in aibldreq.bin)

Gowron wrote:The AI will rush-buy most buildings. On the other hand systems will often just sit there producing nothing.

...also sometimes a system will just "have a break" and do nothing for one or more turns.
Applying Trade Goods (section 3) 1:1 only for AI is the best workaround to get ride of the issue.

As a side effect, this valorizes the whole AI industry, rebalances AI vs. AI, and also therewith the slightly lower AI total income, when using the modification from section 5 instead of the default from section 3, is more than compensated. :)

TradeGoods 1:1 only for AI:

Code: Select all

trek.exe at 0x60390
replace: (45 bytes)
57 8B 43 2C 89 44 24 0C DB 44 24 0C D9 FA 83 EC 08 DD 1C 24 E8 4B C7 0B 00 E8 26 C7 0B 00 DF 7C 24 04 8B 3A 8B 44 24 04 01 C7 89 3A 5F
with:
8B 43 2C 83 79 04 01 74 05 E8 72 F9 FF FF 01 02 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90


460F90     8B43 2C         MOV EAX, [EBX+2C] // industry output
460F93     8379 04 01      CMP [ECX+4], 1 // AI system ?
460F97     74 05           JE SHORT 460F9E // if yes skip next
460F99     E8 72F9FFFF     CALL 460910 (TradeGoodsOutputDisplay/now also player TradeGoods calculation)
460F9E     0102            ADD [EDX], EAX // update Empire Credits
460FA0-460FBC   90         NOP
until
460FBD     83C4 0C         ADD ESP, 0C
Of course, it can be used in combination with:

=> Adjusting trade good output (for players)


The four code changes provided by Gowron are each for:

1-"Credit Deficit" (when upgrading buildings)
2- TradeGoodsOutput_display (player)
3-"Credit Deficit"
4- TradeGoodsOutput_effective


The above AI tweak replaces the code of the 4th alteration.

Code for the forced trade goods in the case of "Credit Deficit" (at asm 46044C-46047E(upgrade) and 460F01-460F25) has not been altered in order to prevent raid abuse of de facto beaten AI empires (provided usage of this Raid Abuse Fix, of course).






:arrow: 7. Tuning AI Morale (-> credit, industry & research output)


Morale, one of the most important resources in BotF - directly affecting credit, industry & research output - also deserves some attention. There are ways to manipulate the starting, base and current (i.e. deterioration mechanics) AI morale:


- The existing AI morale cheats, plus some suggestions for modifications, are explained here.


- Option for a global base morale bonus for all AI systems (default: +10*[difficulty level -1] )

Code: Select all

trek.exe at 0x3E98A
replace: (15 bytes)
8B 51 42 31 C0 C1 FA 10 66 8B 87 F0 02 00 00
with:
0F B7 05 44 2B 5A 00 48 6B C0 0A 66 03 41 58


43F58A     0FB705 442B5A00   MOVZX EAX,WORD [5A2B44]  (difficulty level)
43F591     48                DEC EAX            // difficulty level -1
43F592     6BC0 0A           IMUL EAX,EAX,0A   // [difficulty level -1] * 10
43F595     66:0341 58        ADD AX,WORD [ECX+58]   (base morale)
Note systInfo won't display the bonus, which works in addition to the AI start morale bonus on Impossible!


- In addition to this, here is how to turn off the penalty events (e.g. terrorism) for low morale (rebellious/defiant) AI systems (not to be confused with the system-specific Random Events, cf. section 8 ):

Code: Select all

trek.exe at 0x3EFDE
replace: (31 bytes)
8B 5C 24 2C 8B 96 F4 02 00 00 8D 86 98 02 00 00 83 C2 32 89 44 24 28 89 96 F4 02 00 00 39 D9
with:
83 7E 04 01 74 1B 8D 86 98 02 00 00 89 44 24 28 83 86 F4 02 00 00 32 90 90 90 90 90 90 3B CA


43FBDE     837E 04 01         CMP [ESI+4], 1 // if AI system
43FBE2     74 1B              JE SHORT 43FBFF  // exit
43FBE4     8D86 98020000      LEA EAX, [ESI+298]
43FBEA     894424 28          MOV [ESP+28], EAX
43FBEE     8386 F4020000 32   ADD [ESI+2F4], 32
43FBF5-43FBFA  909090909090   NOP
43FBFB     3BCA               CMP ECX, EDX




:arrow: 8. Disabling the system-specific Random Events for AI


Another bias of difficulty level w.r.t. the AI empires (cf. section 15) are the random events.

Hence, here is how to turn off system events (see Scheme of the Random Events 1.2 - 1.4) for AI systems:

Code: Select all

trek.exe at 0x4B469
replace: (30 bytes)
B9 1E 00 00 00 8A 66 30 8D 9E 98 02 00 00 84 E4 0F 84 0B 01 00 00 8B 43 44 C1 F8 10 83 F8
with:
83 7E 04 01 0F 84 A7 00 00 00 8D 9E 98 02 00 00 80 7E 30 00 0F 84 07 01 00 00 66 83 7B 46


44C069     837E 04 01          CMP [ESI+4], 1    // if AI...
44C06D     0F84 A7000000       JE 44C11A      // exit no events
44C073     8D9E 98020000       LEA EBX, [ESI+298]
44C079     807E 30 00          CMP BYTE [ESI+30], 0 // home system ?
44C07D     0F84 07010000       JE 44C18A
44C083     66 837B 46 FC       CMP WORD [EBX+46], 0FFFC // rebellious ?
Unfortunately, the monsters are still an AI trap. Avoid AI Systems Fix for Monster






:arrow: 9. Determining AI control of Ships / Empires (shortest code example for modders)


via owner race-ID & ds:5A2B28 (PlayerEmpiresBitmask) i.e. without [systInfo+4]

Code: Select all

B5 01            MOV CH, 1
D2E5             SHL CH, CL  //  cl = race-ID
842D 282B5A00    TEST DS:[5A2B28], CH
jump if          jz = AI  //  jnz = player




:arrow: 10. Protecting the AI from Neutron Stars & Black Holes


Since we cannot make the AI aware of neutron stars (AI mass graves in vanilla low tech games), here is how to make neutron stars aware of AI:

Code: Select all

trek.exe at 0x6B076 change 90 to -> 86

AND at 0x6B086
replace: (48 bytes)
00 00 00 00 00 00 00 00 00 00 55 83 EC 34 89 44 24 2C 89 54 24 28 0F BF 00 31 D2 E8 7A DB FD FF 66 8B 50 34 31 ED 66 89 54 24 30 66 83 FA 23 76
with:
55 83 EC 34 89 44 24 2C 89 54 24 28 0F BF 00 33 D2 E8 84 DB FD FF 33 ED 51 66 8B 48 34 66 89 4C 24 34 B5 01 D2 E5 84 2D 28 2B 5A 00 59 90 90 75


46BC75      BA 86BC4600     MOV EDX, 0046BC86 (offset sub_NeutronStar)

46BC86      55              PUSH EBP
46BC87      83EC 34         SUB ESP, 34
46BC8A      894424 2C       MOV [ESP+2C], EAX
46BC8E      895424 28       MOV [ESP+28], EDX
46BC92      0FBF00          MOVSX EAX, WORD [EAX]
46BC95      33D2            XOR EDX, EDX
46BC97      E8 84DBFDFF     CALL 449820 (GTForceList/GWTForce)
46BC9C      33ED            XOR EBP, EBP
46BC9E      51              PUSH ECX
46BC9F      66:8B48 34      MOV CX, [EAX+34]  (owner race ID)
46BCA3      66:894C24 34    MOV [ESP+34], CX
46BCA8      B5 01           MOV CH,1
46BCAA      D2E5            SHL CH,CL
46BCAC      842D 282B5A00   TEST [5A2B28], CH    // AI ?
46BCB2      59              POP ECX
46BCB3      90 90           NOP
46BCB5      75 07           JNZ SHORT 46BCBE
=> Trade Routes, Ship Regeneration, Neutron Stars, Black Holes

:arrow: Protecting the AI from Black Holes





:arrow: 11. Additional Starting Ships & Systems (+pop) for AI


Some examples for:

=> extra starting ships for AI

=> Additional Starting Systems for AI


Option for an AI starting pop bonus on extra starting systems:

=> Tech 1-5 starting pop & credits (first, restore default, if changed)

This keeps the home system start pop value for AI extra systems and reads the (always lower) 3rd 5 values for players only: (->max number of buildings)

Code: Select all

Trek.exe at 0x501A4
replace: (29 bytes)
31 D2 66 8B 94 24 60 01 00 00 8D 04 95 00 00 00 00 01 C2 8B 84 24 34 01 00 00 C1 E2 04
with:
8B 9C 24 50 01 00 00 8B 53 44 6B D2 50 83 7B 04 01 74 03 83 C2 28 8B 84 24 34 01 00 00


450DA4     8B9C24 50010000   MOV EBX, [ESP+150h] // systInfo
450DAB     8B53 44           MOV EDX, [EBX+44h]   // race ID
450DAE     6BD2 50           IMUL EDX, EDX, 50h   // race offset
450DB1     837B 04 01        CMP DWORD [EBX+4], 1 // AI ?
450DB5     74 03             JE SHORT 450DBA // skip next if AI
450DB7     83C2 28           ADD EDX, 28h // player start pop 3rd 5 values
450DBA     8B8424 34010000   MOV EAX, [ESP+134] // starting level




:arrow: 12. Modifying AI Terraforming Speed / Behavior


Instruction can be found here:

=> Modifying AI Terraforming Speed

=> the AI minimum terraform threshold (prevent insufficiently terraformed AI colonies)






:arrow: 13. Editing AI Fleet Buildup / Ship Upgradings


For in-depth information on the subjects, see:

=> AI Fleet Buildup (basics)
=> How the AI decides what ship type to build

=> giving the AI an edge w.r.t. ship upgrading (sections 3.2 & 3.3)






:arrow: 14. Controlling the Amounts of AI Gifts, Offers & Demands


Since all too often the AI tends to offer silly amounts of credits (later stages of game or high tech games), and also some players have complained about too frequent demands in low tech games, here is how to alter the credit amounts:

=> Maximum Amounts for AI Gifts, Offers & Demands to Empires

Given the asm-addresses of all multipliers (8 byte floats) the credits calculations can be adapted - even without assembler knowledge - according to:

( [size value * 0.25] ^2 ) * [current income * 0.05]

As you can see, gift 1 (i.e. size 40) calculates 5 times current income, gift 2 (i.e. size 80) = 20 times, ASO...


Side note - Remember that AI credit feature from section 2?

Adds 20 times current income [EmpsInfo+9C] = gift/offer 2, just to get an impression.


=> AI gift size value for minors - default 20 (Base Amount = 25 times size value, see Gowron)






:arrow: 15. Eliminating the Difficulty Level Bias in Minor Race Evolution


A detailed explanation of this fatal bias (AI empires vs. difficulty level), with step by step instructions how to correct it, can be found in this post:

=> Correcting the Difficuly Level Bias of the Minor Races






:arrow: 16. Remaining to-do's (within the restrictions of the BotF AI coding)


-> Altering Build- & Support- Costs of AI Ships

-> Accelerating AI Outpost/Starbase constuction time (as stopgap for "conflicting orders" which misleads AI to interrupt tasks)

-> Tweaking Planetary Assault AI vs. player (see), see also AI Task Modifiers :idea:

-> In loc_4075A8, there is a broken AI difficulty feature, it sets [edi+1C] to 0 or 1 depending on float data field ds:58AF80 (for difficulty level 2 = 0.5 else blank) vs. a random float. I haven't noticed any ingame effect.
Last edited by Spocks-cuddly-tribble on Fri May 27, 2022 4:31 pm, edited 12 times 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:

Post by Tethys »

These should make the AI a bit harder :D
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Post by Peter1981 »

I can't believe it's taken me two months to finally get round to reading this post properly, but full prais for it SCT this is a brilliant, useful & insightful post! I will make use of every piece of infomation in this post in my TOS MOD. Thanks once again -- truly you deserve the title codemaster




EDIT:

@SCT w.r.t. i tried to implement '10. Protecting the AI from Neutron Stars' however when i ran BotF i got a unceremonial and immediate CTD during turn processing if I sent a ship into a sector containing a neutron star. Sadly there was nothing in the crash.log file.

Spocks-cuddly-tribble wrote:An obvious typo (first byte 68 should be 86). Post edited. :)
thanks -- why did I miss that typo?!? - thanks for the quick responce. \/ \/
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Post by Spocks-cuddly-tribble »

Another workaround for flawed AI building behaviour, which should prevent the AI from getting stuck due to its own misbehavior (since AI is too silly to scrap the unneeded surplus buildings before upgrading):


:arrow: Speeding Up AI System Upgrades

Code: Select all

Trek.exe at 0x5FB5A
replace: (12 bytes)
8B 94 24 84 01 00 00 89 46 0C 3B 94
with:
89 46 0C 83 7D 04 02 75 0E 90 3B 84


46075A     8946 0C          MOV [ESI+C], EAX  // total cost
46075D     837D 04 02       CMP [EBP+4], 2      // if not a player...
460761     75 0E            JNZ 460771       // ...goto finish upgrading
460763     90               NOP
460764     3B8424 88010000  CMP EAX, [ESP+188] // total cost vs. production invested
In the beginning of a game this won't cause significant changes, but the longer a game lasts the better the AI benefits from it. So, in combination with a research modifier (see updated list above), AI should be more competitive in epic games. :)


Also note the faulty AI expansion on enlarged maps should be solved now (see Galaxy Map Size).

-> AI cloak behavior fix :idea:


EDIT: Topic (slightly) renamed to reflect its changed focus.
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
Keldomet
Cadet 1st Year
Cadet 1st Year
Posts: 1
Joined: Wed Feb 01, 2012 8:28 am

Re: AI & Difficulty Level

Post by Keldomet »

Hello, i have a question about the AI income balance, especially the point 5.3 with inserting the new income multipliers.
Am i reading something wrong or is there a error in the replacement code?

" AI for the difficulty levels 1-5 (shared by all AI empires) at 0x48FA8 "
" 0.2 / 0.3 / 0.4 / 0.6 / 1.0 "

new code:
" 9A 99 19 3E 66 66 66 3E 00 00 80 3E 33 33 33 3E CD CC 4C 3E CD CC 4C 3E 9A 99 99 3E CD CC CC 3E 9A 99 19 3F 00 00 80 3F"

where are the multipliers stored at?
if 0x48FA8 is correct it should be CD CC 4C 3E 9A 99 99 3E CD CC CC 3E 9A 99 19 3F 00 00 80 3F
with CD CC 4C = 0.2? -> should be 0.2?
9A 99 99 = 0.6? -> should be 0.3?
CD CC CC = 0.8? -> should be 0.4?
9A 99 19 = 1.0? -> should be 0.6?
00 00 80 = 0.5? -> should be 1.0?

and for what stands the 3E and 3F?
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: AI & Difficulty Level

Post by thunderchero »

UE has a hex convertor use this (in this case float 4 byte) UE will also give you new values to insert.

0.2 = CD CC 4C 3E
0.3 = 9A 99 99 3E
0.4 = CD CC CC 3E
0.6 = 9A 99 19 3F
1.0 = 00 00 80 3F

thunderchero
User avatar
EnPhreg
Lieutenant-Commander
Lieutenant-Commander
Posts: 130
Joined: Thu Jul 10, 2008 2:00 am

Re: AI & Difficulty Level

Post by EnPhreg »

i also have a question about 5.3
it's easy to convert the new code into it's game values via UE,
but how can i convert the vanilla code into it's values?
"3D 88 13 00 00 7C 0C B8 03 00 00 00 FF 24 85 60 9B 44 00 3D DC 05 00 00 7C 0C B8 02 00 00 00 FF 24 85 60 9B 44 00 3D BC"

if i try to convert parts of this code into usefull values via UE, nothing logic turns out.
tried several configurations with the converter.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7848
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: AI & Difficulty Level

Post by thunderchero »

EnPhreg wrote:i also have a question about 5.3
5.3 uses same location as 5.2
Spocks-cuddly-tribble wrote:Change location -> 40 bytes needed (+20 bytes for 5 AI difficulty level multiplier afterwards)


5.2 Freeing-up code space in trek.exe (example for asm-449B94)

Disable [position2] Crew Experience thresholds (see Crew Experience):
the code you posted is part of the Disable [position2] Crew Experience thresholds
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Protecting the AI from Black Holes

Post by Spocks-cuddly-tribble »

Spocks-cuddly-tribble wrote: Sun Dec 19, 2010 8:45 amFor some reason Black Holes are not that of an issue for AI.
I have to correct myself. It seems low tech AIs think dying in black holes is a glorious death... :???:

Code: Select all

NAME: Protecting the AI from Black Holes (updated)
DESC: No Black Hole damage for AI ships.
AUTHOR: Spocks-cuddly-tribble
URL: https://www.armadafleetcommand.com/onscreen/botf/viewtopic.php?p=54832#p54832

>> 0x6B1D6 00 00 00 00 00 00 00 00 00 00
<< 0x6B1D6 33 C0 81 C4 50 01 00 00 5D C3

>> 0x6B222 66 8B 50 34 66 89 94 24 4C 01 00 00 66 83 FA 23 76 0A 31 C0 81 C4 50 01 00 00 5D C3
<< 0x6B222 51 66 8B 48 34 66 89 8C 24 50 01 00 00 B5 01 D2 E5 84 2D 28 2B 5A 00 59 74 9A 90 90

# 46BDD6   33C0                 XOR EAX,EAX      // new AI exit
# 46BDD8   81C4 50010000        ADD ESP,150
# 46BDDE   5D                   POP EBP
# 46BDDF   C3                   RETN

# 46BE22   51                   PUSH ECX
# 46BE23   66:8B48 34           MOV CX,[EAX+34]  (owner race ID)
# 46BE27   66:898C24 50010000   MOV [ESP+150],CX (owner race ID)
# 46BE2F   B5 01                MOV CH,1
# 46BE31   D2E5                 SHL CH,CL        (owner race ID)
# 46BE33   842D 282B5A00        TEST [5A2B28],CH (AI check)
# 46BE39   59                   POP ECX
# 46BE3A  ^74 9A                JE 46BDD6        // exit is AI
# 46BE3C   90 90                NOP
Last edited by Spocks-cuddly-tribble on Sun Dec 11, 2022 8:48 pm, edited 2 times 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
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1883
Joined: Sun Apr 27, 2008 2:00 am

Rebalancing the AI Income Cheat

Post by Spocks-cuddly-tribble »

Spocks-cuddly-tribble wrote: Sun Dec 19, 2010 8:45 am3. AI Total Income Bonuses on Difficulty Level 2-4 (sub_43A434)

This is the AI core cheat in BotF, but since applied to the global income, it greatly imbalances AI vs. AI

Here is the new approach to rebalance AI income cheats for the next ECM update:


AI Cheat Bonus = Population * 0.25 (ferengi default income WITHOUT morale, building bonuses or trade routes) + 12.5% * average tech level

Difficulty Level 1-5 Multiplier = 0 / 0.5 / 1 / 2 / 4 (minimum bonuses for 3-5 = 100 / 125 / 175) -> unchanged default cheat values

Code: Select all

NAME: AI Income Cheat based on Total Population and Average Tech Level
DESC: Population * 0.25 (ferengi default income WITHOUT morale, building bonuses or trade routes) + 12.5% * average tech level.
AUTHOR: Spocks-cuddly-tribble
URL: https://www.armadafleetcommand.com/onscreen/botf/viewtopic.php?p=56614#p56614

>> 0x00039820 86 A5 43 00 F5 A5 43 00 09 A6 43 00 2E A6 43 00 48 A6 43 00
>> 0x000399e4 3d 04
>> 0x000399e7 77
>> 0x000399e9 25 ff ff 00 00 ff 24 85 20 a4 43 00 8b 46 04 8b 2e d1 e8 01 c5 89 2e 83 c4 04 5d 5f 5e 59 5b c3 8b 5e 04 83 fb 64 76 0d 89 d8 01 06

<< 0x00039820 00 00 00 00 00 00 00 00 64 00 00 00 7D 00 00 00 AF 00 00 00
<< 0x000399e4 83 f8
<< 0x000399e7 74
<< 0x000399e9 3e 0f b7 1c 4d 60 36 5a 00 c1 eb 03 83 c3 08 0f af 5e 18 c1 eb 03 b1 04 2a c8 d3 eb 8b 04 85 20 a4 43 00 3b d8 7d 02 8b d8 01 1e 90


#0043A5E3     66:83F8 00               CMP AX,0
#0043A5E7    ^74 9D                    JE 43A586  // skip if 'simple'
#0043A5E9     3E:0FB71C4D 60365A00     MOVZX EBX,WORD [ECX*2+5A3660] // get Tech Score
#0043A5F2     C1EB 03                  SHR EBX,3 // get average tech level = Tech Score / 8
#0043A5F5     83C3 08                  ADD EBX,8 // + 8
#0043A5F8     0FAF5E 18                IMUL EBX,[ESI+18] // * cumulated total population
#0043A5FC     C1EB 03                  SHR EBX,3 //  / 8 = + 12.5% * average tech level
#0043A5FF     B1 04                    MOV CL,4
#0043A601     2AC8                     SUB CL,AL
#0043A603     D3EB                     SHR EBX,CL
#0043A605     8B0485 20A44300          MOV EAX,[EAX*4+43A420]  // get minimum bonus via difficulty level (0 0 64 7D AF) 
#0043A60C     3BD8                     CMP EBX,EAX
#0043A60E     7D 02                    JGE SHORT 43A612
#0043A610     8BD8                     MOV EBX,EAX
#0043A612     011E                     ADD [ESI],EBX // add AI cheat bonus to total credits
#0043A614     90                       NOP

+ 25% * (average tech level - 1)

Code: Select all

>> 0x399F7 08
<< 0x399F7 03
# average tech level +3

>> 0x399FE 03
<< 0x399FE 02
# / 4
Deviation code for/after main patch (option used in ECM 5)
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
Post Reply

Return to “AI & Difficulty Level”