2
0

CGMarket.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
  16. {
  17. public:
  18. int marketEfficiency;
  19. CGMarket(IGameCallback *cb);
  20. ///IObjectInterface
  21. void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
  22. void initObj(vstd::RNG & rand) override;//set skills for trade
  23. ///IMarket
  24. ObjectInstanceID getObjInstanceID() const override;
  25. int getMarketEfficiency() const override;
  26. int availableUnits(EMarketMode mode, int marketItemSerial) const override; //-1 if unlimited
  27. std::set<EMarketMode> availableModes() const override;
  28. template <typename Handler>
  29. void serialize(Handler &h)
  30. {
  31. h & static_cast<CGObjectInstance&>(*this);
  32. if (h.version < Handler::Version::NEW_MARKETS)
  33. {
  34. std::set<EMarketMode> marketModes;
  35. h & marketModes;
  36. }
  37. h & marketEfficiency;
  38. if (h.version < Handler::Version::NEW_MARKETS)
  39. {
  40. std::string speech;
  41. std::string title;
  42. h & speech;
  43. h & title;
  44. }
  45. }
  46. template <typename Handler> void serializeArtifactsAltar(Handler &h)
  47. {
  48. serialize(h);
  49. IMarket::serializeArtifactsAltar(h);
  50. }
  51. };
  52. class DLL_LINKAGE CGBlackMarket : public CGMarket
  53. {
  54. public:
  55. using CGMarket::CGMarket;
  56. std::vector<const CArtifact *> artifacts; //available artifacts
  57. void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
  58. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  59. template <typename Handler> void serialize(Handler &h)
  60. {
  61. h & static_cast<CGMarket&>(*this);
  62. h & artifacts;
  63. }
  64. };
  65. class DLL_LINKAGE CGUniversity : public CGMarket
  66. {
  67. public:
  68. using CGMarket::CGMarket;
  69. std::string speech; //currently shown only in university
  70. std::string title;
  71. std::vector<TradeItemBuy> skills; //available skills
  72. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  73. void onHeroVisit(const CGHeroInstance * h) const override; //open window
  74. template <typename Handler> void serialize(Handler &h)
  75. {
  76. h & static_cast<CGMarket&>(*this);
  77. h & skills;
  78. if (h.version >= Handler::Version::NEW_MARKETS)
  79. {
  80. h & speech;
  81. h & title;
  82. }
  83. }
  84. };
  85. VCMI_LIB_NAMESPACE_END