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; class ResourceSet;
enum class EGameResID : int8_t; enum class EGameResID : int8_t;
class DLL_LINKAGE Creature : public EntityWithBonuses<CreatureID> class DLL_LINKAGE Creature : public EntityWithNativeTerrain<CreatureID>
{ {
protected: protected:
// use getNamePlural/Singular instead // use getNamePlural/Singular instead

View File

@ -13,6 +13,9 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class IBonusBearer; class IBonusBearer;
class FactionID;
enum class ETerrainId;
template<typename T> class Identifier;
class DLL_LINKAGE WithBonuses class DLL_LINKAGE WithBonuses
{ {
@ -20,6 +23,13 @@ public:
virtual const IBonusBearer * getBonusBearer() const = 0; 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 class DLL_LINKAGE Entity
{ {
public: 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 VCMI_LIB_NAMESPACE_END

View File

@ -15,15 +15,12 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class FactionID; class FactionID;
enum class ETerrainId;
enum class EAlignment : uint8_t; 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: public:
virtual bool hasTown() const = 0; virtual bool hasTown() const = 0;
virtual Identifier<ETerrainId> getNativeTerrain() const = 0;
virtual EAlignment getAlignment() const = 0; virtual EAlignment getAlignment() const = 0;
}; };

View File

@ -114,6 +114,11 @@ int32_t CCreature::getFactionIndex() const
return faction; return faction;
} }
FactionID CCreature::getFaction() const
{
return FactionID(faction);
}
int32_t CCreature::getBaseAttack() const int32_t CCreature::getBaseAttack() const
{ {
static const auto SELECTOR = Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK).And(Selector::sourceTypeSel(Bonus::CREATURE_ABILITY)); 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; std::string getNameSingularTextID() const override;
bool isItNativeTerrain(TerrainId terrain) const; bool isItNativeTerrain(TerrainId terrain) const;
FactionID getFaction() const override;
/** /**
Returns creature native terrain considering some terrain bonuses. Returns creature native terrain considering some terrain bonuses.
*/ */
TerrainId getNativeTerrain() const; TerrainId getNativeTerrain() const override;
int32_t getIndex() const override; int32_t getIndex() const override;
int32_t getIconIndex() const override; int32_t getIconIndex() const override;
std::string getJsonKey() const override; std::string getJsonKey() const override;

View File

@ -157,6 +157,11 @@ FactionID CFaction::getId() const
return FactionID(index); return FactionID(index);
} }
FactionID CFaction::getFaction() const
{
return FactionID(index);
}
bool CFaction::hasTown() const bool CFaction::hasTown() const
{ {
return town != nullptr; return town != nullptr;

View File

@ -192,6 +192,8 @@ class DLL_LINKAGE CFaction : public Faction
TFaction index = 0; TFaction index = 0;
FactionID getFaction() const override; //This function should not be used
public: public:
TerrainId nativeTerrain; TerrainId nativeTerrain;
EAlignment alignment = EAlignment::NEUTRAL; EAlignment alignment = EAlignment::NEUTRAL;