view Player.cpp @ 1035:306ec23b37df

004C1EE5 & other stuff
author Nomad
date Wed, 22 May 2013 14:12:51 +0200
parents aa848c90181f
children ff2d888f8033
line wrap: on
line source

#include <assert.h>

#include "stru6.h"


#include "OSAPI.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"






/*  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 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 pConditionStrengthMultiplier[19]     = {100, 100, 100, 120,  50, 200,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100, 100, 100};
unsigned char pConditionIntelligenceMultiplier[19] = {100, 100, 100,  50,  25,  10, 100, 100,  75,  60,  50,  30, 100, 100, 100, 100, 100,   1, 100};
unsigned char pConditionWillpowerMultiplier[19]    = {100, 100, 100,  50,  25,  10, 100, 100,  75,  60,  50,  30, 100, 100, 100, 100, 100,   1, 100};
unsigned char pConditionEnduranceMultiplier[19]    = {100, 100, 100, 100,  50, 150,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100, 100, 100};
unsigned char pConditionAccuracyMultiplier[19]     = {100, 100, 100,  50,  10, 100,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100,  50, 100};
unsigned char pConditionSpeedMultiplier[19]        = {100, 100, 100, 120,  20, 120,  75,  60,  50,  30,  25,  10, 100, 100, 100, 100, 100,  50, 100};
unsigned char pConditionLuckMultiplier[19]         = {100, 100, 100, 100, 200, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};

unsigned char pAgeingStrengthMultiplier[4]     = {100,  75,  40, 10};
unsigned char pAgeingIntelligenceMultiplier[4] = {100, 150, 100, 10};
unsigned char pAgeingWillpowerMultiplier[4]    = {100, 150, 100, 10};
unsigned char pAgeingEnduranceMultiplier[4]    = {100,  75,  40, 10};
unsigned char pAgeingAccuracyMultiplier[4]     = {100, 100,  40, 10};
unsigned char pAgeingSpeedMultiplier[4]        = {100, 100,  40, 10};
unsigned char pAgeingLuckMultiplier[4]         = {100, 100, 100, 100};

unsigned int pAgeingTable[4] = {50, 100, 150, 65535};

unsigned int pConditionImportancyTable[18] = {16, 15, 14, 17, 13, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 0};

short word_4EDFFC[30] = {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, 0};
signed int player_stat_bonuses[30] = {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, 0};


unsigned char pEquipTypeToBodyAnchor[20] = {1, 1, 2, 3, 0, 4, 5, 6, 7, 8, 10, 9, 1, 0, 0, 0, 0, 0, 0, 0};


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) --------------------------------------------------------
signed int __cdecl PlayerCreation_ComputeAttributeBonus()
{
  signed int v0; // edi@1
  signed int v1; // esi@1
  int v2; // ebx@2
  int v3; // ecx@17
  signed int v4; // eax@17
  int v5; // edx@18
  signed int v6; // ecx@18
  signed int v8; // [sp+Ch] [bp-8h]@1
  signed int v9; // [sp+10h] [bp-4h]@2

  v8 = 50;
  v0 = 50;
  v1 = 0;
  do
  {
    v9 = 0;
    v2 = 7 * pParty->pPlayers[v1].GetRace();
    do
    {
      if ( v9 )
      {
        switch ( v9 )
        {
          case 1:
            v0 = pParty->pPlayers[v1].uIntelligence;
            break;
          case 2:
            v0 = pParty->pPlayers[v1].uWillpower;
            break;
          case 3:
            v0 = pParty->pPlayers[v1].uEndurance;
            break;
          case 4:
            v0 = pParty->pPlayers[v1].uAccuracy;
            break;
          case 5:
            v0 = pParty->pPlayers[v1].uSpeed;
            break;
          case 6:
            v0 = pParty->pPlayers[v1].uLuck;
            break;
        }
      }
      else
      {
        v0 = pParty->pPlayers[v1].uMight;
      }
      v3 = v2 + v9;
      v4 = StatTable[0][v3].uBaseValue;
      if ( v0 >= v4 )
      {
        v5 = StatTable[0][v3].uDroppedStep;
        v6 = StatTable[0][v3].uBaseStep;
      }
      else
      {
        v5 = StatTable[0][v3].uBaseStep;
        v6 = StatTable[0][v3].uDroppedStep;
      }
      v8 += v5 * (v4 - v0) / v6;
      ++v9;
    }
    while ( v9 <= 6 );
    ++v1;
  }
  while ( v1 < 4 );
  return v8;
}



//----- (00427730) --------------------------------------------------------
bool Player::CanCastSpell(unsigned int uRequiredMana)
{
  if (sMana >= uRequiredMana)
  {
    sMana -= 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].Broken() )
    sell_price = 1;
  if ( sell_price < 1 )
    sell_price = 1;
  RemoveItemAtInventoryIndex(inventory_idnx);
  Party::SetGold(pParty->uNumGold + sell_price);
}



//----- (0043EEF3) --------------------------------------------------------
bool Player::_43EEF3()
{
  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!=64 &&  item_id!= 65 ) //blaster& blaster rifle
             return false;
         }
      }
      return true;
  }
  



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

//----- (004B807C) --------------------------------------------------------
int Player::_4B807C(float a2)
{
  Player *v2; // edi@1
  unsigned int v3; // eax@1
  int v4; // esi@1
  unsigned int v5; // ebx@7
  int v6; // eax@8
  signed __int64 v7; // qax@13
  unsigned int v9; // [sp-4h] [bp-14h]@4
  signed int v10; // [sp+8h] [bp-8h]@4
  int v11; // [sp+Ch] [bp-4h]@6

  v2 = this;
  v3 = GetMajorConditionIdx();
  v4 = 0;
  if ( (signed int)v3 >= 14 )
  {
    if ( (signed int)v3 <= 15 )
    {
      v10 = 5;
      v9 = v3;
      goto LABEL_6;
    }
    if ( v3 == 16 )
    {
      v10 = 10;
      v9 = 16;
LABEL_6:
      v11 = _4B8040_condition_time(v9);
      goto LABEL_13;
    }
  }
  v10 = 1;
  v5 = 0;
  do
  {
    v6 = _4B8040_condition_time(v5);
    if ( v6 > v4 )
      v4 = v6;
    ++v5;
  }
  while ( (signed int)v5 <= 13 );
  v11 = v4;
  if ( !v4 )
    v11 = 1;
LABEL_13:
  v7 = (signed __int64)((double)v11 * (double)v10 * a2);
  if ( (signed int)v7 < 1 )
    LODWORD(v7) = 1;
  return v7;
}

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

  v3 = (unsigned __int64)(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 = ((100 - GetMerchant()) * (uRealValue * price_multiplier)) / 100;
  assert (price > 0);

  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 __int64)(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 __int64)((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::_4B8213(int a2, float a3)
{
  signed __int64 v3; // qax@1

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

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

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

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

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

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

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





//----- (004B6FF9) --------------------------------------------------------
int Player::_4B6FF9()
{
  Player *v1; // esi@1
  signed int v2; // eax@1
  char v3; // zf@4

  v1 = this;
  v2 = (signed int)window_SpeakInHouse->ptr_1C;
  if ( (v2 == 78 || v2 > 80) && v2 <= 82 )
  {
    if ( GetMajorConditionIdx() == 18 )
      goto LABEL_6;
    v3 = GetMajorConditionIdx() == 17;
  }
  else
  {
    v3 = GetMajorConditionIdx() == 18;
  }
  if ( !v3 )
    return 1;
LABEL_6:
  if ( v1->sHealth < GetMaxHealth() || v1->sMana < GetMaxMana() )
    return 1;
  return 0;
}



//----- (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->pInventoryIndices[item_idx];
    if ( inv_index < 0 )
    {
      *pitem_index = -1 - inv_index;
      inv_index = this->pInventoryIndices[-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 (!(pInventoryItems[item_index_tabl[i]].uAttributes&ITEM_ENCHANTED))
                pInventoryItems[item_index_tabl[rand() % avalible_items]].uAttributes|=ITEM_ENCHANTED; 
        }
       
    }
    else
    {
      for ( i = 0; i < avalible_items; ++i )
      {
        if (!(pInventoryItems[item_index_tabl[i]].uAttributes&ITEM_ENCHANTED))
                pInventoryItems[item_index_tabl[i]].uAttributes|=ITEM_ENCHANTED;
      }
    }
  }
 ;
}

//----- (004948B1) --------------------------------------------------------
void Player::PlaySound(PlayerSpeech speech, int a3)
{
  //Player *pPlayer; // edi@1
  //int v4; // eax@4
  signed int v5; // esi@4
  unsigned char *v6; // ebx@4
  signed int v7; // ecx@5
  unsigned __int8 v8; // al@6
  int v9; // eax@10
  //unsigned int pVoiceID; // ecx@10
  int v11; // esi@10
  //signed int v12; // eax@11
  signed int v13; // esi@12
  int v14; // eax@12
  //int v15; // eax@17
  CHARACTER_EXPRESSION_ID expression; // ebx@17
  signed int v17; // ecx@19
  char *pSoundID; // edi@20
  int v20[5]; // [sp+Ch] [bp-1Ch]@7
  //Player *pPlayer2; // [sp+20h] [bp-8h]@1
  int pPlayerNum; // [sp+24h] [bp-4h]@1
  int pSoundId; // [sp+30h] [bp+8h]@4

  //pPlayer = this;
  //pPlayer2 = this;

  pPlayerNum = 1;
  for (int i = 0; i < 4; ++i)
    if (&pParty->pPlayers[i] == this)
    {
      pPlayerNum = i + 1;
      break;
    }

  //v4 = a2;//102
  v5 = 0;
  pSoundId = 0;
  v6 = SoundSetAction[speech];//byte_4ED280 &byte_4ED3D8[4 * v4] ???
  if (uVoicesVolumeMultiplier)
  {
    v7 = 0;
    do
    {
      v8 = v6[v7];
      if ( v8 )
        v20[v5++] = v8;
      ++v7;
    }
    while ( v7 < 2 );
    if ( v5 )
    {
      v9 = rand();
      //pVoiceID = uVoiceID;
      v11 = v20[v9 % v5];

      if (int _v1 = byte_4ECF08[v11 - 1][uVoiceID])
      {
        pSoundId = rand() % _v1 + 2 * (v11 + 50 * uVoiceID) + 4998;
        pAudioPlayer->PlaySound((SoundID)pSoundId, PID(OBJECT_Player, pPlayerNum + 39), 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
      }
    }
  }

  v13 = 0;
  v14 = (int)(v6 + 3);
  do
  {
    if ( *(char *)v14 )
      v20[v13++] = *(char *)v14;
    ++v14;
  }
  while ( -3 - (signed int)v6 + v14 < 5 );
  if ( v13 )
  {
    pPlayerNum = 0;
    expression = (CHARACTER_EXPRESSION_ID)v20[rand() % v13];
    if (expression == CHARACTER_EXPRESSION_21 && pSoundId )
    {
      v17 = 0;
      if ( (signed int)pSoundList->sNumSounds <= 0 )
      {
LABEL_23:
        v17 = 0;
      }
      else
      {
        pSoundID = (char *)&pSoundList->pSounds->uSoundID;
        while ( *(int *)pSoundID != pSoundId )
        {
          ++v17;
          pSoundID += 120;
          if ( v17 >= (signed int)pSoundList->sNumSounds )
            goto LABEL_23;
        }
      }
      if ( pSoundList->pSounds[v17].pSoundData[0] )
        pPlayerNum = (sLastTrackLengthMS << 7) / 1000;
    }
    /*LOWORD(v14) = */PlayEmotion(expression, pPlayerNum);
  }
  //return v14;
}
// 4948B1: using guessed type int var_1C[5];

//----- (00494A25) --------------------------------------------------------
void Player::PlayEmotion(CHARACTER_EXPRESSION_ID new_expression, int a3)
{
  //signed int v3; // eax@1
  //CHARACTER_EXPRESSION_ID v4; // dx@1
  signed int v5; // edi@15
  PlayerFrame *v6; // esi@17
  signed int v7; // eax@20

  //LOWORD(v3) = this->expression;
  //v4 = expr;
  if (expression != CHARACTER_EXPRESSION_SLEEP &&
      expression != CHARACTER_EXPRESSION_PERTIFIED || new_expression != CHARACTER_EXPRESSION_58)
  {
    int v3 = (unsigned)expression;
    if ( (signed int)(unsigned __int16)v3 >= 2 )
    {
      if ( v3 <= 7 )
        goto LABEL_12;
      if ( v3 > 8 )
      {
        if ( v3 > 11 )
        {
          if ( v3 == CHARACTER_EXPRESSION_PERTIFIED ||( v3 > 97 && v3 <= 99) )
            return;
          goto LABEL_15;
        }
LABEL_12:
        if (new_expression != CHARACTER_EXPRESSION_34 && new_expression != CHARACTER_EXPRESSION_35 && new_expression != CHARACTER_EXPRESSION_36)
          return;
        goto LABEL_15;
      }
    }
  }
LABEL_15:
  //LOWORD(v3) = a3;
  v5 = 0;
  this->uExpressionTimeLength = a3;
  this->uExpressionTimePassed = 0;
  if ( !a3 )
  {
    if ( (signed int)pPlayerFrameTable->uNumFrames <= 0 )
    {
LABEL_20:
      v7 = 0;
    }
    else
    {
      v6 = pPlayerFrameTable->pFrames;
      while ( v6->expression != new_expression )
      {
        ++v5;
        ++v6;
        if ( v5 >= (signed int)pPlayerFrameTable->uNumFrames )
          goto LABEL_20;
      }
      v7 = v5;
    }
    //v4 = expr;
    this->uExpressionTimeLength = 8 * pPlayerFrameTable->pFrames[a3].uAnimLength;
  }
  expression = new_expression;
  viewparams->bRedrawGameUI = 1;
}

//----- (0049327B) --------------------------------------------------------
int Player::_49327B(unsigned int uClass, int a3)
{
  Player *v3; // esi@1
  char v4; // zf@4
  __int16 v5; // dx@9
  signed int result; // eax@84
  unsigned int v7; // [sp-8h] [bp-10h]@3
  int v8; // [sp-4h] [bp-Ch]@3

  v3 = this;
  if ( this->classType == uClass )
  {
LABEL_84:
    result = 1;
  }
  else
  {
    switch ( uClass )
    {
      case 0u:
        v8 = a3;
        v7 = 1;
        goto LABEL_4;
      case 1u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 17)
          || _49327B(2u, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 3;
        goto LABEL_4;
      case 2u:
        v5 = 19;
        goto LABEL_82;
      case 3u:
        v5 = 21;
        goto LABEL_82;
      case 4u:
        v8 = a3;
        v7 = 5;
        goto LABEL_4;
      case 5u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 11)
          || _49327B(6u, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 7;
        goto LABEL_4;
      case 6u:
        if ( !a3 )
          break;
        v5 = 13;
        goto LABEL_82;
      case 7u:
        if ( !a3 )
          break;
        v5 = 15;
        goto LABEL_82;
      case 8u:
        v8 = a3;
        v7 = 9;
        goto LABEL_4;
      case 9u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 23)
          || _49327B(0xAu, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 11;
        goto LABEL_4;
      case 0xAu:
        if ( !a3 )
          break;
        v5 = 25;
        goto LABEL_82;
      case 0xBu:
        if ( !a3 )
          break;
        v5 = 27;
        goto LABEL_82;
      case 0xCu:
        v8 = a3;
        v7 = 13;
        goto LABEL_4;
      case 0xDu:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 41)
          || _49327B(0xEu, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 15;
        goto LABEL_4;
      case 0xEu:
        if ( !a3 )
          break;
        v5 = 43;
        goto LABEL_82;
      case 0xFu:
        if ( !a3 )
          break;
        v5 = 45;
        goto LABEL_82;
      case 0x10u:
        v8 = a3;
        v7 = 17;
        goto LABEL_4;
      case 0x11u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 35)
          || _49327B(0x12u, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 19;
        goto LABEL_4;
      case 0x12u:
        if ( !a3 )
          break;
        v5 = 37;
        goto LABEL_82;
      case 0x13u:
        v5 = 39;
        goto LABEL_82;
      case 0x14u:
        v8 = a3;
        v7 = 21;
        goto LABEL_4;
      case 0x15u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 29)
          || _49327B(0x16u, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 23;
        goto LABEL_4;
      case 0x16u:
        if ( !a3 )
          break;
        v5 = 31;
        goto LABEL_82;
      case 0x17u:
        if ( !a3 )
          break;
        v5 = 33;
        goto LABEL_82;
      case 0x18u:
        if ( !_49327B(0x19u, a3) )
          goto LABEL_56;
        break;
      case 0x19u:
LABEL_56:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)v3->_guilds_member_bits, 63)
          || _49327B(0x1Au, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 27;
        goto LABEL_4;
      case 0x1Au:
        if ( !a3 )
          break;
        v5 = 65;
        goto LABEL_82;
      case 0x1Bu:
        if ( !a3 )
          break;
        v5 = 67;
        goto LABEL_82;
      case 0x1Cu:
        v8 = a3;
        v7 = 29;
        goto LABEL_4;
      case 0x1Du:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 69)
          || _49327B(0x1Eu, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 31;
        goto LABEL_4;
      case 0x1Eu:
        if ( !a3 )
          break;
        v5 = 71;
        goto LABEL_82;
      case 0x1Fu:
        if ( !a3 )
          break;
        v5 = 73;
        goto LABEL_82;
      case 0x20u:
        v8 = a3;
        v7 = 33;
        goto LABEL_4;
      case 0x21u:
        if ( a3 && (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, 73)
          || _49327B(0x22u, a3) )
          goto LABEL_84;
        v8 = a3;
        v7 = 35;
LABEL_4:
        v4 = _49327B(v7, v8) == 0;
        goto LABEL_83;
      case 0x22u:
        if ( !a3 )
          break;
        v5 = 77;
        goto LABEL_82;
      case 0x23u:
        if ( a3 )
        {
          v5 = 79;
LABEL_82:
          v4 = (unsigned __int16)_449B57_test_bit((unsigned __int8 *)this->_guilds_member_bits, v5) == 0;
LABEL_83:
          if ( !v4 )
            goto LABEL_84;
        }
        break;
      default:
        break;
    }
    result = 0;
  }
  return result;
}


//----- (00492C0B) --------------------------------------------------------
bool Player::CanAct()
{
  bool result; // eax@2

  if ( this->pConditions[2] | this->pConditions[12] | this->pConditions[13] | this->pConditions[14] | this->pConditions[15] | this->pConditions[16] )
    result = 0;
  else
    result = 1;
  return result;
}

//----- (00492C40) --------------------------------------------------------
bool Player::CanSteal()
{
  int v1; // eax@1

  LOBYTE(v1) = GetActualSkillLevel(PLAYER_SKILL_STEALING);
  return v1 != 0;
}

//----- (00492C4E) --------------------------------------------------------
bool Player::CanEquip_RaceAndAlignmentCheck(unsigned int uItemID)
{
  char v2; // zf@9
  __int16 v4; // dx@13
  char v5; // zf@15

  if ( (signed int)uItemID > 532 )              //  if (uItemID == 514 ||                       // item233  ®á®å âਪ                àâ¥ä ªâ, §«®
                                                //      uItemID == 516 ||                       // item221  ‘â àë© ¨ª                 àâ¥ä ªâ, §«®
                                                //      uItemID == 524)                         // item325  ‘ã¬à ª                    ५¨ª¢¨ï, §«®
  {
    if ( uItemID == 533 )
    {
      v2 = GetRace() == 1;
    }
    else
    {
      if ( uItemID != 534 )
      {
        if ( uItemID == 535 )                   // 
                                                //  if (uItemID == 530)                         // item093  ƒ¨¡¥«ì «ìä                àâ¥ä ªâ, £®¡«¨­
        {
          switch ( this->uVoiceID )
          {
            default:
              return 1;
            case 4u:
            case 5u:
            case 6u:
            case 7u:
            case 0xAu:
            case 0xBu:
            case 0xEu:                          // 
                                                //  if (uItemID == 535)                         // item129  ᪮àâ ‹¥¤¨                àâ¥ä ªâ, ¦¥­é¨­ 
            case 0xFu:
            case 0x12u:
            case 0x13u:
            case 0x15u:
            case 0x18u:
              return 0;
          }
          return 0;
        }
        if ( uItemID == 536 )                   // 
                                                //  if (uItemID == 531)                         // item093  Žª® Œë᫨                  àâ¥ä ªâ, 祫®¢¥ª
        {
          switch ( this->uVoiceID )
          {
            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 1;
            default:
              return 0;
          }
          return 0;
        }
        if ( uItemID != 604 )                   // 
                                                //  if (uItemID == 532)                         // item073  «ìä¨©áª ï Š®«ìç㣠        àâ¥ä ªâ, í«ìä
          return 1;
        v5 = _43EEF3() == 0;
        goto LABEL_23;
      }
      v2 = GetRace() == 3;                     // 
                                                //  if (uItemID == 533)                         // item113  Š®¢ ­ë¥ ‹ â­ë¥ 㪠¢¨æë    àâ¥ä ªâ, £­®¬
    }
  }
  else
  {
    if ( uItemID != 532 )
    {
      if ( uItemID != 515 && uItemID != 517 )   // 
                                                //  if (uItemID == 534)                         // item104  ®ïá ƒ¥à®ï                 àâ¥ä ªâ, ¬ã¦ç¨­ 
      {
        if ( uItemID == 521 )                   //  if (uItemID == 521 ||                       // item239  ˜«¥¬ ’ «¥¤®­               àâ¥ä ªâ, ¤®¡à®
                                                //      uItemID == 526)                         // item230  ‘¯à ¢¥¤«¨¢®áâì            ५¨ª¢¨ï, ¤®¡à®
        {
LABEL_13:
          v4 = 99;
LABEL_15:
          v5 = (unsigned __int16)_449B57_test_bit(pParty->_quest_bits, v4) == 0;
LABEL_23:
          if ( !v5 )
            return 1;
          return 0;
        }
        if ( uItemID != 525 )
        {
          if ( uItemID != 527 )
          {
            if ( uItemID != 531 )
              return 1;
            v2 = GetRace() == 2;
            goto LABEL_10;
          }
          goto LABEL_13;
        }
      }
      v4 = 100;
      goto LABEL_15;
    }
    v2 = GetRace() == 0;
  }
LABEL_10:
  if ( v2 )
    return 1;
  return 0;
}

//----- (00492D65) --------------------------------------------------------
int Player::SetCondition(unsigned int uConditionIdx, int a3)
    {

    signed int player_sex; // ecx@77
    char zombi_face; // al@80
    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 0;
    players_before = 0;
    for (int i=1;i<5;++i)
        if ( pPlayers[i]->CanAct() )
            ++players_before;

    switch ( uConditionIdx )
        {
    case Condition_Cursed:
        PlaySound((PlayerSpeech)30, 0);
        break;
    case Condition_Weak:
        if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[13].uExpireTime > 0 )
            {--pParty->pPartyBuffs[13].uPower;
        if ( pParty->pPartyBuffs[13].uPower < 1u )
            pParty->pPartyBuffs[13].Reset();
        return 0;
            }

        PlaySound((PlayerSpeech)25, 0);
        break;
    case Condition_Sleep:
        if ( a3 == 1 &&(HasEnchantedItemEquipped(22)||WearsItem(505, 3))) 
            return 0;
        break;

    case Condition_Fear:
        PlaySound((PlayerSpeech)26, 0);
        break;
    case Condition_Drunk:
        PlaySound((PlayerSpeech)31, 0);
        break;

    case Condition_Insane:
        if ( a3 == 1
            && (HasEnchantedItemEquipped(19) || WearsItem(505, 3) || WearsItem(530, 6)) )
            return 0;

        PlaySound((PlayerSpeech)29, 0);
        break;
    case Condition_Poison1:
    case Condition_Poison2:
    case Condition_Poison3:
        if ( a3 == 1 )
            {
            if ( (signed __int64)pParty->pPartyBuffs[13].uExpireTime > 0i64 )
                {
                --pParty->pPartyBuffs[13].uPower;
                if ( pParty->pPartyBuffs[13].uPower < 1u )
                    pParty->pPartyBuffs[13].Reset();
                }
            if ( HasEnchantedItemEquipped(21)
                || WearsItem(505, 3)
                || WearsItem(530, 6) )
                //goto LABEL_76;
                return 0;
            }

        //v23 = 27;
        PlaySound((PlayerSpeech)27, 0);
        break;

    case Condition_Disease1:
    case Condition_Disease2:
    case Condition_Disease3:
        if ( a3 == 1 )
            {            
            if ( pParty->pPartyBuffs[13].uExpireTime > 0i64 )
                {
                --pParty->pPartyBuffs[13].uPower;
                if ( pParty->pPartyBuffs[13].uPower < 1u )
                    pParty->pPartyBuffs[13].Reset();
                return 0;
                }

            if ( HasEnchantedItemEquipped(18) ||WearsItem(505, 3) || WearsItem(530, 6) )
                return 0;
            }
        PlaySound((PlayerSpeech)28, 0);
        break;
    case Condition_Paralyzed:
        if ( a3 == 1 )
            {
            if ( pParty->pPartyBuffs[13].uExpireTime > 0i64 )
                {
                --pParty->pPartyBuffs[13].uPower;
                if ( pParty->pPartyBuffs[13].uPower < 1u )
                    pParty->pPartyBuffs[13].Reset();
                return 0;
                }

            if ( HasEnchantedItemEquipped(20)|| WearsItem(505, 3)|| WearsItem(507, 16)||WearsItem(530, 6))
                return 0;
            }
        break;
    case Condition_Unconcious:
        PlaySound(SPEECH_32, 0);
        if ( sHealth > 0 )
            sHealth = 0;
        break;
    case Condition_Dead:
        if ( a3 == 1 && (signed __int64)pParty->pPartyBuffs[13].uExpireTime > 0i64 && pParty->pPartyBuffs[13].uSkill >= 4u )
            {
            --pParty->pPartyBuffs[13].uPower;
            if ( pParty->pPartyBuffs[13].uPower < 1u )
                pParty->pPartyBuffs[13].Reset();
            }

        PlaySound((PlayerSpeech)33, 0);
        if ( sHealth > 0 )
            sHealth = 0;
        if ( sMana > 0 )
            sMana = 0;
        break;
    case Condition_Pertified:
        if ( a3 == 1
            &&((pParty->pPartyBuffs[13].uExpireTime > 0i64)
            || HasEnchantedItemEquipped(23)|| WearsItem(520, 16) || WearsItem(505, 3) || WearsItem(530, 6)) )

            return 0;
        PlaySound((PlayerSpeech)34, 0);
        break;
    case Condition_Eradicated:
        if ( a3 == 1 && ((signed __int64)pParty->pPartyBuffs[13].uExpireTime > 0 )&&( pParty->pPartyBuffs[13].uSkill >= 4u ))
            {
            --pParty->pPartyBuffs[13].uPower;
            if ( pParty->pPartyBuffs[13].uPower < 1u )
                pParty->pPartyBuffs[13].Reset();
            return 0;
            }
        PlaySound(SPEECH_35, 0);
        if (sHealth > 0 )
            sHealth = 0;
        if ( sMana > 0 )
            sMana = 0;
        break;
    case Condition_Zombie:
        if ( classType == PLAYER_CLASS_LICH || Eradicated() ||Zombie() || !Dead())
            return 0;
        memset(&pConditions[0], 0, sizeof(pConditions));
        sHealth = GetMaxHealth();
        sMana = 0;
        player_sex = 0;
        uPrevFace = uCurrentFace;
        uPrevVoiceID = uVoiceID;
        switch ( uVoiceID )
            {
        case 0:
        case 1:
        case 2:
        case 3:
        case 8:
        case 9:
        case 12:
        case 13:
        case 16:
        case 17:
        case 20:
        case 23:
            player_sex = 0;
            break;
        case 4:
        case 5:
        case 6:
        case 7:
        case 10:
        case 11:
        case 14:
        case 15:
        case 18:
        case 19:
        case 21:
        case 24:
            player_sex = 1;
            break;
        default:
            break;
            }

        zombi_face = (player_sex != 0) + 23;
        uCurrentFace = zombi_face;
        uVoiceID = zombi_face;
        PlaySound((PlayerSpeech)SPEECH_99, 0);
        break;
        }

    remainig_player = 0;
    pConditions[uConditionIdx] = pParty->uTimePlayed;
    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 1;
    }

//----- (00492528) --------------------------------------------------------
bool Player::CanFitItem(unsigned int uSlot, unsigned int uItemID)
{
  //unsigned int v3; // eax@1
  Texture *v4; // esi@1
  unsigned int v5; // ebx@1
  signed int v6; // edi@5
  int *v7; // ecx@6
  signed int v8; // edx@7
  int *v9; // eax@8
  //Player *v11; // [sp+Ch] [bp-4h]@1
  unsigned int uItemIDa; // [sp+1Ch] [bp+Ch]@1

  v4 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
  v5 = GetSizeInInventorySlots(v4->uTextureWidth);
  uItemIDa = GetSizeInInventorySlots(v4->uTextureHeight);
  if ( !areWeLoadingTexture )
  {
    v4->Release();
    pIcons_LOD->SyncLoadedFilesCount();
  }
  if ( (signed int)(v5 + (signed int)uSlot % 14) <= 14 && (signed int)(uItemIDa + (signed int)uSlot / 14) <= 9 )
  {
    v6 = 0;
    if ( (signed int)uItemIDa <= 0 )
      return 1;
    v7 = &pInventoryIndices[uSlot];
    while ( 1 )
    {
      v8 = 0;
      if ( (signed int)v5 > 0 )
        break;
LABEL_11:
      ++v6;
      v7 += 14;
      if ( v6 >= (signed int)uItemIDa )
        return 1;
    }
    v9 = v7;
    while ( !*v9 )
    {
      ++v8;
      ++v9;
      if ( v8 >= (signed int)v5 )
        goto LABEL_11;
    }
  }
  return 0;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (004925E6) --------------------------------------------------------
unsigned int Player::FindFreeInventorySlot()
{
  unsigned int result; // eax@1
  ItemGen *v2; // ecx@1

  result = 0;
  v2 = this->pInventoryItems;
  while ( v2->uItemID )
  {
    ++result;
    ++v2;
    if ( (signed int)result >= 126 )
      return -1;
  }
  return result;
}

//----- (00492600) --------------------------------------------------------
int Player::CreateItemInInventory(unsigned int uSlot, unsigned int uItemID)
{
  signed int v3; // edx@1
  ItemGen *v4; // eax@1
  int result; // eax@8
  unsigned int v6; // ebx@10
  //unsigned int v7; // eax@10
  Texture *v8; // esi@10
  void *v9; // esi@13
  unsigned int v10; // [sp+0h] [bp-Ch]@10
  Player *v11; // [sp+4h] [bp-8h]@1
  signed int v12; // [sp+8h] [bp-4h]@4
  unsigned int uItemIDa; // [sp+18h] [bp+Ch]@10

  v11 = this;
  v3 = 0;
  v4 = this->pInventoryItems;
  while ( v4->uItemID )
  {
    ++v3;
    ++v4;
    if ( v3 >= 126 )
    {
      v12 = -1;
      goto LABEL_5;
    }
  }
  v12 = v3;
LABEL_5:
  if ( v12 == -1 )
  {
    if ( uActiveCharacter )
      pPlayers[uActiveCharacter]->PlaySound(SPEECH_NoRoom, 0);
    result = 0;
  }
  else
  {
    v6 = uItemID;
    v8 = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[uItemID].pIconName, TEXTURE_16BIT_PALETTE);
    v10 = GetSizeInInventorySlots(v8->uTextureWidth);
    uItemIDa = GetSizeInInventorySlots(v8->uTextureHeight);
    if ( !areWeLoadingTexture )
    {
      v8->Release();
      pIcons_LOD->SyncLoadedFilesCount();
    }
    if ( (signed int)uItemIDa > 0 )
    {
      v9 = &v11->pInventoryIndices[uSlot];
      do
      {
        if ( (signed int)v10 > 0 )
          memset32(v9, -1 - uSlot, v10);
        v9 = (char *)v9 + 56;
        --uItemIDa;
      }
      while ( uItemIDa );
    }
    result = v12 + 1;
    v11->pInventoryIndices[uSlot] = v12 + 1;
    v11->pInventoryItems[v12].uItemID = v6;
  }
  return result;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (00492700) --------------------------------------------------------
int Player::HasSkill(unsigned int uSkillType)
{
  signed int result; // eax@3

  if ( (signed int)uSkillType >= 37 || this->pActiveSkills[uSkillType] )
  {
    result = 1;
  }
  else
  {
    sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[67], this->pName);
    ShowStatusBarString(pTmpBuf, 2u);
    result = 0;
  }
  return result;
}

//----- (00492745) --------------------------------------------------------
int Player::WearItem(unsigned int uItemID)
{
  int item_body_anch; // edi@6
  int item_indx;
  //find empty slot
  for(item_indx=0;item_indx<126;++item_indx)
      if (pInventoryItems[item_indx].uItemID==0)
          break; 
  if (item_indx==126) //not found
      item_indx=-1;
  
  if ( item_indx != -1 )
  {

    pInventoryItems[item_indx].uItemID=uItemID;
    item_body_anch=pEquipTypeToBodyAnchor[pItemsTable->pItems[uItemID].uEquipType];
    pEquipment.pIndices[item_body_anch]=item_indx+1;
    pInventoryItems[item_indx].uBodyAnchor=item_body_anch+1;

  }
  return 0;
}

//----- (004927A8) --------------------------------------------------------
int Player::AddItem(int uSlot, unsigned int uItemID)
{
  signed int v3; // ebx@2
  signed int v4; // edi@3
  unsigned int v5; // esi@3
  unsigned int v7; // [sp-8h] [bp-18h]@8
  unsigned int v8; // [sp-4h] [bp-14h]@8
  Player *thisa; // [sp+Ch] [bp-4h]@1

  thisa = this;
  if ( uSlot == -1 )
  {
    v3 = 0;
    while ( true )
    {
      v4 = 0;
      v5 = v3;
      do
      {
        if ( CanFitItem(v5, uItemID) )
        {
          v8 = uItemID;
          v7 = v5;
          return CreateItemInInventory(v7, v8);
        }
        ++v4;
        v5 += 14;
      }
      while ( v4 < 9 );
      ++v3;
      if ( v3 < 14 )
        continue;
      break;
    }
    return 0;
  }
  if ( !CanFitItem(uSlot, uItemID) )
  {
    pAudioPlayer->PlaySound(SOUND_27, 0, 0, -1, 0, 0, 0, 0);
    return 0;
  }
  v8 = uItemID;
  v7 = uSlot;
  return CreateItemInInventory(v7, v8);
}

//----- (00492826) --------------------------------------------------------
int Player::AddItem2(int uSlot, ItemGen *Src)
{
  unsigned int v3; // ebx@1
  unsigned int v4; // esi@3
  signed int v5; // edi@3
  unsigned int v7; // [sp-8h] [bp-18h]@9
  ItemGen *v8; // [sp-4h] [bp-14h]@9
  Player *thisa; // [sp+Ch] [bp-4h]@1
  signed int uSlota; // [sp+18h] [bp+8h]@2

  thisa = this;
  v3 = Src->uItemID;
  pItemsTable->SetSpecialBonus(Src);
  if ( uSlot == -1 )
  {
    uSlota = 0;
    while ( true )
    {
      v4 = uSlota;
      v5 = 0;
      do
      {
        if ( CanFitItem(v4, v3) )
        {
          v8 = Src;
          v7 = v4;
          return CreateItemInInventory2(v7, v8);
        }
        ++v5;
        v4 += 14;
      }
      while ( v5 < 14 );
      ++uSlota;
      if ( uSlota < 9 )
        continue;
      break;
    }
    return 0;
  }
  if ( !CanFitItem(uSlot, v3) )
    return 0;
  v8 = Src;
  v7 = uSlot;
  return CreateItemInInventory2(v7, v8);
}

//----- (0049289C) --------------------------------------------------------
int Player::CreateItemInInventory2(unsigned int uSlot, ItemGen *Src)
{
  signed int v3; // ebx@1
  ItemGen *v4; // eax@1
  int result; // eax@6
  //unsigned int v6; // eax@7
  Texture *item_texture; // esi@7
  unsigned int v8; // edx@9
  int *pInvPos; // esi@10
  unsigned int slot_width; // [sp+4h] [bp-Ch]@7
  unsigned int slot_height; // [sp+8h] [bp-8h]@7
  Player *v12; // [sp+Ch] [bp-4h]@1


  v12 = this;
  v3 = 0;
  v4 = this->pInventoryItems;
  while ( v4->uItemID )
  {
    ++v3;
    ++v4;
    if ( v3 >= 126 )
    {
      v3 = -1;
      break;
    }
  }
  if ( v3 == -1 )
  {
    result = 0;
  }
  else
  {
    item_texture = pIcons_LOD->LoadTexturePtr(pItemsTable->pItems[Src->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_height > 0 )
    {
      pInvPos = &pInventoryIndices[uSlot];
      do
      {
        if ( slot_width > 0 )
          memset32(pInvPos, -1 - uSlot, slot_width);
        pInvPos +=14;
        --slot_height;
      }
      while ( slot_height );
    }
    pInventoryIndices[uSlot] = v3 + 1;
    memcpy(&pInventoryItems[v3], Src, sizeof(ItemGen));
    result = v3 + 1;
  }
  return result;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (0049298B) --------------------------------------------------------
int Player::PutItemArInventoryIndex( ItemGen *item, int item_id, int uSlot )
    {
  //Player *v4; // ebx@1
  //unsigned int v5; // eax@1
  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[item->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 ( (signed int)slot_height > 0 )
  {
    pInvPos = &pInventoryIndices[uSlot]; //14x9
    do
    {
      if ( (signed int)slot_width > 0 )
        memset32(pInvPos, -1 - uSlot, slot_width);
      pInvPos +=14;
      --slot_height;
    }
    while ( slot_height );
  }
  pInventoryIndices[uSlot] = item_id + 1;
  return 1;
}

// 506128: using guessed type int areWeLoadingTexture;

//----- (00492A36) --------------------------------------------------------
void Player::RemoveItemAtInventoryIndex( unsigned int uSlot )
    {

  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->pInventoryItems[pInventoryIndices[uSlot]-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_height > 0 )
  {
    pInvPos = &pInventoryIndices[uSlot];
    do
    {
      if (slot_width > 0 )
        memset32(pInvPos, 0, slot_width);
      pInvPos += 14;
      --slot_height;
    }
    while ( slot_height );
  }
  
}
// 506128: using guessed type int areWeLoadingTexture;

//identf
//----- (00490EEE) --------------------------------------------------------
int Player::SelectPhrasesTransaction(ItemGen *pItem, int building_type, int BuildID_2Events, int ShopMenuType)
{
  int pSkillLevel; // eax@1
  int NotBuy; // eax@1
  int result;
  signed int pEquipType; // esi@1
  float *pPriceMultiplier; // esi@26
  int pPriceItemService; // edi@26

  pSkillLevel = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
  NotBuy = 4;
  pEquipType = pItemsTable->pItems[pItem->uItemID].uEquipType;
  if ( (building_type != 4 || (signed int)pItem->uItemID < 740 || (signed int)pItem->uItemID > 771)
    && ((signed int)pItem->uItemID >= 600 || (signed int)pItem->uItemID >= 529 && (signed int)pItem->uItemID <= 599) )
    return 5;
  if ( building_type == BildingType_WeaponShop )
  {
    if ( pEquipType > EQUIP_BOW )
      return NotBuy;
    if (pItem->Stolen())
      return 6;
  }
  if ( building_type == BildingType_ArmorShop )
  {
    if ( pEquipType < 3 && pEquipType > 9 )
      return NotBuy;
    if (pItem->Stolen())
      return 6;
  }
  if ( building_type == BildingType_MagicShop )
  {
    if ( pItemsTable->pItems[pItem->uItemID].uSkillType == 38 )
    {
      if (pItem->Stolen())
        return 6;
      pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
      pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
      if ( ShopMenuType == 3 )//Sell
      {
        pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
        if (!pItem->Broken())
        {
          if ( pSkillLevel )
            result = (pPriceItemService == pItem->GetValue()) + 2;
          else
            result = 1;
          return result;
        }
        pPriceItemService = 1;
        if ( pSkillLevel )
          result = (pPriceItemService == pItem->GetValue()) + 2;
        else
          result = 1;
        return result;
      }
      if ( ShopMenuType == 4 )//Identify
      {
        pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
        if ( pSkillLevel )
          result = (pPriceItemService == pItem->GetValue()) + 2;
        else
          result = 1;
        return result;
      }
      if ( ShopMenuType == 5 )//Repair
      {
        pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
        if ( pSkillLevel )
          result = (pPriceItemService == pItem->GetValue()) + 2;
        else
          result = 1;
        return result;
      }
      if ( ShopMenuType != 6 )//Buy and ???
      {
        if ( pSkillLevel )
          result = (pPriceItemService == pItem->GetValue()) + 2;
        else
          result = 1;
        return result;
      }
      pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
      if (pItem->Broken())
        pPriceItemService = 1;
      if ( pPriceItemService >= 1 )
      {
        if ( pSkillLevel )
          result = (pPriceItemService == pItem->GetValue()) + 2;
        else
          result = 1;
        return result;
      }
      pPriceItemService = 1;
      if ( pSkillLevel )
        result = (pPriceItemService == pItem->GetValue()) + 2;
      else
        result = 1;
      return result;
    }
    if ( pEquipType != EQUIP_BOOK )
      return NotBuy;
  }
  if ( building_type == BildingType_AlchemistShop )
  {
    if ( pEquipType < EQUIP_REAGENT )
      return NotBuy;
    if ( pEquipType > EQUIP_POTION )
    {
      if ( pEquipType != EQUIP_MESSAGE_SCROLL )
        return NotBuy;
    }
    if (pItem->Stolen())
      return 6;
  }
  pPriceMultiplier = &p2DEvents[BuildID_2Events - 1].fPriceMultiplier;
  pPriceItemService = GetBuyingPrice(pItem->GetValue(), *pPriceMultiplier);
  if ( ShopMenuType == 3 )//Sell
  {
    pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier);
    if (!pItem->Broken())
    {
      if ( pSkillLevel )
        result = (pPriceItemService == pItem->GetValue()) + 2;
      else
        result = 1;
      return result;
    }
    pPriceItemService = 1;
    if ( pSkillLevel )
      result = (pPriceItemService == pItem->GetValue()) + 2;
    else
      result = 1;
    return result;
  }
  if ( ShopMenuType == 4 )//Identify
  {
    pPriceItemService = this->GetPriceIdentification(*pPriceMultiplier);
    if ( pSkillLevel )
      result = (pPriceItemService == pItem->GetValue()) + 2;
    else
      result = 1;
    return result;
  }
  if ( ShopMenuType == 5 )//Repair
  {
    pPriceItemService = this->GetPriceRepair(pItem->GetValue(), *pPriceMultiplier);
    if ( pSkillLevel )
      result = (pPriceItemService == pItem->GetValue()) + 2;
    else
      result = 1;
    return result;
  }
  if ( ShopMenuType != 6 )//Buy and ???
  {
    if ( pSkillLevel )
      result = (pPriceItemService == pItem->GetValue()) + 2;
    else
      result = 1;
    return result;
  }
  pPriceItemService = this->GetPriceSell(pItem->GetValue(), *pPriceMultiplier) / 2;
  if (pItem->Broken())
    pPriceItemService = 1;
  if ( pPriceItemService >= 1 )
  {
    if ( pSkillLevel )
      result = (pPriceItemService == pItem->GetValue()) + 2;
    else
      result = 1;
    return result;
  }
  pPriceItemService = 1;
  if ( pSkillLevel )
    result = (pPriceItemService == pItem->GetValue()) + 2;
  else
    result = 1;
  return result;
}

//----- (0049107D) --------------------------------------------------------
int Player::GetBodybuilding()
{
  int v1; // al@1
  int v2; // ecx@1
  int v4; // eax@3
  signed int v6; // [sp-4h] [bp-4h]@2

  v1 = GetActualSkillLevel(PLAYER_SKILL_BODYBUILDING);
  v2 = v1 & 0x3F;
  if ( v1 & 0x100 )
  {
    v6 = 5;
  }
  else
  {
    if ( (v1&0xFF) >= 0 )
    {
      v4 = ((v1 & 0x40) != 0) + 1;
      return v2 * v4;
    }
    v6 = 3;
  }
  v4 = v6;
  return v2 * v4;
}

//----- (004910A8) --------------------------------------------------------
int Player::GetMeditation()
{
  int v1; // al@1
  int base_level; // ecx@1
  int v4; // eax@3
  signed int v6; // [sp-4h] [bp-4h]@2

  v1 = GetActualSkillLevel(PLAYER_SKILL_MEDITATION);
  base_level = v1 & 0x3F;
  if ( v1 & 0x100 )
  {
    v6 = 5;
  }
  else
  {
    if ( (v1&0xFF) >= 0 )
    {
      v4 = ((v1 & 0x40) != 0) + 1;
      return base_level * v4;
    }
    v6 = 3;
  }
  v4 = v6;
  return base_level * v4;
}

//----- (004910D3) --------------------------------------------------------
int Player::CanIdentify(ItemGen *pItem)
{
  unsigned __int16 v2; // ax@1
  unsigned __int16 v3; // bx@1
  int uSkillMult; // eax@3
  int v5; // edi@7
  signed int v6; // ebp@7
  char *v7; // esi@7
  signed int uSkillMultiplier; // [sp-4h] [bp-14h]@2
  
  if (CheckHiredNPCSpeciality(Scholar))
    return true;

  v2 = pPlayers[uActiveCharacter]->GetActualSkillLevel(PLAYER_SKILL_ITEM_ID);
  v3 = v2;
  if ( v2 & 1 )
  {
    uSkillMultiplier = 5;
  }
  else
  {
    if ( (v2 & 0x80u) == 0 )
    {
      uSkillMult = ((v2 & 0x40) != 0) + 1;
      v5 = uSkillMult * (v3 & 0x3F);
      v6 = 0;
      v7 = (char *)&pItemsTable->pItems[pItem->uItemID].pIconName;

      if ( (signed int)SkillToMastery(v3) >= 4 )
        v6 = 1;
      if ( v5 >= (unsigned __int8)v7[46] )
        v6 = 1;
      return v6;
    }
    uSkillMultiplier = 3;
  }
  uSkillMult = uSkillMultiplier;
  v5 = uSkillMult * (v3 & 0x3F);
  v6 = 0;
  v7 = (char *)&pItemsTable->pItems[pItem->uItemID].pIconName;

  if ( (signed int)SkillToMastery(v3) >= 4 )
    v6 = 1;
  if ( v5 >= (unsigned __int8)v7[46] )
    v6 = 1;
  return v6;
}

//----- (00491151) --------------------------------------------------------
int Player::CanRepair(ItemGen *a2)
{
  unsigned __int16 v2; // ax@1
  unsigned __int16 v3; // bx@1
  int v4; // eax@3
  int v5; // edi@7
  signed int v6; // ebp@7
  signed int v10; // [sp-4h] [bp-14h]@2

  
  auto v7 = &pItemsTable->pItems[a2->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);
  v3 = v2;
  if (v2 & 0x100 )
  {
    v10 = 5;
  }
  else
  {
    if ( (v2 & 0x80u) == 0 )
    {
      v4 = ((v2 & 0x40) != 0) + 1;
      goto LABEL_7;
    }
    v10 = 3;
  }
  v4 = v10;
LABEL_7:
  v5 = v4 * (v3 & 0x3F);
  v6 = 0;
  if ( (signed int)SkillToMastery(v3) >= 4 )
    return true;
  if ( v5 >= *((char *)(v7 + 1) + 2) )
  {
    __debugbreak(); // really odd
    return true;
  }
  return false;
}

//----- (004911F3) --------------------------------------------------------
int Player::GetMerchant()
{
  Player *v1; // edi@1
  unsigned __int16 v2; // ax@1
  unsigned __int16 v3; // bx@1
  int v4; // esi@1
  int v5; // edi@1
  int v7; // eax@3
  int v8; // ecx@7
  signed int v9; // [sp-4h] [bp-10h]@6

  v1 = this;
  v2 = GetActualSkillLevel(PLAYER_SKILL_MERCHANT);
  v3 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT];
  v4 = v2 & 0x003F;
  v5 = v1->pActiveSkills[PLAYER_SKILL_MERCHANT] & 0x3F;
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return 10000;
  v7 = GetPartyReputation();
  if ( !v4 )
    return -v7;
  if ( v3 & 0x100 )
  {
    v9 = 5;
  }
  else
  {
    if ( (v3 & 0x80u) == 0 )
    {
      v8 = ((v3 & 0x40) != 0) + 1;
      return v5 * (v8 - 1) - v7 + v4 + 7;
    }
    v9 = 3;
  }
  v8 = v9;
  return v5 * (v8 - 1) - v7 + v4 + 7;
}

//----- (0049125A) --------------------------------------------------------
int Player::GetPerception()
{
  Player *v1; // edi@1
  unsigned __int16 v2; // ax@1
  unsigned __int16 v3; // bx@1
  int v4; // esi@1
  int v5; // edi@1
  int v7; // eax@5
  signed int v8; // [sp-4h] [bp-10h]@4

  v1 = this;
  v2 = GetActualSkillLevel(PLAYER_SKILL_PERCEPTION);
  v3 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION];
  v4 = v2 & 0x3F;
  v5 = v1->pActiveSkills[PLAYER_SKILL_PERCEPTION] & 0x3F;
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return 10000;
  if ( v3 & 0x100 )
  {
    v8 = 5;
  }
  else
  {
    if ( (v3 & 0x80u) == 0 )
    {
      v7 = ((v3 & 0x40) != 0) + 1;
      return v4 + v5 * (v7 - 1);
    }
    v8 = 3;
  }
  v7 = v8;
  return v4 + v5 * (v7 - 1);
}

//----- (004912B0) --------------------------------------------------------
int Player::GetDisarmTrap()
{
  Player *v1; // ebp@1
  unsigned __int16 v2; // ax@1
  unsigned __int16 v3; // bx@1
  int v4; // esi@1
  int v5; // edi@1
  int v7; // eax@7
  signed int v8; // [sp-4h] [bp-14h]@6

  v1 = this;
  v2 = GetActualSkillLevel(PLAYER_SKILL_TRAP_DISARM);
  v3 = v1->pActiveSkills[29];
  v4 = v2 & 0x3F;
  v5 = v1->pActiveSkills[29] & 0x3F;
  if ( (signed int)SkillToMastery(v2) >= 4 )
    return 10000;
  if ( HasEnchantedItemEquipped(35) )
    v4 *= 2;
  if ( v3 & 0x100 )
  {
    v8 = 5;
  }
  else
  {
    if ( (v3 & 0x80u) == 0 )
    {
      v7 = ((v3 & 0x40) != 0) + 1;
      return v4 + v5 * (v7 - 1);
    }
    v8 = 3;
  }
  v7 = v8;
  return v4 + v5 * (v7 - 1);
}

//----- (00491317) --------------------------------------------------------
char Player::GetLearningPercent()
{
  Player *v1; // esi@1
  int v2; // eax@1
  unsigned __int16 v3; // bx@1
  int v4; // ecx@1
  int v5; // eax@4
  signed int v7; // [sp-4h] [bp-Ch]@3

  v1 = this;
  v2 = GetActualSkillLevel(PLAYER_SKILL_LEARNING);
  v3 = v1->pActiveSkills[36];
  v4 = v2 & 0x3F;
  if ( v2 )
  {
    if (v3 & 0x100 )
    {
      v7 = 5;
    }
    else
    {
      if ( (v3 & 0x80u) == 0 )
      {
        v5 = ((v3 & 0x40) != 0) + 1;
        goto LABEL_8;
      }
      v7 = 3;
    }
    v5 = v7;
LABEL_8:
    v2 = (v1->pActiveSkills[36] & 0x3F) * (v5 - 1) + v4 + 9;
  }
  return v2;
}

//----- (0048C6AF) --------------------------------------------------------
Player::Player()
{  
  memset(&pEquipment, 0, sizeof(PlayerEquipment));
  memset(pInventoryIndices, 0, 126 * sizeof(int));
  for (uint i = 0; i < 126; ++i)
    pInventoryItems[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;

//  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::AddItem(ItemGen *pItem)
{
  unsigned int v2; // eax@1
  unsigned int v3; // ecx@4
  signed int v4; // edx@4
  char *v5; // eax@8
  //unsigned int v6; // eax@10
  Texture *v7; // ebx@10
  signed int v8; // esi@10
  Player *v9; // edi@11
  int v10; // eax@11
  bool result; // eax@15
  std::string v12; // [sp-18h] [bp-40h]@9


  int v15[4] = {0, 1, 2, 3}; // [sp+Ch] [bp-1Ch]@3
  //int v16; // [sp+10h] [bp-18h]@3
  //int v17; // [sp+14h] [bp-14h]@3
  //int v18; // [sp+18h] [bp-10h]@3
  Player *v19; // [sp+1Ch] [bp-Ch]@9
  Party *v20; // [sp+20h] [bp-8h]@1
  int v21; // [sp+24h] [bp-4h]@10

  auto thos = this;

  v20 = thos;
  v2 = pItem->uItemID;
  if ( !pItemsTable->pItems[v2].uItemID_Rep_St )
    pItem->SetIdentified();
  ///v15 = 0;
  //v16 = 1;
  //v18 = 3;
  //v17 = 2;
  if ( uActiveCharacter )
  {
    v3 = uActiveCharacter - 1;
    v4 = 0;
    do
    {
      v15[v4++] = v3++;
      if ( (signed int)v3 >= 4 )
        v3 = 0;
    }
    while ( v4 < 4 );
  }
  v5 = pItemsTable->pItems[v2].pIconName;
  if ( v5 )
  {
    v7 = pIcons_LOD->LoadTexturePtr(v5, TEXTURE_16BIT_PALETTE);
    v21 = areWeLoadingTexture;
    v8 = 0;
    while ( 1 )
    {
      v9 = &v20->pPlayers[v15[v8]];
      v19 = &v20->pPlayers[v15[v8]];
      v10 = v19->AddItem(-1, pItem->uItemID);
      if ( v10 )
        break;
      ++v8;
      if ( v8 >= 4 )
      {
        if ( !v21 )
        {
          v7->Release();
          pIcons_LOD->SyncLoadedFilesCount();
        }
        goto LABEL_15;
      }
    }
    memcpy(&v9->pInventoryItems[v10-1], pItem, 0x24u);
    pItem->Reset();
    pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
    v19->PlaySound(SPEECH_60, 0);
    if ( !v21 )
    {
      v7->Release();
      pIcons_LOD->SyncLoadedFilesCount();
    }
    result = 1;
  }
  else
  {
    MessageBoxW(nullptr, L"Invalid picture_name detected ::addItem()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Party.cpp:795", 0);
LABEL_15:
    result = 0;
  }
  return result;
}
// 506128: using guessed type int areWeLoadingTexture;

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

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

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

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

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

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

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

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

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

//----- (0048C93C) --------------------------------------------------------
int Player::GetActualMight()
{
  Player *v1; // esi@1
  unsigned int v2; // eax@1
  signed int v3; // ecx@1
  signed int v4; // ebx@4
  int v5; // edi@5
  int v6; // ST14_4@5

  v1 = this;
  v2 = this->sAgeModifier + GetBaseAge();
  v3 = 0;
  while ( (signed int)v2 >= (signed int)pAgeingTable[v3] )
  {
    ++v3;
    if ( v3 >= 4 )
    {
      v4 = 100;
      goto LABEL_5;
    }
  }
  v4 = pAgeingStrengthMultiplier[v3];
LABEL_5:
  v5 = pConditionStrengthMultiplier[GetMajorConditionIdx()];
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_STRENGTH, 0);
  return v5 * v4 * v1->uMight / 100 / 100 + GetMagicalBonus((CHARACTER_ATTRIBUTE_TYPE)0) + v6 + v1->uMightBonus;
}

//----- (0048C9C2) --------------------------------------------------------
int Player::GetActualIntelligence()
{
  Player *v1; // esi@1
  unsigned int sAge; // eax@1
  signed int uAgeLevel; // ecx@1
  signed int v4; // ebx@4
  int v5; // edi@5
  int v6; // ebp@5

  v1 = this;
  sAge = this->sAgeModifier + GetBaseAge();
  uAgeLevel = 0;
  while ( (signed int)sAge >= (signed int)pAgeingTable[uAgeLevel] )
  {
    ++uAgeLevel;
    if ( uAgeLevel >= 4 )
    {
      v4 = 100;
      goto LABEL_5;
    }
  }
  v4 = pAgeingIntelligenceMultiplier[uAgeLevel];
LABEL_5:
  v5 = pConditionIntelligenceMultiplier[GetMajorConditionIdx()];
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_INTELLIGENCE, 0);
  return v5 * v4 * v1->uIntelligence / 100 / 100
       + GetMagicalBonus(CHARACTER_ATTRIBUTE_INTELLIGENCE)
       + v6
       + v1->uIntelligenceBonus;
}

//----- (0048CA3F) --------------------------------------------------------
int Player::GetActualWillpower()
{
  int v5; // edi@5
  
  uint uActualAge = GetBaseAge() + sAgeModifier;
  uint uAgeingMultiplier = 100;
  for (uint i = 0; i < 4; ++i)
    if (uActualAge >= pAgeingTable[i])
      uAgeingMultiplier = pAgeingWillpowerMultiplier[i];
    else break;

  v5 = pConditionWillpowerMultiplier[GetMajorConditionIdx()];
  return v5 * uAgeingMultiplier * uWillpower / 100 / 100
       + GetMagicalBonus(CHARACTER_ATTRIBUTE_WILLPOWER)
       + GetItemsBonus(CHARACTER_ATTRIBUTE_WILLPOWER, 0)
       + uWillpowerBonus;
}

//----- (0048CABC) --------------------------------------------------------
int Player::GetActualEndurance()
{
  uint uActualAge = GetBaseAge() + sAgeModifier;
  uint uAgeingMultiplier = 100;
  for (uint i = 0; i < 4; ++i)
    if (uActualAge >= pAgeingTable[i])
      uAgeingMultiplier = pAgeingEnduranceMultiplier[i];
    else break;

  auto uConditionMult = pConditionEnduranceMultiplier[GetMajorConditionIdx()];
  auto uItemBonus = GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0);
  return uConditionMult * uAgeingMultiplier * uEndurance / 100 / 100
       + GetMagicalBonus(CHARACTER_ATTRIBUTE_ENDURANCE)
       + uItemBonus
       + uEnduranceBonus;
}

//----- (0048CB39) --------------------------------------------------------
int Player::GetActualAccuracy()
{
  Player *v1; // esi@1
  unsigned int v2; // eax@1
  signed int v3; // ecx@1
  signed int v4; // ebx@4
  int v5; // edi@5
  int v6; // ebp@5

  v1 = this;
  v2 = this->sAgeModifier + GetBaseAge();
  v3 = 0;
  while ( (signed int)v2 >= (signed int)pAgeingTable[v3] )
  {
    ++v3;
    if ( v3 >= 4 )
    {
      v4 = 100;
      goto LABEL_5;
    }
  }
  v4 = pAgeingAccuracyMultiplier[v3];
LABEL_5:
  v5 = pConditionAccuracyMultiplier[GetMajorConditionIdx()];
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_ACCURACY, 0);
  return v5 * v4 * v1->uAccuracy / 100 / 100
       + GetMagicalBonus(CHARACTER_ATTRIBUTE_ACCURACY)
       + v6
       + v1->uAccuracyBonus;
}

//----- (0048CBB6) --------------------------------------------------------
int Player::GetActualSpeed()
{
  Player *v1; // esi@1
  unsigned int v2; // eax@1
  signed int v3; // ecx@1
  signed int v4; // ebx@4
  int v5; // edi@5
  int v6; // ebp@5

  v1 = this;
  v2 = this->sAgeModifier + GetBaseAge();
  v3 = 0;
  while ( (signed int)v2 >= (signed int)pAgeingTable[v3] )
  {
    ++v3;
    if ( v3 >= 4 )
    {
      v4 = 100;
      goto LABEL_5;
    }
  }
  v4 = pAgeingSpeedMultiplier[v3];
LABEL_5:
  v5 = pConditionSpeedMultiplier[GetMajorConditionIdx()];
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_SPEED, 0);
  return v5 * v4 * v1->uSpeed / 100 / 100
       + GetMagicalBonus(CHARACTER_ATTRIBUTE_SPEED)
       + v6
       + v1->uSpeedBonus;
}

//----- (0048CC33) --------------------------------------------------------
int Player::GetActualLuck()
{
  Player *v1; // esi@1
  unsigned int v2; // eax@7
  signed int v3; // ecx@7
  signed int v4; // ebx@10
  int v5; // edi@11
  int v6; // ebp@11
  signed int v8; // [sp+10h] [bp-4h]@1

  v8 = 0;
  v1 = this;
  if ( CheckHiredNPCSpeciality(Fool) )
    v8 = 5;
  if ( CheckHiredNPCSpeciality(ChimneySweep) )
    v8 += 20;
  if ( CheckHiredNPCSpeciality(Psychic) )
    v8 += 10;
  v2 = v1->sAgeModifier + GetBaseAge();
  v3 = 0;
  while ( (signed int)v2 >= (signed int)pAgeingTable[v3] )
  {
    ++v3;
    if ( v3 >= 4 )
    {
      v4 = 100;
      goto LABEL_11;
    }
  }
  v4 = pAgeingLuckMultiplier[v3];
LABEL_11:
  v5 = pConditionLuckMultiplier[GetMajorConditionIdx()];
  v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_LUCK, 0);
  return GetMagicalBonus(CHARACTER_ATTRIBUTE_LUCK)
       + v6
       + v8
       + v5 * v4 * v1->uLuck / 100 / 100
       + v1->uLuckBonus;
}

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

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

//----- (0048CD45) --------------------------------------------------------
int Player::GetMeleeDamageMinimal()
{
  Player *v1; // edi@1
  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

  v1 = this;
  v2 = GetActualMight();
  v3 = _48EA1B_get_static_effect(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, 0) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v4;
  v6 = v1->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v5;
  result = 1;
  if ( v6 >= 1 )
    result = v6;
  return result;
}

//----- (0048CD90) --------------------------------------------------------
int Player::GetMeleeDamageMaximal()
{
  Player *v1; // edi@1
  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

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

//----- (0048CDDB) --------------------------------------------------------
int Player::CalculateMeleeDamageTo(int a2, int a3, unsigned int uTargetActorID)
{
  int v4; // esi@1
  Player *v5; // edi@1
  ItemGen *v6; // ebx@4
  unsigned int v7; // ebp@4
  unsigned int v8; // esi@4
  int v9; // eax@4
  int v10; // eax@9
  char v11; // zf@9
  int v12; // esi@10
  int v13; // eax@11
  enum MONSTER_SUPERTYPE v14; // edx@24
  ItemGen *v15; // ebx@35
  unsigned int v16; // ebp@35
  unsigned int v17; // esi@35
  int v18; // edx@38
  int v19; // eax@40
  enum MONSTER_SUPERTYPE v20; // edx@53
  int v21; // esi@62
  int v22; // eax@63
  int v23; // ebx@63
  int v24; // ebx@63
  signed int result; // eax@64
  MONSTER_SUPERTYPE v26; // [sp-4h] [bp-24h]@20
  MONSTER_SUPERTYPE v27; // [sp-4h] [bp-24h]@49
  int v28; // [sp+10h] [bp-10h]@1
  int v29; // [sp+10h] [bp-10h]@33
  signed int v30; // [sp+14h] [bp-Ch]@7
  signed int v31; // [sp+14h] [bp-Ch]@36
  int v32; // [sp+18h] [bp-8h]@1
  int v33; // [sp+18h] [bp-8h]@8
  int v34; // [sp+1Ch] [bp-4h]@1
  int v35; // [sp+28h] [bp+8h]@37

  v4 = 0;
  v5 = this;
  v34 = 0;
  v32 = 0;
  v28 = 0;
  if ( IsUnarmed() == 1 )
  {
    v32 = rand() % 3 + 1;
LABEL_61:
    v34 = v4;
    goto LABEL_62;
  }
  if ( HasItemEquipped(EQUIP_MAIN_HAND) )
  {
    v6 = (ItemGen *)&v5->pInventoryItems[v5->pEquipment.uMainHand-1];
    v7 = v6->uItemID;
    v8 = v6->uItemID;
    v9 = pItemsTable->pItems[v8].uDamageDice;
    if ( pItemsTable->pItems[v8].uSkillType == PLAYER_SKILL_SPEAR && !v5->pEquipment.uShield )
      ++v9;
    v30 = pItemsTable->pItems[v8].uDamageRoll;
    if ( v9 > 0 )
    {
      v33 = v9;
      do
      {
        v10 = rand();
        v11 = v33-- == 1;
        v28 += v10 % v30 + 1;
      }
      while ( !v11 );
    }
    v12 = pItemsTable->pItems[v8].uDamageMod + v28;
    if ( !uTargetActorID )
      goto LABEL_28;
    v13 = v6->uSpecEnchantmentType;
    if ( v13 == 64 || v7 == 507 || v7 == 508 || v7 == 527 )
    {
      v14 = (MONSTER_SUPERTYPE)1;
    }
    else
    {
      if ( v13 == 39 )
      {
        v26 = MONSTER_SUPERTYPE_KREEGAN;
      }
      else
      {
        if ( v13 == 40 )
        {
          v26 = MONSTER_SUPERTYPE_DRAGON;
        }
        else
        {
          if ( v13 == 63 || v7 == 517 )
          {
            v26 = MONSTER_SUPERTYPE_ELF;
          }
          else
          {
            if ( v13 != 65 )
            {
LABEL_28:
              if ( (signed int)SkillToMastery(v5->pActiveSkills[2]) >= 3
                && pItemsTable->pItems[v6->uItemID].uSkillType == 2
                && rand() % 100 < 10 )
                v12 *= 3;
              v32 = v12;
              goto LABEL_33;
            }
            v26 = MONSTER_SUPERTYPE_TITAN;
          }
        }
      }
      v14 = v26;
    }
    if ( MonsterStats::BelongsToSupertype(uTargetActorID, v14) )
      v12 *= 2;
    goto LABEL_28;
  }
LABEL_33:
  v29 = 0;
  if ( !a3 )
  {
    if ( v5->HasItemEquipped((ITEM_EQUIP_TYPE)0) )
    {
      v15 = (ItemGen *)&v5->pInventoryItems[v5->pEquipment.uShield - 1];
      v16 = v15->uItemID;
      v17 = v15->uItemID;
      if ( pItemsTable->pItems[v17].uEquipType != 4 )
      {
        v31 = pItemsTable->pItems[v17].uDamageRoll;
        if ( (signed int)pItemsTable->pItems[v17].uDamageDice > 0 )
        {
          v35 = pItemsTable->pItems[v17].uDamageDice;
          do
          {
            v18 = rand() % v31;
            v11 = v35-- == 1;
            v29 += v18 + 1;
          }
          while ( !v11 );
        }
        v4 = pItemsTable->pItems[v17].uDamageMod + v29;
        if ( !uTargetActorID )
          goto LABEL_57;
        v19 = v15->uSpecEnchantmentType;
        if ( v19 == 64 || v16 == 507 || v16 == 508 || v16 == 527 )
        {
          v20 = (MONSTER_SUPERTYPE)1;
        }
        else
        {
          if ( v19 == 39 )
          {
            v27 = MONSTER_SUPERTYPE_KREEGAN;
          }
          else
          {
            if ( v19 == 40 )
            {
              v27 = MONSTER_SUPERTYPE_DRAGON;
            }
            else
            {
              if ( v19 == 63 || v16 == 517 )
              {
                v27 = MONSTER_SUPERTYPE_ELF;
              }
              else
              {
                if ( v19 != 65 )
                {
LABEL_57:
                  if ( pItemsTable->pItems[v15->uItemID].uSkillType == PLAYER_SKILL_DAGGER
                    && SkillToMastery(v5->pActiveSkills[2] >= 3u)
                    && rand() % 100 < 10 )
                    v4 *= 3;
                  goto LABEL_61;
                }
                v27 = MONSTER_SUPERTYPE_TITAN;
              }
            }
          }
          v20 = v27;
        }
        if ( MonsterStats::BelongsToSupertype(uTargetActorID, v20) )
          v4 *= 2;
        goto LABEL_57;
      }
    }
  }
LABEL_62:
  v21 = v32 + v34;
  if ( !a2 )
  {
    v22 = GetActualMight();
    v23 = _48EA1B_get_static_effect(v22);
    v24 = GetSkillBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v23;
    v21 += v5->_melee_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS) + v24;
  }
  result = 1;
  if ( v21 >= 1 )
    result = v21;
  return result;
}

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

  v1 = this;
  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
  if ( v2 < 64 || v2 > 65 )
  {
    v4 = GetActualAccuracy();
    v5 = _48EA1B_get_static_effect(v4);
    v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK, 0) + v5;
    v7 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v6;
    v3 = v1->_ranged_atk_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_ATTACK) + v7;
  }
  else
  {
    v3 = GetActualAttack(1);
  }
  return v3;
}

//----- (0048D124) --------------------------------------------------------
int Player::GetRangedDamageMin()
{
  Player *v1; // esi@1
  int v2; // edi@1
  int v3; // edi@1
  int v4; // edi@1
  unsigned __int16 v5; // ax@1
  int result; // eax@6

  v1 = this;
  v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_MIN, 0);
  v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_BONUS) + v2;
  v4 = v1->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_BONUS) + v3;
  v5 = v1->pActiveSkills[5];
  if ( v5 && (signed int)SkillToMastery(v5) >= 4 && HasItemEquipped(EQUIP_BOW) )
    v4 += v1->pActiveSkills[5] & 0x3F;
  if ( v4 >= 1 )
    result = v4;
  else
    result = 0;
  return result;
}

//----- (0048D191) --------------------------------------------------------
int Player::GetRangedDamageMax()
{
  Player *v1; // esi@1
  int v2; // edi@1
  int v3; // edi@1
  int v4; // edi@1
  unsigned __int16 v5; // ax@1
  int result; // eax@6

  v1 = this;
  v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_MAX, 0);
  v3 = GetSkillBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_BONUS) + v2;
  v4 = v1->_ranged_dmg_bonus + GetMagicalBonus(CHARACTER_ATTRIBUTE_RANGED_DAMAGE_BONUS) + v3;
  v5 = v1->pActiveSkills[5];
  if ( v5 && (signed int)SkillToMastery(v5) >= 4 && HasItemEquipped(EQUIP_BOW) )
    v4 += v1->pActiveSkills[5] & 0x3F;
  if ( v4 >= 1 )
    result = v4;
  else
    result = 0;
  return result;
}

//----- (0048D1FE) --------------------------------------------------------
bool Player::CalculateRangedDamageTo(int a2)
{
  Player *v2; // ebx@1
  bool result; // eax@1
  ItemGen *v4; // ebx@2
  unsigned int v5; // edi@2
  unsigned int v6; // esi@2
  int v7; // edx@4
  char v8; // zf@4
  int v9; // esi@5
  int v10; // ebx@6
  enum MONSTER_SUPERTYPE v11; // edx@7
  unsigned __int16 v12; // ax@19
  MONSTER_SUPERTYPE v13; // [sp-Ch] [bp-20h]@13
  Player *v14; // [sp+4h] [bp-10h]@1
  signed int v15; // [sp+8h] [bp-Ch]@2
  int v16; // [sp+Ch] [bp-8h]@3
  int v17; // [sp+10h] [bp-4h]@1

  v17 = 0;
  v2 = this;
  v14 = this;
  result = HasItemEquipped(EQUIP_BOW);
  if ( !result )
    return result;
  v4 = (ItemGen *)&v2->pInventoryItems[v2->pEquipment.uBow-1];
  v5 = v4->uItemID;
  v6 = v4->uItemID;
  v15 = pItemsTable->pItems[v6].uDamageRoll;
  if ( (signed int)pItemsTable->pItems[v6].uDamageDice > 0 )
  {
    v16 = pItemsTable->pItems[v6].uDamageDice;
    do
    {
      v7 = rand() % v15;
      v8 = v16-- == 1;
      v17 += v7 + 1;
    }
    while ( !v8 );
  }
  v9 = pItemsTable->pItems[v6].uDamageMod + v17;
  if ( a2 )
  {
    v10 = v4->uSpecEnchantmentType;
    if ( v10 == 64 )
    {
      v11 = (MONSTER_SUPERTYPE)1;
      goto LABEL_17;
    }
    if ( v10 == 39 || v5 == 508 )
    {
      v13 = MONSTER_SUPERTYPE_KREEGAN;
      goto LABEL_16;
    }
    if ( v10 == 40 )
    {
      v13 = MONSTER_SUPERTYPE_DRAGON;
      goto LABEL_16;
    }
    if ( v10 == 63 || v5 == 517 )
    {
      v13 = MONSTER_SUPERTYPE_ELF;
LABEL_16:
      v11 = v13;
LABEL_17:
      if ( MonsterStats::BelongsToSupertype(a2, v11) )
        v9 *= 2;
      goto LABEL_19;
    }
  }
LABEL_19:
  v12 = v14->pActiveSkills[5];
  if ( v12 )
  {
    if ( (signed int)SkillToMastery(v12) >= 4 )
      v9 += v14->pActiveSkills[5] & 0x3F;
  }
  return v9;
}

//----- (0048D2EA) --------------------------------------------------------
char *Player::GetMeleeDamageString()
{
  Player *v1; // esi@1
  signed int v2; // eax@1
  signed int v3; // edi@3
  signed int v4; // eax@3
  signed int v5; // ST0C_4@6
  char *v6; // edi@6
  signed int v7; // ST08_4@7
  unsigned int v8; // eax@8
  signed int v9; // esi@9

  static char player__getmeleedamagestring_static_buff[40]; // idb

  v1 = this;
  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
  if ( v2 < 64 || v2 > 65 )
  {
    v3 = GetMeleeDamageMinimal();
    v4 = GetMeleeDamageMaximal();
  }
  else
  {
    v3 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, 0);
    v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, 0);
  }
  if ( v3 == v4 )
  {
    v5 = v3;
    v6 = player__getmeleedamagestring_static_buff;
    sprintf(player__getmeleedamagestring_static_buff, "%d", v5);
  }
  else
  {
    v7 = v3;
    v6 = player__getmeleedamagestring_static_buff;
    sprintf(player__getmeleedamagestring_static_buff, "%d - %d", v7, v4);
  }
  v8 = v1->pEquipment.uMainHand;
  if ( v8 )
  {
    v9 = *(int *)&v1->pInventoryItems[v8-1];
    if ( v9 >= 135 )
    {
      if ( v9 <= 159 )
        strcpy(v6, pGlobalTXT_LocalizationStrings[595]);
    }
  }
  return v6;
}

//----- (0048D396) --------------------------------------------------------
char *Player::GetRangedDamageString()
{
  Player *v1; // esi@1
  signed int v2; // eax@1
  int v3; // edi@3
  int v4; // eax@3
  char *v5; // edi@6
  int v6; // ST0C_4@8
  int v7; // ST08_4@9
  unsigned int v8; // eax@10
  signed int v9; // esi@11
  
  static char player__getrangeddamagestring_static_buff[40]; // idb

  v1 = this;
  v2 = *(int *)&this->pInventoryItems[this->pEquipment.uMainHand-1];
  if ( v2 < 64 || v2 > 65 )
  {
    v3 = GetRangedDamageMin();
    v4 = GetRangedDamageMax();
  }
  else
  {
    v3 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MIN, 1);
    v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_MELEE_DMG_MAX, 1);
  }
  if ( v4 )
  {
    if ( v3 == v4 )
    {
      v6 = v3;
      v5 = player__getrangeddamagestring_static_buff;
      sprintf(player__getrangeddamagestring_static_buff, "%d", v6);
    }
    else
    {
      v7 = v3;
      v5 = player__getrangeddamagestring_static_buff;
      sprintf(player__getrangeddamagestring_static_buff, "%d - %d", v7, v4);
    }
  }
  else
  {
    v5 = player__getrangeddamagestring_static_buff;
    strcpy(player__getrangeddamagestring_static_buff, "N/A");
  }
  v8 = v1->pEquipment.uMainHand;
  if ( v8 )
  {
    v9 = *(int *)&v1->pInventoryItems[v8-1];
    if ( v9 >= 135 )
    {
      if ( v9 <= 159 )
        strcpy(v5, pGlobalTXT_LocalizationStrings[595]);
    }
  }
  return v5;
}

//----- (0048D45A) --------------------------------------------------------
bool Player::CanTrainToNextLevel()
{
  int v1; // edx@1
  int v2; // eax@1
  int i; // esi@1

  v1 = this->uLevel;
  v2 = 0;
  for ( i = 0; i < v1; ++i )
    v2 += i + 1;
  return (signed __int64)this->uExperience >= 1000 * v2;
}

//----- (0048D498) --------------------------------------------------------
unsigned int Player::GetExperienceDisplayColor()
{
  unsigned int result; // eax@2

  if ( CanTrainToNextLevel() )
    result = ui_character_bonus_text_color;
  else
    result = ui_character_default_text_color;
  return result;
}

//----- (0048D4B3) --------------------------------------------------------
int Player::CalculateIncommingDamage(int resistance, signed int type)
{
  Player *v3; // esi@1
  int v4; // edi@8
  int v6; // eax@21
  signed int v7; // ebx@21
  int v8; // eax@22
  signed int v9; // ebx@22
  int v10; // eax@23
  signed int v11; // ebx@23
  int v12; // eax@24
  signed int v13; // edi@24
  unsigned int v14; // eax@27
  int v15; // eax@29
  double v16; // st7@32
  enum CHARACTER_ATTRIBUTE_TYPE v17; // [sp-4h] [bp-10h]@9
  signed int v18; // [sp+8h] [bp-4h]@17

  v3 = this;
  if ( !resistance )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)10;
    goto LABEL_16;
  }
  if ( resistance == 1 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)11;
    goto LABEL_16;
  }
  if ( resistance == 2 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)12;
    goto LABEL_16;
  }
  if ( resistance == 3 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)13;
    goto LABEL_16;
  }
  if ( resistance == 6 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)33;
    goto LABEL_16;
  }
  if ( resistance == 7 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)14;
    goto LABEL_16;
  }
  if ( resistance == 8 )
  {
    v17 = (CHARACTER_ATTRIBUTE_TYPE)15;
LABEL_16:
    v4 = GetActualResistance(v17);
    goto LABEL_17;
  }
  v4 = 0;
LABEL_17:
  v18 = type;
  if ( v3->classType == PLAYER_CLASS_LICH && v4 >= 200 )
    return 0;
  if ( v4 )
  {
    v6 = GetActualLuck();
    v7 = _48EA1B_get_static_effect(v6) + v4 + 30;
    if ( rand() % v7 >= 30 )
    {
      v18 = type >> 1;
      v8 = GetActualLuck();
      v9 = _48EA1B_get_static_effect(v8) + v4 + 30;
      if ( rand() % v9 >= 30 )
      {
        v18 = type >> 2;
        v10 = GetActualLuck();
        v11 = _48EA1B_get_static_effect(v10) + v4 + 30;
        if ( rand() % v11 >= 30 )
        {
          v18 = type >> 3;
          v12 = GetActualLuck();
          v13 = _48EA1B_get_static_effect(v12) + v4 + 30;
          if ( rand() % v13 >= 30 )
            v18 = type >> 4;
        }
      }
    }
  }
  if ( resistance == 4 )
  {
    v14 = v3->pEquipment.uArmor;
    if ( v14 )
    {
     // if ( !(v3->field_1F5[36 * v14 + 15] & 2) )
      if (v3->pOwnItems[v14-1].uAttributes&2) 
      {
        v15 = GetEquippedItemSkillType(EQUIP_ARMOUR) - 10;
        if ( v15 )
        {
          if ( v15 != 1 || (signed int)SkillToMastery(v3->pActiveSkills[11]) < 3 )
            return v18;
          v16 = (double)v18 * 0.5;
          return (signed __int64)v16;
        }
        if ( (signed int)SkillToMastery(v3->pActiveSkills[10]) >= 4 )
        {
          v16 = (double)v18 * 0.66670001;
          return (signed __int64)v16;
        }
      }
    }
  }
  return v18;
}

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

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

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

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

//----- (0048D6D0) --------------------------------------------------------
bool Player::HasEnchantedItemEquipped(int uEnchantment)
{
  for (uint i = 0; i < 16; ++i)
  {
    if (HasItemEquipped((ITEM_EQUIP_TYPE)i) &&
      pInventoryItems[i].uSpecEnchantmentType == uEnchantment)
      //  *(int *)&this->field_1F6[36 * pEquipment[i] + 6] != uEnchantment)
      return true;
  }
  return false;
}

//----- (0048D709) --------------------------------------------------------
bool Player::WearsItem(int a1, signed int a2)
{

  int v6; // esi@5

  if ( a2 >= 16 )
  {
    v6 = 0;
    while ( !HasItemEquipped((ITEM_EQUIP_TYPE)v6)
         || *(int *)&this->pInventoryItems[pEquipment.pIndices[v6] - 1].uItemID != a1 )
    {
      ++v6;
      if ( (signed int)v6 >= 16 )
        return 0;
    }
    return 1;
  }
  if ( HasItemEquipped((ITEM_EQUIP_TYPE)a2) && pInventoryItems[pEquipment.pIndices[a2 - 1]].uItemID == a1 )
    return 1;
  return 0;
}

//----- (0048D76C) --------------------------------------------------------
bool Player::StealFromShop(ItemGen *a2, int a3, int a4, int a5, int *a6)
{
  unsigned __int16 v6; // cx@8
  int v7; // edi@8
  unsigned int v8; // ebx@8
  unsigned int v9; // esi@8
  int v10; // eax@8
  int v11; // edi@12
  bool result; // eax@13

  if ( !a2
    || 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);
    v9 = a2->GetValue();
    v10 = pItemsTable->pItems[a2->uItemID].uEquipType;
    if ( !pItemsTable->pItems[a2->uItemID].uEquipType || v10 == 1 || v10 == 2 )
      v9 *= 3;
    v11 = dword_4EDEB4[rand() % 100 / 20] + v7 * dword_4EDEA0[v8];
    *a6 = 100 * (a4 + a3) + v9 + (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;
            sprintf(pTmpBuf2, 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,
              pGlobalTXT_LocalizationStrings[304],
              v31->pName,
              pItemsTable->pItems[v16].pUnidentifiedName);
            ShowStatusBarString(pTmpBuf2, 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;
    sprintfex(pTmpBuf2, 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 ( !pConditions[Condition_Eradicated] && !pConditions[Condition_Dead] )
  {
    max_health = GetMaxHealth();
    if ( pConditions[Condition_Zombie] )
      max_health /= 2;
    sHealth += amount;
    if ( sHealth > max_health )
        sHealth = max_health;
    if ( pConditions[Condition_Unconcious] )
    {
      if ( sHealth > 0 )
      {
        pConditions[Condition_Unconcious] = 0i64;
      }
    }
  }
}

//----- (0048DC1E) --------------------------------------------------------
int Player::ReceiveDamage(signed int type, int resistance)
{
  Player *v3; // esi@1
  signed int v4; // eax@1
  int v5; // eax@1
  bool v6; // ebx@1
  unsigned int v7; // eax@8
  char *v8; // ecx@9
  int v9; // eax@9
  //signed int typea; // [sp+14h] [bp+8h]@1

  v3 = this;
  this->pConditions[Condition_Sleep] = 0i64;
  v4 = CalculateIncommingDamage(resistance, type);
  v3->sHealth -= v4;
  //typea = v4;
  v5 = v3->sHealth;
  v6 = v5 < -10;
  LOBYTE(v6) = v5 <= -10;
  if ( v5 < 1 )
  {
    if ( v3->sHealth + v3->uEndurance + GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE, 0) >= 1
      || (signed __int64)v3->pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0 )
    {
      SetCondition(Condition_Unconcious, 0);
    }
    else
    {
      SetCondition(Condition_Dead, 0);
      v6 = LODWORD(pParty->uTimePlayed);
      if ( v3->sHealth > 0 )
        v3->sHealth = 0;
    }
    if ( v6 )
    {
      v7 = v3->pEquipment.uArmor;
      if ( v7 )
      {
//        v8 = &v3->field_1F5[36 * v7 + 15];
        v8=(char*)&v3->pOwnItems[v7-1].uAttributes;
        v9 = *(int *)v8;
        if ( !(BYTE1(v9) & 2) )
        {
          LOBYTE(v9) = v9 | 2;
          *(int *)v8 = v9;
        }
      }
    }
  }
  if ( v4 && CanAct() )
    PlaySound(SPEECH_24, 0);
  return v4;
}

//----- (0048DCF6) --------------------------------------------------------
int Player::_48DCF6(int a2, Actor *pActor)
{
  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 = _48EA1B_get_static_effect(v8);
      v10 = GetActualIntelligence();
      v11 = (_48EA1B_get_static_effect(v10) + v9) >> 1;
      break;
    case 17:
      v12 = 0;
      v13 = this->pInventoryItems;
      do
      {
        if ( (signed int)v13->uItemID > 0 && (signed int)v13->uItemID <= 134 && !v13->Broken())
          v46[v4++] = v12;
        ++v12;
        ++v13;
      }
      while ( v12 < 138 );
      goto LABEL_36;
    case 18:
      v14 = 0;
      do
      {
        if ( HasItemEquipped((ITEM_EQUIP_TYPE)v14) )
        {
          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) )
        {
          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->pInventoryItems[(unsigned __int8)v46[rand() % v4]];
      v11 = 3 * (pItemsTable->pItems[*(int *)v48].uMaterial + pItemsTable->pItems[*(int *)v48].uDamageMod);
      break;
    case 20:
      v19 = 0;
      v20 = this->pInventoryIndices;
      do
      {
        if ( *v20 > 0 )
        {
          v21 = *(int *)&v5->pInventoryItems[*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 = _48EA1B_get_static_effect(v6);
LABEL_47:
      v11 = v7;
      break;
    default:
      v11 = 0;
      break;
  }
  v22 = GetActualLuck();
  v23 = _48EA1B_get_static_effect(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->pInventoryItems[v5->pInventoryIndices[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 LOBYTE(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) )
      goto LABEL_17;
    weapon = &pInventoryItems[pEquipment.uBow - 1];
    weapon_desc = &pItemsTable->pItems[weapon->uItemID];
    weapon_recovery = base_recovery_times_per_weapon_type[weapon_desc->uSkillType];
    goto LABEL_17;
  }
  else if ( IsUnarmed() == 1 )
  {
    if (GetActualSkillLevel(PLAYER_SKILL_UNARMED))
    {
      weapon_recovery = base_recovery_times_per_weapon_type[1];
      goto LABEL_17;
    }
  }

  if ( HasItemEquipped(EQUIP_MAIN_HAND) )
  {
    weapon = &pInventoryItems[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 = &pInventoryItems[pEquipment.uShield - 1];
    auto v12_desc = &pItemsTable->pItems[v12->uItemID];
    if (base_recovery_times_per_weapon_type[v12_desc->uSkillType] > weapon_recovery)
    {
      weapon = &pInventoryItems[pEquipment.uShield - 1];
      weapon_desc = &pItemsTable->pItems[weapon->uItemID];
      weapon_recovery = base_recovery_times_per_weapon_type[pItemsTable->pItems[weapon->uItemID].uSkillType];
    }
  }

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

    float armour_recovery_multipliers[4];
    if (armour_skill_type == PLAYER_SKILL_LEATHER)
    {
      armour_recovery_multipliers[0] = 1.0f;
      armour_recovery_multipliers[1] = 0;
      armour_recovery_multipliers[2] = 0;
      armour_recovery_multipliers[3] = 0;
    }
    else if (armour_skill_type == PLAYER_SKILL_CHAIN)
    {
      armour_recovery_multipliers[0] = 1.0f;
      armour_recovery_multipliers[1] = 0.5f;
      armour_recovery_multipliers[2] = 0;
      armour_recovery_multipliers[3] = 0;
    }
    else if (armour_skill_type == PLAYER_SKILL_PLATE)
    {
      armour_recovery_multipliers[0] = 1.0f;
      armour_recovery_multipliers[1] = 0.5f;
      armour_recovery_multipliers[2] = 0.5f;
      armour_recovery_multipliers[3] = 0;
    }
    else
    {
      assert(false && "Unknown armour type"); // what kind of armour is that?
      armour_recovery_multipliers[0] = 1.0f;
      armour_recovery_multipliers[1] = 1.0f;
      armour_recovery_multipliers[2] = 1.0f;
      armour_recovery_multipliers[3] = 1.0f;
    }

    uint skill_mastery = SkillToMastery(pActiveSkills[armour_skill_type]);
    armour_recovery = base_armour_recovery * armour_recovery_multipliers[skill_mastery - 1];
  }

  uint shield_recovery = 0;
  if (HasItemEquipped(EQUIP_OFF_HAND) && GetEquippedItemEquipType(EQUIP_OFF_HAND) == EQUIP_SHIELD)
  {
    float shield_recovery_multipliers[4] = {1, 0, 0, 0};

    auto shield = &pInventoryItems[pEquipment.uShield - 1];
    auto skill_type = pItemsTable->pItems[shield->uItemID].uSkillType;

    uint shield_base_recovery = base_recovery_times_per_weapon_type[skill_type];
    shield_recovery = shield_base_recovery * SkillToMastery(pActiveSkills[skill_type]);
  }

  uint player_speed_recovery_reduction = _48EA1B_get_static_effect(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 v41 = 0;
  if (pPlayerBuffs[PLAYER_BUFF_7].uExpireTime > 0)
    v41 = 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
                 - v41
                 - sword_axe_bow_recovery_reduction
                 - player_speed_recovery_reduction;

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

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

  v3 = _48EA1B_get_static_effect(GetActualEndurance());
  v4 = pBaseHealthPerLevelByClass[classType] * (GetActualLevel() + v3);
  v6 = uFullHealthBonus
     + pBaseHealthByClass[classType / 4]
     + GetSkillBonus(CHARACTER_ATTRIBUTE_HEALTH)
     + GetItemsBonus(CHARACTER_ATTRIBUTE_HEALTH, 0) + v4;
  if (v6 <= 0)
    return 1;
  return 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
  int result; // eax@7

  switch (classType)
  {
    case 5u:
    case 6u:
    case 7u:
    case 0x10u:
    case 0x11u:
    case 0x12u:
    case 0x13u:
    case 0x20u:
    case 0x21u:
    case 0x22u:
    case 0x23u:
      v2 = GetActualIntelligence();
      v3 = _48EA1B_get_static_effect(v2);
      goto LABEL_6;
    case 9u:
    case 0xAu:
    case 0xBu:
    case 0xCu:
    case 0xDu:
    case 0xEu:
    case 0xFu:
    case 0x18u:
    case 0x19u:
    case 0x1Au:
    case 0x1Bu:
      v2 = GetActualWillpower();
      v3 = _48EA1B_get_static_effect(v2);
      goto LABEL_6;
    case 0x15u:
    case 0x16u:
    case 0x17u:
    case 0x1Cu:
    case 0x1Du:
    case 0x1Eu:
    case 0x1Fu:
      v4 = GetActualWillpower();
      v5 = _48EA1B_get_static_effect(v4);
      v6 = GetActualIntelligence();
      v3 = _48EA1B_get_static_effect(v6) + v5;
LABEL_6:
      v7 = pBaseManaPerLevelByClass[classType] * (GetActualLevel() + v3);
      v8 = GetItemsBonus(CHARACTER_ATTRIBUTE_MANA, 0) + v7;
      v9 = uFullManaBonus
         + pBaseManaByClass[classType / 4]
         + GetSkillBonus(CHARACTER_ATTRIBUTE_MANA)
         + v8;
      if ( v9 < 1 )
        goto LABEL_7;
      result = v9;
      break;
    default:
LABEL_7:
      result = 0;
      break;
  }
  return result;
}

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

  v1 = this;
  v2 = GetActualSpeed();
  v3 = _48EA1B_get_static_effect(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_AC_BONUS, 0) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v4;
  if ( v5 >= 1 )
    result = v5;
  else
    result = 0;
  return result;
}

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

  v1 = this;
  v2 = GetActualSpeed();
  v3 = _48EA1B_get_static_effect(v2);
  v4 = GetItemsBonus(CHARACTER_ATTRIBUTE_AC_BONUS, 0) + v3;
  v5 = GetSkillBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v4;
  v6 = v1->sACModifier + GetMagicalBonus(CHARACTER_ATTRIBUTE_AC_BONUS) + v5;
  if ( v6 >= 1 )
    result = v6;
  else
    result = 0;
  return result;
}

//----- (0048E6DC) --------------------------------------------------------
unsigned int Player::GetBaseAge()
{
  return ((__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)
{
  Player *v2; // ebx@1
  signed int v3; // esi@1
  enum CHARACTER_RACE v4; // eax@1
  signed int v5; // edi@8
  char v6; // zf@9
  int v7; // esi@20
  int result; // eax@21
  signed int v9; // [sp-4h] [bp-10h]@11

  v2 = this;
  v3 = 0;
  v4 = GetRace();
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_FIRE )
  {
    v5 = 0;
    goto LABEL_16;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_AIR )
  {
    v5 = 1;
LABEL_16:
    v6 = v4 == 2;
    goto LABEL_17;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_WATER )
  {
    v6 = v4 == 3;
    v5 = 2;
    goto LABEL_17;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_EARTH )
  {
    v5 = 3;
    v6 = v4 == 3;
    goto LABEL_17;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_MIND )
  {
    v5 = 7;
    if ( v4 != 1 )
      goto LABEL_20;
    v9 = 10;
LABEL_19:
    v3 = v9;
    goto LABEL_20;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_BODY || a2 == 33 )
  {
    v5 = 8;
    v6 = v4 == 0;
LABEL_17:
    if ( !v6 )
      goto LABEL_20;
    v9 = 5;
    goto LABEL_19;
  }
  v5 = 0;
LABEL_20:
  v7 = GetItemsBonus(a2, 0) + v3;
  if ( v2->classType != PLAYER_CLASS_LICH || (result = 200, v7 + *(&v2->sResFireBase + v5) <= 200) )
    result = v7 + *(&v2->sResFireBase + v5);
  return result;
}

//----- (0048E7D0) --------------------------------------------------------
int Player::GetActualResistance(enum CHARACTER_ATTRIBUTE_TYPE a2)
{
  signed int v2; // edi@1
  Player *v3; // esi@1
  enum CHARACTER_RACE v4; // ebx@1
  char v6; // zf@18
  int v7; // ebx@28
  int result; // eax@28
  signed int v9; // [sp+10h] [bp-8h]@1
  signed int v10; // [sp+14h] [bp-4h]@1

  v2 = 0;
  v3 = this;
  v10 = 0;
  v9 = 0;
  v4 = GetRace();
  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(v3->pActiveSkills[9]) == 4
    && HasItemEquipped(EQUIP_ARMOUR)
    && GetEquippedItemSkillType(EQUIP_ARMOUR) == PLAYER_SKILL_LEATHER )
    v10 += v3->pActiveSkills[9] & 0x3F;
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_FIRE )
    goto LABEL_25;
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_AIR )
  {
    v2 = 1;
LABEL_25:
    v6 = v4 == 2;
LABEL_26:
    if ( v6 )
      v9 = 5;
    goto LABEL_28;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_WATER )
  {
    v6 = v4 == 3;
    v2 = 2;
    goto LABEL_26;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_RESIST_EARTH )
  {
    v2 = 3;
    if ( v4 == 3 )
      v10 += 5;
  }
  else
  {
    if ( a2 != CHARACTER_ATTRIBUTE_RESIST_MIND )
    {
      if ( a2 != CHARACTER_ATTRIBUTE_RESIST_BODY && a2 != 33 )
        goto LABEL_28;
      v2 = 8;
      v6 = v4 == 0;
      goto LABEL_26;
    }
    v2 = 7;
    if ( v4 == 1 )
      v9 = 10;
  }
LABEL_28:
  v7 = GetItemsBonus(a2, 0);
  result = v10 + GetMagicalBonus(a2) + v7 + v9 + *(&v3->sResFireBonus + v2) + *(&v3->sResFireBase + v2);
  if ( v3->classType == PLAYER_CLASS_LICH )
  {
    if ( result > 200 )
      result = 200;
  }
  return result;
}

//----- (0048E8F5) --------------------------------------------------------
bool Player::Recover(int dt)
{
  //Player *v2; // esi@1
  signed __int64 v3; // qax@1
  //bool result; // eax@4

  //v2 = this;
  v3 = (signed __int64)((double)(dt * _48EA46_calc_special_bonus_by_items(17)) * 0.01 + (double)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::_48EA1B_get_static_effect(int a2)
{
  __int16 v2; // cx@1
  int v3; // eax@1

  v2 = word_4EDFFC[0];
  v3 = 0;
  while ( a2 < v2 && v2 )
    v2 = word_4EDFFC[v3++ + 1];
  return player_stat_bonuses[v3];
}

//----- (0048EA46) --------------------------------------------------------
int Player::_48EA46_calc_special_bonus_by_items(int a2)
{
  int inv_indx; // eax@3

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

//----- (0048EAAE) --------------------------------------------------------
int Player::GetItemsBonus(CHARACTER_ATTRIBUTE_TYPE attr, int a3)
{
  CHARACTER_ATTRIBUTE_TYPE v3; // esi@1
  signed int v4; // eax@1
  int v5; // edi@1
  Player *v6; // ebx@1
  Player *v8; // ecx@48
  int v9; // eax@49
  int v10; // edx@49
  Player *v11; // ecx@55
  int v12; // eax@56
  int v13; // edx@56
  int v14; // ecx@58
  int v15; // eax@58
  Player *v16; // ecx@61
  int v17; // eax@62
  Player *v18; // ecx@66
  int v19; // eax@67
  int v20; // eax@69
  Player *v21; // ecx@75
  int v22; // eax@76
  int v23; // edx@76
  int v24; // eax@79
  int v25; // ecx@80
  int v26; // edi@80
  Player *v27; // ecx@84
  int v28; // eax@85
  int v29; // edx@85
  Player *v30; // ecx@96
  int v31; // ebp@97
  int v32; // eax@98
  unsigned int v33; // eax@100
  int v34; // eax@103
  char v35; // zf@104
  char v36; // zf@107
  unsigned __int8 v37; // zf@119
  char v38; // sf@119
  unsigned __int8 v39; // of@119
  char v40; // zf@122
  char v41; // zf@145
  char v42; // zf@164
  char v43; // zf@173
  char v44; // zf@189
  char v45; // zf@198
  char v46; // zf@239
  int v47; // eax@268
  int v48; // eax@269
  int v49; // eax@291
  char v50; // zf@295
  int v51; // eax@306
  int v52; // eax@307
  char v53; // zf@312
  char v54; // zf@336
  char v55; // zf@348
  int v56; // eax@365
  int v57; // ebx@368
  signed int v58; // [sp-4h] [bp-20h]@10
  signed int v59; // [sp-4h] [bp-20h]@71
  signed int v60; // [sp-4h] [bp-20h]@347
  int v61; // [sp+10h] [bp-Ch]@1
  int v62; // [sp+14h] [bp-8h]@1
  int v63; // [sp+18h] [bp-4h]@101
  ItemGen *attra; // [sp+20h] [bp+4h]@101
  unsigned int v65; // [sp+24h] [bp+8h]@95

  v3 = attr;
  v4 = 36;
  v5 = 0;
  v6 = this;
  v62 = 0;
  v61 = 0;

  switch (attr)
  {
    case CHARACTER_ATTRIBUTE_LEVEL:
      if (HasEnchantedItemEquipped(25))
        return 5;
      return 0;
  };

  if ( (signed int)attr > 36 )
  {
    switch ( attr )
    {
      case 37:
        v58 = 15;
        goto LABEL_35;
      case 38:
        v58 = 16;
        goto LABEL_35;
      case 39:
        v58 = 17;
        goto LABEL_35;
      case 40:
        v58 = 18;
        goto LABEL_35;
      case 41:
        v58 = 19;
        goto LABEL_35;
      case 42:
        v58 = 20;
        goto LABEL_35;
      case 43:
        v58 = 25;
        goto LABEL_35;
      case 44:
        v58 = 5;
        goto LABEL_35;
      case 45:
        v58 = 8;
        goto LABEL_35;
      case 46:
        goto LABEL_36;
      default:
        break;
    }
  }
  else
  {
    if ( attr == 36 )
    {
      v58 = 14;
    }
    else
    {
      if ( (signed int)attr > 21 )
      {
        switch ( attr )
        {
          case 22:
            v58 = 30;
            break;
          case 23:
            v58 = 31;
            break;
          case 34:
            v58 = 12;
            break;
          default:
            if ( attr != 35 )
              goto LABEL_38;
            v58 = 13;
            break;
        }
      }
      else
      {
        switch ( attr )
        {
          case 21:
            v58 = 33;
            break;
          case 16:
            v58 = 35;
            break;
          case 17:
            v58 = 34;
            break;
          case 18:
            v58 = 29;
            break;
          case 19:
            v58 = 21;
            break;
          default:
            if ( attr != 20 )
              goto LABEL_38;
            v58 = 32;
            break;
        }
      }
    }
LABEL_35:
    v4 = v58;
LABEL_36:
    if ( !this->pActiveSkills[v4] )
      return 0;
  }
LABEL_38:
  if ( (signed int)attr > 28 )
  {
    if ( (signed int)attr < 29 )
      return v5 + v62 + v61;
    if ( (signed int)attr <= 30 )
    {
      if ( HasItemEquipped(EQUIP_BOW) )
        v5 = pItemsTable->pItems[*(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1]].uDamageMod;
      return v5 + v62 + v61;
    }
    if ( attr == 31 )
    {
      if ( !HasItemEquipped(EQUIP_BOW) )
        return v5 + v62 + v61;
      v57 = *(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1];
      v5 = pItemsTable->pItems[v57].uDamageMod;
      v56 = pItemsTable->pItems[v57].uDamageDice;
      goto LABEL_366;
    }
    if ( attr == 32 )
    {
      if ( !HasItemEquipped(EQUIP_BOW) )
        return v5 + v62 + v61;
      v20 = *(int *)&v6->pInventoryItems[v6->pEquipment.uBow-1];
      v5 = pItemsTable->pItems[v20].uDamageDice * pItemsTable->pItems[v20].uDamageRoll;
LABEL_365:
      v56 = pItemsTable->pItems[v20].uDamageMod;
LABEL_366:
      v5 += v56;
      return v5 + v62 + v61;
    }
    if ( (signed int)attr <= 33 || (signed int)attr > 46 )
      return v5 + v62 + v61;
LABEL_95:
    v65 = 0;
    while ( 1 )
    {
      if ( !HasItemEquipped((ITEM_EQUIP_TYPE)v65) )
        goto LABEL_361;
      v31 = *(&v6->pEquipment.uShield + v65) - 1;
      if ( v3 == 9 )
      {
        v32 = GetEquippedItemEquipType((ITEM_EQUIP_TYPE)v65);
        if ( v32 >= 3 )
        {
          if ( v32 <= 11 )
          {
            v33 = v6->pInventoryItems[v31].uItemID;
            v5 += pItemsTable->pItems[v33].uDamageDice + pItemsTable->pItems[v33].uDamageMod;
          }
        }
      }
      v63 = (int)((char *)v6 + 36 * v31);
      attra = (ItemGen *)(v63 + 532);
      if ( pItemsTable->IsMaterialNonCommon((ItemGen *)(v63 + 532)) == 1
        && !pItemsTable->IsMaterialSpecial(attra) )
      {
        v34 = attra->uItemID;
        switch ( attra->uItemID )
        {
          case 0x1F4u:
            v35 = v3 == 5;
            goto LABEL_105;
          case 0x1F5u:
            v36 = v3 == 0;
            goto LABEL_108;
          case 0x1F6u:
            if ( v3 == 21 )
              v61 += 10;
            v36 = v3 == 2;
            goto LABEL_108;
          case 0x1F7u:
            if ( v3 == 17 )
              v61 += 5;
            if ( v3 == 18 )
              v61 += 5;
            v36 = v3 == 6;
            goto LABEL_108;
          case 0x1F8u:
            goto LABEL_118;
          case 0x1F9u:
            v40 = v3 == 3;
            goto LABEL_123;
          case 0x1FAu:
            v35 = v3 == 10;
            goto LABEL_105;
          case 0x1FEu:
            v35 = v3 == 4;
            goto LABEL_105;
          case 0x1FFu:
            if ( v3 == 23 )
              v61 += 10;
            if ( v3 == 22 )
              v61 += 10;
            goto LABEL_361;
          case 0x200u:
            if ( v3 == 36 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[14]);
              v62 = ((unsigned int)v34 >> 1) & 0x1F;
            }
            v36 = v3 == 5;
LABEL_108:
            if ( v36 )
              v5 += 40;
            goto LABEL_361;
          case 0x201u:
            if ( v3 == 39 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[17]);
              v34 = ((unsigned int)v34 >> 1) & 0x1F;
              v62 = v34;
            }
            goto LABEL_136;
          case 0x202u:
            if ( !v3 )
              v5 += 150;
            if ( v3 == 1 )
              v5 -= 40;
            if ( v3 == 2 )
              v5 -= 40;
            goto LABEL_145;
          case 0x203u:
            if ( v3 == 42 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[20]);
              v62 = ((unsigned int)v34 >> 1) & 0x1F;
            }
            if ( v3 == 43 )
              v61 += 15;
            goto LABEL_361;
          case 0x204u:
            if ( v3 == 17 )
              v61 += 5;
            if ( v3 == 18 )
              v61 += 5;
            if ( v3 == 6 )
              v5 += 50;
            if ( v3 == 11 || v3 == 10 || v3 == 12 || v3 == 13 || v3 == 33 || v3 == 14 )
              goto LABEL_166;
            v42 = v3 == 15;
            goto LABEL_165;
          case 0x205u:
            if ( v3 == 18 )
              v61 += 5;
            goto LABEL_361;
          case 0x206u:
            if ( !v3 )
              v5 += 100;
            if ( v3 == 3 )
              v5 += 100;
            v43 = v3 == 9;
            goto LABEL_174;
          case 0x207u:
            if ( v3 == 45 )
              v61 += 5;
            if ( v3 == 15 )
              v5 -= 10;
            v42 = v3 == 14;
LABEL_165:
            if ( v42 )
LABEL_166:
              v5 -= 10;
            goto LABEL_361;
          case 0x208u:
            v35 = v3 == 3;
            goto LABEL_105;
          case 0x209u:
            if ( v3 == 2 )
              v5 += 15;
            if ( !v3 )
              v5 += 15;
            v41 = v3 == 6;
            goto LABEL_146;
          case 0x20Au:
            if ( v3 == 46 )
              v61 += 15;
            v44 = v3 == 3;
            goto LABEL_190;
          case 0x20Bu:
            if ( v3 == 34 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[12]);
              v62 = ((unsigned int)v34 >> 1) & 0x1F;
            }
            if ( v3 == 12 )
              v5 += 50;
            if ( v3 == 2 )
              v5 += 30;
            v45 = v3 == 9;
            goto LABEL_199;
          case 0x20Cu:
            if ( !v3 )
              v5 += 75;
            goto LABEL_145;
          case 0x20Du:
            if ( v3 == 5 )
              v5 += 50;
            if ( v3 == 6 )
              v5 += 50;
            if ( v3 == 11 || v3 == 10 || v3 == 12 || v3 == 13 || v3 == 33 || v3 == 14 )
              goto LABEL_374;
            v43 = v3 == 15;
LABEL_174:
            if ( v43 )
LABEL_374:
              v5 -= 15;
            goto LABEL_361;
          case 0x20Eu:
            if ( v3 == 4 )
              v5 += 150;
            if ( v3 == 44 )
              v61 += 5;
            if ( v3 == 9 )
              v5 -= 25;
            goto LABEL_361;
          case 0x20Fu:
            if ( v3 == 39 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[17]);
              v34 = ((unsigned int)v34 >> 1) & 0x1F;
              v62 = v34;
            }
            if ( v3 == 40 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[18]);
              v62 = ((unsigned int)v34 >> 1) & 0x1F;
            }
LABEL_145:
            v41 = v3 == 5;
LABEL_146:
            if ( v41 )
              v5 -= 40;
            goto LABEL_361;
          case 0x210u:
            if ( v3 == 38 )
            {
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[16]);
              v62 = ((unsigned int)v34 >> 1) & 0x1F;
            }
            if ( !v3 )
              v5 += 75;
            v44 = v3 == 11;
LABEL_190:
            if ( v44 )
              v5 -= 50;
            goto LABEL_361;
          case 0x211u:
            if ( v3 == 5 )
              v5 += 100;
            if ( v3 == 4 )
              v5 += 50;
            v35 = v3 == 11;
LABEL_105:
            if ( v35 )
              v5 += 50;
            goto LABEL_361;
          case 0x212u:
            if ( v3 == 1 )
              v5 -= 20;
            v45 = v3 == 2;
LABEL_199:
            if ( v45 )
              v5 -= 20;
            goto LABEL_361;
          case 0x214u:
            if ( v3 == 1 )
              v5 += 15;
            v46 = v3 == 2;
            goto LABEL_240;
          case 0x215u:
            if ( v3 == 5 )
              v5 += 15;
            v46 = v3 == 4;
            goto LABEL_240;
          case 0x216u:
            if ( v3 == 10 )
              v5 += 30;
            if ( !v3 )
              v5 += 15;
            goto LABEL_315;
          case 0x217u:
            if ( v3 == 21 )
              v61 += 5;
            if ( !v3 )
              v5 += 15;
            goto LABEL_253;
          case 0x218u:
            goto LABEL_253;
          default:
            goto LABEL_361;
        }
        goto LABEL_361;
      }
      if ( *(int *)(v63 + 536) == v3 + 1 )
      {
        if ( (signed int)v3 >= 0 )
        {
          if ( (signed int)v3 <= 15 )
          {
            v5 += *((int *)v6->pConditions + 9 * v31 + 135);
          }
          else
          {
            if ( (signed int)v3 <= 23 && v5 < *((int *)v6->pConditions + 9 * v31 + 135) )
              v5 = *((int *)v6->pConditions + 9 * v31 + 135);
          }
        }
        goto LABEL_361;
      }
      v34 = *(int *)(v63 + 544);
      if ( v34 > 48 )
      {
        switch ( v34 )
        {
          case 54:
            goto LABEL_315;
          case 49:
            if ( v3 == 6 )
              goto LABEL_121;
            v50 = v3 == 1;
            goto LABEL_296;
          case 51:
            if ( v3 != 5 && v3 != 1 )
              goto LABEL_309;
            goto LABEL_121;
          case 52:
            if ( v3 == 3 )
              goto LABEL_121;
            v50 = v3 == 4;
            goto LABEL_296;
          case 53:
            if ( !v3 )
              goto LABEL_121;
            v50 = v3 == 2;
            goto LABEL_296;
          case 55:
            v46 = v3 == 6;
            goto LABEL_240;
          case 56:
            if ( !v3 )
              goto LABEL_351;
            v53 = v3 == 3;
            goto LABEL_350;
          case 57:
            if ( v3 == 1 )
              goto LABEL_351;
            v53 = v3 == 2;
            goto LABEL_350;
          case 50:
            if ( v3 == 10 )
              v5 += 30;
            goto LABEL_361;
          case 60:
            if ( v3 != 23 )
              goto LABEL_336;
            if ( v5 >= 3 )
              goto LABEL_361;
            v5 = 3;
LABEL_336:
            v54 = v3 == 22;
            goto LABEL_345;
          case 61:
            if ( v3 != 17 )
              goto LABEL_340;
            if ( v5 >= 3 )
              goto LABEL_361;
            v5 = 3;
LABEL_340:
            v54 = v3 == 18;
            goto LABEL_345;
          case 62:
            if ( v3 != 19 )
              goto LABEL_344;
            if ( v5 >= 3 )
              goto LABEL_361;
            v5 = 3;
LABEL_344:
            v54 = v3 == 20;
LABEL_345:
            if ( !v54 )
              goto LABEL_361;
            if ( v5 >= 3 )
              goto LABEL_361;
            v60 = 3;
            goto LABEL_360;
          case 67:
            v55 = v3 == 18;
            goto LABEL_357;
          case 68:
            v53 = v3 == 9;
            goto LABEL_350;
          case 69:
            if ( v3 == 11 )
              v5 += 20;
            break;
          case 70:
            if ( v3 == 12 )
              v5 += 10;
            v55 = v3 == 16;
LABEL_357:
            if ( v55 && v5 < 2 )
            {
              v60 = 2;
LABEL_360:
              v5 = v60;
            }
            break;
          default:
            goto LABEL_361;
        }
        goto LABEL_361;
      }
      if ( v34 == 48 )
      {
        if ( v3 == 9 )
          v5 += 5;
LABEL_315:
        v46 = v3 == 3;
LABEL_240:
        if ( v46 )
          v5 += 15;
        goto LABEL_361;
      }
      if ( v34 > 32 )
      {
        if ( v34 > 44 )
        {
          v51 = v34 - 45;
          if ( !v51 )
          {
            if ( v3 == 5 )
              goto LABEL_351;
            v53 = v3 == 4;
LABEL_350:
            if ( v53 )
LABEL_351:
              v5 += 5;
            goto LABEL_361;
          }
          v52 = v51 - 1;
          if ( !v52 )
          {
            v40 = v3 == 0;
LABEL_123:
            if ( v40 )
              v5 += 25;
            goto LABEL_361;
          }
          if ( v52 == 1 )
          {
LABEL_309:
            v50 = v3 == 8;
            goto LABEL_296;
          }
        }
        else
        {
          if ( v34 == 44 )
          {
            v50 = v3 == 7;
            goto LABEL_296;
          }
          v34 -= 33;
          if ( !v34 )
          {
            if ( v3 != 38 )
              goto LABEL_361;
            LOBYTE(v34) = LOBYTE(v6->pActiveSkills[16]);
            goto LABEL_138;
          }
          --v34;
          if ( !v34 )
          {
            if ( v3 != 36 )
              goto LABEL_361;
            LOBYTE(v34) = LOBYTE(v6->pActiveSkills[14]);
            goto LABEL_138;
          }
          v49 = v34 - 8;
          if ( !v49 )
          {
            if ( (signed int)v3 >= 0 && (signed int)v3 <= 15 )
              ++v5;
            goto LABEL_361;
          }
          if ( v49 == 1 )
          {
            if ( v3 != 3 && v3 != 7 )
            {
              v50 = v3 == 9;
LABEL_296:
              if ( !v50 )
                goto LABEL_361;
            }
LABEL_121:
            v5 += 10;
            goto LABEL_361;
          }
        }
      }
      else
      {
        if ( v34 == 32 )
        {
          if ( v3 != 39 )
            goto LABEL_361;
          LOBYTE(v34) = LOBYTE(v6->pActiveSkills[17]);
          goto LABEL_138;
        }
        if ( v34 > 28 )
        {
          v34 -= 29;
          if ( v34 )
          {
            --v34;
            if ( v34 )
            {
              --v34;
              if ( v34 || v3 != 41 )
                goto LABEL_361;
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[19]);
            }
            else
            {
              if ( v3 != 34 )
                goto LABEL_361;
              LOBYTE(v34) = LOBYTE(v6->pActiveSkills[12]);
            }
          }
          else
          {
            if ( v3 != 37 )
              goto LABEL_361;
            LOBYTE(v34) = LOBYTE(v6->pActiveSkills[15]);
          }
          goto LABEL_138;
        }
        if ( v34 == 28 )
        {
LABEL_136:
          if ( v3 == 42 )
          {
            LOBYTE(v34) = LOBYTE(v6->pActiveSkills[20]);
LABEL_138:
            v62 = ((unsigned int)v34 >> 1) & 0x1F;
            goto LABEL_361;
          }
        }
        else
        {
          v47 = v34 - 1;
          if ( v47 )
          {
            v48 = v47 - 1;
            if ( v48 )
            {
              v34 = v48 - 24;
              if ( v34 )
              {
                --v34;
                if ( v34 || v3 != 40 )
                  goto LABEL_361;
                LOBYTE(v34) = LOBYTE(v6->pActiveSkills[18]);
              }
              else
              {
                if ( v3 != 35 )
                  goto LABEL_361;
                LOBYTE(v34) = LOBYTE(v6->pActiveSkills[13]);
              }
              goto LABEL_138;
            }
LABEL_118:
            if ( (signed int)v3 < 0 )
              goto LABEL_361;
            v39 = __OFSUB__((int)v3, 6);
            v37 = v3 == 6;
            v38 = v3 - 6 < 0;
          }
          else
          {
LABEL_253:
            if ( (signed int)v3 < 10 )
              goto LABEL_361;
            v39 = __OFSUB__((int)v3, 15);
            v37 = v3 == 15;
            v38 = v3 - 15 < 0;
          }
          if ( (unsigned __int8)(v38 ^ v39) | v37 )
            goto LABEL_121;
        }
      }
LABEL_361:
      ++v65;
      if ( (signed int)v65 >= 16 )
        return v5 + v62 + v61;
    }
  }
  if ( attr == 28 )
  {
    if ( IsUnarmed() != 1 )
    {
      if ( v6->HasItemEquipped(EQUIP_MAIN_HAND) )
      {
        v22 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
        if ( v22 >= 0 )
        {
          if ( v22 <= 2 )
          {
			  v23 = this->pInventoryItems[this->pEquipment.uMainHand].uItemID;
            if ( v6->pEquipment.uShield || pItemsTable->pItems[v23].uSkillType != 4 )
            {
              v24 = v23;
              v26 = pItemsTable->pItems[v23].uDamageRoll;
              v25 = pItemsTable->pItems[v23].uDamageDice;
            }
            else
            {
              v25 = pItemsTable->pItems[v24].uDamageRoll;
              v26 = pItemsTable->pItems[v24].uDamageDice + 1;
            }
            v5 = pItemsTable->pItems[v24].uDamageMod + v25 * v26;
          }
        }
      }
      if ( a3 || !v6->HasItemEquipped(EQUIP_OFF_HAND) || (v28 = v6->GetEquippedItemEquipType(EQUIP_OFF_HAND), v28 < 0) || v28 > 2 )
        return v5 + v62 + v61;
      v15 = pItemsTable->pItems[v29].uDamageMod;
      v14 = pItemsTable->pItems[v29].uDamageDice * pItemsTable->pItems[v29].uDamageRoll;
      goto LABEL_88;
    }
    v59 = 3;
LABEL_74:
    v5 = v59;
    return v5 + v62 + v61;
  }
  if ( (signed int)attr < 0 )
    return v5 + v62 + v61;
  if ( (signed int)attr <= 23 )
    goto LABEL_95;
  if ( (signed int)attr <= 24 )
    return v5 + v62 + v61;
  if ( (signed int)attr <= 26 )
  {
    if ( IsUnarmed() == 1 )
    {
      v5 = 0;
      return v5 + v62 + v61;
    }
    if ( v6->HasItemEquipped(EQUIP_MAIN_HAND) )
    {
      v17 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
      if ( v17 >= 0 )
      {
        if ( v17 <= 2 )
          v5 = pItemsTable->pItems[*(int *)&v6->pInventoryItems[v6->pEquipment.uMainHand-1]].uDamageMod;
      }
    }
    if ( a3 || !v6->HasItemEquipped(EQUIP_OFF_HAND) || (v19 = v6->GetEquippedItemEquipType(EQUIP_OFF_HAND), v19 < 0) || v19 > 2 )
      return v5 + v62 + v61;
    v20 = *(int *)&v6->pInventoryItems[v6->pEquipment.uShield - 1];
    goto LABEL_365;
  }
  if ( attr == 27 )
  {
    if ( IsUnarmed() == 1 )
    {
      v5 = 1;
      return v5 + v62 + v61;
    }
    if ( v6->HasItemEquipped(EQUIP_MAIN_HAND) )
    {
      v9 = this->GetEquippedItemEquipType(EQUIP_MAIN_HAND);
      if ( v9 >= 0 )
      {
        if ( v9 <= 2 )
        {
          v5 = pItemsTable->pItems[this->pInventoryItems[this->pEquipment.uMainHand].uItemID].uDamageDice +
                 pItemsTable->pItems[this->pInventoryItems[this->pEquipment.uMainHand].uItemID].uDamageMod;
          if ( !v6->pEquipment.uShield )
          {
            if ( pItemsTable->pItems[this->pInventoryItems[this->pEquipment.uMainHand].uItemID].uSkillType == 4 )
              ++v5;
          }
        }
      }
    }
    if ( a3 || !v6->HasItemEquipped(EQUIP_OFF_HAND) || (v12 = v6->GetEquippedItemEquipType(EQUIP_OFF_HAND), v12 < 0) || v12 > 2 )
      return v5 + v62 + v61;
    v14 = pItemsTable->pItems[this->pInventoryItems[this->pEquipment.uShield].uItemID].uDamageMod;
    v15 = pItemsTable->pItems[this->pInventoryItems[this->pEquipment.uShield].uItemID].uDamageDice;
LABEL_88:
    v5 += v15 + v14;
  }
  return v5 + v62 + v61;
}

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

  switch (a2)
  {
    case CHARACTER_ATTRIBUTE_LEVEL: return 0;
  }

  result = 0;
  if ( (signed int)a2 > 10 )
  {
    if ( (signed int)a2 <= 15 )
    {
      switch ( a2 )
      {
        case CHARACTER_ATTRIBUTE_RESIST_BODY:
          v3 = this->pPlayerBuffs[2].uPower;
          v4 = pParty->pPartyBuffs[1].uPower;
          break;
        case CHARACTER_ATTRIBUTE_RESIST_AIR:
          v3 = this->pPlayerBuffs[0].uPower;
          v4 = pParty->pPartyBuffs[0].uPower;
          break;
        case CHARACTER_ATTRIBUTE_RESIST_WATER:
          v3 = this->pPlayerBuffs[22].uPower;
          v4 = pParty->pPartyBuffs[17].uPower;
          break;
        case CHARACTER_ATTRIBUTE_RESIST_EARTH:
          v3 = this->pPlayerBuffs[3].uPower;
          v4 = pParty->pPartyBuffs[4].uPower;
          break;
        default:
          if ( a2 != 14 )
            return result;
          v3 = this->pPlayerBuffs[9].uPower;
          v4 = pParty->pPartyBuffs[12].uPower;
          break;
      }
      return v4 + v3;
    }
    if ( a2 != CHARACTER_ATTRIBUTE_ATTACK )
    {
      if ( a2 == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS )
      {
        v3 = this->pPlayerBuffs[8].uPower;
        v4 = pParty->pPartyBuffs[9].uPower;
        return v4 + v3;
      }
      if ( a2 != CHARACTER_ATTRIBUTE_RANGED_ATTACK )
        return result;
    }
    return this->pPlayerBuffs[1].uPower;
  }
  if ( a2 == 10 )
  {
    v3 = this->pPlayerBuffs[5].uPower;
    v4 = pParty->pPartyBuffs[6].uPower;
    return v4 + v3;
  }
  switch ( a2 )
  {
    case CHARACTER_ATTRIBUTE_STRENGTH:
      v3 = pPlayerBuffs[19].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_INTELLIGENCE:
      v3 = pPlayerBuffs[17].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_WILLPOWER:
      v3 = pPlayerBuffs[20].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_ENDURANCE:
      v3 = pPlayerBuffs[16].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_ACCURACY:
      v3 = pPlayerBuffs[15].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_SPEED:
      v3 = pPlayerBuffs[21].uPower;
      goto LABEL_5;
    case CHARACTER_ATTRIBUTE_LUCK:
      v3 = pPlayerBuffs[18].uPower;
LABEL_5:
      v4 = pParty->pPartyBuffs[2].uPower;
      return v4 + v3;
    case CHARACTER_ATTRIBUTE_AC_BONUS:
      v3 = this->pPlayerBuffs[14].uPower;
      v4 = pParty->pPartyBuffs[15].uPower;
      return v4 + v3;
    default:
      return result;
  }
  return result;
}

//----- (0048F882) --------------------------------------------------------
int Player::GetActualSkillLevel( PLAYER_SKILL_TYPE uSkillType )
    {
  signed int v2; // esi@1
  unsigned __int16 v3; // ax@126
  char result; // al@127
  unsigned int v5; // [sp-4h] [bp-14h]@13
  signed int v6; // [sp-4h] [bp-14h]@27
  //unsigned int v7; // [sp-4h] [bp-14h]@35
  CHARACTER_ATTRIBUTE_TYPE v8; // [sp-4h] [bp-14h]@68
  //Player *v9; // [sp+Ch] [bp-4h]@1
  
  v2 = 0;
  switch (uSkillType)
  {
    case PLAYER_SKILL_MONSTER_ID:
    {
      if ( CheckHiredNPCSpeciality(Hunter) )
        v2 = 6;
      if ( CheckHiredNPCSpeciality(Sage) )
        v2 += 6;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)20;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

    case PLAYER_SKILL_ARMSMASTER:
    {
        if ( CheckHiredNPCSpeciality(Armsmaster) )
          v2 = 2;
        if ( CheckHiredNPCSpeciality(Weaponsmaster) )
          v2 += 3;
        v8 = (CHARACTER_ATTRIBUTE_TYPE)21;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

    case PLAYER_SKILL_STEALING:
    {
      if (CheckHiredNPCSpeciality(Burglar))
          v2 = 8;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)17;
      v2 += GetItemsBonus(v8, 0);
    }
    break;


    case PLAYER_SKILL_ALCHEMY:
    {
        if ( CheckHiredNPCSpeciality(Herbalist) )
          v2 = 4;
        if ( CheckHiredNPCSpeciality(Apothecary) )
          v2 += 8;
        v8 = (CHARACTER_ATTRIBUTE_TYPE)16;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

    case PLAYER_SKILL_LEARNING:
    {
        if ( CheckHiredNPCSpeciality(Teacher) )
          v2 = 10;
        if ( CheckHiredNPCSpeciality(Instructor) )
          v2 += 15;
        if ( CheckHiredNPCSpeciality(Scholar) )
          v2 += 5;
        v8 = (CHARACTER_ATTRIBUTE_TYPE)46;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

    case PLAYER_SKILL_UNARMED:
    {
      if (CheckHiredNPCSpeciality(Monk) )
        v2 = 2;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)23;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

    case PLAYER_SKILL_DODGE:
    {
      if ( CheckHiredNPCSpeciality(Monk) )
        v2 = 2;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)22;
      v2 += GetItemsBonus(v8, 0);
    }
    break;
    
    case PLAYER_SKILL_BOW:
      v8 = (CHARACTER_ATTRIBUTE_TYPE)44;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_SHIELD:
      v8 = (CHARACTER_ATTRIBUTE_TYPE)45;
      v2 += GetItemsBonus(v8, 0);
    break;

    case PLAYER_SKILL_EARTH:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            v2 += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            v2 += 3;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)37;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_FIRE:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            v2 += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            v2 += 3;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)34;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_AIR:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            v2 += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            v2 += 3;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)35;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_WATER:
      if ( CheckHiredNPCSpeciality(Apprentice) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Mystic) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Spellmaster) )
            v2 += 4;
          if ( classType == PLAYER_CLASS_WARLOCK && PartyHasDragon() )
            v2 += 3;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)36;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_SPIRIT:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            v2 += 4;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)38;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_MIND:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            v2 += 4;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)39;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_BODY:
          if ( CheckHiredNPCSpeciality(Acolyte2) )
            v2 = 2;
          if ( CheckHiredNPCSpeciality(Initiate) )
            v2 += 3;
          if ( CheckHiredNPCSpeciality(Prelate) )
            v2 += 4;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)40;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_LIGHT:
      v8 = (CHARACTER_ATTRIBUTE_TYPE)41;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_DARK:
    {
      v8 = (CHARACTER_ATTRIBUTE_TYPE)42;
      v2 += GetItemsBonus(v8, 0);
    }
    break;

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

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

    case PLAYER_SKILL_ITEM_ID:
      v8 = (CHARACTER_ATTRIBUTE_TYPE)19;
      v2 += GetItemsBonus(v8, 0);
      break;
    case PLAYER_SKILL_MEDITATION:
      v8 = (CHARACTER_ATTRIBUTE_TYPE)43;
      v2 += GetItemsBonus(v8, 0);
    break;
    case PLAYER_SKILL_TRAP_DISARM:
    {
      if ( CheckHiredNPCSpeciality(Tinker) )
        v2 = 4;
      if ( CheckHiredNPCSpeciality(Locksmith) )
        v2 += 6;
      if ( CheckHiredNPCSpeciality(Burglar) )
        v2 += 8;
      v8 = (CHARACTER_ATTRIBUTE_TYPE)18;
      v2 += GetItemsBonus(v8, 0);
    }
    break;
  }

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

//----- (0048FC00) --------------------------------------------------------
int Player::GetSkillBonus(enum CHARACTER_ATTRIBUTE_TYPE a2)
{
  Player *v2; // esi@1
  int v3; // eax@1
  char v4; // di@1
  signed int v5; // ebx@1
  unsigned int v6; // eax@2
  unsigned __int8 v7; // sf@5
  unsigned __int8 v8; // of@5
  PlayerEquipment *v9; // ebx@19
  Player *v10; // ecx@20
  PLAYER_SKILL_TYPE v11; // edi@21
  int v12; // eax@21
  int v13; // edi@21
  char v14; // di@25
  signed int v15; // esi@25
  char v16; // al@32
  int v18; // eax@36
  unsigned int v19; // eax@37
  ITEM_EQUIP_TYPE v20; // edi@40
  int v21; // edx@41
  int v22; // eax@42
  PLAYER_SKILL_TYPE v23; // edi@45
  unsigned __int16 v24; // ax@45
  unsigned __int16 v25; // bx@45
  unsigned int v26; // eax@45
  unsigned __int8 v27; // sf@50
  unsigned __int8 v28; // of@50
  unsigned int v29; // eax@52
  int v30; // eax@55
  int v31; // eax@58
  unsigned int v32; // eax@59
  int v33; // eax@65
  char v34; // si@65
  ITEM_EQUIP_TYPE v35; // edi@69
  int v36; // edx@70
  int v37; // eax@71
  PLAYER_SKILL_TYPE v38; // edi@74
  int v39; // eax@74
  int v40; // eax@89
  char v41; // si@89
  int v42; // eax@96
  PLAYER_SKILL_TYPE v43; // edx@97
  int v44; // eax@97
  int v45; // eax@98
  int v46; // eax@99
  int v47; // eax@100
  int v48; // eax@101
  int v49; // eax@102
  unsigned __int16 v50; // ax@113
  char v51; // di@113
  unsigned int v52; // eax@113
  int v53; // edi@113
  signed int i; // ecx@113
  unsigned __int16 v55; // ax@118
  char v56; // si@118
  unsigned int v57; // eax@118
  int v58; // esi@121
  signed int j; // ecx@121
  int v60; // edi@126
  int v61; // eax@126
  signed int v62; // [sp-4h] [bp-30h]@26
  signed int v63; // [sp-4h] [bp-30h]@80
  int v64; // [sp+Ch] [bp-20h]@104
  int v65; // [sp+10h] [bp-1Ch]@104
  int v66; // [sp+14h] [bp-18h]@104
  int v67; // [sp+18h] [bp-14h]@104
  int v68; // [sp+1Ch] [bp-10h]@69
  PlayerEquipment *v69; // [sp+20h] [bp-Ch]@1
  int v70; // [sp+24h] [bp-8h]@1
  ITEM_EQUIP_TYPE v71; // [sp+28h] [bp-4h]@1
  int a1; // [sp+34h] [bp+8h]@21
  int a1a; // [sp+34h] [bp+8h]@74
  signed int a1b; // [sp+34h] [bp+8h]@94

  v2 = this;
  v70 = 0;
  v69 = 0;
  v71 = (ITEM_EQUIP_TYPE)0;
  LOBYTE(v3) = GetActualSkillLevel(PLAYER_SKILL_ARMSMASTER);
  v4 = v3;
  v5 = 1;
  if ( v3 )
  {
    v6 = SkillToMastery(v3);
    if ( a2 == CHARACTER_ATTRIBUTE_MELEE_DMG_BONUS )
    {
      if ( (signed int)v6 >= 4 )
        goto LABEL_4;
      v8 = __OFSUB__(v6, 3);
      v7 = ((v6 - 3) & 0x80000000u) != 0;
    }
    else
    {
      if ( a2 != CHARACTER_ATTRIBUTE_ATTACK )
        goto LABEL_11;
      if ( (signed int)v6 >= 4 )
      {
LABEL_4:
        v71 = (ITEM_EQUIP_TYPE)2;
LABEL_11:
        v69 = (PlayerEquipment *)(v71 * (v4 & 0x3F));
        goto LABEL_12;
      }
      v8 = __OFSUB__(v6, 2);
      v7 = ((v6 - 2) & 0x80000000u) != 0;
    }
    if ( !(v7 ^ v8) )
      v71 = (ITEM_EQUIP_TYPE)1;
    goto LABEL_11;
  }
LABEL_12:
  if ( a2 == CHARACTER_ATTRIBUTE_HEALTH )
  {
    v60 = pBaseHealthPerLevelByClass[v2->classType];
    v61 = v2->GetBodybuilding();
    return v60 * v61;
  }
  if ( a2 == CHARACTER_ATTRIBUTE_MANA )
  {
    v60 = pBaseManaPerLevelByClass[v2->classType];
    v61 = v2->GetMeditation();
    return v60 * v61;
  }
  if ( a2 != 9 )
  {
    if ( a2 != CHARACTER_ATTRIBUTE_ATTACK )
    {
      if ( a2 <= CHARACTER_ATTRIBUTE_ATTACK )
        return v70;
      if ( a2 > CHARACTER_ATTRIBUTE_MELEE_DMG_MAX )
      {
        if ( a2 != CHARACTER_ATTRIBUTE_RANGED_ATTACK )
          return v70;
        v71 = (ITEM_EQUIP_TYPE)0;
        v9 = &v2->pEquipment;
        while ( 1 )
        {
          if ( v2->HasItemEquipped(v71) )
          {
            v11 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v2->pInventoryItems[*(_DWORD *)v9].uItemID].uEquipType;
            LOBYTE(v12) = this->GetActualSkillLevel(v11);
            a1 = v12;
            SkillToMastery(v12);
            v13 = v11 - 5;
            if ( !v13 )
              return a1 & 0x3F;
            if ( v13 == 2 )
              break;
          }
          v71 = (ITEM_EQUIP_TYPE)((int)v71 + 1);
          v9 = (PlayerEquipment *)((char *)v9 + 4);
          if ( (signed int)v71 >= 16 )
            return v70;
        }
        v14 = a1;
        v15 = 1;
        if ( (signed int)SkillToMastery(a1) >= 4 )
        {
          v62 = 5;
          goto LABEL_31;
        }
        if ( (signed int)SkillToMastery(a1) >= 3 )
        {
          v62 = 3;
          goto LABEL_31;
        }
        if ( (signed int)SkillToMastery(a1) < 2 )
          goto LABEL_32;
        goto LABEL_30;
      }
      if ( v2->IsUnarmed() )
      {
        LOBYTE(v18) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
        v14 = v18;
        if ( !v18 )
          return v70;
        v15 = 0;
        v19 = SkillToMastery(v18);
        if ( (signed int)v19 < 3 )
        {
          if ( (signed int)v19 >= 2 )
            v15 = 1;
LABEL_32:
          v16 = v14;
          return v15 * (v16 & 0x3F);
        }
LABEL_30:
        v62 = 2;
LABEL_31:
        v15 = v62;
        goto LABEL_32;
      }
      v20 = (ITEM_EQUIP_TYPE)0;
      while ( 1 )
      {
        if ( v2->HasItemEquipped(v20) )
        {
          v22 = this->pInventoryItems[this->pEquipment.pIndices[v20]].uItemID;
          if ( pItemsTable->pItems[v22].uEquipType <= 1u )
            break;
        }
        v20 = (ITEM_EQUIP_TYPE)((int)v20 + 1);
        if ( (signed int)v20 >= 16 )
          return v70;
      }
      v71 = (ITEM_EQUIP_TYPE)0;
      v23 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v22].uSkillType;
      LOBYTE(v24) = v2->GetActualSkillLevel(v23);
      v25 = v24;
      v26 = SkillToMastery(v24);
      if ( !v23 )
      {
        if ( (signed int)SkillToMastery(v25) >= 4 )
        {
          LOBYTE(v31) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
          LOBYTE(v25) = v31;
          if ( v31 )
          {
            v15 = 0;
            v32 = SkillToMastery(v31);
            if ( (signed int)v32 < 3 )
            {
              if ( (signed int)v32 >= 2 )
                v15 = 1;
            }
            else
            {
              v15 = 2;
            }
            v16 = v25;
            return v15 * (v16 & 0x3F);
          }
        }
        goto LABEL_55;
      }
      if ( v23 == PLAYER_SKILL_DAGGER )
      {
        v29 = SkillToMastery(v25);
        v28 = __OFSUB__(v29, 4);
        v27 = ((v29 - 4) & 0x80000000u) != 0;
      }
      else
      {
        if ( v23 <= PLAYER_SKILL_DAGGER )
          goto LABEL_55;
        if ( v23 > PLAYER_SKILL_SPEAR )
        {
          if ( v23 == PLAYER_SKILL_MACE )
          {
            v28 = __OFSUB__(v26, 2);
            v27 = v26 - 2 < 0;
            goto LABEL_53;
          }
LABEL_55:
          v30 = v71 * (v25 & 0x3F);
          return (int)((char *)v69 + v30);
        }
        v28 = __OFSUB__(v26, 3);
        v27 = v26 - 3 < 0;
      }
LABEL_53:
      if ( !(v27 ^ v28) )
        v71 = (ITEM_EQUIP_TYPE)1;
      goto LABEL_55;
    }
    if ( v2->IsUnarmed() == 1 )
    {
      LOBYTE(v33) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
      v34 = v33;
      if ( !v33 )
        return v70;
      if ( (signed int)SkillToMastery(v33) >= 3 )
        v5 = 2;
      v30 = v5 * (v34 & 0x3F);
      return (int)((char *)v69 + v30);
    }
    v35 = (ITEM_EQUIP_TYPE)0;
    v68 = 0;
    while ( 1 )
    {
      if ( v2->HasItemEquipped(v35) )
      {
        v37 = *(int *)&v2->pInventoryItems[v35].uItemID;
        if ( pItemsTable->pItems[v37].uEquipType <= 1u )
          break;
      }
      v35 = (ITEM_EQUIP_TYPE)((int)v35 + 1);
      if ( (signed int)v35 >= 16 )
        return v70;
    }
    v38 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[v37].uSkillType;
    LOBYTE(v39) = v2->GetActualSkillLevel(v38);
    a1a = v39;
    SkillToMastery(v39);
    v71 = (ITEM_EQUIP_TYPE)0;
    if ( v38 )
    {
      if ( (signed int)v38 > 0 )
      {
        if ( (signed int)v38 <= 4 || v38 == 6 )
        {
          v71 = (ITEM_EQUIP_TYPE)1;
        }
        else
        {
          if ( v38 == 7 )
          {
            if ( (signed int)SkillToMastery(a1a) < 4 )
            {
              if ( (signed int)SkillToMastery(a1a) < 3 )
              {
                if ( (signed int)SkillToMastery(a1a) < 2 )
                  return v5 * (a1a & 0x3F);
                v63 = 2;
              }
              else
              {
                v63 = 3;
              }
            }
            else
            {
              v63 = 5;
            }
            v5 = v63;
            return v5 * (a1a & 0x3F);
          }
        }
      }
    }
    else
    {
      v71 = (ITEM_EQUIP_TYPE)1;
      if ( (signed int)SkillToMastery(a1a) >= 4 )
      {
        LOBYTE(v40) = v2->GetActualSkillLevel(PLAYER_SKILL_UNARMED);
        v41 = v40;
        if ( v40 )
        {
          if ( (signed int)SkillToMastery(v40) >= 3 )
            v5 = 2;
          v68 = v5 * (v41 & 0x3F);
        }
      }
    }
    v30 = v68 + v71 * (a1a & 0x3F);
    return (int)((char *)v69 + v30);
  }
  a1b = 0;
  v71 = (ITEM_EQUIP_TYPE)0;
  v68 = 16;
  v69 = &v2->pEquipment;
  do
  {
    if ( !v69->uShield || (v42 = (int)((char *)v2 + 36 * v69->uShield), *(char *)(v42 + 516) & 2) )
      goto LABEL_117;
    v43 = (PLAYER_SKILL_TYPE)pItemsTable->pItems[*(int *)(v42 + 496)].uSkillType;
    v44 = pItemsTable->pItems[*(int *)(v42 + 496)].uSkillType;
    if ( !v44 )
    {
      v64 = 0;
      v65 = 1;
LABEL_111:
      v66 = 0;
      goto LABEL_112;
    }
    v45 = v44 - 1;
    if ( !v45 || (v46 = v45 - 3) == 0 )
    {
      v64 = 0;
      v65 = 0;
      v66 = 0;
      v67 = 1;
      goto LABEL_113;
    }
    v47 = v46 - 4;
    if ( v47 )
    {
      v48 = v47 - 1;
      if ( v48 )
      {
        v49 = v48 - 1;
        if ( v49 )
        {
          if ( v49 != 1 )
            goto LABEL_117;
          a1b = 1;
          v64 = 1;
          v65 = 0;
          v66 = 0;
          v67 = 0;
          goto LABEL_113;
        }
        a1b = 1;
        v64 = 1;
        v65 = 0;
        goto LABEL_111;
      }
      v71 = (ITEM_EQUIP_TYPE)1;
    }
    else
    {
      a1b = 1;
    }
    v64 = 1;
    v65 = 0;
    v66 = 1;
LABEL_112:
    v67 = 0;
LABEL_113:
    LOBYTE(v50) = v2->GetActualSkillLevel(v43);
    v51 = v50;
    v52 = SkillToMastery(v50);
    v53 = v51 & 0x3F;
    for ( i = 0; i < (signed int)v52; ++i )
    {
      if ( *(&v64 + i) )
        v70 += v53;
    }
LABEL_117:
    v69 = (PlayerEquipment *)((char *)v69 + 4);
    --v68;
  }
  while ( v68 );
  v64 = 1;
  v65 = 1;
  v66 = 1;
  v67 = 0;
  LOBYTE(v55) = v2->GetActualSkillLevel(PLAYER_SKILL_DODGE);
  v56 = v55;
  v57 = SkillToMastery(v55);
  if ( !a1b && (!v71 || v57 == 4) )
  {
    v58 = v56 & 0x3F;
    for ( j = 0; j < (signed int)v57; ++j )
    {
      if ( *(&v64 + j) )
        v70 += v58;
    }
  }
  return v70;
}

//----- (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 > 15 )
  {
    if ( uCurrentFace >= 16 && uCurrentFace <= 19 )
      return CHARACTER_RACE_GOBLIN;
  }
  else
  {
    if ( uCurrentFace >= 12 )
    {
      return CHARACTER_RACE_DWARF;
    }
    else
    {
      
        if ( uCurrentFace <= 7 )
        {
          return CHARACTER_RACE_HUMAN;
        }
        else
        {
          if ( uCurrentFace <= 11 )
            return CHARACTER_RACE_ELF;
        }
    }
  }
  return CHARACTER_RACE_HUMAN;
}

//----- (00490141) --------------------------------------------------------
PLAYER_SEX Player::GetSexByVoice()
{
  signed int result; // eax@1

  result = 0;
  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;

    default:
      assert(false);
  }
}

//----- (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:
      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(_guilds_member_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)
{
  PLAYER_SKILL_TYPE result; // eax@5
  int v3; // edx@5
  char *v4; // ecx@5
  int v5; // esi@11
  unsigned __int16 *v6; // edx@11
  int v7; // esi@18
  unsigned __int16 *pActiveSkill; // edx@18

  if ( order >= 0 )
  {
    if ( order <= 1 )
    {
      result = (PLAYER_SKILL_TYPE)0;
      v7 = 0;
      pActiveSkill = this->pActiveSkills;
      do
      {
        if ( *pActiveSkill && pSkillAvailabilityPerClass[classType / 4][result] == 2 )
        {
          if ( v7 == order )
            return result;
          ++v7;
        }
        result = (PLAYER_SKILL_TYPE)((int)result + 1);
        ++pActiveSkill;
      }
      while ( (signed int)result < 37 );
    }
    else
    {
      if ( order <= 3 )
      {
        result = (PLAYER_SKILL_TYPE)0;
        v5 = 0;
        pActiveSkill = this->pActiveSkills;
        do
        {
          if ( *pActiveSkill && pSkillAvailabilityPerClass[classType / 4][result] == 1 )
          {
            if ( v5 == order - 2 )
              return result;
            ++v5;
          }
          result = (PLAYER_SKILL_TYPE)((int)result + 1);
          ++pActiveSkill;
        }
        while ( (signed int)result < 37 );
      }
      else
      {
        if ( order <= 12 )
        {
          result = (PLAYER_SKILL_TYPE)0;
          v3 = 0;
          v4 = (char *)pSkillAvailabilityPerClass[classType / 4];
          do
          {
            if ( *v4 == 1 )
            {
              if ( v3 == order - 4 )
                return result;
              ++v3;
            }
            result = (PLAYER_SKILL_TYPE)((int)result + 1);
            ++v4;
          }
          while ( (signed int)result < 37 );
        }
      }
    }
  }
  return (PLAYER_SKILL_TYPE)37;
}



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

  v2 = eAttribute + 7 * GetRace();
  pBaseValue = StatTable[0][v2].uBaseValue;
  pDroppedStep = StatTable[0][v2].uDroppedStep;
  uMinValue = pBaseValue - 2;
  pStep = StatTable[0][v2].uBaseStep;
    switch ( eAttribute )
    {
      case CHARACTER_MIGHT:
        if ( this->uMight <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uMight - pStep >= uMinValue )
         this->uMight -= pStep;
        break;
	  case CHARACTER_INTELLIGANCE:
        if ( this->uIntelligence <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uIntelligence - pStep >= uMinValue )
          this->uIntelligence -= pStep;
        break;
      case CHARACTER_WILLPOWER:
        if ( this->uWillpower <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uWillpower - pStep >= uMinValue )
          this->uWillpower -= pStep;
        break;
      case CHARACTER_ENDURANCE:
        if ( this->uEndurance <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uEndurance - pStep >= uMinValue )
          this->uEndurance -= pStep;
        break;
      case CHARACTER_ACCURACY:
        if ( this->uAccuracy <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uAccuracy - pStep >= uMinValue )
          this->uAccuracy -= pStep;
        break;
      case CHARACTER_SPEED:
        if ( this->uSpeed <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uSpeed - pStep >= uMinValue )
          this->uSpeed -= pStep;
        break;
      case CHARACTER_LUCK:
		if ( this->uLuck <= pBaseValue )
          pStep = pDroppedStep;
        if ( this->uLuck - pStep >= uMinValue )
          this->uLuck -= pStep;
        break;
    }
}

//----- (004905F5) --------------------------------------------------------
//signed int __thiscall PartyCreation_BtnPlusClick(Player *this, int eAttribute)
int Player::IncreaseAttribute(int eAttribute)
{
  Player *v2; // esi@1
  int v3; // eax@1
  int v4; // ebx@1
  signed int v5; // edi@1
  int v6; // eax@8
  signed int v7; // eax@17
  signed int result; // eax@18
  int v9; // [sp+Ch] [bp-8h]@1
  signed int v10; // [sp+10h] [bp-4h]@1

  v2 = this;
  v3 = eAttribute + 7 * GetRace();
  v4 = StatTable[0][v3].uMaxValue;
  v5 = StatTable[0][v3].uBaseStep;
  v9 = StatTable[0][v3].uBaseValue;
  v10 = StatTable[0][v3].uDroppedStep;
  PlayerCreation_ComputeAttributeBonus();
  if ( eAttribute )
  {
    switch ( eAttribute )
    {
      case 1:
        v6 = v2->uIntelligence;
        break;
      case 2:
        v6 = v2->uWillpower;
        break;
      case 3:
        v6 = v2->uEndurance;
        break;
      case 4:
        v6 = v2->uAccuracy;
        break;
      case 5:
        v6 = v2->uSpeed;
        break;
      case 6:
        v6 = v2->uLuck;
        break;
      default:
        v6 = eAttribute;
        break;
    }
  }
  else
  {
    v6 = v2->uMight;
  }
  if ( v6 < v9 )
  {
    v7 = v5;
    v5 = v10;
    v10 = v7;
  }
  result = PlayerCreation_ComputeAttributeBonus();
  if ( result >= v10 )
  {
    if ( eAttribute )
    {
      switch ( eAttribute )
      {
        case 1:
          result = (signed int)&v2->uIntelligence;
          break;
        case 2:
          result = (signed int)&v2->uWillpower;
          break;
        case 3:
          result = (signed int)&v2->uEndurance;
          break;
        case 4:
          result = (signed int)&v2->uAccuracy;
          break;
        case 5:
          result = (signed int)&v2->uSpeed;
          break;
        default:
          result = eAttribute - 6;
          if ( eAttribute != 6 )
            return result;
          result = (signed int)&v2->uLuck;
          break;
      }
    }
    else
    {
      result = (signed int)&v2->uMight;
    }
    if ( v5 + *(short *)result <= v4 )
      *(short *)result += v5;
  }
  return result;
}

//----- (0049070F) --------------------------------------------------------
void Player::Zero()
{
  Player *v1; // esi@1

  v1 = this;
  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);
  v1->field_1A97 = 0;
  v1->_ranged_dmg_bonus = 0;
  v1->field_1A95 = 0;
  v1->_ranged_atk_bonus = 0;
  v1->field_1A93 = 0;
  v1->_melee_dmg_bonus = 0;
  v1->field_1A91 = 0;
  v1->_some_attack_bonus = 0;
  v1->_mana_related = 0;
  v1->uFullManaBonus = 0;
  v1->_health_related = 0;
  v1->uFullHealthBonus = 0;
}

//----- (004907E7) --------------------------------------------------------
unsigned int Player::GetStatColor(int uStat)
{
  __int16 uWhite; // si@1
  int attribute_value; // edx@1
  unsigned __int8 pBaseAttrValue; // of@1
  __int16 uGreen; // [sp+8h] [bp-8h]@1
  __int16 uRed; // [sp+Ch] [bp-4h]@1

  uRed =   TargetColor(255,  35,   0);
  uGreen = TargetColor(0,   255,   0);
  uWhite = TargetColor(255, 255, 255);
  pBaseAttrValue = 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 == pBaseAttrValue )
    return uWhite;
  else if ( attribute_value > pBaseAttrValue )
    return uGreen;
  else
    return uRed;
}

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

        default:
            v68 = pParty->pPickedItem.GetDisplayName();
            sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[36], v68);//"%s can not be used that way"
            ShowStatusBarString(pTmpBuf, 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 )
                {
                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->_40471C();
                }
            else
                {
                thisb->SetRecoveryTime((signed __int64)(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 ( !pParty->pPlayers[player_num-1].CanAct() )
            {

            v68 = aCharacterConditionNames[v3->GetMajorConditionIdx()];
        sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[382], v68);
        ShowStatusBarString(pTmpBuf, 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->_4114F2();
            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 = v3->spellbook.bHaveSpell[pParty->pPickedItem.uItemID-400];//(char *)&v3->pConditions[0] + pParty->pPickedItem.uItemID + 2;
        if ( v72 )
            {
            v66 = pParty->pPickedItem.GetDisplayName();
            sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[380], v66);//"You already know the %s spell"
            ShowStatusBarString(pTmpBuf, 2u);
            pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
            return;
            }
        if ( !pParty->pPlayers[player_num-1].CanAct() )
            {
            v66 = aCharacterConditionNames[v3->GetMajorConditionIdx()];
            sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[382], v66);//"That player is %s"
            ShowStatusBarString(pTmpBuf, 2u);
            pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);
            return;
            }
        v16 = v15 % 11 + 1;
        v17 = v3->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, pGlobalTXT_LocalizationStrings[381], v22); //"You don't have the skill to learn %s"
            ShowStatusBarString(pTmpBuf, 2u);
            v3->PlaySound((PlayerSpeech)20, 0);
            return; 
            }
     //   v72 = 1;
        v3->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 )
            {
            if ( pParty->bTurnBasedModeOn )
                {
                pParty->pTurnBasedPlayerRecoveryTimes[player_num-1] = 100;
                thisb->SetRecoveryTime(100);
                pTurnEngine->_40471C();
                }
            else
                {
                thisb->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * 213.3333333333333));
                }
            }
        pMouse->RemoveHoldingItem();
        return;

        }

    if ( pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType == EQUIP_MESSAGE_SCROLL )

        {
        if ( pParty->pPlayers[player_num-1].CanAct() )
            {
            CreateMsgScrollWindow(pParty->pPickedItem.uItemID);
            v3->PlaySound(SPEECH_37, 0);
            return;
            }
        v68 = aCharacterConditionNames[v3->GetMajorConditionIdx()];
        sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[382], v68);
        ShowStatusBarString(pTmpBuf, 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:
                v3->uMight += thisa;
                sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 1:
                v3->uIntelligence += thisa;
                sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 2:
                v3->uWillpower += thisa;
                sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 3:
                v3->uEndurance += thisa;
                sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 4:
                v3->uAccuracy += thisa;
               sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 5:
                v3->uSpeed += thisa;
                sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 6:
                v3->uLuck += thisa;
               sprintf(pTmpBuf, "+%u %s %s", thisa, v74, pGlobalTXT_LocalizationStrings[121]);//"Permanent"	
                break;
            case 7:
                party_finds_gold(1000 * thisa, 0);
                sprintf(pTmpBuf, "+%u %s", 1000 * thisa, pGlobalTXT_LocalizationStrings[97]);//"Gold"
                break;
            case 8:
                Party::GiveFood(5 * thisa); 
                sprintf(pTmpBuf, "+%u %s",5 * thisa , pGlobalTXT_LocalizationStrings[653]);//"Food"
                break;
            case 9u:
                v3->uSkillPoints += 2 * thisa;
                sprintf(pTmpBuf, "+%u %s", 2 * thisa, pGlobalTXT_LocalizationStrings[LOCSTR_SKILL_POINTS]);
                break;
            case 10:
                v3->uExperience += 2500 * thisa;
                sprintf(pTmpBuf, "+%u %s", 2500 * thisa, pGlobalTXT_LocalizationStrings[LOCSTR_EXPIRIENCE]);
                break;
            case 11:
                v8 = rand() % 6;
                switch (v8)
                    {
                case 0:
                    v3->sResFireBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[87];
                    break;
                case 1:
                    v3->sResAirBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[6];
                    break;
                case 2:
                    v3->sResWaterBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[240];
                    break;
                case 3:
                    v3->sResEarthBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[70];
                    break;
                case 4:
                    v3->sResMindBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[142];
                    break;
                case 5:
                    v3->sResBodyBase += thisa;
                    v13 = pGlobalTXT_LocalizationStrings[29];
                    break;
                    }
                sprintf(pTmpBuf, "+%u %s %s", thisa, v13, pGlobalTXT_LocalizationStrings[121]);
                break;

                }
            ShowStatusBarString(pTmpBuf, 2u);
            pMouse->RemoveHoldingItem();
            pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, player_num - 1);
            v3->PlaySound(SPEECH_93, 0);
            pAudioPlayer->PlaySound((SoundID)219, 0, 0, -1, 0, 0, 0, 0);
            if ( pParty->uDaysPlayed == 6 || pParty->uDaysPlayed == 20 )
                {
                v3->SetCondition(Condition_Eradicated, 0);
                pAudioPlayer->PlaySound((SoundID)215, 0, 0, -1, 0, 0, 0, 0);
                }
            else if ( pParty->uDaysPlayed == 12 || pParty->uDaysPlayed == 26 )
                {
                v3->SetCondition(Condition_Dead, 0);
                pAudioPlayer->PlaySound((SoundID)215, 0, 0, -1, 0, 0, 0, 0);
                }
            else  if ( pParty->uDaysPlayed == 4 || pParty->uDaysPlayed == 25 )
                {
                v3->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((SoundID)(SOUND_PlayerCantCastSpell|0x2), 0, 0, -1, 0, 0, 0, 0);

            }
        else if ( pParty->pPickedItem.uItemID == 632 ) //Lute
                {
                pAudioPlayer->PlaySound((SoundID)133,  0, 0, -1, 0, 0, 0, 0);
                return;
                }
        else if ( pParty->pPickedItem.uItemID == 633 ) //Faerie Pipes
                {
                pAudioPlayer->PlaySound((SoundID)134,  0, 0, -1, 0, 0, 0, 0);
                return;
                }
        else if ( pParty->pPickedItem.uItemID == 634 ) //Gryphonheart's Trumpet
                {
                pAudioPlayer->PlaySound((SoundID)135,  0, 0, -1, 0, 0, 0, 0);
                return;
                }
        else if ( pParty->pPickedItem.uItemID == 646 ) //Horseshoe
                {
                pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, player_num - 1);
                v5 = PID(OBJECT_Player,player_num + 49);
                pAudioPlayer->PlaySound(SOUND_20001, v5, 0, -1, 0, 0, 0, 0);
                v3->AddVariable(VAR_NumSkillPoints, 2);
                }
        else if ( pParty->pPickedItem.uItemID == 650 ) //Temple in a Bottle
                    {
                    sub_44C28F_open_nwc_dungeon();
                    return;
                    }
        else
                {
   
                v68 = pParty->pPickedItem.GetDisplayName();
                sprintfex(pTmpBuf, pGlobalTXT_LocalizationStrings[36],v68);//"%s can not be used that way"
                ShowStatusBarString(pTmpBuf, 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[11].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->pInventoryItems;
          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[7].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->pInventoryItems[*(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->_guilds_member_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->pInventoryItems;
          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 *((int *)this + 2 * VarNum - 210);
}


//----- (0044A5CB) --------------------------------------------------------
void Player::SetVariable(enum VariableType var_type, signed int var_value)
{
  signed int currPlayerId; // ebx@1
  Player *v4; // esi@1
  unsigned int v5; // edi@1
  unsigned int v6; // esi@13
  unsigned int v7; // esi@14
  signed int v8; // eax@17
  ItemGen *v9; // ecx@17
  int v10; // eax@21
  signed int v11; // eax@30
  Player *v12; // 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 v27; // [sp-4h] [bp-38h]@4
  int v28; // [sp-4h] [bp-38h]@84
  ItemGen item; // [sp+Ch] [bp-28h]@52
  char v30; // [sp+32h] [bp-2h]@1
  char v31; // [sp+33h] [bp-1h]@1

  currPlayerId = 0;
  v30 = 0;
  v31 = 0;
  v4 = this;
  v5 = 0;
  if ( this == pPlayers[2] )
    currPlayerId = 1;
  else if ( this == pPlayers[3] )
    currPlayerId = 2;
  else if ( this == pPlayers[4] )
     currPlayerId  = 3;
  if ( var_type > VAR_AutoNotes )
  {
    if ( var_type <= VAR_GoldInBank )
    {
      if ( var_type == VAR_GoldInBank )
      {
        pParty->uNumGoldInBank = var_value;
        return;
      }
      if ( var_type <= VAR_Counter8 )
      {
        if ( (signed int)var_type >= 0xF5 )
        {
          *(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 *)field_1A50, var_value, 1u);
              break;
            case VAR_NPCs2:
              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 )
      {
        *(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) )
          return;
        bFlashHistoryBook = 1;
      }
LABEL_172:
      v25 = 8 * currPlayerId + 400;
      LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
      pAudioPlayer->PlaySound(SOUND_20001, v25, v5, -1, v5, v5, v5, v5);
      return;
    }
    if ( var_type != 307 )
    {
      switch ( var_type )
      {
        case 308:
          pParty->uNumBountiesCollected = var_value;
          break;
        case 309:
          pParty->uNumPrisonTerms = var_value;
          break;
        case 310:
          pParty->uNumArenaPageWins = var_value;
          break;
        case 311:
          pParty->uNumArenaSquireWins = var_value;
          break;
        case 312:
          pParty->uNumArenaKnightWins = var_value;
          break;
        case 313:
          pParty->uNumArenaLordWins = var_value;
          break;
      }
      return;
    }
    pParty->uNumDeaths = var_value;
LABEL_168:
    if ( v30 != 1 )
    {
LABEL_170:
      if ( v31 != 1 )
        return;
      v5 = 0;
      goto LABEL_172;
    }
LABEL_169:
    pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
    goto LABEL_170;
  }
  if ( var_type == VAR_AutoNotes )
  {
    if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & pParty->_autonote_bits[((signed __int16)var_value - 1) >> 3])
      //&& (&dword_723718_autonote_related)[8 * a3] )
	  && pAutonoteTxt[var_value-1].pText )
    {
      v20 = pPlayers[currPlayerId + 1];
      v30 = 1;
      v20->PlaySound(SPEECH_96, 0);
	  v21 = pAutonoteTxt[var_value-1].eType;// dword_72371C[2 * a3];
      bFlashAutonotesBook = 1;
      _506568_autonote_type = v21;
    }
    _449B7E_toggle_bit(pParty->_autonote_bits, var_value, 1u);
    v31 = 1;
    goto LABEL_168;
  }
  if ( var_type <= VAR_ActualMight )
  {
    if ( var_type != VAR_ActualMight )
    {
      switch ( var_type )
      {
        case VAR_RandomGold:
          v6 = rand() % var_value + 1;
          Party::SetGold(v6);
          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[500], v6);// You have %lu gold
          ShowStatusBarString(pTmpBuf, 2u);
          GameUI_DrawFoodAndGold();
          return;
        case VAR_RandomFood:
          v7 = rand() % var_value + 1;
          Party::SetFood(v7);
          sprintf(pTmpBuf, pGlobalTXT_LocalizationStrings[501], v7);// You have %lu food
          ShowStatusBarString(pTmpBuf, 2u);
          GameUI_DrawFoodAndGold();
          goto LABEL_124;
        case VAR_Sex:
          this->uSex = (PLAYER_SEX)var_value;
          goto LABEL_124;
        case VAR_Class:
          this->classType = (PLAYER_CLASS_TYPE)var_value;
          if ( (char)var_value != 35 )
            goto LABEL_124;
          v8 = 0;
          v9 = this->pInventoryItems;
          break;
        case VAR_CurrentHP:
          this->sHealth = var_value;
          goto LABEL_124;
        case VAR_MaxHP:
          this->sHealth = GetMaxHealth();
          return;
        case VAR_CurrentSP:
          this->sMana = var_value;
          goto LABEL_124;
        case VAR_MaxSP:
          this->sMana = GetMaxMana();
          return;
        case VAR_ACModifier:
          this->sACModifier = (unsigned __int8)var_value;
          goto LABEL_124;
        case VAR_BaseLevel:
          this->uLevel = (unsigned __int8)var_value;
          goto LABEL_124;
        case VAR_LevelModifier:
          this->sLevelModifier = (unsigned __int8)var_value;
          goto LABEL_124;
        case VAR_Age:
          this->sAgeModifier = var_value;
          return;
        case VAR_Award:
          if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & 
			  pPlayers[currPlayerId + 1]->_guilds_member_bits[((signed __int16)var_value - 1)/ 8])
            //&& dword_723E80_award_related[2 * a3] )
			&& pAwards[var_value].pText )
          {
            v30 = 1;
            v31 = 1;
            pPlayers[currPlayerId + 1]->PlaySound(SPEECH_96, 0);
          }
		  _449B7E_toggle_bit((unsigned char *)v4->_guilds_member_bits, var_value, 1u);
          goto LABEL_168;
        case VAR_Experience:
          this->uExperience = var_value;
          goto LABEL_124;
        case VAR_QBits_QuestsDone:
          if ( !((unsigned __int8)(0x80u >> ((signed __int16)var_value - 1) % 8) & pParty->_quest_bits[((signed __int16)var_value - 1) >> 3])
           // && (&dword_722F10)[4 * a3] )
		   && pQuestTable[var_value-1] )
          {
            v14 = pPlayers[currPlayerId + 1];
            bFlashQuestBook = 1;
            v30 = 1;
            v31 = 1;
            v14->PlaySound(SPEECH_93, 0);
          }
          v13 = (char *)pParty->_quest_bits;
LABEL_51:
          _449B7E_toggle_bit((unsigned char *)v13, var_value, 1u);
		  if (( v30 != 1 )&&( v31 != 1 ))
				  return;
		  else
			  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
		  if ( v31 != 1 )
			  return;
		  v25 = 8 * currPlayerId + 400;
		  LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
		  pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
		  return;
        case VAR_PlayerItemInHands:
          item.Reset();
          item.Reset();
          item.uItemID = var_value;
          item.uAttributes = 1;
          pParty->SetHoldingItem(&item);
          if ( var_value >= ITEM_ARTIFACT_PUCK && var_value <= ITEM_RELIC_MEKORIGS_HAMMER )
            pParty->pIsArtifactFound[var_value-500] = 1;
          return;
        case VAR_FixedGold:
          Party::SetGold(var_value);
          return;
        case VAR_BaseMight:
          this->uMight = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BaseIntellect:
          this->uIntelligence = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BasePersonality:
          this->uWillpower = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BaseEndurance:
          this->uEndurance = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BaseSpeed:
          this->uSpeed = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BaseAccuracy:
          this->uAccuracy = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_BaseLuck:
          this->uLuck = (unsigned __int8)var_value;
          goto LABEL_84;
        case VAR_FixedFood:
          Party::SetFood(var_value);
          goto LABEL_124;
        case VAR_MightBonus:
          goto LABEL_64;
        case VAR_IntellectBonus:
          goto LABEL_68;
        case VAR_PersonalityBonus:
          goto LABEL_69;
        case VAR_EnduranceBonus:
          goto LABEL_70;
        case VAR_SpeedBonus:
          goto LABEL_71;
        case VAR_AccuracyBonus:
          goto LABEL_72;
        case VAR_LuckBonus:
          goto LABEL_73;
        default:
          return;
      }
      while ( v9->uItemID != 615 )
      {
        ++v8;
        ++v9;
        if ( v8 >= 138 )
          goto LABEL_22;
      }
      v10 = (int)((char *)v4 + 36 * v8);
      *(int *)(v10 + 532) = 601;
      *(char *)(v10 + 558) = currPlayerId + 1;
LABEL_22:
      if ( v4->sResFireBase < 20 )
        v4->sResFireBase = 20;
      if ( v4->sResAirBase < 20 )
        v4->sResAirBase = 20;
      if ( v4->sResWaterBase < 20 )
        v4->sResWaterBase = 20;
      if ( v4->sResEarthBase < 20 )
        v4->sResEarthBase = 20;
      v4->sResMindBase = 200;
      v4->sResBodyBase = 200;
      v11 = v4->GetSexByVoice();
      v4->uPrevVoiceID = v4->uVoiceID;
      v4->uPrevFace = v4->uCurrentFace;
      if ( v11 )
      {
        v4->uCurrentFace = 21;
        v4->uVoiceID = 21;
      }
      else
      {
        v4->uCurrentFace = 20;
        v4->uVoiceID = 20;
      }
      ReloadPlayerPortraits(currPlayerId, v4->uCurrentFace);
      goto LABEL_124;
    }
LABEL_64:
    this->uMightBonus = (unsigned __int8)var_value;
LABEL_111:
    v28 = 0;
    v26 = SPEECH_91;
LABEL_112:
    v19 = pPlayers[currPlayerId + 1];
    v31 = 1;
    v19->PlaySound((PlayerSpeech)v26, v28);
    goto LABEL_169;
  }
  if ( var_type <= VAR_FireResistanceBonus )
  {
    if ( var_type == VAR_FireResistanceBonus )
    {
      this->sResFireBonus = (unsigned __int8)var_value;
      goto LABEL_111;
    }
    switch ( var_type )
    {
      case VAR_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;
        goto LABEL_84;
      case VAR_AirResistance:
        this->sResAirBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_WaterResistance:
        this->sResWaterBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_EarthResistance:
        this->sResEarthBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_SpiritResistance:
        this->sResSpiritBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_MindResistance:
        this->sResMindBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_BodyResistance:
        this->sResBodyBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_LightResistance:
        this->sResLightBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_DarkResistance:
        this->sResDarkBase = (unsigned __int8)var_value;
        goto LABEL_84;
      case VAR_MagicResistance:
        this->sResMagicBase = (unsigned __int8)var_value;
LABEL_84:
        v28 = 0;
        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 )
      {
        v4->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(v4, 0, 0xA0u);
      }
LABEL_124:
      v31 = 1;
      goto LABEL_169;
    }
LABEL_106:
    v16 = (int)((char *)&v4->pConditions[16] + 2 * var_type);
    v17 = *(char *)v16;
    if ( var_value <= VAR_BodyResistanceBonus )
    {
      LOWORD(v15) = (unsigned __int8)var_value;
      v18 = v15 | v17 & VAR_BodyResistanceBonus;
    }
    else
    {
      LOWORD(v18) = (unsigned __int8)(var_value | v17 & 0xC0);
    }
    *(short *)v16 = v18;
    goto LABEL_124;
  }
  if ( var_type == VAR_DisarmTrapSkill )
	  if ( v30 != 1 )
		  {
		  if ( v31 != 1 )
			  return;
		  v5 = 0;
		  goto LABEL_172;
		  }
	  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
	  goto LABEL_170;
  if ( var_type <= VAR_BodyResistanceBonus )
  {
    switch ( var_type )
    {
      case VAR_BodyResistanceBonus:
        v4->sResBodyBonus = (unsigned __int8)var_value;
        break;
      case VAR_AirResistanceBonus:
        v4->sResAirBonus = (unsigned __int8)var_value;
        break;
      case VAR_WaterResistanceBonus:
        v4->sResWaterBonus = (unsigned __int8)var_value;
        break;
      case VAR_EarthResistanceBonus:
        v4->sResEarthBonus = (unsigned __int8)var_value;
        break;
      case VAR_SpiritResistanceBonus:
        v4->sResSpiritBonus = (unsigned __int8)var_value;
        break;
      default:
        if ( var_type != 62 )
          return;
        v4->sResMindBonus = (unsigned __int8)var_value;
        break;
    }
    goto LABEL_111;
  }
  if ( var_type == VAR_LightResistanceBonus )
  {
    v4->sResLightBonus = (unsigned __int8)var_value;
    goto LABEL_111;
  }
  if ( var_type == VAR_DarkResistanceBonus )
  {
    v4->sResDarkBonus = (unsigned __int8)var_value;
    goto LABEL_111;
  }
  if ( var_type == VAR_MagicResistanceBonus )
  {
    v4->sResMagicBonus = (unsigned __int8)var_value;
    goto LABEL_111;
  }
  if ( var_type > VAR_MagicResistanceBonus && var_type <= VAR_DiplomacySkill )
	  if ( v30 != 1 )
		  {
		  if ( v31 != 1 )
			  return;
		  v5 = 0;
		  v25 = 8 * currPlayerId + 400;
		  LOBYTE(v25) = PID(OBJECT_Player,currPlayerId - 112);
		  pAudioPlayer->PlaySound(SOUND_20001, v25, 0, -1, 0, 0, 0, 0);
		  return;
		  }
	  pGame->pStru6Instance->SetPlayerBuffAnim(0x96u, currPlayerId);
	  goto LABEL_170;
}


//----- (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, pGlobalTXT_LocalizationStrings[502], v7);// You find %lu food
              ShowStatusBarString(pTmpBuf, 2u);
              GameUI_DrawFoodAndGold();
              goto _play_sound;
            case VAR_Sex:
              Dst->uSex = (PLAYER_SEX)val;
              goto _play_anim_and_exit;
            case VAR_Class:
              Dst->classType = (PLAYER_CLASS_TYPE)val;
              goto _play_anim_and_exit;
            case VAR_CurrentHP:
              v8 = &Dst->sHealth;
              *v8 += val;
              if ( Dst->sHealth <= Dst->GetMaxHealth() )
                goto _play_anim_and_exit;
              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;
              }
              goto _play_anim_and_exit;
            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;
              goto _play_anim_and_exit;
            case VAR_Age:
              Dst->sAgeModifier += val;
              return;
            case VAR_Award:
              v13 = pPlayers[uPlayerIdx + 1];
              if (_449B57_test_bit((unsigned __int8 *)pPlayers[uPlayerIdx + 1]->_guilds_member_bits, val) 
             
				&& pAwards[val].pText )
              {
                v14 = pPlayers[uPlayerIdx + 1];
                v34 = 1;
                v3 = 1;
                v14->PlaySound(SPEECH_96, 0);
              }
              v15 = (char *)v4->_guilds_member_bits;
              goto LABEL_44;
            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;
              goto _play_anim_and_exit;
            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-1] )
              {
                //v17 = pPlayers[uPlayerIdx + 1];
                bFlashQuestBook = 1;
                v34 = 1;
                v3 = 1;
                pPlayers[uPlayerIdx + 1]->PlaySound(SPEECH_93, 0);
              }
              v15 = (char *)pParty->_quest_bits;
LABEL_44:
              _449B7E_toggle_bit((unsigned char *)v15, val, 1u);
              goto LABEL_173;
            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, pGlobalTXT_LocalizationStrings[502], val);
              ShowStatusBarString(pTmpBuf, 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;
              v31 = 0;
              v29 = 92;
              goto LABEL_116;
            default:
              return;
          }
          return;
        }
        v19 = &Dst->sResFireBonus;
LABEL_113:
        *v19 += val;
        if ( *v19 > 255 )
          *v19 = 255;
        v31 = 0;
        v29 = SPEECH_91;
LABEL_116:
        v3 = 1;
        pPlayers[uPlayerIdx + 1]->PlaySound((PlayerSpeech)v29, v31);
        goto _play_anim_and_maybe_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;
        }
        goto _play_anim_and_exit;
      }
      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);
      }
_play_anim_and_exit:
      v3 = 1;
_play_anim_and_maybe_sound:
      pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, uPlayerIdx);
_maybe_play_sound:
      if ( v3 != 1 )
        return;
      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-1].pText )
    {
      v23 = pPlayers[uPlayerIdx + 1];
      v34 = 1;
      v23->PlaySound(SPEECH_96, 0);
	  v24 = pAutonoteTxt[val-1].eType;//dword_72371C[2 * val];
      bFlashAutonotesBook = 1;
      _506568_autonote_type = v24;
    }
    _449B7E_toggle_bit(pParty->_autonote_bits, val, 1u);
    v3 = 1;
LABEL_173:
    if ( v34 != 1 )
      goto _maybe_play_sound;
    goto _play_anim_and_maybe_sound;
  }
  if ( var_type > VAR_GoldInBank )
  {
    if ( var_type == 307 )
    {
      pParty->uNumDeaths += val;
      goto LABEL_173;
    }
    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;
  }
}
// 506568: using guessed type int dword_506568;
// 507948: using guessed type char bFlashHistoryBook;
// 507949: using guessed type char bFlashAutonotesBook;
// 50794A: using guessed type char bFlashQuestBook;
// 72371C: using guessed type int dword_72371C[];
// 723E80: using guessed type int dword_723E80_award_related[];




//----- (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;
              if ( (unsigned int)pValue <= *(int *)v17 )
              {
					*(int *)v17 -= (int)pValue;
					result = v17;
			  }
              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;
    }
  }
  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, pGlobalTXT_LocalizationStrings[503], v6);
          ShowStatusBarString(pTmpBuf, 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, pGlobalTXT_LocalizationStrings[504], v7);
          ShowStatusBarString(pTmpBuf, 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, 4);
          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->_guilds_member_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->pInventoryIndices;
          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;
          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->pInventoryItems[pInventoryIndices[v3] - 1].uItemID) == pValue )
        {
          RemoveItemAtInventoryIndex(v3);
          return true;
        }
      }
      if ( pParty->pPickedItem.uItemID == pValue )
      {
        pMouse->RemoveHoldingItem();
        return true;
      }
      return false;
    }
  }
}
// 5B65C4: using guessed type int dword_5B65C4;
// 5B65CC: using guessed type int dword_5B65CC;