1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

vcmi: add native terrain entity

Add interface which should be used on any object with native terrain

So far, it is faction, hero, creature and battle stack
This commit is contained in:
Konstantin 2023-04-05 03:50:29 +03:00
parent 1760d2295c
commit 6d9859932b
7 changed files with 31 additions and 6 deletions

View File

@ -18,7 +18,7 @@ class CreatureID;
class ResourceSet;
enum class EGameResID : int8_t;
class DLL_LINKAGE Creature : public EntityWithBonuses<CreatureID>
class DLL_LINKAGE Creature : public EntityWithNativeTerrain<CreatureID>
{
protected:
// use getNamePlural/Singular instead

View File

@ -13,6 +13,9 @@
VCMI_LIB_NAMESPACE_BEGIN
class IBonusBearer;
class FactionID;
enum class ETerrainId;
template<typename T> class Identifier;
class DLL_LINKAGE WithBonuses
{
@ -20,6 +23,13 @@ public:
virtual const IBonusBearer * getBonusBearer() const = 0;
};
class DLL_LINKAGE WithNativeTerrain
{
public:
virtual Identifier<ETerrainId> getNativeTerrain() const = 0;
virtual FactionID getFaction() const = 0;
};
class DLL_LINKAGE Entity
{
public:
@ -48,4 +58,9 @@ class DLL_LINKAGE EntityWithBonuses : public EntityT<IdType>, public WithBonuses
{
};
template <typename IdType>
class DLL_LINKAGE EntityWithNativeTerrain : public EntityWithBonuses<IdType>, public WithNativeTerrain
{
};
VCMI_LIB_NAMESPACE_END

View File

@ -15,15 +15,12 @@
VCMI_LIB_NAMESPACE_BEGIN
class FactionID;
enum class ETerrainId;
enum class EAlignment : uint8_t;
template<typename T> class Identifier;
class DLL_LINKAGE Faction : public EntityT<FactionID>
class DLL_LINKAGE Faction : public EntityT<FactionID>, public WithNativeTerrain
{
public:
virtual bool hasTown() const = 0;
virtual Identifier<ETerrainId> getNativeTerrain() const = 0;
virtual EAlignment getAlignment() const = 0;
};

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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;