mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
vcmi: remove code duplication for native terrain
This commit is contained in:
@@ -9,12 +9,33 @@
|
||||
*/
|
||||
|
||||
#include "StdInc.h"
|
||||
|
||||
#include "VCMI_Lib.h"
|
||||
#include "GameConstants.h"
|
||||
#include "HeroBonus.h"
|
||||
|
||||
#include <vcmi/Entity.h>
|
||||
#include <vcmi/Faction.h>
|
||||
#include <vcmi/FactionService.h>
|
||||
|
||||
bool INativeTerrainProvider::isItNativeTerrain(TerrainId terrain) const
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
bool INativeTerrainProvider::isNativeTerrain(TerrainId terrain) const
|
||||
{
|
||||
auto native = getNativeTerrain();
|
||||
return native == terrain || native == ETerrainId::ANY_TERRAIN;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user