changeset 1766:110727780974

Player::SetVariable restarting function refatcoring
author Grumpy7
date Tue, 01 Oct 2013 07:29:30 +0200
parents a2ea57410b15
children 3ee4a4d592af
files Player.cpp
diffstat 1 files changed, 340 insertions(+), 309 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Tue Oct 01 06:19:58 2013 +0200
+++ b/Player.cpp	Tue Oct 01 07:29:30 2013 +0200
@@ -5417,15 +5417,15 @@
 void Player::SetVariable(enum VariableType var_type, signed int var_value)
 {
   signed int currPlayerId; // ebx@1
-  Player *v4_unused; // esi@1
-  unsigned int v5_unused; // edi@1
+  Player *v4; // esi@1
+  unsigned int v5; // edi@1
   unsigned int v6; // esi@13
   unsigned int v7; // esi@14
-  signed int v8_unused; // eax@17
+  signed int v8; // eax@17
   ItemGen *v9; // ecx@17
   int v10; // eax@21
   signed int v11; // eax@30
-  Player *unused12; // ecx@44
+  Player *v12; // ecx@44
   char *v13; // ecx@45
   Player *v14; // ecx@49
   int v15; // ecx@86
@@ -5440,23 +5440,23 @@
   DDM_DLV_Header *v24; // ecx@148
   signed int v25; // eax@172
   int v26; // [sp-8h] [bp-3Ch]@84
-  signed int unused27; // [sp-4h] [bp-38h]@4
-  int v28_unused; // [sp-4h] [bp-38h]@84
+  signed int v27; // [sp-4h] [bp-38h]@4
+  int v28; // [sp-4h] [bp-38h]@84
   ItemGen item; // [sp+Ch] [bp-28h]@52
-  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
-  {
-    if ( this == pPlayers[i] )
-    {
-      currPlayerId = i - 1;
-      break;
-    }
-  }
-
-  Assert(currPlayerId != -1);
+  char v30; // [sp+32h] [bp-2h]@1
+  char v31; // [sp+33h] [bp-1h]@1
+
+  currPlayerId = 0;
+  v30 = 0;
+  v31 = 0;
+  v4 = this;
+  v5 = 0;
+  if ( this == pPlayers[2] )
+    currPlayerId = 1;
+  else if ( this == pPlayers[3] )
+    currPlayerId = 2;
+  else if ( this == pPlayers[4] )
+     currPlayerId  = 3;
   if ( var_type > VAR_AutoNotes )
   {
     if ( var_type <= VAR_GoldInBank )
@@ -5518,247 +5518,271 @@
           return;
         bFlashHistoryBook = 1;
       }
+LABEL_172:
       v25 = 8 * currPlayerId + 400;
       LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
-      pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
+      pAudioPlayer->PlaySound(SOUND_20001, v25, v5, -1, v5, v5, v5, v5);
       return;
     }
-    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 != 307 )
+    {
+      switch ( var_type )
+      {
+        case 308:
+          pParty->uNumBountiesCollected = var_value;
+          break;
+        case 309:
+          pParty->uNumPrisonTerms = var_value;
+          break;
+        case 310:
+          pParty->uNumArenaPageWins = var_value;
+          break;
+        case 311:
+          pParty->uNumArenaSquireWins = var_value;
+          break;
+        case 312:
+          pParty->uNumArenaKnightWins = var_value;
+          break;
+        case 313:
+          pParty->uNumArenaLordWins = var_value;
+          break;
+      }
+      return;
+    }
+    pParty->uNumDeaths = var_value;
+LABEL_168:
+    if ( v30 != 1 )
+    {
+LABEL_170:
+      if ( v31 != 1 )
+        return;
+      v5 = 0;
+      goto LABEL_172;
+    }
+LABEL_169:
+    pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
+    goto LABEL_170;
   }
   if ( var_type == 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].pText )
+	  && pAutonoteTxt[var_value-1].pText )
     {
       v20 = pPlayers[currPlayerId + 1];
+      v30 = 1;
       v20->PlaySound(SPEECH_96, 0);
-	  //v21 = pAutonoteTxt[var_value].eType;// dword_72371C[2 * a3];
+	  v21 = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3];
       bFlashAutonotesBook = 1;
-      _506568_autonote_type = pAutonoteTxt[var_value].eType;
-      DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
-    }
-    _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1);
-    PlaySoundBasedOnCondition(currPlayerId);
-    return;
-  }
-  if ( var_type <= VAR_BaseLuck )
-  {
-    switch ( var_type )
-    {
-      case VAR_Sex:
-        this->uSex = (PLAYER_SEX)var_value;
-        goto LABEL_124;
-      case VAR_Class:
-        this->classType = (PLAYER_CLASS_TYPE)var_value;
-        if ( (char)var_value == PLAYER_CLASS_LICH )
-        {
-          for (int i = 0; i < 138; i++)
-          {
-            v9 = &this->pInventoryItemList[i];
-            if (v9->uItemID == ITEM_LICH_JAR_EMPTY)
-            {
-              v9->uItemID = ITEM_LICH_JAR_FULL;
-              v9->uHolderPlayer = currPlayerId + 1;
-              v10 = (int)((char *)this + 36 * 138);
-              *(int *)(v10 + 532) = 601;
-              *(char *)(v10 + 558) = currPlayerId + 1;
-              break;
-            }
-          }
-          if ( this->sResFireBase < 20 )
-            this->sResFireBase = 20;
-          if ( this->sResAirBase < 20 )
-            this->sResAirBase = 20;
-          if ( this->sResWaterBase < 20 )
-            this->sResWaterBase = 20;
-          if ( this->sResEarthBase < 20 )
-            this->sResEarthBase = 20;
-          this->sResMindBase = 200;
-          this->sResBodyBase = 200;
-          this->uPrevVoiceID = this->uVoiceID;
-          this->uPrevFace = this->uCurrentFace;
-          if ( IsFemale() )
-          {
-            this->uCurrentFace = 21;
-            this->uVoiceID = 21;
-          }
-          else
-          {
-            this->uCurrentFace = 20;
-            this->uVoiceID = 20;
-          }
-          ReloadPlayerPortraits(currPlayerId, this->uCurrentFace);
-        }
-        goto LABEL_124;
-      case VAR_CurrentHP:
-        this->sHealth = var_value;
-        goto LABEL_124;
-      case VAR_MaxHP:
-        this->sHealth = GetMaxHealth();
-        return;
-      case VAR_CurrentSP:
-        this->sMana = var_value;
-        goto LABEL_124;
-      case VAR_MaxSP:
-        this->sMana = GetMaxMana();
-        return;
-      case VAR_ACModifier:
-        this->sACModifier = (unsigned __int8)var_value;
-        goto LABEL_124;
-      case VAR_BaseLevel:
-        this->uLevel = (unsigned __int8)var_value;
-        goto LABEL_124;
-      case VAR_LevelModifier:
-        this->sLevelModifier = (unsigned __int8)var_value;
-        goto LABEL_124;
-      case VAR_Age:
-        this->sAgeModifier = var_value;
-        return;
-      case VAR_Award:
-        if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & 
+      _506568_autonote_type = v21;
+    }
+    _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1u);
+    v31 = 1;
+    goto LABEL_168;
+  }
+  if ( var_type <= VAR_ActualMight )
+  {
+    if ( var_type != VAR_ActualMight )
+    {
+      switch ( var_type )
+      {
+        case VAR_RandomGold:
+          v6 = rand() % var_value + 1;
+          Party::SetGold(v6);
+          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[500], v6);// You have %lu gold
+          ShowStatusBarString(pTmpBuf.data(), 2u);
+          GameUI_DrawFoodAndGold();
+          return;
+        case VAR_RandomFood:
+          v7 = rand() % var_value + 1;
+          Party::SetFood(v7);
+          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[501], v7);// You have %lu food
+          ShowStatusBarString(pTmpBuf.data(), 2u);
+          GameUI_DrawFoodAndGold();
+          goto LABEL_124;
+        case VAR_Sex:
+          this->uSex = (PLAYER_SEX)var_value;
+          goto LABEL_124;
+        case VAR_Class:
+          this->classType = (PLAYER_CLASS_TYPE)var_value;
+          if ( (char)var_value != 35 )
+            goto LABEL_124;
+          v8 = 0;
+          v9 = this->pInventoryItemList;
+          break;
+        case VAR_CurrentHP:
+          this->sHealth = var_value;
+          goto LABEL_124;
+        case VAR_MaxHP:
+          this->sHealth = GetMaxHealth();
+          return;
+        case VAR_CurrentSP:
+          this->sMana = var_value;
+          goto LABEL_124;
+        case VAR_MaxSP:
+          this->sMana = GetMaxMana();
+          return;
+        case VAR_ACModifier:
+          this->sACModifier = (unsigned __int8)var_value;
+          goto LABEL_124;
+        case VAR_BaseLevel:
+          this->uLevel = (unsigned __int8)var_value;
+          goto LABEL_124;
+        case VAR_LevelModifier:
+          this->sLevelModifier = (unsigned __int8)var_value;
+          goto LABEL_124;
+        case VAR_Age:
+          this->sAgeModifier = var_value;
+          return;
+        case VAR_Award:
+          if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & 
 			  pPlayers[currPlayerId + 1]->_achieved_awards_bits[((signed __int16)var_value - 1)/ 8])
-              //&& dword_723E80_award_related[2 * a3] )
-		    && pAwards[var_value].pText )
-        {
-          pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0);
-          DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
-          PlaySoundBasedOnCondition(currPlayerId);
-        }
-        _449B7E_toggle_bit((unsigned char *)this->_achieved_awards_bits, var_value, 1u);
-        return;
-      case VAR_Experience:
-        this->uExperience = var_value;
-        goto LABEL_124;
-      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] )
+            //&& dword_723E80_award_related[2 * a3] )
+			&& pAwards[var_value].pText )
+          {
+            v30 = 1;
+            v31 = 1;
+            pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0);
+          }
+		  _449B7E_toggle_bit((unsigned char *)v4->_achieved_awards_bits, var_value, 1u);
+          goto LABEL_168;
+        case VAR_Experience:
+          this->uExperience = var_value;
+          goto LABEL_124;
+        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] )
           {
-          v14 = pPlayers[currPlayerId + 1];
-          bFlashQuestBook = 1;
-          v14->PlaySound(SPEECH_93, 0);
-          DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
-          PlaySoundBasedOnCondition(currPlayerId);
-        }
-        v13 = (char *)pParty->_quest_bits;
-        _449B7E_toggle_bit((unsigned char *)v13, var_value, 1u);
-        return;
-      case VAR_PlayerItemInHands:
-        item.Reset();
-        item.Reset();
-        item.uItemID = var_value;
-        item.uAttributes = 1;
-        pParty->SetHoldingItem(&item);
-        if ( var_value >= ITEM_ARTIFACT_PUCK && var_value <= ITEM_RELIC_MEKORIGS_HAMMER )
-          pParty->pIsArtifactFound[var_value-500] = 1;
-        return;
-      case VAR_FixedGold:
-        Party::SetGold(var_value);
-        return;
-      case VAR_RandomGold:
-        v6 = rand() % var_value + 1;
-        Party::SetGold(v6);
-        sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[500], v6);// You have %lu gold
-        ShowStatusBarString(pTmpBuf.data(), 2u);
-        GameUI_DrawFoodAndGold();
-        return;
-      case VAR_FixedFood:
-        Party::SetFood(var_value);
-        goto LABEL_124;
-      case VAR_RandomFood:
-        v7 = rand() % var_value + 1;
-        Party::SetFood(v7);
-        sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[501], v7);// You have %lu food
-        ShowStatusBarString(pTmpBuf.data(), 2u);
-        GameUI_DrawFoodAndGold();
-        goto LABEL_124;
-      case VAR_MightBonus:
-        goto LABEL_64;
-      case VAR_IntellectBonus:
-        goto LABEL_68;
-      case VAR_PersonalityBonus:
-        goto LABEL_69;
-      case VAR_EnduranceBonus:
-        goto LABEL_70;
-      case VAR_SpeedBonus:
-        goto LABEL_71;
-      case VAR_AccuracyBonus:
-        goto LABEL_72;
-      case VAR_LuckBonus:
-        goto LABEL_73;
-      case VAR_BaseMight:
-        this->uMight = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BaseIntellect:
-        this->uIntelligence = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BasePersonality:
-        this->uWillpower = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BaseEndurance:
-        this->uEndurance = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BaseSpeed:
-        this->uSpeed = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BaseAccuracy:
-        this->uAccuracy = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      case VAR_BaseLuck:
-        this->uLuck = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
-      default:
-        return;
-    }
+            v14 = pPlayers[currPlayerId + 1];
+            bFlashQuestBook = 1;
+            v30 = 1;
+            v31 = 1;
+            v14->PlaySound(SPEECH_93, 0);
+          }
+          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();
+          item.Reset();
+          item.uItemID = var_value;
+          item.uAttributes = 1;
+          pParty->SetHoldingItem(&item);
+          if ( var_value >= ITEM_ARTIFACT_PUCK && var_value <= ITEM_RELIC_MEKORIGS_HAMMER )
+            pParty->pIsArtifactFound[var_value-500] = 1;
+          return;
+        case VAR_FixedGold:
+          Party::SetGold(var_value);
+          return;
+        case VAR_BaseMight:
+          this->uMight = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BaseIntellect:
+          this->uIntelligence = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BasePersonality:
+          this->uWillpower = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BaseEndurance:
+          this->uEndurance = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BaseSpeed:
+          this->uSpeed = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BaseAccuracy:
+          this->uAccuracy = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_BaseLuck:
+          this->uLuck = (unsigned __int8)var_value;
+          goto LABEL_84;
+        case VAR_FixedFood:
+          Party::SetFood(var_value);
+          goto LABEL_124;
+        case VAR_MightBonus:
+          goto LABEL_64;
+        case VAR_IntellectBonus:
+          goto LABEL_68;
+        case VAR_PersonalityBonus:
+          goto LABEL_69;
+        case VAR_EnduranceBonus:
+          goto LABEL_70;
+        case VAR_SpeedBonus:
+          goto LABEL_71;
+        case VAR_AccuracyBonus:
+          goto LABEL_72;
+        case VAR_LuckBonus:
+          goto LABEL_73;
+        default:
+          return;
+      }
+      while ( v9->uItemID != 615 )
+      {
+        ++v8;
+        ++v9;
+        if ( v8 >= 138 )
+          goto LABEL_22;
+      }
+      v10 = (int)((char *)v4 + 36 * v8);
+      *(int *)(v10 + 532) = 601;
+      *(char *)(v10 + 558) = currPlayerId + 1;
+LABEL_22:
+      if ( v4->sResFireBase < 20 )
+        v4->sResFireBase = 20;
+      if ( v4->sResAirBase < 20 )
+        v4->sResAirBase = 20;
+      if ( v4->sResWaterBase < 20 )
+        v4->sResWaterBase = 20;
+      if ( v4->sResEarthBase < 20 )
+        v4->sResEarthBase = 20;
+      v4->sResMindBase = 200;
+      v4->sResBodyBase = 200;
+      v11 = v4->GetSexByVoice();
+      v4->uPrevVoiceID = v4->uVoiceID;
+      v4->uPrevFace = v4->uCurrentFace;
+      if ( v11 )
+      {
+        v4->uCurrentFace = 21;
+        v4->uVoiceID = 21;
+      }
+      else
+      {
+        v4->uCurrentFace = 20;
+        v4->uVoiceID = 20;
+      }
+      ReloadPlayerPortraits(currPlayerId, v4->uCurrentFace);
+      goto LABEL_124;
+    }
+LABEL_64:
+    this->uMightBonus = (unsigned __int8)var_value;
 LABEL_111:
+    v28 = 0;
     v26 = SPEECH_91;
 LABEL_112:
     v19 = pPlayers[currPlayerId + 1];
-    v19->PlaySound((PlayerSpeech)v26, 0);
-    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
-    PlaySoundBasedOnCondition(currPlayerId);
-    return;
-  }
-  if ( var_type <= VAR_MagicResistance )
-  {
+    v31 = 1;
+    v19->PlaySound((PlayerSpeech)v26, v28);
+    goto LABEL_169;
+  }
+  if ( var_type <= VAR_FireResistanceBonus )
+  {
+    if ( var_type == VAR_FireResistanceBonus )
+    {
+      this->sResFireBonus = (unsigned __int8)var_value;
+      goto LABEL_111;
+    }
     switch ( var_type )
     {
-      case VAR_ActualMight:
-LABEL_64:
-        this->uMightBonus = (unsigned __int8)var_value;
-        goto LABEL_111;
       case VAR_ActualIntellect:
 LABEL_68:
         this->uIntelligenceBonus = (unsigned __int8)var_value;
@@ -5785,42 +5809,35 @@
         goto LABEL_111;
       case VAR_FireResistance:
         this->sResFireBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_AirResistance:
         this->sResAirBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_WaterResistance:
         this->sResWaterBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_EarthResistance:
         this->sResEarthBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_SpiritResistance:
         this->sResSpiritBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_MindResistance:
         this->sResMindBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_BodyResistance:
         this->sResBodyBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_LightResistance:
         this->sResLightBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_DarkResistance:
         this->sResDarkBase = (unsigned __int8)var_value;
-        v26 = 92;
-        goto LABEL_112;
+        goto LABEL_84;
       case VAR_MagicResistance:
         this->sResMagicBase = (unsigned __int8)var_value;
+LABEL_84:
+        v28 = 0;
         v26 = 92;
         goto LABEL_112;
       default:
@@ -5837,7 +5854,7 @@
         return;
       if ( var_type <= VAR_Eradicated )
       {
-        this->SetCondition(var_type - 105, 1);
+        v4->SetCondition(var_type - 105, 1);
       }
       else
       {
@@ -5847,78 +5864,92 @@
             byte_5E4C15[var_type] = var_value;
           return;
         }
-        memset(this, 0, 0xA0u);
+        memset(v4, 0, 0xA0u);
       }
+LABEL_124:
+      v31 = 1;
+      goto LABEL_169;
+    }
+LABEL_106:
+    v16 = (int)((char *)&v4->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
     {
-      v16 = (int)((char *)&this->pConditions[16] + 2 * var_type);
-      v17 = *(char *)v16;
-      if ( var_value <= 63 )
-      {
-        LOWORD(v15) = (unsigned __int8)var_value;
-        v18 = v15 | v17 & 63;
-      }
-      else
-      {
-        LOWORD(v18) = (unsigned __int8)(var_value | v17 & 0xC0);
-      }
-      *(short *)v16 = v18;
-    }
-LABEL_124:
-    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
-    PlaySoundBasedOnCondition(currPlayerId);
-    return;
-  }
-  if ( var_type <= VAR_MagicResistanceBonus )
+      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;
+  if ( var_type <= VAR_BodyResistanceBonus )
   {
     switch ( var_type )
     {
-      case VAR_FireResistanceBonus:
-        this->sResFireBonus = (unsigned __int8)var_value;
+      case VAR_BodyResistanceBonus:
+        v4->sResBodyBonus = (unsigned __int8)var_value;
         break;
       case VAR_AirResistanceBonus:
-        this->sResAirBonus = (unsigned __int8)var_value;
+        v4->sResAirBonus = (unsigned __int8)var_value;
         break;
       case VAR_WaterResistanceBonus:
-        this->sResWaterBonus = (unsigned __int8)var_value;
+        v4->sResWaterBonus = (unsigned __int8)var_value;
         break;
       case VAR_EarthResistanceBonus:
-        this->sResEarthBonus = (unsigned __int8)var_value;
+        v4->sResEarthBonus = (unsigned __int8)var_value;
         break;
       case VAR_SpiritResistanceBonus:
-        this->sResSpiritBonus = (unsigned __int8)var_value;
-        break;
-      case VAR_MindResistanceBonus:
-        this->sResMindBonus = (unsigned __int8)var_value;
-        break;
-      case VAR_BodyResistanceBonus:
-        this->sResBodyBonus = (unsigned __int8)var_value;
-        break;
-      case VAR_LightResistanceBonus:
-        this->sResLightBonus = (unsigned __int8)var_value;
-        break;
-      case VAR_DarkResistanceBonus:
-        this->sResDarkBonus = (unsigned __int8)var_value;
-        break;
-      case VAR_PhysicalResistanceBonus:
-        Assert("VAR_PhysicalResistanceBonus variable unsupported" && false);
-        return;
-        break;
-      case VAR_MagicResistanceBonus:
-        this->sResMagicBonus = (unsigned __int8)var_value;
+        v4->sResSpiritBonus = (unsigned __int8)var_value;
         break;
       default:
-          Error("Unexpected var_type: %u", var_type);
+        if ( var_type != 62 )
           return;
+        v4->sResMindBonus = (unsigned __int8)var_value;
         break;
     }
     goto LABEL_111;
   }
-  if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill || var_type == VAR_DisarmTrapSkill)  //VAR_ThieverySkill wasn't present in the original function
-  {
-    return;
-  }
+  if ( var_type == VAR_LightResistanceBonus )
+  {
+    v4->sResLightBonus = (unsigned __int8)var_value;
+    goto LABEL_111;
+  }
+  if ( var_type == VAR_DarkResistanceBonus )
+  {
+    v4->sResDarkBonus = (unsigned __int8)var_value;
+    goto LABEL_111;
+  }
+  if ( var_type == VAR_MagicResistanceBonus )
+  {
+    v4->sResMagicBonus = (unsigned __int8)var_value;
+    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;
 }