ObjectClusterizer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. typedef tbb::concurrent_hash_map<const CGObjectInstance *, ClusterObjectInfo> ClusterObjects;
  20. struct ObjectCluster
  21. {
  22. public:
  23. ClusterObjects objects;
  24. const CGObjectInstance * blocker;
  25. void reset()
  26. {
  27. objects.clear();
  28. }
  29. void addObject(const CGObjectInstance * object, const AIPath & path, float priority);
  30. ObjectCluster(const CGObjectInstance * blocker)
  31. :objects(), blocker(blocker)
  32. {
  33. }
  34. ObjectCluster() : ObjectCluster(nullptr)
  35. {
  36. }
  37. std::vector<const CGObjectInstance *> getObjects() const;
  38. const CGObjectInstance * calculateCenter() const;
  39. };
  40. typedef tbb::concurrent_hash_map<const CGObjectInstance *, std::shared_ptr<ObjectCluster>> ClusterMap;
  41. class ObjectClusterizer
  42. {
  43. private:
  44. ObjectCluster nearObjects;
  45. ObjectCluster farObjects;
  46. ClusterMap blockedObjects;
  47. const Nullkiller * ai;
  48. public:
  49. void clusterize();
  50. std::vector<const CGObjectInstance *> getNearbyObjects() const;
  51. std::vector<const CGObjectInstance *> getFarObjects() const;
  52. std::vector<std::shared_ptr<ObjectCluster>> getLockedClusters() const;
  53. const CGObjectInstance * getBlocker(const AIPath & path) const;
  54. ObjectClusterizer(const Nullkiller * ai)
  55. :nearObjects(), farObjects(), blockedObjects(), ai(ai)
  56. {
  57. }
  58. private:
  59. bool shouldVisitObject(const CGObjectInstance * obj) const;
  60. };