diff Player.cpp @ 1783:a3e86ec5d3ce

Player.cpp cosmetics
author Grumpy7
date Thu, 03 Oct 2013 06:38:20 +0200
parents 421e826f4477
children ebde8e43839c
line wrap: on
line diff
--- a/Player.cpp	Thu Oct 03 05:56:52 2013 +0200
+++ b/Player.cpp	Thu Oct 03 06:38:20 2013 +0200
@@ -297,7 +297,7 @@
     {
       baseConditionMultiplier = 5;
     }
-    if ( conditionIdx == 16 )
+    else //if ( conditionIdx == 16 )
     {
       baseConditionMultiplier = 10;
     }
@@ -900,8 +900,6 @@
 //----- (004927A8) --------------------------------------------------------
 int Player::AddItem(int index, unsigned int uItemID)
 {
-  int xStartValue = 0;
-
   if ( index == -1 )
   {
       for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
@@ -1142,7 +1140,6 @@
 {
   unsigned __int16 v2; // ax@1
   int v5; // edi@7
-  return true;
   if (CheckHiredNPCSpeciality(Scholar))
     return true;
 
@@ -2098,7 +2095,7 @@
   fineIfFailed = actroPtr->pMonsterInfo.uLevel + 100 * (_steal_perm + reputation);
   currMaxItemValue = v29 + v7 * v30;
   pGlobalTXT_LocalizationStrings[200];
-  if ( false && (rand() % 100 < 5 || fineIfFailed > currMaxItemValue || BYTE2(actroPtr->uAttributes) & 8) )
+  if ( rand() % 100 < 5 || fineIfFailed > currMaxItemValue || BYTE2(actroPtr->uAttributes) & 8 )
   {
     Actor::AggroSurroundingPeasants(uActorID, 1);
     sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[376], this->pName);
@@ -2279,6 +2276,7 @@
 
   v4 = 0;
   v47 = 0;
+  v48 = nullptr;
   switch ( attTypeCast )
   {
     case SPECIAL_ATTACK_CURSE:
@@ -2873,6 +2871,8 @@
       if (IsRaceHuman())
         racialBonus = 5;
       break;
+    default:
+      Error("Unknown attribute");
   }
   v7 = GetItemsBonus(a2) + racialBonus;
   return v7 + *resStat;
@@ -2899,25 +2899,26 @@
     v10 += leatherArmorSkillLevel & 0x3F;
   switch (a2)
   {
-  case CHARACTER_ATTRIBUTE_RESIST_FIRE:
-    resStat = &sResFireBonus;
-    break;
-  case CHARACTER_ATTRIBUTE_RESIST_AIR:
-    resStat = &sResAirBonus;
-    break;
-  case  CHARACTER_ATTRIBUTE_RESIST_WATER:
-    resStat = &sResWaterBonus;
-    break;
-  case CHARACTER_ATTRIBUTE_RESIST_EARTH:
-    resStat = &sResEarthBonus;
-    break;
-  case CHARACTER_ATTRIBUTE_RESIST_MIND:
-    resStat = &sResMindBonus;
-    break;
-  case CHARACTER_ATTRIBUTE_RESIST_BODY:
-  case CHARACTER_ATTRIBUTE_RESIST_SPIRIT:
-    resStat = &sResBodyBonus;
-    break;
+    case CHARACTER_ATTRIBUTE_RESIST_FIRE:
+      resStat = &sResFireBonus;
+      break;
+    case CHARACTER_ATTRIBUTE_RESIST_AIR:
+      resStat = &sResAirBonus;
+      break;
+    case  CHARACTER_ATTRIBUTE_RESIST_WATER:
+      resStat = &sResWaterBonus;
+      break;
+    case CHARACTER_ATTRIBUTE_RESIST_EARTH:
+      resStat = &sResEarthBonus;
+      break;
+    case CHARACTER_ATTRIBUTE_RESIST_MIND:
+      resStat = &sResMindBonus;
+      break;
+    case CHARACTER_ATTRIBUTE_RESIST_BODY:
+    case CHARACTER_ATTRIBUTE_RESIST_SPIRIT:
+      resStat = &sResBodyBonus;
+      break;
+    default: Error("Unexpected attribute");
   }
   baseRes = GetBaseResistance(a2);
   result = v10 + GetMagicalBonus(a2) + baseRes + *(resStat);
@@ -4295,6 +4296,7 @@
     case 4:  attribute_value = uAccuracy;     break;
     case 5:  attribute_value = uSpeed;        break;
     case 6:  attribute_value = uLuck;         break;
+    default: Error("Unexpected attribute");
   };
 
   if (attribute_value == base_attribute_value)
@@ -4911,6 +4913,8 @@
                 playerAffected->sResBodyBase += thisa;
                 v13 = pGlobalTXT_LocalizationStrings[29];
                 break;
+            default: ("Unexpected attribute");
+              return;
             }
             sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v13, pGlobalTXT_LocalizationStrings[121]);
             break;
@@ -5008,140 +5012,14 @@
   int actStat; // ebx@161
   int baseStat; // eax@161
 
-  if ( VarNum > VAR_AutoNotes )
-  {
-    switch ( VarNum )
-    {
-      case VAR_AutoNotes :  //TODO: find out why the double subtraction. or whether this is even used
-        test_bit_value = 0x80u >> (pValue - 2) % 8;
-        byteWithRequestedBit = pParty->_autonote_bits[(pValue - 2) /8];
-        return (test_bit_value & byteWithRequestedBit) != 0;
-      case VAR_IsMightMoreThanBase:
-        actStat = GetActualMight();
-        baseStat = GetBaseStrength();
-        return (actStat >= baseStat);
-      case VAR_IsIntellectMoreThanBase:
-        actStat = GetActualIntelligence();
-        baseStat = GetBaseIntelligence();
-        return (actStat >= baseStat);
-      case VAR_IsPersonalityMoreThanBase:
-        actStat = GetActualWillpower();
-        baseStat = GetBaseWillpower();
-        return (actStat >= baseStat);
-      case VAR_IsEnduranceMoreThanBase:
-        actStat = GetActualEndurance();
-        baseStat = GetBaseEndurance();
-        return (actStat >= baseStat);
-      case VAR_IsSpeedMoreThanBase:
-        actStat = GetActualSpeed();
-        baseStat = GetBaseSpeed();
-        return (actStat >= baseStat);
-      case VAR_IsAccuracyMoreThanBase:
-        actStat = GetActualAccuracy();
-        baseStat = GetBaseAccuracy();
-        return (actStat >= baseStat);
-      case VAR_IsLuckMoreThanBase:
-        actStat = GetActualLuck();
-        baseStat = GetBaseLuck();
-        return (actStat >= baseStat);
-      case VAR_PlayerBits:
-        test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8;
-        byteWithRequestedBit = this->field_1A50[((signed __int16)pValue - 1)/8];
-        return ( test_bit_value & byteWithRequestedBit ) != 0;
-      case VAR_NPCs2:
-        return pNPCStats->pNewNPCData[pValue].Hired();
-      case VAR_IsFlying:
-        if ( pParty->bFlying
-          && (pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime> 0) )
-          return true;
-        return false;
-      case VAR_HiredNPCHasSpeciality:
-        return CheckHiredNPCSpeciality(pValue);
-      case VAR_CircusPrises:    //isn't used in MM6 since 0x1D6u is a book of regeneration
-        v4 = 0;
-        for (int playerNum = 0; playerNum < 4; playerNum++)
-        {
-          for (int invPos = 0; invPos < 138; invPos++)
-          {
-            int itemId = pParty->pPlayers[playerNum].pInventoryItemList[invPos].uItemID;
-            switch ( itemId )
-            {
-            case 0x1D6u:
-              ++v4;
-              break;
-            case 0x1D7u:
-              v4 += 3;
-              break;
-            case 0x1DDu:
-              v4 += 5;
-              break;
-            }
-          }
-        }
-        return v4 >= pValue;
-      case VAR_NumSkillPoints:
-        return this->uSkillPoints >= (unsigned int)pValue;
-      case VAR_MonthIs:
-        return (pParty->uCurrentMonth == (unsigned int)pValue);
-      case VAR_Counter1:
-      case VAR_Counter2:
-      case VAR_Counter3:
-      case VAR_Counter4:
-      case VAR_Counter5:
-      case VAR_Counter6:
-      case VAR_Counter7:
-      case VAR_Counter8:
-      case VAR_Counter9:
-      case VAR_Counter10:
-        if (pParty->PartyTimes.CounterEventValues[VarNum - VAR_Counter1])         //originally (signed __int64)(__PAIR__(*(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44304], *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300])
-        {
-          return (pParty->PartyTimes.CounterEventValues[VarNum - VAR_Counter1] + 460800 * pValue * 0.033333335) <= pParty->uTimePlayed ;
-        }
-      case VAR_ReputationInCurrentLocation:
-        v19 = &pOutdoor->ddm;
-        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
-          v19 = &pIndoor->dlv;
-        return (v19->uReputation >= pValue);
-      case VAR_Unknown1:
-        v21 = &pOutdoor->ddm;
-        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
-          v21 = &pIndoor->dlv;
-        return (v21->field_C_alert == pValue);        //yes, equality, not >=
-      case VAR_GoldInBank:
-        return pParty->uNumGoldInBank >= (unsigned int)pValue;
-      case VAR_NumDeaths:
-        return pParty->uNumDeaths >= (unsigned int)pValue;
-      case VAR_NumBounties:
-        return pParty->uNumBountiesCollected >= (unsigned int)pValue;
-      case VAR_PrisonTerms:
-        return pParty->uNumPrisonTerms >= pValue;
-      case VAR_ArenaWinsPage:
-        return (unsigned __int8)pParty->uNumArenaPageWins >= pValue;
-      case VAR_ArenaWinsSquire:
-        return (unsigned __int8)pParty->uNumArenaSquireWins >= pValue;
-      case VAR_ArenaWinsKnight:
-        return (unsigned __int8)pParty->uNumArenaKnightWins >= pValue;
-      case VAR_ArenaWinsLord:
-        return pParty->uNumArenaLordWins >= pValue;
-      case VAR_Invisible:
-        return ( pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime > 0 );
-      case VAR_ItemEquipped:
-        for (int i = 0; i < 16; i++)
-        {
-          if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) && GetNthEquippedIndexItem(i)->uItemID == pValue )
-          {
-            return true;
-          }
-        }
-        return false;
-      default:
-        return false;
-    }
-  }
-  if ( VarNum <= VAR_MajorCondition )
-  {
-    switch ( VarNum )
-    {
+
+  if ( (signed int)VarNum >= VAR_MapPersistentVariable_0 && VarNum <= VAR_MapPersistentVariable_74 )
+    return (unsigned __int8)stru_5E4C90_MapPersistVars.field_0[VarNum - VAR_MapPersistentVariable_0] > 0;  // originally (unsigned __int8)byte_5E4C15[VarNum];
+  if ( (signed int)VarNum >= VAR_MapPersistentVariable_75 && VarNum <= VAR_MapPersistentVariable_99 )
+    return (unsigned __int8)stru_5E4C90_MapPersistVars._decor_events[VarNum - VAR_MapPersistentVariable_75] > 0;      //not really sure whether the number gets up to 99, but can't ignore the possibility
+
+  switch ( VarNum )
+  {
     case VAR_Sex:
       return ( pValue == this->uSex );
     case VAR_Class:
@@ -5167,15 +5045,11 @@
     case VAR_Age:
       return GetActualAge() >= (unsigned int)pValue;
     case VAR_Award:
-      test_bit_value = 0x80u >> (pValue - 1) % 8;
-      byteWithRequestedBit = this->_achieved_awards_bits[(pValue - 1) /8];
-      return ( test_bit_value & byteWithRequestedBit ) != 0;
+      return _449B57_test_bit(this->_achieved_awards_bits, pValue);
     case VAR_Experience:
       return this->uExperience >= pValue;       //TODO change pValue to long long
     case VAR_QBits_QuestsDone:
-      test_bit_value = 0x80u >> (pValue - 1) % 8;
-      byteWithRequestedBit = pParty->_quest_bits[(pValue - 1)/8];
-      return ( test_bit_value & byteWithRequestedBit ) != 0;
+      return _449B57_test_bit(pParty->_quest_bits, pValue);
     case VAR_PlayerItemInHands:
       for (int i = 0; i < 138; i++)
       {
@@ -5402,13 +5276,130 @@
         return v4 >= pValue;
       }
       return true;
-    }
-  }
-  if ( (signed int)VarNum >= VAR_MapPersistentVariable_0 && VarNum <= VAR_MapPersistentVariable_74 )
-    return (unsigned __int8)stru_5E4C90_MapPersistVars.field_0[VarNum - VAR_MapPersistentVariable_0] > 0;  // originally (unsigned __int8)byte_5E4C15[VarNum];
-  if ( (signed int)VarNum >= VAR_MapPersistentVariable_75 && VarNum <= VAR_MapPersistentVariable_99 )
-    return (unsigned __int8)stru_5E4C90_MapPersistVars._decor_events[VarNum - VAR_MapPersistentVariable_75] > 0;      //not really sure whether the number gets up to 99, but can't ignore the possibility
-
+    case VAR_AutoNotes :  //TODO: find out why the double subtraction. or whether this is even used
+      test_bit_value = 0x80u >> (pValue - 2) % 8;
+      byteWithRequestedBit = pParty->_autonote_bits[(pValue - 2) /8];
+      return (test_bit_value & byteWithRequestedBit) != 0;
+    case VAR_IsMightMoreThanBase:
+      actStat = GetActualMight();
+      baseStat = GetBaseStrength();
+      return (actStat >= baseStat);
+    case VAR_IsIntellectMoreThanBase:
+      actStat = GetActualIntelligence();
+      baseStat = GetBaseIntelligence();
+      return (actStat >= baseStat);
+    case VAR_IsPersonalityMoreThanBase:
+      actStat = GetActualWillpower();
+      baseStat = GetBaseWillpower();
+      return (actStat >= baseStat);
+    case VAR_IsEnduranceMoreThanBase:
+      actStat = GetActualEndurance();
+      baseStat = GetBaseEndurance();
+      return (actStat >= baseStat);
+    case VAR_IsSpeedMoreThanBase:
+      actStat = GetActualSpeed();
+      baseStat = GetBaseSpeed();
+      return (actStat >= baseStat);
+    case VAR_IsAccuracyMoreThanBase:
+      actStat = GetActualAccuracy();
+      baseStat = GetBaseAccuracy();
+      return (actStat >= baseStat);
+    case VAR_IsLuckMoreThanBase:
+      actStat = GetActualLuck();
+      baseStat = GetBaseLuck();
+      return (actStat >= baseStat);
+    case VAR_PlayerBits:
+      test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8;
+      byteWithRequestedBit = this->field_1A50[((signed __int16)pValue - 1)/8];
+      return ( test_bit_value & byteWithRequestedBit ) != 0;
+    case VAR_NPCs2:
+      return pNPCStats->pNewNPCData[pValue].Hired();
+    case VAR_IsFlying:
+      if ( pParty->bFlying
+        && (pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime> 0) )
+        return true;
+      return false;
+    case VAR_HiredNPCHasSpeciality:
+      return CheckHiredNPCSpeciality(pValue);
+    case VAR_CircusPrises:    //isn't used in MM6 since 0x1D6u is a book of regeneration
+      v4 = 0;
+      for (int playerNum = 0; playerNum < 4; playerNum++)
+      {
+        for (int invPos = 0; invPos < 138; invPos++)
+        {
+          int itemId = pParty->pPlayers[playerNum].pInventoryItemList[invPos].uItemID;
+          switch ( itemId )
+          {
+          case 0x1D6u:
+            ++v4;
+            break;
+          case 0x1D7u:
+            v4 += 3;
+            break;
+          case 0x1DDu:
+            v4 += 5;
+            break;
+          }
+        }
+      }
+      return v4 >= pValue;
+    case VAR_NumSkillPoints:
+      return this->uSkillPoints >= (unsigned int)pValue;
+    case VAR_MonthIs:
+      return (pParty->uCurrentMonth == (unsigned int)pValue);
+    case VAR_Counter1:
+    case VAR_Counter2:
+    case VAR_Counter3:
+    case VAR_Counter4:
+    case VAR_Counter5:
+    case VAR_Counter6:
+    case VAR_Counter7:
+    case VAR_Counter8:
+    case VAR_Counter9:
+    case VAR_Counter10:
+      if (pParty->PartyTimes.CounterEventValues[VarNum - VAR_Counter1])         //originally (signed __int64)(__PAIR__(*(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44304], *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300])
+      {
+        return (pParty->PartyTimes.CounterEventValues[VarNum - VAR_Counter1] + 460800 * pValue * 0.033333335) <= pParty->uTimePlayed ;
+      }
+    case VAR_ReputationInCurrentLocation:
+      v19 = &pOutdoor->ddm;
+      if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
+        v19 = &pIndoor->dlv;
+      return (v19->uReputation >= pValue);
+    case VAR_Unknown1:
+      v21 = &pOutdoor->ddm;
+      if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
+        v21 = &pIndoor->dlv;
+      return (v21->field_C_alert == pValue);        //yes, equality, not >=
+    case VAR_GoldInBank:
+      return pParty->uNumGoldInBank >= (unsigned int)pValue;
+    case VAR_NumDeaths:
+      return pParty->uNumDeaths >= (unsigned int)pValue;
+    case VAR_NumBounties:
+      return pParty->uNumBountiesCollected >= (unsigned int)pValue;
+    case VAR_PrisonTerms:
+      return pParty->uNumPrisonTerms >= pValue;
+    case VAR_ArenaWinsPage:
+      return (unsigned __int8)pParty->uNumArenaPageWins >= pValue;
+    case VAR_ArenaWinsSquire:
+      return (unsigned __int8)pParty->uNumArenaSquireWins >= pValue;
+    case VAR_ArenaWinsKnight:
+      return (unsigned __int8)pParty->uNumArenaKnightWins >= pValue;
+    case VAR_ArenaWinsLord:
+      return pParty->uNumArenaLordWins >= pValue;
+    case VAR_Invisible:
+      return ( pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime > 0 );
+    case VAR_ItemEquipped:
+      for (int i = 0; i < 16; i++)
+      {
+        if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) && GetNthEquippedIndexItem(i)->uItemID == pValue )
+        {
+          return true;
+        }
+      }
+      return false;
+  }
+  
   return false;
 }
 
@@ -5534,9 +5525,7 @@
       this->sAgeModifier = var_value;
       return;
     case VAR_Award:
-      if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & 
-		this->_achieved_awards_bits[((signed __int16)var_value - 1)/ 8]) //&& dword_723E80_award_related[2 * a3] )
-	&& pAwards[var_value].pText )
+      if ( !_449B57_test_bit(this->_achieved_awards_bits, var_value) && pAwards[var_value].pText )
       {
         PlayAwardSound_Anim(currPlayerId);
         this->PlaySound(SPEECH_96, 0);
@@ -5548,8 +5537,7 @@
       PlayAwardSound_Anim(currPlayerId);
       return;
     case VAR_QBits_QuestsDone:
-      if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & pParty->_quest_bits[((signed __int16)var_value - 1) >> 3])// && (&dword_722F10)[4 * a3] )
-		&& pQuestTable[var_value-1] )
+      if ( !_449B57_test_bit(pParty->_quest_bits, var_value) && pQuestTable[var_value-1] )
       {
         bFlashQuestBook = 1;
         pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
@@ -5807,8 +5795,7 @@
       PlayAwardSound_Anim(currPlayerId);
       return;
     case VAR_AutoNotes:
-      if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & pParty->_autonote_bits[((signed __int16)var_value - 1) >> 3]) //&& (&dword_723718_autonote_related)[8 * a3] )
-        && pAutonoteTxt[var_value-1].pText )
+      if ( !_449B57_test_bit(pParty->_autonote_bits, var_value) && pAutonoteTxt[var_value-1].pText )
       {
         pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
         this->PlaySound(SPEECH_96, 0);
@@ -7400,6 +7387,7 @@
         case 1 : soundToPlay = (SoundID)109; break;
         case 2 : soundToPlay = (SoundID)110; break;
         case 3 : soundToPlay = (SoundID)44; break;
+        default: Error("Unexpected sound value");
       }
     }
     else
@@ -7411,6 +7399,7 @@
         case 1 : soundToPlay = (SoundID)106; break;
         case 2 : soundToPlay = (SoundID)107; break;
         case 3 : soundToPlay = (SoundID)45; break;
+        default: Error("Unexpected sound value");
       }
     }
     pAudioPlayer->PlaySound(soundToPlay, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0);