ObstacleProxy.h 2.1 KB

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