2022-08-09 07:54:32 +02:00
|
|
|
/*
|
|
|
|
* TerrainPainter.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 "TerrainPainter.h"
|
|
|
|
#include "TownPlacer.h"
|
|
|
|
#include "WaterAdopter.h"
|
|
|
|
#include "WaterProxy.h"
|
|
|
|
#include "ConnectionsPlacer.h"
|
|
|
|
#include "ObjectManager.h"
|
2023-05-20 11:45:08 +02:00
|
|
|
#include "../Functions.h"
|
|
|
|
#include "../CMapGenerator.h"
|
|
|
|
#include "../RmgMap.h"
|
|
|
|
#include "../../VCMI_Lib.h"
|
|
|
|
#include "../../TerrainHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../../entities/faction/CFaction.h"
|
|
|
|
#include "../../entities/faction/CTownHandler.h"
|
2022-08-09 07:54:32 +02:00
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
void TerrainPainter::process()
|
|
|
|
{
|
2023-05-20 07:55:28 +02:00
|
|
|
initTerrainType();
|
2023-05-19 20:30:15 +02:00
|
|
|
|
2024-03-27 07:16:48 +02:00
|
|
|
auto v = zone.area()->getTilesVector();
|
2023-05-20 11:46:32 +02:00
|
|
|
mapProxy->drawTerrain(zone.getRand(), v, zone.getTerrainType());
|
2022-08-09 07:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainPainter::init()
|
|
|
|
{
|
|
|
|
DEPENDENCY(TownPlacer);
|
|
|
|
DEPENDENCY_ALL(WaterAdopter);
|
|
|
|
POSTFUNCTION_ALL(WaterProxy);
|
|
|
|
POSTFUNCTION_ALL(ConnectionsPlacer);
|
|
|
|
POSTFUNCTION(ObjectManager);
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
2023-05-20 07:55:28 +02:00
|
|
|
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());
|
|
|
|
|
2023-05-20 11:46:32 +02:00
|
|
|
zone.setTerrainType(*RandomGeneratorUtil::nextItem(waterTerrains, zone.getRand()));
|
2023-05-20 07:55:28 +02:00
|
|
|
}
|
|
|
|
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())
|
|
|
|
{
|
2023-07-02 08:13:06 +02:00
|
|
|
//Fill with all terain types by default
|
|
|
|
{
|
2024-05-17 00:05:51 +02:00
|
|
|
for (const auto & terrain : VLC->terrainTypeHandler->objects)
|
2023-07-02 08:13:06 +02:00
|
|
|
{
|
|
|
|
if (terrain->isLand() && terrain->isPassable())
|
|
|
|
{
|
2023-07-02 09:28:51 +02:00
|
|
|
if ((terrain->isSurface() && !zone.isUnderground()) ||
|
|
|
|
(terrain->isUnderground() && zone.isUnderground()))
|
2023-07-02 08:13:06 +02:00
|
|
|
{
|
2023-07-05 20:53:00 +02:00
|
|
|
terrainTypes.insert(TerrainId(terrain->getId()));
|
2023-07-02 08:13:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-20 07:55:28 +02:00
|
|
|
}
|
2023-07-02 08:13:06 +02:00
|
|
|
zone.setTerrainType(*RandomGeneratorUtil::nextItem(terrainTypes, zone.getRand()));
|
2023-05-20 07:55:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|