CZonePlacer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. class CZoneGraph;
  15. class CMap;
  16. class CRandomGenerator;
  17. class RmgMap;
  18. class Zone;
  19. typedef std::vector<std::pair<TRmgTemplateZoneId, std::shared_ptr<Zone>>> TZoneVector;
  20. typedef std::map<TRmgTemplateZoneId, std::shared_ptr<Zone>> TZoneMap;
  21. typedef std::map<std::shared_ptr<Zone>, float3> TForceVector;
  22. typedef std::map<std::shared_ptr<Zone>, float> TDistanceVector;
  23. class CZonePlacer
  24. {
  25. public:
  26. explicit CZonePlacer(RmgMap & map);
  27. int3 cords (const float3 f) const;
  28. float metric (const int3 &a, const int3 &b) const;
  29. float getDistance(float distance) const; //additional scaling without 0 divison
  30. ~CZonePlacer();
  31. void placeZones(CRandomGenerator * rand);
  32. void assignZones(CRandomGenerator * rand);
  33. private:
  34. void prepareZones(TZoneMap &zones, TZoneVector &zonesVector, const bool underground, CRandomGenerator * rand);
  35. void attractConnectedZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &distances);
  36. void separateOverlappingZones(TZoneMap &zones, TForceVector &forces, TDistanceVector &overlaps);
  37. void moveOneZone(TZoneMap &zones, TForceVector &totalForces, TDistanceVector &distances, TDistanceVector &overlaps);
  38. private:
  39. int width;
  40. int height;
  41. //metric coefiicients
  42. float scaleX;
  43. float scaleY;
  44. float mapSize;
  45. float gravityConstant;
  46. float stiffnessConstant;
  47. //float a1, b1, c1, a2, b2, c2;
  48. //CMap * map;
  49. //std::unique_ptr<CZoneGraph> graph;
  50. RmgMap & map;
  51. };