CQuest.h 7.8 KB

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