Get Battle Unit By Unit ID

From Final Fantasy Hacktics Wiki
Revision as of 15:21, 21 May 2018 by Glain (talk | contribs) (Created page with " # ROUTINE: GET BATTLE UNIT BY UNIT ID # Gets an in-battle unit pointer based on the specified Unit ID. Specified Unit ID can be either ENTD ID (preferred) or a spec...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#   ROUTINE: GET BATTLE UNIT BY UNIT ID
#       Gets an in-battle unit pointer based on the specified Unit ID.  Specified Unit ID can be either ENTD ID (preferred) or a special base class.
#       Parameters:
#           r4 =    unitID  (ENTD Unit ID (preferred) or special base class)
#       Returns:
#           r2  =   (In-battle data pointer) of specified unit, if:
#                       A unit was found with ENTD ID (offset 0x161) equal to the specified Unit ID, OR
#                       A unit was found with a special (non-generic) base class equal to the specified Unit ID,  
#                           and had ENTD ID (0x161) between 0x78 and 0x7c.
#                   -1, otherwise
 
80142508: 27bdffe0 addiu r29,r29,-0x0020
8014250c: afb00018 sw r16,0x0018(r29)
80142510: 00808021 addu r16,r4,r0                  #   unitID
80142514: afbf001c sw r31,0x001c(r29)
80142518: 0c060324 jal 0x80180c90                  #   Find Unit Data Pointer For ENTD Unit ID (unitID, &resultCode);
8014251c: 27a50010 addiu r5,r29,0x0010
80142520: 8fa40010 lw r4,0x0010(r29)               #   resultCode
80142524: 00000000 nop
80142528: 04810013 bgez r4,0x80142578
8014252c: 2602ffff addiu r2,r16,-0x0001            #   unitID - 1
                                                   #   if (resultCode < 0) {           // Unit not found
80142530: 2c420049 sltiu r2,r2,0x0049
80142534: 10400019 beq r2,r0,0x8014259c            #       if ((unitID - 1) >= 0x49)   // Generic class, or 0
80142538: 2402ffff addiu r2,r0,-0x0001             #           return -1;
8014253c: 0c0602cb jal 0x80180b2c                  #       unitIndex = Check Base Class (unitID);
80142540: 02002021 addu r4,r16,r0
80142544: 04400010 bltz r2,0x80142588              #       if (unitIndex < 0) return -1;
80142548: afa20010 sw r2,0x0010(r29)               #       unitIndex                                            
8014254c: 0c0602bf jal 0x80180afc                  #       battleUnit = Get Unit's Data Pointer (unitIndex);
80142550: 00402021 addu r4,r2,r0   
80142554: 00401821 addu r3,r2,r0                   #       battleUnit
80142558: 90620161 lbu r2,0x0161(r3)               #       battleUnit.ENTD_ID
8014255c: 00000000 nop
80142560: 2442ff88 addiu r2,r2,-0x0078             #       battleUnit.ENTD_ID - 0x78
80142564: 2c420005 sltiu r2,r2,0x0005
80142568: 10400007 beq r2,r0,0x80142588            #       if ((battleUnit.ENTD_ID - 0x78) >= 5) return -1;
8014256c: 00601021 addu r2,r3,r0                   #           
80142570: 08050967 j 0x8014259c                    #       return battleUnit;
80142574: 00000000 nop                             #   } else {
80142578: 0c023388 jal 0x0008ce20                  #       unitMiscID = Get Unit Misc ID By Unit Index (unitIndex);
8014257c: 00000000 nop
80142580: 04410003 bgez r2,0x80142590              #       if (unitMiscID < 0) {       // No unit misc data
80142584: 00000000 nop
80142588: 08050967 j 0x8014259c                    #           return -1;
8014258c: 2402ffff addiu r2,r0,-0x0001
                                                   #       }
80142590: 8fa40010 lw r4,0x0010(r29)               #       unitIndex
80142594: 0c0602bf jal 0x80180afc                  #       return Get Unit's Data Pointer (unitIndex);
80142598: 00000000 nop                             #   }
8014259c: 8fbf001c lw r31,0x001c(r29)
801425a0: 8fb00018 lw r16,0x0018(r29)
801425a4: 27bd0020 addiu r29,r29,0x0020
801425a8: 03e00008 jr r31
801425ac: 00000000 nop