CMapDefines.h 4.7 KB

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