Experimental AI: use checked versions of the AI actions
So that only valid actions are executed and useful error messages are produced if something goes wrong.
This commit is contained in:
parent
0b6fa7ed19
commit
496a58d343
3 changed files with 5 additions and 5 deletions
|
@ -559,7 +559,7 @@ return {
|
|||
until recruit_type ~= nil
|
||||
|
||||
if wesnoth.unit_types[recruit_type].cost <= wesnoth.sides[wesnoth.current.side].gold then
|
||||
ai.recruit(recruit_type, recruit_data.recruit.best_hex[1], recruit_data.recruit.best_hex[2])
|
||||
AH.checked_recruit(ai, recruit_type, recruit_data.recruit.best_hex[1], recruit_data.recruit.best_hex[2])
|
||||
|
||||
-- If the recruited unit cannot reach the target hex, return it to the pool of targets
|
||||
if recruit_data.recruit.target_hex ~= nil and recruit_data.recruit.target_hex[1] ~= nil then
|
||||
|
|
|
@ -254,7 +254,7 @@ return {
|
|||
if AH.print_exec() then print_time(' Executing castle_switch CA') end
|
||||
if AH.show_messages() then W.message { speaker = leader.id, message = 'Switching castles' } end
|
||||
|
||||
ai.move(leader, self.data.leader_target[1], self.data.leader_target[2])
|
||||
AH.checked_move(ai, leader, self.data.leader_target[1], self.data.leader_target[2])
|
||||
self.data.leader_target = nil
|
||||
end
|
||||
|
||||
|
@ -500,7 +500,7 @@ return {
|
|||
-- If several attacks have poison, this will always find the last one
|
||||
local is_poisoner, poison_weapon = AH.has_weapon_special(attacker, "poison")
|
||||
|
||||
ai.attack(attacker, defender, poison_weapon)
|
||||
AH.checked_attack(ai, attacker, defender, poison_weapon)
|
||||
|
||||
self.data.attack = nil
|
||||
end
|
||||
|
@ -606,7 +606,7 @@ return {
|
|||
if target then
|
||||
local x, y = wesnoth.find_vacant_tile(target[1], target[2], unit)
|
||||
local dest = AH.next_hop(unit, x, y)
|
||||
ai.move(unit, dest[1], dest[2])
|
||||
AH.checked_move(ai, unit, dest[1], dest[2])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ return {
|
|||
end
|
||||
|
||||
function move_to_any_target:move_to_enemy_exec()
|
||||
ai.move(self.data.unit, self.data.destination[1], self.data.destination[2])
|
||||
AH.checked_move(ai, self.data.unit, self.data.destination[1], self.data.destination[2])
|
||||
end
|
||||
|
||||
return move_to_any_target
|
||||
|
|
Loading…
Add table
Reference in a new issue