Terrain.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Terrain.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 "ConstTransitivePtr.h"
  12. #include "GameConstants.h"
  13. #include "JsonNode.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class DLL_LINKAGE Terrain
  16. {
  17. public:
  18. friend class Manager;
  19. struct Info
  20. {
  21. enum class Type
  22. {
  23. Land, Water, Subterranean, Rock
  24. };
  25. int moveCost;
  26. bool transitionRequired;
  27. std::array<int, 3> minimapBlocked;
  28. std::array<int, 3> minimapUnblocked;
  29. std::string musicFilename;
  30. std::string tilesFilename;
  31. std::string terrainText;
  32. std::string typeCode;
  33. std::string terrainViewPatterns;
  34. std::string rockTerrain;
  35. std::string river;
  36. int horseSoundId;
  37. Type type;
  38. std::vector<std::string> battleFields;
  39. std::vector<Terrain> prohibitTransitions;
  40. };
  41. class DLL_LINKAGE Manager
  42. {
  43. public:
  44. static const std::vector<Terrain> & terrains();
  45. static const Info & getInfo(const Terrain &);
  46. static int id(const Terrain &);
  47. private:
  48. static Manager & get();
  49. Manager();
  50. std::unordered_map<std::string, Info> terrainInfo;
  51. std::vector<Terrain> terrainVault;
  52. std::map<Terrain, int> terrainId;
  53. };
  54. /*enum EETerrainType
  55. {
  56. ANY_TERRAIN = -3,
  57. WRONG = -2, BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
  58. ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK // ROCK is also intended to be max value.
  59. };*/
  60. Terrain(const std::string & _type = "");
  61. static Terrain createTerrainTypeH3M(int tId);
  62. static Terrain createTerrainByCode(const std::string & typeCode);
  63. int id() const; //TODO: has to be completely removed
  64. Terrain& operator=(const std::string & _type);
  65. DLL_LINKAGE friend bool operator==(const Terrain & l, const Terrain & r);
  66. DLL_LINKAGE friend bool operator!=(const Terrain & l, const Terrain & r);
  67. DLL_LINKAGE friend bool operator<(const Terrain & l, const Terrain & r);
  68. static const Terrain ANY;
  69. bool isLand() const;
  70. bool isWater() const;
  71. bool isPassable() const; //ROCK
  72. bool isUnderground() const;
  73. bool isNative() const;
  74. bool isTransitionRequired() const;
  75. operator std::string() const;
  76. template <typename Handler> void serialize(Handler &h, const int version)
  77. {
  78. h & name;
  79. }
  80. protected:
  81. std::string name;
  82. };
  83. DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const Terrain terrainType);
  84. VCMI_LIB_NAMESPACE_END