[FE7] The Official AI Documentation Thread

Something else about routine 0803C0C8:
If AI4 does not have bit 0x20 set, then unset bit 0x02 of 0203A8EC+0x7B (perform AND with 0xFD)

At the beginning of the enemy phase, routine 080348E0 writes 0x01 to 0203A8EC+0x7B (plus does other things). Then for each enemy, routine 0803C0C8 is called which sets or unsets bit 0x02 depending on AI4. Bit 0x02 is also set if AI1 = 0x03 (jump element 0x07)

Near the end of the enemy phase (and player phase) 0x04 gets written to 0203A8EC+0x7B then later 0x00. If I set bit 0x04 earlier in enemy phase, enemies start attacking each other. So it seems bit 0x04 is what allows berserk units to attack their allies.

1 Like

Are the routines just the conditions that the staff will be used?

Who woke me up? Go away. I have quit hacking forever.

Uhh… (that was a long time ago) I believe it covers both the condition and the unit instructions.
Look at what gets written to the stack. I think that data tells where to move unit, what action to perform, and on which target.

[10:17:01 PM] Crazy Colorz: Hey check this out
[10:17:04 PM] Crazy Colorz: AI 0xE - 08B9856C - Heal Allies
01 00 FF 00 00 00 00 00 29 A8 03 08 58 3B 1D 08
03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00

AI 0xF - 08B9858C - Alternate between AI1 0x0E and “action without moving”
01 00 FF 00 00 00 00 00 29 A8 03 08 58 3B 1D 08
07 64 FF 00 00 00 00 00 00 00 00 00 00 00 00 00
03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00
[10:17:15 PM] Crazy Colorz: I think it really does just execute the first AI that evaluates into something
[10:17:27 PM] Crazy Colorz: Let me try editing my custom AI thing
[10:17:31 PM] zahlman: ?
[10:17:34 PM] Crazy Colorz: Like, take out all the gotos
[10:17:45 PM] Crazy Colorz: Like it doesn’t need a 03 to finalize the AI
[10:17:47 PM] zahlman: what’s with the zero probabilities for the heal AI
[10:17:58 PM] Crazy Colorz: I think the probabilities are only used with 05 and 07?
[10:18:01 PM] Crazy Colorz: intSys go figure
[10:18:54 PM] zahlman: ah I see, you’re thinking that 01 (heal) always evaluates to an action, and the 07 has a 100% chance
[10:19:07 PM] zahlman: so on odd turns it will find the heal action, and pause at that point in the ‘loop’
[10:19:13 PM] zahlman: and on even turns then it will do the wait
[10:19:21 PM] zahlman: and then the 03 command just tells it to loop?
[10:19:39 PM] Crazy Colorz: I think 03 is just a goto or something?
[10:19:43 PM] zahlman: yeah
[10:19:48 PM] zahlman: it seems that 03 is goto and 1b is label?
[10:20:23 PM] zahlman: (I bet they were numbered based on like, the order in which they realized they were necessary, lol)[10:17:01 PM] Crazy Colorz: Hey check this out
[10:17:04 PM] Crazy Colorz: AI 0xE - 08B9856C - Heal Allies
01 00 FF 00 00 00 00 00 29 A8 03 08 58 3B 1D 08
03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00

AI 0xF - 08B9858C - Alternate between AI1 0x0E and “action without moving”
01 00 FF 00 00 00 00 00 29 A8 03 08 58 3B 1D 08
07 64 FF 00 00 00 00 00 00 00 00 00 00 00 00 00
03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00
[10:17:15 PM] Crazy Colorz: I think it really does just execute the first AI that evaluates into something
[10:17:27 PM] Crazy Colorz: Let me try editing my custom AI thing
[10:17:31 PM] zahlman: ?
[10:17:34 PM] Crazy Colorz: Like, take out all the gotos
[10:17:45 PM] Crazy Colorz: Like it doesn’t need a 03 to finalize the AI
[10:17:47 PM] zahlman: what’s with the zero probabilities for the heal AI
[10:17:58 PM] Crazy Colorz: I think the probabilities are only used with 05 and 07?
[10:18:01 PM] Crazy Colorz: intSys go figure
[10:18:54 PM] zahlman: ah I see, you’re thinking that 01 (heal) always evaluates to an action, and the 07 has a 100% chance
[10:19:07 PM] zahlman: so on odd turns it will find the heal action, and pause at that point in the ‘loop’
[10:19:13 PM] zahlman: and on even turns then it will do the wait
[10:19:21 PM] zahlman: and then the 03 command just tells it to loop?
[10:19:39 PM] Crazy Colorz: I think 03 is just a goto or something?
[10:19:43 PM] zahlman: yeah
[10:19:48 PM] zahlman: it seems that 03 is goto and 1b is label?
[10:20:23 PM] zahlman: (I bet they were numbered based on like, the order in which they realized they were necessary, lol)

o7

single tear

Whoa. Wait. Huh?
I thought I told you before that 03 was used like a goto and not finalize?

I only just figured that out. Oops. Also, I was trusting what I parsed in the 03 routine, and I guess my logic was a bit off. I already knew and said the Program Counter thing, but I assumed it kepy running until it hit a 03 or something similar.

Alright.
Oh, that reminds me, I think 030013B0 might be used to indicate whether to continue/stop executing commands in current primary/secondary AI entry. 00 = Continue. 01 = Stop.

1 Like

Yep, have that noted, but didn’t put the pieces together until now. Also, @Gryz, you really should read the routines I’ve annotated. They’re in the united dropbox.

On AI Command 00:
Edit: See @Gryz’s post a few below this one

1 Like

AI 0x9 is a blank “do not attack character __” ai
To make it functional, change 0xB970F6

Done empirically.

Oh, crap. I actually looked into jump element 0x00 awhile ago, but I forgot to post it because I am stupid.

My notes about the comparison mode differs from yours though.

Byte 0x01 = Comparison method
00 : if byte 0x04 < memory then branch.
01 : if byte 0x04 <= memory then branch.
02 : if byte 0x04 == memory then branch.
03 : if byte 0x04 >= memory then branch.
04 : if byte 0x04 > memory then branch.
05 : if byte 0x04 != memory then branch.

After another check into the method, You’re right. I missed one of the cases in the middle and mistook one of them.

AI1 0x0C
I know that particular AI gets used a few times in FE6. Let’s see what my CUE searcher program says:

AI 1 : 0x0C
=== Chapter 2 ===
0x0A Fighter (Iron Axe) [15,06] [0C 11 09 00]
0x0B Archer (Iron Bow) [17,04] [0C 12 29 00]
=== Chapter 23 ===
0x31 Sniper (Killer Bow) [06,02] [0C 14 0A 20]
0x32 Sniper (Killer Bow) [04,02] [0C 13 0A 20]
0x33 Druid (Flux, Physic, Berserk) [04,03] [0C 15 0A 20]
0x34 Druid (Nosfertau, Physic, Blue Gem) [05,03] [0C 16 0A 20]
0x35 Druid (Flux, Physic, Sleep) [06,03] [0C 17 0A 20]

Oh, that’s strange. Each enemy has a different AI2. And many have that weird 0x20 for AI4.

The “otherwise, move forward” part is probably due to AI2.

AI1 = 0x0C, AI2 = 0x00
Enemy attacks if foe within movement/2 range, otherwise move forward.

AI1 = 0x0C, AI2 = 0x03
Enemy attacks if foe within movement/2 range, otherwise don’t move.

Yeah, I wouldn’t recommend using AI2 0x00 with AI1 0x0C since it looks silly to have an enemy move up to a player unit without attacking.

Edited to reflect this.

You know how in FE12 certain enemies won’t move until another specific “trigger” enemy attacks? Well, it looks like the GBA FE’s already have built-in support for similar behavior. (It only gets used a few times in FE6)

AI1 0x0D
Move/attack if the unit’s leader has foe in range.
Switches AI1/A12 to 0x00/0x00 (aggressive) when leader is defeated.
The unit must be auto-leveled in order for the unit’s leader data to be loaded.

To create FE12-style enemy traps:
Leader/trigger enemy: AI1 = 0x00, AI2 = 0x03 (attack when foe in range)
Followers: AI1 = 0x0D, AI2 = 0x03 (make sure leader is set and unit is auto-leveled)

Strangely, FE6 mostly uses this AI with an already aggressive leader:
Leader/trigger enemy: AI1 = 0x00, AI2 = 0x00 (aggressive)
Followers: AI1 = 0x0D, AI2 = 0x00
So there might be more to this AI? Or maybe IntSys is just weird.

1 Like

What else is new?

01 00 FF 00 00 00 00 00 BD A5 03 08 00 00 00 00 @Execute this routine. Do nothing if Support#7 is 00 or player unit
Dropbox - AI Byte 1 Commands.txt - Simplify your life
From [the Unified FE Hacking Dropbox][1]

This loads the 0x38 byte of the unit data. For player units, this is Support #7. Am I to assume it’s the leader for enemies?
[1]:Unified FE Hacking Doc Dropbox

Yep, byte 0x38 = enemy leader.