1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/lib/mapObjects/CQuest.h

262 lines
7.6 KiB
C++
Raw Normal View History

/*
* CQuest.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 "CRewardableObject.h"
2023-04-05 02:26:29 +02:00
#include "../ResourceSet.h"
2023-09-27 23:49:27 +02:00
#include "../MetaString.h"
VCMI_LIB_NAMESPACE_BEGIN
class CGCreature;
enum class EQuestMission {
NONE = 0,
LEVEL = 1,
PRIMARY_SKILL = 2,
KILL_HERO = 3,
KILL_CREATURE = 4,
ARTIFACT = 5,
ARMY = 6,
RESOURCES = 7,
HERO = 8,
PLAYER = 9,
HOTA_MULTI = 10,
// end of H3 missions
KEYMASTER = 11,
HOTA_HERO_CLASS = 12,
HOTA_REACH_DATE = 13,
};
2023-10-11 00:47:19 +02:00
class DLL_LINKAGE CQuest final
{
public:
static const std::string & missionName(EQuestMission index);
2023-10-09 19:15:34 +02:00
static const std::string & missionState(int index);
std::string questName;
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;
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
ui8 textOption;
2016-01-20 21:40:21 +02:00
ui8 completedOption;
CreatureID stackToKill;
ui8 stackDirection;
std::string heroName; //backup of hero name
HeroTypeID heroPortrait;
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;
2023-02-12 22:39:17 +02:00
CQuest(); //TODO: Remove constructor
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();
bool operator== (const CQuest & quest) const
{
return (quest.qid == qid);
}
template <typename Handler> void serialize(Handler &h)
{
h & qid;
2023-10-11 21:10:42 +02:00
h & isCompleted;
h & activeForPlayers;
h & lastDay;
h & textOption;
h & stackToKill;
h & stackDirection;
h & heroName;
h & heroPortrait;
h & firstVisitText;
h & nextVisitText;
h & completedText;
h & isCustomFirst;
h & isCustomNext;
h & isCustomComplete;
h & completedOption;
2023-10-09 19:15:34 +02:00
h & questName;
2023-10-11 00:47:19 +02:00
h & mission;
h & killTarget;
}
void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName);
};
class DLL_LINKAGE IQuestObject
{
public:
2023-02-12 22:39:17 +02:00
CQuest * quest = new CQuest();
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;
virtual bool checkQuest (const CGHeroInstance * h) const;
template <typename Handler> void serialize(Handler &h)
{
h & quest;
}
protected:
2023-02-12 22:39:17 +02:00
void afterAddToMapCommon(CMap * map) const;
};
2023-09-17 22:19:45 +02:00
class DLL_LINKAGE CGSeerHut : public CRewardableObject, public IQuestObject
{
public:
2024-01-01 16:37:48 +02:00
using CRewardableObject::CRewardableObject;
std::string seerName;
void initObj(CRandomGenerator & rand) override;
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;
void newTurn(CRandomGenerator & rand) const override;
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;
virtual void init(CRandomGenerator & rand);
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) const;
const CGCreature *getCreatureToKill(bool allowNull) const;
void getRolloverText (MetaString &text, bool onHover) const;
void afterAddToMap(CMap * map) override;
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CRewardableObject&>(*this);
h & static_cast<IQuestObject&>(*this);
h & seerName;
}
protected:
void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
void serializeJsonOptions(JsonSerializeFormat & handler) override;
};
class DLL_LINKAGE CGQuestGuard : public CGSeerHut
{
public:
2024-01-01 16:37:48 +02:00
using CGSeerHut::CGSeerHut;
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;
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGSeerHut&>(*this);
}
protected:
void serializeJsonOptions(JsonSerializeFormat & handler) override;
};
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;
std::string getObjectName() const override; //depending on color
std::string getHoverText(PlayerColor player) const override;
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGObjectInstance&>(*this);
}
};
class DLL_LINKAGE CGKeymasterTent : public CGKeys
{
public:
2024-01-01 16:37:48 +02:00
using CGKeys::CGKeys;
bool wasVisited (PlayerColor player) const override;
void onHeroVisit(const CGHeroInstance * h) const override;
template <typename Handler> void serialize(Handler &h)
{
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;
void initObj(CRandomGenerator & rand) override;
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;
void getRolloverText (MetaString &text, bool onHover) const;
bool checkQuest (const CGHeroInstance * h) const override;
void afterAddToMap(CMap * map) override;
template <typename Handler> void serialize(Handler &h)
{
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;
void onHeroVisit(const CGHeroInstance * h) const override;
bool passableFor(PlayerColor color) const override;
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGBorderGuard&>(*this); //need to serialize or object will be empty
}
};
VCMI_LIB_NAMESPACE_END