AI question re: Byte 2, 0x06 setting[Resolved]

So I’ve been playing around with the AI some more and I believe I’ve run into another problem. If I use the “move if unit is within range * 2” byte (0x06) for Byte 2, along with these other settings:


(That is, “attack enemy”, “move if enemy reaches range * 2”, “no recovery”, nothing for Byte 4)

… there seem to be some occasions–i.e. if the enemy judges that it will die from an encounter with a player unit or that the outcome of the battle is very unfavourable (e.g. an attack with very low hit) the enemy will move towards the player but not attack.

I was wondering if it’s possible to modify this AI and/or the TP system such that the enemy attacks regardless of the battle’s outcome and how I can go about doing that?

if you’re sure that’s what it is then set a break on read of the player unit’s speed and see which read, when fed a lower value, causes the enemy to attack

Byte 0x3 - specifically everything past the first three bits of it - is also used for targeting based on TP. Using 0x8 will make the enemy only consider how much damage it can deal and ignore any damage it might receive from a counter. Try using 0xC (0x4+0x8) for AI Byte 3 and see if that fixes the behavior.

1 Like

From my understanding of the AI, it seems to be a primary/secondary system. Primary AI being attack inrange, so if it finds that it won’t do that, it looks at the secondary, which is move next to player units. Change the 2nd AI Byte to do nothing, possibly?

I changed prologue Lyn into a max-stat Blade Lord and the brigand (AI = 00,06,04,00) still attacks her.

I can only recall “move up to but not attack” behavior happening with stuff like:

  • AI 1 = “do not attack character” without AI 2 = “do not move towards character”
  • AI 1 = 03, AI 2 = 00
  • AI 1 = 00, AI 2 = 00, AI 4 = 20 (AI 4 0x20 apparently makes AI 1 behave like it’s set to 03)

This is my current understanding of the AI 2 0x06 code:

At address 08B97608:
01 00 FF 00 00 00 00 00 C1 A0 03 08 48 3B 1D 08 // Apparently does the expanded range check (pointer 1 = code, pointer 2 = parameters)
00 00 FF 01 00 00 00 00 72 A9 03 02 00 00 00 00 // Jump to 1B(1) if above was true (memory location 0203A972 = 0x01)
0E 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 // Make unit do nothing
03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 // Jump back to top
1B 00 FF 01 00 00 00 00 00 00 00 00 00 00 00 00 // 1B(1)
02 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // Change AI command. AI 1 = unchanged. AI 2 = change to 0x00. Execute new AI immediately.
03 00 FF 01 00 00 00 00 00 00 00 00 00 00 00 00 // Jump to 1B(1) (I don’t think this gets used due to above change AI command)

All AIs are finalized by a 03 code, from my understanding. So basically, once it enters that bottom state, it stays there.

Hmm… it’s still happening. Those are the battle stats of the would-be battle, except that the cavaliers don’t attack. Dale (the player character) is stationed on that forest tile. I tried it with 0x0C as Byte 3, and also with 0x08, and yet again with 0x09 (as this is what the “AttackInRange” setting uses) but the cavaliers still won’t attack. However, they will attack when AttackInRange is used. Could the fact that an effective weapon is equipped be affecting the attacking priorities?

EDIT: herpaderp… so the cavaliers will actually attack. BUT only the turn AFTER they get within attacking range, weirdly enough. I wonder why this is?

On another note, does anyone know howt he game determines the order in which it moves units? Now they do some weird thing where the one out of range actually moves first rather than the one in range, resulting in the one out of range wasting its turn moving.

Was the fighter standing on a mountain tile during the previous turn? Cavaliers can’t move on mountains. I believe the second AI byte is changing to 0x00, but that AI won’t pursue out-of-range units who are on terrain they can’t traverse.

My point is that it won’t ever reach that particular 03 code due to the change AI command above it. If there is an unit in the expanded range, it should stop execution in either AI 1 or the new AI 2.

I don’t think 03 represents finalize and execute.

00 : 01 64 FF 00 00 00 00 00 41 AA 03 08 B0 F3 FF 08 
01 : 01 64 FF 00 00 00 00 00 41 AA 03 08 B4 F3 FF 08 
02 : 01 64 FF 00 00 00 00 00 41 AA 03 08 B8 F3 FF 08 
03 : 01 64 FF 00 00 00 00 00 41 AA 03 08 BC F3 FF 08 
04 : 03 00 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 

This is a modified version of your AI code that made the brigand walk in a loop. It behaves the same without the extra 03 and 1B codes.

In the RAM unit data, the byte after a unit’s AI1/AI2 is like an AI program counter. At the start of each turn, the value indicates which command to execute next.

AI PC for the above code at the start of each turn:
Turn 1 = 00
Turn 2 = 01
Turn 3 = 02
Turn 4 = 03
Turn 5 = 04
Turn 6 = 01 (repeatedly cycles 01-04)

No, he was standing on the forest tile, I believe. I’ll try it again to double check.

Edit: Yes, he was standing on the forest tile. Now that we’re on this topic the range x 2 AI has some odd behaviour. It will indeed begin moving when a unit enters its expanded range, but not necessarily towards that unit, which makes sense given that 0x06 converts to 0x00 afterwards. However upon further testing, that same enemy is now running around and moving up to units without attacking them again–this time it’s lance vs swords and the battle outcome doesn’t seem to affect this behaviour at all. What in the world is going on?

Does the enemy attack if units are adjacent at the start of the enemy phase?
Does the chapter have any change AI events?
Double check the enemies’ AI 1 and AI 4? Triple check?
Do you know how to check the enemies’ current AI in the RAM?
Was your computer hit by a super-charged particle from a solar flare?

Will test in a second…

Yes, though obviously not pertaining to the units in question.

UNIT Estellar LanceKnight Kaelan Level(2,Enemy,True)   [6,18] [6,18] [SteelLance] [0x00,0x06,0x09,0x00]
UNIT Estellar LanceKnight Kaelan Level(2,Enemy,True)   [7,19] [7,19] [SteelLance] [0x00,0x06,0x09,0x60]

I imagine it involves using the memory viewer which I know how to use although it seems to lack a “go to address” function (and also I don’t know the address!)

that would explain a lot

One of your enemies has 0x60 for the fourth AI byte.

I believe you’re using Venno’s AI 4 0x40 = item drop hack? In that case, you just need 0x40 for the fourth AI byte.


how i do this to myself i’ll never know… I somehow thought that Venno’s hack used 0x60 and not 0x40??? stupid stupid stupid

Why would you make the droppable flag a part of the AI
There’s a place for it in the turn status word

It isn’t a part of the AI, it still uses the turn status bit. This hack makes it check for a bit in unit data instead of character/class data in the ROM when generating a unit with a droppable last item.

It is a shame you can’t use UNCM/UNCR with coordinate parameters, you wouldn’t need to use this hack in that case. You could probably edit the UNCM/UNCR code to let it accept coordinate parameters now that I think about it.

Yeah I thought about making it accept coordinates as parameters but that’s work lol