2022-08-09 07:54:32 +02:00
|
|
|
/*
|
|
|
|
* Functions.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 "Functions.h"
|
|
|
|
#include "CMapGenerator.h"
|
|
|
|
#include "RmgMap.h"
|
|
|
|
#include "TileInfo.h"
|
|
|
|
#include "RmgPath.h"
|
2023-01-09 01:17:37 +02:00
|
|
|
#include "../TerrainHandler.h"
|
2022-08-09 07:54:32 +02:00
|
|
|
#include "../CTownHandler.h"
|
|
|
|
#include "../mapping/CMap.h"
|
|
|
|
#include "../mapObjects/CommonConstructors.h"
|
|
|
|
#include "../mapObjects/MapObjects.h" //needed to resolve templates for CommonConstructors.h
|
|
|
|
#include "../VCMI_Lib.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
rmg::Tileset collectDistantTiles(const Zone& zone, int distance)
|
|
|
|
{
|
2022-12-08 23:20:42 +02:00
|
|
|
uint32_t distanceSq = distance * distance;
|
2022-08-09 07:54:32 +02:00
|
|
|
auto subarea = zone.getArea().getSubarea([&zone, distanceSq](const int3 & t)
|
|
|
|
{
|
|
|
|
return t.dist2dSQ(zone.getPos()) > distanceSq;
|
|
|
|
});
|
|
|
|
return subarea.getTiles();
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
int chooseRandomAppearance(CRandomGenerator & generator, si32 ObjID, TerrainId terrain)
|
2022-08-09 07:54:32 +02:00
|
|
|
{
|
|
|
|
auto factories = VLC->objtypeh->knownSubObjects(ObjID);
|
|
|
|
vstd::erase_if(factories, [ObjID, &terrain](si32 f)
|
|
|
|
{
|
2023-04-29 11:46:03 +02:00
|
|
|
//TODO: Use templates with lowest number of terrains (most specific)
|
2022-08-09 07:54:32 +02:00
|
|
|
return VLC->objtypeh->getHandlerFor(ObjID, f)->getTemplates(terrain).empty();
|
|
|
|
});
|
|
|
|
|
|
|
|
return *RandomGeneratorUtil::nextItem(factories, generator);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|