Set AI Flags/Usable Abilities
Jump to navigation
Jump to search
BATTLE.BIN : Set AI Flags/Usable Abilities - (some notes) --------------------------------------------------------------------------------------------- Parameters : r4 = Unit ID Returns : nothing --------------------------------------------------------------------------------------------- 0019a2f0: 27bdffc0 addiu r29,r29,-0x0040 | 0019a2f4: afb3002c sw r19,0x002c(r29) | 0019a2f8: 00809821 addu r19,r4,r0 |r19 = Unit's ID 0019a2fc: afb10024 sw r17,0x0024(r29) | 0019a300: 001310c0 sll r2,r19,0x03 |ID * 8 0019a304: 00531023 subu r2,r2,r19 |ID * 7 0019a308: 00021180 sll r2,r2,0x06 |ID * 0x1c0 0019a30c: 3c038019 lui r3,0x8019 | 0019a310: 246308cc addiu r3,r3,0x08cc |Start of Unit Battle data 0019a314: afb20028 sw r18,0x0028(r29) | 0019a318: 00439021 addu r18,r2,r3 |r18 = Unit's Data Pointer 0019a31c: afb50034 sw r21,0x0034(r29) | 0019a320: 3c15801a lui r21,0x801a | 0019a324: 26b5f3c4 addiu r21,r21,-0x0c3c |r21 = AI used ability Data Pointer 8019f3c4 / 0x8019f3c4 0019a328: afbf003c sw r31,0x003c(r29) | 0019a32c: afb60038 sw r22,0x0038(r29) | 0019a330: afb40030 sw r20,0x0030(r29) | 0019a334: afb00020 sw r16,0x0020(r29) | 0019a338: 92420012 lbu r2,0x0012(r18) |Load Unit's Primary Skillset 0019a33c: 3c01801a lui r1,0x801a | 0019a340: 00330821 addu r1,r1,r19 | 0019a344: 90340d50 lbu r20,0x0d50(r1) |Load Unit's Battle ID (From AI data) 0019a348: 2c4200b0 sltiu r2,r2,0x00b0 |Check if skillset is a monster skillset (start at 0xb0) 0019a34c: 10400047 beq r2,r0,0x0019a46c #If not a monster skillset 0019a350: 00008821 addu r17,r0,r0 |Ability counter = 0x00 0019a354: 00141100 sll r2,r20,0x04 |ID * 16 0019a358: 00541021 addu r2,r2,r20 |ID * 17 0019a35c: 000210c0 sll r2,r2,0x03 |ID * 0x88 0019a360: 00551021 addu r2,r2,r21 |Part of pointer to unit AI move list 8019f3c4 + Unit offset (for unit moves list) 0019a364: 34160001 ori r22,r0,0x0001 |r22 = 1 0019a368: 00131a80 sll r3,r19,0x0a |ID * 0x400 0019a36c: a0560ef2 sb r22,0x0ef2(r2) |Store 1st usable ability Skillset = 1 (Attack) 0x8019f3c4 + 0xef0 - 0x02 + Unit offset 0019a370: a4430ef0 sh r3,0x0ef0(r2) |Store Unit's ID * 4 in 1st usable ability byte 0x01 0019a374: 001410c0 sll r2,r20,0x03 |ID * 8 (unit offset) 0019a378: 24421778 addiu r2,r2,0x1778 | 0019a37c: 00558021 addu r16,r2,r21 |Pointer to unit AI weapon data (AI 0x1778 + Unit offset) 0019a380: ae000000 sw r0,0x0000(r16) |Nullify Unit's AI weapon data from range to AI behavior flag3 0019a384: 92020001 lbu r2,0x0001(r16) |Load AI Behavior Flags 1 0019a388: 92030003 lbu r3,0x0003(r16) |Load AI Behavior Flags 3 0019a38c: ae000004 sw r0,0x0004(r16) |Nullify Unit's AI weapon data from Weapon ID to Byte 0x07 0019a390: 34420080 ori r2,r2,0x0080 |Enable [Affect HP] flag 0019a394: a2020001 sb r2,0x0001(r16) |Store new AI Behavior Flags 1 (with affect HP) 0019a398: 92020002 lbu r2,0x0002(r16) |Load AI Behavior Flags 2 (? Just nullified) 0019a39c: 34630001 ori r3,r3,0x0001 |Enable [Physical Attack] flag 0019a3a0: a2030003 sb r3,0x0003(r16) |Store new AI Behavior Flags 3 (Physical Attack) 0019a3a4: 34420002 ori r2,r2,0x0002 |Enable [Evadeable] Flag 0019a3a8: a2020002 sb r2,0x0002(r16) |Store new AI Behavior Flags 2 (Just Evadable flag) 0019a3ac: afa00010 sw r0,0x0010(r29) |Nullify Stack pointer 0019a3b0: 92420006 lbu r2,0x0006(r18) |Load Unit's Gender byte 0019a3b4: 00000000 nop | 0019a3b8: 30420020 andi r2,r2,0x0020 |Check for Monster 0019a3bc: 14400008 bne r2,r0,0x0019a3e0 #If Unit is not a monster 0019a3c0: 02002021 addu r4,r16,r0 |r4 = Unit's AI Weapon data pointer 0019a3c4: 9245001d lbu r5,0x001d(r18) |Load Unit's RH Weapon ID 0019a3c8: 0c06694b jal 0x0019a52c |-->Store Weapon? Attack Data Update, Range, Behavior 3, ID and Elements and returns flags on stack pointer 0019a3cc: 27a60010 addiu r6,r29,0x0010 |r6 = Pointer to stack 0019a3d0: 02002021 addu r4,r16,r0 |r4 = Unit's AI Weapon data pointer 0019a3d4: 9245001f lbu r5,0x001f(r18) |Load Unit's LH Weapon 0019a3d8: 0c06694b jal 0x0019a52c |-->Store Weapon? Attack Data Same as above, Overwrite ID and Range, Combine Behavior and Elements 0019a3dc: 27a60010 addiu r6,r29,0x0010 |r6 = Pointer to stack 0019a3e0: 8fa30010 lw r3,0x0010(r29) |Load Flags stored on Stack ( Normal - Absorb - Heal) 0019a3e4: 34020001 ori r2,r0,0x0001 | 0019a3e8: 10620010 beq r3,r2,0x0019a42c #Branch to Normal weapon section if flag = 0x01 0019a3ec: 28620002 slti r2,r3,0x0002 |check if flag is 0x00 (since 0x01 has branched)) 0019a3f0: 10400005 beq r2,r0,0x0019a408 #If unit don't uses a special weapon (Flag is not 0x00 and not 0x01) 0019a3f4: 00000000 nop | 0019a3f8: 1060000b beq r3,r0,0x0019a428 #Branch to unarmed section if flag = 0x00 0019a3fc: 00000000 nop | 0019a400: 0806691b j 0x0019a46c >>Negative check : Avoid all section Should never happen (Flag is not 0x01 not 0x00 and not>= 0x02) 0019a404: 26310001 addiu r17,r17,0x0001 |Ability counter = 0x01 0019a408: 34020002 ori r2,r0,0x0002 #Else : Unit uses a special weapon 0019a40c: 1062000c beq r3,r2,0x0019a440 #Branch to Absorption section if Flag = 0x02 0019a410: 00000000 nop | 0019a414: 34020004 ori r2,r0,0x0004 | 0019a418: 1062000d beq r3,r2,0x0019a450 #Branch to Healing section if Flag = 0x04 0019a41c: 00000000 nop | 0019a420: 0806691b j 0x0019a46c >>Avoid all sections if Complex flag (Dual wielding with different flags) 0019a424: 26310001 addiu r17,r17,0x0001 |Ability counter = 0x01 Counter ++ ---- Unarmed section ---- 0019a428: a2160000 sb r22,0x0000(r16) |Force Range = 1 for unarmed attacks ---- Unarmed or Normal Weapon ---- 0019a42c: 92020001 lbu r2,0x0001(r16) |Load AI Behavior Flags 1 0019a430: 00000000 nop | 0019a434: 34420002 ori r2,r2,0x0002 |Enable Target Enemies 0019a438: 0806691a j 0x0019a468 >>Avoid other section 0019a43c: a2020001 sb r2,0x0001(r16) |Store new AI Behavior Flags 1 ---- Absorption Weapon section ---- 0019a440: 92020001 lbu r2,0x0001(r16) |Load AI Behavior Flags 1 0019a444: 92030002 lbu r3,0x0002(r16) |Load AI Behavior Flags 2 0019a448: 08066917 j 0x0019a45c >>Avoid Healing section 0019a44c: 34420002 ori r2,r2,0x0002 |Enable Target Enemies ---- Healing Weapon section ---- 0019a450: 92020001 lbu r2,0x0001(r16) |Load AI Behavior Flags 1 0019a454: 92030002 lbu r3,0x0002(r16) |Load AI Behavior Flags 2 0019a458: 34420001 ori r2,r2,0x0001 |Enable Target Allies ---- Healing or Absorption Weapon section ---- 0019a45c: 34630020 ori r3,r3,0x0020 |Enable Undead Reverse 0019a460: a2020001 sb r2,0x0001(r16) |Store new AI Behavior Flags 1 0019a464: a2030002 sb r3,0x0002(r16) |Store new AI Behavior Flags 2 ---- Unarmed - Normal - Healing - Absorbtion (but not complex flag)---- 0019a468: 26310001 addiu r17,r17,0x0001 |Counter ++ ---- Any flag result (even complex dual wielding or negative check---- 0019a46c: 02602021 addu r4,r19,r0 |r4 = Unit's ID 0019a470: 92450012 lbu r5,0x0012(r18) |Load Unit's Primary Skillset 0019a474: 0c06697e jal 0x0019a5f8 |-->Usable_Ability_Setting Check usable abilities in skillset - returns r2 = Nb of Ability on usable list 0019a478: 02203021 addu r6,r17,r0 |r6 = Counter 0019a47c: 92430012 lbu r3,0x0012(r18) |Load Unit's Primary Skillset 0019a480: 00000000 nop | 0019a484: 2c6300b0 sltiu r3,r3,0x00b0 |Check if skillset is a monster skillset (start at 0xb0) 0019a488: 10600006 beq r3,r0,0x0019a4a4 #If Skillset is not a monster skillset 0019a48c: 00408821 addu r17,r2,r0 |r17 = Counter 0019a490: 02602021 addu r4,r19,r0 |r4 = Unit's ID 0019a494: 92450013 lbu r5,0x0013(r18) |Load Unit's Secondary Skillset 0019a498: 0c06697e jal 0x0019a5f8 |-->Usable_Ability_Setting Check usable abilities - returns r2 = Nb of Ability on usable list 0019a49c: 02203021 addu r6,r17,r0 |r6 = Counter 0019a4a0: 00408821 addu r17,r2,r0 |r17 = Counter 0019a4a4: 00112080 sll r4,r17,0x02 |Counter * 4 (Ability offset) 0019a4a8: 26310001 addiu r17,r17,0x0001 |Ability counter + 1 0019a4ac: 00141100 sll r2,r20,0x04 |Battle ID * 16 0019a4b0: 00541021 addu r2,r2,r20 |ID * 17 0019a4b4: 000228c0 sll r5,r2,0x03 |ID * 0x88 (unit offset) 0019a4b8: 00851821 addu r3,r4,r5 |Unit Offset + Ability Offset 0019a4bc: 02a31821 addu r3,r21,r3 |Part of pointer to Unit usable move list 0x8019f3c4 + unit offset + ability offset 0019a4c0: 340200a9 ori r2,r0,0x00a9 |r2 = 0xa9 0019a4c4: a0620ef2 sb r2,0x0ef2(r3) |Store 0xA9 as skillset after last usable ability 0019a4c8: 00131280 sll r2,r19,0x0a |Units ID * 0x400 0019a4cc: 2442016f addiu r2,r2,0x016f |+Frog attack ID 0019a4d0: a4620ef0 sh r2,0x0ef0(r3) |Store Frog Attack ID + Unit's ID * 0x400 0019a4d4: 00b51021 addu r2,r5,r21 | 0019a4d8: 00822021 addu r4,r4,r2 | 0019a4dc: 34020084 ori r2,r0,0x0084 |r2 = 0x84 0019a4e0: a0820ef3 sb r2,0x0ef3(r4) |Store Usage Type? 0019a4e4: 2a220022 slti r2,r17,0x0022 |check if Ability counter is less than maximum storable abilities 0019a4e8: 10400005 beq r2,r0,0x0019a500 #If there's still room 0019a4ec: 00111080 sll r2,r17,0x02 |r2 = Ability offset 0019a4f0: 00451021 addu r2,r2,r5 |+Unit offset 0019a4f4: 02a21021 addu r2,r21,r2 |Part of pointer to Unit usable move list 0x8019f3c4 + unit offset + ability offset 0019a4f8: 340300ff ori r3,r0,0x00ff |r3 = FF 0019a4fc: a0430ef2 sb r3,0x0ef2(r2) |Store Skillset = 0xFF (end marker) 0019a500: 8fbf003c lw r31,0x003c(r29) END 0019a504: 8fb60038 lw r22,0x0038(r29) 0019a508: 8fb50034 lw r21,0x0034(r29) 0019a50c: 8fb40030 lw r20,0x0030(r29) 0019a510: 8fb3002c lw r19,0x002c(r29) 0019a514: 8fb20028 lw r18,0x0028(r29) 0019a518: 8fb10024 lw r17,0x0024(r29) 0019a51c: 8fb00020 lw r16,0x0020(r29) 0019a520: 27bd0040 addiu r29,r29,0x0040 0019a524: 03e00008 jr r31 0019a528: 00000000 nop
Notes
Routine Fill Unit AI list of usable moves (0x8019f3c4 - 0x0ef0) - 1st Ability is Attack (if not a monster) - Other abilities are set via Usable_Ability_Setting - Last Ability is Frog Attack with skillset 0xA9 (hardcoded) - If there's room after the frog thing, the end of the list is flaged with a skillset 0xff Set data for Unit's AI weapon data (0x8019f3c4 - 0x1778) via Store Weapon? Attack Data - Behavior flag are hardcoded, tied to weapon formula (Absorption - Heal) - No behavior flag if dual wielding weapons with different flag (Normal - Absorb - heal) Hardcoded If Monster primary skillset : avoid weapon flags If Monster primary skillset : avoid secondary skillset
Return location
BATTLE.BIN 00199f44: Usable_Ability_Setting/ENTD_AI_Calculations