CZonePlacer.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * CZonePlacer.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 "float3.h"
  12. #include "../int3.h"
  13. #include "../GameConstants.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CZoneGraph;
  16. class CMap;
  17. class CRandomGenerator;
  18. class RmgMap;
  19. class Zone;
  20. using TZoneVector = std::vector<std::pair<TRmgTemplateZoneId, std::shared_ptr<Zone>>>;
  21. using TZoneMap = std::map<TRmgTemplateZoneId, std::shared_ptr<Zone>>;
  22. using TForceVector = std::map<std::shared_ptr<Zone>, float3>;
  23. using TDistanceVector = std::map<std::shared_ptr<Zone>, float>;
  24. class CZonePlacer
  25. {
  26. public:
  27. explicit CZonePlacer(RmgMap & map);
  28. int3 cords(const float3 & f) const;
  29. float metric (const int3 &a, const int3 &b) const;
  30. float getDistance(float distance) const; //additional scaling without 0 divison
  31. ~CZonePlacer() = default;
  32. void placeZones(CRandomGenerator * rand);
  33. void findPathsBetweenZones();
  34. void placeOnGrid(CRandomGenerator* rand);
  35. void assignZones(CRandomGenerator * rand);
  36. private:
  37. void prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, CRandomGenerator * rand);
  38. void attractConnectedZones(TZoneMap & zones, TForceVector & forces, TDistanceVector & distances) const;
  39. void separateOverlappingZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &overlaps);
  40. void moveOneZone(TZoneMap & zones, TForceVector & totalForces, TDistanceVector & distances, TDistanceVector & overlaps);
  41. private:
  42. int width;
  43. int height;
  44. //metric coeficients
  45. float scaleX;
  46. float scaleY;
  47. float mapSize;
  48. float gravityConstant;
  49. float stiffnessConstant;
  50. float stifness;
  51. float stiffnessIncreaseFactor;
  52. //remember best solution
  53. float bestTotalDistance;
  54. float bestTotalOverlap;
  55. //distance [a][b] = number of zone connections required to travel between the zones
  56. std::map<int, std::map<int, size_t>> distancesBetweenZones;
  57. std::set<TRmgTemplateZoneId> lastSwappedZones;
  58. RmgMap & map;
  59. };
  60. VCMI_LIB_NAMESPACE_END