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"
|
|
|
|
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../NetPacks.h"
|
|
|
|
#include "../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"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-04-28 03:16:10 +02:00
|
|
|
void CGMarket::initObj(CRandomGenerator & rand)
|
|
|
|
{
|
|
|
|
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
|
|
|
|
}
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void CGMarket::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
2023-04-28 03:16:10 +02:00
|
|
|
openWindow(EOpenWindowMode::MARKET_WINDOW, id.getNum(), h->id.getNum());
|
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-08-19 20:43:50 +02:00
|
|
|
std::vector<int> 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-04-28 03:16:10 +02:00
|
|
|
return std::vector<int>();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CGMarket::CGMarket()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-19 20:43:50 +02:00
|
|
|
std::vector<int> 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:
|
|
|
|
{
|
|
|
|
std::vector<int> ret;
|
|
|
|
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
|
|
|
|
ret.push_back(-1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return std::vector<int>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGBlackMarket::newTurn(CRandomGenerator & 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;
|
|
|
|
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;
|
|
|
|
saa.id = id.getNum();
|
2016-09-09 19:30:36 +02:00
|
|
|
cb->pickAllowedArtsSet(saa.arts, rand);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->sendAndApply(&saa);
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGUniversity::initObj(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-04-28 03:16:10 +02:00
|
|
|
CGMarket::initObj(rand);
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
std::vector<int> toChoose;
|
2018-03-31 07:56:40 +02:00
|
|
|
for(int i = 0; i < VLC->skillh->size(); ++i)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-04-28 03:16:10 +02:00
|
|
|
if(!vstd::contains(skills, i) && cb->isAllowed(2, i))
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
toChoose.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-19 20:43:50 +02:00
|
|
|
std::vector<int> CGUniversity::availableItemsIds(EMarketMode mode) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case EMarketMode::RESOURCE_SKILL:
|
|
|
|
return skills;
|
|
|
|
|
|
|
|
default:
|
2023-04-28 03:16:10 +02:00
|
|
|
return std::vector<int>();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGUniversity::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
2023-03-08 00:32:21 +02:00
|
|
|
openWindow(EOpenWindowMode::UNIVERSITY_WINDOW,id.getNum(),h->id.getNum());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|