changeset 1259:d6e5b6b76612

Player::SetVariable cleanup - removing unused variables and function calls with them, some case shuffling
author Grumpy7
date Wed, 12 Jun 2013 04:14:33 +0200
parents eb1a22f7dfef
children dd70fc7eaf08
files Player.cpp Player.h
diffstat 2 files changed, 49 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Wed Jun 12 03:59:08 2013 +0200
+++ b/Player.cpp	Wed Jun 12 04:14:33 2013 +0200
@@ -7897,12 +7897,9 @@
   signed int unused27; // [sp-4h] [bp-38h]@4
   int v28; // [sp-4h] [bp-38h]@84
   ItemGen item; // [sp+Ch] [bp-28h]@52
-  char v30_drawanim; // [sp+32h] [bp-2h]@1
-  char v31_playsound; // [sp+33h] [bp-1h]@1
-
-  v30_drawanim = 0;
-  v31_playsound = 0;
-
+  char v30_unused; // [sp+32h] [bp-2h]@1
+  char v31_unused; // [sp+33h] [bp-1h]@1
+  
   currPlayerId = -1;
   for (int i = 1; i <= 4; i++)  //TODO: add a member variable for playerid in the future
   {
@@ -7983,38 +7980,31 @@
       pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
       return;
     }
-    if ( var_type != VAR_NumDeaths )
-    {
-      switch ( var_type )
-      {
-        case VAR_NumBounties:
-          pParty->uNumBountiesCollected = var_value;
-          break;
-        case VAR_PrisonTerms:
-          pParty->uNumPrisonTerms = var_value;
-          break;
-        case VAR_ArenaWinsPage:
-          pParty->uNumArenaPageWins = var_value;
-          break;
-        case VAR_ArenaWinsSquire:
-          pParty->uNumArenaSquireWins = var_value;
-          break;
-        case VAR_ArenaWinsKnight:
-          pParty->uNumArenaKnightWins = var_value;
-          break;
-        case VAR_ArenaWinsLord:
-          pParty->uNumArenaLordWins = var_value;
-          break;
-      }
-      return;
-    }
-    else
-    {
+    switch ( var_type )
+    {
+    case VAR_NumDeaths:
       pParty->uNumDeaths = var_value;
-      DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
-      PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
-      return;
-    }
+      break;
+    case VAR_NumBounties:
+      pParty->uNumBountiesCollected = var_value;
+      break;
+    case VAR_PrisonTerms:
+      pParty->uNumPrisonTerms = var_value;
+      break;
+    case VAR_ArenaWinsPage:
+      pParty->uNumArenaPageWins = var_value;
+      break;
+    case VAR_ArenaWinsSquire:
+      pParty->uNumArenaSquireWins = var_value;
+      break;
+    case VAR_ArenaWinsKnight:
+      pParty->uNumArenaKnightWins = var_value;
+      break;
+    case VAR_ArenaWinsLord:
+      pParty->uNumArenaLordWins = var_value;
+      break;
+    }
+    return;
   }
   if ( var_type == VAR_AutoNotes )
   {
@@ -8023,16 +8013,14 @@
 	  && pAutonoteTxt[var_value-1].pText )
     {
       v20 = pPlayers[currPlayerId + 1];
-      v30_drawanim = 1;
       v20->PlaySound(SPEECH_96, 0);
 	  v21 = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3];
       bFlashAutonotesBook = 1;
       _506568_autonote_type = v21;
+      DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
     }
     _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1u);
-    v31_playsound = 1;
-    DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
-    PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
+    PlaySoundBasedOnCondition(currPlayerId);
     return;
   }
   if ( var_type <= VAR_BaseLuck )
@@ -8115,13 +8103,11 @@
               //&& dword_723E80_award_related[2 * a3] )
 		    && pAwards[var_value].pText )
         {
-          v30_drawanim = 1;
-          v31_playsound = 1;
           pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0);
+          DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+          PlaySoundBasedOnCondition(currPlayerId);
         }
         _449B7E_toggle_bit((unsigned char *)this->_guilds_member_bits, var_value, 1u);
-        DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
-        PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
         return;
       case VAR_Experience:
         this->uExperience = var_value;
@@ -8133,15 +8119,12 @@
           {
           v14 = pPlayers[currPlayerId + 1];
           bFlashQuestBook = 1;
-          v30_drawanim = 1;
-          v31_playsound = 1;
           v14->PlaySound(SPEECH_93, 0);
+          DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+          PlaySoundBasedOnCondition(currPlayerId);
         }
         v13 = (char *)pParty->_quest_bits;
-LABEL_51:
         _449B7E_toggle_bit((unsigned char *)v13, var_value, 1u);
-        DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
-        PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
         return;
       case VAR_PlayerItemInHands:
         item.Reset();
@@ -8229,10 +8212,9 @@
     v26 = SPEECH_91;
 LABEL_112:
     v19 = pPlayers[currPlayerId + 1];
-    v31_playsound = 1;
     v19->PlaySound((PlayerSpeech)v26, v28);
-    DrawPlayerBuffAnimBasedOnCondition(true, currPlayerId);
-    PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
+    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+    PlaySoundBasedOnCondition(currPlayerId);
     return;
   }
   if ( var_type <= VAR_MagicResistance )
@@ -8344,12 +8326,10 @@
         memset(this, 0, 0xA0u);
       }
 LABEL_124:
-      v31_playsound = 1;
-      DrawPlayerBuffAnimBasedOnCondition(true, currPlayerId);
-      PlaySoundBasedOnCondition(v31_playsound = 1, currPlayerId);
+      DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+      PlaySoundBasedOnCondition(currPlayerId);
       return;
     }
-LABEL_106:
     v16 = (int)((char *)&this->pConditions[16] + 2 * var_type);
     v17 = *(char *)v16;
     if ( var_value <= VAR_BodyResistanceBonus )
@@ -8364,10 +8344,6 @@
     *(short *)v16 = v18;
     goto LABEL_124;
   }
-  if ( var_type == VAR_DisarmTrapSkill )
-    PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
-    DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
-    return;
   if ( var_type <= VAR_MagicResistanceBonus )
   {
     switch ( var_type )
@@ -8413,33 +8389,25 @@
     }
     goto LABEL_111;
   }
-  if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill )
-  {
-    PlaySoundBasedOnCondition(v31_playsound == 1, currPlayerId);
-    DrawPlayerBuffAnimBasedOnCondition(v30_drawanim == 1, currPlayerId);
+  if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill || var_type == VAR_DisarmTrapSkill)  //VAR_ThieverySkill wasn't present in the original function
+  {
     return;
   }
 }
 
 
 //----- (new function) --------------------------------------------------------
-void Player::PlaySoundBasedOnCondition(bool condition, int currPlayerId)
-{
-  if (condition)
-  {
-    signed int v25 = 8 * currPlayerId + 400;
-    LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
-    pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
-  }
+void Player::PlaySoundBasedOnCondition(int currPlayerId)
+{
+  signed int v25 = 8 * currPlayerId + 400;
+  LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
+  pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
 }
 
 //----- (new function) --------------------------------------------------------
-void Player::DrawPlayerBuffAnimBasedOnCondition(bool condition, int currPlayerId)
-{
-  if (condition)
-  {
-    pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
-  }
+void Player::DrawPlayerBuffAnimBasedOnCondition(int currPlayerId)
+{
+  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
 }
 
 //----- (0044AFFB) --------------------------------------------------------
--- a/Player.h	Wed Jun 12 03:59:08 2013 +0200
+++ b/Player.h	Wed Jun 12 04:14:33 2013 +0200
@@ -590,8 +590,8 @@
   void SalesProcess(unsigned int inventory_idnx, int item_index, int _2devent_idx);//0x4BE2DD
   bool Recover(signed int a2);
   bool CanCastSpell(unsigned int uRequiredMana);
-  void PlaySoundBasedOnCondition(bool condition, int currPlayerId);
-  void DrawPlayerBuffAnimBasedOnCondition(bool condition, int currPlayerId);
+  void PlaySoundBasedOnCondition(int currPlayerId);
+  void DrawPlayerBuffAnimBasedOnCondition(int currPlayerId);
 
   inline bool Weak()       {return pConditions[Condition_Weak] != 0;}
   inline bool Dead()       {return pConditions[Condition_Dead] != 0;}