changeset 1791:9f610f471283

Player::AddVariable adding helper functions
author Grumpy7
date Thu, 03 Oct 2013 08:53:25 +0200
parents 5ace90f129d3
children 3155be890554
files Player.cpp Player.h
diffstat 2 files changed, 80 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Thu Oct 03 08:32:59 2013 +0200
+++ b/Player.cpp	Thu Oct 03 08:53:25 2013 +0200
@@ -6083,18 +6083,15 @@
               return;
             case VAR_Sex:
               this->uSex = (PLAYER_SEX)val;
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_Class:
               this->classType = (PLAYER_CLASS_TYPE)val;
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_CurrentHP:
               this->sHealth = min(this->sHealth + val, this->GetMaxHealth() );
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_MaxHP:
               this->_health_related = 0;
@@ -6103,8 +6100,7 @@
               return;
             case VAR_CurrentSP:
               this->sMana = min(this->sMana + val, this->GetMaxMana() );
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_MaxSP:
               this->_mana_related = 0;
@@ -6113,18 +6109,15 @@
               return;
             case VAR_ACModifier:
               this->sACModifier = min(this->sACModifier + val, 255);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_BaseLevel:
               this->uLevel = min(this->uLevel + val, 255);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_LevelModifier:
               this->sLevelModifier = min(this->sLevelModifier + val, 255);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_Age:
               this->sAgeModifier += val;
@@ -6132,24 +6125,19 @@
             case VAR_Award:
               if (_449B57_test_bit(this->_achieved_awards_bits, val) && pAwards[val].pText )
               {
-                this->PlaySound(SPEECH_96, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_96);
               }
               _449B7E_toggle_bit(this->_achieved_awards_bits, val, 1);
               return;
             case VAR_Experience:
               this->uExperience = min(this->uExperience + val, 4000000000i64);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97(uPlayerIdx);
               return;
             case VAR_QBits_QuestsDone:
               if ( !_449B57_test_bit(pParty->_quest_bits, val) && pQuestTable[val] )
               {
                 bFlashQuestBook = 1;
-                this->PlaySound(SPEECH_93, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_93);
               }
               _449B7E_toggle_bit(pParty->_quest_bits, val, 1);
               return;
@@ -6159,7 +6147,7 @@
               item.uItemID = val;
               if ( val >= ITEM_ARTIFACT_PUCK && val <= ITEM_RELIC_MEKORIGS_HAMMER )
                 pParty->pIsArtifactFound[val-500] = 1;
-              if ( val >= ITEM_WAND_FIRE && val <= ITEM_WAND_INCENERATION )
+              else if ( val >= ITEM_WAND_FIRE && val <= ITEM_WAND_INCENERATION )
               {
                 item.uNumCharges = rand() % 6 + item.GetDamageMod() + 1;
                 item.uMaxCharges = LOBYTE(item.uNumCharges);
@@ -6171,45 +6159,31 @@
               return;
             case VAR_BaseMight:
               this->uMight = min(this->uMight + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BaseIntellect:
               this->uIntelligence = min(this->uIntelligence + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BasePersonality:
               this->uWillpower = min(this->uWillpower + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BaseEndurance:
               this->uEndurance = min(this->uEndurance + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BaseSpeed:
               this->uSpeed = min(this->uSpeed + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BaseAccuracy:
               this->uAccuracy = min(this->uAccuracy + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BaseLuck:
               this->uLuck = min(this->uLuck + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_FixedFood:
               Party::GiveFood(val);
@@ -6240,9 +6214,7 @@
         }
 LABEL_62:
         this->uMightBonus = min(this->uMightBonus + val, 255);
-        this->PlaySound(SPEECH_91, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-        PlayAwardSound(uPlayerIdx);
+        PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
         return;
       }
       if ( var_type <= VAR_FireResistanceBonus )
@@ -6254,104 +6226,72 @@
             case VAR_ActualIntellect:
 LABEL_66:
               this->uIntelligenceBonus = min(this->uIntelligenceBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_ActualPersonality:
 LABEL_67:
               this->uWillpowerBonus = min(this->uWillpowerBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_ActualEndurance:
 LABEL_68:
               this->uEnduranceBonus = min(this->uEnduranceBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_ActualSpeed:
 LABEL_69:
               this->uSpeedBonus = min(this->uSpeedBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_ActualAccuracy:
 LABEL_70:
               this->uAccuracyBonus = min(this->uAccuracyBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_ActualLuck:
 LABEL_71:
               this->uLuckBonus = min(this->uLuckBonus + val, 255);
-              this->PlaySound(SPEECH_91, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
               return;
             case VAR_FireResistance:
               this->sResFireBase = min(this->sResFireBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_AirResistance:
               this->sResAirBase = min(this->sResAirBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_WaterResistance:
               this->sResWaterBase = min(this->sResWaterBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_EarthResistance:
               this->sResEarthBase = min(this->sResEarthBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_SpiritResistance:
               this->sResSpiritBase = min(this->sResSpiritBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_MindResistance:
               this->sResMindBase = min(this->sResMindBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_BodyResistance:
               this->sResBodyBase = min(this->sResBodyBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_LightResistance:
               this->sResLightBase = min(this->sResLightBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_DarkResistance:
               this->sResDarkBase = min(this->sResDarkBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             case VAR_MagicResistance:
               this->sResMagicBase = min(this->sResMagicBase + val, 255);
-              this->PlaySound(SPEECH_92, 0);
-              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-              PlayAwardSound(uPlayerIdx);
+              PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_92);
               return;
             default:
               return;
@@ -6359,9 +6299,7 @@
           return;
         }
         this->sResFireBonus = min(this->sResFireBonus + val, 255);
-        this->PlaySound(SPEECH_91, 0);
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-        PlayAwardSound(uPlayerIdx);
+        PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
         return;
       }
       if ( var_type <= VAR_DisarmTrapSkill )
@@ -6374,74 +6312,49 @@
             {
               case VAR_BodyResistanceBonus:
                 this->sResBodyBonus = min(this->sResBodyBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
               case VAR_AirResistanceBonus:
                 this->sResAirBonus = min(this->sResAirBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
               case VAR_WaterResistanceBonus:
                 this->sResWaterBonus = min(this->sResWaterBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
               case VAR_EarthResistanceBonus:
                 this->sResEarthBonus = min(this->sResEarthBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
               case VAR_SpiritResistanceBonus:
                 this->sResSpiritBonus = min(this->sResSpiritBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
               case VAR_MindResistanceBonus:
                 this->sResMindBonus = min(this->sResMindBonus + val, 255);
-                this->PlaySound(SPEECH_91, 0);
-                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-                PlayAwardSound(uPlayerIdx);
+                PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
                 return;
                 break;
               default:
                 return;
             }
-            *v19 += val;
-            if ( *v19 > 255 )
-              *v19 = 255;
-            this->PlaySound(SPEECH_91, 0);
-            pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-            PlayAwardSound(uPlayerIdx);
-            return;
           }
           if ( var_type == VAR_LightResistanceBonus )
           {
             this->sResLightBonus = min(this->sResLightBonus + val, 255);
-            this->PlaySound(SPEECH_91, 0);
-            pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-            PlayAwardSound(uPlayerIdx);
+            PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
             return;
           }
           if ( var_type == VAR_DarkResistanceBonus )
           {
             this->sResDarkBonus = min(this->sResDarkBonus + val, 255);
-            this->PlaySound(SPEECH_91, 0);
-            pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-            PlayAwardSound(uPlayerIdx);
+            PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
             return;
           }
           if ( var_type == VAR_MagicResistanceBonus )
           {
             this->sResMagicBonus = min(this->sResMagicBonus + val, 255);
-            this->PlaySound(SPEECH_91, 0);
-            pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-            PlayAwardSound(uPlayerIdx);
+            PlayAwardSound_Anim97_Face(uPlayerIdx, SPEECH_91);
             return;
           }
           if ( var_type <= VAR_MagicResistanceBonus || var_type > VAR_DiplomacySkill )
@@ -6461,8 +6374,7 @@
           LOBYTE(v21) = v21 & 0xC0;
           *(short *)v20 = v22 | v21;
         }
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-        PlayAwardSound(uPlayerIdx);
+        PlayAwardSound_Anim97(uPlayerIdx);
         return;
       }
       if ( var_type == VAR_LearningSkill )
@@ -6481,8 +6393,7 @@
           LOBYTE(v21) = v21 & 0xC0;
           *(short *)v20 = v22 | v21;
         }
-        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-        PlayAwardSound(uPlayerIdx);
+        PlayAwardSound_Anim97(uPlayerIdx);
         return;
       }
       if ( var_type <= VAR_LearningSkill )
@@ -6506,8 +6417,7 @@
         }
         memset(this, 0, 0xA0u);
       }
-      pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
-      PlayAwardSound(uPlayerIdx);
+      PlayAwardSound_Anim97(uPlayerIdx);
       return;
     }
     if ( !_449B57_test_bit(pParty->_autonote_bits, val) && pAutonoteTxt[val].pText )
@@ -6614,6 +6524,34 @@
   }
 }
 
+//----- (new function) --------------------------------------------------------
+void Player::PlayAwardSound_Anim97(int currPlayerId)
+{
+  pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, currPlayerId);
+  PlayAwardSound(currPlayerId);
+}
+
+//----- (new function) --------------------------------------------------------
+void Player::PlayAwardSound_Anim97_Face(int currPlayerId, PlayerSpeech speech)
+{
+  this->PlaySound(speech, 0);
+  PlayAwardSound_Anim97(currPlayerId);
+}
+
+//----- (new function) --------------------------------------------------------
+void Player::AddSkillByEvent( unsigned __int16 Player::* skillToSet, unsigned __int16 addSkillValue, int currPlayerId )
+{
+  if ( addSkillValue > 63 )
+  {
+    this->*skillToSet = (unsigned __int8)addSkillValue | this->*skillToSet & 63;
+  }
+  else
+  {
+    this->*skillToSet = min(this->*skillToSet + addSkillValue, 60) | this->*skillToSet & 0xC0;
+  }
+  PlayAwardSound_Anim97(currPlayerId);
+  return;
+}
 
 //----- (0044B9C4) --------------------------------------------------------
 bool Player::SubtractVariable(enum VariableType VarNum, signed int pValue)
--- a/Player.h	Thu Oct 03 08:32:59 2013 +0200
+++ b/Player.h	Thu Oct 03 08:53:25 2013 +0200
@@ -603,8 +603,11 @@
   bool WearsItemAnyWhere(int item_id);
   float GetArmorRecoveryMultiplierFromSkillLevel( unsigned char armour_skill_type, float param2, float param3, float param4, float param5 );
   void SetSkillByEvent(unsigned __int16 Player::* skillToSet, unsigned __int16 skillValue, int currPlayerId);
+  void AddSkillByEvent( unsigned __int16 Player::* skillToSet, unsigned __int16 addSkillValue, int currPlayerId );
+  void PlayAwardSound_Anim(int currPlayerId);
   void PlayAwardSound_Anim_Face(int currPlayerId, PlayerSpeech speech);
-  void PlayAwardSound_Anim(int currPlayerId);
+  void PlayAwardSound_Anim97(int currPlayerId);
+  void PlayAwardSound_Anim97_Face(int currPlayerId, PlayerSpeech speech);
 
   bool IsWeak();
   bool IsDead();