| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 | 
							- /*
 
-  * 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
 
-  *
 
-  */
 
- #pragma once
 
- #include "../GameConstants.h"
 
- #include "../int3.h"
 
- #include "../filesystem/ResourcePath.h"
 
- VCMI_LIB_NAMESPACE_BEGIN
 
- class CBinaryReader;
 
- class CLegacyConfigParser;
 
- class JsonNode;
 
- class int3;
 
- 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<TerrainId> allowedTerrains;
 
- 	/// or, allow placing object on any terrain
 
- 	bool anyLandTerrain;
 
- 	void afterLoadFixup();
 
- public:
 
- 	/// H3 ID/subID of this object
 
- 	MapObjectID id;
 
- 	MapObjectSubID 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
 
- 	AnimationPath animationFile;
 
- 	/// map editor only animation file
 
- 	AnimationPath editorAnimationFile;
 
- 	/// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
 
- 	std::string stringID;
 
- 	inline ui32 getWidth() const
 
- 	{
 
- 		return width;
 
- 	};
 
- 	inline ui32 getHeight() const
 
- 	{ 
 
- 		return height;
 
- 	};
 
- 	void setSize(ui32 width, ui32 height);
 
- 	inline bool isVisitable() const
 
- 	{
 
- 		return visitable;
 
- 	};
 
- 	// 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;
 
- 	inline const std::set<int3> & getBlockedOffsets() const
 
- 	{
 
- 		return blockedOffsets;
 
- 	};
 
- 	inline int3 getBlockMapOffset() const
 
- 	{
 
- 		return blockMapOffset; 
 
- 	}
 
- 	inline int3 getTopVisibleOffset() const
 
- 	{
 
- 		return topVisibleOffset;
 
- 	}
 
- 	// Checks if object is visitable from certain direction. X and Y must be between -1..+1
 
- 	bool isVisitableFrom(si8 X, si8 Y) const;
 
- 	inline int3 getVisitableOffset() const
 
- 	{
 
- 		//logGlobal->warn("Warning: getVisitableOffset called on non-visitable obj!");
 
- 		return visitableOffset;
 
- 	};
 
- 	inline bool isVisitableFromTop() const
 
- 	{
 
- 		return visitDir & 2;
 
- 	};
 
- 	inline bool canBePlacedAtAnyTerrain() const
 
- 	{
 
- 		return anyLandTerrain;
 
- 	};
 
- 	const std::set<TerrainId>& getAllowedTerrains() const
 
- 	{
 
- 		return allowedTerrains;
 
- 	}
 
- 	// Checks if object can be placed on specific terrain
 
- 	bool canBePlacedAt(TerrainId terrain) const;
 
- 	ObjectTemplate();
 
- 	//custom copy constructor is required
 
- 	ObjectTemplate(const ObjectTemplate & other);
 
- 	ObjectTemplate& operator=(const ObjectTemplate & rhs);
 
- 	void readTxt(CLegacyConfigParser & parser);
 
- 	void readMsk();
 
- 	void readMap(CBinaryReader & reader);
 
- 	void readJson(const JsonNode & node, bool withTerrain = true);
 
- 	void writeJson(JsonNode & node, bool withTerrain = true) const;
 
- 	bool operator==(const ObjectTemplate& ot) const { return (id == ot.id && subid == ot.subid); }
 
- private:
 
- 	ui32 width;
 
- 	ui32 height;
 
- 	bool visitable;
 
- 	std::set<int3> blockedOffsets;
 
- 	int3 blockMapOffset;
 
- 	int3 visitableOffset;
 
- 	int3 topVisibleOffset;
 
- 	void recalculate();
 
- 	void calculateWidth();
 
- 	void calculateHeight();
 
- 	void calculateVisitable();
 
- 	void calculateBlockedOffsets();
 
- 	void calculateBlockMapOffset();
 
- 	void calculateVisitableOffset();
 
- 	void calculateTopVisibleOffset();
 
- public:
 
- 	template <typename Handler> void serialize(Handler &h)
 
- 	{
 
- 		h & usedTiles;
 
- 		h & allowedTerrains;
 
- 		h & anyLandTerrain;
 
- 		h & animationFile;
 
- 		h & stringID;
 
- 		h & id;
 
- 		subid.serializeIdentifier(h, id);
 
- 		h & printPriority;
 
- 		h & visitDir;
 
- 		h & editorAnimationFile;
 
- 		if (!h.saving)
 
- 		{
 
- 			recalculate();
 
- 		}
 
- 	}
 
- };
 
- VCMI_LIB_NAMESPACE_END
 
 
  |