소스 검색

Fixed AI trying to realize incorrect goals, which could lead to crash

DjWarmonger 12 년 전
부모
커밋
f40863b82f
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      AI/VCAI/VCAI.cpp

+ 12 - 1
AI/VCAI/VCAI.cpp

@@ -2095,7 +2095,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
 	{
 		CGoal goal = ultimateGoal;
 		BNLOG("Striving to goal of type %s", ultimateGoal.name());
-		int maxGoals = 100; //preventing deadlock for mutually dependent goals
+		int maxGoals = 100; //preventing deadlock for mutually dependent goals, FIXME: do not try to realize goal when loop didn't suceed
 		while(!goal.isElementar && !goal.isAbstract && maxGoals)
 		{
 			INDENT;
@@ -2118,6 +2118,12 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
 		{
 			boost::this_thread::interruption_point();
 
+			if (!maxGoals)
+			{
+				std::exception e("Too many subgoals, don't know what to do");
+				throw (e);
+			}
+
 			if (goal.hero) //lock this hero to fulfill ultimate goal
 			{
 				if (maxGoals)
@@ -2185,6 +2191,11 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal)
 			try
 			{
 				boost::this_thread::interruption_point();
+				if (!maxGoals)
+				{
+					std::exception e("Too many subgoals, don't know what to do");
+					throw (e);
+				}
 				tryRealize(goal);
 				boost::this_thread::interruption_point();
 			}