From 8510af487e7cf62ed73abef64a74080fdb43fc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Sun, 18 Jun 2023 19:20:12 +0200 Subject: [PATCH] Place objects away from wide connection --- lib/rmg/modificators/ConnectionsPlacer.cpp | 1 + lib/rmg/modificators/ObjectManager.cpp | 12 ++++++++++++ lib/rmg/modificators/ObjectManager.h | 1 + 3 files changed, 14 insertions(+) diff --git a/lib/rmg/modificators/ConnectionsPlacer.cpp b/lib/rmg/modificators/ConnectionsPlacer.cpp index fecf7c951..d51e9aadb 100644 --- a/lib/rmg/modificators/ConnectionsPlacer.cpp +++ b/lib/rmg/modificators/ConnectionsPlacer.cpp @@ -147,6 +147,7 @@ void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & con { zone.connectPath(ourPath); otherZone->connectPath(theirPath); + otherZone->getModificator()->updateDistances(potentialPos); success = true; break; diff --git a/lib/rmg/modificators/ObjectManager.cpp b/lib/rmg/modificators/ObjectManager.cpp index c82e632e0..15a4f890a 100644 --- a/lib/rmg/modificators/ObjectManager.cpp +++ b/lib/rmg/modificators/ObjectManager.cpp @@ -86,6 +86,18 @@ void ObjectManager::updateDistances(const rmg::Object & obj) } } +void ObjectManager::updateDistances(const int3 & pos) +{ + RecursiveLock lock(externalAccessMutex); + tilesByDistance.clear(); + for (auto tile : zone.areaPossible().getTiles()) //don't need to mark distance for not possible tiles + { + ui32 d = pos.dist2dSQ(tile); //optimization, only relative distance is interesting + map.setNearestObjectDistance(tile, std::min(static_cast(d), map.getNearestObjectDistance(tile))); + tilesByDistance.push(std::make_pair(tile, map.getNearestObjectDistance(tile))); + } +} + const rmg::Area & ObjectManager::getVisitableArea() const { RecursiveLock lock(externalAccessMutex); diff --git a/lib/rmg/modificators/ObjectManager.h b/lib/rmg/modificators/ObjectManager.h index 243407fa4..5e17a3303 100644 --- a/lib/rmg/modificators/ObjectManager.h +++ b/lib/rmg/modificators/ObjectManager.h @@ -62,6 +62,7 @@ public: void placeObject(rmg::Object & object, bool guarded, bool updateDistance); void updateDistances(const rmg::Object & obj); + void updateDistances(const int3& pos); void createDistancesPriorityQueue(); const rmg::Area & getVisitableArea() const;