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)
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)

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

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
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

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

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
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
Note as a replacement for the feature from section 1 this also skips the bugged cheat from section 2.

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
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]
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
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.

Very useful information on the AI building behaviour:
=> aibldreq.bin , AI building behaviour (don't forget to remove/disable trade goods in aibldreq.bin)
Applying Trade Goods (section 3) 1:1 only for AI is the best workaround to get ride of the issue.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.
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
=> 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).

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)
- 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

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 ?

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

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


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

Instruction can be found here:
=> Modifying AI Terraforming Speed
=> the AI minimum terraform threshold (prevent insufficiently terraformed AI colonies)

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)

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)

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

-> 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

-> 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.