AI Project

AI Task Modifiers; 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

AI Project

Post by Spocks-cuddly-tribble » Sat Mar 03, 2012 9:16 am

Altering the bugged AI behavior has been the goal of many mods, but foiled by the very intricate/inefficient implementation in trek.exe. Nevertheless, I've found a very useful piece to the jigsaw. :)



:arrow: AI Task Modifiers (ds:58AFEC)

Address of the two byte modifiers in trek.exe at 0x188DEC + (race ID * 144h) + (task ID * 12h) + (agenda ID * 2)

To get a better overview copy & paste the whole 0x144 byte tables into new hex-editor windows (one for each empire) and set them to 18 bytes per row. Each line represents a task and each two byte column an agenda.

Task IDs: (ship tasks according to sub_4E4218)
Explore (0)
Raid (1)
Colonize (2)
Tform (3)
Develop System (4)
Build Ship (5)
Buildbase (6)
Invade (7)
Accept Proposal (8) default modifier -1
Offer Proposal (9)
Attack (A)
Build Wonder (B)
Patrol (C)
Train (D)
Repair (E)
Harass (F)
There is space for two more tasks (IDs 0x10 & 0x11) but code seems to indicate they're not implemented. Also expect unused tasks (cf. tactical cloak) and maybe not all AI tasks use the modifiers.


Agenda IDs: (set by sub_406990)
DCER wrote:Normal Expansion (0)
Unopposed Expansion (1)
Normal Consolidation (2)
Defensive Consolidation (3)
Offensive Consolidation (4)
Cold War (5)
Defensive War (6)
Offensive War (7)
Jihad (8 )
Default range of the modifiers is between 0 and 10 resp -1 for task ID 8. Higher values are possible. I successfully tested colonization modifiers of 0x32 (for all 9 cardassian task 2 agendas), observing a more aggressive colonization behavior.
Last edited by Spocks-cuddly-tribble on Tue Mar 06, 2012 3:26 pm, edited 1 time in total.
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

User avatar
Flocke
BORG Trouble Maker
BORG Trouble Maker
Posts: 2546
Joined: Sun Apr 27, 2008 2:00 am
Location: Hamburg, Germany
Contact:

Re: AI Project

Post by Flocke » Sat Mar 03, 2012 9:39 am

cool stuff, am sure AI can be tweaked alot! :)

User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 6059
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.
Contact:

Re: AI Project

Post by thunderchero » Sat Mar 03, 2012 3:27 pm

Nice piece of the puzzle agreed, :wink:

I wonder if the table could be increased to include minors :D (I know I am just dreaming)

thunderchero

User avatar
Peter1981
Rear-Admiral
Rear-Admiral
Posts: 1118
Joined: Tue May 06, 2008 2:00 am
Location: England

Re: AI Project

Post by Peter1981 » Sat Mar 03, 2012 5:58 pm

Spocks-cuddly-tribble wrote:I successfully tested colonization modifiers of 0x32 (for all 9 cardassian task 2 agendas), observing a more aggressive colonization behavior.
This may hold the promise to solve one of the most obvious AI flaws. Good work SCT :D

User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2065
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Re: AI Project

Post by Tethys » Sat Mar 03, 2012 9:40 pm

Just some thoughts on the ones that are still unknown, hopefully some will be right :lol: :

Enter wormhole
Fleet (re)deployment
Defend
Rendezvous
Not for the weak of heart...
Image
GALM <--- GALM/Galaxies Mod

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

Re: AI Project

Post by Spocks-cuddly-tribble » Tue Mar 06, 2012 3:30 pm

The missing AI tasks are: (4, 5 & B system tasks)

Develop System 4
Build Ship 5
Accept Proposal 8 (default -1)
Offer Proposal 9
Build Wonder B

Expect unused tasks and/or modifiers. For instance proposal modifiers of 0 did not prevent the AI from accepting/offering non-aggression.

thunderchero wrote:I wonder if the table could be increased to include minors
We know the modifiers can inhibit some ship tasks but not set them. Maybe 10+ just means limit is disabled?

For minor race ship tasks see sub_414E50. There are references to Explore, Patrol, Raid and Harass (Harass = bomb systems?).

If you want to have a look, here is my IDA-database: (labeled on the fly, so expect errors)
http://www.file-upload.net/download-416 ... k.idb.html
The Raid / Harass random switch at asm-414C51 could be replaced with a minor race personality check. However, it's too soon to waste time with in-depth editings. We first need to understand the whole mechanics.
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

AI Buying Behavior

Post by Spocks-cuddly-tribble » Thu Mar 15, 2012 4:10 pm

Another step closer to controlling AI tasks. :)

Three categories of expenditures (ships, buildings and gifts) are sorted by priority 1-3 in two identical tables in trek.exe.

0x188DB0 (asm-58AFB0) -> credit allotments (aka budget limits)
0x18A048 (asm-58C248) -> chronology of purchase orders

Set to 12 bytes per row we see the default priorities 1-3 for AI empires card-rom:

Code: Select all

01 00 00 00 04 00 00 00 03 00 00 00
03 00 00 00 04 00 00 00 01 00 00 00
04 00 00 00 03 00 00 00 01 00 00 00
01 00 00 00 04 00 00 00 03 00 00 00
04 00 00 00 01 00 00 00 03 00 00 00
01 = Ships
03 = Gifts/Offers
04 = Buildings/Upgrades

First the AI determines its budget limit by substracting a reserve fund of 5 times effective fleet support cost from the current total credits (if fleet cost is larger than pop support). Another unkown value gets substracted, but most likely it's zero due to broken code and meant to be treaty costs per turn.

This result gets compared with the nominal income and the greater value is used as budget limit for priority 1 tasks. After that, the budget limit for priorities 2 and 3 is obtained by successively substracting the lower values each i.e. by increasing the untouchable reserve fund.

Example:

Klingon AI; 12000 credits, 1000 income, 300 credits/turn effective fleet support cost

Budget limits for buying: (reduced after each purchase order)

12000 -1500(5*300) = 10500 (Ships 01) -> unusable reserve = 1500
10500 -1000 = 9500 (Buildings/Upgrades 04) -> unusable reserve = 2500
9500 -1000 = 8500 (Gifts/Offers 03) -> unusable reserve = 3500

The chronology of the purchase orders, i.e. the category priorities from table 0x18A048, is skipped if the AI loses all shipyards, refineries or the territory is threatened. In this case the chronology is: 1. Gifts/Offers, 2. Ships, 3. Buildings/Upgrades. It's the same check for triggering the emergency ship building agenda: viewtopic.php?p=34142&sid=2ecf63a015a38 ... 6e1#p34142

Every item gets purchased if not prevented by the corresponding budget limit. Unlike ships and buildings the AI just lowers the amount of Gifts/Offers if insufficient credits instead to skip them. viewtopic.php?p=24148&sid=2ecf63a015a38 ... 6e1#p24148
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

Displaying AI Datas on the Map

Post by Spocks-cuddly-tribble » Mon Mar 26, 2012 6:34 am

A diagnostic development feature enables viewing of 24 types of AI map data.

0x193674 (default 01) -> 0 = show AI data if "Build Tasks" are turned off
0x193678 (default 01) -> 0-17h = map ai data type
0xE6BC6 (default 30 D2) -> B2 0X = show data of AI empire ID X (next ID if player, default 0 card)

Hotkey control would be more comfortable, but seems to be not pre-installed.


Index code key of the "map ai data type" switch: (at asm-4E7430)

0 'Sector Density' (based on nearby map objects, own systems do not count)
1 'Current Build' (most trade goods, AI gives orders between turns)
2 'Current System Class' (property type)
3 'All System Classes' (property potential)
4 'Sectors Scanned'
5 'System Production' (output values)
6 'Ship Tasks' (token)
7 'Ship List (%s)' (detailed task list)
8 'Population Data' (laborer assignations)
9 'Territory' (sector claims)
A 'Border Influence' (claim predictors)
B 'System Colonization Value (%s)' (base layer)
C 'System Colonization Priority (%s)'
D 'Rights of Passage (%s)' (sectors not accessible)
E 'Task List (%s)' (agenda, production focus & planned tasks)
F 'Game Statistics' (economic & military power)
10 ? 'Threat Level (%s)' (range class of possible target systems)
11 ? 'Staging Points (%s)' (mark closest opponent systems with XXX)
12 'Diplomatic Info'
13 ? 'Local Advantage (%s)' (depends on opponent systems in sector range)
14 'Base Placement (%s)' (sector density + own systems 100, with yard 110, anomaly = 0)
15 'Raiding Value (%s)' (nearby systems pop -system defenses)
16 ? 'Sphere Of Influence' (purpose unknown, close to savegame file SphOfIn)
17 ? 'Defense Patrol Points (%s)' (purpose unknown, based on own + ally territory)


Labels taken from asm-581450. 10h+ are out of sync, i.e. maybe some of the question marks are wrong assigned.

Data types 7, E, F and 12h display a list instead of the map (navigation still via I, O and arrow keys).

Some datas depend on known opponents i.e. show nothing on turn 1 (e.g. 11h, 13h).

Some views are restricted to the AI's range other not (e.g. Colonization, Raiding).

When testing AI data E 'Task List (%s)', the AI's "master plan", watch for the "Build Wonder" task (still unknown).


Map datas 13h, 14h and C have a major importance and are loaded into the main AI-Agents every time a game is started or loaded.

13h View1 -> sub_419260
14h View2 -> sub_419B70 (cf. sub_41A580)
C View3 -> sub_41A6D0
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

'Unopposed' AI Agenda Fix

Post by Spocks-cuddly-tribble » Wed Apr 20, 2016 4:55 pm

DCER wrote:At the begining their agenda is Normal expansion. One would expect Unopposed expansion, but that is not the case.
viewtopic.php?f=218&t=707#p9673

'Unopposed' requires:
  • all empires unknown
  • a minimum distance of 6+ sectors between the own and all other empire home systems
However, sub_4068D0 is bizarrely flawed, even by BotF standards. It loads instead of the other empire's StarIDs always the own one for comparison.


'Unopposed' AI Agenda Fix (helps AI in the beginning of large map games)

Code: Select all

trek.exe at 0x5D05 change 0x15 bytes to

33 DB E8 A4 03 04 00 8B 04 5D 5E 23 5B 00 3A 5F 08 75 42 90 90

-asm-
00406905   33DB              XOR EBX,EBX              // prepare empire ID for loop

0040690C   8B045D 5E235B00   MOV EAX, [EBX*2+5B235E]  // prepare starID from RToSInfo
00406913   3A5F 08           CMP BL, [EDI+8]          // own empire?
00406916   75 42             JNZ 40695A               // if not check distance
00406918   90 90             NOP
The minimum distance to all other home systems must be greater than: ds:576810 (default 5.0) 8 byte float
On the verge of a nervous breakdown? Try the relaxing tribble sounds.

Post Reply

Return to “AI Task Modifiers”

Who is online

Users browsing this forum: No registered users