WC: Update a bunch of deprecated things
This commit is contained in:
parent
bb7483d456
commit
22fe1e9b71
25 changed files with 98 additions and 115 deletions
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)])
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -19,7 +19,7 @@ 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
|
||||
|
@ -27,7 +27,7 @@ on_event("recruit", 1, function(ec)
|
|||
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 )
|
||||
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -253,7 +253,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]
|
||||
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
|
||||
|
@ -261,7 +261,7 @@ function wc2_era.expand_hero_types(types_str)
|
|||
types = types_new
|
||||
types_new = {}
|
||||
end
|
||||
wc2_utils.remove_dublicates(types_res)
|
||||
wc2_utils.remove_duplicates(types_res)
|
||||
return types_res
|
||||
end
|
||||
|
||||
|
@ -269,7 +269,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 = wc2_utils.split_to_array(types_str)
|
||||
local types = stringx.split(types_str)
|
||||
local types_new = {}
|
||||
local names_res = {}
|
||||
while #types > 0 do
|
||||
|
@ -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
|
||||
|
@ -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)" ..
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
|
|
@ -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 = {}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -5,8 +5,8 @@ local wc2_invest = {}
|
|||
|
||||
function wc2_invest.add_items(side_num, num_items)
|
||||
local side = wesnoth.sides[side_num]
|
||||
local items_left = wc2_utils.split_to_array(side.variables["wc2.items_left"])
|
||||
local items_available = wc2_utils.split_to_array(side.variables["wc2.items"])
|
||||
local items_left = stringx.split(side.variables["wc2.items_left"])
|
||||
local items_available = stringx.split(side.variables["wc2.items"])
|
||||
for j = 1, num_items do
|
||||
local i = wesnoth.random(#items_left)
|
||||
table.insert(items_available, items_left[i])
|
||||
|
@ -26,7 +26,7 @@ end
|
|||
function wc2_invest.initialize()
|
||||
local all_items = {}
|
||||
for i,v in ipairs(wc2_artifacts.get_artifact_list()) do
|
||||
local not_available = wc2_utils.split_to_set(v.not_available or "")
|
||||
local not_available = stringx.map_split(v.not_available or "")
|
||||
if not not_available["player"] then
|
||||
table.insert(all_items, i)
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ end
|
|||
function wc2_invest.do_gold()
|
||||
local side_num = wesnoth.current.side
|
||||
local side = wesnoth.sides[side_num]
|
||||
local leaders = wesnoth.get_units { side = side_num, canrecruit = true }
|
||||
local leaders = wesnoth.units.find_on_map { side = side_num, canrecruit = true }
|
||||
side.gold = side.gold + 70
|
||||
wesnoth.wml_actions.wc2_map_supply_village {
|
||||
x = leaders[1].x,
|
||||
|
@ -68,10 +68,10 @@ end
|
|||
function wc2_invest.do_hero(t, is_local)
|
||||
local side_num = wesnoth.current.side
|
||||
local side = wesnoth.sides[side_num]
|
||||
local leaders = wesnoth.get_units { side = side_num, canrecruit = true }
|
||||
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 = wc2_utils.split_to_array(side.variables["wc2.commanders"])
|
||||
local commanders = stringx.split(side.variables["wc2.commanders"])
|
||||
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 = wc2_utils.split_to_array(side.variables["wc2.deserters"])
|
||||
local deserters = stringx.split(side.variables["wc2.deserters"])
|
||||
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 = wc2_utils.split_to_array(side.variables["wc2.heroes"])
|
||||
local heroes_available = stringx.split(side.variables["wc2.heroes"])
|
||||
local i = find_index(heroes_available, t)
|
||||
if i == nil then
|
||||
error("wc2 invest: invalid pick")
|
||||
|
@ -114,10 +114,10 @@ end
|
|||
function wc2_invest.do_item(t)
|
||||
local side_num = wesnoth.current.side
|
||||
local side = wesnoth.sides[side_num]
|
||||
local leaders = wesnoth.get_units { side = side_num, canrecruit = true }
|
||||
local leaders = wesnoth.units.find_on_map { side = side_num, canrecruit = true }
|
||||
local x,y = leaders[1].x, leaders[1].y
|
||||
|
||||
local items_available = wc2_utils.split_to_array(side.variables["wc2.items"], {}, tonumber)
|
||||
local items_available = stringx.split(side.variables["wc2.items"], {}, tonumber)
|
||||
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 = wc2_utils.split_to_array(side.variables["wc2.items"])
|
||||
local heroes_available = wc2_utils.split_to_array(side.variables["wc2.heroes"])
|
||||
local commanders_available = wc2_utils.split_to_array(side.variables["wc2.commanders"])
|
||||
local deserters_available = wc2_utils.split_to_array(side.variables["wc2.deserters"])
|
||||
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 trainings_available = wc2_training.list_available(side_num, {2,3,4,5,6})
|
||||
local gold_available = true
|
||||
for i =1,2 do
|
||||
|
|
|
@ -122,7 +122,7 @@ function wc2_show_invest_dialog_impl(args)
|
|||
local train_message = wc2_training.generate_message(v, current_grade + 1)
|
||||
local train_message_before = wc2_training.generate_message(v, current_grade)
|
||||
|
||||
local title = wesnoth.format(_ "$name Training", { name = training_info.name })
|
||||
local title = stringx.vformat(_ "$name Training", { name = training_info.name })
|
||||
local desc = wc2_training.describe_training_level2(current_grade, #training_info.grade) .. wc2_color.tc_text(" → ") .. wc2_training.describe_training_level2(current_grade + 1, #training_info.grade)
|
||||
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ local strings = {
|
|||
|
||||
-- when a leader dies, take a commonder and make him the leader.
|
||||
on_event("die", function(cx)
|
||||
local u = wesnoth.get_unit(cx.x1, cx.y1)
|
||||
local u = wesnoth.units.get(cx.x1, cx.y1)
|
||||
if (not u) or (not u:matches({ canrecruit = true })) then
|
||||
return
|
||||
end
|
||||
local commander = wesnoth.get_units {
|
||||
local commander = wesnoth.units.find_on_map {
|
||||
side = u.side,
|
||||
role = "commander",
|
||||
canrecruit = false
|
||||
|
|
|
@ -4,7 +4,7 @@ random_names.list = _"Aban,Abidin,Acacalide,Acimaëli,Acratoforo,Actarof,Adham,A
|
|||
|
||||
function random_names.generate()
|
||||
if type(random_names.list) ~= "table" then
|
||||
random_names.list = wc2_utils.split_to_array(tostring(random_names.list))
|
||||
random_names.list = stringx.splitandom_names.list))
|
||||
end
|
||||
return random_names.list[wesnoth.random(#random_names.list)]
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ end
|
|||
|
||||
-- the implementation of the addons reduces recall cost mechanic.
|
||||
function wesnoth.wml_actions.wc2_set_recall_cost(cfg)
|
||||
for i,u in ipairs(wesnoth.get_units { side = "1,2,3" }) do
|
||||
for i,u in ipairs(wesnoth.units.find_on_map { side = "1,2,3" }) do
|
||||
add_rc_object(u)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ local supply_images =
|
|||
}
|
||||
|
||||
function wesnoth.wml_actions.wc2_map_supply_village(t)
|
||||
local unit = wesnoth.get_unit(t.x, t.y)
|
||||
local unit = wesnoth.units.get(t.x, t.y)
|
||||
local loc = unit.loc
|
||||
wesnoth.set_terrain(loc, "Kh^Vov", "overlay")
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
local _ = wesnoth.textdomain 'wesnoth-wc'
|
||||
local on_event = wesnoth.require("on_event")
|
||||
local helper = wesnoth.require("helper")
|
||||
|
||||
local on_event = wesnoth.require "on_event"
|
||||
|
||||
local training = {}
|
||||
|
||||
|
@ -110,11 +108,11 @@ end
|
|||
|
||||
function training.describe_training_level(name, level, max_level)
|
||||
if level == max_level then
|
||||
return tostring(wesnoth.format(_ "$name Training Maximum Level", {
|
||||
return tostring(stringx.vformat(_ "$name Training Maximum Level", {
|
||||
name = name
|
||||
}))
|
||||
else
|
||||
return tostring(wesnoth.format(_ "$name Training level $level", {
|
||||
return tostring(stringx.vformat(_ "$name Training level $level", {
|
||||
name = name,
|
||||
level = level
|
||||
}))
|
||||
|
@ -125,7 +123,7 @@ function training.describe_training_level2(level, max_level)
|
|||
if level == max_level then
|
||||
return _ "Maximum Level"
|
||||
else
|
||||
return tostring(wesnoth.format(_ "level $level", {
|
||||
return tostring(stringx.vformat(_ "level $level", {
|
||||
level = level
|
||||
}))
|
||||
end
|
||||
|
@ -140,9 +138,9 @@ function training.generate_message(n_trainer, n_grade)
|
|||
local caption = training.describe_training_level(c_trainer.name, n_grade, #c_trainer.grade - 1)
|
||||
local messages = {}
|
||||
for unused, chance in ipairs(c_grade.chance) do
|
||||
local vchance = chance.variable_substitution ~= false and wesnoth.tovconfig(chance) or chance
|
||||
local vchance = chance.variable_substitution ~= false and wml.tovconfig(chance) or chance
|
||||
if (chance.value or 0) < 100 then
|
||||
local str = wesnoth.format(_ "$chance| chance to $arrow $desc", {
|
||||
local str = stringx.vformat(_ "$chance| chance to $arrow $desc", {
|
||||
chance = ("%d%%"):format(vchance.value),
|
||||
desc = wc2_utils.get_fstring(chance, "info"),
|
||||
arrow = wc2_color.tc_text(" → ")
|
||||
|
@ -165,7 +163,7 @@ function training.give_bonus(side_num, cx, amount, traintype_index)
|
|||
local cur_level = training.get_level(side_num, traintype_index)
|
||||
local new_level = cur_level + amount
|
||||
local teacher = wc2_heroes.place(amount > 1 and traintype.advanced_type or traintype.type, side_num, cx.x1,cx.y1)
|
||||
local u = wesnoth.get_unit(cx.x1, cx.y1)
|
||||
local u = wesnoth.units.get(cx.x1, cx.y1)
|
||||
wc2_utils.facing_each_other(u, teacher)
|
||||
|
||||
wesnoth.wml_actions.sound {
|
||||
|
@ -208,7 +206,7 @@ function training.pick_bonus(side_num)
|
|||
end
|
||||
|
||||
on_event("recruit", function(event_context)
|
||||
training.apply(wesnoth.get_unit(event_context.x1, event_context.y1))
|
||||
training.apply(wesnoth.units.get(event_context.x1, event_context.y1))
|
||||
end)
|
||||
|
||||
function training.apply(u)
|
||||
|
@ -225,13 +223,13 @@ function training.apply(u)
|
|||
local level = training.get_level(side, i) or 0
|
||||
for unused, chance in ipairs(training.get_chances(i, level)) do
|
||||
--some effects use expressions like $(5+{GRADE}) so we want variable_substitution there
|
||||
local vchance = wesnoth.tovconfig(chance)
|
||||
local vchance = wml.tovconfig(chance)
|
||||
local filter = wml.get_child(vchance, "filter")
|
||||
local matches_filter = (not filter) or u:matches(filter)
|
||||
if wesnoth.random(100) <= vchance.value and matches_filter then
|
||||
--wesnoth.wml_actions.message { message = "Got it" }
|
||||
table.insert(descriptions, wc2_utils.get_fstring(chance, "info"))
|
||||
for effect in helper.child_range(vchance, "effect") do
|
||||
for effect in wml.child_range(vchance, "effect") do
|
||||
table.insert(trait, {"effect", effect })
|
||||
end
|
||||
end
|
||||
|
@ -248,7 +246,7 @@ function training.apply(u)
|
|||
end
|
||||
|
||||
function wesnoth.wml_actions.wc2_apply_training(cfg)
|
||||
for i,u in ipairs(wesnoth.get_units(cfg)) do
|
||||
for i,u in ipairs(wesnoth.units.find_on_map(cfg)) do
|
||||
training.apply(u)
|
||||
end
|
||||
end
|
||||
|
@ -256,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 wc2_utils.split_to_array(cfg.among)
|
||||
local among = cfg.among and stringx.split(cfg.among)
|
||||
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
|
||||
|
@ -273,7 +271,7 @@ function training.describe_bonus(side, traintype)
|
|||
if cur_level == max_level then
|
||||
message = _"Nothing to learn here"
|
||||
else
|
||||
message = wesnoth.format(_"From $level_before to $level_after", {
|
||||
message = stringx.vformat(_"From $level_before to $level_after", {
|
||||
level_before = training.describe_training_level(traintype_data.name, cur_level, max_level),
|
||||
level_after = training.describe_training_level(traintype_data.name, cur_level + 1, max_level)
|
||||
})
|
||||
|
|
|
@ -1,23 +1,7 @@
|
|||
local on_event = wesnoth.require("on_event")
|
||||
local on_event = wesnoth.require "on_event"
|
||||
|
||||
local wc2_utils = {}
|
||||
|
||||
function wc2_utils.split_to_array(s, res)
|
||||
res = res or {}
|
||||
for part in tostring(s or ""):gmatch("[^%s,][^,]*") do
|
||||
table.insert(res, part)
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function wc2_utils.split_to_set(s, res)
|
||||
res = res or {}
|
||||
for part in tostring(s or ""):gmatch("[^%s,][^,]*") do
|
||||
res[part] = true
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function wc2_utils.set_to_array(s, res)
|
||||
res = res or {}
|
||||
for k,v in pairs(s) do
|
||||
|
@ -28,7 +12,7 @@ function wc2_utils.set_to_array(s, res)
|
|||
end
|
||||
|
||||
|
||||
function wc2_utils.remove_dublicates(t)
|
||||
function wc2_utils.remove_duplicates(t)
|
||||
local found = {}
|
||||
for i = #t, 1, -1 do
|
||||
local v = t[i]
|
||||
|
@ -44,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 wc2_utils.split_to_array(s2) or {}
|
||||
local array = s2 and stringx.split(s2) or {}
|
||||
if #array == 0 and generator then
|
||||
array = generator()
|
||||
end
|
||||
|
@ -76,7 +60,7 @@ function wc2_utils.pick_random_filtered(str, generator, filter)
|
|||
return
|
||||
end
|
||||
|
||||
local array = s2 and wc2_utils.split_to_array(s2) or {}
|
||||
local array = s2 and stringx.split(s2) or {}
|
||||
if #array == 0 and generator then
|
||||
array = generator()
|
||||
end
|
||||
|
@ -207,7 +191,7 @@ function wc2_utils.get_fstring(t, key)
|
|||
else
|
||||
args = {}
|
||||
end
|
||||
return wesnoth.format(t[key], args)
|
||||
return stringx.vformat(t[key], args)
|
||||
end
|
||||
|
||||
function wc2_utils.get_fstring_all(t)
|
||||
|
|
|
@ -142,7 +142,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
|
|||
}
|
||||
|
||||
for p_wml in wml.child_range(faction_info, "pair") do
|
||||
local p = wc2_utils.split_to_array(p_wml.types)
|
||||
local p = stringx.split(p_wml.types)
|
||||
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]))
|
||||
|
||||
|
@ -160,7 +160,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
|
|||
|
||||
if faction_wml then
|
||||
local random_leaders = {}
|
||||
for i,v in ipairs(wc2_utils.split_to_array(faction_wml.random_leader)) do
|
||||
for i,v in ipairs(stringx.split(faction_wml.random_leader)) do
|
||||
table.insert(random_leaders, wesnoth.unit_types[v].name)
|
||||
end
|
||||
random_leaders = wesnoth.format_conjunct_list("", random_leaders)
|
||||
|
@ -187,7 +187,7 @@ function wesnoth.wml_actions.wc2_show_wocopedia(cfg)
|
|||
local artifact_icon = artifact.icon or ""
|
||||
local artifact_name = artifact.name or ""
|
||||
local artifact_desc = artifact.description or ""
|
||||
local not_available = wc2_utils.split_to_set(artifact.not_available or "")
|
||||
local not_available = stringx.map_split(artifact.not_available or "")
|
||||
|
||||
if not_available.player then
|
||||
artifact_name = artifact_name .. str_not_for_players
|
||||
|
@ -251,7 +251,7 @@ wc2_utils.menu_item {
|
|||
image= "help/closed_section.png~SCALE(18,17)",
|
||||
synced = false,
|
||||
filter = function(x, y)
|
||||
local u = wesnoth.get_unit(x, y)
|
||||
local u = wesnoth.units.get(x, y)
|
||||
if wc2_artifacts.is_item_at(x, y) then
|
||||
return false
|
||||
end
|
||||
|
|
|
@ -76,7 +76,7 @@ function set_terrain_impl(data)
|
|||
end
|
||||
|
||||
function set_terrain_simul(cfg)
|
||||
cfg = helper.parsed(cfg)
|
||||
cfg = wml.parsed(cfg)
|
||||
local data = {}
|
||||
for i, r in ipairs(cfg) do
|
||||
r_new = {
|
||||
|
|
|
@ -152,7 +152,7 @@ function wct_bonus_chose_scenery(loc, theme, filter_extra)
|
|||
}
|
||||
}
|
||||
for i,v in ipairs(terrain_to_scenery) do
|
||||
for str in utils.split(v.terrain) do
|
||||
for j,str in ipairs(stringx.split(v.terrain)) do
|
||||
if str == terrain then
|
||||
scenery = v.scenery
|
||||
goto intial_list_screated
|
||||
|
|
|
@ -15,7 +15,7 @@ function pick_advance.has_options(u)
|
|||
end
|
||||
|
||||
on_event("pre_advance", function(ec)
|
||||
local u = wesnoth.get_unit(ec.x1, ec.y1)
|
||||
local u = wesnoth.units.get(ec.x1, ec.y1)
|
||||
if not pick_advance.has_options(u) then
|
||||
return
|
||||
end
|
||||
|
@ -27,12 +27,12 @@ on_event("pre_advance", function(ec)
|
|||
end)
|
||||
|
||||
function wesnoth.wml_actions.wc2_pya_set_pick(cfg)
|
||||
local u = wesnoth.get_unit(cfg.x, cfg.y)
|
||||
local u = wesnoth.units.get(cfg.x, cfg.y)
|
||||
u.variables.wc2_pya_pick = cfg.pick
|
||||
end
|
||||
|
||||
function wesnoth.wml_actions.wc2_pya_pick(cfg)
|
||||
local u = wesnoth.get_unit(cfg.x, cfg.y)
|
||||
local u = wesnoth.units.get(cfg.x, cfg.y)
|
||||
if not pick_advance.has_options(u) then
|
||||
return
|
||||
end
|
||||
|
@ -43,7 +43,7 @@ function wesnoth.wml_actions.wc2_pya_pick(cfg)
|
|||
local message_wml = {
|
||||
x=cfg.x,
|
||||
y=cfg.y,
|
||||
message= wesnoth.format(str_advancer_option, {name = current_name}),
|
||||
message= stringx.vformat(str_advancer_option, {name = current_name}),
|
||||
wml.tag.option {
|
||||
label = _"Random",
|
||||
image = wc2_color.tc_image("units/unknown-unit.png"),
|
||||
|
@ -80,7 +80,7 @@ wc2_utils.menu_item {
|
|||
if wml.variables.wc2_config_enable_pya == false then
|
||||
return false
|
||||
end
|
||||
local u = wesnoth.get_unit(x, y)
|
||||
local u = wesnoth.units.get(x, y)
|
||||
return u and u.side == wesnoth.current.side and pick_advance.has_options(u)
|
||||
end,
|
||||
handler = function(cx)
|
||||
|
|
|
@ -27,7 +27,7 @@ function wesnoth.effects.wc2_unitmarker(u, cfg)
|
|||
end
|
||||
|
||||
function wesnoth.wml_actions.wc2_toggle_overlay(cfg)
|
||||
local units = wesnoth.get_units(cfg)
|
||||
local units = wesnoth.units.find_on_map(cfg)
|
||||
for i, u in ipairs(units) do
|
||||
local overlay_nr = u.variables["mods.wc2_unitmarker"]
|
||||
if overlay_nr ~= nil then
|
||||
|
@ -54,7 +54,7 @@ wc2_utils.menu_item {
|
|||
if wml.variables.wc2_config_enable_unitmarker == false then
|
||||
return false
|
||||
end
|
||||
local u = wesnoth.get_unit(x, y)
|
||||
local u = wesnoth.units.get(x, y)
|
||||
return u and u.side == wesnoth.current.side
|
||||
end,
|
||||
handler = function(cx)
|
||||
|
|
|
@ -48,6 +48,7 @@ _ "World Conquest 3p" #enddef
|
|||
if status then
|
||||
return res
|
||||
else
|
||||
print(res)
|
||||
std_print(res)
|
||||
end
|
||||
"
|
||||
|
|
Loading…
Add table
Reference in a new issue