Improving AI assault system

General Modding Information/Questions; support/discussion/questions

Moderator: thunderchero

Forum rules
:idea: Please search before starting new topic. :idea:
There is a good chance it has already been asked.
Post Reply
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Improving AI assault system

Post by thunderchero »

I was wondering is there a way to get AI to assault a system with more troop transports?
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

Good timing, my ida database is spammed with codes still in development (tuning of the calculations).


I'm just posting my unfinished notes: :wink:

- the AI may appear slower conquering enemy systems, but in the long run it does better (score and fleet).

- the AI needs iterations to test the assigning of ships (sorted by function) to optimize tasks (sorted by modifier).
-> the turn process patch might be a problem (albeit you say the AI builds more ships): viewtopic.php?p=54732#p54732

- new AI patches expect all known bugs and missing features from the game manual, listed in this topic, were fixed: viewtopic.php?p=17963#p17963


AI OB attack check for Invade and Harass tasks: [EDIT: just updated] :!:

Code: Select all

>> 0x78D3F 8A 40 52 89 E2 25 FF 00 00 00 E8 72 60 FF FF 8B 54 24 68 66 83 FA 04 0F 85 FF 00 00 00 31 C0 66 8B 84 24 1C 01 00 00 47 01 C6
<< 0x78D3F 8B 68 3C 89 E2 0F B6 40 52 90 E8 72 60 FF FF 8A 44 24 68 3C 04 7F 13 8B 94 24 94 00 00 00 3C 03 75 03 D1 E2 90 03 EA 47 03 F5

>> 0x78DA1 E8 DA 9C FD FF 89 C3 0F AF D9 31 C0 BA 02 00 00 00 8A 45 4C E8 C6 9C FD FF 0F AF C1 8B 94 24 30 01 00 00 01 D8 0F AF D0 8D 04 95 00 00 00 00 29 D0
<< 0x78DA1 3C 23 75 03 8A 45 44 E8 D3 9C FD FF 8B 9C 24 30 01 00 00 3B FB 7D 02 33 FF 0F AF C1 0F AF C3 90 90 3B C6 7C 02 33 FF 8B D0 D1 E0 D1 E0 90 90 90 90
If you want the AI taking more risks against OBs, end of code change: D1 E0 90 90 90 90 -> 03 C2 90 90 90 90 ; even more risks -> 90 90 90 90 90 90


AI Invade task ground combat check:

Code: Select all

>> 0x78F6C E8 0F 9B FD FF
<< 0x78F6C 90 90 90 90 90

>> 0x78F91 31 C0 8D 94 24 20 01 00 00
<< 0x78F91 03 7B 70 EB 55 90 90 90 90
 
>> 0x79006 89 84 24 4C 01 00 00 8B 84 24 5C 01 00 00 8B 94 24 5C 01 00 00 8B 40 40 66 8B 52 44 89 84 24 48 01 00 00 31 C0 DF AC 24 48 01 00 00 66 89 D0 DD 9C 24 48 01 00 00 E8 AF C7 FE FF DC 8C 24 48 01 00 00 D9 84 24 60 01 00 00
<< 0x79006 8B D4 8B C5 89 3A DB 02 69 C8 BC 01 00 00 0F B7 89 A6 1B 5B 00 83 C1 64 89 0A DB 02 DC 0D 7C 87 57 00 DE C9 E8 C1 C7 FE FF DE C9 D8 C8 8B 84 24 5C 01 00 00 0F BF 00 E8 AE CC FC FF 89 02 DB 02 D8 C8 D8 C1 DE F9 EB 75 90

TT ground combat popup fix with empire-wide ground combat bonus:

Code: Select all

>> 0xEA735 31 C0 89 84 24 24 05 00 00 89 E8 89 AC 24 20 05 00 00 31 E8 DF AC 24 20 05 00 00 66 8B 41 28 DD 9C 24 20 05 00 00 E8 90 B0 F7 FF DC 8C 24 20 05 00 00
<< 0xEA735 8D 94 24 20 05 00 00 0F B6 41 28 DB 41 70 69 C8 BC 01 00 00 0F B7 89 A6 1B 5B 00 83 C1 64 89 0A DB 02 DC 0D 7C 87 57 00 DE C9 E8 8C B0 F7 FF DE C9 90

system attack ground combat calculation fix with empire-wide bonus factor of attacking TTs now squared (bonus might be too strong?).

Code: Select all

>> 0x6672E DC 8C 24 20
<< 0x6672E 8B 84 24 F8
>> 0x66751 8B 84 24 F8 03 00 00 DC 0D 6C AC 57 00
<< 0x66751 DC 0D 6C AC 57 00 D8 C8 90 90 90 90 90

Missing feature fix from the game manual (random bonus for attackers when freeing systems)

The resistance will support the liberating forces (defending system ground combat value -25%) - hard to notice due to the bad random engine in BotF.

Code: Select all

>> 0x66761 DD 9C 24 20 03 00 00 E8 83 F5 FD FF 89 84 24 10 04 00 00 DB 84 24 10 04 00 00 DC C8 DC 84 24 20 03 00 00 DC BC 24 20 03 00 00
<< 0x66761 8D 94 24 98 03 00 00 DD 5A 88 E8 80 F5 FD FF 83 7A 48 01 74 09 8B C8 C1 E9 02 90 90 2B C1 89 02 DB 02 D8 C8 DC 42 88 DC 7A 88


New building output types: (random ideas) bonus names could be improved?

+ Extra Pop for Ground Defense

+ Ground Defense (local static bonus)

new buildings -> e.g. Garrison or Mercenary Units

Option -> credit cost per turn, but no energy cost i.e. more than one per system possible
e.g. +50 Ground Defense each for 5 credits/turn for Mercenary Units (scrap if no longer needed, not for AI aibldreq.bin)


Required => Extending Edifbnft.bst (new building types/bonuses) viewtopic.php?p=32866#p32866

Recommended => Ground Defense Fix for Minor & Rebel Systems viewtopic.php?p=33681#p33681 NOT the additive bonuses option -> conflict!


New bonus output IDs to use in edifice.bst: (given an updated edifbnft.bst file)

0x33 = Extra Pop for Ground Defense (all other bonuses apply)
0x34 = Ground Defense (local static bonus) like Utopia Planitia or Wind Turbine

Code: Select all

NAME: New Building Bonuses 'Extra Pop for Ground Defense' & 'Ground Defense'
DESC: Requires 'Extending Edifbnft.bst (new building types/bonuses)' base patches and updated edifbnft.bst file.
AUTHOR: Spocks-cuddly-tribble
URL: 

>> 0x45CF6 98 69 C0 28 03 00 00 8B 15 C8 36 5A 00 01 C2 8D 82 80 01 00 00 DB 80 94 00 00 00
<< 0x45CF6 69 D0 28 03 00 00 03 15 C8 36 5A 00 8D 82 14 02 00 00 DB 00 8B 40 F0 89 44 24 10

>> 0x45D67 89
<< 0x45D67 01

>> 0x45D80 DB 5C 24 28 8B 44 24 28 5E 83 C4 28 5A 59 5B
<< 0x45D80 5E DB 1C 24 8B 04 24 03 82 1C 02 00 00 EB 52

>> 0x18DA6C FF 02 FF 02
<< 0x18DA6C 84 00 9C 00


# trek.exe 0x18DA6C address-map update for new building output bonus IDs 0x33 & 0x34 in systInfo:
#
# 84 +204 = unused # Extra Pop for Ground Defense
# 9C +21C = unused # Ground Defense (local static bonus)


#004468F6     69D0 28030000    IMUL EDX,EAX,328 // system ID * 808 entry size
#004468FC     0315 C8365A00    ADD EDX, [5A36C8] // adr systInfo
#00446902     8D82 14020000    LEA EAX, [EDX+214] // systInfo adr of % ground defense bonus
#00446908     DB00             FILD DWORD [EAX] // % ground defense bonus to FPU
#0044690A     8B40 F0          MOV EAX, [EAX-10] // systInfo+204 = new Extra Pop for Ground Defense bonus
#0044690D     894424 10        MOV [ESP+10],EAX // new Extra Pop for Ground Defense bonus 

#00446967     014424 14        ADD [ESP+14],EAX // add pop to new Extra Pop for Ground Defense bonus

# -> conflict with patch changing effect of local + global ground combat bonuses from multiplicative to additive (not recommended anyway)

#00446980     5E               POP ESI
#00446981     DB1C24           FISTP DWORD [ESP]
#00446984     8B0424           MOV EAX,[ESP] // system ground combat value
#00446987     0382 1C020000    ADD EAX,[EDX+21C] // add new Ground Defense (local static bonus)
#0044698D     EB 52            JMP SHORT 4469E1 // exit
Last edited by Spocks-cuddly-tribble on Sun May 15, 2022 8:11 am, 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
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Improving AI assault system

Post by thunderchero »

Spocks-cuddly-tribble wrote: Sat May 14, 2022 5:58 pm system attack ground combat calculation fix with empire-wide bonus factor of attacking TTs now squared (bonus might be too strong?).
would this be attacking fleet would need production = to 4x ground combat + bonuses?
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

Not exactly. The higher the % bonus the higher the effect deviation between star systems and TTs. My patch fixes this deviation = same effect for TTs.

It's an old hotfix oversight of BotF Patch Version 1.0.1 for the empire-wide ground combat bonus:
Spocks-cuddly-tribble wrote: Sun Nov 28, 2010 7:02 am
Gowron wrote:It is a little bit odd that the empire-wide bonus of the attackers is included in the calculation although it does not affect the (displayed) ground combat values of troop transports.
Well, so at least this statement isn't untruth:
BotF Patch Version 1.0.1 Changes wrote:Ground combat bonuses from structures such as the Angosian Super Soldier Academy are now applied to troop transports and ground forces.
They still missed the TT popup code and a deviation in the ground combat calculation: viewtopic.php?p=22232#p22232

For star systems the bonus is a linear multiplier in popup, but in effective code it's quadratic, but linear for TTs (calculation bias).


EDIT Example vanilla default: (deviation only for empire-wide bonus!)

Linear bonus multiplier is 1+%bonus -> +100% = *2, +200% = *3, +300% = *4... (popup display star systems & TT effective, TT popup +0)

Quadratic multiplier is 1+%bonus squared -> +100% = *4, +200% = *9, +300% = *16... (star systems effective)

So the bonus multiplier (e.g. +200 empire-wide = *3) is also effect deviation factor for sysPop vs TTs (*9[3*3] vs *3 = *3).
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Improving AI assault system

Post by thunderchero »

when it comes to equations like this I am a complete pakled
what would it take to get AI to use more TT's on system assault
lets say system should fall with 1 TT, I want AI to use 4 TT
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

The next patch update will feature an option for a minimum safety buffer of X*defender value. :wink:

But this won't fix two other issues:

- AI does not destroy all OBs before the TT attack, they attack at the same time with the war ships (random OB loss issue)

- the random engine in BotF is crap, even worse is the FPU random engine (float between 0-1) which is compared to the success chance of invasion
-> If you get a bad number, you fail even with a 10 times advantage :mad:

Other than that, (with the empire wide bonus fixed for TTs) the displayed ground combat value of the TTs should be twice the systems value for a 80% chance (given none gets destroyed by OBs). So your idea of x4 sounds good.

But there might be an issue with low tech TT-1 vanilla games, where it is not realistic for the AI to attack bigger systems like home systems or developped minors?


EDIT: According to Gowron the formula is:

For attacker ground combat value = X * defender value -> X*X / (1 + X*X)

2 times 4/5 = 0.8 or 80%
2.5 times 6.25/7.25 =0.862 or 86%
3 times 9/10 = 0.9 or 90%
4 times 16/17 = 0.941 or 94%

My above code gives the AI the correct chance for the number of TTs the AI is assigning in the current iteration of the Invade task.
Last edited by Spocks-cuddly-tribble on Mon May 16, 2022 10:53 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
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Improving AI assault system

Post by thunderchero »

Spocks-cuddly-tribble wrote: Mon May 16, 2022 9:48 pm The next patch update will feature an option for a minimum safety buffer of X*defender value. :wink:

But this won't fix two other issues:

- AI does not destroy all OBs before the TT attack, they attack at the same time with the war ships (random OB loss issue)

- the random engine in BotF is crap, even worse is the FPU random engine (float between 0-1) which is compared to the success chance of invasion
-> If you get a bad number, you fail even with a 10 times advantage :mad:

Other than that, (with the empire wide bonus fixed for TTs) the displayed ground combat value of the TTs should be twice the systems value for for 80% chance (given none gets destroyed by OBs). So your idea of x4 sounds good.

But there might be an issue with low tech TT-1 vanilla games, where it is not realistic for the AI to attack bigger systems like home systems or developped minors?
sounds great, as for minors from my observations the AI has no issues, except when controlled by human, but AI vs AI or AI vs human that is where it almost every time fails :mad:
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

I meant WITH a 4 times minimum limit the AI could get an issue for low tech TT-1 games. :idea:

Also I updated my above post with a list of success chances for you to get an idea. :wink:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Improving AI assault system

Post by thunderchero »

Spocks-cuddly-tribble wrote: Mon May 16, 2022 10:52 pm I meant WITH a 4 times minimum limit the AI could get an issue for low tech TT-1 games. :idea:

Also I updated my above post with a list of success chances for you to get an idea. :wink:
in t1 starts since tech advances so quick I would expect this not to be an issue.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

thunderchero wrote: Mon May 16, 2022 8:48 pmwhat would it take to get AI to use more TT's on system assault
lets say system should fall with 1 TT, I want AI to use 4 TT
EDIT: Second modifier added :!:

Code: Select all

41E45B   fcomp   ds:577754 // 0.85 -> AI should give number of TTs in sector the 'attack system' order to this min limit?

0x175554 33 33 33 33 33 33 EB 3F

41E87C   fcomp   ds:577704 // 0.75 -> AI should add TTs to invade task for this minimum safety buffer?

0x175504 00 00 00 00 00 00 E8 3F
Spocks-cuddly-tribble wrote: Mon May 16, 2022 9:48 pmthe formula is:

For attacker ground combat value = X * defender value -> X*X / (1 + X*X)

2 times 4/5 = 0.8 or 80%
2.5 times 6.25/7.25 =0.862 or 86%
3 times 9/10 = 0.9 or 90%
4 times 16/17 = 0.941 or 94%

My above code gives the AI the correct chance for the number of TTs the AI is assigning in the current iteration of the Invade task.
Using this info, with my above code, you can set a minimum safety buffer of e.g. 4 * defender ground combat value with 0.941 :idea:

Default value 0.85 with my code would be * 2.4 TT ground combat value.
Second value 0.75 with my code would be * 1.75 TT ground combat value.

I hope this works for you. :wink:


---

Old post: Example: Epic game started on tech 1, current tech levels about 3, say the Ferengi AI wants to invade the Cardassian home system, using their superior fleet, with a x4 ground combat min limit using troop transport version 1.

They might not even attack since the new code switch would give out value 0 for invade ground combat task.

Given the above chance values, x2 to x3 might be a better choice (I'd go for 2.5)?

EDIT: I forgot there is still: Increasing the AI's offensive ground combat strength :wink:
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7851
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Re: Improving AI assault system

Post by thunderchero »

Spocks-cuddly-tribble wrote: Thu May 19, 2022 5:25 pm

Code: Select all

41E45B   fcomp   ds:577754 // 0.85 -> AI should give number of TTs in sector the 'attack system' order to this min limit?

0x175554 33 33 33 33 33 33 EB 3F

41E87C   fcomp   ds:577704 // 0.75 -> AI should add TTs to invade task for this minimum safety buffer?

0x175504 00 00 00 00 00 00 E8 3F
I tried 0.941 at 0x175554 and every assault they only brought 1 tt, and lost 50%
I tried many value before I ended up using 2.0
anything below that I only saw 1 tt
when set to 2.0 they would bring 2-8 tt's and won 95% (so I don't mind them bringing extra)
note; on impossible all assaults were against 1 of my 3 starting systems with 10 ob's, shields and bunkers active.

also when I used mudd to see number of tt's (cloaked romulan tt's) one of the other races only had 1 system left (cards) the ferengi had almost wiped them out.

I saw your edit (Second modifier added) halfway though testing. but saw no effect at any value -1.0 -> 5.0 with limiting testing mostly using 0.941 for first value.
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1884
Joined: Sun Apr 27, 2008 2:00 am

Re: Improving AI assault system

Post by Spocks-cuddly-tribble »

Many specifics of the AI tasks are still unclear. After a quick test it appears that:

0.75 -> min limit vs the cumulated ground combat value of ALL AI TTs to issue the invade task (to prevent disadvantageous fleet staging or war declaration) > 1 or jump removed means AI cannot issue any invade tasks i.e. conquer systems

0.85 -> allocation limit for further TTs to specific invade tasks IF the TskSh TTs' ground combat value is OK vs ratio value (probability with my code)
- Other tasks might also need TTs (it's the shipunits vs tasks iteration loop -> turn lag topic)
- A higher value just opens the option for further TT allocations depending on other tasks and ship positions.
- So > 1 or removing the jump does NOT enforce a minimum TT allocation for tasks and at the same time confuses/slows down the vanilla AI.


Another problem is, when invading with more than one taskforce, the AI doesn't collect the TTs in the same taskforce (bad for ground combat success chance).:mad:


thunderchero wrote: Sun May 22, 2022 10:08 pmI tried 0.941 at 0x175554 and every assault they only brought 1 tt, and lost 50%
I tried many value before I ended up using 2.0
anything below that I only saw 1 tt
when set to 2.0 they would bring 2-8 tt's and won 95% (so I don't mind them bringing extra)
If you set reference values beyond the max value-range of functions (here 0-1, resp with my new TT code < 1) then you remove the feature switch (same as nop or force jump).

You did this often in MUM trek.exe to make the AIs more aggressive (invade/attack sooner/more often) without knowing the features each. If this seems to work it's fine, but some useful AI functions might be 'crippled' without you noticing (blindfold AI). Also since the codes are interconnected (e.g. you increased another MUM multiplier of the code for the above 0.85 by factor 1000) there is no way to say how the code would behave in vanilla.

My first patch test (with defaults 0.75 & 0.85) definitely triggered the vanilla AI to bring more TTs and attack bigger systems later to reach a better ground combat ratio.


This exploit code should force a minimum limit of X TTs (default 4) no matter what:

Code: Select all

>> 0x0001d865 08
>> 0x0001d873 00 00 00 00
>> 0x0001d87a 00 00 00 00 00
>> 0x0001dc17 00 00 00 00 00 00 00 00 00
>> 0x0001dc57 35
>> 0x0001dc86 0f
>> 0x0001dc8d 89 d0 e8 8c fa ff ff eb c2 b8 01 00 00 00

<< 0x0001d865 0d
<< 0x0001d873 66 83 be 9e
<< 0x0001d87a 04 7f f1 eb e7
<< 0x0001dc17 8b c2 e8 02 fb ff ff eb 38
<< 0x0001dc57 bf
<< 0x0001dc86 06
<< 0x0001dc8d 66 83 ba 9e 00 00 00 04 7d f0 33 c0 b0 01


#0041E464     73 0D                  JNB SHORT 41E473

#0041E473     66:83BE 9E000000 04    CMP WORD [ESI+9E],4 // skip ship allocation limit if less than 4 TTs
#0041E47B    ^7D F1                  JGE SHORT 41E46E
#0041E47D    ^EB E7                  JMP SHORT 41E466


#0041E817     8BC2                   MOV EAX,EDX
#0041E819     E8 02FBFFFF            CALL 41E320
#0041E81E     EB 38                  JMP SHORT 41E858

#0041E856    ^75 BF                  JNZ SHORT 41E817

#0041E885     73 06                  JNB SHORT 41E88D

#0041E88D     66:83BA 9E000000 04    CMP WORD [EDX+9E],4 // demand a minimum of 4 TTs for Task
#0041E895    ^7C F0                  JL  SHORT 41E887
#0041E897     33C0                   XOR EAX,EAX
#0041E899     B0 01                  MOV AL,1
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 “General Modding Information/Questions”