Get Battle Unit Index By ENTD Unit ID

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: GET BATTLE UNIT INDEX BY ENTD UNIT ID
#       Parameters:
#           r4 = (ENTDUnitID) ENTD Unit ID
#       Returns:
#           r2 =    (Battle unit index) of unit with specified ENTD unit ID, if exists
#                   2000, if no such battle unit exists

8012dcac: 27bdffe8 addiu r29,r29,-0x0018
8012dcb0: afbf0010 sw r31,0x0010(r29)
8012dcb4: 0c04cc56 jal 0x80133158                   #   miscID = Get misc ID (ENTDUnitID);
8012dcb8: 00000000 nop
8012dcbc: 00402021 addu r4,r2,r0                    #   miscID
8012dcc0: 340207d0 ori r2,r0,0x07d0                 #   2000
8012dcc4: 10820008 beq r4,r2,0x8012dce8             #   if (miscID == 2000) return;
8012dcc8: 00000000 nop
8012dccc: 0c023374 jal 0x8008cdd0                   #   battleUnitIndex = Get Battle Unit Index By Unit Misc ID (miscID);
8012dcd0: 00000000 nop
8012dcd4: 00401821 addu r3,r2,r0                    #   battleUnitIndex
8012dcd8: 2402ffff addiu r2,r0,-0x0001              #   -1
8012dcdc: 14620002 bne r3,r2,0x8012dce8             
8012dce0: 00601021 addu r2,r3,r0                    #   result = battleUnitIndex
                                                    #   if (battleUnitIndex == -1) {
8012dce4: 340207d0 ori r2,r0,0x07d0                 #       result = 2000
                                                    #   }
8012dce8: 8fbf0010 lw r31,0x0010(r29)               #   return result;
8012dcec: 27bd0018 addiu r29,r29,0x0018
8012dcf0: 03e00008 jr r31
8012dcf4: 00000000 nop