mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* VCAI: fixed possible endless loop of realizing GATHERRESOURCE goal
* an assertion failing when quest object cannot find its targeted monster ("crash early" policy), related to #1076
This commit is contained in:
parent
0435d5a4f1
commit
8bb4abb75a
@ -1947,6 +1947,9 @@ void VCAI::tryRealize(CGoal g)
|
||||
break;
|
||||
|
||||
case COLLECT_RES: //TODO: use piles and mines?
|
||||
if(cb->getResourceAmount(g.resID) >= g.value)
|
||||
throw cannotFulfillGoalException("Goal is already fulfilled!");
|
||||
|
||||
if(const CGObjectInstance *obj = cb->getObj(g.objid, false))
|
||||
{
|
||||
if(const IMarket *m = IMarket::castFrom(obj, false))
|
||||
@ -1957,10 +1960,13 @@ void VCAI::tryRealize(CGoal g)
|
||||
int toGive, toGet;
|
||||
m->getOffer(i, g.resID, toGive, toGet, EMarketMode::RESOURCE_RESOURCE);
|
||||
toGive = toGive * (cb->getResourceAmount(i) / toGive);
|
||||
//TODO trade only as much as needed
|
||||
cb->trade(obj, EMarketMode::RESOURCE_RESOURCE, i, g.resID, toGive);
|
||||
if(cb->getResourceAmount(g.resID) >= g.value)
|
||||
return;
|
||||
} //TODO: stop when we've sold all the resources
|
||||
}
|
||||
|
||||
throw cannotFulfillGoalException("I cannot get needed resources by trade!");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4405,6 +4405,7 @@ void CGSeerHut::setObjToKill()
|
||||
if (quest.missionType == CQuest::MISSION_KILL_CREATURE)
|
||||
{
|
||||
quest.stackToKill = getCreatureToKill(false)->getStack(0); //FIXME: stacks tend to dissapear (desync?) on server :?
|
||||
assert(quest.stackToKill.type);
|
||||
quest.stackToKill.count = 0; //no count in info window
|
||||
quest.stackDirection = checkDirection();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user