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.
This commit is contained in:
parent
835194eee4
commit
d3e9cb3957
2 changed files with 12 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue