Difference between revisions of "Enemy AI"

From Chrono Compendium
Jump to: navigation, search
(Condition list fix)
(32 intermediate revisions by 3 users not shown)
Line 9: Line 9:
 
___________________________________________________________________
 
___________________________________________________________________
  
WaddlerD's conversation to me:
+
</pre>
___________________________________________________________________
+
  
WaddlerD 85: The AI tactics is quite interesting.
 
WaddlerD 85: All the monsters has 2 main patterns.
 
WaddlerD 85: A "normal", move on will pattern and a "counter, move
 
with the response of an attack or action, pattern.
 
WaddlerD 85: It's always seperated by FE FF
 
WaddlerD 85: The stuff between the FE FF is simple and complicated
 
in a way.
 
WaddlerD 85: The first 4 bytes are ALWAYS to going to be a
 
precondition.
 
WaddlerD 85: followed by a FE
 
WaddlerD 85: to seperate the precondition from the actual actions.
 
WaddlerD 85: I haven't found out all the preconditions yet, as there
 
are quite a few, but usually 00 00 00 00 is the default.
 
WaddlerD 85: As it means, "If the monster is alive" probaby.
 
WaddlerD 85: probably*
 
WaddlerD 85: You can put more than one precondition in a pattern,
 
though.
 
WaddlerD 85: Like for instance.
 
WaddlerD 85: FE FF 00 00 00 00 FE Blah blah blah FE 00 00 00 00 FE
 
Blah Blah FE FF <--- Normal attack pattern
 
WaddlerD 85: The four bytes.
 
WaddlerD 85: Though it's also good to know that the precondition can
 
be expanded into some big "and" precondition.
 
WaddlerD 85: Like for instance 01 03 00 00 15 40 00 00 = "When HP is
 
at 50% AND Monster is hit with Shadow based elemental attack.
 
WaddlerD 85: There is quite a few interesting preconditions that I
 
found out so far.
 
  
  
WaddlerD 85: Somewhat sloppy, but it should be good enough
 
WaddlerD 85: Byte #1: 00 = No Attack
 
01 = Attack
 
Byte #2: 00 = Normal Attack
 
01 = Secondary Attack
 
Byte #3: (Target?)
 
Byte #4: Animation that is done before attack
 
01 = Up Close
 
04 = Stand Still Action
 
0A = Circle around
 
0E = Going Astray
 
  
 +
==Summary==
  
02 XX 05 XX XX XX
+
Enemy AI is divided into two blocks that terminate with $FF.
  
Byte #1: 02 = Techs/Magic
+
<pre>
Byte #2: XX = Attack Type
+
AAAAAAAAFF
Byte #3: Targeting style?
+
BBBBBBBBFF
Byte #4: Double Tech targeting?
+
Byte #5: Triple Tech targeting?
+
Byte #6: Message
+
 
+
 
+
 
+
0A XX XX
+
 
+
Byte #1: 0A = Disables Enemy
+
XX = Special Attack
+
XX = Message
+
 
+
 
+
0B XX XX 00 XX
+
 
+
Byte #1: 0B = Setting Stat
+
Byte #2: XX = Stat Type
+
Byte #3: XX = Stat set
+
Byte #4: 00 = ?
+
Byte #5: XX = Message
+
 
+
 
+
0C 3D XX XX
+
 
+
Byte #1: 0C = Adding Stat
+
Byte #2: 3D = Offense
+
39 = Magic
+
3B = Evade
+
38 = Speed
+
3E = Defense
+
3F = Lightning Defense
+
40 = Shadow Defense
+
41 = Water Defense
+
42 = Fire Defense
+
Byte #3: Increment
+
Byte #4: Message
+
 
+
0D XX
+
 
+
 
+
0F XX
+
 
+
Byte #1: 0F = Message Enable
+
Byte #2: XX = Message
+
 
+
Attack/Counterattack Preconditions
+
15 XX = Counters with Type of Attack
+
 
+
20 00 00 00 = Final Attack
+
17 XX 00 00 = Chances Pattern will be used
+
1F 04 XX 00 = Distance
+
07 01 00 00 = Custom Pattern is active
+
11 00 00 00 = Physical Attack
+
12 XX 01 = Magic Attack
+
01 03 = HP is at 50%
+
05 XX = Number of Monsters in battle
+
 
+
 
+
 
+
WaddlerD 85: Here's the first bit of attacks that I have found out.
+
WaddlerD 85: 00 = Flash
+
01 = Enemy Cure (Target problems, they cure YOU...)
+
02 = Lock
+
03 = Bird Screech
+
04 = Slow Gas Attack
+
05 = Nagaette's Slow Spell
+
06 = Mune Attack
+
07 = Jump n' Land Strike
+
08 = Sleep Wave
+
09 = Dust Breath Attack
+
0A = Fire Breath Attack
+
0B = Grinder Plowing Attack
+
0C = Dragon Tank Missile Salvo
+
0D = Bubble
+
0E = Yakra's Needlespin
+
0F = Sleep Bomb
+
10 = Cybot Singing
+
11 = Spewing Volcano
+
12 = Rasp
+
13 = Venomous Gas
+
14 = Laser Beam
+
15 = Laser Beam Again
+
16 = Missile Salvo
+
17 = Orb Bomb
+
18 = Area Bomb
+
19 = Amplifire
+
1A = Delta Attack
+
1B = Ink Blast
+
1C = Harmful Gas
+
1D = Attack, Attack, Attack/Bugged
+
1E = Chaos Bell
+
1F = Azala Break
+
20 = Yes Indeed!
+
21 = Whirlwind Dance/Bugged Alone
+
22 = X-Strike/Bugged Alone
+
23 = Whirlwind Blast
+
24 = Less Hitting Poison Gas
+
25 = Fire Trail or Enemy Fire 1
+
26 = Pushback Attack
+
27 = Static Shock (ALL)
+
28 = Static Shock (ONE)
+
29 = Shower
+
2A = Enemy Ice 1
+
2B = Enemy Lightning 1
+
2C = Self-Destruct
+
2D = Nuke
+
2E = Bugged?
+
2F = Point Flare
+
 
+
WaddlerD 85: Found out another precondition.
+
 
+
WaddlerD 85: I think 40 00 XX 01 points out "When Monster XX is
+
dead"
+
WaddlerD 85: So if you put 40 00 CF 01 in there, it says "When
+
Monster "Bit" is dead", do this.
+
 
+
WaddlerD 85: Ok, should be simple enough.
+
WaddlerD 85: You know though...
+
WaddlerD 85: There may be something more than what I put down
+
for 1F 04 XX XX
+
WaddlerD 85: A lot more...
+
 
+
WaddlerD 85: Because Gato has 1F 06 00 00 for his counter attack
+
precondition...
+
 
+
WaddlerD 85: Well, 1F usually deals with distance
+
WaddlerD 85: So I guess the three bytes after it have to do with
+
something...
+
 
</pre>
 
</pre>
  
==Other Findings==
+
The first block contains actions that the enemy performs on its own.
 +
The second block contains reactions when the enemy is attacked.
  
''Justin3009''
+
Each block can be broken down into sections that alternate between Condition and Action.
  
38910 - Marle Invisible Monster's transform
 
  
34341/33345/59108/42312/34523/34112/32198/33333/35312/35464/34921/32421/35353/(44217/45217)(Counter Attack) - Enemy Melee
+
'''Condition'''
  
45629 - Weird Attack by enemy (almost like golem's)
+
Conditions are a multiple of 4 bytes, each of which is a boolean statement.  All must be true for the following Action section to be executed.  The section is terminated by $FE.
  
43212 - Robot/Dragon Tank Moves?
+
'''Action'''
  
46645/43217 - robot move
+
Actions can contain one or more commands to perform.  An enemy's attack meter must refill first before it can continue with the next command.  The section is terminated by $FE.
  
54332 - Span Death/ Arm Revives Body (Kills Hero and 2 Enemies)
+
==Conditions==
  
54512/54651/54325 - Barrier Change Message Repeating
+
There is a total of 41 Conditions ($00-28)
  
56654 - Hexagon Mist/Water Message Repeating
+
<pre>xx - unused,
 +
tt - targeting byte 80 - copy flag, copies $7E:AED8 to $7E:AECC, ignore Targeting 0x7F - targeting routine,
 +
?? - unknown
 +
00 xx xx xx - Default, always passes.
 +
01 tt xx xx - HP less than half (tt is usually set to 03 for current enemy,
 +
              but other values could be used).
 +
02 tt oo bb - Check for status. tt - Target, 00 for PCs, 01 for enemies. oo - Offset from
 +
              battle data 0x1D (start of status flags). bb - Bits to check.
 +
03 tt mm xx - Checks if something moved. mm - Monster/PC index
 +
04 xx mm ss - Checks status of monster mm - monster index, ss - Status - 00 Alive, 01 - Dead.
 +
05 nn xx xx - Checks for maximum number of living enemies. nn - number of enemies.
 +
06 ff ff ff - Check if battle frame counter is at least ff.
 +
              Value is little endian (lowest byte stored first).
 +
07 vv cc xx - Check custom mode. vv - value, cc - Compare type - 00 >=, 01 <=
 +
08 tt hh hh - Check if HP <= value. hh - HP to compare.
 +
              Value is little endian (lowest byte stored first).
 +
09 tt ss vv - Check if stat is less than value. ss - stat offset. vv - value
 +
0A tt ss bb - Check if stat has bitflags set. ss - stat offset, bb - bitflags set.
 +
0B tt ss vv - Check if stat is less than or equal to value. ss - stat offset, vv - value.
 +
0C tt ff xx - Check if target is inside or outside of a 32 pixel radius. ff - 00 Inside, 01 Outside
 +
0D tt ff xx - Check if X distance against 32 pixels. ff - 00 >, 01 <=
 +
0E tt rr ?? - Distance related. rr - result check mode.
 +
0F tt rr ?? - Distance related. rr - result check mode.
 +
10 xx bb aa - Likely distance related. aa - First calculation switch. bb - Second calculation switch
 +
11 ee xx mm - Check if hit by tech type. ee - 00 player tech, 01 enemy tech. mm - 00 ==, 01 !=
 +
12 ee aa mm - Check if hit by specific tech.  ee - 00 player tech, 01 enemy tech. aa - tech index.
 +
              mm - 00 ==, 01 !=
 +
13 aa xx mm - Check Attacker. aa - 00 player, 01 enemy. mm - 0 ==, 01 !=
 +
14 vv mm ee - Check specific attacker. mm - mode 00 Check attacker against value vv, 01 buggy.
 +
              ee - 00 ==, 01 !=.
 +
              Only checks against player techs and attacks, or enemy techs without enemy vs
 +
              enemy attack set. There is a minor bug in mode 00 when ee is 01. Set 0x019551
 +
              to 89 to fix in the Japanese and US releases.
 +
15 ee xx ff - Checks element of attack, ff - 00 ==, 01 !=, ee - element 20 Ice, 10 Fire,
 +
              80 Lightning, 40 Shadow, 02 Magic, 04 Physical
 +
16 xx xx xx - Copy of 00.
 +
17 pp xx xx - Percent chance. pp - percent
 +
18 vv tt ss - Check if stat is equal. vv - value, ss - stat offset.
 +
19 xx xx xx - Copy of 00.
 +
1A mm aa ss - Check if monster type is alone or not. mm - monster index, aa - 0 - alone,
 +
              1 - with other types.
 +
              ss - If with other types, should the condition succeed? 0 - fail, 1 - succeed.
 +
1B pp xx xx - Count of living PCs is at most pp.
 +
1C tt pp ll - Is PC present or absent. tt can load any targeting routine, but only routines 30-36
 +
              will produce expected results.
 +
              pp - Presence status. 00 - Present, 01 - Absent. ll - Life status. 01 - may be dead.
 +
1D tt xx aa - Check if target is alive or not.
 +
1E xx xx xx - Copy of 00 that sets $7E:AF24 (failure status) to 1 (failed).
 +
1F tt ff xx - Check if target is inside or outside of a 48 pixel radius. ff - 00 Inside, 01 Outside
 +
20 xx xx xx - Final Attack.
 +
21 xx xx xx - $7E:AF15 related.
 +
22 tt ?? cc - $7E:B158 related. cc - compare type 0 - Less than, 1 - Greater than or equal to.
 +
23 vv tt ss - (same as 18)
 +
24 vv tt ss - (same as 18)
 +
25 vv tt ss - (same as 18)
 +
26 vv tt ss - (same as 18)
 +
27 vv tt ss - (same as 18)
 +
28 vv tt ss - (same as 18)</pre>
  
45333 - Zeal (Hands/Head Moves)
+
==Actions==
  
51652 - (Magus Moves)
+
There is a total of 23 Actions ($00-16)
  
42217 - Low Life
 
 
48217 - Automatic Win
 
 
59217 - Area Change?/Hero's Attack Themselves?
 
 
52217 - Area Bomb Message Appears
 
 
12341/12741 - Strange Win?
 
 
23411/15297/59231/12347/23409/23421/958/951/14512 - Freezes Game
 
 
43123 - Copy Cat Ability/Copies Phycics message repeating
 
 
38764 - 1 hit win
 
 
42978 - Dragon Tank
 
 
55789/54129/54213/53451/54643/53750 - Barrier Change Message Repeating
 
 
49876/50000 - Unfinished Double techs
 
 
29873 - Gaia Magnade/Fire Message Repeating
 
 
39065 - Absorbs More Elemental Damage
 
 
19824/24312 - Slows Game
 
 
48971 - Strange Effects...
 
 
49441 - The Parts on the Right Store Energy...Message Repeating
 
 
43298/43291 - Automatic win/Apart Masa and Mune Are Powerless Msg..
 
 
42831 - 1 Yakra Move
 
 
12478 - Double Part Attack/Dark Plasma Message Repeating
 
 
45123 - hero takes over enemy
 
 
42312/38312(Close Range) - Enemy Steals Life
 
 
12973 - Defense Down Message Appears and Freezes Game
 
 
47819 - Dragon Tank Missles
 
 
5309 - Grand Stone/ Ultimnate physical attack (Freezes game)
 
 
61470 - Dark Gear/ Shadow Message Repeating
 
 
40395 - Enemy Uses weird move (Screen turns red and rocks fall)
 
 
24341 - Either Slows game or Slows Battle Stances
 
 
45432 - Counter Attack/ Life Shaver
 
 
51312 - Counter Attack: Flare
 
 
52312 - Gives weird mana drains all items and Barrier Change/Ding-Aling-Chaos message
 
 
49312 - Lavos Moves/Yakra Move?
 
 
47312 - Steals life/ Shakes the Ground/Tornado Energy Neutralized message
 
 
44312 - Destroy's Graphics/ Bad Impulse ---- (Couldn't read rest of message)
 
 
43312 - Attacks Hero, but when attacked, Apart Masa and Mune Are Powerless (Ends Battle)
 
 
36312 - Shoots a Bunch of Flames
 
 
51112 - Area Bomb on Enemy
 
 
51012 - Go ahead...Try and attack (Shoot's Flame)
 
 
51002 - Lavos Core is Defended! (Shoot's Flame)
 
 
51119 - Area Bomb On Hero's
 
 
51149 - Golem Boss Run Away Move
 
 
56512 - Removes third party menu over and over
 
 
34523 - Walk Around and Attack
 
 
57298/12451/41931 - destroys graphics (does many things)
 
 
32489 - Freezes game
 
 
40000 - Shoots Laser
 
 
47800 - Shoots Missles
 
 
57212 - Hero's attack themselves and Reprogramming/Chaos Message Appears
 
 
57212 - Hero's attack themselves and Reprogramming/Chaos Message Appears
 
 
3561 - Span Death/Arm Revives Main Body.. Message Repeats
 
 
10294 - After any attack game screen goes black and dissappears
 
 
9931 - Kills enemy after 3 turns and constantly plays enemy death sound then game freezes
 
 
16528/15460 - Enemy tries to run then game freezes
 
 
13256 - Attack/will attack with no center bit.
 
 
15555 - Double-Part Attack/Dark-Plasma
 
 
43216 - Copy Cat Ability/Copies Phycics message repeating (Does Missle Attack, Laser Beam, and Time Stop)
 
 
49216 - Blue scout fights all mag but "water".
 
 
46216 - Eats hero for life and uses some strange fire attack that hits everything
 
 
10896 - 1st person in slot shakes head and game freezes
 
 
59230 - Lavos Core is Defended! message repeats
 
 
42190 - Makes game skippy
 
 
42956 - Shoots yellow laser beam
 
 
43956 - Slashes's Attacks
 
 
45956 - Robo's Heal Beam?
 
 
47956 - Missles
 
 
50956 - Lavos Bit Attacks?
 
 
51956 - Fire 2, Lightning 2, Ice 2
 
 
57956 - Js theot ththingver: Th Message appears (automatic win) But drains life
 
 
61956 - Mutant Gas/Poison Message Repeats
 
 
39956 - Blue scout fights all mag but "lightning". Then does MP Buster
 
 
37956 - Shoots Dirt at Heroes and Melee attacks
 
 
16956 - Napalm Message Repeats (hero Attacks enemy but then attacks a hero)
 
 
12956 - Shadow Slay Message Repeats
 
 
5956 - Freeze/stop message repeats
 
 
61258 - ♪-- ♪- ♪♪--/chaos message repeats
 
 
45874 - Sand Breath/Darkness (Def powered up when attack) Steals Life
 
 
41874 - If hero attack Enemy runs away (Attack pwr up) Message repeats
 
 
39874 - 10,000 Hz/sleep strike from the heavens above
 
 
38874 - Physical defense on If attacked Magical Defense on if Magic
 
 
37874 - If attacked does hallation
 
 
36874 - If attacked uses Cure 2?
 
 
40874 - Does slash and slow
 
 
24874 - Crying Heavens/Hidden Below message repeats
 
 
16874 - Double-Part Attack/Dark-Plasma Message repeats If hero lands a strike, Hero attacks him/herself
 
 
15874 - Obstacle message repeats
 
 
11523 - Counter-Attack
 
 
10523 - Plays enemy death sound when enemy is defeated over and over. Then says destruction zone, screws up the graphics, anything other then that turns into a robot laser.
 
 
9523 - Plays enemy death sound when enemy is defeated over and over. Then says Mortal Blow, screws up the graphics, anything other then that turns into a robot laser.
 
 
45523 - Doom, Doom Doom Doom... - Screws up Graphics and does some odd attack.
 
 
59632 - Attacks enemy then shakes head left to right
 
 
10203 - hero dissappears enemy dissappears turns into a "nu" or so they say and screws up graphics on hero
 
 
50314 - Shoots flames and eats hero
 
 
13620 - Counter attacks during battle message repeats
 
 
60340 - Pain... Message appears at the beginning of the battle
 
 
32056 - Counter-Attacks
 
 
16450 - Life Shaver/ Hp goes to 1 - If successful hit hero attacks themselves and takes no dmg
 
 
63190 - Waltz of the wind (insert heart symbol here)/chaos
 
 
40210 - Barghest's shield destroyed... message appears after the first attack
 
 
 
''Chickenlump''
 
<pre>
 
09 XX
 
XX = Attack to use
 
 
These attacks do absolutely no damage (not even 0), but the attack effect plays out.
 
I've seen these in 2 unnamed monster's scripts (lavos support monsters I think, they have no name, #'s B5 and B6).
 
 
28 XX YY  - Change Stats
 
XX - Stat to change
 
YY - Amount to change
 
 
You can change HP, MP, wounded, etc. stats of characters with this one.</pre>
 
 
''Vehek''
 
 
<pre>
 
<pre>
07 XX YY ZZ - Become different monster
+
00 ?? jj ??  wander mode.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index
XX - Type of monster to become
+
01 aa jj ??  attack mode.  aa - attack index jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index
YY - Attack animation to use. Not all attacks update the sprite and name.
+
02 tt jj jj jj ss  tech mode.  tt - tech index jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index ss - battle enemy message string
ZZ - Haven't really investigated; affects whether it keeps its current HP when it changes.
+
03 (nothing, no routines)
This requires the location events to be set up in a certain way.
+
04  random action.  uses a random number to determine which action in current section to start on.
 +
05 ?? ??  unknown, possibly unused, and not confirmed if it is a 3 byte command.
 +
06 (nothing, no routines)
 +
07 mm aa hh  become monster.  mm - monster to turn into aa - animation? hh - hp
 +
08 (nothing, no routines)
 +
09 ??  display flashes for distant attack?
 +
0A aa ss  run away.  aa - action to show ss - battle enemy message string
 +
0B oo vv mm ss  set stat.  oo - offset from enemy stat set start vv - value to set/bitwise OR mm - mode, 00 set value 01 bitwise OR ss - battle enemy message string
 +
0C oo vv ss  stat math. oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
 +
0D ?? ss  unknown, state change?  ss - battle enemy message string
 +
0E (nothing, no routines)
 +
0F ss  display text. ss - battle enemy message string
 +
10 vv ee ss  revive support enemies.  vv - unk. stored to temp 7E000E ee - battle sound effect ss - battle enemy message string
 +
11 oo vv oo vv oo vv oo vv ss  multi stat set.  oo - offset from enemy stat set start vv - value to set ss - battle enemy message string
 +
12 ?? ?? jj jj oo vv oo vv oo vv oo vv oo vv ss  special multi stat set.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index  oo - offset from enemy stat set start vv - value to set ss - battle enemy message string
 +
13 jj vv  unknown, possibly unused, and not confirmed if it is a 3 byte command. jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index vv - unknown value stored to temp 7E000E
 +
14 oo vv oo vv oo vv oo vv ss  multi stat math.  oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
 +
15 ?? ?? jj jj oo vv oo vv oo vv oo vv oo vv ss  special multi stat math.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
 +
16 -- tt oo vv oo vv oo vv oo vv ss  multi revive and set stat.  tt - tech/tech animation related index oo - offset from enemy stat set start vv - value to set ss - battle enemy message string
 
</pre>
 
</pre>
  
  
==Summary==
+
'''Older data not 100% confirmed:'''
Enemy AI is split into two sections seperated by the bytes FE FF.
+
  
<pre>
 
XXXXXXXXXXXXXXX FE FF YYYYYYYYYYYYYYYY
 
</pre>
 
 
The first section is the normal enemy moves.  The second section is the counter section is used if the enemy is hit.  Each section has the following layout.
 
  
 
<pre>
 
<pre>
<condition_1>  FE  <action_1>  FE <condition_2> FE <action_2> .... FE <condition_n> FE <action_n>
+
00 WW XX YY            - wander mode YY is how you wander, WW animation related?
 +
02 WW 05 XX YY ZZ      - Spell WW, Message ZZ, XX YY for double/triple?
 
</pre>
 
</pre>
  
Each condition is a multiple of 4 bytes.  Every 4 bytes is a boolean statement (see below conditions).  If there are more than one statements they must all evaluate to true in order to do the corresponding action. 
+
==Enemy AI Targeting subroutines==
  
 +
Used by Conditions: 01, 03, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 18, 1C*, 1D, 1F, 22, 23-28
 +
Used by Actions: 00, 01, 02, 12, 13, 15
  
==Know Conditions==
+
*Condition 1C does not treat the data obtained the from the routines the same way as the others, so it will have unexpected results.
  
<pre>
+
jj - Multiply x2 + 0x01B8BB to obtain the pointer
00 00 00 00 - Normal attack./enemy alive
+
01 03 00 00 - HP is at 50% or less.
+
09 00 00 00 - Physical Counter.
+
10 00 00 00 - Always Counter.
+
11 00 00 00 - Magical Counter.
+
15 XX 00 00 - Elemental Counter - 20 Ice, 10 Fire, 80 Lightning, 40 Shadow, 00 Physical. (02 and 04 have been used, only saw them skimming the listings)
+
1F 04 XX 00 - Is enemy distant (non-zero) or up close (zero)?
+
20 00 00 00 - Final attack.
+
</pre>
+
 
+
==Know Actions==
+
<pre>
+
 
+
 
+
00 WW XX YY ZZ        - wander mode ZZ is how you wonder, WW animation related?
+
02 WW 05 XX YY ZZ      - Spell WW, Message ZZ, XX YY for double/triple?
+
07 XX YY ZZ            - Become different monster XX using animation YY.  ZZ affects keeping HP requires event code
+
09 XX                  - Pretend to do attack XX
+
0A XX YY-              - Disable do animation XX display Message YY
+
0B XX YY 00 ZZ        - Set stat type XX, Stat YY, with message ZZ
+
0C XX YY ZZ            - Add stat XX by YY message ZZ
+
0F XX                  - Display Message XX
+
28 XX YY              - Change Stat XX by YY
+
</pre>
+
  
 +
<pre>00 - Nothing
 +
01 - All PCs
 +
02 - All enemies
 +
03 - Current enemy
 +
04 - Attacking PC
 +
05 - Random PC
 +
06 - Nearest PC
 +
07 - Farthest PC
 +
08 - PC with lowest HP. This routine does not properly check PC1's HP. To fix, replace 0x01A50C (unheadered US or Japanese ROM) with D0 05 EA EA.
 +
09 - PCs with any flags on battle data 0x1D set. 80 is used for a dead PC, others are unknown.
 +
0A - PCs with any negative status.
 +
0B - PCs with any flags on battle data 0x1F (unknown)
 +
0C - PCs with any positive status from set 1 (2x Evade/Unknown Status/2.5x Evade/Haste)
 +
0D - PCs with any positive status from set 2 (Attack Power Up/Shield (Defense Up)/Max Attack Power Up/MP Regen/Barrier (M. Defense Up)/Berserk)
 +
0E - Sleeping PCs
 +
0F - Stopped PCs
 +
10 - Confused PCs
 +
11 - Shielded (Defense Up) PCs
 +
12 - Barriered (M. Defense Up) PCs
 +
13 - PCs with bit 10 of positive status set 2 (unused)
 +
14 - PCs with bit 8 of battle data 01 (unknown)
 +
15 - Other enemies
 +
16 - Living enemies
 +
17 - Nearest enemy
 +
18 - Farthest enemy
 +
19 - Enemy with lowest HP
 +
1A - Other enemies with any battle data 0x1D flags set
 +
1B - All enemies with any battle data 0x1D flags set
 +
1C - Other enemies with any negative status
 +
1D - All enemies with any negative status
 +
1E - Other enemies with any flags on battle data 0x1F (unknown)
 +
1F - All enemies with any flags on battle data 0x1F (unknown)
 +
20 - Other Sleeping enemies
 +
21 - Other Stopped enemies
 +
22 - Other Confused enemies
 +
23 - Other Barriered (M. Defense Up) enemies
 +
24 - Other enemies with 0x1D bitflag 2 set
 +
25 - Other enemies with 0x19 bitflag 1 set
 +
26 - Enemy with lowest HP other than self
 +
27 - Enemy 03. This and the following routines are mostly used with multi-part bosses. Enemy index is determined by event commands.
 +
28 - Enemy 04
 +
29 - Enemy 05
 +
2A - Enemy 06
 +
2B - Enemy 07
 +
2C - Enemy 08
 +
2D - Enemy 09
 +
2E - Enemy 0A
 +
2F - Random enemy with $7E:AF15 bit 80 set
 +
30 - PC 1. This and the following routines were most likely designed for condition 1C, check for specific PC. If used in that condition, it would check for Crono.
 +
31 - PC 2
 +
32 - PC 3
 +
33 - Enemy 3
 +
34 - Enemy 4
 +
35 - Enemy 5
 +
36 - Enemy 6
 +
37 - PC with highest HP
 +
38 - Random enemy other than self</pre>
  
 
==Supplemental Material==
 
==Supplemental Material==
[[EnemyAI Old]]
+
*[[EnemyAI Old]]
 +
*[[Enemy AI_Listings]]
  
 
''From'': [[Offsets (Chrono Trigger)]]
 
''From'': [[Offsets (Chrono Trigger)]]

Revision as of 22:54, 13 November 2017

Notes on Enemy AI are currently incomplete; eventually, data will be decoded and added into Temporal Flux for functionality. Enemy AI information will be updated as new stuff comes.

Offsets

Directly from Geiger's Offsets.txt
___________________________________________________________________
0C8B08 0C8D07 PTR No No Pointers to Enemy AI (local) 6/21/2004
0C8D08 0CCBC8 AI No No Enemy AI 7/14/2003
___________________________________________________________________



Summary

Enemy AI is divided into two blocks that terminate with $FF.

AAAAAAAAFF
BBBBBBBBFF

The first block contains actions that the enemy performs on its own. The second block contains reactions when the enemy is attacked.

Each block can be broken down into sections that alternate between Condition and Action.


Condition

Conditions are a multiple of 4 bytes, each of which is a boolean statement. All must be true for the following Action section to be executed. The section is terminated by $FE.

Action

Actions can contain one or more commands to perform. An enemy's attack meter must refill first before it can continue with the next command. The section is terminated by $FE.

Conditions

There is a total of 41 Conditions ($00-28)

xx - unused, 
tt - targeting byte 80 - copy flag, copies $7E:AED8 to $7E:AECC, ignore Targeting 0x7F - targeting routine, 
?? - unknown
00 xx xx xx - Default, always passes.
01 tt xx xx - HP less than half (tt is usually set to 03 for current enemy, 
              but other values could be used).
02 tt oo bb - Check for status. tt - Target, 00 for PCs, 01 for enemies. oo - Offset from 
              battle data 0x1D (start of status flags). bb - Bits to check.
03 tt mm xx - Checks if something moved. mm - Monster/PC index
04 xx mm ss - Checks status of monster mm - monster index, ss - Status - 00 Alive, 01 - Dead.
05 nn xx xx - Checks for maximum number of living enemies. nn - number of enemies.
06 ff ff ff - Check if battle frame counter is at least ff. 
              Value is little endian (lowest byte stored first).
07 vv cc xx - Check custom mode. vv - value, cc - Compare type - 00 >=, 01 <=
08 tt hh hh - Check if HP <= value. hh - HP to compare. 
              Value is little endian (lowest byte stored first).
09 tt ss vv - Check if stat is less than value. ss - stat offset. vv - value
0A tt ss bb - Check if stat has bitflags set. ss - stat offset, bb - bitflags set.
0B tt ss vv - Check if stat is less than or equal to value. ss - stat offset, vv - value.
0C tt ff xx - Check if target is inside or outside of a 32 pixel radius. ff - 00 Inside, 01 Outside
0D tt ff xx - Check if X distance against 32 pixels. ff - 00 >, 01 <=
0E tt rr ?? - Distance related. rr - result check mode.
0F tt rr ?? - Distance related. rr - result check mode.
10 xx bb aa - Likely distance related. aa - First calculation switch. bb - Second calculation switch
11 ee xx mm - Check if hit by tech type. ee - 00 player tech, 01 enemy tech. mm - 00 ==, 01 !=
12 ee aa mm - Check if hit by specific tech.  ee - 00 player tech, 01 enemy tech. aa - tech index. 
              mm - 00 ==, 01 !=
13 aa xx mm - Check Attacker. aa - 00 player, 01 enemy. mm - 0 ==, 01 !=
14 vv mm ee - Check specific attacker. mm - mode 00 Check attacker against value vv, 01 buggy. 
              ee - 00 ==, 01 !=. 
              Only checks against player techs and attacks, or enemy techs without enemy vs 
              enemy attack set. There is a minor bug in mode 00 when ee is 01. Set 0x019551 
              to 89 to fix in the Japanese and US releases.
15 ee xx ff - Checks element of attack, ff - 00 ==, 01 !=, ee - element 20 Ice, 10 Fire, 
              80 Lightning, 40 Shadow, 02 Magic, 04 Physical
16 xx xx xx - Copy of 00.
17 pp xx xx - Percent chance. pp - percent
18 vv tt ss - Check if stat is equal. vv - value, ss - stat offset.
19 xx xx xx - Copy of 00.
1A mm aa ss - Check if monster type is alone or not. mm - monster index, aa - 0 - alone, 
              1 - with other types. 
              ss - If with other types, should the condition succeed? 0 - fail, 1 - succeed.
1B pp xx xx - Count of living PCs is at most pp.
1C tt pp ll - Is PC present or absent. tt can load any targeting routine, but only routines 30-36 
              will produce expected results. 
              pp - Presence status. 00 - Present, 01 - Absent. ll - Life status. 01 - may be dead.
1D tt xx aa - Check if target is alive or not.
1E xx xx xx - Copy of 00 that sets $7E:AF24 (failure status) to 1 (failed).
1F tt ff xx - Check if target is inside or outside of a 48 pixel radius. ff - 00 Inside, 01 Outside
20 xx xx xx - Final Attack.
21 xx xx xx - $7E:AF15 related.
22 tt ?? cc - $7E:B158 related. cc - compare type 0 - Less than, 1 - Greater than or equal to.
23 vv tt ss - (same as 18)
24 vv tt ss - (same as 18)
25 vv tt ss - (same as 18)
26 vv tt ss - (same as 18)
27 vv tt ss - (same as 18)
28 vv tt ss - (same as 18)

Actions

There is a total of 23 Actions ($00-16)

00 ?? jj ??  wander mode.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index
01 aa jj ??  attack mode.  aa - attack index jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index
02 tt jj jj jj ss  tech mode.  tt - tech index jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index ss - battle enemy message string
03 (nothing, no routines)
04  random action.  uses a random number to determine which action in current section to start on.
05 ?? ??  unknown, possibly unused, and not confirmed if it is a 3 byte command.
06 (nothing, no routines)
07 mm aa hh  become monster.  mm - monster to turn into aa - animation? hh - hp
08 (nothing, no routines)
09 ??  display flashes for distant attack?
0A aa ss  run away.  aa - action to show ss - battle enemy message string
0B oo vv mm ss  set stat.  oo - offset from enemy stat set start vv - value to set/bitwise OR mm - mode, 00 set value 01 bitwise OR ss - battle enemy message string
0C oo vv ss  stat math.  oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
0D ?? ss  unknown, state change?  ss - battle enemy message string
0E (nothing, no routines)
0F ss  display text.  ss - battle enemy message string
10 vv ee ss  revive support enemies.  vv - unk. stored to temp 7E000E ee - battle sound effect ss - battle enemy message string
11 oo vv oo vv oo vv oo vv ss  multi stat set.  oo - offset from enemy stat set start vv - value to set ss - battle enemy message string
12 ?? ?? jj jj oo vv oo vv oo vv oo vv oo vv ss  special multi stat set.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index  oo - offset from enemy stat set start vv - value to set ss - battle enemy message string
13 jj vv  unknown, possibly unused, and not confirmed if it is a 3 byte command.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index vv - unknown value stored to temp 7E000E
14 oo vv oo vv oo vv oo vv ss  multi stat math.  oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
15 ?? ?? jj jj oo vv oo vv oo vv oo vv oo vv ss  special multi stat math.  jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index oo - offset from enemy stat set start vv - multipurpose byte, 80 subtract flag, 7F amount to add/sub ss - battle enemy message string
16 -- tt oo vv oo vv oo vv oo vv ss  multi revive and set stat.  tt - tech/tech animation related index oo - offset from enemy stat set start vv - value to set ss - battle enemy message string


Older data not 100% confirmed:


00 WW XX YY            - wander mode YY is how you wander, WW animation related?
02 WW 05 XX YY ZZ      - Spell WW, Message ZZ, XX YY for double/triple?

Enemy AI Targeting subroutines

Used by Conditions: 01, 03, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 18, 1C*, 1D, 1F, 22, 23-28 Used by Actions: 00, 01, 02, 12, 13, 15

  • Condition 1C does not treat the data obtained the from the routines the same way as the others, so it will have unexpected results.

jj - Multiply x2 + 0x01B8BB to obtain the pointer

00 - Nothing
01 - All PCs
02 - All enemies
03 - Current enemy
04 - Attacking PC
05 - Random PC
06 - Nearest PC
07 - Farthest PC
08 - PC with lowest HP. This routine does not properly check PC1's HP. To fix, replace 0x01A50C (unheadered US or Japanese ROM) with D0 05 EA EA.
09 - PCs with any flags on battle data 0x1D set. 80 is used for a dead PC, others are unknown.
0A - PCs with any negative status.
0B - PCs with any flags on battle data 0x1F (unknown)
0C - PCs with any positive status from set 1 (2x Evade/Unknown Status/2.5x Evade/Haste)
0D - PCs with any positive status from set 2 (Attack Power Up/Shield (Defense Up)/Max Attack Power Up/MP Regen/Barrier (M. Defense Up)/Berserk)
0E - Sleeping PCs
0F - Stopped PCs
10 - Confused PCs
11 - Shielded (Defense Up) PCs
12 - Barriered (M. Defense Up) PCs
13 - PCs with bit 10 of positive status set 2 (unused)
14 - PCs with bit 8 of battle data 01 (unknown)
15 - Other enemies
16 - Living enemies
17 - Nearest enemy
18 - Farthest enemy
19 - Enemy with lowest HP
1A - Other enemies with any battle data 0x1D flags set
1B - All enemies with any battle data 0x1D flags set
1C - Other enemies with any negative status
1D - All enemies with any negative status
1E - Other enemies with any flags on battle data 0x1F (unknown)
1F - All enemies with any flags on battle data 0x1F (unknown)
20 - Other Sleeping enemies
21 - Other Stopped enemies
22 - Other Confused enemies
23 - Other Barriered (M. Defense Up) enemies
24 - Other enemies with 0x1D bitflag 2 set
25 - Other enemies with 0x19 bitflag 1 set
26 - Enemy with lowest HP other than self
27 - Enemy 03. This and the following routines are mostly used with multi-part bosses. Enemy index is determined by event commands.
28 - Enemy 04
29 - Enemy 05
2A - Enemy 06
2B - Enemy 07
2C - Enemy 08
2D - Enemy 09
2E - Enemy 0A
2F - Random enemy with $7E:AF15 bit 80 set
30 - PC 1. This and the following routines were most likely designed for condition 1C, check for specific PC. If used in that condition, it would check for Crono.
31 - PC 2
32 - PC 3
33 - Enemy 3
34 - Enemy 4
35 - Enemy 5
36 - Enemy 6
37 - PC with highest HP
38 - Random enemy other than self

Supplemental Material

From: Offsets (Chrono Trigger)