From d3e9cb39573853b7b9c712f27abbe3c6e2047e2f Mon Sep 17 00:00:00 2001 From: mattsc Date: Thu, 27 Feb 2014 11:02:14 -0800 Subject: [PATCH] Micro AIs: add check for valid recruiting and error message This now checks whether the recruiting intended to be done with ai.recruit is possible and displays an error message if it is not. --- data/ai/lua/ai_helper.lua | 11 +++++++++++ data/ai/micro_ais/cas/ca_recruit_random.lua | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index 6d4109a9d4d1..7dd079cb208e 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -173,6 +173,17 @@ function ai_helper.checked_move(ai, unit, x, y) ai_helper.checked_move_core(ai, unit, x, y, 'ai.move') end +function ai_helper.checked_recruit(ai, unit_type, x, y) + local check = ai.check_recruit(unit_type, x, y) + + if (not check.ok) then + ai_helper.checked_action_error('ai.recruit', check.status) + return + end + + ai.recruit(unit_type, x, y) +end + function ai_helper.checked_stopunit_all(ai, unit) local check = ai.check_stopunit(unit) diff --git a/data/ai/micro_ais/cas/ca_recruit_random.lua b/data/ai/micro_ais/cas/ca_recruit_random.lua index 426c030ec5eb..f2ad064e14e9 100644 --- a/data/ai/micro_ais/cas/ca_recruit_random.lua +++ b/data/ai/micro_ais/cas/ca_recruit_random.lua @@ -103,7 +103,7 @@ end function ca_recruit_random:execution(ai, cfg) -- Let this function blacklist itself if the chosen recruit is too expensive if wesnoth.unit_types[recruit].cost <= wesnoth.sides[wesnoth.current.side].gold then - ai.recruit(recruit) + AH.checked_recruit(ai, recruit) end end