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
|
|
|
|
|
|
|
|
#include "CObjectHandler.h"
|
|
|
|
#include "CArmedInstance.h"
|
|
|
|
|
|
|
|
#include "../NetPacksBase.h"
|
|
|
|
#include "../ResourceSet.h"
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-04-25 17:59:05 +03:00
|
|
|
class CRandomRewardObjectInfo;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
/// Limiters of rewards. Rewards will be granted to hero only if he satisfies requirements
|
|
|
|
/// Note: for this is only a test - it won't remove anything from hero (e.g. artifacts or creatures)
|
|
|
|
/// NOTE: in future should (partially) replace seer hut/quest guard quests checks
|
|
|
|
class DLL_LINKAGE CRewardLimiter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// how many times this reward can be granted, 0 for unlimited
|
|
|
|
si32 numOfGrants;
|
|
|
|
|
|
|
|
/// day of week, unused if 0, 1-7 will test for current day of week
|
|
|
|
si32 dayOfWeek;
|
|
|
|
|
|
|
|
/// level that hero needs to have
|
|
|
|
si32 minLevel;
|
|
|
|
|
|
|
|
/// resources player needs to have in order to trigger reward
|
|
|
|
TResources resources;
|
|
|
|
|
|
|
|
/// skills hero needs to have
|
|
|
|
std::vector<si32> primary;
|
|
|
|
std::map<SecondarySkill, si32> secondary;
|
|
|
|
|
|
|
|
/// artifacts that hero needs to have (equipped or in backpack) to trigger this
|
|
|
|
/// Note: does not checks for multiple copies of the same arts
|
|
|
|
std::vector<ArtifactID> artifacts;
|
|
|
|
|
|
|
|
/// creatures that hero needs to have
|
|
|
|
std::vector<CStackBasicDescriptor> creatures;
|
|
|
|
|
|
|
|
CRewardLimiter():
|
2014-06-29 20:13:25 +03:00
|
|
|
numOfGrants(0),
|
2014-04-06 23:14:26 +03:00
|
|
|
dayOfWeek(0),
|
2014-04-07 14:56:59 +03:00
|
|
|
minLevel(0),
|
|
|
|
primary(4, 0)
|
2014-04-06 23:14:26 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool heroAllowed(const CGHeroInstance * hero) const;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & numOfGrants;
|
|
|
|
h & dayOfWeek;
|
|
|
|
h & minLevel;
|
|
|
|
h & resources;
|
|
|
|
h & primary;
|
|
|
|
h & secondary;
|
|
|
|
h & artifacts;
|
|
|
|
h & creatures;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Reward that can be granted to a hero
|
|
|
|
/// NOTE: eventually should replace seer hut rewards and events/pandoras
|
|
|
|
class DLL_LINKAGE CRewardInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// resources that will be given to player
|
|
|
|
TResources resources;
|
|
|
|
|
|
|
|
/// received experience
|
|
|
|
ui32 gainedExp;
|
|
|
|
/// received levels (converted into XP during grant)
|
|
|
|
ui32 gainedLevels;
|
|
|
|
|
|
|
|
/// mana given to/taken from hero, fixed value
|
|
|
|
si32 manaDiff;
|
|
|
|
/// fixed value, in form of percentage from max
|
|
|
|
si32 manaPercentage;
|
|
|
|
|
|
|
|
/// movement points, only for current day. Bonuses should be used to grant MP on any other day
|
|
|
|
si32 movePoints;
|
|
|
|
/// fixed value, in form of percentage from max
|
|
|
|
si32 movePercentage;
|
|
|
|
|
|
|
|
/// list of bonuses, e.g. morale/luck
|
|
|
|
std::vector<Bonus> bonuses;
|
|
|
|
|
|
|
|
/// skills that hero may receive or lose
|
|
|
|
std::vector<si32> primary;
|
|
|
|
std::map<SecondarySkill, si32> secondary;
|
|
|
|
|
|
|
|
/// objects that hero may receive
|
|
|
|
std::vector<ArtifactID> artifacts;
|
|
|
|
std::vector<SpellID> spells;
|
|
|
|
std::vector<CStackBasicDescriptor> creatures;
|
|
|
|
|
2014-04-12 16:16:23 +03:00
|
|
|
/// list of components that will be added to reward description. First entry in list will override displayed component
|
|
|
|
std::vector<Component> extraComponents;
|
|
|
|
|
2014-04-12 16:47:48 +03:00
|
|
|
/// if set to true, object will be removed after granting reward
|
|
|
|
bool removeObject;
|
|
|
|
|
2016-01-31 09:12:01 +02:00
|
|
|
/// Generates list of components that describes reward for a specific hero
|
|
|
|
virtual void loadComponents(std::vector<Component> & comps,
|
|
|
|
const CGHeroInstance * h) const;
|
|
|
|
Component getDisplayedComponent(const CGHeroInstance * h) const;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CRewardInfo() :
|
|
|
|
gainedExp(0),
|
|
|
|
gainedLevels(0),
|
|
|
|
manaDiff(0),
|
|
|
|
manaPercentage(-1),
|
|
|
|
movePoints(0),
|
2014-04-07 14:56:59 +03:00
|
|
|
movePercentage(-1),
|
2014-04-12 16:47:48 +03:00
|
|
|
primary(4, 0),
|
|
|
|
removeObject(false)
|
2014-04-06 23:14:26 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & resources;
|
|
|
|
h & extraComponents;
|
|
|
|
h & removeObject;
|
|
|
|
h & manaPercentage;
|
|
|
|
h & movePercentage;
|
|
|
|
h & gainedExp;
|
|
|
|
h & gainedLevels;
|
|
|
|
h & manaDiff;
|
|
|
|
h & movePoints;
|
|
|
|
h & primary;
|
|
|
|
h & secondary;
|
|
|
|
h & bonuses;
|
|
|
|
h & artifacts;
|
|
|
|
h & spells;
|
|
|
|
h & creatures;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-26 21:12:37 +03:00
|
|
|
class DLL_LINKAGE CVisitInfo
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CRewardLimiter limiter;
|
|
|
|
CRewardInfo reward;
|
|
|
|
|
2014-04-07 14:56:59 +03:00
|
|
|
/// Message that will be displayed on granting of this reward, if not empty
|
2014-04-06 23:14:26 +03:00
|
|
|
MetaString message;
|
|
|
|
|
2014-05-24 01:56:51 +03:00
|
|
|
/// Chance for this reward to be selected in case of random choice
|
|
|
|
si32 selectChance;
|
|
|
|
|
2014-04-07 14:56:59 +03:00
|
|
|
/// How many times this reward has been granted since last reset
|
|
|
|
si32 numOfGrants;
|
|
|
|
|
|
|
|
CVisitInfo():
|
2016-08-18 17:53:28 +02:00
|
|
|
selectChance(0),
|
2014-04-07 14:56:59 +03:00
|
|
|
numOfGrants(0)
|
|
|
|
{}
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & limiter;
|
|
|
|
h & reward;
|
|
|
|
h & message;
|
|
|
|
h & selectChance;
|
|
|
|
h & numOfGrants;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-14 20:51:19 +02:00
|
|
|
namespace Rewardable
|
|
|
|
{
|
|
|
|
const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer", "selectRandom"};
|
|
|
|
const std::array<std::string, 5> VisitModeString{"unlimited", "once", "hero", "bonus", "player"};
|
|
|
|
}
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
/// Base class that can handle granting rewards to visiting heroes.
|
|
|
|
/// Inherits from CArmedInstance for proper trasfer of armies
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CRewardableObject : public CArmedInstance
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
/// function that must be called if hero got level-up during grantReward call
|
|
|
|
void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
|
|
|
|
|
2014-04-11 20:38:27 +03:00
|
|
|
/// grants reward to hero
|
|
|
|
void grantRewardBeforeLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
|
2016-01-30 22:51:21 +02:00
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
protected:
|
|
|
|
/// controls selection of reward granted to player
|
|
|
|
enum ESelectMode
|
|
|
|
{
|
|
|
|
SELECT_FIRST, // first reward that matches limiters
|
|
|
|
SELECT_PLAYER, // player can select from all allowed rewards
|
|
|
|
SELECT_RANDOM // reward will be selected from allowed randomly
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EVisitMode
|
|
|
|
{
|
2014-04-25 17:59:05 +03:00
|
|
|
VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text
|
2014-04-06 23:14:26 +03:00
|
|
|
VISIT_ONCE, // only once, first to visit get all the rewards
|
|
|
|
VISIT_HERO, // every hero can visit object once
|
2014-07-01 17:19:08 +03:00
|
|
|
VISIT_BONUS, // can be visited by any hero that don't have bonus from this object
|
2014-04-06 23:14:26 +03:00
|
|
|
VISIT_PLAYER // every player can visit object once
|
|
|
|
};
|
|
|
|
|
|
|
|
/// filters list of visit info and returns rewards that can be granted to current hero
|
|
|
|
virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const;
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
|
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2016-10-09 18:38:13 +02:00
|
|
|
virtual void triggerRewardReset() const;
|
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
/// Rewards that can be granted by an object
|
2014-04-06 23:14:26 +03:00
|
|
|
std::vector<CVisitInfo> info;
|
|
|
|
|
|
|
|
/// MetaString's that contain text for messages for specific situations
|
2014-04-11 20:38:27 +03:00
|
|
|
MetaString onSelect;
|
2014-04-06 23:14:26 +03:00
|
|
|
MetaString onVisited;
|
|
|
|
MetaString onEmpty;
|
|
|
|
|
|
|
|
/// how reward will be selected, uses ESelectMode enum
|
|
|
|
ui8 selectMode;
|
|
|
|
/// contols who can visit an object, uses EVisitMode enum
|
|
|
|
ui8 visitMode;
|
|
|
|
/// reward selected by player
|
|
|
|
ui16 selectedReward;
|
|
|
|
|
|
|
|
/// object visitability info will be reset each resetDuration days
|
|
|
|
ui16 resetDuration;
|
|
|
|
|
2014-04-11 20:38:27 +03:00
|
|
|
/// if true - player can refuse visiting an object (e.g. Tomb)
|
|
|
|
bool canRefuse;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
public:
|
|
|
|
void setPropertyDer(ui8 what, ui32 val) override;
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string getHoverText(PlayerColor player) const override;
|
|
|
|
std::string getHoverText(const CGHeroInstance * hero) const override;
|
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;
|
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;
|
|
|
|
|
|
|
|
///possibly resets object state
|
2016-09-09 19:30:36 +02:00
|
|
|
void newTurn(CRandomGenerator & 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
|
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
|
|
|
|
|
|
|
/// function that will be called once reward is fully granted to hero
|
|
|
|
virtual void onRewardGiven(const CGHeroInstance * hero) const;
|
2022-09-14 20:51:19 +02:00
|
|
|
|
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
CRewardableObject();
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CArmedInstance&>(*this);
|
2017-07-31 15:35:42 +02:00
|
|
|
h & info;
|
|
|
|
h & canRefuse;
|
|
|
|
h & resetDuration;
|
|
|
|
h & onSelect;
|
|
|
|
h & onVisited;
|
|
|
|
h & onEmpty;
|
|
|
|
h & visitMode;
|
|
|
|
h & selectMode;
|
|
|
|
h & selectedReward;
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
2014-04-25 17:59:05 +03:00
|
|
|
|
|
|
|
// for configuration/object setup
|
|
|
|
friend class CRandomRewardObjectInfo;
|
2014-04-06 23:14:26 +03:00
|
|
|
};
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CGPickable : public CRewardableObject //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CGPickable();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-06-05 14:19:47 +03:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-01-30 22:51:21 +02:00
|
|
|
protected:
|
|
|
|
CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const override;
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CGBonusingObject();
|
|
|
|
|
2016-01-30 22:51:21 +02:00
|
|
|
void onHeroVisit(const CGHeroInstance *h) const override;
|
|
|
|
|
2016-02-01 08:41:15 +02:00
|
|
|
bool wasVisited(const CGHeroInstance * h) const override;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-12-22 10:56:53 +02:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CGOnceVisitable : public CRewardableObject // wagon, corpse, lean to, warriors tomb
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CGOnceVisitable();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-06-05 14:19:47 +03:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CGVisitableOPH : public CRewardableObject //objects visitable only once per hero
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CGVisitableOPH();
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-06-05 14:19:47 +03:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
class DLL_LINKAGE CGVisitableOPW : public CRewardableObject //objects visitable once per week
|
2014-04-06 23:14:26 +03:00
|
|
|
{
|
2016-10-09 18:38:13 +02:00
|
|
|
protected:
|
|
|
|
void triggerRewardReset() const override;
|
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
|
|
|
|
CGVisitableOPW();
|
|
|
|
|
2016-01-30 18:11:22 +02:00
|
|
|
void setPropertyDer(ui8 what, ui32 val) override;
|
2016-09-28 19:07:48 +02:00
|
|
|
void setRandomReward(CRandomGenerator & rand);
|
2016-01-30 18:11:22 +02:00
|
|
|
|
2014-04-06 23:14:26 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2014-06-05 14:19:47 +03:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2014-04-06 23:14:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
///Special case - magic spring that has two separate visitable entrances
|
|
|
|
class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const override;
|
|
|
|
|
|
|
|
public:
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-04-06 23:14:26 +03:00
|
|
|
std::vector<int3> getVisitableOffsets() const;
|
|
|
|
int3 getVisitableOffset() const override;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CGVisitableOPW&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO:
|
|
|
|
|
|
|
|
// MAX
|
|
|
|
// class DLL_LINKAGE CGPandoraBox : public CArmedInstance
|
|
|
|
// class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
|
|
|
|
// class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
|
|
|
|
// class DLL_LINKAGE CGQuestGuard : public CGSeerHut
|
|
|
|
// 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
|
|
|
|
// class DLL_LINKAGE CGWitchHut : public CPlayersVisited
|
|
|
|
// class DLL_LINKAGE CGScholar : public CGObjectInstance
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|