diff --git a/include/vcmi/Creature.h b/include/vcmi/Creature.h index e6e72e188..b6172fcf8 100644 --- a/include/vcmi/Creature.h +++ b/include/vcmi/Creature.h @@ -18,7 +18,7 @@ class CreatureID; class ResourceSet; enum class EGameResID : int8_t; -class DLL_LINKAGE Creature : public EntityWithBonuses +class DLL_LINKAGE Creature : public EntityWithNativeTerrain { protected: // use getNamePlural/Singular instead diff --git a/include/vcmi/Entity.h b/include/vcmi/Entity.h index b34d692f3..edf18148e 100644 --- a/include/vcmi/Entity.h +++ b/include/vcmi/Entity.h @@ -13,6 +13,9 @@ VCMI_LIB_NAMESPACE_BEGIN class IBonusBearer; +class FactionID; +enum class ETerrainId; +template class Identifier; class DLL_LINKAGE WithBonuses { @@ -20,6 +23,13 @@ public: virtual const IBonusBearer * getBonusBearer() const = 0; }; +class DLL_LINKAGE WithNativeTerrain +{ +public: + virtual Identifier getNativeTerrain() const = 0; + virtual FactionID getFaction() const = 0; +}; + class DLL_LINKAGE Entity { public: @@ -48,4 +58,9 @@ class DLL_LINKAGE EntityWithBonuses : public EntityT, public WithBonuses { }; +template +class DLL_LINKAGE EntityWithNativeTerrain : public EntityWithBonuses, public WithNativeTerrain +{ +}; + VCMI_LIB_NAMESPACE_END diff --git a/include/vcmi/Faction.h b/include/vcmi/Faction.h index 2b21cf0ec..14be851f2 100644 --- a/include/vcmi/Faction.h +++ b/include/vcmi/Faction.h @@ -15,15 +15,12 @@ VCMI_LIB_NAMESPACE_BEGIN class FactionID; -enum class ETerrainId; enum class EAlignment : uint8_t; -template class Identifier; -class DLL_LINKAGE Faction : public EntityT +class DLL_LINKAGE Faction : public EntityT, public WithNativeTerrain { public: virtual bool hasTown() const = 0; - virtual Identifier getNativeTerrain() const = 0; virtual EAlignment getAlignment() const = 0; }; diff --git a/lib/CCreatureHandler.cpp b/lib/CCreatureHandler.cpp index 6e22a1a46..a70e19f73 100644 --- a/lib/CCreatureHandler.cpp +++ b/lib/CCreatureHandler.cpp @@ -114,6 +114,11 @@ int32_t CCreature::getFactionIndex() const return faction; } +FactionID CCreature::getFaction() const +{ + return FactionID(faction); +} + int32_t CCreature::getBaseAttack() const { static const auto SELECTOR = Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK).And(Selector::sourceTypeSel(Bonus::CREATURE_ABILITY)); diff --git a/lib/CCreatureHandler.h b/lib/CCreatureHandler.h index 535978c72..65abe571d 100644 --- a/lib/CCreatureHandler.h +++ b/lib/CCreatureHandler.h @@ -163,10 +163,11 @@ public: std::string getNameSingularTextID() const override; bool isItNativeTerrain(TerrainId terrain) const; + FactionID getFaction() const override; /** Returns creature native terrain considering some terrain bonuses. */ - TerrainId getNativeTerrain() const; + TerrainId getNativeTerrain() const override; int32_t getIndex() const override; int32_t getIconIndex() const override; std::string getJsonKey() const override; diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 11fe60c45..903b89608 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -157,6 +157,11 @@ FactionID CFaction::getId() const return FactionID(index); } +FactionID CFaction::getFaction() const +{ + return FactionID(index); +} + bool CFaction::hasTown() const { return town != nullptr; diff --git a/lib/CTownHandler.h b/lib/CTownHandler.h index 46f65d3a8..9ac2714f1 100644 --- a/lib/CTownHandler.h +++ b/lib/CTownHandler.h @@ -192,6 +192,8 @@ class DLL_LINKAGE CFaction : public Faction TFaction index = 0; + FactionID getFaction() const override; //This function should not be used + public: TerrainId nativeTerrain; EAlignment alignment = EAlignment::NEUTRAL;