diff Player.cpp @ 501:6fa3ff8ef729

SubtractVariables
author Ritor1
date Fri, 01 Mar 2013 17:37:47 +0600
parents 59649750a054
children 7c86030324a5
line wrap: on
line diff
--- a/Player.cpp	Thu Feb 28 10:36:37 2013 +0600
+++ b/Player.cpp	Fri Mar 01 17:37:47 2013 +0600
@@ -1744,7 +1744,6 @@
   unsigned int uSlota; // [sp+14h] [bp+4h]@1
 
   pIndices = &this->pInventoryIndices[uSlot];
-
   v3 = &this->pInventoryItems[*pIndices-1];
   v4 = v3->uItemID;
   v3->Reset();
@@ -8893,11 +8892,11 @@
                 //&& (&dword_722F10)[4 * val] )
 				&& pQuestTable[val-1] )
               {
-                v17 = pPlayers[uPlayerIdx + 1];
+                //v17 = pPlayers[uPlayerIdx + 1];
                 bFlashQuestBook = 1;
                 v34 = 1;
                 v3 = 1;
-                v17->PlaySound(SPEECH_93, 0);
+                pPlayers[uPlayerIdx + 1]->PlaySound(SPEECH_93, 0);
               }
               v15 = (char *)pParty->_quest_bits;
 LABEL_44:
@@ -9279,11 +9278,11 @@
 
 
 //----- (0044B9C4) --------------------------------------------------------
-void Player::SubtractVariable(enum VariableType var, void *a3)
+bool Player::SubtractVariable(enum VariableType VarNum, signed int pValue)
 {
   unsigned int v3; // ebx@1
   signed int v4; // esi@1
-  enum VariableType v5; // eax@8
+  bool result; // eax@8
   int v6; // esi@11
   int v7; // edi@14
   signed int v8; // eax@17
@@ -9293,10 +9292,10 @@
   char *v12; // ecx@27
   __int64 v13; // qax@27
   unsigned __int8 v14; // cf@27
-  char *v15; // edx@29
+  int *v15; // edx@29
   char *v16; // eax@90
   char *v17; // ecx@94
-  void *v18; // esi@97
+  int v18; // esi@97
   signed int v19; // edx@97
   char *v20; // ecx@98
   int v21; // eax@100
@@ -9324,52 +9323,53 @@
   }
   v4 = v24;
 LABEL_8:
-  v5 = var;
-  if ( (signed int)var > 222 )
-  {
-    if ( (signed int)var <= 307 )
-    {
-      if ( var == 307 )
-      {
-        pParty->uNumDeaths -= (unsigned int)a3;
-        return;
-      }
-      if ( var == 223 )
+  result = false;
+  if ( (signed int)VarNum > 222 )
+  {
+    if ( (signed int)VarNum <= 307 )
+    {
+      if ( VarNum == 307 )
+      {
+        pParty->uNumDeaths -= (unsigned int)pValue;
+        return pValue;
+      }
+      if ( VarNum == 223 )
       {
         v11 = (char *)pParty->_autonote_bits;
-        v22 = (short)a3 - 1;
+        v22 = (short)pValue - 1;
       }
       else
       {
-        if ( var != 231 )
+        if ( VarNum != 231 )
         {
-          switch ( var )
+          switch ( VarNum )
           {
             case 232:
-              var = (VariableType)0;
-              GetNewNPCData(uDialogue_SpeakingActorNPC_ID, (int)&var);
-              dword_5B65CC = 0;
-              if ( (void *)var == a3 )
+              VarNum = (VariableType)0;
+              GetNewNPCData(uDialogue_SpeakingActorNPC_ID, (int)&VarNum);
+              result = (bool) pValue;
+			  dword_5B65CC = 0;
+              if ( (int)VarNum == pValue )
               {
-                dword_5B65CC = (int)a3;
+                dword_5B65CC = (int)pValue;
               }
               else
               {
                 pParty->field_709 = 0;
-                LOBYTE(pNPCStats->pNewNPCData[(int)a3].uFlags) &= 0x7Fu;
+                LOBYTE(pNPCStats->pNewNPCData[(int)pValue].uFlags) &= 0x7Fu;
                 sub_44A56A();
                 viewparams->bRedrawGameUI = 1;
               }
               break;
             case 241:
-              v18 = a3;
+              v18 = pValue;
               v19 = 0;
               if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
               {
                 v20 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
                 do
                 {
-                  if ( *((void **)v20 + 4) == v18 )
+                  if ( *((void **)v20 + 4) == (void *)v18 )
                   {
                     v21 = *(int *)v20;
                     if ( (char)*(int *)v20 < 0 )
@@ -9383,17 +9383,21 @@
                 }
                 while ( v19 < (signed int)pNPCStats->uNumNewNPCs );
               }
-              if ( (void *)pParty->pHirelings[0].uProfession == v18 )
+              if ( pParty->pHirelings[0].uProfession == v18 )
                 memset(pParty->pHirelings, 0, 0x4Cu);
-              if ( (void *)pParty->pHirelings[1].uProfession == v18 )
+              if ( pParty->pHirelings[1].uProfession == v18 )
                 memset(&pParty->pHirelings[1], 0, 0x4Cu);
               pParty->field_709 = 0;
               sub_44A56A();
               break;
             case 243:
               v17 = (char *)&this->uSkillPoints;
-              if ( (unsigned int)a3 <= *(int *)v17 )
-                *(int *)v17 -= (int)a3;
+			  result = *v17;
+              if ( (unsigned int)pValue <= *(int *)v17 )
+              {
+					*(int *)v17 -= (int)pValue;
+					result = v17;
+			  }
               else
                 *(int *)v17 = 0;
               break;
@@ -9401,70 +9405,80 @@
               v16 = (char *)&pOutdoor->ddm;
               if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
                 v16 = (char *)&pIndoor->dlv;
-              *((int *)v16 + 2) -= (int)a3;
+              *((int *)v16 + 2) -= (int)pValue;
               if ( *((int *)v16 + 2) < -10000 )
                 *((int *)v16 + 2) = -10000;
               break;
             case 306:
-              if ( (unsigned int)a3 <= pParty->uNumGoldInBank )
-                pParty->uNumGoldInBank -= (unsigned int)a3;
+				result = VarNum - 306;
+              if ( (unsigned int)pValue <= pParty->uNumGoldInBank )
+			  {
+				result = (bool)pValue;
+                pParty->uNumGoldInBank -= (unsigned int)pValue;
+			  }
               else
 LABEL_88:
                 dword_5B65C4 = 1;
               break;
           }
-          return;
+          return result;
         }
         v11 = this->field_1A50;
 LABEL_112:
-        v22 = (signed __int16)a3;
+        v22 = (signed __int16)pValue;
       }
       _449B7E_toggle_bit((unsigned char *)v11, v22, 0);
-      return;
-    }
-    switch ( var )
+      return result;
+    }
+    switch ( VarNum )
     {
       case 308:
-        pParty->uNumBountiesCollected -= (unsigned int)a3;
+		  result = (bool)pValue;
+        pParty->uNumBountiesCollected -= (unsigned int)pValue;
         break;
       case 309:
-        pParty->uNumPrisonTerms -= (int)a3;
+		  result = (bool)pValue;
+        pParty->uNumPrisonTerms -= (int)pValue;
         break;
       case 310:
-        pParty->uNumArenaPageWins -= (char)a3;
+		  result = (bool)pValue;
+        pParty->uNumArenaPageWins -= (char)pValue;
         break;
       case 311:
-        pParty->uNumArenaSquireWins -= (char)a3;
+		  result = (bool)pValue;
+        pParty->uNumArenaSquireWins -= (char)pValue;
         break;
       case 312:
-        pParty->uNumArenaKnightWins -= (char)a3;
+		  result = (bool)pValue;
+        pParty->uNumArenaKnightWins -= (char)pValue;
         break;
       case 313:
-        pParty->uNumArenaLordWins -= (char)a3;
+		  result = (bool)pValue;
+        pParty->uNumArenaLordWins -= (char)pValue;
         break;
     }
   }
   else
   {
-    if ( (signed int)var >= 123 )
-    {
-      byte_5E4C15[var] -= (char)a3;
+    if ( (signed int)VarNum >= 123 )
+    {
+      byte_5E4C15[VarNum] -= (char)pValue;
     }
     else
     {
-      switch ( var )
+      switch ( VarNum )
       {
         case VAR_RandomGold:
-          v6 = rand() % (signed int)a3 + 1;
+          v6 = rand() % (signed int)pValue + 1;
           if ( v6 > pParty->uNumGold )
             v6 = pParty->uNumGold;
           Party::TakeGold(v6);
           sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[503], v6);
           ShowStatusBarString(pTmpBuf, 2u);
           GameUI_DrawFoodAndGold();
-          return;
+          return result;
         case VAR_RandomFood:
-          v7 = rand() % (signed int)a3 + 1;
+          v7 = rand() % (signed int)pValue + 1;
           if ( v7 > pParty->uNumFoodRations )
             v7 = pParty->uNumFoodRations;
           Party::TakeFood(v7);
@@ -9473,162 +9487,162 @@
           GameUI_DrawFoodAndGold();
           goto LABEL_17;
         default:
-          return;
+          return result;
         case VAR_CurrentHP:
-          ReceiveDamage((signed int)a3, 4);
+          ReceiveDamage((signed int)pValue, 4);
           goto LABEL_17;
         case VAR_CurrentSP:
           v9 = (char *)&this->sMana;
-          v10 = this->sMana - (signed int)a3 < 0;
-          *(int *)v9 -= (int)a3;
+          v10 = this->sMana - (signed int)pValue < 0;
+          *(int *)v9 -= (int)pValue;
           if ( v10 )
             *(int *)v9 = 0;
           goto LABEL_17;
         case VAR_ACModifier:
-          this->sACModifier -= (unsigned __int8)a3;
+          this->sACModifier -= (unsigned __int8)pValue;
           goto LABEL_17;
         case VAR_BaseLevel:
-          this->uLevel -= (unsigned __int8)a3;
+          this->uLevel -= (unsigned __int8)pValue;
           goto LABEL_17;
         case VAR_LevelModifier:
-          this->sLevelModifier -= (unsigned __int8)a3;
+          this->sLevelModifier -= (unsigned __int8)pValue;
           goto LABEL_17;
         case VAR_Age:
-          this->sAgeModifier -= (signed __int16)a3;
-          return;
+          this->sAgeModifier -= (signed __int16)pValue;
+          return result;
         case VAR_Award:
           v11 = this->_guilds_member_bits;
           goto LABEL_112;
         case VAR_Experience:
           v12 = (char *)&this->uExperience;
-          v13 = (signed int)a3;
-          v14 = *(int *)v12 < (unsigned int)a3;
-          *(int *)v12 -= (int)a3;
+          v13 = (signed int)pValue;
+          v14 = *(int *)v12 < (unsigned int)pValue;
+          *(int *)v12 -= (int)pValue;
           *((int *)v12 + 1) -= v14 + HIDWORD(v13);
           goto LABEL_17;
         case VAR_QBits_QuestsDone:
-          _449B7E_toggle_bit(pParty->_quest_bits, (__int16)a3, 0);
+          _449B7E_toggle_bit(pParty->_quest_bits, (__int16)pValue, 0);
           pPlayers[v4 + 1]->PlaySound(SPEECH_96, 0);
-          return;
+          return true;
         case VAR_PlayerItemInHands:
-          v15 = (char *)this->pInventoryIndices;
+          v15 = this->pInventoryIndices;
           break;
         case VAR_FixedGold:
-          if ( (unsigned int)a3 > pParty->uNumGold )
+          if ( (unsigned int)pValue > pParty->uNumGold )
             goto LABEL_88;
-          Party::TakeGold((unsigned int)a3);
-          return;
+          Party::TakeGold((unsigned int)pValue);
+          return result;
         case VAR_MightBonus:
         case VAR_ActualMight:
-          this->uMightBonus -= (unsigned __int16)a3;
+          this->uMightBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_IntellectBonus:
         case VAR_ActualIntellect:
-          this->uIntelligenceBonus -= (unsigned __int16)a3;
+          this->uIntelligenceBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_PersonalityBonus:
         case VAR_ActualPersonality:
-          this->uWillpowerBonus -= (unsigned __int16)a3;
+          this->uWillpowerBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_EnduranceBonus:
         case VAR_ActualEndurance:
-          this->uEnduranceBonus -= (unsigned __int16)a3;
+          this->uEnduranceBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_SpeedBonus:
         case VAR_ActualSpeed:
-          this->uSpeedBonus -= (unsigned __int16)a3;
+          this->uSpeedBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_AccuracyBonus:
         case VAR_ActualAccuracy:
-          this->uAccuracyBonus -= (unsigned __int16)a3;
+          this->uAccuracyBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_LuckBonus:
         case VAR_ActualLuck:
-          this->uLuckBonus -= (unsigned __int16)a3;
+          this->uLuckBonus -= (unsigned __int16)pValue;
           goto LABEL_72;
         case VAR_BaseMight:
-          this->uMight -= (unsigned __int16)a3;
+          this->uMight -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BaseIntellect:
-          this->uIntelligence -= (unsigned __int16)a3;
+          this->uIntelligence -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BasePersonality:
-          this->uWillpower -= (unsigned __int16)a3;
+          this->uWillpower -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BaseEndurance:
-          this->uEndurance -= (unsigned __int16)a3;
+          this->uEndurance -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BaseSpeed:
-          this->uSpeed -= (unsigned __int16)a3;
+          this->uSpeed -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BaseAccuracy:
-          this->uAccuracy -= (unsigned __int16)a3;
+          this->uAccuracy -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_BaseLuck:
-          this->uLuck -= (unsigned __int16)a3;
+          this->uLuck -= (unsigned __int16)pValue;
           goto LABEL_45;
         case VAR_FireResistance:
-          this->sResFireBase -= (signed __int16)a3;
+          this->sResFireBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_AirResistance:
-          this->sResAirBase -= (signed __int16)a3;
+          this->sResAirBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_WaterResistance:
-          this->sResWaterBase -= (signed __int16)a3;
+          this->sResWaterBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_EarthResistance:
-          this->sResEarthBase -= (signed __int16)a3;
+          this->sResEarthBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_SpiritResistance:
-          this->sResSpiritBase -= (signed __int16)a3;
+          this->sResSpiritBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_MindResistance:
-          this->sResMindBase -= (signed __int16)a3;
+          this->sResMindBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_BodyResistance:
-          this->sResBodyBase -= (signed __int16)a3;
+          this->sResBodyBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_LightResistance:
-          this->sResLightBase -= (signed __int16)a3;
+          this->sResLightBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_DarkResistance:
-          this->sResDarkBase -= (signed __int16)a3;
+          this->sResDarkBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_MagicResistance:
-          this->sResMagicBase -= (signed __int16)a3;
+          this->sResMagicBase -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_FireResistanceBonus:
-          this->sResFireBonus -= (signed __int16)a3;
+          this->sResFireBonus -= (signed __int16)pValue;
           goto LABEL_45;
         case VAR_AirResistanceBonus:
-          this->sResAirBonus -= (signed __int16)a3;
+          this->sResAirBonus -= (signed __int16)pValue;
 LABEL_45:
           v25 = 0;
           v23 = 92;
           goto LABEL_73;
         case VAR_WaterResistanceBonus:
-          this->sResWaterBonus -= (signed __int16)a3;
+          this->sResWaterBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_EarthResistanceBonus:
-          this->sResEarthBonus -= (signed __int16)a3;
+          this->sResEarthBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_SpiritResistanceBonus:
-          this->sResSpiritBonus -= (signed __int16)a3;
+          this->sResSpiritBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_MindResistanceBonus:
-          this->sResMindBonus -= (signed __int16)a3;
+          this->sResMindBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_BodyResistanceBonus:
-          this->sResBodyBonus -= (signed __int16)a3;
+          this->sResBodyBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_LightResistanceBonus:
-          this->sResLightBonus -= (signed __int16)a3;
+          this->sResLightBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_DarkResistanceBonus:
-          this->sResDarkBonus -= (signed __int16)a3;
+          this->sResDarkBonus -= (signed __int16)pValue;
           goto LABEL_72;
         case VAR_MagicResistanceBonus:
-          this->sResMagicBonus -= (signed __int16)a3;
+          this->sResMagicBonus -= (signed __int16)pValue;
 LABEL_72:
           v25 = 0;
           v23 = SPEECH_91;
@@ -9636,7 +9650,7 @@
           pPlayers[v4 + 1]->PlaySound((PlayerSpeech)v23, v25);
           goto LABEL_17;
         case VAR_FixedFood:
-          Party::TakeFood((unsigned int)a3);
+          Party::TakeFood((unsigned int)pValue);
           goto LABEL_17;
         case VAR_StaffSkill:
         case VAR_SwordSkill:
@@ -9668,7 +9682,7 @@
         case VAR_DiplomacySkill:
         case VAR_DisarmTrapSkill:
         case VAR_LearningSkill:
-          *((short *)&this->pConditions[16] + var) -= (unsigned __int8)a3;
+          *((short *)&this->pConditions[16] + VarNum) -= (unsigned __int8)pValue;
           goto LABEL_17;
         case VAR_Cursed:
         case VAR_Weak:
@@ -9687,28 +9701,33 @@
         case VAR_Dead:
         case VAR_Stoned:
         case VAR_Eradicated:
-          *((int *)this + 2 * var - 210) = 0;
-          *((int *)this + 2 * v5 - 209) = 0;
+          *((int *)this + 2 * VarNum - 210) = 0;
+          *((int *)this + 2 * result - 209) = 0;
 LABEL_17:
           pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
           v8 = 8 * v4 + 400;
           LOBYTE(v8) = (8 * v4 - 112) | 4;
           pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
-          return;
-      }
-      do
-      {
-        if ( *(void **)&this->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * *(int *)v15 + 5] == a3 )
+          return result;
+      }
+      //do
+	  for (v3 = 1; v3 < 126; v3++)
+      {
+		  if ( *(&this->pInventoryItems[pInventoryIndices[v3] - 1].uItemID) == pValue )//pValue = ItemID, pInventoryItems[3] = 222
         {
-          RemoveItemAtInventoryIndex(v3);
-          return;
+          RemoveItemAtInventoryIndex(v3);// &this->pInventoryIndices[puSlot], pInventoryIndices[1] = 4
+          return true;
         }
-        ++v3;
-        v15 += 4;
-      }
-      while ( (signed int)v3 < 126 );
-      if ( (void *)pParty->pPickedItem.uItemID == a3 )
-        pMouse->RemoveHoldingItem();
+        //++v3;
+        //v15 ++;
+      }
+      //while ( (signed int)v3 < 126 );
+      if ( pParty->pPickedItem.uItemID == pValue )
+      {
+         pMouse->RemoveHoldingItem();
+		 return true;
+	  }
+	  return false;
     }
   }
 }