ObstacleSetHandler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * ObstacleSetHandler.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 "../GameConstants.h"
  12. #include "../constants/EntityIdentifiers.h"
  13. #include "../IHandlerBase.h"
  14. #include "../json/JsonNode.h"
  15. #include "ObjectTemplate.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class DLL_LINKAGE ObstacleSet
  18. {
  19. public:
  20. // TODO: Create string constants for these
  21. enum EObstacleType
  22. {
  23. MOUNTAINS,
  24. TREES,
  25. LAKES, // Inluding dry or lava lakes
  26. CRATERS, // Chasms, Canyons, etc.
  27. ROCKS,
  28. PLANTS, // Flowers, cacti, mushrooms, logs, shrubs, etc.
  29. STRUCTURES, // Buildings, ruins, etc.
  30. ANIMALS, // Living, or bones
  31. OTHER // Crystals, shipwrecks, barrels, etc.
  32. };
  33. explicit ObstacleSet(EObstacleType type, TerrainId terrain);
  34. void addObstacle(std::shared_ptr<const ObjectTemplate> obstacle);
  35. std::vector<std::shared_ptr<const ObjectTemplate>> getObstacles() const;
  36. EObstacleType getType() const;
  37. TerrainId getTerrain() const;
  38. private:
  39. EObstacleType type;
  40. TerrainId terrain;
  41. std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
  42. };
  43. typedef std::vector<ObstacleSet> TObstacleTypes;
  44. class DLL_LINKAGE ObstacleSetFilter
  45. {
  46. public:
  47. ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain);
  48. ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain);
  49. bool filter(const ObstacleSet &set) const;
  50. std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
  51. TerrainId getTerrain() const;
  52. private:
  53. std::vector<ObstacleSet::EObstacleType> allowedTypes;
  54. // TODO: Filter by faction, alignment, surface/underground, etc.
  55. const TerrainId terrain;
  56. };
  57. // TODO: Instantiate ObstacleSetHandler
  58. class DLL_LINKAGE ObstacleSetHandler : public IHandlerBase, boost::noncopyable
  59. {
  60. public:
  61. ObstacleSetHandler() = default;
  62. ~ObstacleSetHandler() = default;
  63. // FIXME: Not needed at all
  64. std::vector<JsonNode> loadLegacyData() override {return {};};
  65. virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override {};
  66. virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override {};
  67. ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id);
  68. // TODO: Populate obstacleSets with all the obstacle sets from the game data
  69. void addObstacleSet(const ObstacleSet &set);
  70. TObstacleTypes getObstacles(const ObstacleSetFilter &filter) const;
  71. private:
  72. std::map<ObstacleSet::EObstacleType, std::vector<ObstacleSet>> obstacleSets;
  73. };
  74. VCMI_LIB_NAMESPACE_END