2007-06-09 05:32:43 +03:00
|
|
|
#include "stdafx.h"
|
2007-06-08 17:58:04 +03:00
|
|
|
#include "CHeroHandler.h"
|
2007-06-18 15:48:29 +03:00
|
|
|
#include "CGameInfo.h"
|
2007-07-11 15:08:42 +03:00
|
|
|
#include <sstream>
|
|
|
|
#define CGI (CGameInfo::mainObj)
|
2007-06-08 17:58:04 +03:00
|
|
|
|
|
|
|
void CHeroHandler::loadHeroes()
|
|
|
|
{
|
2007-06-16 16:33:58 +03:00
|
|
|
int ID=0;
|
2007-06-10 21:04:15 +03:00
|
|
|
std::ifstream inp("H3bitmap.lod\\HOTRAITS.TXT", std::ios::in);
|
2007-06-08 17:58:04 +03:00
|
|
|
std::string dump;
|
|
|
|
for(int i=0; i<25; ++i)
|
|
|
|
{
|
|
|
|
inp>>dump;
|
|
|
|
}
|
|
|
|
inp.ignore();
|
2007-07-16 13:03:54 +03:00
|
|
|
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;
|
|
|
|
|
2007-06-08 17:58:04 +03:00
|
|
|
while(!inp.eof())
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
CHero * nher = new CHero;
|
|
|
|
if(currentClass<18)
|
|
|
|
{
|
|
|
|
nher->heroType = (EHeroClasses)currentClass;
|
|
|
|
++numberOfCurrentClassHeroes;
|
|
|
|
if(numberOfCurrentClassHeroes==8)
|
|
|
|
{
|
|
|
|
numberOfCurrentClassHeroes = 0;
|
|
|
|
++currentClass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nher->heroType = addTab[additHero++];
|
|
|
|
}
|
2007-06-08 17:58:04 +03:00
|
|
|
std::string base;
|
|
|
|
char * tab = new char[500];
|
|
|
|
int iit = 0;
|
|
|
|
inp.getline(tab, 500);
|
|
|
|
base = std::string(tab);
|
|
|
|
if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
|
|
|
|
{
|
2007-06-09 16:28:03 +03:00
|
|
|
loadSpecialAbilities();
|
2007-06-11 20:21:27 +03:00
|
|
|
loadBiographies();
|
2007-06-18 15:48:29 +03:00
|
|
|
loadHeroClasses();
|
2007-07-16 13:03:54 +03:00
|
|
|
initHeroClasses();
|
2007-06-22 16:50:16 +03:00
|
|
|
inp.close();
|
2007-06-08 17:58:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while(base[iit]!='\t')
|
|
|
|
{
|
|
|
|
++iit;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->name = base.substr(0, iit);
|
2007-06-08 17:58:04 +03:00
|
|
|
++iit;
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->low1stack = atoi(base.substr(iit, i).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->high1stack = atoi(base.substr(iit, i).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int ipom=iit;
|
|
|
|
while(base[ipom]!='\t')
|
|
|
|
{
|
|
|
|
++ipom;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->refType1stack = base.substr(iit, ipom-iit);
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=ipom+1;
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->low2stack = atoi(base.substr(iit, i-iit).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->high2stack = atoi(base.substr(iit, i-iit).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipom=iit;
|
|
|
|
while(base[ipom]!='\t')
|
|
|
|
{
|
|
|
|
++ipom;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->refType2stack = base.substr(iit, ipom-iit);
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=ipom+1;
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->low3stack = atoi(base.substr(iit, i-iit).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=iit; i<iit+100; ++i)
|
|
|
|
{
|
|
|
|
if(base[i]==(char)(10) || base[i]==(char)(9))
|
|
|
|
{
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->high3stack = atoi(base.substr(iit, i-iit).c_str());
|
2007-06-08 17:58:04 +03:00
|
|
|
iit=i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
nher->refType3stack = base.substr(iit, base.size()-iit);
|
|
|
|
nher->ID=ID++;
|
2007-06-08 17:58:04 +03:00
|
|
|
heroes.push_back(nher);
|
|
|
|
delete[500] tab;
|
|
|
|
}
|
2007-06-09 16:28:03 +03:00
|
|
|
loadSpecialAbilities();
|
2007-07-17 23:51:49 +03:00
|
|
|
|
|
|
|
//for (int i=0;i<heroes.size();i++)
|
|
|
|
//TODO: read portrait
|
|
|
|
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
|
|
|
void CHeroHandler::loadSpecialAbilities()
|
|
|
|
{
|
2007-06-10 21:04:15 +03:00
|
|
|
std::ifstream inp("H3bitmap.lod\\HEROSPEC.txt", std::ios::in);
|
2007-06-09 16:28:03 +03:00
|
|
|
std::string dump;
|
|
|
|
for(int i=0; i<7; ++i)
|
|
|
|
{
|
|
|
|
inp>>dump;
|
|
|
|
}
|
|
|
|
inp.ignore();
|
|
|
|
int whHero=0;
|
2007-06-10 21:04:15 +03:00
|
|
|
while(!inp.eof() && whHero<heroes.size())
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
|
|
|
std::string base;
|
|
|
|
char * tab = new char[500];
|
|
|
|
int iitBef = 0;
|
|
|
|
int iit = 0;
|
|
|
|
inp.getline(tab, 500);
|
|
|
|
base = std::string(tab);
|
|
|
|
if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
|
|
|
|
{
|
2007-06-22 16:50:16 +03:00
|
|
|
inp.close();
|
2007-06-09 16:28:03 +03:00
|
|
|
return; //add counter
|
|
|
|
}
|
|
|
|
while(base[iit]!='\t')
|
|
|
|
{
|
|
|
|
++iit;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
heroes[whHero]->bonusName = base.substr(0, iit);
|
2007-06-09 16:28:03 +03:00
|
|
|
++iit;
|
|
|
|
iitBef=iit;
|
|
|
|
|
2007-07-16 13:03:54 +03:00
|
|
|
if(heroes[whHero]->bonusName == std::string("Ogry"))
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
|
|
|
char * tab2 = new char[500];
|
|
|
|
inp.getline(tab2, 500);
|
|
|
|
base += std::string(tab2);
|
|
|
|
delete [500] tab2;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(base[iit]!='\t')
|
|
|
|
{
|
|
|
|
++iit;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
heroes[whHero]->shortBonus = base.substr(iitBef, iit-iitBef);
|
2007-06-09 16:28:03 +03:00
|
|
|
++iit;
|
|
|
|
iitBef=iit;
|
|
|
|
|
|
|
|
while(base[iit]!='\t' && iit<base.size())
|
|
|
|
{
|
|
|
|
++iit;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
heroes[whHero]->longBonus = base.substr(iitBef, iit-iitBef);
|
2007-06-09 16:28:03 +03:00
|
|
|
++whHero;
|
|
|
|
delete [500] tab;
|
|
|
|
}
|
2007-06-22 16:50:16 +03:00
|
|
|
inp.close();
|
2007-06-11 20:21:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroHandler::loadBiographies()
|
|
|
|
{
|
|
|
|
std::ifstream inp("H3bitmap.lod\\HEROBIOS.TXT", std::ios::in | std::ios::binary);
|
|
|
|
inp.seekg(0,std::ios::end); // na koniec
|
|
|
|
int andame = inp.tellg(); // read length
|
|
|
|
inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
|
|
|
char * bufor = new char[andame]; // allocate memory
|
|
|
|
inp.read((char*)bufor, andame); // read map file to buffer
|
2007-06-22 16:50:16 +03:00
|
|
|
inp.close();
|
2007-06-11 20:21:27 +03:00
|
|
|
std::string buf = std::string(bufor);
|
|
|
|
delete [andame] bufor;
|
|
|
|
int i = 0; //buf iterator
|
|
|
|
for(int q=0; q<heroes.size(); ++q)
|
|
|
|
{
|
|
|
|
int befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\r')
|
|
|
|
break;
|
|
|
|
}
|
2007-07-16 13:03:54 +03:00
|
|
|
heroes[q]->biography = buf.substr(befi, i-befi);
|
2007-06-11 20:21:27 +03:00
|
|
|
i+=2;
|
|
|
|
}
|
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
|
|
|
|
void CHeroHandler::loadHeroClasses()
|
|
|
|
{
|
2007-07-16 17:42:44 +03:00
|
|
|
//std::ifstream inp("H3bitmap.lod\\HCTRAITS.TXT", std::ios::in | std::ios::binary);
|
|
|
|
//inp.seekg(0,std::ios::end); // na koniec
|
|
|
|
//int andame = inp.tellg(); // read length
|
|
|
|
//inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
|
|
|
//char * bufor = new char[andame]; // allocate memory
|
|
|
|
//inp.read((char*)bufor, andame); // read map file to buffer
|
|
|
|
//inp.close();
|
|
|
|
//std::string buf = std::string(bufor);
|
|
|
|
//delete [andame] bufor;
|
|
|
|
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HCTRAITS.TXT");
|
|
|
|
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;
|
|
|
|
|
2007-06-18 15:48:29 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proAttack[0] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proDefence[0] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proPower[0] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proKnowledge[0] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proAttack[1] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proDefence[1] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
2007-06-18 13:49:06 +03:00
|
|
|
|
2007-06-18 15:48:29 +03:00
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proPower[1] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
|
|
|
befi=i;
|
|
|
|
for(i; i<andame; ++i)
|
|
|
|
{
|
|
|
|
if(buf[i]=='\t')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hc->proKnowledge[1] = atoi(buf.substr(befi, i-befi).c_str());
|
|
|
|
++i;
|
|
|
|
|
2007-07-16 13:03:54 +03:00
|
|
|
//CHero kkk = heroes[0];
|
2007-06-18 15:48:29 +03:00
|
|
|
|
|
|
|
for(int dd=0; dd<CGameInfo::mainObj->abilh->abilities.size(); ++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);
|
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];
|
|
|
|
}
|
|
|
|
}
|