ObjectTemplate.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "GameConstants.h"
  3. /*
  4. * ObjectTemplate.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. class CBinaryReader;
  13. class CLegacyConfigParser;
  14. class JsonNode;
  15. class DLL_LINKAGE ObjectTemplate
  16. {
  17. enum EBlockMapBits
  18. {
  19. VISIBLE = 1,
  20. VISITABLE = 2,
  21. BLOCKED = 4
  22. };
  23. /// tiles that are covered by this object, uses EBlockMapBits enum as flags
  24. std::vector<std::vector<ui8>> usedTiles;
  25. /// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
  26. ui8 visitDir;
  27. /// list of terrains on which this object can be placed
  28. std::set<ETerrainType> allowedTerrains;
  29. public:
  30. /// H3 ID/subID of this object
  31. Obj id;
  32. si32 subid;
  33. /// print priority, objects with higher priority will be print first, below everything else
  34. si32 printPriority;
  35. /// animation file that should be used to display object
  36. std::string animationFile;
  37. /// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
  38. std::string stringID;
  39. ui32 getWidth() const;
  40. ui32 getHeight() const;
  41. void setSize(ui32 width, ui32 height);
  42. bool isVisitable() const;
  43. // Checks object used tiles
  44. // Position is relative to bottom-right corner of the object, can not be negative
  45. bool isWithin(si32 X, si32 Y) const;
  46. bool isVisitableAt(si32 X, si32 Y) const;
  47. bool isVisibleAt(si32 X, si32 Y) const;
  48. bool isBlockedAt(si32 X, si32 Y) const;
  49. // Checks if object is visitable from certain direction. X and Y must be between -1..+1
  50. bool isVisitableFrom(si8 X, si8 Y) const;
  51. // Checks if object can be placed on specific terrain
  52. bool canBePlacedAt(ETerrainType terrain) const;
  53. ObjectTemplate();
  54. void readTxt(CLegacyConfigParser & parser);
  55. void readMsk();
  56. void readMap(CBinaryReader & reader);
  57. void readJson(const JsonNode & node);
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & usedTiles & allowedTerrains & animationFile & stringID;
  61. h & id & subid & printPriority & visitDir;
  62. }
  63. };