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"
|
2023-03-15 21:34:29 +02:00
|
|
|
#include "../GameSettings.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"
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
bool CGMarket::allowsTrade(EMarketMode mode) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-04-28 03:16:10 +02:00
|
|
|
return marketModes.count(mode);
|
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;
|
|
|
|
}
|
|
|
|
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> CGMarket::availableItemsIds(EMarketMode mode) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-04-28 03:16:10 +02:00
|
|
|
if(allowsTrade(mode))
|
2014-06-05 19:52:14 +03:00
|
|
|
return IMarket::availableItemsIds(mode);
|
2023-11-08 17:49:08 +02:00
|
|
|
return std::vector<TradeItemBuy>();
|
2014-06-05 19:52:14 +03: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::ARTIFACT_RESOURCE:
|
|
|
|
return IMarket::availableItemsIds(mode);
|
|
|
|
case EMarketMode::RESOURCE_ARTIFACT:
|
|
|
|
{
|
2023-11-08 17:49:08 +02:00
|
|
|
std::vector<TradeItemBuy> ret;
|
2014-06-05 19:52:14 +03:00
|
|
|
for(const CArtifact *a : artifacts)
|
|
|
|
if(a)
|
2023-01-02 15:58:56 +02:00
|
|
|
ret.push_back(a->getId());
|
2014-06-05 19:52:14 +03:00
|
|
|
else
|
2023-11-08 17:49:08 +02:00
|
|
|
ret.push_back(ArtifactID{});
|
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
|
|
|
{
|
2023-03-15 23:47:26 +02:00
|
|
|
int resetPeriod = VLC->settings()->getInteger(EGameSettings::MARKETS_BLACK_MARKET_RESTOCK_PERIOD);
|
|
|
|
|
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);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->sendAndApply(&saa);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-01-12 23:57:19 +02:00
|
|
|
ArtBearer::ArtBearer CGArtifactsAltar::bearerType() const
|
|
|
|
{
|
|
|
|
return ArtBearer::ALTAR;
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|