2014-04-06 23:14:26 +03:00
|
|
|
/*
|
2014-06-05 14:19:47 +03:00
|
|
|
* CRewardableObject.h, part of VCMI engine
|
2014-04-06 23:14:26 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#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"
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-04-29 22:59:02 +02:00
|
|
|
/// Base class that can handle granting rewards to visiting heroes.
|
2024-06-24 03:23:26 +02:00
|
|
|
/// Inherits from CArmedInstance for proper transfer 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-10-16 16:55:31 +02:00
|
|
|
|
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;
|
2023-09-13 09:18:46 +02:00
|
|
|
|
|
|
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
2023-09-17 18:02:24 +02:00
|
|
|
|
|
|
|
virtual void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const;
|
2024-06-24 03:23:26 +02:00
|
|
|
virtual void selectRewardWithMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, const MetaString & dialog) const;
|
2023-04-30 01:15:59 +02:00
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
virtual void grantAllRewardsWithMessage(const CGHeroInstance * contextHero, const std::vector<ui32>& rewardIndices, bool markAsVisit) const;
|
2023-10-31 19:21:50 +02:00
|
|
|
|
2023-10-16 22:55:37 +02:00
|
|
|
std::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
|
|
|
|
|
2023-10-19 13:36:11 +02:00
|
|
|
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;
|
|
|
|
|
2024-08-30 16:21:44 +02:00
|
|
|
void doHeroVisit(const CGHeroInstance *h) const;
|
|
|
|
|
|
|
|
/// Returns true if this object might have guards present, whether they were cleared or not
|
|
|
|
bool guardedPotentially() const;
|
|
|
|
/// Returns true if this object is currently guarded
|
|
|
|
bool guardedPresently() const;
|
2023-04-30 01:15:59 +02:00
|
|
|
public:
|
2024-08-30 16:21:44 +02:00
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
/// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
|
2016-02-01 08:41:15 +02:00
|
|
|
bool wasVisited(PlayerColor player) const override;
|
|
|
|
bool wasVisited(const CGHeroInstance * h) const override;
|
2023-10-16 16:55:31 +02:00
|
|
|
|
|
|
|
/// 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
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
/// gives reward to player or ask for choice in case of multiple rewards
|
|
|
|
void onHeroVisit(const CGHeroInstance *h) const override;
|
|
|
|
|
2024-08-30 16:21:44 +02:00
|
|
|
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
///possibly resets object state
|
2024-06-01 17:28:17 +02:00
|
|
|
void newTurn(vstd::RNG & rand) const override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
/// 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
|
2024-08-09 00:28:28 +02:00
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void initObj(vstd::RNG & rand) override;
|
2024-08-30 16:21:44 +02:00
|
|
|
|
2024-08-31 17:28:58 +02:00
|
|
|
bool isCoastVisitable() const override;
|
|
|
|
|
2024-08-30 16:21:44 +02:00
|
|
|
void initializeGuards();
|
2023-04-30 01:15:59 +02:00
|
|
|
|
2023-11-06 18:27:16 +02:00
|
|
|
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
CRewardableObject(IGameCallback *cb);
|
2023-04-29 22:59:02 +02:00
|
|
|
|
|
|
|
std::string getHoverText(PlayerColor player) const override;
|
|
|
|
std::string getHoverText(const CGHeroInstance * hero) const override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2023-10-19 13:36:11 +02:00
|
|
|
std::string getPopupText(PlayerColor player) const override;
|
|
|
|
std::string getPopupText(const CGHeroInstance * hero) const override;
|
2023-10-17 15:35:34 +02:00
|
|
|
|
2023-10-16 22:55:37 +02:00
|
|
|
std::vector<Component> getPopupComponents(PlayerColor player) const override;
|
|
|
|
std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
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;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO:
|
|
|
|
// 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
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|