1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

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

This commit is contained in:
DjWarmonger 2013-02-23 19:13:15 +00:00
parent 5a135b9f42
commit f40863b82f

View File

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