mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Change Callback to abstract
This commit is contained in:
parent
dfb078a4d9
commit
333e7d683c
@ -1385,7 +1385,7 @@ void AIGateway::tryRealize(Goals::Trade & g) //trade
|
||||
//TODO trade only as much as needed
|
||||
if (toGive) //don't try to sell 0 resources
|
||||
{
|
||||
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, res, g.resID, toGive);
|
||||
cb->trade(m, EMarketMode::RESOURCE_RESOURCE, res, g.resID, toGive);
|
||||
accquiredResources = static_cast<int>(toGet * (it->resVal / toGive));
|
||||
logAi->debug("Traded %d of %s for %d of %s at %s", toGive, res, accquiredResources, g.resID, obj->getObjectName());
|
||||
}
|
||||
|
@ -2130,7 +2130,7 @@ void VCAI::tryRealize(Goals::Trade & g) //trade
|
||||
//TODO trade only as much as needed
|
||||
if (toGive) //don't try to sell 0 resources
|
||||
{
|
||||
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, res, g.resID, toGive);
|
||||
cb->trade(m, EMarketMode::RESOURCE_RESOURCE, res, g.resID, toGive);
|
||||
accquiredResources = static_cast<int>(toGet * (it->resVal / toGive));
|
||||
logAi->debug("Traded %d of %s for %d of %s at %s", toGive, res, accquiredResources, g.resID, obj->getObjectName());
|
||||
}
|
||||
|
@ -244,15 +244,15 @@ void CCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid)
|
||||
sendRequest(&pack);
|
||||
}
|
||||
|
||||
void CCallback::trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero)
|
||||
void CCallback::trade(const IMarket * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero)
|
||||
{
|
||||
trade(market, mode, std::vector<ui32>(1, id1), std::vector<ui32>(1, id2), std::vector<ui32>(1, val1), hero);
|
||||
}
|
||||
|
||||
void CCallback::trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero)
|
||||
void CCallback::trade(const IMarket * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero)
|
||||
{
|
||||
TradeOnMarketplace pack;
|
||||
pack.marketId = market->id;
|
||||
pack.marketId = dynamic_cast<const CGObjectInstance *>(market)->id;
|
||||
pack.heroId = hero ? hero->id : ObjectInstanceID();
|
||||
pack.mode = mode;
|
||||
pack.r1 = id1;
|
||||
|
@ -33,6 +33,7 @@ class IBattleEventsReceiver;
|
||||
class IGameEventsReceiver;
|
||||
struct ArtifactLocation;
|
||||
class BattleStateInfoForRetreat;
|
||||
class IMarket;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
@ -73,8 +74,8 @@ public:
|
||||
virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made
|
||||
virtual void swapGarrisonHero(const CGTownInstance *town)=0;
|
||||
|
||||
virtual void trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero = nullptr)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
|
||||
virtual void trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr)=0;
|
||||
virtual void trade(const IMarket * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero = nullptr)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
|
||||
virtual void trade(const IMarket * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr)=0;
|
||||
|
||||
virtual int selectionMade(int selection, QueryID queryID) =0;
|
||||
virtual int sendQueryReply(const JsonNode & reply, QueryID queryID) =0;
|
||||
@ -168,8 +169,8 @@ public:
|
||||
void endTurn() override;
|
||||
void swapGarrisonHero(const CGTownInstance *town) override;
|
||||
void buyArtifact(const CGHeroInstance *hero, ArtifactID aid) override;
|
||||
void trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero = nullptr) override;
|
||||
void trade(const CGObjectInstance * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr) override;
|
||||
void trade(const IMarket * market, EMarketMode::EMarketMode mode, ui32 id1, ui32 id2, ui32 val1, const CGHeroInstance * hero = nullptr) override;
|
||||
void trade(const IMarket * market, EMarketMode::EMarketMode mode, const std::vector<ui32> & id1, const std::vector<ui32> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr) override;
|
||||
void setFormation(const CGHeroInstance * hero, bool tight) override;
|
||||
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero) override;
|
||||
void save(const std::string &fname) override;
|
||||
|
@ -832,15 +832,14 @@ void CMarketplaceWindow::makeDeal()
|
||||
|
||||
if(allowDeal)
|
||||
{
|
||||
const auto * o = dynamic_cast<const CGObjectInstance *>(market);
|
||||
if(slider)
|
||||
{
|
||||
LOCPLINT->cb->trade(o, mode, leftIdToSend, hRight->id, slider->getValue() * r1, hero);
|
||||
LOCPLINT->cb->trade(market, mode, leftIdToSend, hRight->id, slider->getValue() * r1, hero);
|
||||
slider->moveTo(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOCPLINT->cb->trade(o, mode, leftIdToSend, hRight->id, r2, hero);
|
||||
LOCPLINT->cb->trade(market, mode, leftIdToSend, hRight->id, r2, hero);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1240,7 +1239,7 @@ void CAltarWindow::makeDeal()
|
||||
}
|
||||
}
|
||||
|
||||
LOCPLINT->cb->trade(dynamic_cast<const CGObjectInstance *>(market), mode, ids, {}, toSacrifice, hero);
|
||||
LOCPLINT->cb->trade(market, mode, ids, {}, toSacrifice, hero);
|
||||
|
||||
for(int& val : sacrificedUnits)
|
||||
val = 0;
|
||||
@ -1259,7 +1258,7 @@ void CAltarWindow::makeDeal()
|
||||
positions.push_back(hero->getArtPos(art));
|
||||
}
|
||||
|
||||
LOCPLINT->cb->trade(dynamic_cast<const CGObjectInstance *>(market), mode, positions, {}, {}, hero);
|
||||
LOCPLINT->cb->trade(market, mode, positions, {}, {}, hero);
|
||||
arts->artifactsOnAltar.clear();
|
||||
|
||||
for(auto item : items[0])
|
||||
|
Loading…
Reference in New Issue
Block a user