view Items.cpp @ 501:6fa3ff8ef729

SubtractVariables
author Ritor1
date Fri, 01 Mar 2013 17:37:47 +0600
parents 4bd56919f075
children 214d9d47cf1f
line wrap: on
line source

#include <stdlib.h>
#include <assert.h>

#include "Items.h"
#include "MapInfo.h"
#include "FrameTableInc.h"
#include "Allocator.h"
#include "GUIWindow.h"
#include "Events2D.h"
#include "Chest.h"
#include "LOD.h"
#include "Monsters.h"
#include "Party.h"
#include "FactionTable.h"
#include "StorylineTextTable.h"
#include "texts.h"
#include "mm7_data.h"



struct ITEM_VARIATION
	{
	unsigned __int16 treasure_level;
	unsigned __int16 item_class[4];
	};


char uItemsAmountPerShopType[5]={ 0, 6, 8, 12, 12};

ITEM_VARIATION shopWeap_variation_ord[15] ={
	{ 0, { 0, 0, 0, 0 }},
	{ 1, { 23, 27, 20, 20 }},
	{ 1, { 23, 24, 28, 20 }},
	{ 2, { 23, 24, 25, 20 }},
	{ 2, { 27, 27, 26, 26 }},
	{ 4, { 24, 30, 25, 27 }},
	{ 4, { 24, 30, 25, 27 }},
	{ 3, { 30, 24, 20, 20 }},
	{ 2, { 20, 20, 20, 20 }},
	{ 3, { 27, 27, 26, 26 }},
	{ 3, { 28, 28, 25, 25 }},
	{ 2, { 23, 23, 24, 24 }},
	{ 3, { 23, 23, 26, 26 }},
	{ 2, { 30, 26, 26, 26 }},
	{ 2, { 28, 25, 28, 29 }}};

ITEM_VARIATION shopArmr_variation_ord[28] ={
	{ 1, { 35, 35, 38, 38 }},
	{ 1, { 31, 31, 31, 34 }},
	{ 1, { 35, 35, 38, 38 }},
	{ 1, { 31, 31, 32, 34 }},
	{ 2, { 35, 35, 38, 38 }},
	{ 2, { 31, 32, 32, 33 }},
	{ 2, { 35, 35, 38, 38 }},
	{ 2, { 31, 31, 32, 32 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 31, 32, 33, 34 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 31, 32, 33, 34 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 31, 31, 31 }},
	{ 2, { 35, 35, 38, 38 }},
	{ 2, { 31, 32, 34, 34 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 31, 32, 32 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 32, 32, 32, 33 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 31, 31, 32 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 33, 31, 32, 34 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 33, 31, 32, 34 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 33, 31, 32, 34 }}};



unsigned __int16 shopMagic_treasure_lvl[14]= {0, 1, 1, 2, 2, 4, 4, 3, 2, 2, 2, 2, 2, 2};
unsigned __int16 shopAlch_treasure_lvl[13] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 2, 2, 2, 2};

ITEM_VARIATION shopWeap_variation_spc[15]={
	{ 0, { 0, 0, 0, 0 }},
	{ 2, { 25, 30, 20, 20}},
	{ 2, { 23, 24, 28, 20}},
	{ 3, { 23, 24, 25, 20}},
	{ 3, { 27, 27, 26, 26}},
	{ 5, { 23, 26, 28, 27}},
	{ 5, { 23, 26, 28, 27}},
	{ 4, { 30, 24, 20, 20}},
	{ 3, { 20, 20, 20, 20}},
	{ 4, { 27, 27, 26, 26}},
	{ 4, { 28, 28, 25, 25}},
	{ 4, { 23, 23, 24, 24}},
	{ 4, { 24, 24, 27, 20}},
	{ 4, { 30, 26, 26, 26}},
	{ 4, { 28, 25, 28, 29}}};

ITEM_VARIATION shopArmr_variation_spc[28]={
	{ 2, { 35, 35, 38, 38 }},
	{ 2, { 31, 31, 31, 34 }},
	{ 2, { 35, 35, 38, 38 }},
	{ 2, { 31, 31, 32, 34 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 32, 32, 33 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 31, 32, 32 }},
	{ 5, { 35, 35, 38, 38 }},
	{ 5, { 31, 32, 33, 34 }},
	{ 5, { 35, 35, 38, 38 }},
	{ 5, { 31, 32, 33, 34 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 31, 31, 31, 31 }},
	{ 3, { 35, 35, 38, 38 }},
	{ 3, { 31, 32, 34, 34 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 31, 31, 32, 33 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 32, 32, 33, 34 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 31, 31, 31, 32 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 32, 32, 32, 32 }},
	{ 4, { 35, 35, 38, 38 }},
	{ 4, { 34, 34, 34, 34 }},
	{ 5, { 35, 35, 38, 38 }},
	{ 5, { 33, 33, 33, 33 }}
	};

unsigned __int16 shopMagicSpc_treasure_lvl[14]  =  {0, 2, 2, 3, 3, 5, 5, 4, 3, 3, 3, 3, 3, 3};
unsigned __int16 shopAlchSpc_treasure_lvl[13]   =  {0, 2, 2, 3, 3, 4, 4, 5, 5, 3, 2, 2, 2};

int  sub_4BE571(int a1, int *a2, int a3, int a4);

ItemGen *ptr_50C9A4;

struct ItemsTable *pItemsTable; // 005D29E0





//----- (00439DF3) --------------------------------------------------------
int ItemGen::_439DF3_get_additional_damage(int *damage_type, bool *draintargetHP)
	{
	*damage_type = 0;
	if ( !uItemID )
		return 0;
	UpdateTempBonus(pParty->uTimePlayed);
	if (uItemID == 501 )  //Iron Feather -sword
		{
		*damage_type = 1;
		return rand() % 10 + 6;
		}
	if (uItemID == 507 ) //Ghoulsbane  -axe
		{
		*damage_type = 0;
		return rand() % 16 + 3;
		}
	if ( uItemID == 510 ) //Ullyses  -bow
		{
		*damage_type = 2;
		return rand() % 4 + 9;
		}
	if ( uItemID == 517 ) //Old Nick -dagger
		{
		*damage_type = 8;
		return 8;
		}

	switch (uSpecEnchantmentType)
		{
	case 4:  //Adds 3-4 points of Cold damage.
		*damage_type = 2;
		return rand() % 2 + 3;
		break;
	case 5:  //Adds 6-8 points of Cold damage.
		*damage_type = 2;
		return rand() % 3 + 6;
		break;
	case 6: //Adds 9-12 points of Cold damage.
		*damage_type = 2;
		return rand() % 4 + 9;
		break;
	case 7: //Adds 2-5 points of Electrical damage.
		*damage_type = 1;
		return rand() % 4 + 2;
		break;
	case 8: //Adds 4-10 points of Electrical damage.
		*damage_type = 1;
		return rand() % 7 + 4;
		break;
	case 9: //Adds 6-15 points of Electrical damage.
		*damage_type = 1;
		return rand() % 10 + 6;
		break;
	case 10: //Adds 1-6 points of Fire damage.
		*damage_type = 0;
		return GetDiceResult(1, 6);
		break;
	case 11: //Adds 2-12 points of Fire damage.
		*damage_type = 0;
		return GetDiceResult(2, 6);
		break;
	case 12: //Adds 3-18 points of Fire damage.
		*damage_type = 0;
		return GetDiceResult(3, 6);
		break;
	case 13: //Adds 5 points of Body damage.
		*damage_type = 8;
		return 5;
		break;
	case 14: //Adds 8 points of Body damage.
		*damage_type = 8;
		return 8;
		break;
	case 15: //Adds 12 points of Body damage.
		*damage_type = 8;
		return 12;
		break;
	case 16: //Drain Hit Points from target.
	case 41: //Drain Hit Points from target and Increased Weapon speed.
		*damage_type = 10;
		*draintargetHP = true;
		return 0;
		break;
	case 46:  //Adds 10-20 points of Fire damage and +25 Might.
		*damage_type = 0;
		return rand() % 11 + 10;
		break;
	default:
		*damage_type = 0;
		return 0;

		}

	}


//----- (00402F07) --------------------------------------------------------
void ItemGen::Reset()
{
  this->uHolderPlayer = 0;
  this->uAttributes = 0;
  this->uNumCharges = 0;
  this->uSpecEnchantmentType = 0;
  this->_bonus_strength = 0;
  this->uEncantmentType = 0;
  this->uItemID = 0;
  this->uBodyAnchor = 0;
  this->uExpireTime = 0i64;
}

//----- (00458260) --------------------------------------------------------
void ItemGen::UpdateTempBonus(__int64 uTimePlayed)
{
  if ( this->uAttributes & ITEM_TEMP_BONUS )
  {
    if ( uTimePlayed > (signed __int64)this->uExpireTime )
    {
      this->uEncantmentType = 0;
      this->uSpecEnchantmentType = 0;
      this->uAttributes = this->uAttributes&(~ITEM_TEMP_BONUS);
    }
  }
}

//----- (0045814E) --------------------------------------------------------
void ItemsTable::Release()
{
  if ( pMonstersTXT_Raw )
    pAllocator->FreeChunk(pMonstersTXT_Raw);
  if ( pMonsterPlacementTXT_Raw )
    pAllocator->FreeChunk(pMonsterPlacementTXT_Raw);
  if ( pSkillDescTXT_Raw )
    pAllocator->FreeChunk(pSkillDescTXT_Raw);
  if (pSpcItemsTXT_Raw )
    pAllocator->FreeChunk(pSpcItemsTXT_Raw);
  if ( pStdItemsTXT_Raw )
    pAllocator->FreeChunk(pStdItemsTXT_Raw);
  if ( pRndItemsTXT_Raw )
    pAllocator->FreeChunk(pRndItemsTXT_Raw);
  if ( pItemsTXT_Raw )
    pAllocator->FreeChunk(pItemsTXT_Raw);
  if ( pHostileTXT_Raw )
    pAllocator->FreeChunk(pHostileTXT_Raw);
  if ( pHistoryTXT_Raw )
    pAllocator->FreeChunk(pHistoryTXT_Raw);
  if ( pPotionsTXT_Raw )
    pAllocator->FreeChunk(pPotionsTXT_Raw);
  if ( pPotionNotesTXT_Raw )
    pAllocator->FreeChunk(pPotionNotesTXT_Raw);
  pSpcItemsTXT_Raw = NULL;
  pSkillDescTXT_Raw = NULL;
  pStdItemsTXT_Raw = NULL;
  pRndItemsTXT_Raw = NULL;
  pItemsTXT_Raw = NULL;

}


//----- (00456D84) --------------------------------------------------------
void ItemsTable::Initialize()
	{
	int i,j;
	char* test_string;
	unsigned char c;
	bool break_loop;
	unsigned int temp_str_len;
	char* tmp_pos;
	int decode_step;
	int item_counter;

	pMapStats = new MapStats;
	pMapStats->Initialize();

	pMonsterStats = new MonsterStats;
	pMonsterStats->Initialize();
	pMonsterStats->InitializePlacements();

	pSpellStats = new SpellStats;
	pSpellStats->Initialize();

	LoadPotions();
	LoadPotionNotes();

	pFactionTable = new FactionTable;
	pFactionTable->Initialize();

	pStorylineText = new StorylineText;
	pStorylineText->Initialize();

	pStdItemsTXT_Raw = NULL;
	pStdItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stditems.txt", 0);
	strtok(pStdItemsTXT_Raw, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	//Standard Bonuses by Group	
	for (i=0;i<24;++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 0: 
					pEnchantments[i].pBonusStat=RemoveQuotes(test_string);
					break;
				case 1:
					pEnchantments[i].pOfName= RemoveQuotes(test_string);
					break;
				default:
					pEnchantments[i].to_item[decode_step-2]=atoi(test_string);
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<11)&&!break_loop);
		}

	memset(&pEnchantmentsSumm, 0, 36);
	for(i=0;i<9;++i)
		{
		for (j=0;j<24;++j)
			pEnchantmentsSumm[i]+=pEnchantments[j].to_item[i];
		}

	//Bonus range for Standard by Level
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	for(i=0;i<6;++i) //counted from 1
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if  (decode_step==2)
				bonus_ranges[i].minR = atoi(test_string);
			else if (decode_step==3)
				bonus_ranges[i].maxR =atoi(test_string);
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<4)&&!break_loop);
		}


	pSpcItemsTXT_Raw = 0;
	pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0);
	strtok(pSpcItemsTXT_Raw, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	for (i=0;i<72;++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 0: 
					pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(test_string);
					break;
				case 1:
					pSpecialEnchantments[i].pNameAdd= RemoveQuotes(test_string);
					break;
				case 14:
					int res;
					res=atoi(test_string);
					if(!res)
						{
						++test_string; 
						while (*test_string==' ')//fix X 2 case
							++test_string; 
						res=atoi(test_string);
						}				
					pSpecialEnchantments[i].iValue=res;
					break;
				case 15:
					pSpecialEnchantments[i].iTreasureLevel=  tolower(*test_string) - 97;;
					break;
				default:
					pSpecialEnchantments[i].to_item_apply[decode_step-2]=atoi(test_string);
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<16)&&!break_loop);
		}

	pSpecialEnchantments_count = 71;
	memset(&pSpecialEnchantmentsSumm, 0, 96);
	for(i=0;i<12;++i)
		{
		for (j=0;j<pSpecialEnchantments_count;++j)
			pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i];
		}

	Initialize2DA();

	pItemsTXT_Raw = NULL;
	pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0);
	strtok(pItemsTXT_Raw, "\r");
	strtok(NULL, "\r");
	uAllItemsCount = 0;
	item_counter = 0;
	while (true)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 0: //Item #
					item_counter=atoi(test_string);
					uAllItemsCount=item_counter;
					break;
				case 1: //Pic File
					pItems[item_counter].pIconName = RemoveQuotes(test_string);
					break;
				case 2: //Name
					pItems[item_counter].pName = RemoveQuotes(test_string);
					break;
				case 3: //Value
					pItems[item_counter].uValue=atoi(test_string);
					break;
				case 4: //Equip Stat
					{
					if ( !_strcmpi(test_string, "weapon") )
						{
						pItems[item_counter].uEquipType = EQUIP_ONE_OR_TWO_HANDS;
						break;
						}
					if ( !_strcmpi(test_string, "weapon2") )
						{
						pItems[item_counter].uEquipType = EQUIP_TWO_HANDED;
						break;
						}
					if ( !_strcmpi(test_string, "weapon1or2") )
						{
						pItems[item_counter].uEquipType = EQUIP_ONE_OR_TWO_HANDS;
						break;
						}
					if ( !(_strcmpi(test_string, "missile")&&_strcmpi(test_string, "bow")))
						{
						pItems[item_counter].uEquipType = EQUIP_BOW;
						break;
						}
					if ( !_strcmpi(test_string, "armor") )
						{
						pItems[item_counter].uEquipType = EQUIP_ARMOUR;
						break;
						}
					if ( !_strcmpi(test_string, "shield") )
						{
						pItems[item_counter].uEquipType = EQUIP_SHIELD;
						break;
						}
					if ( !_strcmpi(test_string, "helm") )
						{
						pItems[item_counter].uEquipType = EQUIP_HELMET;
						break;
						}
					if ( !_strcmpi(test_string, "belt") )
						{
						pItems[item_counter].uEquipType = EQUIP_BELT;
						break;
						}
					if ( !_strcmpi(test_string, "cloak") )
						{
						pItems[item_counter].uEquipType = EQUIP_CLOAK;
						break;
						}
					if ( !_strcmpi(test_string, "gauntlets") )
						{
						pItems[item_counter].uEquipType = EQUIP_GAUNTLETS;
						break;
						}
					if ( !_strcmpi(test_string, "boots") )
						{
						pItems[item_counter].uEquipType = EQUIP_BOOTS;
						break;
						}
					if ( !_strcmpi(test_string, "ring") )
						{
						pItems[item_counter].uEquipType = EQUIP_RING;
						break;
						}
					if ( !_strcmpi(test_string, "amulet") )
						{
						pItems[item_counter].uEquipType = EQUIP_AMULET;
						break;
						}
					if ( !_strcmpi(test_string, "weaponw") )
						{
						pItems[item_counter].uEquipType = EQUIP_WAND;
						break;
						}
					if ( !(_strcmpi(test_string, "herb")&&_strcmpi(test_string, "reagent")))
						{
						pItems[item_counter].uEquipType = EQUIP_REAGENT;
						break;
						}
					if ( !_strcmpi(test_string, "bottle") )
						{
						pItems[item_counter].uEquipType = EQUIP_POTION;
						break;
						}
					if ( !_strcmpi(test_string, "sscroll") )
						{
						pItems[item_counter].uEquipType = EQUIP_SPELL_SCROLL;
						break;
						}
					if ( !_strcmpi(test_string, "book") )
						{
						pItems[item_counter].uEquipType = EQUIP_BOOK;
						break;
						}
					if ( !_strcmpi(test_string, "mscroll") )
						{
						pItems[item_counter].uEquipType = EQUIP_MESSAGE_SCROLL;
						break;
						}
					if ( !_strcmpi(test_string, "gold") )
						{
						pItems[item_counter].uEquipType = EQUIP_GOLD;
						break;
						}
					if ( !_strcmpi(test_string, "gem") )
						{
						pItems[item_counter].uEquipType = EQUIP_GEM;
						break;
						}
					pItems[item_counter].uEquipType = EQUIP_NONE;
					break;
					}
				case 5: //Skill Group
					{
					if ( !_strcmpi(test_string, "staff") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_STAFF;
						break;
						}
					if ( !_strcmpi(test_string, "sword") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_SWORD;
						break;
						}
					if ( !_strcmpi(test_string, "dagger") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_DAGGER;
						break;
						}
					if ( !_strcmpi(test_string, "axe") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_AXE;
						break;
						}
					if ( !_strcmpi(test_string, "spear") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_SPEAR;
						break;
						}
					if ( !_strcmpi(test_string, "bow") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_BOW;
						break;
						}
					if ( !_strcmpi(test_string, "mace") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_MACE;
						break;
						}
					if ( !_strcmpi(test_string, "blaster") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_BLASTER;
						break;
						}
					if ( !_strcmpi(test_string, "shield") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_SHIELD;
						break;
						}
					if ( !_strcmpi(test_string, "leather") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_LEATHER;
						break;
						}
					if ( !_strcmpi(test_string, "chain") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_CHAIN;
						break;
						}
					if ( !_strcmpi(test_string, "plate") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_PLATE;
						break;
						}
					if ( !_strcmpi(test_string, "club") )
						{
						pItems[item_counter].uSkillType = PLAYER_SKILL_CLUB;
						break;
						}
					pItems[item_counter].uSkillType = PLAYER_SKILL_MISC;
					break;
					}
				case 6: //Mod1
					{
					int ii;
					char* test_char;
					int tst_len;
					tst_len=strlen(test_string);
					pItems[item_counter].uDamageDice=0;
					pItems[item_counter].uDamageRoll=0;
					test_char=test_string;
					for (ii=0; ii<tst_len; ++ii)
						{
						if (tolower(*test_char)=='d')
							{
							*test_char=0;
							pItems[item_counter].uDamageDice=atoi(test_string);
							pItems[item_counter].uDamageRoll=atoi(test_char+1);
							*test_char='d';
							break;
							}
						++test_char;
						}
					test_char=test_string;
					if ((ii==tst_len)&&(tolower(*test_char)=='s'))
						{
						pItems[item_counter].uDamageDice=atoi(test_char+1);
						pItems[item_counter].uDamageRoll=1;
						}
					break;
					}
				case 7: //Mod2
					pItems[item_counter].uDamageMod=atoi(test_string);
					break;
				case 8: //material
					{
					if ( !_strcmpi(test_string, "artifact") )
						{
						pItems[item_counter].uMaterial = MATERIAL_ARTEFACT;
						break;
						}
					if ( !_strcmpi(test_string, "relic") )
						{
						pItems[item_counter].uMaterial = MATERIAL_RELIC;
						break;
						}
					if ( !_strcmpi(test_string, "special") )
						{
						pItems[item_counter].uMaterial = MATERIAL_SPECIAL;
						break;
						}
					pItems[item_counter].uMaterial = MATERIAL_COMMON;
					break;}
				case 9:  //ID/Rep/St
					pItems[item_counter].uItemID_Rep_St=atoi(test_string);
					break;
				case 10: //Not identified name
					pItems[item_counter].pUnidentifiedName = RemoveQuotes(test_string);
					break;
				case 11: //Sprite Index
					pItems[item_counter].uSpriteID=atoi(test_string);
					break;
				case 12: //VarA
					{
					pItems[item_counter]._additional_value=0;
					pItems[item_counter]._bonus_type=0;
					if (pItems[item_counter].uMaterial==MATERIAL_SPECIAL)
						{
						for(int ii=0; ii<24; ++ii)
							{
							if (stricmp(test_string,pEnchantments[ii].pBonusStat))
								{
								pItems[item_counter]._bonus_type=ii+1;
								break;
								}
							}
						if (!pItems[item_counter]._bonus_type)
							{
							for(int ii=0; ii<72; ++ii)
								{
								if (stricmp(test_string,pSpecialEnchantments[ii].pBonusStatement))
									{
									pItems[item_counter]._additional_value=ii+1;
									}
								}
							}
						}

					break;
					}
				case 13: //VarB
					if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type))
						{
						char b_s=atoi(test_string);
						if (b_s)
							pItems[item_counter]._bonus_strength=b_s;
						else
							pItems[item_counter]._bonus_strength=1;
						}
					else
						pItems[item_counter]._bonus_strength=0;
					break;
				case 14: //Equip X
					pItems[item_counter].uEquipX=atoi(test_string);
					break;
				case 15: //Equip Y
					pItems[item_counter].uEquipY=atoi(test_string);
					break;
				case 16: //Notes
					pItems[item_counter].pDescription = RemoveQuotes(test_string);
					break;

					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<17)&&!break_loop);
			++item_counter;
			if (item_counter>799)
				break;
		}


	pRndItemsTXT_Raw = NULL;
	uAllItemsCount = item_counter;
	pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0);
	strtok(pRndItemsTXT_Raw, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	item_counter = 0;
	while (true)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 0: 
					item_counter=atoi(test_string);
					break;
				case 2:
					pItems[item_counter].uChanceByTreasureLvl1=atoi(test_string);
					break;
				case 3:
					pItems[item_counter].uChanceByTreasureLvl2=atoi(test_string);
					break;
				case 4:
					pItems[item_counter].uChanceByTreasureLvl3=atoi(test_string);
					break;
				case 5:
					pItems[item_counter].uChanceByTreasureLvl4=atoi(test_string);
					break;
				case 6:
					pItems[item_counter].uChanceByTreasureLvl5=atoi(test_string);
					break;
				case 7:
					pItems[item_counter].uChanceByTreasureLvl6=atoi(test_string);
					break;
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<8)&&!break_loop);
			++item_counter;
			if (item_counter>618)
				break;
		}

	if ( pRndItemsTXT_Raw )
		{
		pAllocator->FreeChunk(pRndItemsTXT_Raw);
		pRndItemsTXT_Raw = NULL;
		}
	//ChanceByTreasureLvl Summ - anti cheating?
	memset(&uChanceByTreasureLvlSumm, 0, 24);
	for(i=0;i<6;++i)
		{
		for (j=0;j<800;++j)
			uChanceByTreasureLvlSumm[i]+=pItems[j].uChanceByTreasureLvl[i];
		}

	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	strtok(NULL, "\r");
	for (i=0;i<3;++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 2: 
					switch (i)
						{
					case 0:
						uBonusChanceStandart[0]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[0]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[0]=atoi(test_string);
						break;
						}
					break;
				case 3:
					switch (i)
						{
					case 0:
						uBonusChanceStandart[1]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[1]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[1]=atoi(test_string);
						break;
						}
					break;
				case 4: 
					switch (i)
						{
					case 0:
						uBonusChanceStandart[2]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[2]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[2]=atoi(test_string);
						break;
						}
					break;
				case 5:
					switch (i)
						{
					case 0:
						uBonusChanceStandart[3]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[3]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[3]=atoi(test_string);
						break;
						}
					break;
				case 6: 
					switch (i)
						{
					case 0:
						uBonusChanceStandart[4]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[4]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[4]=atoi(test_string);
						break;
						}
					break;
				case 7:
					switch (i)
						{
					case 0:
						uBonusChanceStandart[5]=atoi(test_string);
						break;
					case 1:
						uBonusChanceSpecial[5]=atoi(test_string);
						break;
					case 2:
						uBonusChanceWpSpecial[5]=atoi(test_string);
						break;
						}
					break;
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<8)&&!break_loop);
		}

	pSkillDescTXT_Raw = NULL;
	pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0);
	strtok(pSkillDescTXT_Raw, "\r");
	for (i=0; i<37; ++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (decode_step)
					{
				case 1:
					pSkillDesc[i] = RemoveQuotes(test_string);
					break;
				case 2:
					pNormalSkillDesc[i] = RemoveQuotes(test_string);
					break;
				case 3:
					pExpertSkillDesc[i] = RemoveQuotes(test_string);
					break;
				case 4:
					pMasterSkillDesc[i] = RemoveQuotes(test_string);
					break;
				case 5:
					pGrandSkillDesc[i] = RemoveQuotes(test_string);
					break;	  
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<6)&&!break_loop);
		}

	pStatsTXT_Raw = 0;
	pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0);
	strtok(pStatsTXT_Raw, "\r");
	for (i=0; i<26; ++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				switch (i)
					{
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
					pAttributeDescriptions[i] = RemoveQuotes(test_string);
					break;
				case 7:
					pHealthPointsAttributeDescription = RemoveQuotes(test_string);
					break;
				case 8:
					pArmourClassAttributeDescription = RemoveQuotes(test_string);
					break;
				case 9:
					pSpellPointsAttributeDescription = RemoveQuotes(test_string);
					break;
				case 10:
					pPlayerConditionAttributeDescription = RemoveQuotes(test_string);
					break;
				case 11:
					pFastSpellAttributeDescription = RemoveQuotes(test_string);
					break;
				case 12:
					pPlayerAgeAttributeDescription = RemoveQuotes(test_string);
					break;
				case 13:
					pPlayerLevelAttributeDescription = RemoveQuotes(test_string);
					break;
				case 14:
					pPlayerExperienceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 15:
					pAttackBonusAttributeDescription = RemoveQuotes(test_string);
					break;
				case 16:
					pAttackDamageAttributeDescription = RemoveQuotes(test_string);
					break;
				case 17:
					pMissleBonusAttributeDescription = RemoveQuotes(test_string);
					break;
				case 18:
					pMissleDamageAttributeDescription = RemoveQuotes(test_string);
					break;
				case 19:
					pFireResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 20:
					pAirResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 21:
					pWaterResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 22:
					pEarthResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 23:
					pMindResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 24:
					pBodyResistanceAttributeDescription = RemoveQuotes(test_string);
					break;
				case 25:
					pSkillPointsAttributeDescription = RemoveQuotes(test_string);
					break;  
					}
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<2)&&!break_loop);
		}


	pClassTXT_Raw = 0;
	pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0);
	strtok(pClassTXT_Raw, "\r");
	for (i=0; i<36; ++i)
		{
		test_string = strtok(NULL, "\r") + 1;
		break_loop = false;
		decode_step=0;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{
				//if(i) 
					pClassDescriptions[i]=RemoveQuotes(test_string);
				}
			else
				{ 
				if (!decode_step)
					break_loop = true;
				}
			++decode_step;
			test_string=tmp_pos+1;
			} while ((decode_step<2)&&!break_loop);
		}

	}

//----- (00456D17) --------------------------------------------------------
void ItemsTable::SetSpecialBonus(ItemGen *pItem)
{
  if ( pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL )
  {
    pItem->uEncantmentType = pItems[pItem->uItemID]._bonus_type;
    pItem->uSpecEnchantmentType = pItems[pItem->uItemID]._additional_value;
    pItem->_bonus_strength = pItems[pItem->uItemID]._bonus_strength;
  }
}

//----- (00456D43) --------------------------------------------------------
bool ItemsTable::IsMaterialSpecial(ItemGen *pItem)
{
  return this->pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL;
}

//----- (00456D5E) --------------------------------------------------------
bool ItemsTable::IsMaterialNonCommon(ItemGen *pItem)
{
  return pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL ||
	      pItems[pItem->uItemID].uMaterial == MATERIAL_RELIC || 
		  pItems[pItem->uItemID].uMaterial == MATERIAL_ARTEFACT;
}


//----- (00453B3C) --------------------------------------------------------
void ItemsTable::LoadPotions()
	{

	CHAR Text[90]; // [sp+Ch] [bp-6Ch]@26
	char* test_string;
	unsigned int uRow;
	unsigned int uColumn;
	unsigned __int8 potion_value;

	if ( pPotionsTXT_Raw )
		pAllocator->FreeChunk(pPotionsTXT_Raw);
	pPotionsTXT_Raw = NULL;
	pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0);
	test_string = strtok(pPotionsTXT_Raw,"\t\r\n");
	while ( 1 )
		{
		if ( !test_string )
			{
			MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
			return;
			}
		if ( !strcmp(test_string, "222") )
			break;

		test_string = strtok(NULL, "\t\r\n");
		}
	while ( 1 )
		{
		test_string = strtok(NULL, "\t\r\n");

		if ( !test_string )
			{
			MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
			return;
			}
		if ( !strcmp(test_string, "222") )
			break;
		}

	for (uRow = 0;uRow < 50; ++uRow)
		{
		int skip_count;
		for (skip_count = 0;skip_count < 6; ++skip_count)
			{
			if ( !strtok(NULL, "\r\t\n") )
				break;
			}
		if ( skip_count != 6 )
			break;
		for (uColumn = 0; uColumn < 50; ++uColumn)
			{
			test_string = strtok(NULL, "\r\t\n");   
			if ( !test_string )
				break;
			potion_value = atoi(test_string);
			unsigned char c=*test_string;
			if ( !potion_value )
				{
				if ( tolower(c) == 'e' )
					potion_value = atoi(test_string + 1);
				else
					potion_value = 0;
				}
			this->potion_data[uRow][uColumn]=potion_value;
			}
		if ( uColumn != 50 )
			break;
		strtok(NULL, "\r\t\n");
		}

	if ( uRow != 50 )
		{
		wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, uColumn);
		MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
		}
	if ( pPotionsTXT_Raw )
		{
		pAllocator->FreeChunk(pPotionsTXT_Raw);
		pPotionsTXT_Raw = 0;
		}
	}

//----- (00453CE5) --------------------------------------------------------
void ItemsTable::LoadPotionNotes()
	{

	CHAR Text[90]; 
	char* test_string;
	unsigned int uRow;
	unsigned int uColumn;
	unsigned __int8 potion_note;

	if ( pPotionNotesTXT_Raw )
		pAllocator->FreeChunk(pPotionNotesTXT_Raw);
	pPotionNotesTXT_Raw = NULL;
	pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0);
	test_string = strtok(pPotionNotesTXT_Raw ,"\t\r\n");
	while ( 1 )
		{
		if ( !test_string )
			{
			MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
			return;
			}	
		if ( !strcmp(test_string, "222") )
			break;
		test_string = strtok(NULL, "\t\r\n");
		}
	while ( 1 )
		{
		test_string = strtok(NULL, "\t\r\n");

		if ( !test_string )
			{
			MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
			return;
			}
		if ( !strcmp(test_string, "222") )
			break;
		}

	for (uRow = 0;uRow < 50; ++uRow)
		{
		int skip_count;
		for (skip_count = 0;skip_count < 6; ++skip_count)
			{
			if ( !strtok(NULL, "\r\t\n") )
				break;
			}
		if ( skip_count != 6 )
			break;
		for (uColumn = 0; uColumn < 50; ++uColumn)
			{
			test_string = strtok(NULL, "\r\t\n");   
			if ( !test_string )
				break;
			potion_note = atoi(test_string);
			unsigned char c=*test_string;
			if ( !potion_note )
				{
				if ( tolower(c) == 'e' )
					potion_note = atoi(test_string + 1);
				else
					potion_note = 0;
				}
			this->potion_note[uRow][uColumn]=potion_note;
			}
		if ( uColumn != 50 )
			break;
		strtok(NULL, "\r\t\n");
		}
	if ( uRow != 50 )
		{
		wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, uColumn);
		MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
		}
	}


//----- (00456442) --------------------------------------------------------
unsigned int ItemGen::GetValue()
	{
	unsigned int uBaseValue; // edi@1
	unsigned int bonus;

	uBaseValue = pItemsTable->pItems[this->uItemID].uValue;
	if ( this->uAttributes & ITEM_TEMP_BONUS || pItemsTable->IsMaterialNonCommon(this) )
		return uBaseValue;
	if (uEncantmentType )
		return uBaseValue + 100 * _bonus_strength;;
	if (uSpecEnchantmentType )
		{
		bonus = pItemsTable->pSpecialEnchantments[uSpecEnchantmentType].iTreasureLevel;
		if ( bonus > 10 )
			return uBaseValue + bonus;
		else
			return uBaseValue * bonus;
		} 
	return uBaseValue;
	}

//----- (00456499) --------------------------------------------------------
const char *ItemGen::GetDisplayName()
{
  if (Identified())
    return GetIdentifiedName();
  else
    return pItemsTable->pItems[uItemID].pUnidentifiedName;
}

//----- (004564B3) --------------------------------------------------------
const char *ItemGen::GetIdentifiedName()
{
  unsigned __int8 equip_type; 
  const char *player_name; 
  const char *nameModificator; 
  const char *format_str; 

  equip_type = pItemsTable->pItems[uItemID].uEquipType;
  if ( (equip_type == EQUIP_REAGENT) || (equip_type == EQUIP_POTION) || (equip_type == EQUIP_GOLD) )
  {
    sprintf(item__getname_buffer, "%s", pItemsTable->pItems[uItemID].pName);
    return item__getname_buffer;
  }
  sprintf(item__getname_buffer, "%s", pItemsTable->pItems[uItemID].pName);
  if ( uItemID == ITEM_LICH_JAR )  //Lich Jar
  {
    if ( (uHolderPlayer >0 )&& (uHolderPlayer <= 4) )
      {
        player_name = pPlayers[uHolderPlayer]->pName;
        strlen(player_name);
        if ( player_name[strlen(player_name) - 1] == 's' )
          format_str = pGlobalTXT_LocalizationStrings[655]; //"%s' Jar"
        else
          format_str = pGlobalTXT_LocalizationStrings[654]; //"%s's Jar"
		sprintf(item__getname_buffer, format_str, pPlayers[uHolderPlayer]->pName);
		return item__getname_buffer;
      }
  }
  if ( !pItemsTable->IsMaterialNonCommon(this) )
  {
    if ( uEncantmentType )
    {
      strcat(item__getname_buffer, " ");
      nameModificator = pItemsTable->pEnchantments[uEncantmentType-1].pOfName;
    }
    else
    {
      if ( !uSpecEnchantmentType )
        return item__getname_buffer;
      if ( uSpecEnchantmentType == 16 //Drain Hit Points from target.
        || uSpecEnchantmentType == 39 //Double damage vs Demons.
        || uSpecEnchantmentType == 40 //Double damage vs Dragons
        || uSpecEnchantmentType == 45 //+5 Speed and Accuracy
        || uSpecEnchantmentType == 56 //+5 Might and Endurance.
        || uSpecEnchantmentType == 57 //+5 Intellect and Personality.
        || uSpecEnchantmentType == 58 //Increased Value.
        || uSpecEnchantmentType == 60 //+3 Unarmed and Dodging skills
        || uSpecEnchantmentType == 61 //+3 Stealing and Disarm skills.
        || uSpecEnchantmentType == 59  //Increased Weapon speed.
        || uSpecEnchantmentType == 63 //Double Damage vs. Elves.
        || uSpecEnchantmentType == 64 //Double Damage vs. Undead.
        || uSpecEnchantmentType == 67 //Adds 5 points of Body damage and +2 Disarm skill.
        || uSpecEnchantmentType == 68 ) //Adds 6-8 points of Cold damage and +5 Armor Class.
      {  //enchantment and name positions inverted!
        sprintf( item__getname_buffer, "%s %s",
				  pItemsTable->pSpecialEnchantments[uSpecEnchantmentType-1].pNameAdd,
				  pItemsTable->pItems[uItemID].pName);
        return item__getname_buffer;
      }
      strcat(item__getname_buffer, " ");
	  nameModificator = pItemsTable->pSpecialEnchantments[uSpecEnchantmentType-1].pNameAdd;
    }
    strcat(item__getname_buffer, nameModificator);
  }
  return item__getname_buffer;
}


//----- (00456620) --------------------------------------------------------
void ItemsTable::GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *out_item)
{
  
ItemGen *v4; // esi@1
  ItemsTable *v5; // edi@1
  int v6; // ebx@3
  int *v7; // ecx@33
  //int v8; // eax@34
  //int v9; // eax@39
  int v10; // ebx@43
  int v11; // ecx@47
  unsigned int *v12; // edx@48
  unsigned int v13; // eax@49
  signed int v14; // ebx@52
  int v15; // eax@53
  signed int v16; // eax@55
  int v17; // ebx@57
  int v18; // edx@62
  signed int v19; // ebx@70
  unsigned __int8 v20; // al@81
  int v21; // eax@84
  int v22; // ebx@85
  int v23; // eax@86
  int v24; // ebx@86
  int v25; // edx@86
  int v26; // edx@89
  unsigned int v27; // eax@89
  int i; // ebx@89
  unsigned int v29; // ecx@90
  int v30; // ebx@91
  int v31; // eax@91
  int v32; // ecx@91
  int v33; // eax@91
  int v34; // eax@97
  unsigned __int8 v35; // sf@97
  unsigned __int8 v36; // of@97
  int v37; // ebx@98
  int v38; // edx@99
  signed int v39; // ebx@101
  int v40; // ecx@102
  char v41; // zf@107
  char v42; // al@108
  char v43; // al@111
  int *v44; // edx@118
  int v45; // eax@120
  int v46; // edx@120
  int *j; // eax@121
  unsigned int v48; // ecx@123
  int v49; // eax@123
  int v50; // eax@123
  int Dst[800]; // [sp+Ch] [bp-C88h]@33
  int v52; // [sp+C8Ch] [bp-8h]@33
  int v53; // [sp+C90h] [bp-4h]@1
  int v54; // [sp+C9Ch] [bp+8h]@3
  //int v55; // [sp+CA0h] [bp+Ch]@34
  signed int v56; // [sp+CA0h] [bp+Ch]@55
  int v57; // [sp+CA0h] [bp+Ch]@62
  int *v58; // [sp+CA0h] [bp+Ch]@102
  int v59; // [sp+CA0h] [bp+Ch]@123
  //signed int a2a; // [sp+CA4h] [bp+10h]@33
  int a2b; // [sp+CA4h] [bp+10h]@101
  int a2c; // [sp+CA4h] [bp+10h]@120

  v53 = -1;
  v5 = this;
  if (!out_item)
    out_item = (ItemGen *)pAllocator->AllocNamedChunk(out_item, sizeof(*out_item), "newItemGen");
  memset(out_item, 0, sizeof(*out_item));

  v4 = out_item;
  v6 = treasure_level - 1;
  v54 = treasure_level - 1;
  if ( uTreasureType ) //generate known treasure type
  {
    ITEM_EQUIP_TYPE   requested_equip;
    PLAYER_SKILL_TYPE requested_skill = PLAYER_SKILL_INVALID;
    switch (uTreasureType)
     {
      case 20: requested_equip = EQUIP_ONE_OR_TWO_HANDS; break;
      case 21: requested_equip = EQUIP_ARMOUR; break;
      case 22: requested_skill = PLAYER_SKILL_MISC; break;
      case 23: requested_skill = PLAYER_SKILL_SWORD; break;
      case 24: requested_skill = PLAYER_SKILL_DAGGER; break;
      case 25: requested_skill = PLAYER_SKILL_AXE; break;
      case 26: requested_skill = PLAYER_SKILL_SPEAR; break;
      case 27: requested_skill = PLAYER_SKILL_BOW; break;
      case 28: requested_skill = PLAYER_SKILL_MACE; break;
      case 29: requested_skill = PLAYER_SKILL_CLUB; break;
      case 30: requested_skill = PLAYER_SKILL_STAFF; break;
      case 31: requested_skill = PLAYER_SKILL_LEATHER; break;
      case 32: requested_skill = PLAYER_SKILL_CHAIN; break;
      case 33: requested_skill = PLAYER_SKILL_PLATE; break;
      case 34: requested_equip = EQUIP_SHIELD; break;
      case 35: requested_equip = EQUIP_HELMET; break;
      case 36: requested_equip = EQUIP_BELT; break;
      case 37: requested_equip = EQUIP_CLOAK; break;
      case 38: requested_equip = EQUIP_GAUNTLETS; break;
      case 39: requested_equip = EQUIP_BOOTS; break;
      case 40: requested_equip = EQUIP_RING; break;
      case 41: requested_equip = EQUIP_AMULET; break;
      case 42: requested_equip = EQUIP_WAND; break;
	  case 43: requested_equip = EQUIP_SPELL_SCROLL; break;
      case 44: requested_equip = EQUIP_POTION; break;
      case 45: requested_equip = EQUIP_REAGENT; break;
      case 46: requested_equip = EQUIP_GEM; break;
      default:
        __debugbreak(); // check this condition
        requested_equip = (ITEM_EQUIP_TYPE)(uTreasureType - 1);
      break;
    }
    memset(Dst, 0, sizeof(Dst));
    v52 = 0;
    v7 = Dst;
    //a2a = 1;
    if (requested_skill == PLAYER_SKILL_INVALID)  // no skill for this item needed
    {
      for (uint i = 1; i < 500; ++i)
      {
        if (pItems[i].uEquipType == requested_equip)
        {
          *v7++ = i;
          v52 += pItems[i].uChanceByTreasureLvl[v6];
        }
      }
    }
    else  //have needed skill
    {
      for (uint i = 1; i < 500; ++i)
      {
        if (pItems[i].uSkillType == requested_skill)
        {
          *v7++ = i;
          v52 += pItems[i].uChanceByTreasureLvl[v6];
        }
      }
    }

    v10 = 0;
    if ( v52 )
      v10 = rand() % v52;

    out_item->uItemID = *Dst;
    if (!out_item->uItemID)
      out_item->uItemID = 1;

    v11 = pItems[out_item->uItemID].uChanceByTreasureLvl[v6];
    if ( v11 < v10 )
    {
      v12 = (uint *)Dst;
      do
      {
        ++v12;
        v13 = *v12;
        out_item->uItemID = *v12;
        v11 += pItems[v13].uChanceByTreasureLvl[v6];
      }
      while ( v11 < v10 );
    }
	
    if (pItems[out_item->uItemID].uEquipType == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE )
    {// if it potion set potion spec
      out_item->uEncantmentType = 0;
     for (int i=0; i<2; ++i)
        out_item->uEncantmentType += rand() % 4 + 1;
      out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
    }
  }
  else
  {
    v16 = 0;
    v56 = 0;
    do
      v56 += pParty->pIsArtifactFound[v16++];
    while ( v16 < 29 );
    v17 = rand() % 29;

    if ( v6 == 5 && rand() % 100 < 5 && !pParty->pIsArtifactFound[v17] && v56 < 13 )
    {
      pParty->pIsArtifactFound[v17] = 1;
      out_item->uAttributes = 0;
      out_item->uItemID = v17 + 500;
      SetSpecialBonus(out_item);
      return;
    }

    v57 = 0;
    v18 = rand() % v5->uChanceByTreasureLvlSumm[v54];// v5->field_11684[v54];
    out_item->uItemID = 0;
    if ( v18 > 0 )
    {
      do
        v57 += pItems[out_item->uItemID++ + 1].uChanceByTreasureLvl[v6];
      while ( v57 < v18 );
    }

    if ( !v18 )
      out_item->uItemID = 1;
    if ( !out_item->uItemID )
      out_item->uItemID = 1;
	if (pItems[out_item->uItemID].uEquipType == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE )
		{// if it potion set potion spec
		out_item->uEncantmentType = 0;
		for (int i=0; i<2; ++i)
			out_item->uEncantmentType += rand() % 4 + 1;
		out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
		}
	out_item->uEncantmentType = out_item->uEncantmentType * treasure_level; 
  }
  if ( v4->uItemID == ITEM_SPELLBOOK_LIGHT_DIVINE_INTERVENTION
    && !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 239) )
    v4->uItemID = ITEM_SPELLBOOK_LIGHT_SUN_BURST;
  if ( pItemsTable->pItems[v4->uItemID + 1].uItemID_Rep_St )
    v4->uAttributes = 0;
  else
    v4->uAttributes = 1;
  if ( pItems[out_item->uItemID].uEquipType != EQUIP_POTION )
  {
    out_item->uSpecEnchantmentType = 0;
    out_item->uEncantmentType = 0;
  }
  v20 = pItems[out_item->uItemID].uEquipType;
  if ( v20 <= EQUIP_BOW )
  {
    v37 = v5->uBonusChanceWpSpecial[v54];
    if ( !v37 )
      return;
    v38 = rand() % 100;
    v36 = __OFSUB__(v38, v37);
    v35 = v38 - v37 < 0;
  }
  else
  {
    if ( v20 > EQUIP_AMULET )
    {
      if ( v20 == EQUIP_WAND )
      {
        v21 = rand() % 6 + pItemsTable->pItems[v4->uItemID].uDamageMod + 1;
        out_item->uNumCharges = v21;
        out_item->uMaxCharges = v21;
      }
      return;
    }
    v22 = uBonusChanceStandart[v6];
    if ( !v22 )
      return;
    v24 = v22;
    v25 = rand() % 100;
    if ( !uBonusChanceSpecial[v6] && !(v25 < v24))
        return;
    if ( v25 < v24 || v25 < v24)
    {
      v26 = rand() % v5->uBonusChanceWpSpecial[v5->pItems[v4->uItemID].uEquipType + 3];
      v27 = v4->uItemID;
      v4->uEncantmentType = 0;
      for ( i = pEnchantments[0].to_item[pItems[v27].uEquipType + 1];
            i < v26;
            i += pEnchantments[v4->uEncantmentType].to_item[pItems[v29].uEquipType + 1] )
      {
        v29 = v4->uItemID;
        ++v4->uEncantmentType;
      }
      ++v4->uEncantmentType;
      v30 = 10;// v5->field_116D8[2 * v54 + 12];
      v31 = rand();
      v32 = v4->uEncantmentType - 1;
      v33 = v31 % 10;//(v5->field_116D8[2 * v54 + 13] - v30 + 1) + v30;
      v4->_bonus_strength = v33;
      if ( v32 == 21 || v32 == 22 || v32 == 23 )
        v4->_bonus_strength = v33 >> 1;
      if ( v4->_bonus_strength <= 0 )
        v4->_bonus_strength = 1;
      return;
    }
    v34 = v24 + 10;//*(unsigned int *)&v5->field_1169C[4 * v54 + 24];
    v36 = __OFSUB__(v25, v34);
    v35 = v25 - v34 < 0;
  }
  if ( !(v35 ^ v36) )
    return;
  memset(&Dst, 0, 0xC80u);
  v39 = 0;
  a2b = 0;
  if ( pSpecialEnchantments_count > 0 )
  {
    v52 = -16 - (uint)this;
    v58 = (int *)&Dst;
    v40 = (int)&pSpecialEnchantments[1];
    do
    {
      switch ( v6 )
      {
        case 2:
          if ( !*(unsigned char *)v40 )
          {
            v39 += *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType);
            if ( *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType) )
            {
              v44 = v58;
              ++v58;
              *v44 = a2b;
            }
            ++a2b;
			v40 += 28;
			continue;
          }
          v41 = *(unsigned char *)v40 == 1;
          break;
        case 3:
          v43 = *(unsigned char *)v40;
          if ( !*(unsigned char *)v40 || v43 == 1 )
          {
            v39 += *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType);
            if ( *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType) )
            {
              v44 = v58;
              ++v58;
              *v44 = a2b;
            }
            ++a2b;
			v40 += 28;
			continue;
          }
          v41 = v43 == 2;
          break;
        case 4:
          v42 = *(unsigned char *)v40;
          if ( *(unsigned char *)v40 == 1 || v42 == 2 )
          {
            v39 += *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType);
            if ( *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType) )
            {
              v44 = v58;
              ++v58;
              *v44 = a2b;
            }
            ++a2b;
			v40 += 28;
			continue;
          }
          v41 = v42 == 3;
          break;
        default:
          if ( v6 != 5 )
		  {
            ++a2b;
			v40 += 28;
			continue;
		  }
          v41 = *(unsigned char *)v40 == 3;
          break;
      }
      if ( v41 )
      {
		v39 += *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType);
		if ( *((unsigned char *)&uAllItemsCount + v40 + v52 + pItems[v4->uItemID].uEquipType) )
		{
			v44 = v58;
			++v58;
			*v44 = a2b;
		}
	  }
LABEL_119:
      ++a2b;
      v40 += 28;
    }
    while ( a2b < pSpecialEnchantments_count );
  }
  v45 = rand();
  v4->uSpecEnchantmentType = *(uint *)Dst;
  v46 = v45 % v39 + 1;
  a2c = *((unsigned char *)&uAllItemsCount + 28 * (*(uint *)Dst + 1389) + pItems[v4->uItemID].uEquipType);
  if ( a2c < v46 )
  {
    for ( j = (int *)&Dst; ; j = (int *)v59 )
    {
      v48 = v4->uItemID;
      v49 = (int)(j + 1);
      v59 = v49;
      v50 = *(unsigned int *)v49;
      v4->uSpecEnchantmentType = v50;
      a2c += *((unsigned char *)&uAllItemsCount + 28 * (v50 + 1389) + pItems[v48].uEquipType);
      if ( a2c >= v46 )
        break;
    }
  }
  ++v4->uSpecEnchantmentType;
}

//----- (004505CC) --------------------------------------------------------
bool ItemGen::GenerateArtifact()
{
  signed int uNumArtifactsNotFound; // esi@1
  int artifacts_list[32]; 

  memset(artifacts_list, 0,sizeof(artifacts_list));
  uNumArtifactsNotFound = 0;

  for (int i=500;i<529;++i)
     if ( !pParty->pIsArtifactFound[i-500] )
        artifacts_list[uNumArtifactsNotFound++] = i;

  Reset();
  if ( uNumArtifactsNotFound )
  {
    uItemID = artifacts_list[rand() % uNumArtifactsNotFound];
    pItemsTable->SetSpecialBonus(this);
    return true;
  }
  else
    return false;

}
//----- (004B8E3D) --------------------------------------------------------
void GenerateStandartShopItems()
	{
	signed int item_count; 
	signed int shop_index; 
	int treasure_lvl; 
	int item_class; 
	int mdf;

	shop_index = (signed int)window_SpeakInHouse->ptr_1C;
	if ( uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType] )
		{
	    for (item_count=0; item_count<=uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType]; ++item_count )
		{
		   if (shop_index<=14) //weapon shop
			   {
			   treasure_lvl = shopWeap_variation_ord[shop_index].treasure_level;
			   item_class =shopWeap_variation_ord[shop_index].item_class[rand() % 4];
			   }
		   else if (shop_index<=28) //armor shop
			   {
			   mdf =0;
			   if (item_count > 3)
					 ++mdf;// rechek offsets
			    treasure_lvl = shopArmr_variation_ord[2*(shop_index-15)+mdf].treasure_level;
				item_class =shopArmr_variation_ord[2*(shop_index-15)+mdf].item_class[rand() % 4];
			   }
		   else if (shop_index<=41)  //magic shop
			   {
			   treasure_lvl = shopMagic_treasure_lvl[shop_index-28];
			   item_class = 22;  //misc
			   }
		   else if (shop_index<=53) //alchemist shop
			   {
			    if (item_count<6)
					{
					pParty->StandartItemsInShops[shop_index][item_count].Reset();
					pParty->StandartItemsInShops[shop_index][item_count].uItemID = 220;  //potion bottle
					continue;
					}
				else
					{
					treasure_lvl = shopAlch_treasure_lvl[shop_index-41];
					item_class = 45;  //reagent
					}
			   }
		   pItemsTable->GenerateItem(treasure_lvl, item_class, &pParty->StandartItemsInShops[shop_index][item_count]);
		   pParty->StandartItemsInShops[shop_index][item_count].SetIdentified();  //identified
		}
		}
	pParty->InTheShopFlags[shop_index] = 0;
	}

//----- (004B8F94) --------------------------------------------------------
void  GenerateSpecialShopItems()
	{
	signed int item_count; 
	signed int shop_index; 
	int treasure_lvl; 
	int item_class; 
	int mdf;

	shop_index = (signed int)window_SpeakInHouse->ptr_1C;
	if ( uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType] )
		{
		for (item_count=0; item_count<=uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType]; ++item_count )
			{
			if (shop_index<=14) //weapon shop
				{
				treasure_lvl = shopWeap_variation_spc[shop_index].treasure_level;
				item_class =  shopWeap_variation_spc[shop_index].item_class[rand() % 4];
				}
			else if (shop_index<=28) //armor shop
				{
				mdf =0;
				if (item_count > 3)
					++mdf;
				treasure_lvl = shopArmr_variation_spc[2*(shop_index-15)+mdf].treasure_level;
				item_class =shopArmr_variation_spc[2*(shop_index-15)+mdf].item_class[rand() % 4];
				}
			else if (shop_index<=41)  //magic shop
				{
				treasure_lvl = shopMagicSpc_treasure_lvl[shop_index-28];
				item_class = 22;  //misc
				}
			else if (shop_index<=53) //alchemist shop
				{
				if (item_count<6)
					{
					pParty->SpecialItemsInShops[shop_index][item_count].Reset();
					pParty->SpecialItemsInShops[shop_index][item_count].uItemID = rand() % 32 + 740;  //mscrool
					continue;
					}
				else
					{
					treasure_lvl = shopAlchSpc_treasure_lvl[shop_index-41];
					item_class = 44;  //potion
					}
				}
			pItemsTable->GenerateItem(treasure_lvl, item_class, &pParty->SpecialItemsInShops[shop_index][item_count]);
			pParty->SpecialItemsInShops[shop_index][item_count].SetIdentified();  //identified
			}
		}
	pParty->InTheShopFlags[shop_index] = 0;
	}


//----- (00450218) --------------------------------------------------------
void __cdecl sub_450218_prolly_generate_chests_loot()
	{
	unsigned int v0; // eax@1
	Chest *v1; // ebx@1
	MapInfo *v2; // esi@1
	ItemGen *v3; // ebx@2
	int v4; // ebp@4
	int v5; // edi@4
	int v6; // esi@4
	int v7; // eax@4
	signed int v8; // esi@4
	int v9; // edx@4
	int v10; // esi@8
	int v11; // ebp@25
	int v12; // esi@25
	signed int v13; // ebp@27
	ItemGen *v14; // edi@28
	signed int v15; // edx@32
	signed __int64 v16; // qtt@32
	int v17; // esi@34
	signed int v18; // [sp+10h] [bp-18h]@1
	int v19; // [sp+14h] [bp-14h]@4
	MapInfo *v20; // [sp+18h] [bp-10h]@1
	Chest *v21; // [sp+1Ch] [bp-Ch]@1
	int v22; // [sp+20h] [bp-8h]@26
	signed int v23; // [sp+24h] [bp-4h]@2

	v18 = rand() % 100;
	v0 = pMapStats->GetMapInfo(pCurrentMapName);
	v1 = pChests;
	v2 = &pMapStats->pInfos[v0];
	v21 = pChests;
	v20 = &pMapStats->pInfos[v0];
	do
		{
		v3 = v1->mm7__vector_pItems;
		v23 = 140;
		do
			{
			if ( (v3->uItemID & 0x80000000u) == 0 )
				goto LABEL_56;
			v4 = rand() % 5 + 1;
			v5 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 2];
			v6 = (unsigned __int8)byte_4E8168[abs((int)v3->uItemID)-1][2*v2->Treasure_prob+1];//[2 * (v2->Treasure_prob + 7 * abs((int)v3->uItemID)) + 3];
			v7 = rand();
			v8 = v6 - v5 + 1;
			v9 = v5 + v7 % v8;
			v19 = v5 + v7 % v8;
			if ( v9 < 7 )
				{
				if ( v18 < 20 )
					{
					v3->Reset();
					goto LABEL_25;
					}
				if ( v18 < 60 )
					{
					v10 = 0;
					v3->Reset();
					if ( v19 == 1 )
						{
						v10 = rand() % 51 + 50;
						}
					else
						{
						if ( v19 != 2 )
							{
							if ( v19 == 3 )
								{
								v10 = rand() % 301 + 200;
								}
							else
								{
								if ( v19 != 4 )
									{
									if ( v19 == 5 )
										{
										v10 = rand() % 1001 + 1000;
LABEL_15:
										v3->uItemID = 199;
										}
									else
										{
										if ( v19 == 6 )
											{
											v10 = rand() % 3001 + 2000;
											goto LABEL_15;
											}
										}
LABEL_23:
									v3->SetIdentified();
									v3->uSpecEnchantmentType = v10;
LABEL_25:
									v11 = v4 - 1;
									v12 = 0;
									if ( v11 > 0 )
										{
										v22 = v11;
										while ( 1 )
											{
											v13 = v12;
											if ( v12 >= 140 )
												goto LABEL_52;
											v14 = &v21->mm7__vector_pItems[v12];
											while ( v14->uItemID )
												{
												++v13;
												++v14;
												if ( v13 >= 140 )
													goto LABEL_52;
												}
											v16 = rand();
											v15 = v16 % 100;
											v18 = v16 % 100;
											if ( v15 < 20 )
												goto LABEL_52;
											if ( v15 >= 60 )
												{
												pItemsTable->GenerateItem(v19, 0, v14);
												goto LABEL_51;
												}
											v17 = 0;
											v14->Reset();
											if ( v19 == 1 )
												{
												v17 = rand() % 51 + 50;
												goto LABEL_48;
												}
											if ( v19 == 2 )
												{
												v17 = rand() % 101 + 100;
LABEL_48:
												v14->uItemID = 197;
												goto LABEL_49;
												}
											if ( v19 == 3 )
												{
												v17 = rand() % 301 + 200;
												goto LABEL_44;
												}
											if ( v19 == 4 )
												{
												v17 = rand() % 501 + 500;
LABEL_44:
												v14->uItemID = 198;
												goto LABEL_49;
												}
											if ( v19 == 5 )
												break;
											if ( v19 == 6 )
												{
												v17 = rand() % 3001 + 2000;
LABEL_41:
												v14->uItemID = 199;
												}
LABEL_49:
											v14->uSpecEnchantmentType = v17;
LABEL_51:
											v12 = v13 + 1;
LABEL_52:
											--v22;
											if ( !v22 )
												goto LABEL_55;
											}
										v17 = rand() % 1001 + 1000;
										goto LABEL_41;
										}
									goto LABEL_55;
									}
								v10 = rand() % 501 + 500;
								}
							v3->uItemID = 198;
							goto LABEL_23;
							}
						v10 = rand() % 101 + 100;
						}
					v3->uItemID = 197;
					goto LABEL_23;
					}
				pItemsTable->GenerateItem(v9, 0, v3);
				goto LABEL_25;
				}
			v3->GenerateArtifact();
LABEL_55:
			v2 = v20;
LABEL_56:
			++v3;
			--v23;
			}
			while ( v23 );
			v1 = v21 + 1;
			++v21;
		}
		while ( (signed int)v21 < (signed int)&uNumChests );
	}


	

// 4505CC: using guessed type int var_A0[32];
	//----- (004B3703) --------------------------------------------------------
void FillAviableSkillsToTeach( int _this )
	{
	char *v30; // ecx@65
	unsigned int v29; // edx@56
	int v15; // ecx@19
	int v33; // [sp-4h] [bp-2Ch]@23
	int v34; // [sp-4h] [bp-2Ch]@43
	int v21; // ecx@34
	int v35[5]; // [sp+Ch] [bp-1Ch]@8
	int v37=0; // [sp+24h] [bp-4h]@1*
	int i=0;

	dword_F8B1DC = 0;

	switch (_this)
		{
	case 1:  //shop weapon
		for (int i=0; i<2; ++i)
			{
			for (int j=0; j<4; ++j)
				{
				if ( i )
					v21 = shopWeap_variation_spc[(unsigned int)window_SpeakInHouse->ptr_1C].item_class[j];
				else
					v21 = shopWeap_variation_ord[(unsigned int)window_SpeakInHouse->ptr_1C].item_class[j];

				switch (v21)
					{
				case 23:  v34 = 37;	break;
				case 24:  v34 = 38;	break;
				case 25:  v34 = 39;	break;
				case 26:  v34 = 40;	break;
				case 27:  v34 = 41;	break;
				case 28:  v34 = 42; break;
				case 30:  v34 = 36;	break;
				default:
					continue;
					}	
				v37 = sub_4BE571(v34, v35, v37, 5);
				}
			}
		break;
	case 2: //shop armor

		for (int i=0; i<2; ++i)
			{
			for (int j=0; j<2; ++j)
				{
				for (int k=0; k<4; ++k)
					{
					if ( i )
						v15 = shopArmr_variation_spc[(unsigned int)window_SpeakInHouse->ptr_1C-15+j].item_class[k];
					else
						v15 = shopArmr_variation_ord[(unsigned int)window_SpeakInHouse->ptr_1C-15+j].item_class[k];
					switch (v15)
						{
					case 31: v33 = 45; break;
					case 32: v33 = 46; break;
					case 33: v33 = 47; break;
					case 34: v33 = 44; break;
					default:
						continue;
						}
					v37 = sub_4BE571(v33, v35, v37, 5);
					}
				}
			}
		break;
	case 3:  //shop magic
		v37 = 2;
		v35[0] = 57;
		v35[1] = 59;
		break;
	case 4: //shop alchemist
		v37 = 2;
		v35[0] = 71;
		v35[1] = 68;
		break;
	case 21:  //tavern
		v37 = 3;
		v35[0] = 70;
		v35[1] = 65;
		v35[2] = 62;
		break;
	case 23:  //temple
		v37 = 3;
		v35[0] = 67;
		v35[1] = 66;
		v35[2] = 58;
		break;
	case 30:  ///trainig
		v37 = 2;
		v35[0] = 69;
		v35[1] = 60;
		break;
		}
	for(i=0;i<v37;++i) 
		{
		v29=v35[i];
		switch(v29)
			{
		case 40 :v30 = pSkillNames[4];	break;
		case 5 : v30 = pSkillNames[23];	break;
		case 36 :v30 = pSkillNames[0];	break;
		case 37 :v30 = pSkillNames[1];	break;
		case 38 :v30 = pSkillNames[2];	break;
		case 39 :v30 = pSkillNames[3];	break;
		case 41 :v30 = pSkillNames[5];	break;
		case 42 :v30 = pSkillNames[6];	break;
		case 44 :v30 = pSkillNames[8];	break;
		case 45 :v30 = pSkillNames[9];	break;
		case 46 :v30 = pSkillNames[10];	break;
		case 47 :v30 = pSkillNames[11];	break;
		case 66 :v30 = pSkillNames[30];	break;
		case 57 :v30 = pSkillNames[21];	break;
		case 58 :v30 = pSkillNames[22];	break;
		case 60 :v30 = pSkillNames[24];	break;
		case 62 :v30 = pSkillNames[26];	break;
		case 65 :v30 = pSkillNames[29];	break;
		case 67:v30 = pSkillNames[31];	break;
		case 68:v30 = pSkillNames[32];	break;
		case 69:v30 = pSkillNames[33];	break;
		case 70:v30 = pSkillNames[34];	break;
		case 71:v30 = pSkillNames[35]; break;
		default:
			v30 = pGlobalTXT_LocalizationStrings[127]; //"No Text!"
			}
		pShopOptions[dword_F8B1DC] = v30;
		++dword_F8B1DC;
		CreateButtonInColumn(i+1, v29);
		}
	pDialogueWindow->_41D08F(i, 1, 0, 2);
	dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
	}

	//----- (004BE571) --------------------------------------------------------
int  sub_4BE571(int a1, int *a2, int a3, int a4)
	{
	int result; // eax@1
	int i; // esi@3

	result = a3;
	if ( a3 < a4 )
		{
		for ( i = 0; i < a3; ++i )
			{
			if ( a1 == a2[i] )
				break;
			}
		if ( i == a3 )
			{
			a2[a3] = a1;
			result = a3 + 1;
			}
		return result;
		}
	else
		{
		return  a4;
		}
	}