comparison Items.cpp @ 2282:f5680ba9c96d

SpellStats::Initialize using tokenizer
author Grumpy7
date Fri, 14 Mar 2014 23:06:24 +0100
parents b13ab8114e5d
children 40c4065234f8
comparison
equal deleted inserted replaced
2281:d8b4a36f54a4 2282:f5680ba9c96d
12 #include "Party.h" 12 #include "Party.h"
13 #include "FactionTable.h" 13 #include "FactionTable.h"
14 #include "StorylineTextTable.h" 14 #include "StorylineTextTable.h"
15 #include "texts.h" 15 #include "texts.h"
16 #include "mm7_data.h" 16 #include "mm7_data.h"
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 };
34 17
35 18
36 struct ITEM_VARIATION 19 struct ITEM_VARIATION
37 { 20 {
38 unsigned __int16 treasure_level; 21 unsigned __int16 treasure_level;
370 std::map<std::string, ITEM_MATERIAL, ci_less> materialMap; 353 std::map<std::string, ITEM_MATERIAL, ci_less> materialMap;
371 materialMap["artifact"] = MATERIAL_ARTEFACT; 354 materialMap["artifact"] = MATERIAL_ARTEFACT;
372 materialMap["relic"] = MATERIAL_RELIC; 355 materialMap["relic"] = MATERIAL_RELIC;
373 materialMap["special"] = MATERIAL_SPECIAL; 356 materialMap["special"] = MATERIAL_SPECIAL;
374 357
375 int i,j;
376 char* test_string; 358 char* test_string;
377 int item_counter; 359 int item_counter;
378 360
379 pMapStats = new MapStats; 361 pMapStats = new MapStats;
380 pMapStats->Initialize(); 362 pMapStats->Initialize();
400 strtok(pStdItemsTXT_Raw, "\r"); 382 strtok(pStdItemsTXT_Raw, "\r");
401 strtok(NULL, "\r"); 383 strtok(NULL, "\r");
402 strtok(NULL, "\r"); 384 strtok(NULL, "\r");
403 strtok(NULL, "\r"); 385 strtok(NULL, "\r");
404 //Standard Bonuses by Group 386 //Standard Bonuses by Group
405 for (i=0;i<24;++i) 387 for (int i=0;i<24;++i)
406 { 388 {
407 test_string = strtok(NULL, "\r") + 1; 389 test_string = strtok(NULL, "\r") + 1;
408 auto tokens = Tokenize(test_string, '\t'); 390 auto tokens = Tokenize(test_string, '\t');
409 pEnchantments[i].pBonusStat=RemoveQuotes(tokens[0]); 391 pEnchantments[i].pBonusStat=RemoveQuotes(tokens[0]);
410 pEnchantments[i].pOfName=RemoveQuotes(tokens[1]); 392 pEnchantments[i].pOfName=RemoveQuotes(tokens[1]);
413 pEnchantments[i].to_item[j]=atoi(tokens[j+2]); 395 pEnchantments[i].to_item[j]=atoi(tokens[j+2]);
414 } 396 }
415 } 397 }
416 398
417 memset(&pEnchantmentsSumm, 0, 36); 399 memset(&pEnchantmentsSumm, 0, 36);
418 for(i=0;i<9;++i) 400 for(int i=0;i<9;++i)
419 { 401 {
420 for (j=0;j<24;++j) 402 for (int j=0;j<24;++j)
421 pEnchantmentsSumm[i]+=pEnchantments[j].to_item[i]; 403 pEnchantmentsSumm[i]+=pEnchantments[j].to_item[i];
422 } 404 }
423 405
424 //Bonus range for Standard by Level 406 //Bonus range for Standard by Level
425 strtok(NULL, "\r"); 407 strtok(NULL, "\r");
426 strtok(NULL, "\r"); 408 strtok(NULL, "\r");
427 strtok(NULL, "\r"); 409 strtok(NULL, "\r");
428 strtok(NULL, "\r"); 410 strtok(NULL, "\r");
429 strtok(NULL, "\r"); 411 strtok(NULL, "\r");
430 for(i=0;i<6;++i) //counted from 1 412 for(int i=0;i<6;++i) //counted from 1
431 { 413 {
432 test_string = strtok(NULL, "\r") + 1; 414 test_string = strtok(NULL, "\r") + 1;
433 auto tokens = Tokenize(test_string, '\t'); 415 auto tokens = Tokenize(test_string, '\t');
434 Assert(tokens.size() == 4, "Invalid number of tokens"); 416 Assert(tokens.size() == 4, "Invalid number of tokens");
435 bonus_ranges[i].minR = atoi(tokens[2]); 417 bonus_ranges[i].minR = atoi(tokens[2]);
441 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0); 423 pSpcItemsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spcitems.txt", 0);
442 strtok(pSpcItemsTXT_Raw, "\r"); 424 strtok(pSpcItemsTXT_Raw, "\r");
443 strtok(NULL, "\r"); 425 strtok(NULL, "\r");
444 strtok(NULL, "\r"); 426 strtok(NULL, "\r");
445 strtok(NULL, "\r"); 427 strtok(NULL, "\r");
446 for (i=0;i<72;++i) 428 for (int i=0;i<72;++i)
447 { 429 {
448 test_string = strtok(NULL, "\r") + 1; 430 test_string = strtok(NULL, "\r") + 1;
449 auto tokens = Tokenize(test_string, '\t'); 431 auto tokens = Tokenize(test_string, '\t');
450 Assert(tokens.size() >= 17, "Invalid number of tokens"); 432 Assert(tokens.size() >= 17, "Invalid number of tokens");
451 pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]); 433 pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]);
467 pSpecialEnchantments[i].iTreasureLevel= tolower(tokens[15][0]) - 97; 449 pSpecialEnchantments[i].iTreasureLevel= tolower(tokens[15][0]) - 97;
468 } 450 }
469 451
470 pSpecialEnchantments_count = 71; 452 pSpecialEnchantments_count = 71;
471 memset(&pSpecialEnchantmentsSumm, 0, 96); 453 memset(&pSpecialEnchantmentsSumm, 0, 96);
472 for(i=0;i<12;++i) 454 for(int i=0;i<12;++i)
473 { 455 {
474 for (unsigned int j=0;j<=pSpecialEnchantments_count;++j) 456 for (unsigned int j=0;j<=pSpecialEnchantments_count;++j)
475 pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i]; 457 pSpecialEnchantmentsSumm[i]+=pSpecialEnchantments[j].to_item_apply[i];
476 } 458 }
477 459
580 pItems[item_counter].uChanceByTreasureLvl6=atoi(tokens[7]); 562 pItems[item_counter].uChanceByTreasureLvl6=atoi(tokens[7]);
581 } 563 }
582 564
583 //ChanceByTreasureLvl Summ - to calculate chance 565 //ChanceByTreasureLvl Summ - to calculate chance
584 memset(&uChanceByTreasureLvlSumm, 0, 24); 566 memset(&uChanceByTreasureLvlSumm, 0, 24);
585 for(i=0;i<6;++i) 567 for(int i=0;i<6;++i)
586 { 568 {
587 for (j=1;j<item_counter;++j) 569 for (int j=1;j<item_counter;++j)
588 uChanceByTreasureLvlSumm[i]+=pItems[j].uChanceByTreasureLvl[i]; 570 uChanceByTreasureLvlSumm[i]+=pItems[j].uChanceByTreasureLvl[i];
589 } 571 }
590 572
591 strtok(NULL, "\r"); 573 strtok(NULL, "\r");
592 strtok(NULL, "\r"); 574 strtok(NULL, "\r");
593 strtok(NULL, "\r"); 575 strtok(NULL, "\r");
594 strtok(NULL, "\r"); 576 strtok(NULL, "\r");
595 strtok(NULL, "\r"); 577 strtok(NULL, "\r");
596 for (i=0;i<3;++i) 578 for (int i=0;i<3;++i)
597 { 579 {
598 test_string = strtok(NULL, "\r") + 1; 580 test_string = strtok(NULL, "\r") + 1;
599 auto tokens = Tokenize(test_string, '\t'); 581 auto tokens = Tokenize(test_string, '\t');
600 Assert(tokens.size() > 7, "Invalid number of tokens"); 582 Assert(tokens.size() > 7, "Invalid number of tokens");
601 switch (i) 583 switch (i)
634 } 616 }
635 617
636 pSkillDescTXT_Raw = NULL; 618 pSkillDescTXT_Raw = NULL;
637 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0); 619 pSkillDescTXT_Raw = (char *)pEvents_LOD->LoadRaw("skilldes.txt", 0);
638 strtok(pSkillDescTXT_Raw, "\r"); 620 strtok(pSkillDescTXT_Raw, "\r");
639 for (i=0; i<37; ++i) 621 for (int i=0; i<37; ++i)
640 { 622 {
641 test_string = strtok(NULL, "\r") + 1; 623 test_string = strtok(NULL, "\r") + 1;
642 auto tokens = Tokenize(test_string, '\t'); 624 auto tokens = Tokenize(test_string, '\t');
643 Assert(tokens.size() >= 6, "Invalid number of tokens"); 625 Assert(tokens.size() >= 6, "Invalid number of tokens");
644 pSkillDesc[i] = RemoveQuotes(tokens[1]); 626 pSkillDesc[i] = RemoveQuotes(tokens[1]);
649 } 631 }
650 632
651 pStatsTXT_Raw = 0; 633 pStatsTXT_Raw = 0;
652 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0); 634 pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0);
653 strtok(pStatsTXT_Raw, "\r"); 635 strtok(pStatsTXT_Raw, "\r");
654 for (i=0; i<26; ++i) 636 for (int i=0; i<26; ++i)
655 { 637 {
656 test_string = strtok(NULL, "\r") + 1; 638 test_string = strtok(NULL, "\r") + 1;
657 auto tokens = Tokenize(test_string, '\t'); 639 auto tokens = Tokenize(test_string, '\t');
658 Assert(tokens.size() == 2, "Invalid number of tokens"); 640 Assert(tokens.size() == 2, "Invalid number of tokens");
659 switch (i) 641 switch (i)
728 } 710 }
729 711
730 pClassTXT_Raw = 0; 712 pClassTXT_Raw = 0;
731 pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0); 713 pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0);
732 strtok(pClassTXT_Raw, "\r"); 714 strtok(pClassTXT_Raw, "\r");
733 for (i=0; i<36; ++i) 715 for (int i=0; i<36; ++i)
734 { 716 {
735 test_string = strtok(NULL, "\r") + 1; 717 test_string = strtok(NULL, "\r") + 1;
736 auto tokens = Tokenize(test_string, '\t'); 718 auto tokens = Tokenize(test_string, '\t');
737 Assert(tokens.size() == 3, "Invalid number of tokens"); 719 Assert(tokens.size() == 3, "Invalid number of tokens");
738 pClassDescriptions[i]=RemoveQuotes(tokens[1]); 720 pClassDescriptions[i]=RemoveQuotes(tokens[1]);