Check Battle Outcome

From Final Fantasy Hacktics Wiki
Revision as of 22:20, 11 August 2020 by Glain (talk | contribs) (Created page with " # ROUTINE: CHECK BATTLE OUTCOME # No parameters. # Returns: # r2 = { # 0 , On player victory # -1, On player defea...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#   ROUTINE: CHECK BATTLE OUTCOME
#       No parameters.
#       Returns:
#           r2 = {
#               0 ,  On player victory 
#               -1,  On player defeat
#               1 ,  If no outcome has been reached
#           }

80183374: 27bdffd0 addiu r29,r29,-0x0030
80183378: afb3001c sw r19,0x001c(r29)
8018337c: 00009821 addu r19,r0,r0                   #   playerUnitCount = 0
80183380: afb40020 sw r20,0x0020(r29)
80183384: 0000a021 addu r20,r0,r0                   #   enemyUnitCount = 0
80183388: afb20018 sw r18,0x0018(r29)
8018338c: 00009021 addu r18,r0,r0                   #   index = 0
80183390: afb50024 sw r21,0x0024(r29)
80183394: 0000a821 addu r21,r0,r0                   
80183398: afbf0028 sw r31,0x0028(r29)
8018339c: afb10014 sw r17,0x0014(r29)
801833a0: afb00010 sw r16,0x0010(r29)
                                                    #   do {
801833a4: 3c028019 lui r2,0x8019
801833a8: 244208cc addiu r2,r2,0x08cc               #       units
801833ac: 02a28821 addu r17,r21,r2                  #       units[index]
801833b0: 922201ba lbu r2,0x01ba(r17)               #       units[index].ModifiedENTDFlags
801833b4: 34030003 ori r3,r0,0x0003
801833b8: 30420003 andi r2,r2,0x0003
801833bc: 14430014 bne r2,r3,0x80183410             #       if (((units[index].ModifiedENTDFlags & 0x03) == 0x03)   // Unit is essential?
801833c0: 340200ff ori r2,r0,0x00ff
801833c4: 92230183 lbu r3,0x0183(r17)               
801833c8: 00000000 nop
801833cc: 10620010 beq r3,r2,0x80183410             #           && (units[index].0x183 != 0xff)
801833d0: 38620080 xori r2,r3,0x0080
801833d4: 2c500001 sltiu r16,r2,0x0001
801833d8: 02202021 addu r4,r17,r0
801833dc: 0c01786c jal 0x8005e1b0                   
801833e0: 34050001 ori r5,r0,0x0001
801833e4: 02028021 addu r16,r16,r2
801833e8: 12000009 beq r16,r0,0x80183410            #           && ((Does Unit Have Status In Set (units[index], 1)) || (units[index].0x183 == 0x80)))  // Checking Crystal, Invite, Treasure
801833ec: 00000000 nop                              #       {
801833f0: 922201ba lbu r2,0x01ba(r17)               
801833f4: 00000000 nop
801833f8: 30420030 andi r2,r2,0x0030
801833fc: 10400003 beq r2,r0,0x8018340c             #           if ((units[index].ModifiedENTDFlags & 0x30) != 0) {     //  Not on Player Team
80183400: 00000000 nop
80183404: 08060d04 j 0x80183410
80183408: 26940001 addiu r20,r20,0x0001             #               enemyUnitCount++;
                                                    #           } else {
8018340c: 26730001 addiu r19,r19,0x0001             #               playerUnitCount++;
                                                    #           }
                                                    #       }
80183410: 26520001 addiu r18,r18,0x0001             #       index++
80183414: 2a420015 slti r2,r18,0x0015
80183418: 1440ffe2 bne r2,r0,0x801833a4
8018341c: 26b501c0 addiu r21,r21,0x01c0
                                                    #   } while (index < 21);
80183420: 1660001b bne r19,r0,0x80183490            #   if (playerUnitCount != 0) return -1;        // Player defeat (if at least one essential player unit is gone)
80183424: 00000000 nop
80183428: 1680001a bne r20,r0,0x80183494            #   if (enemyUnitCount != 0) return 0;          // Player victory (if at least one essential enemy unit is gone)
8018342c: 00001021 addu r2,r0,r0
80183430: 00009021 addu r18,r0,r0                   #   index = 0
80183434: 3c118019 lui r17,0x8019
80183438: 263108cc addiu r17,r17,0x08cc             #   units[index]
                                                    #   do {
8018343c: 92230001 lbu r3,0x0001(r17)               #       units[index].UnitID
80183440: 340200ff ori r2,r0,0x00ff
80183444: 1062000c beq r3,r2,0x80183478             #       if ((units[index].UnitID != 0xff)
80183448: 02202021 addu r4,r17,r0
8018344c: 922201ba lbu r2,0x01ba(r17)
80183450: 00002821 addu r5,r0,r0
80183454: 0c01786c jal 0x8005e1b0
80183458: 30500030 andi r16,r2,0x0030
8018345c: 14400006 bne r2,r0,0x80183478             #           && (!Does Unit Have Status In Set (units[index], 0)))       //  Checking (not) Crystal, Dead, Petrify, Invite, Blood Suck, Treasure
80183460: 00000000 nop                              #       {
80183464: 12000003 beq r16,r0,0x80183474            #           if ((units[index].ModifiedENTDFlags & 0x30) != 0) {             //  Not on Player Team
80183468: 00000000 nop
8018346c: 08060d1e j 0x80183478
80183470: 26940001 addiu r20,r20,0x0001             #               enemyUnitCount++
                                                    #           } else {
80183474: 26730001 addiu r19,r19,0x0001             #               playerUnitCount++
                                                    #           }
                                                    #       }
80183478: 26520001 addiu r18,r18,0x0001             #       index++;
8018347c: 2a420015 slti r2,r18,0x0015
80183480: 1440ffee bne r2,r0,0x8018343c
80183484: 263101c0 addiu r17,r17,0x01c0
                                                    #   } while (index < 21);
80183488: 16600002 bne r19,r0,0x80183494            #   if (playerUnitCount != 0) return ((enemyUnitCount != 0) ? 1 : 0);       // No outcome if enemies remain; player victory if no enemies remain
8018348c: 0014102b sltu r2,r0,r20
80183490: 2402ffff addiu r2,r0,-0x0001              #   return -1;      // Player defeat (all player units defeated)
80183494: 8fbf0028 lw r31,0x0028(r29)
80183498: 8fb50024 lw r21,0x0024(r29)
8018349c: 8fb40020 lw r20,0x0020(r29)
801834a0: 8fb3001c lw r19,0x001c(r29)
801834a4: 8fb20018 lw r18,0x0018(r29)
801834a8: 8fb10014 lw r17,0x0014(r29)
801834ac: 8fb00010 lw r16,0x0010(r29)
801834b0: 27bd0030 addiu r29,r29,0x0030
801834b4: 03e00008 jr r31
801834b8: 00000000 nop