CMapDefines.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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<int3> 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. h & deletedObjectsCoordinates;
  64. else
  65. h & unused;
  66. }
  67. virtual void serializeJson(JsonSerializeFormat & handler);
  68. };
  69. /// The castle event builds/adds buildings/creatures for a specific town.
  70. class DLL_LINKAGE CCastleEvent: public CMapEvent
  71. {
  72. public:
  73. CCastleEvent() = default;
  74. std::set<BuildingID> buildings;
  75. std::vector<si32> creatures;
  76. template <typename Handler>
  77. void serialize(Handler & h)
  78. {
  79. h & static_cast<CMapEvent &>(*this);
  80. h & buildings;
  81. h & creatures;
  82. }
  83. void serializeJson(JsonSerializeFormat & handler) override;
  84. };
  85. /// The terrain tile describes the terrain type and the visual representation of the terrain.
  86. /// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  87. struct DLL_LINKAGE TerrainTile
  88. {
  89. TerrainTile();
  90. /// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  91. bool entrableTerrain(const TerrainTile * from = nullptr) const;
  92. bool entrableTerrain(bool allowLand, bool allowSea) const;
  93. /// Checks for blocking objects and terraint type (water / land).
  94. bool isClear(const TerrainTile * from = nullptr) const;
  95. /// Gets the ID of the top visitable object or -1 if there is none.
  96. Obj topVisitableId(bool excludeTop = false) const;
  97. CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
  98. bool isWater() const;
  99. EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
  100. bool hasFavorableWinds() const;
  101. const TerrainType * terType;
  102. const RiverType * riverType;
  103. const RoadType * roadType;
  104. ui8 terView;
  105. ui8 riverDir;
  106. ui8 roadDir;
  107. /// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  108. /// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
  109. ui8 extTileFlags;
  110. bool visitable;
  111. bool blocked;
  112. std::vector<CGObjectInstance *> visitableObjects;
  113. std::vector<CGObjectInstance *> blockingObjects;
  114. template <typename Handler>
  115. void serialize(Handler & h)
  116. {
  117. h & terType;
  118. h & terView;
  119. h & riverType;
  120. h & riverDir;
  121. h & roadType;
  122. h & roadDir;
  123. h & extTileFlags;
  124. h & visitable;
  125. h & blocked;
  126. h & visitableObjects;
  127. h & blockingObjects;
  128. }
  129. };
  130. VCMI_LIB_NAMESPACE_END