WC: Make sure we don't try to split nil

This commit is contained in:
Celtic Minstrel 2021-03-28 10:51:15 -04:00
parent f737013203
commit 7b4b9d8969
8 changed files with 26 additions and 26 deletions

View file

@ -23,7 +23,7 @@ local function get_advanced_units(level, list, res)
end
function enemy.pick_suitable_enemy_item(unit)
local enemy_items = stringx.split(wml.variables["wc2_enemy_army.artifacts"])
local enemy_items = stringx.split(wml.variables["wc2_enemy_army.artifacts"] or "")
if #enemy_items == 0 then
enemy_items = wc2_artifacts.fresh_artifacts_list("enemy")
end
@ -166,7 +166,7 @@ function enemy.do_recall(cfg, group_id, loc)
local amount = wml.get_child(cfg, "recall")["level" .. level] or 0
local types = stringx.split(wml.get_child(group, "recall")["level" .. level] or "")
if #types == 0 then
get_advanced_units(level, stringx.split(group.recruit), types)
get_advanced_units(level, stringx.split(group.recruit or ""), types)
end
for i = 1, amount do
table.insert(to_recall, types[wesnoth.random(#types)])

View file

@ -27,7 +27,7 @@ on_event("recruit", function(ctx)
local unittype = unit.type
for i,v in ipairs(wml.array_access.get("wc2.pair", side)) do
local p = stringx.split(v.types)
local p = stringx.split(v.types or "")
if p[1] == unittype and p[2] ~= nil then
wesnoth.wml_actions.disallow_recruit {
side = side_num,
@ -73,7 +73,7 @@ local function init_side(side_num)
local i = 0
for v in wml.child_range(faction, "pair") do
i = i + 1
local p = stringx.split(v.types)
local p = stringx.split(v.types or "")
if wesnoth.random(1,2) == 2 then
p[1],p[2] = p[2],p[1]
end
@ -226,7 +226,7 @@ end
-- picks a deserter for the side @a side_num using the list of posibel deserters for that sides faction.
function wc2_era.pick_deserter(side_num)
local side_variables = wesnoth.sides[side_num].variables
local deserters = stringx.split(side_variables["wc2.deserters"])
local deserters = stringx.split(side_variables["wc2.deserters"] or "")
if #deserters == 0 then
return nil
end
@ -242,7 +242,7 @@ end
-- @a types_str a comma seperated list of unti types and group ids.
-- @returns an array of unit types.
function wc2_era.expand_hero_types(types_str)
local types = stringx.split(types_str)
local types = stringx.split(types_str or "")
local types_new = {}
local types_res = {}
while #types > 0 do
@ -251,7 +251,7 @@ function wc2_era.expand_hero_types(types_str)
table.insert(types_res, v)
elseif wc2_era.hero_types[v] then
local group = wc2_era.hero_types[v]
local these_types = stringx.split(group.types)
local these_types = stringx.split(group.types or "")
for j,type in ipairs(these_types) do
table.insert(types_new, type)
end
@ -270,7 +270,7 @@ end
-- @a types_str a comma seperated list of unti types and group ids.
-- @returns an array of unit type names.
function wc2_era.expand_hero_names(types_str, only_unitnames)
local types = stringx.split(types_str)
local types = stringx.split(types_str or "")
local types_new = {}
local names_res = {}
while #types > 0 do
@ -283,7 +283,7 @@ function wc2_era.expand_hero_names(types_str, only_unitnames)
if group.name and not only_unitnames then
table.insert(names_res, group.name)
else
local these_types = stringx.split(group.types)
local these_types = stringx.split(group.types or "")
for j,type in ipairs(these_types) do
table.insert(types_new, type)
end
@ -330,7 +330,7 @@ function wesnoth.wml_actions.wc2_recruit_info(cfg)
}
for i,v in ipairs(wml.array_access.get("wc2.pair", side_num)) do
local p = stringx.split(v.types)
local p = stringx.split(v.types or "")
local ut1 = wesnoth.unit_types[p[1]]
local ut2 = wesnoth.unit_types[p[2]]
local img = "misc/blank.png~SCALE(144,72)" ..

View file

@ -138,7 +138,7 @@ end
-- Similar to the usual apply_to=overlay effect but does not add overlays the the unit already has.
function wesnoth.effects.wc2_overlay(u, cfg)
if cfg.add then
local to_add_old = stringx.split(cfg.add)
local to_add_old = stringx.split(cfg.add or "")
local to_add_new = {}
local current = u.overlays
for i1,v1 in ipairs(to_add_old) do

View file

@ -5,7 +5,7 @@ local wc2_invest = {}
function wc2_invest.add_items(side_num, num_items)
local side = wesnoth.sides[side_num]
local items_left = stringx.split(side.variables["wc2.items_left"])
local items_left = stringx.split(side.variables["wc2.items_left"] or "")
local items_available = stringx.split(side.variables["wc2.items"] or "")
for j = 1, num_items do
local i = wesnoth.random(#items_left)
@ -71,7 +71,7 @@ function wc2_invest.do_hero(t, is_local)
local leaders = wesnoth.units.find_on_map { side = side_num, canrecruit = true }
local x,y = leaders[1].x, leaders[1].y
if t == "wc2_commander" then
local commanders = stringx.split(side.variables["wc2.commanders"])
local commanders = stringx.split(side.variables["wc2.commanders"] or "")
local i = wesnoth.random(#commanders)
t = commanders[i]
table.remove(commanders, i)
@ -84,7 +84,7 @@ function wc2_invest.do_hero(t, is_local)
wesnoth.sides[side_num].gold = wesnoth.sides[side_num].gold + 15
local deserters = stringx.split(side.variables["wc2.deserters"])
local deserters = stringx.split(side.variables["wc2.deserters"] or "")
local i = wesnoth.random(#deserters)
t = deserters[i]
table.remove(deserters, i)
@ -94,7 +94,7 @@ function wc2_invest.do_hero(t, is_local)
end
wc2_heroes.place(t, side_num, x, y, false)
else
local heroes_available = stringx.split(side.variables["wc2.heroes"])
local heroes_available = stringx.split(side.variables["wc2.heroes"] or "")
local i = find_index(heroes_available, t)
if i == nil then
error("wc2 invest: invalid pick")
@ -117,7 +117,7 @@ function wc2_invest.do_item(t)
local leaders = wesnoth.units.find_on_map { side = side_num, canrecruit = true }
local x,y = leaders[1].x, leaders[1].y
local items_available = stringx.split(side.variables["wc2.items"])
local items_available = stringx.split(side.variables["wc2.items"] or "")
local i = find_index(items_available, tostring(t))
if i == nil then
error("wc2 invest: invalid item pick '" .. t .. "' (" .. type(t) ..")")
@ -131,10 +131,10 @@ end
function wc2_invest.invest()
local side_num = wesnoth.current.side
local side = wesnoth.sides[side_num]
local items_available = stringx.split(side.variables["wc2.items"])
local heroes_available = stringx.split(side.variables["wc2.heroes"])
local commanders_available = stringx.split(side.variables["wc2.commanders"])
local deserters_available = stringx.split(side.variables["wc2.deserters"])
local items_available = stringx.split(side.variables["wc2.items"] or "")
local heroes_available = stringx.split(side.variables["wc2.heroes"] or "")
local commanders_available = stringx.split(side.variables["wc2.commanders"] or "")
local deserters_available = stringx.split(side.variables["wc2.deserters"] or "")
local trainings_available = wc2_training.list_available(side_num, {2,3,4,5,6})
local gold_available = true
for i =1,2 do

View file

@ -254,7 +254,7 @@ end
function wesnoth.wml_actions.wc2_give_random_training(cfg)
local side_num = cfg.side
local amount = cfg.amount or 1
local among = cfg.among and stringx.split(cfg.among)
local among = cfg.among and stringx.split(cfg.among or "")
for i = 1, amount do
local traintype = training.find_available(side_num, among)
if traintype == nil then error("wc2_give_random_training: everything alerady maxed") end

View file

@ -28,7 +28,7 @@ end
function wc2_utils.pick_random(str, generator)
local s2 = wml.variables[str]
if s2 ~= nil or generator then
local array = s2 and stringx.split(s2) or {}
local array = s2 and stringx.split(s2 or "") or {}
if #array == 0 and generator then
array = generator()
end
@ -60,7 +60,7 @@ function wc2_utils.pick_random_filtered(str, generator, filter)
return
end
local array = s2 and stringx.split(s2) or {}
local array = s2 and stringx.split(s2 or "") or {}
if #array == 0 and generator then
array = generator()
end

View file

@ -137,7 +137,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
}
for p_wml in wml.child_range(faction_info, "pair") do
local p = stringx.split(p_wml.types)
local p = stringx.split(p_wml.types or "")
local ut1 = wesnoth.unit_types[p[1]] or error("invald unit type" .. tostring(p[1]))
local ut2 = wesnoth.unit_types[p[2]] or error("invald unit type" .. tostring(p[2]))
@ -155,7 +155,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
if faction_wml then
local random_leaders = {}
for i,v in ipairs(stringx.split(faction_wml.random_leader)) do
for i,v in ipairs(stringx.split(faction_wml.random_leader or "")) do
table.insert(random_leaders, wesnoth.unit_types[v].name)
end
random_leaders = wesnoth.format_conjunct_list("", random_leaders)

View file

@ -152,7 +152,7 @@ function wct_bonus_chose_scenery(loc, theme, filter_extra)
}
}
for i,v in ipairs(terrain_to_scenery) do
for j,str in ipairs(stringx.split(v.terrain)) do
for j,str in ipairs(stringx.split(v.terrain or "")) do
if str == terrain then
scenery = v.scenery
goto intial_list_screated