Get Overlapping Unit Misc Data Pointer

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: GET OVERLAPPING UNIT MISC DATA POINTER
#       Checks if there is a unit on the specified (X, Y, HigherElevation coordinates) separate from the specified unit and returns its (Unit misc data pointer) if so.
#       Prefers the pointer at 0x80196118, if it matches.
#       Parameters:
#           r4 = (p_MiscData) Unit misc data pointer
#           r5 = (p_X) X Coordinate
#           r6 = (p_Y) Y Coordinate
#           r7 = (p_HigherElevation) Higher Elevation
#       Returns:
#           r2 = (Unit misc data pointer) of a unit on the specified coordinates that is not the specified unit and not the specified unit's rider (if the specified unit is a mount),
#               or returns null if no such unit could be found.

8007a5d0: 27bdffb8 addiu r29,r29,-0x0048
8007a5d4: 3c08800a lui r8,0x800a
8007a5d8: 8d088a54 lw r8,-0x75ac(r8)            #   miscData = *0x80098a54;
8007a5dc: 00000000 nop
8007a5e0: 11000029 beq r8,r0,0x8007a688             
8007a5e4: 00004821 addu r9,r0,r0                #   count = 0;
                                                #   if (miscData != null) {
8007a5e8: 340b00ff ori r11,r0,0x00ff            #       0xff
8007a5ec: 03a05021 addu r10,r29,r0              #       miscDataPointerArray
                                                #       do {
8007a5f0: 11040021 beq r8,r4,0x8007a678         #           if ((miscData != p_MiscData)
8007a5f4: 00000000 nop
8007a5f8: 9102007c lbu r2,0x007c(r8)
8007a5fc: 00000000 nop
8007a600: 1445001d bne r2,r5,0x8007a678         #               and (miscData.X == p_X)
8007a604: 00000000 nop
8007a608: 9102007d lbu r2,0x007d(r8)
8007a60c: 00000000 nop
8007a610: 14460019 bne r2,r6,0x8007a678         #               and (miscData.Y == p_Y)
8007a614: 00000000 nop
8007a618: 9102007e lbu r2,0x007e(r8)
8007a61c: 00000000 nop
8007a620: 14470015 bne r2,r7,0x8007a678         #               and (miscData.HigherElevation == p_HigherElevation)
8007a624: 00000000 nop
8007a628: 8d020134 lw r2,0x0134(r8)
8007a62c: 00000000 nop
8007a630: 10400011 beq r2,r0,0x8007a678         #               and (miscData.UnitBattleData != null)
8007a634: 00000000 nop
8007a638: 90420001 lbu r2,0x0001(r2)
8007a63c: 00000000 nop
8007a640: 104b000d beq r2,r11,0x8007a678        #               and (miscData.UnitBattleData.UnitID != 0xff)) {
8007a644: 00000000 nop
8007a648: 90820130 lbu r2,0x0130(r4)
8007a64c: 00000000 nop
8007a650: 10400006 beq r2,r0,0x8007a66c         #                   if (p_MiscData.MountRiderValue != 0) {
8007a654: 00000000 nop
8007a658: 91030004 lbu r3,0x0004(r8)            #                       miscData.unitMiscID
8007a65c: 90820131 lbu r2,0x0131(r4)            #                       p_MiscData.MountRiderID                
8007a660: 00000000 nop
8007a664: 10620004 beq r3,r2,0x8007a678         #                       if (miscData.UnitMiscID == p_MiscData.MountRiderID) skip = true;
8007a668: 00000000 nop
                                                #                   }
                                                #                   if (!skip)
8007a66c: ad480000 sw r8,0x0000(r10)            #                       miscDataPointerArray[count] = miscData
8007a670: 254a0004 addiu r10,r10,0x0004         #                       (miscDataPointerArray + count);     // Points to next array element
8007a674: 25290001 addiu r9,r9,0x0001           #                       count = count + 1
                                                #                   }
                                                #           }
8007a678: 8d080000 lw r8,0x0000(r8)             #           miscData = miscData.Previous
8007a67c: 00000000 nop
8007a680: 1500ffdb bne r8,r0,0x8007a5f0         #       } while (miscData != null)
8007a684: 00000000 nop
                                                #   }
8007a688: 11200013 beq r9,r0,0x8007a6d8         #   if (count == 0)
8007a68c: 00001021 addu r2,r0,r0                #       return null;
8007a690: 1920000d blez r9,0x8007a6c8           #   if (count > 0) {
8007a694: 00002021 addu r4,r0,r0                #       innerCount = 0
8007a698: 3c068009 lui r6,0x8009
8007a69c: 8cc66118 lw r6,0x6118(r6)             #       *0x80196118
8007a6a0: 03a02821 addu r5,r29,r0               #       miscDataPointerArrayElementPtr = miscDataPointerArray
                                                #       do {
8007a6a4: 8ca30000 lw r3,0x0000(r5)             #           currentMiscData = *miscDataPointerArrayElementPtr
8007a6a8: 00000000 nop
8007a6ac: 90620004 lbu r2,0x0004(r3)            #           currentMiscData.UnitMiscID
8007a6b0: 00000000 nop
8007a6b4: 10460007 beq r2,r6,0x8007a6d4         #           if (currentMiscData.UnitMiscID == *0x80196118), return currentMiscData;
8007a6b8: 24840001 addiu r4,r4,0x0001           #           innerCount = innerCount + 1
8007a6bc: 0089102a slt r2,r4,r9
8007a6c0: 1440fff8 bne r2,r0,0x8007a6a4
8007a6c4: 24a50004 addiu r5,r5,0x0004           #           miscDataPointerArrayElementPtr = miscDataPointerArrayElementPtr + 4     // Points to next element
                                                #       } while (innerCount < count)
                                                #   }
8007a6c8: 8fa20000 lw r2,0x0000(r29)            #   return miscDataPointerArray[0];
8007a6cc: 0801e9b6 j 0x8007a6d8
8007a6d0: 00000000 nop

8007a6d4: 00601021 addu r2,r3,r0

8007a6d8: 27bd0048 addiu r29,r29,0x0048
8007a6dc: 03e00008 jr r31
8007a6e0: 00000000 nop