2008-06-14 13:20:18 +03:00
|
|
|
#define VCMI_DLL
|
2008-01-09 19:21:31 +02:00
|
|
|
#include "../stdafx.h"
|
2007-06-08 17:58:04 +03:00
|
|
|
#include "CHeroHandler.h"
|
2007-07-11 15:08:42 +03:00
|
|
|
#include <sstream>
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2008-06-13 11:16:51 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
|
|
|
void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
2008-08-04 18:56:36 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CHeroHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-08-04 18:56:36 +03:00
|
|
|
CHeroClass::CHeroClass()
|
|
|
|
{
|
|
|
|
skillLimit = 8;
|
|
|
|
}
|
|
|
|
CHeroClass::~CHeroClass()
|
|
|
|
{
|
|
|
|
}
|
2008-09-29 14:03:30 +03:00
|
|
|
int CHeroClass::chooseSecSkill(const std::set<int> & possibles) const //picks secondary skill out from given possibilities
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
|
|
|
if(possibles.size()==1)
|
|
|
|
return *possibles.begin();
|
|
|
|
int totalProb = 0;
|
2008-09-29 14:03:30 +03:00
|
|
|
for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
|
|
|
totalProb += proSec[*i];
|
|
|
|
}
|
|
|
|
int ran = rand()%totalProb;
|
2008-09-29 14:03:30 +03:00
|
|
|
for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
|
2008-08-04 18:56:36 +03:00
|
|
|
{
|
|
|
|
ran -= proSec[*i];
|
|
|
|
if(ran<0)
|
|
|
|
return *i;
|
|
|
|
}
|
2008-11-28 03:36:34 +02:00
|
|
|
throw std::string("Cannot pick secondary skill!");
|
2008-08-04 18:56:36 +03:00
|
|
|
}
|
|
|
|
|
2009-02-09 16:50:32 +02:00
|
|
|
int CObstacleInfo::getWidth()
|
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
int line = 1;
|
|
|
|
for(int h=0; h<blockmap.size(); ++h)
|
|
|
|
{
|
|
|
|
int cur = - line/2;
|
|
|
|
switch(blockmap[h])
|
|
|
|
{
|
|
|
|
case 'X' : case 'N':
|
|
|
|
++cur;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if(cur > ret)
|
|
|
|
ret = cur;
|
|
|
|
++line;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CObstacleInfo::getHeight()
|
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
for(int h=0; h<blockmap.size(); ++h)
|
|
|
|
{
|
|
|
|
if(blockmap[h] == 'L')
|
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> CObstacleInfo::getBlocked(int hex)
|
|
|
|
{
|
|
|
|
std::vector<int> ret;
|
|
|
|
int cur = hex; //currently browsed hex
|
|
|
|
int curBeg = hex; //beginning of current line
|
|
|
|
for(int h=0; h<blockmap.size(); ++h)
|
|
|
|
{
|
|
|
|
switch(blockmap[h])
|
|
|
|
{
|
|
|
|
case 'X':
|
|
|
|
ret.push_back(cur);
|
|
|
|
++cur;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if((cur/17)%2 == 0)
|
|
|
|
{
|
|
|
|
cur = curBeg + 17;
|
|
|
|
curBeg = cur;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cur = curBeg + 16;
|
|
|
|
curBeg = cur;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
++cur;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-20 02:38:11 +03:00
|
|
|
CHeroHandler::~CHeroHandler()
|
2009-01-11 00:08:18 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < heroes.size(); i++)
|
|
|
|
delete heroes[i];
|
|
|
|
|
|
|
|
for (int i = 0; i < heroClasses.size(); i++)
|
|
|
|
delete heroClasses[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
CHeroHandler::CHeroHandler()
|
2008-06-13 11:16:51 +03:00
|
|
|
{}
|
2009-01-11 00:08:18 +02:00
|
|
|
|
2009-02-07 18:07:29 +02:00
|
|
|
void CHeroHandler::loadObstacles()
|
|
|
|
{
|
|
|
|
std::ifstream inp;
|
|
|
|
inp.open("config" PATHSEPARATOR "obstacles.txt", std::ios_base::in|std::ios_base::binary);
|
|
|
|
if(!inp.is_open())
|
|
|
|
{
|
2009-04-12 03:58:41 +03:00
|
|
|
tlog1<<"missing file: config/obstacles.txt"<<std::endl;
|
2009-02-07 18:07:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string dump;
|
|
|
|
for(int i=0; i<99; ++i)
|
|
|
|
{
|
|
|
|
inp>>dump;
|
|
|
|
}
|
|
|
|
while(true)
|
|
|
|
{
|
2009-02-09 16:50:32 +02:00
|
|
|
CObstacleInfo obi;
|
2009-02-07 18:07:29 +02:00
|
|
|
inp>>obi.ID;
|
|
|
|
if(obi.ID == -1) break;
|
|
|
|
inp>>obi.defName;
|
|
|
|
inp>>obi.blockmap;
|
|
|
|
inp>>obi.allowedTerrains;
|
|
|
|
obstacles[obi.ID] = obi;
|
|
|
|
}
|
|
|
|
inp.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 17:58:04 +03:00
|
|
|
void CHeroHandler::loadHeroes()
|
|
|
|
{
|
2008-06-30 03:06:41 +03:00
|
|
|
VLC->heroh = this;
|
2007-06-16 16:33:58 +03:00
|
|
|
int ID=0;
|
2008-06-13 11:16:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("HOTRAITS.TXT");
|
2007-08-04 22:01:22 +03:00
|
|
|
int it=0;
|
2007-06-08 17:58:04 +03:00
|
|
|
std::string dump;
|
2007-08-04 22:01:22 +03:00
|
|
|
for(int i=0; i<2; ++i)
|
2007-06-08 17:58:04 +03:00
|
|
|
{
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(dump,buf,it,3);
|
2007-06-08 17:58:04 +03:00
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
|
2007-07-16 13:03:54 +03:00
|
|
|
int numberOfCurrentClassHeroes = 0;
|
|
|
|
int currentClass = 0;
|
|
|
|
int additHero = 0;
|
2009-05-07 20:20:41 +03:00
|
|
|
CHero::EHeroClasses addTab[12];
|
|
|
|
addTab[0] = CHero::KNIGHT;
|
|
|
|
addTab[1] = CHero::WITCH;
|
|
|
|
addTab[2] = CHero::KNIGHT;
|
|
|
|
addTab[3] = CHero::WIZARD;
|
|
|
|
addTab[4] = CHero::RANGER;
|
|
|
|
addTab[5] = CHero::BARBARIAN;
|
|
|
|
addTab[6] = CHero::DEATHKNIGHT;
|
|
|
|
addTab[7] = CHero::WARLOCK;
|
|
|
|
addTab[8] = CHero::KNIGHT;
|
|
|
|
addTab[9] = CHero::WARLOCK;
|
|
|
|
addTab[10] = CHero::BARBARIAN;
|
|
|
|
addTab[11] = CHero::DEMONIAC;
|
2007-07-16 13:03:54 +03:00
|
|
|
|
2007-08-04 22:01:22 +03:00
|
|
|
|
|
|
|
for (int i=0; i<HEROES_QUANTITY; i++)
|
2007-06-08 17:58:04 +03:00
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
CHero * nher = new CHero;
|
|
|
|
if(currentClass<18)
|
|
|
|
{
|
2009-05-07 20:20:41 +03:00
|
|
|
nher->heroType = static_cast<CHero::EHeroClasses>(currentClass);
|
2007-07-16 13:03:54 +03:00
|
|
|
++numberOfCurrentClassHeroes;
|
|
|
|
if(numberOfCurrentClassHeroes==8)
|
|
|
|
{
|
|
|
|
numberOfCurrentClassHeroes = 0;
|
|
|
|
++currentClass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nher->heroType = addTab[additHero++];
|
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
|
|
|
|
std::string pom ;
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(nher->name,buf,it,4);
|
2007-08-04 22:01:22 +03:00
|
|
|
|
2008-05-03 18:30:11 +03:00
|
|
|
for(int x=0;x<3;x++)
|
|
|
|
{
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(pom,buf,it,4);
|
2008-05-03 18:30:11 +03:00
|
|
|
nher->lowStack[x] = atoi(pom.c_str());
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(pom,buf,it,4);
|
2008-05-03 18:30:11 +03:00
|
|
|
nher->highStack[x] = atoi(pom.c_str());
|
2008-06-13 11:16:51 +03:00
|
|
|
loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4));
|
2008-05-31 23:37:54 +03:00
|
|
|
int hlp = nher->refTypeStack[x].find_first_of(' ',0);
|
|
|
|
if(hlp>=0)
|
|
|
|
nher->refTypeStack[x].replace(hlp,1,"");
|
2008-05-03 18:30:11 +03:00
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
|
|
|
|
nher->ID = heroes.size();
|
2007-06-08 17:58:04 +03:00
|
|
|
heroes.push_back(nher);
|
|
|
|
}
|
2008-09-29 14:03:30 +03:00
|
|
|
//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
|
|
|
|
|
2007-08-04 22:01:22 +03:00
|
|
|
loadHeroClasses();
|
|
|
|
initHeroClasses();
|
2008-01-27 18:07:27 +02:00
|
|
|
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);
|
2007-07-17 23:51:49 +03:00
|
|
|
|
2009-02-06 16:15:45 +02:00
|
|
|
//ballistics info
|
|
|
|
buf = bitmaph->getTextFile("BALLIST.TXT");
|
|
|
|
it = 0;
|
|
|
|
for(int i=0; i<22; ++i)
|
|
|
|
{
|
|
|
|
loadToIt(dump,buf,it,4);
|
|
|
|
}
|
|
|
|
for(int lvl=0; lvl<4; ++lvl)
|
|
|
|
{
|
|
|
|
CHeroHandler::SBallisticsLevelInfo bli;
|
|
|
|
si32 tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.keep = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.tower = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.gate = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.wall = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.shots = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.noDmg = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.oneDmg = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.twoDmg = tempNum;
|
|
|
|
loadToIt(tempNum,buf,it,4);
|
|
|
|
bli.sum = tempNum;
|
|
|
|
if(lvl!=3)
|
|
|
|
{
|
|
|
|
loadToIt(dump,buf,it,4);
|
|
|
|
}
|
|
|
|
ballistics.push_back(bli);
|
|
|
|
}
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
void CHeroHandler::loadHeroClasses()
|
|
|
|
{
|
2008-06-13 11:16:51 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("HCTRAITS.TXT");
|
2007-07-16 17:42:44 +03:00
|
|
|
int andame = buf.size();
|
|
|
|
for(int y=0; y<andame; ++y)
|
|
|
|
if(buf[y]==',')
|
|
|
|
buf[y]='.';
|
2007-06-18 13:49:06 +03:00
|
|
|
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;
|
|
|
|
|
2008-05-03 18:30:11 +03:00
|
|
|
hc->primChance.resize(PRIMARY_SKILLS);
|
|
|
|
for(int x=0;x<PRIMARY_SKILLS;x++)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2008-05-03 18:30:11 +03:00
|
|
|
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;
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
2008-05-03 18:30:11 +03:00
|
|
|
for(int x=0;x<PRIMARY_SKILLS;x++)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2008-05-03 18:30:11 +03:00
|
|
|
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;
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
|
|
|
|
2007-07-16 13:03:54 +03:00
|
|
|
//CHero kkk = heroes[0];
|
2007-06-18 15:48:29 +03:00
|
|
|
|
2008-06-13 11:16:51 +03:00
|
|
|
for(int dd=0; dd<SKILL_QUANTITY; ++dd)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
|
|
|
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);
|
2007-06-18 13:49:06 +03:00
|
|
|
}
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
|
|
|
|
void CHeroHandler::initHeroClasses()
|
|
|
|
{
|
|
|
|
for(int gg=0; gg<heroes.size(); ++gg)
|
|
|
|
{
|
|
|
|
heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
|
|
|
|
}
|
2007-08-15 18:13:11 +03:00
|
|
|
initTerrainCosts();
|
2009-06-30 15:28:22 +03:00
|
|
|
loadNativeTerrains();
|
2007-07-16 13:03:54 +03:00
|
|
|
}
|
2007-08-12 20:48:05 +03:00
|
|
|
|
|
|
|
unsigned int CHeroHandler::level(unsigned int experience)
|
|
|
|
{
|
2008-01-27 18:07:27 +02:00
|
|
|
int add=0;
|
|
|
|
while(experience>=expPerLevel[expPerLevel.size()-1])
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-01-27 18:07:27 +02:00
|
|
|
experience/=1.2;
|
2008-01-31 23:35:30 +02:00
|
|
|
add+=1;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
for(int i=expPerLevel.size()-1; i>=0; --i)
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-01-27 18:07:27 +02:00
|
|
|
if(experience>=expPerLevel[i])
|
2008-11-15 02:55:19 +02:00
|
|
|
return 1+i+add;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-01-31 14:10:59 +02:00
|
|
|
return -1;
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CHeroHandler::reqExp(unsigned int level)
|
|
|
|
{
|
|
|
|
level-=1;
|
2008-11-14 20:18:13 +02:00
|
|
|
if(level<expPerLevel.size())
|
2008-01-27 18:07:27 +02:00
|
|
|
return expPerLevel[level];
|
|
|
|
else
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-01-27 18:07:27 +02:00
|
|
|
unsigned int exp = expPerLevel[expPerLevel.size()-1];
|
2008-11-14 20:18:13 +02:00
|
|
|
level-=(expPerLevel.size()-1);
|
2008-01-27 18:07:27 +02:00
|
|
|
while(level>0)
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-01-27 18:07:27 +02:00
|
|
|
--level;
|
|
|
|
exp*=1.2;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-11-14 20:18:13 +02:00
|
|
|
return exp;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-01-31 14:10:59 +02:00
|
|
|
return -1;
|
2007-08-12 20:48:05 +03:00
|
|
|
}
|
|
|
|
|
2007-08-15 18:13:11 +03:00
|
|
|
void CHeroHandler::initTerrainCosts()
|
|
|
|
{
|
2007-09-15 21:04:12 +03:00
|
|
|
std::ifstream inp;
|
2008-08-17 22:15:31 +03:00
|
|
|
inp.open("config" PATHSEPARATOR "TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary);
|
2009-06-30 15:28:22 +03:00
|
|
|
|
|
|
|
if(!inp.is_open())
|
|
|
|
{
|
|
|
|
tlog1 << "Error while opening config/TERCOSTS.TXT file!" << std::endl;
|
|
|
|
}
|
|
|
|
|
2007-09-15 21:04:12 +03:00
|
|
|
int tynum;
|
|
|
|
inp>>tynum;
|
|
|
|
for(int i=0; i<2*tynum; i+=2)
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2007-09-15 21:04:12 +03:00
|
|
|
int catNum;
|
|
|
|
inp>>catNum;
|
|
|
|
for(int k=0; k<catNum; ++k)
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2007-09-15 21:04:12 +03:00
|
|
|
int curCost;
|
|
|
|
inp>>curCost;
|
|
|
|
heroClasses[i]->terrCosts.push_back(curCost);
|
|
|
|
heroClasses[i+1]->terrCosts.push_back(curCost);
|
2007-08-15 18:13:11 +03:00
|
|
|
}
|
|
|
|
}
|
2007-09-15 21:04:12 +03:00
|
|
|
inp.close();
|
2007-10-17 23:05:49 +03:00
|
|
|
}
|
|
|
|
|
2009-06-30 15:28:22 +03:00
|
|
|
void CHeroHandler::loadNativeTerrains()
|
|
|
|
{
|
|
|
|
std::ifstream inp;
|
|
|
|
inp.open("config" PATHSEPARATOR "native_terrains.txt", std::ios_base::in|std::ios_base::binary);
|
|
|
|
|
|
|
|
if(!inp.is_open())
|
|
|
|
{
|
|
|
|
tlog1 << "Error while opening config/native_terrains.txt file!" << std::endl;
|
|
|
|
}
|
|
|
|
const int MAX_ELEM = 1000;
|
|
|
|
char buf[MAX_ELEM+1];
|
|
|
|
inp.getline(buf, MAX_ELEM);
|
|
|
|
inp.getline(buf, MAX_ELEM);
|
|
|
|
|
|
|
|
nativeTerrains.resize(F_NUMBER);
|
|
|
|
for(int i=0; i<F_NUMBER; ++i)
|
|
|
|
{
|
|
|
|
int faction, terrain;
|
|
|
|
inp >> faction;
|
|
|
|
inp >> terrain;
|
|
|
|
nativeTerrains[faction] = terrain;
|
|
|
|
}
|
|
|
|
inp.close();
|
|
|
|
}
|