1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00

Mine roads (#808)

* Create dirt roads to mines if there are no roads in a zone.
This commit is contained in:
DjWarmonger 2022-09-04 08:54:06 +02:00 committed by Andrii Danylchenko
parent 2ff8c1091b
commit 6a011b5ee0
7 changed files with 43 additions and 5 deletions

View File

@ -22,6 +22,7 @@
}, },
"minGuardStrength" : 2000, "minGuardStrength" : 2000,
"defaultRoadType" : "pc", //pd - dirt, pg - gravel, pc - cobblestone "defaultRoadType" : "pc", //pd - dirt, pg - gravel, pc - cobblestone
"secondaryRoadType": "pd",
"treasureValueLimit" : 20000, //generate pandora with gold for treasure above this limit "treasureValueLimit" : 20000, //generate pandora with gold for treasure above this limit
"prisons" : "prisons" :
{ {

View File

@ -64,6 +64,7 @@ void CMapGenerator::loadConfig()
config.mineExtraResources = randomMapJson["mines"]["extraResourcesLimit"].Integer(); config.mineExtraResources = randomMapJson["mines"]["extraResourcesLimit"].Integer();
config.minGuardStrength = randomMapJson["minGuardStrength"].Integer(); config.minGuardStrength = randomMapJson["minGuardStrength"].Integer();
config.defaultRoadType = randomMapJson["defaultRoadType"].String(); config.defaultRoadType = randomMapJson["defaultRoadType"].String();
config.secondaryRoadType = randomMapJson["secondaryRoadType"].String();
config.treasureValueLimit = randomMapJson["treasureValueLimit"].Integer(); config.treasureValueLimit = randomMapJson["treasureValueLimit"].Integer();
for(auto & i : randomMapJson["prisons"]["experience"].Vector()) for(auto & i : randomMapJson["prisons"]["experience"].Vector())
config.prisonExperience.push_back(i.Integer()); config.prisonExperience.push_back(i.Integer());

View File

@ -38,6 +38,7 @@ public:
int mineExtraResources; int mineExtraResources;
int minGuardStrength; int minGuardStrength;
std::string defaultRoadType; std::string defaultRoadType;
std::string secondaryRoadType;
int treasureValueLimit; int treasureValueLimit;
std::vector<int> prisonExperience, prisonValues; std::vector<int> prisonExperience, prisonValues;
std::vector<int> scrollValues; std::vector<int> scrollValues;

View File

@ -77,6 +77,21 @@ const rmg::Area & ObjectManager::getVisitableArea() const
return objectsVisitableArea; return objectsVisitableArea;
} }
std::vector<CGObjectInstance*> ObjectManager::getMines() const
{
std::vector<CGObjectInstance*> 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<float(const int3)> weightFunction, OptimizeType optimizer) const int3 ObjectManager::findPlaceForObject(const rmg::Area & searchArea, rmg::Object & obj, std::function<float(const int3)> weightFunction, OptimizeType optimizer) const
{ {
float bestWeight = 0.f; float bestWeight = 0.f;

View File

@ -63,6 +63,8 @@ public:
void createDistancesPriorityQueue(); void createDistancesPriorityQueue();
const rmg::Area & getVisitableArea() const; const rmg::Area & getVisitableArea() const;
std::vector<CGObjectInstance*> getMines() const;
protected: protected:
//content info //content info

View File

@ -10,6 +10,7 @@
#include "StdInc.h" #include "StdInc.h"
#include "RoadPlacer.h" #include "RoadPlacer.h"
#include "ObjectManager.h"
#include "Functions.h" #include "Functions.h"
#include "CMapGenerator.h" #include "CMapGenerator.h"
#include "RmgMap.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.areaPossible().subtract(roads);
zone.freePaths().unite(roads); zone.freePaths().unite(roads);
map.getEditManager()->getTerrainSelection().setSelection(roads.getTilesVector()); 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) void RoadPlacer::addRoadNode(const int3& node)
@ -78,7 +80,22 @@ void RoadPlacer::addRoadNode(const int3& node)
void RoadPlacer::connectRoads() 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<ObjectManager>())
{
for (auto object : m->getMines())
{
addRoadNode(object->visitablePos());
}
}
}
if(roadNodes.size() < 2)
return; return;
//take any tile from road nodes as destination zone for all other road nodes //take any tile from road nodes as destination zone for all other road nodes
@ -90,7 +107,8 @@ void RoadPlacer::connectRoads()
createRoad(node); createRoad(node);
} }
drawRoads(); //Draw dirt roads if there are only mines
drawRoads(noRoadNodes);
} }
char RoadPlacer::dump(const int3 & t) char RoadPlacer::dump(const int3 & t)

View File

@ -28,7 +28,7 @@ public:
protected: protected:
bool createRoad(const int3 & dst); bool createRoad(const int3 & dst);
void drawRoads(); //actually updates tiles void drawRoads(bool secondary = false); //actually updates tiles
protected: protected:
rmg::Tileset roadNodes; //tiles to be connected with roads rmg::Tileset roadNodes; //tiles to be connected with roads