ObstacleProxy.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ObstacleProxy.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 "../rmg/RmgObject.h"
  12. #include "CMapEditManager.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CMapEditManager;
  15. class CGObjectInstance;
  16. class ObjectTemplate;
  17. class CRandomGenerator;
  18. class DLL_LINKAGE ObstacleProxy
  19. {
  20. //Base class generating random obstacles for RMG and map editor
  21. public:
  22. ObstacleProxy() = default;
  23. virtual ~ObstacleProxy() = default;
  24. void collectPossibleObstacles(TerrainId terrain);
  25. void addBlockedTile(const int3 & tile);
  26. void setBlockedArea(const rmg::Area & area);
  27. void clearBlockedArea();
  28. virtual bool isProhibited(const rmg::Area& objArea) const;
  29. virtual std::pair<bool, bool> verifyCoverage(const int3 & t) const;
  30. virtual void placeObject(rmg::Object & object, std::set<CGObjectInstance*> & instances);
  31. virtual std::set<CGObjectInstance*> createObstacles(CRandomGenerator & rand);
  32. virtual bool isInTheMap(const int3& tile) = 0;
  33. void finalInsertion(CMapEditManager * manager, std::set<CGObjectInstance*> & instances);
  34. virtual void postProcess(const rmg::Object& object) {};
  35. protected:
  36. int getWeightedObjects(const int3& tile, CRandomGenerator& rand, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
  37. rmg::Area blockedArea;
  38. using ObstacleVector = std::vector<std::shared_ptr<const ObjectTemplate>>;
  39. std::map<int, ObstacleVector> obstaclesBySize;
  40. using ObstaclePair = std::pair<int, ObstacleVector>;
  41. std::vector<ObstaclePair> possibleObstacles;
  42. };
  43. class DLL_LINKAGE EditorObstaclePlacer : public ObstacleProxy
  44. {
  45. public:
  46. EditorObstaclePlacer(CMap* map);
  47. bool isInTheMap(const int3& tile) override;
  48. std::set<CGObjectInstance*> placeObstacles(CRandomGenerator& rand);
  49. private:
  50. CMap* map;
  51. };
  52. VCMI_LIB_NAMESPACE_END