From 1f7ce7c1d97e5dd7bf9e699b2fbbc86da21101a7 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 23 Sep 2014 21:12:10 +0200 Subject: [PATCH] Cut area around towns to prevent sealing off parts of zone. --- lib/rmg/CRmgTemplateZone.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index 1a0999dbf..1f293d3e6 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -406,6 +406,11 @@ void CRmgTemplateZone::createBorder(CMapGenerator* gen) void CRmgTemplateZone::fractalize(CMapGenerator* gen) { + for (auto tile : tileinfo) + { + if (gen->isFree(tile)) + freePaths.insert(tile); + } std::vector clearedTiles (freePaths.begin(), freePaths.end()); std::set possibleTiles; std::set tilesToClear; //will be set clear @@ -917,11 +922,26 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen) //FIXME: handle case that this player is not present -> towns should be set to neutral int totalTowns = 0; - auto addNewTowns = [&totalTowns, gen, this](int count, bool hasFort, PlayerColor player) + auto cutPathAroundTown = [gen, this](const CGTownInstance * town) + { + //cut contour around town in case it was placed in a middle of path. TODO: find better solution + for (auto tile : town->getBlockedPos()) + { + gen->foreach_neighbour(tile, [gen, &tile](int3& pos) + { + if (gen->isPossible(pos)) + { + gen->setOccupied(pos, ETileType::FREE); + } + }); + } + }; + + auto addNewTowns = [&totalTowns, gen, this, &cutPathAroundTown](int count, bool hasFort, PlayerColor player) { for (int i = 0; i < count; i++) { - auto town = new CGTownInstance(); + auto town = new CGTownInstance(); town->ID = Obj::TOWN; if (this->townsAreSameType) @@ -942,6 +962,7 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen) gen->registerZone(town->subID); //first town in zone goes in the middle placeAndGuardObject(gen, town, getPos() + town->getVisitableOffset(), 0); + cutPathAroundTown(town); } else addRequiredObject (town); @@ -973,6 +994,7 @@ void CRmgTemplateZone::initTownType (CMapGenerator* gen) town->builtBuildings.insert(BuildingID::DEFAULT); //towns are big objects and should be centered around visitable position placeAndGuardObject(gen, town, getPos() + town->getVisitableOffset(), 0); //generate no guards, but free path to entrance + cutPathAroundTown(town); totalTowns++; //register MAIN town of zone only