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
|
|
|
|
|
|
|
|
#include "CObjectHandler.h"
|
|
|
|
#include "CArmedInstance.h"
|
|
|
|
|
|
|
|
#include "../CCreatureSet.h"
|
|
|
|
#include "../NetPacksBase.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2014-06-25 17:11:07 +03:00
|
|
|
class CGCreature;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
class DLL_LINKAGE CQuest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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, MISSION_KEYMASTER = 10};
|
|
|
|
enum Eprogress {NOT_ACTIVE, IN_PROGRESS, COMPLETE};
|
|
|
|
|
|
|
|
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;
|
|
|
|
std::vector<ui16> m5arts; //artifacts id
|
|
|
|
std::vector<CStackBasicDescriptor> m6creatures; //pair[cre id, cre count], CreatureSet info irrelevant
|
|
|
|
std::vector<ui32> m7resources; //TODO: use resourceset?
|
|
|
|
|
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;
|
|
|
|
bool isCustomFirst, isCustomNext, isCustomComplete;
|
|
|
|
|
2016-08-22 19:41:37 +02:00
|
|
|
CQuest();
|
2014-06-05 19:52:14 +03:00
|
|
|
virtual ~CQuest(){};
|
|
|
|
|
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;
|
|
|
|
virtual void getCompletionText (MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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:
|
|
|
|
CQuest * quest;
|
|
|
|
|
2016-08-30 08:46:01 +02:00
|
|
|
IQuestObject();
|
|
|
|
virtual ~IQuestObject();
|
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:
|
|
|
|
void afterAddToMapCommon(CMap * map);
|
2014-06-05 19:52:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum ERewardType {NOTHING, EXPERIENCE, MANA_POINTS, MORALE_BONUS, LUCK_BONUS, RESOURCES, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE};
|
|
|
|
ERewardType rewardType;
|
|
|
|
si32 rID; //reward ID
|
|
|
|
si32 rVal; //reward value
|
|
|
|
std::string seerName;
|
|
|
|
|
2015-03-01 10:07:43 +02:00
|
|
|
CGSeerHut();
|
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 getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
|
|
|
|
void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
|
|
|
|
virtual void completeQuest (const CGHeroInstance * h) const;
|
|
|
|
|
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)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & static_cast<CArmedInstance&>(*this);
|
|
|
|
h & static_cast<IQuestObject&>(*this);
|
|
|
|
h & rewardType;
|
|
|
|
h & rID;
|
|
|
|
h & rVal;
|
|
|
|
h & seerName;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
protected:
|
2016-01-29 19:21:19 +02:00
|
|
|
static const 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:
|
|
|
|
CGQuestGuard() : CGSeerHut(){};
|
2016-09-09 19:30:36 +02:00
|
|
|
void init(CRandomGenerator & rand) override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void completeQuest (const CGHeroInstance * h) const override;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
bool wasMyColorVisited (PlayerColor player) const;
|
|
|
|
|
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:
|
|
|
|
CGBorderGuard() : IQuestObject(){};
|
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);
|
|
|
|
h & blockVisit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBorderGate : public CGBorderGuard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGBorderGate() : CGBorderGuard(){};
|
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|