@@ -67,6 +67,9 @@ return {
67
67
68
68
---- ---- Castle Switch CA --------------
69
69
local function get_reachable_enemy_leaders (unit )
70
+ -- We're cheating a little here and also find hidden enemy leaders. That's
71
+ -- because a human player could make a pretty good educated guess as to where
72
+ -- the enemy leaders are likely to be while the AI does not know how to do that.
70
73
local potential_enemy_leaders = AH .get_live_units { canrecruit = ' yes' ,
71
74
{ " filter_side" , { { " enemy_of" , {side = wesnoth .current .side } } } }
72
75
}
@@ -228,7 +231,7 @@ return {
228
231
local should_wait = false
229
232
for i ,loc in ipairs (castle ) do
230
233
local unit = wesnoth .get_unit (loc [1 ], loc [2 ])
231
- if not unit then
234
+ if ( not AH . is_visible_unit ( wesnoth . current . side , unit )) then
232
235
should_wait = false
233
236
break
234
237
elseif unit .moves > 0 then
@@ -273,9 +276,7 @@ return {
273
276
return 0
274
277
end
275
278
276
- local enemies = AH .get_live_units {
277
- { " filter_side" , {{" enemy_of" , {side = wesnoth .current .side } }} }
278
- }
279
+ local enemies = AH .get_attackable_enemies ()
279
280
280
281
local villages = wesnoth .get_villages ()
281
282
-- Just in case:
@@ -331,7 +332,7 @@ return {
331
332
for i ,u in ipairs (units ) do
332
333
-- Skip villages that have units other than 'u' itself on them
333
334
local village_occupied = false
334
- if unit_in_way and (( unit_in_way . x ~= u . x ) or ( unit_in_way . y ~= u . y )) then
335
+ if AH . is_visible_unit ( wesnoth . current . side , unit_in_way ) and (( unit_in_way ~= u )) then
335
336
village_occupied = true
336
337
end
337
338
@@ -486,21 +487,13 @@ return {
486
487
487
488
function generic_rush :spread_poison_exec ()
488
489
local attacker = wesnoth .get_unit (self .data .attack .src .x , self .data .attack .src .y )
490
+ -- If several attacks have poison, this will always find the last one
491
+ local is_poisoner , poison_weapon = AH .has_weapon_special (attacker , " poison" )
489
492
490
493
if AH .print_exec () then print_time (' Executing spread_poison CA' ) end
491
494
if AH .show_messages () then W .message { speaker = attacker .id , message = ' Poison attack' } end
492
495
493
- local defender = wesnoth .get_unit (self .data .attack .target .x , self .data .attack .target .y )
494
-
495
- AH .movefull_stopunit (ai , attacker , self .data .attack .dst .x , self .data .attack .dst .y )
496
- if (not attacker ) or (not attacker .valid ) then return end
497
- if (not defender ) or (not defender .valid ) then return end
498
-
499
- -- Find the poison weapon
500
- -- If several attacks have poison, this will always find the last one
501
- local is_poisoner , poison_weapon = AH .has_weapon_special (attacker , " poison" )
502
-
503
- AH .checked_attack (ai , attacker , defender , poison_weapon )
496
+ AH .robust_move_and_attack (ai , attacker , self .data .attack .dst , self .data .attack .target , { weapon = poison_weapon })
504
497
505
498
self .data .attack = nil
506
499
end
@@ -544,7 +537,7 @@ return {
544
537
end
545
538
546
539
function generic_rush :retreat_injured_units_exec ()
547
- AH .movefull_outofway_stopunit (ai , self .data .retreat_unit , self .data .retreat_loc )
540
+ AH .robust_move_and_attack (ai , self .data .retreat_unit , self .data .retreat_loc )
548
541
self .data .retreat_unit = nil
549
542
self .data .retreat_loc = nil
550
543
end
0 commit comments