Skip to content

Commit

Permalink
WC: Update a bunch of deprecated things
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 20, 2021
1 parent bb7483d commit 22fe1e9
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 115 deletions.
2 changes: 1 addition & 1 deletion data/campaigns/World_Conquest/lua/campaign/difficulty.lua
Expand Up @@ -35,7 +35,7 @@ local function wct_difficulty(name, power, enemy_t, heroes, gold, train, exp)
heroes = heroes + 1
end
-- adjust bonus gold for number of players
gold = gold * math.pow(2, 3 - nplayers)
gold = gold * 2 ^ (3 - nplayers)
return wml.tag.command {
wml.tag.set_variables {
name = "wc2_difficulty",
Expand Down
20 changes: 10 additions & 10 deletions data/campaigns/World_Conquest/lua/campaign/enemy.lua
Expand Up @@ -23,7 +23,7 @@ local function get_advanced_units(level, list, res)
end

function enemy.pick_suitable_enemy_item(unit)
local enemy_items = wc2_utils.split_to_array(wml.variables["wc2_enemy_army.artifacts"])
local enemy_items = stringx.split(wml.variables["wc2_enemy_army.artifacts"])
if #enemy_items == 0 then
enemy_items = wc2_artifacts.fresh_artifacts_list("enemy")
end
Expand Down Expand Up @@ -59,7 +59,7 @@ on_event("recruit", function(ec)
return
end
side_variables["wc2.random_items"] = needs_item - 1
local unit = wesnoth.get_unit(ec.x1, ec.y1)
local unit = wesnoth.units.get(ec.x1, ec.y1)
local item_id = enemy.pick_suitable_enemy_item(unit)
wc2_artifacts.give_item(unit, item_id, false)
if true then
Expand Down Expand Up @@ -104,7 +104,7 @@ function enemy.do_supply(cfg, group_id, loc)
if not (cfg.supply == 1) then
return
end
local u = wesnoth.get_unit(loc[1], loc[2])
local u = wesnoth.units.get(loc[1], loc[2])
u:add_modification("trait", wc2_heroes.trait_expert)

wesnoth.wml_actions.event {
Expand All @@ -121,7 +121,7 @@ end
on_event("recruit", function(ec)
local side_num = wesnoth.current.side
local side_variables = wesnoth.sides[side_num].variables
local to_recall = wc2_utils.split_to_array(side_variables["wc2.to_recall"] or "")
local to_recall = stringx.split(side_variables["wc2.to_recall"] or "")
if #to_recall == 0 then
return
end
Expand Down Expand Up @@ -161,12 +161,12 @@ function enemy.do_recall(cfg, group_id, loc)
local side_variables = wesnoth.sides[side_num].variables

local group = wml.variables[("wc2_enemy_army.group[%d]"):format(group_id)]
local to_recall = wc2_utils.split_to_array(side_variables["wc2.to_recall"])
local to_recall = stringx.split(side_variables["wc2.to_recall"])
local function recall_level(level)
local amount = wml.get_child(cfg, "recall")["level" .. level] or 0
local types = wc2_utils.split_to_array(wml.get_child(group, "recall")["level" .. level] or "")
local types = stringx.split(wml.get_child(group, "recall")["level" .. level] or "")
if #types == 0 then
get_advanced_units(level, wc2_utils.split_to_array(group.recruit), types)
get_advanced_units(level, stringx.split(group.recruit), types)
end
for i = 1, amount do
table.insert(to_recall, types[wesnoth.random(#types)])
Expand All @@ -180,7 +180,7 @@ end
-- WCT_ENEMY_FAKE_RECALL
function enemy.fake_recall(side_num, t, loc)
local side = wesnoth.sides[side_num]
local u = wesnoth.create_unit {
local u = wesnoth.units.create {
side = side_num,
type = t,
generate_name = true,
Expand Down Expand Up @@ -247,7 +247,7 @@ function wesnoth.wml_actions.wc2_enemy(cfg)
enemy.do_gold(cfg, side)
local dummy_unit = wesnoth.get_units({side = side_num, canrecruit = true})[1]
local dummy_unit = wesnoth.units.find_on_map({side = side_num, canrecruit = true})[1]
local loc = {dummy_unit.x,dummy_unit.y}
dummy_unit:erase()
local enemy_type_id = wc2_utils.pick_random("wc2_enemy_army.factions_available") - 1
Expand All @@ -261,7 +261,7 @@ function wesnoth.wml_actions.wc2_enemy(cfg)
end
end
local leader_cfg = wc2_utils.pick_random_t(("wc2_enemy_army.group[%d].leader"):format(enemy_type_id))
local unit = wesnoth.create_unit {
local unit = wesnoth.units.create {
x = loc[1],
y = loc[2],
type = scenario == 1 and leader_cfg.level2 or leader_cfg.level3,
Expand Down
4 changes: 2 additions & 2 deletions data/campaigns/World_Conquest/lua/campaign/enemy_themed.lua
Expand Up @@ -11,7 +11,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance)
if wesnoth.random(100) > chance then
return
end
local boss = wesnoth.get_units {
local boss = wesnoth.units.find_on_map {
side="4,5,6,7,8,9",
canrecruit=true,
race=race,
Expand Down Expand Up @@ -76,7 +76,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance)
y = boss.y,
type=pet,
side = boss.side,
name= wesnoth.format(enemy_pet, { name = boss.name }),
name= stringx.vformat(enemy_pet, { name = boss.name }),
role = "hero",
overlays = "misc/hero-icon.png",
wml.tag.modifications {
Expand Down
6 changes: 3 additions & 3 deletions data/campaigns/World_Conquest/lua/campaign/scenario.lua
Expand Up @@ -19,15 +19,15 @@ end

-- happens before training events.
on_event("recruit", 1, function(ec)
local u = wesnoth.get_unit(ec.x1, ec.y1)
local u = wesnoth.units.get(ec.x1, ec.y1)
if (not u) or (not wc2_scenario.is_human_side(u.side)) then
return
end
u:add_modification("advancement", { wc2_scenario.experience_penalty() })
end)

function wesnoth.wml_actions.wc2_start_units(cfg)
local u = wesnoth.get_units({ side = cfg.side, canrecruit = true })[1]
local u = wesnoth.units.find_on_map({ side = cfg.side, canrecruit = true })[1]
if not u then error("[wc2_start_units] no leader found") end
u:add_modification("advancement", { wc2_scenario.experience_penalty() })
u:add_modification("trait", wc2_heroes.trait_heroic )
Expand All @@ -43,7 +43,7 @@ function wesnoth.wml_actions.wc2_start_units(cfg)
end

function wesnoth.wml_actions.wc2_store_carryover(cfg)
local human_sides = wesnoth.get_sides(wml.get_child(cfg, "sides"))
local human_sides = wesnoth.sides.find(wml.get_child(cfg, "sides"))
--use an the average amount of villages for this scenario to stay independent of map generator results.
local nvillages = cfg.nvillages
local turns_left = math.max(wesnoth.game_config.last_turn - wesnoth.current.turn, 0)
Expand Down
38 changes: 19 additions & 19 deletions data/campaigns/World_Conquest/lua/era/era.lua
Expand Up @@ -20,14 +20,14 @@ local images = {

-- the wc2 recruit pair logic.
on_event("recruit", function(ctx)
local unit = wesnoth.get_unit(ctx.x1, ctx.y1)
local unit = wesnoth.units.get(ctx.x1, ctx.y1)

local side_num = unit.side
local side = wesnoth.sides[side_num]
local unittype = unit.type

for i,v in ipairs(wml.array_access.get("wc2.pair", side)) do
local p = wc2_utils.split_to_array(v.types)
local p = stringx.split(v.types)
if p[1] == unittype and p[2] ~= nil then
wesnoth.wml_actions.disallow_recruit {
side = side_num,
Expand Down Expand Up @@ -60,7 +60,7 @@ end

local function init_side(side_num)

if wesnoth.get_side_variable(side_num, "wc2.faction_id") ~= nil then
if wesnoth.sides[side_num].variables["wc2.faction_id"] ~= nil then
-- don't do this twice.
return
end
Expand All @@ -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 = wc2_utils.split_to_array(v.types)
local p = stringx.split(v.types)
if wesnoth.random(1,2) == 2 then
p[1],p[2] = p[2],p[1]
end
Expand Down Expand Up @@ -115,13 +115,13 @@ local function add_known_hero_group(id, cfg)
end

local function add_known_spawn_filter(spawn_filter)
local types = wc2_utils.split_to_set(spawn_filter.types)
local types = stringx.map_split(spawn_filter.types)
local filter_location = wml.get_child(spawn_filter, "filter_location") or helper.wml_error("missing [filter_location] in [hero_spawn_filter]")
table.insert(wc2_era.spawn_filters, { types = types, filter_location = filter_location} )
end

local function add_known_trait_extra(trait_extra)
local types = wc2_utils.split_to_set(trait_extra.types)
local types = stringx.map_split(trait_extra.types)
local trait = wml.get_child(trait_extra, "trait") or helper.wml_error("missing [trait] in [trait_extra]")
table.insert(wc2_era.hero_traits, { types = types, trait = trait} )
end
Expand All @@ -138,11 +138,11 @@ function wc2_era.create_random_faction(id)
local i_heroes2 = wesnoth.random(#wc2_era.standard_factions)
local i_commanders = wesnoth.random(#wc2_era.standard_factions)

wc2_utils.split_to_set(wc2_era.standard_factions[i_deserters1].recruits, deserters_set)
wc2_utils.split_to_set(wc2_era.standard_factions[i_deserters2].recruits, deserters_set)
wc2_utils.split_to_set(wc2_era.standard_factions[i_heroes1].recruits, heros_set)
wc2_utils.split_to_set(wc2_era.standard_factions[i_heroes2].recruits, heros_set)
wc2_utils.split_to_set(wc2_era.standard_factions[i_commanders].recruits, commanders_set)
stringx.map_split(wc2_era.standard_factions[i_deserters1].recruits, deserters_set)
stringx.map_split(wc2_era.standard_factions[i_deserters2].recruits, deserters_set)
stringx.map_split(wc2_era.standard_factions[i_heroes1].recruits, heros_set)
stringx.map_split(wc2_era.standard_factions[i_heroes2].recruits, heros_set)
stringx.map_split(wc2_era.standard_factions[i_commanders].recruits, commanders_set)

local faction = {
id = "custom_random",
Expand Down Expand Up @@ -228,7 +228,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 = wc2_utils.split_to_array(side_variables["wc2.deserters"])
local deserters = stringx.split(side_variables["wc2.deserters"])
if #deserters == 0 then
return nil
end
Expand All @@ -244,7 +244,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 = wc2_utils.split_to_array(types_str)
local types = stringx.split(types_str)
local types_new = {}
local types_res = {}
while #types > 0 do
Expand All @@ -253,23 +253,23 @@ 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]
wc2_utils.split_to_array(group.types, types_new)
stringx.split(group.types, types_new)
else
wesnoth.message("WCII ERROR", "unknown deserter group: '" .. v .. "'")
end
end
types = types_new
types_new = {}
end
wc2_utils.remove_dublicates(types_res)
wc2_utils.remove_duplicates(types_res)
return types_res
end

-- replaces group ids with the corresponding unit lists.and replaces unit type ids with their names. (used by wocopedia)
-- @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 = wc2_utils.split_to_array(types_str)
local types = stringx.split(types_str)
local types_new = {}
local names_res = {}
while #types > 0 do
Expand All @@ -282,7 +282,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
wc2_utils.split_to_array(group.types, types_new)
stringx.split(group.types, types_new)
end
end
end
Expand Down Expand Up @@ -326,7 +326,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 = wc2_utils.split_to_array(v.types)
local p = stringx.split(v.types)
local ut1 = wesnoth.unit_types[p[1]]
local ut2 = wesnoth.unit_types[p[2]]
local img = "misc/blank.png~SCALE(144,72)" ..
Expand All @@ -347,7 +347,7 @@ wc2_utils.menu_item {
image=images.menu_recruit_info,
synced=false,
filter = function (x, y)
local u wesnoth.get_unit(x, y)
local u wesnoth.units.get(x, y)
if u and u.side == wesnoth.current.side then
return false
end
Expand Down
Expand Up @@ -3,7 +3,7 @@ local on_event = wesnoth.require("on_event")
----- the 'full movement on turn recuited' ability implementation -----
-- priority -1 because this event must be happen after the training event.
on_event("recruit,recall", -1, function(ec)
local unit = wesnoth.get_unit(ec.x1, ec.y1)
local unit = wesnoth.units.get(ec.x1, ec.y1)
if not unit then
return
end
Expand Down Expand Up @@ -37,7 +37,7 @@ end)

----- the 'disengage' ability implementation -----
on_event("attack_end", function(cx)
local u = wesnoth.get_unit(cx.x1, cx.y1)
local u = wesnoth.units.get(cx.x1, cx.y1)
if not u then
return
end
Expand Down
Expand Up @@ -121,7 +121,7 @@ end
-- unit picking up artifacts
on_event("wc2_drop_pickup", function(ec)
local item = wc2_dropping.current_item
local unit = wesnoth.get_unit(ec.x1, ec.y1)
local unit = wesnoth.units.get(ec.x1, ec.y1)
if not item.variables.wc2_atrifact_id then
return
end
Expand Down Expand Up @@ -165,7 +165,7 @@ end)
function artifacts.fresh_artifacts_list(for_type)
local res = {}
for i,v in ipairs(artifacts.get_artifact_list()) do
if not for_type or not wc2_utils.split_to_set(v.not_available or "")[for_type] then
if not for_type or not stringx.map_split(v.not_available or "")[for_type] then
table.insert(res, i)
end
end
Expand All @@ -175,7 +175,7 @@ end

-- drop all items a dying unit carries.
on_event("die", function(event_context)
local unit = wesnoth.get_unit(event_context.x1, event_context.y1)
local unit = wesnoth.units.get(event_context.x1, event_context.y1)
if not unit then
return
end
Expand Down
4 changes: 2 additions & 2 deletions data/campaigns/World_Conquest/lua/game_mechanics/bonus.lua
Expand Up @@ -31,7 +31,7 @@ function wesnoth.wml_actions.wc2_place_bonus(cfg)
wesnoth.wml_actions.label {
x = x,
y = y,
text = span_font_family(wesnoth.format(_ "$name's $type", {name = name1, type = name2}), "Lucida Sans Unicode")
text = span_font_family(stringx.vformat(_ "$name's $type", {name = name1, type = name2}), "Lucida Sans Unicode")
}
end

Expand Down Expand Up @@ -157,7 +157,7 @@ function bonus.found_artifact(ec, index)
end

function bonus.found_hero(ec, herotype)
local finder = wesnoth.get_unit(ec.x1, ec.y1)
local finder = wesnoth.units.get(ec.x1, ec.y1)
wesnoth.wml_actions.message {
x = ec.x1,
y = ec.y1,
Expand Down
4 changes: 2 additions & 2 deletions data/campaigns/World_Conquest/lua/game_mechanics/color.lua
Expand Up @@ -42,8 +42,8 @@ end
-- colors in the mp setup screen, we have to remember those settings and
-- set the teams color in later scenarios acccordingly.
function wesnoth.wml_actions.wc2_fix_colors(cfg)
local player_sides = wesnoth.get_sides(wml.get_child(cfg, "player_sides"))
local other_sides = wesnoth.get_sides { { "not", wml.get_child(cfg, "player_sides") } }
local player_sides = wesnoth.sides.find(wml.get_child(cfg, "player_sides"))
local other_sides = wesnoth.sides.find { { "not", wml.get_child(cfg, "player_sides") } }
local available_colors = { "red", "blue", "green", "purple", "black", "brown", "orange", "white", "teal" }
local taken_colors = {}

Expand Down
Expand Up @@ -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 = wc2_utils.split_to_array(cfg.add)
local to_add_old = stringx.split(cfg.add)
local to_add_new = {}
local current = u.overlays
for i1,v1 in ipairs(to_add_old) do
Expand Down
Expand Up @@ -74,7 +74,7 @@ function wc2_heroes.place(t, side, x, y, is_commander)
modifications,
is_commander and wc2_heroes.commander_overlay_object() or wc2_heroes.hero_overlay_object()
)
local u = wesnoth.create_unit {
local u = wesnoth.units.create {
type = t,
side = side,
random_traits = false,
Expand Down

0 comments on commit 22fe1e9

Please sign in to comment.