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:
parent
2ff8c1091b
commit
6a011b5ee0
@ -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" :
|
||||
{
|
||||
|
@ -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());
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
int mineExtraResources;
|
||||
int minGuardStrength;
|
||||
std::string defaultRoadType;
|
||||
std::string secondaryRoadType;
|
||||
int treasureValueLimit;
|
||||
std::vector<int> prisonExperience, prisonValues;
|
||||
std::vector<int> scrollValues;
|
||||
|
@ -77,6 +77,21 @@ const rmg::Area & ObjectManager::getVisitableArea() const
|
||||
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
|
||||
{
|
||||
float bestWeight = 0.f;
|
||||
|
@ -63,6 +63,8 @@ public:
|
||||
void createDistancesPriorityQueue();
|
||||
|
||||
const rmg::Area & getVisitableArea() const;
|
||||
|
||||
std::vector<CGObjectInstance*> getMines() const;
|
||||
|
||||
protected:
|
||||
//content info
|
||||
|
@ -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<ObjectManager>())
|
||||
{
|
||||
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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user