ObstacleProxy.h 1.9 KB

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