1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

- changes in LodHandler:

-- file type (text, image...) can be specified in getFile(), all hacks removed
-- replaced Nodrze with std::set
-  some gcc warnings fixed
This commit is contained in:
Ivan Savenko
2010-11-09 11:27:58 +00:00
parent 4434a73651
commit 9771dd12ff
17 changed files with 206 additions and 219 deletions

View File

@ -155,62 +155,34 @@ SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
tlog2 << "Call to loadBitmap with void fname!\n"; tlog2 << "Call to loadBitmap with void fname!\n";
return NULL; return NULL;
} }
unsigned char * pcx; SDL_Surface * ret=NULL;
std::transform(fname.begin(),fname.end(),fname.begin(),toupper); int size;
int dotPos = fname.find_last_of('.'); unsigned char * file = bitmaph->giveFile(fname, FILE_GRAPHICS, &size);
if ( dotPos != -1 )
fname.erase(dotPos);
Entry *e = bitmaph->entries.znajdz(fname); if (!file)
if(!e)
{ {
tlog2<<"Entry for file "<<fname<<" was not found"<<std::endl; tlog2<<"Entry for file "<<fname<<" was not found"<<std::endl;
return NULL; return NULL;
} }
if(e->offset<0)//not in LOD
{ if (isPCX(file))
fname = e->realName; {//H3-style PCX
fname = DATA_DIR "/Data/" + fname;
FILE * f = fopen(fname.c_str(),"r");
unsigned char sign[12];
if(!f)
{
tlog1 << "Cannot open " << fname << " - file not found!\n";
return NULL;
}
fread(sign,1,12,f);
SDL_Surface * ret=NULL;
if (isPCX(sign))//H3-style PCX
{
CPCXConv cp; CPCXConv cp;
pcx = new unsigned char[e->realSize]; cp.openPCX((char*)file,size);
memcpy(pcx,sign,3);
int res = fread((char*)pcx+3, 1, e->realSize-3, f); //TODO use me
fclose(f);
cp.openPCX((char*)pcx,e->realSize);
ret = cp.getSurface(); ret = cp.getSurface();
if (!ret) if (!ret)
tlog1<<"Failed to open "<<fname<<" as H3 PCX!\n"; tlog1<<"Failed to open "<<fname<<" as H3 PCX!\n";
}
else //try loading via SDL_Image
{
fclose(f);
ret = IMG_Load(fname.c_str());
if (!ret)
tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";
}
return ret;
}
//loading from LOD
pcx = bitmaph->giveFile(e->nameStr, NULL);
CPCXConv cp;
cp.openPCX((char*)pcx, e->realSize);
SDL_Surface * ret = cp.getSurface();
if(ret->format->BytesPerPixel == 1 && setKey) if(ret->format->BytesPerPixel == 1 && setKey)
{ {
const SDL_Color &c = ret->format->palette->colors[0]; const SDL_Color &c = ret->format->palette->colors[0];
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b)); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b));
} }
}
else
{ //loading via SDL_Image
ret = IMG_Load_RW( SDL_RWFromMem((void*)file, size), 1);
if (!ret)
tlog1<<"Failed to open "<<fname<<" via SDL_Image\n";
}
return ret; return ret;
} }

View File

@ -39,7 +39,7 @@ void CCreatureAnimation::setType(int type)
CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), once(false) CCreatureAnimation::CCreatureAnimation(std::string name) : internalFrame(0), once(false)
{ {
FDef = spriteh->giveFile(name); //load main file FDef = spriteh->giveFile(name, FILE_ANIMATION); //load main file
//init anim data //init anim data
int i,j, totalInBlock; int i,j, totalInBlock;

View File

@ -412,23 +412,10 @@ void processCommand(const std::string &message)
CLodHandler * txth = new CLodHandler; CLodHandler * txth = new CLodHandler;
txth->init(std::string(DATA_DIR "/Data/H3bitmap.lod"),""); txth->init(std::string(DATA_DIR "/Data/H3bitmap.lod"),"");
tlog0<<"done.\nScanning .lod file\n"; tlog0<<"done.\nScanning .lod file\n";
int curp=0;
std::string pattern = ".TXT", pom; BOOST_FOREACH(Entry e, txth->entries)
for(int i=0;i<txth->entries.size(); i++) if( e.type == FILE_TEXT )
{ txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+e.name,e.name);
pom = txth->entries[i].nameStr;
if(boost::algorithm::find_last(pom,pattern))
{
txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+pom,pom);
}
if(i%8) continue;
int p2 = ((float)i/(float)txth->entries.size())*(float)100;
if(p2!=curp)
{
curp = p2;
tlog0<<"\r"<<curp<<"%";
}
}
tlog0<<"\rExtracting done :)\n"; tlog0<<"\rExtracting done :)\n";
} }
else if(cn=="crash") else if(cn=="crash")

View File

@ -159,7 +159,7 @@ SDL_Surface * Graphics::drawTownInfoWin( const InfoAboutTown & curh )
void Graphics::loadPaletteAndColors() void Graphics::loadPaletteAndColors()
{ {
std::string pals = bitmaph->getTextFile("PLAYERS.PAL"); std::string pals = bitmaph->getTextFile("PLAYERS.PAL", FILE_OTHER);
playerColorPalette = new SDL_Color[256]; playerColorPalette = new SDL_Color[256];
neutralColor = new SDL_Color; neutralColor = new SDL_Color;
playerColors = new SDL_Color[PLAYER_LIMIT]; playerColors = new SDL_Color[PLAYER_LIMIT];
@ -690,7 +690,7 @@ void Graphics::loadTrueType()
Font * Graphics::loadFont( const char * name ) Font * Graphics::loadFont( const char * name )
{ {
int len = 0; int len = 0;
unsigned char * hlp = bitmaph->giveFile(name, &len); unsigned char * hlp = bitmaph->giveFile(name, FILE_FONT, &len);
if(!hlp || !len) if(!hlp || !len)
{ {
tlog1 << "Error: cannot load font: " << name << std::endl; tlog1 << "Error: cannot load font: " << name << std::endl;
@ -698,7 +698,7 @@ Font * Graphics::loadFont( const char * name )
} }
int magic = *(const int*)hlp; int magic = *(const int*)hlp;
if(len < 10000 || magic != 589598 && magic != 589599) if(len < 10000 || (magic != 589598 && magic != 589599))
{ {
tlog1 << "Suspicious font file (length " << len <<", fname " << name << "), logging to suspicious_" << name << ".fnt\n"; tlog1 << "Suspicious font file (length " << len <<", fname " << name << "), logging to suspicious_" << name << ".fnt\n";
std::string suspFName = "suspicious_" + std::string(name) + ".fnt"; std::string suspFName = "suspicious_" + std::string(name) + ".fnt";
@ -717,7 +717,6 @@ void Graphics::loadFonts()
assert(ARRAY_COUNT(fontnames) == FONTS_NUMBER); assert(ARRAY_COUNT(fontnames) == FONTS_NUMBER);
for(int i = 0; i < FONTS_NUMBER; i++) for(int i = 0; i < FONTS_NUMBER; i++)
if(i != 2) //TODO TODO TODO !!!
fonts[i] = loadFont(fontnames[i]); fonts[i] = loadFont(fontnames[i]);
} }

View File

@ -282,7 +282,7 @@ BMPPalette * CDefFile::getPalette()
CDefFile::CDefFile(std::string Name):data(NULL),colors(NULL) CDefFile::CDefFile(std::string Name):data(NULL),colors(NULL)
{ {
data = spriteh->giveFile(Name, &datasize); data = spriteh->giveFile(Name, FILE_ANIMATION, &datasize);
if (!data) if (!data)
{ {
tlog0<<"Error: file "<< Name <<" not found\n"; tlog0<<"Error: file "<< Name <<" not found\n";
@ -399,7 +399,7 @@ bool CAnimation::loadFrame(CDefFile * file, size_t frame, size_t group)
else else
str << name << '#' << (frame+1);//file#34.* str << name << '#' << (frame+1);//file#34.*
pic = spriteh->giveFile(str.str(), &size); pic = spriteh->giveFile(str.str(), FILE_GRAPHICS, &size);
if (pic) if (pic)
{ {
if (compressed) if (compressed)

View File

@ -53,13 +53,11 @@ std::vector<CCampaignHeader> CCampaignHandler::getCampaignHeaders(GetMode mode)
} }
if (mode == ALL) //add all lod campaigns if (mode == ALL) //add all lod campaigns
{ {
ext = "#H3C"; BOOST_FOREACH(Entry e, bitmaph->entries)
for(int g=0; g<bitmaph->entries.size(); ++g)
{ {
const std::string & nameS = bitmaph->entries[g].nameStr; if( e.type == FILE_CAMPAIGN && e.name != "TOSBLK1" )
if( boost::ends_with(nameS, ext) && nameS != "TOSBLK1#H3C" )
{ {
ret.push_back( getHeader(bitmaph->entries[g].nameStr, true) ); ret.push_back( getHeader(e.name, true) );
} }
} }
@ -422,7 +420,7 @@ unsigned char * CCampaignHandler::getFile( const std::string & name, bool fromLo
unsigned char * cmpgn; unsigned char * cmpgn;
if(fromLod) if(fromLod)
{ {
cmpgn = bitmaph->giveFile(name, &outSize); cmpgn = bitmaph->giveFile(name, FILE_CAMPAIGN, &outSize);
FILE * tmp = fopen("tmp_cmpgn", "wb"); FILE * tmp = fopen("tmp_cmpgn", "wb");
fwrite(cmpgn, 1, outSize, tmp); fwrite(cmpgn, 1, outSize, tmp);
fclose(tmp); fclose(tmp);

View File

@ -365,7 +365,7 @@ CDefEssential * CDefHandler::essentialize()
CDefHandler * CDefHandler::giveDef(const std::string & defName) CDefHandler * CDefHandler::giveDef(const std::string & defName)
{ {
unsigned char * data = spriteh->giveFile(defName); unsigned char * data = spriteh->giveFile(defName, FILE_ANIMATION);
if(!data) if(!data)
throw "bad def name!"; throw "bad def name!";
CDefHandler * nh = new CDefHandler(); CDefHandler * nh = new CDefHandler();

View File

@ -38,8 +38,7 @@ CGDefInfo::CGDefInfo()
void CGDefInfo::fetchInfoFromMSK() void CGDefInfo::fetchInfoFromMSK()
{ {
std::string nameCopy = name; std::string msk = spriteh->getTextFile(name, FILE_MASK);
std::string msk = spriteh->getTextFile(nameCopy.replace( nameCopy.size()-4, 4, "#MSK" ));
width = msk[0]; width = msk[0];
height = msk[1]; height = msk[1];

View File

@ -7,11 +7,11 @@
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <fstream>
#include "boost/filesystem/operations.hpp" #include "boost/filesystem/operations.hpp"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/foreach.hpp>
#include <SDL_endian.h> #include <SDL_endian.h>
#ifdef max #ifdef max
#undef max #undef max
@ -60,58 +60,69 @@ std::string readString(const unsigned char * bufor, int &i)
return ret; return ret;
} }
unsigned char * CLodHandler::giveFile(std::string defName, int * length) Entry CLodHandler::getEntry(const std::string name, LodFileType type)
{ {
std::transform(defName.begin(), defName.end(), defName.begin(), (int(*)(int))toupper); Entry ret;
int dotPos = defName.find_last_of('.'); std::set<Entry>::iterator it = entries.find(Entry(name, type));
if ( dotPos != -1 )
defName.erase(dotPos);
Entry * ourEntry = entries.znajdz(Entry(defName)); if (it!=entries.end())
if(!ourEntry) //nothing's been found ret = *it;
return ret;
}
unsigned char * CLodHandler::giveFile(const std::string defName, LodFileType type, int * length)
{
std::string fname = defName;
std::transform(fname.begin(), fname.end(), fname.begin(), (int(*)(int))toupper);
int dotPos = fname.find_last_of('.');
if ( dotPos != -1 )
fname.erase(dotPos);
Entry ourEntry = getEntry(fname, type);
if(!vstd::contains(entries, ourEntry)) //nothing's been found
{ {
tlog1 << "Cannot find file: " << defName << std::endl; tlog1 << "Cannot find file: " << fname << std::endl;
return NULL; return NULL;
} }
if(length) *length = ourEntry->realSize; if(length) *length = ourEntry.realSize;
mutex->lock(); mutex->lock();
unsigned char * outp; unsigned char * outp;
if (ourEntry->offset<0) //file is in the sprites/ folder; no compression if (ourEntry.offset<0) //file is in the sprites/ folder; no compression
{ {
int result; int result;
unsigned char * outp = new unsigned char[ourEntry->realSize]; unsigned char * outp = new unsigned char[ourEntry.realSize];
FILE * f = fopen((myDir + "/" + ourEntry->realName).c_str(), "rb"); FILE * f = fopen((myDir + "/" + ourEntry.realName).c_str(), "rb");
if (f) { if (f) {
result = fread(outp,1,ourEntry->realSize,f); result = fread(outp,1,ourEntry.realSize,f);
fclose(f); fclose(f);
} else } else
result = -1; result = -1;
mutex->unlock(); mutex->unlock();
if(result<0) { if(result<0) {
tlog1<<"Error in file reading: " << myDir << "/" << ourEntry->nameStr << std::endl; tlog1<<"Error in file reading: " << myDir << "/" << ourEntry.name << std::endl;
delete[] outp; delete[] outp;
return NULL; return NULL;
} else } else
return outp; return outp;
} }
else if (ourEntry->size==0) //file is not compressed else if (ourEntry.size==0) //file is not compressed
{ {
outp = new unsigned char[ourEntry->realSize]; outp = new unsigned char[ourEntry.realSize];
LOD.seekg(ourEntry->offset, std::ios::beg); LOD.seekg(ourEntry.offset, std::ios::beg);
LOD.read((char*)outp, ourEntry->realSize); LOD.read((char*)outp, ourEntry.realSize);
mutex->unlock(); mutex->unlock();
return outp; return outp;
} }
else //we will decompress file else //we will decompress file
{ {
outp = new unsigned char[ourEntry->size]; outp = new unsigned char[ourEntry.size];
LOD.seekg(ourEntry->offset, std::ios::beg); LOD.seekg(ourEntry.offset, std::ios::beg);
LOD.read((char*)outp, ourEntry->size); LOD.read((char*)outp, ourEntry.size);
unsigned char * decomp = NULL; unsigned char * decomp = NULL;
infs2(outp, ourEntry->size, ourEntry->realSize, decomp); infs2(outp, ourEntry.size, ourEntry.realSize, decomp);
mutex->unlock(); mutex->unlock();
delete[] outp; delete[] outp;
return decomp; return decomp;
@ -119,15 +130,15 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
return NULL; return NULL;
} }
bool CLodHandler::haveFile(std::string name) bool CLodHandler::haveFile(const std::string name, LodFileType type)
{ {
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); std::string fname = name;
int dotPos = name.find_last_of('.'); std::transform(fname.begin(), fname.end(), fname.begin(), (int(*)(int))toupper);
int dotPos = fname.find_last_of('.');
if ( dotPos != -1 ) if ( dotPos != -1 )
name.erase(dotPos); fname.erase(dotPos);
Entry * ourEntry = entries.znajdz(Entry(name)); return vstd::contains(entries, Entry(fname, type));
return ourEntry != NULL;
} }
DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits) DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char *& out, int wBits)
@ -194,10 +205,10 @@ DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, un
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
} }
void CLodHandler::extractFile(std::string FName, std::string name) void CLodHandler::extractFile(const std::string FName, const std::string name)
{ {
int len; //length of file to write int len; //length of file to write
unsigned char * outp = giveFile(name, &len); unsigned char * outp = giveFile(name, FILE_ANY, &len);
std::ofstream out; std::ofstream out;
out.open(FName.c_str(), std::ios::binary); out.open(FName.c_str(), std::ios::binary);
if(!out.is_open()) if(!out.is_open())
@ -211,11 +222,44 @@ void CLodHandler::extractFile(std::string FName, std::string name)
} }
} }
void CLodHandler::init(std::string lodFile, std::string dirName) void CLodHandler::initEntry(Entry &e, const std::string name)
{ {
e.name = name;
//file names stored in upper case without extension
std::transform(e.name.begin(), e.name.end(), e.name.begin(), toupper);
std::string ext;
size_t dotPos = e.name.find_last_of('.');
if ( dotPos < e.name.size() )
{
ext = e.name.substr(dotPos);
e.name.erase(dotPos);
}
std::map<std::string, LodFileType>::iterator it = extMap.find(ext);
if (it == extMap.end())
e.type = FILE_OTHER;
else
e.type = it->second;
}
void CLodHandler::init(const std::string lodFile, const std::string dirName)
{
#define EXT(NAME, TYPE) extMap.insert(std::pair<std::string, LodFileType>(NAME, TYPE));
EXT(".TXT", FILE_TEXT);
EXT(".DEF", FILE_ANIMATION);
EXT(".MSK", FILE_MASK);
EXT(".MSG", FILE_MASK);
EXT(".H3C", FILE_CAMPAIGN);
EXT(".H3M", FILE_MAP);
EXT(".FNT", FILE_FONT);
EXT(".BMP", FILE_GRAPHICS);
EXT(".JPG", FILE_GRAPHICS);
EXT(".PCX", FILE_GRAPHICS);
EXT(".PNG", FILE_GRAPHICS);
#undef EXT
myDir = dirName; myDir = dirName;
std::string Ts;
Uint32 temp;
LOD.open(lodFile.c_str(), std::ios::in | std::ios::binary); LOD.open(lodFile.c_str(), std::ios::in | std::ios::binary);
@ -225,6 +269,7 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
return; return;
} }
Uint32 temp;
LOD.seekg(8); LOD.seekg(8);
LOD.read((char *)&temp, 4); LOD.read((char *)&temp, 4);
totalFiles = SDL_SwapLE32(temp); totalFiles = SDL_SwapLE32(temp);
@ -237,30 +282,13 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
for (unsigned int i=0; i<totalFiles; i++) for (unsigned int i=0; i<totalFiles; i++)
{ {
Entry entry; Entry entry;
initEntry(entry, lodEntries[i].filename);
entry.nameStr = lodEntries[i].filename;
//format string: upper-case, remove extension
std::transform(entry.nameStr.begin(), entry.nameStr.end(),
entry.nameStr.begin(), toupper);
if(entry.nameStr == "GARRISON.TXT") //crude workaround -> there are both GARRISON.TXT and GARRSION.BMP, since we ommit extensions, first one (not used by VCMI) would overwrite the second
continue;
size_t dotPos = entry.nameStr.find_last_of('.');
if ( dotPos < entry.nameStr.size() )
{
std::string ext = entry.nameStr.substr(dotPos);
if (ext == ".MSK" || ext == ".MSG" || ext == ".H3C")
entry.nameStr[dotPos] = '#';//this files have same name as def - rename to defName#msk
else
entry.nameStr.erase(dotPos);//filename.ext becomes filename
}
entry.offset= SDL_SwapLE32(lodEntries[i].offset); entry.offset= SDL_SwapLE32(lodEntries[i].offset);
entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize); entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
entry.size = SDL_SwapLE32(lodEntries[i].size); entry.size = SDL_SwapLE32(lodEntries[i].size);
entries.push_back(entry); entries.insert(entry);
} }
delete [] lodEntries; delete [] lodEntries;
@ -272,36 +300,16 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
{ {
if(boost::filesystem::is_regular(dir->status())) if(boost::filesystem::is_regular(dir->status()))
{ {
std::string name = dir->path().leaf(); Entry e;
std::string realname = name; e.realName = dir->path().leaf();
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper); initEntry(e, e.realName);
size_t dotPos = name.find_last_of('.'); if(vstd::contains(entries, e)) //file present in .lod - overwrite its entry
if ( dotPos < name.size() ) entries.erase(e);
{
std::string ext = name.substr(dotPos);
if (ext == ".MSK" || ext == ".MSG" || ext == ".H3C")
name[dotPos] = '#';//this files have same name as def - rename to defName#msk
else
name.erase(dotPos);//filename.ext becomes filename
}
Entry * e = entries.znajdz(name); e.offset = -1;
if(e) //file present in .lod - overwrite its entry e.realSize = e.size = boost::filesystem::file_size(dir->path());
{ entries.insert(e);
e->offset = -1;
e->realName = realname;
e->realSize = e->size = boost::filesystem::file_size(dir->path());
}
else //file not present in lod - add entry for it
{
Entry e2;
e2.offset = -1;
e2.nameStr = name;
e2.realName = realname;
e2.realSize = e2.size = boost::filesystem::file_size(dir->path());
entries.push_back(e2);
}
} }
} }
} }
@ -310,10 +318,10 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl; tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
} }
} }
std::string CLodHandler::getTextFile(std::string name) std::string CLodHandler::getTextFile(const std::string name, LodFileType type)
{ {
int length=-1; int length=-1;
unsigned char* data = giveFile(name,&length); unsigned char* data = giveFile(name, type, &length);
if (!data) { if (!data) {
tlog1<<"Fatal error. Missing game file: " << name << ". Aborting!"<<std::endl; tlog1<<"Fatal error. Missing game file: " << name << ". Aborting!"<<std::endl;

View File

@ -3,7 +3,9 @@
#include "../global.h" #include "../global.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include "../nodrze.h" #include <fstream>
#include <set>
#include <map>
/* /*
* CLodhandler.h, part of VCMI engine * CLodhandler.h, part of VCMI engine
@ -15,9 +17,6 @@
* *
*/ */
struct SDL_Surface;
class CDefHandler;
class CDefEssential;
namespace boost namespace boost
{class mutex;} {class mutex;}
namespace NLoadHandlerHelp namespace NLoadHandlerHelp
@ -41,46 +40,69 @@ DLL_EXPORT char readChar(const unsigned char * bufor, int &i);
DLL_EXPORT std::string readString(const unsigned char * bufor, int &i); DLL_EXPORT std::string readString(const unsigned char * bufor, int &i);
enum LodFileType{
FILE_ANY,
FILE_TEXT,
FILE_ANIMATION,
FILE_MASK,
FILE_CAMPAIGN,
FILE_MAP,
FILE_FONT,
FILE_GRAPHICS,
FILE_OTHER
};
struct Entry struct Entry
{ {
// Info extracted from LOD file // Info extracted from LOD file
std::string nameStr, std::string name,
realName; realName;//for external files - case\extension may not match
int offset, //from beginning int offset, //from beginning
realSize, //size without compression realSize, //size without compression
size; //and with size; //and with
LodFileType type;// file type determined by extension
bool operator<(const std::string & comp) const
{
return nameStr<comp;
}
bool operator<(const Entry & comp) const bool operator<(const Entry & comp) const
{ {
return nameStr<comp.nameStr; return type==comp.type ? name<comp.name
: type<comp.type;
} }
Entry(std::string con): nameStr(con){};
//Entry(unsigned char ): nameStr(con){}; bool operator == (const Entry & comp) const
{
return (type==comp.type || comp.type== FILE_ANY) && name==comp.name;
}
Entry(std::string con, LodFileType TYPE): name(con), type(TYPE){};
Entry(std::string con): name(con){};
Entry(){}; Entry(){};
}; };
class DLL_EXPORT CLodHandler class DLL_EXPORT CLodHandler
{ {
std::map<std::string, LodFileType> extMap;// to convert extensions to file type
std::ifstream LOD; std::ifstream LOD;
unsigned int totalFiles; unsigned int totalFiles;
boost::mutex *mutex; boost::mutex *mutex;
std::string myDir; //load files from this dir instead of .lod file std::string myDir; //load files from this dir instead of .lod file
void initEntry(Entry &e, const std::string name);
Entry getEntry(const std::string name, LodFileType);
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
public: public:
nodrze<Entry> entries;
std::set<Entry> entries;
CLodHandler(); CLodHandler();
~CLodHandler(); ~CLodHandler();
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler void init(const std::string lodFile, const std::string dirName);
unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
bool haveFile(std::string name);//check if file is present in lod unsigned char * giveFile(const std::string defName, LodFileType type=FILE_ANY, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
std::string getTextFile(std::string name); //extracts one file bool haveFile(const std::string name, LodFileType type=FILE_ANY);//check if file is present in lod
void extractFile(std::string FName, std::string name); //extracts a specific file std::string getTextFile(const std::string name, LodFileType type=FILE_TEXT); //extracts one file
void init(std::string lodFile, std::string dirName); void extractFile(const std::string FName, const std::string name); //extracts a specific file
static unsigned char * getUnpackedFile(const std::string & path, int * sizeOut); //loads given file, decompresses and returns static unsigned char * getUnpackedFile(const std::string & path, int * sizeOut); //loads given file, decompresses and returns
}; };

View File

@ -115,7 +115,7 @@ void CCreatureSet::addToSlot(TSlot slot, TCreature cre, TQuantity count, bool al
{ {
assert(slot >= 0); assert(slot >= 0);
const CCreature *c = VLC->creh->creatures[cre]; const CCreature *c = VLC->creh->creatures[cre];
assert(!vstd::contains(slots, slot) || slots[slot].type == c && allowMerging); //that slot was empty or contained same type creature assert(!vstd::contains(slots, slot) || (slots[slot].type == c && allowMerging)); //that slot was empty or contained same type creature
slots[slot].type = c; slots[slot].type = c;
slots[slot].count += count; slots[slot].count += count;

View File

@ -2166,7 +2166,7 @@ int CGameState::battleGetBattlefieldType(int3 tile)
const TerrainTile &t = map->getTile(tile); const TerrainTile &t = map->getTile(tile);
//fight in mine -> subterranean //fight in mine -> subterranean
if(const CGMine *mine = dynamic_cast<const CGMine *>(t.visitableObjects.front())) if(dynamic_cast<const CGMine *>(t.visitableObjects.front()))
return 12; return 12;
const std::vector <CGObjectInstance*> & objs = map->objects; const std::vector <CGObjectInstance*> & objs = map->objects;
@ -2800,7 +2800,7 @@ void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int
} }
if ( tinfo->tertype == TerrainTile::rock//it's rock if ( tinfo->tertype == TerrainTile::rock//it's rock
|| !onLand && node.land //it's land and we cannot walk on land (complementary condition is handled above) || (!onLand && node.land) //it's land and we cannot walk on land (complementary condition is handled above)
|| !FoW[i][j][k] //tile is covered by the FoW || !FoW[i][j][k] //tile is covered by the FoW
|| leaveAsBlocked || leaveAsBlocked
) )
@ -3795,8 +3795,8 @@ int CGameState::victoryCheck( ui8 player ) const
case transportItem: case transportItem:
{ {
const CGTownInstance *t = static_cast<const CGTownInstance *>(map->victoryCondition.obj); const CGTownInstance *t = static_cast<const CGTownInstance *>(map->victoryCondition.obj);
if(t->visitingHero && t->visitingHero->hasArt(map->victoryCondition.ID) if((t->visitingHero && t->visitingHero->hasArt(map->victoryCondition.ID))
|| t->garrisonHero && t->garrisonHero->hasArt(map->victoryCondition.ID)) || (t->garrisonHero && t->garrisonHero->hasArt(map->victoryCondition.ID)))
{ {
return 1; return 1;
} }

View File

@ -1084,7 +1084,7 @@ DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs )
changedStack->state.insert(SUMMONED); changedStack->state.insert(SUMMONED);
//changedStack->bonuses.push_back( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) ); //changedStack->bonuses.push_back( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) );
} }
int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft; //int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft;
int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->count ); int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->count );
changedStack->count += res; changedStack->count += res;
changedStack->firstHPleft += healedStacks[g].healedHP - res * changedStack->MaxHealth(); changedStack->firstHPleft += healedStacks[g].healedHP - res * changedStack->MaxHealth();

View File

@ -56,7 +56,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 0: case 0:
{ {
int hmcr = 0; int hmcr = 0;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\t') if(src[iter]=='\t')
++hmcr; ++hmcr;
@ -66,7 +66,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter; ++iter;
int befi=iter; int befi=iter;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\t') if(src[iter]=='\t')
break; break;
@ -75,7 +75,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter; ++iter;
hmcr = 0; hmcr = 0;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\r') if(src[iter]=='\r')
++hmcr; ++hmcr;
@ -88,7 +88,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 1: case 1:
{ {
int hmcr = 0; int hmcr = 0;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\t') if(src[iter]=='\t')
++hmcr; ++hmcr;
@ -98,7 +98,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter; ++iter;
int befi=iter; int befi=iter;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\r') if(src[iter]=='\r')
break; break;
@ -110,7 +110,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 2: case 2:
{ {
int befi=iter; int befi=iter;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\t') if(src[iter]=='\t')
break; break;
@ -119,7 +119,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter; ++iter;
int hmcr = 0; int hmcr = 0;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\r') if(src[iter]=='\r')
++hmcr; ++hmcr;
@ -132,7 +132,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 3: case 3:
{ {
int befi=iter; int befi=iter;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\r') if(src[iter]=='\r')
break; break;
@ -144,7 +144,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 4: case 4:
{ {
int befi=iter; int befi=iter;
for(iter; iter<src.size(); ++iter) for(; iter<src.size(); ++iter)
{ {
if(src[iter]=='\t') if(src[iter]=='\t')
break; break;

View File

@ -165,7 +165,7 @@ void CMapHeader::initFromMemory( const unsigned char *bufor, int &i )
pom = i; pom = i;
allowedHeroes.resize(HEROES_QUANTITY,false); allowedHeroes.resize(HEROES_QUANTITY,false);
for(i; i<pom+ (version == RoE ? 16 : 20) ; ++i) for(; i<pom+ (version == RoE ? 16 : 20) ; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -687,7 +687,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
int ist = i; int ist = i;
if(version>RoE) if(version>RoE)
{ {
for(i; i<ist+9; ++i) for(; i<ist+9; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -702,7 +702,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
} }
ist = i; ist = i;
for(i; i<ist+9; ++i) for(; i<ist+9; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -921,7 +921,7 @@ void Mapa::loadHero( CGObjectInstance * &nobj, const unsigned char * bufor, int
{ {
nhi->spells.insert(0xffffffff); //placeholder "preset spells" nhi->spells.insert(0xffffffff); //placeholder "preset spells"
int ist = i; int ist = i;
for(i; i<ist+9; ++i) for(; i<ist+9; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -1011,7 +1011,7 @@ void Mapa::readHeader( const unsigned char * bufor, int &i)
if (version!=RoE) if (version!=RoE)
{ {
ist=i; //starting i for loop ist=i; //starting i for loop
for (i; i<ist+(version==AB ? 17 : 18); ++i) for (; i<ist+(version==AB ? 17 : 18); ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for (int yy=0; yy<8; ++yy) for (int yy=0; yy<8; ++yy)
@ -1038,7 +1038,7 @@ void Mapa::readHeader( const unsigned char * bufor, int &i)
{ {
//reading allowed spells (9 bytes) //reading allowed spells (9 bytes)
ist=i; //starting i for loop ist=i; //starting i for loop
for(i; i<ist+9; ++i) for(; i<ist+9; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -1050,7 +1050,7 @@ void Mapa::readHeader( const unsigned char * bufor, int &i)
//allowed hero's abilities (4 bytes) //allowed hero's abilities (4 bytes)
ist=i; //starting i for loop ist=i; //starting i for loop
for(i; i<ist+4; ++i) for(; i<ist+4; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -1139,11 +1139,11 @@ void Mapa::readPredefinedHeroes( const unsigned char * bufor, int &i)
} //artifacts } //artifacts
if(readChar(bufor,i))//customBio if(readChar(bufor,i))//customBio
cgh->biography = readString(bufor,i); cgh->biography = readString(bufor,i);
int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female int sex = bufor[i++]; // 0xFF is default, 00 male, 01 female //FIXME:unused?
if(readChar(bufor,i))//are spells if(readChar(bufor,i))//are spells
{ {
int ist = i; int ist = i;
for(i; i<ist+9; ++i) for(; i<ist+9; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -1498,7 +1498,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
if(version>RoE) //in reo we cannot specify it - all are allowed (I hope) if(version>RoE) //in reo we cannot specify it - all are allowed (I hope)
{ {
int ist=i; //starting i for loop int ist=i; //starting i for loop
for(i; i<ist+4; ++i) for(; i<ist+4; ++i)
{ {
unsigned char c = bufor[i]; unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy) for(int yy=0; yy<8; ++yy)
@ -2114,7 +2114,7 @@ bool TerrainTile::entrableTerrain(const TerrainTile *from /*= NULL*/) const
bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const bool TerrainTile::entrableTerrain(bool allowLand, bool allowSea) const
{ {
return tertype != rock return tertype != rock
&& (allowSea && tertype == water || allowLand && tertype != water); && ((allowSea && tertype == water) || (allowLand && tertype != water));
} }
bool TerrainTile::isClear(const TerrainTile *from /*= NULL*/) const bool TerrainTile::isClear(const TerrainTile *from /*= NULL*/) const

View File

@ -5,6 +5,8 @@
//ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine //ignore comment above, it is simply TowDragon's envy. Everything (without removing) is working fine
//TODO? remove file - not used anymore
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
@ -180,7 +182,7 @@ template <typename T> void nodrze<T>::wypisujPre(wezel<T> * w, std::ostream & st
} }
template <typename T> void nodrze<T>::wypiszObficie(std::ostream & strum) template <typename T> void nodrze<T>::wypiszObficie(std::ostream & strum)
{ {
strum << "Nodrze " <<this<<" ma " << ile << " elementw."<<std::endl; strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<std::endl;
strum << "NIL to " << NIL <<std::endl; strum << "NIL to " << NIL <<std::endl;
strum << "Ostatnio bralismy "<<ktory<<std::flush<<" element, czyli "<<" ("<<ostatnio<<")"<<std::flush<<*ostatnio<<std::flush<<std::endl; strum << "Ostatnio bralismy "<<ktory<<std::flush<<" element, czyli "<<" ("<<ostatnio<<")"<<std::flush<<*ostatnio<<std::flush<<std::endl;
strum << "Nasze wezly in-order"<<std::endl; strum << "Nasze wezly in-order"<<std::endl;
@ -589,14 +591,14 @@ template <typename T> wezel<T> * nodrze<T>::usunRBT (wezel<T> * nowy)
} }
else if (nowy == ostatnio) else if (nowy == ostatnio)
{ {
CLOG ("To by ostatnio ogldany element. Elementem o numerze "<<ktory<<" bedzie teraz "); CLOG ("To by³ ostatnio ogl¹dany element. Elementem o numerze "<<ktory<<" bedzie teraz ");
if (ktory < ile) if (ktory < ile)
{ {
ostatnio = nastepnik(ostatnio); ostatnio = nastepnik(ostatnio);
} }
else else
{ {
CLOG ("Ojej, koniec. Cofamy si. "<<std::endl); CLOG ("Ojej, koniec. Cofamy siê. "<<std::endl);
ostatnio = poprzednik(ostatnio); ostatnio = poprzednik(ostatnio);
ktory--; ktory--;
} }
@ -753,7 +755,7 @@ template <typename T> bool nodrze<T>::sprawdzW(wezel<T> * w)
} }
template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x) template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x)
{ {
//CLOG("Wykonuje lew rotacj na "<<x->zawart<<std::endl); //CLOG("Wykonuje lew¹ rotacjê na "<<x->zawart<<std::endl);
wezel<T> * y = x->prawy; wezel<T> * y = x->prawy;
x->prawy = y->lewy; // zamiana lewego poddrzewa y na prawe poddrzewo x x->prawy = y->lewy; // zamiana lewego poddrzewa y na prawe poddrzewo x
if (y->lewy != NIL) y->lewy->ojciec = x; // i przypisanie ojcostwa temu poddrzewu if (y->lewy != NIL) y->lewy->ojciec = x; // i przypisanie ojcostwa temu poddrzewu
@ -769,7 +771,7 @@ template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x)
} }
template <typename T> void nodrze<T>::rotacjaPrawa (wezel<T> * y) template <typename T> void nodrze<T>::rotacjaPrawa (wezel<T> * y)
{ {
//CLOG("Wykonuje prawa rotacj na "<<y->zawart<<std::endl); //CLOG("Wykonuje prawa rotacjê na "<<y->zawart<<std::endl);
wezel<T> * x = y->lewy; wezel<T> * x = y->lewy;
y->lewy = x->prawy; // zamiana prawe poddrzewa x na lewe poddrzewo y y->lewy = x->prawy; // zamiana prawe poddrzewa x na lewe poddrzewo y
if (x->prawy != NIL) x->prawy->ojciec = y; // i przypisanie ojcostwa temu poddrzewu if (x->prawy != NIL) x->prawy->ojciec = y; // i przypisanie ojcostwa temu poddrzewu

View File

@ -18,7 +18,7 @@ class timeHandler
public: public:
clock_t start, last, mem; clock_t start, last, mem;
timeHandler():start(clock()){last=clock();mem=0;}; timeHandler():start(clock()){last=clock();mem=0;};
long getDif(){long ret=clock()-last;last=clock();return ret;}; long getDif(){long ret=clock()-last;last=clock();return ret/(CLOCKS_PER_SEC/1000);};//get diff in milliseconds
void update(){last=clock();}; void update(){last=clock();};
void remember(){mem=clock();}; void remember(){mem=clock();};
long memDif(){return clock()-mem;}; long memDif(){return clock()-mem;};