| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #define VCMI_DLL
- #include "../stdafx.h"
- #include "CSpellHandler.h"
- #include "CLodHandler.h"
- #include "../lib/VCMI_Lib.h"
- #include <boost/algorithm/string/replace.hpp>
- extern CLodHandler *bitmaph;
- void CSpellHandler::loadSpells()
- {
- 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);
- bool combSpells=false; //true, if we are reading combat spells
- bool creatureAbility=false; //if true, only creature can use this spell
- int ifHit = 0;
- while(i<andame)
- {
- if(spells.size()==81)
- break;
- CSpell nsp; //new currently being read spell
- loadToIt(nsp.name,buf,i,4);
- if(nsp.name == std::string(""))
- {
- if(ifHit == 0)
- {
- combSpells = true;
- }
- if(ifHit == 1)
- {
- creatureAbility = true;
- }
- for(int z=0; z<3; ++z)
- loadToIt(pom,buf,i,3);
- loadToIt(nsp.name,buf,i,4);
- ++ifHit;
- }
- loadToIt(nsp.abbName,buf,i,4);
- loadToIt(nsp.level,buf,i,4);
- 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;
- 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);
- nsp.probabilities.resize(9);
- for (int z = 0; z < 9 ; z++)
- loadToIt(nsp.probabilities[z],buf,i,4);
- nsp.AIVals.resize(4);
- for (int z = 0; z < 4 ; z++)
- loadToIt(nsp.AIVals[z],buf,i,4);
- nsp.descriptions.resize(4);
- for (int z = 0; z < 4 ; z++)
- {
- loadToIt(nsp.descriptions[z],buf,i,4);
- boost::algorithm::replace_all(nsp.descriptions[z],"\"","");
- }
- loadToIt(nsp.attributes,buf,i,3);
- nsp.id = spells.size();
- nsp.combatSpell = combSpells;
- nsp.creatureAbility = creatureAbility;
- spells.push_back(nsp);
- }
- //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;
- }
- }
- }
|