1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +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";
return NULL;
}
unsigned char * pcx;
std::transform(fname.begin(),fname.end(),fname.begin(),toupper);
int dotPos = fname.find_last_of('.');
if ( dotPos != -1 )
fname.erase(dotPos);
SDL_Surface * ret=NULL;
int size;
unsigned char * file = bitmaph->giveFile(fname, FILE_GRAPHICS, &size);
Entry *e = bitmaph->entries.znajdz(fname);
if(!e)
if (!file)
{
tlog2<<"Entry for file "<<fname<<" was not found"<<std::endl;
return NULL;
}
if(e->offset<0)//not in LOD
{
fname = e->realName;
fname = DATA_DIR "/Data/" + fname;
FILE * f = fopen(fname.c_str(),"r");
unsigned char sign[12];
if(!f)
if (isPCX(file))
{//H3-style PCX
CPCXConv cp;
cp.openPCX((char*)file,size);
ret = cp.getSurface();
if (!ret)
tlog1<<"Failed to open "<<fname<<" as H3 PCX!\n";
if(ret->format->BytesPerPixel == 1 && setKey)
{
tlog1 << "Cannot open " << fname << " - file not found!\n";
return NULL;
const SDL_Color &c = ret->format->palette->colors[0];
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format, c.r, c.g, c.b));
}
fread(sign,1,12,f);
SDL_Surface * ret=NULL;
if (isPCX(sign))//H3-style PCX
{
CPCXConv cp;
pcx = new unsigned char[e->realSize];
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();
if (!ret)
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)
{
const SDL_Color &c = ret->format->palette->colors[0];
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;
}

View File

@ -39,7 +39,7 @@ void CCreatureAnimation::setType(int type)
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
int i,j, totalInBlock;

View File

@ -412,23 +412,10 @@ void processCommand(const std::string &message)
CLodHandler * txth = new CLodHandler;
txth->init(std::string(DATA_DIR "/Data/H3bitmap.lod"),"");
tlog0<<"done.\nScanning .lod file\n";
int curp=0;
std::string pattern = ".TXT", pom;
for(int i=0;i<txth->entries.size(); i++)
{
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<<"%";
}
}
BOOST_FOREACH(Entry e, txth->entries)
if( e.type == FILE_TEXT )
txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+e.name,e.name);
tlog0<<"\rExtracting done :)\n";
}
else if(cn=="crash")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,11 +7,11 @@
#include <cctype>
#include <cstring>
#include <iostream>
#include <fstream>
#include "boost/filesystem/operations.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/thread.hpp>
#include <boost/foreach.hpp>
#include <SDL_endian.h>
#ifdef max
#undef max
@ -60,58 +60,69 @@ std::string readString(const unsigned char * bufor, int &i)
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);
int dotPos = defName.find_last_of('.');
Entry ret;
std::set<Entry>::iterator it = entries.find(Entry(name, type));
if (it!=entries.end())
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 )
defName.erase(dotPos);
fname.erase(dotPos);
Entry * ourEntry = entries.znajdz(Entry(defName));
if(!ourEntry) //nothing's been found
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;
}
if(length) *length = ourEntry->realSize;
if(length) *length = ourEntry.realSize;
mutex->lock();
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;
unsigned char * outp = new unsigned char[ourEntry->realSize];
FILE * f = fopen((myDir + "/" + ourEntry->realName).c_str(), "rb");
unsigned char * outp = new unsigned char[ourEntry.realSize];
FILE * f = fopen((myDir + "/" + ourEntry.realName).c_str(), "rb");
if (f) {
result = fread(outp,1,ourEntry->realSize,f);
result = fread(outp,1,ourEntry.realSize,f);
fclose(f);
} else
result = -1;
mutex->unlock();
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;
return NULL;
} else
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.read((char*)outp, ourEntry->realSize);
LOD.seekg(ourEntry.offset, std::ios::beg);
LOD.read((char*)outp, ourEntry.realSize);
mutex->unlock();
return outp;
}
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.read((char*)outp, ourEntry->size);
LOD.seekg(ourEntry.offset, std::ios::beg);
LOD.read((char*)outp, ourEntry.size);
unsigned char * decomp = NULL;
infs2(outp, ourEntry->size, ourEntry->realSize, decomp);
infs2(outp, ourEntry.size, ourEntry.realSize, decomp);
mutex->unlock();
delete[] outp;
return decomp;
@ -119,15 +130,15 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
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);
int dotPos = name.find_last_of('.');
std::string fname = name;
std::transform(fname.begin(), fname.end(), fname.begin(), (int(*)(int))toupper);
int dotPos = fname.find_last_of('.');
if ( dotPos != -1 )
name.erase(dotPos);
fname.erase(dotPos);
Entry * ourEntry = entries.znajdz(Entry(name));
return ourEntry != NULL;
return vstd::contains(entries, Entry(fname, type));
}
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;
}
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
unsigned char * outp = giveFile(name, &len);
unsigned char * outp = giveFile(name, FILE_ANY, &len);
std::ofstream out;
out.open(FName.c_str(), std::ios::binary);
if(!out.is_open())
@ -211,12 +222,45 @@ 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)
{
myDir = dirName;
std::string Ts;
Uint32 temp;
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;
LOD.open(lodFile.c_str(), std::ios::in | std::ios::binary);
if (!LOD.is_open())
@ -225,6 +269,7 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
return;
}
Uint32 temp;
LOD.seekg(8);
LOD.read((char *)&temp, 4);
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++)
{
Entry entry;
entry.nameStr = lodEntries[i].filename;
//format string: upper-case, remove extension
std::transform(entry.nameStr.begin(), entry.nameStr.end(),
entry.nameStr.begin(), toupper);
initEntry(entry, lodEntries[i].filename);
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.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
entry.size = SDL_SwapLE32(lodEntries[i].size);
entries.push_back(entry);
entries.insert(entry);
}
delete [] lodEntries;
@ -272,36 +300,16 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
{
if(boost::filesystem::is_regular(dir->status()))
{
std::string name = dir->path().leaf();
std::string realname = name;
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
size_t dotPos = name.find_last_of('.');
if ( dotPos < name.size() )
{
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);
if(e) //file present in .lod - overwrite its entry
{
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);
}
Entry e;
e.realName = dir->path().leaf();
initEntry(e, e.realName);
if(vstd::contains(entries, e)) //file present in .lod - overwrite its entry
entries.erase(e);
e.offset = -1;
e.realSize = e.size = boost::filesystem::file_size(dir->path());
entries.insert(e);
}
}
}
@ -310,10 +318,10 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
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;
unsigned char* data = giveFile(name,&length);
unsigned char* data = giveFile(name, type, &length);
if (!data) {
tlog1<<"Fatal error. Missing game file: " << name << ". Aborting!"<<std::endl;

View File

@ -3,7 +3,9 @@
#include "../global.h"
#include <vector>
#include <string>
#include "../nodrze.h"
#include <fstream>
#include <set>
#include <map>
/*
* CLodhandler.h, part of VCMI engine
@ -15,9 +17,6 @@
*
*/
struct SDL_Surface;
class CDefHandler;
class CDefEssential;
namespace boost
{class mutex;}
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);
enum LodFileType{
FILE_ANY,
FILE_TEXT,
FILE_ANIMATION,
FILE_MASK,
FILE_CAMPAIGN,
FILE_MAP,
FILE_FONT,
FILE_GRAPHICS,
FILE_OTHER
};
struct Entry
{
// Info extracted from LOD file
std::string nameStr,
realName;
std::string name,
realName;//for external files - case\extension may not match
int offset, //from beginning
realSize, //size without compression
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
{
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(){};
};
class DLL_EXPORT CLodHandler
{
std::map<std::string, LodFileType> extMap;// to convert extensions to file type
std::ifstream LOD;
unsigned int totalFiles;
boost::mutex *mutex;
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:
nodrze<Entry> entries;
std::set<Entry> entries;
CLodHandler();
~CLodHandler();
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
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
std::string getTextFile(std::string name); //extracts one file
void extractFile(std::string FName, std::string name); //extracts a specific file
void init(std::string lodFile, std::string dirName);
void init(const std::string lodFile, const std::string dirName);
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!
bool haveFile(const std::string name, LodFileType type=FILE_ANY);//check if file is present in lod
std::string getTextFile(const std::string name, LodFileType type=FILE_TEXT); //extracts one file
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
};

View File

@ -115,7 +115,7 @@ void CCreatureSet::addToSlot(TSlot slot, TCreature cre, TQuantity count, bool al
{
assert(slot >= 0);
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].count += count;

View File

@ -2166,7 +2166,7 @@ int CGameState::battleGetBattlefieldType(int3 tile)
const TerrainTile &t = map->getTile(tile);
//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;
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
|| !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
|| leaveAsBlocked
)
@ -3795,8 +3795,8 @@ int CGameState::victoryCheck( ui8 player ) const
case transportItem:
{
const CGTownInstance *t = static_cast<const CGTownInstance *>(map->victoryCondition.obj);
if(t->visitingHero && t->visitingHero->hasArt(map->victoryCondition.ID)
|| t->garrisonHero && t->garrisonHero->hasArt(map->victoryCondition.ID))
if((t->visitingHero && t->visitingHero->hasArt(map->victoryCondition.ID))
|| (t->garrisonHero && t->garrisonHero->hasArt(map->victoryCondition.ID)))
{
return 1;
}

View File

@ -1084,7 +1084,7 @@ DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs )
changedStack->state.insert(SUMMONED);
//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 );
changedStack->count += res;
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:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
@ -66,7 +66,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
@ -75,7 +75,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter;
hmcr = 0;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
++hmcr;
@ -88,7 +88,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 1:
{
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
++hmcr;
@ -98,7 +98,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter;
int befi=iter;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
break;
@ -110,7 +110,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 2:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;
@ -119,7 +119,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
++iter;
int hmcr = 0;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
++hmcr;
@ -132,7 +132,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 3:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\r')
break;
@ -144,7 +144,7 @@ DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, i
case 4:
{
int befi=iter;
for(iter; iter<src.size(); ++iter)
for(; iter<src.size(); ++iter)
{
if(src[iter]=='\t')
break;

View File

@ -165,7 +165,7 @@ void CMapHeader::initFromMemory( const unsigned char *bufor, int &i )
pom = i;
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];
for(int yy=0; yy<8; ++yy)
@ -687,7 +687,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
int ist = i;
if(version>RoE)
{
for(i; i<ist+9; ++i)
for(; i<ist+9; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
@ -702,7 +702,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
}
ist = i;
for(i; i<ist+9; ++i)
for(; i<ist+9; ++i)
{
unsigned char c = bufor[i];
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"
int ist = i;
for(i; i<ist+9; ++i)
for(; i<ist+9; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
@ -1011,7 +1011,7 @@ void Mapa::readHeader( const unsigned char * bufor, int &i)
if (version!=RoE)
{
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];
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)
ist=i; //starting i for loop
for(i; i<ist+9; ++i)
for(; i<ist+9; ++i)
{
unsigned char c = bufor[i];
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)
ist=i; //starting i for loop
for(i; i<ist+4; ++i)
for(; i<ist+4; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
@ -1139,11 +1139,11 @@ void Mapa::readPredefinedHeroes( const unsigned char * bufor, int &i)
} //artifacts
if(readChar(bufor,i))//customBio
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
{
int ist = i;
for(i; i<ist+9; ++i)
for(; i<ist+9; ++i)
{
unsigned char c = bufor[i];
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)
{
int ist=i; //starting i for loop
for(i; i<ist+4; ++i)
for(; i<ist+4; ++i)
{
unsigned char c = bufor[i];
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
{
return tertype != rock
&& (allowSea && tertype == water || allowLand && tertype != water);
&& ((allowSea && tertype == water) || (allowLand && tertype != water));
}
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
//TODO? remove file - not used anymore
#include <iostream>
#include <fstream>
#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)
{
strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<std::endl;
strum << "Nodrze " <<this<<" ma " << ile << " elementów."<<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 << "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)
{
CLOG ("To był ostatnio oglšdany element. Elementem o numerze "<<ktory<<" bedzie teraz ");
CLOG ("To by³ ostatnio ogl¹dany element. Elementem o numerze "<<ktory<<" bedzie teraz ");
if (ktory < ile)
{
ostatnio = nastepnik(ostatnio);
}
else
{
CLOG ("Ojej, koniec. Cofamy się. "<<std::endl);
CLOG ("Ojej, koniec. Cofamy siê. "<<std::endl);
ostatnio = poprzednik(ostatnio);
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)
{
//CLOG("Wykonuje lewš rotację na "<<x->zawart<<std::endl);
//CLOG("Wykonuje lew¹ rotacjê na "<<x->zawart<<std::endl);
wezel<T> * y = x->prawy;
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
@ -769,7 +771,7 @@ template <typename T> void nodrze<T>::rotacjaLewa (wezel<T> * x)
}
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;
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

View File

@ -18,7 +18,7 @@ class timeHandler
public:
clock_t start, last, mem;
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 remember(){mem=clock();};
long memDif(){return clock()-mem;};