diff --git a/config/randomMap.json b/config/randomMap.json index 4a9a9a50e..e5c341c7a 100644 --- a/config/randomMap.json +++ b/config/randomMap.json @@ -22,6 +22,7 @@ }, "minGuardStrength" : 2000, "defaultRoadType" : "pc", //pd - dirt, pg - gravel, pc - cobblestone + "secondaryRoadType": "pd", "treasureValueLimit" : 20000, //generate pandora with gold for treasure above this limit "prisons" : { diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index d4e6a98dc..3dbf3efd7 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -64,6 +64,7 @@ void CMapGenerator::loadConfig() config.mineExtraResources = randomMapJson["mines"]["extraResourcesLimit"].Integer(); config.minGuardStrength = randomMapJson["minGuardStrength"].Integer(); config.defaultRoadType = randomMapJson["defaultRoadType"].String(); + config.secondaryRoadType = randomMapJson["secondaryRoadType"].String(); config.treasureValueLimit = randomMapJson["treasureValueLimit"].Integer(); for(auto & i : randomMapJson["prisons"]["experience"].Vector()) config.prisonExperience.push_back(i.Integer()); diff --git a/lib/rmg/CMapGenerator.h b/lib/rmg/CMapGenerator.h index 34ca69be0..29fa72411 100644 --- a/lib/rmg/CMapGenerator.h +++ b/lib/rmg/CMapGenerator.h @@ -38,6 +38,7 @@ public: int mineExtraResources; int minGuardStrength; std::string defaultRoadType; + std::string secondaryRoadType; int treasureValueLimit; std::vector prisonExperience, prisonValues; std::vector scrollValues; diff --git a/lib/rmg/ObjectManager.cpp b/lib/rmg/ObjectManager.cpp index 06f037e00..b995941d9 100644 --- a/lib/rmg/ObjectManager.cpp +++ b/lib/rmg/ObjectManager.cpp @@ -77,6 +77,21 @@ const rmg::Area & ObjectManager::getVisitableArea() const return objectsVisitableArea; } +std::vector ObjectManager::getMines() const +{ + std::vector mines; + + for (auto object : objects) + { + if (object->ID == Obj::MINE) + { + mines.push_back(object); + } + } + + return mines; +} + int3 ObjectManager::findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, std::function weightFunction, OptimizeType optimizer) const { float bestWeight = 0.f; diff --git a/lib/rmg/ObjectManager.h b/lib/rmg/ObjectManager.h index 3349d293d..ff3148af6 100644 --- a/lib/rmg/ObjectManager.h +++ b/lib/rmg/ObjectManager.h @@ -63,6 +63,8 @@ public: void createDistancesPriorityQueue(); const rmg::Area & getVisitableArea() const; + + std::vector getMines() const; protected: //content info diff --git a/lib/rmg/RoadPlacer.cpp b/lib/rmg/RoadPlacer.cpp index 03860fbae..8f605a0d6 100644 --- a/lib/rmg/RoadPlacer.cpp +++ b/lib/rmg/RoadPlacer.cpp @@ -10,6 +10,7 @@ #include "StdInc.h" #include "RoadPlacer.h" +#include "ObjectManager.h" #include "Functions.h" #include "CMapGenerator.h" #include "RmgMap.h" @@ -63,12 +64,13 @@ bool RoadPlacer::createRoad(const int3 & dst) } -void RoadPlacer::drawRoads() +void RoadPlacer::drawRoads(bool secondary) { zone.areaPossible().subtract(roads); zone.freePaths().unite(roads); map.getEditManager()->getTerrainSelection().setSelection(roads.getTilesVector()); - map.getEditManager()->drawRoad(generator.getConfig().defaultRoadType, &generator.rand); + std::string roadType = (secondary ? generator.getConfig().secondaryRoadType : generator.getConfig().defaultRoadType); + map.getEditManager()->drawRoad(roadType, &generator.rand); } void RoadPlacer::addRoadNode(const int3& node) @@ -78,7 +80,22 @@ void RoadPlacer::addRoadNode(const int3& node) void RoadPlacer::connectRoads() { - if(roadNodes.empty()) + bool noRoadNodes = false; + //Assumes objects are already placed + if (roadNodes.size() < 2) + { + //If there are no nodes, draw roads to mines + noRoadNodes = true; + if (auto* m = zone.getModificator()) + { + for (auto object : m->getMines()) + { + addRoadNode(object->visitablePos()); + } + } + } + + if(roadNodes.size() < 2) return; //take any tile from road nodes as destination zone for all other road nodes @@ -90,7 +107,8 @@ void RoadPlacer::connectRoads() createRoad(node); } - drawRoads(); + //Draw dirt roads if there are only mines + drawRoads(noRoadNodes); } char RoadPlacer::dump(const int3 & t) diff --git a/lib/rmg/RoadPlacer.h b/lib/rmg/RoadPlacer.h index 5c7f44337..585679ee6 100644 --- a/lib/rmg/RoadPlacer.h +++ b/lib/rmg/RoadPlacer.h @@ -28,7 +28,7 @@ public: protected: bool createRoad(const int3 & dst); - void drawRoads(); //actually updates tiles + void drawRoads(bool secondary = false); //actually updates tiles protected: rmg::Tileset roadNodes; //tiles to be connected with roads