ObstacleProxy.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 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(TerrainId terrain, CRandomGenerator & 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(CRandomGenerator & 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, CRandomGenerator& rand, IGameCallback * cb, std::list<rmg::Object>& allObjects, std::vector<std::pair<rmg::Object*, int3>>& weightedObjects);
  39. rmg::Area blockedArea;
  40. using ObstacleVector = std::vector<std::shared_ptr<const ObjectTemplate>>;
  41. std::map<int, ObstacleVector> obstaclesBySize;
  42. using ObstaclePair = std::pair<int, ObstacleVector>;
  43. std::vector<ObstaclePair> possibleObstacles;
  44. };
  45. class DLL_LINKAGE EditorObstaclePlacer : public ObstacleProxy
  46. {
  47. public:
  48. EditorObstaclePlacer(CMap* map);
  49. bool isInTheMap(const int3& tile) override;
  50. std::set<CGObjectInstance*> placeObstacles(CRandomGenerator& rand);
  51. private:
  52. CMap* map;
  53. };
  54. VCMI_LIB_NAMESPACE_END