CZonePlacer.h 2.2 KB

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