MiscObjects.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. #pragma once
  2. #include "CObjectHandler.h"
  3. #include "CArmedInstance.h"
  4. #include "../ResourceSet.h"
  5. /*
  6. * MiscObjects.h, part of VCMI engine
  7. *
  8. * Authors: listed in file AUTHORS in main folder
  9. *
  10. * License: GNU General Public License v2.0 or later
  11. * Full text of license available in license.txt file, in main folder
  12. *
  13. */
  14. class DLL_LINKAGE CPlayersVisited: public CGObjectInstance
  15. {
  16. public:
  17. std::set<PlayerColor> players; //players that visited this object
  18. bool wasVisited(PlayerColor player) const;
  19. bool wasVisited(TeamID team) const;
  20. void setPropertyDer(ui8 what, ui32 val) override;
  21. template <typename Handler> void serialize(Handler &h, const int version)
  22. {
  23. h & static_cast<CGObjectInstance&>(*this);
  24. h & players;
  25. }
  26. };
  27. class DLL_LINKAGE CGCreature : public CArmedInstance //creatures on map
  28. {
  29. enum Action {
  30. FIGHT = -2, FLEE = -1, JOIN_FOR_FREE = 0 //values > 0 mean gold price
  31. };
  32. public:
  33. ui32 identifier; //unique code for this monster (used in missions)
  34. si8 character; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage)
  35. std::string message; //message printed for attacking hero
  36. TResources resources; // resources given to hero that has won with monsters
  37. ArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none
  38. bool neverFlees; //if true, the troops will never flee
  39. bool notGrowingTeam; //if true, number of units won't grow
  40. ui64 temppower; //used to handle fractional stack growth for tiny stacks
  41. bool refusedJoining;
  42. void onHeroVisit(const CGHeroInstance * h) const override;
  43. std::string getHoverText(PlayerColor player) const override;
  44. std::string getHoverText(const CGHeroInstance * hero) const override;
  45. void initObj() override;
  46. void newTurn() const override;
  47. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  48. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  49. struct DLL_LINKAGE formationInfo // info about merging stacks after battle back into one
  50. {
  51. si32 basicType;
  52. ui32 randomFormation; //random seed used to determine number of stacks and is there's upgraded stack
  53. template <typename Handler> void serialize(Handler &h, const int version)
  54. {
  55. h & basicType & randomFormation;
  56. }
  57. } formation;
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & static_cast<CArmedInstance&>(*this);
  61. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam & temppower;
  62. h & refusedJoining & formation;
  63. }
  64. protected:
  65. void setPropertyDer(ui8 what, ui32 val) override;
  66. private:
  67. void fight(const CGHeroInstance *h) const;
  68. void flee( const CGHeroInstance * h ) const;
  69. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  70. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  71. int takenAction(const CGHeroInstance *h, bool allowJoin=true) const; //action on confrontation: -2 - fight, -1 - flee, >=0 - will join for given value of gold (may be 0)
  72. };
  73. class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  74. {
  75. public:
  76. std::string message;
  77. void onHeroVisit(const CGHeroInstance * h) const override;
  78. void initObj() override;
  79. template <typename Handler> void serialize(Handler &h, const int version)
  80. {
  81. h & static_cast<CGObjectInstance&>(*this);
  82. h & message;
  83. }
  84. };
  85. class DLL_LINKAGE CGWitchHut : public CPlayersVisited
  86. {
  87. public:
  88. std::vector<si32> allowedAbilities;
  89. ui32 ability;
  90. std::string getHoverText(PlayerColor player) const override;
  91. std::string getHoverText(const CGHeroInstance * hero) const override;
  92. void onHeroVisit(const CGHeroInstance * h) const override;
  93. void initObj() override;
  94. template <typename Handler> void serialize(Handler &h, const int version)
  95. {
  96. h & static_cast<CPlayersVisited&>(*this);
  97. h & allowedAbilities & ability;
  98. }
  99. };
  100. class DLL_LINKAGE CGScholar : public CGObjectInstance
  101. {
  102. public:
  103. enum EBonusType {PRIM_SKILL, SECONDARY_SKILL, SPELL, RANDOM = 255};
  104. EBonusType bonusType;
  105. ui16 bonusID; //ID of skill/spell
  106. // void giveAnyBonus(const CGHeroInstance * h) const; //TODO: remove
  107. CGScholar() : bonusType(EBonusType::RANDOM){};
  108. void onHeroVisit(const CGHeroInstance * h) const override;
  109. void initObj() override;
  110. template <typename Handler> void serialize(Handler &h, const int version)
  111. {
  112. h & static_cast<CGObjectInstance&>(*this);
  113. h & bonusType & bonusID;
  114. }
  115. };
  116. class DLL_LINKAGE CGGarrison : public CArmedInstance
  117. {
  118. public:
  119. bool removableUnits;
  120. bool passableFor(PlayerColor color) const override;
  121. void onHeroVisit(const CGHeroInstance * h) const override;
  122. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  123. template <typename Handler> void serialize(Handler &h, const int version)
  124. {
  125. h & static_cast<CArmedInstance&>(*this);
  126. h & removableUnits;
  127. }
  128. };
  129. class DLL_LINKAGE CGArtifact : public CArmedInstance
  130. {
  131. public:
  132. CArtifactInstance *storedArtifact;
  133. std::string message;
  134. CGArtifact() : CArmedInstance() {storedArtifact = nullptr;};
  135. void onHeroVisit(const CGHeroInstance * h) const override;
  136. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  137. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  138. std::string getObjectName() const override;
  139. void pick( const CGHeroInstance * h ) const;
  140. void initObj() override;
  141. template <typename Handler> void serialize(Handler &h, const int version)
  142. {
  143. h & static_cast<CArmedInstance&>(*this);
  144. h & message & storedArtifact;
  145. }
  146. };
  147. class DLL_LINKAGE CGResource : public CArmedInstance
  148. {
  149. public:
  150. ui32 amount; //0 if random
  151. std::string message;
  152. CGResource();
  153. void onHeroVisit(const CGHeroInstance * h) const override;
  154. void initObj() override;
  155. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  156. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  157. std::string getHoverText(PlayerColor player) const override;
  158. void collectRes(PlayerColor player) const;
  159. template <typename Handler> void serialize(Handler &h, const int version)
  160. {
  161. h & static_cast<CArmedInstance&>(*this);
  162. h & amount & message;
  163. }
  164. };
  165. class DLL_LINKAGE CGShrine : public CPlayersVisited
  166. {
  167. public:
  168. SpellID spell; //id of spell or NONE if random
  169. void onHeroVisit(const CGHeroInstance * h) const override;
  170. void initObj() override;
  171. std::string getHoverText(PlayerColor player) const override;
  172. std::string getHoverText(const CGHeroInstance * hero) const override;
  173. template <typename Handler> void serialize(Handler &h, const int version)
  174. {
  175. h & static_cast<CPlayersVisited&>(*this);;
  176. h & spell;
  177. }
  178. };
  179. class DLL_LINKAGE CGMine : public CArmedInstance
  180. {
  181. public:
  182. Res::ERes producedResource;
  183. ui32 producedQuantity;
  184. void onHeroVisit(const CGHeroInstance * h) const override;
  185. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  186. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  187. void flagMine(PlayerColor player) const;
  188. void newTurn() const override;
  189. void initObj() override;
  190. std::string getObjectName() const override;
  191. std::string getHoverText(PlayerColor player) const override;
  192. template <typename Handler> void serialize(Handler &h, const int version)
  193. {
  194. h & static_cast<CArmedInstance&>(*this);
  195. h & producedResource & producedQuantity;
  196. }
  197. ui32 defaultResProduction();
  198. };
  199. class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates
  200. {
  201. public:
  202. static std::map<Obj, std::map<int, std::vector<ObjectInstanceID> > > objs; //teleports: map[ID][subID] => vector of ids
  203. static std::vector<std::pair<ObjectInstanceID, ObjectInstanceID> > gates; //subterranean gates: pairs of ids
  204. void onHeroVisit(const CGHeroInstance * h) const override;
  205. void initObj() override;
  206. static void postInit();
  207. static ObjectInstanceID getMatchingGate(ObjectInstanceID id); //receives id of one subterranean gate and returns id of the paired one, -1 if none
  208. template <typename Handler> void serialize(Handler &h, const int version)
  209. {
  210. h & static_cast<CGObjectInstance&>(*this);
  211. }
  212. };
  213. class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  214. {
  215. public:
  216. void onHeroVisit(const CGHeroInstance * h) const override;
  217. std::string getHoverText(const CGHeroInstance * hero) const override;
  218. template <typename Handler> void serialize(Handler &h, const int version)
  219. {
  220. h & static_cast<CGObjectInstance&>(*this);
  221. }
  222. };
  223. class DLL_LINKAGE CGSirens : public CGObjectInstance
  224. {
  225. public:
  226. void onHeroVisit(const CGHeroInstance * h) const override;
  227. std::string getHoverText(const CGHeroInstance * hero) const override;
  228. void initObj() override;
  229. template <typename Handler> void serialize(Handler &h, const int version)
  230. {
  231. h & static_cast<CGObjectInstance&>(*this);
  232. }
  233. };
  234. class DLL_LINKAGE CGObservatory : public CGObjectInstance //Redwood observatory
  235. {
  236. public:
  237. void onHeroVisit(const CGHeroInstance * h) const override;
  238. template <typename Handler> void serialize(Handler &h, const int version)
  239. {
  240. h & static_cast<CGObjectInstance&>(*this);
  241. }
  242. };
  243. class DLL_LINKAGE CGBoat : public CGObjectInstance
  244. {
  245. public:
  246. ui8 direction;
  247. const CGHeroInstance *hero; //hero on board
  248. void initObj() override;
  249. CGBoat()
  250. {
  251. hero = nullptr;
  252. direction = 4;
  253. }
  254. template <typename Handler> void serialize(Handler &h, const int version)
  255. {
  256. h & static_cast<CGObjectInstance&>(*this) & direction & hero;
  257. }
  258. };
  259. class CGShipyard : public CGObjectInstance, public IShipyard
  260. {
  261. public:
  262. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  263. CGShipyard();
  264. void onHeroVisit(const CGHeroInstance * h) const override;
  265. template <typename Handler> void serialize(Handler &h, const int version)
  266. {
  267. h & static_cast<CGObjectInstance&>(*this);
  268. h & static_cast<IShipyard&>(*this);
  269. }
  270. };
  271. class DLL_LINKAGE CGMagi : public CGObjectInstance
  272. {
  273. public:
  274. static std::map <si32, std::vector<ObjectInstanceID> > eyelist; //[subID][id], supports multiple sets as in H5
  275. void initObj() override;
  276. void onHeroVisit(const CGHeroInstance * h) const override;
  277. template <typename Handler> void serialize(Handler &h, const int version)
  278. {
  279. h & static_cast<CGObjectInstance&>(*this);
  280. }
  281. };
  282. class DLL_LINKAGE CCartographer : public CPlayersVisited
  283. {
  284. ///behaviour varies depending on surface and floor
  285. public:
  286. void onHeroVisit(const CGHeroInstance * h) const override;
  287. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  288. template <typename Handler> void serialize(Handler &h, const int version)
  289. {
  290. h & static_cast<CPlayersVisited&>(*this);
  291. }
  292. };
  293. class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance
  294. {
  295. void onHeroVisit(const CGHeroInstance * h) const override;
  296. };
  297. class DLL_LINKAGE CGObelisk : public CPlayersVisited
  298. {
  299. public:
  300. static ui8 obeliskCount; //how many obelisks are on map
  301. static std::map<TeamID, ui8> visited; //map: team_id => how many obelisks has been visited
  302. void onHeroVisit(const CGHeroInstance * h) const override;
  303. void initObj() override;
  304. std::string getHoverText(PlayerColor player) const override;
  305. template <typename Handler> void serialize(Handler &h, const int version)
  306. {
  307. h & static_cast<CPlayersVisited&>(*this);
  308. }
  309. protected:
  310. void setPropertyDer(ui8 what, ui32 val) override;
  311. };
  312. class DLL_LINKAGE CGLighthouse : public CGObjectInstance
  313. {
  314. public:
  315. void onHeroVisit(const CGHeroInstance * h) const override;
  316. void initObj() override;
  317. std::string getHoverText(PlayerColor player) const override;
  318. template <typename Handler> void serialize(Handler &h, const int version)
  319. {
  320. h & static_cast<CGObjectInstance&>(*this);
  321. }
  322. void giveBonusTo( PlayerColor player ) const;
  323. };