ObjectClusterizer.h 1.7 KB

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