mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
Refactored Functions.cpp, removed unused function.
This commit is contained in:
parent
c27b8383e7
commit
71f882d5ba
@ -861,8 +861,9 @@ void CZonePlacer::assignZones(CRandomGenerator * rand)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//make sure that terrain inside zone is not a rock
|
//make sure that terrain inside zone is not a rock
|
||||||
//FIXME: reorder actions?
|
|
||||||
paintZoneTerrain(*zone.second, *rand, map.getMapProxy(), ETerrainId::SUBTERRANEAN);
|
auto v = zone.second->getArea().getTilesVector();
|
||||||
|
map.getMapProxy()->drawTerrain(*rand, v, ETerrainId::SUBTERRANEAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logGlobal->info("Finished zone colouring");
|
logGlobal->info("Finished zone colouring");
|
||||||
|
@ -61,14 +61,14 @@ void ConnectionsPlacer::process()
|
|||||||
|
|
||||||
diningPhilosophers([this](const rmg::ZoneConnection& c)
|
diningPhilosophers([this](const rmg::ZoneConnection& c)
|
||||||
{
|
{
|
||||||
this->selfSideDirectConnection(c);
|
selfSideDirectConnection(c);
|
||||||
});
|
});
|
||||||
|
|
||||||
createBorder(map, zone);
|
createBorder();
|
||||||
|
|
||||||
diningPhilosophers([this](const rmg::ZoneConnection& c)
|
diningPhilosophers([this](const rmg::ZoneConnection& c)
|
||||||
{
|
{
|
||||||
this->selfSideIndirectConnection(c);
|
selfSideIndirectConnection(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,4 +313,34 @@ void ConnectionsPlacer::collectNeighbourZones()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionsPlacer::createBorder()
|
||||||
|
{
|
||||||
|
rmg::Area borderArea(zone.getArea().getBorder());
|
||||||
|
rmg::Area borderOutsideArea(zone.getArea().getBorderOutside());
|
||||||
|
auto blockBorder = borderArea.getSubarea([this, &borderOutsideArea](const int3 & t)
|
||||||
|
{
|
||||||
|
auto tile = borderOutsideArea.nearest(t);
|
||||||
|
return map.isOnMap(tile) && map.getZones()[map.getZoneID(tile)]->getType() != ETemplateZoneType::WATER;
|
||||||
|
});
|
||||||
|
|
||||||
|
Zone::Lock lock(zone.areaMutex); //Protect from erasing same tiles again
|
||||||
|
for(const auto & tile : blockBorder.getTilesVector())
|
||||||
|
{
|
||||||
|
if(map.isPossible(tile))
|
||||||
|
{
|
||||||
|
map.setOccupied(tile, ETileType::BLOCKED);
|
||||||
|
zone.areaPossible().erase(tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
map.foreachDirectNeighbour(tile, [this](int3 &nearbyPos)
|
||||||
|
{
|
||||||
|
if(map.isPossible(nearbyPos) && map.getZoneID(nearbyPos) == zone.getId())
|
||||||
|
{
|
||||||
|
map.setOccupied(nearbyPos, ETileType::BLOCKED);
|
||||||
|
zone.areaPossible().erase(nearbyPos);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -27,6 +27,7 @@ public:
|
|||||||
void selfSideDirectConnection(const rmg::ZoneConnection & connection);
|
void selfSideDirectConnection(const rmg::ZoneConnection & connection);
|
||||||
void selfSideIndirectConnection(const rmg::ZoneConnection & connection);
|
void selfSideIndirectConnection(const rmg::ZoneConnection & connection);
|
||||||
void otherSideConnection(const rmg::ZoneConnection & connection);
|
void otherSideConnection(const rmg::ZoneConnection & connection);
|
||||||
|
void createBorder();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void collectNeighbourZones();
|
void collectNeighbourZones();
|
||||||
|
@ -11,19 +11,11 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "Functions.h"
|
#include "Functions.h"
|
||||||
#include "CMapGenerator.h"
|
#include "CMapGenerator.h"
|
||||||
#include "ObjectManager.h"
|
|
||||||
#include "RoadPlacer.h"
|
|
||||||
#include "TreasurePlacer.h"
|
|
||||||
#include "ConnectionsPlacer.h"
|
|
||||||
#include "TownPlacer.h"
|
|
||||||
#include "WaterProxy.h"
|
|
||||||
#include "WaterRoutes.h"
|
|
||||||
#include "RmgMap.h"
|
#include "RmgMap.h"
|
||||||
#include "TileInfo.h"
|
#include "TileInfo.h"
|
||||||
#include "RmgPath.h"
|
#include "RmgPath.h"
|
||||||
#include "../TerrainHandler.h"
|
#include "../TerrainHandler.h"
|
||||||
#include "../CTownHandler.h"
|
#include "../CTownHandler.h"
|
||||||
#include "../mapping/CMapEditManager.h"
|
|
||||||
#include "../mapping/CMap.h"
|
#include "../mapping/CMap.h"
|
||||||
#include "../mapObjects/CommonConstructors.h"
|
#include "../mapObjects/CommonConstructors.h"
|
||||||
#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h
|
#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h
|
||||||
@ -41,42 +33,6 @@ rmg::Tileset collectDistantTiles(const Zone& zone, int distance)
|
|||||||
return subarea.getTiles();
|
return subarea.getTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void createBorder(RmgMap & gen, Zone & zone)
|
|
||||||
{
|
|
||||||
rmg::Area borderArea(zone.getArea().getBorder());
|
|
||||||
rmg::Area borderOutsideArea(zone.getArea().getBorderOutside());
|
|
||||||
auto blockBorder = borderArea.getSubarea([&gen, &borderOutsideArea](const int3 & t)
|
|
||||||
{
|
|
||||||
auto tile = borderOutsideArea.nearest(t);
|
|
||||||
return gen.isOnMap(tile) && gen.getZones()[gen.getZoneID(tile)]->getType() != ETemplateZoneType::WATER;
|
|
||||||
});
|
|
||||||
|
|
||||||
Zone::Lock lock(zone.areaMutex); //Protect from erasing same tiles again
|
|
||||||
for(const auto & tile : blockBorder.getTilesVector())
|
|
||||||
{
|
|
||||||
if(gen.isPossible(tile))
|
|
||||||
{
|
|
||||||
gen.setOccupied(tile, ETileType::BLOCKED);
|
|
||||||
zone.areaPossible().erase(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
gen.foreachDirectNeighbour(tile, [&gen, &zone](int3 &nearbyPos)
|
|
||||||
{
|
|
||||||
if(gen.isPossible(nearbyPos) && gen.getZoneID(nearbyPos) == zone.getId())
|
|
||||||
{
|
|
||||||
gen.setOccupied(nearbyPos, ETileType::BLOCKED);
|
|
||||||
zone.areaPossible().erase(nearbyPos);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, std::shared_ptr<MapProxy> mapProxy, TerrainId terrain)
|
|
||||||
{
|
|
||||||
auto v = zone.getArea().getTilesVector();
|
|
||||||
mapProxy->drawTerrain(generator, v, terrain);
|
|
||||||
}
|
|
||||||
|
|
||||||
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain)
|
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain)
|
||||||
{
|
{
|
||||||
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
|
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
|
||||||
@ -89,85 +45,4 @@ int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId t
|
|||||||
return *RandomGeneratorUtil::nextItem(factories, generator);
|
return *RandomGeneratorUtil::nextItem(factories, generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTerrainType(Zone & zone, CMapGenerator & gen)
|
|
||||||
{
|
|
||||||
if(zone.getType()==ETemplateZoneType::WATER)
|
|
||||||
{
|
|
||||||
//collect all water terrain types
|
|
||||||
std::vector<TerrainId> waterTerrains;
|
|
||||||
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
|
||||||
if(terrain->isWater())
|
|
||||||
waterTerrains.push_back(terrain->getId());
|
|
||||||
|
|
||||||
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, gen.rand));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(zone.isMatchTerrainToTown() && zone.getTownType() != ETownType::NEUTRAL)
|
|
||||||
{
|
|
||||||
auto terrainType = (*VLC->townh)[zone.getTownType()]->nativeTerrain;
|
|
||||||
|
|
||||||
if (terrainType <= ETerrainId::NONE)
|
|
||||||
{
|
|
||||||
logGlobal->warn("Town %s has invalid terrain type: %d", zone.getTownType(), terrainType);
|
|
||||||
zone.setTerrainType(ETerrainId::DIRT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zone.setTerrainType(terrainType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto terrainTypes = zone.getTerrainTypes();
|
|
||||||
if (terrainTypes.empty())
|
|
||||||
{
|
|
||||||
logGlobal->warn("No terrain types found, falling back to DIRT");
|
|
||||||
zone.setTerrainType(ETerrainId::DIRT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
zone.setTerrainType(*RandomGeneratorUtil::nextItem(terrainTypes, gen.rand));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Now, replace disallowed terrains on surface and in the underground
|
|
||||||
const auto & terrainType = VLC->terrainTypeHandler->getById(zone.getTerrainType());
|
|
||||||
|
|
||||||
if(zone.isUnderground())
|
|
||||||
{
|
|
||||||
if(!terrainType->isUnderground())
|
|
||||||
{
|
|
||||||
zone.setTerrainType(ETerrainId::SUBTERRANEAN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!terrainType->isSurface())
|
|
||||||
{
|
|
||||||
zone.setTerrainType(ETerrainId::DIRT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void createObstaclesCommon2(RmgMap & map, CRandomGenerator & generator)
|
|
||||||
{
|
|
||||||
if(map.levels())
|
|
||||||
{
|
|
||||||
//finally mark rock tiles as occupied, spawn no obstacles there
|
|
||||||
for(int x = 0; x < map.width(); x++)
|
|
||||||
{
|
|
||||||
for(int y = 0; y < map.height(); y++)
|
|
||||||
{
|
|
||||||
int3 tile(x, y, 1);
|
|
||||||
if(!map.getTile(tile).terType->isPassable())
|
|
||||||
{
|
|
||||||
map.setOccupied(tile, ETileType::USED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -41,12 +41,6 @@ public:
|
|||||||
|
|
||||||
rmg::Tileset collectDistantTiles(const Zone & zone, int distance);
|
rmg::Tileset collectDistantTiles(const Zone & zone, int distance);
|
||||||
|
|
||||||
void createBorder(RmgMap & gen, Zone & zone);
|
|
||||||
|
|
||||||
void paintZoneTerrain(const Zone & zone, CRandomGenerator & generator, std::shared_ptr<MapProxy> mapProxy, TerrainId terrainType);
|
|
||||||
|
|
||||||
void initTerrainType(Zone & zone, CMapGenerator & gen);
|
|
||||||
|
|
||||||
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain);
|
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain);
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,15 +18,17 @@
|
|||||||
#include "Functions.h"
|
#include "Functions.h"
|
||||||
#include "CMapGenerator.h"
|
#include "CMapGenerator.h"
|
||||||
#include "RmgMap.h"
|
#include "RmgMap.h"
|
||||||
|
#include "../VCMI_Lib.h"
|
||||||
|
#include "../TerrainHandler.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
void TerrainPainter::process()
|
void TerrainPainter::process()
|
||||||
{
|
{
|
||||||
//TODO: Make member methods
|
initTerrainType();
|
||||||
|
|
||||||
initTerrainType(zone, generator);
|
auto v = zone.getArea().getTilesVector();
|
||||||
paintZoneTerrain(zone, generator.rand, mapProxy, zone.getTerrainType());
|
mapProxy->drawTerrain(generator.rand, v, zone.getTerrainType());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainPainter::init()
|
void TerrainPainter::init()
|
||||||
@ -38,4 +40,66 @@ void TerrainPainter::init()
|
|||||||
POSTFUNCTION(ObjectManager);
|
POSTFUNCTION(ObjectManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TerrainPainter::initTerrainType()
|
||||||
|
{
|
||||||
|
if(zone.getType()==ETemplateZoneType::WATER)
|
||||||
|
{
|
||||||
|
//collect all water terrain types
|
||||||
|
std::vector<TerrainId> waterTerrains;
|
||||||
|
for(const auto & terrain : VLC->terrainTypeHandler->objects)
|
||||||
|
if(terrain->isWater())
|
||||||
|
waterTerrains.push_back(terrain->getId());
|
||||||
|
|
||||||
|
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, generator.rand));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(zone.isMatchTerrainToTown() && zone.getTownType() != ETownType::NEUTRAL)
|
||||||
|
{
|
||||||
|
auto terrainType = (*VLC->townh)[zone.getTownType()]->nativeTerrain;
|
||||||
|
|
||||||
|
if (terrainType <= ETerrainId::NONE)
|
||||||
|
{
|
||||||
|
logGlobal->warn("Town %s has invalid terrain type: %d", zone.getTownType(), terrainType);
|
||||||
|
zone.setTerrainType(ETerrainId::DIRT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zone.setTerrainType(terrainType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto terrainTypes = zone.getTerrainTypes();
|
||||||
|
if (terrainTypes.empty())
|
||||||
|
{
|
||||||
|
logGlobal->warn("No terrain types found, falling back to DIRT");
|
||||||
|
zone.setTerrainType(ETerrainId::DIRT);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zone.setTerrainType(*RandomGeneratorUtil::nextItem(terrainTypes, generator.rand));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now, replace disallowed terrains on surface and in the underground
|
||||||
|
const auto & terrainType = VLC->terrainTypeHandler->getById(zone.getTerrainType());
|
||||||
|
|
||||||
|
if(zone.isUnderground())
|
||||||
|
{
|
||||||
|
if(!terrainType->isUnderground())
|
||||||
|
{
|
||||||
|
zone.setTerrainType(ETerrainId::SUBTERRANEAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!terrainType->isSurface())
|
||||||
|
{
|
||||||
|
zone.setTerrainType(ETerrainId::DIRT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -20,6 +20,8 @@ public:
|
|||||||
|
|
||||||
void process() override;
|
void process() override;
|
||||||
void init() override;
|
void init() override;
|
||||||
|
|
||||||
|
void initTerrainType();
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -38,7 +38,8 @@ void WaterProxy::process()
|
|||||||
map.setOccupied(t, ETileType::POSSIBLE);
|
map.setOccupied(t, ETileType::POSSIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
paintZoneTerrain(zone, generator.rand, mapProxy, zone.getTerrainType());
|
auto v = zone.getArea().getTilesVector();
|
||||||
|
mapProxy->drawTerrain(generator.rand, v, zone.getTerrainType());
|
||||||
|
|
||||||
//check terrain type
|
//check terrain type
|
||||||
for([[maybe_unused]] const auto & t : zone.area().getTilesVector())
|
for([[maybe_unused]] const auto & t : zone.area().getTilesVector())
|
||||||
|
Loading…
Reference in New Issue
Block a user