Process Unit Misc State Value

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: PROCESS UNIT MISC STATE VALUE
#       Processes a unit misc ID and state value, possibly from output value of Try Get Unit Misc Data By Unit ID, and returns a result as outlined below.
#       Parameters:
#           r4 = (ptr_Output_UnitMiscID) Output pointer to copy Unit Misc ID into
#           r5 = (ptr_UnitMiscID) Pointer to Unit Misc ID
#           r6 = (ptr_State) Pointer to State (e.g. Output value from Try Get Unit Misc Data By Unit ID)
#       Returns: 
#           r2 = (Value from table below)
#               State      Conditions                                                                                   Value
#               0           -                                                                                           1
#               1           Misc Unit exists with specified ID                                                          1
#               2           (Battle unit does not exist)                                                                1
#               2           (Battle unit on player's team)                                                              1
#               3           (Battle unit does not exist)                                                                1
#               3           (Battle unit has status in set at 0x800662f8) and (Battle unit on player's team)            1
#               4           (Battle unit on player's team)                                                              1
#               5           (Battle unit has status in set at 0x800662f8, excluding Undead, and is on player's team)    1
#               Other       -                                                                                           (State)
#               (Any other scenario)                                                                                    0

801479ac: 27bdffd8 addiu r29,r29,-0x0028
801479b0: afb3001c sw r19,0x001c(r29)
801479b4: 00c09821 addu r19,r6,r0                   #   ptr_State
801479b8: afbf0020 sw r31,0x0020(r29)
801479bc: afb20018 sw r18,0x0018(r29)
801479c0: afb10014 sw r17,0x0014(r29)
801479c4: afb00010 sw r16,0x0010(r29)
801479c8: 8e620000 lw r2,0x0000(r19)                #   state = *ptr_State
801479cc: 00000000 nop
801479d0: 10400032 beq r2,r0,0x80147a9c             #   if (state == 0) return 1;
801479d4: 00808021 addu r16,r4,r0                   #   ptr_Output_UnitMiscID
801479d8: 94a20000 lhu r2,0x0000(r5)                #   *ptr_UnitMiscID
801479dc: 00000000 nop
801479e0: a6020000 sh r2,0x0000(r16)                #   *ptr_Output_UnitMiscID = *ptr_UnitMiscID
801479e4: 96040000 lhu r4,0x0000(r16)               #   *ptr_Output_UnitMiscID
801479e8: 0c0232ed jal 0x8008cbb4                   #   miscUnitExists = Does Misc Unit Exist With ID (*ptr_Output_UnitMiscID);
801479ec: 00000000 nop
801479f0: 1040000b beq r2,r0,0x80147a20             #   if (miscUnitExists) {
801479f4: 00000000 nop
801479f8: 96040000 lhu r4,0x0000(r16)               #       *ptr_Output_UnitMiscID
801479fc: 0c023374 jal 0x8008cdd0                   #       battleUnitIndex = Get Battle Unit Index By Unit Misc ID (*ptr_Output_UnitMiscID);
80147a00: 00000000 nop
80147a04: 00409021 addu r18,r2,r0                   #       battleUnitIndex
80147a08: 2402ffff addiu r2,r0,-0x0001              #       -1
80147a0c: 12420004 beq r18,r2,0x80147a20            #       if (battleUnitIndex != -1) {
80147a10: 00000000 nop
80147a14: 0c0602bf jal 0x80180afc                   #           unit = Get Unit's Data Pointer (battleUnitIndex);
80147a18: 02402021 addu r4,r18,r0
80147a1c: 00408821 addu r17,r2,r0                   #           unit
                                                    #       }
                                                    #   }
80147a20: 8e630000 lw r3,0x0000(r19)                #   state
80147a24: 34020001 ori r2,r0,0x0001                 #   1
80147a28: 14620006 bne r3,r2,0x80147a44             #   if (state == 1) {
80147a2c: 00000000 nop
80147a30: 96040000 lhu r4,0x0000(r16)               #       *ptr_Output_UnitMiscID
80147a34: 0c0232ed jal 0x8008cbb4                   #       miscUnitExists = Does Misc Unit Exist With ID (*ptr_Output_UnitMiscID);
80147a38: 00000000 nop
80147a3c: 08051eec j 0x80147bb0                     #       return miscUnitExists;
80147a40: 00000000 nop                              #   }
80147a44: 96040000 lhu r4,0x0000(r16)               #   *ptr_Output_UnitMiscID
80147a48: 0c0232ed jal 0x8008cbb4                   #   miscUnitExists = Does Misc Unit Exist With ID (*ptr_Output_UnitMiscID);
80147a4c: 00000000 nop
80147a50: 10400038 beq r2,r0,0x80147b34             #   if (!miscUnitExists) return 0;
80147a54: 34020002 ori r2,r0,0x0002                 #   2
80147a58: 8e630000 lw r3,0x0000(r19)                #   state
80147a5c: 00000000 nop
80147a60: 14620009 bne r3,r2,0x80147a88             
80147a64: 34020003 ori r2,r0,0x0003                 #   3
                                                    #   if (state == 2) {
80147a68: 2402ffff addiu r2,r0,-0x0001              #       -1
80147a6c: 1242000b beq r18,r2,0x80147a9c            #       if (battleUnitIndex == -1)
80147a70: 00000000 nop                              #           return 1;
80147a74: 92220005 lbu r2,0x0005(r17)               #       unit.ENTDFlags
80147a78: 00000000 nop
80147a7c: 30420030 andi r2,r2,0x0030                #       unitTeamFlags = unit.ENTDFlags & 0x30
80147a80: 08051eec j 0x80147bb0                     #       return (unitTeamFlags == 0) ? 1 : 0;
80147a84: 2c420001 sltiu r2,r2,0x0001
                                                    #   }
80147a88: 1462001b bne r3,r2,0x80147af8             #   if (state == 3) {
80147a8c: 34020004 ori r2,r0,0x0004
80147a90: 2402ffff addiu r2,r0,-0x0001
80147a94: 16420003 bne r18,r2,0x80147aa4
80147a98: 00002021 addu r4,r0,r0                    #       unitStatusByteIndex = 0
                                                    #       if (battleUnitIndex == -1) {
80147a9c: 08051eec j 0x80147bb0                     #           return 1;
80147aa0: 34020001 ori r2,r0,0x0001
                                                    #       } else { 
                                                    #           do {
80147aa4: 02241021 addu r2,r17,r4
80147aa8: 90420058 lbu r2,0x0058(r2)                #               unit.currentStatus[unitStatusByteIndex]
80147aac: 3c018006 lui r1,0x8006
80147ab0: 00240821 addu r1,r1,r4
80147ab4: 902362f8 lbu r3,0x62f8(r1)                #               tempStatusByte = *(0x800662f8 + unitStatusByteIndex)  
80147ab8: 00000000 nop
80147abc: 00431024 and r2,r2,r3                     #               unit.currentStatus[unitStatusByteIndex] & tempStatusByte
80147ac0: 14400005 bne r2,r0,0x80147ad8             #               if (unit.currentStatus[unitStatusByteIndex] & tempStatusByte) break;
80147ac4: 00000000 nop
80147ac8: 24840001 addiu r4,r4,0x0001               #               unitStatusByteIndex = unitStatusByteIndex + 1
80147acc: 28820005 slti r2,r4,0x0005
80147ad0: 1440fff4 bne r2,r0,0x80147aa4
80147ad4: 00000000 nop                              #           } while (unitStatusByteIndex < 5);
80147ad8: 92230005 lbu r3,0x0005(r17)               #           unit.ENTDFlags
80147adc: 00000000 nop
80147ae0: 30630030 andi r3,r3,0x0030                #           unitTeamFlags = unit.ENTDFlags & 0x30
80147ae4: 14600032 bne r3,r0,0x80147bb0             #           if (unitTeamFlags != 0)
80147ae8: 00001021 addu r2,r0,r0                    #               return 0;
80147aec: 38820005 xori r2,r4,0x0005
80147af0: 08051eec j 0x80147bb0                     #           return (unitStatusByteIndex == 5) ? 1 : 0;      // 1 if one of the status bytes existed on the unit, 0 otherwise
80147af4: 2c420001 sltiu r2,r2,0x0001
                                                    #       }
                                                    #   }
80147af8: 14620009 bne r3,r2,0x80147b20             #   if (state == 4) {
80147afc: 34020005 ori r2,r0,0x0005
80147b00: 2402ffff addiu r2,r0,-0x0001
80147b04: 1242000b beq r18,r2,0x80147b34            #       if (battleUnitIndex == -1) return 0;
80147b08: 00000000 nop
80147b0c: 92220005 lbu r2,0x0005(r17)               #       unit.ENTDFlags
80147b10: 00000000 nop
80147b14: 30420030 andi r2,r2,0x0030                #       unitTeamFlags = unit.ENTDFlags & 0x30
80147b18: 08051eec j 0x80147bb0
80147b1c: 0002102b sltu r2,r0,r2                    #       return (unitTeamFlags != 0) ? 1 : 0;
                                                    #   }
80147b20: 14620023 bne r3,r2,0x80147bb0             #   if (state != 5) return state;
80147b24: 00000000 nop
80147b28: 2402ffff addiu r2,r0,-0x0001
80147b2c: 16420003 bne r18,r2,0x80147b3c            #   if (battleUnitIndex == -1) return 0;
80147b30: 00002021 addu r4,r0,r0                    #   unitStatusByteIndex = 0

80147b34: 08051eec j 0x80147bb0
80147b38: 00001021 addu r2,r0,r0
                                                    
80147b3c: 3c058006 lui r5,0x8006
80147b40: 90a562f8 lbu r5,0x62f8(r5)                #   *0x800662f8
                                                    #   do {
80147b44: 14800006 bne r4,r0,0x80147b60             #       if (unitStatusByteIndex == 0) {
80147b48: 00000000 nop
80147b4c: 92220058 lbu r2,0x0058(r17)               #           unit.currentStatus[0]
80147b50: 00000000 nop
80147b54: 304200ef andi r2,r2,0x00ef                #           unit.currentStatus[0] & 0xEF      // Removes 0x10 = Undead
80147b58: 08051edf j 0x80147b7c
80147b5c: 00a21024 and r2,r5,r2                     #           testValue = unit.currentStatus[0] & 0xEF & *0x800662f8
                                                    #       } else {
80147b60: 02241021 addu r2,r17,r4                   
80147b64: 90420058 lbu r2,0x0058(r2)                #           unit.currentStatus[unitStatusByteIndex]
80147b68: 3c018006 lui r1,0x8006
80147b6c: 00240821 addu r1,r1,r4
80147b70: 902362f8 lbu r3,0x62f8(r1)                #           tempStatusByte = *(0x800662f8 + unitStatusByteIndex)
80147b74: 00000000 nop
80147b78: 00431024 and r2,r2,r3                     #           testValue = unit.currentStatus[unitStatusByteIndex] & tempStatusByte
                                                    #       }
80147b7c: 14400005 bne r2,r0,0x80147b94             #       if (testValue != 0) break;
80147b80: 00000000 nop
80147b84: 24840001 addiu r4,r4,0x0001               #       unitStatusByteIndex = unitStatusByteIndex + 1
80147b88: 28820005 slti r2,r4,0x0005
80147b8c: 1440ffed bne r2,r0,0x80147b44
80147b90: 00000000 nop                              #   } while (unitStatusByteIndex < 5);
80147b94: 92230005 lbu r3,0x0005(r17)               #   unit.ENTDFlags
80147b98: 00000000 nop
80147b9c: 30630030 andi r3,r3,0x0030                #   unitTeamFlags = unit.ENTDFlags & 0x30
80147ba0: 10600003 beq r3,r0,0x80147bb0             #   if (unitTeamFlags == 0)
80147ba4: 00001021 addu r2,r0,r0                    #       return 0;
80147ba8: 38820005 xori r2,r4,0x0005
80147bac: 2c420001 sltiu r2,r2,0x0001               #   return (unitStatusByteIndex == 5) ? 1 : 0;      // 1 if one of the status bytes existed on the unit, 0 otherwise
80147bb0: 8fbf0020 lw r31,0x0020(r29)
80147bb4: 8fb3001c lw r19,0x001c(r29)
80147bb8: 8fb20018 lw r18,0x0018(r29)
80147bbc: 8fb10014 lw r17,0x0014(r29)
80147bc0: 8fb00010 lw r16,0x0010(r29)
80147bc4: 27bd0028 addiu r29,r29,0x0028
80147bc8: 03e00008 jr r31
80147bcc: 00000000 nop