1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/lib/mapObjects/CRewardableObject.h

106 lines
4.1 KiB
C++
Raw Normal View History

/*
* CRewardableObject.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
2023-09-13 01:40:07 +02:00
#include "CArmedInstance.h"
2023-04-30 15:13:07 +02:00
#include "../rewardable/Interface.h"
VCMI_LIB_NAMESPACE_BEGIN
2023-04-29 22:59:02 +02:00
/// Base class that can handle granting rewards to visiting heroes.
/// Inherits from CArmedInstance for proper trasfer of armies
2023-04-30 01:15:59 +02:00
class DLL_LINKAGE CRewardableObject : public CArmedInstance, public Rewardable::Interface
2023-04-29 22:59:02 +02:00
{
protected:
2023-04-30 01:15:59 +02:00
bool onceVisitableObjectCleared = false;
2023-04-29 23:43:02 +02:00
/// reward selected by player, no serialize
ui16 selectedReward = 0;
2023-04-30 01:15:59 +02:00
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
void markAsVisited(const CGHeroInstance * hero) const;
2023-04-29 22:59:02 +02:00
/// return true if this object was "cleared" before and no longer has rewards applicable to selected hero
/// unlike wasVisited, this method uses information not available to player owner, for example, if object was cleared by another player before
bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
void serializeJsonOptions(JsonSerializeFormat & handler) override;
2023-09-17 18:02:24 +02:00
virtual void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const;
2023-09-19 17:11:03 +02:00
virtual void selectRewardWthMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, const MetaString & dialog) const;
2023-04-30 01:15:59 +02:00
std::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;
std::string getDescriptionMessage(PlayerColor player, const CGHeroInstance * hero) const;
std::vector<Component> getPopupComponentsImpl(PlayerColor player, const CGHeroInstance * hero) const;
2023-04-30 01:15:59 +02:00
public:
/// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
bool wasVisited(PlayerColor player) const override;
bool wasVisited(const CGHeroInstance * h) const override;
/// Returns true if object was scouted by player and he is aware of its internal state
bool wasScouted(PlayerColor player) const;
2023-04-29 22:59:02 +02:00
/// gives reward to player or ask for choice in case of multiple rewards
void onHeroVisit(const CGHeroInstance *h) const override;
///possibly resets object state
void newTurn(CRandomGenerator & rand) const override;
/// gives second part of reward after hero level-ups for proper granting of spells/mana
void heroLevelUpDone(const CGHeroInstance *hero) const override;
/// applies player selection of reward
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
2022-09-14 20:51:19 +02:00
void initObj(CRandomGenerator & rand) override;
2023-04-30 01:15:59 +02:00
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
CRewardableObject();
2023-04-29 22:59:02 +02:00
std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
std::string getPopupText(PlayerColor player) const override;
std::string getPopupText(const CGHeroInstance * hero) const override;
std::vector<Component> getPopupComponents(PlayerColor player) const override;
std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this);
2023-04-30 01:15:59 +02:00
h & static_cast<Rewardable::Interface&>(*this);
2023-04-29 23:43:02 +02:00
h & onceVisitableObjectCleared;
}
};
//TODO:
// MAX
// class DLL_LINKAGE CBank : public CArmedInstance
// class DLL_LINKAGE CGPyramid : public CBank
// EXTRA
// class DLL_LINKAGE COPWBonus : public CGTownBuilding
// class DLL_LINKAGE CTownBonus : public CGTownBuilding
// class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
// class DLL_LINKAGE CGKeymasterTent : public CGKeys
// class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
// POSSIBLE
// class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
VCMI_LIB_NAMESPACE_END