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-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2009-08-31 18:57:15 +03:00
|
|
|
#include <iomanip>
|
2010-07-06 10:32:40 +03:00
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <boost/spirit.hpp>
|
|
|
|
using namespace boost::spirit;
|
2009-08-31 18:57:15 +03:00
|
|
|
|
2008-06-13 11:16:51 +03:00
|
|
|
extern CLodHandler * bitmaph;
|
2010-02-12 17:04:01 +02:00
|
|
|
void loadToIt(std::string &dest, const std::string &src, int &iter, int mode);
|
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
|
|
|
}
|
|
|
|
|
2010-07-20 09:05:45 +03:00
|
|
|
EAlignment CHeroClass::getAlignment()
|
|
|
|
{
|
|
|
|
return (EAlignment)alignment;
|
|
|
|
}
|
|
|
|
|
2009-09-25 14:38:18 +03:00
|
|
|
int CObstacleInfo::getWidth() const
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-25 14:38:18 +03:00
|
|
|
int CObstacleInfo::getHeight() const
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
for(int h=0; h<blockmap.size(); ++h)
|
|
|
|
{
|
|
|
|
if(blockmap[h] == 'L')
|
|
|
|
{
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-09-25 14:38:18 +03:00
|
|
|
std::vector<int> CObstacleInfo::getBlocked(int hex) const
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-09-25 14:38:18 +03:00
|
|
|
int CObstacleInfo::getMaxBlocked(int hex) const
|
|
|
|
{
|
|
|
|
std::vector<int> blocked = getBlocked(hex);
|
|
|
|
return *std::max_element(blocked.begin(), blocked.end());
|
|
|
|
}
|
|
|
|
|
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-08-26 17:09:55 +03:00
|
|
|
void CHeroHandler::loadWallPositions()
|
|
|
|
{
|
|
|
|
std::ifstream inp;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/wall_pos.txt", std::ios_base::in|std::ios_base::binary);
|
2009-08-26 17:09:55 +03:00
|
|
|
if(!inp.is_open())
|
|
|
|
{
|
|
|
|
tlog1<<"missing file: config/wall_pos.txt"<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int MAX_BUF = 2000;
|
|
|
|
char buf[MAX_BUF+1];
|
|
|
|
|
|
|
|
inp.getline(buf, MAX_BUF);
|
|
|
|
std::string dump;
|
|
|
|
for(int g=0; g<ARRAY_COUNT(wallPositions); ++g)
|
|
|
|
{
|
|
|
|
inp >> dump;
|
2009-09-07 15:30:10 +03:00
|
|
|
for(int b=0; b<12; ++b)
|
2009-08-26 17:09:55 +03:00
|
|
|
{
|
|
|
|
std::pair<int, int> pt;
|
|
|
|
inp >> pt.first;
|
|
|
|
inp >> pt.second;
|
|
|
|
wallPositions[g].push_back(pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inp.close();
|
|
|
|
}
|
|
|
|
|
2009-02-07 18:07:29 +02:00
|
|
|
void CHeroHandler::loadObstacles()
|
|
|
|
{
|
|
|
|
std::ifstream inp;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/obstacles.txt", std::ios_base::in|std::ios_base::binary);
|
2009-02-07 18:07:29 +02:00
|
|
|
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
|
|
|
|
{
|
2009-08-30 15:58:38 +03:00
|
|
|
const int MAX_DUMP = 10000;
|
|
|
|
char dump[MAX_DUMP+1];
|
|
|
|
|
|
|
|
for(int i=0; i<8; ++i)
|
2009-02-07 18:07:29 +02:00
|
|
|
{
|
2009-08-30 15:58:38 +03:00
|
|
|
inp.getline(dump, MAX_DUMP);
|
2009-02-07 18:07:29 +02:00
|
|
|
}
|
|
|
|
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;
|
2009-08-30 15:58:38 +03:00
|
|
|
inp>>obi.posShift.first;
|
|
|
|
inp>>obi.posShift.second;
|
2009-02-07 18:07:29 +02:00
|
|
|
obstacles[obi.ID] = obi;
|
|
|
|
}
|
|
|
|
inp.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-31 18:57:15 +03:00
|
|
|
void CHeroHandler::loadPuzzleInfo()
|
|
|
|
{
|
|
|
|
std::ifstream inp;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/puzzle_map.txt", std::ios_base::in|std::ios_base::binary);
|
2009-08-31 18:57:15 +03:00
|
|
|
if(!inp.is_open())
|
|
|
|
{
|
|
|
|
tlog1<<"missing file: config/puzzle_map.txt"<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int MAX_DUMP = 10000;
|
|
|
|
char dump[MAX_DUMP+1];
|
|
|
|
|
|
|
|
inp.getline(dump, MAX_DUMP);
|
|
|
|
|
|
|
|
for(int fct = 0; fct < F_NUMBER; ++fct)
|
|
|
|
{
|
|
|
|
std::string dmp;
|
|
|
|
inp >> dmp;
|
|
|
|
|
|
|
|
for(int g=0; g<PUZZLES_PER_FACTION; ++g)
|
|
|
|
{
|
|
|
|
SPuzzleInfo spi;
|
|
|
|
inp >> spi.x;
|
|
|
|
inp >> spi.y;
|
|
|
|
inp >> spi.whenUncovered;
|
|
|
|
spi.number = g;
|
|
|
|
|
|
|
|
//filename calculation
|
|
|
|
std::ostringstream suffix;
|
|
|
|
suffix << std::setfill('0') << std::setw(2);
|
|
|
|
suffix << g << ".BMP";
|
|
|
|
|
2010-02-15 15:19:13 +02:00
|
|
|
static const std::string factionToInfix[F_NUMBER] = {"CAS", "RAM", "TOW", "INF", "NEC", "DUN", "STR", "FOR", "ELE"};
|
2009-08-31 18:57:15 +03:00
|
|
|
spi.filename = "PUZ" + factionToInfix[fct] + suffix.str();
|
|
|
|
|
|
|
|
puzzleInfo[fct].push_back(spi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2009-07-03 21:40:36 +03:00
|
|
|
std::ifstream inp;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/heroes_sec_skills.txt", std::ios_base::in|std::ios_base::binary);
|
2009-07-03 21:40:36 +03:00
|
|
|
if(!inp.is_open())
|
2008-09-29 14:03:30 +03:00
|
|
|
{
|
2009-07-03 21:40:36 +03:00
|
|
|
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)
|
2008-09-29 14:03:30 +03:00
|
|
|
{
|
2009-07-03 21:40:36 +03:00
|
|
|
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));
|
|
|
|
}
|
2008-09-29 14:03:30 +03:00
|
|
|
}
|
2009-07-03 21:40:36 +03:00
|
|
|
inp.close();
|
2008-09-29 14:03:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//initial skills loaded
|
|
|
|
|
2009-07-03 21:40:36 +03:00
|
|
|
{
|
|
|
|
std::ifstream inp;
|
|
|
|
std::istringstream iss;
|
|
|
|
dump.clear();
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/hero_spells.txt");
|
2009-07-03 21:40:36 +03:00
|
|
|
while(inp)
|
|
|
|
{
|
|
|
|
getline(inp, dump);
|
|
|
|
if(!dump.size() || dump[0] == '-')
|
|
|
|
continue;
|
|
|
|
iss.clear();
|
|
|
|
iss.str(dump);
|
|
|
|
int hid, sid;
|
|
|
|
iss >> hid >> sid;
|
|
|
|
heroes[hid]->startingSpell = sid;
|
|
|
|
}
|
2010-07-06 10:32:40 +03:00
|
|
|
inp.close();
|
2009-07-03 21:40:36 +03:00
|
|
|
}
|
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);
|
2009-07-12 17:07:36 +03:00
|
|
|
expPerLevel.push_back(4600);
|
|
|
|
expPerLevel.push_back(6200);
|
|
|
|
expPerLevel.push_back(8000);
|
|
|
|
expPerLevel.push_back(10000);
|
|
|
|
expPerLevel.push_back(12200);
|
|
|
|
expPerLevel.push_back(14700);
|
|
|
|
expPerLevel.push_back(17500);
|
|
|
|
expPerLevel.push_back(20600);
|
|
|
|
expPerLevel.push_back(24320);
|
|
|
|
expPerLevel.push_back(28784);
|
|
|
|
expPerLevel.push_back(34140);
|
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);
|
|
|
|
}
|
2010-07-06 10:32:40 +03:00
|
|
|
{
|
|
|
|
it = 0;
|
|
|
|
std::ifstream inp;
|
|
|
|
dump.clear();
|
|
|
|
inp.open(DATA_DIR "/config/specials.txt"); //loading hero specials
|
2010-07-14 05:53:21 +03:00
|
|
|
assert(inp);
|
2010-07-06 10:32:40 +03:00
|
|
|
specialInfo dummy;
|
|
|
|
si32 hid;
|
|
|
|
inp.ignore(100, '\n');
|
2010-07-15 22:38:15 +03:00
|
|
|
for (int i = 0; i < 175; ++i)
|
2010-07-06 10:32:40 +03:00
|
|
|
{
|
|
|
|
inp >> hid;
|
|
|
|
inp >> dummy.type;
|
|
|
|
inp >> dummy.val;
|
|
|
|
inp >> dummy.subtype;
|
|
|
|
inp >> dummy.additionalinfo;
|
|
|
|
heroes[hid]->spec.push_back(dummy); //put a copy of dummy
|
|
|
|
}
|
|
|
|
inp.close();
|
|
|
|
}
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
void CHeroHandler::loadHeroClasses()
|
|
|
|
{
|
2009-07-16 14:38:07 +03:00
|
|
|
std::istringstream str(bitmaph->getTextFile("HCTRAITS.TXT")); //we'll be reading from it
|
|
|
|
const int BUFFER_SIZE = 5000;
|
|
|
|
char buffer[BUFFER_SIZE+1];
|
2007-06-18 13:49:06 +03:00
|
|
|
|
2009-07-16 14:38:07 +03:00
|
|
|
for(int i=0; i<3; ++i) str.getline(buffer, BUFFER_SIZE); //omiting rubbish
|
2007-06-18 13:49:06 +03:00
|
|
|
|
|
|
|
|
2009-07-16 14:38:07 +03:00
|
|
|
for(int ss=0; ss<18; ++ss) //18 classes of hero (including conflux)
|
|
|
|
{
|
|
|
|
CHeroClass * hc = new CHeroClass;
|
2010-07-20 09:05:45 +03:00
|
|
|
hc->alignment = ss / 6;
|
2007-06-18 13:49:06 +03:00
|
|
|
|
2009-07-16 14:38:07 +03:00
|
|
|
char name[BUFFER_SIZE+1];
|
|
|
|
str.get(name, BUFFER_SIZE, '\t');
|
|
|
|
hc->name = name;
|
|
|
|
str >> hc->aggression;
|
|
|
|
str >> hc->initialAttack;
|
|
|
|
str >> hc->initialDefence;
|
|
|
|
str >> hc->initialPower;
|
|
|
|
str >> hc->initialKnowledge;
|
2007-06-18 13:49:06 +03:00
|
|
|
|
2008-05-03 18:30:11 +03:00
|
|
|
hc->primChance.resize(PRIMARY_SKILLS);
|
2009-07-16 14:38:07 +03:00
|
|
|
for(int x=0; x<PRIMARY_SKILLS; ++x)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2009-07-16 14:38:07 +03:00
|
|
|
str >> hc->primChance[x].first;
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
2009-07-16 14:38:07 +03:00
|
|
|
for(int x=0; x<PRIMARY_SKILLS; ++x)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2009-07-16 14:38:07 +03:00
|
|
|
str >> hc->primChance[x].second;
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
|
|
|
|
2009-07-16 14:38:07 +03:00
|
|
|
hc->proSec.resize(SKILL_QUANTITY);
|
2008-06-13 11:16:51 +03:00
|
|
|
for(int dd=0; dd<SKILL_QUANTITY; ++dd)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2009-07-16 14:38:07 +03:00
|
|
|
str >> hc->proSec[dd];
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
|
|
|
|
2009-07-16 14:38:07 +03:00
|
|
|
for(int dd=0; dd<ARRAY_COUNT(hc->selectionProbability); ++dd)
|
2007-06-18 15:48:29 +03:00
|
|
|
{
|
2009-07-16 14:38:07 +03:00
|
|
|
str >> hc->selectionProbability[dd];
|
2007-06-18 15:48:29 +03:00
|
|
|
}
|
2009-07-16 14:38:07 +03:00
|
|
|
|
2007-06-18 15:48:29 +03:00
|
|
|
heroClasses.push_back(hc);
|
2009-07-16 14:38:07 +03:00
|
|
|
str.getline(buffer, BUFFER_SIZE); //removing end of line characters
|
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
|
|
|
|
2009-08-16 18:39:18 +03:00
|
|
|
unsigned int CHeroHandler::level (ui64 experience)
|
2007-08-12 20:48:05 +03:00
|
|
|
{
|
2009-07-20 06:30:48 +03:00
|
|
|
int i;
|
2009-08-16 18:39:18 +03:00
|
|
|
if (experience <= expPerLevel.back())
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2009-08-17 13:02:29 +03:00
|
|
|
for (i = expPerLevel.size()-1; experience < expPerLevel[i]; i--);
|
2009-07-20 06:30:48 +03:00
|
|
|
return i + 1;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2009-07-20 06:30:48 +03:00
|
|
|
else
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2009-08-17 13:02:29 +03:00
|
|
|
i = expPerLevel.size() - 1;
|
2009-08-16 18:39:18 +03:00
|
|
|
while (experience > reqExp (i))
|
|
|
|
i++;
|
|
|
|
return i;
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
2009-08-16 18:39:18 +03:00
|
|
|
ui64 CHeroHandler::reqExp (unsigned int level)
|
2008-01-27 18:07:27 +02:00
|
|
|
{
|
2009-07-20 06:30:48 +03:00
|
|
|
if(!level)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-28 12:45:45 +02:00
|
|
|
if (level <= expPerLevel.size())
|
2009-07-20 06:30:48 +03:00
|
|
|
{
|
2009-10-28 12:45:45 +02:00
|
|
|
return expPerLevel[level-1];
|
2009-07-20 06:30:48 +03:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
else
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2009-08-16 18:39:18 +03:00
|
|
|
while (level > expPerLevel.size())
|
|
|
|
{
|
|
|
|
int i = expPerLevel.size() - 1;
|
2009-10-28 12:45:45 +02:00
|
|
|
expPerLevel.push_back (expPerLevel[i] + (expPerLevel[i] - expPerLevel[i-1]) * 1.2);
|
2009-08-16 18:39:18 +03:00
|
|
|
}
|
|
|
|
return expPerLevel[level-1];
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
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;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/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;
|
2009-10-04 05:02:45 +03:00
|
|
|
inp.open(DATA_DIR "/config/native_terrains.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/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();
|
|
|
|
}
|
2009-07-03 21:40:36 +03:00
|
|
|
|
|
|
|
CHero::CHero()
|
|
|
|
{
|
|
|
|
startingSpell = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHero::~CHero()
|
|
|
|
{
|
|
|
|
|
2009-10-04 05:02:45 +03:00
|
|
|
}
|