Lua AIs: don't initiate variables as empty tables
... if they might not be needed.
(cherry-picked from commit a23f06dc20
)
This commit is contained in:
parent
7067402209
commit
e68a6eaba0
5 changed files with 13 additions and 13 deletions
|
@ -298,7 +298,7 @@ return {
|
|||
local enemy_attack_map = BC.get_attack_map(enemies).units
|
||||
|
||||
-- Now we go through the villages and units
|
||||
local max_rating, best_village, best_unit = - math.huge, {}, {}
|
||||
local max_rating, best_village, best_unit = - math.huge
|
||||
local village_ratings = {}
|
||||
for j,v in ipairs(villages) do
|
||||
-- First collect all information that only depends on the village
|
||||
|
@ -370,7 +370,7 @@ return {
|
|||
end
|
||||
end
|
||||
|
||||
if (max_rating > - math.huge) then
|
||||
if best_village then
|
||||
self.data.unit, self.data.village = best_unit, best_village
|
||||
if (max_rating >= 1000) then
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
|
@ -423,7 +423,7 @@ return {
|
|||
end
|
||||
|
||||
-- Go through all possible attacks with poisoners
|
||||
local max_rating, best_attack = - math.huge, {}
|
||||
local max_rating, best_attack = - math.huge
|
||||
for i,a in ipairs(attacks) do
|
||||
local attacker = wesnoth.get_unit(a.src.x, a.src.y)
|
||||
local defender = wesnoth.get_unit(a.target.x, a.target.y)
|
||||
|
@ -465,7 +465,7 @@ return {
|
|||
end
|
||||
end
|
||||
|
||||
if (max_rating > - math.huge) then
|
||||
if best_attack then
|
||||
self.data.attack = best_attack
|
||||
if AH.print_eval() then AH.done_eval_messages(start_time, ca_name) end
|
||||
return 190000
|
||||
|
|
|
@ -33,7 +33,7 @@ function ca_forest_animals_tusklet_move:execution(cfg)
|
|||
local tusklet = get_tusklets(cfg)[1]
|
||||
local tuskers = get_tuskers(cfg)
|
||||
|
||||
local goto_tusker, min_dist = {}, math.huge
|
||||
local min_dist, goto_tusker = math.huge
|
||||
for _,tusker in ipairs(tuskers) do
|
||||
local dist = M.distance_between(tusker.x, tusker.y, tusklet.x, tusklet.y)
|
||||
if (dist < min_dist) then
|
||||
|
|
|
@ -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 max_rating, best_hex, best_unit = - math.huge, {}
|
||||
local max_rating, best_hex, best_unit = - math.huge
|
||||
for i,u in ipairs(units) do
|
||||
local reach = wesnoth.find_reach(u)
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ function ca_transport:execution()
|
|||
end
|
||||
end
|
||||
|
||||
if (max_rating > - math.huge) then
|
||||
if best_unit then
|
||||
ai.move_full(best_unit, best_hex[1], best_hex[2])
|
||||
|
||||
-- Also unload units
|
||||
|
@ -128,12 +128,12 @@ function ca_transport:execution()
|
|||
}
|
||||
)
|
||||
|
||||
local max_rating, best_unit, best_hex = - math.huge, {}, {}
|
||||
local max_rating, best_unit, best_hex = - math.huge
|
||||
for i,u in ipairs(transports) do
|
||||
local dst = { u.variables.destination_x, u.variables.destination_y }
|
||||
local reach = wesnoth.find_reach(u)
|
||||
|
||||
local max_rating_unit, best_hex_unit = - math.huge, {}
|
||||
local max_rating_unit, best_hex_unit = - math.huge
|
||||
for i,r in ipairs(reach) do
|
||||
if deep_water_map:get(r[1], r[2]) and (not blocked_hex_map:get(r[1], r[2])) then
|
||||
local rating = -M.distance_between(r[1], r[2], dst[1], dst[2])
|
||||
|
@ -149,7 +149,7 @@ function ca_transport:execution()
|
|||
|
||||
-- We give a penalty to hexes occupied by another transport that can still move away.
|
||||
-- All ratings need to be set to the same value for this to work.
|
||||
if (max_rating_unit > - math.huge) then
|
||||
if best_hex_unit then
|
||||
max_rating_unit = 0
|
||||
if transport_map:get(best_hex_unit[1], best_hex_unit[2]) then
|
||||
max_rating_unit = -1
|
||||
|
@ -163,7 +163,7 @@ function ca_transport:execution()
|
|||
end
|
||||
end
|
||||
|
||||
if best_unit.id then
|
||||
if best_unit then
|
||||
ai.move_full(best_unit, best_hex[1], best_hex[2])
|
||||
else -- still need to make sure gamestate gets changed
|
||||
ai.stopunit_moves(transports[1])
|
||||
|
|
|
@ -15,7 +15,7 @@ function ca_aggressive_attack_no_suicide:evaluation(cfg, data)
|
|||
if (not attacks[1]) then return 0 end
|
||||
|
||||
-- Now find the best of the possible attacks
|
||||
local max_rating, best_attack = - math.huge, {}
|
||||
local max_rating, best_attack = - math.huge
|
||||
for i, att in ipairs(attacks) do
|
||||
local attacker = wesnoth.get_unit(att.src.x, att.src.y)
|
||||
local defender = wesnoth.get_unit(att.target.x, att.target.y)
|
||||
|
@ -44,7 +44,7 @@ function ca_aggressive_attack_no_suicide:evaluation(cfg, data)
|
|||
end
|
||||
end
|
||||
|
||||
if (max_rating > - math.huge) then
|
||||
if best_attack then
|
||||
data.attack = best_attack
|
||||
return 100000
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue