CGMarket.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * CGMarket.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CGObjectInstance.h"
  12. #include "IMarket.h"
  13. #include "../CArtHandler.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class MarketInstanceConstructor;
  16. class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
  17. {
  18. std::shared_ptr<MarketInstanceConstructor> getMarketHandler() const;
  19. public:
  20. int marketEfficiency;
  21. CGMarket(IGameCallback *cb);
  22. ///IObjectInterface
  23. void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
  24. void initObj(vstd::RNG & rand) override;//set skills for trade
  25. std::string getPopupText(PlayerColor player) const override;
  26. std::string getPopupText(const CGHeroInstance * hero) const override;
  27. ///IMarket
  28. ObjectInstanceID getObjInstanceID() const override;
  29. int getMarketEfficiency() const override;
  30. int availableUnits(EMarketMode mode, int marketItemSerial) const override; //-1 if unlimited
  31. std::set<EMarketMode> availableModes() const override;
  32. template <typename Handler>
  33. void serialize(Handler &h)
  34. {
  35. h & static_cast<CGObjectInstance&>(*this);
  36. if (h.version < Handler::Version::NEW_MARKETS)
  37. {
  38. std::set<EMarketMode> marketModes;
  39. h & marketModes;
  40. }
  41. h & marketEfficiency;
  42. if (h.version < Handler::Version::NEW_MARKETS)
  43. {
  44. std::string speech;
  45. std::string title;
  46. h & speech;
  47. h & title;
  48. }
  49. }
  50. template <typename Handler> void serializeArtifactsAltar(Handler &h)
  51. {
  52. serialize(h);
  53. IMarket::serializeArtifactsAltar(h);
  54. }
  55. };
  56. class DLL_LINKAGE CGBlackMarket : public CGMarket
  57. {
  58. public:
  59. using CGMarket::CGMarket;
  60. std::vector<ArtifactID> artifacts; //available artifacts
  61. void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
  62. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  63. template <typename Handler> void serialize(Handler &h)
  64. {
  65. h & static_cast<CGMarket&>(*this);
  66. if (h.version < Handler::Version::REMOVE_VLC_POINTERS)
  67. {
  68. int32_t size = 0;
  69. h & size;
  70. for (int32_t i = 0; i < size; ++i)
  71. {
  72. bool isNull = false;
  73. ArtifactID artifact;
  74. h & isNull;
  75. if (!isNull)
  76. h & artifact;
  77. artifacts.push_back(artifact);
  78. }
  79. }
  80. else
  81. {
  82. h & artifacts;
  83. }
  84. }
  85. };
  86. class DLL_LINKAGE CGUniversity : public CGMarket
  87. {
  88. public:
  89. using CGMarket::CGMarket;
  90. std::string speech; //currently shown only in university
  91. std::string title;
  92. std::vector<TradeItemBuy> skills; //available skills
  93. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  94. void onHeroVisit(const CGHeroInstance * h) const override; //open window
  95. template <typename Handler> void serialize(Handler &h)
  96. {
  97. h & static_cast<CGMarket&>(*this);
  98. h & skills;
  99. if (h.version >= Handler::Version::NEW_MARKETS)
  100. {
  101. h & speech;
  102. h & title;
  103. }
  104. }
  105. };
  106. VCMI_LIB_NAMESPACE_END