mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
vcmi: specialize native terrain entity
Specialize native terrain entity for all object that have native terrain. Allow creatures to take global bonuses into account when checking for native terrain.
This commit is contained in:
@@ -25,6 +25,9 @@
|
||||
#include "serializer/JsonSerializeFormat.h"
|
||||
#include "NetPacksBase.h"
|
||||
|
||||
#include <vcmi/FactionService.h>
|
||||
#include <vcmi/Faction.h>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
@@ -912,6 +915,31 @@ void CStackInstance::serializeJson(JsonSerializeFormat & handler)
|
||||
}
|
||||
}
|
||||
|
||||
FactionID CStackInstance::getFaction() const
|
||||
{
|
||||
if(type)
|
||||
return type->getFaction();
|
||||
|
||||
return FactionID::NEUTRAL;
|
||||
}
|
||||
|
||||
const IBonusBearer* CStackInstance::getBonusBearer() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
TerrainId CStackInstance::getNativeTerrain() const
|
||||
{
|
||||
const std::string cachingStringNoTerrainPenalty = "type_NO_TERRAIN_PENALTY_sANY";
|
||||
static const auto selectorNoTerrainPenalty = Selector::typeSubtype(Bonus::NO_TERRAIN_PENALTY, static_cast<int>(ETerrainId::ANY_TERRAIN));
|
||||
|
||||
//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)
|
||||
? TerrainId(ETerrainId::ANY_TERRAIN)
|
||||
: VLC->factions()->getById(getFaction())->getNativeTerrain();
|
||||
}
|
||||
|
||||
CCommanderInstance::CCommanderInstance()
|
||||
{
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user