Lua AIs: no need to set variables to nil explicitely

This is mostly done for consistency across the Lua AI code

(cherry-picked from commit 0e7c09f7b5)
This commit is contained in:
mattsc 2018-08-30 07:35:57 -07:00
parent 3c558c7360
commit f761493c75
4 changed files with 7 additions and 7 deletions

View file

@ -111,7 +111,7 @@ return {
-- In several cases this function only approximates the correct value (eg Thunderguard vs Goblin Spearman has damage capped by target health)
-- In some cases (like poison), this approximation is preferred to the actual value.
local best_damage = 0
local best_attack = nil
local best_attack
local best_poison_damage = 0
-- Steadfast is currently disabled because it biases the AI too much in favour of Guardsmen
-- Basically it sees the defender stats for damage and wrongfully concludes that the unit is amazing
@ -548,7 +548,7 @@ return {
end
end
-- Correct count of units for each range
local most_common_range = nil
local most_common_range
local most_common_range_count = 0
for range, count in pairs(attack_range_count) do
attack_range_count[range] = count/enemy_type_count
@ -562,7 +562,7 @@ return {
attack_type_count[attack_type] = count/enemy_type_count
end
local recruit_type = nil
local recruit_type
local leader = wesnoth.get_units { side = wesnoth.current.side, canrecruit = 'yes' }[1]
repeat
recruit_data.recruit.best_hex, recruit_data.recruit.target_hex = ai_cas:find_best_recruit_hex(leader, recruit_data)
@ -779,7 +779,7 @@ return {
end
local healer_count, healable_count = get_unit_counts_for_healing()
local best_score = 0
local recruit_type = nil
local recruit_type
local offense_weight = 2.5
local defense_weight = 1/hp_ratio^0.5
local move_weight = math.max((distance_to_enemy/20)^2, 0.25)

View file

@ -574,7 +574,7 @@ return {
})[1]
local villages = wesnoth.get_villages()
local target, best_cost = nil, AH.no_path
local best_cost, target = AH.no_path
for i,v in ipairs(villages) do
if not wesnoth.match_location(v[1], v[2], { {"filter_owner", { {"ally_of", { side = wesnoth.current.side }} }} }) then
local path, cost = wesnoth.find_path(unit, v[1], v[2], { ignore_units = true, max_cost = best_cost })

View file

@ -114,7 +114,7 @@ function retreat_functions.get_retreat_injured_units(healees, regenerates)
local healing_locs = retreat_functions.get_healing_locations()
local max_rating, best_loc, best_unit = - math.huge, nil, nil
local max_rating, best_loc, best_unit = - math.huge
for i,u in ipairs(healees) do
local possible_locations = wesnoth.find_reach(u)
-- TODO: avoid ally's villages (may be preferable to lower rating so they will

View file

@ -29,7 +29,7 @@ function ca_ogres_flee:execution()
local enemies = wesnoth.get_units { { "filter_side", { {"enemy_of", {side = wesnoth.current.side} } } } }
local enemy_attack_map = BC.get_attack_map(enemies)
local best_hex, best_unit, max_rating = {}, nil, - math.huge
local max_rating, best_hex, best_unit = - math.huge, {}
for i,u in ipairs(units) do
local reach = wesnoth.find_reach(u)