ObjectTemplate.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. int3 getVisitableOffset() const;
  55. bool isVisitableFromTop() const;
  56. // Checks if object can be placed on specific terrain
  57. bool canBePlacedAt(ETerrainType terrain) const;
  58. ObjectTemplate();
  59. void readTxt(CLegacyConfigParser & parser);
  60. void readMsk();
  61. void readMap(CBinaryReader & reader);
  62. void readJson(const JsonNode & node);
  63. template <typename Handler> void serialize(Handler &h, const int version)
  64. {
  65. h & usedTiles & allowedTerrains & animationFile & stringID;
  66. h & id & subid & printPriority & visitDir;
  67. }
  68. };