ObjectManager.h 2.5 KB

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