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

częściowa obsługa zaczytywania budynków (ale to co jest działa i się nie wykrzacza, a nawet jest w miarę sensowne)

przystosowanie zaczytywania na pliki z lodów (zmieniony folder, zaczytuje teraz także pliki angielskojęzyczne); w tym przepisane od nowa zaczytywanie opisów potworów
This commit is contained in:
mateuszb 2007-06-10 18:04:15 +00:00
parent 93e2667e9e
commit eb7ef1d52c
9 changed files with 559 additions and 168 deletions

View File

@ -3,7 +3,7 @@
void CAbilityHandler::loadAbilities()
{
std::ifstream inp("SSTRAITS.TXT", std::ios::in);
std::ifstream inp("H3bitmap.lod\\SSTRAITS.TXT", std::ios::in);
std::string dump;
for(int i=0; i<5; ++i)
{

View File

@ -3,7 +3,7 @@
void CArtHandler::loadArtifacts()
{
std::ifstream inp("ARTRAITS.TXT", std::ios::in);
std::ifstream inp("H3bitmap.lod\\ARTRAITS.TXT", std::ios::in);
std::string dump;
for(int i=0; i<44; ++i)
{
@ -209,7 +209,7 @@ void CArtHandler::loadArtifacts()
bool CArtHandler::loadArtEvents()
{
std::ifstream inp("ARTEVENT.TXT", std::ios::in);
std::ifstream inp("H3bitmap.lod\\ARTEVENT.TXT", std::ios::in);
if(!inp.is_open())
{
return false;

342
CBuildingHandler.cpp Normal file
View File

@ -0,0 +1,342 @@
#include "stdafx.h"
#include "CBuildingHandler.h"
void CBuildingHandler::loadBuildings()
{
std::ifstream inp("H3bitmap.lod\\BUILDING.TXT", std::ios::in | std::ios::binary);
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
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')
++hmcr;
if(hmcr==3)
break;
}
i+=2;
EbuildingType currType; //current type of building
bool currDwel = false; //true, if we are reading dwellings
while(!inp.eof())
{
CBuilding nbu; //currently read building
if(buildings.size()>200 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
break;
std::string firstStr;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
firstStr = buf.substr(befi, i-befi);
++i;
if(firstStr == std::string(""))
{
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
if(firstStr == std::string("Castle"))
{
currType = CASTLE;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Rampart"))
{
currType = RAMPART;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Tower"))
{
currType = TOWER;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Inferno"))
{
currType = INFERNO;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Necropolis"))
{
currType = NECROPOLIS;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Dungeon"))
{
currType = DUNGEON;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Stronghold"))
{
currType = STRONGHOLD;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Fortress"))
{
currType = FORTRESS;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Conflux"))
{
currType = CONFLUX;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Neutral Buildings"))
{
currType = NEUTRAL;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else if(firstStr == std::string("Dwellings"))
{
currDwel = true;
for(i; i<andame; ++i) //omitting rubbish
{
if(buf[i]=='\r')
break;
}
i+=2;
continue;
}
else
{
nbu.wood = atoi(firstStr.c_str());
}
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.mercury = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.ore = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.sulfur = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.crystal = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.gems = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
nbu.gold = atoi(buf.substr(befi, i-befi).c_str());
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r' || buf[i]=='\t')
break;
}
nbu.refName = buf.substr(befi, i-befi);
i+=2;
nbu.type = currType;
nbu.isDwelling = currDwel;
if(nbu.refName[0]==' ')
nbu.refName = nbu.refName.substr(1, nbu.name.size()-1);
buildings.push_back(nbu);
}
loadNames();
}
void CBuildingHandler::loadNames()
{
std::ifstream inp("H3bitmap.lod\\BLDGSPEC.TXT", std::ios::in | std::ios::binary);
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
std::string buf = std::string(bufor);
delete [andame] bufor;
int i=0; //buf iterator
for(int ii=0; ii<9; ++ii)
{
for(int q=0; q<11; ++q)
{
if (q<9) //normal building names and descriptions
{
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
buildings[ii*9+q].name = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
buildings[ii*9+q].description = buf.substr(befi, i-befi);
i+=2;
}
else if (q==9) //for graal buildings
{
CBuilding graal;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
graal.name = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
graal.description = buf.substr(befi, i-befi);
i+=2;
graal.type = EbuildingType(ii+1);
graal.wood = graal.mercury = graal.ore = graal.sulfur = graal.crystal = graal.gems = graal.gold = 0;
graal.isDwelling = false;
graals.push_back(graal);
}
else //for resource silos
{
CBuilding graal;
int befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\t')
break;
}
graal.name = buf.substr(befi, i-befi);
++i;
befi=i;
for(i; i<andame; ++i)
{
if(buf[i]=='\r')
break;
}
graal.description = buf.substr(befi, i-befi);
i+=2;
graal.type = EbuildingType(ii+1);
graal.wood = graal.mercury = graal.ore = graal.sulfur = graal.crystal = graal.gems = graal.gold = 0;
graal.isDwelling = false;
resourceSilos.push_back(graal);
}
}
}
}

30
CBuildingHandler.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef CBUILDINGHANDLER_H
#define CBUILDINGHANDLER_H
#include <vector>
#include <string>
enum EbuildingType {NEUTRAL=0, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX};
class CBuilding //a typical building encountered in every castle ;]
{
public:
std::string name;
std::string refName; //reference name, for identification
int wood, mercury, ore, sulfur, crystal, gems, gold;
std::string description;
EbuildingType type; //type of building (occures in many castles or is specific for one castle)
bool isDwelling; //true, if this building is a dwelling
};
class CBuildingHandler
{
public:
std::vector<CBuilding> buildings; //vector of buildings
std::vector<CBuilding> resourceSilos; //vector with resource silos only - for castle profiled descriptions
std::vector<CBuilding> graals; //vector with graal - type buildings only - for castle profiled descriptions
void loadBuildings();
void loadNames();
};
#endif //CBUILDINGHANDLER_H

View File

@ -3,245 +3,258 @@
void CCreatureHandler::loadCreatures()
{
std::ifstream inp("ZCRTRAIT.TXT", std::ios::in);
std::string dump;
for(int i=0; i<42; ++i)
std::ifstream inp("H3bitmap.lod\\ZCRTRAIT.TXT", std::ios::in|std::ios::binary);
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
std::string buf = std::string(bufor);
delete [andame] bufor;
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
{
inp>>dump;
if(buf[i]=='\r')
++hmcr;
if(hmcr==2)
break;
}
inp.ignore();
while(!inp.eof())
i+=2;
while(i<buf.size())
{
CCreature ncre; //new creature, that will be read
std::string base;
char * tab = new char[500];
int iitBef = 0;
int iit = 0;
inp.getline(tab, 500);
base = std::string(tab);
if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
{
return; //add counter
}
while(base[iit]!='\t')
{
++iit;
}
ncre.nameSing = base.substr(0, iit);
++iit;
iitBef=iit;
if(creatures.size()>190 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
break;
//////// omijanie problemu z kasowaniem znaków CR - ifujê problematyczne miejsca
if(ncre.nameSing==std::string("Wilko³ak") || ncre.nameSing==std::string("Werewolf")
|| ncre.nameSing==std::string("Piekielny Rumak") || ncre.nameSing==std::string("Hell Steed")
|| ncre.nameSing==std::string("Sylwañski Centaur") || ncre.nameSing==std::string("Sylvan Centaur"))
{
std::string base2;
char * tab2 = new char[500];
inp.getline(tab2, 500);
base2 = std::string(tab2);
base+=base2;
}
///////
CCreature ncre;
while(base[iit]!='\t')
int befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.namePl = base.substr(iitBef, iit-iitBef);
++iit;
iitBef=iit;
ncre.nameSing = buf.substr(befi, i-befi);
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.wood = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.namePl = buf.substr(befi, i-befi);
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.mercury = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.wood = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.ore = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.mercury = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.sulfur = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.ore = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.crystal = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.sulfur = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.gems = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.crystal = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.gold = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.gems = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.fightValue = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.gold = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.AIValue = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.fightValue = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.growth = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.AIValue = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.hordeGrowth = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.growth = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.hitPoints = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.hordeGrowth = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.speed = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.hitPoints = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.attack = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.speed = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.defence = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.attack = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.low1 = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.defence = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.high1 = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.low1 = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.shots = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.high1 = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.spells = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.shots = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.low2 = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.spells = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.high2 = atoi(base.substr(iitBef, iit-iitBef).c_str());
++iit;
iitBef=iit;
ncre.low2 = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t')
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.abilityText = base.substr(iitBef, iit-iitBef);
++iit;
iitBef=iit;
ncre.high2 = atoi(buf.substr(befi, i-befi).c_str());
++i;
while(base[iit]!='\t' && iit<base.size())
befi=i;
for(i; i<andame; ++i)
{
++iit;
if(buf[i]=='\t')
break;
}
ncre.abilityRefs = base.substr(iitBef, iit-iitBef);
++iit;
iitBef=iit;
ncre.abilityText = buf.substr(befi, i-befi);
++i;
if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
befi=i;
for(i; i<andame; ++i)
{
ncre.idNumber=creatures.size();
creatures.push_back(ncre);
if(buf[i]=='\r')
break;
}
delete[500] tab;
ncre.abilityRefs = buf.substr(befi, i-befi);
i+=2;
ncre.idNumber = creatures.size();
creatures.push_back(ncre);
}
}

View File

@ -7,6 +7,7 @@
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CAmbarCendamo.h"
#include "CBuildingHandler.h"
/*
CGameInfo class
@ -22,6 +23,7 @@ public:
CAbilityHandler * abilh;
CSpellHandler * spellh;
CAmbarCendamo * ac;
CBuildingHandler * buildh;
};
#endif //CGAMEINFO_H

View File

@ -3,7 +3,7 @@
void CHeroHandler::loadHeroes()
{
std::ifstream inp("HOTRAITS.TXT", std::ios::in);
std::ifstream inp("H3bitmap.lod\\HOTRAITS.TXT", std::ios::in);
std::string dump;
for(int i=0; i<25; ++i)
{
@ -105,7 +105,7 @@ void CHeroHandler::loadHeroes()
}
void CHeroHandler::loadSpecialAbilities()
{
std::ifstream inp("HeroSpec.txt", std::ios::in);
std::ifstream inp("H3bitmap.lod\\HEROSPEC.txt", std::ios::in);
std::string dump;
for(int i=0; i<7; ++i)
{
@ -113,7 +113,7 @@ void CHeroHandler::loadSpecialAbilities()
}
inp.ignore();
int whHero=0;
while(!inp.eof())
while(!inp.eof() && whHero<heroes.size())
{
std::string base;
char * tab = new char[500];

View File

@ -15,6 +15,7 @@
#include "CCreatureHandler.h"
#include "CAbilityHandler.h"
#include "CSpellHandler.h"
#include "CBuildingHandler.h"
#include "CGameInfo.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
@ -243,8 +244,11 @@ int _tmain(int argc, _TCHAR* argv[])
abilh->loadAbilities();
cgi->abilh = abilh;
CSpellHandler * spellh = new CSpellHandler;
spellh->loadSpells(); //TODO - naprawić i dokończyć!
spellh->loadSpells();
cgi->spellh = spellh;
CBuildingHandler * buildh = new CBuildingHandler;
buildh->loadBuildings();
cgi->buildh = buildh;
CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
cgi->ac = ac;
THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;

View File

@ -3,7 +3,7 @@
void CSpellHandler::loadSpells()
{
std::ifstream inp("SPTRAITS.TXT", std::ios::in | std::ios::binary);
std::ifstream inp("H3bitmap.lod\\SPTRAITS.TXT", std::ios::in | std::ios::binary);
inp.seekg(0,std::ios::end); // na koniec
int andame = inp.tellg(); // read length
inp.seekg(0,std::ios::beg); // wracamy na poczatek