From b3adb9e5545f22fdb2113e94a113ad137b0d5083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Mon, 22 Jan 2024 09:27:30 +0100 Subject: [PATCH] Do not place zone guards adjacent to 3rd zone --- lib/rmg/modificators/ConnectionsPlacer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/rmg/modificators/ConnectionsPlacer.cpp b/lib/rmg/modificators/ConnectionsPlacer.cpp index d2c1ddada..89689c932 100644 --- a/lib/rmg/modificators/ConnectionsPlacer.cpp +++ b/lib/rmg/modificators/ConnectionsPlacer.cpp @@ -177,6 +177,21 @@ void ConnectionsPlacer::selfSideDirectConnection(const rmg::ZoneConnection & con int3 potentialPos = zone.areaPossible().nearest(borderPos); assert(borderPos != potentialPos); + //Check if guard pos doesn't touch any 3rd zone. This would create unwanted passage to 3rd zone + bool adjacentZone = false; + map.foreach_neighbour(potentialPos, [this, &adjacentZone, otherZoneId](int3 & pos) + { + auto zoneId = map.getZoneID(pos); + if (zoneId != zone.getId() && zoneId != otherZoneId) + { + adjacentZone = true; + } + }); + if (adjacentZone) + { + continue; + } + //Take into account distance to objects from both sides float dist = std::min(map.getTileInfo(potentialPos).getNearestObjectDistance(), map.getTileInfo(borderPos).getNearestObjectDistance());