From 67fd4367fd5de28aabfb9f43c6a21a4ebcfd73ba Mon Sep 17 00:00:00 2001 From: mattsc Date: Fri, 21 Oct 2016 07:59:03 -0700 Subject: [PATCH] Wolves Micro AI: better recovery from ambushes etc. This is not necessary for most other Micro AIs, but this AI moves several units per execution. If an ambush or failed teleport or similar happens, it is better to reconsider rather than pull through with the previously planned moves. --- data/ai/micro_ais/cas/ca_wolves_move.lua | 8 ++++++-- data/ai/micro_ais/cas/ca_wolves_wander.lua | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/ai/micro_ais/cas/ca_wolves_move.lua b/data/ai/micro_ais/cas/ca_wolves_move.lua index c2aa8ba620f..a41337a08a1 100644 --- a/data/ai/micro_ais/cas/ca_wolves_move.lua +++ b/data/ai/micro_ais/cas/ca_wolves_move.lua @@ -63,7 +63,9 @@ function ca_wolves_move:execution(cfg) return rating end) - AH.movefull_stopunit(ai, wolves[1], wolf1) + local move_result = AH.movefull_stopunit(ai, wolves[1], wolf1) + -- If the wolf was ambushed, return and reconsider; also if an event removed a wolf + if (AH.is_incomplete_move(move_result)) then return end for _,check_wolf in ipairs(wolves) do if (not check_wolf) or (not check_wolf.valid) then return end end @@ -90,7 +92,9 @@ function ca_wolves_move:execution(cfg) return rating end) - AH.movefull_stopunit(ai, wolves[i], move) + local move_result = AH.movefull_stopunit(ai, wolves[i], move) + -- If the wolf was ambushed, return and reconsider; also if an event removed a wolf + if (AH.is_incomplete_move(move_result)) then return end for _,check_wolf in ipairs(wolves) do if (not check_wolf) or (not check_wolf.valid) then return end end diff --git a/data/ai/micro_ais/cas/ca_wolves_wander.lua b/data/ai/micro_ais/cas/ca_wolves_wander.lua index c5a4692c4d4..2be9874df4f 100644 --- a/data/ai/micro_ais/cas/ca_wolves_wander.lua +++ b/data/ai/micro_ais/cas/ca_wolves_wander.lua @@ -52,7 +52,9 @@ function ca_wolves_wander:execution(cfg) return rating end) - AH.movefull_stopunit(ai, wolf, best_hex) + local move_result = AH.movefull_stopunit(ai, wolf, best_hex) + -- If the wolf was ambushed, return and reconsider; also if an event removed a wolf + if (AH.is_incomplete_move(move_result)) then return end for _,check_wolf in ipairs(wolves) do if (not check_wolf) or (not check_wolf.valid) then return end end