1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

reading some text files from lods, enabling object sorting

This commit is contained in:
mateuszb 2007-07-16 14:42:44 +00:00
parent b65f1dae0f
commit cc67967051
13 changed files with 133 additions and 125 deletions

View File

@ -12,7 +12,7 @@ void CAbilityHandler::loadAbilities()
inp.ignore();
while(!inp.eof())
{
CAbility nab; //new creature, that will be read
CAbility * nab = new CAbility; //new creature, that will be read
std::string base;
char * tab = new char[500];
int iitBef = 0;
@ -28,11 +28,11 @@ void CAbilityHandler::loadAbilities()
{
++iit;
}
nab.name = base.substr(0, iit);
nab->name = base.substr(0, iit);
++iit;
iitBef=iit;
nab.basicText = base.substr(iitBef, base.size()-iitBef);
nab->basicText = base.substr(iitBef, base.size()-iitBef);
inp.getline(tab, 500);
inp.getline(tab, 500);
@ -45,11 +45,11 @@ void CAbilityHandler::loadAbilities()
{
++iit;
}
nab.basicText2 = base.substr(0, iit);
nab->basicText2 = base.substr(0, iit);
++iit;
iitBef=iit;
nab.advText = base.substr(iitBef, base.size()-iitBef);
nab->advText = base.substr(iitBef, base.size()-iitBef);
inp.getline(tab, 500);
inp.getline(tab, 500);
@ -62,19 +62,19 @@ void CAbilityHandler::loadAbilities()
{
++iit;
}
nab.advText2 = base.substr(0, iit);
nab->advText2 = base.substr(0, iit);
++iit;
iitBef=iit;
nab.expText = base.substr(iitBef, base.size()-iitBef);
nab->expText = base.substr(iitBef, base.size()-iitBef);
inp.getline(tab, 500);
inp.getline(tab, 500);
base = std::string(tab);
nab.expText2 = base;
nab->expText2 = base;
nab.idNumber = abilities.size();
nab->idNumber = abilities.size();
abilities.push_back(nab);
delete [500] tab;
}

View File

@ -18,7 +18,7 @@ public:
class CAbilityHandler
{
public:
std::vector<CAbility> abilities;
std::vector<CAbility *> abilities;
void loadAbilities();
};

View File

@ -345,9 +345,9 @@ void CAmbarCendamo::deh3m()
if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
{
if(c != (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = true;
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = true;
else
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy].isAllowed = false;
CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]->isAllowed = false;
}
}
}
@ -462,7 +462,7 @@ void CAmbarCendamo::deh3m()
int howManyObjs = readNormalNr(i, 4); i+=4;
for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
{
std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
//std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
CObjectInstance nobj; //we will read this object
nobj.id = CGameInfo::mainObj->objh->objInstances.size();
nobj.x = bufor[i++];
@ -533,7 +533,7 @@ void CAmbarCendamo::deh3m()
gabn = readNormalNr(i, 1); ++i;
for(int oo = 0; oo<gabn; ++oo)
{
spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
}
int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
@ -591,7 +591,7 @@ void CAmbarCendamo::deh3m()
int howMany = readNormalNr(i); i+=4;
for(int yy=0; yy<howMany; ++yy)
{
spec->abilities.push_back(&(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)])); ++i;
spec->abilities.push_back(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)]); ++i;
spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
}
}
@ -1069,7 +1069,7 @@ void CAmbarCendamo::deh3m()
case 7:
{
int abid = bufor[i]; ++i;
spec->r7ability = &(CGameInfo::mainObj->abilh->abilities[abid]);
spec->r7ability = CGameInfo::mainObj->abilh->abilities[abid];
spec->r7level = bufor[i]; ++i;
break;
}
@ -1109,7 +1109,7 @@ void CAmbarCendamo::deh3m()
if((i-ist)*8+yy < CGameInfo::mainObj->abilh->abilities.size())
{
if(c == (c|((unsigned char)intPow(2, yy))))
spec->allowedAbilities.push_back(&(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]));
spec->allowedAbilities.push_back(CGameInfo::mainObj->abilh->abilities[(i-ist)*8+yy]);
}
}
}
@ -1130,7 +1130,7 @@ void CAmbarCendamo::deh3m()
spec->r0type = bufor[i]; ++i;
break;
case 1:
spec->r1 = &(CGameInfo::mainObj->abilh->abilities[bufor[i]]); ++i;
spec->r1 = CGameInfo::mainObj->abilh->abilities[bufor[i]]; ++i;
break;
case 2:
spec->r2 = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
@ -1398,7 +1398,7 @@ void CAmbarCendamo::deh3m()
gabn = readNormalNr(i, 1); ++i;
for(int oo = 0; oo<gabn; ++oo)
{
spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
spec->abilities.push_back((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)]); ++i;
spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
}
int gart = readNormalNr(i, 1); ++i; //number of gained artifacts

View File

@ -1,17 +1,11 @@
#include "stdafx.h"
#include "CGameInfo.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("BUILDING.TXT");
int andame = buf.size();
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i) //omitting rubbish
@ -24,7 +18,7 @@ void CBuildingHandler::loadBuildings()
i+=2;
EbuildingType currType; //current type of building
bool currDwel = false; //true, if we are reading dwellings
while(!inp.eof())
while(true)
{
CBuilding nbu; //currently read building
if(buildings.size()>200 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos)
@ -255,15 +249,8 @@ void CBuildingHandler::loadBuildings()
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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("BLDGSPEC.TXT");
int andame = buf.size();
int i=0; //buf iterator
for(int ii=0; ii<9; ++ii)
{
@ -519,15 +506,8 @@ void CBuildingHandler::loadNames()
void CBuildingHandler::loadNeutNames()
{
std::ifstream inp("H3bitmap.lod\\BLDGNEUT.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("BLDGNEUT.TXT");
int andame = buf.size();
int i=0; //buf iterator
for(int q=0; q<15; ++q)
{
@ -643,15 +623,8 @@ void CBuildingHandler::loadNeutNames()
void CBuildingHandler::loadDwellingNames()
{
std::ifstream inp("H3bitmap.lod\\DWELLING.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("DWELLING.TXT");
int andame = buf.size();
int i = 0; //buf iterator
int whdw = 98; //wchich dwelling we are currently reading
for(whdw; whdw<224; ++whdw)

View File

@ -1,16 +1,11 @@
#include "stdafx.h"
#include "CGameInfo.h"
#include "CCreatureHandler.h"
void CCreatureHandler::loadCreatures()
{
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;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("ZCRTRAIT.TXT");
int andame = buf.size();
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
@ -277,15 +272,8 @@ void CCreatureHandler::loadCreatures()
void CCreatureHandler::loadAnimationInfo()
{
std::ifstream inp("H3bitmap.lod\\CRANIM.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("CRANIM.TXT");
int andame = buf.size();
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)

View File

@ -1,18 +1,12 @@
#include "stdafx.h"
#include "CGeneralTextHandler.h"
#include "CGameInfo.h"
#include <fstream>
void CGeneralTextHandler::load()
{
std::ifstream inp("H3bitmap.lod\\GENRLTXT.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("GENRLTXT.TXT");
int andame = buf.size();
int i=0; //buf iterator
for(i; i<andame; ++i)
{

View File

@ -228,15 +228,20 @@ void CHeroHandler::loadBiographies()
void CHeroHandler::loadHeroClasses()
{
std::ifstream inp("H3bitmap.lod\\HCTRAITS.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
//std::ifstream inp("H3bitmap.lod\\HCTRAITS.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
//inp.close();
//std::string buf = std::string(bufor);
//delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HCTRAITS.TXT");
int andame = buf.size();
for(int y=0; y<andame; ++y)
if(buf[y]==',')
buf[y]='.';
int i = 0; //buf iterator
int hmcr = 0;
for(i; i<andame; ++i) //omitting rubbish

View File

@ -836,3 +836,41 @@ void CLodHandler::init(std::string lodFile)
entries[i].size=readNormalNr(temp,4);
}
}
std::string CLodHandler::getTextFile(std::string name)
{
std::string ret0;
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
int i;
for (int i=0;i<totalFiles;i++)
{
std::string buf1 = std::string((char*)entries[i].name);
bool exists = false;
int curDef;
if(buf1!=name)
continue;
FLOD.seekg(entries[i].offset,std::ios_base::beg);
unsigned char * outp;
if (entries[i].size==0) //file is not compressed
{
outp = new unsigned char[entries[i].realSize];
FLOD.read((char*)outp, entries[i].realSize);
std::string ret = std::string((char*)outp);
delete outp;
return ret;
}
else //we will decompressing file
{
outp = new unsigned char[entries[i].size];
FLOD.read((char*)outp, entries[i].size);
FLOD.seekg(0, std::ios_base::beg);
unsigned char * decomp = NULL;
int decRes = infs2(outp, entries[i].size, entries[i].realSize, decomp);
std::string ret = std::string((char*)decomp);
delete outp;
delete decomp;
return ret;
}
}
return ret0;
}

View File

@ -63,6 +63,7 @@ public:
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn); //extrats given files (defs only)
CDefHandler * giveDef(std::string defName);
std::string getTextFile(std::string name); //extracts one file
void extract(std::string FName);
void extractFile(std::string FName, std::string name); //extracts a specific file
void init(std::string lodFile);

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "CPreGameTextHandler.h"
#include "CGameInfo.h"
std::string CPreGameTextHandler::getTitle(std::string text)
{
std::string ret;
@ -492,15 +493,17 @@ void CPreGameTextHandler::loadToIt(std::string &dest, std::string &src, int &ite
void CPreGameTextHandler::loadVictoryConditions()
{
std::ifstream inp("H3bitmap.lod\\VCDESC.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
//std::ifstream inp("H3bitmap.lod\\VCDESC.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
//inp.close();
//std::string buf = std::string(bufor);
//delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("VCDESC.TXT");
int andame = buf.size();
int i=0; //buf iterator
for(int gg=0; gg<14; ++gg)
@ -518,15 +521,17 @@ void CPreGameTextHandler::loadVictoryConditions()
void CPreGameTextHandler::loadLossConditions()
{
std::ifstream inp("H3bitmap.lod\\LCDESC.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
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
//std::ifstream inp("H3bitmap.lod\\LCDESC.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
//inp.close();
//std::string buf = std::string(bufor);
//delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("LCDESC.TXT");
int andame = buf.size();
int i=0; //buf iterator
for(int gg=0; gg<4; ++gg)

View File

@ -1,17 +1,11 @@
#include "stdafx.h"
#include "CSpellHandler.h"
#include "CGameInfo.h"
void CSpellHandler::loadSpells()
{
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
char * bufor = new char[andame]; // allocate memory
inp.read((char*)bufor, andame); // read map file to buffer
inp.close();
std::string buf = std::string(bufor);
delete [andame] bufor;
std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("SPTRAITS.TXT");
int andame = buf.size();
int i=0; //buf iterator
int hmcr=0;
for(i; i<andame; ++i)
@ -25,6 +19,8 @@ void CSpellHandler::loadSpells()
bool combSpells=false; //true, if we are reading combat spells
while(i<andame)
{
if(spells.size()==81)
break;
CSpell nsp; //new currently being read spell
int befi=i;
for(i; i<andame; ++i)

View File

@ -353,12 +353,21 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
}
}
}
//std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), pox);
//std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), poy);
//std::stable_sort(highPrObjs.begin(), highPrObjs.end(),pox);
//std::stable_sort(highPrObjs.begin(), highPrObjs.end(),poy);
//std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
//std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
#ifndef _DEBUG
std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), pox);
std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), poy);
std::stable_sort(highPrObjs.begin(), highPrObjs.end(),pox);
std::stable_sort(highPrObjs.begin(), highPrObjs.end(),poy);
std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
#else
std::sort(lowPrObjs.begin(), lowPrObjs.end(), pox);
std::sort(lowPrObjs.begin(), lowPrObjs.end(), poy);
std::sort(highPrObjs.begin(), highPrObjs.end(),pox);
std::sort(highPrObjs.begin(), highPrObjs.end(),poy);
std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
#endif
for(int yy=0; yy<lowPrObjs.size(); ++yy)
{
SDL_Rect * sr = new SDL_Rect;

View File

@ -5,7 +5,6 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>