2015-12-02 21:05:10 +02:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CGMarket.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CGMarket.h"
|
|
|
|
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../texts/CGeneralTextHandler.h"
|
2014-06-25 17:11:07 +03:00
|
|
|
#include "../IGameCallback.h"
|
|
|
|
#include "../CCreatureHandler.h"
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "CGTownInstance.h"
|
2024-08-31 13:00:36 +02:00
|
|
|
#include "../IGameSettings.h"
|
2018-03-31 07:56:40 +02:00
|
|
|
#include "../CSkillHandler.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
|
|
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
2024-08-27 15:44:30 +02:00
|
|
|
#include "../mapObjectConstructors/CommonConstructors.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../networkPacks/PacksForClient.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-08-20 16:15:50 +02:00
|
|
|
ObjectInstanceID CGMarket::getObjInstanceID() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void CGMarket::initObj(vstd::RNG & rand)
|
2023-04-28 03:16:10 +02:00
|
|
|
{
|
2023-10-24 16:11:25 +02:00
|
|
|
getObjectHandler()->configureObject(this, rand);
|
2023-04-28 03:16:10 +02:00
|
|
|
}
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void CGMarket::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
2023-09-28 00:17:05 +02:00
|
|
|
cb->showObjectWindow(this, EOpenWindowMode::MARKET_WINDOW, h, true);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2024-10-30 15:20:21 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
int CGMarket::getMarketEfficiency() const
|
|
|
|
{
|
2023-05-01 02:07:31 +02:00
|
|
|
return marketEfficiency;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-08-19 20:43:50 +02:00
|
|
|
int CGMarket::availableUnits(EMarketMode mode, int marketItemSerial) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-10-30 15:20:21 +02:00
|
|
|
std::shared_ptr<MarketInstanceConstructor> CGMarket::getMarketHandler() const
|
2024-08-27 15:44:30 +02:00
|
|
|
{
|
|
|
|
const auto & baseHandler = getObjectHandler();
|
|
|
|
const auto & ourHandler = std::dynamic_pointer_cast<MarketInstanceConstructor>(baseHandler);
|
2024-10-30 15:20:21 +02:00
|
|
|
return ourHandler;
|
|
|
|
}
|
2024-08-27 15:44:30 +02:00
|
|
|
|
2024-10-30 15:20:21 +02:00
|
|
|
std::set<EMarketMode> CGMarket::availableModes() const
|
|
|
|
{
|
|
|
|
return getMarketHandler()->availableModes();
|
2024-08-27 15:44:30 +02:00
|
|
|
}
|
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
CGMarket::CGMarket(IGameCallback *cb):
|
|
|
|
CGObjectInstance(cb)
|
|
|
|
{}
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> CGBlackMarket::availableItemsIds(EMarketMode mode) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case EMarketMode::RESOURCE_ARTIFACT:
|
|
|
|
{
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> ret;
|
2024-10-12 20:19:58 +02:00
|
|
|
for(const auto & a : artifacts)
|
|
|
|
ret.push_back(a);
|
2014-06-05 19:52:14 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
default:
|
2023-11-08 17:49:08 +02:00
|
|
|
return std::vector<TradeItemBuy>();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-01 17:28:17 +02:00
|
|
|
void CGBlackMarket::newTurn(vstd::RNG & rand) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2024-08-31 13:00:36 +02:00
|
|
|
int resetPeriod = cb->getSettings().getInteger(EGameSettings::MARKETS_BLACK_MARKET_RESTOCK_PERIOD);
|
2023-03-15 23:47:26 +02:00
|
|
|
|
2023-04-19 22:11:17 +02:00
|
|
|
bool isFirstDay = cb->getDate(Date::DAY) == 1;
|
2024-08-17 11:59:15 +02:00
|
|
|
bool regularResetTriggered = resetPeriod != 0 && ((cb->getDate(Date::DAY)-1) % resetPeriod) == 0;
|
2017-07-14 23:46:18 +02:00
|
|
|
|
2023-04-19 22:11:17 +02:00
|
|
|
if (!isFirstDay && !regularResetTriggered)
|
2014-06-05 19:52:14 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
SetAvailableArtifacts saa;
|
2023-11-06 18:27:16 +02:00
|
|
|
saa.id = id;
|
2016-09-09 19:30:36 +02:00
|
|
|
cb->pickAllowedArtsSet(saa.arts, rand);
|
2024-10-04 20:59:51 +02:00
|
|
|
cb->sendAndApply(saa);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> CGUniversity::availableItemsIds(EMarketMode mode) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case EMarketMode::RESOURCE_SKILL:
|
|
|
|
return skills;
|
|
|
|
|
|
|
|
default:
|
2023-11-08 17:49:08 +02:00
|
|
|
return std::vector<TradeItemBuy>();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGUniversity::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
2023-09-28 00:17:05 +02:00
|
|
|
cb->showObjectWindow(this, EOpenWindowMode::UNIVERSITY_WINDOW, h, true);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|