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

134 lines
3.1 KiB
C++
Raw Normal View History

/*
* CGMarket.cpp, 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
*
*/
#include "StdInc.h"
#include "CGMarket.h"
#include "../texts/CGeneralTextHandler.h"
#include "../IGameCallback.h"
#include "../CCreatureHandler.h"
#include "CGTownInstance.h"
#include "../IGameSettings.h"
#include "../CSkillHandler.h"
#include "../mapObjectConstructors/AObjectTypeHandler.h"
#include "../mapObjectConstructors/CObjectClassesHandler.h"
#include "../mapObjectConstructors/CommonConstructors.h"
#include "../networkPacks/PacksForClient.h"
VCMI_LIB_NAMESPACE_BEGIN
2024-08-20 16:15:50 +02:00
ObjectInstanceID CGMarket::getObjInstanceID() const
{
return id;
}
void CGMarket::initObj(vstd::RNG & rand)
2023-04-28 03:16:10 +02:00
{
getObjectHandler()->configureObject(this, rand);
2023-04-28 03:16:10 +02:00
}
void CGMarket::onHeroVisit(const CGHeroInstance * h) const
{
cb->showObjectWindow(this, EOpenWindowMode::MARKET_WINDOW, h, true);
}
std::string CGMarket::getPopupText(PlayerColor player) const
{
if (!getMarketHandler()->hasDescription())
return getHoverText(player);
MetaString message = MetaString::createFromRawString("{%s}\r\n\r\n%s");
message.replaceName(ID);
message.replaceTextID(TextIdentifier(getObjectHandler()->getBaseTextID(), "description").get());
return message.toString();
}
std::string CGMarket::getPopupText(const CGHeroInstance * hero) const
{
return getPopupText(hero->getOwner());
}
int CGMarket::getMarketEfficiency() const
{
return marketEfficiency;
}
int CGMarket::availableUnits(EMarketMode mode, int marketItemSerial) const
{
return -1;
}
std::shared_ptr<MarketInstanceConstructor> CGMarket::getMarketHandler() const
{
const auto & baseHandler = getObjectHandler();
const auto & ourHandler = std::dynamic_pointer_cast<MarketInstanceConstructor>(baseHandler);
return ourHandler;
}
std::set<EMarketMode> CGMarket::availableModes() const
{
return getMarketHandler()->availableModes();
}
2024-01-01 16:37:48 +02:00
CGMarket::CGMarket(IGameCallback *cb):
CGObjectInstance(cb)
{}
std::vector<TradeItemBuy> CGBlackMarket::availableItemsIds(EMarketMode mode) const
{
switch(mode)
{
case EMarketMode::RESOURCE_ARTIFACT:
{
std::vector<TradeItemBuy> ret;
for(const auto & a : artifacts)
ret.push_back(a);
return ret;
}
default:
return std::vector<TradeItemBuy>();
}
}
void CGBlackMarket::newTurn(vstd::RNG & rand) const
{
int resetPeriod = cb->getSettings().getInteger(EGameSettings::MARKETS_BLACK_MARKET_RESTOCK_PERIOD);
2023-04-19 22:11:17 +02:00
bool isFirstDay = cb->getDate(Date::DAY) == 1;
bool regularResetTriggered = resetPeriod != 0 && ((cb->getDate(Date::DAY)-1) % resetPeriod) == 0;
2023-04-19 22:11:17 +02:00
if (!isFirstDay && !regularResetTriggered)
return;
SetAvailableArtifacts saa;
saa.id = id;
cb->pickAllowedArtsSet(saa.arts, rand);
cb->sendAndApply(saa);
}
std::vector<TradeItemBuy> CGUniversity::availableItemsIds(EMarketMode mode) const
{
switch (mode)
{
case EMarketMode::RESOURCE_SKILL:
return skills;
default:
return std::vector<TradeItemBuy>();
}
}
void CGUniversity::onHeroVisit(const CGHeroInstance * h) const
{
cb->showObjectWindow(this, EOpenWindowMode::UNIVERSITY_WINDOW, h, true);
}
VCMI_LIB_NAMESPACE_END