CQuest.h 7.8 KB

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