2014-06-05 14:19:47 +03:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../GameConstants.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ObjectTemplate.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CBinaryReader;
|
|
|
|
class CLegacyConfigParser;
|
|
|
|
class JsonNode;
|
2014-06-28 10:46:32 +03:00
|
|
|
class int3;
|
2014-06-05 14:19:47 +03:00
|
|
|
|
|
|
|
class DLL_LINKAGE ObjectTemplate
|
|
|
|
{
|
|
|
|
enum EBlockMapBits
|
|
|
|
{
|
|
|
|
VISIBLE = 1,
|
|
|
|
VISITABLE = 2,
|
|
|
|
BLOCKED = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/// tiles that are covered by this object, uses EBlockMapBits enum as flags
|
|
|
|
std::vector<std::vector<ui8>> usedTiles;
|
|
|
|
/// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
|
|
|
|
ui8 visitDir;
|
|
|
|
/// list of terrains on which this object can be placed
|
|
|
|
std::set<ETerrainType> allowedTerrains;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// H3 ID/subID of this object
|
|
|
|
Obj id;
|
|
|
|
si32 subid;
|
|
|
|
/// print priority, objects with higher priority will be print first, below everything else
|
|
|
|
si32 printPriority;
|
|
|
|
/// animation file that should be used to display object
|
|
|
|
std::string animationFile;
|
|
|
|
|
|
|
|
/// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
|
|
|
|
std::string stringID;
|
|
|
|
|
|
|
|
ui32 getWidth() const;
|
|
|
|
ui32 getHeight() const;
|
|
|
|
void setSize(ui32 width, ui32 height);
|
|
|
|
|
|
|
|
bool isVisitable() const;
|
|
|
|
|
|
|
|
// Checks object used tiles
|
|
|
|
// Position is relative to bottom-right corner of the object, can not be negative
|
|
|
|
bool isWithin(si32 X, si32 Y) const;
|
|
|
|
bool isVisitableAt(si32 X, si32 Y) const;
|
|
|
|
bool isVisibleAt(si32 X, si32 Y) const;
|
|
|
|
bool isBlockedAt(si32 X, si32 Y) const;
|
2014-06-28 10:46:32 +03:00
|
|
|
std::set<int3> getBlockedOffsets() const;
|
|
|
|
int3 getBlockMapOffset() const; //bottom-right corner when firts blocked tile is
|
2014-06-05 14:19:47 +03:00
|
|
|
|
|
|
|
// Checks if object is visitable from certain direction. X and Y must be between -1..+1
|
|
|
|
bool isVisitableFrom(si8 X, si8 Y) const;
|
|
|
|
|
|
|
|
// Checks if object can be placed on specific terrain
|
|
|
|
bool canBePlacedAt(ETerrainType terrain) const;
|
|
|
|
|
|
|
|
ObjectTemplate();
|
|
|
|
|
|
|
|
void readTxt(CLegacyConfigParser & parser);
|
|
|
|
void readMsk();
|
|
|
|
void readMap(CBinaryReader & reader);
|
|
|
|
void readJson(const JsonNode & node);
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & usedTiles & allowedTerrains & animationFile & stringID;
|
|
|
|
h & id & subid & printPriority & visitDir;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|