AI ability processing

From Final Fantasy Hacktics Wiki
Revision as of 23:48, 8 March 2017 by Dokurider (talk | contribs) (New Documentation)
Jump to navigation Jump to search
Unit Reactions Evaluation Routine
0019dd8c: 27bdff90 addiu r29,r29,0xff90
0019dd90: afb40058 sw r20,0x0058(r29)
0019dd94: 0080a021 addu r20,r4,r0		r20 = Acting Unit ID Pointer
0019dd98: afb1004c sw r17,0x004c(r29)
0019dd9c: 3c11801a lui r17,0x801a
0019dda0: 2631f3c4 addiu r17,r17,0xf3c4		r17 = AI Data Pointer
0019dda4: afbf006c sw r31,0x006c(r29)
0019dda8: afbe0068 sw r30,0x0068(r29)
0019ddac: afb70064 sw r23,0x0064(r29)
0019ddb0: afb60060 sw r22,0x0060(r29)
0019ddb4: afb5005c sw r21,0x005c(r29)
0019ddb8: afb30054 sw r19,0x0054(r29)
0019ddbc: afb20050 sw r18,0x0050(r29)
0019ddc0: afb00048 sw r16,0x0048(r29)
0019ddc4: 14a00006 bne r5,r0,0x0019dde0		Branch if Evaluating a Reacting Unit/Reaction
0019ddc8: afa50040 sw r5,0x0040(r29)		Store PV
0019ddcc: 92840000 lbu r4,0x0000(r20)		Load Acting Unit's ID
0019ddd0: 0c05f26e jal 0x0017c9b8			Prep Current Action Data
0019ddd4: 00000000 nop
0019ddd8: 144000d4 bne r2,r0,0x0019e12c		Branch if Usage Result != 0
0019dddc: 00000000 nop
0019dde0: 86820002 lh r2,0x0002(r20)		Load Acting Unit's Used Ability ID
0019dde4: 3c038006 lui r3,0x8006
0019dde8: 2463ebf4 addiu r3,r3,0xebf4
0019ddec: 000210c0 sll r2,r2,0x03		ID * 8
0019ddf0: 00439821 addu r19,r2,r3		r19 = Ability's AI Behavior Flags 1 Pointer
0019ddf4: 3c03801a lui r3,0x801a
0019ddf8: 9063007e lbu r3,0x007e(r3)		Load ?
0019ddfc: 340200ff ori r2,r0,0x00ff		r2 = FF
0019de00: 1062000a beq r3,r2,0x0019de2c		Branch if ? = FF
0019de04: 341500ff ori r21,r0,0x00ff		r21 = FF
0019de08: 0000b021 addu r22,r0,r0		r22 = 0
0019de0c: 0000f021 addu r30,r0,r0		r30 = 0
0019de10: 92620000 lbu r2,0x0000(r19)		Load Ability's AI Behavior Flags
0019de14: 00000000 nop
0019de18: 30420008 andi r2,r2,0x0008
0019de1c: 10400003 beq r2,r0,0x0019de2c		Branch if Ability doesn't have Stat Changes
0019de20: 34170001 ori r23,r0,0x0001		r23 = Target Priority - 1
0019de24: 341e0003 ori r30,r0,0x0003		r30 = Target Priority + 3
0019de28: 34170004 ori r23,r0,0x0004		r23 = Target Priority - 4
<Begin Main Loop?>
0019de2c: 92840000 lbu r4,0x0000(r20)		r4 = Acting Unit's ID
0019de30: 0c05f391 jal 0x0017ce44			Main Ability Routine (Check if ability is targeting a unit, then calculate damage)
0019de34: 27a50010 addiu r5,r29,0x0010		r5 = Stack Pointer + 0x10
0019de38: 14400083 bne r2,r0,0x0019e048		Branch if ability is not hitting a unit
0019de3c: 00000000 nop
0019de40: 93a20011 lbu r2,0x0011(r29)
0019de44: 00000000 nop
0019de48: 1040007f beq r2,r0,0x0019e048		Branch if false
0019de4c: 27a30012 addiu r3,r29,0x0012
0019de50: 93a20012 lbu r2,0x0012(r29)		Load Ability Counter
0019de54: 00000000 nop
0019de58: 1055007b beq r2,r21,0x0019e048	Branch if ? = FF (Skip Ability Loop)
0019de5c: afa00038 sw r0,0x0038(r29)		Empty Ability Counter
<Begin Ability Loop>
0019de60: 8fa20038 lw r2,0x0038(r29)		Load Ability Counter
0019de64: 00000000 nop
0019de68: 00621021 addu r2,r3,r2
0019de6c: 90500000 lbu r16,0x0000(r2)		Load Acting Unit ID?
0019de70: 3c038019 lui r3,0x8019
0019de74: 24630a58 addiu r3,r3,0x0a58		Load Current Action Data (0x018c)
0019de78: 001010c0 sll r2,r16,0x03
0019de7c: 00501023 subu r2,r2,r16
0019de80: 00021180 sll r2,r2,0x06
0019de84: 00439021 addu r18,r2,r3
<Can this ability hit this unit?>
0019de88: 8642002a lh r2,0x002a(r18)		Load Hit % (Displayed Amount)
0019de8c: 00000000 nop
0019de90: 18400064 blez r2,0x0019e024		Branch if negative
0019de94: 00000000 nop
0019de98: 92620001 lbu r2,0x0001(r19)		Load AI Ability Behavior Flag 2
0019de9c: 00000000 nop
0019dea0: 30420080 andi r2,r2,0x0080
0019dea4: 1440001d bne r2,r0,0x0019df1c		Branch if Ignore Range
0019dea8: 00000000 nop
0019deac: 0c065b3a jal 0x00196ce8			Check if Unit can be hit (Crystal/Treasure/Transparent/Mounted)
0019deb0: 02002021 addu r4,r16,r0
0019deb4: 1440005b bne r2,r0,0x0019e024		Branch if Unit cannot be hit
0019deb8: 34020006 ori r2,r0,0x0006
0019debc: 9283000a lbu r3,0x000a(r20)		Load TargetUnitorPanel
0019dec0: 00000000 nop
0019dec4: 1462000c bne r3,r2,0x0019def8		Branch if ability is targeting Unit (as opposed to Tile)
0019dec8: 00000000 nop
0019decc: 9283000b lbu r3,0x000b(r20)		Load Target ID?
0019ded0: 00000000 nop
0019ded4: 02231021 addu r2,r17,r3
0019ded8: 90420e18 lbu r2,0x0e18(r2)		Load Targetable Unit List
0019dedc: 00000000 nop
0019dee0: 10400005 beq r2,r0,0x0019def8		Branch if Unit is targeting self/not targeting anything?
0019dee4: 00000000 nop
0019dee8: 1070000c beq r3,r16,0x0019df1c	Branch if targeting own panel
0019deec: 00000000 nop
0019def0: 08067809 j 0x0019e024
0019def4: 00000000 nop
<Targeting Unit>
0019def8: 92620000 lbu r2,0x0000(r19)		Load Ability AI Behavior Flag 1
0019defc: 00000000 nop
0019df00: 30420001 andi r2,r2,0x0001
0019df04: 14400005 bne r2,r0,0x0019df1c		<Reaction Routine> if Ability Targets Allies
0019df08: 02301021 addu r2,r17,r16
0019df0c: 90420e18 lbu r2,0x0e18(r2)		Load Targetable Unit List?
0019df10: 00000000 nop
0019df14: 14400043 bne r2,r0,0x0019e024		Branch if Unit isn't targeting anything?
0019df18: 00000000 nop
0019df1c: 0c062f82 jal 0x0018be08			Main Reaction Routine
0019df20: 02002021 addu r4,r16,r0
0019df24: 92220cba lbu r2,0x0cba(r17)		Load Usable Ability Counter
0019df28: 00000000 nop
0019df2c: 1055003d beq r2,r21,0x0019e024	Loop if No Usable Abilities Yet
0019df30: 00000000 nop
<Target Allies>
0019df34: 92630000 lbu r3,0x0000(r19)		Load Ability AI Behavior Flag 1
0019df38: 00000000 nop
0019df3c: 30620002 andi r2,r3,0x0002
0019df40: 10400006 beq r2,r0,0x0019df5c		Branch if Ability does not target Enemies
0019df44: 00101100 sll r2,r16,0x04
0019df48: 02221021 addu r2,r17,r2
0019df4c: 90421834 lbu r2,0x1834(r2)		Load Enemy Flag
0019df50: 00000000 nop
0019df54: 14400009 bne r2,r0,0x0019df7c		Branch to modify Priority if Enemy	
0019df58: 00000000 nop
0019df5c: 30620001 andi r2,r3,0x0001
0019df60: 10400009 beq r2,r0,0x0019df88		Branch if Ability is not Target Allies
0019df64: 00101100 sll r2,r16,0x04
0019df68: 02221021 addu r2,r17,r2
0019df6c: 90421834 lbu r2,0x1834(r2)		Load Enemy Flag
0019df70: 00000000 nop
0019df74: 14400004 bne r2,r0,0x0019df88		Branch if Enemy
0019df78: 00000000 nop
0019df7c: 96220032 lhu r2,0x0032(r17)		Load Target Priority
0019df80: 080677f7 j 0x0019dfdc				Jump and Save Priority (For Allied Unit)
0019df84: 005e1021 addu r2,r2,r30			Add +3/other value to Target Priority
<If Target Enemy>
0019df88: 92630000 lbu r3,0x0000(r19)		Load Ability AI Behavior Flag 1
0019df8c: 00000000 nop
0019df90: 30620002 andi r2,r3,0x0002
0019df94: 10400006 beq r2,r0,0x0019dfb0		Branch if Ability is not Target Enemies
0019df98: 00101100 sll r2,r16,0x04
0019df9c: 02221021 addu r2,r17,r2
0019dfa0: 90421834 lbu r2,0x1834(r2)		Load Enemy Flag
0019dfa4: 00000000 nop
0019dfa8: 10400009 beq r2,r0,0x0019dfd0		Branch if Ally
0019dfac: 00000000 nop
0019dfb0: 30620001 andi r2,r3,0x0001
0019dfb4: 1040000a beq r2,r0,0x0019dfe0		Branch if Ability is not Target Allies
0019dfb8: 00101100 sll r2,r16,0x04
0019dfbc: 02221021 addu r2,r17,r2
0019dfc0: 90421834 lbu r2,0x1834(r2)		Load Enemy Flag
0019dfc4: 00000000 nop
0019dfc8: 10400005 beq r2,r0,0x0019dfe0		Branch if Ally
0019dfcc: 00000000 nop
0019dfd0: 96220032 lhu r2,0x0032(r17)		Load Target Priority
0019dfd4: 00000000 nop
0019dfd8: 00571023 subu r2,r2,r23			Subtract 1 or 4 from Priority
0019dfdc: a6220032 sh r2,0x0032(r17)		Save Unit Target Priority
<If Target Neither>
0019dfe0: 92220cba lbu r2,0x0cba(r17)		Usable Ability Counter
0019dfe4: 00000000 nop
0019dfe8: 24420001 addiu r2,r2,0x0001
0019dfec: a2220cba sb r2,0x0cba(r17)		Usable Ability Counter++
0019dff0: 96220cb8 lhu r2,0x0cb8(r17)		Load AI Hit %
0019dff4: 9643002a lhu r3,0x002a(r18)		Load Hit % (Displayed Amount)
0019dff8: 92240e2e lbu r4,0x0e2e(r17)		Load Acting Unit ID
0019dffc: 00431021 addu r2,r2,r3
0019e000: 16040002 bne r16,r4,0x0019e00c	Branch if not Targeting Self? Not the current acting unit this turn?
0019e004: a6220cb8 sh r2,0x0cb8(r17)		Save Hit %
0019e008: 34160001 ori r22,r0,0x0001		r22 = 1
0019e00c: 02301021 addu r2,r17,r16
0019e010: 90420c8d lbu r2,0x0c8d(r2)		Load Calculator Type ID?
0019e014: 00000000 nop
0019e018: 10400002 beq r2,r0,0x0019e024		Branch if not planning on using a Math Skill?
0019e01c: 34020001 ori r2,r0,0x0001
0019e020: a22219ba sb r2,0x19ba(r17)		Ability can hit because it's a math skill?
<Next Ability?>
0019e024: 8fa20038 lw r2,0x0038(r29)		Load Ability Counter
0019e028: 27a30012 addiu r3,r29,0x0012
0019e02c: 24420001 addiu r2,r2,0x0001
0019e030: afa20038 sw r2,0x0038(r29)		
0019e034: 00621021 addu r2,r3,r2
0019e038: 90420000 lbu r2,0x0000(r2)		Load Ability List?
0019e03c: 00000000 nop
0019e040: 1455ff87 bne r2,r21,0x0019de60	Loop until End of Ability List
0019e044: 00000000 nop
<Next ?>
0019e048: 92840000 lbu r4,0x0000(r20)		Load Unit Data	
0019e04c: 0c0635c3 jal 0x0018d70c			Store target stats pointer data
0019e050: 00000000 nop
0019e054: 93a20028 lbu r2,0x0028(r29)		Load ?
0019e058: 00000000 nop
0019e05c: 1440ff73 bne r2,r0,0x0019de2c		Loop until False
0019e060: 340200ff ori r2,r0,0x00ff
0019e064: 92230cba lbu r3,0x0cba(r17)		Load # of Usable Abilities
0019e068: 00000000 nop
0019e06c: 10620012 beq r3,r2,0x0019e0b8		Branch if no usable abilities (FF = default)
0019e070: 00000000 nop
0019e074: 92220e4d lbu r2,0x0e4d(r17)		Acting units ID?
0019e078: 00000000 nop
0019e07c: 1040000e beq r2,r0,0x0019e0b8		Branch if self?
0019e080: 34020001 ori r2,r0,0x0001
0019e084: 92230e4c lbu r3,0x0e4c(r17)		Load ?
0019e088: 00000000 nop
0019e08c: 14620004 bne r3,r2,0x0019e0a0		Branch if not 1
0019e090: 00000000 nop
0019e094: 16c00007 bne r22,r0,0x0019e0b4	Branch if able to hit target
0019e098: 34020001 ori r2,r0,0x0001
0019e09c: 92230e4c lbu r3,0x0e4c(r17)		Load ?
0019e0a0: 34020002 ori r2,r0,0x0002
0019e0a4: 14620004 bne r3,r2,0x0019e0b8		Branch if not 2
0019e0a8: 00000000 nop
0019e0ac: 16c00002 bne r22,r0,0x0019e0b8	Branch if able to hit Target
0019e0b0: 34020001 ori r2,r0,0x0001
0019e0b4: a2220e4e sb r2,0x0e4e(r17)		Can effect target = True?
<Evaluate Reactions to Ability>
0019e0b8: 92820000 lbu r2,0x0000(r20)		Load Acting Unit's ID
0019e0bc: 3c108019 lui r16,0x8019
0019e0c0: 261008cc addiu r16,r16,0x08cc		r16 = Unit Data Pointer
0019e0c4: 000220c0 sll r4,r2,0x03
0019e0c8: 00822023 subu r4,r4,r2
0019e0cc: 00042180 sll r4,r4,0x06			Unit ID * 1c0
0019e0d0: 0c05f6f2 jal 0x0017dbc8			Store Some Acting Unit Data
0019e0d4: 00902021 addu r4,r4,r16			Get Acting Unit Data
0019e0d8: 8fa60040 lw r6,0x0040(r29)		Load isEvaluatingReactingUnit
0019e0dc: 00000000 nop
0019e0e0: 14c00012 bne r6,r0,0x0019e12c		Exit if routine was evaluating reacting unit (and to prevent an infinite loop)
0019e0e4: 2413ffff addiu r19,r0,0xffff
0019e0e8: 2612016e addiu r18,r16,0x016e		Point to Target Action Data
0019e0ec: 0c05f85e jal 0x0017e178			Check if any unit can react
0019e0f0: 27a40038 addiu r4,r29,0x0038
0019e0f4: 00408021 addu r16,r2,r0			r16 = Reactor ID?
0019e0f8: 1213000c beq r16,r19,0x0019e12c	Exit if no unit reacted
<Ability can be reacted to>
0019e0fc: 02301021 addu r2,r17,r16
0019e100: 90420e18 lbu r2,0x0e18(r2)		Load Targetable Unit List?
0019e104: 00000000 nop
0019e108: 1440fff8 bne r2,r0,0x0019e0ec		Branch if Reactor isn't hitting anyone?	
0019e10c: 001020c0 sll r4,r16,0x03			Next Unit
0019e110: 00902023 subu r4,r4,r16			r4 = Pointer - Reactor ID
0019e114: 00042180 sll r4,r4,0x06			Unit Target ID Pointer
0019e118: 00922021 addu r4,r4,r18			Get Target Data for Reactor
0019e11c: 0c067763 jal 0x0019dd8c			Loop through this entire current routine again (!)
0019e120: 34050001 ori r5,r0,0x0001			isEvaluatingReactingUnit = True
0019e124: 0806783b j 0x0019e0ec				Loop for all effected units
0019e128: 00000000 nop
<Exit>
0019e12c: 8fbf006c lw r31,0x006c(r29)
0019e130: 8fbe0068 lw r30,0x0068(r29)
0019e134: 8fb70064 lw r23,0x0064(r29)
0019e138: 8fb60060 lw r22,0x0060(r29)
0019e13c: 8fb5005c lw r21,0x005c(r29)
0019e140: 8fb40058 lw r20,0x0058(r29)
0019e144: 8fb30054 lw r19,0x0054(r29)
0019e148: 8fb20050 lw r18,0x0050(r29)
0019e14c: 8fb1004c lw r17,0x004c(r29)
0019e150: 8fb00048 lw r16,0x0048(r29)
0019e154: 27bd0070 addiu r29,r29,0x0070
0019e158: 03e00008 jr r31
0019e15c: 00000000 nop