CQuest.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #pragma once
  2. #include "CObjectHandler.h"
  3. #include "CArmedInstance.h"
  4. #include "../CCreatureSet.h"
  5. #include "../NetPacksBase.h"
  6. /*
  7. * CQuest.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  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 field 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
  32. ui8 textOption;
  33. CStackBasicDescriptor stackToKill;
  34. ui8 stackDirection;
  35. std::string heroName; //backup of hero name
  36. si32 heroPortrait;
  37. std::string firstVisitText, nextVisitText, completedText;
  38. bool isCustomFirst, isCustomNext, isCustomComplete;
  39. CQuest(){missionType = MISSION_NONE;}; //default constructor
  40. virtual ~CQuest(){};
  41. virtual bool checkQuest (const CGHeroInstance * h) const; //determines whether the quest is complete or not
  42. virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
  43. virtual void getCompletionText (MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
  44. virtual void getRolloverText (MetaString &text, bool onHover) const; //hover or quest log entry
  45. virtual void completeQuest (const CGHeroInstance * h) const {};
  46. virtual void addReplacements(MetaString &out, const std::string &base) const;
  47. bool operator== (const CQuest & quest) const
  48. {
  49. return (quest.qid == qid);
  50. }
  51. template <typename Handler> void serialize(Handler &h, const int version)
  52. {
  53. h & qid & missionType & progress & lastDay & m13489val & m2stats & m5arts & m6creatures & m7resources
  54. & textOption & stackToKill & stackDirection & heroName & heroPortrait
  55. & firstVisitText & nextVisitText & completedText & isCustomFirst & isCustomNext & isCustomComplete;
  56. }
  57. };
  58. class DLL_LINKAGE IQuestObject
  59. {
  60. public:
  61. CQuest * quest;
  62. IQuestObject(): quest(new CQuest()){};
  63. virtual ~IQuestObject() {};
  64. virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const;
  65. virtual bool checkQuest (const CGHeroInstance * h) const;
  66. template <typename Handler> void serialize(Handler &h, const int version)
  67. {
  68. h & quest;
  69. }
  70. };
  71. class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
  72. {
  73. public:
  74. enum ERewardType {NOTHING, EXPERIENCE, MANA_POINTS, MORALE_BONUS, LUCK_BONUS, RESOURCES, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE};
  75. ERewardType rewardType;
  76. si32 rID; //reward ID
  77. si32 rVal; //reward value
  78. std::string seerName;
  79. CGSeerHut();
  80. void initObj() override;
  81. std::string getHoverText(PlayerColor player) const override;
  82. void newTurn() const override;
  83. void onHeroVisit(const CGHeroInstance * h) const override;
  84. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  85. virtual void init();
  86. int checkDirection() const; //calculates the region of map where monster is placed
  87. void setObjToKill(); //remember creatures / heroes to kill after they are initialized
  88. const CGHeroInstance *getHeroToKill(bool allowNull = false) const;
  89. const CGCreature *getCreatureToKill(bool allowNull = false) const;
  90. void getRolloverText (MetaString &text, bool onHover) const;
  91. void getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h = nullptr) const;
  92. void finishQuest (const CGHeroInstance * h, ui32 accept) const; //common for both objects
  93. virtual void completeQuest (const CGHeroInstance * h) const;
  94. template <typename Handler> void serialize(Handler &h, const int version)
  95. {
  96. h & static_cast<CArmedInstance&>(*this) & static_cast<IQuestObject&>(*this);
  97. h & rewardType & rID & rVal & seerName;
  98. }
  99. protected:
  100. static constexpr int OBJPROP_VISITED = 10;
  101. void setPropertyDer(ui8 what, ui32 val) override;
  102. };
  103. class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  104. {
  105. public:
  106. CGQuestGuard() : CGSeerHut(){};
  107. void init() override;
  108. void completeQuest (const CGHeroInstance * h) const override;
  109. template <typename Handler> void serialize(Handler &h, const int version)
  110. {
  111. h & static_cast<CGSeerHut&>(*this);
  112. }
  113. };
  114. class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  115. {
  116. public:
  117. static std::map <PlayerColor, std::set <ui8> > playerKeyMap; //[players][keysowned]
  118. //SubID 0 - lightblue, 1 - green, 2 - red, 3 - darkblue, 4 - brown, 5 - purple, 6 - white, 7 - black
  119. bool wasMyColorVisited (PlayerColor player) const;
  120. std::string getObjectName() const override; //depending on color
  121. std::string getHoverText(PlayerColor player) const override;
  122. template <typename Handler> void serialize(Handler &h, const int version)
  123. {
  124. h & static_cast<CGObjectInstance&>(*this);
  125. }
  126. protected:
  127. void setPropertyDer(ui8 what, ui32 val) override;
  128. };
  129. class DLL_LINKAGE CGKeymasterTent : public CGKeys
  130. {
  131. public:
  132. bool wasVisited (PlayerColor player) const override;
  133. void onHeroVisit(const CGHeroInstance * h) const override;
  134. template <typename Handler> void serialize(Handler &h, const int version)
  135. {
  136. h & static_cast<CGObjectInstance&>(*this);
  137. }
  138. };
  139. class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  140. {
  141. public:
  142. CGBorderGuard() : IQuestObject(){};
  143. void initObj() override;
  144. void onHeroVisit(const CGHeroInstance * h) const override;
  145. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  146. void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = nullptr) const override;
  147. void getRolloverText (MetaString &text, bool onHover) const;
  148. bool checkQuest (const CGHeroInstance * h) const override;
  149. template <typename Handler> void serialize(Handler &h, const int version)
  150. {
  151. h & static_cast<IQuestObject&>(*this);
  152. h & static_cast<CGObjectInstance&>(*this);
  153. h & blockVisit;
  154. }
  155. };
  156. class DLL_LINKAGE CGBorderGate : public CGBorderGuard
  157. {
  158. public:
  159. CGBorderGate() : CGBorderGuard(){};
  160. void onHeroVisit(const CGHeroInstance * h) const override;
  161. bool passableFor(PlayerColor color) const override;
  162. template <typename Handler> void serialize(Handler &h, const int version)
  163. {
  164. h & static_cast<CGBorderGuard&>(*this); //need to serialize or object will be empty
  165. }
  166. };