CQuest.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. h & completedOption;
  78. }
  79. void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName);
  80. };
  81. class DLL_LINKAGE IQuestObject
  82. {
  83. public:
  84. CQuest * quest;
  85. IQuestObject();
  86. virtual ~IQuestObject();
  87. virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
  88. virtual bool checkQuest (const CGHeroInstance * h) const;
  89. template <typename Handler> void serialize(Handler &h, const int version)
  90. {
  91. h & quest;
  92. }
  93. protected:
  94. void afterAddToMapCommon(CMap * map);
  95. };
  96. class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
  97. {
  98. public:
  99. enum ERewardType {NOTHING, EXPERIENCE, MANA_POINTS, MORALE_BONUS, LUCK_BONUS, RESOURCES, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE};
  100. ERewardType rewardType;
  101. si32 rID; //reward ID
  102. si32 rVal; //reward value
  103. std::string seerName;
  104. CGSeerHut();
  105. void initObj(CRandomGenerator & rand) override;
  106. std::string getHoverText(PlayerColor player) const override;
  107. void newTurn(CRandomGenerator & rand) const override;
  108. void onHeroVisit(const CGHeroInstance * h) const override;
  109. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  110. virtual void init(CRandomGenerator & rand);
  111. int checkDirection() const; //calculates the region of map where monster is placed
  112. void setObjToKill(); //remember creatures / heroes to kill after they are initialized
  113. const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
  114. const CGCreature *getCreatureToKill(bool allowNull = false) const;
  115. void getRolloverText (MetaString &text, bool onHover) const;
  116. void getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
  117. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  118. virtual void completeQuest (const CGHeroInstance * h) const;
  119. void afterAddToMap(CMap * map) override;
  120. template <typename Handler> void serialize(Handler &h, const int version)
  121. {
  122. h & static_cast<CArmedInstance&>(*this);
  123. h & static_cast<IQuestObject&>(*this);
  124. h & rewardType;
  125. h & rID;
  126. h & rVal;
  127. h & seerName;
  128. }
  129. protected:
  130. static const int OBJPROP_VISITED = 10;
  131. void setPropertyDer(ui8 what, ui32 val) override;
  132. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  133. };
  134. class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  135. {
  136. public:
  137. CGQuestGuard() : CGSeerHut(){};
  138. void init(CRandomGenerator & rand) override;
  139. void completeQuest (const CGHeroInstance * h) const override;
  140. template <typename Handler> void serialize(Handler &h, const int version)
  141. {
  142. h & static_cast<CGSeerHut&>(*this);
  143. }
  144. protected:
  145. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  146. };
  147. class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  148. {
  149. public:
  150. static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned]
  151. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  152. static void reset();
  153. bool wasMyColorVisited (PlayerColor player) const;
  154. std::string getObjectName() const override; //depending on color
  155. std::string getHoverText(PlayerColor player) const override;
  156. template <typename Handler> void serialize(Handler &h, const int version)
  157. {
  158. h & static_cast<CGObjectInstance&>(*this);
  159. }
  160. protected:
  161. void setPropertyDer(ui8 what, ui32 val) override;
  162. };
  163. class DLL_LINKAGE CGKeymasterTent : public CGKeys
  164. {
  165. public:
  166. bool wasVisited (PlayerColor player) const override;
  167. void onHeroVisit(const CGHeroInstance * h) const override;
  168. template <typename Handler> void serialize(Handler &h, const int version)
  169. {
  170. h & static_cast<CGObjectInstance&>(*this);
  171. }
  172. };
  173. class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  174. {
  175. public:
  176. CGBorderGuard() : IQuestObject(){};
  177. void initObj(CRandomGenerator & rand) override;
  178. void onHeroVisit(const CGHeroInstance * h) const override;
  179. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  180. void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
  181. void getRolloverText (MetaString &text, bool onHover) const;
  182. bool checkQuest (const CGHeroInstance * h) const override;
  183. void afterAddToMap(CMap * map) override;
  184. template <typename Handler> void serialize(Handler &h, const int version)
  185. {
  186. h & static_cast<IQuestObject&>(*this);
  187. h & static_cast<CGObjectInstance&>(*this);
  188. h & blockVisit;
  189. }
  190. };
  191. class DLL_LINKAGE CGBorderGate : public CGBorderGuard
  192. {
  193. public:
  194. CGBorderGate() : CGBorderGuard(){};
  195. void onHeroVisit(const CGHeroInstance * h) const override;
  196. bool passableFor(PlayerColor color) const override;
  197. template <typename Handler> void serialize(Handler &h, const int version)
  198. {
  199. h & static_cast<CGBorderGuard&>(*this); //need to serialize or object will be empty
  200. }
  201. };