Skip to content

Commit

Permalink
Campaigns: cleaned up more cases of deprecated Lua API usage
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Vultraz committed Mar 16, 2018
1 parent c723ca4 commit 3783693
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
30 changes: 15 additions & 15 deletions data/campaigns/Eastern_Invasion/lua/bandits.lua
Expand Up @@ -5,17 +5,17 @@ local helper = wesnoth.require "helper"
local wml_actions = wesnoth.wml_actions
local _ = wesnoth.textdomain "wesnoth-ei"
local T = wml.tag
local vars = wml.variables

function wml_actions.spread_bandit_villages(cfg)
local x = cfg.x or helper.wml_error("[spread_bandit_villages] missing required x= attribute.")
local y = cfg.y or helper.wml_error("[spread_bandit_villages] missing required y= attribute.")
local count = cfg.count or helper.wml_error("[spread_bandit_villages] missing required count= attribute.")
local types = cfg.types or helper.wml_error("[spread_bandit_villages] missing required types= attribute.")

wesnoth.set_variable("villages_visited", 0)
wesnoth.set_variable("boss_found", false)

wesnoth.set_variable("bandit_types", types)
vars.villages_visited = 0
vars.boss_found = false
vars.bandit_types = types

local villages = wesnoth.get_villages(cfg)

Expand All @@ -27,17 +27,17 @@ function wml_actions.spread_bandit_villages(cfg)
for i = 0, (count - 1) do
village_i = helper.rand("1.."..#villages)

wesnoth.set_variable(string.format("bandit_villages[%d].x", i), villages[village_i][1])
wesnoth.set_variable(string.format("bandit_villages[%d].y", i), villages[village_i][2])
vars[string.format("bandit_villages[%d].x", i)] = villages[village_i][1]
vars[string.format("bandit_villages[%d].y", i)] = villages[village_i][2]
table.remove(villages, village_i)
end
end

local function bandits_found(x,y)
local bandit_types = wesnoth.get_variable("bandit_types")
local bandit_villages = helper.get_variable_array("bandit_villages")
local boss_found = wesnoth.get_variable("boss_found")
local visited = wesnoth.get_variable("villages_visited")
local bandit_types = vars.bandit_types
local bandit_villages = wml.variable.get_array("bandit_villages")
local boss_found = vars.boss_found
local visited = vars.villages_visited
local rand1 = helper.rand("3,4")
local rand2 = helper.rand("2.."..rand1)

Expand All @@ -61,24 +61,24 @@ local function bandits_found(x,y)
local rand3 = helper.rand("1..100")

if rand3 <= boss_chance or #bandit_villages < 3 then
wesnoth.set_variable("boss_found", true)
vars.boss_found = true;
local loc = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } })[1]
wesnoth.fire_event("boss_found", x, y, loc[1], loc[2])
end
end
end

function wml_actions.bandit_village_capture(cfg)
local bandit_villages = helper.get_variable_proxy_array("bandit_villages")
local bandit_villages = wml.variable.get_proxy_array("bandit_villages")
local x = cfg.x or helper.wml_error("[bandit_village_capture] missing required x= attribute.")
local y = cfg.y or helper.wml_error("[bandit_village_capture] missing required y= attribute.")

for i=1,#bandit_villages do
if bandit_villages[i].x == x and bandit_villages[i].y == y then
wesnoth.set_variable(string.format("bandit_villages[%d]", i - 1))
vars[string.format("bandit_villages[%d]"] = i - 1

local visited = wesnoth.get_variable("villages_visited")
wesnoth.set_variable("villages_visited", visited + 1)
local visited = vars.villages_visited
vars.villages_visited = visited + 1

wesnoth.fire("message" , { x = x , y = y , message = _"They're here!"})

Expand Down
Expand Up @@ -169,7 +169,7 @@

local locations = wesnoth.get_locations{terrain = 'Ce,Ch,Chr,Co,Gd,Gd^Vc,Gd^Vh,Gd^Vo,Gll^Fp,Hhd,Hhd^Fp,Hhd^Vo,Ke,Khr,Ko,Md,Mm,Rd,Re,Re^Vo,Rr,Ww'}

local coverage = wesnoth.get_variable("snowCoverage")
local coverage = wml.variables.snowCoverage
if coverage == nil or coverage < 0 then
coverage = 0
elseif coverage > 1 then
Expand Down
Expand Up @@ -19,10 +19,11 @@
[lua]
code=<<
function wesnoth.wml_actions.show_countdown(cfg)
local vars = wml.variables
local _ = wesnoth.textdomain "wesnoth-httt"
local n = wesnoth.get_variable("units_to_slay")
local n = vars.units_to_slay
local obj = _("Defeat one more enemy unit", "Defeat $units_to_slay enemy units", n)
wesnoth.set_variable("units_to_slay_obj", wesnoth.format(obj, {units_to_slay = n}))
vars.units_to_slay_obj = wesnoth.format(obj, {units_to_slay = n})
if not cfg.silent then
local splash = _("Still $units_to_slay clan member to defeat!", "Still $units_to_slay clan members to defeat!", n)
wesnoth.wml_actions.print{
Expand Down
40 changes: 20 additions & 20 deletions data/campaigns/Legend_of_Wesmere/lua/wml_tags.lua
Expand Up @@ -7,7 +7,7 @@ local replace_map = wesnoth.wml_actions.replace_map
local helper = wesnoth.require "helper"
local wml_actions = wesnoth.wml_actions
local T = wml.tag
local V = wml.variables
local vars = wml.variables

function wesnoth.wml_actions.shift_labels(cfg)
for k, v in ipairs(labels) do
Expand Down Expand Up @@ -71,15 +71,15 @@ function wesnoth.wml_actions.persistent_carryover_store(cfg)
variable = "side_store.unit"
}
--TODO: apply carryover multipler and carryover bonus.
V["side_store.gold"] = side.gold
for i = 1, V["side_store.unit.length"] do
V[string.format("side_store.unit[%d].x", i - 1)] = nil
V[string.format("side_store.unit[%d].y", i - 1)] = nil
V[string.format("side_store.unit[%d].hitpoints", i - 1)] = nil
V[string.format("side_store.unit[%d].moves", i - 1)] = nil
V[string.format("side_store.unit[%d].side", i - 1)] = nil
V[string.format("side_store.unit[%d].goto_x", i - 1)] = nil
V[string.format("side_store.unit[%d].goto_y", i - 1)] = nil
vars["side_store.gold"] = side.gold
for i = 1, vars["side_store.unit.length"] do
vars[string.format("side_store.unit[%d].x", i - 1)] = nil
vars[string.format("side_store.unit[%d].y", i - 1)] = nil
vars[string.format("side_store.unit[%d].hitpoints", i - 1)] = nil
vars[string.format("side_store.unit[%d].moves", i - 1)] = nil
vars[string.format("side_store.unit[%d].side", i - 1)] = nil
vars[string.format("side_store.unit[%d].goto_x", i - 1)] = nil
vars[string.format("side_store.unit[%d].goto_y", i - 1)] = nil
end
wml_actions.set_global_variable {
namespace = cfg.scenario_id,
Expand All @@ -88,7 +88,7 @@ function wesnoth.wml_actions.persistent_carryover_store(cfg)
immediate = true,
side = "global",
}
V["side_store"] = nil
vars["side_store"] = nil
::continue::
end
end
Expand All @@ -109,17 +109,17 @@ function wesnoth.wml_actions.persistent_carryover_unstore(cfg)
immediate = true,
}
end
if V["side_store.gold"] then
if vars["side_store.gold"] then
break
end
end
for i = 1, V["side_store.unit.length"] do
V[string.format("side_store.unit[%d].side", i - 1)] = num
local u = wesnoth.get_unit(V[string.format("side_store.unit[%d].id", i - 1)])
for i = 1, vars["side_store.unit.length"] do
vars[string.format("side_store.unit[%d].side", i - 1)] = num
local u = wesnoth.get_unit(vars[string.format("side_store.unit[%d].id", i - 1)])

if u then
V[string.format("side_store.unit[%d].x", i - 1)] = u.x
V[string.format("side_store.unit[%d].y", i - 1)] = u.y
vars[string.format("side_store.unit[%d].x", i - 1)] = u.x
vars[string.format("side_store.unit[%d].y", i - 1)] = u.y
u:extract()
end
wml_actions.unstore_unit {
Expand All @@ -130,9 +130,9 @@ function wesnoth.wml_actions.persistent_carryover_unstore(cfg)
animate = false,
}
end
if V["side_store.gold"] then
side.gold = side.gold + V["side_store.gold"]
if vars["side_store.gold"] then
side.gold = side.gold + vars["side_store.gold"]
end
V["side_store"] = nil
vars["side_store"] = nil
end
end
5 changes: 3 additions & 2 deletions data/campaigns/Northern_Rebirth/lua/respawn_utils.lua
@@ -1,5 +1,6 @@
local helper = wesnoth.require "helper"
local T = wml.tag
local vars = wml.variables

function wesnoth.wml_actions.find_respawn_point(cfg)
local respawn_near = cfg.respawn_near or helper.wml_error "[find_respawn_point] missing required respawn_near= key"
Expand Down Expand Up @@ -32,6 +33,6 @@ function wesnoth.wml_actions.find_respawn_point(cfg)
radius = radius + 1
until respawn_point[1]

wesnoth.set_variable(variable .. ".x", respawn_point[1][1])
wesnoth.set_variable(variable .. ".y", respawn_point[1][2])
vars[variable .. ".x"] = respawn_point[1][1]
vars[variable .. ".y"] = respawn_point[1][2]
end
2 changes: 1 addition & 1 deletion data/campaigns/The_Hammer_of_Thursagan/lua/spawns.lua
Expand Up @@ -28,7 +28,7 @@ function wml_actions.spawn_units(cfg)
end

if done > 0 then
for then_child in helper.child_range(cfg, "then") do
for then_child in wml.child_range(cfg, "then") do
local action = utils.handle_event_commands(then_child, "conditional")
if action ~= "none" then return end
end
Expand Down
2 changes: 1 addition & 1 deletion data/campaigns/tutorial/lua/character_selection.lua
Expand Up @@ -86,7 +86,7 @@ function wml_actions.select_character()
}

local character = wesnoth.show_dialog(character_selection_dialog)
local unit = wesnoth.get_variable("student_store")
local unit = wml.variables.student_store

if character == 2 then
wesnoth.put_unit({
Expand Down
4 changes: 2 additions & 2 deletions data/campaigns/tutorial/scenarios/01_Tutorial_part_1.cfg
Expand Up @@ -189,8 +189,8 @@

if hp_diff > 7 then hp_diff = 8 end

wesnoth.set_variable("student_hp", unit.hitpoints)
wesnoth.set_variable("student_hp_heal_amount", hp_diff)
wml.variables.student_hp = unit.hitpoints
wml.variables.student_hp_heal_amount = hp_diff
>>
[/lua]
[/event]
Expand Down

0 comments on commit 3783693

Please sign in to comment.