2008-08-20 09:57:53 +03:00
|
|
|
#define VCMI_DLL
|
|
|
|
#include "../stdafx.h"
|
2007-06-09 16:28:03 +03:00
|
|
|
#include "CSpellHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CLodHandler.h"
|
2008-08-20 09:57:53 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
extern CLodHandler *bitmaph;
|
2007-06-09 16:28:03 +03:00
|
|
|
void CSpellHandler::loadSpells()
|
|
|
|
{
|
2008-08-20 09:57:53 +03:00
|
|
|
std::string buf = bitmaph->getTextFile("SPTRAITS.TXT"), pom;
|
|
|
|
int andame = buf.size(), i=0; //buf iterator
|
|
|
|
for(int z=0; z<5; ++z)
|
|
|
|
loadToIt(pom,buf,i,3);
|
|
|
|
|
2007-06-09 23:23:44 +03:00
|
|
|
bool combSpells=false; //true, if we are reading combat spells
|
2008-09-12 16:06:53 +03:00
|
|
|
bool creatureAbility=false; //if true, only creature can use this spell
|
|
|
|
int ifHit = 0;
|
2007-06-09 23:23:44 +03:00
|
|
|
while(i<andame)
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2007-07-16 17:42:44 +03:00
|
|
|
if(spells.size()==81)
|
|
|
|
break;
|
2007-06-09 23:23:44 +03:00
|
|
|
CSpell nsp; //new currently being read spell
|
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
loadToIt(nsp.name,buf,i,4);
|
2007-06-09 23:23:44 +03:00
|
|
|
if(nsp.name == std::string(""))
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2008-09-12 16:06:53 +03:00
|
|
|
if(ifHit == 0)
|
|
|
|
{
|
|
|
|
combSpells = true;
|
|
|
|
}
|
|
|
|
if(ifHit == 1)
|
|
|
|
{
|
|
|
|
creatureAbility = true;
|
|
|
|
}
|
2008-08-20 09:57:53 +03:00
|
|
|
for(int z=0; z<3; ++z)
|
|
|
|
loadToIt(pom,buf,i,3);
|
|
|
|
loadToIt(nsp.name,buf,i,4);
|
2008-09-12 16:06:53 +03:00
|
|
|
++ifHit;
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
loadToIt(nsp.abbName,buf,i,4);
|
|
|
|
loadToIt(nsp.level,buf,i,4);
|
2007-06-09 23:23:44 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
loadToIt(pom,buf,i,4);
|
|
|
|
nsp.earth = pom[0]=='x' ? true : false;
|
|
|
|
loadToIt(pom,buf,i,4);
|
|
|
|
nsp.water = pom[0]=='x' ? true : false;
|
|
|
|
loadToIt(pom,buf,i,4);
|
|
|
|
nsp.fire = pom[0]=='x' ? true : false;
|
|
|
|
loadToIt(pom,buf,i,4);
|
|
|
|
nsp.air = pom[0]=='x' ? true : false;
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
nsp.costs.resize(4);
|
|
|
|
for (int z = 0; z < 4 ; z++)
|
|
|
|
loadToIt(nsp.costs[z],buf,i,4);
|
|
|
|
loadToIt(nsp.power,buf,i,4);
|
|
|
|
nsp.powers.resize(4);
|
|
|
|
for (int z = 0; z < 4 ; z++)
|
|
|
|
loadToIt(nsp.powers[z],buf,i,4);
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
nsp.probabilities.resize(9);
|
|
|
|
for (int z = 0; z < 9 ; z++)
|
|
|
|
loadToIt(nsp.probabilities[z],buf,i,4);
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
nsp.AIVals.resize(4);
|
|
|
|
for (int z = 0; z < 4 ; z++)
|
|
|
|
loadToIt(nsp.AIVals[z],buf,i,4);
|
2007-06-09 16:28:03 +03:00
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
nsp.descriptions.resize(4);
|
|
|
|
for (int z = 0; z < 4 ; z++)
|
2007-06-09 16:28:03 +03:00
|
|
|
{
|
2008-08-20 09:57:53 +03:00
|
|
|
loadToIt(nsp.descriptions[z],buf,i,4);
|
|
|
|
boost::algorithm::replace_all(nsp.descriptions[z],"\"","");
|
2007-06-09 16:28:03 +03:00
|
|
|
}
|
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
loadToIt(nsp.attributes,buf,i,3);
|
|
|
|
nsp.id = spells.size();
|
2007-06-09 23:23:44 +03:00
|
|
|
nsp.combatSpell = combSpells;
|
2008-09-12 16:06:53 +03:00
|
|
|
nsp.creatureAbility = creatureAbility;
|
2007-06-09 16:28:03 +03:00
|
|
|
spells.push_back(nsp);
|
|
|
|
}
|
2008-12-20 19:08:51 +02:00
|
|
|
//loading of additional spell traits
|
|
|
|
std::ifstream ast;
|
|
|
|
ast.open("config/spell_info.txt", std::ios::binary);
|
|
|
|
if(!ast.is_open())
|
|
|
|
{
|
|
|
|
tlog1<<"lack of config/spell_info.txt file!"<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//reading header
|
|
|
|
std::string dump;
|
|
|
|
for(int i=0; i<42; ++i) ast>>dump;
|
|
|
|
//reading exact info
|
|
|
|
int spellID;
|
|
|
|
ast>>spellID;
|
|
|
|
while(spellID != -1)
|
|
|
|
{
|
|
|
|
int buf;
|
|
|
|
ast>>buf;
|
|
|
|
spells[spellID].positiveness = buf;
|
|
|
|
ast>>spellID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|