From b2581bcb7c136ed64bfef707ac687c8e5d85d7e2 Mon Sep 17 00:00:00 2001 From: mattsc Date: Thu, 16 Oct 2014 13:16:24 -0700 Subject: [PATCH] Lurkers Micro AI: fix bug in wander terrain selection Need to verify that the goal hex for the wander is not occupied by an ally, otherwise the unit might end up on the wrong type of terrain. --- changelog | 1 + data/ai/micro_ais/cas/ca_lurkers.lua | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/changelog b/changelog index 5e24ad74835..0c85704fabb 100644 --- a/changelog +++ b/changelog @@ -14,6 +14,7 @@ Version 1.13.0-dev: * Stationed Guardian Micro AI: make guard_x/y= optional keys * Messenger Escort Micro AI: bug fix for escort units blocking messenger's progress + * Lurkers Micro AI: fix bug in wander terrain selection * Several Micro AIs: fix a variety of rarely occurring but serious bugs, such as invalid savegames or disabling the AI from working for the rest of the turn or after changing the Micro AI settings. diff --git a/data/ai/micro_ais/cas/ca_lurkers.lua b/data/ai/micro_ais/cas/ca_lurkers.lua index 28a123252a2..e46bae7a5d0 100644 --- a/data/ai/micro_ais/cas/ca_lurkers.lua +++ b/data/ai/micro_ais/cas/ca_lurkers.lua @@ -73,6 +73,15 @@ function ca_lurkers:execution(ai, cfg) }) reachable_wander_terrain:inter(reach) + -- Need to restrict that to reachable and not occupied by an ally (except own position) + local reachable_wander_terrain = reachable_wander_terrain:filter(function(x, y, v) + local occ_hex = wesnoth.get_units { + x = x, y = y, + { "not", { x = lurker.x, y = lurker.y } } + }[1] + return not occ_hex + end) + if (reachable_wander_terrain:size() > 0) then local dst = reachable_wander_terrain:to_stable_pairs() local rand = math.random(1, reachable_wander_terrain:size())