| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- #define VCMI_DLL
- #include "../stdafx.h"
- #include "CHeroHandler.h"
- #include <sstream>
- #include "CLodHandler.h"
- #include "../lib/VCMI_Lib.h"
- extern CLodHandler * bitmaph;
- void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
- CHeroClass::CHeroClass()
- {
- skillLimit = 8;
- }
- CHeroClass::~CHeroClass()
- {
- }
- int CHeroClass::chooseSecSkill(const std::set<int> & possibles) const //picks secondary skill out from given possibilities
- {
- if(possibles.size()==1)
- return *possibles.begin();
- int totalProb = 0;
- for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
- {
- totalProb += proSec[*i];
- }
- int ran = rand()%totalProb;
- for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
- {
- ran -= proSec[*i];
- if(ran<0)
- return *i;
- }
- }
- CHeroHandler::~CHeroHandler()
- {}
- void CHeroHandler::loadPortraits()
- {
- std::string strs = bitmaph->getTextFile("PRISKILL.TXT");
- int itr=0;
- for (int i=0; i<PRIMARY_SKILLS; i++)
- {
- std::string tmp;
- loadToIt(tmp, strs, itr, 3);
- pskillsn.push_back(tmp);
- }
- }
- void CHeroHandler::loadHeroes()
- {
- VLC->heroh = this;
- int ID=0;
- std::string buf = bitmaph->getTextFile("HOTRAITS.TXT");
- int it=0;
- std::string dump;
- for(int i=0; i<2; ++i)
- {
- loadToIt(dump,buf,it,3);
- }
- int numberOfCurrentClassHeroes = 0;
- int currentClass = 0;
- int additHero = 0;
- EHeroClasses addTab[12];
- addTab[0] = HERO_KNIGHT;
- addTab[1] = HERO_WITCH;
- addTab[2] = HERO_KNIGHT;
- addTab[3] = HERO_WIZARD;
- addTab[4] = HERO_RANGER;
- addTab[5] = HERO_BARBARIAN;
- addTab[6] = HERO_DEATHKNIGHT;
- addTab[7] = HERO_WARLOCK;
- addTab[8] = HERO_KNIGHT;
- addTab[9] = HERO_WARLOCK;
- addTab[10] = HERO_BARBARIAN;
- addTab[11] = HERO_DEMONIAC;
-
- for (int i=0; i<HEROES_QUANTITY; i++)
- {
- CHero * nher = new CHero;
- if(currentClass<18)
- {
- nher->heroType = (EHeroClasses)currentClass;
- ++numberOfCurrentClassHeroes;
- if(numberOfCurrentClassHeroes==8)
- {
- numberOfCurrentClassHeroes = 0;
- ++currentClass;
- }
- }
- else
- {
- nher->heroType = addTab[additHero++];
- }
- std::string pom ;
- loadToIt(nher->name,buf,it,4);
- for(int x=0;x<3;x++)
- {
- loadToIt(pom,buf,it,4);
- nher->lowStack[x] = atoi(pom.c_str());
- loadToIt(pom,buf,it,4);
- nher->highStack[x] = atoi(pom.c_str());
- loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4));
- int hlp = nher->refTypeStack[x].find_first_of(' ',0);
- if(hlp>=0)
- nher->refTypeStack[x].replace(hlp,1,"");
- }
-
- nher->ID = heroes.size();
- heroes.push_back(nher);
- }
- //loading initial secondary skills
- std::ifstream inp;
- inp.open("config" PATHSEPARATOR "heroes_sec_skills.txt", std::ios_base::in|std::ios_base::binary);
- if(!inp.is_open())
- {
- tlog1<<"missing file: config/heroes_sec_skills.txt"<<std::endl;
- }
- else
- {
- inp>>dump;
- int hid; //ID of currently read hero
- int secQ; //number of secondary abilities
- while(true)
- {
- inp>>hid;
- if(hid == -1)
- break;
- inp>>secQ;
- for(int g=0; g<secQ; ++g)
- {
- int a, b;
- inp>>a; inp>>b;
- heroes[hid]->secSkillsInit.push_back(std::make_pair(a, b));
- }
- }
- inp.close();
- }
- //initial skills loaded
- loadSpecialAbilities();
- loadBiographies();
- loadHeroClasses();
- initHeroClasses();
- expPerLevel.push_back(0);
- expPerLevel.push_back(1000);
- expPerLevel.push_back(2000);
- expPerLevel.push_back(3200);
- expPerLevel.push_back(4500);
- expPerLevel.push_back(6000);
- expPerLevel.push_back(7700);
- expPerLevel.push_back(9000);
- expPerLevel.push_back(11000);
- expPerLevel.push_back(13200);
- expPerLevel.push_back(15500);
- expPerLevel.push_back(18500);
- expPerLevel.push_back(22100);
- expPerLevel.push_back(26420);
- expPerLevel.push_back(31604);
- return;
- }
- void CHeroHandler::loadSpecialAbilities()
- {
- std::string buf = bitmaph->getTextFile("HEROSPEC.TXT");
- int it=0;
- std::string dump;
- for(int i=0; i<2; ++i)
- {
- loadToIt(dump,buf,it,3);
- }
- for (int i=0;i<heroes.size();i++)
- {
- loadToIt(heroes[i]->bonusName,buf,it,4);
- loadToIt(heroes[i]->shortBonus,buf,it,4);
- loadToIt(heroes[i]->longBonus,buf,it,3);
- }
- }
- void CHeroHandler::loadBiographies()
- {
- std::string buf = bitmaph->getTextFile("HEROBIOS.TXT");
- int it=0;
- for (int i=0;i<heroes.size();i++)
- {
- loadToIt(heroes[i]->biography,buf,it,3);
- }
- }
- void CHeroHandler::loadHeroClasses()
- {
- std::string buf = bitmaph->getTextFile("HCTRAITS.TXT");
- int andame = buf.size();
- for(int y=0; y<andame; ++y)
- if(buf[y]==',')
- buf[y]='.';
- int i = 0; //buf iterator
- int hmcr = 0;
- for(i; i<andame; ++i) //omitting rubbish
- {
- if(buf[i]=='\r')
- ++hmcr;
- if(hmcr==2)
- break;
- }
- i+=2;
- for(int ss=0; ss<18; ++ss) //18 classes of hero (including conflux)
- {
- CHeroClass * hc = new CHeroClass;
- int befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->name = buf.substr(befi, i-befi);
- ++i;
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->aggression = atof(buf.substr(befi, i-befi).c_str());
- ++i;
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->initialAttack = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->initialDefence = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->initialPower = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->initialKnowledge = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- hc->primChance.resize(PRIMARY_SKILLS);
- for(int x=0;x<PRIMARY_SKILLS;x++)
- {
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->primChance[x].first = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- }
- for(int x=0;x<PRIMARY_SKILLS;x++)
- {
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- hc->primChance[x].second = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- }
- //CHero kkk = heroes[0];
- for(int dd=0; dd<SKILL_QUANTITY; ++dd)
- {
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t')
- break;
- }
- int buff = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- hc->proSec.push_back(buff);
- }
- for(int dd=0; dd<9; ++dd)
- {
- befi=i;
- for(i; i<andame; ++i)
- {
- if(buf[i]=='\t' || buf[i]=='\r')
- break;
- }
- hc->selectionProbability[dd] = atoi(buf.substr(befi, i-befi).c_str());
- ++i;
- }
- ++i;
- heroClasses.push_back(hc);
- }
- }
- void CHeroHandler::initHeroClasses()
- {
- for(int gg=0; gg<heroes.size(); ++gg)
- {
- heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
- }
- initTerrainCosts();
- }
- unsigned int CHeroHandler::level(unsigned int experience)
- {
- int add=0;
- while(experience>=expPerLevel[expPerLevel.size()-1])
- {
- experience/=1.2;
- add+=1;
- }
- for(int i=expPerLevel.size()-1; i>=0; --i)
- {
- if(experience>=expPerLevel[i])
- return i+add;
- }
- return -1;
- }
- unsigned int CHeroHandler::reqExp(unsigned int level)
- {
- level-=1;
- if(level<expPerLevel.size())
- return expPerLevel[level];
- else
- {
- unsigned int exp = expPerLevel[expPerLevel.size()-1];
- level-=(expPerLevel.size()-1);
- while(level>0)
- {
- --level;
- exp*=1.2;
- }
- return exp;
- }
- return -1;
- }
- void CHeroHandler::initTerrainCosts()
- {
- std::ifstream inp;
- inp.open("config" PATHSEPARATOR "TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary);
- int tynum;
- inp>>tynum;
- for(int i=0; i<2*tynum; i+=2)
- {
- int catNum;
- inp>>catNum;
- for(int k=0; k<catNum; ++k)
- {
- int curCost;
- inp>>curCost;
- heroClasses[i]->terrCosts.push_back(curCost);
- heroClasses[i+1]->terrCosts.push_back(curCost);
- }
- }
- inp.close();
- }
|