Skip to content

Commit

Permalink
Micro AIs: add check for valid recruiting and error message
Browse files Browse the repository at this point in the history
This now checks whether the recruiting intended to be done with
ai.recruit is possible and displays an error message if it is not.
  • Loading branch information
mattsc committed Feb 28, 2014
1 parent 835194e commit d3e9cb3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions data/ai/lua/ai_helper.lua
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion data/ai/micro_ais/cas/ca_recruit_random.lua
Expand Up @@ -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

Expand Down

0 comments on commit d3e9cb3

Please sign in to comment.