CMapDefines.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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<int3> deletedObjectsCoordinates;
  39. std::vector<ObjectInstanceID> deletedObjectsInstances;
  40. std::vector<int3> unused;
  41. std::set<const CGObjectInstance*> unused2;
  42. template <typename Handler>
  43. void serialize(Handler & h)
  44. {
  45. h & name;
  46. h & message;
  47. h & resources;
  48. if (h.version >= Handler::Version::EVENTS_PLAYER_SET)
  49. {
  50. h & players;
  51. }
  52. else
  53. {
  54. ui8 playersMask = 0;
  55. h & playersMask;
  56. for (int i = 0; i < 8; ++i)
  57. if ((playersMask & (1 << i)) != 0)
  58. players.insert(PlayerColor(i));
  59. }
  60. h & humanAffected;
  61. h & computerAffected;
  62. h & firstOccurrence;
  63. h & nextOccurrence;
  64. if(h.version >= Handler::Version::EVENT_OBJECTS_DELETION)
  65. {
  66. h & deletedObjectsCoordinates;
  67. h & deletedObjectsInstances;
  68. }
  69. else
  70. {
  71. h & unused;
  72. h & unused2;
  73. }
  74. }
  75. virtual void serializeJson(JsonSerializeFormat & handler);
  76. };
  77. /// The castle event builds/adds buildings/creatures for a specific town.
  78. class DLL_LINKAGE CCastleEvent: public CMapEvent
  79. {
  80. public:
  81. CCastleEvent() = default;
  82. std::set<BuildingID> buildings;
  83. std::vector<si32> creatures;
  84. template <typename Handler>
  85. void serialize(Handler & h)
  86. {
  87. h & static_cast<CMapEvent &>(*this);
  88. h & buildings;
  89. h & creatures;
  90. }
  91. void serializeJson(JsonSerializeFormat & handler) override;
  92. };
  93. /// The terrain tile describes the terrain type and the visual representation of the terrain.
  94. /// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  95. struct DLL_LINKAGE TerrainTile
  96. {
  97. TerrainTile();
  98. /// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  99. bool entrableTerrain(const TerrainTile * from = nullptr) const;
  100. bool entrableTerrain(bool allowLand, bool allowSea) const;
  101. /// Checks for blocking objects and terraint type (water / land).
  102. bool isClear(const TerrainTile * from = nullptr) const;
  103. /// Gets the ID of the top visitable object or -1 if there is none.
  104. Obj topVisitableId(bool excludeTop = false) const;
  105. CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
  106. bool isWater() const;
  107. EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
  108. bool hasFavorableWinds() const;
  109. const TerrainType * terType;
  110. const RiverType * riverType;
  111. const RoadType * roadType;
  112. ui8 terView;
  113. ui8 riverDir;
  114. ui8 roadDir;
  115. /// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  116. /// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
  117. ui8 extTileFlags;
  118. bool visitable;
  119. bool blocked;
  120. std::vector<CGObjectInstance *> visitableObjects;
  121. std::vector<CGObjectInstance *> blockingObjects;
  122. template <typename Handler>
  123. void serialize(Handler & h)
  124. {
  125. h & terType;
  126. h & terView;
  127. h & riverType;
  128. h & riverDir;
  129. h & roadType;
  130. h & roadDir;
  131. h & extTileFlags;
  132. h & visitable;
  133. h & blocked;
  134. h & visitableObjects;
  135. h & blockingObjects;
  136. }
  137. };
  138. VCMI_LIB_NAMESPACE_END