mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Remove excess pointer from market interface
This commit is contained in:
parent
ac09f78c67
commit
59bc9326e9
@ -149,9 +149,10 @@ TSubgoal CollectRes::whatToDoToTrade()
|
||||
|
||||
markets.erase(boost::remove_if(markets, [](const IMarket * market) -> bool
|
||||
{
|
||||
if (!(market->o->ID == Obj::TOWN && market->o->tempOwner == ai->playerID))
|
||||
auto * o = dynamic_cast<const CGObjectInstance *>(market);
|
||||
if(o && !(o->ID == Obj::TOWN && o->tempOwner == ai->playerID))
|
||||
{
|
||||
if (!ai->isAccessible(market->o->visitablePos()))
|
||||
if(!ai->isAccessible(o->visitablePos()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -182,9 +183,10 @@ TSubgoal CollectRes::whatToDoToTrade()
|
||||
|
||||
if (howManyCanWeBuy >= value)
|
||||
{
|
||||
auto backObj = cb->getTopObj(m->o->visitablePos()); //it'll be a hero if we have one there; otherwise marketplace
|
||||
auto * o = dynamic_cast<const CGObjectInstance *>(m);
|
||||
auto backObj = cb->getTopObj(o->visitablePos()); //it'll be a hero if we have one there; otherwise marketplace
|
||||
assert(backObj);
|
||||
auto objid = m->o->id.getNum();
|
||||
auto objid = o->id.getNum();
|
||||
if (backObj->tempOwner != ai->playerID) //top object not owned
|
||||
{
|
||||
return sptr(VisitObj(objid)); //just go there
|
||||
|
@ -1709,7 +1709,8 @@ void CPlayerInterface::stopMovement()
|
||||
void CPlayerInterface::showMarketWindow(const IMarket *market, const CGHeroInstance *visitor)
|
||||
{
|
||||
EVENT_HANDLER_CALLED_BY_CLIENT;
|
||||
if (market->o->ID == Obj::ALTAR_OF_SACRIFICE)
|
||||
auto * o = dynamic_cast<const CGObjectInstance *>(market);
|
||||
if(o && o->ID == Obj::ALTAR_OF_SACRIFICE)
|
||||
{
|
||||
//EEMarketMode mode = market->availableModes().front();
|
||||
if (market->allowsTrade(EMarketMode::ARTIFACT_EXP) && visitor->getAlignment() != EAlignment::EVIL)
|
||||
|
@ -679,7 +679,7 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta
|
||||
|
||||
std::string title;
|
||||
|
||||
if(market->o->ID == Obj::TOWN)
|
||||
if(auto * o = dynamic_cast<const CGTownInstance *>(market))
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
@ -687,11 +687,11 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta
|
||||
title = (*CGI->townh)[ETownType::STRONGHOLD]->town->buildings[BuildingID::FREELANCERS_GUILD]->getNameTranslated();
|
||||
break;
|
||||
case EMarketMode::RESOURCE_ARTIFACT:
|
||||
title = (*CGI->townh)[market->o->subID]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated();
|
||||
title = (*CGI->townh)[o->subID]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated();
|
||||
sliderNeeded = false;
|
||||
break;
|
||||
case EMarketMode::ARTIFACT_RESOURCE:
|
||||
title = (*CGI->townh)[market->o->subID]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated();
|
||||
title = (*CGI->townh)[o->subID]->town->buildings[BuildingID::ARTIFACT_MERCHANT]->getNameTranslated();
|
||||
|
||||
// create image that copies part of background containing slot MISC_1 into position of slot MISC_5
|
||||
// this is workaround for bug in H3 files where this slot for ragdoll on this screen is missing
|
||||
@ -705,21 +705,24 @@ CMarketplaceWindow::CMarketplaceWindow(const IMarket * Market, const CGHeroInsta
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(market->o->ID)
|
||||
if(auto * o = dynamic_cast<const CGObjectInstance *>(market))
|
||||
{
|
||||
case Obj::BLACK_MARKET:
|
||||
title = CGI->generaltexth->allTexts[349];
|
||||
sliderNeeded = false;
|
||||
break;
|
||||
case Obj::TRADING_POST:
|
||||
title = CGI->generaltexth->allTexts[159];
|
||||
break;
|
||||
case Obj::TRADING_POST_SNOW:
|
||||
title = CGI->generaltexth->allTexts[159];
|
||||
break;
|
||||
default:
|
||||
title = market->o->getObjectName();
|
||||
break;
|
||||
switch(o->ID)
|
||||
{
|
||||
case Obj::BLACK_MARKET:
|
||||
title = CGI->generaltexth->allTexts[349];
|
||||
sliderNeeded = false;
|
||||
break;
|
||||
case Obj::TRADING_POST:
|
||||
title = CGI->generaltexth->allTexts[159];
|
||||
break;
|
||||
case Obj::TRADING_POST_SNOW:
|
||||
title = CGI->generaltexth->allTexts[159];
|
||||
break;
|
||||
default:
|
||||
title = o->getObjectName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -838,14 +841,15 @@ void CMarketplaceWindow::makeDeal()
|
||||
|
||||
if(allowDeal)
|
||||
{
|
||||
const auto * o = dynamic_cast<const CGObjectInstance *>(market);
|
||||
if(slider)
|
||||
{
|
||||
LOCPLINT->cb->trade(market->o, mode, leftIdToSend, hRight->id, slider->getValue() * r1, hero);
|
||||
LOCPLINT->cb->trade(o, mode, leftIdToSend, hRight->id, slider->getValue() * r1, hero);
|
||||
slider->moveTo(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->cb->trade(market->o, mode, leftIdToSend, hRight->id, r2, hero);
|
||||
LOCPLINT->cb->trade(o, mode, leftIdToSend, hRight->id, r2, hero);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1245,7 +1249,7 @@ void CAltarWindow::makeDeal()
|
||||
}
|
||||
}
|
||||
|
||||
LOCPLINT->cb->trade(market->o, mode, ids, {}, toSacrifice, hero);
|
||||
LOCPLINT->cb->trade(dynamic_cast<const CGObjectInstance *>(market), mode, ids, {}, toSacrifice, hero);
|
||||
|
||||
for(int& val : sacrificedUnits)
|
||||
val = 0;
|
||||
@ -1266,8 +1270,8 @@ void CAltarWindow::makeDeal()
|
||||
}
|
||||
std::sort(positions.begin(), positions.end(), std::greater<>());
|
||||
|
||||
LOCPLINT->cb->trade(market->o, mode, positions, {}, {}, hero);
|
||||
artifactsOfHero->artifactsOnAltar.clear();
|
||||
LOCPLINT->cb->trade(dynamic_cast<const CGObjectInstance *>(market), mode, positions, {}, {}, hero);
|
||||
arts->artifactsOnAltar.clear();
|
||||
|
||||
for(auto item : items[0])
|
||||
{
|
||||
|
@ -1288,18 +1288,11 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket
|
||||
bars->setCustom("UNIVGREN", 2, 0);
|
||||
bars->preload();
|
||||
|
||||
if(market->o->ID == Obj::TOWN)
|
||||
if(auto town = dynamic_cast<const CGTownInstance *>(_market))
|
||||
{
|
||||
auto town = dynamic_cast<const CGTownInstance *>(_market);
|
||||
|
||||
if(town)
|
||||
{
|
||||
auto faction = town->town->faction->getId();
|
||||
auto bid = town->town->getSpecialBuilding(BuildingSubID::MAGIC_UNIVERSITY)->bid;
|
||||
titlePic = std::make_shared<CAnimImage>((*CGI->townh)[faction]->town->clientInfo.buildingsIcons, bid);
|
||||
}
|
||||
else
|
||||
titlePic = std::make_shared<CAnimImage>((*CGI->townh)[ETownType::CONFLUX]->town->clientInfo.buildingsIcons, BuildingID::MAGIC_UNIVERSITY);
|
||||
auto faction = town->town->faction->getId();
|
||||
auto bid = town->town->getSpecialBuilding(BuildingSubID::MAGIC_UNIVERSITY)->bid;
|
||||
titlePic = std::make_shared<CAnimImage>((*CGI->townh)[faction]->town->clientInfo.buildingsIcons, bid);
|
||||
}
|
||||
else
|
||||
titlePic = std::make_shared<CPicture>("UNIVBLDG");
|
||||
@ -1321,7 +1314,7 @@ CUniversityWindow::CUniversityWindow(const CGHeroInstance * _hero, const IMarket
|
||||
|
||||
void CUniversityWindow::makeDeal(int skill)
|
||||
{
|
||||
LOCPLINT->cb->trade(market->o, EMarketMode::RESOURCE_SKILL, 6, skill, 1, hero);
|
||||
LOCPLINT->cb->trade(dynamic_cast<const CGObjectInstance *>(market), EMarketMode::RESOURCE_SKILL, 6, skill, 1, hero);
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,10 +177,8 @@ const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose)
|
||||
}
|
||||
}
|
||||
|
||||
IMarket::IMarket(const CGObjectInstance *O)
|
||||
:o(O)
|
||||
IMarket::IMarket()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<EMarketMode::EMarketMode> IMarket::availableModes() const
|
||||
@ -250,7 +248,6 @@ std::vector<int> CGMarket::availableItemsIds(EMarketMode::EMarketMode mode) cons
|
||||
}
|
||||
|
||||
CGMarket::CGMarket()
|
||||
:IMarket(this)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,10 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
class DLL_LINKAGE IMarket
|
||||
{
|
||||
public:
|
||||
const CGObjectInstance *o;
|
||||
|
||||
IMarket(const CGObjectInstance *O);
|
||||
IMarket();
|
||||
virtual ~IMarket() {}
|
||||
|
||||
virtual int getMarketEfficiency() const =0;
|
||||
virtual int getMarketEfficiency() const = 0;
|
||||
virtual bool allowsTrade(EMarketMode::EMarketMode mode) const;
|
||||
virtual int availableUnits(EMarketMode::EMarketMode mode, int marketItemSerial) const; //-1 if unlimited
|
||||
virtual std::vector<int> availableItemsIds(EMarketMode::EMarketMode mode) const;
|
||||
@ -30,11 +28,6 @@ public:
|
||||
std::vector<EMarketMode::EMarketMode> availableModes() const;
|
||||
|
||||
static const IMarket *castFrom(const CGObjectInstance *obj, bool verbose = true);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & o;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_LINKAGE CGMarket : public CGObjectInstance, public IMarket
|
||||
@ -53,7 +46,6 @@ public:
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CGObjectInstance&>(*this);
|
||||
h & static_cast<IMarket&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -220,7 +220,7 @@ bool CGTownInstance::hasCapitol() const
|
||||
|
||||
CGTownInstance::CGTownInstance():
|
||||
IShipyard(this),
|
||||
IMarket(this),
|
||||
IMarket(),
|
||||
town(nullptr),
|
||||
builded(0),
|
||||
destroyed(0),
|
||||
@ -365,23 +365,6 @@ bool CGTownInstance::isBonusingBuildingAdded(BuildingID::EBuildingID bid) const
|
||||
return present != bonusingBuildings.end();
|
||||
}
|
||||
|
||||
//it does not check hasBuilt because this check is in the OnHeroVisit handler
|
||||
void CGTownInstance::tryAddOnePerWeekBonus(BuildingSubID::EBuildingSubID subID)
|
||||
{
|
||||
auto bid = town->getBuildingType(subID);
|
||||
|
||||
if(bid != BuildingID::NONE && !isBonusingBuildingAdded(bid))
|
||||
bonusingBuildings.push_back(new COPWBonus(bid, subID, this));
|
||||
}
|
||||
|
||||
void CGTownInstance::tryAddVisitingBonus(BuildingSubID::EBuildingSubID subID)
|
||||
{
|
||||
auto bid = town->getBuildingType(subID);
|
||||
|
||||
if(bid != BuildingID::NONE && !isBonusingBuildingAdded(bid))
|
||||
bonusingBuildings.push_back(new CTownBonus(bid, subID, this));
|
||||
}
|
||||
|
||||
void CGTownInstance::addTownBonuses()
|
||||
{
|
||||
for(const auto & kvp : town->buildings)
|
||||
@ -487,11 +470,6 @@ void CGTownInstance::initObj(CRandomGenerator & rand) ///initialize town structu
|
||||
updateAppearance();
|
||||
}
|
||||
|
||||
bool CGTownInstance::hasBuiltInOldWay(ETownType::ETownType type, const BuildingID & bid) const
|
||||
{
|
||||
return (this->town->faction != nullptr && this->town->faction->getIndex() == type && hasBuilt(bid));
|
||||
}
|
||||
|
||||
void CGTownInstance::newTurn(CRandomGenerator & rand) const
|
||||
{
|
||||
if (cb->getDate(Date::DAY_OF_WEEK) == 1) //reset on new week
|
||||
|
@ -74,7 +74,6 @@ public:
|
||||
{
|
||||
h & static_cast<CGDwelling&>(*this);
|
||||
h & static_cast<IShipyard&>(*this);
|
||||
h & static_cast<IMarket&>(*this);
|
||||
h & name;
|
||||
h & builded;
|
||||
h & destroyed;
|
||||
@ -212,11 +211,8 @@ private:
|
||||
void setOwner(const PlayerColor & owner) const;
|
||||
void onTownCaptured(const PlayerColor & winner) const;
|
||||
int getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<ConstTransitivePtr<CGDwelling> >& dwellings) const;
|
||||
bool hasBuiltInOldWay(ETownType::ETownType type, const BuildingID & bid) const;
|
||||
bool townEnvisagesBuilding(BuildingSubID::EBuildingSubID bid) const;
|
||||
bool isBonusingBuildingAdded(BuildingID::EBuildingID bid) const;
|
||||
void tryAddOnePerWeekBonus(BuildingSubID::EBuildingSubID subID);
|
||||
void tryAddVisitingBonus(BuildingSubID::EBuildingSubID subID);
|
||||
void initOverriddenBids();
|
||||
void addTownBonuses();
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ void registerTypesMapObjects1(Serializer &s)
|
||||
s.template registerType<CGObjectInstance, CGDenOfthieves>();
|
||||
s.template registerType<CGObjectInstance, CGLighthouse>();
|
||||
s.template registerType<CGObjectInstance, CGTerrainPatch>();
|
||||
s.template registerType<CGObjectInstance, CGMarket>(); s.template registerType<IMarket, CGMarket>();
|
||||
s.template registerType<CGObjectInstance, CGMarket>();
|
||||
s.template registerType<CGMarket, CGBlackMarket>();
|
||||
s.template registerType<CGMarket, CGUniversity>();
|
||||
s.template registerType<CGObjectInstance, CGHeroPlaceholder>();
|
||||
@ -67,7 +67,7 @@ void registerTypesMapObjects1(Serializer &s)
|
||||
// Armed objects
|
||||
s.template registerType<CArmedInstance, CGHeroInstance>(); s.template registerType<IBoatGenerator, CGHeroInstance>(); s.template registerType<CArtifactSet, CGHeroInstance>();
|
||||
s.template registerType<CArmedInstance, CGDwelling>();
|
||||
s.template registerType<CGDwelling, CGTownInstance>(); s.template registerType<IShipyard, CGTownInstance>(); s.template registerType<IMarket, CGTownInstance>();
|
||||
s.template registerType<CGDwelling, CGTownInstance>(); s.template registerType<IShipyard, CGTownInstance>();
|
||||
s.template registerType<CArmedInstance, CGPandoraBox>();
|
||||
s.template registerType<CGPandoraBox, CGEvent>();
|
||||
s.template registerType<CArmedInstance, CGCreature>();
|
||||
|
@ -4177,12 +4177,12 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, GameRe
|
||||
giveResource(h->tempOwner, rid, -b1);
|
||||
|
||||
SetAvailableArtifacts saa;
|
||||
if (m->o->ID == Obj::TOWN)
|
||||
if(dynamic_cast<const CGTownInstance *>(m))
|
||||
{
|
||||
saa.id = -1;
|
||||
saa.arts = CGTownInstance::merchantArtifacts;
|
||||
}
|
||||
else if (const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(m->o)) //black market
|
||||
else if(const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(m)) //black market
|
||||
{
|
||||
saa.id = bm->id.getNum();
|
||||
saa.arts = bm->artifacts;
|
||||
@ -4309,7 +4309,7 @@ bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance
|
||||
if (hero)
|
||||
army = hero;
|
||||
else
|
||||
army = dynamic_cast<const CGTownInstance *>(market->o);
|
||||
army = dynamic_cast<const CGTownInstance *>(market);
|
||||
|
||||
if (!army)
|
||||
COMPLAIN_RET("Incorrect call to transform in undead!");
|
||||
|
Loading…
Reference in New Issue
Block a user