Lua AI code: update deprecated functions
This commit is contained in:
parent
8080271231
commit
55478e20ad
11 changed files with 27 additions and 27 deletions
|
@ -1295,7 +1295,7 @@ function ai_helper.get_cheapest_recruit_cost(leader)
|
|||
if leader then
|
||||
leaders = { leader }
|
||||
else
|
||||
leaders = wesnoth.get_units { side = wesnoth.current.side, canrecruit = 'yes' }
|
||||
leaders = wesnoth.units.find_on_map { side = wesnoth.current.side, canrecruit = 'yes' }
|
||||
end
|
||||
for _,l in ipairs(leaders) do
|
||||
for _,recruit_id in ipairs(l.extra_recruit) do
|
||||
|
@ -1490,7 +1490,7 @@ function ai_helper.next_hop(unit, x, y, cfg)
|
|||
|
||||
-- Need the reach map of the unit from the ideal next hop hex
|
||||
-- There will always be another unit there, otherwise we would not have gotten here
|
||||
local unit_in_way = wesnoth.get_unit(next_hop_ideal[1], next_hop_ideal[2])
|
||||
local unit_in_way = wesnoth.units.get(next_hop_ideal[1], next_hop_ideal[2])
|
||||
unit_in_way:extract()
|
||||
local old_x, old_y = unit.x, unit.y
|
||||
unit:extract()
|
||||
|
@ -1501,12 +1501,12 @@ function ai_helper.next_hop(unit, x, y, cfg)
|
|||
unit_in_way:to_map()
|
||||
|
||||
local terrain = wesnoth.get_terrain(next_hop_ideal[1], next_hop_ideal[2])
|
||||
local move_cost_endpoint = wesnoth.unit_movement_cost(unit, terrain)
|
||||
local move_cost_endpoint = wesnoth.units.movement_on(unit, terrain)
|
||||
local inverse_reach_map = LS.create()
|
||||
for _,r in pairs(inverse_reach) do
|
||||
-- We want the moves left for moving into the opposite direction in which the reach map was calculated
|
||||
local terrain = wesnoth.get_terrain(r[1], r[2])
|
||||
local move_cost = wesnoth.unit_movement_cost(unit, terrain)
|
||||
local move_cost = wesnoth.units.movement_on(unit, terrain)
|
||||
local inverse_cost = r[3] + move_cost - move_cost_endpoint
|
||||
inverse_reach_map:insert(r[1], r[2], inverse_cost)
|
||||
end
|
||||
|
@ -1709,7 +1709,7 @@ function ai_helper.custom_cost_with_avoid(x, y, prev_cost, unit, avoid_map, ally
|
|||
|
||||
local max_moves = unit.max_moves
|
||||
local terrain = wesnoth.get_terrain(x, y)
|
||||
local move_cost = wesnoth.unit_movement_cost(unit, terrain)
|
||||
local move_cost = wesnoth.units.movement_on(unit, terrain)
|
||||
|
||||
if (move_cost > max_moves) then
|
||||
return ai_helper.no_path
|
||||
|
@ -1790,7 +1790,7 @@ function ai_helper.custom_cost_with_avoid(x, y, prev_cost, unit, avoid_map, ally
|
|||
-- will potentially add to the cost and might make the path inaccurate. However, for an average
|
||||
-- defense of 50 along the path, this will not happen until the path is 1000 hexes long. Also,
|
||||
-- in most cases this will simply add to the cost, rather than change the path itself.
|
||||
local defense = unit:defense(terrain)
|
||||
local defense = unit:defense_on(terrain)
|
||||
-- We need this to be multiples of 10 for the penalty identification to work
|
||||
defense = H.round(defense / 10) * 10
|
||||
if (defense > 90) then defense = 90 end
|
||||
|
@ -1838,7 +1838,7 @@ function ai_helper.find_path_with_avoid(unit, x, y, avoid_map, options)
|
|||
return nil, ai_helper.no_path
|
||||
end
|
||||
|
||||
local all_units = wesnoth.get_units()
|
||||
local all_units = wesnoth.units.find_on_map()
|
||||
local ally_map, enemy_map = LS.create(), LS.create()
|
||||
for _,u in ipairs(all_units) do
|
||||
if (u.id ~= unit.id) and ai_helper.is_visible_unit(wesnoth.current.side, u) then
|
||||
|
|
|
@ -73,7 +73,7 @@ function battle_calcs.unit_attack_info(unit, cache)
|
|||
|
||||
local attack_types = { "arcane", "blade", "cold", "fire", "impact", "pierce" }
|
||||
for _,attack_type in ipairs(attack_types) do
|
||||
unit_info.resist_mod[attack_type] = unit:resistance(attack_type) / 100.
|
||||
unit_info.resist_mod[attack_type] = unit:resistance_against(attack_type) / 100.
|
||||
end
|
||||
|
||||
if cache then cache[cind] = unit_info end
|
||||
|
@ -677,8 +677,8 @@ function battle_calcs.battle_outcome(attacker, defender, cfg, cache)
|
|||
if (def_max_hits > att_strikes) then def_max_hits = att_strikes end
|
||||
|
||||
-- Probability of landing a hit
|
||||
local att_hit_prob = defender:defense(wesnoth.get_terrain(defender.x, defender.y)) / 100.
|
||||
local def_hit_prob = attacker:defense(wesnoth.get_terrain(dst[1], dst[2])) / 100.
|
||||
local att_hit_prob = defender:defense_on(wesnoth.get_terrain(defender.x, defender.y)) / 100.
|
||||
local def_hit_prob = attacker:defense_on(wesnoth.get_terrain(dst[1], dst[2])) / 100.
|
||||
|
||||
-- Magical: attack and defense, and under all circumstances
|
||||
if att_attack.magical then att_hit_prob = 0.7 end
|
||||
|
@ -924,7 +924,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache)
|
|||
-- We don't need a bonus for good terrain for the attacker, as that is covered in the damage calculation
|
||||
-- However, we add a small bonus for good terrain defense of the _defender_ on the _attack_ hex
|
||||
-- This is in order to take good terrain away from defender on next move, all else being equal
|
||||
local defender_defense = - defender:defense(wesnoth.get_terrain(dst[1], dst[2])) / 100.
|
||||
local defender_defense = - defender:defense_on(wesnoth.get_terrain(dst[1], dst[2])) / 100.
|
||||
defender_value = defender_value + defender_defense * defense_weight
|
||||
|
||||
-- Get a very small bonus for hexes in between defender and AI leader
|
||||
|
@ -1316,7 +1316,7 @@ function battle_calcs.best_defense_map(units, cfg)
|
|||
if max_moves then unit.moves = old_moves end
|
||||
|
||||
for _,loc in ipairs(reach) do
|
||||
local defense = 100 - unit:defense(wesnoth.get_terrain(loc[1], loc[2]))
|
||||
local defense = 100 - unit:defense_on(wesnoth.get_terrain(loc[1], loc[2]))
|
||||
|
||||
if (defense > (defense_map:get(loc[1], loc[2]) or - math.huge)) then
|
||||
defense_map:insert(loc[1], loc[2], defense)
|
||||
|
@ -1524,7 +1524,7 @@ function battle_calcs.get_attack_combos_subset(units, enemy, cfg)
|
|||
-- Store information about it in 'loc' and add this to 'locs'
|
||||
-- Want coordinates (dst) and terrain defense (for sorting)
|
||||
loc.dst = xa * 1000 + ya
|
||||
loc.hit_prob = unit:defense(wesnoth.get_terrain(xa, ya))
|
||||
loc.hit_prob = unit:defense_on(wesnoth.get_terrain(xa, ya))
|
||||
table.insert(locs, loc)
|
||||
|
||||
-- Also mark this hex as usable
|
||||
|
|
|
@ -75,7 +75,7 @@ function ca_spread_poison:evaluation(cfg, data, filter_own)
|
|||
end
|
||||
|
||||
-- More priority to enemies on strong terrain
|
||||
local defense_rating = (100 - defender:defense(defender_terrain)) / 100
|
||||
local defense_rating = (100 - defender:defense_on(defender_terrain)) / 100
|
||||
|
||||
attacker_rating = attacker_rating * (1 - aggression)
|
||||
local combat_rating = attacker_rating + defender_rating + additional_poison_rating
|
||||
|
|
|
@ -85,7 +85,7 @@ return {
|
|||
local best_defense = 100
|
||||
|
||||
for i, terrain in ipairs(terrain_archetypes) do
|
||||
local defense = unit:defense(terrain)
|
||||
local defense = unit:defense_on(terrain)
|
||||
if defense < best_defense then
|
||||
best_defense = defense
|
||||
end
|
||||
|
@ -195,7 +195,7 @@ return {
|
|||
if (sp[1] == 'drains') and drainable(attacker) then
|
||||
-- TODO: calculate chance to hit
|
||||
-- currently assumes 50% chance to hit using supplied constant
|
||||
local attacker_resistance = attacker:resistance(defender_attack.type)
|
||||
local attacker_resistance = attacker:resistance_against(defender_attack.type)
|
||||
drain_recovery = (defender_attack.damage*defender_attack.number*attacker_resistance*attacker_defense/2)/10000
|
||||
end
|
||||
end
|
||||
|
@ -203,7 +203,7 @@ return {
|
|||
end
|
||||
|
||||
defense = defense/100.0
|
||||
local resistance = defender:resistance(attack.type)
|
||||
local resistance = defender:resistance_against(attack.type)
|
||||
if steadfast and (resistance < 100) then
|
||||
resistance = 100 - ((100 - resistance) * 2)
|
||||
if (resistance < 50) then
|
||||
|
@ -257,7 +257,7 @@ return {
|
|||
random_gender = false
|
||||
}
|
||||
local can_poison = poisonable(unit) and (not unit:ability('regenerate'))
|
||||
local flat_defense = unit:defense("Gt")
|
||||
local flat_defense = unit:defense_on("Gt")
|
||||
local best_defense = get_best_defense(unit)
|
||||
|
||||
local recruit = wesnoth.units.create {
|
||||
|
@ -266,7 +266,7 @@ return {
|
|||
name = "X",
|
||||
random_gender = false
|
||||
}
|
||||
local recruit_flat_defense = recruit:defense("Gt")
|
||||
local recruit_flat_defense = recruit:defense_on("Gt")
|
||||
local recruit_best_defense = get_best_defense(recruit)
|
||||
|
||||
local can_poison_retaliation = poisonable(recruit) and (not recruit:ability('regenerate'))
|
||||
|
|
|
@ -21,7 +21,7 @@ function retreat_functions.min_hp(unit)
|
|||
if (caution_factor < 0) then caution_factor = 0 end
|
||||
caution_factor = math.sqrt(caution_factor) * 2
|
||||
|
||||
local hp_per_level = unit:defense(wesnoth.get_terrain(unit.x, unit.y))/15 * caution_factor
|
||||
local hp_per_level = unit:defense_on(wesnoth.get_terrain(unit.x, unit.y))/15 * caution_factor
|
||||
local level = unit.level
|
||||
|
||||
-- Leaders are considered to be higher level because of their value
|
||||
|
@ -212,7 +212,7 @@ function retreat_functions.get_retreat_injured_units(healees, regen_amounts, avo
|
|||
rating = rating - enemy_count * 100000
|
||||
|
||||
-- Penalty based on terrain defense for unit
|
||||
rating = rating - u:defense(wesnoth.get_terrain(loc[1], loc[2]))/10
|
||||
rating = rating - u:defense_on(wesnoth.get_terrain(loc[1], loc[2]))/10
|
||||
|
||||
if (loc[1] == u.x) and (loc[2] == u.y) and (not u.status.poisoned) then
|
||||
if is_healthy or enemy_count == 0 then
|
||||
|
|
|
@ -95,7 +95,7 @@ function ca_assassin_move:execution(cfg)
|
|||
-- Penalties for damage by enemies
|
||||
local enemy_rating_map = LS.create()
|
||||
enemy_damage_map:iter(function(x, y, enemy_damage)
|
||||
local hit_chance = (unit:defense(wesnoth.get_terrain(x, y))) / 100.
|
||||
local hit_chance = (unit:defense_on(wesnoth.get_terrain(x, y))) / 100.
|
||||
|
||||
local rating = hit_chance * enemy_damage
|
||||
rating = rating / unit.max_hitpoints
|
||||
|
|
|
@ -157,7 +157,7 @@ function ca_fast_attack_utils.get_unit_defense(unit_copy, x, y, defense_maps)
|
|||
if (not defense_maps[unit_copy.id][x]) then defense_maps[unit_copy.id][x] = {} end
|
||||
|
||||
if (not defense_maps[unit_copy.id][x][y]) then
|
||||
local defense = (100. - unit_copy:defense(wesnoth.get_terrain(x, y))) / 100.
|
||||
local defense = (100. - unit_copy:defense_on(wesnoth.get_terrain(x, y))) / 100.
|
||||
defense_maps[unit_copy.id][x][y] = { defense = defense }
|
||||
end
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ function ca_healer_move:evaluation(cfg, data)
|
|||
local is_village = wesnoth.get_terrain_info(terrain).village
|
||||
if is_village then rating = rating + 2 end
|
||||
|
||||
local defense = 100 - healer:defense(terrain)
|
||||
local defense = 100 - healer:defense_on(terrain)
|
||||
rating = rating + defense / 10.
|
||||
end
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ function ca_protect_unit_move:execution(cfg, data)
|
|||
|
||||
local terrain_defense_map = LS.create()
|
||||
reach_map:iter(function(x, y, data)
|
||||
terrain_defense_map:insert(x, y, 100 - unit:defense(wesnoth.get_terrain(x, y)))
|
||||
terrain_defense_map:insert(x, y, 100 - unit:defense_on(wesnoth.get_terrain(x, y)))
|
||||
end)
|
||||
|
||||
local goal_distance_map = LS.create()
|
||||
|
|
|
@ -61,7 +61,7 @@ function ca_stationed_guardian:execution(cfg)
|
|||
if (not AH.is_visible_unit(wesnoth.current.side, unit_in_way))
|
||||
or (unit_in_way == guardian)
|
||||
then
|
||||
local defense = 100 - guardian:defense(wesnoth.get_terrain(xa, ya))
|
||||
local defense = 100 - guardian:defense_on(wesnoth.get_terrain(xa, ya))
|
||||
local nh = AH.next_hop(guardian, xa, ya)
|
||||
if nh then
|
||||
if (nh[1] == xa) and (nh[2] == ya) and (defense > best_defense) then
|
||||
|
|
|
@ -46,7 +46,7 @@ function ca_zone_guardian:execution(cfg)
|
|||
if (not AH.is_visible_unit(wesnoth.current.side, unit_in_way))
|
||||
or (unit_in_way == guardian)
|
||||
then
|
||||
local defense = 100 - guardian:defense(wesnoth.get_terrain(xa, ya))
|
||||
local defense = 100 - guardian:defense_on(wesnoth.get_terrain(xa, ya))
|
||||
local nh = AH.next_hop(guardian, xa, ya)
|
||||
if nh then
|
||||
if (nh[1] == xa) and (nh[2] == ya) and (defense > best_defense) then
|
||||
|
|
Loading…
Add table
Reference in a new issue