CQuest.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * CQuest.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CObjectHandler.h"
  12. #include "CArmedInstance.h"
  13. #include "../CCreatureSet.h"
  14. #include "../NetPacksBase.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CGCreature;
  17. class DLL_LINKAGE CQuest
  18. {
  19. public:
  20. enum Emission {MISSION_NONE = 0, MISSION_LEVEL = 1, MISSION_PRIMARY_STAT = 2, MISSION_KILL_HERO = 3, MISSION_KILL_CREATURE = 4,
  21. MISSION_ART = 5, MISSION_ARMY = 6, MISSION_RESOURCES = 7, MISSION_HERO = 8, MISSION_PLAYER = 9, MISSION_KEYMASTER = 10};
  22. enum Eprogress {NOT_ACTIVE, IN_PROGRESS, COMPLETE};
  23. si32 qid; //unique quest id for serialization / identification
  24. Emission missionType;
  25. Eprogress progress;
  26. si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
  27. ui32 m13489val;
  28. std::vector<ui32> m2stats;
  29. std::vector<ui16> m5arts; //artifacts id
  30. std::vector<CStackBasicDescriptor> m6creatures; //pair[cre id, cre count], CreatureSet info irrelevant
  31. std::vector<ui32> m7resources; //TODO: use resourceset?
  32. // following fields are used only for kill creature/hero missions, the original
  33. // objects became inaccessible after their removal, so we need to store info
  34. // needed for messages / hover text
  35. ui8 textOption;
  36. ui8 completedOption;
  37. CStackBasicDescriptor stackToKill;
  38. ui8 stackDirection;
  39. std::string heroName; //backup of hero name
  40. si32 heroPortrait;
  41. std::string firstVisitText, nextVisitText, completedText;
  42. bool isCustomFirst, isCustomNext, isCustomComplete;
  43. CQuest();
  44. virtual ~CQuest(){};
  45. static bool checkMissionArmy(const CQuest * q, const CCreatureSet * army);
  46. virtual bool checkQuest (const CGHeroInstance * h) const; //determines whether the quest is complete or not
  47. virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
  48. virtual void getCompletionText (MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
  49. virtual void getRolloverText (MetaString &text, bool onHover) const; //hover or quest log entry
  50. virtual void completeQuest (const CGHeroInstance * h) const {};
  51. virtual void addReplacements(MetaString &out, const std::string &base) const;
  52. bool operator== (const CQuest & quest) const
  53. {
  54. return (quest.qid == qid);
  55. }
  56. template <typename Handler> void serialize(Handler &h, const int version)
  57. {
  58. h & qid;
  59. h & missionType;
  60. h & progress;
  61. h & lastDay;
  62. h & m13489val;
  63. h & m2stats;
  64. h & m5arts;
  65. h & m6creatures;
  66. h & m7resources;
  67. h & textOption;
  68. h & stackToKill;
  69. h & stackDirection;
  70. h & heroName;
  71. h & heroPortrait;
  72. h & firstVisitText;
  73. h & nextVisitText;
  74. h & completedText;
  75. h & isCustomFirst;
  76. h & isCustomNext;
  77. h & isCustomComplete;
  78. h & completedOption;
  79. }
  80. void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName);
  81. };
  82. class DLL_LINKAGE IQuestObject
  83. {
  84. public:
  85. CQuest * quest;
  86. IQuestObject();
  87. virtual ~IQuestObject();
  88. virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
  89. virtual bool checkQuest (const CGHeroInstance * h) const;
  90. template <typename Handler> void serialize(Handler &h, const int version)
  91. {
  92. h & quest;
  93. }
  94. protected:
  95. void afterAddToMapCommon(CMap * map);
  96. };
  97. class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
  98. {
  99. public:
  100. enum ERewardType {NOTHING, EXPERIENCE, MANA_POINTS, MORALE_BONUS, LUCK_BONUS, RESOURCES, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE};
  101. ERewardType rewardType;
  102. si32 rID; //reward ID
  103. si32 rVal; //reward value
  104. std::string seerName;
  105. CGSeerHut();
  106. void initObj(CRandomGenerator & rand) override;
  107. std::string getHoverText(PlayerColor player) const override;
  108. void newTurn(CRandomGenerator & rand) const override;
  109. void onHeroVisit(const CGHeroInstance * h) const override;
  110. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  111. virtual void init(CRandomGenerator & rand);
  112. int checkDirection() const; //calculates the region of map where monster is placed
  113. void setObjToKill(); //remember creatures / heroes to kill after they are initialized
  114. const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
  115. const CGCreature *getCreatureToKill(bool allowNull = false) const;
  116. void getRolloverText (MetaString &text, bool onHover) const;
  117. void getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
  118. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  119. virtual void completeQuest (const CGHeroInstance * h) const;
  120. void afterAddToMap(CMap * map) override;
  121. template <typename Handler> void serialize(Handler &h, const int version)
  122. {
  123. h & static_cast<CArmedInstance&>(*this);
  124. h & static_cast<IQuestObject&>(*this);
  125. h & rewardType;
  126. h & rID;
  127. h & rVal;
  128. h & seerName;
  129. }
  130. protected:
  131. static const int OBJPROP_VISITED = 10;
  132. void setPropertyDer(ui8 what, ui32 val) override;
  133. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  134. };
  135. class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  136. {
  137. public:
  138. CGQuestGuard() : CGSeerHut(){};
  139. void init(CRandomGenerator & rand) override;
  140. void completeQuest (const CGHeroInstance * h) const override;
  141. template <typename Handler> void serialize(Handler &h, const int version)
  142. {
  143. h & static_cast<CGSeerHut&>(*this);
  144. }
  145. protected:
  146. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  147. };
  148. class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  149. {
  150. public:
  151. static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned]
  152. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  153. static void reset();
  154. bool wasMyColorVisited (PlayerColor player) const;
  155. std::string getObjectName() const override; //depending on color
  156. std::string getHoverText(PlayerColor player) const override;
  157. template <typename Handler> void serialize(Handler &h, const int version)
  158. {
  159. h & static_cast<CGObjectInstance&>(*this);
  160. }
  161. protected:
  162. void setPropertyDer(ui8 what, ui32 val) override;
  163. };
  164. class DLL_LINKAGE CGKeymasterTent : public CGKeys
  165. {
  166. public:
  167. bool wasVisited (PlayerColor player) const override;
  168. void onHeroVisit(const CGHeroInstance * h) const override;
  169. template <typename Handler> void serialize(Handler &h, const int version)
  170. {
  171. h & static_cast<CGObjectInstance&>(*this);
  172. }
  173. };
  174. class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  175. {
  176. public:
  177. CGBorderGuard() : IQuestObject(){};
  178. void initObj(CRandomGenerator & rand) override;
  179. void onHeroVisit(const CGHeroInstance * h) const override;
  180. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  181. void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
  182. void getRolloverText (MetaString &text, bool onHover) const;
  183. bool checkQuest (const CGHeroInstance * h) const override;
  184. void afterAddToMap(CMap * map) override;
  185. template <typename Handler> void serialize(Handler &h, const int version)
  186. {
  187. h & static_cast<IQuestObject&>(*this);
  188. h & static_cast<CGObjectInstance&>(*this);
  189. h & blockVisit;
  190. }
  191. };
  192. class DLL_LINKAGE CGBorderGate : public CGBorderGuard
  193. {
  194. public:
  195. CGBorderGate() : CGBorderGuard(){};
  196. void onHeroVisit(const CGHeroInstance * h) const override;
  197. bool passableFor(PlayerColor color) const override;
  198. template <typename Handler> void serialize(Handler &h, const int version)
  199. {
  200. h & static_cast<CGBorderGuard&>(*this); //need to serialize or object will be empty
  201. }
  202. };
  203. VCMI_LIB_NAMESPACE_END