mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Merge remote-tracking branch 'upstream/develop' into rewardable-expand
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -297,6 +297,12 @@ int RewardEvaluator::getGoldCost(const CGObjectInstance * target, const CGHeroIn
|
||||
{
|
||||
if(!target)
|
||||
return 0;
|
||||
|
||||
if(auto * m = dynamic_cast<const IMarket *>(target))
|
||||
{
|
||||
if(m->allowsTrade(EMarketMode::RESOURCE_SKILL))
|
||||
return 2000;
|
||||
}
|
||||
|
||||
switch(target->ID)
|
||||
{
|
||||
@@ -305,8 +311,6 @@ int RewardEvaluator::getGoldCost(const CGObjectInstance * target, const CGHeroIn
|
||||
case Obj::SCHOOL_OF_MAGIC:
|
||||
case Obj::SCHOOL_OF_WAR:
|
||||
return 1000;
|
||||
case Obj::UNIVERSITY:
|
||||
return 2000;
|
||||
case Obj::CREATURE_GENERATOR1:
|
||||
case Obj::CREATURE_GENERATOR2:
|
||||
case Obj::CREATURE_GENERATOR3:
|
||||
|
||||
@@ -131,13 +131,16 @@ TSubgoal CollectRes::whatToDoToTrade()
|
||||
|
||||
std::vector<const CGObjectInstance *> visObjs;
|
||||
ai->retrieveVisitableObjs(visObjs, true);
|
||||
for (const CGObjectInstance * obj : visObjs)
|
||||
for(const CGObjectInstance * obj : visObjs)
|
||||
{
|
||||
if (const IMarket * m = IMarket::castFrom(obj, false))
|
||||
if(const IMarket * m = IMarket::castFrom(obj, false); m->allowsTrade(EMarketMode::RESOURCE_RESOURCE))
|
||||
{
|
||||
if (obj->ID == Obj::TOWN && obj->tempOwner == ai->playerID && m->allowsTrade(EMarketMode::RESOURCE_RESOURCE))
|
||||
markets.push_back(m);
|
||||
else if (obj->ID == Obj::TRADING_POST)
|
||||
if(obj->ID == Obj::TOWN)
|
||||
{
|
||||
if(obj->tempOwner == ai->playerID)
|
||||
markets.push_back(m);
|
||||
}
|
||||
else
|
||||
markets.push_back(m);
|
||||
}
|
||||
}
|
||||
@@ -149,9 +152,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 +186,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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user