MiscObjects.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. void onHeroVisit(const CGHeroInstance * h) const override;
  108. void initObj() override;
  109. template <typename Handler> void serialize(Handler &h, const int version)
  110. {
  111. h & static_cast<CGObjectInstance&>(*this);
  112. h & bonusType & bonusID;
  113. }
  114. };
  115. class DLL_LINKAGE CGGarrison : public CArmedInstance
  116. {
  117. public:
  118. bool removableUnits;
  119. bool passableFor(PlayerColor color) const override;
  120. void onHeroVisit(const CGHeroInstance * h) const override;
  121. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  122. template <typename Handler> void serialize(Handler &h, const int version)
  123. {
  124. h & static_cast<CArmedInstance&>(*this);
  125. h & removableUnits;
  126. }
  127. };
  128. class DLL_LINKAGE CGArtifact : public CArmedInstance
  129. {
  130. public:
  131. CArtifactInstance *storedArtifact;
  132. std::string message;
  133. CGArtifact() : CArmedInstance() {storedArtifact = nullptr;};
  134. void onHeroVisit(const CGHeroInstance * h) const override;
  135. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  136. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  137. std::string getObjectName() const override;
  138. void pick( const CGHeroInstance * h ) const;
  139. void initObj() override;
  140. template <typename Handler> void serialize(Handler &h, const int version)
  141. {
  142. h & static_cast<CArmedInstance&>(*this);
  143. h & message & storedArtifact;
  144. }
  145. };
  146. class DLL_LINKAGE CGResource : public CArmedInstance
  147. {
  148. public:
  149. ui32 amount; //0 if random
  150. std::string message;
  151. void onHeroVisit(const CGHeroInstance * h) const override;
  152. void initObj() override;
  153. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  154. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  155. std::string getHoverText(PlayerColor player) const override;
  156. void collectRes(PlayerColor player) const;
  157. template <typename Handler> void serialize(Handler &h, const int version)
  158. {
  159. h & static_cast<CArmedInstance&>(*this);
  160. h & amount & message;
  161. }
  162. };
  163. class DLL_LINKAGE CGShrine : public CPlayersVisited
  164. {
  165. public:
  166. SpellID spell; //id of spell or NONE if random
  167. void onHeroVisit(const CGHeroInstance * h) const override;
  168. void initObj() override;
  169. std::string getHoverText(PlayerColor player) const override;
  170. std::string getHoverText(const CGHeroInstance * hero) const override;
  171. template <typename Handler> void serialize(Handler &h, const int version)
  172. {
  173. h & static_cast<CPlayersVisited&>(*this);;
  174. h & spell;
  175. }
  176. };
  177. class DLL_LINKAGE CGMine : public CArmedInstance
  178. {
  179. public:
  180. Res::ERes producedResource;
  181. ui32 producedQuantity;
  182. void onHeroVisit(const CGHeroInstance * h) const override;
  183. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  184. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  185. void flagMine(PlayerColor player) const;
  186. void newTurn() const override;
  187. void initObj() override;
  188. std::string getObjectName() const override;
  189. std::string getHoverText(PlayerColor player) const override;
  190. template <typename Handler> void serialize(Handler &h, const int version)
  191. {
  192. h & static_cast<CArmedInstance&>(*this);
  193. h & producedResource & producedQuantity;
  194. }
  195. ui32 defaultResProduction();
  196. };
  197. class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates
  198. {
  199. public:
  200. static std::map<Obj, std::map<int, std::vector<ObjectInstanceID> > > objs; //teleports: map[ID][subID] => vector of ids
  201. static std::vector<std::pair<ObjectInstanceID, ObjectInstanceID> > gates; //subterranean gates: pairs of ids
  202. void onHeroVisit(const CGHeroInstance * h) const override;
  203. void initObj() override;
  204. static void postInit();
  205. static ObjectInstanceID getMatchingGate(ObjectInstanceID id); //receives id of one subterranean gate and returns id of the paired one, -1 if none
  206. template <typename Handler> void serialize(Handler &h, const int version)
  207. {
  208. h & static_cast<CGObjectInstance&>(*this);
  209. }
  210. };
  211. class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  212. {
  213. public:
  214. void onHeroVisit(const CGHeroInstance * h) const override;
  215. std::string getHoverText(const CGHeroInstance * hero) const override;
  216. template <typename Handler> void serialize(Handler &h, const int version)
  217. {
  218. h & static_cast<CGObjectInstance&>(*this);
  219. }
  220. };
  221. class DLL_LINKAGE CGSirens : public CGObjectInstance
  222. {
  223. public:
  224. void onHeroVisit(const CGHeroInstance * h) const override;
  225. std::string getHoverText(const CGHeroInstance * hero) const override;
  226. void initObj() override;
  227. template <typename Handler> void serialize(Handler &h, const int version)
  228. {
  229. h & static_cast<CGObjectInstance&>(*this);
  230. }
  231. };
  232. class DLL_LINKAGE CGObservatory : public CGObjectInstance //Redwood observatory
  233. {
  234. public:
  235. void onHeroVisit(const CGHeroInstance * h) const override;
  236. template <typename Handler> void serialize(Handler &h, const int version)
  237. {
  238. h & static_cast<CGObjectInstance&>(*this);
  239. }
  240. };
  241. class DLL_LINKAGE CGBoat : public CGObjectInstance
  242. {
  243. public:
  244. ui8 direction;
  245. const CGHeroInstance *hero; //hero on board
  246. void initObj() override;
  247. CGBoat()
  248. {
  249. hero = nullptr;
  250. direction = 4;
  251. }
  252. template <typename Handler> void serialize(Handler &h, const int version)
  253. {
  254. h & static_cast<CGObjectInstance&>(*this) & direction & hero;
  255. }
  256. };
  257. class CGShipyard : public CGObjectInstance, public IShipyard
  258. {
  259. public:
  260. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  261. CGShipyard();
  262. void onHeroVisit(const CGHeroInstance * h) const override;
  263. template <typename Handler> void serialize(Handler &h, const int version)
  264. {
  265. h & static_cast<CGObjectInstance&>(*this);
  266. h & static_cast<IShipyard&>(*this);
  267. }
  268. };
  269. class DLL_LINKAGE CGMagi : public CGObjectInstance
  270. {
  271. public:
  272. static std::map <si32, std::vector<ObjectInstanceID> > eyelist; //[subID][id], supports multiple sets as in H5
  273. void initObj() override;
  274. void onHeroVisit(const CGHeroInstance * h) const override;
  275. template <typename Handler> void serialize(Handler &h, const int version)
  276. {
  277. h & static_cast<CGObjectInstance&>(*this);
  278. }
  279. };
  280. class DLL_LINKAGE CCartographer : public CPlayersVisited
  281. {
  282. ///behaviour varies depending on surface and floor
  283. public:
  284. void onHeroVisit(const CGHeroInstance * h) const override;
  285. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  286. template <typename Handler> void serialize(Handler &h, const int version)
  287. {
  288. h & static_cast<CPlayersVisited&>(*this);
  289. }
  290. };
  291. class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance
  292. {
  293. void onHeroVisit(const CGHeroInstance * h) const override;
  294. };
  295. class DLL_LINKAGE CGObelisk : public CPlayersVisited
  296. {
  297. public:
  298. static ui8 obeliskCount; //how many obelisks are on map
  299. static std::map<TeamID, ui8> visited; //map: team_id => how many obelisks has been visited
  300. void onHeroVisit(const CGHeroInstance * h) const override;
  301. void initObj() override;
  302. std::string getHoverText(PlayerColor player) const override;
  303. template <typename Handler> void serialize(Handler &h, const int version)
  304. {
  305. h & static_cast<CPlayersVisited&>(*this);
  306. }
  307. protected:
  308. void setPropertyDer(ui8 what, ui32 val) override;
  309. };
  310. class DLL_LINKAGE CGLighthouse : public CGObjectInstance
  311. {
  312. public:
  313. void onHeroVisit(const CGHeroInstance * h) const override;
  314. void initObj() override;
  315. std::string getHoverText(PlayerColor player) const override;
  316. template <typename Handler> void serialize(Handler &h, const int version)
  317. {
  318. h & static_cast<CGObjectInstance&>(*this);
  319. }
  320. void giveBonusTo( PlayerColor player ) const;
  321. };