MiscObjects.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. #pragma once
  2. #include "CObjectHandler.h"
  3. #include "CGArmedInstance.h"
  4. /*
  5. * CObjectHandler.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. const std::string & getHoverText() const override;
  43. void initObj() override;
  44. void newTurn() const override;
  45. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  46. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  47. struct DLL_LINKAGE formationInfo // info about merging stacks after battle back into one
  48. {
  49. si32 basicType;
  50. ui32 randomFormation; //random seed used to determine number of stacks and is there's upgraded stack
  51. template <typename Handler> void serialize(Handler &h, const int version)
  52. {
  53. h & basicType & randomFormation;
  54. }
  55. } formation;
  56. template <typename Handler> void serialize(Handler &h, const int version)
  57. {
  58. h & static_cast<CArmedInstance&>(*this);
  59. h & identifier & character & message & resources & gainedArtifact & neverFlees & notGrowingTeam & temppower;
  60. h & refusedJoining & formation;
  61. }
  62. protected:
  63. void setPropertyDer(ui8 what, ui32 val) override;
  64. private:
  65. void fight(const CGHeroInstance *h) const;
  66. void flee( const CGHeroInstance * h ) const;
  67. void fleeDecision(const CGHeroInstance *h, ui32 pursue) const;
  68. void joinDecision(const CGHeroInstance *h, int cost, ui32 accept) const;
  69. 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)
  70. };
  71. class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  72. {
  73. public:
  74. std::string message;
  75. void onHeroVisit(const CGHeroInstance * h) const override;
  76. void initObj() override;
  77. template <typename Handler> void serialize(Handler &h, const int version)
  78. {
  79. h & static_cast<CGObjectInstance&>(*this);
  80. h & message;
  81. }
  82. };
  83. class DLL_LINKAGE CGWitchHut : public CPlayersVisited
  84. {
  85. public:
  86. std::vector<si32> allowedAbilities;
  87. ui32 ability;
  88. const std::string & getHoverText() const override;
  89. void onHeroVisit(const CGHeroInstance * h) const override;
  90. void initObj() override;
  91. template <typename Handler> void serialize(Handler &h, const int version)
  92. {
  93. h & static_cast<CPlayersVisited&>(*this);
  94. h & allowedAbilities & ability;
  95. }
  96. };
  97. class DLL_LINKAGE CGScholar : public CGObjectInstance
  98. {
  99. public:
  100. enum EBonusType {PRIM_SKILL, SECONDARY_SKILL, SPELL, RANDOM = 255};
  101. EBonusType bonusType;
  102. ui16 bonusID; //ID of skill/spell
  103. // void giveAnyBonus(const CGHeroInstance * h) const; //TODO: remove
  104. void onHeroVisit(const CGHeroInstance * h) const override;
  105. void initObj() override;
  106. template <typename Handler> void serialize(Handler &h, const int version)
  107. {
  108. h & static_cast<CGObjectInstance&>(*this);
  109. h & bonusType & bonusID;
  110. }
  111. };
  112. class DLL_LINKAGE CGGarrison : public CArmedInstance
  113. {
  114. public:
  115. bool removableUnits;
  116. ui8 getPassableness() const;
  117. void onHeroVisit(const CGHeroInstance * h) const override;
  118. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  119. template <typename Handler> void serialize(Handler &h, const int version)
  120. {
  121. h & static_cast<CArmedInstance&>(*this);
  122. h & removableUnits;
  123. }
  124. };
  125. class DLL_LINKAGE CGArtifact : public CArmedInstance
  126. {
  127. public:
  128. CArtifactInstance *storedArtifact;
  129. std::string message;
  130. void onHeroVisit(const CGHeroInstance * h) const override;
  131. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  132. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  133. void pick( const CGHeroInstance * h ) const;
  134. void initObj() override;
  135. template <typename Handler> void serialize(Handler &h, const int version)
  136. {
  137. h & static_cast<CArmedInstance&>(*this);
  138. h & message & storedArtifact;
  139. }
  140. };
  141. class DLL_LINKAGE CGResource : public CArmedInstance
  142. {
  143. public:
  144. ui32 amount; //0 if random
  145. std::string message;
  146. void onHeroVisit(const CGHeroInstance * h) const override;
  147. void initObj() override;
  148. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  149. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  150. void collectRes(PlayerColor player) const;
  151. template <typename Handler> void serialize(Handler &h, const int version)
  152. {
  153. h & static_cast<CArmedInstance&>(*this);
  154. h & amount & message;
  155. }
  156. };
  157. class DLL_LINKAGE CGShrine : public CPlayersVisited
  158. {
  159. public:
  160. SpellID spell; //id of spell or NONE if random
  161. void onHeroVisit(const CGHeroInstance * h) const override;
  162. void initObj() override;
  163. const std::string & getHoverText() const override;
  164. template <typename Handler> void serialize(Handler &h, const int version)
  165. {
  166. h & static_cast<CPlayersVisited&>(*this);;
  167. h & spell;
  168. }
  169. };
  170. class DLL_LINKAGE CGMine : public CArmedInstance
  171. {
  172. public:
  173. Res::ERes producedResource;
  174. ui32 producedQuantity;
  175. void onHeroVisit(const CGHeroInstance * h) const override;
  176. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  177. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  178. void flagMine(PlayerColor player) const;
  179. void newTurn() const override;
  180. void initObj() override;
  181. template <typename Handler> void serialize(Handler &h, const int version)
  182. {
  183. h & static_cast<CArmedInstance&>(*this);
  184. h & producedResource & producedQuantity;
  185. }
  186. ui32 defaultResProduction();
  187. };
  188. class DLL_LINKAGE CGTeleport : public CGObjectInstance //teleports and subterranean gates
  189. {
  190. public:
  191. static std::map<Obj, std::map<int, std::vector<ObjectInstanceID> > > objs; //teleports: map[ID][subID] => vector of ids
  192. static std::vector<std::pair<ObjectInstanceID, ObjectInstanceID> > gates; //subterranean gates: pairs of ids
  193. void onHeroVisit(const CGHeroInstance * h) const override;
  194. void initObj() override;
  195. static void postInit();
  196. static ObjectInstanceID getMatchingGate(ObjectInstanceID id); //receives id of one subterranean gate and returns id of the paired one, -1 if none
  197. template <typename Handler> void serialize(Handler &h, const int version)
  198. {
  199. h & static_cast<CGObjectInstance&>(*this);
  200. }
  201. };
  202. class DLL_LINKAGE CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
  203. {
  204. public:
  205. void onHeroVisit(const CGHeroInstance * h) const override;
  206. const std::string & getHoverText() const override;
  207. template <typename Handler> void serialize(Handler &h, const int version)
  208. {
  209. h & static_cast<CGObjectInstance&>(*this);
  210. }
  211. };
  212. class DLL_LINKAGE CGSirens : public CGObjectInstance
  213. {
  214. public:
  215. void onHeroVisit(const CGHeroInstance * h) const override;
  216. const std::string & getHoverText() const override;
  217. void initObj() 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 CGObservatory : public CGObjectInstance //Redwood observatory
  224. {
  225. public:
  226. void onHeroVisit(const CGHeroInstance * h) const 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 CGBoat : public CGObjectInstance
  233. {
  234. public:
  235. ui8 direction;
  236. const CGHeroInstance *hero; //hero on board
  237. void initObj() override;
  238. CGBoat()
  239. {
  240. hero = nullptr;
  241. direction = 4;
  242. }
  243. template <typename Handler> void serialize(Handler &h, const int version)
  244. {
  245. h & static_cast<CGObjectInstance&>(*this) & direction & hero;
  246. }
  247. };
  248. class CGShipyard : public CGObjectInstance, public IShipyard
  249. {
  250. public:
  251. void getOutOffsets(std::vector<int3> &offsets) const; //offsets to obj pos when we boat can be placed
  252. CGShipyard();
  253. void onHeroVisit(const CGHeroInstance * h) const override;
  254. template <typename Handler> void serialize(Handler &h, const int version)
  255. {
  256. h & static_cast<CGObjectInstance&>(*this);
  257. h & static_cast<IShipyard&>(*this);
  258. }
  259. };
  260. class DLL_LINKAGE CGMagi : public CGObjectInstance
  261. {
  262. public:
  263. static std::map <si32, std::vector<ObjectInstanceID> > eyelist; //[subID][id], supports multiple sets as in H5
  264. void initObj() override;
  265. void onHeroVisit(const CGHeroInstance * h) const override;
  266. template <typename Handler> void serialize(Handler &h, const int version)
  267. {
  268. h & static_cast<CGObjectInstance&>(*this);
  269. }
  270. };
  271. class DLL_LINKAGE CCartographer : public CPlayersVisited
  272. {
  273. ///behaviour varies depending on surface and floor
  274. public:
  275. void onHeroVisit(const CGHeroInstance * h) const override;
  276. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  277. template <typename Handler> void serialize(Handler &h, const int version)
  278. {
  279. h & static_cast<CPlayersVisited&>(*this);
  280. }
  281. };
  282. class DLL_LINKAGE CGDenOfthieves : public CGObjectInstance
  283. {
  284. void onHeroVisit(const CGHeroInstance * h) const override;
  285. };
  286. class DLL_LINKAGE CGObelisk : public CPlayersVisited
  287. {
  288. public:
  289. static ui8 obeliskCount; //how many obelisks are on map
  290. static std::map<TeamID, ui8> visited; //map: team_id => how many obelisks has been visited
  291. void onHeroVisit(const CGHeroInstance * h) const override;
  292. void initObj() override;
  293. const std::string & getHoverText() const override;
  294. template <typename Handler> void serialize(Handler &h, const int version)
  295. {
  296. h & static_cast<CPlayersVisited&>(*this);
  297. }
  298. protected:
  299. void setPropertyDer(ui8 what, ui32 val) override;
  300. };
  301. class DLL_LINKAGE CGLighthouse : public CGObjectInstance
  302. {
  303. public:
  304. void onHeroVisit(const CGHeroInstance * h) const override;
  305. void initObj() override;
  306. const std::string & getHoverText() const override;
  307. template <typename Handler> void serialize(Handler &h, const int version)
  308. {
  309. h & static_cast<CGObjectInstance&>(*this);
  310. }
  311. void giveBonusTo( PlayerColor player ) const;
  312. };