1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
* 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"
#include "../Functions.h"
#include "../CMapGenerator.h"
#include "../RmgMap.h"
#include "../../VCMI_Lib.h"
#include "../../TerrainHandler.h"
#include "../../entities/faction/CFaction.h"
#include "../../entities/faction/CTownHandler.h"
#include <vstd/RNG.h>
VCMI_LIB_NAMESPACE_BEGIN
void TerrainPainter::process()
{
initTerrainType();
auto v = zone.area()->getTilesVector();
mapProxy->drawTerrain(zone.getRand(), v, zone.getTerrainType());
}
void TerrainPainter::init()
{
DEPENDENCY(TownPlacer);
DEPENDENCY_ALL(WaterAdopter);
POSTFUNCTION_ALL(WaterProxy);
POSTFUNCTION_ALL(ConnectionsPlacer);
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, zone.getRand()));
}
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())
{
//Fill with all terain types by default
{
for (const auto & terrain : VLC->terrainTypeHandler->objects)
{
if (terrain->isLand() && terrain->isPassable())
{
if ((terrain->isSurface() && !zone.isUnderground()) ||
(terrain->isUnderground() && zone.isUnderground()))
{
terrainTypes.insert(TerrainId(terrain->getId()));
}
}
}
}
}
zone.setTerrainType(*RandomGeneratorUtil::nextItem(terrainTypes, zone.getRand()));
}
//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
|