Переглянути джерело

* 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

Michał W. Urbańczyk 13 роки тому
батько
коміт
8bb4abb75a
2 змінених файлів з 8 додано та 1 видалено
  1. 7 1
      AI/VCAI/VCAI.cpp
  2. 1 0
      lib/CObjectHandler.cpp

+ 7 - 1
AI/VCAI/VCAI.cpp

@@ -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
 			{

+ 1 - 0
lib/CObjectHandler.cpp

@@ -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();
 	}