////////////////////////////////////////////////////////////////////////////////
// Support for MechWarrior 3 ZBD archives
// Copyright Bjoern Ganster
// Developed since 2007
////////////////////////////////////////////////////////////////////////////////

#ifndef MechWarrior3ZBD__H
#define MechWarrior3ZBD__H

#include "Archive.h"
#include "FileCache.h"
#include "Matrix.h"
#include "MechWarrior3GameZArchive.h"
#include "Point3D.h"
#include "TextureCompiler.h"

class Texture;
class Mesh;

////////////////////////////////////////////////////////////////////////////////

// Decode 555 image
bool Decode_MW3_555 (unsigned char* mem, size_t size, Texture& texture, bool flipY);

////////////////////////////////////////////////////////////////////////////////
// Local header for a polygon in a mechlib.zbd or gamez.zbd (MW3, not PM)

struct LocalPolygonHeader {
	uint8_t vertexCount;
	uint8_t polygonMode; // Or just flags?
	uint8_t data1[12];
	uint8_t hasPointIndex2; // DWORD?
	uint8_t data2[3];
	uint8_t flags;
	uint8_t data3[9];
	uint16_t textureID;
	uint8_t data4[6];
}; // 36 bytes

////////////////////////////////////////////////////////////////////////////////

class MechWarrior3ZBD: public MWArchive {
public:
	// Constructor
	MechWarrior3ZBD();

	// Destructor
	~MechWarrior3ZBD() OVERRIDE;

	// Open file
	bool open(const PathChar* PRJFN, bool readOnly = true) OVERRIDE;

	// Close file
	void close() OVERRIDE;

	// Read bufSize bytes from file numbered index at offset into buf
	bool getFileChunk(size_t index, size_t offset, void* buf, size_t bufSize);
private:
	FileCache fc;
};

#endif
