1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Lighthouse / flaggable objects now has dedicated bonus system node

this alows to remove multiple hacks from lighthouse logic
This commit is contained in:
Ivan Savenko
2025-05-13 17:07:58 +03:00
parent 716da918f8
commit b37a3dc63c
7 changed files with 58 additions and 63 deletions

View File

@@ -11,32 +11,49 @@
#include "CGObjectInstance.h"
#include "IOwnableObject.h"
#include "../bonuses/CBonusSystemNode.h"
VCMI_LIB_NAMESPACE_BEGIN
struct Bonus;
class FlaggableInstanceConstructor;
class DLL_LINKAGE FlaggableMapObject : public CGObjectInstance, public IOwnableObject
class DLL_LINKAGE FlaggableMapObject final : public CGObjectInstance, public IOwnableObject, public CBonusSystemNode
{
std::shared_ptr<FlaggableInstanceConstructor> getFlaggableHandler() const;
void giveBonusTo(IGameEventCallback & gameEvents, const PlayerColor & player, bool onInit = false) const;
void takeBonusFrom(IGameEventCallback & gameEvents, const PlayerColor & player) const;
void initBonuses();
public:
using CGObjectInstance::CGObjectInstance;
void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
void markAsDeleted() const;
void initObj(vstd::RNG & rand) override;
const IOwnableObject * asOwnable() const final;
ResourceSet dailyIncome() const override;
std::vector<CreatureID> providedCreatures() const override;
protected:
void attachToBonusSystem(CGameState & gs) override;
void detachFromBonusSystem(CGameState & gs) override;
void restoreBonusSystem(CGameState & gs) override;
PlayerColor getOwner() const override
{
return CGObjectInstance::getOwner();
}
void serializeJsonOptions(JsonSerializeFormat & handler) override;
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGObjectInstance&>(*this);
if (h.version >= Handler::Version::FLAGGABLE_BONUS_SYSTEM_NODE)
h & static_cast<CBonusSystemNode&>(*this);
else
initBonuses();
}
};
VCMI_LIB_NAMESPACE_END