Skip to content

Commit

Permalink
Lua AIs: no need to set variables to nil explicitely
Browse files Browse the repository at this point in the history
This is mostly done for consistency across the Lua AI code
  • Loading branch information
mattsc committed Aug 30, 2018
1 parent 80ae232 commit 0e7c09f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions data/ai/lua/generic_recruit_engine.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion data/ai/lua/generic_rush_engine.lua
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion data/ai/lua/retreat.lua
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua
Expand Up @@ -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)

Expand Down

0 comments on commit 0e7c09f

Please sign in to comment.