ObjectManager.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. class ObjectManager: public Modificator
  27. {
  28. public:
  29. enum OptimizeType
  30. {
  31. NONE = 0x00000000,
  32. WEIGHT = 0x00000001,
  33. DISTANCE = 0x00000010
  34. };
  35. public:
  36. MODIFICATOR(ObjectManager);
  37. void process() override;
  38. void init() override;
  39. void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0);
  40. void addCloseObject(CGObjectInstance * obj, si32 guardStrength = 0);
  41. void addNearbyObject(CGObjectInstance * obj, CGObjectInstance * nearbyTarget);
  42. bool createRequiredObjects();
  43. int3 findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, si32 min_dist, OptimizeType optimizer) const;
  44. int3 findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, const std::function<float(const int3)> & weightFunction, OptimizeType optimizer) const;
  45. rmg::Path placeAndConnectObject(const rmg::Area & searchArea, rmg::Object & obj, si32 min_dist, bool isGuarded, bool onlyStraight, OptimizeType optimizer) const;
  46. rmg::Path placeAndConnectObject(const rmg::Area & searchArea, rmg::Object & obj, const std::function<float(const int3)> & weightFunction, bool isGuarded, bool onlyStraight, OptimizeType optimizer) const;
  47. CGCreature * chooseGuard(si32 strength, bool zoneGuard = false);
  48. bool addGuard(rmg::Object & object, si32 strength, bool zoneGuard = false);
  49. void placeObject(rmg::Object & object, bool guarded, bool updateDistance);
  50. void updateDistances(const rmg::Object & obj);
  51. void createDistancesPriorityQueue();
  52. const rmg::Area & getVisitableArea() const;
  53. std::vector<CGObjectInstance*> getMines() const;
  54. protected:
  55. //content info
  56. std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
  57. std::vector<std::pair<CGObjectInstance*, ui32>> closeObjects;
  58. std::vector<std::pair<CGObjectInstance*, int3>> instantObjects;
  59. std::vector<std::pair<CGObjectInstance*, CGObjectInstance*>> nearbyObjects;
  60. std::vector<CGObjectInstance*> objects;
  61. rmg::Area objectsVisitableArea;
  62. boost::heap::priority_queue<TDistance, boost::heap::compare<DistanceMaximizeFunctor>> tilesByDistance;
  63. };
  64. VCMI_LIB_NAMESPACE_END