Terrain.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. class DLL_LINKAGE Terrain
  15. {
  16. public:
  17. friend class Manager;
  18. struct Info
  19. {
  20. enum class Type
  21. {
  22. Land, Water, Subterranean, Rock
  23. };
  24. int moveCost;
  25. bool transitionRequired;
  26. std::array<int, 3> minimapBlocked;
  27. std::array<int, 3> minimapUnblocked;
  28. std::string musicFilename;
  29. std::string tilesFilename;
  30. std::string terrainText;
  31. std::string typeCode;
  32. std::string terrainViewPatterns;
  33. std::string rockTerrain;
  34. std::string river;
  35. int horseSoundId;
  36. Type type;
  37. std::vector<std::string> battleFields;
  38. std::vector<Terrain> prohibitTransitions;
  39. };
  40. class DLL_LINKAGE Manager
  41. {
  42. public:
  43. static const std::vector<Terrain> & terrains();
  44. static const Info & getInfo(const Terrain &);
  45. static int id(const Terrain &);
  46. private:
  47. static Manager & get();
  48. Manager();
  49. std::unordered_map<std::string, Info> terrainInfo;
  50. std::vector<Terrain> terrainVault;
  51. std::map<Terrain, int> terrainId;
  52. };
  53. /*enum EETerrainType
  54. {
  55. ANY_TERRAIN = -3,
  56. WRONG = -2, BORDER = -1, DIRT, SAND, GRASS, SNOW, SWAMP,
  57. ROUGH, SUBTERRANEAN, LAVA, WATER, ROCK // ROCK is also intended to be max value.
  58. };*/
  59. Terrain(const std::string & _type = "");
  60. static Terrain createTerrainTypeH3M(int tId);
  61. static Terrain createTerrainByCode(const std::string & typeCode);
  62. int id() const; //TODO: has to be completely removed
  63. Terrain& operator=(const Terrain & _type);
  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);