RCA AI: remove possibility of infinite candidate action loops

The RCA AI main_loop stage prevents infinite candidate action loops by blacklisting CAs that do not change the game state. However, the different stopunit actions previously always marked the game state as changed, even when used on units which already did not have moves and/or attacks.
This commit is contained in:
mattsc 2018-12-28 13:35:28 -08:00
parent 8b3c6b1fa9
commit 6c8e7280a3
2 changed files with 5 additions and 2 deletions

View file

@ -109,6 +109,7 @@
* New option "Keep saved AI" when reloading games from the MP Create Game screen. Choosing this option
prevents overwriting of the saved AI by the default AI. (issue #3791)
* Forest Animals Micro AI: fix AI crash when using custom rabbit hole image
* Fix Lua AIs using the ai.stopunit_*() functions potentially creating infinite candidate action loops
### Campaigns
* Descent Into Darkness:
* Allow converting L3 necromancers to liches from S12 onwards (issue #3165).

View file

@ -898,12 +898,14 @@ void stopunit_result::do_execute()
}
try {
if (remove_movement_){
// Don't mark the game state as changed if unit already has no moves or attacks.
// Doing so can cause infinite candidate action loops.
if (remove_movement_ && un->movement_left() != 0) {
un->remove_movement_ai();
set_gamestate_changed();
manager::get_singleton().raise_gamestate_changed();
}
if (remove_attacks_){
if (remove_attacks_ && un->attacks_left() != 0){
un->remove_attacks_ai();
set_gamestate_changed();
manager::get_singleton().raise_gamestate_changed();//to be on the safe side