mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
AI will not try to sell reserved resources.
This commit is contained in:
parent
2aa0a6fe2f
commit
9e34ef5534
@ -1086,7 +1086,7 @@ TSubgoal Goals::CollectRes::whatToDoToTrade()
|
||||
int toGive = -1, toReceive = -1;
|
||||
m->getOffer(i, resID, toGive, toReceive, EMarketMode::RESOURCE_RESOURCE);
|
||||
assert(toGive > 0 && toReceive > 0);
|
||||
howManyCanWeBuy += toReceive * (cb->getResourceAmount(i) / toGive);
|
||||
howManyCanWeBuy += toReceive * (ah->freeResources()[i] / toGive);
|
||||
}
|
||||
|
||||
if (howManyCanWeBuy >= value)
|
||||
|
@ -2171,20 +2171,22 @@ void VCAI::tryRealize(Goals::Trade & g) //trade
|
||||
{
|
||||
if(const IMarket * m = IMarket::castFrom(obj, false))
|
||||
{
|
||||
for(Res::ERes i = Res::WOOD; i <= Res::GOLD; vstd::advance(i, 1))
|
||||
auto freeRes = ah->freeResources(); //trade only resources which are not reserved
|
||||
for(auto it = Res::ResourceSet::nziterator(freeRes); it.valid(); it++)
|
||||
{
|
||||
if(i == g.resID) //sell any other resource
|
||||
auto res = it->resType;
|
||||
if(res == g.resID) //sell any other resource
|
||||
continue;
|
||||
//TODO: check all our reserved resources and avoid them
|
||||
|
||||
int toGive, toGet;
|
||||
m->getOffer(i, g.resID, toGive, toGet, EMarketMode::RESOURCE_RESOURCE);
|
||||
toGive = toGive * (cb->getResourceAmount(i) / toGive);
|
||||
m->getOffer(res, g.resID, toGive, toGet, EMarketMode::RESOURCE_RESOURCE);
|
||||
toGive = toGive * (it->resVal / toGive);
|
||||
//TODO trade only as much as needed
|
||||
if (toGive) //don't try to sell 0 resources
|
||||
{
|
||||
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, i, g.resID, toGive);
|
||||
logAi->debug("Traded %d of %s for %d of %s at %s", toGive, i, toGet, g.resID, obj->getObjectName());
|
||||
accquiredResources += toGet;
|
||||
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, res, g.resID, toGive);
|
||||
logAi->debug("Traded %d of %s for %d of %s at %s", toGive, res, toGet, g.resID, obj->getObjectName());
|
||||
accquiredResources += toGet; //FIXME: this is incorrect, always equal to 1
|
||||
}
|
||||
if (accquiredResources >= g.value) //we traded all we needed
|
||||
throw goalFulfilledException(sptr(g));
|
||||
|
Loading…
x
Reference in New Issue
Block a user