1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

dokończenie czytania spelli, drobne poprawki, czytanie kilku fragmentow nagłówka mapy (przetestować jeszcze trochę)

This commit is contained in:
mateuszb 2007-06-09 20:23:44 +00:00
parent 97f722e90b
commit 367259f372
6 changed files with 315 additions and 230 deletions

View File

@ -12,6 +12,7 @@ public:
std::string advText, advText2; std::string advText, advText2;
std::string expText, expText2; std::string expText, expText2;
int idNumber; int idNumber;
bool isAllowed; //true if we can use this hero's ability (map information)
}; };
class CAbilityHandler class CAbilityHandler

View File

@ -4,9 +4,9 @@
#include "CGameInfo.h" #include "CGameInfo.h"
#include <set> #include <set>
int intPow(int a, int b) unsigned int intPow(unsigned int a, unsigned int b)
{ {
int ret=1; unsigned int ret=1;
for(int i=0; i<b; ++i) for(int i=0; i<b; ++i)
ret*=a; ret*=a;
return ret; return ret;
@ -277,15 +277,67 @@ void CAmbarCendamo::deh3m()
{ {
if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size()) if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
{ {
if(c == c&intPow(2, yy)) if(c == c|intPow(2, yy))
CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = true; CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = true;
else else
CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = false; CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = false;
} }
} }
} }
//allowed heroes read //allowed heroes have been read
i+=67; i+=36;
//reading allowed artifacts //18 bytes
ist=i; //starting i for loop
for(i; i<ist+18; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<7; ++yy)
{
if((i-ist)*8+yy < CGameInfo::mainObj->arth->artifacts.size())
{
if(c == c|intPow(2, yy))
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->arth->artifacts[(i-ist)*8+yy].isAllowed = false;
}
}
}
//allowed artifacts have been read
//reading allowed spells (9 bytes)
ist=i; //starting i for loop
for(i; i<ist+9; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<7; ++yy)
{
if((i-ist)*8+yy < CGameInfo::mainObj->spellh->spells.size())
{
if(c == c|intPow(2, yy))
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->spellh->spells[(i-ist)*8+yy].isAllowed = false;
}
}
}
//allowed spells have been read
//allowed hero's abilities (4 bytes)
ist=i; //starting i for loop
for(i; i<ist+4; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<7; ++yy)
{
if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
{
if(c == c|intPow(2, yy))
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = true;
else
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = false;
}
}
}
//allowed hero's abilities have been read
THC std::cout<<"Wczytywanie naglowka: "<<th.getDif()<<std::endl; THC std::cout<<"Wczytywanie naglowka: "<<th.getDif()<<std::endl;
int rumNr = readNormalNr(i,4);i+=4; int rumNr = readNormalNr(i,4);i+=4;
for (int it=0;it<rumNr;it++) for (int it=0;it<rumNr;it++)

View File

@ -17,6 +17,7 @@ public:
bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4, misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso, lHand, rHand, neck, shoulders, head; bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4, misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso, lHand, rHand, neck, shoulders, head;
EartClass aClass; EartClass aClass;
int number; int number;
bool isAllowed; //true if we can use this artifact (map information)
}; };
class CArtHandler //handles artifacts class CArtHandler //handles artifacts

View File

@ -243,7 +243,7 @@ int _tmain(int argc, _TCHAR* argv[])
abilh->loadAbilities(); abilh->loadAbilities();
cgi->abilh = abilh; cgi->abilh = abilh;
CSpellHandler * spellh = new CSpellHandler; CSpellHandler * spellh = new CSpellHandler;
//spellh->loadSpells(); //TODO - naprawić i dokończyć! spellh->loadSpells(); //TODO - naprawić i dokończyć!
cgi->spellh = spellh; cgi->spellh = spellh;
CAmbarCendamo * ac = new CAmbarCendamo("4gryf"); CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
cgi->ac = ac; cgi->ac = ac;

View File

@ -1,331 +1,361 @@
#include "stdafx.h" #include "stdafx.h"
#include "CSpellHandler.h" #include "CSpellHandler.h"
#include <string>
void CSpellHandler::loadSpells() void CSpellHandler::loadSpells()
{ {
std::ifstream inp("SPTRAITS.TXT", std::ios::in | std::ios::binary); std::ifstream inp("SPTRAITS.TXT", std::ios::in | std::ios::binary);
//std::string dump; inp.seekg(0,std::ios::end); // na koniec
bool combatSeries=false; //false - now we are reading adventure spells; true - combat spells int andame = inp.tellg(); // read length
//for(int i=0; i<52; ++i) inp.seekg(0,std::ios::beg); // wracamy na poczatek
//{ char * bufor = new char[andame]; // allocate memory
// inp>>dump; inp.read((char*)bufor, andame); // read map file to buffer
//} std::string buf = std::string(bufor);
//inp.ignore(37); delete [andame] bufor;
char * tpom = new char[100000]; int i=0; //buf iterator
inp.get(tpom, 100000); int hmcr=0;
inp.get(tpom, 100000); for(i; i<andame; ++i)
//inp.get(tpom, 1000, '\r');
//inp.get(tpom, 1000, '\r');
inp.ignore(1);
std::string bb = std::string(tpom);
//delete [100000] tpom;
//std::string ppp(inp, 0, inp.tellg());
/*for(int ii=0; ii<10000; ++ii)
{ {
char c; if(buf[i]=='\r')
inp.get(c); ++hmcr;
inp.get(c); if(hmcr==5)
ppp+=c; break;
inp.ignore(100, '\n'); }
}*/ i+=2;
bool combSpells=false; //true, if we are reading combat spells
while(!inp.eof()) while(i<andame)
{ {
CSpell nsp; CSpell nsp; //new currently being read spell
std::string base; int befi=i;
char * tab = new char[5000]; for(i; i<andame; ++i)
int iit = 0;
int iitBef = 0;
inp.get(tab, 5000, '\r');
base = std::string(tab);
if(base.size()<2)
{ {
return; if(buf[i]=='\t')
break;
} }
while(base[iit]!='\t') nsp.name = buf.substr(befi, i-befi);
{ ++i;
++iit;
}
nsp.name = base.substr(0, iit);
++iit;
iitBef=iit;
if (nsp.name==std::string("Adventure Spells")) if(nsp.name == std::string(""))
{ {
combatSeries=false; combSpells = true;
inp.getline(tab, 500); int hmcr=0;
continue; for(i; i<andame; ++i)
} {
else if (nsp.name==std::string("Combat Spells")) if(buf[i]=='\r')
{ ++hmcr;
combatSeries=true; if(hmcr==4)
inp.getline(tab, 500); break;
continue; }
++i;
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nsp.name = buf.substr(befi, i-befi);
++i;
} }
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.abbName = base.substr(iitBef, iit-iitBef); nsp.abbName = buf.substr(befi, i-befi);
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.level = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.level = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.earth = base.substr(iitBef, iit-iitBef)==std::string("x") ? true : false; nsp.earth = buf.substr(befi, i-befi)[0]=='x' ? true : false;
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.water = base.substr(iitBef, iit-iitBef)==std::string("x") ? true : false; nsp.water = buf.substr(befi, i-befi)[0]=='x' ? true : false;
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.fire = base.substr(iitBef, iit-iitBef)==std::string("x") ? true : false; nsp.fire = buf.substr(befi, i-befi)[0]=='x' ? true : false;
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.air = base.substr(iitBef, iit-iitBef)==std::string("x") ? true : false; nsp.air = buf.substr(befi, i-befi)[0]=='x' ? true : false;
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.costNone = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.costNone = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.costBas = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.costBas = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.costAdv = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.costAdv = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.costExp = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.costExp = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.power = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.power = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.powerNone = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.powerNone = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.powerBas = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.powerBas = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.powerAdv = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.powerAdv = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.powerExp = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.powerExp = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.castle = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.castle = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.rampart = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.rampart = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.tower = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.tower = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.inferno = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.inferno = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.necropolis = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.necropolis = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.dungeon = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.dungeon = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.stronghold = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.stronghold = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.fortress = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.fortress = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.conflux = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.conflux = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.none2 = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.none2 = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.bas2 = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.bas2 = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.adv2 = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.adv2 = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t') befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.exp2 = atoi(base.substr(iitBef, iit-iitBef).c_str()); nsp.exp2 = atoi(buf.substr(befi, i-befi).c_str());
++iit; ++i;
iitBef=iit;
while(base[iit]!='\t' && iit<base.size()) befi=i;
for(i; i<andame; ++i)
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.noneTip = base.substr(iitBef, iit-iitBef); nsp.noneTip = buf.substr(befi, i-befi).c_str();
++i;
inp.getline(tab, 500); befi=i;
inp.getline(tab, 500); for(i; i<andame; ++i)
base = std::string(tab);
nsp.noneTip += std::string("\n");
nsp.noneTip += base;
nsp.noneTip += std::string("\n");
inp.getline(tab, 500);
inp.getline(tab, 500);
base = std::string(tab);
iit = 0;
iitBef = 0;
while(base[iit]!='\t' && iit<base.size())
{ {
++iit; if(buf[i]=='\t')
break;
} }
nsp.noneTip += base.substr(0, iit); nsp.basTip = buf.substr(befi, i-befi).c_str();
++iit; ++i;
iitBef=iit;
////////////// befi=i;
inp.get(tab, 5000, '\r'); for(i; i<andame; ++i)
base = std::string(tab); {
////////////// if(buf[i]=='\t')
break;
}
nsp.advTip = buf.substr(befi, i-befi).c_str();
++i;
nsp.combatSpell = combatSeries; befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nsp.expTip = buf.substr(befi, i-befi).c_str();
++i;
delete [500] tab; befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
nsp.attributes = buf.substr(befi, i-befi).c_str();
++i;
++i;
nsp.combatSpell = combSpells;
spells.push_back(nsp); spells.push_back(nsp);
} }
inp.ignore(); }
}

View File

@ -25,9 +25,10 @@ public:
int powerExp; //efect with expert magic ability int powerExp; //efect with expert magic ability
int castle, rampart, tower, inferno, necropolis, dungeon, stronghold, fortress, conflux; //% chance to gain int castle, rampart, tower, inferno, necropolis, dungeon, stronghold, fortress, conflux; //% chance to gain
int none2, bas2, adv2, exp2; //AI values int none2, bas2, adv2, exp2; //AI values
std::string noneTip, basicTip, advTip, expTip; //descriptions of spell std::string noneTip, basTip, advTip, expTip; //descriptions of spell
std::string attributes; //reference only attributes std::string attributes; //reference only attributes
bool combatSpell; //is this spell combat (true) or adventure (false) bool combatSpell; //is this spell combat (true) or adventure (false)
bool isAllowed; //true if we can use this spell (depends on map)
}; };
class CSpellHandler class CSpellHandler