2023-04-05 17:56:28 +02:00
|
|
|
/*
|
|
|
|
* BasicTypes.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"
|
2023-04-09 18:30:29 +02:00
|
|
|
|
|
|
|
#include "VCMI_Lib.h"
|
2023-04-05 17:56:28 +02:00
|
|
|
#include "GameConstants.h"
|
2023-04-09 18:30:29 +02:00
|
|
|
#include "HeroBonus.h"
|
2023-04-05 17:56:28 +02:00
|
|
|
|
|
|
|
#include <vcmi/Entity.h>
|
2023-04-09 18:30:29 +02:00
|
|
|
#include <vcmi/Faction.h>
|
|
|
|
#include <vcmi/FactionService.h>
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
2023-04-05 17:56:28 +02:00
|
|
|
|
2023-04-09 18:30:29 +02:00
|
|
|
bool INativeTerrainProvider::isNativeTerrain(TerrainId terrain) const
|
2023-04-05 17:56:28 +02:00
|
|
|
{
|
|
|
|
auto native = getNativeTerrain();
|
|
|
|
return native == terrain || native == ETerrainId::ANY_TERRAIN;
|
2023-04-09 18:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TerrainId IConstBonusNativeTerrainProvider::getNativeTerrain() const
|
|
|
|
{
|
|
|
|
constexpr auto any = TerrainId(ETerrainId::ANY_TERRAIN);
|
|
|
|
const std::string cachingStringNoTerrainPenalty = "type_NO_TERRAIN_PENALTY_sANY";
|
|
|
|
static const auto selectorNoTerrainPenalty = Selector::typeSubtype(Bonus::NO_TERRAIN_PENALTY, any);
|
|
|
|
|
|
|
|
//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
|
|
|
|
//and in the CGHeroInstance::getNativeTerrain() to setup movement bonuses or/and penalties.
|
|
|
|
return getBonusBearer()->hasBonus(selectorNoTerrainPenalty, cachingStringNoTerrainPenalty)
|
|
|
|
? any : VLC->factions()->getById(getFaction())->getNativeTerrain();
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|