New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI: fix freeze while endlesly trying to recruit hero #527

Merged
merged 1 commit into from Dec 25, 2018

Conversation

Projects
None yet
2 participants
@nullkiller
Copy link
Contributor

nullkiller commented Dec 25, 2018

Conquer goal sometimes want to recruit a hero. If it is possible but is declined by ResourceManager because it has something more important or wants to save money it stores RecruitHero goal in its own cache and waits for a better time. When the better time happens we just want to execute RecruitHero elementar version as it was stored in elementar form in ResourceManager. The last more or less blindly tries to recruit hero and fails with cannotCompleteGoal exception. But the one path which checks presence of any tavern does not. It just does nothing and exits. So we try to recruit hero again and again and goal does nothing. It is not completed because it did not throw goalCompletedException nor it canceled because it did not threw cannotCompleteGoalException.

@@ -1007,6 +1008,9 @@ void VCAI::mainLoop()
for (auto basicGoal : ultimateGoalsFromBasic[goalToRealize])
goalsToRemove.push_back(basicGoal);

// sometimes resource manager contains an elementar goal which is not able to execute anymore and just fails each turn.
ai->ah->notifyGoalCompleted(goalToRealize);

This comment has been minimized.

@nullkiller

nullkiller Dec 25, 2018

Contributor

Just an optimization hack. Otherwise it will try to recruit hero once each turn until is completed.

@@ -2056,6 +2060,10 @@ void VCAI::tryRealize(Goals::RecruitHero & g)
//TODO try to free way to blocked town
//TODO: adventure map tavern or prison?
}
else
{
throw cannotFulfillGoalException("No town to recruit hero!");

This comment has been minimized.

@nullkiller

nullkiller Dec 25, 2018

Contributor

Main fix.

@alexvins alexvins merged commit cbbb85f into vcmi:develop Dec 25, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment