# HG changeset patch # User Grumpy7 # Date 1394062864 -3600 # Node ID eab43c3d776751e181b7c68c125644bbf1fe769d # Parent 43a508455445959b198d98cf1d2a55d2df459c17 Using new tokenizer in Items.cpp initialize function diff -r 43a508455445 -r eab43c3d7767 Build/Visual Studio 2012/World of Might and Magic.vcxproj --- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj Tue Mar 04 00:02:21 2014 +0100 +++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj Thu Mar 06 00:41:04 2014 +0100 @@ -168,6 +168,7 @@ + diff -r 43a508455445 -r eab43c3d7767 Items.cpp --- a/Items.cpp Tue Mar 04 00:02:21 2014 +0100 +++ b/Items.cpp Thu Mar 06 00:41:04 2014 +0100 @@ -1,5 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #include +#include #include "Items.h" #include "MapInfo.h" @@ -14,6 +15,22 @@ #include "texts.h" #include "mm7_data.h" +struct ci_less : std::binary_function +{ + // case-independent (ci) compare_less binary function + struct nocase_compare : public std::binary_function + { + bool operator() (const unsigned char& c1, const unsigned char& c2) const { + return tolower (c1) < tolower (c2); + } + }; + bool operator() (const std::string & s1, const std::string & s2) const { + return std::lexicographical_compare + (s1.begin (), s1.end (), // source range + s2.begin (), s2.end (), // dest range + nocase_compare ()); // comparison + } +}; struct ITEM_VARIATION @@ -309,7 +326,52 @@ //----- (00456D84) -------------------------------------------------------- void ItemsTable::Initialize() - { +{ + std::map equipStatMap; + equipStatMap["weapon"] = EQUIP_SINGLE_HANDED; + equipStatMap["weapon2"] = EQUIP_TWO_HANDED; + equipStatMap["weapon1or2"] = EQUIP_SINGLE_HANDED; + equipStatMap["missile"] = EQUIP_BOW; + equipStatMap["bow"] = EQUIP_BOW; + equipStatMap["armor"] = EQUIP_ARMOUR; + equipStatMap["shield"] = EQUIP_SHIELD; + equipStatMap["helm"] = EQUIP_HELMET; + equipStatMap["belt"] = EQUIP_BELT; + equipStatMap["cloak"] = EQUIP_CLOAK; + equipStatMap["gauntlets"] = EQUIP_GAUNTLETS; + equipStatMap["boots"] = EQUIP_BOOTS; + equipStatMap["ring"] = EQUIP_RING; + equipStatMap["amulet"] = EQUIP_AMULET; + equipStatMap["weaponw"] = EQUIP_WAND; + equipStatMap["herb"] = EQUIP_REAGENT; + equipStatMap["reagent"] = EQUIP_REAGENT; + equipStatMap["bottle"] = EQUIP_POTION; + equipStatMap["sscroll"] = EQUIP_SPELL_SCROLL; + equipStatMap["book"] = EQUIP_BOOK; + equipStatMap["mscroll"] = EQUIP_MESSAGE_SCROLL; + equipStatMap["gold"] = EQUIP_GOLD; + equipStatMap["gem"] = EQUIP_GEM; + + std::map equipSkillMap; + equipSkillMap["staff"] = PLAYER_SKILL_STAFF; + equipSkillMap["sword"] = PLAYER_SKILL_SWORD; + equipSkillMap["dagger"] = PLAYER_SKILL_DAGGER; + equipSkillMap["axe"] = PLAYER_SKILL_AXE; + equipSkillMap["spear"] = PLAYER_SKILL_SPEAR; + equipSkillMap["bow"] = PLAYER_SKILL_BOW; + equipSkillMap["mace"] = PLAYER_SKILL_MACE; + equipSkillMap["blaster"] = PLAYER_SKILL_BLASTER; + equipSkillMap["shield"] = PLAYER_SKILL_SHIELD; + equipSkillMap["leather"] = PLAYER_SKILL_LEATHER; + equipSkillMap["chain"] = PLAYER_SKILL_CHAIN; + equipSkillMap["plate"] = PLAYER_SKILL_PLATE; + equipSkillMap["club"] = PLAYER_SKILL_CLUB; + + std::map materialMap; + materialMap["artifact"] = MATERIAL_ARTEFACT; + materialMap["relic"] = MATERIAL_RELIC; + materialMap["special"] = MATERIAL_SPECIAL; + int i,j; char* test_string; unsigned char c; @@ -348,44 +410,14 @@ for (i=0;i<24;++i) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 0: - pEnchantments[i].pBonusStat=RemoveQuotes(test_string); - break; - case 1: - pEnchantments[i].pOfName= RemoveQuotes(test_string); - break; - default: - pEnchantments[i].to_item[decode_step-2]=atoi(test_string); - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<11)&&!break_loop); - } + auto tokens = Tokenize(test_string, '\t'); + pEnchantments[i].pBonusStat=RemoveQuotes(tokens[0]); + pEnchantments[i].pOfName=RemoveQuotes(tokens[1]); + for (int j = 0; j < 9; j++) + { + pEnchantments[i].to_item[j]=atoi(tokens[j+2]); + } + } memset(&pEnchantmentsSumm, 0, 36); for(i=0;i<9;++i) @@ -401,31 +433,13 @@ strtok(NULL, "\r"); strtok(NULL, "\r"); for(i=0;i<6;++i) //counted from 1 - { - test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (decode_step==2) - bonus_ranges[i].minR = atoi(test_string); - else if (decode_step==3) - bonus_ranges[i].maxR =atoi(test_string); - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<4)&&!break_loop); - } + { + test_string = strtok(NULL, "\r") + 1; + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() == 4, "Invalid number of tokens"); + bonus_ranges[i].minR = atoi(tokens[2]); + bonus_ranges[i].maxR =atoi(tokens[3]); + } pSpcItemsTXT_Raw = 0; @@ -435,61 +449,28 @@ strtok(NULL, "\r"); strtok(NULL, "\r"); for (i=0;i<72;++i) - { - test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 0: - pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(test_string); - break; - case 1: - pSpecialEnchantments[i].pNameAdd= RemoveQuotes(test_string); - break; - case 14: - int res; - res=atoi(test_string); - if(!res) - { - ++test_string; - while (*test_string==' ')//fix X 2 case - ++test_string; - res=atoi(test_string); - } - pSpecialEnchantments[i].iValue=res; - break; - case 15: - pSpecialEnchantments[i].iTreasureLevel= tolower(*test_string) - 97;; - break; - default: - pSpecialEnchantments[i].to_item_apply[decode_step-2]=atoi(test_string); - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<16)&&!break_loop); - } + { + test_string = strtok(NULL, "\r") + 1; + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() == 17, "Invalid number of tokens"); + pSpecialEnchantments[i].pBonusStatement=RemoveQuotes(tokens[0]); + pSpecialEnchantments[i].pNameAdd= RemoveQuotes(tokens[1]); + for (int i = 0; i < 12; i++) + { + pSpecialEnchantments[i].to_item_apply[i]=atoi(tokens[i+2]); + } + int res; + res=atoi(tokens[14]); + if(!res) + { + ++tokens[14]; + while (*tokens[14]==' ')//fix X 2 case + ++tokens[14]; + res=atoi(tokens[14]); + } + pSpecialEnchantments[i].iValue=res; + pSpecialEnchantments[i].iTreasureLevel= tolower(tokens[15][0]) - 97; + } pSpecialEnchantments_count = 71; memset(&pSpecialEnchantmentsSumm, 0, 96); @@ -507,345 +488,81 @@ strtok(NULL, "\r"); uAllItemsCount = 0; item_counter = 0; - while (true) + while (item_counter < 800) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 0: //Item # - item_counter=atoi(test_string); - uAllItemsCount=item_counter; - break; - case 1: //Pic File - pItems[item_counter].pIconName = RemoveQuotes(test_string); - break; - case 2: //Name - pItems[item_counter].pName = RemoveQuotes(test_string); - break; - case 3: //Value - pItems[item_counter].uValue=atoi(test_string); - break; - case 4: //Equip Stat - { - if ( !_stricmp(test_string, "weapon") ) - { - pItems[item_counter].uEquipType = EQUIP_SINGLE_HANDED; - break; - } - if ( !_stricmp(test_string, "weapon2") ) - { - pItems[item_counter].uEquipType = EQUIP_TWO_HANDED; - break; - } - if ( !_stricmp(test_string, "weapon1or2") ) - { - pItems[item_counter].uEquipType = EQUIP_SINGLE_HANDED; - break; - } - if ( !(_stricmp(test_string, "missile")&&_stricmp(test_string, "bow"))) - { - pItems[item_counter].uEquipType = EQUIP_BOW; - break; - } - if ( !_stricmp(test_string, "armor") ) - { - pItems[item_counter].uEquipType = EQUIP_ARMOUR; - break; - } - if ( !_stricmp(test_string, "shield") ) - { - pItems[item_counter].uEquipType = EQUIP_SHIELD; - break; - } - if ( !_stricmp(test_string, "helm") ) - { - pItems[item_counter].uEquipType = EQUIP_HELMET; - break; - } - if ( !_stricmp(test_string, "belt") ) - { - pItems[item_counter].uEquipType = EQUIP_BELT; - break; - } - if ( !_stricmp(test_string, "cloak") ) - { - pItems[item_counter].uEquipType = EQUIP_CLOAK; - break; - } - if ( !_stricmp(test_string, "gauntlets") ) - { - pItems[item_counter].uEquipType = EQUIP_GAUNTLETS; - break; - } - if ( !_stricmp(test_string, "boots") ) - { - pItems[item_counter].uEquipType = EQUIP_BOOTS; - break; - } - if ( !_stricmp(test_string, "ring") ) - { - pItems[item_counter].uEquipType = EQUIP_RING; - break; - } - if ( !_stricmp(test_string, "amulet") ) - { - pItems[item_counter].uEquipType = EQUIP_AMULET; - break; - } - if ( !_stricmp(test_string, "weaponw") ) - { - pItems[item_counter].uEquipType = EQUIP_WAND; - break; - } - if ( !(_stricmp(test_string, "herb")&&_stricmp(test_string, "reagent"))) - { - pItems[item_counter].uEquipType = EQUIP_REAGENT; - break; - } - if ( !_stricmp(test_string, "bottle") ) - { - pItems[item_counter].uEquipType = EQUIP_POTION; - break; - } - if ( !_stricmp(test_string, "sscroll") ) - { - pItems[item_counter].uEquipType = EQUIP_SPELL_SCROLL; - break; - } - if ( !_stricmp(test_string, "book") ) - { - pItems[item_counter].uEquipType = EQUIP_BOOK; - break; - } - if ( !_stricmp(test_string, "mscroll") ) - { - pItems[item_counter].uEquipType = EQUIP_MESSAGE_SCROLL; - break; - } - if ( !_stricmp(test_string, "gold") ) - { - pItems[item_counter].uEquipType = EQUIP_GOLD; - break; - } - if ( !_stricmp(test_string, "gem") ) - { - pItems[item_counter].uEquipType = EQUIP_GEM; - break; - } - pItems[item_counter].uEquipType = EQUIP_NONE; - break; - } - case 5: //Skill Group - { - if ( !_stricmp(test_string, "staff") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_STAFF; - break; - } - if ( !_stricmp(test_string, "sword") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_SWORD; - break; - } - if ( !_stricmp(test_string, "dagger") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_DAGGER; - break; - } - if ( !_stricmp(test_string, "axe") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_AXE; - break; - } - if ( !_stricmp(test_string, "spear") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_SPEAR; - break; - } - if ( !_stricmp(test_string, "bow") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_BOW; - break; - } - if ( !_stricmp(test_string, "mace") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_MACE; - break; - } - if ( !_stricmp(test_string, "blaster") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_BLASTER; - break; - } - if ( !_stricmp(test_string, "shield") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_SHIELD; - break; - } - if ( !_stricmp(test_string, "leather") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_LEATHER; - break; - } - if ( !_stricmp(test_string, "chain") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_CHAIN; - break; - } - if ( !_stricmp(test_string, "plate") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_PLATE; - break; - } - if ( !_stricmp(test_string, "club") ) - { - pItems[item_counter].uSkillType = PLAYER_SKILL_CLUB; - break; - } - pItems[item_counter].uSkillType = PLAYER_SKILL_MISC; - break; - } - case 6: //Mod1 - { - int ii; - char* test_char; - int tst_len; - tst_len=strlen(test_string); - pItems[item_counter].uDamageDice=0; - pItems[item_counter].uDamageRoll=0; - test_char=test_string; - for (ii=0; iisecond; + auto findResult2 = equipSkillMap.find(tokens[5]); + pItems[item_counter].uSkillType = findResult2 == equipSkillMap.end() ? PLAYER_SKILL_MISC : findResult->second; + auto tokens2 = Tokenize(tokens[6], 'd'); + if (tokens2.size() == 2) + { + pItems[item_counter].uDamageDice=atoi(tokens2[0]); + pItems[item_counter].uDamageRoll=atoi(tokens2[1]); + } + else if (tolower(test_string[0]) != 's') + { + pItems[item_counter].uDamageDice=atoi(test_string); + pItems[item_counter].uDamageRoll=1; + } + else + { + pItems[item_counter].uDamageDice=0; + pItems[item_counter].uDamageRoll=0; + } + pItems[item_counter].uDamageMod=atoi(tokens[7]); + auto findResult3 = materialMap.find(tokens[8]); + pItems[item_counter].uSkillType = findResult3 == materialMap.end() ? MATERIAL_COMMON : findResult->second; + pItems[item_counter].uItemID_Rep_St=atoi(tokens[9]); + pItems[item_counter].pUnidentifiedName = RemoveQuotes(tokens[10]); + pItems[item_counter].uSpriteID=atoi(tokens[11]); - break; - } - case 13: //VarB - if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type)) - { - char b_s=atoi(test_string); - if (b_s) - pItems[item_counter]._bonus_strength=b_s; - else - pItems[item_counter]._bonus_strength=1; - } - else - pItems[item_counter]._bonus_strength=0; - break; - case 14: //Equip X - pItems[item_counter].uEquipX=atoi(test_string); - break; - case 15: //Equip Y - pItems[item_counter].uEquipY=atoi(test_string); - break; - case 16: //Notes - pItems[item_counter].pDescription = RemoveQuotes(test_string); - break; + pItems[item_counter]._additional_value=0; + pItems[item_counter]._bonus_type=0; + if (pItems[item_counter].uMaterial==MATERIAL_SPECIAL) + { + for(int ii=0; ii<24; ++ii) + { + if (!_stricmp(tokens[12],pEnchantments[ii].pOfName)) + { + pItems[item_counter]._bonus_type=ii+1; + break; + } + } + if (!pItems[item_counter]._bonus_type) + { + for(int ii=0; ii<72; ++ii) + { + if (!_stricmp(tokens[12],pSpecialEnchantments[ii].pNameAdd)) + { + pItems[item_counter]._additional_value=ii+1; + } + } + } + } - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<17)&&!break_loop); - ++item_counter; - if (item_counter>799) - break; - } + if ((pItems[item_counter].uMaterial==MATERIAL_SPECIAL)&&(pItems[item_counter]._bonus_type)) + { + char b_s=atoi(tokens[13]); + if (b_s) + pItems[item_counter]._bonus_strength=b_s; + else + pItems[item_counter]._bonus_strength=1; + } + else + pItems[item_counter]._bonus_strength=0; + pItems[item_counter].uEquipX=atoi(tokens[14]); + pItems[item_counter].uEquipY=atoi(tokens[15]); + pItems[item_counter].pDescription = RemoveQuotes(tokens[16]); + item_counter++; + } pRndItemsTXT_Raw = NULL; @@ -855,64 +572,19 @@ strtok(NULL, "\r"); strtok(NULL, "\r"); strtok(NULL, "\r"); - item_counter = 0; - while (true) + for (int item_counter = 0; item_counter < 619; item_counter++) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 0: - item_counter=atoi(test_string); - break; - case 2: - pItems[item_counter].uChanceByTreasureLvl1=atoi(test_string); - break; - case 3: - pItems[item_counter].uChanceByTreasureLvl2=atoi(test_string); - break; - case 4: - pItems[item_counter].uChanceByTreasureLvl3=atoi(test_string); - break; - case 5: - pItems[item_counter].uChanceByTreasureLvl4=atoi(test_string); - break; - case 6: - pItems[item_counter].uChanceByTreasureLvl5=atoi(test_string); - break; - case 7: - pItems[item_counter].uChanceByTreasureLvl6=atoi(test_string); - break; - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<8)&&!break_loop); - ++item_counter; - if (item_counter>618) - break; - } + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() > 7, "Invalid number of tokens"); + item_counter = atoi(tokens[0]); + pItems[item_counter].uChanceByTreasureLvl1=atoi(tokens[2]); + pItems[item_counter].uChanceByTreasureLvl2=atoi(tokens[3]); + pItems[item_counter].uChanceByTreasureLvl3=atoi(tokens[4]); + pItems[item_counter].uChanceByTreasureLvl4=atoi(tokens[5]); + pItems[item_counter].uChanceByTreasureLvl5=atoi(tokens[6]); + pItems[item_counter].uChanceByTreasureLvl6=atoi(tokens[7]); + } //ChanceByTreasureLvl Summ - to calculate chance memset(&uChanceByTreasureLvlSumm, 0, 24); @@ -930,119 +602,35 @@ for (i=0;i<3;++i) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 2: - switch (i) - { - case 0: - uBonusChanceStandart[0]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[0]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[0]=atoi(test_string); - break; - } - break; - case 3: - switch (i) - { - case 0: - uBonusChanceStandart[1]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[1]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[1]=atoi(test_string); - break; - } - break; - case 4: - switch (i) - { - case 0: - uBonusChanceStandart[2]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[2]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[2]=atoi(test_string); - break; - } - break; - case 5: - switch (i) - { - case 0: - uBonusChanceStandart[3]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[3]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[3]=atoi(test_string); - break; - } - break; - case 6: - switch (i) - { - case 0: - uBonusChanceStandart[4]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[4]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[4]=atoi(test_string); - break; - } - break; - case 7: - switch (i) - { - case 0: - uBonusChanceStandart[5]=atoi(test_string); - break; - case 1: - uBonusChanceSpecial[5]=atoi(test_string); - break; - case 2: - uBonusChanceWpSpecial[5]=atoi(test_string); - break; - } - break; - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<8)&&!break_loop); + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() > 7, "Invalid number of tokens"); + switch (i) + { + case 0: + uBonusChanceStandart[0]=atoi(tokens[2]); + uBonusChanceStandart[1]=atoi(tokens[3]); + uBonusChanceStandart[2]=atoi(tokens[4]); + uBonusChanceStandart[3]=atoi(tokens[5]); + uBonusChanceStandart[4]=atoi(tokens[6]); + uBonusChanceStandart[5]=atoi(tokens[7]); + break; + case 1: + uBonusChanceSpecial[0]=atoi(tokens[2]); + uBonusChanceSpecial[1]=atoi(tokens[3]); + uBonusChanceSpecial[2]=atoi(tokens[4]); + uBonusChanceSpecial[3]=atoi(tokens[5]); + uBonusChanceSpecial[4]=atoi(tokens[6]); + uBonusChanceSpecial[5]=atoi(tokens[7]); + break; + case 2: + uBonusChanceWpSpecial[0]=atoi(tokens[2]); + uBonusChanceWpSpecial[1]=atoi(tokens[3]); + uBonusChanceWpSpecial[2]=atoi(tokens[4]); + uBonusChanceWpSpecial[3]=atoi(tokens[5]); + uBonusChanceWpSpecial[4]=atoi(tokens[6]); + uBonusChanceWpSpecial[5]=atoi(tokens[7]); + break; + } } if ( pRndItemsTXT_Raw ) @@ -1057,51 +645,14 @@ for (i=0; i<37; ++i) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (decode_step) - { - case 1: - pSkillDesc[i] = RemoveQuotes(test_string); - break; - case 2: - pNormalSkillDesc[i] = RemoveQuotes(test_string); - break; - case 3: - pExpertSkillDesc[i] = RemoveQuotes(test_string); - break; - case 4: - pMasterSkillDesc[i] = RemoveQuotes(test_string); - break; - case 5: - pGrandSkillDesc[i] = RemoveQuotes(test_string); - break; - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<6)&&!break_loop); - } + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() == 6, "Invalid number of tokens"); + pSkillDesc[i] = RemoveQuotes(tokens[1]); + pNormalSkillDesc[i] = RemoveQuotes(tokens[2]); + pExpertSkillDesc[i] = RemoveQuotes(tokens[3]); + pMasterSkillDesc[i] = RemoveQuotes(tokens[4]); + pGrandSkillDesc[i] = RemoveQuotes(tokens[5]); + } pStatsTXT_Raw = 0; pStatsTXT_Raw = (char *)pEvents_LOD->LoadRaw("stats.txt", 0); @@ -1109,139 +660,89 @@ for (i=0; i<26; ++i) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - switch (i) - { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - pAttributeDescriptions[i] = RemoveQuotes(test_string); - break; - case 7: - pHealthPointsAttributeDescription = RemoveQuotes(test_string); - break; - case 8: - pArmourClassAttributeDescription = RemoveQuotes(test_string); - break; - case 9: - pSpellPointsAttributeDescription = RemoveQuotes(test_string); - break; - case 10: - pPlayerConditionAttributeDescription = RemoveQuotes(test_string); - break; - case 11: - pFastSpellAttributeDescription = RemoveQuotes(test_string); - break; - case 12: - pPlayerAgeAttributeDescription = RemoveQuotes(test_string); - break; - case 13: - pPlayerLevelAttributeDescription = RemoveQuotes(test_string); - break; - case 14: - pPlayerExperienceAttributeDescription = RemoveQuotes(test_string); - break; - case 15: - pAttackBonusAttributeDescription = RemoveQuotes(test_string); - break; - case 16: - pAttackDamageAttributeDescription = RemoveQuotes(test_string); - break; - case 17: - pMissleBonusAttributeDescription = RemoveQuotes(test_string); - break; - case 18: - pMissleDamageAttributeDescription = RemoveQuotes(test_string); - break; - case 19: - pFireResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 20: - pAirResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 21: - pWaterResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 22: - pEarthResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 23: - pMindResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 24: - pBodyResistanceAttributeDescription = RemoveQuotes(test_string); - break; - case 25: - pSkillPointsAttributeDescription = RemoveQuotes(test_string); - break; - } - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<2)&&!break_loop); - } - - + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() == 2, "Invalid number of tokens"); + switch (i) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + pAttributeDescriptions[i] = RemoveQuotes(tokens[1]); + break; + case 7: + pHealthPointsAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 8: + pArmourClassAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 9: + pSpellPointsAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 10: + pPlayerConditionAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 11: + pFastSpellAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 12: + pPlayerAgeAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 13: + pPlayerLevelAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 14: + pPlayerExperienceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 15: + pAttackBonusAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 16: + pAttackDamageAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 17: + pMissleBonusAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 18: + pMissleDamageAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 19: + pFireResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 20: + pAirResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 21: + pWaterResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 22: + pEarthResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 23: + pMindResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 24: + pBodyResistanceAttributeDescription = RemoveQuotes(tokens[1]); + break; + case 25: + pSkillPointsAttributeDescription = RemoveQuotes(tokens[1]); + break; + } + } + pClassTXT_Raw = 0; pClassTXT_Raw = (char *)pEvents_LOD->LoadRaw("class.txt", 0); strtok(pClassTXT_Raw, "\r"); for (i=0; i<36; ++i) { test_string = strtok(NULL, "\r") + 1; - break_loop = false; - decode_step=0; - do - { - c = *(unsigned char*)test_string; - temp_str_len = 0; - while((c!='\t')&&(c>0)) - { - ++temp_str_len; - c=test_string[temp_str_len]; - } - tmp_pos=test_string+temp_str_len; - if (*tmp_pos == 0) - break_loop = true; - *tmp_pos = 0; - if (temp_str_len) - { - //if(i) - pClassDescriptions[i]=RemoveQuotes(test_string); - } - else - { - if (decode_step) - break_loop = true; - } - ++decode_step; - test_string=tmp_pos+1; - } while ((decode_step<2)&&!break_loop); - } + auto tokens = Tokenize(test_string, '\t'); + Assert(tokens.size() == 3, "Invalid number of tokens"); + pClassDescriptions[i]=RemoveQuotes(tokens[1]); + } diff -r 43a508455445 -r eab43c3d7767 texts.cpp --- a/texts.cpp Tue Mar 04 00:02:21 2014 +0100 +++ b/texts.cpp Thu Mar 06 00:41:04 2014 +0100 @@ -6,6 +6,36 @@ #include "texts.h" +std::vector Tokenize( char* input, const char separator ) +{ + std::vector retVect; + char* lastInput = input; + while (*input) + { + if (*input == separator) + { + if (lastInput != nullptr) + { + *input = '\0'; + retVect.push_back(lastInput); + lastInput = nullptr; + } + } + else + { + if (lastInput == nullptr) + { + lastInput = input; + } + } + ++input; + } + if (lastInput != nullptr) + { + retVect.push_back(lastInput); + } + return retVect; +} diff -r 43a508455445 -r eab43c3d7767 texts.h --- a/texts.h Tue Mar 04 00:02:21 2014 +0100 +++ b/texts.h Thu Mar 06 00:41:04 2014 +0100 @@ -1,5 +1,6 @@ #pragma once #include +#include int sprintfex(char *buf, const char *format, ...); @@ -9,6 +10,7 @@ char *RemoveQuotes(char *Str); void InitializeGameText(); +std::vector Tokenize(char* input, const char separator); enum GLOBAL_LOCALIZ_INDEX {