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:
[0x00,0x06,0x04,0x00]
(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.
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?
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.
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?
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!)
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.