CMapDefines.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. #include "../ResourceSet.h"
  12. #include "../texts/MetaString.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class TerrainType;
  15. class RiverType;
  16. class RoadType;
  17. class CGObjectInstance;
  18. class CGTownInstance;
  19. class JsonSerializeFormat;
  20. /// The map event is an event which e.g. gives or takes resources of a specific
  21. /// amount to/from players and can appear regularly or once a time.
  22. class DLL_LINKAGE CMapEvent
  23. {
  24. public:
  25. CMapEvent();
  26. virtual ~CMapEvent() = default;
  27. bool occursToday(int currentDay) const;
  28. bool affectsPlayer(PlayerColor player, bool isHuman) const;
  29. std::string name;
  30. MetaString message;
  31. TResources resources;
  32. std::set<PlayerColor> players;
  33. bool humanAffected;
  34. bool computerAffected;
  35. ui32 firstOccurrence;
  36. ui32 nextOccurrence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
  37. template <typename Handler>
  38. void serialize(Handler & h)
  39. {
  40. h & name;
  41. h & message;
  42. h & resources;
  43. if (h.version >= Handler::Version::EVENTS_PLAYER_SET)
  44. {
  45. h & players;
  46. }
  47. else
  48. {
  49. ui8 playersMask = 0;
  50. h & playersMask;
  51. for (int i = 0; i < 8; ++i)
  52. if ((playersMask & (1 << i)) != 0)
  53. players.insert(PlayerColor(i));
  54. }
  55. h & humanAffected;
  56. h & computerAffected;
  57. h & firstOccurrence;
  58. h & nextOccurrence;
  59. }
  60. virtual void serializeJson(JsonSerializeFormat & handler);
  61. };
  62. /// The castle event builds/adds buildings/creatures for a specific town.
  63. class DLL_LINKAGE CCastleEvent: public CMapEvent
  64. {
  65. public:
  66. CCastleEvent() = default;
  67. std::set<BuildingID> buildings;
  68. std::vector<si32> creatures;
  69. template <typename Handler>
  70. void serialize(Handler & h)
  71. {
  72. h & static_cast<CMapEvent &>(*this);
  73. h & buildings;
  74. h & creatures;
  75. }
  76. void serializeJson(JsonSerializeFormat & handler) override;
  77. };
  78. /// The terrain tile describes the terrain type and the visual representation of the terrain.
  79. /// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  80. struct DLL_LINKAGE TerrainTile
  81. {
  82. TerrainTile();
  83. /// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  84. bool entrableTerrain(const TerrainTile * from = nullptr) const;
  85. bool entrableTerrain(bool allowLand, bool allowSea) const;
  86. /// Checks for blocking objects and terraint type (water / land).
  87. bool isClear(const TerrainTile * from = nullptr) const;
  88. /// Gets the ID of the top visitable object or -1 if there is none.
  89. Obj topVisitableId(bool excludeTop = false) const;
  90. CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
  91. bool isWater() const;
  92. bool isLand() const;
  93. EDiggingStatus getDiggingStatus(bool excludeTop = true) const;
  94. bool hasFavorableWinds() const;
  95. bool visitable() const;
  96. bool blocked() const;
  97. const TerrainType * getTerrain() const;
  98. const RiverType * getRiver() const;
  99. const RoadType * getRoad() const;
  100. TerrainId getTerrainID() const;
  101. RiverId getRiverID() const;
  102. RoadId getRoadID() const;
  103. bool hasRiver() const;
  104. bool hasRoad() const;
  105. TerrainId terrainType;
  106. RiverId riverType;
  107. RoadId roadType;
  108. ui8 terView;
  109. ui8 riverDir;
  110. ui8 roadDir;
  111. /// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  112. /// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
  113. ui8 extTileFlags;
  114. std::vector<CGObjectInstance *> visitableObjects;
  115. std::vector<CGObjectInstance *> blockingObjects;
  116. template <typename Handler>
  117. void serialize(Handler & h)
  118. {
  119. if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
  120. {
  121. h & terrainType;
  122. }
  123. else
  124. {
  125. bool isNull = false;
  126. h & isNull;
  127. if (isNull)
  128. h & terrainType;
  129. }
  130. h & terrainType;
  131. h & terView;
  132. if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
  133. {
  134. h & riverType;
  135. }
  136. else
  137. {
  138. bool isNull = false;
  139. h & isNull;
  140. if (isNull)
  141. h & riverType;
  142. }
  143. h & riverDir;
  144. if (h.version >= Handler::Version::REMOVE_VLC_POINTERS)
  145. {
  146. h & roadType;
  147. }
  148. else
  149. {
  150. bool isNull = false;
  151. h & isNull;
  152. if (isNull)
  153. h & roadType;
  154. }
  155. h & roadDir;
  156. h & extTileFlags;
  157. if (h.version < Handler::Version::REMOVE_VLC_POINTERS)
  158. {
  159. bool unused = false;
  160. h & unused;
  161. h & unused;
  162. }
  163. h & visitableObjects;
  164. h & blockingObjects;
  165. }
  166. };
  167. VCMI_LIB_NAMESPACE_END