CMapDefines.h 3.4 KB

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