ObjectManager.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * ObjectManager.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 "../Zone.h"
  12. #include "../RmgObject.h"
  13. #include <boost/heap/priority_queue.hpp> //A*
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CGObjectInstance;
  16. class ObjectTemplate;
  17. class CGCreature;
  18. using TDistance = std::pair<int3, float>;
  19. struct DistanceMaximizeFunctor
  20. {
  21. bool operator()(const TDistance & lhs, const TDistance & rhs) const
  22. {
  23. return (rhs.second > lhs.second);
  24. }
  25. };
  26. struct RequiredObjectInfo
  27. {
  28. RequiredObjectInfo();
  29. RequiredObjectInfo(std::shared_ptr<CGObjectInstance> obj, ui32 guardStrength = 0, bool createRoad = false, CGObjectInstance* nearbyTarget = nullptr);
  30. std::shared_ptr<CGObjectInstance> obj;
  31. CGObjectInstance* nearbyTarget;
  32. int3 pos;
  33. ui32 guardStrength;
  34. bool createRoad;
  35. };
  36. class ObjectManager: public Modificator
  37. {
  38. public:
  39. enum OptimizeType
  40. {
  41. NONE = 0x00000000,
  42. WEIGHT = 0x00000001,
  43. DISTANCE = 0x00000010,
  44. BOTH = 0x00000011
  45. };
  46. public:
  47. MODIFICATOR(ObjectManager);
  48. void process() override;
  49. void init() override;
  50. void addRequiredObject(const RequiredObjectInfo & info);
  51. void addCloseObject(const RequiredObjectInfo & info);
  52. void addNearbyObject(const RequiredObjectInfo & info);
  53. bool createMonoliths();
  54. bool createRequiredObjects();
  55. int3 findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, si32 min_dist, OptimizeType optimizer) const;
  56. int3 findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, const std::function<float(const int3)> & weightFunction, OptimizeType optimizer) const;
  57. rmg::Path placeAndConnectObject(const rmg::Area & searchArea, rmg::Object & obj, si32 min_dist, bool isGuarded, bool onlyStraight, OptimizeType optimizer) const;
  58. rmg::Path placeAndConnectObject(const rmg::Area & searchArea, rmg::Object & obj, const std::function<float(const int3)> & weightFunction, bool isGuarded, bool onlyStraight, OptimizeType optimizer) const;
  59. std::shared_ptr<CGCreature> chooseGuard(si32 strength, bool zoneGuard = false);
  60. bool addGuard(rmg::Object & object, si32 strength, bool zoneGuard = false);
  61. void placeObject(rmg::Object & object, bool guarded, bool updateDistance, bool createRoad = false);
  62. void updateDistances(const rmg::Object & obj);
  63. void updateDistances(const int3& pos);
  64. void updateDistances(std::function<ui32(const int3 & tile)> distanceFunction);
  65. void createDistancesPriorityQueue();
  66. const rmg::Area & getVisitableArea() const;
  67. std::vector<CGObjectInstance*> getMines() const;
  68. protected:
  69. //content info
  70. std::vector<RequiredObjectInfo> requiredObjects;
  71. std::vector<RequiredObjectInfo> closeObjects;
  72. std::vector<RequiredObjectInfo> instantObjects;
  73. std::vector<RequiredObjectInfo> nearbyObjects;
  74. std::vector<CGObjectInstance*> objects;
  75. rmg::Area objectsVisitableArea;
  76. boost::heap::priority_queue<TDistance, boost::heap::compare<DistanceMaximizeFunctor>> tilesByDistance;
  77. };
  78. VCMI_LIB_NAMESPACE_END