|
|
@@ -11,19 +11,11 @@
|
|
|
#include "StdInc.h"
|
|
|
#include "Functions.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 "TileInfo.h"
|
|
|
#include "RmgPath.h"
|
|
|
#include "../TerrainHandler.h"
|
|
|
#include "../CTownHandler.h"
|
|
|
-#include "../mapping/CMapEditManager.h"
|
|
|
#include "../mapping/CMap.h"
|
|
|
#include "../mapObjects/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();
|
|
|
}
|
|
|
|
|
|
-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)
|
|
|
{
|
|
|
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
|
|
|
@@ -89,85 +45,4 @@ int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId t
|
|
|
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
|