diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index e0df36309888..616002cc908d 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -1146,11 +1146,9 @@ end function ai_helper.has_weapon_special(unit, special) -- Returns true/false depending on whether @unit has a weapon with special @special -- Also returns the number of the first weapon with this special - local weapon_number = 0 - for att in H.child_range(unit.__cfg, 'attack') do - weapon_number = weapon_number + 1 - for sp in H.child_range(att, 'specials') do - if H.get_child(sp, special) then + for weapon_number,att in ipairs(unit.attacks) do + for _,sp in ipairs(att.specials) do + if (sp[1] == special) then return true, weapon_number end end diff --git a/data/ai/micro_ais/cas/ca_bottleneck_attack.lua b/data/ai/micro_ais/cas/ca_bottleneck_attack.lua index 222cbb99e5c6..8c256f934791 100644 --- a/data/ai/micro_ais/cas/ca_bottleneck_attack.lua +++ b/data/ai/micro_ais/cas/ca_bottleneck_attack.lua @@ -17,10 +17,7 @@ function ca_bottleneck_attack:evaluation(cfg, data) local targets = AH.get_attackable_enemies { { "filter_adjacent", { id = attacker.id } } } for _,target in ipairs(targets) do - local n_weapon = 0 - for weapon in H.child_range(attacker.__cfg, "attack") do - n_weapon = n_weapon + 1 - + for n_weapon,weapon in ipairs(attacker.attacks) do local att_stats, def_stats = wesnoth.simulate_combat(attacker, n_weapon, target) local rating diff --git a/data/ai/micro_ais/cas/ca_bottleneck_move.lua b/data/ai/micro_ais/cas/ca_bottleneck_move.lua index 9324cf56421e..28cf39f8d3d1 100644 --- a/data/ai/micro_ais/cas/ca_bottleneck_move.lua +++ b/data/ai/micro_ais/cas/ca_bottleneck_move.lua @@ -379,9 +379,7 @@ function ca_bottleneck_move:evaluation(cfg, data) if (attack.x == loc[1]) and (attack.y == loc[2]) and (unit.max_experience - unit.experience <= 8 * attack.defender_level) then - local n_weapon = 0 - for weapon in H.child_range(unit.__cfg, "attack") do - n_weapon = n_weapon + 1 + for n_weapon,weapon in ipairs(unit.attacks) do local att_stats, def_stats = BC.simulate_combat_loc(unit, { attack.x, attack.y }, attack.defender, n_weapon) -- Execute level-up attack when: diff --git a/data/ai/micro_ais/cas/ca_messenger_move.lua b/data/ai/micro_ais/cas/ca_messenger_move.lua index e22af55eaae0..596dee3c0726 100644 --- a/data/ai/micro_ais/cas/ca_messenger_move.lua +++ b/data/ai/micro_ais/cas/ca_messenger_move.lua @@ -93,10 +93,7 @@ function ca_messenger_move:execution(cfg) local max_rating, best_target, best_weapon = -9e99 for _,target in ipairs(targets) do - local n_weapon = 0 - for weapon in H.child_range(messenger.__cfg, "attack") do - n_weapon = n_weapon + 1 - + for n_weapon,weapon in ipairs(messenger.attacks) do local att_stats, def_stats = wesnoth.simulate_combat(messenger, n_weapon, target) local rating = -9e99 diff --git a/data/ai/micro_ais/cas/ca_protect_unit_attack.lua b/data/ai/micro_ais/cas/ca_protect_unit_attack.lua index 07eef03a8b1b..4095127bc900 100644 --- a/data/ai/micro_ais/cas/ca_protect_unit_attack.lua +++ b/data/ai/micro_ais/cas/ca_protect_unit_attack.lua @@ -49,11 +49,8 @@ function ca_protect_unit_attack:evaluation(cfg) max_counter_damage = max_counter_damage + counter_damage_table[str] else -- if not, calculate it and save value -- Go thru all weapons, as "best weapon" might be different later on - local n_weapon = 0 local min_hp = unit.hitpoints - for weapon in H.child_range(enemy_attack.enemy.__cfg, "attack") do - n_weapon = n_weapon + 1 - + for n_weapon,weapon in ipairs(enemy_attack.enemy.attacks) do -- Terrain does not matter for this, we're only interested in the maximum damage local att_stats, def_stats = wesnoth.simulate_combat(enemy_attack.enemy, n_weapon, unit)