Skip to content

Commit feabc70

Browse files
MeridianOXCSupSuper
authored andcommitted
Prevent AI frozen in place
I received a report of AI freeze, which looks like this: 1. AI runs setupEscape() and decides it should escape to the same tile as it currently occupies (for whatever reason); _escapeTUs is set to 1 2. AI evaluation sets _AIMode to 3 (=escape) 3. at the end of the think() cycle, _escapeTUs is not reset (because there is no need to move) Starting from this point setupEscape() is not executed anymore, because _escapeTUs != 0. And as long as the enemy sees (or knows about) xcom, it will not re-evaluate. Thus every turn it will just stay where it is without doing anything (only thing it can do are reaction shots). The freeze breaks only after turn 20 (or other forced re-evaluate). Or after save and reload... because _escapeTUs is not saved and will get reset back to 0 after reload.
1 parent 49eb7d6 commit feabc70

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/Battlescape/AIModule.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ AIModule::~AIModule()
7878
delete _psiAction;
7979
}
8080

81+
/**
82+
* Resets the unsaved AI state.
83+
*/
84+
void AIModule::reset()
85+
{
86+
// these variables are not saved in save() and also not initiated in think()
87+
_escapeTUs = 0;
88+
_ambushTUs = 0;
89+
}
90+
8191
/**
8292
* Loads the AI state from a YAML file.
8393
* @param node YAML node.

‎src/Battlescape/AIModule.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class AIModule
5858
AIModule(SavedBattleGame *save, BattleUnit *unit, Node *node);
5959
/// Cleans up the AIModule.
6060
~AIModule();
61+
/// Resets the unsaved AI state.
62+
void reset();
6163
/// Loads the AI Module from YAML.
6264
void load(const YAML::Node& node);
6365
/// Saves the AI Module to YAML.

‎src/Savegame/SavedBattleGame.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ void SavedBattleGame::endTurn()
884884
{
885885
(*i)->setTurnsSinceSpotted(0);
886886
}
887+
if ((*i)->getAIModule())
888+
{
889+
(*i)->getAIModule()->reset(); // clean up AI state
890+
}
887891
}
888892
}
889893
// hide all aliens (VOF calculations below will turn them visible again)

0 commit comments

Comments
 (0)