ObjectGraphCalculator.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * ObjectGraphCalculator.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 "ObjectGraph.h"
  12. #include "../AIUtility.h"
  13. namespace NKAI
  14. {
  15. struct ConnectionCostInfo
  16. {
  17. float totalCost = 0;
  18. float avg = 0;
  19. int connectionsCount = 0;
  20. };
  21. class ObjectGraphCalculator
  22. {
  23. private:
  24. ObjectGraph * target;
  25. const Nullkiller * ai;
  26. std::mutex syncLock;
  27. std::map<const CGHeroInstance *, HeroRole> actors;
  28. std::map<const CGHeroInstance *, const CGObjectInstance *> actorObjectMap;
  29. std::vector<std::unique_ptr<CGBoat>> temporaryBoats;
  30. std::vector<std::unique_ptr<CGHeroInstance>> temporaryActorHeroes;
  31. public:
  32. ObjectGraphCalculator(ObjectGraph * target, const Nullkiller * ai);
  33. void setGraphObjects();
  34. void calculateConnections();
  35. float getNeighborConnectionsCost(const int3 & pos, std::vector<AIPath> & pathCache);
  36. void addMinimalDistanceJunctions();
  37. private:
  38. void updatePaths();
  39. void calculateConnections(const int3 & pos, std::vector<AIPath> & pathCache);
  40. bool isExtraConnection(float direct, float side1, float side2) const;
  41. void removeExtraConnections();
  42. void addObjectActor(const CGObjectInstance * obj);
  43. void addJunctionActor(const int3 & visitablePos, bool isVirtualBoat = false);
  44. ConnectionCostInfo getConnectionsCost(std::vector<AIPath> & paths) const;
  45. };
  46. }