CMapDefines.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * CMapDefines.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. #include "../ResourceSet.h"
  13. class TerrainType;
  14. class RiverType;
  15. class RoadType;
  16. class CGObjectInstance;
  17. class CGTownInstance;
  18. class JsonSerializeFormat;
  19. /// The map event is an event which e.g. gives or takes resources of a specific
  20. /// amount to/from players and can appear regularly or once a time.
  21. class DLL_LINKAGE CMapEvent
  22. {
  23. public:
  24. CMapEvent();
  25. virtual ~CMapEvent() = default;
  26. bool earlierThan(const CMapEvent & other) const;
  27. bool earlierThanOrEqual(const CMapEvent & other) const;
  28. std::string name;
  29. std::string message;
  30. TResources resources;
  31. ui8 players; // affected players, bit field?
  32. ui8 humanAffected;
  33. ui8 computerAffected;
  34. ui32 firstOccurence;
  35. ui32 nextOccurence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
  36. template <typename Handler>
  37. void serialize(Handler & h, const int version)
  38. {
  39. h & name;
  40. h & message;
  41. h & resources;
  42. h & players;
  43. h & humanAffected;
  44. h & computerAffected;
  45. h & firstOccurence;
  46. h & nextOccurence;
  47. }
  48. virtual void serializeJson(JsonSerializeFormat & handler);
  49. };
  50. /// The castle event builds/adds buildings/creatures for a specific town.
  51. class DLL_LINKAGE CCastleEvent: public CMapEvent
  52. {
  53. public:
  54. CCastleEvent() = default;
  55. std::set<BuildingID> buildings;
  56. std::vector<si32> creatures;
  57. template <typename Handler>
  58. void serialize(Handler & h, const int version)
  59. {
  60. h & static_cast<CMapEvent &>(*this);
  61. h & buildings;
  62. h & creatures;
  63. }
  64. void serializeJson(JsonSerializeFormat & handler) override;
  65. };
  66. /// The terrain tile describes the terrain type and the visual representation of the terrain.
  67. /// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  68. struct DLL_LINKAGE TerrainTile
  69. {
  70. TerrainTile();
  71. /// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  72. bool entrableTerrain(const TerrainTile * from = nullptr) const;
  73. bool entrableTerrain(bool allowLand, bool allowSea) const;
  74. /// Checks for blocking objects and terraint type (water / land).
  75. bool isClear(const TerrainTile * from = nullptr) const;
  76. /// Gets the ID of the top visitable object or -1 if there is none.
  77. Obj topVisitableId(bool excludeTop = false) const;
  78. CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
  79. bool isWater() const;
  80. EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
  81. bool hasFavorableWinds() const;
  82. const TerrainType * terType;
  83. ui8 terView;
  84. const RiverType * riverType;
  85. ui8 riverDir;
  86. const RoadType * roadType;
  87. ui8 roadDir;
  88. /// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  89. /// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
  90. ui8 extTileFlags;
  91. bool visitable;
  92. bool blocked;
  93. std::vector<CGObjectInstance *> visitableObjects;
  94. std::vector<CGObjectInstance *> blockingObjects;
  95. template <typename Handler>
  96. void serialize(Handler & h, const int version)
  97. {
  98. h & terType;
  99. h & terView;
  100. h & riverType;
  101. h & riverDir;
  102. h & roadType;
  103. h & roadDir;
  104. h & extTileFlags;
  105. h & visitable;
  106. h & blocked;
  107. h & visitableObjects;
  108. h & blockingObjects;
  109. }
  110. };
  111. VCMI_LIB_NAMESPACE_END