ObstacleProxy.h 2.1 KB

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