CMapDefines.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include "../MetaString.h"
  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 earlierThan(const CMapEvent & other) const;
  28. bool earlierThanOrEqual(const CMapEvent & other) const;
  29. std::string name;
  30. MetaString message;
  31. TResources resources;
  32. ui8 players; // affected players, bit field?
  33. ui8 humanAffected;
  34. ui8 computerAffected;
  35. ui32 firstOccurence;
  36. ui32 nextOccurence; /// 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, const int version)
  39. {
  40. h & name;
  41. h & message;
  42. h & resources;
  43. h & players;
  44. h & humanAffected;
  45. h & computerAffected;
  46. h & firstOccurence;
  47. h & nextOccurence;
  48. }
  49. virtual void serializeJson(JsonSerializeFormat & handler);
  50. };
  51. /// The castle event builds/adds buildings/creatures for a specific town.
  52. class DLL_LINKAGE CCastleEvent: public CMapEvent
  53. {
  54. public:
  55. CCastleEvent() = default;
  56. std::set<BuildingID> buildings;
  57. std::vector<si32> creatures;
  58. template <typename Handler>
  59. void serialize(Handler & h, const int version)
  60. {
  61. h & static_cast<CMapEvent &>(*this);
  62. h & buildings;
  63. h & creatures;
  64. }
  65. void serializeJson(JsonSerializeFormat & handler) override;
  66. };
  67. /// The terrain tile describes the terrain type and the visual representation of the terrain.
  68. /// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  69. struct DLL_LINKAGE TerrainTile
  70. {
  71. TerrainTile();
  72. /// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  73. bool entrableTerrain(const TerrainTile * from = nullptr) const;
  74. bool entrableTerrain(bool allowLand, bool allowSea) const;
  75. /// Checks for blocking objects and terraint type (water / land).
  76. bool isClear(const TerrainTile * from = nullptr) const;
  77. /// Gets the ID of the top visitable object or -1 if there is none.
  78. Obj topVisitableId(bool excludeTop = false) const;
  79. CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
  80. bool isWater() const;
  81. EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
  82. bool hasFavorableWinds() const;
  83. const TerrainType * terType;
  84. ui8 terView;
  85. const RiverType * riverType;
  86. ui8 riverDir;
  87. const RoadType * roadType;
  88. ui8 roadDir;
  89. /// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  90. /// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favorable Winds effect
  91. ui8 extTileFlags;
  92. bool visitable;
  93. bool blocked;
  94. std::vector<CGObjectInstance *> visitableObjects;
  95. std::vector<CGObjectInstance *> blockingObjects;
  96. template <typename Handler>
  97. void serialize(Handler & h, const int version)
  98. {
  99. h & terType;
  100. h & terView;
  101. h & riverType;
  102. h & riverDir;
  103. h & roadType;
  104. h & roadDir;
  105. h & extTileFlags;
  106. h & visitable;
  107. h & blocked;
  108. h & visitableObjects;
  109. h & blockingObjects;
  110. }
  111. };
  112. VCMI_LIB_NAMESPACE_END