mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
Mine roads (#808)
* Create dirt roads to mines if there are no roads in a zone.
This commit is contained in:
committed by
Andrii Danylchenko
parent
99a9680f62
commit
f81d869b4a
@ -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)
|
||||
|
Reference in New Issue
Block a user