AI Depth Elemental Monster Skill Use Check (0019b4f4)

From Final Fantasy Hacktics Wiki
(Redirected from 0019b4f4 - 0019b6ac)
Jump to navigation Jump to search
BATTLE.BIN :  - AI Depth Elemental Monster Skill Use Check
------------------------------------------------------------------------------------------
Parameter : r4 = Pointer to some coordinates (see return locations)
Return : r2 = 0x01 if considered Ability is usable
         r2 = 0x00 if not usable
------------------------------------------------------------------------------------------
0019b4f4: 3c02801a lui r2,0x801a             |
0019b4f8: 90420d7d lbu r2,0x0d7d(r2)         |AI 0x19b7
0019b4fc: 27bdffd8 addiu r29,r29,-0x0028     |
0019b500: afb10014 sw r17,0x0014(r29)        |
0019b504: 00808821 addu r17,r4,r0            |Analyzed coordinates pointer
0019b508: afb40020 sw r20,0x0020(r29)        |
0019b50c: 3c14801a lui r20,0x801a            |
0019b510: 2694f3c4 addiu r20,r20,-0x0c3c     |0x8019f3c4
0019b514: afbf0024 sw r31,0x0024(r29)        |
0019b518: afb3001c sw r19,0x001c(r29)        |
0019b51c: afb20018 sw r18,0x0018(r29)        |
0019b520: 10400015 beq r2,r0,0x0019b578      #If AI 0x19b7 <> 0x00
0019b524: afb00010 sw r16,0x0010(r29)            |
0019b528: 92230002 lbu r3,0x0002(r17)            |Y coordinates
0019b52c: 3c02801a lui r2,0x801a                 |
0019b530: 904201fe lbu r2,0x01fe(r2)             |Map Max X
0019b534: 00000000 nop                           |
0019b538: 00620018 mult r3,r2                    |
0019b53c: 92230001 lbu r3,0x0001(r17)            |Elevation
0019b540: 92240000 lbu r4,0x0000(r17)            |X coordinates
0019b544: 00031a00 sll r3,r3,0x08                |Elevation offset
0019b548: 00001012 mflo r2                       |
0019b54c: 00441021 addu r2,r2,r4                 |
0019b550: 00431021 addu r2,r2,r3                 |(Y*Max X) + X + Elevation offset
0019b554: 000210c0 sll r2,r2,0x03                |8 bytes per Tiles
0019b558: 3c018019 lui r1,0x8019                 |
0019b55c: 00220821 addu r1,r1,r2                 |
0019b560: 9022f8cf lbu r2,-0x0731(r1)            |Load Tile Depth 8018f8cc + Tile Offset + 0x03
0019b564: 00000000 nop                           |
0019b568: 00021142 srl r2,r2,0x05                |Keep Depht Only (0x20 -> 0x01)
0019b56c: 28420002 slti r2,r2,0x0002             |0x1 if Depht < 2
0019b570: 10400046 beq r2,r0,0x0019b68c          #If Depht > 1 then  Exit routine Returns 0x00
0019b574: 00001021 addu r2,r0,r0                 |
                                             Else  : AI 0x19b7 = 0x00  / Or Depth is OK
0019b578: 92820000 lbu r2,0x0000(r20)            |Considered Ability's skillset
0019b57c: 3c018006 lui r1,0x8006                 |
0019b580: 00220821 addu r1,r1,r2                 |
0019b584: 90235cb4 lbu r3,0x5cb4(r1)             |Considered Action Menu
0019b588: 34020004 ori r2,r0,0x0004              |
0019b58c: 14620005 bne r3,r2,0x0019b5a4          #If Action Menu is [Elements]
0019b590: 3c030800 lui r3,0x0800                     |
0019b594: 0c066dd5 jal 0x0019b754                    |-->See_if_elemental_ability_can_be_used
0019b598: 02202021 addu r4,r17,r0                    |Send Coordinates
0019b59c: 08066da3 j 0x0019b68c                      |Exit routine
0019b5a0: 00000000 nop                               |
                                                 Else : NOT [Elements]
0019b5a4: 8e82000c lw r2,0x000c(r20)                 |Ability AI behaviors flags 1 to 4
0019b5a8: 00000000 nop                               |
0019b5ac: 00431024 and r2,r2,r3                      |
0019b5b0: 10400035 beq r2,r0,0x0019b688              #If This skill do NOT requires [Monster Skill] Exit routine Returns 0x01
0019b5b4: 00009821 addu r19,r0,r0                    |
                                                     Else : [Monster skill]
0019b5b8: 00009021 addu r18,r0,r0                        |Initialize Battle data dynamic offset
                                                        @LOOP - through all units (seek form monster skill support)
0019b5bc: 3c028019 lui r2,0x8019                             |
0019b5c0: 244208cc addiu r2,r2,0x08cc                        |
0019b5c4: 02428021 addu r16,r18,r2                           |Dynamic pointer to Unit Battle data
0019b5c8: 92030001 lbu r3,0x0001(r16)                        |Load Unit ID
0019b5cc: 340200ff ori r2,r0,0x00ff                          |
0019b5d0: 10620027 beq r3,r2,0x0019b670                      #If Unit doesn't exist Go to Next Unit
0019b5d4: 00000000 nop                                       |
0019b5d8: 92020092 lbu r2,0x0092(r16)                        |Load Support 4
0019b5dc: 00000000 nop                                       |
0019b5e0: 30420080 andi r2,r2,0x0080                         |
0019b5e4: 10400022 beq r2,r0,0x0019b670                      #If Unit do not have [Monster Skill] Go to Next Unit
0019b5e8: 00000000 nop                                       |
0019b5ec: 920201ba lbu r2,0x01ba(r16)                        |load modified ENTD flags
0019b5f0: 92830e39 lbu r3,0x0e39(r20)                        |
0019b5f4: 30420030 andi r2,r2,0x0030                         |
0019b5f8: 1443001d bne r2,r3,0x0019b670                      #If Acting Unit and This Unit are enemies Go to Next Unit
0019b5fc: 02002021 addu r4,r16,r0                            |
0019b600: 0c01786c jal 0x0005e1b0                            |-->Status_Checks_(r5_%3D_set_to_check)
0019b604: 34050004 ori r5,r0,0x0004                          |Check if unit can react
0019b608: 14400019 bne r2,r0,0x0019b670                      #If This unit is disabled  Go to Next Unit
0019b60c: 00000000 nop                                       |
0019b610: 92030047 lbu r3,0x0047(r16)                        |Target X
0019b614: 92220000 lbu r2,0x0000(r17)                        |CasterX
0019b618: 00000000 nop                                       |
0019b61c: 00622023 subu r4,r3,r2                             |Delta X
0019b620: 04810002 bgez r4,0x0019b62c                        #Make Delta X positive if needed
0019b624: 00000000 nop                                       |
0019b628: 00042023 subu r4,r0,r4                             |
0019b62c: 92030048 lbu r3,0x0048(r16)                        |Target Y
0019b630: 92220002 lbu r2,0x0002(r17)                        |Caster Y
0019b634: 00000000 nop                                       |
0019b638: 00621823 subu r3,r3,r2                             |Delta Y
0019b63c: 04610003 bgez r3,0x0019b64c                        #Make Delta Y positive if needed
0019b640: 00831021 addu r2,r4,r3                             |
0019b644: 00031823 subu r3,r0,r3                             |
0019b648: 00831021 addu r2,r4,r3                             |Get Absolute Distance
0019b64c: 28420002 slti r2,r2,0x0002                         |
0019b650: 10400007 beq r2,r0,0x0019b670                      #If Acting Unit is out of this Unit Monster Skill Aura Go to Next Unit
0019b654: 02202021 addu r4,r17,r0                            |
0019b658: 0c066dac jal 0x0019b6b0                            |-->Calculate_Height_Difference_Between_Units
0019b65c: 02002821 addu r5,r16,r0                            |
0019b660: 24420002 addiu r2,r2,0x0002                        |Delta Z +2
0019b664: 2c420005 sltiu r2,r2,0x0005                        |
0019b668: 14400008 bne r2,r0,0x0019b68c                      #If Delta Z < 5 : Everything is good ! Exit routine Returns 0x01
0019b66c: 34020001 ori r2,r0,0x0001                          |
0019b670: 26730001 addiu r19,r19,0x0001                      |Unit counter +1
0019b674: 2a620015 slti r2,r19,0x0015                        |
0019b678: 1440ffd0 bne r2,r0,0x0019b5bc                  Λ Check All Units
0019b67c: 265201c0 addiu r18,r18,0x01c0                      |Battle data offset (0x1c0 eahc iteration)
0019b680: 08066da3 j 0x0019b68c                          |Exit routine
0019b684: 00001021 addu r2,r0,r0                         |Returns 0x00 (Monster skill not usable)
0019b688: 34020001 ori r2,r0,0x0001
0019b68c: 8fbf0024 lw r31,0x0024(r29)
0019b690: 8fb40020 lw r20,0x0020(r29)
0019b694: 8fb3001c lw r19,0x001c(r29)
0019b698: 8fb20018 lw r18,0x0018(r29)
0019b69c: 8fb10014 lw r17,0x0014(r29)
0019b6a0: 8fb00010 lw r16,0x0010(r29)
0019b6a4: 27bd0028 addiu r29,r29,0x0028
0019b6a8: 03e00008 jr r31
0019b6ac: 00000000 nop

Return locations

BATTLE.BIN
 00196f38: Check_if_map_allows_use_and_find_Highest_Target_(00196ef4)   8019f3c4 + 0x0e30
 00196f80: Check_if_map_allows_use_and_find_Highest_Target_(00196ef4)   8019f3c4 + 0x0018
 0019775c: Store_ability/skillset_data,_set_AI_settings_for_ability?    8019f3c4 + 0x0c74
 0019b470: Check_if_any_units_are_in_range_(0019b30c)                   8019f3c4 + 0x0e30
 0019ba4c: AI_Targeting_Matrix_Analysis_(0019b7b8)                      8019f3c4 + 0x0e30
 0019bc2c: Math_Skill_Targeting                                         8019f3c4 + 0x0e30