CGMarket.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. template <typename Handler> void serialize(Handler &h)
  28. {
  29. h & static_cast<CGObjectInstance&>(*this);
  30. h & static_cast<IMarket&>(*this);
  31. h & marketEfficiency;
  32. if (h.version < Handler::Version::NEW_MARKETS)
  33. {
  34. std::string speech;
  35. std::string title;
  36. h & speech;
  37. h & title;
  38. }
  39. }
  40. template <typename Handler> void serializeArtifactsAltar(Handler &h)
  41. {
  42. serialize(h);
  43. IMarket::serializeArtifactsAltar(h);
  44. }
  45. };
  46. class DLL_LINKAGE CGBlackMarket : public CGMarket
  47. {
  48. public:
  49. using CGMarket::CGMarket;
  50. std::vector<const CArtifact *> artifacts; //available artifacts
  51. void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
  52. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  53. template <typename Handler> void serialize(Handler &h)
  54. {
  55. h & static_cast<CGMarket&>(*this);
  56. h & artifacts;
  57. }
  58. };
  59. class DLL_LINKAGE CGUniversity : public CGMarket
  60. {
  61. public:
  62. using CGMarket::CGMarket;
  63. std::string speech; //currently shown only in university
  64. std::string title;
  65. std::vector<TradeItemBuy> skills; //available skills
  66. std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
  67. void onHeroVisit(const CGHeroInstance * h) const override; //open window
  68. template <typename Handler> void serialize(Handler &h)
  69. {
  70. h & static_cast<CGMarket&>(*this);
  71. h & skills;
  72. if (h.version >= Handler::Version::NEW_MARKETS)
  73. {
  74. h & speech;
  75. h & title;
  76. }
  77. }
  78. };
  79. VCMI_LIB_NAMESPACE_END