2014-06-05 19:52:14 +03:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CQuest.h, part of VCMI engine
|
2014-06-05 19:52:14 +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 "CRewardableObject.h"
|
2023-04-05 02:26:29 +02:00
|
|
|
#include "../ResourceSet.h"
|
2023-09-27 23:49:27 +02:00
|
|
|
#include "../MetaString.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-25 17:11:07 +03:00
|
|
|
class CGCreature;
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
class DLL_LINKAGE CQuest final
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
public:
|
2022-12-27 23:17:41 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
static const std::string & missionName(int index);
|
|
|
|
static const std::string & missionState(int index);
|
|
|
|
|
|
|
|
std::string questName;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
si32 qid; //unique quest id for serialization / identification
|
|
|
|
|
|
|
|
si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
|
2023-10-11 00:47:19 +02:00
|
|
|
ObjectInstanceID killTarget;
|
|
|
|
Rewardable::Limiter mission;
|
2023-10-09 15:54:14 +02:00
|
|
|
bool repeatedQuest;
|
2023-10-11 21:10:42 +02:00
|
|
|
bool isCompleted;
|
|
|
|
std::set<PlayerColor> activeForPlayers;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2016-01-20 21:40:21 +02:00
|
|
|
// following fields are used only for kill creature/hero missions, the original
|
|
|
|
// objects became inaccessible after their removal, so we need to store info
|
|
|
|
// needed for messages / hover text
|
2014-06-05 19:52:14 +03:00
|
|
|
ui8 textOption;
|
2016-01-20 21:40:21 +02:00
|
|
|
ui8 completedOption;
|
2023-11-12 19:18:00 +02:00
|
|
|
CreatureID stackToKill;
|
2014-06-05 19:52:14 +03:00
|
|
|
ui8 stackDirection;
|
|
|
|
std::string heroName; //backup of hero name
|
2023-09-28 18:43:04 +02:00
|
|
|
HeroTypeID heroPortrait;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-11-26 18:53:34 +02:00
|
|
|
MetaString firstVisitText;
|
|
|
|
MetaString nextVisitText;
|
|
|
|
MetaString completedText;
|
2023-02-12 22:39:17 +02:00
|
|
|
bool isCustomFirst;
|
|
|
|
bool isCustomNext;
|
|
|
|
bool isCustomComplete;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
CQuest(); //TODO: Remove constructor
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2021-05-23 13:28:43 +02:00
|
|
|
static bool checkMissionArmy(const CQuest * q, const CCreatureSet * army);
|
2023-10-10 01:20:55 +02:00
|
|
|
virtual bool checkQuest(const CGHeroInstance * h) const; //determines whether the quest is complete or not
|
2024-01-01 16:37:48 +02:00
|
|
|
virtual void getVisitText(IGameCallback * cb, MetaString &text, std::vector<Component> & components, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
|
|
|
|
virtual void getCompletionText(IGameCallback * cb, MetaString &text) const;
|
|
|
|
virtual void getRolloverText (IGameCallback * cb, MetaString &text, bool onHover) const; //hover or quest log entry
|
2023-10-09 02:19:58 +02:00
|
|
|
virtual void completeQuest(IGameCallback *, const CGHeroInstance * h) const;
|
2024-01-01 16:37:48 +02:00
|
|
|
virtual void addTextReplacements(IGameCallback * cb, MetaString &out, std::vector<Component> & components) const;
|
2023-10-09 19:15:34 +02:00
|
|
|
virtual void addKillTargetReplacements(MetaString &out) const;
|
|
|
|
void defineQuestName();
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
bool operator== (const CQuest & quest) const
|
|
|
|
{
|
|
|
|
return (quest.qid == qid);
|
|
|
|
}
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & qid;
|
2023-10-11 21:10:42 +02:00
|
|
|
h & isCompleted;
|
|
|
|
h & activeForPlayers;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & lastDay;
|
|
|
|
h & textOption;
|
|
|
|
h & stackToKill;
|
|
|
|
h & stackDirection;
|
|
|
|
h & heroName;
|
|
|
|
h & heroPortrait;
|
|
|
|
h & firstVisitText;
|
|
|
|
h & nextVisitText;
|
|
|
|
h & completedText;
|
|
|
|
h & isCustomFirst;
|
|
|
|
h & isCustomNext;
|
|
|
|
h & isCustomComplete;
|
2022-06-20 16:39:50 +02:00
|
|
|
h & completedOption;
|
2023-10-09 19:15:34 +02:00
|
|
|
h & questName;
|
2023-10-11 00:47:19 +02:00
|
|
|
h & mission;
|
|
|
|
h & killTarget;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName);
|
2014-06-05 19:52:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE IQuestObject
|
|
|
|
{
|
|
|
|
public:
|
2023-02-12 22:39:17 +02:00
|
|
|
CQuest * quest = new CQuest();
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
///Information about quest should remain accessible even if IQuestObject removed from map
|
|
|
|
///All CQuest objects are freed in CMap destructor
|
|
|
|
virtual ~IQuestObject() = default;
|
2024-01-01 16:37:48 +02:00
|
|
|
virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h = nullptr) const = 0;
|
2014-06-05 19:52:14 +03:00
|
|
|
virtual bool checkQuest (const CGHeroInstance * h) const;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & quest;
|
|
|
|
}
|
2017-05-28 15:23:42 +02:00
|
|
|
protected:
|
2023-02-12 22:39:17 +02:00
|
|
|
void afterAddToMapCommon(CMap * map) const;
|
2014-06-05 19:52:14 +03:00
|
|
|
};
|
|
|
|
|
2023-09-17 22:19:45 +02:00
|
|
|
class DLL_LINKAGE CGSeerHut : public CRewardableObject, public IQuestObject
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CRewardableObject::CRewardableObject;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
std::string seerName;
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string getHoverText(PlayerColor player) const override;
|
2023-11-02 15:50:24 +02:00
|
|
|
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;
|
2016-09-09 19:30:36 +02:00
|
|
|
void newTurn(CRandomGenerator & rand) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
2024-01-01 16:37:48 +02:00
|
|
|
void getVisitText (MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
virtual void init(CRandomGenerator & rand);
|
2014-06-05 19:52:14 +03:00
|
|
|
int checkDirection() const; //calculates the region of map where monster is placed
|
|
|
|
void setObjToKill(); //remember creatures / heroes to kill after they are initialized
|
|
|
|
const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
|
|
|
|
const CGCreature *getCreatureToKill(bool allowNull = false) const;
|
|
|
|
void getRolloverText (MetaString &text, bool onHover) const;
|
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void afterAddToMap(CMap * map) override;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-09-15 15:29:41 +02:00
|
|
|
h & static_cast<CRewardableObject&>(*this);
|
2017-07-31 15:35:42 +02:00
|
|
|
h & static_cast<IQuestObject&>(*this);
|
|
|
|
h & seerName;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
protected:
|
2023-11-06 18:27:16 +02:00
|
|
|
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
2014-06-05 19:52:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGQuestGuard : public CGSeerHut
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGSeerHut::CGSeerHut;
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void init(CRandomGenerator & rand) override;
|
2023-10-11 23:15:24 +02:00
|
|
|
|
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
|
|
|
bool passableFor(PlayerColor color) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGSeerHut&>(*this);
|
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
protected:
|
|
|
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
2014-06-05 19:52:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGObjectInstance::CGObjectInstance;
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
bool wasMyColorVisited(const PlayerColor & player) const;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string getObjectName() const override; //depending on color
|
|
|
|
std::string getHoverText(PlayerColor player) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGKeymasterTent : public CGKeys
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGKeys::CGKeys;
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
bool wasVisited (PlayerColor player) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGKeys::CGKeys;
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void initObj(CRandomGenerator & rand) override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
|
|
|
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
void getVisitText (MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void getRolloverText (MetaString &text, bool onHover) const;
|
2015-10-12 15:47:10 +02:00
|
|
|
bool checkQuest (const CGHeroInstance * h) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void afterAddToMap(CMap * map) override;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<IQuestObject&>(*this);
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBorderGate : public CGBorderGuard
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGBorderGuard::CGBorderGuard;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
|
|
|
|
2014-06-24 02:26:36 +03:00
|
|
|
bool passableFor(PlayerColor color) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGBorderGuard&>(*this); //need to serialize or object will be empty
|
|
|
|
}
|
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|