comparison Items.cpp @ 2260:eab43c3d7767

Using new tokenizer in Items.cpp initialize function
author Grumpy7
date Thu, 06 Mar 2014 00:41:04 +0100
parents aff7a7b072b7
children 236d8d7c7295
comparison
equal deleted inserted replaced
2259:43a508455445 2260:eab43c3d7767
1 #define _CRT_SECURE_NO_WARNINGS 1 #define _CRT_SECURE_NO_WARNINGS
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string>
3 4
4 #include "Items.h" 5 #include "Items.h"
5 #include "MapInfo.h" 6 #include "MapInfo.h"
6 #include "GUIWindow.h" 7 #include "GUIWindow.h"
7 #include "Events2D.h" 8 #include "Events2D.h"
12 #include "FactionTable.h" 13 #include "FactionTable.h"
13 #include "StorylineTextTable.h" 14 #include "StorylineTextTable.h"
14 #include "texts.h" 15 #include "texts.h"
15 #include "mm7_data.h" 16 #include "mm7_data.h"
16 17
18 struct ci_less : std::binary_function<std::string, std::string, bool>
19 {
20 // case-independent (ci) compare_less binary function
21 struct nocase_compare : public std::binary_function<unsigned char,unsigned char,bool>
22 {
23 bool operator() (const unsigned char& c1, const unsigned char& c2) const {
24 return tolower (c1) < tolower (c2);
25 }
26 };
27 bool operator() (const std::string & s1, const std::string & s2) const {
28 return std::lexicographical_compare
29 (s1.begin (), s1.end (), // source range
30 s2.begin (), s2.end (), // dest range
31 nocase_compare ()); // comparison
32 }
33 };
17 34
18 35
19 struct ITEM_VARIATION 36 struct ITEM_VARIATION
20 { 37 {
21 unsigned __int16 treasure_level; 38 unsigned __int16 treasure_level;
307 } 324 }
308 325
309 326
310 //----- (00456D84) -------------------------------------------------------- 327 //----- (00456D84) --------------------------------------------------------
311 void ItemsTable::Initialize() 328 void ItemsTable::Initialize()
312 { 329 {
330 std::map<std::string, ITEM_EQUIP_TYPE, ci_less> equipStatMap;
331 equipStatMap["weapon"] = EQUIP_SINGLE_HANDED;
332 equipStatMap["weapon2"] = EQUIP_TWO_HANDED;
333 equipStatMap["weapon1or2"] = EQUIP_SINGLE_HANDED;
334 equipStatMap["missile"] = EQUIP_BOW;
335 equipStatMap["bow"] = EQUIP_BOW;
336 equipStatMap["armor"] = EQUIP_ARMOUR;
337 equipStatMap["shield"] = EQUIP_SHIELD;
338 equipStatMap["helm"] = EQUIP_HELMET;
339 equipStatMap["belt"] = EQUIP_BELT;
340 equipStatMap["cloak"] = EQUIP_CLOAK;
341 equipStatMap["gauntlets"] = EQUIP_GAUNTLETS;
342 equipStatMap["boots"] = EQUIP_BOOTS;
343 equipStatMap["ring"] = EQUIP_RING;
344 equipStatMap["amulet"] = EQUIP_AMULET;
345 equipStatMap["weaponw"] = EQUIP_WAND;
346 equipStatMap["herb"] = EQUIP_REAGENT;
347 equipStatMap["reagent"] = EQUIP_REAGENT;
348 equipStatMap["bottle"] = EQUIP_POTION;
349 equipStatMap["sscroll"] = EQUIP_SPELL_SCROLL;
350 equipStatMap["book"] = EQUIP_BOOK;
351 equipStatMap["mscroll"] = EQUIP_MESSAGE_SCROLL;
352 equipStatMap["gold"] = EQUIP_GOLD;
353 equipStatMap["gem"] = EQUIP_GEM;
354
355 std::map<std::string, PLAYER_SKILL_TYPE, ci_less> equipSkillMap;
356 equipSkillMap["staff"] = PLAYER_SKILL_STAFF;
357 equipSkillMap["sword"] = PLAYER_SKILL_SWORD;
358 equipSkillMap["dagger"] = PLAYER_SKILL_DAGGER;
359 equipSkillMap["axe"] = PLAYER_SKILL_AXE;
360 equipSkillMap["spear"] = PLAYER_SKILL_SPEAR;
361 equipSkillMap["bow"] = PLAYER_SKILL_BOW;
362 equipSkillMap["mace"] = PLAYER_SKILL_MACE;
363 equipSkillMap["blaster"] = PLAYER_SKILL_BLASTER;
364 equipSkillMap["shield"] = PLAYER_SKILL_SHIELD;
365 equipSkillMap["leather"] = PLAYER_SKILL_LEATHER;
366 equipSkillMap["chain"] = PLAYER_SKILL_CHAIN;
367 equipSkillMap["plate"] = PLAYER_SKILL_PLATE;
368 equipSkillMap["club"] = PLAYER_SKILL_CLUB;
369
370 std::map<std::string, ITEM_MATERIAL, ci_less> materialMap;
371 materialMap["artifact"] = MATERIAL_ARTEFACT;
372 materialMap["relic"] = MATERIAL_RELIC;
373 materialMap["special"] = MATERIAL_SPECIAL;
374
313 int i,j; 375 int i,j;
314 char* test_string; 376 char* test_string;
315 unsigned char c; 377 unsigned char c;
316 bool break_loop; 378 bool break_loop;
317 unsigned int temp_str_len; 379 unsigned int temp_str_len;
346 strtok(NULL, "\r"); 408 strtok(NULL, "\r");
347 //Standard Bonuses by Group 409 //Standard Bonuses by Group
348 for (i=0;i<24;++i) 410 for (i=0;i<24;++i)
349 { 411 {
350 test_string = strtok(NULL, "\r") + 1; 412 test_string = strtok(NULL, "\r") + 1;
351 break_loop = false; 413 auto tokens = Tokenize(test_string, '\t');
352 decode_step=0; 414 pEnchantments[i].pBonusStat=RemoveQuotes(tokens[0]);
353 do 415 pEnchantments[i].pOfName=RemoveQuotes(tokens[1]);
354 { 416 for (int j = 0; j < 9; j++)
355 c = *(unsigned char*)test_string; 417 {
356 temp_str_len = 0; 418 pEnchantments[i].to_item[j]=atoi(tokens[j+2]);
357 while((c!='\t')&&(c>0)) 419 }
358 { 420 }
359 ++temp_str_len;
360 c=test_string[temp_str_len];
361 }
362 tmp_pos=test_string+temp_str_len;
363 if (*tmp_pos == 0)
364 break_loop = true;
365 *tmp_pos = 0;
366 if (temp_str_len)
367 {
368 switch (decode_step)
369 {
370 case 0:
371 pEnchantments[i].pBonusStat=RemoveQuotes(test_string);
372 break;
373 case 1:
374 pEnchantments[i].pOfName= RemoveQuotes(test_string);
375 break;
376 default:
377 pEnchantments[i].to_item[decode_step-2]=atoi(test_string);
378 }
379 }
380 else
381 {
382 if (decode_step)
383 break_loop = true;
384 }
385 ++decode_step;
386 test_string=tmp_pos+1;
387 } while ((decode_step<11)&&!break_loop);
388 }
389 421
390 memset(&pEnchantmentsSumm, 0, 36); 422 memset(&pEnchantmentsSumm, 0, 36);
391 for(i=0;i<9;++i) 423 for(i=0;i<9;++i)
392 { 424 {
393 for (j=0;j<24;++j) 425 for (j=0;j<24;++j)
399 strtok(NULL, "\r"); 431 strtok(NULL, "\r");
400 strtok(NULL, "\r"); 432 strtok(NULL, "\r");
401 strtok(NULL, "\r"); 433 strtok(NULL, "\r");
402 strtok(NULL, "\r"); 434 strtok(NULL, "\r");
403 for(i=0;i<6;++i) //counted from 1 435 for(i=0;i<6;++i) //counted from 1
404 { 436 {
405 test_string = strtok(NULL, "\r") + 1; 437 test_string = strtok(NULL, "\r") + 1;
406 break_loop = false; 438 auto tokens = Tokenize(test_string, '\t');
407 decode_step=0; 439 Assert(tokens.size() == 4, "Invalid number of tokens");
408 do 440 bonus_ranges[i].minR = atoi(tokens[2]);
409 { 441 bonus_ranges[i].maxR =atoi(tokens[3]);
410 c = *(unsigned char*)test_string; 442 }
411 temp_str_len = 0;
412 while((c!='\t')&&(c>0))
413 {
414 ++temp_str_len;
415 c=test_string[temp_str_len];
416 }
417 tmp_pos=test_string+temp_str_len;
418 if (*tmp_pos == 0)
419 break_loop = true;
420 *tmp_pos = 0;
421 if (decode_step==2)
422 bonus_ranges[i].minR = atoi(test_string);
423 else if (decode_step==3)
424 bonus_ranges[i].maxR =atoi(test_string);
425 ++decode_step;
426 test_string=tmp_pos+1;
427 } while ((decode_step<4)&&!break_loop);
428 }
429 443
430 444
431 pSpcItemsTXT_Raw = 0; 445 pSpcItemsTXT_Raw = 0;
432 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0); 446 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0);
433 strtok(pSpcItemsTXT_Raw, "\r"); 447 strtok(pSpcItemsTXT_Raw, "\r");
434 strtok(NULL, "\r"); 448 strtok(NULL, "\r");
435 strtok(NULL, "\r"); 449 strtok(NULL, "\r");
436 strtok(NULL, "\r"); 450 strtok(NULL, "\r");
437 for (i=0;i<72;++i) 451 for (i=0;i<72;++i)
438 { 452 {
439 test_string = strtok(NULL, "\r") + 1; 453 test_string = strtok(NULL, "\r") + 1;
440 break_loop = false; 454 auto tokens = Tokenize(test_string, '\t');
441 decode_step=0; 455 Assert(tokens.size() == 17, "Invalid number of tokens");
442 do 456 pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]);
443 { 457 pSpecialEnchantments[i].pNameAdd= RemoveQuotes(tokens[1]);
444 c = *(unsigned char*)test_string; 458 for (int i = 0; i < 12; i++)
445 temp_str_len = 0; 459 {
446 while((c!='\t')&&(c>0)) 460 pSpecialEnchantments[i].to_item_apply[i]=atoi(tokens[i+2]);
447 { 461 }
448 ++temp_str_len; 462 int res;
449 c=test_string[temp_str_len]; 463 res=atoi(tokens[14]);
450 } 464 if(!res)
451 tmp_pos=test_string+temp_str_len; 465 {
452 if (*tmp_pos == 0) 466 ++tokens[14];
453 break_loop = true; 467 while (*tokens[14]==' ')//fix X 2 case
454 *tmp_pos = 0; 468 ++tokens[14];
455 if (temp_str_len) 469 res=atoi(tokens[14]);
456 { 470 }
457 switch (decode_step) 471 pSpecialEnchantments[i].iValue=res;
458 { 472 pSpecialEnchantments[i].iTreasureLevel= tolower(tokens[15][0]) - 97;
459 case 0: 473 }
460 pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(test_string);
461 break;
462 case 1:
463 pSpecialEnchantments[i].pNameAdd= RemoveQuotes(test_string);
464 break;
465 case 14:
466 int res;
467 res=atoi(test_string);
468 if(!res)
469 {
470 ++test_string;
471 while (*test_string==' ')//fix X 2 case
472 ++test_string;
473 res=atoi(test_string);
474 }
475 pSpecialEnchantments[i].iValue=res;
476 break;
477 case 15:
478 pSpecialEnchantments[i].iTreasureLevel= tolower(*test_string) - 97;;
479 break;
480 default:
481 pSpecialEnchantments[i].to_item_apply[decode_step-2]=atoi(test_string);
482 }
483 }
484 else
485 {
486 if (decode_step)
487 break_loop = true;
488 }
489 ++decode_step;
490 test_string=tmp_pos+1;
491 } while ((decode_step<16)&&!break_loop);
492 }
493 474
494 pSpecialEnchantments_count = 71; 475 pSpecialEnchantments_count = 71;
495 memset(&pSpecialEnchantmentsSumm, 0, 96); 476 memset(&pSpecialEnchantmentsSumm, 0, 96);
496 for(i=0;i<12;++i) 477 for(i=0;i<12;++i)
497 { 478 {
505 pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0); 486 pItemsTXT_Raw = (char*) pEvents_LOD->LoadRaw("items.txt", 0);
506 strtok(pItemsTXT_Raw, "\r"); 487 strtok(pItemsTXT_Raw, "\r");
507 strtok(NULL, "\r"); 488 strtok(NULL, "\r");
508 uAllItemsCount = 0; 489 uAllItemsCount = 0;
509 item_counter = 0; 490 item_counter = 0;
510 while (true) 491 while (item_counter < 800)
511 { 492 {
512 test_string = strtok(NULL, "\r") + 1; 493 test_string = strtok(NULL, "\r") + 1;
513 break_loop = false; 494 auto tokens = Tokenize(test_string, '\t');
514 decode_step=0; 495 item_counter=atoi(tokens[0]);
515 do 496 uAllItemsCount=item_counter;
516 { 497 pItems[item_counter].pIconName = RemoveQuotes(tokens[1]);
517 c = *(unsigned char*)test_string; 498 pItems[item_counter].pName = RemoveQuotes(tokens[2]);
518 temp_str_len = 0; 499 pItems[item_counter].uValue=atoi(tokens[3]);
519 while((c!='\t')&&(c>0)) 500 auto findResult = equipStatMap.find(tokens[4]);
520 { 501 pItems[item_counter].uEquipType = findResult == equipStatMap.end() ? EQUIP_NONE : findResult->second;
521 ++temp_str_len; 502 auto findResult2 = equipSkillMap.find(tokens[5]);
522 c=test_string[temp_str_len]; 503 pItems[item_counter].uSkillType = findResult2 == equipSkillMap.end() ? PLAYER_SKILL_MISC : findResult->second;
523 } 504 auto tokens2 = Tokenize(tokens[6], 'd');
524 tmp_pos=test_string+temp_str_len; 505 if (tokens2.size() == 2)
525 if (*tmp_pos == 0) 506 {
526 break_loop = true; 507 pItems[item_counter].uDamageDice=atoi(tokens2[0]);
527 *tmp_pos = 0; 508 pItems[item_counter].uDamageRoll=atoi(tokens2[1]);
528 if (temp_str_len) 509 }
529 { 510 else if (tolower(test_string[0]) != 's')
530 switch (decode_step) 511 {
531 { 512 pItems[item_counter].uDamageDice=atoi(test_string);
532 case 0: //Item # 513 pItems[item_counter].uDamageRoll=1;
533 item_counter=atoi(test_string); 514 }
534 uAllItemsCount=item_counter; 515 else
535 break; 516 {
536 case 1: //Pic File 517 pItems[item_counter].uDamageDice=0;
537 pItems[item_counter].pIconName = RemoveQuotes(test_string); 518 pItems[item_counter].uDamageRoll=0;
538 break; 519 }
539 case 2: //Name 520 pItems[item_counter].uDamageMod=atoi(tokens[7]);
540 pItems[item_counter].pName = RemoveQuotes(test_string); 521 auto findResult3 = materialMap.find(tokens[8]);
541 break; 522 pItems[item_counter].uSkillType = findResult3 == materialMap.end() ? MATERIAL_COMMON : findResult->second;
542 case 3: //Value 523 pItems[item_counter].uItemID_Rep_St=atoi(tokens[9]);
543 pItems[item_counter].uValue=atoi(test_string); 524 pItems[item_counter].pUnidentifiedName = RemoveQuotes(tokens[10]);
544 break; 525 pItems[item_counter].uSpriteID=atoi(tokens[11]);
545 case 4: //Equip Stat 526
546 { 527 pItems[item_counter]._additional_value=0;
547 if ( !_stricmp(test_string, "weapon") ) 528 pItems[item_counter]._bonus_type=0;
548 { 529 if (pItems[item_counter].uMaterial==MATERIAL_SPECIAL)
549 pItems[item_counter].uEquipType = EQUIP_SINGLE_HANDED; 530 {
550 break; 531 for(int ii=0; ii<24; ++ii)
551 } 532 {
552 if ( !_stricmp(test_string, "weapon2") ) 533 if (!_stricmp(tokens[12],pEnchantments[ii].pOfName))
553 { 534 {
554 pItems[item_counter].uEquipType = EQUIP_TWO_HANDED; 535 pItems[item_counter]._bonus_type=ii+1;
555 break; 536 break;
556 } 537 }
557 if ( !_stricmp(test_string, "weapon1or2") ) 538 }
558 { 539 if (!pItems[item_counter]._bonus_type)
559 pItems[item_counter].uEquipType = EQUIP_SINGLE_HANDED; 540 {
560 break; 541 for(int ii=0; ii<72; ++ii)
561 } 542 {
562 if ( !(_stricmp(test_string, "missile")&&_stricmp(test_string, "bow"))) 543 if (!_stricmp(tokens[12],pSpecialEnchantments[ii].pNameAdd))
563 { 544 {
564 pItems[item_counter].uEquipType = EQUIP_BOW; 545 pItems[item_counter]._additional_value=ii+1;
565 break; 546 }
566 } 547 }
567 if ( !_stricmp(test_string, "armor") ) 548 }
568 { 549 }
569 pItems[item_counter].uEquipType = EQUIP_ARMOUR; 550
570 break; 551 if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type))
571 } 552 {
572 if ( !_stricmp(test_string, "shield") ) 553 char b_s=atoi(tokens[13]);
573 { 554 if (b_s)
574 pItems[item_counter].uEquipType = EQUIP_SHIELD; 555 pItems[item_counter]._bonus_strength=b_s;
575 break; 556 else
576 } 557 pItems[item_counter]._bonus_strength=1;
577 if ( !_stricmp(test_string, "helm") ) 558 }
578 { 559 else
579 pItems[item_counter].uEquipType = EQUIP_HELMET; 560 pItems[item_counter]._bonus_strength=0;
580 break; 561 pItems[item_counter].uEquipX=atoi(tokens[14]);
581 } 562 pItems[item_counter].uEquipY=atoi(tokens[15]);
582 if ( !_stricmp(test_string, "belt") ) 563 pItems[item_counter].pDescription = RemoveQuotes(tokens[16]);
583 { 564 item_counter++;
584 pItems[item_counter].uEquipType = EQUIP_BELT; 565 }
585 break;
586 }
587 if ( !_stricmp(test_string, "cloak") )
588 {
589 pItems[item_counter].uEquipType = EQUIP_CLOAK;
590 break;
591 }
592 if ( !_stricmp(test_string, "gauntlets") )
593 {
594 pItems[item_counter].uEquipType = EQUIP_GAUNTLETS;
595 break;
596 }
597 if ( !_stricmp(test_string, "boots") )
598 {
599 pItems[item_counter].uEquipType = EQUIP_BOOTS;
600 break;
601 }
602 if ( !_stricmp(test_string, "ring") )
603 {
604 pItems[item_counter].uEquipType = EQUIP_RING;
605 break;
606 }
607 if ( !_stricmp(test_string, "amulet") )
608 {
609 pItems[item_counter].uEquipType = EQUIP_AMULET;
610 break;
611 }
612 if ( !_stricmp(test_string, "weaponw") )
613 {
614 pItems[item_counter].uEquipType = EQUIP_WAND;
615 break;
616 }
617 if ( !(_stricmp(test_string, "herb")&&_stricmp(test_string, "reagent")))
618 {
619 pItems[item_counter].uEquipType = EQUIP_REAGENT;
620 break;
621 }
622 if ( !_stricmp(test_string, "bottle") )
623 {
624 pItems[item_counter].uEquipType = EQUIP_POTION;
625 break;
626 }
627 if ( !_stricmp(test_string, "sscroll") )
628 {
629 pItems[item_counter].uEquipType = EQUIP_SPELL_SCROLL;
630 break;
631 }
632 if ( !_stricmp(test_string, "book") )
633 {
634 pItems[item_counter].uEquipType = EQUIP_BOOK;
635 break;
636 }
637 if ( !_stricmp(test_string, "mscroll") )
638 {
639 pItems[item_counter].uEquipType = EQUIP_MESSAGE_SCROLL;
640 break;
641 }
642 if ( !_stricmp(test_string, "gold") )
643 {
644 pItems[item_counter].uEquipType = EQUIP_GOLD;
645 break;
646 }
647 if ( !_stricmp(test_string, "gem") )
648 {
649 pItems[item_counter].uEquipType = EQUIP_GEM;
650 break;
651 }
652 pItems[item_counter].uEquipType = EQUIP_NONE;
653 break;
654 }
655 case 5: //Skill Group
656 {
657 if ( !_stricmp(test_string, "staff") )
658 {
659 pItems[item_counter].uSkillType = PLAYER_SKILL_STAFF;
660 break;
661 }
662 if ( !_stricmp(test_string, "sword") )
663 {
664 pItems[item_counter].uSkillType = PLAYER_SKILL_SWORD;
665 break;
666 }
667 if ( !_stricmp(test_string, "dagger") )
668 {
669 pItems[item_counter].uSkillType = PLAYER_SKILL_DAGGER;
670 break;
671 }
672 if ( !_stricmp(test_string, "axe") )
673 {
674 pItems[item_counter].uSkillType = PLAYER_SKILL_AXE;
675 break;
676 }
677 if ( !_stricmp(test_string, "spear") )
678 {
679 pItems[item_counter].uSkillType = PLAYER_SKILL_SPEAR;
680 break;
681 }
682 if ( !_stricmp(test_string, "bow") )
683 {
684 pItems[item_counter].uSkillType = PLAYER_SKILL_BOW;
685 break;
686 }
687 if ( !_stricmp(test_string, "mace") )
688 {
689 pItems[item_counter].uSkillType = PLAYER_SKILL_MACE;
690 break;
691 }
692 if ( !_stricmp(test_string, "blaster") )
693 {
694 pItems[item_counter].uSkillType = PLAYER_SKILL_BLASTER;
695 break;
696 }
697 if ( !_stricmp(test_string, "shield") )
698 {
699 pItems[item_counter].uSkillType = PLAYER_SKILL_SHIELD;
700 break;
701 }
702 if ( !_stricmp(test_string, "leather") )
703 {
704 pItems[item_counter].uSkillType = PLAYER_SKILL_LEATHER;
705 break;
706 }
707 if ( !_stricmp(test_string, "chain") )
708 {
709 pItems[item_counter].uSkillType = PLAYER_SKILL_CHAIN;
710 break;
711 }
712 if ( !_stricmp(test_string, "plate") )
713 {
714 pItems[item_counter].uSkillType = PLAYER_SKILL_PLATE;
715 break;
716 }
717 if ( !_stricmp(test_string, "club") )
718 {
719 pItems[item_counter].uSkillType = PLAYER_SKILL_CLUB;
720 break;
721 }
722 pItems[item_counter].uSkillType = PLAYER_SKILL_MISC;
723 break;
724 }
725 case 6: //Mod1
726 {
727 int ii;
728 char* test_char;
729 int tst_len;
730 tst_len=strlen(test_string);
731 pItems[item_counter].uDamageDice=0;
732 pItems[item_counter].uDamageRoll=0;
733 test_char=test_string;
734 for (ii=0; ii<tst_len; ++ii)
735 {
736 if (tolower(*test_char)=='d')
737 {
738 *test_char=0;
739 pItems[item_counter].uDamageDice=atoi(test_string);
740 pItems[item_counter].uDamageRoll=atoi(test_char+1);
741 *test_char='d';
742 break;
743 }
744 ++test_char;
745 }
746 test_char=test_string;
747 if ((ii==tst_len)&&(tolower(*test_char)!='s'))
748 {
749 pItems[item_counter].uDamageDice=atoi(test_char);
750 pItems[item_counter].uDamageRoll=1;
751 }
752 break;
753 }
754 case 7: //Mod2
755 pItems[item_counter].uDamageMod=atoi(test_string);
756 break;
757 case 8: //material
758 {
759 if ( !_stricmp(test_string, "artifact") )
760 {
761 pItems[item_counter].uMaterial = MATERIAL_ARTEFACT;
762 break;
763 }
764 if ( !_stricmp(test_string, "relic") )
765 {
766 pItems[item_counter].uMaterial = MATERIAL_RELIC;
767 break;
768 }
769 if ( !_stricmp(test_string, "special") )
770 {
771 pItems[item_counter].uMaterial = MATERIAL_SPECIAL;
772 break;
773 }
774 pItems[item_counter].uMaterial = MATERIAL_COMMON;
775 break;}
776 case 9: //ID/Rep/St
777 pItems[item_counter].uItemID_Rep_St=atoi(test_string);
778 break;
779 case 10: //Not identified name
780 pItems[item_counter].pUnidentifiedName = RemoveQuotes(test_string);
781 break;
782 case 11: //Sprite Index
783 pItems[item_counter].uSpriteID=atoi(test_string);
784 break;
785 case 12: //VarA
786 {
787 pItems[item_counter]._additional_value=0;
788 pItems[item_counter]._bonus_type=0;
789 if (pItems[item_counter].uMaterial==MATERIAL_SPECIAL)
790 {
791 for(int ii=0; ii<24; ++ii)
792 {
793 if (!_stricmp(test_string,pEnchantments[ii].pOfName))
794 {
795 pItems[item_counter]._bonus_type=ii+1;
796 break;
797 }
798 }
799 if (!pItems[item_counter]._bonus_type)
800 {
801 for(int ii=0; ii<72; ++ii)
802 {
803 if (!_stricmp(test_string,pSpecialEnchantments[ii].pNameAdd))
804 {
805 pItems[item_counter]._additional_value=ii+1;
806 }
807 }
808 }
809 }
810
811 break;
812 }
813 case 13: //VarB
814 if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type))
815 {
816 char b_s=atoi(test_string);
817 if (b_s)
818 pItems[item_counter]._bonus_strength=b_s;
819 else
820 pItems[item_counter]._bonus_strength=1;
821 }
822 else
823 pItems[item_counter]._bonus_strength=0;
824 break;
825 case 14: //Equip X
826 pItems[item_counter].uEquipX=atoi(test_string);
827 break;
828 case 15: //Equip Y
829 pItems[item_counter].uEquipY=atoi(test_string);
830 break;
831 case 16: //Notes
832 pItems[item_counter].pDescription = RemoveQuotes(test_string);
833 break;
834
835 }
836 }
837 else
838 {
839 if (decode_step)
840 break_loop = true;
841 }
842 ++decode_step;
843 test_string=tmp_pos+1;
844 } while ((decode_step<17)&&!break_loop);
845 ++item_counter;
846 if (item_counter>799)
847 break;
848 }
849 566
850 567
851 pRndItemsTXT_Raw = NULL; 568 pRndItemsTXT_Raw = NULL;
852 uAllItemsCount = item_counter; 569 uAllItemsCount = item_counter;
853 pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0); 570 pRndItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("rnditems.txt", 0);
854 strtok(pRndItemsTXT_Raw, "\r"); 571 strtok(pRndItemsTXT_Raw, "\r");
855 strtok(NULL, "\r"); 572 strtok(NULL, "\r");
856 strtok(NULL, "\r"); 573 strtok(NULL, "\r");
857 strtok(NULL, "\r"); 574 strtok(NULL, "\r");
858 item_counter = 0; 575 for (int item_counter = 0; item_counter < 619; item_counter++)
859 while (true)
860 { 576 {
861 test_string = strtok(NULL, "\r") + 1; 577 test_string = strtok(NULL, "\r") + 1;
862 break_loop = false; 578 auto tokens = Tokenize(test_string, '\t');
863 decode_step=0; 579 Assert(tokens.size() > 7, "Invalid number of tokens");
864 do 580 item_counter = atoi(tokens[0]);
865 { 581 pItems[item_counter].uChanceByTreasureLvl1=atoi(tokens[2]);
866 c = *(unsigned char*)test_string; 582 pItems[item_counter].uChanceByTreasureLvl2=atoi(tokens[3]);
867 temp_str_len = 0; 583 pItems[item_counter].uChanceByTreasureLvl3=atoi(tokens[4]);
868 while((c!='\t')&&(c>0)) 584 pItems[item_counter].uChanceByTreasureLvl4=atoi(tokens[5]);
869 { 585 pItems[item_counter].uChanceByTreasureLvl5=atoi(tokens[6]);
870 ++temp_str_len; 586 pItems[item_counter].uChanceByTreasureLvl6=atoi(tokens[7]);
871 c=test_string[temp_str_len]; 587 }
872 }
873 tmp_pos=test_string+temp_str_len;
874 if (*tmp_pos == 0)
875 break_loop = true;
876 *tmp_pos = 0;
877 if (temp_str_len)
878 {
879 switch (decode_step)
880 {
881 case 0:
882 item_counter=atoi(test_string);
883 break;
884 case 2:
885 pItems[item_counter].uChanceByTreasureLvl1=atoi(test_string);
886 break;
887 case 3:
888 pItems[item_counter].uChanceByTreasureLvl2=atoi(test_string);
889 break;
890 case 4:
891 pItems[item_counter].uChanceByTreasureLvl3=atoi(test_string);
892 break;
893 case 5:
894 pItems[item_counter].uChanceByTreasureLvl4=atoi(test_string);
895 break;
896 case 6:
897 pItems[item_counter].uChanceByTreasureLvl5=atoi(test_string);
898 break;
899 case 7:
900 pItems[item_counter].uChanceByTreasureLvl6=atoi(test_string);
901 break;
902 }
903 }
904 else
905 {
906 if (decode_step)
907 break_loop = true;
908 }
909 ++decode_step;
910 test_string=tmp_pos+1;
911 } while ((decode_step<8)&&!break_loop);
912 ++item_counter;
913 if (item_counter>618)
914 break;
915 }
916 588
917 //ChanceByTreasureLvl Summ - to calculate chance 589 //ChanceByTreasureLvl Summ - to calculate chance
918 memset(&uChanceByTreasureLvlSumm, 0, 24); 590 memset(&uChanceByTreasureLvlSumm, 0, 24);
919 for(i=0;i<6;++i) 591 for(i=0;i<6;++i)
920 { 592 {
928 strtok(NULL, "\r"); 600 strtok(NULL, "\r");
929 strtok(NULL, "\r"); 601 strtok(NULL, "\r");
930 for (i=0;i<3;++i) 602 for (i=0;i<3;++i)
931 { 603 {
932 test_string = strtok(NULL, "\r") + 1; 604 test_string = strtok(NULL, "\r") + 1;
933 break_loop = false; 605 auto tokens = Tokenize(test_string, '\t');
934 decode_step=0; 606 Assert(tokens.size() > 7, "Invalid number of tokens");
935 do 607 switch (i)
936 { 608 {
937 c = *(unsigned char*)test_string; 609 case 0:
938 temp_str_len = 0; 610 uBonusChanceStandart[0]=atoi(tokens[2]);
939 while((c!='\t')&&(c>0)) 611 uBonusChanceStandart[1]=atoi(tokens[3]);
940 { 612 uBonusChanceStandart[2]=atoi(tokens[4]);
941 ++temp_str_len; 613 uBonusChanceStandart[3]=atoi(tokens[5]);
942 c=test_string[temp_str_len]; 614 uBonusChanceStandart[4]=atoi(tokens[6]);
943 } 615 uBonusChanceStandart[5]=atoi(tokens[7]);
944 tmp_pos=test_string+temp_str_len; 616 break;
945 if (*tmp_pos == 0) 617 case 1:
946 break_loop = true; 618 uBonusChanceSpecial[0]=atoi(tokens[2]);
947 *tmp_pos = 0; 619 uBonusChanceSpecial[1]=atoi(tokens[3]);
948 if (temp_str_len) 620 uBonusChanceSpecial[2]=atoi(tokens[4]);
949 { 621 uBonusChanceSpecial[3]=atoi(tokens[5]);
950 switch (decode_step) 622 uBonusChanceSpecial[4]=atoi(tokens[6]);
951 { 623 uBonusChanceSpecial[5]=atoi(tokens[7]);
952 case 2: 624 break;
953 switch (i) 625 case 2:
954 { 626 uBonusChanceWpSpecial[0]=atoi(tokens[2]);
955 case 0: 627 uBonusChanceWpSpecial[1]=atoi(tokens[3]);
956 uBonusChanceStandart[0]=atoi(test_string); 628 uBonusChanceWpSpecial[2]=atoi(tokens[4]);
957 break; 629 uBonusChanceWpSpecial[3]=atoi(tokens[5]);
958 case 1: 630 uBonusChanceWpSpecial[4]=atoi(tokens[6]);
959 uBonusChanceSpecial[0]=atoi(test_string); 631 uBonusChanceWpSpecial[5]=atoi(tokens[7]);
960 break; 632 break;
961 case 2: 633 }
962 uBonusChanceWpSpecial[0]=atoi(test_string);
963 break;
964 }
965 break;
966 case 3:
967 switch (i)
968 {
969 case 0:
970 uBonusChanceStandart[1]=atoi(test_string);
971 break;
972 case 1:
973 uBonusChanceSpecial[1]=atoi(test_string);
974 break;
975 case 2:
976 uBonusChanceWpSpecial[1]=atoi(test_string);
977 break;
978 }
979 break;
980 case 4:
981 switch (i)
982 {
983 case 0:
984 uBonusChanceStandart[2]=atoi(test_string);
985 break;
986 case 1:
987 uBonusChanceSpecial[2]=atoi(test_string);
988 break;
989 case 2:
990 uBonusChanceWpSpecial[2]=atoi(test_string);
991 break;
992 }
993 break;
994 case 5:
995 switch (i)
996 {
997 case 0:
998 uBonusChanceStandart[3]=atoi(test_string);
999 break;
1000 case 1:
1001 uBonusChanceSpecial[3]=atoi(test_string);
1002 break;
1003 case 2:
1004 uBonusChanceWpSpecial[3]=atoi(test_string);
1005 break;
1006 }
1007 break;
1008 case 6:
1009 switch (i)
1010 {
1011 case 0:
1012 uBonusChanceStandart[4]=atoi(test_string);
1013 break;
1014 case 1:
1015 uBonusChanceSpecial[4]=atoi(test_string);
1016 break;
1017 case 2:
1018 uBonusChanceWpSpecial[4]=atoi(test_string);
1019 break;
1020 }
1021 break;
1022 case 7:
1023 switch (i)
1024 {
1025 case 0:
1026 uBonusChanceStandart[5]=atoi(test_string);
1027 break;
1028 case 1:
1029 uBonusChanceSpecial[5]=atoi(test_string);
1030 break;
1031 case 2:
1032 uBonusChanceWpSpecial[5]=atoi(test_string);
1033 break;
1034 }
1035 break;
1036 }
1037 }
1038 else
1039 {
1040 if (decode_step)
1041 break_loop = true;
1042 }
1043 ++decode_step;
1044 test_string=tmp_pos+1;
1045 } while ((decode_step<8)&&!break_loop);
1046 } 634 }
1047 635
1048 if ( pRndItemsTXT_Raw ) 636 if ( pRndItemsTXT_Raw )
1049 { 637 {
1050 free(pRndItemsTXT_Raw); 638 free(pRndItemsTXT_Raw);
1055 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0); 643 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0);
1056 strtok(pSkillDescTXT_Raw, "\r"); 644 strtok(pSkillDescTXT_Raw, "\r");
1057 for (i=0; i<37; ++i) 645 for (i=0; i<37; ++i)
1058 { 646 {
1059 test_string = strtok(NULL, "\r") + 1; 647 test_string = strtok(NULL, "\r") + 1;
1060 break_loop = false; 648 auto tokens = Tokenize(test_string, '\t');
1061 decode_step=0; 649 Assert(tokens.size() == 6, "Invalid number of tokens");
1062 do 650 pSkillDesc[i] = RemoveQuotes(tokens[1]);
1063 { 651 pNormalSkillDesc[i] = RemoveQuotes(tokens[2]);
1064 c = *(unsigned char*)test_string; 652 pExpertSkillDesc[i] = RemoveQuotes(tokens[3]);
1065 temp_str_len = 0; 653 pMasterSkillDesc[i] = RemoveQuotes(tokens[4]);
1066 while((c!='\t')&&(c>0)) 654 pGrandSkillDesc[i] = RemoveQuotes(tokens[5]);
1067 { 655 }
1068 ++temp_str_len;
1069 c=test_string[temp_str_len];
1070 }
1071 tmp_pos=test_string+temp_str_len;
1072 if (*tmp_pos == 0)
1073 break_loop = true;
1074 *tmp_pos = 0;
1075 if (temp_str_len)
1076 {
1077 switch (decode_step)
1078 {
1079 case 1:
1080 pSkillDesc[i] = RemoveQuotes(test_string);
1081 break;
1082 case 2:
1083 pNormalSkillDesc[i] = RemoveQuotes(test_string);
1084 break;
1085 case 3:
1086 pExpertSkillDesc[i] = RemoveQuotes(test_string);
1087 break;
1088 case 4:
1089 pMasterSkillDesc[i] = RemoveQuotes(test_string);
1090 break;
1091 case 5:
1092 pGrandSkillDesc[i] = RemoveQuotes(test_string);
1093 break;
1094 }
1095 }
1096 else
1097 {
1098 if (decode_step)
1099 break_loop = true;
1100 }
1101 ++decode_step;
1102 test_string=tmp_pos+1;
1103 } while ((decode_step<6)&&!break_loop);
1104 }
1105 656
1106 pStatsTXT_Raw = 0; 657 pStatsTXT_Raw = 0;
1107 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0); 658 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0);
1108 strtok(pStatsTXT_Raw, "\r"); 659 strtok(pStatsTXT_Raw, "\r");
1109 for (i=0; i<26; ++i) 660 for (i=0; i<26; ++i)
1110 { 661 {
1111 test_string = strtok(NULL, "\r") + 1; 662 test_string = strtok(NULL, "\r") + 1;
1112 break_loop = false; 663 auto tokens = Tokenize(test_string, '\t');
1113 decode_step=0; 664 Assert(tokens.size() == 2, "Invalid number of tokens");
1114 do 665 switch (i)
1115 { 666 {
1116 c = *(unsigned char*)test_string; 667 case 0:
1117 temp_str_len = 0; 668 case 1:
1118 while((c!='\t')&&(c>0)) 669 case 2:
1119 { 670 case 3:
1120 ++temp_str_len; 671 case 4:
1121 c=test_string[temp_str_len]; 672 case 5:
1122 } 673 case 6:
1123 tmp_pos=test_string+temp_str_len; 674 pAttributeDescriptions[i] = RemoveQuotes(tokens[1]);
1124 if (*tmp_pos == 0) 675 break;
1125 break_loop = true; 676 case 7:
1126 *tmp_pos = 0; 677 pHealthPointsAttributeDescription = RemoveQuotes(tokens[1]);
1127 if (temp_str_len) 678 break;
1128 { 679 case 8:
1129 switch (i) 680 pArmourClassAttributeDescription = RemoveQuotes(tokens[1]);
1130 { 681 break;
1131 case 0: 682 case 9:
1132 case 1: 683 pSpellPointsAttributeDescription = RemoveQuotes(tokens[1]);
1133 case 2: 684 break;
1134 case 3: 685 case 10:
1135 case 4: 686 pPlayerConditionAttributeDescription = RemoveQuotes(tokens[1]);
1136 case 5: 687 break;
1137 case 6: 688 case 11:
1138 pAttributeDescriptions[i] = RemoveQuotes(test_string); 689 pFastSpellAttributeDescription = RemoveQuotes(tokens[1]);
1139 break; 690 break;
1140 case 7: 691 case 12:
1141 pHealthPointsAttributeDescription = RemoveQuotes(test_string); 692 pPlayerAgeAttributeDescription = RemoveQuotes(tokens[1]);
1142 break; 693 break;
1143 case 8: 694 case 13:
1144 pArmourClassAttributeDescription = RemoveQuotes(test_string); 695 pPlayerLevelAttributeDescription = RemoveQuotes(tokens[1]);
1145 break; 696 break;
1146 case 9: 697 case 14:
1147 pSpellPointsAttributeDescription = RemoveQuotes(test_string); 698 pPlayerExperienceAttributeDescription = RemoveQuotes(tokens[1]);
1148 break; 699 break;
1149 case 10: 700 case 15:
1150 pPlayerConditionAttributeDescription = RemoveQuotes(test_string); 701 pAttackBonusAttributeDescription = RemoveQuotes(tokens[1]);
1151 break; 702 break;
1152 case 11: 703 case 16:
1153 pFastSpellAttributeDescription = RemoveQuotes(test_string); 704 pAttackDamageAttributeDescription = RemoveQuotes(tokens[1]);
1154 break; 705 break;
1155 case 12: 706 case 17:
1156 pPlayerAgeAttributeDescription = RemoveQuotes(test_string); 707 pMissleBonusAttributeDescription = RemoveQuotes(tokens[1]);
1157 break; 708 break;
1158 case 13: 709 case 18:
1159 pPlayerLevelAttributeDescription = RemoveQuotes(test_string); 710 pMissleDamageAttributeDescription = RemoveQuotes(tokens[1]);
1160 break; 711 break;
1161 case 14: 712 case 19:
1162 pPlayerExperienceAttributeDescription = RemoveQuotes(test_string); 713 pFireResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1163 break; 714 break;
1164 case 15: 715 case 20:
1165 pAttackBonusAttributeDescription = RemoveQuotes(test_string); 716 pAirResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1166 break; 717 break;
1167 case 16: 718 case 21:
1168 pAttackDamageAttributeDescription = RemoveQuotes(test_string); 719 pWaterResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1169 break; 720 break;
1170 case 17: 721 case 22:
1171 pMissleBonusAttributeDescription = RemoveQuotes(test_string); 722 pEarthResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1172 break; 723 break;
1173 case 18: 724 case 23:
1174 pMissleDamageAttributeDescription = RemoveQuotes(test_string); 725 pMindResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1175 break; 726 break;
1176 case 19: 727 case 24:
1177 pFireResistanceAttributeDescription = RemoveQuotes(test_string); 728 pBodyResistanceAttributeDescription = RemoveQuotes(tokens[1]);
1178 break; 729 break;
1179 case 20: 730 case 25:
1180 pAirResistanceAttributeDescription = RemoveQuotes(test_string); 731 pSkillPointsAttributeDescription = RemoveQuotes(tokens[1]);
1181 break; 732 break;
1182 case 21: 733 }
1183 pWaterResistanceAttributeDescription = RemoveQuotes(test_string); 734 }
1184 break; 735
1185 case 22:
1186 pEarthResistanceAttributeDescription = RemoveQuotes(test_string);
1187 break;
1188 case 23:
1189 pMindResistanceAttributeDescription = RemoveQuotes(test_string);
1190 break;
1191 case 24:
1192 pBodyResistanceAttributeDescription = RemoveQuotes(test_string);
1193 break;
1194 case 25:
1195 pSkillPointsAttributeDescription = RemoveQuotes(test_string);
1196 break;
1197 }
1198 }
1199 else
1200 {
1201 if (decode_step)
1202 break_loop = true;
1203 }
1204 ++decode_step;
1205 test_string=tmp_pos+1;
1206 } while ((decode_step<2)&&!break_loop);
1207 }
1208
1209
1210 pClassTXT_Raw = 0; 736 pClassTXT_Raw = 0;
1211 pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0); 737 pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0);
1212 strtok(pClassTXT_Raw, "\r"); 738 strtok(pClassTXT_Raw, "\r");
1213 for (i=0; i<36; ++i) 739 for (i=0; i<36; ++i)
1214 { 740 {
1215 test_string = strtok(NULL, "\r") + 1; 741 test_string = strtok(NULL, "\r") + 1;
1216 break_loop = false; 742 auto tokens = Tokenize(test_string, '\t');
1217 decode_step=0; 743 Assert(tokens.size() == 3, "Invalid number of tokens");
1218 do 744 pClassDescriptions[i]=RemoveQuotes(tokens[1]);
1219 { 745 }
1220 c = *(unsigned char*)test_string;
1221 temp_str_len = 0;
1222 while((c!='\t')&&(c>0))
1223 {
1224 ++temp_str_len;
1225 c=test_string[temp_str_len];
1226 }
1227 tmp_pos=test_string+temp_str_len;
1228 if (*tmp_pos == 0)
1229 break_loop = true;
1230 *tmp_pos = 0;
1231 if (temp_str_len)
1232 {
1233 //if(i)
1234 pClassDescriptions[i]=RemoveQuotes(test_string);
1235 }
1236 else
1237 {
1238 if (decode_step)
1239 break_loop = true;
1240 }
1241 ++decode_step;
1242 test_string=tmp_pos+1;
1243 } while ((decode_step<2)&&!break_loop);
1244 }
1245 746
1246 747
1247 748
1248 ItemGen::PopulateSpecialBonusMap(); 749 ItemGen::PopulateSpecialBonusMap();
1249 ItemGen::PopulateArtifactBonusMap(); 750 ItemGen::PopulateArtifactBonusMap();