MiscObjects.h 12 KB

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