ObjectClusterizer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * DangerHitMapAnalyzer.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 "../Pathfinding/AINodeStorage.h"
  12. struct ClusterObjectInfo
  13. {
  14. float priority;
  15. float movementCost;
  16. uint64_t danger;
  17. uint8_t turn;
  18. };
  19. struct ObjectCluster
  20. {
  21. public:
  22. std::map<const CGObjectInstance *, ClusterObjectInfo> objects;
  23. const CGObjectInstance * blocker;
  24. void reset()
  25. {
  26. objects.clear();
  27. }
  28. void addObject(const CGObjectInstance * object, const AIPath & path, float priority);
  29. ObjectCluster(const CGObjectInstance * blocker)
  30. :objects(), blocker(blocker)
  31. {
  32. }
  33. ObjectCluster() : ObjectCluster(nullptr)
  34. {
  35. }
  36. std::vector<const CGObjectInstance *> getObjects() const;
  37. const CGObjectInstance * calculateCenter() const;
  38. };
  39. class ObjectClusterizer
  40. {
  41. private:
  42. ObjectCluster nearObjects;
  43. ObjectCluster farObjects;
  44. std::map<const CGObjectInstance *, std::shared_ptr<ObjectCluster>> blockedObjects;
  45. const Nullkiller * ai;
  46. public:
  47. void clusterize();
  48. std::vector<const CGObjectInstance *> getNearbyObjects() const;
  49. std::vector<const CGObjectInstance *> getFarObjects() const;
  50. std::vector<std::shared_ptr<ObjectCluster>> getLockedClusters() const;
  51. const CGObjectInstance * getBlocker(const AIPath & path) const;
  52. ObjectClusterizer(const Nullkiller * ai)
  53. :nearObjects(), farObjects(), blockedObjects(), ai(ai)
  54. {
  55. }
  56. private:
  57. bool shouldVisitObject(const CGObjectInstance * obj) const;
  58. };