MiscObjects.h 11 KB

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