From 0e7c09f7b549bb43aec248bad04fcf0bffef17d5 Mon Sep 17 00:00:00 2001 From: mattsc Date: Thu, 30 Aug 2018 07:35:57 -0700 Subject: [PATCH] Lua AIs: no need to set variables to nil explicitely This is mostly done for consistency across the Lua AI code --- data/ai/lua/generic_recruit_engine.lua | 8 ++++---- data/ai/lua/generic_rush_engine.lua | 2 +- data/ai/lua/retreat.lua | 2 +- data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/data/ai/lua/generic_recruit_engine.lua b/data/ai/lua/generic_recruit_engine.lua index 480e9204a25e..9aa09d04c687 100644 --- a/data/ai/lua/generic_recruit_engine.lua +++ b/data/ai/lua/generic_recruit_engine.lua @@ -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) diff --git a/data/ai/lua/generic_rush_engine.lua b/data/ai/lua/generic_rush_engine.lua index 65182a172a04..3ae255800191 100644 --- a/data/ai/lua/generic_rush_engine.lua +++ b/data/ai/lua/generic_rush_engine.lua @@ -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 }) diff --git a/data/ai/lua/retreat.lua b/data/ai/lua/retreat.lua index c3219e90f372..f994be228044 100644 --- a/data/ai/lua/retreat.lua +++ b/data/ai/lua/retreat.lua @@ -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 diff --git a/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua b/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua index 0d7673448044..de5c27a70136 100644 --- a/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua +++ b/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua @@ -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)