CZonePlacer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. namespace vstd
  16. {
  17. class RNG;
  18. }
  19. class CZoneGraph;
  20. class CMap;
  21. class RmgMap;
  22. class Zone;
  23. typedef std::vector<std::pair<TRmgTemplateZoneId, std::shared_ptr<Zone>>> TZoneVector;
  24. typedef std::map<TRmgTemplateZoneId, std::shared_ptr<Zone>> TZoneMap;
  25. typedef std::map<std::shared_ptr<Zone>, float3> TForceVector;
  26. typedef std::map<std::shared_ptr<Zone>, float> TDistanceVector;
  27. typedef std::map<int, std::map<int, size_t>> TDistanceMap;
  28. class CZonePlacer
  29. {
  30. public:
  31. explicit CZonePlacer(RmgMap & map);
  32. int3 cords(const float3 & f) const;
  33. float metric (const int3 &a, const int3 &b) const;
  34. float getDistance(float distance) const; //additional scaling without 0 division
  35. ~CZonePlacer() = default;
  36. void placeZones(vstd::RNG * rand);
  37. void findPathsBetweenZones();
  38. void placeOnGrid(vstd::RNG* rand);
  39. float scaleForceBetweenZones(const std::shared_ptr<Zone> zoneA, const std::shared_ptr<Zone> zoneB) const;
  40. void assignZones(vstd::RNG * rand);
  41. void RemoveRoadsForWideConnections();
  42. const TDistanceMap & getDistanceMap();
  43. private:
  44. void prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const int mapLevels, vstd::RNG * rand);
  45. void attractConnectedZones(TZoneMap & zones, TForceVector & forces, TDistanceVector & distances) const;
  46. void separateOverlappingZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &overlaps);
  47. void moveOneZone(TZoneMap & zones, TForceVector & totalForces, TDistanceVector & distances, TDistanceVector & overlaps);
  48. private:
  49. int width;
  50. int height;
  51. //metric coefficient
  52. float mapSize;
  53. float gravityConstant;
  54. float stiffnessConstant;
  55. float stifness;
  56. float stiffnessIncreaseFactor;
  57. //remember best solution
  58. float bestTotalDistance;
  59. float bestTotalOverlap;
  60. //distance [a][b] = number of zone connections required to travel between the zones
  61. TDistanceMap distancesBetweenZones;
  62. std::set<TRmgTemplateZoneId> lastSwappedZones;
  63. RmgMap & map;
  64. };
  65. VCMI_LIB_NAMESPACE_END