MiscObjects.h 11 KB

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