diff --git a/.luacheckrc b/.luacheckrc index 8fafac1bea6..005120ed2a3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -12,7 +12,4 @@ quiet=1 global=false -- don't show unused variables unused=false --- excluded files due to using lua 5.4 syntax that currently gets flagged as a syntax error --- clear out once a newer Ubuntu LTS base is used for our docker images, which would then also have a newer luacheck available --- leave the lua module exclusion however -exclude_files={"data/lua/core/wml.lua","data/lua/wml-flow.lua","data/lua/wml/find_path.lua","data/lua/wml/harm_unit.lua","data/lua/wml/modify_unit.lua","data/lua/wml/random_placement.lua","data/lua/functional.lua","src/modules/lua/testes/*.lua"} +exclude_files={"src/modules/lua/testes/*.lua"} diff --git a/data/lua/wml/find_path.lua b/data/lua/wml/find_path.lua index 94347ffd4a5..736a823415e 100644 --- a/data/lua/wml/find_path.lua +++ b/data/lua/wml/find_path.lua @@ -59,9 +59,9 @@ function wesnoth.wml_actions.find_path(cfg) ignore_visibility = ignore_visibility } ) - if #path == 0 or cost >= 42424241 then - -- it's not a reachable hex. 42424242 is the high value returned for unwalkable or busy terrains - else + -- it's a reachable hex. + -- it's not 0, and less than 42424242 which is the high value returned for unwalkable or busy terrains + if #path ~= 0 and cost < 42424241 then local steps = #path local is_better = false diff --git a/data/lua/wml/harm_unit.lua b/data/lua/wml/harm_unit.lua index cb3114aaaef..0d22257d21a 100644 --- a/data/lua/wml/harm_unit.lua +++ b/data/lua/wml/harm_unit.lua @@ -78,7 +78,6 @@ function wml_actions.harm_unit(cfg) damage_multiplier = damage_multiplier - tod_bonus elseif alignment == "liminal" then damage_multiplier = damage_multiplier + math.max(0, wesnoth.current.schedule.liminal_bonus - math.abs(tod_bonus)) - else -- neutral, do nothing end local resistance_modified = resistance * modifier damage_multiplier = damage_multiplier * resistance_modified diff --git a/data/lua/wml/modify_unit.lua b/data/lua/wml/modify_unit.lua index d5843520314..f9c017b1a87 100644 --- a/data/lua/wml/modify_unit.lua +++ b/data/lua/wml/modify_unit.lua @@ -10,20 +10,20 @@ function wml_actions.modify_unit(cfg) local replace_mode = cfg.mode == "replace" - local function handle_attributes(cfg, unit_path, toplevel) - for current_key, current_value in pairs(wml.shallow_parsed(cfg)) do + local function handle_attributes(child_cfg, unit_path, toplevel) + for current_key, current_value in pairs(wml.shallow_parsed(child_cfg)) do if type(current_value) ~= "table" and (not toplevel or (current_key ~= "type" and current_key ~= "mode")) then wml.variables[string.format("%s.%s", unit_path, current_key)] = current_value end end end - local function handle_child(cfg, unit_path) + local function handle_child(child_cfg, unit_path) local children_handled = {} - local cfg = wml.shallow_parsed(cfg) - handle_attributes(cfg, unit_path) + child_cfg = wml.shallow_parsed(child_cfg) + handle_attributes(child_cfg, unit_path) - for current_index, current_table in ipairs(cfg) do + for current_index, current_table in ipairs(child_cfg) do local current_tag = current_table[1] local tag_index = children_handled[current_tag] or 0 handle_child(current_table[2], string.format("%s.%s[%u]", @@ -43,7 +43,7 @@ function wml_actions.modify_unit(cfg) for current_index, current_table in ipairs(wml.shallow_parsed(cfg)) do local current_tag = current_table[1] if current_tag == "filter" then - -- nothing + goto skip elseif current_tag == "object" or current_tag == "trait" or current_tag == "advancement" then local mod = current_table[2] if mod.delayed_variable_substitution then @@ -85,6 +85,7 @@ function wml_actions.modify_unit(cfg) unit_path, current_tag, tag_index)) children_handled[current_tag] = tag_index + 1 end + ::skip:: end if cfg.type then diff --git a/data/lua/wml/random_placement.lua b/data/lua/wml/random_placement.lua index f71adede906..353b053a790 100644 --- a/data/lua/wml/random_placement.lua +++ b/data/lua/wml/random_placement.lua @@ -43,6 +43,7 @@ wesnoth.wml_actions.random_placement = function(cfg) wml.variables[variable .. ".terrain"] = wesnoth.current.map[point] if distance < 0 then -- optimisation: nothing to do for distance < 0 + goto skip elseif distance == 0 then -- optimisation: for distance = 0 we just need to remove the element at index -- optimisation: swapping elements and storing size in an extra variable is faster than table.remove(locs, j) @@ -77,6 +78,7 @@ wesnoth.wml_actions.random_placement = function(cfg) ::continue:: end end + ::skip:: -- TODO: This should really be "do" but is kept as "command" for compatibility for do_child in wml.child_range(cfg, "command") do local action = utils.handle_event_commands(do_child, "loop")