2022-07-26 15:07:42 +02:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CGMarket.h, part of VCMI engine
|
2014-06-05 19:52:14 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "CGObjectInstance.h"
|
|
|
|
#include "IMarket.h"
|
2024-01-12 23:57:19 +02:00
|
|
|
#include "../CArtHandler.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-10-30 15:20:21 +02:00
|
|
|
class MarketInstanceConstructor;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
|
|
|
|
{
|
2024-11-19 16:38:27 +02:00
|
|
|
protected:
|
2024-10-30 15:20:21 +02:00
|
|
|
std::shared_ptr<MarketInstanceConstructor> getMarketHandler() const;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
CGMarket(IGameCallback *cb);
|
2023-04-28 03:16:10 +02:00
|
|
|
///IObjectInterface
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
|
2024-06-01 17:28:17 +02:00
|
|
|
void initObj(vstd::RNG & rand) override;//set skills for trade
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-10-30 15:20:21 +02:00
|
|
|
std::string getPopupText(PlayerColor player) const override;
|
|
|
|
std::string getPopupText(const CGHeroInstance * hero) const override;
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
///IMarket
|
2024-08-20 16:15:50 +02:00
|
|
|
ObjectInstanceID getObjInstanceID() const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
int getMarketEfficiency() const override;
|
2023-08-19 20:43:50 +02:00
|
|
|
int availableUnits(EMarketMode mode, int marketItemSerial) const override; //-1 if unlimited
|
2024-08-27 15:44:30 +02:00
|
|
|
std::set<EMarketMode> availableModes() const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-08-29 20:51:53 +02:00
|
|
|
template <typename Handler>
|
|
|
|
void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGObjectInstance&>(*this);
|
2024-08-27 15:44:30 +02:00
|
|
|
if (h.version < Handler::Version::NEW_MARKETS)
|
|
|
|
{
|
|
|
|
std::set<EMarketMode> marketModes;
|
|
|
|
h & marketModes;
|
|
|
|
}
|
|
|
|
|
2024-11-19 16:38:27 +02:00
|
|
|
if (h.version < Handler::Version::MARKET_TRANSLATION_FIX)
|
|
|
|
{
|
|
|
|
int unused = 0;
|
|
|
|
h & unused;
|
|
|
|
}
|
|
|
|
|
2024-08-26 22:52:37 +02:00
|
|
|
if (h.version < Handler::Version::NEW_MARKETS)
|
|
|
|
{
|
|
|
|
std::string speech;
|
|
|
|
std::string title;
|
|
|
|
h & speech;
|
|
|
|
h & title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Handler> void serializeArtifactsAltar(Handler &h)
|
|
|
|
{
|
|
|
|
serialize(h);
|
2024-08-29 20:51:53 +02:00
|
|
|
IMarket::serializeArtifactsAltar(h);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGBlackMarket : public CGMarket
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGMarket::CGMarket;
|
|
|
|
|
2024-10-12 20:19:58 +02:00
|
|
|
std::vector<ArtifactID> artifacts; //available artifacts
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGMarket&>(*this);
|
2024-11-07 14:08:08 +02:00
|
|
|
if (h.version < Handler::Version::REMOVE_VLC_POINTERS)
|
|
|
|
{
|
|
|
|
int32_t size = 0;
|
|
|
|
h & size;
|
|
|
|
for (int32_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
bool isNull = false;
|
|
|
|
ArtifactID artifact;
|
|
|
|
h & isNull;
|
|
|
|
if (!isNull)
|
|
|
|
h & artifact;
|
|
|
|
artifacts.push_back(artifact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h & artifacts;
|
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CGUniversity : public CGMarket
|
|
|
|
{
|
|
|
|
public:
|
2024-01-01 16:37:48 +02:00
|
|
|
using CGMarket::CGMarket;
|
2024-11-19 16:38:27 +02:00
|
|
|
|
|
|
|
std::string getSpeechTranslated() const;
|
2024-01-01 16:37:48 +02:00
|
|
|
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> skills; //available skills
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
|
2014-06-05 19:52:14 +03:00
|
|
|
void onHeroVisit(const CGHeroInstance * h) const override; //open window
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
h & static_cast<CGMarket&>(*this);
|
|
|
|
h & skills;
|
2024-11-19 16:38:27 +02:00
|
|
|
if (h.version >= Handler::Version::NEW_MARKETS && h.version < Handler::Version::MARKET_TRANSLATION_FIX)
|
2024-08-26 22:52:37 +02:00
|
|
|
{
|
2024-11-19 16:38:27 +02:00
|
|
|
std::string temp;
|
|
|
|
h & temp;
|
|
|
|
h & temp;
|
2024-08-26 22:52:37 +02:00
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|