view Player.cpp @ 1640:afc1c3514dd5

Some common code from ODM and BLV RenderParams moved to IndoorCameraD3D
author Nomad
date Tue, 17 Sep 2013 17:40:59 +0200
parents 61ea994a1812
children 511cd6dd1048
line wrap: on
line source

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "stru6.h"

#include "Player.h"
#include "PlayerFrameTable.h"
#include "AudioPlayer.h"
#include "Party.h"
#include "Log.h"
#include "LOD.h"
#include "GUIWindow.h"
#include "Viewport.h"
#include "Actor.h"
#include "Game.h"
#include "Mouse.h"
#include "TurnEngine.h"
#include "Events.h"
#include "Events2D.h"
#include "Outdoor.h"
#include "StorylineTextTable.h"
#include "Autonotes.h"
#include "Awards.h"
#include "texts.h"

#include "mm7_data.h"
#include "MM7.h"
#include "SpriteObject.h"
#include "DecalBuilder.h"





/*  381 */
#pragma pack(push, 1)
struct PlayerCreation_AttributeProps
{
  unsigned __int8 uBaseValue;
  char uMaxValue;
  char uDroppedStep;
  char uBaseStep;
};
#pragma pack(pop)


#pragma pack(push, 1)



#pragma pack(pop)
PlayerCreation_AttributeProps StatTable[4][7] = //0x4ED7B0
{
  {{11, 25, 1, 1}, {11, 25, 1, 1}, {11, 25, 1, 1}, { 9, 25, 1, 1}, {11, 25, 1, 1}, {11, 25, 1, 1}, {9, 25, 1, 1},},
  {{ 7, 15, 2, 1}, {14, 30, 1, 2}, {11, 25, 1, 1}, { 7, 15, 2, 1}, {14, 30, 1, 2}, {11, 25, 1, 1}, {9, 20, 1, 1},},
  {{14, 30, 1, 2}, { 7, 15, 2, 1}, { 7, 15, 2, 1}, {11, 25, 1, 1}, {11, 25, 1, 1}, {14, 30, 1, 2}, {9, 20, 1, 1},},
  {{14, 30, 1, 2}, {11, 25, 1, 1}, {11, 25, 1, 1}, {14, 30, 1, 2}, { 7, 15, 2, 1}, { 7, 15, 2, 1}, {9, 20, 1, 1}}
};






 // available skills per class ( 9 classes X 37 skills )
 // 0 - not available
 // 1 - available
 // 2 - primary skill
unsigned char pSkillAvailabilityPerClass[9][37] =  // byte[] @ MM7.exe::004ED820
{
  {0, 2, 0, 1, 1, 1, 1, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  {0, 1, 2, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 2, 1, 0},
  {1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 1, 1, 0, 0, 0},
  {0, 1, 1, 1, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
  {0, 1, 0, 1, 1, 2, 0, 0, 0, 1, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
  {0, 1, 1, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
  {0, 0, 2, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
  {2, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0} // some of these are started at 4ED94C, but needs to be here
};


unsigned char pEquipTypeToBodyAnchor[21] = // 4E8398
{
  1, // EQUIP_OFF_HAND
  1, // EQUIP_MAIN_HAND
  2, // EQUIP_BOW
  3, // EQUIP_ARMOUR
  0, // EQUIP_SHIELD
  4, // EQUIP_HELMET
  5, // EQUIP_BELT
  6, // EQUIP_CLOAK
  7, // EQUIP_GAUNTLETS
  8, // EQUIP_BOOTS
  10, // EQUIP_RING
  9, // EQUIP_AMULET
  1, // EQUIP_WAND
  0, // EQUIP_REAGENT
  0, // EQUIP_POTION
  0, // EQUIP_SPELL_SCROLL
  0, // EQUIP_BOOK
  0, // EQUIP_MESSAGE_SCROLL
  0, // EQUIP_GOLD
  0, // EQUIP_GEM
  0 // EQUIP_NONE
};


unsigned char pBaseHealthByClass[12] = {40, 35, 35, 30, 30, 30, 25, 20, 20, 0, 0, 0};
unsigned char pBaseManaByClass[12]   = { 0,  0,  0,  5,  5,  0, 10, 10, 15, 0, 0, 0};
unsigned char pBaseHealthPerLevelByClass[36] = {5, 7, 9, 9, 4, 6, 8, 8, 5, 6, 8, 8, 4, 5, 6, 6, 3, 4, 6, 6, 4, 5, 6, 6, 2, 3, 4, 4, 2, 3, 4, 4, 2, 3, 3, 3};
unsigned char pBaseManaPerLevelByClass[36]   = {0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 2, 3, 3, 1, 2, 3, 3, 0, 2, 3, 3, 3, 4, 5, 5, 3, 4, 5, 5, 3, 4, 6, 6};

unsigned char pConditionAttributeModifier[7][19]   =  
{{100, 100, 100, 120,  50, 200,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100, 100, 100},  //Might
 {100, 100, 100,  50,  25,  10, 100, 100,  75,  60,  50,  30, 100, 100, 100, 100, 100,   1, 100},  //Intelligence
 {100, 100, 100,  50,  25,  10, 100, 100,  75,  60,  50,  30, 100, 100, 100, 100, 100,   1, 100},  //Willpower
 {100, 100, 100, 100,  50, 150,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100, 100, 100},  //Endurance
 {100, 100, 100,  50,  10, 100,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100,  50, 100},  //Accuracy
 {100, 100, 100, 120,  20, 120,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100,  50, 100},  //Speed
 {100, 100, 100, 100, 200, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}}; //Luck

unsigned char pAgingAttributeModifier[7][4] = 
{{100,  75,  40, 10},   //Might
 {100, 150, 100, 10},   //Intelligence
 {100, 150, 100, 10},   //Willpower
 {100,  75,  40, 10},   //Endurance
 {100, 100,  40, 10},   //Accuracy
 {100, 100,  40, 10},   //Speed
 {100, 100, 100, 100}}; //Luck

signed int pAgeingTable[4] = {50, 100, 150, 0xFFFF};

std::array<unsigned int, 18> pConditionImportancyTable = {{16, 15, 14, 17, 13, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 0}};

short param_to_bonus_table[29] = {500, 400, 350, 300, 275, 250, 225, 200, 175,
                         150, 125, 100,  75,  50,  40,  35,  30,  25,  21,
                         19,   17,  15,  13,  11,   9,   7,   5,   3,   0};
signed int parameter_to_bonus_value[29] = {30, 25, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6};


unsigned short base_recovery_times_per_weapon_type[12] =
{
  100,  // PLAYER_SKILL_STAFF   && Unarmed withoud skill
   90,  // PLAYER_SKILL_SWORD   && Unarmed with skill
   60,  // PLAYER_SKILL_DAGGER
  100,  // PLAYER_SKILL_AXE
   80,  // PLAYER_SKILL_SPEAR
  100,  // PLAYER_SKILL_BOW
   80,  // PLAYER_SKILL_MACE
   30,  // PLAYER_SKILL_BLASTER
   10,  // PLAYER_SKILL_SHIELD
   10,  // PLAYER_SKILL_LEATHER
   20,  // PLAYER_SKILL_CHAIN
   30   // PLAYER_SKILL_PLATE
};

//----- (00490913) --------------------------------------------------------
int PlayerCreation_GetUnspentAttributePointCount()
{
  signed int v0; // edi@1
  int raceId; // ebx@2
  signed int v4; // eax@17
  int v5; // edx@18
  signed int v6; // ecx@18
  signed int remainingStatPoints; // [sp+Ch] [bp-8h]@1

  remainingStatPoints = 50;
  v0 = 50;
  for (int playerNum = 0; playerNum < 4; playerNum++)
  {
    raceId = pParty->pPlayers[playerNum].GetRace();
    for (int statNum = 0; statNum <= 6; statNum++)
    {
      switch ( statNum )
      {
      case 0:
        v0 = pParty->pPlayers[playerNum].uMight;
        break;
      case 1:
        v0 = pParty->pPlayers[playerNum].uIntelligence;
        break;
      case 2:
        v0 = pParty->pPlayers[playerNum].uWillpower;
        break;
      case 3:
        v0 = pParty->pPlayers[playerNum].uEndurance;
        break;
      case 4:
        v0 = pParty->pPlayers[playerNum].uAccuracy;
        break;
      case 5:
        v0 = pParty->pPlayers[playerNum].uSpeed;
        break;
      case 6:
        v0 = pParty->pPlayers[playerNum].uLuck;
        break;
      }
      v4 = StatTable[raceId][statNum].uBaseValue;
      if ( v0 >= v4 )
      {
        v5 = StatTable[raceId][statNum].uDroppedStep;
        v6 = StatTable[raceId][statNum].uBaseStep;
      }
      else
      {
        v5 = StatTable[raceId][statNum].uBaseStep;
        v6 = StatTable[raceId][statNum].uDroppedStep;
      }
      remainingStatPoints += v5 * (v4 - v0) / v6;
    }
  }
  return remainingStatPoints;
}



//----- (00427730) --------------------------------------------------------
bool Player::CanCastSpell(unsigned int uRequiredMana)
{
  if (sMana >= (signed int)uRequiredMana)
  {
    sMana -= (signed int)uRequiredMana;
    return true;
  }

  pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
  return false;
}


//----- (004BE2DD) --------------------------------------------------------
void Player::SalesProcess( unsigned int inventory_idnx, int item_index, int _2devent_idx )
    {
  float v6; // ST04_4@1
  signed int item_value; // eax@1
  signed int sell_price; // ebx@1

  item_value =pOwnItems[item_index].GetValue();
  v6 = p2DEvents[ _2devent_idx - 1].fPriceMultiplier;
  sell_price = GetPriceSell(item_value, v6);
  if ( pOwnItems[item_index].IsBroken() )
    sell_price = 1;
  if ( sell_price < 1 )
    sell_price = 1;
  RemoveItemAtInventoryIndex(inventory_idnx);
  Party::SetGold(pParty->uNumGold + sell_price);
}



//----- (0043EEF3) --------------------------------------------------------
bool Player::NothingOrJustBlastersEquipped()
{
  signed int item_idx; // esi@1
  signed int item_id; // esi@1
  for (int i = 0; i < 16; ++i)
  {
    item_idx = pEquipment.pIndices[i];
    if (item_idx)
    {
      item_id = pOwnItems[item_idx - 1].uItemID;
      if ( item_id != ITEM_BLASTER && item_id != ITEM_LASER_RIFLE ) //blaster& blaster rifle
          return false;
    }
  }
  return true;
}
  



//----- (004B8040) --------------------------------------------------------
int Player::GetConditionDayOfWeek( unsigned int uCondition )
    {
  return (unsigned int)(((signed __int64)((double)this->pConditions[uCondition] * 0.234375) / 60 / 60) / 24) % 7 + 1;
}

//----- (004B807C) --------------------------------------------------------
int Player::GetTempleHealCostModifier(float a2)
{
  unsigned int conditionIdx; // eax@1
  int conditionTimeMultiplier; // esi@1
  int v6; // eax@8
  signed int result; // qax@13
  signed int baseConditionMultiplier; // [sp+8h] [bp-8h]@4

  conditionIdx = GetMajorConditionIdx();
  if ( conditionIdx >= 14 && conditionIdx <= 16)
  {
    if ( conditionIdx <= 15 )
    {
      baseConditionMultiplier = 5;
    }
    if ( conditionIdx == 16 )
    {
      baseConditionMultiplier = 10;
    }
    conditionTimeMultiplier = GetConditionDayOfWeek(conditionIdx);
  }
  else 
  {
    conditionTimeMultiplier = 1;
    baseConditionMultiplier = 1;
    if (conditionIdx < 14)
    {
      for (int i = 0; i <= 13; i++)
      {
        v6 = GetConditionDayOfWeek(i);
        if ( v6 > conditionTimeMultiplier )
          conditionTimeMultiplier = v6;
      }
    }
  }
  result = (int)((double)conditionTimeMultiplier * (double)baseConditionMultiplier * a2);
  if ( result < 1 )
    result = 1;
  return result;
}

//----- (004B8102) --------------------------------------------------------
int Player::GetPriceSell(int uRealValue, float price_multiplier)
{
  signed int v3; // esi@1
  signed int result; // eax@3

  v3 = (signed int)((signed __int64)((double)uRealValue / (price_multiplier + 2.0)) + uRealValue * GetMerchant() / 100);
  if ( v3 > uRealValue )
    v3 = uRealValue;
  result = 1;
  if ( v3 >= 1 )
    result = v3;
  return result;
}

//----- (004B8142) --------------------------------------------------------
int Player::GetBuyingPrice(unsigned int uRealValue, float price_multiplier)
{
  uint price = (uint)(((100 - GetMerchant()) * (uRealValue * price_multiplier)) / 100);

  if (price < uRealValue)
    price = uRealValue;
  return price;
}

//----- (004B8179) --------------------------------------------------------
int Player::GetPriceIdentification(float a2)
{
  signed int v2; // esi@1
  int v3; // ecx@1
  signed int result; // eax@3

  v2 = (signed int)(a2 * 50.0);
  v3 = v2 * (100 - GetMerchant()) / 100;
  if ( v3 < v2 / 3 )
    v3 = v2 / 3;
  result = 1;
  if ( v3 >= 1 )
    result = v3;
  return result;
}

//----- (004B81C3) --------------------------------------------------------
int Player::GetPriceRepair(int a2, float a3)
{
  signed int v3; // esi@1
  int v4; // ecx@1
  signed int result; // eax@3

  v3 = (signed int)((double)a2 / (6.0 - a3));
  v4 = v3 * (100 - GetMerchant()) / 100;
  if ( v4 < v3 / 3 )
    v4 = v3 / 3;
  result = 1;
  if ( v4 >= 1 )
    result = v4;
  return result;
}

//----- (004B8213) --------------------------------------------------------
int Player::GetBaseSellingPrice(int a2, float a3)
{
  signed int v3; // qax@1

  v3 = (signed int)((double)a2 / (a3 + 2.0));
  if ( v3 < 1 )
    v3 = 1;
  return v3;
}

//----- (004B8233) --------------------------------------------------------
int Player::GetBaseBuyingPrice(int a2, float a3)
{
  signed int v3; // qax@1

  v3 = (signed int)((double)a2 * a3);
  if ( v3 < 1 )
    v3 = 1;
  return v3;
}

//----- (004B824B) --------------------------------------------------------
int Player::GetBaseIdentifyPrice(float a2)
{
  signed int v2; // qax@1

  v2 = (signed int)(a2 * 50.0);
  if ( v2 < 1 )
    v2 = 1;
  return v2;
}

//----- (004B8265) --------------------------------------------------------
int Player::GetBaseRepairPrice(int a2, float a3)
{
  signed int v3; // qax@1

  v3 = (signed int)((double)a2 / (6.0 - a3));
  if ( v3 < 1 )
    v3 = 1;
  return v3;
}





//----- (004B6FF9) --------------------------------------------------------
bool Player::IsPlayerHealableByTemple()
{
  signed int v2; // eax@1
  v2 = (signed int)window_SpeakInHouse->ptr_1C;
  if (this->sHealth >= GetMaxHealth() && this->sMana >= GetMaxMana() && GetMajorConditionIdx() == Condition_Good)
  {
    return false;
  }
  else
  {
    if (GetMajorConditionIdx() == Condition_Zombie)
    {
      if ((v2 == 78 || v2 == 81 || v2 == 82))
      {
        return false;
      }
      else
      {
        return true;
      }
    }
    else
    {
      return true;
    }
  }
}



//----- (00421E75) --------------------------------------------------------
unsigned int Player::GetItemIDAtInventoryIndex(int *pitem_index)
{
  int item_idx; // eax@1
  int inv_index; // eax@3


  item_idx = *pitem_index;
  if ( item_idx >125 || item_idx < 0 )
  {
    return 0;
  }
  
    inv_index = this->pInventoryMatrix[item_idx];
    if ( inv_index < 0 )
    {
      *pitem_index = -1 - inv_index;
      inv_index = this->pInventoryMatrix[-1 - inv_index];
    }

  return inv_index;
}



//----- (004160CA) --------------------------------------------------------
void Player::ItemsEnchant( int enchant_count )
    {
  int avalible_items; // ebx@1
  int i; // edx@8
  __int16 item_index_tabl[138]; // [sp+Ch] [bp-118h]@1
 
  avalible_items = 0;
  memset (item_index_tabl,0,sizeof(item_index_tabl));

  for (i = 0; i < 138; ++i)
  {
    if (( pOwnItems[i].uItemID>0)&&(pOwnItems[i].uItemID <= 134))
      item_index_tabl[avalible_items++] = i;
  }

  if ( avalible_items )
  {
    if ( enchant_count )
    {
      for ( i = 0; i < enchant_count; ++i )
      {
        if (!(pInventoryItemList[item_index_tabl[i]].uAttributes&ITEM_ENCHANTED))
          pInventoryItemList[item_index_tabl[rand() % avalible_items]].uAttributes |= ITEM_ENCHANTED; 
      }
    }
    else
    {
      for ( i = 0; i < avalible_items; ++i )
      {
          pInventoryItemList[item_index_tabl[i]].uAttributes |= ITEM_ENCHANTED;
      }
    }
  }
}

//----- (004948B1) --------------------------------------------------------
void Player::PlaySound(PlayerSpeech speech, int a3)
{
  signed int speechCount = 0; // esi@4
  signed int expressionCount = 0; // esi@4
  int pickedVariant; // esi@10
  CHARACTER_EXPRESSION_ID expression; // ebx@17
  signed int pSoundID; // ecx@19
  int speechVariantArray[5]; // [sp+Ch] [bp-1Ch]@7
  int expressionVariantArray[5]; 
  unsigned int pickedSoundID; // [sp+30h] [bp+8h]@4
  unsigned int expressionDuration = 0;

  pickedSoundID = 0;
  if (uVoicesVolumeMultiplier)
  {
    for (int i = 0; i < 2; i++)
    {
      if ( SoundSetAction[speech][i] )
      {
        speechVariantArray[speechCount] = SoundSetAction[speech][i];
        speechCount++;
      }
    }
    if ( speechCount )
    {
      pickedVariant = speechVariantArray[rand() % speechCount];
      int numberOfSubvariants = byte_4ECF08[pickedVariant - 1][uVoiceID];
      if (numberOfSubvariants > 0)
      {
        pickedSoundID = rand() % numberOfSubvariants + 2 * (pickedVariant + 50 * uVoiceID) + 4998;
        pAudioPlayer->PlaySound((SoundID)pickedSoundID, PID(OBJECT_Player, uActiveCharacter + 39), 0, -1, 0, 0, (int)(pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f), 0);
      }
    }
  }

  for (int i = 0; i < 5; i++)
  {
    if ( SoundSetAction[speech][i + 3] )
    {
      expressionVariantArray[expressionCount] = SoundSetAction[speech][i + 3];
      expressionCount++;
    }
  }
  if ( expressionCount )
  {
    expression = (CHARACTER_EXPRESSION_ID)expressionVariantArray[rand() % expressionCount];
    if (expression == CHARACTER_EXPRESSION_21 && pickedSoundID )
    {
      pSoundID = 0;
      if ( pSoundList->sNumSounds )
      {
        for (int i = 0; i < pSoundList->sNumSounds; i++)
        {
          if (pSoundList->pSounds[i].uSoundID == pickedSoundID)
            pSoundID = i;
        }
      }
      if ( pSoundList->pSounds[pSoundID].pSoundData[0] )
        expressionDuration = (sLastTrackLengthMS << 7) / 1000;
    }
    PlayEmotion(expression, expressionDuration);
  }
}
// 4948B1: using guessed type int var_1C[5];

//----- (00494A25) --------------------------------------------------------
void Player::PlayEmotion(CHARACTER_EXPRESSION_ID new_expression, int a3)
{
  unsigned int v3 = expression;
  if (expression == CHARACTER_EXPRESSION_DEAD || expression == CHARACTER_EXPRESSION_ERADICATED)
  {
    return;
  }
  else if (expression == CHARACTER_EXPRESSION_PERTIFIED && new_expression != CHARACTER_EXPRESSION_FALLING)
  {
    return;
  }
  else 
  {
    if (expression != CHARACTER_EXPRESSION_SLEEP || new_expression != CHARACTER_EXPRESSION_FALLING)
    {
      if (v3 >= 2 && v3 <= 11 && v3 != 8 && !(new_expression == CHARACTER_EXPRESSION_DMGRECVD_MINOR || new_expression == CHARACTER_EXPRESSION_DMGRECVD_MODERATE || new_expression == CHARACTER_EXPRESSION_DMGRECVD_MAJOR))
      {
        return;
      }
    }
  }
  this->uExpressionTimePassed = 0;
  if ( !a3 )
  {
    this->uExpressionTimeLength = 8 * pPlayerFrameTable->pFrames[a3].uAnimLength;
  }
  else
  {
    this->uExpressionTimeLength = 0;
  }
  expression = new_expression;
  viewparams->bRedrawGameUI = 1;
}

//----- (0049327B) --------------------------------------------------------
bool Player::ProfessionOrGuildFlagsCorrect( unsigned int uClass, int a3 )
{
  if ( this->classType == uClass )
  {
    return true;
  }
  else
  {
    if (!a3)
    {
      return false;
    }
    switch ( uClass )
    {
      case 0x1Au:
        return(_449B57_test_bit((unsigned __int8 *)this->_achieved_awards_bits, 65));
      case 0x1Bu:
        return(_449B57_test_bit((unsigned __int8 *)this->_achieved_awards_bits, 67));
      case 0x22u:
        return(_449B57_test_bit((unsigned __int8 *)this->_achieved_awards_bits, 77));
      case 0x23u:
        return(_449B57_test_bit((unsigned __int8 *)this->_achieved_awards_bits, 79));
        break;
      default:
        Error("Should not be able to get here (%u)", uClass);
        break;
    }
    return false;
  }
}


//----- (00492C0B) --------------------------------------------------------
bool Player::CanAct()
{
  if ( this->IsAsleep() || this->IsParalyzed() || 
       this->IsUnconcious() || this->IsDead() || 
       this->IsPertified() || this->IsEradicated() )
    return false;
  else
    return true;
}

//----- (00492C40) --------------------------------------------------------
bool Player::CanSteal()
{
  return GetActualSkillLevel(PLAYER_SKILL_STEALING) != 0;
}

//----- (00492C4E) --------------------------------------------------------
bool Player::CanEquip_RaceAndAlignmentCheck(unsigned int uItemID)
{
  switch (uItemID)
  {
  case ITEM_RELIC_ETHRICS_STAFF: 
  case ITEM_RELIC_OLD_NICK: 
  case ITEM_RELIC_TWILIGHT: return pParty->IsPartyEvil(); break;
  case ITEM_RELIC_TALEDONS_HELM: 
  case ITEM_RELIC_JUSTICE: return pParty->IsPartyGood(); break;
  case ITEM_ARTIFACT_ELFBANE: return IsRaceGoblin(); break;
  case ITEM_ARTIFACT_MINDS_EYE: return IsRaceHuman(); break;
  case ITEM_ELVEN_CHAINMAIL: return IsRaceElf(); break;
  case ITEM_FORGE_GAUNTLETS: return IsRaceDwarf(); break;
  case ITEM_ARTIFACT_HEROS_BELT: return IsMale(); break;
  case ITEM_ARTIFACT_LADYS_ESCORT: return IsFemale(); break;
  case ITEM_WETSUIT: return NothingOrJustBlastersEquipped(); break;
  default: return 1; break;
  }
}

//----- (00492D65) --------------------------------------------------------
void Player::SetCondition( unsigned int uConditionIdx, int a3 )
{
  signed int player_sex; // ecx@77
  signed int remainig_player; // ebx@82
  int players_before; // [sp+10h] [bp-4h]@2
  int players_after; // [sp+20h] [bp+Ch]@82

  if ( pConditions[uConditionIdx] )
      return;
  
  if (!ConditionProcessor::IsPlayerAffected(this, uConditionIdx, a3))
  {
    return;
  }

  switch ( uConditionIdx )
  {
    case Condition_Cursed: PlaySound(SPEECH_30, 0); break;
    case Condition_Weak: PlaySound(SPEECH_25, 0); break;
    case Condition_Sleep: break; //nosound
    case Condition_Fear: PlaySound(SPEECH_26, 0); break;
    case Condition_Drunk: PlaySound(SPEECH_31, 0); break;
    case Condition_Insane: PlaySound(SPEECH_29, 0); break;
    case Condition_Poison1:
    case Condition_Poison2:
    case Condition_Poison3: PlaySound(SPEECH_27, 0); break;
    case Condition_Disease1:
    case Condition_Disease2:
    case Condition_Disease3: PlaySound(SPEECH_28, 0);break;
    case Condition_Paralyzed: break;  //nosound
    case Condition_Unconcious:
      PlaySound(SPEECH_32, 0);
      if ( sHealth > 0 )
        sHealth = 0;
    break;
    case Condition_Dead:
      PlaySound(SPEECH_33, 0);
      if ( sHealth > 0 )
        sHealth = 0;
      if ( sMana > 0 )
        sMana = 0;
    break;
    case Condition_Pertified:
      PlaySound(SPEECH_34, 0);
    break;
    case Condition_Eradicated:
      PlaySound(SPEECH_35, 0);
      if (sHealth > 0 )
        sHealth = 0;
      if ( sMana > 0 )
        sMana = 0;
    break;
    case Condition_Zombie:
      if ( classType == PLAYER_CLASS_LICH || IsEradicated() || IsZombie() || !IsDead())
        return;
      memset(&pConditions[0], 0, sizeof(pConditions));
      sHealth = GetMaxHealth();
      sMana = 0;
      player_sex = 0;
      uPrevFace = uCurrentFace;
      uPrevVoiceID = uVoiceID;
      if (IsMale())
      {
        uCurrentFace = 23;
        uVoiceID = 23;
      }
      else
      {
        uCurrentFace = 24;
        uVoiceID = 24;
      }
      PlaySound(SPEECH_99, 0);
    break;
  }

  players_before = 0;
  for (int i = 1; i < 5; ++i)
  {
    if ( pPlayers[i]->CanAct() )
      ++players_before;
  }

  pConditions[uConditionIdx] = 1;

  remainig_player = 0;
  players_after = 0;
  for (int i = 1; i < 5; ++i)
  {
    if ( pPlayers[i]->CanAct() )
    {
      remainig_player = i;
      ++players_after;
    }
  }
  if (( players_before == 2 ) && ( players_after == 1 ))
  {
    pPlayers[remainig_player]->PlaySound(SPEECH_107, 0);
  }
  return;
}

//----- (00492528) --------------------------------------------------------
bool Player::CanFitItem(unsigned int uSlot, unsigned int uItemID)
{
  Texture *texture; // esi@1
  unsigned int slotWidth; // ebx@1
  unsigned int slotHeight; // [sp+1Ch] [bp+Ch]@1

  texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
  slotWidth = GetSizeInInventorySlots(texture->uTextureWidth);
  slotHeight = GetSizeInInventorySlots(texture->uTextureHeight);
  if ( !areWeLoadingTexture )
  {
    texture->Release();
    pIcons_LOD->SyncLoadedFilesCount();
  }
  Assert(slotHeight > 0 && slotWidth > 0, "Items should have nonzero dimensions");
  if ( (slotWidth + uSlot % INVETORYSLOTSWIDTH) <= INVETORYSLOTSWIDTH && (slotHeight + uSlot / INVETORYSLOTSWIDTH) <= INVETORYSLOTSHEIGHT )
  {
      for (unsigned int x = 0; x < slotWidth; x++)
      {
        for (unsigned int y = 0; y < slotHeight; y++)
        {
          if (pInventoryMatrix[y * INVETORYSLOTSWIDTH + x + uSlot] != 0)
          {
            return false;
          }
        }
      }
    return true;
  }
  return false;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (004925E6) --------------------------------------------------------
int Player::FindFreeInventoryListSlot()
{
  for (int i = 0; i < 126; i++ )
  {
    if (pInventoryItemList[i].uItemID == 0)
    {
      return i;
    }
  }
  return -1;
}

//----- (00492600) --------------------------------------------------------
int Player::CreateItemInInventory(unsigned int uSlot, unsigned int uItemID)
{
  int result; // eax@8
  signed int freeSlot; // [sp+8h] [bp-4h]@4

  freeSlot = FindFreeInventoryListSlot();
  if ( freeSlot == -1 )
  {
    if ( uActiveCharacter )
      pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
    return 0;
  }
  else
  {
    PutItemArInventoryIndex(uItemID, freeSlot, uSlot);
    result = freeSlot + 1;
    this->pInventoryItemList[freeSlot].uItemID = uItemID;
  }
  return result;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (00492700) --------------------------------------------------------
int Player::HasSkill(unsigned int uSkillType)
{
  if ( uSkillType >= 37 || this->pActiveSkills[uSkillType] )
  {
    return 1;
  }
  else
  {
    sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[67], this->pName);
    ShowStatusBarString(pTmpBuf.data(), 2u);
    return 0;
  }
}

//----- (00492745) --------------------------------------------------------
void Player::WearItem( unsigned int uItemID )
{
  int item_body_anch; // edi@6
  int item_indx;
  item_indx = FindFreeInventoryListSlot();
  
  if ( item_indx != -1 )
  {
    pInventoryItemList[item_indx].uItemID = uItemID;
    item_body_anch = pEquipTypeToBodyAnchor[pItemsTable->pItems[uItemID].uEquipType];
    pEquipment.pIndices[item_body_anch] = item_indx + 1;
    pInventoryItemList[item_indx].uBodyAnchor = item_body_anch + 1;
  }
}

//----- (004927A8) --------------------------------------------------------
int Player::AddItem(int index, unsigned int uItemID)
{
  int xStartValue = 0;

  if ( index == -1 )
  {
      for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
      {
        for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)
        {
          if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID) )
          {
            return CreateItemInInventory(ycoord * INVETORYSLOTSWIDTH + xcoord, uItemID);
          }
        }
      }
    return 0;
  }
  if ( !CanFitItem(index, uItemID) )
  {
    pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
    return 0;
  }
  return CreateItemInInventory(index, uItemID);
}

//----- (00492826) --------------------------------------------------------
int Player::AddItem2(int index, ItemGen *Src)
{
  pItemsTable->SetSpecialBonus(Src);

  if ( index == -1 )
  {
    for (int xcoord = 0; xcoord < INVETORYSLOTSWIDTH; xcoord++)
    {
      for (int ycoord = 0; ycoord < INVETORYSLOTSHEIGHT; ycoord++)      //TODO: change pInventoryMatrix to 2 dimensional array.
      {
        if ( CanFitItem(ycoord * INVETORYSLOTSWIDTH + xcoord, Src->uItemID) )
        {
          return CreateItemInInventory2(ycoord * INVETORYSLOTSWIDTH + xcoord, Src);
        }
      }
    }
    return 0;
  }
  if ( !CanFitItem(index, Src->uItemID) )
    return 0;
  return CreateItemInInventory2(index, Src);
}

//----- (0049289C) --------------------------------------------------------
int Player::CreateItemInInventory2( unsigned int index, ItemGen *Src )
{
  signed int freeSlot; // ebx@1
  int result; // eax@6

  freeSlot = FindFreeInventoryListSlot();
  if ( freeSlot == -1 )
  {
    result = 0;
  }
  else
  {
    PutItemArInventoryIndex(Src->uItemID, freeSlot, index);
    memcpy(&pInventoryItemList[freeSlot], Src, sizeof(ItemGen));
    result = freeSlot + 1;
  }
  return result;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (0049298B) --------------------------------------------------------
void Player::PutItemArInventoryIndex( int uItemID, int itemListPos, int index )   //originally accepted ItemGen* but needed only its uItemID
{
  Texture *item_texture; // esi@1
  int *pInvPos; // esi@4
  unsigned int slot_width; // [sp+Ch] [bp-4h]@1
  unsigned int slot_height; // [sp+18h] [bp+8h]@1

  item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
  slot_width =  GetSizeInInventorySlots(item_texture->uTextureWidth);
  slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight);
  if ( !areWeLoadingTexture )
  {
    item_texture->Release();
    pIcons_LOD->SyncLoadedFilesCount();
  }
  if ( slot_width > 0 )
  {
    pInvPos = &pInventoryMatrix[index];
    for (unsigned int i = 0; i < slot_height; i++)
    {
      memset32(pInvPos, -1 - index, slot_width);//TODO: try to come up with a better solution. negative values are used when drawing the inventory - nothing is drawn
      pInvPos += INVETORYSLOTSWIDTH;
    }
  }
  pInventoryMatrix[index] = itemListPos + 1;
}

// 506128: using guessed type int areWeLoadingTexture;

//----- (00492A36) --------------------------------------------------------
void Player::RemoveItemAtInventoryIndex( unsigned int index )
{
  ItemGen *item_in_slot; // ecx@1
  Texture *item_texture; // esi@1
  unsigned int slot_height; // ebp@1
  int *pInvPos; // edx@4
  unsigned int slot_width; // [sp+14h] [bp+4h]@1

  item_in_slot = &this->pInventoryItemList[pInventoryMatrix[index]-1];  
  item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[item_in_slot->uItemID].pIconName, TEXTURE_16BIT_PALETTE);
  item_in_slot->Reset();
  slot_width = GetSizeInInventorySlots(item_texture->uTextureWidth);
  slot_height = GetSizeInInventorySlots(item_texture->uTextureHeight);
  if ( !areWeLoadingTexture )
  {
    item_texture->Release();
    pIcons_LOD->SyncLoadedFilesCount();
  }
  if ( slot_width > 0 )
  {
    pInvPos = &pInventoryMatrix[index];
    for (unsigned int i = 0; i < slot_height; i++)
    {
      memset32(pInvPos, 0, slot_width);
      pInvPos += INVETORYSLOTSWIDTH;
    }
  }
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (00490EEE) --------------------------------------------------------
int Player::SelectPhrasesTransaction(ItemGen *pItem, int building_type, int BuildID_2Events, int ShopMenuType)  //TODO: probably move this somewhere else, not really Player:: stuff
{
  unsigned int idemId; // edx@1
  signed int equipType; // esi@1
  float multiplier; // ST04_4@26
  int price; // edi@26
  int merchantLevel; // [sp+10h] [bp-8h]@1
  int itemValue;

  merchantLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
  idemId = pItem->uItemID;
  equipType = pItemsTable->pItems[idemId].uEquipType;
  itemValue = pItem->GetValue();

  switch (building_type)
  {
    case BuildingType_WeaponShop:
      if (idemId >= ITEM_ARTIFACT_HERMES_SANDALS)
        return 5;
      if (equipType > EQUIP_BOW)
        return 4;
    break;
    case BuildingType_ArmorShop:
      if (idemId >= ITEM_ARTIFACT_HERMES_SANDALS)
        return 5;
      if ( equipType < EQUIP_ARMOUR || equipType > EQUIP_BOOTS)
        return 4;
    break;
    case BuildingType_MagicShop:
      if (idemId >= ITEM_ARTIFACT_HERMES_SANDALS)
        return 5;
      if ( pItemsTable->pItems[idemId].uSkillType != PLAYER_SKILL_MISC )
        return 4;
    break;
    case BuildingType_AlchemistShop:
      if ((idemId >= ITEM_ARTIFACT_HERMES_SANDALS && idemId < ITEM_RECIPE_REJUVENATION) || idemId > ITEM_RECIPE_BODY_RESISTANCE)
        return 5;
      if ( !(equipType == EQUIP_REAGENT || equipType == EQUIP_POTION || equipType == EQUIP_MESSAGE_SCROLL))
        return 4;
    break;
    default:
      Error("(%u)", building_type);
    break;
  }
  if (pItem->IsStolen())
    return 6;

  multiplier = p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
  switch (ShopMenuType)
  {
    case 2:
      price = GetBuyingPrice(itemValue, multiplier);
    break;
    case 3:
      if (pItem->IsBroken())
        price = 1;
      else
        price = this->GetPriceSell(itemValue, multiplier);
    break;
    case 4:
      price = this->GetPriceIdentification(multiplier);
    break;
    case 5:
      price = this->GetPriceRepair(itemValue, multiplier);
      break;
    default:
      Error("(%u)", ShopMenuType);
    break;
  }
  if ( merchantLevel )
  {
    if (price == itemValue)
    {
      return 3;
    }
    else
    {
      return 2;
    }
  }
  else
  {
    return 1;
  }
}

//----- (0049107D) --------------------------------------------------------
int Player::GetBodybuilding()
{
  int v1; // al@1

  v1 = GetActualSkillLevel(PLAYER_SKILL_BODYBUILDING);
  int multiplier = GetMultiplierForSkillLevel(v1, 1, 2, 3, 5);
  return multiplier * (v1 & 0x3F);
}

//----- (004910A8) --------------------------------------------------------
int Player::GetMeditation()
{
  int v1; // al@1

  v1 = GetActualSkillLevel(PLAYER_SKILL_MEDITATION);
  int multiplier = GetMultiplierForSkillLevel(v1, 1, 2, 3, 5);
  return multiplier * (v1 & 0x3F);
}

//----- (004910D3) --------------------------------------------------------
bool Player::CanIdentify( ItemGen *pItem )
{
  unsigned __int16 v2; // ax@1
  int v5; // edi@7
  return true;
  if (CheckHiredNPCSpeciality(Scholar))
    return true;

  v2 = GetActualSkillLevel(PLAYER_SKILL_ITEM_ID);
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return true;

  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  v5 = multiplier * (v2 & 0x3F);
  return v5 >= pItemsTable->pItems[pItem->uItemID].uItemID_Rep_St;
}

//----- (00491151) --------------------------------------------------------
bool Player::CanRepair( ItemGen *pItem )
{
  unsigned __int16 v2; // ax@1
  int v5; // edi@7

  ItemDesc* v7 = &pItemsTable->pItems[pItem->uItemID];
  if (CheckHiredNPCSpeciality(Smith) && v7->uEquipType <= 2 ||
      CheckHiredNPCSpeciality(Armorer) && v7->uEquipType >= 3 && v7->uEquipType <= 9 ||
      CheckHiredNPCSpeciality(Alchemist) && v7->uEquipType >= 9 )
    return true;

  v2 = GetActualSkillLevel(PLAYER_SKILL_REPAIR);
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return true;

  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  v5 = multiplier * (v2 & 0x3F);
  return v5 >= v7->uItemID_Rep_St;
}

//----- (004911F3) --------------------------------------------------------
int Player::GetMerchant()
{
  unsigned __int16 v2; // ax@1
  int v5; // edi@1
  int v7; // eax@3

  v2 = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
  if ( SkillToMastery(v2) >= 4 )
    return 10000;

  v7 = GetPartyReputation();
  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  v5 = multiplier * (v2 & 0x3F);
  if (v5 == 0)
  {
    return -v7;
  }
  return v5 - v7 + 7;
}

//----- (0049125A) --------------------------------------------------------
int Player::GetPerception()
{
  unsigned __int16 v2; // ax@1
  int v5; // edi@1

  v2 = GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
  if ( SkillToMastery(v2) >= 4 )
    return 10000;

  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  v5 = multiplier * (v2 & 0x3F);
  return v5;
}

//----- (004912B0) --------------------------------------------------------
int Player::GetDisarmTrap()
{
  unsigned __int16 v2; // ax@1
  int v5; // edi@1

  v2 = GetActualSkillLevel(PLAYER_SKILL_TRAP_DISARM);
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return 10000;

  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  if ( HasEnchantedItemEquipped(35) )  //only the real skill level is supposed to be added again, not the multiplied value
    multiplier++;
  v5 = multiplier * (v2 & 0x3F);
  return v5;
}

//----- (00491317) --------------------------------------------------------
char Player::GetLearningPercent()
{
  int v2; // eax@1

  v2 = GetActualSkillLevel(PLAYER_SKILL_LEARNING);
  int multiplier = GetMultiplierForSkillLevel(v2, 1, 2, 3, 5);
  return multiplier * v2 + 9;
}

//----- (0048C6AF) --------------------------------------------------------
Player::Player()
{  
  memset(&pEquipment, 0, sizeof(PlayerEquipment));
  memset(pInventoryMatrix, 0, 126 * sizeof(int));
  for (uint i = 0; i < 126; ++i)
    pInventoryItemList[i].Reset();
  for (uint i = 0; i < 12; ++i)
    pEquippedItems[i].Reset();


  for (uint i = 0; i < 24; ++i)
  {
    pPlayerBuffs[i].uSkill = 0;
    pPlayerBuffs[i].uSkill = 0;
    pPlayerBuffs[i].uPower = 0;
    pPlayerBuffs[i].uExpireTime = 0;
    pPlayerBuffs[i].uCaster = 0;
    pPlayerBuffs[i].uFlags = 0;
  }

  pName[0] = 0;
  uCurrentFace = 0;
  uVoiceID = 0;
  memset(pConditions, 0, 20 * sizeof(__int64));

  field_BB = 0;

  uMight = uMightBonus = 0;
  uIntelligence = uIntelligenceBonus = 0;
  uWillpower = uWillpowerBonus = 0;
  uEndurance = uEnduranceBonus = 0;
  uSpeed = uSpeedBonus = 0;
  uAccuracy = uAccuracyBonus = 0;
  uLuck = uLuckBonus = 0;
  uLevel = sLevelModifier = 0;
  sAgeModifier = 0;
  sACModifier = 0;

//  memset(field_1F5, 0, 30);
  pure_luck_used=0;      
  pure_speed_used=0; 
  pure_intellect_used=0;  
  pure_endurance_used=0;  
  pure_willpower_used=0;       
  pure_accuracy_used=0;      
  pure_might_used=0;  

  sResFireBase = sResFireBonus = 0;
  sResAirBase = sResAirBonus = 0;
  sResWaterBase = sResWaterBonus = 0;
  sResEarthBase = sResEarthBonus = 0;
  sResMagicBase = sResMagicBonus = 0;
  sResSpiritBase = sResSpiritBonus = 0;
  sResMindBase = sResMindBonus = 0;
  sResBodyBase = sResBodyBonus = 0;
  sResLightBase = sResLightBonus = 0;
  sResDarkBase = sResDarkBonus = 0;

  uTimeToRecovery = 0;

  uSkillPoints = 0;

  sHealth = 0;
  uFullHealthBonus = 0;
  _health_related = 0;

  sMana = 0;
  uFullManaBonus = 0;
  _mana_related = 0;

  uQuickSpell = 0;
  memset(pInstalledBeacons, 0, 5 * sizeof(LloydBeacon));

  _some_attack_bonus = 0;
  field_1A91 = 0;
  _melee_dmg_bonus = 0;
  field_1A93 = 0;
  _ranged_atk_bonus = 0;
  field_1A95 = 0;
  _ranged_dmg_bonus = 0;
  field_1A97 = 0;

  expression = CHARACTER_EXPRESSION_INVALID;
  uExpressionTimePassed = 0;
  uExpressionTimeLength = 0;

  uNumDivineInterventionCastsThisDay = 0;
  uNumArmageddonCasts = 0;
  uNumFireSpikeCasts = 0;

  memset(field_1988, 0, 49 * sizeof(int));
  memset(field_1A50, 0, 64 * sizeof(char));

  field_E0 = 0;
  field_E4 = 0;
  field_E8 = 0;
  field_EC = 0;
  field_F0 = 0;
  field_F4 = 0;
  field_F8 = 0;
  field_FC = 0;
  field_100 = 0;
  field_104 = 0;

  _expression21_animtime = 0;
  _expression21_frameset = 0;

  lastOpenedSpellbookPage = 0;
}

//----- (0048C6F6) --------------------------------------------------------
bool Party::AddItemToParty(ItemGen *pItem)      //TODO move to party.cpp
{
  unsigned int v2; // eax@1
  char *v5; // eax@8
  Texture *v7; // ebx@10
  signed int v8; // esi@10
  Player *v9; // edi@11
  int v10; // eax@11
  int v21; // [sp+24h] [bp-4h]@10

  v2 = pItem->uItemID;
  if ( !pItemsTable->pItems[v2].uItemID_Rep_St )
    pItem->SetIdentified();

  v5 = pItemsTable->pItems[v2].pIconName;
  if ( v5 )
  {
    v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
    v21 = areWeLoadingTexture;
    v8 = 0;
    int startId = uActiveCharacter >= 0 ? uActiveCharacter - 1 : 0;
    for (int i = 0; i < 4; i++)
    {
      v9 = &pPlayers[(startId + i) % 4];  //start with current active player, then cycle right if item won't fit
      v10 = v9->AddItem(-1, pItem->uItemID);
      if ( v10 )
      {
        memcpy(&v9->pInventoryItemList[v10-1], pItem, 0x24u);
        pItem->Reset();
        pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
        v9->PlaySound(SPEECH_60, 0);
        if ( !v21 )
        {
          v7->Release();
          pIcons_LOD->SyncLoadedFilesCount();
        }
        return true;
      }
    }
    if ( !v21 )
    {
      v7->Release();
      pIcons_LOD->SyncLoadedFilesCount();
    }
    return false;
  }
  else
  {
    MessageBoxW(nullptr, L"Invalid picture_name detected ::addItem()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Party.cpp:795", 0);
    return false;
  }
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (0048C855) --------------------------------------------------------
int Player::GetBaseStrength()
{
  return this->uMight + GetItemsBonus(CHARACTER_ATTRIBUTE_STRENGTH);
}

//----- (0048C86C) --------------------------------------------------------
int Player::GetBaseIntelligence()
{
  return this->uIntelligence + GetItemsBonus(CHARACTER_ATTRIBUTE_INTELLIGENCE);
}

//----- (0048C883) --------------------------------------------------------
int Player::GetBaseWillpower()
{
  return this->uWillpower + GetItemsBonus(CHARACTER_ATTRIBUTE_WILLPOWER);
}

//----- (0048C89A) --------------------------------------------------------
int Player::GetBaseEndurance()
{
  return this->uEndurance + GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE);
}

//----- (0048C8B1) --------------------------------------------------------
int Player::GetBaseAccuracy()
{
  return this->uAccuracy + GetItemsBonus(CHARACTER_ATTRIBUTE_ACCURACY);
}

//----- (0048C8C8) --------------------------------------------------------
int Player::GetBaseSpeed()
{
  return this->uSpeed + GetItemsBonus(CHARACTER_ATTRIBUTE_SPEED);
}

//----- (0048C8DF) --------------------------------------------------------
int Player::GetBaseLuck()
{
  return this->uLuck + GetItemsBonus(CHARACTER_ATTRIBUTE_LUCK);
}

//----- (0048C8F6) --------------------------------------------------------
int Player::GetBaseLevel()
{
  return this->uLevel + GetItemsBonus(CHARACTER_ATTRIBUTE_LEVEL);
}

//----- (0048C90D) --------------------------------------------------------
int Player::GetActualLevel()
{
  return uLevel + sLevelModifier +
         GetMagicalBonus(CHARACTER_ATTRIBUTE_LEVEL) +
         GetItemsBonus(CHARACTER_ATTRIBUTE_LEVEL);
}

//----- (0048C93C) --------------------------------------------------------
int Player::GetActualMight()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_STRENGTH, &Player::uMight, &Player::uMightBonus);
}

//----- (0048C9C2) --------------------------------------------------------
int Player::GetActualIntelligence()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_INTELLIGENCE, &Player::uIntelligence, &Player::uIntelligenceBonus);
}

//----- (0048CA3F) --------------------------------------------------------
int Player::GetActualWillpower()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_WILLPOWER, &Player::uWillpower, &Player::uWillpowerBonus);
}

//----- (0048CABC) --------------------------------------------------------
int Player::GetActualEndurance()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_ENDURANCE, &Player::uEndurance, &Player::uEnduranceBonus);
}

//----- (0048CB39) --------------------------------------------------------
int Player::GetActualAccuracy()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_ACCURACY, &Player::uAccuracy, &Player::uAccuracyBonus);
}

//----- (0048CBB6) --------------------------------------------------------
int Player::GetActualSpeed()
{
  return GetActualAttribute(CHARACTER_ATTRIBUTE_SPEED, &Player::uSpeed, &Player::uSpeedBonus);
}

//----- (0048CC33) --------------------------------------------------------
int Player::GetActualLuck()
{
  signed int npc_luck_bonus; // [sp+10h] [bp-4h]@1

  npc_luck_bonus = 0;
  if ( CheckHiredNPCSpeciality(Fool) )
    npc_luck_bonus = 5;
  if ( CheckHiredNPCSpeciality(ChimneySweep) )
    npc_luck_bonus += 20;
  if ( CheckHiredNPCSpeciality(Psychic) )
    npc_luck_bonus += 10;

  return GetActualAttribute(CHARACTER_ATTRIBUTE_LUCK, &Player::uLuck, &Player::uLuckBonus)
       + npc_luck_bonus;
}

//----- (new function) --------------------------------------------------------
int Player::GetActualAttribute( CHARACTER_ATTRIBUTE_TYPE attrId, unsigned short Player::* attrValue, unsigned short Player::* attrBonus )
{
  uint uActualAge = this->sAgeModifier + GetBaseAge();
  uint uAgeingMultiplier = 100;
  for (uint i = 0; i < 4; ++i)
  {
    if (uActualAge >= pAgeingTable[i])
      uAgeingMultiplier = pAgingAttributeModifier[attrId][i];
    else 
      break;
  }

  auto uConditionMult = pConditionAttributeModifier[attrId][GetMajorConditionIdx()];
  int magicBonus = GetMagicalBonus(attrId);
  int itemBonus = GetItemsBonus(attrId);
  return uConditionMult * uAgeingMultiplier * this->*attrValue / 100 / 100
    + magicBonus
    + itemBonus
    + this->*attrBonus;
}

//----- (0048CCF5) --------------------------------------------------------
int Player::GetActualAttack(int a2)
{
  int v3; // eax@1
  int v4; // edi@1
  int v5; // ebx@1
  int v6; // ebp@1

  v3 = GetActualAccuracy();
  v4 = GetParameterBonus(v3);
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_ATTACK);
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_ATTACK, a2);
  return v4 + v5 + v6 + GetMagicalBonus(CHARACTER_ATTRIBUTE_ATTACK) + this->_some_attack_bonus;
}

//----- (0048CD45) --------------------------------------------------------
int Player::GetMeleeDamageMinimal()
{
  int v2; // eax@1
  int v3; // esi@1
  int v4; // esi@1
  int v5; // esi@1
  signed int result; // eax@1
 
  v2 = GetActualMight();
  v3 = GetParameterBonus(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v4;
  result = _melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v5;
  if ( result < 1 )
    result = 1;
  return result;
}

//----- (0048CD90) --------------------------------------------------------
int Player::GetMeleeDamageMaximal()
{
  int v2; // eax@1
  int v3; // esi@1
  int v4; // esi@1
  int v5; // esi@1
  int v6; // esi@1
  signed int result; // eax@1

  v2 = GetActualMight();
  v3 = GetParameterBonus(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v4;
  v6 = this->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v5;
  result = 1;
  if ( v6 >= 1 )
    result = v6;
  return result;
}

//----- (0048CDDB) --------------------------------------------------------
int Player::CalculateMeleeDamageTo( bool ignoreSkillBonus, bool ignoreOffhand, unsigned int uTargetActorID )
{
  int dmgSum; // esi@62
  signed int result; // eax@64
  int mainWpnDmg; // [sp+18h] [bp-8h]@1
  int offHndWpnDmg; // [sp+1Ch] [bp-4h]@1

  offHndWpnDmg = 0;
  mainWpnDmg = 0;
  if ( IsUnarmed() )
  {
    mainWpnDmg = rand() % 3 + 1;
  }
  else
  {
    if ( HasItemEquipped(EQUIP_MAIN_HAND) )
    {
      ItemGen *mainHandItemGen = &this->pInventoryItemList[this->pEquipment.uMainHand-1];
      int itemId = mainHandItemGen->uItemID;
      bool addOneDice = false;
      if ( pItemsTable->pItems[itemId].uSkillType == PLAYER_SKILL_SPEAR && !this->pEquipment.uShield )
        addOneDice = true;
      mainWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(mainHandItemGen, uTargetActorID, addOneDice);
    }
    if ( !ignoreOffhand )
    {
      if ( this->HasItemEquipped(EQUIP_OFF_HAND) )
      {
        ItemGen *offHandItemGen = (ItemGen *)&this->pInventoryItemList[this->pEquipment.uShield - 1];
        int itemId = offHandItemGen->uItemID;
        if ( pItemsTable->pItems[itemId].uEquipType != EQUIP_SHIELD )
        {
          offHndWpnDmg = CalculateMeleeDmgToEnemyWithWeapon(offHandItemGen, uTargetActorID, false);
        }
      }
    }
  }
  dmgSum = mainWpnDmg + offHndWpnDmg;
  if ( !ignoreSkillBonus )
  {
    int might = GetActualMight();
    int mightBonus = GetParameterBonus(might);
    int mightAndSkillbonus = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightBonus;
    dmgSum += this->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + mightAndSkillbonus;
  }
  result = 1;
  if ( dmgSum >= 1 )
    result = dmgSum;
  return result;
}


int Player::CalculateMeleeDmgToEnemyWithWeapon( ItemGen * weapon, unsigned int uTargetActorID , bool addOneDice )
{
  int itemId = weapon->uItemID;
  int diceCount = pItemsTable->pItems[itemId].uDamageDice;
  if (addOneDice)
  {
    diceCount++;
  }
  int diceSides = pItemsTable->pItems[itemId].uDamageRoll;
  int diceResult = 0;
  for (int i = 0; i < diceCount; i++)
  {
    diceResult += rand() % diceSides + 1;
  }
  int totalDmg = pItemsTable->pItems[itemId].uDamageMod + diceResult;
  if ( uTargetActorID > 0)
  {
    int enchType = weapon->uSpecEnchantmentType;
    if ( MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_UNDEAD) && (enchType == 64 || itemId == ITEM_ARTIFACT_GHOULSBANE || itemId == ITEM_ARTIFACT_GIBBET || itemId == ITEM_RELIC_JUSTICE) )
    {
      totalDmg *= 2;
    }
    else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_KREEGAN) && ( enchType == 39 || itemId == ITEM_ARTIFACT_GIBBET))
    {
      totalDmg *= 2;
    }
    else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_DRAGON) && ( enchType == 40 || itemId == ITEM_ARTIFACT_GIBBET))
    {
      totalDmg *= 2;
    }
    else if (MonsterStats::BelongsToSupertype(uTargetActorID, MONSTER_SUPERTYPE_TITAN) && ( enchType == 65 ))
    {
      totalDmg *= 2;
    }
  }
  if ( (signed int)SkillToMastery(this->pActiveSkills[2]) >= 3
    && pItemsTable->pItems[itemId].uSkillType == 2
    && rand() % 100 < 10 )
    totalDmg *= 3;
  return totalDmg;
}


//----- (0048D0B9) --------------------------------------------------------
int Player::GetRangedAttack()
{
  int v2; // eax@1
  int v3; // edi@3
  int v4; // eax@4
  int v5; // edi@4
  int v6; // edi@4
  int v7; // edi@4

  v2 = *(int *)&this->pInventoryItemList[this->pEquipment.uMainHand-1];
  if ( v2 < ITEM_BLASTER || v2 > ITEM_LASER_RIFLE )
  {
    v4 = GetActualAccuracy();
    v5 = GetParameterBonus(v4);
    v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v5;
    v7 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v6;
    v3 = this->_ranged_atk_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v7;
  }
  else
  {
    v3 = GetActualAttack(1);
  }
  return v3;
}

//----- (0048D124) --------------------------------------------------------
int Player::GetRangedDamageMin()
{
  int v2; // edi@1
  int v3; // edi@1
  int v4; // edi@1
  int result; // eax@6

  v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_MIN);
  v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v2;
  v4 = this->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
  if ( v4 >= 1 )
    result = v4;
  else
    result = 0;
  return result;
}

//----- (0048D191) --------------------------------------------------------
int Player::GetRangedDamageMax()
{
  int v2; // edi@1
  int v3; // edi@1
  int v4; // edi@1
  int result; // eax@6

  v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_MAX);
  v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v2;
  v4 = this->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS) + v3;
  if ( v4 >= 1 )
    result = v4;
  else
    result = 0;
  return result;
}

//----- (0048D1FE) --------------------------------------------------------
int Player::CalculateRangedDamageTo( int a2 )
{
  ItemGen *v4; // ebx@2
  unsigned int v5; // edi@2
  int v9; // esi@5
  int v10; // ebx@6
  signed int v15; // [sp+8h] [bp-Ch]@2
  int v17; // [sp+10h] [bp-4h]@1

  v17 = 0;
  if ( !HasItemEquipped(EQUIP_BOW) )
    return 0;
  v4 = (ItemGen *)&this->pInventoryItemList[this->pEquipment.uBow-1];
  v5 = v4->uItemID;
  v15 = pItemsTable->pItems[v5].uDamageRoll;
  for( int i = 0; i < pItemsTable->pItems[v5].uDamageDice; i++ )
  {
    int v7 = rand() % v15;
    v17 += v7 + 1;
  }
  v9 = pItemsTable->pItems[v5].uDamageMod + v17;
  if ( a2 )
  {
    v10 = v4->uSpecEnchantmentType;
    if ( v10 == 64 && MonsterStats::BelongsToSupertype(a2, MONSTER_SUPERTYPE_UNDEAD))
    {
      v9 *= 2;
    }
    else if ( v10 == 39 && MonsterStats::BelongsToSupertype(a2, MONSTER_SUPERTYPE_KREEGAN))
    {
      v9 *= 2;
    }
    else if ( v10 == 40 && MonsterStats::BelongsToSupertype(a2, MONSTER_SUPERTYPE_DRAGON))
    {
      v9 *= 2;
    }
    else if ( v10 == 63 && MonsterStats::BelongsToSupertype(a2, MONSTER_SUPERTYPE_ELF))
    {
      v9 *= 2;
    }
  }
  return v9 + this->GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS);
}

//----- (0048D2EA) --------------------------------------------------------
char *Player::GetMeleeDamageString()
{
  signed int itemid; // eax@1
  int min_damage; // edi@3
  int max_damage; // eax@3

  static char player__getmeleedamagestring_static_buff[40]; // idb

  if (pEquipment.uMainHand >= 0)
  {
    itemid = pOwnItems[this->pEquipment.uMainHand-1].uItemID;
  }

  if (pEquipment.uMainHand >= 0 && ( itemid >= 135 ) && ( itemid <= 159 ))
  {
    strcpy(player__getmeleedamagestring_static_buff, pGlobalTXT_LocalizationStrings[595]); //"Wand"
    return player__getmeleedamagestring_static_buff;
  }
  else if (pEquipment.uMainHand >= 0 && (itemid == ITEM_BLASTER || itemid == ITEM_LASER_RIFLE))
  {
    min_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, true);
    max_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, true);
  }
  else
  {
    min_damage = GetMeleeDamageMinimal();
    max_damage = GetMeleeDamageMaximal();
  }
  if ( min_damage == max_damage )
  {
    sprintf(player__getmeleedamagestring_static_buff, "%d", min_damage);
  }
  else
  {
    sprintf(player__getmeleedamagestring_static_buff, "%d - %d", min_damage, max_damage);
  }
  return player__getmeleedamagestring_static_buff;
}

//----- (0048D396) --------------------------------------------------------
char *Player::GetRangedDamageString()
{
    signed int itemid; // eax@1
    int min_damage; // edi@3
    int max_damage; // eax@3

    static char player__getrangeddamagestring_static_buff[40]; // idb

    if (pEquipment.uMainHand >= 0)
    {
      itemid = pOwnItems[this->pEquipment.uMainHand-1].uItemID;
    }

    if (pEquipment.uMainHand >= 0 && ( itemid >= 135 ) && ( itemid <= 159 ))
    {
      strcpy(player__getrangeddamagestring_static_buff, pGlobalTXT_LocalizationStrings[595]); //"Wand"
      return player__getrangeddamagestring_static_buff;
    }
    else if (pEquipment.uMainHand >= 0 && (itemid == ITEM_BLASTER || itemid == ITEM_LASER_RIFLE))
    {
      min_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, true);
      max_damage = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, true);
    }
    else
    {
      min_damage = GetRangedDamageMin();
      max_damage = GetRangedDamageMax();
    }
    if ( max_damage > 0)
    {
      if ( min_damage == max_damage )
      {
        sprintf(player__getrangeddamagestring_static_buff, "%d", min_damage);
      }
      else
      {
        sprintf(player__getrangeddamagestring_static_buff, "%d - %d", min_damage, max_damage);
      }
    }
    else
    {
      strcpy(player__getrangeddamagestring_static_buff, "N/A");
    }
    return player__getrangeddamagestring_static_buff;
}

//----- (0048D45A) --------------------------------------------------------
bool Player::CanTrainToNextLevel()
{
  int lvl = this->uLevel + 1;
  int neededExp = ((lvl * (lvl - 1)) / 2 * 1000);
  return this->uExperience >= neededExp;
}

//----- (0048D498) --------------------------------------------------------
unsigned int Player::GetExperienceDisplayColor()
{
  if ( CanTrainToNextLevel() )
    return ui_character_bonus_text_color;
  else
    return ui_character_default_text_color;
}

//----- (0048D4B3) --------------------------------------------------------
int Player::CalculateIncommingDamage( DAMAGE_TYPE dmg_type, int dmg )
{
  int resist_value; // edi@8
  int player_luck; // eax@21
  signed int res_rand_divider; // ebx@2
  int armor_skill; // eax@29

  if ( classType == PLAYER_CLASS_LICH && (dmg_type == CHARACTER_ATTRIBUTE_RESIST_MIND || dmg_type == CHARACTER_ATTRIBUTE_RESIST_BODY || dmg_type == CHARACTER_ATTRIBUTE_RESIST_SPIRIT )) //TODO: determine if spirit resistance should be handled by body res. modifier
    return 0;

  resist_value = 0;
  switch(dmg_type)
      {
      case DMGT_FIRE:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_FIRE); break;
      case DMGT_ELECTR: resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_AIR);  break;
      case DMGT_COLD:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_WATER); break;
      case DMGT_EARTH:  resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_EARTH); break;
      
      case DMGT_SPIRIT: resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_SPIRIT);break;
      case DMGT_MIND:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_MIND); break;
      case DMGT_BODY:   resist_value = GetActualResistance(CHARACTER_ATTRIBUTE_RESIST_BODY); break;
      }

  player_luck = GetActualLuck();
  res_rand_divider = GetParameterBonus(player_luck) + resist_value + 30;

  if ( GetParameterBonus(player_luck) + resist_value > 0 )
  { 
    for (int i = 0; i < 4; i++)
    {
      if ( rand() % res_rand_divider >= 30 )
        dmg >>= 1;
      else
        break;
    }
  }
  if (( dmg_type == DMGT_PHISYCAL ) && ( pEquipment.uArmor ))
  {
      if (!pOwnItems[pEquipment.uArmor - 1].IsBroken()) 
      {
        armor_skill = GetEquippedItemSkillType(EQUIP_ARMOUR);
        if ( armor_skill==PLAYER_SKILL_PLATE )
        {
          if ( SkillToMastery(pActiveSkills[PLAYER_SKILL_PLATE]) >= 3 )
              return dmg / 2;
        }
        if (armor_skill==PLAYER_SKILL_CHAIN )
        {
          if (SkillToMastery(pActiveSkills[PLAYER_SKILL_CHAIN]) == 4) 
             return dmg * 2 / 3;
        }
      }
  }
  return dmg;
}

//----- (0048D62C) --------------------------------------------------------
ITEM_EQUIP_TYPE Player::GetEquippedItemEquipType(ITEM_EQUIP_TYPE uEquipSlot)
{
  return pItemsTable->pItems[pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].uItemID].uEquipType;
}

//----- (0048D651) --------------------------------------------------------
PLAYER_SKILL_TYPE Player::GetEquippedItemSkillType(ITEM_EQUIP_TYPE uEquipSlot)
{
  return (PLAYER_SKILL_TYPE)pItemsTable->pItems[pInventoryItemList[pEquipment.pIndices[uEquipSlot] - 1].uItemID].uSkillType;
}

//----- (0048D676) --------------------------------------------------------
bool Player::IsUnarmed()
{
  return !HasItemEquipped(EQUIP_MAIN_HAND) &&
        (!HasItemEquipped(EQUIP_OFF_HAND) || GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD);
}

//----- (0048D6AA) --------------------------------------------------------
bool Player::HasItemEquipped(ITEM_EQUIP_TYPE uEquipIndex)
{
  auto i = pEquipment.pIndices[uEquipIndex];
  if (i)
    return (~(pOwnItems[i - 1].uAttributes & ITEM_BROKEN)) != 0;
  else 
    return false;
}

//----- (0048D6D0) --------------------------------------------------------
bool Player::HasEnchantedItemEquipped(int uEnchantment)
{
  for (uint i = 0; i < 16; ++i)
  {
    if (HasItemEquipped((ITEM_EQUIP_TYPE)i) &&
      pOwnItems[pEquipment.pIndices[i]-1].uSpecEnchantmentType == uEnchantment)
      return true;
  }
  return false;
}

//----- (0048D709) --------------------------------------------------------
bool Player::WearsItem( int item_id, ITEM_EQUIP_TYPE equip_type )
{
  return ( HasItemEquipped(equip_type) && pInventoryItemList[pEquipment.pIndices[equip_type - 1]].uItemID == item_id );
}

bool Player::WearsItemAnyWhere(int item_id)
{
  for (int i = 0; i < 16; i++)
  {
    if (WearsItem(item_id, (ITEM_EQUIP_TYPE) i))
    {
      return true;
    }
  }
  return false;
}

//----- (0048D76C) --------------------------------------------------------
bool Player::StealFromShop(ItemGen *itemToSteal, int a3, int reputation, int a5, int *a6)   //check stealing in IDA pro once I get home. The whole thing looks odd, dword_4EDEB4 and dword_4EDEA0 are never filled, might be a bug, might me on purpose
{
  unsigned __int16 v6; // cx@8
  int v7; // edi@8
  unsigned int v8; // ebx@8
  unsigned int itemvalue; // esi@8
  int v10; // eax@8
  int v11; // edi@12
  bool result; // eax@13

  if ( !itemToSteal
    || this->pConditions[16]
    || this->pConditions[14]
    || this->pConditions[15]
    || this->pConditions[4]
    || this->pConditions[13]
    || this->pConditions[2] )
  {
    result = 0;
  }
  else
  {
    v6 = this->pActiveSkills[34];
    v7 = v6 & 0x3F;
    v8 = SkillToMastery(v6);
    itemvalue = itemToSteal->GetValue();
    v10 = pItemsTable->pItems[itemToSteal->uItemID].uEquipType;
    if ( !pItemsTable->pItems[itemToSteal->uItemID].uEquipType || v10 == 1 || v10 == 2 )
      itemvalue *= 3;
    v11 = dword_4EDEB4[rand() % 100 / 20] + v7 * dword_4EDEA0[v8];
    *a6 = 100 * (reputation + a3) + itemvalue + (a5 != 0 ? 0x1F4 : 0);
    if ( rand() % 100 >= 5 )
    {
      if ( *a6 > v11 )
        result = *a6 - v11 < 500;
      else
        result = 2;
    }
    else
    {
      result = 0;
    }
  }
  return result;
}
// 4EDEA0: using guessed type int dword_4EDEA0[];
// 4EDEB4: using guessed type int dword_4EDEB4[];

//----- (0048D88B) --------------------------------------------------------
int Player::StealFromActor(unsigned int uActorID, int _steal_perm, int reputation)
{
  Player *v4; // esi@1
  Actor *v5; // edi@1
  unsigned __int16 v6; // cx@10
  int v7; // ebx@10
  unsigned int v8; // esi@10
  int v9; // eax@10
  int v10; // esi@10
  int v11; // eax@13
  signed int v12; // ebx@15
  signed int v13; // edx@15
  int v14; // ecx@15
  unsigned __int16 v15; // si@21
  unsigned int v16; // ebx@24
  int v17; // esi@24
  const void *v18; // eax@29
  unsigned int v19; // esi@31
  int v20; // eax@34
  char v21; // zf@36
  unsigned int v22; // ST0C_4@39
  char *v23; // esi@39
  const char *v25; // [sp-Ch] [bp-48h]@40
  int v26; // [sp-8h] [bp-44h]@40
  ItemGen v27; // [sp+8h] [bp-34h]@15
  unsigned int v28; // [sp+2Ch] [bp-10h]@10
  int v29; // [sp+30h] [bp-Ch]@10
  int v30; // [sp+34h] [bp-8h]@10
  Player *v31; // [sp+38h] [bp-4h]@1
  signed int _steal_perma; // [sp+48h] [bp+Ch]@12

  v4 = this;
  v5 = &pActors[uActorID];
  v31 = this;
  if ( &pActors[uActorID]
    && !this->pConditions[16]
    && !this->pConditions[14]
    && !this->pConditions[15]
    && !this->pConditions[4]
    && !this->pConditions[13]
    && !this->pConditions[2] )
  {
    if ( !(BYTE2(v5->uAttributes) & 0x80) )
      pActors[uActorID].SetRandomGoldIfTheresNoItem();
    v6 = v4->pActiveSkills[34];
    v7 = v6 & 0x3F;
    v8 = SkillToMastery(v6);
    v9 = rand();
    v28 = 4 * v8;
    v30 = dword_4EDEA0[v8];
    v29 = dword_4EDEB4[v9 % 100 / 20];
    v10 = v5->pMonsterInfo.uLevel + 100 * (_steal_perm + reputation);
    if ( rand() % 100 < 5 || v10 > v29 + v7 * v30 || (_steal_perma = 2, BYTE2(v5->uAttributes) & 8) )
    {
      Actor::AggroSurroundingPeasants(uActorID, 1);
      _steal_perma = 0;
      v26 = (int)v31->pName;
      v25 = pGlobalTXT_LocalizationStrings[376];
    }
    else
    {
      v11 = rand();
      if ( v11 % 100 >= 40 )
      {
        if ( v11 % 100 >= 70 )
        {
          v19 = 0;
          if ( v7 > 0 )
          {
            do
            {
              --v7;
              v19 += rand() % dword_4EDEC4[v28 / 4] + 1;
            }
            while ( v7 );
          }
          if ( pItemsTable->pItems[v5->array_000234[3].uItemID].uEquipType != 18 )
            return _steal_perma;
          v20 = (int)&v5->array_000234[3].uSpecEnchantmentType;
          if ( (signed int)v19 > v5->array_000234[3].uSpecEnchantmentType )
            v19 = v5->array_000234[3].uSpecEnchantmentType;
          v21 = *(int *)v20 == v19;
          *(int *)v20 -= v19;
          if ( v21 )
            v5->array_000234[3].uItemID = 0;
          if ( v19 )
          {
            party_finds_gold(v19, 2);
            v22 = v19;
            v23 = pTmpBuf2.data();
            sprintf(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[302], v31->pName, v22);
LABEL_43:
            ShowStatusBarString(v23, 2u);
            return _steal_perma;
          }
        }
        else
        {
          v27.Reset();
          v12 = 0;
          v13 = 0;
          v14 = (int)v5->array_000234;
          while ( !*(int *)v14 || pItemsTable->pItems[*(int *)v14].uEquipType == 18 )
          {
            ++v13;
            v14 += 36;
            if ( v13 >= 4 )
              goto LABEL_21;
          }
          v12 = 1;
LABEL_21:
          v15 = v5->uCarriedItemID;
          if ( v15 || v12 )
          {
            v27.Reset();
            if ( v15 )
            {
              v16 = (signed __int16)v15;
              v5->uCarriedItemID = 0;
              v27.uItemID = (signed __int16)v15;
              v17 = (signed __int16)v15;
              if ( pItemsTable->pItems[v17].uEquipType == 12 )
                v27.uNumCharges = rand() % 6 + pItemsTable->pItems[v17].uDamageMod + 1;
              if ( pItemsTable->pItems[v17].uEquipType == 14 )
              {
                if ( v16 != 220 )
                  v27.uEnchantmentType = 2 * rand() % 4 + 2;
              }
            }
            else
            {
              v18 = &v5->array_000234[rand() % 4];
              memcpy(&v27, v18, sizeof(v27));
              ((ItemGen *)v18)->Reset();
              v16 = v27.uItemID;
            }
            sub_421B2C_PlaceInInventory_or_DropPickedItem();
            sprintf(
              pTmpBuf2.data(),
              pGlobalTXT_LocalizationStrings[304],
              v31->pName,
              pItemsTable->pItems[v16].pUnidentifiedName);
            ShowStatusBarString(pTmpBuf2.data(), 2u);
            sub_421B2C_PlaceInInventory_or_DropPickedItem();
            memcpy(&pParty->pPickedItem, &v27, sizeof(pParty->pPickedItem));
            pMouse->SetCursorBitmapFromItemID(v16);
            return _steal_perma;
          }
        }
      }
      v26 = (int)v31->pName;
      v25 = pGlobalTXT_LocalizationStrings[377];
    }
    v23 = pTmpBuf2.data();
    sprintfex(pTmpBuf2.data(), v25, v26);
    goto LABEL_43;
  }
  return 0;
}
// 4EDEA0: using guessed type int dword_4EDEA0[];
// 4EDEB4: using guessed type int dword_4EDEB4[];
// 4EDEC4: using guessed type int dword_4EDEC4[];

//----- (0048DBB9) --------------------------------------------------------
void Player::Heal(int amount)
{
  signed int max_health; // eax@3

  if ( !IsEradicated() && !IsDead() )
  {
    max_health = GetMaxHealth();
    if ( IsZombie() )
      max_health /= 2;
    sHealth += amount;
    if ( sHealth > max_health )
        sHealth = max_health;
    if ( IsUnconcious() )
    {
      if ( sHealth > 0 )
      {
        SetUnconcious(false);
      }
    }
  }
}

//----- (0048DC1E) --------------------------------------------------------
int Player::ReceiveDamage( signed int amount, DAMAGE_TYPE dmg_type )
    {
  signed int recieved_dmg; // eax@1
  unsigned int armor_indx; // eax@8
  bool broke_armor;
 
  SetAsleep(false);
  recieved_dmg = CalculateIncommingDamage(dmg_type, amount);
  sHealth -= recieved_dmg;
  broke_armor = sHealth <= -10;
  if ( sHealth < 1 ) //
  {
    if ( (sHealth + uEndurance + GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) >= 1)
      || pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0 )
    {
      SetCondUnconsciousWithBlockCheck(false);
    }
    else
    {
      SetCondDeadWithBlockCheck(false);
      if ( sHealth > 0 )
        sHealth = 0;
    }
    if (broke_armor )
    {
      armor_indx = pEquipment.uArmor;
      if ( armor_indx )
      {
        if ( !(pOwnItems[armor_indx-1].uAttributes & ITEM_ENCHANTED))
        {
          pOwnItems[armor_indx-1].SetBroken();
        }
      }
    }
  }
  if ( recieved_dmg && CanAct() )
    PlaySound(SPEECH_24, 0);
  return recieved_dmg;
}

//----- (0048DCF6) --------------------------------------------------------
int Player::_48DCF6(int a2, Actor *pActor)  //TODO check this with IDA to see what the uninitialized vars are supposed to contain
{
  signed int v3; // edi@1
  signed int v4; // ebx@1
  Player *v5; // esi@1
  int v6; // eax@2
  int v7; // eax@5
  int v8; // eax@8
  int v9; // ebx@8
  int v10; // eax@8
  int v11; // ebx@8
  signed int v12; // edx@9
  ItemGen *v13; // eax@9
  int v14; // edx@16
  unsigned int v15; // edx@17
  int v16; // edx@26
  unsigned int v17; // edx@27
  signed int v19; // edx@38
  int *v20; // ecx@38
  signed int v21; // eax@40
  int v22; // eax@49
  signed int v23; // ebx@49
  unsigned int v24; // eax@60
  int v25; // ecx@61
  int v26; // ebx@74
  void *v27; // ecx@76
  unsigned int v28; // ebx@78
  signed int result; // eax@86
  SoundID v30; // [sp-20h] [bp-C0h]@56
  signed int v31; // [sp-1Ch] [bp-BCh]@56
  unsigned int v32; // [sp-18h] [bp-B8h]@56
  signed int v33; // [sp-14h] [bp-B4h]@56
  signed int v34; // [sp-10h] [bp-B0h]@56
  int v35; // [sp-Ch] [bp-ACh]@56
  unsigned int v36; // [sp-8h] [bp-A8h]@51
  unsigned int v37; // [sp-8h] [bp-A8h]@56
  unsigned int v38; // [sp-8h] [bp-A8h]@57
  unsigned int v39; // [sp-8h] [bp-A8h]@68
  enum CHARACTER_ATTRIBUTE_TYPE v40; // [sp-4h] [bp-A4h]@4
  int v41; // [sp-4h] [bp-A4h]@51
  int v42; // [sp-4h] [bp-A4h]@56
  int v43; // [sp-4h] [bp-A4h]@57
  signed int v44; // [sp-4h] [bp-A4h]@59
  int v45; // [sp-4h] [bp-A4h]@68
  char v46[140]; // [sp+Ch] [bp-94h]@13
  unsigned int v47; // [sp+98h] [bp-8h]@1
  int v48; // [sp+9Ch] [bp-4h]@1

  v3 = 0;
  v4 = 0;
  v5 = this;
  v47 = 0;
  v48 = 0;
  switch ( a2 )
  {
    case 1:
      v6 = GetActualWillpower();
      goto LABEL_46;
    case 2:
    case 3:
    case 4:
    case 9:
    case 10:
    case 11:
    case 13:
    case 21:
      v6 = GetActualEndurance();
      goto LABEL_46;
    case 5:
    case 12:
    case 23:
      v40 = (CHARACTER_ATTRIBUTE_TYPE)14;
      goto LABEL_5;
    case 15:
      v40 = (CHARACTER_ATTRIBUTE_TYPE)13;
      goto LABEL_5;
    case 6:
    case 7:
    case 8:
    case 14:
    case 16:
      v40 = (CHARACTER_ATTRIBUTE_TYPE)15;
LABEL_5:
      v7 = GetActualResistance(v40);
      goto LABEL_47;
    case 22:
      v8 = GetActualWillpower();
      v9 = GetParameterBonus(v8);
      v10 = GetActualIntelligence();
      v11 = (GetParameterBonus(v10) + v9) >> 1;
      break;
    case 17:
      v12 = 0;
      v13 = this->pInventoryItemList;
      do
      {
        if ( (signed int)v13->uItemID > 0 && (signed int)v13->uItemID <= 134 && !v13->IsBroken())
          v46[v4++] = v12;
        ++v12;
        ++v13;
      }
      while ( v12 < 138 );
      goto LABEL_36;
    case 18:
      v14 = 0;
      do
      {
        if ( HasItemEquipped((ITEM_EQUIP_TYPE)v14) )
        {
          __debugbreak(); // player.cpp(2871): warning C4700: uninitialized local variable 'v15' used
          if ( v15 == EQUIP_ARMOUR )
            v46[v4++] = LOBYTE(v5->pEquipment.uArmor) - 1;
          if ( (!v15 || v15 == 1) && GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v15) == 4 )
            v46[v4++] = *((char *)&v5->pEquipment.uShield + 4 * v15) - 1;
        }
        v14 = v15 + 1;
      }
      while ( v14 < 16 );
      goto LABEL_36;
    case 19:
      v16 = 0;
      do
      {
        if ( HasItemEquipped((ITEM_EQUIP_TYPE)v16) )
        {
          __debugbreak(); // player.cpp(2886): warning C4700: uninitialized local variable 'v17' used
          if ( v17 == 2 )
            v46[v4++] = LOBYTE(v5->pEquipment.uBow) - 1;
          if ( (!v17 || v17 == 1)
            && (!GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v17) || GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v17) == 1) )
            v46[v4++] = *((char *)&v5->pEquipment.uShield + 4 * v17) - 1;
        }
        v16 = v17 + 1;
      }
      while ( v16 < 16 );
LABEL_36:
      if ( !v4 )
        goto LABEL_87;
      v48 = (int)&v5->pInventoryItemList[(unsigned __int8)v46[rand() % v4]];
      v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod);
      break;
    case 20:
      v19 = 0;
      v20 = this->pInventoryMatrix;
      do
      {
        if ( *v20 > 0 )
        {
          v21 = *(int *)&v5->pInventoryItemList[*v20-1];
          if ( v21 > 0 )
          {
            if ( v21 <= 134 )
              v46[v4++] = v19;
          }
        }
        ++v19;
        ++v20;
      }
      while ( v19 < 126 );
      if ( !v4 )
        goto LABEL_87;
      v47 = (unsigned __int8)v46[rand() % v4];
      v6 = GetActualAccuracy();
LABEL_46:
      v7 = GetParameterBonus(v6);
LABEL_47:
      v11 = v7;
      break;
    default:
      v11 = 0;
      break;
  }
  v22 = GetActualLuck();
  v23 = GetParameterBonus(v22) + v11 + 30;
  if ( rand() % v23 >= 30 )
  {
LABEL_87:
    result = 0;
  }
  else
  {
    switch ( a2 )
    {
      case 1:
        v41 = 1;
        v36 = 0;
        goto LABEL_56;
      case 2:
        v41 = 1;
        v36 = 1;
        goto LABEL_56;
      case 3:
        v41 = 1;
        v36 = 2;
        goto LABEL_56;
      case 23:
        v41 = 1;
        v36 = 3;
        goto LABEL_56;
      case 4:
        v41 = 1;
        v36 = 4;
LABEL_56:
        SetCondition(v36, v41);
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)221;
        goto LABEL_83;
      case 5:
        v43 = 1;
        v38 = 5;
        goto LABEL_70;
      case 6:
      case 7:
      case 8:
        if ( a2 == 6 )
        {
          v44 = 6;
          goto LABEL_60;
        }
        v25 = 2 * (a2 != 8) + 8;
        goto LABEL_65;
      case 9:
        if ( a2 == 6 )
        {
          v44 = 7;
LABEL_60:
          v24 = v44;
        }
        else
        {
          v25 = 2 * (a2 != 8) + 9;
LABEL_65:
          v24 = v25;
        }
        SetCondition(v24, 1);
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)222;
LABEL_83:
        pAudioPlayer->PlaySound(v30, v31, v32, v33, v34, v35, v37, v42);
        do
        {
LABEL_84:
          if ( v5 == pPlayers[v3 + 1] )
            break;
          ++v3;
        }
        while ( v3 < 4 );
        pGame->pStru6Instance->SetPlayerBuffAnim(0x99u, v3);
        result = 1;
        break;
      case 12:
        v43 = 1;
        v38 = 12;
        goto LABEL_70;
      case 15:
        v45 = 1;
        v39 = 15;
        goto LABEL_73;
      case 13:
        v43 = 1;
        v38 = 13;
LABEL_70:
        SetCondition(v38, v43);
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)224;
        goto LABEL_83;
      case 14:
        v45 = 1;
        v39 = 14;
        goto LABEL_73;
      case 16:
        v45 = 1;
        v39 = 16;
LABEL_73:
        SetCondition(v39, v45);
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)225;
        goto LABEL_83;
      case 17:
      case 18:
      case 19:
        v26 = v48;
        if ( *(char *)(v48 + 21) & 2 )
          goto LABEL_84;
        PlaySound(SPEECH_40, 0);
        *(int *)(v26 + 20) |= 2u;
        goto LABEL_79;
      case 20:
        PlaySound(SPEECH_40, 0);
        v27 = pActor->array_000234;
        if ( pActor->array_000234[0].uItemID )
        {
          v27 = &pActor->array_000234[1];
          if ( pActor->array_000234[1].uItemID )
            goto LABEL_84;
        }
        v28 = v47;
        memcpy(v27, &v5->pInventoryItemList[v5->pInventoryMatrix[v47]-1], 0x24u);
        RemoveItemAtInventoryIndex(v28);
LABEL_79:
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)47;
        goto LABEL_83;
      case 21:
        PlaySound(SPEECH_42, 0);
        ++v5->sAgeModifier;
        goto LABEL_82;
      case 22:
        PlaySound(SPEECH_41, 0);
        v5->sMana = 0;
LABEL_82:
        v42 = 0;
        v37 = 0;
        v35 = 0;
        v34 = 0;
        v33 = -1;
        v32 = 0;
        v31 = 0;
        v30 = (SoundID)226;
        goto LABEL_83;
      default:
        goto LABEL_87;
    }
  }
  return result;
}

// 48DCF6: using guessed type char var_94[140];

//----- (0048E1A3) --------------------------------------------------------
unsigned int Player::GetSpellSchool(unsigned int uSpellID)
{
  return pSpellStats->pInfos[uSpellID].uSchool;
}

//----- (0048E1B5) --------------------------------------------------------
int Player::GetAttackRecoveryTime(bool bRangedAttack)
{
  ItemGen  *weapon = nullptr;
  ItemDesc *weapon_desc = nullptr;
  uint      weapon_recovery = base_recovery_times_per_weapon_type[0];
  if (bRangedAttack)
  {
    if ( HasItemEquipped(EQUIP_BOW) )
    {
      weapon = &pInventoryItemList[pEquipment.uBow - 1];
      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
      weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
    }
  }
  else if ( IsUnarmed() == 1 && GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0)
  {
      weapon_recovery = base_recovery_times_per_weapon_type[1];
  }
  else if ( HasItemEquipped(EQUIP_MAIN_HAND) )
  {
    weapon = &pInventoryItemList[pEquipment.uMainHand - 1];
    weapon_desc = &pItemsTable->pItems[weapon->uItemID];
    if (weapon_desc->uEquipType == EQUIP_WAND)
    {
      __debugbreak();  // looks like offset in player's inventory and wand_lut much like case in 0042ECB5
      __debugbreak();  // looks like wands were two-handed weapons once, or supposed to be. should not get here now
      weapon_recovery = pSpellDatas[wand_spell_ids[weapon->uItemID - ITEM_WAND_FIRE]].uExpertLevelRecovery;
    }
    else
      weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
  }
  if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) != EQUIP_SHIELD) 
      // ADD: shield check because shield recovery is added later and can be accidentally doubled
  {
    auto v12 = &pInventoryItemList[pEquipment.uShield - 1];
    auto v12_desc = &pItemsTable->pItems[v12->uItemID];
    if (base_recovery_times_per_weapon_type[v12_desc->uSkillType] > weapon_recovery)
    {
      weapon = &pInventoryItemList[pEquipment.uShield - 1];
      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
      weapon_recovery = base_recovery_times_per_weapon_type[pItemsTable->pItems[weapon->uItemID].uSkillType];
    }
  }

  uint armour_recovery = 0;
  if ( HasItemEquipped(EQUIP_ARMOUR) )
  {
    auto armour_skill_type = pItemsTable->pItems[pInventoryItemList[pEquipment.uArmor - 1].uItemID].uSkillType;
    uint base_armour_recovery = base_recovery_times_per_weapon_type[armour_skill_type];
    float multiplier;

    if (armour_skill_type == PLAYER_SKILL_LEATHER)
    {
      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0, 0, 0);
    }
    else if (armour_skill_type == PLAYER_SKILL_CHAIN)
    {
      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0.5f, 0, 0);
    }
    else if (armour_skill_type == PLAYER_SKILL_PLATE)
    {
      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 0.5f, 0.5f, 0);
    }
    else
    {
      Error("Unknown armour type"); // what kind of armour is that?
      multiplier = GetArmorRecoveryMultiplierFromSkillLevel(armour_skill_type, 1.0f, 1.0f, 1.0f, 1.0f);
    }

    armour_recovery = (uint)(base_armour_recovery * multiplier);
  }

  uint shield_recovery = 0;
  if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD)
  {
    auto shield = &pInventoryItemList[pEquipment.uShield - 1];
    auto skill_type = pItemsTable->pItems[shield->uItemID].uSkillType;

    uint shield_base_recovery = base_recovery_times_per_weapon_type[skill_type];
    float multiplier = GetArmorRecoveryMultiplierFromSkillLevel(skill_type, 1.0f, 0, 0, 0);
    shield_recovery = (uint)(shield_base_recovery * multiplier);
  }

  uint player_speed_recovery_reduction = GetParameterBonus(GetActualSpeed()),
       sword_axe_bow_recovery_reduction = 0;
  bool shooting_laser = false;
  if (weapon_desc)
  {
    if (GetActualSkillLevel((PLAYER_SKILL_TYPE)weapon_desc->uSkillType) &&
        (weapon_desc->uSkillType == PLAYER_SKILL_SWORD || weapon_desc->uSkillType == PLAYER_SKILL_AXE || weapon_desc->uSkillType == PLAYER_SKILL_BOW) )
    {
      if (SkillToMastery(pActiveSkills[weapon_desc->uSkillType]) >= 2 )  // Expert   Sword, Axe & Bow   reduce recovery
        sword_axe_bow_recovery_reduction = pActiveSkills[weapon_desc->uSkillType] & 0x3F;
    }
    if (weapon_desc->uSkillType == PLAYER_SKILL_BLASTER)
      shooting_laser = true;
  }

  uint armsmaster_recovery_reduction = 0;
  if (!bRangedAttack && !shooting_laser)
  {
    if (uint armsmaster_level = GetActualSkillLevel(PLAYER_SKILL_ARMSMASTER))
    {
      armsmaster_recovery_reduction = armsmaster_level & 0x3F;
      if (SkillToMastery(armsmaster_level) >= 4)
        armsmaster_recovery_reduction *= 2;
    }
  }

  uint hasteRecoveryReduction = 0;
  if (pPlayerBuffs[PLAYER_BUFF_HASTE].uExpireTime > 0 || pParty->pPartyBuffs[PARTY_BUFF_HASTE].uExpireTime > 0 )
    hasteRecoveryReduction = 25;

  uint weapon_enchantment_recovery_reduction = 0;
  if ( weapon  )
  {
    if (weapon->uSpecEnchantmentType == 59 ||
        weapon->uSpecEnchantmentType == 41 ||
        weapon->uSpecEnchantmentType == 500)
      weapon_enchantment_recovery_reduction = 20;
  }

  int recovery = weapon_recovery +
                 armour_recovery +
                 shield_recovery
                 - armsmaster_recovery_reduction
                 - weapon_enchantment_recovery_reduction
                 - hasteRecoveryReduction
                 - sword_axe_bow_recovery_reduction
                 - player_speed_recovery_reduction;

  if (recovery < 0)
    recovery = 0;
  return recovery;
}


//----- new --------------------------------------------------------
float Player::GetArmorRecoveryMultiplierFromSkillLevel( unsigned char armour_skill_type, float mult1, float mult2, float mult3, float mult4 )
{
  uint skill_mastery = SkillToMastery(pActiveSkills[armour_skill_type]);
  switch (skill_mastery)
  {
    case 1: return mult1; break;
    case 2: return mult2; break;
    case 3: return mult3; break;
    case 4: return mult4; break;
  }
  Error("Unexpected input value: %d", armour_skill_type);
  return 0;
}

//----- (0048E4F8) --------------------------------------------------------
int Player::GetMaxHealth()
{
  int v3; // esi@1
  int v4; // esi@1
  int v6; // esi@1

  v3 = GetParameterBonus(GetActualEndurance());
  v4 = pBaseHealthPerLevelByClass[classType] * (GetActualLevel() + v3);
  v6 = uFullHealthBonus
     + pBaseHealthByClass[classType / 4]
     + GetSkillBonus(CHARACTER_ATTRIBUTE_HEALTH)
     + GetItemsBonus(CHARACTER_ATTRIBUTE_HEALTH) + v4;
  return max(1, v6);
}

//----- (0048E565) --------------------------------------------------------
int Player::GetMaxMana()
{
  int v2; // eax@2
  int v3; // esi@4
  int v4; // eax@5
  int v5; // esi@5
  int v6; // eax@5
  int v7; // esi@6
  int v8; // esi@6
  int v9; // esi@6
  
  switch (classType)
  {
    case PLAYER_CLASS_ROGUE:
    case PLAYER_CLASS_SPY:
    case PLAYER_CLASS_ASSASSIN:
    case PLAYER_CLASS_ARCHER:
    case PLAYER_CLASS_WARRIOR_MAGE:
    case PLAYER_CLASS_MASTER_ARCHER:
    case PLAYER_CLASS_SNIPER:
    case PLAYER_CLASS_SORCERER:
    case PLAYER_CLASS_WIZARD:
    case PLAYER_CLASS_ARCHMAGE:
    case PLAYER_CLASS_LICH:
      v2 = GetActualIntelligence();
      v3 = GetParameterBonus(v2);
      break;
    case PLAYER_CLASS_INITIATE:
    case PLAYER_CLASS_MASTER:
    case PLAYER_CLASS_NINJA:
    case PLAYER_CLASS_PALADIN:
    case PLAYER_CLASS_CRUSADER:
    case PLAYER_CLASS_HERO:
    case PLAYER_CLASS_VILLIAN:
    case PLAYER_CLASS_CLERIC:
    case PLAYER_CLASS_PRIEST:
    case PLAYER_CLASS_PRIEST_OF_SUN:
    case PLAYER_CLASS_PRIEST_OF_MOON:
      v2 = GetActualWillpower();
      v3 = GetParameterBonus(v2);
      break;
    case PLAYER_CLASS_HUNTER:
    case PLAYER_CLASS_RANGER_LORD:
    case PLAYER_CLASS_BOUNTY_HUNTER:
    case PLAYER_CLASS_DRUID:
    case PLAYER_CLASS_GREAT_DRUID:
    case PLAYER_CLASS_ARCH_DRUID:
    case PLAYER_CLASS_WARLOCK:
      v4 = GetActualWillpower();
      v5 = GetParameterBonus(v4);
      v6 = GetActualIntelligence();
      v3 = GetParameterBonus(v6) + v5;
      break;
    default:
      return 0;
      break;
  }
  v7 = pBaseManaPerLevelByClass[classType] * (GetActualLevel() + v3);
  v8 = GetItemsBonus(CHARACTER_ATTRIBUTE_MANA) + v7;
  v9 = uFullManaBonus
      + pBaseManaByClass[classType / 4]
  + GetSkillBonus(CHARACTER_ATTRIBUTE_MANA)
      + v8;
  return max(0,v9);
}

//----- (0048E656) --------------------------------------------------------
int Player::GetBaseAC()
{
  int v2; // eax@1
  int v3; // esi@1
  int v4; // esi@1
  int v5; // esi@1

  v2 = GetActualSpeed();
  v3 = GetParameterBonus(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v4;
  return max(0, v5);
}

//----- (0048E68F) --------------------------------------------------------
int Player::GetActualAC()
{
  int v2; // eax@1
  int v3; // esi@1
  int v4; // esi@1
  int v5; // esi@1
  int v6; // esi@1

  v2 = GetActualSpeed();
  v3 = GetParameterBonus(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v4;
  v6 = this->sACModifier + GetMagicalBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v5;
  return max(0, v6);
}

//----- (0048E6DC) --------------------------------------------------------
unsigned int Player::GetBaseAge()
{
  return (unsigned int)(((__int64)(pParty->uTimePlayed * 0.234375) / 60 / 60 / 24) / 7 / 4 / 12 - uBirthYear + game_starting_year);
}

//----- (0048E72C) --------------------------------------------------------
unsigned int Player::GetActualAge()
{
  return this->sAgeModifier + GetBaseAge();
}

//----- (0048E73F) --------------------------------------------------------
int Player::GetBaseResistance(enum CHARACTER_ATTRIBUTE_TYPE a2)
{
  int v7; // esi@20
  int racialBonus = 0;
  __int16* resStat;

  switch (a2)
  {
    case CHARACTER_ATTRIBUTE_RESIST_FIRE:
      resStat = &sResFireBase;
      if (IsRaceGoblin())
        racialBonus = 5;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_AIR:
      resStat = &sResAirBase;
      if (IsRaceGoblin())
        racialBonus = 5;
      break;
    case  CHARACTER_ATTRIBUTE_RESIST_WATER:
      resStat = &sResWaterBase;
      if (IsRaceDwarf())
        racialBonus = 5;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_EARTH:
      resStat = &sResEarthBase;
      if (IsRaceDwarf())
        racialBonus = 5;
    break;
    case CHARACTER_ATTRIBUTE_RESIST_MIND:
      resStat = &sResMindBase;
      if (IsRaceElf())
        racialBonus = 10;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_BODY:
    case CHARACTER_ATTRIBUTE_RESIST_SPIRIT:
      resStat = &sResBodyBase;
      if (IsRaceHuman())
        racialBonus = 5;
      break;
  }
  v7 = GetItemsBonus(a2) + racialBonus;
  return v7 + *resStat;
}

//----- (0048E7D0) --------------------------------------------------------
int Player::GetActualResistance(enum CHARACTER_ATTRIBUTE_TYPE a2)
{
  signed int v10 = 0; // [sp+14h] [bp-4h]@1
  __int16* resStat;
  int result;
  int baseRes;

  int leatherArmorSkillLevel = GetActualSkillLevel(PLAYER_SKILL_LEATHER);
  if ( CheckHiredNPCSpeciality(Enchanter) )
    v10 = 20;
  if ( (a2 == CHARACTER_ATTRIBUTE_RESIST_FIRE
     || a2 == CHARACTER_ATTRIBUTE_RESIST_AIR
     || a2 == CHARACTER_ATTRIBUTE_RESIST_WATER
     || a2 == CHARACTER_ATTRIBUTE_RESIST_EARTH)
    && SkillToMastery(leatherArmorSkillLevel) == 4
    && HasItemEquipped(EQUIP_ARMOUR)
    && GetEquippedItemSkillType(EQUIP_ARMOUR) == PLAYER_SKILL_LEATHER )
    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;
  }
  baseRes = GetBaseResistance(a2);
  result = v10 + GetMagicalBonus(a2) + baseRes + *(resStat);
  return result;
}

//----- (0048E8F5) --------------------------------------------------------
bool Player::Recover(int dt)
{
  int v3; // qax@1

  v3 = (int)(dt * GetSpecialItemBonus(17) * 0.01 + dt);

  Log::Warning(L"Recover(dt = %u/%u - %u", dt, (uint)v3, (uint)uTimeToRecovery);

  if (uTimeToRecovery > v3)
  {
    uTimeToRecovery -= v3;
    return true;
  }
  else
  {
    uTimeToRecovery = 0;
    viewparams->bRedrawGameUI = true;
    if (!uActiveCharacter)
      uActiveCharacter = pParty->GetNextActiveCharacter();
    return false;
  }
}

//----- (0048E96A) --------------------------------------------------------
void Player::SetRecoveryTime(signed int rec)
{
  Assert(rec >= 0);

  if (rec > uTimeToRecovery)
    uTimeToRecovery = rec;

  if (pPlayers[uActiveCharacter] == this && !some_active_character)
    uActiveCharacter = pParty->GetNextActiveCharacter();

  viewparams->bRedrawGameUI = true;
}
// 50C0C4: using guessed type int some_active_character;

//----- (0048E9B7) --------------------------------------------------------
void Player::RandomizeName()
{
  if (!uExpressionTimePassed)
    strcpy(pName, pNPCStats->pNPCNames[rand() % pNPCStats->uNumNPCNames[uSex]][uSex]);
}

//----- (0048E9F4) --------------------------------------------------------
unsigned int Player::GetMajorConditionIdx()
{
  for (uint i = 0; i < 18; ++i)
    if (pConditions[pConditionImportancyTable[i]] != 0)
      return pConditionImportancyTable[i];

  return 18;
}

//----- (0048EA1B) --------------------------------------------------------
int Player::GetParameterBonus( int player_parameter )
{
  int i; // eax@1
  i = 0;
  while (param_to_bonus_table[i])
  { 
    if (player_parameter >= param_to_bonus_table[i])
      break;
    ++i;    
  }   
  return parameter_to_bonus_value[i];
}

//----- (0048EA46) --------------------------------------------------------
int Player::GetSpecialItemBonus( int enchantmentId )
{
  int inv_indx; // eax@3

  for (int i = EQUIP_OFF_HAND; i < EQUIP_BOOK; ++i )
  {
    if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) )
    {
      inv_indx = pEquipment.pIndices[i]  - 1;
      if (enchantmentId == 17)
      {
        if ((pInventoryItemList[inv_indx].uSpecEnchantmentType == 17) || (pInventoryItemList[inv_indx].uItemID == 533)) //Elven Chainmail+Increases rate of Recovery
          return 50;
      }
      if (enchantmentId == 24) 
      {
        if (pInventoryItemList[inv_indx].uSpecEnchantmentType == 24) //Increased Knockback.
          return 5;
      }
    }
  }
  return 0;
}

//----- (0048EAAE) --------------------------------------------------------
int Player::GetItemsBonus( enum CHARACTER_ATTRIBUTE_TYPE attr, bool getOnlyMainHandDmg /*= false*/ )
{
  int v5; // edi@1
  int v9; // eax@49
  int v14; // ecx@58
  int v15; // eax@58
  int v17; // eax@62
  int v20; // eax@69
  int v22; // eax@76
  int v23; // edx@76
  int v25; // ecx@80
  int v26; // edi@80
  int v31; // ebp@97
  int v32; // eax@98
  unsigned int v33; // eax@100
  int v56; // eax@365
  int v57; // ebx@368
  signed int v58; // [sp-4h] [bp-20h]@10
  int v61; // [sp+10h] [bp-Ch]@1
  int v62; // [sp+14h] [bp-8h]@1
  ItemGen *currEquippedItem; // [sp+20h] [bp+4h]@101
  bool no_skills;

  v5 = 0;
  v62 = 0;
  v61 = 0;
  
  no_skills=false;
  switch (attr)
  {
    case  CHARACTER_ATTRIBUTE_SKILL_ALCHEMY:      v58 = PLAYER_SKILL_ALCHEMY;      break;
    case  CHARACTER_ATTRIBUTE_SKILL_STEALING:     v58 = PLAYER_SKILL_STEALING;     break;
    case  CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM:  v58 = PLAYER_SKILL_TRAP_DISARM;  break;
    case  CHARACTER_ATTRIBUTE_SKILL_ITEM_ID:      v58 = PLAYER_SKILL_ITEM_ID;      break;
    case  CHARACTER_ATTRIBUTE_SKILL_MONSTER_ID:   v58 = PLAYER_SKILL_MONSTER_ID;   break;
    case  CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER:   v58 = PLAYER_SKILL_ARMSMASTER;   break;
    case  CHARACTER_ATTRIBUTE_SKILL_DODGE:        v58 = PLAYER_SKILL_DODGE;        break;
    case  CHARACTER_ATTRIBUTE_SKILL_UNARMED:      v58 = PLAYER_SKILL_UNARMED;      break;
    case  CHARACTER_ATTRIBUTE_SKILL_FIRE:         v58 = PLAYER_SKILL_FIRE;         break;
    case  CHARACTER_ATTRIBUTE_SKILL_AIR:          v58 = PLAYER_SKILL_AIR;          break;
    case  CHARACTER_ATTRIBUTE_SKILL_WATER:        v58 = PLAYER_SKILL_WATER;        break;
    case  CHARACTER_ATTRIBUTE_SKILL_EARTH:        v58 = PLAYER_SKILL_EARTH;        break;
    case  CHARACTER_ATTRIBUTE_SKILL_SPIRIT:       v58 = PLAYER_SKILL_SPIRIT;       break;
    case  CHARACTER_ATTRIBUTE_SKILL_MIND:         v58 = PLAYER_SKILL_MIND;         break;
    case  CHARACTER_ATTRIBUTE_SKILL_BODY:         v58 = PLAYER_SKILL_BODY;         break;
    case  CHARACTER_ATTRIBUTE_SKILL_LIGHT:        v58 = PLAYER_SKILL_LIGHT;        break;
    case  CHARACTER_ATTRIBUTE_SKILL_DARK:         v58 = PLAYER_SKILL_DARK;         break;
    case  CHARACTER_ATTRIBUTE_SKILL_MEDITATION:   v58 = PLAYER_SKILL_MEDITATION;   break;
    case  CHARACTER_ATTRIBUTE_SKILL_BOW:          v58 = PLAYER_SKILL_BOW;          break;
    case  CHARACTER_ATTRIBUTE_SKILL_SHIELD:       v58 = PLAYER_SKILL_SHIELD;       break;
    case  CHARACTER_ATTRIBUTE_SKILL_LEARNING:     v58 = PLAYER_SKILL_LEARNING;     break;
    default:
      no_skills=true;
  }
  if (!no_skills)
  {
    if ( !this->pActiveSkills[v58] )
      return 0;
  }

  switch(attr)      //TODO would be nice to move these into separate functions
  {
    case CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS:
    case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
      if ( HasItemEquipped(EQUIP_BOW) )
        v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uBow-1].uItemID].uDamageMod;
      return v5;
      break;

    case CHARACTER_ATTRIBUTE_RANGED_DMG_MIN:
      if ( !HasItemEquipped(EQUIP_BOW) )
        return 0;
      v57 = this->pOwnItems[this->pEquipment.uBow-1].uItemID;
      v5 = pItemsTable->pItems[v57].uDamageMod;
      v56 = pItemsTable->pItems[v57].uDamageDice;
      return v5 + v56;
      break;

    case CHARACTER_ATTRIBUTE_RANGED_DMG_MAX:
      if ( !HasItemEquipped(EQUIP_BOW) )
        return 0;
      v20 = this->pOwnItems[this->pEquipment.uBow-1].uItemID;
      v5 = pItemsTable->pItems[v20].uDamageDice * pItemsTable->pItems[v20].uDamageRoll;
      v56 = pItemsTable->pItems[v20].uDamageMod;
      return v5 + v56;

    case CHARACTER_ATTRIBUTE_LEVEL: 
      if ( !Player::HasEnchantedItemEquipped(25) )
        return 0;
      return 5;
      break;

    case CHARACTER_ATTRIBUTE_MELEE_DMG_MAX:
      if ( IsUnarmed() )
      {
        return 3;
      }
      else
      {
        if ( this->HasItemEquipped(EQUIP_MAIN_HAND) )
        {
          v22 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
          if ( v22 >= 0 && v22 <= 2)
          {
            v23 = this->pOwnItems[this->pEquipment.uMainHand].uItemID;
            v26 = pItemsTable->pItems[v23].uDamageRoll;
            if ( this->pEquipment.uShield || pItemsTable->pItems[v23].uSkillType != 4 )
            {
              v25 = pItemsTable->pItems[v23].uDamageDice;
            }
            else
            {
              v25 = pItemsTable->pItems[v23].uDamageDice + 1;
            }
            v5 = pItemsTable->pItems[v23].uDamageMod + v25 * v26;
          }
        }
        if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) ||  (GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0 && GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2))
        {
            return v5;
        }
        else
        {
          v23 = this->pOwnItems[this->pEquipment.uShield].uItemID;
          v15 = pItemsTable->pItems[v23].uDamageMod;
          v14 = pItemsTable->pItems[v23].uDamageDice * pItemsTable->pItems[v23].uDamageRoll;
          return v5 + v15 + v14;
        }
      }
    break;

    case CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS:
    case CHARACTER_ATTRIBUTE_ATTACK:
      if ( IsUnarmed() )
      {
        return 0;
      }
      if ( this->HasItemEquipped(EQUIP_MAIN_HAND) )
      {
        v17 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
        if ( v17 >= 0 && v17 <= 2)
        {
          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand-1].uItemID].uDamageMod;
        }
      }
      if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) || (this->GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0) || this->GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2 )
        return v5;
      else
      {
        v20 = this->pOwnItems[this->pEquipment.uShield - 1].uItemID;
        v56 = pItemsTable->pItems[v20].uDamageMod;
        return v5 + v56;
      }
      break;

    case CHARACTER_ATTRIBUTE_MELEE_DMG_MIN:
      if ( IsUnarmed() )
      {
        return 1;
      }
      if ( this->HasItemEquipped(EQUIP_MAIN_HAND) )
      {
        v9 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
        if ( v9 >= 0 && v9 <= 2)
        {
          v5 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uDamageDice +
            pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uDamageMod;
          if ( !this->pEquipment.uShield && pItemsTable->pItems[this->pOwnItems[this->pEquipment.uMainHand].uItemID].uSkillType == 4)
          {
            ++v5;
          }
        }
      }

      if ( getOnlyMainHandDmg || !this->HasItemEquipped(EQUIP_OFF_HAND) || (this->GetEquippedItemEquipType(EQUIP_OFF_HAND) < 0) || this->GetEquippedItemEquipType(EQUIP_OFF_HAND) > 2 )
      {
        return v5;
      }
      else
      {
        v14 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uShield].uItemID].uDamageMod;
        v15 = pItemsTable->pItems[this->pOwnItems[this->pEquipment.uShield].uItemID].uDamageDice;
        return v5 + v15 + v14;
      }
      break;

    case   CHARACTER_ATTRIBUTE_STRENGTH:
    case   CHARACTER_ATTRIBUTE_INTELLIGENCE:
    case   CHARACTER_ATTRIBUTE_WILLPOWER:
    case   CHARACTER_ATTRIBUTE_ENDURANCE:
    case   CHARACTER_ATTRIBUTE_ACCURACY:
    case   CHARACTER_ATTRIBUTE_SPEED:
    case   CHARACTER_ATTRIBUTE_LUCK:
    case   CHARACTER_ATTRIBUTE_HEALTH:
    case   CHARACTER_ATTRIBUTE_MANA:
    case   CHARACTER_ATTRIBUTE_AC_BONUS:

    case   CHARACTER_ATTRIBUTE_RESIST_FIRE:
    case   CHARACTER_ATTRIBUTE_RESIST_AIR:
    case   CHARACTER_ATTRIBUTE_RESIST_WATER:
    case   CHARACTER_ATTRIBUTE_RESIST_EARTH:
    case   CHARACTER_ATTRIBUTE_RESIST_MIND:
    case   CHARACTER_ATTRIBUTE_RESIST_BODY:        
    case   CHARACTER_ATTRIBUTE_RESIST_SPIRIT:

    case   CHARACTER_ATTRIBUTE_SKILL_ALCHEMY:
    case   CHARACTER_ATTRIBUTE_SKILL_STEALING:
    case   CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM:
    case   CHARACTER_ATTRIBUTE_SKILL_ITEM_ID:
    case   CHARACTER_ATTRIBUTE_SKILL_MONSTER_ID:
    case   CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER:
    case   CHARACTER_ATTRIBUTE_SKILL_DODGE:
    case   CHARACTER_ATTRIBUTE_SKILL_UNARMED:

    case   CHARACTER_ATTRIBUTE_SKILL_FIRE:
    case   CHARACTER_ATTRIBUTE_SKILL_AIR:
    case   CHARACTER_ATTRIBUTE_SKILL_WATER:
    case   CHARACTER_ATTRIBUTE_SKILL_EARTH:
    case   CHARACTER_ATTRIBUTE_SKILL_SPIRIT:
    case   CHARACTER_ATTRIBUTE_SKILL_MIND:
    case   CHARACTER_ATTRIBUTE_SKILL_BODY:
    case   CHARACTER_ATTRIBUTE_SKILL_LIGHT:
    case   CHARACTER_ATTRIBUTE_SKILL_DARK:
    case   CHARACTER_ATTRIBUTE_SKILL_MEDITATION:
    case   CHARACTER_ATTRIBUTE_SKILL_BOW:
    case   CHARACTER_ATTRIBUTE_SKILL_SHIELD:
    case   CHARACTER_ATTRIBUTE_SKILL_LEARNING:
      for (int i = 0; i < 16; i++)
      {
        if ( HasItemEquipped((ITEM_EQUIP_TYPE)i) )
        {
          v31 = this->pEquipment.pIndices[i] - 1;
          currEquippedItem = &this->pInventoryItemList[v31];
          if ( attr == CHARACTER_ATTRIBUTE_AC_BONUS )
          {
            v32 = GetEquippedItemEquipType((ITEM_EQUIP_TYPE)i);
            if ( v32 >= 3 && v32 <= 11 )
            {
              v33 = currEquippedItem->uItemID;
              v5 += pItemsTable->pItems[v33].uDamageDice + pItemsTable->pItems[v33].uDamageMod;
            }
          }
          if ( pItemsTable->IsMaterialNonCommon((ItemGen *)(currEquippedItem))
            && !pItemsTable->IsMaterialSpecial(currEquippedItem) )
          {
            currEquippedItem->GetItemBonusArtifact(this, attr, &v62);
          }
          else if ( currEquippedItem->uEnchantmentType != 0 )
          {
            if (currEquippedItem->IsRegularEnchanmentForAttribute(attr))
            {
              if ( attr > CHARACTER_ATTRIBUTE_RESIST_BODY && v5 < currEquippedItem->m_enchantmentStrength )
                v5 = currEquippedItem->m_enchantmentStrength;
              else
                v5 += currEquippedItem->m_enchantmentStrength;
            }
          }
          else
          {
            currEquippedItem->GetItemBonusSpecialEnchantment(this, attr, &v5, &v61);
          }
        }
      }
      return v5 + v62 + v61;
      break;
    default:
      return 0;
    }
}

//----- (0048F73C) --------------------------------------------------------
int Player::GetMagicalBonus(enum CHARACTER_ATTRIBUTE_TYPE a2)
{
  int v3 = 0; // eax@4
  int v4 = 0; // ecx@5

  switch ( a2 )
  {
    case CHARACTER_ATTRIBUTE_RESIST_FIRE:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_FIRE].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_FIRE].uPower;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_AIR:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_AIR].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_AIR].uPower;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_BODY:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_BODY].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_BODY].uPower;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_WATER:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_WATER].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_WATER].uPower;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_EARTH:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_EARTH].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_EARTH].uPower;
      break;
    case CHARACTER_ATTRIBUTE_RESIST_MIND:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_RESIST_MIND].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_RESIST_MIND].uPower;
      break;
    case CHARACTER_ATTRIBUTE_ATTACK:
    case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_BLESS].uPower;  //only player effect spell in both VI and VII
      break;
    case CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_HEROISM].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_HEROISM].uPower;
      break;
    case CHARACTER_ATTRIBUTE_STRENGTH:
      v3 = pPlayerBuffs[PLAYER_BUFF_STRENGTH].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_INTELLIGENCE:
      v3 = pPlayerBuffs[PLAYER_BUFF_INTELLIGENCE].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_WILLPOWER:
      v3 = pPlayerBuffs[PLAYER_BUFF_WILLPOWER].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_ENDURANCE:
      v3 = pPlayerBuffs[PLAYER_BUFF_ENDURANCE].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_ACCURACY:
      v3 = pPlayerBuffs[PLAYER_BUFF_ACCURACY].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_SPEED:
      v3 = pPlayerBuffs[PLAYER_BUFF_SPEED].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_LUCK:
      v3 = pPlayerBuffs[PLAYER_BUFF_LUCK].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].uPower;
      break;
    case CHARACTER_ATTRIBUTE_AC_BONUS:
      v3 = this->pPlayerBuffs[PLAYER_BUFF_STONESKIN].uPower;
      v4 = pParty->pPartyBuffs[PARTY_BUFF_STONE_SKIN].uPower;
      break;
  }
  return v3 + v4;
}

//----- (0048F882) --------------------------------------------------------
int Player::GetActualSkillLevel( PLAYER_SKILL_TYPE uSkillType )
{
  signed int bonus_value; // esi@1
  unsigned __int16 skill_value; // ax@126
  int result; // al@127
  
  bonus_value = 0;
  switch (uSkillType)
  {
    case PLAYER_SKILL_MONSTER_ID:
    {
      if ( CheckHiredNPCSpeciality(Hunter) )
        bonus_value = 6;
      if ( CheckHiredNPCSpeciality(Sage) )
        bonus_value += 6;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_MONSTER_ID);
    }
    break;

    case PLAYER_SKILL_ARMSMASTER:
    {
        if ( CheckHiredNPCSpeciality(Armsmaster) )
          bonus_value = 2;
        if ( CheckHiredNPCSpeciality(Weaponsmaster) )
          bonus_value += 3;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER);
    }
    break;

    case PLAYER_SKILL_STEALING:
    {
      if (CheckHiredNPCSpeciality(Burglar))
          bonus_value = 8;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_STEALING);
    }
    break;


    case PLAYER_SKILL_ALCHEMY:
    {
        if ( CheckHiredNPCSpeciality(Herbalist) )
          bonus_value = 4;
        if ( CheckHiredNPCSpeciality(Apothecary) )
          bonus_value += 8;
        bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_ALCHEMY);
    }
    break;

    case PLAYER_SKILL_LEARNING:
    {
        if ( CheckHiredNPCSpeciality(Teacher) )
          bonus_value = 10;
        if ( CheckHiredNPCSpeciality(Instructor) )
          bonus_value += 15;
        if ( CheckHiredNPCSpeciality(Scholar) )
          bonus_value += 5;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_LEARNING);
    }
    break;

    case PLAYER_SKILL_UNARMED:
    {
      if (CheckHiredNPCSpeciality(Monk) )
        bonus_value = 2;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_UNARMED);
    }
    break;

    case PLAYER_SKILL_DODGE:
    {
      if ( CheckHiredNPCSpeciality(Monk) )
        bonus_value = 2;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_DODGE);
    }
    break;
    
    case PLAYER_SKILL_BOW:
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_BOW);
    break;
    case PLAYER_SKILL_SHIELD:
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_SHIELD);
    break;

    case PLAYER_SKILL_EARTH:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            bonus_value += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            bonus_value += 3;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_EARTH);
    break;
    case PLAYER_SKILL_FIRE:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            bonus_value += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            bonus_value += 3;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_FIRE);
    break;
    case PLAYER_SKILL_AIR:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            bonus_value += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            bonus_value += 3;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_AIR);
    break;
    case PLAYER_SKILL_WATER:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            bonus_value += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            bonus_value += 3;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_WATER);
    break;
    case PLAYER_SKILL_SPIRIT:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            bonus_value += 4;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_SPIRIT);
    break;
    case PLAYER_SKILL_MIND:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            bonus_value += 4;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_MIND);
    break;
    case PLAYER_SKILL_BODY:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            bonus_value = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            bonus_value += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            bonus_value += 4;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_BODY);
    break;
    case PLAYER_SKILL_LIGHT:
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_LIGHT);
    break;
    case PLAYER_SKILL_DARK:
    {
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_DARK);
    }
    break;

    case PLAYER_SKILL_MERCHANT:
    {
        if ( CheckHiredNPCSpeciality(Trader) )
          bonus_value = 4;
        if ( CheckHiredNPCSpeciality(Merchant) )
          bonus_value += 6;
        if ( CheckHiredNPCSpeciality(Gypsy) )
          bonus_value += 3;
        if ( CheckHiredNPCSpeciality(Duper) )
          bonus_value += 8;
    }
    break;

    case PLAYER_SKILL_PERCEPTION:
    {
      if ( CheckHiredNPCSpeciality(Scout) )
        bonus_value = 6;
      if ( CheckHiredNPCSpeciality(Psychic) )
        bonus_value += 5;
    }
    break;

    case PLAYER_SKILL_ITEM_ID:
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_ITEM_ID);
      break;
    case PLAYER_SKILL_MEDITATION:
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_MEDITATION);
    break;
    case PLAYER_SKILL_TRAP_DISARM:
    {
      if ( CheckHiredNPCSpeciality(Tinker) )
        bonus_value = 4;
      if ( CheckHiredNPCSpeciality(Locksmith) )
        bonus_value += 6;
      if ( CheckHiredNPCSpeciality(Burglar) )
        bonus_value += 8;
      bonus_value += GetItemsBonus(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM);
    }
    break;
  }

  skill_value = pActiveSkills[uSkillType];
  if ( bonus_value + (skill_value & 0x3F) < 60 )
    result = bonus_value + skill_value;
  else
    result = skill_value & 0xFFFC | 0x3C; //al
  return result;
}


//----- (0048FC00) --------------------------------------------------------
int Player::GetSkillBonus(enum CHARACTER_ATTRIBUTE_TYPE inSkill)    //TODO: move the individual implementations to attribute classes once possible
{
  int armsMasterBonus;

  armsMasterBonus = 0;
  int armmaster_skill = GetActualSkillLevel(PLAYER_SKILL_ARMSMASTER);
  if ( armmaster_skill > 0 )
  {
    int multiplier = 0;
    if ( inSkill == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS )
    {
      multiplier = GetMultiplierForSkillLevel(armmaster_skill, 0, 0, 1, 2);
    }
    else if ( inSkill == CHARACTER_ATTRIBUTE_ATTACK )
    {
      multiplier = GetMultiplierForSkillLevel(armmaster_skill, 0, 1, 1, 2);
    } 
    armsMasterBonus = multiplier * (armmaster_skill & 0x3F);
  }

  switch(inSkill)
  {
  case CHARACTER_ATTRIBUTE_RANGED_DMG_BONUS:
    if (HasItemEquipped(EQUIP_BOW))
    {
      int bowSkillLevel = GetActualSkillLevel(PLAYER_SKILL_DODGE);
      int multiplier = GetMultiplierForSkillLevel(bowSkillLevel, 0, 0, 0, 1);
      return multiplier * (bowSkillLevel & 0x3F);
    }
    return 0;
    break;
  case CHARACTER_ATTRIBUTE_HEALTH:
    {
      int base_value = pBaseHealthPerLevelByClass[classType];
      int attrib_modif = GetBodybuilding();
      return base_value * attrib_modif;
    }
    break;
  case CHARACTER_ATTRIBUTE_MANA:
    {
      int base_value = pBaseManaPerLevelByClass[classType];
      int attrib_modif = GetMeditation();
      return base_value * attrib_modif;
    }
    break;
  case CHARACTER_ATTRIBUTE_AC_BONUS:
    {
      bool wearingArmor = false;
      bool wearingLeather = false;
      unsigned int ACSum = 0;

      for (int j = 0; j < 16; ++j) 
      {
        if (pEquipment.pIndices[j] && (!pOwnItems[pEquipment.pIndices[j]].IsBroken()))
        {
          int curr_item = pOwnItems[pEquipment.pIndices[j] - 1].uItemID;
          PLAYER_SKILL_TYPE itemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[curr_item].uSkillType;
          int currArmorSkillLevel = GetActualSkillLevel(itemSkillType);
          int multiplier = 0;
          switch (itemSkillType)
          {
          case PLAYER_SKILL_STAFF:
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 0, 1, 1, 1);
            break;
          case PLAYER_SKILL_SWORD:
          case PLAYER_SKILL_SPEAR:
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 0, 0, 0, 1);
            break;
          case PLAYER_SKILL_SHIELD:
            wearingArmor = true;
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 2, 2);
            break;
          case PLAYER_SKILL_LEATHER:
            wearingLeather = true;
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 2, 2);
            break;
          case PLAYER_SKILL_CHAIN:
            wearingArmor = true;
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 1, 1);
            break;
          case PLAYER_SKILL_PLATE:
            wearingArmor = true; 
            multiplier = GetMultiplierForSkillLevel(currArmorSkillLevel, 1, 1, 1, 1);
            break;
          }
          ACSum += multiplier * (currArmorSkillLevel & 0x3F);
        }
      }

      int dodgeSkillLevel = GetActualSkillLevel(PLAYER_SKILL_DODGE);
      int dodgeMastery = SkillToMastery(dodgeSkillLevel);
      int multiplier = GetMultiplierForSkillLevel(dodgeSkillLevel, 1, 2, 3, 3);
      if ( !wearingArmor && (!wearingLeather || dodgeMastery == 4) )
      {
        ACSum += multiplier * (dodgeSkillLevel & 0x3F);
      }
      return ACSum;
    }
    break;
  case CHARACTER_ATTRIBUTE_ATTACK:
    if ( this->IsUnarmed() )
    {
      int unarmedSkill = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
      if (!unarmedSkill)
      {
        return 0;
      }
      int multiplier = GetMultiplierForSkillLevel(unarmedSkill, 0, 1, 2, 2);
      return armsMasterBonus + multiplier * (unarmedSkill & 0x3F);
    }
    for (int i = 0; i < 16; ++i)
    {
      if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
      {
        ItemDesc currItem = pItemsTable->pItems[this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID];
        if ( currItem.uEquipType <= EQUIP_MAIN_HAND)
        {
          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)currItem.uSkillType;
          int currentItemSkillLevel = this->GetActualSkillLevel(currItemSkillType);
          if (currItemSkillType == PLAYER_SKILL_BLASTER)
          {
            int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 2, 3, 5);
            return multiplier * (currentItemSkillLevel & 0x3F);
          }
          else if (currItemSkillType == PLAYER_SKILL_STAFF && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0)
          {
            int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
            int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 1, 2, 2);
            return multiplier * (unarmedSkillLevel & 0x3F) + armsMasterBonus + (currentItemSkillLevel & 0x3F);
          }
          else
          {
            return armsMasterBonus + (currentItemSkillLevel & 0x3F);
          }
        }
      }
    }
    return 0;
    break;

  case CHARACTER_ATTRIBUTE_RANGED_ATTACK:
    for (int i = 0; i < 16; i++)
    {
      if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
      {
        PLAYER_SKILL_TYPE currentItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID].uSkillType;
        int currentItemSkillLevel = this->GetActualSkillLevel(currentItemSkillType);
        if ( currentItemSkillType == PLAYER_SKILL_BOW )
        {
          int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 1, 1, 1);
          return multiplier * (currentItemSkillLevel & 0x3F);
        }
        else if ( currentItemSkillType == PLAYER_SKILL_BLASTER )
        {      
          int multiplier = GetMultiplierForSkillLevel(currentItemSkillLevel, 1, 2, 3, 5);
          return multiplier * (currentItemSkillLevel & 0x3F);
        }
      }
    }
    return 0;
    break;

  case CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS:
    if ( this->IsUnarmed() )
    {
      int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
      if ( !unarmedSkillLevel )
      {
        return 0;
      }
      int multiplier = GetMultiplierForSkillLevel(unarmedSkillLevel, 0, 1, 2, 2);
      return multiplier * (unarmedSkillLevel & 0x3F);
    }
    for (int i = 0; i < 16; i++)
    {
      if ( this->HasItemEquipped((ITEM_EQUIP_TYPE)i) )
      {
        int currItemId = this->pInventoryItemList[this->pEquipment.pIndices[i]].uItemID;
        if ( pItemsTable->pItems[currItemId].uEquipType == EQUIP_MAIN_HAND || pItemsTable->pItems[currItemId].uEquipType == EQUIP_OFF_HAND )
        {
          PLAYER_SKILL_TYPE currItemSkillType = (PLAYER_SKILL_TYPE)pItemsTable->pItems[currItemId].uSkillType;
          int currItemSkillLevel = this->GetActualSkillLevel(currItemSkillType);
          int baseSkillBonus;
          int multiplier;
          switch (currItemSkillType)
          {
          case PLAYER_SKILL_STAFF:
            if ( SkillToMastery(currItemSkillLevel) >= 4 && this->GetActualSkillLevel(PLAYER_SKILL_UNARMED) > 0)
            {
              int unarmedSkillLevel = this->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
              int multiplier = GetMultiplierForSkillLevel(unarmedSkillLevel, 0, 1, 2, 2);
              return multiplier * (unarmedSkillLevel & 0x3F);
            }
            else
            {
              return armsMasterBonus;
            }
            break;

          case PLAYER_SKILL_DAGGER:
            multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 0, 1);
            baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F);
            return armsMasterBonus + baseSkillBonus;
            break;
          case PLAYER_SKILL_SWORD:
            multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 0, 0);
            baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F);
            return armsMasterBonus + baseSkillBonus;
            break;
          case PLAYER_SKILL_MACE:
          case PLAYER_SKILL_SPEAR:
            multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 1, 1, 1);
            baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F);
            return armsMasterBonus + baseSkillBonus;
            break;
          case PLAYER_SKILL_AXE:
            multiplier = GetMultiplierForSkillLevel(currItemSkillLevel, 0, 0, 1, 1);
            baseSkillBonus = multiplier * (currItemSkillLevel & 0x3F);
            return armsMasterBonus + baseSkillBonus;
            break;
          }
        }
      }
    }
    return 0;
    break;
  default:
    return 0;
  }
}

unsigned int Player::GetMultiplierForSkillLevel(unsigned int skillValue, int mult1, int mult2, int mult3, int mult4)
{
  int masteryLvl = SkillToMastery(skillValue);
  switch (masteryLvl)
  {
    case 1: return mult1;
    case 2: return mult2;
    case 3: return mult3;
    case 4: return mult4;
  }
  Error("(%u)", masteryLvl);
  return 0;
}
//----- (00490109) --------------------------------------------------------
// faces are:  0  1  2  3   human males
//             4  5  6  7   human females
//                   8  9   elf males
//                  10 11   elf females
//                  12 13   dwarf males
//                  14 15   dwarf females
//                  16 17   goblin males
//                  18 19   goblin females
//                     20   lich male
//                     21   lich female
//                     22   underwater suits (unused)
//                     23   zombie male
//                     24   zombie female
enum CHARACTER_RACE Player::GetRace()
{
  if ( uCurrentFace <= 7 )
  {
    return CHARACTER_RACE_HUMAN;
  }
  else if ( uCurrentFace <= 11 )
  {
      return CHARACTER_RACE_ELF;
  }
  else if ( uCurrentFace <= 15 )
  {
    return CHARACTER_RACE_DWARF;
  }
  else if ( uCurrentFace <= 19 )
  {
    return CHARACTER_RACE_GOBLIN;
  }
  else
  {
    return CHARACTER_RACE_HUMAN;
  }
}

//----- (00490141) --------------------------------------------------------
PLAYER_SEX Player::GetSexByVoice()
{
  switch ( this->uVoiceID )
  {
    case 0u:
    case 1u:
    case 2u:
    case 3u:
    case 8u:
    case 9u:
    case 0xCu:
    case 0xDu:
    case 0x10u:
    case 0x11u:
    case 0x14u:
    case 0x17u:
      return SEX_MALE;

    case 4u:
    case 5u:
    case 6u:
    case 7u:
    case 0xAu:
    case 0xBu:
    case 0xEu:
    case 0xFu:
    case 0x12u:
    case 0x13u:
    case 0x15u:
    case 0x18u:
      return SEX_FEMALE;
  }
  Error("(%u)", this->uVoiceID);
  return SEX_MALE;
}

//----- (00490188) --------------------------------------------------------
void Player::SetInitialStats()
{
  auto v1 = GetRace();
  uMight = StatTable[v1][0].uBaseValue;
  uIntelligence = StatTable[v1][1].uBaseValue;
  uWillpower = StatTable[v1][2].uBaseValue;
  uEndurance = StatTable[v1][3].uBaseValue;
  uAccuracy = StatTable[v1][4].uBaseValue;
  uSpeed = StatTable[v1][5].uBaseValue;
  uLuck = StatTable[v1][6].uBaseValue;
}

//----- (004901FC) --------------------------------------------------------
void Player::SetSexByVoice()
{
  switch ( this->uVoiceID)
  {
    case 0:
    case 1:
    case 2:
    case 3:
    case 8:
    case 9:
    case 0xC:
    case 0xD:
    case 0x10:
    case 0x11:
    case 0x14:
    case 0x17:
      this->uSex = SEX_MALE;
      break;
    case 4:
    case 5:
    case 6:
    case 7:
    case 0xA:
    case 0xB:
    case 0xE:
    case 0xF:
    case 0x12:
    case 0x13:
    case 0x15:
    case 0x18:
      this->uSex = SEX_FEMALE;
      break;
    default:
      Error("(%u)", this->uVoiceID);
      break;
  }
 
}

//----- (0049024A) --------------------------------------------------------
void Player::Reset(PLAYER_CLASS_TYPE cls)
{
  sLevelModifier = 0;
  sAgeModifier = 0;

  classType = cls;
  uLuckBonus = 0;
  uSpeedBonus = 0;
  uAccuracyBonus = 0;
  uEnduranceBonus = 0;
  uWillpowerBonus = 0;
  uIntelligenceBonus = 0;
  uMightBonus = 0;
  uLevel = 1;
  uExperience = 251 + rand() % 100;
  uBirthYear = 1147 - rand() % 6;
  memset(pActiveSkills, 0, sizeof(pActiveSkills));
  memset(_achieved_awards_bits, 0, 64);
  memset(&spellbook, 0, sizeof(PlayerSpells));

  for (uint i = 0; i < 37; ++i)
  {
    if (pSkillAvailabilityPerClass[classType / 4][i] != 2)
      continue;

    pActiveSkills[i] = 1;

    switch (i)
    {
      case PLAYER_SKILL_FIRE:
        spellbook.pFireSpellbook.bIsSpellAvailable[0] = true;//its temporary, for test spells

        extern bool all_magic;
        if ( all_magic == true )
        {
          pActiveSkills[PLAYER_SKILL_AIR] = 1;
          pActiveSkills[PLAYER_SKILL_WATER] = 1;
          pActiveSkills[PLAYER_SKILL_EARTH] = 1;
          spellbook.pFireSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pFireSpellbook.bIsSpellAvailable[10] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[0] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pAirSpellbook.bIsSpellAvailable[10] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[0] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pWaterSpellbook.bIsSpellAvailable[10] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[0] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pEarthSpellbook.bIsSpellAvailable[10] = true;
        }
        break;
      case PLAYER_SKILL_AIR:
        spellbook.pAirSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_WATER:
        spellbook.pWaterSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_EARTH:
        spellbook.pEarthSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_SPIRIT:
        spellbook.pSpiritSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_MIND:
        spellbook.pMindSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_BODY:
        spellbook.pBodySpellbook.bIsSpellAvailable[0] = true;

        if ( all_magic == true )
        {
          pActiveSkills[PLAYER_SKILL_MIND] = 1;
          pActiveSkills[PLAYER_SKILL_SPIRIT] = 1;
          spellbook.pBodySpellbook.bIsSpellAvailable[1] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[2] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[3] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[4] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[5] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[6] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[7] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[8] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[9] = true;
          spellbook.pBodySpellbook.bIsSpellAvailable[10] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[0] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pMindSpellbook.bIsSpellAvailable[10] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[0] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[1] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[2] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[3] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[4] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[5] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[6] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[7] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[8] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[9] = true;
          spellbook.pSpiritSpellbook.bIsSpellAvailable[10] = true;
        }
        break;
      case PLAYER_SKILL_LIGHT:
        spellbook.pLightSpellbook.bIsSpellAvailable[0] = true;
        break;
      case PLAYER_SKILL_DARK:
        spellbook.pDarkSpellbook.bIsSpellAvailable[0] = true;
        break;
    }
  }

  sHealth = GetMaxHealth();
  sMana = GetMaxMana();
}

//----- (004903C9) --------------------------------------------------------
PLAYER_SKILL_TYPE Player::GetSkillIdxByOrder(signed int order)
{
  int counter; // edx@5
  bool canBeInactive;
  unsigned char requiredValue;
  signed int offset;

  if ( order <= 1 )
  {
    canBeInactive = false;
    requiredValue = 2;  // 2 - primary skill
    offset = 0;
  }
  else if ( order <= 3 )
  {
    canBeInactive = false;
    requiredValue = 1;  // 1 - available
    offset = 2;
  }
  else if ( order <= 12 )
  {
    canBeInactive = true;
    requiredValue = 1;  // 1 - available
    offset = 4;
  }
  else
  {
    return (PLAYER_SKILL_TYPE)37;
  }
  counter = 0;
  for (int i = 0; i < 37; i++)
  {
    if ( (this->pActiveSkills[i] || canBeInactive) && pSkillAvailabilityPerClass[classType / 4][i] == requiredValue )
    {
      if ( counter == order - offset )
        return (PLAYER_SKILL_TYPE)i;
      ++counter;
    }
  }

  return (PLAYER_SKILL_TYPE)37;
}



//----- (0049048D) --------------------------------------------------------
//unsigned __int16 PartyCreation_BtnMinusClick(Player *_this, int eAttribute)
void Player::DecreaseAttribute(int eAttribute)
{
  int pBaseValue; // ecx@1
  int pDroppedStep; // ebx@1
  int pStep; // esi@1
  int uMinValue; // [sp+Ch] [bp-4h]@1

  int raceId = GetRace();
  pBaseValue = StatTable[raceId][eAttribute].uBaseValue;
  pDroppedStep = StatTable[raceId][eAttribute].uDroppedStep;
  uMinValue = pBaseValue - 2;
  pStep = StatTable[raceId][eAttribute].uBaseStep;
  unsigned short* AttrToChange = nullptr;
  switch ( eAttribute )
  {
    case CHARACTER_ATTRIBUTE_STRENGTH:
      AttrToChange = &this->uMight;
      break;
    case CHARACTER_ATTRIBUTE_INTELLIGENCE:
      AttrToChange = &this->uIntelligence;
      break;
    case CHARACTER_ATTRIBUTE_WILLPOWER:
      AttrToChange = &this->uWillpower;
      break;
    case CHARACTER_ATTRIBUTE_ENDURANCE:
      AttrToChange = &this->uEndurance;
      break;
    case CHARACTER_ATTRIBUTE_ACCURACY:
      AttrToChange = &this->uAccuracy;
      break;
    case CHARACTER_ATTRIBUTE_SPEED:
      AttrToChange = &this->uSpeed;
      break;
    case CHARACTER_ATTRIBUTE_LUCK:
      AttrToChange = &this->uLuck;
      break;
  }
  if ( *AttrToChange <= pBaseValue )
    pStep = pDroppedStep;
  if ( *AttrToChange - pStep >= uMinValue )
    *AttrToChange -= pStep;
}

//----- (004905F5) --------------------------------------------------------
//signed int  PartyCreation_BtnPlusClick(Player *this, int eAttribute)
void Player::IncreaseAttribute( int eAttribute )
{
  int raceId; // eax@1
  int maxValue; // ebx@1
  signed int baseStep; // edi@1
  signed int tmp; // eax@17
  signed int result; // eax@18
  int baseValue; // [sp+Ch] [bp-8h]@1
  signed int droppedStep; // [sp+10h] [bp-4h]@1
  unsigned short* statToChange;

  raceId = GetRace();
  maxValue = StatTable[raceId][eAttribute].uMaxValue;
  baseStep = StatTable[raceId][eAttribute].uBaseStep;
  baseValue = StatTable[raceId][eAttribute].uBaseValue;
  droppedStep = StatTable[raceId][eAttribute].uDroppedStep;
  PlayerCreation_GetUnspentAttributePointCount();
  switch ( eAttribute )
  {
  case 0:
    statToChange = &this->uMight;
    break;
  case 1:
    statToChange = &this->uIntelligence;
    break;
  case 2:
    statToChange = &this->uWillpower;
    break;
  case 3:
    statToChange = &this->uEndurance;
    break;
  case 4:
    statToChange = &this->uAccuracy;
    break;
  case 5:
    statToChange = &this->uSpeed;
    break;
  case 6:
    statToChange = &this->uLuck;
  default:
    Error("(%u)", eAttribute);
  }
  if ( *statToChange < baseValue )
  {
    tmp = baseStep;
    baseStep = droppedStep;
    droppedStep = tmp;
  }
  result = PlayerCreation_GetUnspentAttributePointCount();
  if ( result >= droppedStep )
  {
    if ( baseStep + *statToChange <= maxValue )
      *statToChange += baseStep;
  }
}

//----- (0049070F) --------------------------------------------------------
void Player::Zero()
{
  this->sLevelModifier = 0;
  this->sACModifier = 0;
  this->uLuckBonus = 0;
  this->uAccuracyBonus = 0;
  this->uSpeedBonus = 0;
  this->uEnduranceBonus = 0;
  this->uWillpowerBonus = 0;
  this->uIntelligenceBonus = 0;
  this->uMightBonus = 0;
  this->field_100 = 0;
  this->field_FC = 0;
  this->field_F8 = 0;
  this->field_F4 = 0;
  this->field_F0 = 0;
  this->field_EC = 0;
  this->field_E8 = 0;
  this->field_E4 = 0;
  this->field_E0 = 0;
  memset(&this->sResFireBonus, 0, 0x16u);
  this->field_1A97 = 0;
  this->_ranged_dmg_bonus = 0;
  this->field_1A95 = 0;
  this->_ranged_atk_bonus = 0;
  this->field_1A93 = 0;
  this->_melee_dmg_bonus = 0;
  this->field_1A91 = 0;
  this->_some_attack_bonus = 0;
  this->_mana_related = 0;
  this->uFullManaBonus = 0;
  this->_health_related = 0;
  this->uFullHealthBonus = 0;
}

//----- (004907E7) --------------------------------------------------------
unsigned int Player::GetStatColor(int uStat)
{
  int attribute_value; // edx@1

  int base_attribute_value = StatTable[GetRace()][uStat].uBaseValue;
  switch (uStat)
  {
    case 0:  attribute_value = uMight;        break;
    case 1:  attribute_value = uIntelligence; break;
    case 2:  attribute_value = uWillpower;    break;
    case 3:  attribute_value = uEndurance;    break;
    case 4:  attribute_value = uAccuracy;     break;
    case 5:  attribute_value = uSpeed;        break;
    case 6:  attribute_value = uLuck;         break;
  };

  if (attribute_value == base_attribute_value)
    return ui_character_stat_default_color;
  else if (attribute_value > base_attribute_value)
    return ui_character_stat_buffed_color;
  else
    return ui_character_stat_debuffed_color;
}

//----- (004908A8) --------------------------------------------------------
bool Player::DiscardConditionIfLastsLongerThan(unsigned int uCondition, unsigned __int64 uTime)
{
  if ( pConditions[uCondition] && (uTime < pConditions[uCondition]) )
  {
    pConditions[uCondition] = 0i64;
    return true;
  }
  else
   return false;
}

//----- (004680ED) --------------------------------------------------------
void Player::UseItem_DrinkPotion_etc(signed int player_num, int a3)
{
  Player *playerAffected; // esi@1
  signed int v5; // eax@17
  int v8; // edx@39
  char *v13; // eax@45
  signed int v15; // edi@68
  int v16; // edx@73
  unsigned __int16 v17; // edi@73
  unsigned int v18; // eax@73
  const char *v22; // eax@84
  int scroll_id; // esi@96
  int v25; // eax@109
  int v26; // eax@113
  int new_mana_val; // edi@114
  signed __int64 v28; // qax@120
  __int64 v30; // edi@137
  __int64 v32; // ST3C_4@137
  __int64 v34; // ST34_4@137
  unsigned __int16 v50; // [sp-Ch] [bp-38h]@120
  const char *v66; // [sp-4h] [bp-30h]@69
  signed int v67; // [sp-4h] [bp-30h]@77
  const char *v68; // [sp-4h] [bp-30h]@89
  char v72; // [sp+20h] [bp-Ch]@68
  signed int v73; // [sp+24h] [bp-8h]@1
  char*  v74; // [sp+24h] [bp-8h]@23
  Player *thisb; // [sp+28h] [bp-4h]@1
  unsigned int thisa; // [sp+28h] [bp-4h]@22

  thisb = this;
  playerAffected = &pParty->pPlayers[player_num-1];
  v73 = 1;
  if ( pParty->bTurnBasedModeOn == 1 && (pTurnEngine->turn_stage == 1 || pTurnEngine->turn_stage == 3) )
      return;
  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_REAGENT )
  {
    if ( pParty->pPickedItem.uItemID == 160 )
    { 
      playerAffected->SetCondition(Condition_Poison1, 1);
    }
    else if ( pParty->pPickedItem.uItemID == 161 )
    {
      new_mana_val = playerAffected->sMana;
      new_mana_val += 2;
      if ( new_mana_val > playerAffected->GetMaxMana() )
        new_mana_val = playerAffected->GetMaxMana();
      playerAffected->PlaySound(SPEECH_36, 0);
    }
    else if ( pParty->pPickedItem.uItemID == 162 )
    {
      playerAffected->Heal(2);
      playerAffected->PlaySound(SPEECH_36, 0);
    }
    else
    {    
      v68 = pParty->pPickedItem.GetDisplayName();
      sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[36], v68);//"%s can not be used that way"
      ShowStatusBarString(pTmpBuf.data(), 2);
      pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
      return;
    }
    pAudioPlayer->PlaySound((SoundID)211, 0, 0, -1, 0, 0, 0, 0);

    if ( pGUIWindow_CurrentMenu && pGUIWindow_CurrentMenu->eWindowType != WINDOW_null)
    {
      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
    }
    if ( v73 )
    {
      if ( pParty->bTurnBasedModeOn )
      {
        pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
        thisb->SetRecoveryTime(100);
        pTurnEngine->ApplyPlayerAction();
      }
      else
      {
        thisb->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * 213.3333333333333);
      }
    }
    pMouse->RemoveHoldingItem();
    return;
  }

  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_POTION )
  {
      switch ( pParty->pPickedItem.uItemID )
      {
          case 221: //Catalyst
              playerAffected->SetCondition(Condition_Poison1, 1);
              break;
          case 222: //Cure Wounds
              v25 = pParty->pPickedItem.uEnchantmentType + 10;
              playerAffected->Heal(v25);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 223: //Magic Potion
              v26 = pParty->pPickedItem.uEnchantmentType + 10;
              new_mana_val = playerAffected->sMana;
              new_mana_val += v26;
              if ( new_mana_val > playerAffected->GetMaxMana() )
                  new_mana_val = playerAffected->GetMaxMana();
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 224: //Cure Weakness
              playerAffected->pConditions[Condition_Weak] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 225: //Cure Disease
              playerAffected->pConditions[Condition_Disease3] = 0i64;      
              playerAffected->pConditions[Condition_Disease2] = 0i64;
              playerAffected->pConditions[Condition_Disease1] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 226: //Cure Poison
              playerAffected->pConditions[Condition_Poison3] = 0i64;
              playerAffected->pConditions[Condition_Poison2] = 0i64;
              playerAffected->pConditions[Condition_Poison1] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 227: //Awaken
              playerAffected->pConditions[Condition_Sleep] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 228: //Haste
              if ( !playerAffected->pConditions[Condition_Weak] )
              {
                v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
                playerAffected->pPlayerBuffs[7].Apply(pParty->uTimePlayed + v28, 3, 5, 0, 0);
                playerAffected->PlaySound(SPEECH_36, 0);
              }
              break;
          case 229: //Heroism
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[8].Apply(pParty->uTimePlayed + v28, 3, 5, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 230: //Bless
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[1].Apply(pParty->uTimePlayed + v28, 3, 5, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 231: //Preservation
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[11].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 232: //Shield
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[13].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 234: //Stoneskin
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[14].Apply(pParty->uTimePlayed + v28, 3, 5, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 235: //Water Breathing
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335),
              playerAffected->pPlayerBuffs[23].Apply(pParty->uTimePlayed +v28,  3, 5, 0, 0);
              break;
          case 237: //Remove Fear
              playerAffected->pConditions[Condition_Fear] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 238: //Remove Curse
              playerAffected->pConditions[Condition_Cursed] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 239: //Cure Insanity
              playerAffected->pConditions[Condition_Insane] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 240: //Might Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[19].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 241: //Intellect Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[17].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 242: //Personality Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[20].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 243://Endurance Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[16].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 244: //Speed Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[21].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 245: //Accuracy Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[15].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 251: //Cure Paralysis
              playerAffected->pConditions[Condition_Paralyzed] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 252://Divine Restoration
              v30 = playerAffected->pConditions[Condition_Dead];
              v32 = playerAffected->pConditions[Condition_Pertified];
              v34 = playerAffected->pConditions[Condition_Eradicated];    
              memset(&playerAffected->pConditions,0,sizeof(pConditions));
              playerAffected->pConditions[Condition_Dead] = v30;
              playerAffected->pConditions[Condition_Pertified] = v32;
              playerAffected->pConditions[Condition_Eradicated] = v34;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 253: //Divine Cure
              v25 = 5 * pParty->pPickedItem.uEnchantmentType;
              playerAffected->Heal(v25);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 254: //Divine Power
              v26 = 5 * pParty->pPickedItem.uEnchantmentType;
              new_mana_val = playerAffected->sMana;
              new_mana_val += v26;
              if ( new_mana_val > playerAffected->GetMaxMana() )
                  new_mana_val = playerAffected->GetMaxMana();
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 255: //Luck Boost
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[18].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 256: //Fire Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[5].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 257: //Air Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[0].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 258: //Water Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[22].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 259: //Earth Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[3].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 260: //Mind Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[9].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 261: //Body Resistance
              v50 = 3 * pParty->pPickedItem.uEnchantmentType;
              v28 = (signed __int64)((double)(230400 * pParty->pPickedItem.uEnchantmentType) * 0.033333335);
              playerAffected->pPlayerBuffs[2].Apply(pParty->uTimePlayed + v28, 0, v50, 0, 0);
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 262: //Stone to Flesh
              playerAffected->pConditions[Condition_Pertified] = 0i64;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 264: //Pure Luck
              if ( !playerAffected->pure_luck_used )
              {
                playerAffected->uLuck += 50;
                playerAffected->pure_luck_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 265: //Pure Speed
              if ( !playerAffected->pure_speed_used )
              {
                playerAffected->uSpeed += 50;
                playerAffected->pure_speed_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 266: //Pure Intellect
              if ( !playerAffected->pure_intellect_used )
              {
                playerAffected->uIntelligence += 50;
                playerAffected->pure_intellect_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 267: //Pure Endurance
              if ( !playerAffected->pure_endurance_used )
              {
                playerAffected->uEndurance += 50;
                playerAffected->pure_endurance_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 268:  //Pure Personality
              if ( !playerAffected->pure_willpower_used )
              {
                playerAffected->uWillpower += 50;
                playerAffected->pure_willpower_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 269: //Pure Accuracy
              if ( !playerAffected->pure_accuracy_used )
              {
                playerAffected->uAccuracy += 50;
                playerAffected->pure_accuracy_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 270: //Pure Might
              if ( !playerAffected->pure_might_used )
              {
                playerAffected->uMight += 50;
                playerAffected->pure_might_used = 1;
              }
              playerAffected->PlaySound(SPEECH_36, 0);
              break;
          case 271: //Rejuvenation
              playerAffected->sAgeModifier = 0;
              playerAffected->PlaySound(SPEECH_36, 0);
              break;

          default:
          v68 = pParty->pPickedItem.GetDisplayName();
          sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[36], v68);//"%s can not be used that way"
          ShowStatusBarString(pTmpBuf.data(), 2u);
          pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
          return;
      }
      pAudioPlayer->PlaySound((SoundID)210, 0, 0, -1, 0, 0, 0, 0);
      if ( pGUIWindow_CurrentMenu && pGUIWindow_CurrentMenu->eWindowType != WINDOW_null)
      {
//         if ( !v73 )                                            v73 is always 1 at this point
//         {
//           pMouse->RemoveHoldingItem();
//           return;
//         }
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
      }
      if ( v73 )
      {
        if ( pParty->bTurnBasedModeOn )
        {
          pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
          thisb->SetRecoveryTime(100);
          pTurnEngine->ApplyPlayerAction();
        }
        else
        {
          thisb->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * 213.3333333333333);
        }
      }
      pMouse->RemoveHoldingItem();
      return;
  }


  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_SPELL_SCROLL )
  {
    if ( pCurrentScreen == SCREEN_CASTING )
        return;
    if ( !playerAffected->CanAct() )
    {

      v68 = aCharacterConditionNames[playerAffected->GetMajorConditionIdx()];
      sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[382], v68);
      ShowStatusBarString(pTmpBuf.data(), 2u);
      pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
      return;
    }
    if ( bUnderwater == 1 )
    {
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[652], 2u);//"You can not do that while you are underwater!"
      pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
      return;
    }
    dword_50C9AC = 1;
    scroll_id = pParty->pPickedItem.uItemID - 299;
    if ( scroll_id == 30 || scroll_id == 4 || scroll_id == 91 || scroll_id == 28 ) //Enchant Item scroll, Vampiric Weapon scroll ,Recharge Item ,Fire Aura
    {
      pMouse->RemoveHoldingItem();
      pGUIWindow_CurrentMenu->Release();
      pIcons_LOD->RemoveTexturesPackFromTextureList();
      pCurrentScreen = SCREEN_GAME;
      viewparams->bRedrawGameUI = 1;
      _42777D_CastSpell_UseWand_ShootArrow(scroll_id, player_num - 1, 0x85u, 1, 0);
    }
    else
    {
      _720984_unused = pParty->pPickedItem.uItemID;
      pMouse->RemoveHoldingItem();
      pMessageQueue_50C9E8->AddMessage(UIMSG_SpellScrollUse, scroll_id, player_num - 1);
      if ( pCurrentScreen && pGUIWindow_CurrentMenu
        && (pGUIWindow_CurrentMenu->eWindowType != WINDOW_null))
      {
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
      }
    }
    return;
  }

  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_BOOK )
  {  
      v15 = pParty->pPickedItem.uItemID - 400;
      v72 = playerAffected->spellbook.bHaveSpell[pParty->pPickedItem.uItemID-400];//(char *)&v3->pConditions[0] + pParty->pPickedItem.uItemID + 2;
      if ( v72 )
      {
        v66 = pParty->pPickedItem.GetDisplayName();
        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[380], v66);//"You already know the %s spell"
        ShowStatusBarString(pTmpBuf.data(), 2u);
        pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
        return;
      }
      if ( !playerAffected->CanAct() )
      {
        v66 = aCharacterConditionNames[playerAffected->GetMajorConditionIdx()];
        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[382], v66);//"That player is %s"
        ShowStatusBarString(pTmpBuf.data(), 2u);
        pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
        return;
      }
      v16 = v15 % 11 + 1;
      v17 = playerAffected->pActiveSkills[v15 / 11 + 12];
      v18 = SkillToMastery(v17) - 1;
      switch (v18)  
      {
        case 0: v67 = 4; break;
        case 1: v67 = 7; break;
        case 2: v67 = 10; break;
        case 3: v67 = 11; break;
        default:
          v67 = player_num;   
      }
  
      if ( v16 > v67 || !v17 )
      {
        v22 = pParty->pPickedItem.GetDisplayName();
        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[381], v22); //"You don't have the skill to learn %s"
        ShowStatusBarString(pTmpBuf.data(), 2u);
        playerAffected->PlaySound((PlayerSpeech)20, 0);
        return; 
      }
    //   v72 = 1;
      playerAffected->PlaySound(SPEECH_21, 0);
      v73 = 0;


      if ( pGUIWindow_CurrentMenu && pGUIWindow_CurrentMenu->eWindowType != WINDOW_null)
      {
        if ( !v73 )
        {
          pMouse->RemoveHoldingItem();
          return;
        }
        pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
      }
//       if ( v73 )                                                v73 is always 0 at this point
//       {
//         if ( pParty->bTurnBasedModeOn )
//         {
//           pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
//           thisb->SetRecoveryTime(100);
//           pTurnEngine->ApplyPlayerAction();
//         }
//         else
//         {
//           thisb->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * 213.3333333333333);
//         }
//       }
      pMouse->RemoveHoldingItem();
      return;
  }

  if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_MESSAGE_SCROLL )
  {
      if ( playerAffected->CanAct() )
      {
          CreateMsgScrollWindow(pParty->pPickedItem.uItemID);
          playerAffected->PlaySound(SPEECH_37, 0);
          return;
      }
      v68 = aCharacterConditionNames[playerAffected->GetMajorConditionIdx()];
      sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[382], v68);
      ShowStatusBarString(pTmpBuf.data(), 2u);
      pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
      return;
  }
  else
  {
    if (pParty->pPickedItem.uItemID == 616) //Genie Lamp
    {
      thisa = pParty->uCurrentMonthWeek + 1;
      if ( pParty->uCurrentMonth >= 7 )
          v74 = NULL;
      else
          v74 = aAttributeNames[pParty->uCurrentMonth];
      switch ( pParty->uCurrentMonth )
      {
        case 0:
            playerAffected->uMight += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 1:
            playerAffected->uIntelligence += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 2:
            playerAffected->uWillpower += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 3:
            playerAffected->uEndurance += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 4:
            playerAffected->uAccuracy += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 5:
            playerAffected->uSpeed += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 6:
            playerAffected->uLuck += thisa;
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
            break;
        case 7:
            party_finds_gold(1000 * thisa, 0);
            sprintf(pTmpBuf.data(), "+%u %s", 1000 * thisa, pGlobalTXT_LocalizationStrings[97]);//"Gold"
            break;
        case 8:
            Party::GiveFood(5 * thisa); 
            sprintf(pTmpBuf.data(), "+%u %s",5 * thisa , pGlobalTXT_LocalizationStrings[653]);//"Food"
            break;
        case 9u:
            playerAffected->uSkillPoints += 2 * thisa;
            sprintf(pTmpBuf.data(), "+%u %s", 2 * thisa, pGlobalTXT_LocalizationStrings[LOCSTR_SKILL_POINTS]);
            break;
        case 10:
            playerAffected->uExperience += 2500 * thisa;
            sprintf(pTmpBuf.data(), "+%u %s", 2500 * thisa, pGlobalTXT_LocalizationStrings[LOCSTR_EXPIRIENCE]);
            break;
        case 11:
            v8 = rand() % 6;
            switch (v8)
            {
            case 0:
                playerAffected->sResFireBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[87];
                break;
            case 1:
                playerAffected->sResAirBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[6];
                break;
            case 2:
                playerAffected->sResWaterBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[240];
                break;
            case 3:
                playerAffected->sResEarthBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[70];
                break;
            case 4:
                playerAffected->sResMindBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[142];
                break;
            case 5:
                playerAffected->sResBodyBase += thisa;
                v13 = pGlobalTXT_LocalizationStrings[29];
                break;
            }
            sprintf(pTmpBuf.data(), "+%u %s %s", thisa, v13, pGlobalTXT_LocalizationStrings[121]);
            break;

      }
      ShowStatusBarString(pTmpBuf.data(), 2u);
      pMouse->RemoveHoldingItem();
      pGame->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
      playerAffected->PlaySound(SPEECH_93, 0);
      pAudioPlayer->PlaySound((SoundID)219, 0, 0, -1, 0, 0, 0, 0);
      if ( pParty->uDaysPlayed == 6 || pParty->uDaysPlayed == 20 )
          {
          playerAffected->SetCondition(Condition_Eradicated, 0);
          pAudioPlayer->PlaySound((SoundID)215, 0, 0, -1, 0, 0, 0, 0);
          }
      else if ( pParty->uDaysPlayed == 12 || pParty->uDaysPlayed == 26 )
          {
          playerAffected->SetCondition(Condition_Dead, 0);
          pAudioPlayer->PlaySound((SoundID)215, 0, 0, -1, 0, 0, 0, 0);
          }
      else  if ( pParty->uDaysPlayed == 4 || pParty->uDaysPlayed == 25 )
      {
        playerAffected->SetCondition(Condition_Pertified, 0);
        pAudioPlayer->PlaySound((SoundID)215, 0, 0, -1, 0, 0, 0, 0);                 
      }
      return;
      }
      else if ( pParty->pPickedItem.uItemID == 630 ) //Red Apple
      {
          Party::GiveFood(1u);
          pAudioPlayer->PlaySound(SOUND_EatApple, 0, 0, -1, 0, 0, 0, 0);
      }
      else if ( pParty->pPickedItem.uItemID == 632 ) //Lute
      {
        pAudioPlayer->PlaySound(SOUND_PlayLute,  0, 0, -1, 0, 0, 0, 0);
        return;
      }
      else if ( pParty->pPickedItem.uItemID == 633 ) //Faerie Pipes
      {
        pAudioPlayer->PlaySound(SOUND_PlayFaeriePipes,  0, 0, -1, 0, 0, 0, 0);
        return;
      }
      else if ( pParty->pPickedItem.uItemID == 634 ) //Gryphonheart's Trumpet
      {
        pAudioPlayer->PlaySound(SOUND_PlayGryphonheartsTrumpet,  0, 0, -1, 0, 0, 0, 0);
        return;
      }
      else if ( pParty->pPickedItem.uItemID == 646 ) //Horseshoe
      {
        pGame->pStru6Instance->SetPlayerBuffAnim(SPELL_QUEST_COMPLETED, player_num - 1);
        v5 = PID(OBJECT_Player, player_num + 49);
        pAudioPlayer->PlaySound(SOUND_20001, v5, 0, -1, 0, 0, 0, 0);
        playerAffected->AddVariable(VAR_NumSkillPoints, 2);
      }
      else if ( pParty->pPickedItem.uItemID == 650 ) //Temple in a Bottle
      {
        TeleportToNWCDungeon();
        return;
      }
      else
      {
        v68 = pParty->pPickedItem.GetDisplayName();
        sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[36],v68);//"%s can not be used that way"
        ShowStatusBarString(pTmpBuf.data(), 2u);
        pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
        return;
      }

      pMouse->RemoveHoldingItem();
      return;
  }
}

//----- (00449BB4) --------------------------------------------------------
bool Player::CompareVariable( enum VariableType VarNum, signed int pValue )
{
  Player *v3; // esi@1
  signed int v4; // edi@1
  unsigned int v5; // eax@8
  int v6; // eax@9
  enum CHARACTER_RACE v7; // eax@11
  signed int v8; // eax@17
  unsigned __int8 v9; // sf@17
  unsigned __int8 v10; // of@17
  int v11; // eax@19
  unsigned int v12; // eax@20
  unsigned int test_bit_value; // eax@25
  unsigned __int8 our_bit_value; // cl@25
  signed int v15; // ecx@28
  ItemGen *v16; // eax@28
  char v17; // zf@31
  int v18; // edi@90
  DDM_DLV_Header *v19; // eax@122
  char v20; // cl@124
  DDM_DLV_Header *v21; // eax@126
  unsigned int v22; // edi@129
  Player *v23; // esi@134
  ItemGen *v24; // ecx@135
  signed int v25; // edx@135
  ITEM_EQUIP_TYPE v26; // ebx@155
  char *v27; // edi@155
  int v28; // ebx@161
  int v29; // eax@161

  v6 = 0;
  v3 = this;
  v4 = -1;
  if ( VarNum > VAR_AutoNotes )
  {
    switch ( VarNum )
    {
      case VAR_Invisible:
        if ( pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].uExpireTime >0 )
          return true;
        return false;
      case VAR_NumDeaths:
        v4 = pParty->uNumDeaths;
        return v4 >= pValue;
      case VAR_NumBounties:
        v4 = pParty->uNumBountiesCollected;
        return v4 >= pValue;
      case VAR_PrisonTerms:
        v4 = pParty->uNumPrisonTerms;
        return v4 >= pValue;
      case VAR_ArenaWinsPage:
        v4 = (unsigned __int8)pParty->uNumArenaPageWins;
        return v4 >= pValue;
      case VAR_ArenaWinsSquire:
        v4 = (unsigned __int8)pParty->uNumArenaSquireWins;
        return v4 >= pValue;
      case VAR_ArenaWinsKnight:
        v4 = (unsigned __int8)pParty->uNumArenaKnightWins;
        return v4 >= pValue;
      case VAR_ArenaWinsLord:
        v4 = (unsigned __int8)pParty->uNumArenaLordWins;
        return v4 >= pValue;
      case VAR_ReputationInCurrentLocation:
        v19 = &pOutdoor->ddm;
        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
          v19 = &pIndoor->dlv;
        v6 = v19->uReputation >= pValue;
        return v6;
      case VAR_History_28|VAR_Sex:
        v21 = &pOutdoor->ddm;
        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
          v21 = &pIndoor->dlv;
        v6 = v21->field_C_alert == pValue;
        return v6;
      case VAR_MonthEquals2|VAR_Sex:
      case VAR_MonthEquals2|VAR_Class:
      case VAR_Counter1:
      case VAR_Counter2:
      case VAR_Counter3:
      case VAR_Counter4:
      case VAR_Counter5:
      case VAR_Counter6:
      case VAR_Counter7:
      case VAR_Counter8:
        v22 = *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44304];
        if ( v22 | *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300]
          && (signed __int64)(__PAIR__(v22, *(int *)&stru_AA1058[3].pSounds[8 * VarNum + 44300])
                            + (signed __int64)((double)(460800 * pValue) * 0.033333335)) <= (signed __int64)pParty->uTimePlayed )
          return true;
        return false;
      case VAR_NumSkillPoints:
        v4 = this->uSkillPoints;
        return v4 >= pValue;
      case VAR_CircusPrises:
        v4 = 0;
        v23 = pParty->pPlayers;//[0].pInventoryItems;
        do
        {
          v24 = v23->pInventoryItemList;
          v25 = 138;
          do
          {
            switch ( v24->uItemID )
            {
              case 0x1D6u:
                ++v4;
                break;
              case 0x1D7u:
                v4 += 3;
                break;
              case 0x1DDu:
                v4 += 5;
                break;
            }
            ++v24;
            --v25;
          }
          while ( v25 );
          ++v23;
        }
        while ( v23 <= &pParty->pPlayers[3] );
        return v4 >= pValue;
      case VAR_MonthEquals2:
        v6 = pParty->uCurrentMonth == pValue;
        return v6;
      case VAR_IsFlying:
        if ( pParty->bFlying
          && (pParty->pPartyBuffs[PARTY_BUFF_FLY].uExpireTime> 0) )
          return true;
        return false;
      case VAR_HiredNPCHasSpeciality:
        LOBYTE(v6) = CheckHiredNPCSpeciality(pValue);
        return v6;
      case VAR_NPCs2:
        return pNPCStats->pNewNPCData[pValue].Hired();
      case VAR_MonthEquals|VAR_CurrentSP:
        test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8;
        our_bit_value = this->field_1A50[((signed __int16)pValue - 1)/8];
        if ( !((unsigned __int8)test_bit_value & our_bit_value) )
          return v4 >= pValue;
        v4 = pValue;
        return v4 >= pValue;
      case VAR_ItemEquipped:
        v26 = (ITEM_EQUIP_TYPE)0;
        v27 = (char *)&this->pEquipment;
        break;
      case VAR_GoldInBank:
        v4 = pParty->uNumGoldInBank;
        return v4 >= pValue;
      case VAR_ThieverySkill|0x80:
        v28 = GetActualMight();
        v29 = v3->GetBaseStrength();
        goto LABEL_168;
      case VAR_DisarmTrapSkill|0x80:
        v28 = GetActualIntelligence();
        v29 = v3->GetBaseIntelligence();
        goto LABEL_168;
      case VAR_MonthEquals:
        v28 = GetActualWillpower();
        v29 = v3->GetBaseWillpower();
        goto LABEL_168;
      case VAR_MonthEquals|VAR_Sex:
        v28 = GetActualEndurance();
        v29 = v3->GetBaseEndurance();
        goto LABEL_168;
      case VAR_IdentifyMonsterSkill|0x80:
        v28 = GetActualSpeed();
        v29 = v3->GetBaseSpeed();
        goto LABEL_168;
      case VAR_ArmsmasterSkill|0x80:
        v28 = GetActualAccuracy();
        v29 = v3->GetBaseAccuracy();
        goto LABEL_168;
      case VAR_MonthEquals|VAR_MaxHP:
        v28 = GetActualLuck();
        v29 = v3->GetBaseLuck();
LABEL_168:
        v10 = __OFSUB__(v28, v29);
        v9 = v28 - v29 < 0;
LABEL_169:
        if ( v9 ^ v10 )
          return v4 >= pValue;
        return true;
      default:
        return v4 >= pValue;
    }
    while ( !v3->HasItemEquipped(v26)
         || *(int *)&v3->pInventoryItemList[*(int *)v27-1] != pValue )
    {
      v26 = (ITEM_EQUIP_TYPE)((int)v26 + 1);
      v27 += 4;
      if ( (signed int)v26 >= 16 )
        return false;
    }
    return true;
  }
  if ( VarNum == VAR_AutoNotes )
  {
    test_bit_value = 0x80u >> ((signed __int16)(pValue - 1) - 1) % 8;
    our_bit_value = pParty->_autonote_bits[((signed __int16)(pValue - 1) - 1) /8];
    if ( !((unsigned __int8)test_bit_value & our_bit_value) )
      return false;
    return true;
  }
  if ( VarNum <= VAR_BaseLuck )
  {
    if ( VarNum != VAR_BaseLuck )
    {
      switch ( VarNum )
      {
        case VAR_Hour:
          if ( (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60 % 24 == pValue )
            return true;
          return false;
        case VAR_DayOfYear:
          v5 = (unsigned int)((signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60) / 0x18 % 0x150 + 1;
          v6 = v5 == pValue;
          return v6;
        case VAR_DayOfWeek:
          v5 = (unsigned int)((signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60 / 60) / 0x18 % 7;
          v6 = v5 == pValue;
          return v6;
        case VAR_Sex:
          if ( pValue == (CHARACTER_RACE)this->uSex )
            return true;
          return v4 >= pValue;
        case VAR_Class:
          v7 = (CHARACTER_RACE)this->classType;
          if ( pValue == v7 )
            return true;
          return v4 >= pValue;
        case VAR_Race:
          v7 = GetRace();
          if ( pValue == v7 )
            return true;
          return v4 >= pValue;
        case VAR_CurrentHP:
          v4 = this->sHealth;
          return v4 >= pValue;
        case VAR_MaxHP:
          v8 = GetMaxHealth();
          v10 = __OFSUB__(v3->sHealth, v8);
          v9 = v3->sHealth - v8 < 0;
          goto LABEL_169;
        case VAR_CurrentSP:
          v4 = this->sMana;
          return v4 >= pValue;
        case VAR_MaxSP:
          v11 = GetMaxMana();
          v10 = __OFSUB__(v3->sMana, v11);
          v9 = v3->sMana - v11 < 0;
          goto LABEL_169;
        case VAR_ActualAC:
          v12 = GetActualAC();
          goto _j_cmp_against_arg;
        case VAR_ACModifier:
          v4 = this->sACModifier;
          return v4 >= pValue;
        case VAR_BaseLevel:
          v4 = this->uLevel;
          return v4 >= pValue;
        case VAR_LevelModifier:
          v4 = this->sLevelModifier;
          return v4 >= pValue;
        case VAR_Age:
          v12 = GetActualAge();
          goto _j_cmp_against_arg;
        case VAR_Award:
          test_bit_value = 0x80u >> ((signed __int16)pValue - 1) % 8;
          our_bit_value = this->_achieved_awards_bits[((signed __int16)pValue - 1) /8];
          if ( !((unsigned __int8)test_bit_value & our_bit_value) )
            return true;
          return false;
        case VAR_Experience:
          v4 = LODWORD(this->uExperience);
          return v4 >= pValue;
        case VAR_QBits_QuestsDone:
          test_bit_value = 0x80u >> (pValue - 1) % 8;
          our_bit_value = pParty->_quest_bits[(pValue - 1)/8];
          if ( test_bit_value & our_bit_value )
            return true;
          return false;
        case VAR_PlayerItemInHands:
          v15 = 0;
          v16 = v3->pInventoryItemList;
          break;
        case VAR_FixedGold:
          v4 = pParty->uNumGold;
          return v4 >= pValue;
        case VAR_MightBonus:
          v4 = this->uMightBonus;
          return v4 >= pValue;
        case VAR_IntellectBonus:
          v4 = this->uIntelligenceBonus;
          return v4 >= pValue;
        case VAR_PersonalityBonus:
          v4 = this->uWillpowerBonus;
          return v4 >= pValue;
        case VAR_EnduranceBonus:
          v4 = this->uEnduranceBonus;
          return v4 >= pValue;
        case VAR_SpeedBonus:
          v4 = this->uSpeedBonus;
          return v4 >= pValue;
        case VAR_AccuracyBonus:
          v4 = this->uAccuracyBonus;
          return v4 >= pValue;
        case VAR_LuckBonus:
          v4 = this->uLuckBonus;
          return v4 >= pValue;
        case VAR_BaseMight:
          v4 = this->uMight;
          return v4 >= pValue;
        case VAR_BaseIntellect:
          v4 = this->uIntelligence;
          return v4 >= pValue;
        case VAR_BasePersonality:
          v4 = this->uWillpower;
          return v4 >= pValue;
        case VAR_BaseEndurance:
          v4 = this->uEndurance;
          return v4 >= pValue;
        case VAR_BaseSpeed:
          v4 = this->uSpeed;
          return v4 >= pValue;
        case VAR_BaseAccuracy:
          v4 = this->uAccuracy;
          return v4 >= pValue;
        case VAR_FixedFood:
          v4 = pParty->uNumFoodRations;
          return v4 >= pValue;
        default:
          return v4 >= pValue;
      }
      while ( v16->uItemID != pValue )
      {
        ++v15;
        ++v16;
        if ( v15 >= 138 )
        {
          v6 = pParty->pPickedItem.uItemID == pValue;
          return v6;
        }
      }
      return true;
    }
    v4 = this->uLuck;
      return v4 >= pValue;
  }
  if ( VarNum <= VAR_MagicResistance )
  {
    if ( VarNum == VAR_MagicResistance )
    {
      v4 = this->sResMagicBase;
    }
    else
    {
      switch ( VarNum )
      {
        case VAR_FireResistance:
          v4 = this->sResFireBase;
          return v4 >= pValue;
        case VAR_AirResistance:
          v4 = this->sResAirBase;
          return v4 >= pValue;
        case VAR_WaterResistance:
          v4 = this->sResWaterBase;
          return v4 >= pValue;
        case VAR_EarthResistance:
          v4 = this->sResEarthBase;
          return v4 >= pValue;
        case VAR_SpiritResistance:
          v4 = this->sResSpiritBase;
          return v4 >= pValue;
        case VAR_MindResistance:
          v4 = this->sResMindBase;
          return v4 >= pValue;
        case VAR_BodyResistance:
          v4 = this->sResBodyBase;
          return v4 >= pValue;
        case VAR_LightResistance:
          v4 = this->sResLightBase;
          return v4 >= pValue;
        case VAR_DarkResistance:
          v4 = this->sResDarkBase;
          return v4 >= pValue;
        case VAR_ActualMight:
          v12 = GetActualMight();
          goto _j_cmp_against_arg;
        case VAR_ActualIntellect:
          v12 = GetActualIntelligence();
          goto _j_cmp_against_arg;
        case VAR_ActualPersonality:
          v12 = GetActualWillpower();
          goto _j_cmp_against_arg;
        case VAR_ActualEndurance:
          v12 = GetActualEndurance();
          goto _j_cmp_against_arg;
        case VAR_ActualSpeed:
          v12 = GetActualSpeed();
          goto _j_cmp_against_arg;
        case VAR_ActualAccuracy:
          v12 = GetActualAccuracy();
          goto _j_cmp_against_arg;
        case VAR_ActualLuck:
          v12 = GetActualLuck();
_j_cmp_against_arg:
          v4 = v12;
          break;
        default:
          return v4 >= pValue;
      }
    }
    return v4 >= pValue;
  }
  if ( VarNum <= VAR_DisarmTrapSkill )
  {
    if ( VarNum != VAR_DisarmTrapSkill )
    {
      if ( VarNum <= VAR_MindResistanceBonus )
      {
        switch ( VarNum )
        {
          case VAR_MindResistanceBonus:
            v4 = this->sResMindBonus;
            break;
          case VAR_FireResistanceBonus:
            v4 = this->sResFireBonus;
            break;
          case VAR_AirResistanceBonus:
            v4 = this->sResAirBonus;
            break;
          case VAR_WaterResistanceBonus:
            v4 = this->sResWaterBonus;
            break;
          case VAR_EarthResistanceBonus:
            v4 = this->sResEarthBonus;
            break;
          case VAR_SpiritResistanceBonus:
            v4 = this->sResSpiritBonus;
            break;
        }
        return v4 >= pValue;
      }
      if ( VarNum == VAR_BodyResistanceBonus )
      {
        v4 = this->sResBodyBonus;
        return v4 >= pValue;
      }
      if ( VarNum == VAR_LightResistanceBonus )
      {
        v4 = this->sResLightBonus;
        return v4 >= pValue;
      }
      if ( VarNum == VAR_DarkResistanceBonus )
      {
        v4 = this->sResDarkBonus;
        return v4 >= pValue;
      }
      if ( VarNum == VAR_MagicResistanceBonus )
      {
        v4 = this->sResMagicBonus;
        return v4 >= pValue;
      }
      if ( VarNum <= VAR_MagicResistanceBonus || VarNum > VAR_DiplomacySkill )
        return v4 >= pValue;
    }
LABEL_90:
    v18 = *((short *)&this->pConditions[16] + VarNum);
    if ( pValue <= 63 )
      v4 = v18 & 0x3F;
    else
      v4 = pValue & v18;
    return v4 >= pValue;
  }
  if ( VarNum == 104 )
    goto LABEL_90;
  if ( (signed int)VarNum <= 104 )
    return v4 >= pValue;
  if ( (signed int)VarNum > 0x79 )
  {
    if ( VarNum != 122 )
    {
      if ( (signed int)VarNum > 122 && VarNum <= VAR_ActiveSpells )
        v4 = (unsigned __int8)byte_5E4C15[VarNum];
      return v4 >= pValue;
    }
    v4 = GetMajorConditionIdx();
    if ( v4 != 18 )
    {
      return v4 >= pValue;
    }
    v4 = pValue;
    return v4 >= pValue;
  }
  return &LODWORD(this->pConditions[VarNum]);// *((int *)this + 2 * VarNum - 210);
}


//----- (0044A5CB) --------------------------------------------------------
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
  unsigned int v6; // esi@13
  unsigned int v7; // esi@14
  signed int v8_unused; // eax@17
  ItemGen *v9; // ecx@17
  int v10; // eax@21
  signed int v11; // eax@30
  Player *unused12; // ecx@44
  char *v13; // ecx@45
  Player *v14; // ecx@49
  int v15; // ecx@86
  int v16; // esi@106
  char v17; // al@106
  int v18; // eax@107
  Player *v19; // ecx@112
  Player *v20; // ecx@127
  int v21; // eax@127
  int v22; // eax@145
  char v23; // zf@146
  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
  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);
  if ( var_type > VAR_AutoNotes )
  {
    if ( var_type <= VAR_GoldInBank )
    {
      if ( var_type == VAR_GoldInBank )
      {
        pParty->uNumGoldInBank = var_value;
        return;
      }
      if ( var_type <= VAR_Counter8 )
      {
        if ( (signed int)var_type >= 0xF5 )
        {
          __debugbreak(); //how do I get here?
          *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44300] = LODWORD(pParty->uTimePlayed);
          *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44304] = HIDWORD(pParty->uTimePlayed);
        }
        else
        {
          switch ( var_type )
          {
            case VAR_MonthEquals|VAR_CurrentSP:
              __debugbreak(); //how do I get here?
              _449B7E_toggle_bit((unsigned char *)field_1A50, var_value, 1u);
              break;
            case VAR_NPCs2:
              __debugbreak(); //how do I get here?
              pParty->field_709 = 0;
              LOBYTE(pNPCStats->pNewNPCData[var_value].uFlags) |= 0x80u;
              pParty->CountHirelings();
              viewparams->bRedrawGameUI = true;
              break;
            case VAR_NumSkillPoints:
              this->uSkillPoints = var_value;
              break;
          }
        }
        return;
      }
      if ( var_type < VAR_Counter9 )
        return;
      if ( (signed int)var_type <= 0x112 )
      {
        __debugbreak(); //how do I get here?
        *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44532] = LODWORD(pParty->uTimePlayed);
        *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44536] = HIDWORD(pParty->uTimePlayed);
      }
      else
      {
        if ( var_type == VAR_ReputationInCurrentLocation )
        {
          v24 = &pOutdoor->ddm;
          if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
            v24 = &pIndoor->dlv;
          v24->uReputation = var_value;
          if ( var_value > 10000 )
            v24->uReputation = 10000;
          return;
        }
        if ( var_type <= VAR_ReputationInCurrentLocation
          || var_type > VAR_History_28
          || (v22 = var_type - 276, pParty->field_3C.field_4F0[2 * v22 + 1] | pParty->field_3C.field_4F0[2 * v22])
          || (pParty->field_3C.field_4F0[2 * (var_type - 276)] = LODWORD(pParty->uTimePlayed),
              v23 = pStorylineText->StoreLine[v22].pText == 0,//*(&pStorylineText->field_0 + 3 * v22) == 0,
              pParty->field_3C.field_4F0[2 * (var_type - 276) + 1] = HIDWORD(pParty->uTimePlayed),
              v23) )
              __debugbreak(); //how do I get here?
          return;
        bFlashHistoryBook = 1;
      }
      v25 = 8 * currPlayerId + 400;
      LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
      pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
      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 == 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 )
    {
      v20 = pPlayers[currPlayerId + 1];
      v20->PlaySound(SPEECH_96, 0);
	  //v21 = pAutonoteTxt[var_value].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 )
        {
          v9 = NULL;
          for (int i = 0; i < 138; i++)
          {
            v9 = &this->pInventoryItemList[i];
            if (v9->uItemID == ITEM_LICH_JAR_EMPTY)
              break;
          }
          if (v9 != NULL && v9->uItemID != ITEM_LICH_JAR_EMPTY)
          {
            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 )
            this->sResAirBase = 20;
          if ( this->sResWaterBase < 20 )
            this->sResWaterBase = 20;
          if ( this->sResEarthBase < 20 )
            this->sResEarthBase = 20;
          this->sResMindBase = 200;
          this->sResBodyBase = 200;
          v11 = this->GetSexByVoice();
          this->uPrevVoiceID = this->uVoiceID;
          this->uPrevFace = this->uCurrentFace;
          if ( v11 )
          {
            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) & 
			  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] )
          {
          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;
    }
LABEL_111:
    v26 = SPEECH_91;
LABEL_112:
    v19 = pPlayers[currPlayerId + 1];
    v19->PlaySound((PlayerSpeech)v26, 0);
    DrawPlayerBuffAnimBasedOnCondition(currPlayerId);
    PlaySoundBasedOnCondition(currPlayerId);
    return;
  }
  if ( var_type <= VAR_MagicResistance )
  {
    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;
        goto LABEL_111;
      case VAR_ActualPersonality:
LABEL_69:
        this->uWillpowerBonus = (unsigned __int8)var_value;
        goto LABEL_111;
      case VAR_ActualEndurance:
LABEL_70:
        this->uEnduranceBonus = (unsigned __int8)var_value;
        goto LABEL_111;
      case VAR_ActualSpeed:
LABEL_71:
        this->uSpeedBonus = (unsigned __int8)var_value;
        goto LABEL_111;
      case VAR_ActualAccuracy:
LABEL_72:
        this->uAccuracyBonus = (unsigned __int8)var_value;
        goto LABEL_111;
      case VAR_ActualLuck:
LABEL_73:
        this->uLuckBonus = (unsigned __int8)var_value;
        goto LABEL_111;
      case VAR_FireResistance:
        this->sResFireBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_AirResistance:
        this->sResAirBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_WaterResistance:
        this->sResWaterBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_EarthResistance:
        this->sResEarthBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_SpiritResistance:
        this->sResSpiritBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_MindResistance:
        this->sResMindBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_BodyResistance:
        this->sResBodyBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_LightResistance:
        this->sResLightBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_DarkResistance:
        this->sResDarkBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      case VAR_MagicResistance:
        this->sResMagicBase = (unsigned __int8)var_value;
        v26 = 92;
        goto LABEL_112;
      default:
        return;
    }
    return;
  }
  HIWORD(v15) = 0;
  if ( var_type > VAR_DisarmTrapSkill )
  {
    if ( var_type != VAR_LearningSkill )
    {
      if ( var_type <= VAR_LearningSkill )
        return;
      if ( var_type <= VAR_Eradicated )
      {
        this->SetCondition(var_type - 105, 1);
      }
      else
      {
        if ( var_type != VAR_MajorCondition )
        {
          if ( var_type > VAR_MajorCondition && var_type <= VAR_ActiveSpells )
            byte_5E4C15[var_type] = var_value;
          return;
        }
        memset(this, 0, 0xA0u);
      }
    }
    else
    {
      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 )
    {
      case VAR_FireResistanceBonus:
        this->sResFireBonus = (unsigned __int8)var_value;
        break;
      case VAR_AirResistanceBonus:
        this->sResAirBonus = (unsigned __int8)var_value;
        break;
      case VAR_WaterResistanceBonus:
        this->sResWaterBonus = (unsigned __int8)var_value;
        break;
      case VAR_EarthResistanceBonus:
        this->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;
        break;
      default:
          Error("Unexpected var_type: %u", var_type);
          return;
        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;
  }
}


//----- (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)
{
  char v3; // bl@1
  Player *v4; // esi@1
  signed int uPlayerIdx; // edi@1
  int v6; // eax@15
  unsigned int v7; // esi@18
  int *v8; // ebx@21
  int v9; // eax@22
  signed int v10; // eax@24
  int v11; // eax@27
  __int16 *v12; // esi@28
  Player *v13; // ecx@34
  Player *v14; // ecx@36
  char *v15; // ecx@37
  unsigned __int8 v16; // cf@38
  Player *v17; // ecx@42
  __int16 *v18; // esi@53
  __int16 *v19; // esi@62
  char *v20; // esi@107
  __int16 v21; // dx@107
  int v22; // ecx@107
  Player *v23; // ecx@132
  int v24; // eax@132
  int v25; // eax@150
  char v26; // zf@151
  DDM_DLV_Header *v27; // eax@153
  signed int v28; // eax@176
  int v29; // [sp-8h] [bp-40h]@84
 // signed int v30; // [sp-4h] [bp-3Ch]@4
  int v31; // [sp-4h] [bp-3Ch]@84
  ItemGen item; // [sp+Ch] [bp-2Ch]@45
  unsigned int v33; // [sp+30h] [bp-8h]@34
  char v34; // [sp+37h] [bp-1h]@1

  auto Dst = this;
  v3 = 0;
  v34 = 0;
  v4 = Dst;
  uPlayerIdx = 0;
  if ( Dst == pPlayers[2] )
    uPlayerIdx = 1;
  else if ( Dst == pPlayers[3] )
    uPlayerIdx = 2;
  else if ( Dst == pPlayers[4] )  
    uPlayerIdx = 3;
 
  if ( var_type <= VAR_AutoNotes )
  {
    if ( var_type != VAR_AutoNotes )
    {
      if ( var_type <= VAR_ActualMight )
      {
        if ( var_type != VAR_ActualMight )
        {
          switch ( var_type )
          {
            case VAR_RandomGold:
              if ( !val )
                val = 1;
              v6 = rand();
              party_finds_gold(v6 % val + 1, 1);
              GameUI_DrawFoodAndGold();
              return;
            case VAR_RandomFood:
              if ( !val )
                val = 1;
              v7 = rand() % val + 1;
              Party::GiveFood(v7);
              sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[502], v7);// You find %lu food
              ShowStatusBarString(pTmpBuf.data(), 2u);
              GameUI_DrawFoodAndGold();
              goto _play_sound;
            case VAR_Sex:
              Dst->uSex = (PLAYER_SEX)val;
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            case VAR_Class:
              Dst->classType = (PLAYER_CLASS_TYPE)val;
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            case VAR_CurrentHP:
              v8 = &Dst->sHealth;
              *v8 += val;
              if ( Dst->sHealth <= Dst->GetMaxHealth() )
              {
                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
                goto _play_sound;
              }
              v9 = v4->GetMaxHealth();
              goto LABEL_23;
            case VAR_MaxHP:
              v10 = Dst->GetMaxHealth();
              v4->_health_related = 0;
              v4->uFullHealthBonus = 0;
              v4->sHealth = v10;
              return;
            case VAR_CurrentSP:
              v8 = &Dst->sMana;
              *v8 += val;
              if ( Dst->sMana > GetMaxMana() )
              {
                v9 = v4->GetMaxMana();
LABEL_23:
                *v8 = v9;
              }
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            case VAR_MaxSP:
              v11 = GetMaxMana();
              v4->_mana_related = 0;
              v4->uFullManaBonus = 0;
              v4->sMana = v11;
              return;
            case VAR_ACModifier:
              v12 = &Dst->sACModifier;
              goto LABEL_29;
            case VAR_BaseLevel:
              v12 = (__int16 *)&Dst->uLevel;
              goto LABEL_29;
            case VAR_LevelModifier:
              v12 = &Dst->sLevelModifier;
LABEL_29:
              *v12 += val;
              if ( *v12 > 255 )
                *v12 = 255;
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            case VAR_Age:
              Dst->sAgeModifier += val;
              return;
            case VAR_Award:
              v13 = pPlayers[uPlayerIdx + 1];
              if (_449B57_test_bit((unsigned __int8 *)pPlayers[uPlayerIdx + 1]->_achieved_awards_bits, val) 
             
				&& pAwards[val].pText )
              {
                v14 = pPlayers[uPlayerIdx + 1];
                v34 = 1;
                v3 = 1;
                v14->PlaySound(SPEECH_96, 0);
              }
              v15 = (char *)v4->_achieved_awards_bits;
              _449B7E_toggle_bit((unsigned char *)v15, val, 1);
              if ( v34 != 1 )
              {
                if ( v3 != 1 )
                  return;
                goto _play_sound;
              }
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              if ( v3 != 1 )
                return;
              goto _play_sound;
            case VAR_Experience:
              v16 = __CFADD__(val, LODWORD(Dst->uExperience));
              LODWORD(Dst->uExperience) += val;
              HIDWORD(Dst->uExperience) += ((unsigned __int64)val >> 32) + v16;
              if ( (signed __int64)Dst->uExperience > 4000000000i64 )
                Dst->uExperience = 4000000000i64;
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            case VAR_QBits_QuestsDone:
              if ( !((unsigned __int8)(0x80u >> ((signed __int16)val - 1) % 8) & pParty->_quest_bits[((signed __int16)val - 1) >> 3])
                //&& (&dword_722F10)[4 * val] )
				&& pQuestTable[val] )
              {
                //v17 = pPlayers[uPlayerIdx + 1];
                bFlashQuestBook = 1;
                v34 = 1;
                v3 = 1;
                pPlayers[uPlayerIdx + 1]->PlaySound(SPEECH_93, 0);
              }
              v15 = (char *)pParty->_quest_bits;
              _449B7E_toggle_bit((unsigned char *)v15, val, 1);
              if ( v34 != 1 )
              {
                if ( v3 != 1 )
                  return;
                goto _play_sound;
              }
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              if ( v3 != 1 )
                return;
              goto _play_sound;
            case VAR_PlayerItemInHands:
              item.Reset();
              item.Reset();
              item.uAttributes = 1;
              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 )
              {
                item.uNumCharges = rand() % 6 + pItemsTable->pItems[item.uItemID].uDamageMod + 1;
                item.uMaxCharges = LOBYTE(item.uNumCharges);
              }
              pParty->SetHoldingItem(&item);
              return;
            case VAR_FixedGold:
              party_finds_gold(val, 1);
              return;
            case VAR_BaseMight:
              v18 = (__int16 *)&Dst->uMight;
              goto LABEL_82;
            case VAR_BaseIntellect:
              v18 = (__int16 *)&Dst->uIntelligence;
              goto LABEL_82;
            case VAR_BasePersonality:
              v18 = (__int16 *)&Dst->uWillpower;
              goto LABEL_82;
            case VAR_BaseEndurance:
              v18 = (__int16 *)&Dst->uEndurance;
              goto LABEL_82;
            case VAR_BaseSpeed:
              v18 = (__int16 *)&Dst->uSpeed;
              goto LABEL_82;
            case VAR_BaseAccuracy:
              v18 = (__int16 *)&Dst->uAccuracy;
              goto LABEL_82;
            case VAR_BaseLuck:
              v18 = (__int16 *)&Dst->uLuck;
              goto LABEL_82;
            case VAR_FixedFood:
              Party::GiveFood(val);
              sprintfex(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[502], val);
              ShowStatusBarString(pTmpBuf.data(), 2u);
              if ( pParty->uNumFoodRations > 0xFFFF )
                Party::SetFood(0xFFFFu);
              goto _play_sound;
            case VAR_MightBonus:
              goto LABEL_62;
            case VAR_IntellectBonus:
              goto LABEL_66;
            case VAR_PersonalityBonus:
              goto LABEL_67;
            case VAR_EnduranceBonus:
              goto LABEL_68;
            case VAR_SpeedBonus:
              goto LABEL_69;
            case VAR_AccuracyBonus:
              goto LABEL_70;
            case VAR_LuckBonus:
              goto LABEL_71;
            default:
              return;
          }
          return;
        }
LABEL_62:
        v19 = (__int16 *)&Dst->uMightBonus;
        goto LABEL_113;
      }
      if ( var_type <= VAR_FireResistanceBonus )
      {
        if ( var_type != VAR_FireResistanceBonus )
        {
          switch ( var_type )
          {
            case VAR_ActualIntellect:
LABEL_66:
              v19 = (__int16 *)&Dst->uIntelligenceBonus;
              goto LABEL_113;
            case VAR_ActualPersonality:
LABEL_67:
              v19 = (__int16 *)&Dst->uWillpowerBonus;
              goto LABEL_113;
            case VAR_ActualEndurance:
LABEL_68:
              v19 = (__int16 *)&Dst->uEnduranceBonus;
              goto LABEL_113;
            case VAR_ActualSpeed:
LABEL_69:
              v19 = (__int16 *)&Dst->uSpeedBonus;
              goto LABEL_113;
            case VAR_ActualAccuracy:
LABEL_70:
              v19 = (__int16 *)&Dst->uAccuracyBonus;
              goto LABEL_113;
            case VAR_ActualLuck:
LABEL_71:
              v19 = (__int16 *)&Dst->uLuckBonus;
              goto LABEL_113;
            case VAR_FireResistance:
              v18 = &Dst->sResFireBase;
              goto LABEL_82;
            case VAR_AirResistance:
              v18 = &Dst->sResAirBase;
              goto LABEL_82;
            case VAR_WaterResistance:
              v18 = &Dst->sResWaterBase;
              goto LABEL_82;
            case VAR_EarthResistance:
              v18 = &Dst->sResEarthBase;
              goto LABEL_82;
            case VAR_SpiritResistance:
              v18 = &Dst->sResSpiritBase;
              goto LABEL_82;
            case VAR_MindResistance:
              v18 = &Dst->sResMindBase;
              goto LABEL_82;
            case VAR_BodyResistance:
              v18 = &Dst->sResBodyBase;
              goto LABEL_82;
            case VAR_LightResistance:
              v18 = &Dst->sResLightBase;
              goto LABEL_82;
            case VAR_DarkResistance:
              v18 = &Dst->sResDarkBase;
              goto LABEL_82;
            case VAR_MagicResistance:
              v18 = &Dst->sResMagicBase;
LABEL_82:
              *v18 += val;
              if ( *v18 > 255 )
                *v18 = 255;
              pPlayers[uPlayerIdx + 1]->PlaySound(SPEECH_92, 0);
              pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
              goto _play_sound;
            default:
              return;
          }
          return;
        }
        v19 = &Dst->sResFireBonus;
LABEL_113:
        *v19 += val;
        if ( *v19 > 255 )
          *v19 = 255;
        v31 = 0;
        v29 = SPEECH_91;
        pPlayers[uPlayerIdx + 1]->PlaySound((PlayerSpeech)v29, v31);
        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
        goto _play_sound;
      }
      if ( var_type <= VAR_DisarmTrapSkill )
      {
        if ( var_type != VAR_DisarmTrapSkill )
        {
          if ( var_type <= VAR_BodyResistanceBonus )
          {
            switch ( var_type )
            {
              case VAR_BodyResistanceBonus:
                v19 = &Dst->sResBodyBonus;
                break;
              case VAR_AirResistanceBonus:
                v19 = &Dst->sResAirBonus;
                break;
              case VAR_WaterResistanceBonus:
                v19 = &Dst->sResWaterBonus;
                break;
              case VAR_EarthResistanceBonus:
                v19 = &Dst->sResEarthBonus;
                break;
              case VAR_SpiritResistanceBonus:
                v19 = &Dst->sResSpiritBonus;
                break;
              default:
                if ( var_type != 62 )
                  return;
                v19 = &Dst->sResMindBonus;
                break;
            }
            goto LABEL_113;
          }
          if ( var_type == VAR_LightResistanceBonus )
          {
            v19 = &Dst->sResLightBonus;
            goto LABEL_113;
          }
          if ( var_type == VAR_DarkResistanceBonus )
          {
            v19 = &Dst->sResDarkBonus;
            goto LABEL_113;
          }
          if ( var_type == VAR_MagicResistanceBonus )
          {
            v19 = &Dst->sResMagicBonus;
            goto LABEL_113;
          }
          if ( var_type <= VAR_MagicResistanceBonus || var_type > VAR_DiplomacySkill )
            return;
        }
        goto LABEL_106;
      }
      if ( var_type == VAR_LearningSkill )
      {
LABEL_106:
        if ( val <= VAR_BodyResistanceBonus )
        {
          *((short *)&Dst->pConditions[16] + var_type) = (unsigned __int8)val | *((char *)&Dst->pConditions[16] + 2 * var_type) & VAR_BodyResistanceBonus;
        }
        else
        {
          v20 = (char *)&Dst->pConditions[16] + 2 * var_type;
          v21 = *(short *)v20;
          v22 = (unsigned __int8)val + (v21 & VAR_BodyResistanceBonus);
          if ( v22 > 60 )
            LOWORD(v22) = 60;
          LOBYTE(v21) = v21 & 0xC0;
          *(short *)v20 = v22 | v21;
        }
        pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
        goto _play_sound;
      }
      if ( var_type <= VAR_LearningSkill )
        return;
      if ( var_type <= VAR_Eradicated )
      {
        Dst->SetCondition(var_type - 105, 0);
      }
      else
      {
        if ( var_type != VAR_MajorCondition )
        {
          if ( var_type > VAR_MajorCondition && var_type <= VAR_ActiveSpells )
          {
            if ( (unsigned __int8)val + (unsigned __int8)byte_5E4C15[var_type] <= 255 )
              byte_5E4C15[var_type] += val;
            else
              byte_5E4C15[var_type] = -1;
          }
          return;
        }
        memset(Dst, 0, 0xA0u);
      }
      pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
      goto _play_sound;
    }
    if ( !((unsigned __int8)(0x80u >> ((signed __int16)val - 1) % 8) & pParty->_autonote_bits[((signed __int16)val - 1) >> 3])
      //&& (&dword_723718_autonote_related)[8 * val] )
	  && pAutonoteTxt[val].pText )
    {
      v23 = pPlayers[uPlayerIdx + 1];
      v34 = 1;
      v23->PlaySound(SPEECH_96, 0);
	  //v24 = pAutonoteTxt[val].eType;//dword_72371C[2 * val];
      bFlashAutonotesBook = 1;
      _506568_autonote_type = pAutonoteTxt[val].eType;
    }
    _449B7E_toggle_bit(pParty->_autonote_bits, val, 1);
    v3 = 1;
    if ( v34 != 1 )
    {
      if ( v3 != 1 )
        return;
      goto _play_sound;
    }
    pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
    if ( v3 != 1 )
      return;
    goto _play_sound;
  }
  if ( var_type > VAR_GoldInBank )
  {
    if ( var_type == 307 )
    {
      pParty->uNumDeaths += val;
      if ( v34 != 1 )
      {
        if ( v3 != 1 )
          return;
        goto _play_sound;
      }
      pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
      if ( v3 != 1 )
        return;
      goto _play_sound;
    }
    switch ( var_type )
    {
      case 308:
        pParty->uNumBountiesCollected += val;
        break;
      case 309:
        pParty->uNumPrisonTerms += val;
        break;
      case 310:
        pParty->uNumArenaPageWins += val;
        break;
      case 311:
        pParty->uNumArenaSquireWins += val;
        break;
      case 312:
        pParty->uNumArenaKnightWins += val;
        break;
      case 313:
        pParty->uNumArenaLordWins += val;
        break;
    }
  }
  else
  {
    if ( var_type == VAR_GoldInBank )
    {
      pParty->uNumGoldInBank += val;
      return;
    }
    if ( var_type <= VAR_Counter8 )
    {
      if ( (signed int)var_type >= 245 )
      {
        *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44300] = LODWORD(pParty->uTimePlayed);
        *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44304] = HIDWORD(pParty->uTimePlayed);
      }
      else
      {
        switch ( var_type )
        {
          case VAR_MonthEquals|VAR_CurrentSP:
            _449B7E_toggle_bit((unsigned char *)Dst->field_1A50, val, 1u);
            break;
          case VAR_NPCs2:
            pParty->field_709 = 0;
            LOBYTE(pNPCStats->pNewNPCData[val].uFlags) |= 0x80u;
            pParty->CountHirelings();
            viewparams->bRedrawGameUI = true;
            break;
          case VAR_NumSkillPoints:
            Dst->uSkillPoints += val;
            break;
        }
      }
      return;
    }
    if ( var_type < VAR_Counter9 )
      return;
    if ( (signed int)var_type <= 274 )
    {
      *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44532] = LODWORD(pParty->uTimePlayed);
      *(int *)&stru_AA1058[3].pSounds[8 * var_type + 44536] = HIDWORD(pParty->uTimePlayed);
      goto _play_sound;
    }
    if ( var_type != VAR_ReputationInCurrentLocation )
    {
      if ( var_type <= VAR_ReputationInCurrentLocation
        || var_type > VAR_History_28
        || (v25 = var_type - 276, pParty->field_3C.field_4F0[2 * v25 + 1] | pParty->field_3C.field_4F0[2 * v25])
        || (pParty->field_3C.field_4F0[2 * (var_type - 276)] = LODWORD(pParty->uTimePlayed),
            v26 = pStorylineText->StoreLine[v25].pText==0,//*(&pStorylineText->field_0 + 3 * v25) == 0,
            pParty->field_3C.field_4F0[2 * (var_type - 276) + 1] = HIDWORD(pParty->uTimePlayed),
            v26) )
        return;
      bFlashHistoryBook = 1;
_play_sound:
      v28 = 8 * uPlayerIdx + 400;
      LOBYTE(v28) = PID(OBJECT_Player,uPlayerIdx - 112);
      pAudioPlayer->PlaySound(SOUND_20001, v28, 0, -1, 0, 0, 0, 0);
      return;
    }
    v27 = &pOutdoor->ddm;
    if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
      v27 = &pIndoor->dlv;
    v27->uReputation += val;
    if ( v27->uReputation > 10000 )
      v27->uReputation = 10000;
  }
}


//----- (0044B9C4) --------------------------------------------------------
bool Player::SubtractVariable(enum VariableType VarNum, signed int pValue)
{
  unsigned int v3; // ebx@1
  signed int v4; // esi@1
  bool result; // eax@8
  int v6; // esi@11
  int v7; // edi@14
  signed int v8; // eax@17
  char *v9; // eax@20
  char v10; // sf@20
  char *v11; // ecx@26
  char *v12; // ecx@27
  __int64 v13; // qax@27
  unsigned __int8 v14; // cf@27
  int *v15; // edx@29
  char *v16; // eax@90
  char *v17; // ecx@94
  int v18; // esi@97
  signed int v19; // edx@97
  char *v20; // ecx@98
  int v21; // eax@100
  __int16 v22; // dx@112
  int v23; // [sp-8h] [bp-14h]@45
  signed int v24; // [sp-4h] [bp-10h]@4
  int v25; // [sp-4h] [bp-10h]@45

  v3 = 0;
  v4 = uActiveCharacter - 1;
  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)pValue - 1;
      }
      else
      {
        if ( VarNum != 231 )
        {
          switch ( VarNum )
          {
            case 232:
              VarNum = (VariableType)0;
              GetNewNPCData(sDialogue_SpeakingActorNPC_ID, (int*)&VarNum);
              result = (bool) pValue;
			  dword_5B65CC = 0;
              if ( (int)VarNum == pValue )
              {
                dword_5B65CC = (int)pValue;
              }
              else
              {
                pParty->field_709 = 0;
                LOBYTE(pNPCStats->pNewNPCData[(int)pValue].uFlags) &= 0x7Fu;
                pParty->CountHirelings();
                viewparams->bRedrawGameUI = true;
              }
              break;
            case 241:
              if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
              {
                v20 = (char *)&pNPCStats->pNewNPCData[0].uFlags;
                for ( v19 = 0; v19 < (signed int)pNPCStats->uNumNewNPCs; ++v19 )
                {
                  if ( *((void **)v20 + 4) == (void *)pValue )
                  {
                    v21 = *(int *)v20;
                    if ( (char)*(int *)v20 < 0 )
                    {
                      LOBYTE(v21) = v21 & 0x7F;
                      *(int *)v20 = v21;
                    }
                  }
                  v20 += 76;
                }
              }
              if ( pParty->pHirelings[0].uProfession == pValue )
                memset(pParty->pHirelings, 0, 0x4Cu);
              if ( pParty->pHirelings[1].uProfession == pValue )
                memset(&pParty->pHirelings[1], 0, 0x4Cu);
              pParty->field_709 = 0;
              pParty->CountHirelings();
              break;
            case 243:
              v17 = (char *)&this->uSkillPoints;
			  result = *v17 != NULL;
              if ( (unsigned int)pValue <= *(int *)v17 )
              {
					*(int *)v17 -= (int)pValue;
					result = (v17 != NULL);
			  }
              else
                *(int *)v17 = 0;
              break;
            case 275:
              v16 = (char *)&pOutdoor->ddm;
              if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor )
                v16 = (char *)&pIndoor->dlv;
              *((int *)v16 + 2) -= (int)pValue;
              if ( *((int *)v16 + 2) < -10000 )
                *((int *)v16 + 2) = -10000;
              break;
            case 306:
				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 result;
        }
        v11 = this->field_1A50;
        v22 = (signed __int16)pValue;
      }
      _449B7E_toggle_bit((unsigned char *)v11, v22, 0);
      return result;
    }
    switch ( VarNum )
    {
      case 308:
		  result = (bool)pValue;
        pParty->uNumBountiesCollected -= (unsigned int)pValue;
        break;
      case 309:
		  result = (bool)pValue;
        pParty->uNumPrisonTerms -= (int)pValue;
        break;
      case 310:
		  result = (bool)pValue;
        pParty->uNumArenaPageWins -= (char)pValue;
        break;
      case 311:
		  result = (bool)pValue;
        pParty->uNumArenaSquireWins -= (char)pValue;
        break;
      case 312:
		  result = (bool)pValue;
        pParty->uNumArenaKnightWins -= (char)pValue;
        break;
      case 313:
		  result = (bool)pValue;
        pParty->uNumArenaLordWins -= (char)pValue;
        break;
    }
    Error("Function not returning any value! (%u)", VarNum);
  }
  else
  {
    if ( (signed int)VarNum >= 123 )
    {
      byte_5E4C15[VarNum] -= (char)pValue;
    }
    else
    {
      switch ( VarNum )
      {
        case VAR_RandomGold:
          v6 = rand() % (signed int)pValue + 1;
          if ( v6 > pParty->uNumGold )
            v6 = pParty->uNumGold;
          Party::TakeGold(v6);
          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[503], v6);
          ShowStatusBarString(pTmpBuf.data(), 2);
          GameUI_DrawFoodAndGold();
          return result;
        case VAR_RandomFood:
          v7 = rand() % (signed int)pValue + 1;
          if ( v7 > pParty->uNumFoodRations )
            v7 = pParty->uNumFoodRations;
          Party::TakeFood(v7);
          sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[504], v7);
          ShowStatusBarString(pTmpBuf.data(), 2u);
          GameUI_DrawFoodAndGold();
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_CurrentHP:
          ReceiveDamage((signed int)pValue, DMGT_PHISYCAL);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_CurrentSP:
          v9 = (char *)&this->sMana;
          v10 = this->sMana - (signed int)pValue < 0;
          *(int *)v9 -= (int)pValue;
          if ( v10 )
            *(int *)v9 = 0;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_ACModifier:
          this->sACModifier -= (unsigned __int8)pValue;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseLevel:
          this->uLevel -= (unsigned __int8)pValue;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_LevelModifier:
          this->sLevelModifier -= (unsigned __int8)pValue;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_Age:
          this->sAgeModifier -= (signed __int16)pValue;
          return result;
        case VAR_Award:
          _449B7E_toggle_bit((unsigned char *)this->_achieved_awards_bits, (signed __int16)pValue, 0);
          return result;
        case VAR_Experience:
          v12 = (char *)&this->uExperience;
          v13 = (signed int)pValue;
          v14 = *(int *)v12 < (unsigned int)pValue;
          *(int *)v12 -= (int)pValue;
          *((int *)v12 + 1) -= v14 + HIDWORD(v13);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_QBits_QuestsDone:
          _449B7E_toggle_bit(pParty->_quest_bits, (__int16)pValue, 0);
          pPlayers[v4 + 1]->PlaySound(SPEECH_96, 0);
          return true;
        case VAR_PlayerItemInHands:
          v15 = this->pInventoryMatrix;
          break;
        case VAR_FixedGold:
          if ( (unsigned int)pValue > pParty->uNumGold )
            goto LABEL_88;
          Party::TakeGold((unsigned int)pValue);
          return result;
        case VAR_MightBonus:
        case VAR_ActualMight:
          this->uMightBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_IntellectBonus:
        case VAR_ActualIntellect:
          this->uIntelligenceBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_PersonalityBonus:
        case VAR_ActualPersonality:
          this->uWillpowerBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_EnduranceBonus:
        case VAR_ActualEndurance:
          this->uEnduranceBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_SpeedBonus:
        case VAR_ActualSpeed:
          this->uSpeedBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_AccuracyBonus:
        case VAR_ActualAccuracy:
          this->uAccuracyBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_LuckBonus:
        case VAR_ActualLuck:
          this->uLuckBonus -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseMight:
          this->uMight -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseIntellect:
          this->uIntelligence -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BasePersonality:
          this->uWillpower -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseEndurance:
          this->uEndurance -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseSpeed:
          this->uSpeed -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseAccuracy:
          this->uAccuracy -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BaseLuck:
          this->uLuck -= (unsigned __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_FireResistance:
          this->sResFireBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_AirResistance:
          this->sResAirBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_WaterResistance:
          this->sResWaterBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_EarthResistance:
          this->sResEarthBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_SpiritResistance:
          this->sResSpiritBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_MindResistance:
          this->sResMindBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BodyResistance:
          this->sResBodyBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_LightResistance:
          this->sResLightBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_DarkResistance:
          this->sResDarkBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_MagicResistance:
          this->sResMagicBase -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_FireResistanceBonus:
          this->sResFireBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_AirResistanceBonus:
          this->sResAirBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)92, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_WaterResistanceBonus:
          this->sResWaterBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_EarthResistanceBonus:
          this->sResEarthBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_SpiritResistanceBonus:
          this->sResSpiritBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_MindResistanceBonus:
          this->sResMindBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_BodyResistanceBonus:
          this->sResBodyBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_LightResistanceBonus:
          this->sResLightBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_DarkResistanceBonus:
          this->sResDarkBonus -= (signed __int16)pValue;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)SPEECH_91, 0);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_MagicResistanceBonus:
          this->sResMagicBonus -= (signed __int16)pValue;
          v25 = 0;
          v23 = SPEECH_91;
          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)v23, v25);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_FixedFood:
          Party::TakeFood((unsigned int)pValue);
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_StaffSkill:
        case VAR_SwordSkill:
        case VAR_DaggerSkill:
        case VAR_AxeSkill:
        case VAR_SpearSkill:
        case VAR_BowSkill:
        case VAR_MaceSkill:
        case VAR_BlasterSkill:
        case VAR_ShieldSkill:
        case VAR_LeatherSkill:
        case VAR_SkillChain:
        case VAR_PlateSkill:
        case VAR_FireSkill:
        case VAR_AirSkill:
        case VAR_WaterSkill:
        case VAR_EarthSkill:
        case VAR_SpiritSkill:
        case VAR_MindSkill:
        case VAR_BodySkill:
        case VAR_LightSkill:
        case VAR_DarkSkill:
        case VAR_IdentifyItemSkill:
        case VAR_MerchantSkill:
        case VAR_RepairSkill:
        case VAR_BodybuildingSkill:
        case VAR_MeditationSkill:
        case VAR_PerceptionSkill:
        case VAR_DiplomacySkill:
        case VAR_DisarmTrapSkill:
        case VAR_LearningSkill:
          *((short *)&this->pConditions[16] + VarNum) -= (unsigned __int8)pValue;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        case VAR_Cursed:
        case VAR_Weak:
        case VAR_Asleep:
        case VAR_Afraid:
        case VAR_Drunk:
        case VAR_Insane:
        case VAR_PoisonedGreen:
        case VAR_DiseasedGreen:
        case VAR_PoisonedYellow:
        case VAR_DiseasedYellow:
        case VAR_PoisonedRed:
        case VAR_DiseasedRed:
        case VAR_Paralyzed:
        case VAR_Unconsious:
        case VAR_Dead:
        case VAR_Stoned:
        case VAR_Eradicated:
          //*((int *)this + 2 * VarNum - 210) = 0;
		  //*((int *)this + 2 * result - 209) = 0;
		  this->pConditions[VarNum] = 0;
          pGame->pStru6Instance->SetPlayerBuffAnim(0x98u, v4);
          v8 = 8 * v4 + 400;
          LOBYTE(v8) = PID(OBJECT_Player,v4 - 112);
          pAudioPlayer->PlaySound(SOUND_20001, v8, 0, -1, 0, 0, 0, 0);
          return result;
        default:
          return result;
      }
      for (v3 = 1; v3 < 126; v3++)
      {
        if ( *(&this->pInventoryItemList[pInventoryMatrix[v3] - 1].uItemID) == pValue )
        {
          RemoveItemAtInventoryIndex(v3);
          return true;
        }
      }
      if ( pParty->pPickedItem.uItemID == pValue )
      {
        pMouse->RemoveHoldingItem();
        return true;
      }
      return false;
    }
  }

  //assert(false);
  return false;
}
// 5B65C4: using guessed type int dword_5B65C4;
// 5B65CC: using guessed type int dword_5B65CC;


//----- (00467E7F) --------------------------------------------------------
void Player::EquipBody(ITEM_EQUIP_TYPE uEquipType)
{
  int v2; // ebx@1
  Player *v3; // eax@1
  int v4; // edx@1
  int v7; // eax@3
  ItemGen tempPickedItem; // [sp+Ch] [bp-30h]@1
  unsigned int *v11; // [sp+38h] [bp-4h]@1

  tempPickedItem.Reset();
  v2 = pEquipTypeToBodyAnchor[uEquipType];
  v3 = pPlayers[uActiveCharacter];
  v11 = &v3->pEquipment.pIndices[v2];
  v4 = *v11;
  if ( v4 )
  {
    memcpy(&tempPickedItem, &pParty->pPickedItem, sizeof(tempPickedItem));
    v3->pInventoryItemList[v4 - 1].uBodyAnchor = 0;
    pParty->pPickedItem.Reset();
    pParty->SetHoldingItem(&v3->pInventoryItemList[v4 - 1]);
    tempPickedItem.uBodyAnchor = v2 + 1;
    memcpy(&v3->pInventoryItemList[v4 - 1], &tempPickedItem, sizeof(ItemGen));
    *v11 = v4;
  }
  else
  {
    v7 = v3->FindFreeInventoryListSlot();
    if (v7 >= 0)
    {
      pParty->pPickedItem.uBodyAnchor = v2 + 1;
      memcpy(&v3->pInventoryItemList[v7], &pParty->pPickedItem, sizeof(ItemGen));
      *v11 = v7 + 1;
      pMouse->RemoveHoldingItem();
    }
  }
}


//----- (0049387A) --------------------------------------------------------
int CycleCharacter(bool backwards)
{
  const int PARTYSIZE = 4;
  int valToAdd = backwards ? (PARTYSIZE - 2) : 0;
  int mult = backwards ? -1 : 1;

  for (int i = 0; i < (PARTYSIZE - 1); i++)
  {
    int currCharId = ((uActiveCharacter + mult * i + valToAdd) % PARTYSIZE) + 1;
    if ( pPlayers[currCharId]->uTimeToRecovery == 0 )
    {
      return currCharId;
    }
  }
  return uActiveCharacter;
}

//----- (0043EE77) --------------------------------------------------------
bool Player::HasUnderwaterSuitEquipped() //the original function took the player number as a parameter. if it was 0, the whole party was checked. calls with the parameter 0 have been changed to calls to this for every player
{
  if (this->pEquipment.uArmor == 0 || this->pInventoryItemList[this->pEquipment.uArmor].uItemID != 604)
  {
    return false;
  }
  return true;
}

//----- (0043EE15) --------------------------------------------------------
bool Player::HasItem( unsigned int uItemID, char a3 )
{
  if ( !a3 || pParty->pPickedItem.uItemID != uItemID )
  {
    for ( uint i = 0; i < 126; ++i )
    {
      if ( this->pInventoryMatrix[i] > 0 )
      {
        if ( (unsigned int)this->pInventoryItemList[this->pInventoryMatrix[i] - 1].uItemID == uItemID )
          return true;
      }
    }
    for ( uint i = 0; i < 16; ++i )
    {
      if ( this->pEquipment.pIndices[i] )
      {
        if ( (unsigned int)this->pInventoryItemList[this->pEquipment.pIndices[i] - 1].uItemID == uItemID )
          return true;
      }
    }
  }
  return false;
}
//----- (0043EDB9) --------------------------------------------------------
bool ShouldLoadTexturesForRaceAndGender(unsigned int _this)
{
  CHARACTER_RACE race; // edi@2
  PLAYER_SEX sex; // eax@2

  for (int i = 1; i <= 4; i++)
  {
    race = pPlayers[i]->GetRace();
    sex = pPlayers[i]->GetSexByVoice();
    switch(_this)
    {
       case 0:
         if (( race == CHARACTER_RACE_HUMAN || race == CHARACTER_RACE_ELF || race == CHARACTER_RACE_GOBLIN ) && sex == SEX_MALE )
           return true;
         break;
       case 1:
         if (( race == CHARACTER_RACE_HUMAN || race == CHARACTER_RACE_ELF || race == CHARACTER_RACE_GOBLIN ) && sex == SEX_FEMALE )
           return true;
         break;
       case 2:
         if ( race == CHARACTER_RACE_DWARF && sex == SEX_MALE )
           return true;
         break;
       case 3:
         if ( race == CHARACTER_RACE_DWARF && sex == SEX_FEMALE )
           return true;
         break;
    }
  }
  return false;
}
//----- (0043ED6F) --------------------------------------------------------
bool _43ED6F_check_party_races(bool a1)
{
  bool v6; // zf@5

  for (uint i = 0; i < 4; ++i)
  {
    auto player = pParty->pPlayers + i;
    auto race = player->GetRace();

    if (race != CHARACTER_RACE_HUMAN &&
        race != CHARACTER_RACE_ELF &&
        race != CHARACTER_RACE_GOBLIN)
      v6 = a1 == 1;
    else
      v6 = !a1;

    if (v6)
      return true;
  }
  return false;
}
//----- (00439FCB) --------------------------------------------------------
void __fastcall DamagePlayerFromMonster(unsigned int uObjID, int a2, Vec3_int_ *pPos, unsigned int a4)
{
  signed int v4; // esi@1
  unsigned int v5; // ecx@1
  Player *v6; // ebx@3
  Actor *v7; // esi@3
  unsigned int v8; // eax@4
  char *v9; // eax@5
  signed int v10; // eax@6
  int v11; // edx@8
  int v12; // edx@9
  int v13; // edx@10
  int v14; // edx@16
  int v15; // edx@17
  int v16; // edx@18
  enum SoundID v17; // eax@24
  int v18; // eax@26
  unsigned __int8 v19; // zf@26
  unsigned __int8 v20; // sf@26
  unsigned __int16 v21; // ax@29
  signed int v22; // edi@36
  int v23; // eax@38
  signed int v24; // eax@44
  unsigned __int16 v25; // cx@47
  signed int v26; // eax@49
  int v27; // eax@54
  float v28; // ST18_4@58
  double v29; // st7@58
  float v30; // ST08_4@58
  double v31; // st7@58
  float v32; // ST04_4@58
  float v33; // ST00_4@58
  int v34; // edi@61
  int v35; // eax@70
  double v36; // st7@70
  SpriteObject *v37; // ebx@77
  int v38; // edi@77
  int v39; // esi@77
  int v40; // eax@77
  int v41; // eax@77
  int v42; // eax@78
  Player *v43; // eax@81
  Actor *v44; // esi@82
  Player *v45; // edi@84
  unsigned __int16 v46; // ax@84
  int v47; // ebx@105
  int v48; // eax@107
  unsigned __int16 v49; // ax@116
  int v50; // ebx@123
  unsigned __int16 v51; // ax@124
  char v52; // bl@124
  int v53; // eax@128
  signed int v54; // eax@134
  unsigned __int16 v55; // cx@137
  signed int v56; // eax@139
  int v57; // eax@144
  float v58; // ST18_4@148
  double v59; // st7@148
  float v60; // ST08_4@148
  double v61; // st7@148
  float v62; // ST04_4@148
  float v63; // ST00_4@148
  int v64; // ebx@151
  int v65; // eax@161
  double v66; // st7@161
  signed int v67; // ecx@164
  signed int v68; // eax@170
  int v69; // ecx@170
  int v70; // eax@171
  enum SoundID v71; // [sp+20h] [bp-34h]@12
  int v72; // [sp+30h] [bp-24h]@164
  double v73; // [sp+40h] [bp-14h]@72
  signed int v74; // [sp+44h] [bp-10h]@1
  unsigned int v75; // [sp+48h] [bp-Ch]@3
  unsigned int uActorID; // [sp+4Ch] [bp-8h]@1
  int v77; // [sp+50h] [bp-4h]@26
  signed int a4a; // [sp+60h] [bp+Ch]@162
  Player *a4b; // [sp+60h] [bp+Ch]@168

  v4 = PID_ID(uObjID);
  v5 = PID_TYPE(uObjID) - 2;
  v74 = a2;
  uActorID = v4;
  if ( v5 )
  {
    if ( v5 != 1
      || (v6 = &pParty->pPlayers[a4], v7 = &pActors[v4],
                                     v75 = v6->sHealth,
                                     !stru_50C198.ActorHitOrMiss(v7, v6)) )
      return;
    v8 = v6->pEquipment.uArmor;
    if ( !v8
      || (v9 = (char *)v6 + 36 * v8, v9[516] & 2)
      || (v10 = pItemsTable->pItems[*((int *)v9 + 124)].uSkillType, v10 < 10)
      || v10 > 11 )
    {
      v14 = rand() % 4;
      if ( !v14 )
      {
        v71 = (SoundID)108;
        goto LABEL_24;
      }
      v15 = v14 - 1;
      if ( !v15 )
      {
        v71 = (SoundID)109;
        goto LABEL_24;
      }
      v16 = v15 - 1;
      if ( !v16 )
      {
        v71 = (SoundID)110;
        goto LABEL_24;
      }
      if ( v16 == 1 )
      {
        v71 = (SoundID)44;
        goto LABEL_24;
      }
    }
    else
    {
      v11 = rand() % 4;
      if ( !v11 )
      {
        v71 = (SoundID)105;
        goto LABEL_24;
      }
      v12 = v11 - 1;
      if ( !v12 )
      {
        v71 = (SoundID)106;
        goto LABEL_24;
      }
      v13 = v12 - 1;
      if ( !v13 )
      {
        v71 = (SoundID)107;
        goto LABEL_24;
      }
      if ( v13 == 1 )
      {
        v71 = (SoundID)45;
LABEL_24:
        v17 = v71;
        goto LABEL_26;
      }
    }
    v17 = (SoundID)a4;
LABEL_26:
    pAudioPlayer->PlaySound(v17, PID(OBJECT_Player,a4 + 80), 0, -1, 0, 0, 0, 0);
    v18 = Actor::_43B3E0_CalcDamage(v7, v74);
    v19 = HIDWORD(v7->pActorBuffs[3].uExpireTime) == 0;
    v20 = SHIDWORD(v7->pActorBuffs[3].uExpireTime) < 0;
    v77 = v18;
    if ( !v20 && (!(v20 | v19) || LODWORD(v7->pActorBuffs[3].uExpireTime) > 0) )
    {
      v21 = v7->pActorBuffs[3].uPower;
      if ( v21 )
        v77 /= (signed int)v21;
    }
    if ( v74 )
    {
      if ( v74 == 1 )
      {
        v22 = v7->pMonsterInfo.uAttack2Type;
      }
      else
      {
        if ( v74 == 2 )
        {
          v23 = v7->pMonsterInfo.uSpell1ID;
        }
        else
        {
          if ( v74 != 3 )
          {
            if ( v74 == 4 )
              v22 = v7->pMonsterInfo.field_3C_some_special_attack;
            else
              v22 = 4;
            goto LABEL_43;
          }
          v23 = v7->pMonsterInfo.uSpell2ID;
        }
        v22 = LOBYTE(pSpellStats->pInfos[v23].uSchool);
      }
    }
    else
    {
      v22 = v7->pMonsterInfo.uAttack1Type;
    }
LABEL_43:
    if ( !(dword_6BE368_debug_settings_2 & 0x10) )
    {
      v24 = v6->ReceiveDamage(v77, (DAMAGE_TYPE)v22);
      if ( SHIDWORD(v6->pPlayerBuffs[10].uExpireTime) >= 0
        && (SHIDWORD(v6->pPlayerBuffs[10].uExpireTime) > 0 || LODWORD(v6->pPlayerBuffs[10].uExpireTime)) )
      {
        v25 = v7->uAIState;
        if ( v25 != 5 )
        {
          if ( v25 != 4 )
          {
            v26 = stru_50C198.CalcMagicalDamageToActor(v7, v22, v24);
            v7->sCurrentHP -= v26;
            if ( v26 )
            {
              if ( v7->sCurrentHP >= 1 )
              {
                Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
                Actor::AggroSurroundingPeasants(uActorID, 1);
              }
              else
              {
                if ( pMonsterStats->pInfos[v7->pMonsterInfo.uID].bQuestMonster & 1 )
                {
                  v27 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * v7->uActorRadius : v7->uActorRadius;
                  v74 = v27;
                  if ( pRenderer->pRenderD3D )
                  {
                    if ( pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
                    {
                      v28 = (double)v74;
                      v74 = v7->vPosition.z;
                      v29 = (double)v74;
                      v74 = v7->vPosition.y;
                      v30 = v29;
                      v31 = (double)v74;
                      v74 = v7->vPosition.x;
                      v32 = v31;
                      v33 = (double)v74;
                      pDecalBuilder->AddBloodsplat(v33, v32, v30, 1.0, 0.0, 0.0, v28, 0, 0);
                    }
                  }
                }
                Actor::Die(uActorID);
                Actor::ApplyFineForKillingPeasant(uActorID);
                Actor::AggroSurroundingPeasants(uActorID, 1);
                if ( v7->pMonsterInfo.uExp )
                  GivePartyExp(pMonsterStats->pInfos[v7->pMonsterInfo.uID].uExp);
                v34 = SPEECH_51;
                if ( rand() % 100 < 20 )
                  v34 = ((signed int)v7->pMonsterInfo.uHP >= 100) + 1;
                v6->PlaySound((PlayerSpeech)v34, 0);
              }
            }
          }
        }
      }
      if ( !(dword_6BE368_debug_settings_2 & 0x10)
        && v7->pMonsterInfo.uSpecialAttack
        && rand() % 100 < v7->pMonsterInfo.uLevel * v7->pMonsterInfo.uSpecialAttackType )
        v6->_48DCF6(v7->pMonsterInfo.uSpecialAttack, v7);
    }
    if ( !pParty->bTurnBasedModeOn )
    {
      v35 = v6->GetActualEndurance();
      v36 = (double)(20 - v6->GetParameterBonus(v35)) * flt_6BE3A4_debug_recmod1 * 2.133333333333333;
      v6->SetRecoveryTime((signed __int64)v36);
    }
    if ( v77 )
    {
      v73 = (double)(signed int)v75;
      if ( (double)v6->GetMaxHealth() * 0.25 < v73 )
      {
        if ( v6->sHealth > 0 )
        {
          if ( (double)v6->GetMaxHealth() * 0.25 >= (double)v6->sHealth )
            v6->PlaySound(SPEECH_48, 0);
        }
      }
    }
    viewparams->bRedrawGameUI = 1;
    return;
  }
  v37 = &pSpriteObjects[uActorID];
  v38 = PID_TYPE(v37->spell_caster_pid);
  v39 = PID_ID(v37->spell_caster_pid);
  v40 = PID_TYPE(v37->spell_caster_pid);
  uActorID = PID_ID(v37->spell_caster_pid);
  v41 = v40 - 2;
  if ( !v41 )
    goto LABEL_80;
  v42 = v41 - 1;
  if ( !v42 )
  {
    v44 = &pActors[v39];
    if ( a4 == -1 )
      a4 = stru_50C198.which_player_would_attack(v44);
    v45 = &pParty->pPlayers[a4];
    v77 = Actor::_43B3E0_CalcDamage(v44, v74);
    v46 = v37->uType;
    if ( v37->uType == 545 )
    {
      LOBYTE(v51) = v45->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
      v52 = v51;
      if ( (signed int)SkillToMastery(v51) >= 4 && rand() % 100 < (v52 & 0x3F) )
      {
		  sprintf(pTmpBuf.data(), pGlobalTXT_LocalizationStrings[637], v45->pName);
        ShowStatusBarString(pTmpBuf.data(), 2u);
        v45->PlaySound(SPEECH_6, 0);
        return;
      }
    }
    else
    {
      if ( v46 != 555
        && v46 != 510
        && v46 != 500
        && v46 != 515
        && v46 != 505
        && v46 != 530
        && v46 != 525
        && v46 != 520
        && v46 != 535
        && v46 != 540 )
        goto LABEL_115;
    }
    if ( !stru_50C198.ActorHitOrMiss(v44, v45) )
      return;
    if ( (signed __int64)v45->pPlayerBuffs[13].uExpireTime > 0 )
      v77 >>= 1;
    if ( v45->HasEnchantedItemEquipped(36) )
      v77 >>= 1;
    if ( v45->HasEnchantedItemEquipped(69) )
      v77 >>= 1;
    if ( v45->HasItemEquipped(EQUIP_ARMOUR)
		&& *(_DWORD *)&v45->pInventoryItemList[v45->pEquipment.uArmor-1] == 504 )
      v77 >>= 1;
    v75 = 0;
	v47 = (int)&v45->pEquipment;
    do
    {
      if ( v45->HasItemEquipped((ITEM_EQUIP_TYPE)v75) )
      {
        v48 = *(int *)&v45[36 * *(int *)v47 + 496];
        if ( v48 == 520 )
          v77 >>= 1;
        if ( v48 == 531 )
          v77 >>= 1;
        if ( v45->GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v75) == EQUIP_SHIELD && SkillToMastery(v45->pActiveSkills[PLAYER_SKILL_SHIELD]) == 4 )
          v77 >>= 1;
      }
      ++v75;
      v47 += 4;
    }
    while ( (signed int)v75 <= 1 );
LABEL_115:
    if ( (signed __int64)v44->pActorBuffs[3].uExpireTime > 0 )
    {
      v49 = v44->pActorBuffs[3].uPower;
      if ( v49 )
        v77 /= (signed int)v49;
    }
    if ( !v74 )
    {
      v50 = v44->pMonsterInfo.uAttack1Type;
      goto LABEL_133;
    }
    if ( v74 == 1 )
    {
      v50 = v44->pMonsterInfo.uAttack2Type;
      goto LABEL_133;
    }
    if ( v74 == 2 )
    {
      v53 = v44->pMonsterInfo.uSpell1ID;
    }
    else
    {
      if ( v74 != 3 )
      {
        if ( v74 == 4 )
          v50 = v44->pMonsterInfo.field_3C_some_special_attack;
        else
          v50 = 4;
LABEL_133:
        if ( !(dword_6BE368_debug_settings_2 & 0x10) )
        {
          v54 = v45->ReceiveDamage(v77, (DAMAGE_TYPE)v50);
          if ( SHIDWORD(v45->pPlayerBuffs[10].uExpireTime) >= 0 )
          {
            if ( SHIDWORD(v45->pPlayerBuffs[10].uExpireTime) > 0 || LODWORD(v45->pPlayerBuffs[10].uExpireTime) )
            {
              v55 = v44->uAIState;
              if ( v55 != 5 )
              {
                if ( v55 != 4 )
                {
                  v56 = stru_50C198.CalcMagicalDamageToActor(v44, v50, v54);
                  v44->sCurrentHP -= v56;
                  if ( v56 )
                  {
                    if ( v44->sCurrentHP >= 1 )
                    {
                      Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0);
                      Actor::AggroSurroundingPeasants(uActorID, 1);
                    }
                    else
                    {
                      if ( pMonsterStats->pInfos[v44->pMonsterInfo.uID].bQuestMonster & 1 )
                      {
                        v57 = byte_4D864C && BYTE2(pGame->uFlags) & 8 ? 10 * v44->uActorRadius : v44->uActorRadius;
                        v75 = v57;
                        if ( pRenderer->pRenderD3D )
                        {
                          if ( pGame->uFlags2 & GAME_FLAGS_2_DRAW_BLOODSPLATS )
                          {
                            v58 = (double)(signed int)v75;
                            v75 = v44->vPosition.z;
                            v59 = (double)(signed int)v75;
                            v75 = v44->vPosition.y;
                            v60 = v59;
                            v61 = (double)(signed int)v75;
                            v75 = v44->vPosition.x;
                            v62 = v61;
                            v63 = (double)(signed int)v75;
                            pDecalBuilder->AddBloodsplat(v63, v62, v60, 1.0, 0.0, 0.0, v58, 0, 0);
                          }
                        }
                      }
                      Actor::Die(uActorID);
                      Actor::ApplyFineForKillingPeasant(uActorID);
                      Actor::AggroSurroundingPeasants(uActorID, 1);
                      if ( v44->pMonsterInfo.uExp )
                        GivePartyExp(pMonsterStats->pInfos[v44->pMonsterInfo.uID].uExp);
                      v64 = SPEECH_51;
                      if ( rand() % 100 < 20 )
                        v64 = ((signed int)v44->pMonsterInfo.uHP >= 100) + 1;
                      v45->PlaySound((PlayerSpeech)v64, 0);
                    }
                  }
                }
              }
            }
          }
        }
        if ( !v74
          && !(dword_6BE368_debug_settings_2 & 0x10)
          && v44->pMonsterInfo.uSpecialAttack
          && rand() % 100 < v44->pMonsterInfo.uLevel * v44->pMonsterInfo.uSpecialAttackType )
          v45->_48DCF6(v44->pMonsterInfo.uSpecialAttack, v44);
        if ( !pParty->bTurnBasedModeOn )
        {
          v65 = v45->GetActualEndurance();
          v66 = (double)(20 - v45->GetParameterBonus(v65))
              * flt_6BE3A4_debug_recmod1
              * 2.133333333333333;
          v45->SetRecoveryTime((signed __int64)v66);
        }
        return;
      }
      v53 = v44->pMonsterInfo.uSpell2ID;
    }
    v50 = LOBYTE(pSpellStats->pInfos[v53].uSchool);
    goto LABEL_133;
  }
  if ( v42 != 1 )
    return;
LABEL_80:
  if ( a4 != -1 )
  {
    v43 = &pParty->pPlayers[a4];
LABEL_168:
    a4b = v43;
    if ( v38 != OBJECT_Player || v37->spell_id != SPELL_BOW_ARROW)
    {
      v70 = v43->GetMaxHealth();
      v68 = _43AFE3_calc_spell_damage(v37->spell_id, v37->spell_level, v37->spell_skill, v70);
      v69 = LOBYTE(pSpellStats->pInfos[v37->spell_id].uSchool);
    }
    else
    {
      v68 = pParty->pPlayers[uActorID].CalculateRangedDamageTo(0);
      v69 = 0;
    }
    a4b->ReceiveDamage(v68, (DAMAGE_TYPE)v69);
    if ( v38 == OBJECT_Player && !qword_A750D8 )
    {
      qword_A750D8 = 256i64;
      PlayerSpeechID = SPEECH_44;
      uSpeakingCharacter = uActorID + 1;
    }
    return;
  }
  v74 = 0;
  a4a = 1;
  do
  {
    if ( pPlayers[a4a]->CanAct() )
    {
      v67 = v74++;
      *(&v72 + v67) = a4a;
    }
    ++a4a;
  }
  while ( a4a <= 4 );
  if ( v74 )
  {
    v43 = &pParty->pPlayers[*(&v72+rand()%v74)-1];//&stru_AA1058[3].pSounds[6972 * *(&v72 + rand() % v74) + 40552];
    goto LABEL_168;
  }
}
//----- (00421EA6) --------------------------------------------------------
void  OnInventoryLeftClick()
{
  Player *v0; // ebx@1
  signed int v1; // eax@2
  signed int v2; // ecx@2
  int v3; // eax@2
  char v4; // sf@2
  int v5; // eax@2
  unsigned int v6; // eax@7
  unsigned int v7; // esi@12
  unsigned int v8; // eax@12
  unsigned int v9; // eax@16
  unsigned int v10; // eax@18
  ItemGen this_; // [sp+Ch] [bp-3Ch]@1
  POINT a2; // [sp+30h] [bp-18h]@4
  unsigned int v13; // [sp+38h] [bp-10h]@13
  unsigned int pY; // [sp+3Ch] [bp-Ch]@2
  unsigned int pX; // [sp+40h] [bp-8h]@2
  int a4; // [sp+44h] [bp-4h]@2

  v0 = pPlayers[uActiveCharacter];
  if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 )
  {
    pMouse->GetClickPos(&pX, &pY);
    pY = pY - 17;
    v2 =pX - 14;
    pX = v2;
    v3 = 14 * (pY >> 5);
    v2 >>= 5;
    v4 = v2 + v3 < 0;
    v5 = v2 + v3;
    a4 = v5;
    if ( !v4 )
    {
      if ( v5 <= 126 && pMouse->GetCursorPos(&a2)->x < 462
            && pMouse->GetCursorPos(&a2)->x >= 14 )
      {
        if ( unk_50C9A0 )
        {
          v6 = v0->GetItemIDAtInventoryIndex(&a4);
          if ( v6 )
          {
            *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu;
            *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1;
            *((int *)pGUIWindow_Settings->ptr_1C + 3) = v6 - 1;
            *((short *)pGUIWindow_Settings->ptr_1C + 3) = a4;
            ptr_50C9A4 = (ItemGen *)&v0->pInventoryItemList[v6-1];
            unk_50C9A0 = 0;
            if ( pMessageQueue_50CBD0->uNumMessages )
              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
            pMouse->SetCursorBitmap("MICON1");
            dword_50C9D0 = 113;
            dword_50C9D4 = 0;
            dword_50C9D8 = 256;
          }
          return;
        }
        if ( ptr_50C9A4 )
          return;
        v7 = pParty->pPickedItem.uItemID;
        v8 = v0->GetItemIDAtInventoryIndex(&a4);
        if ( !v7 )
        {
          if ( !v8 )
            return;
          memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[v8-1], sizeof(pParty->pPickedItem));
          v0->RemoveItemAtInventoryIndex(a4);
          v9 = pParty->pPickedItem.uItemID;
          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
          return;
        }
        v13 = v8;
        if ( v8 )
        {
          a2.y = (LONG)&v0->pInventoryItemList[v8-1];
          memcpy(&this_, (const void *)a2.y, sizeof(this_));
          v0->RemoveItemAtInventoryIndex(a4);
          pX = v0->AddItem2(a4, &pParty->pPickedItem);
          if ( !pX )
          {
            pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem);
            if ( !pX )
            {
              v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4);
              memcpy((void *)a2.y, &this_, sizeof(ItemGen));
              return;
            }
          }
          v9 = this_.uItemID;
          memcpy(&pParty->pPickedItem, &this_, sizeof(pParty->pPickedItem));
          pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName);
          return;
        }
        v10 = v0->AddItem(a4, v7);
        pX = v10;
        if ( v10 || (v10 = v0->AddItem(-1, pParty->pPickedItem.uItemID), (pX = v10) != 0) )
        {
          memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, 0x24u);
          pMouse->RemoveHoldingItem();
        }
      }
    }
  }
}


bool Player::IsWeak()
{
  return pConditions[Condition_Weak] != 0;
}

bool Player::IsDead()
{
  return pConditions[Condition_Dead] != 0;
}

bool Player::IsEradicated()
{
  return pConditions[Condition_Eradicated] != 0;
}

bool Player::IsZombie()
{
  return pConditions[Condition_Zombie] != 0;
}

bool Player::IsCursed()
{
  return pConditions[Condition_Cursed] != 0;
}

bool Player::IsPertified()
{
  return pConditions[Condition_Pertified] != 0;
}

bool Player::IsUnconcious()
{
  return pConditions[Condition_Unconcious] != 0;
}

bool Player::IsAsleep()
{
  return pConditions[Condition_Sleep] != 0;
}

bool Player::IsParalyzed()
{
  return pConditions[Condition_Paralyzed] != 0;
}

void Player::SetCursed( bool state )
{
  pConditions[Condition_Cursed] = state;
}

void Player::SetWeak( bool state )
{
  pConditions[Condition_Weak] = state;
}

void Player::SetAsleep( bool state )
{
  pConditions[Condition_Sleep] = state;
}

void Player::SetAfraid( bool state )
{
  pConditions[Condition_Fear] = state;
}

void Player::SetDrunk( bool state )
{
  pConditions[Condition_Drunk] = state;
}

void Player::SetInsane( bool state )
{
  pConditions[Condition_Insane] = state;
}

void Player::SetPoison1( bool state )
{
  pConditions[Condition_Poison1] = state;
}

void Player::SetDisease1( bool state )
{
  pConditions[Condition_Disease1] = state;
}

void Player::SetPoison2( bool state )
{
  pConditions[Condition_Poison2] = state;
}

void Player::SetDisease2( bool state )
{
  pConditions[Condition_Disease2] = state;
}

void Player::SetPoison3( bool state )
{
  pConditions[Condition_Poison3] = state;
}

void Player::SetDisease3( bool state )
{
  pConditions[Condition_Disease3] = state;
}

void Player::SetParalyzed( bool state )
{
  pConditions[Condition_Paralyzed] = state;
}

void Player::SetUnconcious( bool state )
{
  pConditions[Condition_Unconcious] = state;
}

void Player::SetDead( bool state )
{
  pConditions[Condition_Dead] = state;
}

void Player::SetPertified( bool state )
{
  pConditions[Condition_Pertified] = state;
}

void Player::SetEradicated( bool state )
{
  pConditions[Condition_Eradicated] = state;
}

void Player::SetZombie( bool state )
{
  pConditions[Condition_Zombie] = state;
}

void Player::SetCondWeakWithBlockCheck( int blockable )
{
  SetCondition(Condition_Weak, blockable);
}

void Player::SetCondInsaneWithBlockCheck( int blockable )
{
  SetCondition(Condition_Insane, blockable);
}

void Player::SetCondDeadWithBlockCheck( int blockable )
{
  SetCondition(Condition_Dead, blockable);
}

void Player::SetCondUnconsciousWithBlockCheck( int blockable )
{
  SetCondition(Condition_Dead, blockable);
}