Enemy Artificial “Intellgence”
Every enemy has, in its bestiary definition, a defined AI ID. Changing this does not actually have any discernable effect; I’m not sure why that byte is in the monster definition. I’m not arguing, because it provided me a clue as to how to find the following table: the AI IDs are found at 0×22f0b8 to 0×22f17a. This is a span of 195 bytes, so each monster gets exactly one byte. The bytes are listed in monster ID order, so you’ll need to refer back to the bestiary entry to get the listing for the various IDs.
It will be noted that the value 2c is plentiful. That’s because this value is set to “fight 100% of the time”.
AI Indices table, by Monster
To save you the trouble of figuring out what each ID refers to, I’ve got a handy-dandy chart showing the first monster to use each AI ID.
|0×00||Winter Wolf||Fire Lizard||Basilisk||Big Eyes|
|0×04||Deep Eyes||Hellhound||Ogre Mage||Sand Worm|
|0×08||Evil Eye||Death Eye||Rakshasa||Vampire|
|0×0c||Vampire Lord||Horned Devil||White Dragon||Red Dragon|
|0×10||Pyrolisk||Fire Hydra||Water Naga||Spirit Naga|
|0×18||Blue Dragon||Clay Golem||Stone Golem||Iron Golem|
|0×1c||Death Knight||Dark Wizard||Dark Fighter||Nightmare|
|0×20||Death Machine||Manticore||Lich||Lich (Chaos)|
|0×24||Marilith||Marilith (Chaos)||Kraken||Kraken (Chaos)|
|0×30||Scarmiglione (cloaked)||Scarmiglione (undead)||Cagnazzo||Barbariccia|
|0×3c||Death Gaze||Devil Wizard||Holy Dragon||Bloody Eye|
|0×40||Black Dragon||Earth Plant||Yamatano Orochi||Dark Elemental|
Table location: 0×22f17c — 0×22f5cb.
Data structure size: 16 bytes per AI entry.
|AI Record||Spell %||Ability %||Spell Queue||FF||Ability Queue||FF|
|03— Big Eyes||00||80||ff ff ff ff ff ff ff ff||ff||03 03 03 03||ff|
|06— Ogre Mage||40||00||04 26 22 2a 30 ff ff ff||ff||ff ff ff ff||ff|
|28— Tiamat||00||40||ff ff ff ff ff ff ff ff||ff||11 10 0a 0b||ff|
|29— Tiamat (Chaos)||40||40||32 30 2b 29 32 30 2b 29||ff||11 10 0a 0b||ff|
Decoding AI information
Spell % and Ability %
These values I’ve misnamed a bit, as they are not technically “percent” values. IIRC, the game first checks to see whether the monster casts a spell. A random number is rolled between 1 and 0×80, or 128, and if this number is less than the value stated in Spell %, then the next spell in the individual monster’s queue is cast.
If the monster didn’t cast a spell, then the game checks whether it used an ability. This is done in the same manner, using another number rolled between 1 and 128.
Of course, if the monster didn’t cast a spell and didn’t use an ability, then it will attack. And a 00 in these values guarantees that the monster will fail its check to use a spell or use an ability (depending on where the 0×80 is placed).
Spell Queue and Ability Queue
Each AI is allotted a queue of up to eight spells, and up to four monster abilities. A monster may be able to cast spells, use abilities, and some intrepid critters can even do both of these things.
The first time a monster uses a spell, the game picks the first spell in the queue, and that’s the monster’s action. The second time a monster casts a spell, the second spell is used. When it reaches the end of the list (denoted by ff), the list gets reused. Setting the Spell (or Ability) % to a non-zero number, and setting the Spell (or Ability) Queue to all ff‘s will very likely lead to Very Bad Things. Don’t do this, it isn’t nice.
For help in figuring out what values correspond to which Spells or Monster attacks, you’ll need to refer back to the Spells and Monster Attacks article. The IDs listed there for the Spells is accurate. The IDs for Monster Abilities listed in that page do not correspond to the values in the AI table. To calculate what the IDs should be in the Ability Queue, take the ID from the Spells and Monster Attacks article and subtract 0×41.