2007-09-02 15:36:54 +03:00
|
|
|
#include "stdafx.h"
|
2007-06-08 17:58:04 +03:00
|
|
|
#include "CHeroHandler.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "../CGameInfo.h"
|
2007-07-11 15:08:42 +03:00
|
|
|
#include <sstream>
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "../CGameInfo.h"
|
2007-08-04 22:01:22 +03:00
|
|
|
#include "CGeneralTextHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
|
|
|
#include "CAbilityHandler.h"
|
2007-09-15 21:04:12 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2007-09-14 16:11:10 +03:00
|
|
|
#include <cmath>
|
2007-09-15 21:04:12 +03:00
|
|
|
#include <iomanip>
|
2007-08-04 22:01:22 +03:00
|
|
|
|
2007-07-20 02:38:11 +03:00
|
|
|
CHeroHandler::~CHeroHandler()
|
|
|
|
{
|
|
|
|
for (int j=0;j<heroes.size();j++)
|
|
|
|
{
|
|
|
|
if (heroes[j]->portraitSmall)
|
|
|
|
SDL_FreeSurface(heroes[j]->portraitSmall);
|
|
|
|
delete heroes[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CHeroHandler::loadPortraits()
|
|
|
|
{
|
2007-09-16 20:21:23 +03:00
|
|
|
std::ifstream of("config/portrety.txt");
|
2007-07-20 02:38:11 +03:00
|
|
|
for (int j=0;j<heroes.size();j++)
|
|
|
|
{
|
|
|
|
int ID;
|
|
|
|
of>>ID;
|
|
|
|
std::string path;
|
|
|
|
of>>path;
|
|
|
|
heroes[ID]->portraitSmall=CGI->bitmaph->loadBitmap(path);
|
|
|
|
if (!heroes[ID]->portraitSmall)
|
|
|
|
std::cout<<"Can't read portrait for "<<ID<<" ("<<path<<")\n";
|
|
|
|
}
|
|
|
|
of.close();
|
|
|
|
}
|
2007-06-08 17:58:04 +03:00
|
|
|
void CHeroHandler::loadHeroes()
|
|
|
|
{
|
2007-06-16 16:33:58 +03:00
|
|
|
int ID=0;
|
2007-08-04 22:01:22 +03:00
|
|
|
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HOTRAITS.TXT");
|
|
|
|
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
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
CGeneralTextHandler::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;
|
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
nher->heroType = (EHeroClasses)currentClass;
|
|
|
|
++numberOfCurrentClassHeroes;
|
|
|
|
if(numberOfCurrentClassHeroes==8)
|
|
|
|
{
|
|
|
|
numberOfCurrentClassHeroes = 0;
|
|
|
|
++currentClass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nher->heroType = addTab[additHero++];
|
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
|
|
|
|
std::string pom ;
|
|
|
|
CGeneralTextHandler::loadToIt(nher->name,buf,it,4);
|
|
|
|
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->low1stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->high1stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(nher->refType1stack,buf,it,4);
|
|
|
|
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->low2stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->high2stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(nher->refType2stack,buf,it,4);
|
|
|
|
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->low3stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(pom,buf,it,4);
|
|
|
|
nher->high3stack = atoi(pom.c_str());
|
|
|
|
CGeneralTextHandler::loadToIt(nher->refType3stack,buf,it,3);
|
|
|
|
|
|
|
|
nher->ID = heroes.size();
|
2007-06-08 17:58:04 +03:00
|
|
|
heroes.push_back(nher);
|
|
|
|
}
|
2007-06-09 16:28:03 +03:00
|
|
|
loadSpecialAbilities();
|
2007-08-04 22:01:22 +03:00
|
|
|
loadBiographies();
|
|
|
|
loadHeroClasses();
|
|
|
|
initHeroClasses();
|
|
|
|
return;
|
2007-07-17 23:51:49 +03:00
|
|
|
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
|
|
|
void CHeroHandler::loadSpecialAbilities()
|
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HEROSPEC.TXT");
|
|
|
|
int it=0;
|
2007-06-09 16:28:03 +03:00
|
|
|
std::string dump;
|
2007-08-04 22:01:22 +03:00
|
|
|
for(int i=0; i<2; ++i)
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
CGeneralTextHandler::loadToIt(dump,buf,it,3);
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
2007-08-04 22:01:22 +03:00
|
|
|
for (int i=0;i<heroes.size();i++)
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
CGeneralTextHandler::loadToIt(heroes[i]->bonusName,buf,it,4);
|
|
|
|
CGeneralTextHandler::loadToIt(heroes[i]->shortBonus,buf,it,4);
|
|
|
|
CGeneralTextHandler::loadToIt(heroes[i]->longBonus,buf,it,3);
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
2007-06-11 20:21:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroHandler::loadBiographies()
|
2007-08-04 22:01:22 +03:00
|
|
|
{
|
|
|
|
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HEROBIOS.TXT");
|
|
|
|
int it=0;
|
|
|
|
for (int i=0;i<heroes.size();i++)
|
2007-06-11 20:21:27 +03:00
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
CGeneralTextHandler::loadToIt(heroes[i]->biography,buf,it,3);
|
2007-06-11 20:21:27 +03:00
|
|
|
}
|
|
|
|
}
|
2007-06-18 13:49:06 +03:00
|
|
|
|
|
|
|
void CHeroHandler::loadHeroClasses()
|
|
|
|
{
|
2007-07-16 17:42:44 +03:00
|
|
|
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;
|
2007-09-15 21:04:12 +03:00
|
|
|
std::stringstream nm;
|
|
|
|
nm<<"AH";
|
|
|
|
nm<<std::setw(2);
|
|
|
|
nm<<std::setfill('0');
|
|
|
|
nm<<heroClasses.size();
|
|
|
|
nm<<"_.DEF";
|
|
|
|
hc->moveAnim = CGI->spriteh->giveDef(nm.str());
|
|
|
|
|
|
|
|
for(int o=0; o<hc->moveAnim->ourImages.size(); ++o)
|
|
|
|
{
|
|
|
|
if(hc->moveAnim->ourImages[o].groupNumber==6)
|
|
|
|
{
|
|
|
|
for(int e=0; e<8; ++e)
|
|
|
|
{
|
|
|
|
Cimage nci;
|
|
|
|
nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap);
|
|
|
|
nci.groupNumber = 10;
|
|
|
|
nci.imName = std::string();
|
|
|
|
hc->moveAnim->ourImages.push_back(nci);
|
|
|
|
}
|
|
|
|
o+=8;
|
|
|
|
}
|
|
|
|
if(hc->moveAnim->ourImages[o].groupNumber==7)
|
|
|
|
{
|
|
|
|
for(int e=0; e<8; ++e)
|
|
|
|
{
|
|
|
|
Cimage nci;
|
|
|
|
nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap);
|
|
|
|
nci.groupNumber = 11;
|
|
|
|
nci.imName = std::string();
|
|
|
|
hc->moveAnim->ourImages.push_back(nci);
|
|
|
|
}
|
|
|
|
o+=8;
|
|
|
|
}
|
|
|
|
if(hc->moveAnim->ourImages[o].groupNumber==8)
|
|
|
|
{
|
|
|
|
for(int e=0; e<8; ++e)
|
|
|
|
{
|
|
|
|
Cimage nci;
|
|
|
|
nci.bitmap = CSDL_Ext::rotate01(hc->moveAnim->ourImages[o+e].bitmap);
|
|
|
|
nci.groupNumber = 12;
|
|
|
|
nci.imName = std::string();
|
|
|
|
hc->moveAnim->ourImages.push_back(nci);
|
|
|
|
}
|
|
|
|
o+=8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int ff=0; ff<hc->moveAnim->ourImages.size(); ++ff)
|
|
|
|
{
|
|
|
|
CSDL_Ext::fullAlphaTransform(hc->moveAnim->ourImages[ff].bitmap);
|
|
|
|
}
|
|
|
|
hc->moveAnim->alphaTransformed = true;
|
2007-06-18 15:48:29 +03:00
|
|
|
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();
|
2007-07-16 13:03:54 +03:00
|
|
|
}
|
2007-08-12 20:48:05 +03:00
|
|
|
|
|
|
|
unsigned int CHeroInstance::getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype)
|
|
|
|
{
|
2007-08-15 18:13:11 +03:00
|
|
|
unsigned int ret = type->heroClass->terrCosts[ttype];
|
|
|
|
switch(rdtype)
|
|
|
|
{
|
|
|
|
case Eroad::dirtRoad:
|
|
|
|
ret*=0.75;
|
|
|
|
break;
|
|
|
|
case Eroad::grazvelRoad:
|
|
|
|
ret*=0.667;
|
|
|
|
break;
|
|
|
|
case Eroad::cobblestoneRoad:
|
|
|
|
ret*=0.5;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
2007-08-12 20:48:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CHeroHandler::level(unsigned int experience)
|
|
|
|
{
|
2007-09-14 16:11:10 +03:00
|
|
|
if (experience==0)
|
|
|
|
return 0;
|
|
|
|
else if (experience<14700) //level < 10
|
|
|
|
{
|
|
|
|
return (-500+20*sqrt((float)experience+1025))/(200);
|
|
|
|
}
|
|
|
|
else if (experience<24320) //10 - 12
|
|
|
|
{
|
|
|
|
if (experience>20600)
|
|
|
|
return 12;
|
|
|
|
else if (experience>17500)
|
|
|
|
return 11;
|
|
|
|
else return 10;
|
|
|
|
}
|
|
|
|
else //>12
|
|
|
|
{
|
|
|
|
int lvl=12;
|
|
|
|
int xp = 24320; //xp needed for 13 lvl
|
|
|
|
int td = 4464; //diff 14-13
|
|
|
|
float mp = 1.2;
|
|
|
|
while (experience>xp)
|
|
|
|
{
|
|
|
|
xp+=td;
|
|
|
|
td*=mp;
|
|
|
|
lvl++;
|
|
|
|
}
|
|
|
|
return lvl;
|
|
|
|
}
|
2007-08-12 20:48:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CHeroInstance::getLowestCreatureSpeed()
|
|
|
|
{
|
2007-08-15 18:13:11 +03:00
|
|
|
unsigned int sl = 100;
|
|
|
|
for(int h=0; h<army.slots.size(); ++h)
|
|
|
|
{
|
|
|
|
if(army.slots[h].first->speed<sl)
|
|
|
|
sl = army.slots[h].first->speed;
|
|
|
|
}
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroHandler::initTerrainCosts()
|
|
|
|
{
|
2007-09-15 21:04:12 +03:00
|
|
|
std::ifstream inp;
|
2007-09-17 20:36:20 +03:00
|
|
|
inp.open("config\\TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary);
|
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-08-15 18:13:11 +03:00
|
|
|
}
|