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"
|
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;
|
|
|
|
|
2022-10-01 08:24:58 +02:00
|
|
|
class DLL_LINKAGE CQuest final
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2022-11-30 17:57:39 +02:00
|
|
|
mutable std::unordered_map<ArtifactID, unsigned, ArtifactID::hash> artifactsRequirements; // artifact ID -> required count
|
2022-10-01 08:28:32 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
public:
|
2022-12-27 23:17:41 +02:00
|
|
|
enum Emission {
|
|
|
|
MISSION_NONE = 0,
|
|
|
|
MISSION_LEVEL = 1,
|
|
|
|
MISSION_PRIMARY_STAT = 2,
|
|
|
|
MISSION_KILL_HERO = 3,
|
|
|
|
MISSION_KILL_CREATURE = 4,
|
|
|
|
MISSION_ART = 5,
|
|
|
|
MISSION_ARMY = 6,
|
|
|
|
MISSION_RESOURCES = 7,
|
|
|
|
MISSION_HERO = 8,
|
|
|
|
MISSION_PLAYER = 9,
|
2023-04-05 00:08:24 +02:00
|
|
|
MISSION_HOTA_MULTI = 10,
|
|
|
|
// end of H3 missions
|
|
|
|
MISSION_KEYMASTER = 100,
|
|
|
|
MISSION_HOTA_HERO_CLASS = 101,
|
|
|
|
MISSION_HOTA_REACH_DATE = 102
|
2022-12-27 23:17:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Eprogress {
|
|
|
|
NOT_ACTIVE,
|
|
|
|
IN_PROGRESS,
|
|
|
|
COMPLETE
|
|
|
|
};
|
|
|
|
|
|
|
|
static const std::string & missionName(Emission mission);
|
|
|
|
static const std::string & missionState(int index);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
si32 qid; //unique quest id for serialization / identification
|
|
|
|
|
|
|
|
Emission missionType;
|
|
|
|
Eprogress progress;
|
|
|
|
si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
|
|
|
|
|
|
|
|
ui32 m13489val;
|
|
|
|
std::vector<ui32> m2stats;
|
2022-11-29 00:11:46 +02:00
|
|
|
std::vector<ArtifactID> m5arts; // artifact IDs. Add IDs through addArtifactID(), not directly to the field.
|
2014-06-05 19:52:14 +03:00
|
|
|
std::vector<CStackBasicDescriptor> m6creatures; //pair[cre id, cre count], CreatureSet info irrelevant
|
2023-04-05 02:26:29 +02:00
|
|
|
TResources m7resources;
|
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;
|
2014-06-05 19:52:14 +03:00
|
|
|
CStackBasicDescriptor stackToKill;
|
|
|
|
ui8 stackDirection;
|
|
|
|
std::string heroName; //backup of hero name
|
|
|
|
si32 heroPortrait;
|
|
|
|
|
|
|
|
std::string firstVisitText, nextVisitText, 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);
|
2014-06-05 19:52:14 +03:00
|
|
|
virtual bool checkQuest (const CGHeroInstance * h) const; //determines whether the quest is complete or not
|
|
|
|
virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
|
2023-09-13 01:40:07 +02:00
|
|
|
virtual void getCompletionText(MetaString &text) const;
|
2014-06-05 19:52:14 +03:00
|
|
|
virtual void getRolloverText (MetaString &text, bool onHover) const; //hover or quest log entry
|
|
|
|
virtual void completeQuest (const CGHeroInstance * h) const {};
|
|
|
|
virtual void addReplacements(MetaString &out, const std::string &base) const;
|
2023-02-12 22:39:17 +02:00
|
|
|
void addArtifactID(const ArtifactID & id);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
bool operator== (const CQuest & quest) const
|
|
|
|
{
|
|
|
|
return (quest.qid == qid);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & qid;
|
|
|
|
h & missionType;
|
|
|
|
h & progress;
|
|
|
|
h & lastDay;
|
|
|
|
h & m13489val;
|
|
|
|
h & m2stats;
|
|
|
|
h & m5arts;
|
|
|
|
h & m6creatures;
|
|
|
|
h & m7resources;
|
|
|
|
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;
|
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;
|
2014-06-05 19:52:14 +03:00
|
|
|
virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
|
|
|
|
virtual bool checkQuest (const CGHeroInstance * h) const;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
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;
|
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;
|
|
|
|
|
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;
|
|
|
|
void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
|
2023-09-13 01:40:07 +02:00
|
|
|
virtual void completeQuest() const;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void afterAddToMap(CMap * map) override;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
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-02-12 22:39:17 +02:00
|
|
|
static constexpr int OBJPROP_VISITED = 10;
|
2016-01-20 09:44:13 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void setPropertyDer(ui8 what, ui32 val) 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:
|
2016-09-09 19:30:36 +02:00
|
|
|
void init(CRandomGenerator & rand) override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned]
|
|
|
|
//SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
|
|
|
|
|
2016-08-25 14:52:20 +02:00
|
|
|
static void reset();
|
|
|
|
|
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
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
void setPropertyDer(ui8 what, ui32 val) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGKeymasterTent : public CGKeys
|
|
|
|
{
|
|
|
|
public:
|
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;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
|
|
|
|
{
|
|
|
|
public:
|
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;
|
|
|
|
|
2015-10-12 15:47:10 +02:00
|
|
|
void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, 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;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<IQuestObject&>(*this);
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBorderGate : public CGBorderGuard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
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
|