ObjectTemplate.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 int3;
  16. class DLL_LINKAGE ObjectTemplate
  17. {
  18. enum EBlockMapBits
  19. {
  20. VISIBLE = 1,
  21. VISITABLE = 2,
  22. BLOCKED = 4
  23. };
  24. /// tiles that are covered by this object, uses EBlockMapBits enum as flags
  25. std::vector<std::vector<ui8>> usedTiles;
  26. /// directions from which object can be entered, format same as for moveDir in CGHeroInstance(but 0 - 7)
  27. ui8 visitDir;
  28. /// list of terrains on which this object can be placed
  29. std::set<ETerrainType> allowedTerrains;
  30. public:
  31. /// H3 ID/subID of this object
  32. Obj id;
  33. si32 subid;
  34. /// print priority, objects with higher priority will be print first, below everything else
  35. si32 printPriority;
  36. /// animation file that should be used to display object
  37. std::string animationFile;
  38. /// string ID, equals to def base name for h3m files (lower case, no extension) or specified in mod data
  39. std::string stringID;
  40. ui32 getWidth() const;
  41. ui32 getHeight() const;
  42. void setSize(ui32 width, ui32 height);
  43. bool isVisitable() const;
  44. // Checks object used tiles
  45. // Position is relative to bottom-right corner of the object, can not be negative
  46. bool isWithin(si32 X, si32 Y) const;
  47. bool isVisitableAt(si32 X, si32 Y) const;
  48. bool isVisibleAt(si32 X, si32 Y) const;
  49. bool isBlockedAt(si32 X, si32 Y) const;
  50. std::set<int3> getBlockedOffsets() const;
  51. int3 getBlockMapOffset() const; //bottom-right corner when firts blocked tile is
  52. // Checks if object is visitable from certain direction. X and Y must be between -1..+1
  53. bool isVisitableFrom(si8 X, si8 Y) const;
  54. // Checks if object can be placed on specific terrain
  55. bool canBePlacedAt(ETerrainType terrain) const;
  56. ObjectTemplate();
  57. void readTxt(CLegacyConfigParser & parser);
  58. void readMsk();
  59. void readMap(CBinaryReader & reader);
  60. void readJson(const JsonNode & node);
  61. template <typename Handler> void serialize(Handler &h, const int version)
  62. {
  63. h & usedTiles & allowedTerrains & animationFile & stringID;
  64. h & id & subid & printPriority & visitDir;
  65. }
  66. };