[FE8] The Official AI Documentation Thread


Worth mentioning here that the Label opcode in FE8 is 0x1C instead of 0x1B like it is in FE7. Maybe one additional built in AI??


Added a ton of stuff. These have ? by them because they have the same structure as the corresponding entries in FE7, but I haven’t actually confirmed their effects. They look the same though, so I think that’s accurate.



Initialization: Push r4-r7, r14. Move r0 (RAM char struct pointer of character being looked at) into r7. Move 0xFF to r4 and r5, and move 0x0 to r4. Load the item id of the first item into r0. BL to 3B794.

At 5A83A4, there’s an array of item halfwords, arranged in order of descending importance, and terminated with 0xFFFF. This function iterates through the array and compares each value to the item id in question. r0 has a counter of how far into the array the item is, and this number is what is returned. If the item isn’t in the array by the time it reads 0xFFFF (read: not stealable), it moves 0xFFFFFFFF into r0.

Once returned, compare r0 to r6. If (signed) less than, move r0 to r6 (current most valulable item according to that array), and move the inventory slot into r5. Load the next item and repeat the previous steps.

Once all the items have been iterated through, move r5 (slot with most valuable item) to r0 and return (3DC0C is a BL 3B7C8). Get the item id of that slot and bl to 3B794 again to get the “how valuable is this item” number.
Once obtained, load r3 with [sp,#0x14], which has the previous contender of “most valuable item”. Compare r0 and r3; if r0 is (signed) less than, store r0 in the space r3 used to be
Not entirely sure what happens next. Loads 202E4D8, dereferences that, then does a bunch of other stuff. I think one of the pointers has the allegiance byte of the current character being looked at?
After a while, it stores r6 (current most valuable item) into sp,[0x18].

Value is determined by location in an array located at 5A83A4. Only item ID is checked, not weapon type. Therefore, you can repoint and expand this to make enemy thieves steal whatever according to a priority table of your making.
If a character has 2 of the same most valuable items, the one in the lowest (lowest meaning closest to bottom, not numerically) slot will be stolen, regardless of uses.
If two characters have the same most valuable item, the one with a lower deployment number will be stolen from, regardless of uses.


Unit position will be the tiebreaker in this scenario.

In FE7, many AI routines start at the bottom-right corner then scan rows right-to-left until it reaches the top-left corner. When an item of equal priority is encountered, it becomes the new steal target. So, when 2 units have the same most valuable item, stealing priority goes to the upmost then leftmost unit. I did a quick test in FE8 and this still seems to be the case.

Here’s a general outline of the FE7 steal AI (08038C44):
Examine each map tile. Start at bottom-right corner, stop at top-left corner, read rows right-to-left.
Check conditions for each tile:

  1. Tile is within steal range
  2. Tile contains a unit
  3. Unit cannot be in the same alliance as thief
  4. There is a open, reachable position around unit (where to execute the steal command)
  5. Thief speed >= target speed
  6. Unit has an item from the stealable item table (lower index = higher priority)
  7. Item index in stealable item table <= index of best item seen so far
    If all conditions met, unit/item becomes the new best target
    Repeat until all tiles have been examined
    Write steal command if a valid target was found

[FE7] The Official AI Documentation Thread

Could you repost this into the FE7 thread as well?


Yeah, sure.

In FE8, the chapter array that controls the AI’s ability to use door keys, lockpicks, and antitoxins is located at 0D8538 (each chapter entry is 4 bytes)

Bit 01 = enable door key. Bit 02 = enable lockpick. Bit 04 = enable antitoxin.

Turn off door keys if you find your enemies being stupid with doors.
Don’t worry about lockpicks since AI2 0x04 and AI2 0x05 will use them anyways.
I have no idea why banning antitoxins is even a thing.