1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/mapObjects/CGMarket.h

132 lines
3.0 KiB
C++
Raw Normal View History

/*
* CGMarket.h, part of VCMI engine
*
* 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
*
*/
#pragma once
#include "CGObjectInstance.h"
#include "IMarket.h"
2024-01-12 23:57:19 +02:00
#include "../CArtHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
class MarketInstanceConstructor;
class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
{
protected:
std::shared_ptr<MarketInstanceConstructor> getMarketHandler() const;
public:
2024-01-01 16:37:48 +02:00
CGMarket(IGameCallback *cb);
2023-04-28 03:16:10 +02:00
///IObjectInterface
void onHeroVisit(const CGHeroInstance * h) const override; //open trading window
void initObj(vstd::RNG & rand) override;//set skills for trade
std::string getPopupText(PlayerColor player) const override;
std::string getPopupText(const CGHeroInstance * hero) const override;
///IMarket
2024-08-20 16:15:50 +02:00
ObjectInstanceID getObjInstanceID() const override;
int getMarketEfficiency() const override;
int availableUnits(EMarketMode mode, int marketItemSerial) const override; //-1 if unlimited
std::set<EMarketMode> availableModes() const override;
template <typename Handler>
void serialize(Handler &h)
{
h & static_cast<CGObjectInstance&>(*this);
if (h.version < Handler::Version::NEW_MARKETS)
{
std::set<EMarketMode> marketModes;
h & marketModes;
}
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);
IMarket::serializeArtifactsAltar(h);
}
};
class DLL_LINKAGE CGBlackMarket : public CGMarket
{
public:
2024-01-01 16:37:48 +02:00
using CGMarket::CGMarket;
std::vector<ArtifactID> artifacts; //available artifacts
void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
template <typename Handler> void serialize(Handler &h)
{
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;
}
}
};
class DLL_LINKAGE CGUniversity : public CGMarket
{
public:
2024-01-01 16:37:48 +02:00
using CGMarket::CGMarket;
std::string getSpeechTranslated() const;
2024-01-01 16:37:48 +02:00
std::vector<TradeItemBuy> skills; //available skills
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;
void onHeroVisit(const CGHeroInstance * h) const override; //open window
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<CGMarket&>(*this);
h & skills;
if (h.version >= Handler::Version::NEW_MARKETS && h.version < Handler::Version::MARKET_TRANSLATION_FIX)
2024-08-26 22:52:37 +02:00
{
std::string temp;
h & temp;
h & temp;
2024-08-26 22:52:37 +02:00
}
}
};
VCMI_LIB_NAMESPACE_END