2011-12-14 00:23:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2013-02-05 22:56:28 +03:00
|
|
|
#include "../lib/vcmi_endian.h"
|
2010-08-17 17:58:13 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
struct SDL_Surface;
|
2010-08-17 17:58:13 +03:00
|
|
|
struct BMPPalette;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CDefHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct Cimage
|
|
|
|
{
|
|
|
|
int groupNumber;
|
|
|
|
std::string imName; //name without extension
|
|
|
|
SDL_Surface * bitmap;
|
|
|
|
};
|
|
|
|
|
2009-10-11 21:26:36 +03:00
|
|
|
// Def entry in file. Integer fields are all little endian and will
|
|
|
|
// need to be converted.
|
2013-02-05 22:56:28 +03:00
|
|
|
struct SDefEntryBlock
|
|
|
|
{
|
2010-08-17 17:58:13 +03:00
|
|
|
ui32 unknown1;
|
|
|
|
ui32 totalInBlock;
|
|
|
|
ui32 unknown2;
|
|
|
|
ui32 unknown3;
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 data[0];
|
2013-02-05 22:56:28 +03:00
|
|
|
} PACKED_STRUCT;
|
2009-10-11 21:26:36 +03:00
|
|
|
|
|
|
|
// Def entry in file. Integer fields are all little endian and will
|
|
|
|
// need to be converted.
|
2013-02-05 22:56:28 +03:00
|
|
|
struct SDefEntry
|
|
|
|
{
|
2010-08-17 17:58:13 +03:00
|
|
|
ui32 DEFType;
|
|
|
|
ui32 width;
|
|
|
|
ui32 height;
|
|
|
|
ui32 totalBlocks;
|
2009-10-11 21:26:36 +03:00
|
|
|
|
|
|
|
struct {
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 R;
|
|
|
|
ui8 G;
|
|
|
|
ui8 B;
|
2009-10-11 21:26:36 +03:00
|
|
|
} palette[256];
|
|
|
|
|
2009-10-16 17:56:57 +03:00
|
|
|
// SDefEntry is followed by a series of SDefEntryBlock
|
|
|
|
// This is commented out because VC++ doesn't accept C99 syntax.
|
|
|
|
//struct SDefEntryBlock blocks[];
|
2013-02-05 22:56:28 +03:00
|
|
|
} PACKED_STRUCT;
|
2009-10-11 21:26:36 +03:00
|
|
|
|
|
|
|
// Def entry in file. Integer fields are all little endian and will
|
|
|
|
// need to be converted.
|
2013-02-05 22:56:28 +03:00
|
|
|
struct SSpriteDef
|
|
|
|
{
|
2010-08-17 17:58:13 +03:00
|
|
|
ui32 prSize;
|
|
|
|
ui32 defType2;
|
|
|
|
ui32 FullWidth;
|
|
|
|
ui32 FullHeight;
|
|
|
|
ui32 SpriteWidth;
|
|
|
|
ui32 SpriteHeight;
|
|
|
|
ui32 LeftMargin;
|
|
|
|
ui32 TopMargin;
|
2013-02-05 22:56:28 +03:00
|
|
|
} PACKED_STRUCT;
|
2010-08-17 17:58:13 +03:00
|
|
|
|
|
|
|
class CDefEssential //DefHandler with images only
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<Cimage> ourImages;
|
|
|
|
~CDefEssential(); //d-tor
|
2009-10-11 21:26:36 +03:00
|
|
|
};
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
class CDefHandler
|
|
|
|
{
|
|
|
|
private:
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 DEFType;
|
2009-04-16 14:14:13 +03:00
|
|
|
struct SEntry
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
int offset;
|
|
|
|
int group;
|
|
|
|
} ;
|
|
|
|
std::vector<SEntry> SEntries ;
|
|
|
|
|
|
|
|
public:
|
|
|
|
int width, height; //width and height
|
2009-10-25 16:36:11 +02:00
|
|
|
std::string defName;
|
2009-04-16 14:14:13 +03:00
|
|
|
std::vector<Cimage> ourImages;
|
|
|
|
bool notFreeImgs;
|
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
CDefHandler(); //c-tor
|
|
|
|
~CDefHandler(); //d-tor
|
2011-12-14 00:23:17 +03:00
|
|
|
SDL_Surface * getSprite (int SIndex, const ui8 * FDef, const BMPPalette * palette) const; //saves picture with given number to "testtt.bmp"
|
|
|
|
static void expand(ui8 N,ui8 & BL, ui8 & BR);
|
|
|
|
void openFromMemory(ui8 * table, const std::string & name);
|
2009-04-16 14:14:13 +03:00
|
|
|
CDefEssential * essentialize();
|
|
|
|
|
2010-02-21 20:07:24 +02:00
|
|
|
static CDefHandler * giveDef(const std::string & defName);
|
|
|
|
static CDefEssential * giveDefEss(const std::string & defName);
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|