I'm finally back home, sorry for keeping you waiting!
Okay, I'll tell you some things about FFVIII ai scripts, I hope myst6re doesn't mind the huge post in this topic. You might have figured out already part (or all?) of what is written below, but I find it more apropriate to start with the basics. I have no idea how monsters ai is coded in other FF game, FFVIII is the only one I've been toying with.
First, structure. Part 8 can be divided as follow :
- offsets
- ai script
- text
I'd be detailling the offsets. Let's take the classical galbadian for example : (note - '__' stands for '00')
03 __ __ __
10 __ __ __ : point to ai offsets
d8 __ __ __ : point to text offsets
e4 __ __ __ : point to text lines
14 __ __ __ : point to loading code (executed when the enemy appears)
58 __ __ __ : point to code executed at enemy's turn
bc __ __ __ : point to counterattack code
c0 __ __ __ : point to death code
c4 __ __ __ : not sure about that one.
values are given starting from the beginning of part 8 for the first four, and from one line after for the other (I suppose that's what the second offset is for.)
Now, syntaxis.
Let's take an extract from Edea1 :
02 04 c8 03 15 __ 07__ 04 c8 0c 06 23 06 __ 04 c9 0b 01 02 03 23 06 __
here we have three parts. The first one is actually a test : 02 04 c8 03 15
All tests begin with 02 ; I'll detail them later. If the result from this test is true, it will follow with the amount of bytes that is given afterwards : 07 00, that's 7 bytes. So now we have : [test] __ 07 00 [code if true] 04 c9 0b 01 02 03 23 06 __
That 'code if true' ends with 23 06 00. You can translate that by : skip 6 bytes. So in this case, we have a simple "if(condition is true) {04 c8 0c 06} else {04 c9 0b 01 02 03}"!
Last thing to tell : when the code will enconter a 00 it will stop. Best example is that piece of code, which you'll encounter with a lot of enemies, that tell them to skip their turn :
02 02 03 __ __ __ 04 __ [__ 23 __ __]
(02 02 03 is a probabilty of 1/3)
Now. Let's detail a little more what we can encounter - keep in mind that I'm far for having decrytped everything.
Tests
for most of them (I'm not sure about how the probability thing exactly works)
first byte : 02
third byte : target.
fourth byte :
00 : =
01 : <
02 : >
03 : !=
04 : <or=
05 : >or=
fith byte : number
second byte - tells what to check
00 : monster own HP (ex : 02 00 c8 01 03 __ would be if his HP are below 30%)
01 : other monster HP (ex: 02 01 57 01 05 __ would be if a galbadian is below 50%)
03 : battle scene (ex : 02 03 c8 03 04 : if we are not in fight 04)
04 : self, status (ex below : 02 04 c8 03 15, if she haven't got status 15 (safe))
05 : ennemies, status (ex : 02 05 c8 00 17, if one of us acursed seeds have got status 17 (reflect))
06 : number of alive members in our party (ex : 02 06 c8 00 01, only one remains)
09 : is a certain character is present & alive (ex : 02 09 c8 00 03 : if Quistis is here)
0e : monster difficulty level (ex : 02 0e c8 05 01 : if difficulty level higher or equal to ‘1’ (medium)
00 = retarded n00b, 01 = medium, 02 = hard.
11 : check if we have stolen a GF (ex : 02 11 c8 03 cc : monster lost his GF.)
talking of status, here is my current list :
01 : poison
03 : blind
04 : mute
05 : berserk
06 : zombi
10 : sleep
11 : haste
15 : safe
16 : shell
17 : reflect
18 : aura
1d : float
1e : confuse
21 : double
22 : triple
Variables - just a few examples
ex : dc, dd, de, df, 60, 61 ...
0e dc 00 : set dc = 0
13 60 01 : add 1 to 60.
02 dc c8 00 00 : if(dc=0)
Text :
texts can be launched by some attacks, but it can be called directly from the ai code as well.
01 02 : say text line n°3.
1a 01 : say text line n°2, but after attack.
There are others, I won't detail all of them.
... I will continue later