mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
f835ea9033
* more logging around #19 from that thread * glowing effect of yellow border around creatures * blue glowing border around hovered creature * making animation on battlefield more smooth * standing stacks have more static animation
638 lines
13 KiB
C++
638 lines
13 KiB
C++
#define VCMI_DLL
|
|
#include "../stdafx.h"
|
|
#include "CCreatureHandler.h"
|
|
#include "CLodHandler.h"
|
|
#include <sstream>
|
|
#include <boost/assign/std/set.hpp>
|
|
#include <boost/assign/std/vector.hpp>
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <boost/algorithm/string/find.hpp>
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
#include "../lib/VCMI_Lib.h"
|
|
using namespace boost::assign;
|
|
extern CLodHandler * bitmaph;
|
|
CCreatureHandler::CCreatureHandler()
|
|
{
|
|
VLC->creh = this;
|
|
}
|
|
int CCreature::getQuantityID(const int & quantity)
|
|
{
|
|
if (quantity<5)
|
|
return 0;
|
|
if (quantity<10)
|
|
return 1;
|
|
if (quantity<20)
|
|
return 2;
|
|
if (quantity<50)
|
|
return 3;
|
|
if (quantity<100)
|
|
return 4;
|
|
if (quantity<250)
|
|
return 5;
|
|
if (quantity<500)
|
|
return 5;
|
|
if (quantity<1000)
|
|
return 6;
|
|
if (quantity<4000)
|
|
return 7;
|
|
return 8;
|
|
}
|
|
|
|
bool CCreature::isDoubleWide() const
|
|
{
|
|
return vstd::contains(abilities,DOUBLE_WIDE);
|
|
}
|
|
|
|
bool CCreature::isFlying() const
|
|
{
|
|
return vstd::contains(abilities,FLYING);
|
|
}
|
|
bool CCreature::isShooting() const
|
|
{
|
|
return vstd::contains(abilities,SHOOTER);
|
|
}
|
|
si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatures can be bought
|
|
{
|
|
int ret = 2147483645;
|
|
int resAmnt = std::min(res.size(),cost.size());
|
|
for(int i=0;i<resAmnt;i++)
|
|
if(cost[i])
|
|
ret = std::min(ret,(int)(res[i]/cost[i]));
|
|
return ret;
|
|
}
|
|
|
|
void CCreatureHandler::loadCreatures()
|
|
{
|
|
notUsedMonsters += 122,124,126,128,145,146,147,148,149,160,161,162,163,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191;
|
|
tlog5 << "\t\tReading ZCRTRAIT.TXT" << std::endl;
|
|
std::string buf = 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())
|
|
{
|
|
CCreature ncre;
|
|
ncre.cost.resize(RESOURCE_QUANTITY);
|
|
ncre.level=0;
|
|
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.cost[0] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[1] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[2] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[3] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[4] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[5] = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.cost[6] = 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.damageMin = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.damageMax = 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.ammMin = atoi(buf.substr(befi, i-befi).c_str());
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame; ++i)
|
|
{
|
|
if(buf[i]=='\t')
|
|
break;
|
|
}
|
|
ncre.ammMax = 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(boost::algorithm::find_first(ncre.abilityRefs, "DOUBLE_WIDE"))
|
|
ncre.abilities.insert(DOUBLE_WIDE);
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "FLYING_ARMY"))
|
|
ncre.abilities.insert(FLYING);
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
|
|
ncre.abilities.insert(SHOOTER);
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "SIEGE_WEAPON"))
|
|
ncre.abilities.insert(SIEGE_WEAPON);
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
|
|
ncre.abilities.insert(TWICE_ATTACK);
|
|
if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))
|
|
ncre.abilities.insert(NO_ENEMY_RETALIATION);
|
|
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
|
|
{
|
|
ncre.idNumber = creatures.size();
|
|
creatures.push_back(ncre);
|
|
}
|
|
}
|
|
|
|
tlog5 << "\t\tReading config/crerefnam.txt" << std::endl;
|
|
//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();
|
|
ifs.clear();
|
|
for(int i=1;i<=10;i++)
|
|
levelCreatures.insert(std::pair<int,std::vector<CCreature*> >(i,std::vector<CCreature*>()));
|
|
|
|
tlog5 << "\t\tReading config/monsters.txt" << std::endl;
|
|
ifs.open("config/monsters.txt");
|
|
{
|
|
while(!ifs.eof())
|
|
{
|
|
int id, lvl;
|
|
ifs >> id >> lvl;
|
|
if(lvl>0)
|
|
{
|
|
creatures[id].level = lvl;
|
|
levelCreatures[lvl].push_back(&(creatures[id]));
|
|
}
|
|
}
|
|
}
|
|
ifs.close();
|
|
ifs.clear();
|
|
|
|
tlog5 << "\t\tReading config/cr_factions.txt" << std::endl;
|
|
ifs.open("config/cr_factions.txt");
|
|
while(!ifs.eof())
|
|
{
|
|
int id, fact;
|
|
ifs >> id >> fact;
|
|
creatures[id].faction = fact;
|
|
}
|
|
ifs.close();
|
|
ifs.clear();
|
|
|
|
tlog5 << "\t\tReading config/cr_upgrade_list.txt" << std::endl;
|
|
ifs.open("config/cr_upgrade_list.txt");
|
|
while(!ifs.eof())
|
|
{
|
|
int id, up;
|
|
ifs >> id >> up;
|
|
creatures[id].upgrades.insert(up);
|
|
}
|
|
ifs.close();
|
|
ifs.clear();
|
|
|
|
//loading unit animation def names
|
|
tlog5 << "\t\tReading config/CREDEFS.TXT" << std::endl;
|
|
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 andame2 = inp.tellg(); // read length
|
|
inp.seekg(0,std::ios::beg); // wracamy na poczatek
|
|
char * bufor = new char[andame2]; // allocate memory
|
|
inp.read((char*)bufor, andame2); // read map file to buffer
|
|
inp.close();
|
|
buf = std::string(bufor);
|
|
delete [] bufor;
|
|
|
|
i = 0; //buf iterator
|
|
hmcr = 0;
|
|
for(i; i<andame2; ++i) //omitting rubbish
|
|
{
|
|
if(buf[i]=='\r')
|
|
break;
|
|
}
|
|
i+=2;
|
|
tlog5 << "We have "<<creatures.size() << " creatures\n";
|
|
for(int s=0; s<creatures.size(); ++s)
|
|
{
|
|
//tlog5 <<"\t\t\t" << s <<". Reading defname. \n";
|
|
int befi=i;
|
|
std::string rub;
|
|
for(i; i<andame2; ++i)
|
|
{
|
|
if(buf[i]==' ')
|
|
break;
|
|
}
|
|
rub = buf.substr(befi, i-befi);
|
|
++i;
|
|
|
|
befi=i;
|
|
for(i; i<andame2; ++i)
|
|
{
|
|
if(buf[i]=='\r')
|
|
break;
|
|
}
|
|
std::string defName = buf.substr(befi, i-befi);
|
|
creatures[s].animDefName = defName;
|
|
}
|
|
tlog5 << "\t\tReading CRANIM.TXT.txt" << std::endl;
|
|
loadAnimationInfo();
|
|
|
|
//loading id to projectile mapping
|
|
|
|
tlog5 << "\t\tReading config/cr_shots.txt" << std::endl;
|
|
std::ifstream inp2("config" PATHSEPARATOR "cr_shots.txt", std::ios::in | std::ios::binary); //this file is not in lod
|
|
char dump [200];
|
|
inp2.getline(dump, 200);
|
|
while(true)
|
|
{
|
|
int id;
|
|
std::string name;
|
|
bool spin;
|
|
|
|
inp2>>id;
|
|
if(id == -1)
|
|
break;
|
|
inp2>>name;
|
|
idToProjectile[id] = name;
|
|
inp2>>spin;
|
|
idToProjectileSpin[id] = spin;
|
|
}
|
|
inp2.close();
|
|
|
|
|
|
|
|
creatures[115].abilities.insert(DOUBLE_WIDE);//water elemental should be treated as double-wide
|
|
creatures[123].abilities.insert(DOUBLE_WIDE);//ice elemental should be treated as double-wide
|
|
creatures[140].abilities.insert(DOUBLE_WIDE);//boar should be treated as double-wide
|
|
creatures[142].abilities.insert(DOUBLE_WIDE);//nomads should be treated as double-wide
|
|
}
|
|
|
|
void CCreatureHandler::loadAnimationInfo()
|
|
{
|
|
std::string buf = bitmaph->getTextFile("CRANIM.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;
|
|
for(int dd=0; dd<creatures.size(); ++dd)
|
|
{
|
|
//tlog5 << "\t\t\tReading animation info for creature " << dd << std::endl;
|
|
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;
|
|
}
|
|
|
|
CCreatureHandler::~CCreatureHandler()
|
|
{
|
|
} |