comparison Engine/Objects/Items.cpp @ 2497:82d5d92a097c

for MVS2012
author Ritor1
date Thu, 18 Sep 2014 23:59:29 +0600
parents
children 68cdef6879a0
comparison
equal deleted inserted replaced
2496:5abd8fc8f1c6 2497:82d5d92a097c
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6 #include <stdlib.h>
7 #include <string>
8 #include "UI\UIHouses.h"
9 #include "GUIButton.h"
10
11 #include "ErrorHandling.h"
12
13 #include "Items.h"
14 #include "MapInfo.h"
15 #include "GUIWindow.h"
16 #include "Chest.h"
17 #include "LOD.h"
18 #include "Monsters.h"
19 #include "Party.h"
20 #include "FactionTable.h"
21 #include "StorylineTextTable.h"
22 #include "texts.h"
23 #include "mm7_data.h"
24 #include "OurMath.h"
25
26
27
28 struct ITEM_VARIATION
29 {
30 unsigned __int16 treasure_level;
31 unsigned __int16 item_class[4];
32 };
33
34
35 std::array<const char, 5> uItemsAmountPerShopType={ 0, 6, 8, 12, 12};
36
37 const ITEM_VARIATION shopWeap_variation_ord[15] ={
38 { 0, { 0, 0, 0, 0 }},
39 { 1, { 23, 27, 20, 20 }},
40 { 1, { 23, 24, 28, 20 }},
41 { 2, { 23, 24, 25, 20 }},
42 { 2, { 27, 27, 26, 26 }},
43 { 4, { 24, 30, 25, 27 }},
44 { 4, { 24, 30, 25, 27 }},
45 { 3, { 30, 24, 20, 20 }},
46 { 2, { 20, 20, 20, 20 }},
47 { 3, { 27, 27, 26, 26 }},
48 { 3, { 28, 28, 25, 25 }},
49 { 2, { 23, 23, 24, 24 }},
50 { 3, { 23, 23, 26, 26 }},
51 { 2, { 30, 26, 26, 26 }},
52 { 2, { 28, 25, 28, 29 }}};
53
54 const ITEM_VARIATION shopArmr_variation_ord[28] ={
55 { 1, { 35, 35, 38, 38 }},
56 { 1, { 31, 31, 31, 34 }},
57 { 1, { 35, 35, 38, 38 }},
58 { 1, { 31, 31, 32, 34 }},
59 { 2, { 35, 35, 38, 38 }},
60 { 2, { 31, 32, 32, 33 }},
61 { 2, { 35, 35, 38, 38 }},
62 { 2, { 31, 31, 32, 32 }},
63 { 4, { 35, 35, 38, 38 }},
64 { 4, { 31, 32, 33, 34 }},
65 { 4, { 35, 35, 38, 38 }},
66 { 4, { 31, 32, 33, 34 }},
67 { 3, { 35, 35, 38, 38 }},
68 { 3, { 31, 31, 31, 31 }},
69 { 2, { 35, 35, 38, 38 }},
70 { 2, { 31, 32, 34, 34 }},
71 { 3, { 35, 35, 38, 38 }},
72 { 3, { 31, 31, 32, 32 }},
73 { 3, { 35, 35, 38, 38 }},
74 { 3, { 32, 32, 32, 33 }},
75 { 3, { 35, 35, 38, 38 }},
76 { 3, { 31, 31, 31, 32 }},
77 { 3, { 35, 35, 38, 38 }},
78 { 3, { 33, 31, 32, 34 }},
79 { 3, { 35, 35, 38, 38 }},
80 { 3, { 33, 31, 32, 34 }},
81 { 4, { 35, 35, 38, 38 }},
82 { 4, { 33, 31, 32, 34 }}};
83
84
85
86 const unsigned __int16 shopMagic_treasure_lvl[14]= {0, 1, 1, 2, 2, 4, 4, 3, 2, 2, 2, 2, 2, 2};
87 const unsigned __int16 shopAlch_treasure_lvl[13] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 2, 2, 2, 2};
88
89 const ITEM_VARIATION shopWeap_variation_spc[15]={
90 { 0, { 0, 0, 0, 0 }},
91 { 2, { 25, 30, 20, 20}},
92 { 2, { 23, 24, 28, 20}},
93 { 3, { 23, 24, 25, 20}},
94 { 3, { 27, 27, 26, 26}},
95 { 5, { 23, 26, 28, 27}},
96 { 5, { 23, 26, 28, 27}},
97 { 4, { 30, 24, 20, 20}},
98 { 3, { 20, 20, 20, 20}},
99 { 4, { 27, 27, 26, 26}},
100 { 4, { 28, 28, 25, 25}},
101 { 4, { 23, 23, 24, 24}},
102 { 4, { 24, 24, 27, 20}},
103 { 4, { 30, 26, 26, 26}},
104 { 4, { 28, 25, 28, 29}}};
105
106 const ITEM_VARIATION shopArmr_variation_spc[28]={
107 { 2, { 35, 35, 38, 38 }},
108 { 2, { 31, 31, 31, 34 }},
109 { 2, { 35, 35, 38, 38 }},
110 { 2, { 31, 31, 32, 34 }},
111 { 3, { 35, 35, 38, 38 }},
112 { 3, { 31, 32, 32, 33 }},
113 { 3, { 35, 35, 38, 38 }},
114 { 3, { 31, 31, 32, 32 }},
115 { 5, { 35, 35, 38, 38 }},
116 { 5, { 31, 32, 33, 34 }},
117 { 5, { 35, 35, 38, 38 }},
118 { 5, { 31, 32, 33, 34 }},
119 { 4, { 35, 35, 38, 38 }},
120 { 4, { 31, 31, 31, 31 }},
121 { 3, { 35, 35, 38, 38 }},
122 { 3, { 31, 32, 34, 34 }},
123 { 4, { 35, 35, 38, 38 }},
124 { 4, { 31, 31, 32, 33 }},
125 { 4, { 35, 35, 38, 38 }},
126 { 4, { 32, 32, 33, 34 }},
127 { 4, { 35, 35, 38, 38 }},
128 { 4, { 31, 31, 31, 32 }},
129 { 4, { 35, 35, 38, 38 }},
130 { 4, { 32, 32, 32, 32 }},
131 { 4, { 35, 35, 38, 38 }},
132 { 4, { 34, 34, 34, 34 }},
133 { 5, { 35, 35, 38, 38 }},
134 { 5, { 33, 33, 33, 33 }}
135 };
136
137 const unsigned __int16 shopMagicSpc_treasure_lvl[14] = {0, 2, 2, 3, 3, 5, 5, 4, 3, 3, 3, 3, 3, 3};
138 const unsigned __int16 shopAlchSpc_treasure_lvl[13] = {0, 2, 2, 3, 3, 4, 4, 5, 5, 3, 2, 2, 2};
139
140
141 std::array< std::array<char, 14>, 7> byte_4E8168={{ //byte_4E8178
142 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
143 { 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
144 { 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3},
145 { 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4},
146 { 2, 2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5},
147 { 2, 2, 2, 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6},
148 { 2, 2, 2, 2, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}}};
149
150 int sub_4BE571_AddItemToSet(int valueToAdd, int *outPutSet, int elemsAlreadyPresent, int elemsNeeded);
151 int dword_F8B1DC_currentShopOption; // weak
152
153 ItemGen *ptr_50C9A4_ItemToEnchant;
154
155 struct ItemsTable *pItemsTable; // 005D29E0
156
157
158
159
160
161 //----- (00439DF3) --------------------------------------------------------
162 int ItemGen::_439DF3_get_additional_damage(int *damage_type, bool *draintargetHP)
163 {
164 *draintargetHP = false;
165 *damage_type = 0;
166 if ( !uItemID )
167 return 0;
168 UpdateTempBonus(pParty->uTimePlayed);
169 if (uItemID == 501 ) //Iron Feather -sword
170 {
171 *damage_type = 1;
172 return rand() % 10 + 6;
173 }
174 if (uItemID == 507 ) //Ghoulsbane -axe
175 {
176 *damage_type = 0;
177 return rand() % 16 + 3;
178 }
179 if ( uItemID == 510 ) //Ullyses -bow
180 {
181 *damage_type = 2;
182 return rand() % 4 + 9;
183 }
184 if ( uItemID == 517 ) //Old Nick -dagger
185 {
186 *damage_type = 8;
187 return 8;
188 }
189
190 switch (uSpecEnchantmentType)
191 {
192 case 4: //Adds 3-4 points of Cold damage.
193 *damage_type = 2;
194 return rand() % 2 + 3;
195 break;
196 case 5: //Adds 6-8 points of Cold damage.
197 *damage_type = 2;
198 return rand() % 3 + 6;
199 break;
200 case 6: //Adds 9-12 points of Cold damage.
201 *damage_type = 2;
202 return rand() % 4 + 9;
203 break;
204 case 7: //Adds 2-5 points of Electrical damage.
205 *damage_type = 1;
206 return rand() % 4 + 2;
207 break;
208 case 8: //Adds 4-10 points of Electrical damage.
209 *damage_type = 1;
210 return rand() % 7 + 4;
211 break;
212 case 9: //Adds 6-15 points of Electrical damage.
213 *damage_type = 1;
214 return rand() % 10 + 6;
215 break;
216 case 10: //Adds 1-6 points of Fire damage.
217 *damage_type = 0;
218 return GetDiceResult(1, 6);
219 break;
220 case 11: //Adds 2-12 points of Fire damage.
221 *damage_type = 0;
222 return GetDiceResult(2, 6);
223 break;
224 case 12: //Adds 3-18 points of Fire damage.
225 *damage_type = 0;
226 return GetDiceResult(3, 6);
227 break;
228 case 13: //Adds 5 points of Body damage.
229 *damage_type = 8;
230 return 5;
231 break;
232 case 14: //Adds 8 points of Body damage.
233 *damage_type = 8;
234 return 8;
235 break;
236 case 15: //Adds 12 points of Body damage.
237 *damage_type = 8;
238 return 12;
239 break;
240 case 16: //Drain Hit Points from target.
241 case 41: //Drain Hit Points from target and Increased Weapon speed.
242 *damage_type = 10;
243 *draintargetHP = true;
244 return 0;
245 break;
246 case 46: //Adds 10-20 points of Fire damage and +25 Might.
247 *damage_type = 0;
248 return rand() % 11 + 10;
249 break;
250 default:
251 *damage_type = 0;
252 return 0;
253
254 }
255
256 }
257
258
259 //----- (00402F07) --------------------------------------------------------
260 void ItemGen::Reset()
261 {
262 this->uHolderPlayer = 0;
263 this->uAttributes = 0;
264 this->uNumCharges = 0;
265 this->uSpecEnchantmentType = 0;
266 this->m_enchantmentStrength = 0;
267 this->uEnchantmentType = 0;
268 this->uItemID = 0;
269 this->uBodyAnchor = 0;
270 this->uExpireTime = 0i64;
271 }
272
273 //----- (00458260) --------------------------------------------------------
274 void ItemGen::UpdateTempBonus(__int64 uTimePlayed)
275 {
276 if ( this->uAttributes & ITEM_TEMP_BONUS )
277 {
278 if ( uTimePlayed > (signed __int64)this->uExpireTime )
279 {
280 this->uEnchantmentType = 0;
281 this->uSpecEnchantmentType = 0;
282 this->uAttributes = this->uAttributes&(~ITEM_TEMP_BONUS);
283 }
284 }
285 }
286
287 //----- (0045814E) --------------------------------------------------------
288 void ItemsTable::Release()
289 {
290 free(pMonstersTXT_Raw);
291 free(pMonsterPlacementTXT_Raw);
292 free(pSkillDescTXT_Raw);
293 free(pSpcItemsTXT_Raw);
294 free(pStdItemsTXT_Raw);
295 free(pRndItemsTXT_Raw);
296 free(pItemsTXT_Raw);
297 free(pHostileTXT_Raw);
298 free(pHistoryTXT_Raw);
299 free(pPotionsTXT_Raw);
300 free(pPotionNotesTXT_Raw);
301 pMonstersTXT_Raw = nullptr;
302 pMonsterPlacementTXT_Raw = nullptr;
303 pSpcItemsTXT_Raw = nullptr;
304 pSkillDescTXT_Raw = nullptr;
305 pStdItemsTXT_Raw = nullptr;
306 pRndItemsTXT_Raw = nullptr;
307 pItemsTXT_Raw = nullptr;
308 pHostileTXT_Raw = nullptr;
309 pHistoryTXT_Raw = nullptr;
310 pPotionsTXT_Raw = nullptr;
311 pPotionNotesTXT_Raw = nullptr;
312 }
313
314
315 //----- (00456D84) --------------------------------------------------------
316 void ItemsTable::Initialize()
317 {
318 std::map<std::string, ITEM_EQUIP_TYPE, ci_less> equipStatMap;
319 equipStatMap["weapon"] = EQUIP_SINGLE_HANDED;
320 equipStatMap["weapon2"] = EQUIP_TWO_HANDED;
321 equipStatMap["weapon1or2"] = EQUIP_SINGLE_HANDED;
322 equipStatMap["missile"] = EQUIP_BOW;
323 equipStatMap["bow"] = EQUIP_BOW;
324 equipStatMap["armor"] = EQUIP_ARMOUR;
325 equipStatMap["shield"] = EQUIP_SHIELD;
326 equipStatMap["helm"] = EQUIP_HELMET;
327 equipStatMap["belt"] = EQUIP_BELT;
328 equipStatMap["cloak"] = EQUIP_CLOAK;
329 equipStatMap["gauntlets"] = EQUIP_GAUNTLETS;
330 equipStatMap["boots"] = EQUIP_BOOTS;
331 equipStatMap["ring"] = EQUIP_RING;
332 equipStatMap["amulet"] = EQUIP_AMULET;
333 equipStatMap["weaponw"] = EQUIP_WAND;
334 equipStatMap["herb"] = EQUIP_REAGENT;
335 equipStatMap["reagent"] = EQUIP_REAGENT;
336 equipStatMap["bottle"] = EQUIP_POTION;
337 equipStatMap["sscroll"] = EQUIP_SPELL_SCROLL;
338 equipStatMap["book"] = EQUIP_BOOK;
339 equipStatMap["mscroll"] = EQUIP_MESSAGE_SCROLL;
340 equipStatMap["gold"] = EQUIP_GOLD;
341 equipStatMap["gem"] = EQUIP_GEM;
342
343 std::map<std::string, PLAYER_SKILL_TYPE, ci_less> equipSkillMap;
344 equipSkillMap["staff"] = PLAYER_SKILL_STAFF;
345 equipSkillMap["sword"] = PLAYER_SKILL_SWORD;
346 equipSkillMap["dagger"] = PLAYER_SKILL_DAGGER;
347 equipSkillMap["axe"] = PLAYER_SKILL_AXE;
348 equipSkillMap["spear"] = PLAYER_SKILL_SPEAR;
349 equipSkillMap["bow"] = PLAYER_SKILL_BOW;
350 equipSkillMap["mace"] = PLAYER_SKILL_MACE;
351 equipSkillMap["blaster"] = PLAYER_SKILL_BLASTER;
352 equipSkillMap["shield"] = PLAYER_SKILL_SHIELD;
353 equipSkillMap["leather"] = PLAYER_SKILL_LEATHER;
354 equipSkillMap["chain"] = PLAYER_SKILL_CHAIN;
355 equipSkillMap["plate"] = PLAYER_SKILL_PLATE;
356 equipSkillMap["club"] = PLAYER_SKILL_CLUB;
357
358 std::map<std::string, ITEM_MATERIAL, ci_less> materialMap;
359 materialMap["artifact"] = MATERIAL_ARTEFACT;
360 materialMap["relic"] = MATERIAL_RELIC;
361 materialMap["special"] = MATERIAL_SPECIAL;
362
363 char* test_string;
364 int item_counter;
365
366 pMapStats = new MapStats;
367 pMapStats->Initialize();
368
369 pMonsterStats = new MonsterStats;
370 pMonsterStats->Initialize();
371 pMonsterStats->InitializePlacements();
372
373 pSpellStats = new SpellStats;
374 pSpellStats->Initialize();
375
376 LoadPotions();
377 LoadPotionNotes();
378
379 pFactionTable = new FactionTable;
380 pFactionTable->Initialize();
381
382 pStorylineText = new StorylineText;
383 pStorylineText->Initialize();
384
385 pStdItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stditems.txt", 0);
386 strtok(pStdItemsTXT_Raw, "\r");
387 strtok(NULL, "\r");
388 strtok(NULL, "\r");
389 strtok(NULL, "\r");
390 //Standard Bonuses by Group
391 for (int i=0;i<24;++i)
392 {
393 test_string = strtok(NULL, "\r") + 1;
394 auto tokens = Tokenize(test_string, '\t');
395 pEnchantments[i].pBonusStat=RemoveQuotes(tokens[0]);
396 pEnchantments[i].pOfName=RemoveQuotes(tokens[1]);
397 for (int j = 0; j < 9; j++)
398 {
399 pEnchantments[i].to_item[j]=atoi(tokens[j+2]);
400 }
401 }
402
403 memset(&pEnchantmentsSumm, 0, 36);
404 for(int i=0;i<9;++i)
405 {
406 for (int j=0;j<24;++j)
407 pEnchantmentsSumm[i]+=pEnchantments[j].to_item[i];
408 }
409
410 //Bonus range for Standard by Level
411 strtok(NULL, "\r");
412 strtok(NULL, "\r");
413 strtok(NULL, "\r");
414 strtok(NULL, "\r");
415 strtok(NULL, "\r");
416 for(int i=0;i<6;++i) //counted from 1
417 {
418 test_string = strtok(NULL, "\r") + 1;
419 auto tokens = Tokenize(test_string, '\t');
420 Assert(tokens.size() == 4, "Invalid number of tokens");
421 bonus_ranges[i].minR = atoi(tokens[2]);
422 bonus_ranges[i].maxR =atoi(tokens[3]);
423 }
424
425
426 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0);
427 strtok(pSpcItemsTXT_Raw, "\r");
428 strtok(NULL, "\r");
429 strtok(NULL, "\r");
430 strtok(NULL, "\r");
431 for (int i=0;i<72;++i)
432 {
433 test_string = strtok(NULL, "\r") + 1;
434 auto tokens = Tokenize(test_string, '\t');
435 Assert(tokens.size() >= 17, "Invalid number of tokens");
436 pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]);
437 pSpecialEnchantments[i].pNameAdd= RemoveQuotes(tokens[1]);
438 for (int j = 0; j < 12; j++)
439 {
440 pSpecialEnchantments[i].to_item_apply[j]=atoi(tokens[j+2]);
441 }
442 int res;
443 res=atoi(tokens[14]);
444 if(!res)
445 {
446 ++tokens[14];
447 while (*tokens[14]==' ')//fix X 2 case
448 ++tokens[14];
449 res=atoi(tokens[14]);
450 }
451 pSpecialEnchantments[i].iValue=res;
452 pSpecialEnchantments[i].iTreasureLevel= tolower(tokens[15][0]) - 97;
453 }
454
455 pSpecialEnchantments_count = 71;
456 memset(&pSpecialEnchantmentsSumm, 0, 96);
457 for(int i=0;i<12;++i)
458 {
459 for (unsigned int j=0;j<=pSpecialEnchantments_count;++j)
460 pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i];
461 }
462
463 InitializeBuildingResidents();
464
465 pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0);
466 strtok(pItemsTXT_Raw, "\r");
467 strtok(NULL, "\r");
468 uAllItemsCount = 0;
469 item_counter = 0;
470 while (item_counter < 800)
471 {
472 test_string = strtok(NULL, "\r") + 1;
473 auto tokens = Tokenize(test_string, '\t');
474 item_counter=atoi(tokens[0]);
475 uAllItemsCount=item_counter;
476 pItems[item_counter].pIconName = RemoveQuotes(tokens[1]);
477 pItems[item_counter].pName = RemoveQuotes(tokens[2]);
478 pItems[item_counter].uValue=atoi(tokens[3]);
479 auto findResult = equipStatMap.find(tokens[4]);
480 pItems[item_counter].uEquipType = findResult == equipStatMap.end() ? EQUIP_NONE : findResult->second;
481 auto findResult2 = equipSkillMap.find(tokens[5]);
482 pItems[item_counter].uSkillType = findResult2 == equipSkillMap.end() ? PLAYER_SKILL_MISC : findResult2->second;
483 auto tokens2 = Tokenize(tokens[6], 'd');
484 if (tokens2.size() == 2)
485 {
486 pItems[item_counter].uDamageDice=atoi(tokens2[0]);
487 pItems[item_counter].uDamageRoll=atoi(tokens2[1]);
488 }
489 else if (tolower(tokens2[0][0]) != 's')
490 {
491 pItems[item_counter].uDamageDice=atoi(tokens2[0]);
492 pItems[item_counter].uDamageRoll=1;
493 }
494 else
495 {
496 pItems[item_counter].uDamageDice=0;
497 pItems[item_counter].uDamageRoll=0;
498 }
499 pItems[item_counter].uDamageMod=atoi(tokens[7]);
500 auto findResult3 = materialMap.find(tokens[8]);
501 pItems[item_counter].uMaterial = findResult3 == materialMap.end() ? MATERIAL_COMMON : findResult3->second;
502 pItems[item_counter].uItemID_Rep_St=atoi(tokens[9]);
503 pItems[item_counter].pUnidentifiedName = RemoveQuotes(tokens[10]);
504 pItems[item_counter].uSpriteID=atoi(tokens[11]);
505
506 pItems[item_counter]._additional_value=0;
507 pItems[item_counter]._bonus_type=0;
508 if (pItems[item_counter].uMaterial==MATERIAL_SPECIAL)
509 {
510 for(int ii=0; ii<24; ++ii)
511 {
512 if (!_stricmp(tokens[12],pEnchantments[ii].pOfName))
513 {
514 pItems[item_counter]._bonus_type=ii+1;
515 break;
516 }
517 }
518 if (!pItems[item_counter]._bonus_type)
519 {
520 for(int ii=0; ii<72; ++ii)
521 {
522 if (!_stricmp(tokens[12],pSpecialEnchantments[ii].pNameAdd))
523 {
524 pItems[item_counter]._additional_value=ii+1;
525 }
526 }
527 }
528 }
529
530 if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type))
531 {
532 char b_s=atoi(tokens[13]);
533 if (b_s)
534 pItems[item_counter]._bonus_strength=b_s;
535 else
536 pItems[item_counter]._bonus_strength=1;
537 }
538 else
539 pItems[item_counter]._bonus_strength=0;
540 pItems[item_counter].uEquipX=atoi(tokens[14]);
541 pItems[item_counter].uEquipY=atoi(tokens[15]);
542 pItems[item_counter].pDescription = RemoveQuotes(tokens[16]);
543 item_counter++;
544 }
545
546 uAllItemsCount = item_counter;
547 pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0);
548 strtok(pRndItemsTXT_Raw, "\r");
549 strtok(NULL, "\r");
550 strtok(NULL, "\r");
551 strtok(NULL, "\r");
552 for (item_counter = 0; item_counter < 619; item_counter++)
553 {
554 test_string = strtok(NULL, "\r") + 1;
555 auto tokens = Tokenize(test_string, '\t');
556 Assert(tokens.size() > 7, "Invalid number of tokens");
557 item_counter = atoi(tokens[0]);
558 pItems[item_counter].uChanceByTreasureLvl1=atoi(tokens[2]);
559 pItems[item_counter].uChanceByTreasureLvl2=atoi(tokens[3]);
560 pItems[item_counter].uChanceByTreasureLvl3=atoi(tokens[4]);
561 pItems[item_counter].uChanceByTreasureLvl4=atoi(tokens[5]);
562 pItems[item_counter].uChanceByTreasureLvl5=atoi(tokens[6]);
563 pItems[item_counter].uChanceByTreasureLvl6=atoi(tokens[7]);
564 }
565
566 //ChanceByTreasureLvl Summ - to calculate chance
567 memset(&uChanceByTreasureLvlSumm, 0, 24);
568 for(int i=0;i<6;++i)
569 {
570 for (int j=1;j<item_counter;++j)
571 uChanceByTreasureLvlSumm[i]+=pItems[j].uChanceByTreasureLvl[i];
572 }
573
574 strtok(NULL, "\r");
575 strtok(NULL, "\r");
576 strtok(NULL, "\r");
577 strtok(NULL, "\r");
578 strtok(NULL, "\r");
579 for (int i=0;i<3;++i)
580 {
581 test_string = strtok(NULL, "\r") + 1;
582 auto tokens = Tokenize(test_string, '\t');
583 Assert(tokens.size() > 7, "Invalid number of tokens");
584 switch (i)
585 {
586 case 0:
587 uBonusChanceStandart[0]=atoi(tokens[2]);
588 uBonusChanceStandart[1]=atoi(tokens[3]);
589 uBonusChanceStandart[2]=atoi(tokens[4]);
590 uBonusChanceStandart[3]=atoi(tokens[5]);
591 uBonusChanceStandart[4]=atoi(tokens[6]);
592 uBonusChanceStandart[5]=atoi(tokens[7]);
593 break;
594 case 1:
595 uBonusChanceSpecial[0]=atoi(tokens[2]);
596 uBonusChanceSpecial[1]=atoi(tokens[3]);
597 uBonusChanceSpecial[2]=atoi(tokens[4]);
598 uBonusChanceSpecial[3]=atoi(tokens[5]);
599 uBonusChanceSpecial[4]=atoi(tokens[6]);
600 uBonusChanceSpecial[5]=atoi(tokens[7]);
601 break;
602 case 2:
603 uBonusChanceWpSpecial[0]=atoi(tokens[2]);
604 uBonusChanceWpSpecial[1]=atoi(tokens[3]);
605 uBonusChanceWpSpecial[2]=atoi(tokens[4]);
606 uBonusChanceWpSpecial[3]=atoi(tokens[5]);
607 uBonusChanceWpSpecial[4]=atoi(tokens[6]);
608 uBonusChanceWpSpecial[5]=atoi(tokens[7]);
609 break;
610 }
611 }
612 free(pRndItemsTXT_Raw);
613 pRndItemsTXT_Raw = nullptr;
614
615 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0);
616 strtok(pSkillDescTXT_Raw, "\r");
617 for (int i=0; i<37; ++i)
618 {
619 test_string = strtok(NULL, "\r") + 1;
620 auto tokens = Tokenize(test_string, '\t');
621 Assert(tokens.size() >= 6, "Invalid number of tokens");
622 pSkillDesc[i] = RemoveQuotes(tokens[1]);
623 pNormalSkillDesc[i] = RemoveQuotes(tokens[2]);
624 pExpertSkillDesc[i] = RemoveQuotes(tokens[3]);
625 pMasterSkillDesc[i] = RemoveQuotes(tokens[4]);
626 pGrandSkillDesc[i] = RemoveQuotes(tokens[5]);
627 }
628
629 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0);
630 strtok(pStatsTXT_Raw, "\r");
631 for (int i=0; i<26; ++i)
632 {
633 test_string = strtok(NULL, "\r") + 1;
634 auto tokens = Tokenize(test_string, '\t');
635 Assert(tokens.size() == 2, "Invalid number of tokens");
636 switch (i)
637 {
638 case 0:
639 case 1:
640 case 2:
641 case 3:
642 case 4:
643 case 5:
644 case 6:
645 pAttributeDescriptions[i] = RemoveQuotes(tokens[1]);
646 break;
647 case 7:
648 pHealthPointsAttributeDescription = RemoveQuotes(tokens[1]);
649 break;
650 case 8:
651 pArmourClassAttributeDescription = RemoveQuotes(tokens[1]);
652 break;
653 case 9:
654 pSpellPointsAttributeDescription = RemoveQuotes(tokens[1]);
655 break;
656 case 10:
657 pPlayerConditionAttributeDescription = RemoveQuotes(tokens[1]);
658 break;
659 case 11:
660 pFastSpellAttributeDescription = RemoveQuotes(tokens[1]);
661 break;
662 case 12:
663 pPlayerAgeAttributeDescription = RemoveQuotes(tokens[1]);
664 break;
665 case 13:
666 pPlayerLevelAttributeDescription = RemoveQuotes(tokens[1]);
667 break;
668 case 14:
669 pPlayerExperienceAttributeDescription = RemoveQuotes(tokens[1]);
670 break;
671 case 15:
672 pAttackBonusAttributeDescription = RemoveQuotes(tokens[1]);
673 break;
674 case 16:
675 pAttackDamageAttributeDescription = RemoveQuotes(tokens[1]);
676 break;
677 case 17:
678 pMissleBonusAttributeDescription = RemoveQuotes(tokens[1]);
679 break;
680 case 18:
681 pMissleDamageAttributeDescription = RemoveQuotes(tokens[1]);
682 break;
683 case 19:
684 pFireResistanceAttributeDescription = RemoveQuotes(tokens[1]);
685 break;
686 case 20:
687 pAirResistanceAttributeDescription = RemoveQuotes(tokens[1]);
688 break;
689 case 21:
690 pWaterResistanceAttributeDescription = RemoveQuotes(tokens[1]);
691 break;
692 case 22:
693 pEarthResistanceAttributeDescription = RemoveQuotes(tokens[1]);
694 break;
695 case 23:
696 pMindResistanceAttributeDescription = RemoveQuotes(tokens[1]);
697 break;
698 case 24:
699 pBodyResistanceAttributeDescription = RemoveQuotes(tokens[1]);
700 break;
701 case 25:
702 pSkillPointsAttributeDescription = RemoveQuotes(tokens[1]);
703 break;
704 }
705 }
706
707 pClassTXT_Raw = 0;
708 pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0);
709 strtok(pClassTXT_Raw, "\r");
710 for (int i=0; i<36; ++i)
711 {
712 test_string = strtok(NULL, "\r") + 1;
713 auto tokens = Tokenize(test_string, '\t');
714 Assert(tokens.size() == 3, "Invalid number of tokens");
715 pClassDescriptions[i]=RemoveQuotes(tokens[1]);
716 }
717
718
719
720 ItemGen::PopulateSpecialBonusMap();
721 ItemGen::PopulateArtifactBonusMap();
722 ItemGen::PopulateRegularBonusMap();
723
724
725 }
726
727 //----- (00456D17) --------------------------------------------------------
728 void ItemsTable::SetSpecialBonus(ItemGen *pItem)
729 {
730 if ( pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL )
731 {
732 pItem->uEnchantmentType = pItems[pItem->uItemID]._bonus_type;
733 pItem->uSpecEnchantmentType = pItems[pItem->uItemID]._additional_value;
734 pItem->m_enchantmentStrength = pItems[pItem->uItemID]._bonus_strength;
735 }
736 }
737
738 //----- (00456D43) --------------------------------------------------------
739 bool ItemsTable::IsMaterialSpecial(ItemGen *pItem)
740 {
741 return this->pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL;
742 }
743
744 //----- (00456D5E) --------------------------------------------------------
745 bool ItemsTable::IsMaterialNonCommon(ItemGen *pItem)
746 {
747 return pItems[pItem->uItemID].uMaterial == MATERIAL_SPECIAL ||
748 pItems[pItem->uItemID].uMaterial == MATERIAL_RELIC ||
749 pItems[pItem->uItemID].uMaterial == MATERIAL_ARTEFACT;
750 }
751
752
753 //----- (00453B3C) --------------------------------------------------------
754 void ItemsTable::LoadPotions()
755 {
756
757 CHAR Text[90];
758 char* test_string;
759 unsigned int uRow;
760 unsigned int uColumn;
761 unsigned __int8 potion_value;
762
763 free(pPotionNotesTXT_Raw);
764 auto tokens = Tokenize("", '\t');
765 char* pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0);
766 test_string = strtok(pPotionsTXT_Raw ,"\r") + 1;
767 while (test_string)
768 {
769 tokens = Tokenize(test_string, '\t');
770 if (!strcmp(tokens[0], "222"))
771 break;
772 test_string = strtok(NULL ,"\r") + 1;
773 }
774 if (!test_string)
775 {
776 MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
777 return;
778 }
779
780 for (uRow = 0;uRow < 50; ++uRow)
781 {
782 if (tokens.size() < 50)
783 {
784 wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, tokens.size());
785 MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
786 return;
787 }
788 for (uColumn = 0; uColumn < 50; ++uColumn)
789 {
790 char* currValue = tokens[uColumn + 7];
791 potion_value = atoi(currValue);
792 if ( !potion_value && tolower(currValue[0]) == 'e')
793 {
794 potion_value = atoi(currValue + 1);
795 }
796 this->potion_data[uRow][uColumn]=potion_value;
797 }
798
799 test_string = strtok(NULL ,"\r") + 1;
800 if (!test_string)
801 {
802 wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, 0);
803 MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
804 return;
805 }
806 tokens = Tokenize(test_string, '\t');
807 }
808 }
809
810 //----- (00453CE5) --------------------------------------------------------
811 void ItemsTable::LoadPotionNotes()
812 {
813
814 CHAR Text[90];
815 char* test_string;
816 unsigned int uRow;
817 unsigned int uColumn;
818 unsigned __int8 potion_note;
819
820 free(pPotionNotesTXT_Raw);
821 auto tokens = Tokenize("", '\t');
822 char* pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0);
823 test_string = strtok(pPotionNotesTXT_Raw ,"\r") + 1;
824 while (test_string)
825 {
826 tokens = Tokenize(test_string, '\t');
827 if (!strcmp(tokens[0], "222"))
828 break;
829 test_string = strtok(NULL ,"\r") + 1;
830 }
831 if (!test_string)
832 {
833 MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
834 return;
835 }
836
837 for (uRow = 0;uRow < 50; ++uRow)
838 {
839 if (tokens.size() < 50)
840 {
841 wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, tokens.size());
842 MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
843 return;
844 }
845 for (uColumn = 0; uColumn < 50; ++uColumn)
846 {
847 char* currValue = tokens[uColumn + 7];
848 potion_note = atoi(currValue);
849 if ( !potion_note && tolower(currValue[0]) == 'e')
850 {
851 potion_note = atoi(currValue + 1);
852 }
853 this->potion_note[uRow][uColumn]=potion_note;
854 }
855
856 test_string = strtok(NULL ,"\r") + 1;
857 if (!test_string)
858 {
859 wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, 0);
860 MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE);
861 return;
862 }
863 tokens = Tokenize(test_string, '\t');
864 }
865
866
867 }
868
869
870 //----- (00456442) --------------------------------------------------------
871 unsigned int ItemGen::GetValue()
872 {
873 unsigned int uBaseValue; // edi@1
874 unsigned int bonus;
875
876 uBaseValue = pItemsTable->pItems[this->uItemID].uValue;
877 if ( this->uAttributes & ITEM_TEMP_BONUS || pItemsTable->IsMaterialNonCommon(this) )
878 return uBaseValue;
879 if (uEnchantmentType )
880 return uBaseValue + 100 * m_enchantmentStrength;;
881 if (uSpecEnchantmentType )
882 {
883 bonus = pItemsTable->pSpecialEnchantments[uSpecEnchantmentType].iTreasureLevel;
884 if ( bonus > 10 )
885 return uBaseValue + bonus;
886 else
887 return uBaseValue * bonus;
888 }
889 return uBaseValue;
890 }
891
892 //----- (00456499) --------------------------------------------------------
893 const char *ItemGen::GetDisplayName()
894 {
895 if (IsIdentified())
896 return GetIdentifiedName();
897 else
898 return pItemsTable->pItems[uItemID].pUnidentifiedName;
899 }
900
901 //----- (004564B3) --------------------------------------------------------
902 const char *ItemGen::GetIdentifiedName()
903 {
904 unsigned __int8 equip_type;
905 const char *player_name;
906 const char *nameModificator;
907 const char *format_str;
908
909 equip_type = GetItemEquipType();
910 if ( (equip_type == EQUIP_REAGENT) || (equip_type == EQUIP_POTION) || (equip_type == EQUIP_GOLD) )
911 {
912 sprintf(item__getname_buffer.data(), "%s", pItemsTable->pItems[uItemID].pName);
913 return item__getname_buffer.data();
914 }
915 sprintf(item__getname_buffer.data(), "%s", pItemsTable->pItems[uItemID].pName);
916 if ( uItemID == ITEM_LICH_JAR_FULL ) //Lich Jar
917 {
918 if ( (uHolderPlayer >0 )&& (uHolderPlayer <= 4) )
919 {
920 player_name = pPlayers[uHolderPlayer]->pName;
921 if ( player_name[strlen(player_name) - 1] == 's' )
922 format_str = pGlobalTXT_LocalizationStrings[655]; //"%s' Jar"
923 else
924 format_str = pGlobalTXT_LocalizationStrings[654]; //"%s's Jar"
925 sprintf(item__getname_buffer.data(), format_str, pPlayers[uHolderPlayer]->pName);
926 return item__getname_buffer.data();
927 }
928 }
929 if ( !pItemsTable->IsMaterialNonCommon(this) )
930 {
931 if ( uEnchantmentType )
932 {
933 strcat(item__getname_buffer.data(), " ");
934 nameModificator = pItemsTable->pEnchantments[uEnchantmentType-1].pOfName;
935 }
936 else
937 {
938 if ( !uSpecEnchantmentType )
939 return item__getname_buffer.data();
940 if ( uSpecEnchantmentType == 16 //Drain Hit Points from target.
941 || uSpecEnchantmentType == 39 //Double damage vs Demons.
942 || uSpecEnchantmentType == 40 //Double damage vs Dragons
943 || uSpecEnchantmentType == 45 //+5 Speed and Accuracy
944 || uSpecEnchantmentType == 56 //+5 Might and Endurance.
945 || uSpecEnchantmentType == 57 //+5 Intellect and Personality.
946 || uSpecEnchantmentType == 58 //Increased Value.
947 || uSpecEnchantmentType == 60 //+3 Unarmed and Dodging skills
948 || uSpecEnchantmentType == 61 //+3 Stealing and Disarm skills.
949 || uSpecEnchantmentType == 59 //Increased Weapon speed.
950 || uSpecEnchantmentType == 63 //Double Damage vs. Elves.
951 || uSpecEnchantmentType == 64 //Double Damage vs. Undead.
952 || uSpecEnchantmentType == 67 //Adds 5 points of Body damage and +2 Disarm skill.
953 || uSpecEnchantmentType == 68 ) //Adds 6-8 points of Cold damage and +5 Armor Class.
954 { //enchantment and name positions inverted!
955 sprintf( item__getname_buffer.data(), "%s %s",
956 pItemsTable->pSpecialEnchantments[uSpecEnchantmentType-1].pNameAdd,
957 pItemsTable->pItems[uItemID].pName);
958 return item__getname_buffer.data();
959 }
960 strcat(item__getname_buffer.data(), " ");
961 nameModificator = pItemsTable->pSpecialEnchantments[uSpecEnchantmentType-1].pNameAdd;
962 }
963 strcat(item__getname_buffer.data(), nameModificator);
964 }
965 return item__getname_buffer.data();
966 }
967
968
969 //----- (00456620) --------------------------------------------------------
970 void ItemsTable::GenerateItem(int treasure_level, unsigned int uTreasureType, ItemGen *out_item)
971 {
972 int treasureLevelMinus1; // ebx@3
973 int current_chance; // ebx@43
974 int tmp_chance; // ecx@47
975 int v17; // ebx@57
976 int v18; // edx@62
977 unsigned int special_chance; // edx@86
978 unsigned int v26; // edx@89
979 unsigned int v27; // eax@89
980 int v32; // ecx@91
981 int v33; // eax@91
982 // unsigned int v34; // eax@97
983 int v45; // eax@120
984 int v46; // edx@120
985 int j; // eax@121
986 int val_list[800]; // [sp+Ch] [bp-C88h]@33
987 int total_chance; // [sp+C8Ch] [bp-8h]@33
988 signed int v56; // [sp+CA0h] [bp+Ch]@55
989 int v57; // [sp+CA0h] [bp+Ch]@62
990
991 if (!out_item)
992 out_item = (ItemGen *)malloc(sizeof(ItemGen));
993 memset(out_item, 0, sizeof(*out_item));
994
995
996 treasureLevelMinus1 = treasure_level - 1;
997 if ( uTreasureType ) //generate known treasure type
998 {
999 ITEM_EQUIP_TYPE requested_equip;
1000 PLAYER_SKILL_TYPE requested_skill = PLAYER_SKILL_INVALID;
1001 switch (uTreasureType)
1002 {
1003 case 20: requested_equip = EQUIP_SINGLE_HANDED; break;
1004 case 21: requested_equip = EQUIP_ARMOUR; break;
1005 case 22: requested_skill = PLAYER_SKILL_MISC; break;
1006 case 23: requested_skill = PLAYER_SKILL_SWORD; break;
1007 case 24: requested_skill = PLAYER_SKILL_DAGGER; break;
1008 case 25: requested_skill = PLAYER_SKILL_AXE; break;
1009 case 26: requested_skill = PLAYER_SKILL_SPEAR; break;
1010 case 27: requested_skill = PLAYER_SKILL_BOW; break;
1011 case 28: requested_skill = PLAYER_SKILL_MACE; break;
1012 case 29: requested_skill = PLAYER_SKILL_CLUB; break;
1013 case 30: requested_skill = PLAYER_SKILL_STAFF; break;
1014 case 31: requested_skill = PLAYER_SKILL_LEATHER; break;
1015 case 32: requested_skill = PLAYER_SKILL_CHAIN; break;
1016 case 33: requested_skill = PLAYER_SKILL_PLATE; break;
1017 case 34: requested_equip = EQUIP_SHIELD; break;
1018 case 35: requested_equip = EQUIP_HELMET; break;
1019 case 36: requested_equip = EQUIP_BELT; break;
1020 case 37: requested_equip = EQUIP_CLOAK; break;
1021 case 38: requested_equip = EQUIP_GAUNTLETS; break;
1022 case 39: requested_equip = EQUIP_BOOTS; break;
1023 case 40: requested_equip = EQUIP_RING; break;
1024 case 41: requested_equip = EQUIP_AMULET; break;
1025 case 42: requested_equip = EQUIP_WAND; break;
1026 case 43: requested_equip = EQUIP_SPELL_SCROLL; break;
1027 case 44: requested_equip = EQUIP_POTION; break;
1028 case 45: requested_equip = EQUIP_REAGENT; break;
1029 case 46: requested_equip = EQUIP_GEM; break;
1030 default:
1031 __debugbreak(); // check this condition
1032 requested_equip = (ITEM_EQUIP_TYPE)(uTreasureType - 1);
1033 break;
1034 }
1035 memset(val_list, 0, sizeof(val_list));
1036 total_chance = 0;
1037 j=0;
1038 //a2a = 1;
1039 if (requested_skill == PLAYER_SKILL_INVALID) // no skill for this item needed
1040 {
1041 for (uint i = 1; i < 500; ++i)
1042 {
1043 if (pItems[i].uEquipType == requested_equip)
1044 {
1045 val_list[j] = i;
1046 ++j;
1047 total_chance += pItems[i].uChanceByTreasureLvl[treasure_level - 1];
1048 }
1049 }
1050 }
1051 else //have needed skill
1052 {
1053 for (uint i = 1; i < 500; ++i)
1054 {
1055 if (pItems[i].uSkillType == requested_skill)
1056 {
1057 val_list[j] = i;
1058 ++j;
1059 total_chance += pItems[i].uChanceByTreasureLvl[treasure_level - 1];
1060 }
1061 }
1062 }
1063
1064 current_chance = 0;
1065 if ( total_chance )
1066 {
1067 current_chance = rand() % total_chance + 1;
1068 tmp_chance = 0;
1069 j=0;
1070 while(tmp_chance < current_chance)
1071 {
1072 out_item->uItemID = val_list[j];
1073 tmp_chance += pItems[val_list[j]].uChanceByTreasureLvl[treasure_level - 1];
1074 ++j;
1075 }
1076 }
1077 else
1078 {
1079 out_item->uItemID = 1;
1080 }
1081 }
1082 else
1083 {
1084 //artifact
1085 if ( treasureLevelMinus1 == 5 )
1086 {
1087 v56 = 0;
1088 for(int i=0; i<29; ++i)
1089 v56 += pParty->pIsArtifactFound[i];
1090 v17 = rand() % 29;
1091 if ((rand() % 100 < 5) && !pParty->pIsArtifactFound[v17] && v56 < 13)
1092 {
1093 pParty->pIsArtifactFound[v17] = 1;
1094 out_item->uAttributes = 0;
1095 out_item->uItemID = v17 + 500;
1096 SetSpecialBonus(out_item);
1097 return;
1098 }
1099 }
1100
1101 v57 = 0;
1102 v18 = rand() % this->uChanceByTreasureLvlSumm[treasure_level - 1] + 1;
1103 while (v57 < v18)
1104 {
1105 ++out_item->uItemID;
1106 v57 += pItems[out_item->uItemID].uChanceByTreasureLvl[treasureLevelMinus1];
1107 }
1108 }
1109 if (out_item->GetItemEquipType() == EQUIP_POTION && out_item->uItemID != ITEM_POTION_BOTTLE )
1110 {// if it potion set potion spec
1111 out_item->uEnchantmentType = 0;
1112 for (int i=0; i<2; ++i)
1113 out_item->uEnchantmentType += rand() % 4 + 1;
1114 out_item->uEnchantmentType = out_item->uEnchantmentType * treasure_level;
1115 }
1116
1117 if ( out_item->uItemID == ITEM_SPELLBOOK_LIGHT_DIVINE_INTERVENTION
1118 && !(unsigned __int16)_449B57_test_bit(pParty->_quest_bits, 239) )
1119 out_item->uItemID = ITEM_SPELLBOOK_LIGHT_SUN_BURST;
1120 if ( pItemsTable->pItems[out_item->uItemID].uItemID_Rep_St )
1121 out_item->uAttributes = 0;
1122 else
1123 out_item->uAttributes = 1;
1124
1125 if ( out_item->GetItemEquipType() != EQUIP_POTION )
1126 {
1127 out_item->uSpecEnchantmentType = 0;
1128 out_item->uEnchantmentType = 0;
1129 }
1130 //try get special enhansment
1131 switch (out_item->GetItemEquipType())
1132 {
1133 case EQUIP_SINGLE_HANDED:
1134 case EQUIP_TWO_HANDED :
1135 case EQUIP_BOW :
1136 if ( !uBonusChanceWpSpecial[treasureLevelMinus1] )
1137 return;
1138 if ((uint)(rand() % 100)>=uBonusChanceWpSpecial[treasureLevelMinus1])
1139 return;
1140 break;
1141 case EQUIP_ARMOUR :
1142 case EQUIP_SHIELD :
1143 case EQUIP_HELMET :
1144 case EQUIP_BELT :
1145 case EQUIP_CLOAK :
1146 case EQUIP_GAUNTLETS :
1147 case EQUIP_BOOTS :
1148 case EQUIP_RING :
1149
1150 if ( !uBonusChanceStandart[treasureLevelMinus1] )
1151 return;
1152 special_chance = rand() % 100;
1153 if ( special_chance < uBonusChanceStandart[treasureLevelMinus1])
1154 {
1155 v26 = rand() %pEnchantmentsSumm[out_item->GetItemEquipType()-3] + 1;
1156 v27 = 0;
1157 while(v27 < v26)
1158 {
1159 ++out_item->uEnchantmentType;
1160 v27+=pEnchantments[out_item->uEnchantmentType].to_item[out_item->GetItemEquipType()-3];
1161 }
1162
1163 v33 = rand() % (bonus_ranges[treasureLevelMinus1].maxR - bonus_ranges[treasureLevelMinus1].minR + 1);
1164 out_item->m_enchantmentStrength = v33 + bonus_ranges[treasureLevelMinus1].minR;
1165 v32 = out_item->uEnchantmentType - 1;
1166 if ( v32 == 21 || v32 == 22 || v32 == 23 ) //Armsmaster skill, Dodge skill, Unarmed skill
1167 out_item->m_enchantmentStrength = out_item->m_enchantmentStrength/2;
1168 if ( out_item->m_enchantmentStrength <= 0 )
1169 out_item->m_enchantmentStrength = 1;
1170 return;
1171
1172 }
1173 else if ( special_chance >= uBonusChanceStandart[treasureLevelMinus1] + uBonusChanceSpecial[treasureLevelMinus1] )
1174 return;
1175 break;
1176 case EQUIP_WAND:
1177 out_item->uNumCharges = rand() % 6 + out_item->GetDamageMod() + 1;
1178 out_item->uMaxCharges = out_item->uNumCharges;
1179 return;
1180 default:
1181 return;
1182 }
1183
1184 j=0;
1185 int spc_sum=0;
1186 int spc;
1187 memset(&val_list, 0, 3200);
1188 for (unsigned int i=0; i<pSpecialEnchantments_count;++i)
1189 {
1190 int tr_lv= pSpecialEnchantments[i].iTreasureLevel;
1191 if ((treasure_level - 1 == 2) && ( tr_lv == 1 || tr_lv == 0 ) ||
1192 (treasure_level - 1 == 3) && (tr_lv == 2 || tr_lv == 1 || tr_lv == 0) ||
1193 (treasure_level - 1 == 4) && (tr_lv == 3 || tr_lv == 2 || tr_lv == 1) ||
1194 (treasure_level - 1 == 5) && (tr_lv == 3)
1195 )
1196 {
1197 spc=pSpecialEnchantments[i].to_item_apply[out_item->GetItemEquipType()];
1198 spc_sum+=spc;
1199 if(spc)
1200 {
1201 val_list[j++]=i;
1202 }
1203 }
1204 }
1205
1206 v46 = rand()%spc_sum+1;//ñëó÷àéíûå çíà÷åíèÿ îò 1 äî spc_sum
1207 j=0;
1208 v45 = 0;
1209 while (v45<v46)
1210 {
1211 ++j;
1212 out_item->uSpecEnchantmentType=val_list[j];
1213 v45+=pSpecialEnchantments[val_list[j]].to_item_apply[out_item->GetItemEquipType()];
1214 }
1215 }
1216
1217 //----- (004505CC) --------------------------------------------------------
1218 bool ItemGen::GenerateArtifact()
1219 {
1220 signed int uNumArtifactsNotFound; // esi@1
1221 int artifacts_list[32];
1222
1223 memset(artifacts_list, 0,sizeof(artifacts_list));
1224 uNumArtifactsNotFound = 0;
1225
1226 for (int i=500;i<529;++i)
1227 if ( !pParty->pIsArtifactFound[i-500] )
1228 artifacts_list[uNumArtifactsNotFound++] = i;
1229
1230 Reset();
1231 if ( uNumArtifactsNotFound )
1232 {
1233 uItemID = artifacts_list[rand() % uNumArtifactsNotFound];
1234 pItemsTable->SetSpecialBonus(this);
1235 return true;
1236 }
1237 else
1238 return false;
1239
1240 }
1241
1242 std::map<int, std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* >ItemGen::regularBonusMap;
1243 std::map<int, std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* >ItemGen::specialBonusMap;
1244 std::map<int, std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* >ItemGen::artifactBonusMap;
1245
1246 #define NEWBONUSINTOSPECIALLIST(x,y) AddToMap(ItemGen::specialBonusMap, enchId, x, y);
1247 #define NEWBONUSINTOSPECIALLIST2(x,y,z) AddToMap(ItemGen::specialBonusMap, enchId, x, y, z);
1248
1249 #define NEWBONUSINTOREGULARLIST(x) AddToMap(ItemGen::regularBonusMap, enchId, x);
1250
1251 #define NEWBONUSINTOARTIFACTLIST(x,y) AddToMap(ItemGen::artifactBonusMap, itemId, x, y);
1252 #define NEWBONUSINTOARTIFACTLIST2(x,y,z) AddToMap(ItemGen::artifactBonusMap, itemId, x, y, z);
1253
1254 void ItemGen::AddToMap( std::map<int, std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* > &maptoadd, int enchId, CHARACTER_ATTRIBUTE_TYPE attrId, int bonusValue /*= 0*/, unsigned __int16 Player::* skillPtr /*= NULL*/ )
1255 {
1256 auto key = maptoadd.find(enchId);
1257 std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* currMap;
1258 if (key == maptoadd.end())
1259 {
1260 currMap = new std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>;
1261 maptoadd[enchId] = currMap;
1262 }
1263 else
1264 {
1265 currMap = key->second;
1266 }
1267 Assert(currMap->find(attrId) == currMap->end(), "Attribute %d already present for enchantment %d", attrId, enchId);
1268 (*currMap)[attrId] = new CEnchantment(bonusValue, skillPtr);
1269 }
1270
1271 void ItemGen::PopulateSpecialBonusMap()
1272 {
1273 int enchId = 1;// of Protection, +10 to all Resistances
1274 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 10);
1275 NEWBONUSINTOSPECIALLIST( CHARACTER_ATTRIBUTE_RESIST_AIR, 10);
1276 NEWBONUSINTOSPECIALLIST( CHARACTER_ATTRIBUTE_RESIST_WATER, 10);
1277 NEWBONUSINTOSPECIALLIST( CHARACTER_ATTRIBUTE_RESIST_EARTH, 10);
1278 NEWBONUSINTOSPECIALLIST( CHARACTER_ATTRIBUTE_RESIST_MIND, 10);
1279 NEWBONUSINTOSPECIALLIST( CHARACTER_ATTRIBUTE_RESIST_BODY, 10);
1280
1281 enchId = 2;//of The Gods, +10 to all Seven Statistics
1282 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_STRENGTH, 10);
1283 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 10);
1284 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 10);
1285 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 10);
1286 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ACCURACY, 10);
1287 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_SPEED, 10);
1288 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_LUCK, 10);
1289
1290 enchId = 26;//of Air Magic
1291 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_AIR,0, &Player::skillAir);
1292
1293 enchId = 27;//of Body Magic
1294 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_BODY,0, &Player::skillBody);
1295
1296 enchId = 28;//of Dark Magic
1297 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_DARK,0, &Player::skillDark);
1298
1299 enchId = 29;//of Earth Magic
1300 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_EARTH,0, &Player::skillEarth);
1301
1302 enchId = 30;//of Fire Magic
1303 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_FIRE,0, &Player::skillFire);
1304
1305 enchId = 31;//of Light Magic
1306 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_LIGHT,0, &Player::skillLight);
1307
1308 enchId = 32;//of Mind Magic
1309 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_MIND,0, &Player::skillMind);
1310
1311 enchId = 33;//of Spirit Magic
1312 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_SPIRIT,0, &Player::skillSpirit);
1313
1314 enchId = 34;//of Water Magic
1315 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_WATER,0, &Player::skillWater);
1316
1317 enchId = 42;//of Doom
1318 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_STRENGTH, 1);
1319 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 1);
1320 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 1);
1321 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 1);
1322 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ACCURACY, 1);
1323 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_SPEED, 1);
1324 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_LUCK, 1);
1325 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_HEALTH, 1);
1326 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_MANA, 1);
1327 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_AC_BONUS, 1);
1328 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 1);
1329 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, 1);
1330 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, 1);
1331 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH, 1);
1332 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_MIND, 1);
1333 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_BODY, 1);
1334
1335 enchId = 43;//of Earth
1336 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 10);
1337 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_AC_BONUS, 10);
1338 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_HEALTH, 10);
1339
1340 enchId = 44;//of Life
1341 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_HEALTH, 10);
1342
1343 enchId = 45;//Rogues
1344 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_SPEED, 5);
1345 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ACCURACY, 5);
1346
1347 enchId = 46;//of The Dragon
1348 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_STRENGTH, 25);
1349
1350 enchId = 47;//of The Eclipse
1351 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_MANA, 10);
1352
1353 enchId = 48;//of The Golem
1354 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 15);
1355 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_AC_BONUS, 5);
1356
1357 enchId = 49;//of The Moon
1358 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 10);
1359 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_LUCK, 10);
1360
1361 enchId = 50;//of The Phoenix
1362 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 30);
1363
1364 enchId = 51;//of The Sky
1365 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_MANA, 10);
1366 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_SPEED, 10);
1367 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 10);
1368
1369 enchId = 52;//of The Stars
1370 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 10);
1371 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ACCURACY, 10);
1372
1373 enchId = 53;//of The Sun
1374 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_STRENGTH, 10);
1375 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 10);
1376
1377 enchId = 54;//of The Troll
1378 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 15);
1379
1380 enchId = 55;//of The Unicorn
1381 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_LUCK, 15);
1382
1383 enchId = 56;//Warriors
1384 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_STRENGTH, 5);
1385 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 5);
1386
1387 enchId = 57;//Wizards
1388 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 5);
1389 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 5);
1390
1391 enchId = 60;//Monks'
1392 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_DODGE, 3, &Player::skillDodge);
1393 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_UNARMED, 3, &Player::skillUnarmed);
1394
1395 enchId = 61;//Thieves'
1396 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM, 3, &Player::skillStealing);
1397 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_STEALING, 3, &Player::skillDisarmTrap);
1398
1399 enchId = 62;//of Identifying
1400 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_ITEM_ID, 3, &Player::skillItemId);
1401 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_MONSTER_ID, 3, &Player::skillMonsterId);
1402
1403 enchId = 67;//Assassins'
1404 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM, 2, &Player::skillDisarmTrap);
1405
1406 enchId = 68;//Barbarians'
1407 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_AC_BONUS, 5);
1408
1409 enchId = 69;//of the Storm
1410 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, 20);
1411
1412 enchId = 70;//of the Ocean
1413 NEWBONUSINTOSPECIALLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, 10);
1414 NEWBONUSINTOSPECIALLIST2(CHARACTER_ATTRIBUTE_SKILL_ALCHEMY, 2, &Player::skillAlchemy);
1415 }
1416
1417 void ItemGen::PopulateRegularBonusMap()
1418 {
1419 int enchId = 1;//of Might
1420 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_STRENGTH);
1421
1422 enchId = 2;//of Thought
1423 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE);
1424
1425 enchId = 3;//of Charm
1426 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_WILLPOWER);
1427
1428 enchId = 4;//of Vigor
1429 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_ENDURANCE);
1430
1431 enchId = 5;//of Precision
1432 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_ACCURACY);
1433
1434 enchId = 6;//of Speed
1435 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SPEED);
1436
1437 enchId = 7;//of Luck
1438 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_LUCK);
1439
1440 enchId = 8;//of Health
1441 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_HEALTH);
1442
1443 enchId = 9;//of Magic
1444 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_MANA);
1445
1446 enchId = 10;//of Defense
1447 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_AC_BONUS);
1448
1449 enchId = 11;//of Fire Resistance
1450 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE);
1451
1452 enchId = 12;//of Air Resistance
1453 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_AIR);
1454
1455 enchId = 13;//of Water Resistance
1456 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_WATER);
1457
1458 enchId = 14;//of Earth Resistance
1459 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH);
1460
1461 enchId = 15;//of Mind Resistance
1462 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_MIND);
1463
1464 enchId = 16;//of Body Resistance
1465 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_RESIST_BODY);
1466
1467 enchId = 17;//of Alchemy
1468 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_ALCHEMY);
1469
1470 enchId = 18;//of Stealing
1471 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_STEALING);
1472
1473 enchId = 19;//of Disarming
1474 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM);
1475
1476 enchId = 20;//of Items
1477 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_ITEM_ID);
1478
1479 enchId = 21;//of Monsters
1480 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_MONSTER_ID);
1481
1482 enchId = 22;//of Arms
1483 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER);
1484
1485 enchId = 23;//of Dodging
1486 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_DODGE);
1487
1488 enchId = 24;//of the Fist
1489 NEWBONUSINTOREGULARLIST(CHARACTER_ATTRIBUTE_SKILL_UNARMED);
1490 }
1491
1492 void ItemGen::PopulateArtifactBonusMap()
1493 {
1494 int itemId;
1495 itemId = ITEM_ARTIFACT_PUCK;
1496 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 40);
1497
1498 itemId = ITEM_ARTIFACT_IRON_FEATHER;
1499 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 40);
1500
1501 itemId = ITEM_ARTIFACT_WALLACE;
1502 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 40);
1503 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER, 10);
1504
1505 itemId = ITEM_ARTIFACT_CORSAIR;
1506 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_LUCK, 40);
1507 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM, 5);
1508 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_STEALING, 5);
1509
1510 itemId = ITEM_ARTIFACT_GOVERNORS_ARMOR;
1511 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 10);
1512 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 10);
1513 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 10);
1514 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 10);
1515 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ACCURACY, 10);
1516 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, 10);
1517 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_LUCK, 10);
1518
1519 itemId = ITEM_ARTIFACT_YORUBA;
1520 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 25);
1521
1522 itemId = ITEM_ARTIFACT_SPLITTER;
1523 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 50);
1524
1525 itemId = ITEM_ARTEFACT_ULLYSES,
1526 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ACCURACY, 50);
1527
1528 itemId = ITEM_ARTEFACT_HANDS_OF_THE_MASTER,
1529 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_DODGE, 10);
1530 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_UNARMED, 10);
1531
1532 itemId = ITEM_ARTIFACT_LEAGUE_BOOTS;
1533 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, 40);
1534 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_WATER, 0, &Player::skillWater);
1535
1536 itemId = ITEM_ARTIFACT_RULERS_RING;
1537 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_MIND, 0, &Player::skillMind);
1538 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_DARK, 0, &Player::skillDark);
1539
1540 itemId = ITEM_RELIC_MASH;
1541 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 150);
1542 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, -40);
1543 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, -40);
1544 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, -40);
1545
1546 itemId = ITEM_RELIC_ETHRICS_STAFF;
1547 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_DARK, 0, &Player::skillDark);
1548 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_MEDITATION, 15);
1549
1550 itemId = ITEM_RELIC_HARECS_LEATHER;
1551 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM, 5);
1552 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_STEALING, 5);
1553 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_LUCK, 50);
1554 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, -10);
1555 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, -10);
1556 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, -10);
1557 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH, -10);
1558 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_MIND, -10);
1559 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_BODY, -10);
1560
1561 itemId = ITEM_RELIC_OLD_NICK;
1562 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_TRAP_DISARM, 5);
1563
1564 itemId = ITEM_RELIC_AMUCK;
1565 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 100);
1566 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 100);
1567 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_AC_BONUS, -15);
1568
1569 itemId = ITEM_RELIC_GLORY_SHIELD;
1570 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_SPIRIT, 0, &Player::skillSpirit);
1571 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_SHIELD, 5);
1572 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_MIND, -10);
1573 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_BODY, -10);
1574
1575 itemId = ITEM_RELIC_KELEBRIM;
1576 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 50);
1577 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH, -30);
1578
1579 itemId = ITEM_RELIC_TALEDONS_HELM;
1580 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_LIGHT, 0, &Player::skillLight);
1581 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 15);
1582 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 15);
1583 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_LUCK, -40);
1584
1585 itemId = ITEM_RELIC_SCHOLARS_CAP;
1586 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_LEARNING, +15);
1587 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, -50);
1588
1589 itemId = ITEM_RELIC_PHYNAXIAN_CROWN;
1590 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_FIRE, 0, &Player::skillFire);
1591 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, +50);
1592 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 30);
1593 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_AC_BONUS, -20);
1594
1595 itemId = ITEM_RILIC_TITANS_BELT;
1596 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 75);
1597 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, -40);
1598
1599 itemId = ITEM_RELIC_TWILIGHT;
1600 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, 50);
1601 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_LUCK, 50);
1602 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, -15);
1603 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, -15);
1604 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, -15);
1605 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH, -15);
1606 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_MIND, -15);
1607 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_BODY, -15);
1608
1609 itemId = ITEM_RELIC_ANIA_SELVING;
1610 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ACCURACY, 150);
1611 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_BOW, 5);
1612 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_AC_BONUS, -25);
1613
1614 itemId = ITEM_RELIC_JUSTICE;
1615 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_MIND, 0, &Player::skillMind);
1616 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_BODY, 0, &Player::skillBody);
1617 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, -40);
1618
1619 itemId = ITEM_RELIC_MEKORIGS_HAMMER;
1620 NEWBONUSINTOARTIFACTLIST2(CHARACTER_ATTRIBUTE_SKILL_SPIRIT, 0, &Player::skillSpirit);
1621 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 75);
1622 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, -50);
1623
1624 itemId = ITEM_ARTIFACT_HERMES_SANDALS;
1625 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, 100);
1626 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ACCURACY, 50);
1627 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, 50);
1628
1629 itemId = ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP;
1630 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, -20);
1631 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, -20);
1632
1633 itemId = ITEM_ARTIFACT_MINDS_EYE;
1634 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_WILLPOWER, 15);
1635 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_INTELLIGENCE, 15);
1636
1637 itemId = ITEM_ELVEN_CHAINMAIL;
1638 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SPEED, 15);
1639 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ACCURACY, 15);
1640
1641 itemId = ITEM_FORGE_GAUNTLETS;
1642 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 15);
1643 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_ENDURANCE, 15);
1644 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 30);
1645
1646 itemId = ITEM_ARTIFACT_HEROS_BELT;
1647 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_STRENGTH, 15);
1648 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_SKILL_ARMSMASTER, 5);
1649
1650 itemId = ITEM_ARTIFACT_LADYS_ESCORT;
1651 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_FIRE, 10);
1652 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_AIR, 10);
1653 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_WATER, 10);
1654 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_EARTH, 10);
1655 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_MIND, 10);
1656 NEWBONUSINTOARTIFACTLIST(CHARACTER_ATTRIBUTE_RESIST_BODY, 10);
1657 }
1658
1659 void ItemGen::GetItemBonusSpecialEnchantment( Player* owner, CHARACTER_ATTRIBUTE_TYPE attrToGet, int* additiveBonus, int* halfSkillBonus )
1660 {
1661 auto bonusList = ItemGen::specialBonusMap.find(this->uSpecEnchantmentType);
1662 if (bonusList == ItemGen::specialBonusMap.end())
1663 {
1664 return;
1665 }
1666 std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* currList = bonusList->second;
1667 if (currList->find(attrToGet) != currList->end())
1668 {
1669 CEnchantment* currBonus = (*currList)[attrToGet];
1670 if (currBonus->statPtr != NULL)
1671 {
1672 if (currBonus->statBonus == 0)
1673 {
1674 *halfSkillBonus = owner->*currBonus->statPtr / 2;
1675 }
1676 else
1677 {
1678 if (*additiveBonus < currBonus->statBonus)
1679 {
1680 *additiveBonus = currBonus->statBonus;
1681 }
1682 }
1683 }
1684 else
1685 {
1686 *additiveBonus += currBonus->statBonus;
1687 }
1688 }
1689 }
1690
1691 void ItemGen::GetItemBonusArtifact( Player* owner, CHARACTER_ATTRIBUTE_TYPE attrToGet, int* bonusSum )
1692 {
1693 auto bonusList = ItemGen::artifactBonusMap.find(this->uItemID);
1694 if (bonusList == ItemGen::artifactBonusMap.end())
1695 {
1696 return;
1697 }
1698 std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* currList = bonusList->second;
1699 if (currList->find(attrToGet) != currList->end())
1700 {
1701 CEnchantment* currBonus = (*currList)[attrToGet];
1702 if (currBonus->statPtr != NULL)
1703 {
1704 *bonusSum = owner->*currBonus->statPtr / 2;
1705 }
1706 else
1707 {
1708 *bonusSum += currBonus->statBonus;
1709 }
1710 }
1711 }
1712
1713 bool ItemGen::IsRegularEnchanmentForAttribute( CHARACTER_ATTRIBUTE_TYPE attrToGet )
1714 {
1715 auto bonusList = ItemGen::specialBonusMap.find(this->uEnchantmentType);
1716 if (bonusList == ItemGen::specialBonusMap.end())
1717 {
1718 return false;
1719 }
1720 std::map<CHARACTER_ATTRIBUTE_TYPE, CEnchantment*>* currList = bonusList->second;
1721 return (currList->find(attrToGet) != currList->end());
1722 }
1723
1724 ITEM_EQUIP_TYPE ItemGen::GetItemEquipType()
1725 {
1726 return pItemsTable->pItems[this->uItemID].uEquipType;
1727 }
1728
1729 unsigned char ItemGen::GetPlayerSkillType()
1730 {
1731 return pItemsTable->pItems[this->uItemID].uSkillType;
1732 }
1733
1734 char* ItemGen::GetIconName()
1735 {
1736 return pItemsTable->pItems[this->uItemID].pIconName;
1737 }
1738
1739 unsigned __int8 ItemGen::GetDamageDice()
1740 {
1741 return pItemsTable->pItems[this->uItemID].uDamageDice;
1742 }
1743
1744 unsigned __int8 ItemGen::GetDamageRoll()
1745 {
1746 return pItemsTable->pItems[this->uItemID].uDamageRoll;
1747 }
1748
1749 unsigned __int8 ItemGen::GetDamageMod()
1750 {
1751 return pItemsTable->pItems[this->uItemID].uDamageMod;
1752 }
1753 //----- (004B8E3D) --------------------------------------------------------
1754 void GenerateStandartShopItems()
1755 {
1756 signed int item_count;
1757 signed int shop_index;
1758 int treasure_lvl;
1759 int item_class;
1760 int mdf;
1761
1762 shop_index = (signed int)window_SpeakInHouse->ptr_1C;
1763 if ( uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType] )
1764 {
1765 for (item_count = 0; item_count < uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType]; ++item_count )
1766 {
1767 if (shop_index <= 14) //weapon shop
1768 {
1769 treasure_lvl = shopWeap_variation_ord[shop_index].treasure_level;
1770 item_class = shopWeap_variation_ord[shop_index].item_class[rand() % 4];
1771 }
1772 else if (shop_index <= 28) //armor shop
1773 {
1774 mdf = 0;
1775 if (item_count > 3)
1776 ++mdf;// rechek offsets
1777 treasure_lvl = shopArmr_variation_ord[2*(shop_index - 15) + mdf].treasure_level;
1778 item_class = shopArmr_variation_ord[2*(shop_index - 15) + mdf].item_class[rand() % 4];
1779 }
1780 else if (shop_index <= 41) //magic shop
1781 {
1782 treasure_lvl = shopMagic_treasure_lvl[shop_index - 28];
1783 item_class = 22; //misc
1784 }
1785 else if (shop_index <= 53) //alchemist shop
1786 {
1787 if (item_count < 6)
1788 {
1789 pParty->StandartItemsInShops[shop_index][item_count].Reset();
1790 pParty->StandartItemsInShops[shop_index][item_count].uItemID = 220; //potion bottle
1791 continue;
1792 }
1793 else
1794 {
1795 treasure_lvl = shopAlch_treasure_lvl[shop_index - 41];
1796 item_class = 45; //reagent
1797 }
1798 }
1799 pItemsTable->GenerateItem(treasure_lvl, item_class, &pParty->StandartItemsInShops[shop_index][item_count]);
1800 pParty->StandartItemsInShops[shop_index][item_count].SetIdentified(); //identified
1801 }
1802 }
1803 pParty->InTheShopFlags[shop_index] = 0;
1804 }
1805
1806 //----- (004B8F94) --------------------------------------------------------
1807 void GenerateSpecialShopItems()
1808 {
1809 signed int item_count;
1810 signed int shop_index;
1811 int treasure_lvl;
1812 int item_class;
1813 int mdf;
1814
1815 shop_index = (signed int)window_SpeakInHouse->ptr_1C;
1816 if ( uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType] )
1817 {
1818 for ( item_count = 0; item_count < uItemsAmountPerShopType[p2DEvents[shop_index - 1].uType]; ++item_count )
1819 {
1820 if (shop_index <= 14) //weapon shop
1821 {
1822 treasure_lvl = shopWeap_variation_spc[shop_index].treasure_level;
1823 item_class = shopWeap_variation_spc[shop_index].item_class[rand() % 4];
1824 }
1825 else if (shop_index <= 28) //armor shop
1826 {
1827 mdf = 0;
1828 if (item_count > 3)
1829 ++mdf;
1830 treasure_lvl = shopArmr_variation_spc[2*(shop_index - 15) + mdf].treasure_level;
1831 item_class = shopArmr_variation_spc[2*(shop_index - 15) + mdf].item_class[rand() % 4];
1832 }
1833 else if (shop_index <= 41) //magic shop
1834 {
1835 treasure_lvl = shopMagicSpc_treasure_lvl[shop_index - 28];
1836 item_class = 22; //misc
1837 }
1838 else if (shop_index <= 53) //alchemist shop
1839 {
1840 if (item_count < 6)
1841 {
1842 pParty->SpecialItemsInShops[shop_index][item_count].Reset();
1843 pParty->SpecialItemsInShops[shop_index][item_count].uItemID = rand() % 32 + 740; //mscrool
1844 continue;
1845 }
1846 else
1847 {
1848 treasure_lvl = shopAlchSpc_treasure_lvl[shop_index - 41];
1849 item_class = 44; //potion
1850 }
1851 }
1852 pItemsTable->GenerateItem(treasure_lvl, item_class, &pParty->SpecialItemsInShops[shop_index][item_count]);
1853 pParty->SpecialItemsInShops[shop_index][item_count].SetIdentified(); //identified
1854 }
1855 }
1856 pParty->InTheShopFlags[shop_index] = 0;
1857 }
1858
1859
1860 //----- (00450218) --------------------------------------------------------
1861 void GenerateItemsInChest()
1862 {
1863 unsigned int mapType; // eax@1
1864 MapInfo *currMapInfo; // esi@1
1865 ItemGen *currItem; // ebx@2
1866 int additionaItemCount; // ebp@4
1867 int treasureLevelBot; // edi@4
1868 int treasureLevelTop; // esi@4
1869 signed int treasureLevelRange; // esi@4
1870 int resultTreasureLevel; // edx@4
1871 int goldAmount; // esi@8
1872 int v11; // ebp@25
1873 int v12; // esi@25
1874 signed int whatToGenerateProb; // [sp+10h] [bp-18h]@1
1875
1876 mapType = pMapStats->GetMapInfo(pCurrentMapName);
1877 currMapInfo = &pMapStats->pInfos[mapType];
1878 for(int i=1; i<20;++i)
1879 {
1880 for(int j=0; j<140;++j)
1881 {
1882
1883 currItem = &pChests[i].igChestItems[j];
1884 if ( currItem->uItemID < 0 )
1885 {
1886 additionaItemCount = rand() % 5; //additional items in chect
1887 treasureLevelBot = byte_4E8168[abs(currItem->uItemID)-1][2*currMapInfo->Treasure_prob];
1888 treasureLevelTop = byte_4E8168[abs(currItem->uItemID)-1][2*currMapInfo->Treasure_prob+1];
1889 treasureLevelRange = treasureLevelTop - treasureLevelBot + 1;
1890 resultTreasureLevel = treasureLevelBot + rand() % treasureLevelRange; //treasure level
1891 if (resultTreasureLevel<7)
1892 {
1893 v11 = 0;
1894 do
1895 {
1896 whatToGenerateProb = rand() % 100;
1897 if (whatToGenerateProb<20)
1898 {
1899 currItem->Reset();
1900 }
1901 else if (whatToGenerateProb<60) //generate gold
1902 {
1903 goldAmount=0;
1904 currItem->Reset();
1905 switch (resultTreasureLevel)
1906 {
1907 case 1: //small gold
1908 goldAmount = rand() % 51 + 50;
1909 currItem->uItemID = 197;
1910 break;
1911 case 2://small gold
1912 goldAmount = rand() % 101 + 100;
1913 currItem->uItemID = 197;
1914 break;
1915 case 3: //medium
1916 goldAmount = rand() % 301 + 200;
1917 currItem->uItemID = 198;
1918 break;
1919 case 4: //medium
1920 goldAmount = rand() % 501 + 500;
1921 currItem->uItemID = 198;
1922 break;
1923 case 5: //big
1924 goldAmount = rand() % 1001 + 1000;
1925 currItem->uItemID = 199;
1926 break;
1927 case 6: //big
1928 goldAmount = rand() % 3001 + 2000;
1929 currItem->uItemID = 199;
1930 break;
1931 }
1932 currItem->SetIdentified();
1933 currItem->uSpecEnchantmentType = goldAmount;
1934 }
1935 else
1936 {
1937 pItemsTable->GenerateItem(resultTreasureLevel, 0, currItem);
1938 }
1939 v12 = 0;
1940 while ( !(pChests[i].igChestItems[v12].uItemID==0) &&(v12<140))
1941 {
1942 ++v12;
1943 }
1944 if (v12 >= 140)
1945 break;
1946 currItem=&pChests[i].igChestItems[v12];
1947 v11++;
1948 } while (v11 < additionaItemCount + 1); // + 1 because it's the item at pChests[i].igChestItems[j] and the additional ones
1949 }
1950 else
1951 currItem->GenerateArtifact();
1952 }
1953 }
1954 }
1955
1956 }
1957
1958
1959
1960
1961 // 4505CC: using guessed type int var_A0[32];
1962 //----- (004B3703) --------------------------------------------------------
1963 void FillAviableSkillsToTeach( int _this )
1964 {
1965 const char *v30; // ecx@65
1966 unsigned int v29; // edx@56
1967 int v15; // ecx@19
1968 int v33; // [sp-4h] [bp-2Ch]@23
1969 int v34; // [sp-4h] [bp-2Ch]@43
1970 int v21; // ecx@34
1971 int v35[5]; // [sp+Ch] [bp-1Ch]@8
1972 int v37=0; // [sp+24h] [bp-4h]@1*
1973 int i=0;
1974
1975 dword_F8B1DC_currentShopOption = 0;
1976
1977 switch (_this)
1978 {
1979 case 1: //shop weapon
1980 for (int i=0; i<2; ++i)
1981 {
1982 for (int j=0; j<4; ++j)
1983 {
1984 if ( i )
1985 v21 = shopWeap_variation_spc[(unsigned int)window_SpeakInHouse->ptr_1C].item_class[j];
1986 else
1987 v21 = shopWeap_variation_ord[(unsigned int)window_SpeakInHouse->ptr_1C].item_class[j];
1988
1989 switch (v21)
1990 {
1991 case 23: v34 = 37; break;
1992 case 24: v34 = 38; break;
1993 case 25: v34 = 39; break;
1994 case 26: v34 = 40; break;
1995 case 27: v34 = 41; break;
1996 case 28: v34 = 42; break;
1997 case 30: v34 = 36; break;
1998 default:
1999 continue;
2000 }
2001 v37 = sub_4BE571_AddItemToSet(v34, v35, v37, 5);
2002 }
2003 }
2004 break;
2005 case 2: //shop armor
2006
2007 for (int i=0; i<2; ++i)
2008 {
2009 for (int j=0; j<2; ++j)
2010 {
2011 for (int k=0; k<4; ++k)
2012 {
2013 if ( i )
2014 v15 = shopArmr_variation_spc[(unsigned int)window_SpeakInHouse->ptr_1C-15+j].item_class[k];
2015 else
2016 v15 = shopArmr_variation_ord[(unsigned int)window_SpeakInHouse->ptr_1C-15+j].item_class[k];
2017 switch (v15)
2018 {
2019 case 31: v33 = 45; break;
2020 case 32: v33 = 46; break;
2021 case 33: v33 = 47; break;
2022 case 34: v33 = 44; break;
2023 default:
2024 continue;
2025 }
2026 v37 = sub_4BE571_AddItemToSet(v33, v35, v37, 5);
2027 }
2028 }
2029 }
2030 break;
2031 case 3: //shop magic
2032 v37 = 2;
2033 v35[0] = 57;
2034 v35[1] = 59;
2035 break;
2036 case 4: //shop alchemist
2037 v37 = 2;
2038 v35[0] = 71;
2039 v35[1] = 68;
2040 break;
2041 case 21: //tavern
2042 v37 = 3;
2043 v35[0] = 70;
2044 v35[1] = 65;
2045 v35[2] = 62;
2046 break;
2047 case 23: //temple
2048 v37 = 3;
2049 v35[0] = 67;
2050 v35[1] = 66;
2051 v35[2] = 58;
2052 break;
2053 case 30: ///trainig
2054 v37 = 2;
2055 v35[0] = 69;
2056 v35[1] = 60;
2057 break;
2058 }
2059 for(i=0;i<v37;++i)
2060 {
2061 v29=v35[i];
2062 switch(v29)
2063 {
2064 case 40 :v30 = pSkillNames[4]; break;
2065 case 5 : v30 = pSkillNames[23]; break;
2066 case 36 :v30 = pSkillNames[0]; break;
2067 case 37 :v30 = pSkillNames[1]; break;
2068 case 38 :v30 = pSkillNames[2]; break;
2069 case 39 :v30 = pSkillNames[3]; break;
2070 case 41 :v30 = pSkillNames[5]; break;
2071 case 42 :v30 = pSkillNames[6]; break;
2072 case 44 :v30 = pSkillNames[8]; break;
2073 case 45 :v30 = pSkillNames[9]; break;
2074 case 46 :v30 = pSkillNames[10]; break;
2075 case 47 :v30 = pSkillNames[11]; break;
2076 case 66 :v30 = pSkillNames[30]; break;
2077 case 57 :v30 = pSkillNames[21]; break;
2078 case 58 :v30 = pSkillNames[22]; break;
2079 case 60 :v30 = pSkillNames[24]; break;
2080 case 62 :v30 = pSkillNames[26]; break;
2081 case 65 :v30 = pSkillNames[29]; break;
2082 case 67:v30 = pSkillNames[31]; break;
2083 case 68:v30 = pSkillNames[32]; break;
2084 case 69:v30 = pSkillNames[33]; break;
2085 case 70:v30 = pSkillNames[34]; break;
2086 case 71:v30 = pSkillNames[35]; break;
2087 default:
2088 v30 = pGlobalTXT_LocalizationStrings[127]; //"No Text!"
2089 }
2090 pShopOptions[dword_F8B1DC_currentShopOption] = const_cast<char *>(v30);
2091 ++dword_F8B1DC_currentShopOption;
2092 CreateButtonInColumn(i+1, v29);
2093 }
2094 pDialogueWindow->_41D08F_set_keyboard_control_group(i, 1, 0, 2);
2095 dword_F8B1E0 = pDialogueWindow->pNumPresenceButton;
2096 }
2097
2098 //----- (004BE571) --------------------------------------------------------
2099 int sub_4BE571_AddItemToSet(int valueToAdd, int *outPutSet, int elemsAlreadyPresent, int elemsNeeded)
2100 {
2101 int i; // esi@3
2102
2103 if ( elemsAlreadyPresent < elemsNeeded )
2104 {
2105 for ( i = 0; i < elemsAlreadyPresent; ++i )
2106 {
2107 if ( valueToAdd == outPutSet[i] )
2108 return elemsAlreadyPresent;
2109 }
2110 outPutSet[elemsAlreadyPresent] = valueToAdd;
2111 return elemsAlreadyPresent + 1;
2112 }
2113 return elemsNeeded;
2114 }
2115 //----- (0043C91D) --------------------------------------------------------
2116 int GetItemTextureFilename(char *pOut, signed int item_id, int index, int shoulder)
2117 {
2118 int result; // eax@2
2119 ITEM_EQUIP_TYPE pEquipType;
2120
2121 result = 0; //BUG fn is void
2122 pEquipType = pItemsTable->pItems[item_id].uEquipType;
2123 if ( item_id > 500 )
2124 {
2125 switch ( item_id )
2126 {
2127 case ITEM_RELIC_HARECS_LEATHER:
2128 if (byte_5111F6_OwnedArtifacts[2] != 0)
2129 item_id = 234;
2130 break;
2131 case ITEM_ARTIFACT_YORUBA:
2132 if (byte_5111F6_OwnedArtifacts[1] != 0)
2133 item_id = 236;
2134 break;
2135 case ITEM_ARTIFACT_GOVERNORS_ARMOR:
2136 if (byte_5111F6_OwnedArtifacts[0] != 0)
2137 item_id = 235;
2138 break;
2139 case ITEM_ELVEN_CHAINMAIL:
2140 if (byte_5111F6_OwnedArtifacts[16] != 0)
2141 item_id = 73;
2142 break;
2143 case ITEM_ARTIFACT_LEAGUE_BOOTS:
2144 if (byte_5111F6_OwnedArtifacts[3] != 0)
2145 item_id = 312;
2146 break;
2147 case ITEM_RELIC_TALEDONS_HELM:
2148 if (byte_5111F6_OwnedArtifacts[4] != 0)
2149 item_id = 239;
2150 break;
2151 case ITEM_RELIC_SCHOLARS_CAP:
2152 if (byte_5111F6_OwnedArtifacts[5] != 0)
2153 item_id = 240;
2154 break;
2155 case ITEM_RELIC_PHYNAXIAN_CROWN:
2156 if (byte_5111F6_OwnedArtifacts[6] != 0)
2157 item_id = 241;
2158 break;
2159 case ITEM_ARTIFACT_MINDS_EYE:
2160 if (byte_5111F6_OwnedArtifacts[7] != 0)
2161 item_id = 93;
2162 break;
2163 case ITEM_RARE_SHADOWS_MASK:
2164 if (byte_5111F6_OwnedArtifacts[8] != 0)
2165 item_id = 344;
2166 break;
2167 case ITEM_RILIC_TITANS_BELT:
2168 if (byte_5111F6_OwnedArtifacts[9] != 0)
2169 item_id = 324;
2170 break;
2171 case ITEM_ARTIFACT_HEROS_BELT:
2172 if (byte_5111F6_OwnedArtifacts[10] != 0)
2173 item_id = 104;
2174 break;
2175 case ITEM_RELIC_TWILIGHT:
2176 if (byte_5111F6_OwnedArtifacts[11] != 0)
2177 item_id = 325;
2178 break;
2179 case ITEM_ARTIFACT_CLOAK_OF_THE_SHEEP:
2180 if (byte_5111F6_OwnedArtifacts[12] != 0)
2181 item_id = 330;
2182 break;
2183 case ITEM_RARE_SUN_CLOAK:
2184 if (byte_5111F6_OwnedArtifacts[13] != 0)
2185 item_id = 347;
2186 break;
2187 case ITEM_RARE_MOON_CLOAK:
2188 if (byte_5111F6_OwnedArtifacts[14] != 0)
2189 item_id = 348;
2190 break;
2191 case ITEM_RARE_VAMPIRES_CAPE:
2192 if (byte_5111F6_OwnedArtifacts[15] != 0)
2193 item_id = 350;
2194 break;
2195 default:
2196 return 0;
2197 }
2198 }
2199
2200 switch (pEquipType)
2201 {
2202 case EQUIP_ARMOUR:
2203 if ( !shoulder )
2204 return sprintf(pOut, "item%3.3dv%d", item_id, index);
2205 else if ( shoulder == 1 )
2206 return sprintf(pOut, "item%3.3dv%da1", item_id, index);
2207 else if ( shoulder == 2 )
2208 return sprintf(pOut, "item%3.3dv%da2", item_id, index);
2209 break;
2210 case EQUIP_CLOAK:
2211 if ( !shoulder )
2212 return sprintf(pOut, "item%3.3dv%d", item_id, index);
2213 else
2214 return sprintf(pOut, "item%3.3dv%da1", item_id, index);
2215 default:
2216 return sprintf(pOut, "item%3.3dv%d", item_id, index);
2217 }
2218
2219 result = item_id - 504;
2220 return result;
2221 }
2222
2223
2224 //----- (004BDAAF) --------------------------------------------------------
2225 bool ItemGen::MerchandiseTest(int _2da_idx)
2226 {
2227 bool test;
2228
2229 if ( (p2DEvents[_2da_idx - 1].uType != 4 || (signed int)this->uItemID < 740 || (signed int)this->uItemID > 771)
2230 && ((signed int)this->uItemID >= 600 || (signed int)this->uItemID >= 529 && (signed int)this->uItemID <= 599) || this->IsStolen())
2231 return false;
2232 switch( p2DEvents[_2da_idx - 1].uType )
2233 {
2234 case BuildingType_WeaponShop:
2235 {
2236 test = this->GetItemEquipType() <= EQUIP_BOW;
2237 break;
2238 }
2239 case BuildingType_ArmorShop:
2240 {
2241 test = this->GetItemEquipType() >= EQUIP_ARMOUR && this->GetItemEquipType() <= EQUIP_BOOTS;
2242 break;
2243 }
2244 case BuildingType_MagicShop:
2245 {
2246 test = this->GetPlayerSkillType() == PLAYER_SKILL_MISC || this->GetItemEquipType() == EQIUP_ANY;
2247 break;
2248 }
2249 case BuildingType_AlchemistShop:
2250 {
2251 test = this->GetItemEquipType() == EQUIP_REAGENT || this->GetItemEquipType() == EQUIP_POTION
2252 || (this->GetItemEquipType() > EQUIP_POTION && !(this->GetItemEquipType() != EQUIP_MESSAGE_SCROLL
2253 || (signed int)this->uItemID < 740) && this->uItemID != 771);
2254 break;
2255 }
2256 default:
2257 {
2258 test = false;
2259 break;
2260 }
2261 }
2262 return test;
2263 }
2264
2265 //----- (00493F79) --------------------------------------------------------
2266 void init_summoned_item(stru351_summoned_item *_this, __int64 duration)
2267 {
2268 signed __int64 v2; // ST2C_8@1
2269 signed __int64 v3; // qax@1
2270 //signed __int64 v4; // ST1C_8@1
2271 unsigned __int64 v5; // qax@1
2272 unsigned int v6; // ebx@1
2273
2274 v2 = (signed __int64)((double)duration * 0.234375);
2275 v3 = v2 / 60 / 60;
2276 //v4 = v3;
2277 v5 = (unsigned int)v3 / 0x18;
2278 v6 = (unsigned int)(v5 / 7) >> 2;
2279 _this->field_0_expire_second = v2 % 60;
2280 _this->field_4_expire_minute = v2 / 60 % 60;
2281 _this->field_8_expire_hour = v3 % 24;
2282 _this->field_10_expire_week = v5 / 7 & 3;
2283 _this->field_C_expire_day = (unsigned int)v5 % 0x1C;
2284 _this->field_14_exprie_month = v6 % 0xC;
2285 _this->field_18_expire_year = v6 / 0xC + game_starting_year;
2286 }