1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/hch/CCreatureHandler.cpp
Michał W. Urbańczyk 4cca2da9c0 * added #38
* CDefEssential is now useful
* initGameState shouldn't overwrite starting armies
* loading more graphics (small creature icons, large hero portraits)
* functions for getting current valueof morale/luck (unfinished)
* added in CLodHandler function that returns CDefEssential with images from desired .def
* copySurface works correctly (I hope)
2007-10-16 22:39:11 +00:00

521 lines
9.3 KiB
C++

#include "stdafx.h"
#include "../CGameInfo.h"
#include "CCreatureHandler.h"
#include "CLodHandler.h"
#include <sstream>
#include <boost/assign/std/vector.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
void CCreatureHandler::loadCreatures()
{
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("ZCRTRAIT.TXT");
int andame = buf.size();
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
++hmcr;
if(hmcr==2)
break;
}
i+=2;
while(i<buf.size())
{
//if(creatures.size()>190 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
//{
// loadAnimationInfo();
// loadUnitAnimations();
// break;
//}
CCreature ncre;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.nameSing = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.namePl = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.wood = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.mercury = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.ore = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.sulfur = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.crystal = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.gems = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.gold = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.fightValue = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.AIValue = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.growth = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.hordeGrowth = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.hitPoints = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.speed = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.attack = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.defence = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.low1 = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.high1 = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.shots = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.spells = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.low2 = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.high2 = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
ncre.abilityText = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
ncre.abilityRefs = buf.substr(befi, i-befi);
i+=2;
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
{
ncre.idNumber = creatures.size();
ncre.isDefinite = true;
creatures.push_back(ncre);
}
}
for(int bb=1; bb<8; ++bb)
{
CCreature ncre;
ncre.isDefinite = false;
ncre.indefLevel = bb;
ncre.indefUpgraded = false;
creatures.push_back(ncre);
ncre.indefUpgraded = true;
creatures.push_back(ncre);
}
//loading reference names
std::ifstream ifs("config/crerefnam.txt");
int tempi;
std::string temps;
for (;;)
{
ifs >> tempi >> temps;
if (tempi>=creatures.size())
break;
boost::assign::insert(nameToID)(temps,tempi);
creatures[tempi].nameRef=temps;
}
ifs.close();
//loading 32x32px imgs
CDefHandler *smi = CGI->spriteh->giveDef("CPRSMALL.DEF");
smi->notFreeImgs = true;
for (int i=0; i<smi->ourImages.size(); i++)
{
boost::assign::insert(smallImgs)(i-2,smi->ourImages[i].bitmap);
}
delete smi;
}
void CCreatureHandler::loadAnimationInfo()
{
//std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("CRANIM.TXT");
//int andame = buf.size();
//int i=0; //buf iterator
//hmcr=0;
//for(i; i<andame; ++i)
//{
// if(buf[i]=='\r')
// ++hmcr;
// if(hmcr==2)
// break;
//}
//i+=2;
//for(int dd=0; dd<creatures.size(); ++dd)
//{
// loadUnitAnimInfo(creatures[dd], buf, i);
//}
return;
}
void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int & i)
{
int befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
++i;
while(unit.timeBetweenFidgets == 0.0)
{
for(i; i<src.size(); ++i)
{
if(src[i]=='\r')
break;
}
i+=2;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.timeBetweenFidgets = atof(src.substr(befi, i-befi).c_str());
++i;
}
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.walkAnimationTime = atof(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.attackAnimationTime = atof(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.flightAnimationDistance = atof(src.substr(befi, i-befi).c_str());
++i;
///////////////////////
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.upperRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.upperRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.rightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.rightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.lowerRightMissleOffsetX = atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.lowerRightMissleOffsetY = atoi(src.substr(befi, i-befi).c_str());
++i;
///////////////////////
for(int jjj=0; jjj<12; ++jjj)
{
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.missleFrameAngles[jjj] = atof(src.substr(befi, i-befi).c_str());
++i;
}
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.troopCountLocationOffset= atoi(src.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\t')
break;
}
unit.attackClimaxFrame = atoi(src.substr(befi, i-befi).c_str());
++i;
for(i; i<src.size(); ++i)
{
if(src[i]=='\r')
break;
}
i+=2;
}
void CCreatureHandler::loadUnitAnimations()
{
std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
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;
int i = 0; //buf iterator
int hmcr = 0;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
for(int s=0; s<creatures.size(); ++s)
{
int befi=i;
std::string rub;
for(i; i<andame; ++i)
{
if(buf[i]==' ')
break;
}
rub = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
std::string defName = buf.substr(befi, i-befi);
if(defName != std::string("x"))
creatures[s].battleAnimation = CGameInfo::mainObj->spriteh->giveDef(defName);
else
creatures[s].battleAnimation = NULL;
i+=2;
}
}