1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/rmg/modificators/RockPlacer.cpp

107 lines
2.4 KiB
C++
Raw Normal View History

/*
* RockPlacer.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "RockPlacer.h"
#include "TreasurePlacer.h"
#include "ObjectManager.h"
#include "RoadPlacer.h"
#include "RiverPlacer.h"
2023-05-20 10:17:37 +02:00
#include "../RmgMap.h"
#include "../CMapGenerator.h"
#include "../Functions.h"
#include "../../TerrainHandler.h"
#include "../../CRandomGenerator.h"
#include "../../mapping/CMapEditManager.h"
#include "../TileInfo.h"
VCMI_LIB_NAMESPACE_BEGIN
class TileInfo;
void RockPlacer::process()
{
blockRock();
}
2024-05-01 09:16:10 +02:00
void RockPlacer::blockRock()
{
rockTerrain = VLC->terrainTypeHandler->getById(zone.getTerrainType())->rockTerrain;
assert(!VLC->terrainTypeHandler->getById(rockTerrain)->isPassable());
accessibleArea = zone.freePaths() + zone.areaUsed();
2024-05-01 09:16:10 +02:00
if(auto * rp = zone.getModificator<RoadPlacer>())
{
accessibleArea.unite(rp->getRoads());
}
if(auto * m = zone.getModificator<ObjectManager>())
2024-05-01 09:16:10 +02:00
{
accessibleArea.unite(m->getVisitableArea());
2024-05-01 09:16:10 +02:00
}
//negative approach - create rock tiles first, then make sure all accessible tiles have no rock
rockArea = zone.area()->getSubarea([this](const int3 & t)
{
return map.shouldBeBlocked(t);
});
}
void RockPlacer::postProcess()
{
{
Zone::Lock lock(zone.areaMutex);
//Finally mark rock tiles as occupied, spawn no obstacles there
rockArea = zone.area()->getSubarea([this](const int3 & t)
{
return !map.getTile(t).terType->isPassable();
});
2024-05-01 09:16:10 +02:00
// Do not place rock on roads
if(auto * rp = zone.getModificator<RoadPlacer>())
{
rockArea.subtract(rp->getRoads());
}
zone.areaUsed()->unite(rockArea);
zone.areaPossible()->subtract(rockArea);
}
//RecursiveLock lock(externalAccessMutex);
if(auto * m = zone.getModificator<RiverPlacer>())
m->riverProhibit().unite(rockArea);
if(auto * m = zone.getModificator<RoadPlacer>())
m->areaIsolated().unite(rockArea);
}
void RockPlacer::init()
{
2024-05-01 09:16:10 +02:00
DEPENDENCY(RoadPlacer);
for (const auto& zone : map.getZonesOnLevel(1))
{
2024-05-01 09:16:10 +02:00
auto * tp = zone.second->getModificator<TreasurePlacer>();
if (tp)
{
2024-05-01 09:16:10 +02:00
dependency(tp);
}
}
}
char RockPlacer::dump(const int3 & t)
{
if(!map.getTile(t).terType->isPassable())
{
return zone.area()->contains(t) ? 'R' : 'E';
}
return Modificator::dump(t);
}
VCMI_LIB_NAMESPACE_END