changeset 1261:cdee1d692a4a

Merge
author Grumpy7
date Wed, 12 Jun 2013 15:13:45 +0200
parents dd70fc7eaf08 (diff) 8cf1eb87a44e (current diff)
children 0aeac0b9ca30 73269755dd89
files
diffstat 2 files changed, 128 insertions(+), 143 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Wed Jun 12 12:06:42 2013 +0400
+++ b/Player.cpp	Wed Jun 12 15:13:45 2013 +0200
@@ -7871,11 +7871,11 @@
 void Player::SetVariable(enum VariableType var_type, signed int var_value)
 {
   signed int currPlayerId; // ebx@1
-  Player *unused4; // esi@1
-  unsigned int v5; // edi@1
+  Player *v4_unused; // esi@1
+  unsigned int v5_unused; // edi@1
   unsigned int v6; // esi@13
   unsigned int v7; // esi@14
-  signed int v8; // eax@17
+  signed int v8_unused; // eax@17
   ItemGen *v9; // ecx@17
   int v10; // eax@21
   signed int v11; // eax@30
@@ -7895,15 +7895,11 @@
   signed int v25; // eax@172
   int v26; // [sp-8h] [bp-3Ch]@84
   signed int unused27; // [sp-4h] [bp-38h]@4
-  int v28; // [sp-4h] [bp-38h]@84
+  int v28_unused; // [sp-4h] [bp-38h]@84
   ItemGen item; // [sp+Ch] [bp-28h]@52
-  char v30; // [sp+32h] [bp-2h]@1
-  char v31; // [sp+33h] [bp-1h]@1
-
-  v30 = 0;
-  v31 = 0;
-  v5 = 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
   {
@@ -7979,49 +7975,36 @@
           return;
         bFlashHistoryBook = 1;
       }
-LABEL_172:
       v25 = 8 * currPlayerId + 400;
       LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
-      pAudioPlayer->PlaySound(SOUND_20001, v25, v5, -1, v5, v5, v5, v5);
+      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;
-    }
-    pParty->uNumDeaths = var_value;
-LABEL_168:
-    if (v30 == 1)
-    {
-LABEL_169:
-      pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
-    }
-LABEL_170:
-    if ( v31 != 1 )
-      return;
-    v5 = 0;
-    goto LABEL_172;
+    switch ( var_type )
+    {
+    case VAR_NumDeaths:
+      pParty->uNumDeaths = var_value;
+      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 )
   {
@@ -8030,15 +8013,15 @@
 	  && pAutonoteTxt[var_value-1].pText )
     {
       v20 = pPlayers[currPlayerId + 1];
-      v30 = 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 = 1;
-    goto LABEL_168;
+    PlaySoundBasedOnCondition(currPlayerId);
+    return;
   }
   if ( var_type <= VAR_BaseLuck )
   {
@@ -8051,19 +8034,19 @@
         this->classType = (PLAYER_CLASS_TYPE)var_value;
         if ( (char)var_value == PLAYER_CLASS_LICH )
         {
-          v8 = 0;
-          v9 = this->pInventoryItems;
-          while ( v9->uItemID != 615 )
+          v9 = NULL;
+          for (int i = 0; i < 138; i++)
           {
-            ++v8;
-            ++v9;
-            if ( v8 >= 138 )
-              goto LABEL_22;
+            v9 = &this->pInventoryItems[i];
+            if (v9->uItemID == 615)
+              break;
           }
-          v10 = (int)((char *)this + 36 * v8);
-          *(int *)(v10 + 532) = 601;
-          *(char *)(v10 + 558) = currPlayerId + 1;
-LABEL_22:
+          if (v9 != NULL || v9->uItemID != 615)
+          {
+            v10 = (int)((char *)this + 36 * 138);   //originally 36 * v8. the code got to this condition only if v8 was equal to 138
+            *(int *)(v10 + 532) = 601;
+            *(char *)(v10 + 558) = currPlayerId + 1;
+          }
           if ( this->sResFireBase < 20 )
             this->sResFireBase = 20;
           if ( this->sResAirBase < 20 )
@@ -8120,12 +8103,12 @@
               //&& dword_723E80_award_related[2 * a3] )
 		    && pAwards[var_value].pText )
         {
-          v30 = 1;
-          v31 = 1;
           pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0);
+          DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+          PlaySoundBasedOnCondition(currPlayerId);
         }
         _449B7E_toggle_bit((unsigned char *)this->_guilds_member_bits, var_value, 1u);
-        goto LABEL_168;
+        return;
       case VAR_Experience:
         this->uExperience = var_value;
         goto LABEL_124;
@@ -8136,22 +8119,12 @@
           {
           v14 = pPlayers[currPlayerId + 1];
           bFlashQuestBook = 1;
-          v30 = 1;
-          v31 = 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);
-        if (( v30 != 1 )&&( v31 != 1 ))
-          return;
-        else
-          pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
-        if ( v31 != 1 )
-          return;
-        v25 = 8 * currPlayerId + 400;
-        LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
-        pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
         return;
       case VAR_PlayerItemInHands:
         item.Reset();
@@ -8198,36 +8171,43 @@
         goto LABEL_73;
       case VAR_BaseMight:
         this->uMight = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BaseIntellect:
         this->uIntelligence = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BasePersonality:
         this->uWillpower = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BaseEndurance:
         this->uEndurance = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BaseSpeed:
         this->uSpeed = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BaseAccuracy:
         this->uAccuracy = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BaseLuck:
         this->uLuck = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       default:
         return;
     }
 LABEL_111:
-    v28 = 0;
     v26 = SPEECH_91;
 LABEL_112:
     v19 = pPlayers[currPlayerId + 1];
-    v31 = 1;
-    v19->PlaySound((PlayerSpeech)v26, v28);
-    goto LABEL_169;
+    v19->PlaySound((PlayerSpeech)v26, 0);
+    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+    PlaySoundBasedOnCondition(currPlayerId);
+    return;
   }
   if ( var_type <= VAR_MagicResistance )
   {
@@ -8263,35 +8243,42 @@
         goto LABEL_111;
       case VAR_FireResistance:
         this->sResFireBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_AirResistance:
         this->sResAirBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_WaterResistance:
         this->sResWaterBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_EarthResistance:
         this->sResEarthBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_SpiritResistance:
         this->sResSpiritBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_MindResistance:
         this->sResMindBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_BodyResistance:
         this->sResBodyBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_LightResistance:
         this->sResLightBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_DarkResistance:
         this->sResDarkBase = (unsigned __int8)var_value;
-        goto LABEL_84;
+        v26 = 92;
+        goto LABEL_112;
       case VAR_MagicResistance:
         this->sResMagicBase = (unsigned __int8)var_value;
-LABEL_84:
-        v28 = 0;
         v26 = 92;
         goto LABEL_112;
       default:
@@ -8320,35 +8307,27 @@
         }
         memset(this, 0, 0xA0u);
       }
-LABEL_124:
-      v31 = 1;
-      goto LABEL_169;
-    }
-LABEL_106:
-    v16 = (int)((char *)&this->pConditions[16] + 2 * var_type);
-    v17 = *(char *)v16;
-    if ( var_value <= VAR_BodyResistanceBonus )
-    {
-      LOWORD(v15) = (unsigned __int8)var_value;
-      v18 = v15 | v17 & VAR_BodyResistanceBonus;
     }
     else
     {
-      LOWORD(v18) = (unsigned __int8)(var_value | v17 & 0xC0);
-    }
-    *(short *)v16 = v18;
-    goto LABEL_124;
-  }
-  if ( var_type == VAR_DisarmTrapSkill )
-	  if ( v30 != 1 )
-		  {
-		  if ( v31 != 1 )
-			  return;
-		  v5 = 0;
-		  goto LABEL_172;
-		  }
-	  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
-	  goto LABEL_170;
+      v16 = (int)((char *)&this->pConditions[16] + 2 * var_type);
+      v17 = *(char *)v16;
+      if ( var_value <= VAR_BodyResistanceBonus )
+      {
+        LOWORD(v15) = (unsigned __int8)var_value;
+        v18 = v15 | v17 & VAR_BodyResistanceBonus;
+      }
+      else
+      {
+        LOWORD(v18) = (unsigned __int8)(var_value | v17 & 0xC0);
+      }
+      *(short *)v16 = v18;
+    }
+LABEL_124:
+    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
+    PlaySoundBasedOnCondition(currPlayerId);
+    return;
+  }
   if ( var_type <= VAR_MagicResistanceBonus )
   {
     switch ( var_type )
@@ -8394,21 +8373,26 @@
     }
     goto LABEL_111;
   }
-  if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill )
-	  if ( v30 != 1 )
-		  {
-		  if ( v31 != 1 )
-			  return;
-		  v5 = 0;
-		  v25 = 8 * currPlayerId + 400;
-		  LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
-		  pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
-		  return;
-		  }
-	  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
-	  goto LABEL_170;
-}
-
+  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(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(int currPlayerId)
+{
+  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
+}
 
 //----- (0044AFFB) --------------------------------------------------------
 void Player::AddVariable(enum VariableType var_type, signed int val)
--- a/Player.h	Wed Jun 12 12:06:42 2013 +0400
+++ b/Player.h	Wed Jun 12 15:13:45 2013 +0200
@@ -590,6 +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(int currPlayerId);
+  void DrawPlayerBuffAnimBasedOnCondition(int currPlayerId);
 
   inline bool Weak()       {return pConditions[Condition_Weak] != 0;}
   inline bool Dead()       {return pConditions[Condition_Dead] != 0;}
@@ -619,7 +621,6 @@
 
 
 
-
   __int64 pConditions[20];
   unsigned __int64 uExperience;
   char pName[16];