Difference between revisions of "Enemy AI"

From Chrono Compendium
Jump to: navigation, search
(List of all targeting subroutines.)
Line 138: Line 138:
 
</pre>
 
</pre>
  
==Enemy AI subroutines==
+
==Enemy AI Targeting subroutines==
  
Used by Conditions: 18, and many others (to be determined)<br>
+
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<br><br>
+
Used by Actions: 00, 01, 02, 12, 13, 15
  
jj - Multiply x2 + 01B8BB to obtain the pointer<br><br>
+
*Condition 1C does not treat the data obtained the from the routines the same way as the others, so it will have unexpected results.
  
<tt>
+
jj - Multiply x2 + 0x01B8BB to obtain the pointer
00 - nothing, no routines<br>
+
 
03 - used by Condition 18, enemy stat related?<br>
+
<tt>00 - Nothing
04 - used by Condition 18, PC stat related?<br>
+
01 - All PCs
05 - target random PC<br>
+
02 - All enemies
06 - target nearest PC<br>
+
03 - Current enemy
08 - target PC using unknown PC HP conditions<br>
+
04 - Attacking PC
</tt>
+
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</tt>
  
 
==Supplemental Material==
 
==Supplemental Material==

Revision as of 01:11, 16 September 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)

00 ?? ?? ?? nothing.  continue with following Action
01 hh ?? ?? check health.  hh - 03=50%
02 ?? ?? ??
03 ?? mm ?? unknown.  mm - monster index
04 ?? mm ?? check if monster is alive.  mm - monster index
05 nn ?? ?? check number of enemies.  nn - minimum? number of enemies that must exist for the following Action to be executed
06 ?? ?? ??
07 nn ?? ?? check times attacked.  nn - number of times the enemy must be attacked for the following Action section to be executed
08 ?? ?? ??
09 ?? ?? ?? check if hit at all
0A ?? ?? ??
0B ?? ?? ??
0C ss ?? ?? check if hit by status ss.  ss = 01 chaos, 00 none, 06 sleep
0D ?? ?? ??
0E ?? ?? ??
0F ?? ?? ??
10 ?? ?? ?? (only used once for Enemy $F8 R Series?)
11 ?? ?? ?? check if hit by magic
12 ?? tt ?? if hit with tech.  tt - tech index
13 ?? ?? ??
14 ?? ?? ??
15 ee ?? ?? if hit by element.  ee - 80=lightning
16 ?? ?? ?? (possibly unused)
17 cc ?? ?? load random number.  cc - chance to execute following Action
18 vv jj oo check weapon or other stat.  vv - weapon index or other value to check if equal jj - multipurpose byte, 80 copy flag: 7EAED8 to 7EAECC, 7F subroutine index oo - offset from stat set start
19 ?? ?? ??
1A mm nn ?? if  number monsters alive?? -- mm monster index, nn number needed to be alive
1B nn ?? ?? if num pc's  (alive?) -- number of pc's
1C ?? ?? ??
1D ?? ?? ??
1E ?? ?? ??
1F ?? ?? ?? check distance.
20 ?? ?? ?? check if defeated.
21 ?? ?? ??
22 ?? ?? ??
23 ?? ?? ?? (same as 18)
24 ?? ?? ?? (same as 18)
25 ?? ?? ?? (same as 18)
26 ?? ?? ?? (same as 18)
27 ?? ?? ?? (same as 18)
28 ?? ?? ?? (same as 18)


Older data not 100% confirmed:


05 XX 00 00 - number of enemies atleast XX
40 00 XX 01 - If monster XX is dead...byte 2/4 unexplored
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)?

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)