1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00
Files
vcmi/include/vcmi/Entity.h
Ivan Savenko 3dd4fa2528 Reduce usage of pointers to VLC entities
Final goal (of multiple PR's) is to remove all remaining pointers from
serializeable game state, and replace them with either identifiers or
with shared/unique pointers.

CGTownInstance::town and CGHeroInstance::type members have been removed.
Now this data is computed dynamically using subID member.

VLC entity of a town can now be accessed via following methods:
- getFactionID() returns ID of a faction
- getFaction() returns pointer to a faction
- getTown() returns pointer to a town

VLC entity of a hero can now be accessed via following methods:
- getHeroTypeID() returns ID of a hero
- getHeroClassID() returns ID of a hero class
- getHeroType() returns pointer to a hero
- getHeroClass() returns pointer to a hero class
2024-10-10 12:28:08 +00:00

65 lines
1.5 KiB
C++

/*
* Entity.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
VCMI_LIB_NAMESPACE_BEGIN
class IBonusBearer;
class FactionID;
class TerrainId;
class DLL_LINKAGE IConstBonusProvider
{
public:
virtual const IBonusBearer * getBonusBearer() const = 0;
};
class DLL_LINKAGE INativeTerrainProvider
{
public:
virtual TerrainId getNativeTerrain() const = 0;
virtual FactionID getFactionID() const = 0;
virtual bool isNativeTerrain(TerrainId terrain) const;
};
class DLL_LINKAGE Entity : boost::noncopyable
{
public:
using IconRegistar = std::function<void(int32_t index, int32_t group, const std::string & listName, const std::string & imageName)>;
virtual ~Entity() = default;
virtual int32_t getIndex() const = 0;
virtual int32_t getIconIndex() const = 0;
virtual std::string getJsonKey() const = 0;
virtual std::string getModScope() const = 0;
virtual std::string getNameTranslated() const = 0;
virtual std::string getNameTextID() const = 0;
virtual void registerIcons(const IconRegistar & cb) const = 0;
};
template <typename IdType>
class DLL_LINKAGE EntityT : public Entity
{
public:
using IdentifierType = IdType;
virtual IdType getId() const = 0;
};
template <typename IdType>
class DLL_LINKAGE EntityWithBonuses : public EntityT<IdType>, public IConstBonusProvider
{
};
VCMI_LIB_NAMESPACE_END