From a0ed8e0d6d72c1cf250ea72477b5380416de33ee Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Mon, 25 May 2015 19:25:48 +0200 Subject: [PATCH] An attempt to straighten roads. --- lib/rmg/CRmgTemplateZone.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index fbf330b3e..a1be53605 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -719,7 +719,7 @@ bool CRmgTemplateZone::createRoad(CMapGenerator* gen, const int3& src, const int std::set closed; // The set of nodes already evaluated. std::set open{src}; // The set of tentative nodes to be evaluated, initially containing the start node std::map cameFrom; // The map of navigated nodes. - std::map distances; + std::map distances; int3 currentNode = src; gen->setRoad (src, ERoadType::NO_ROAD); //just in case zone guard already has road under it. Road under nodes will be added at very end @@ -758,10 +758,11 @@ bool CRmgTemplateZone::createRoad(CMapGenerator* gen, const int3& src, const int else { bool directNeighbourFound = false; + float movementCost = 1; - auto foo = [gen, this, &open, &closed, &cameFrom, ¤tNode, &distances, &dst, &directNeighbourFound](int3& pos) -> void + auto foo = [gen, this, &open, &closed, &cameFrom, ¤tNode, &distances, &dst, &directNeighbourFound, movementCost](int3& pos) -> void { - int distance = distances[currentNode] + 1; + int distance = distances[currentNode] + movementCost; int bestDistanceSoFar = 1e6; //FIXME: boost::limits auto it = distances.find(pos); if (it != distances.end()) @@ -787,7 +788,10 @@ bool CRmgTemplateZone::createRoad(CMapGenerator* gen, const int3& src, const int gen->foreachDirectNeighbour (currentNode, foo); // roads cannot be rendered correctly for diagonal directions if (!directNeighbourFound) - gen->foreach_neighbour (currentNode, foo); + { + movementCost = 2.1f; //moving diagonally is penalized over moving two tiles straight + gen->foreach_neighbour(currentNode, foo); + } } }