mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-20 14:21:08 +00:00

* Add basic achievements functionality. This reads the mainline achievements.cfg and then all the achievements of each installed add-on. This is intentionally handled separately from other WML loading so that: a) All achievements and their status are able to be displayed on the main menu right after Wesnoth starts and regardless of which add-ons are active. b) Add-ons can add additional achievements to other content, whether UMC or mainline. For example, a modification that adds more achievements for mainline campaigns. Marking something as achieved is handled by the new [set_achieved] tag and whether an achievement has been completed can be checked via [has_achievement]. There is no attempt to prevent people from manually editing which achievements they've accomplished. NOTE: These are *not* in any way related to Steam achievements!
45 lines
1.2 KiB
Lua
45 lines
1.2 KiB
Lua
function wesnoth.wml_conditionals.proceed_to_next_scenario(cfg)
|
|
local endlevel_data = wesnoth.scenario.end_level_data
|
|
|
|
if not endlevel_data then
|
|
return false
|
|
else
|
|
return endlevel_data.proceed_to_next_level
|
|
end
|
|
end
|
|
|
|
function wesnoth.wml_conditionals.lua(cfg)
|
|
cfg = wml.shallow_literal(cfg)
|
|
local bytecode, message = load(cfg.code or "", cfg.name or nil)
|
|
|
|
if not bytecode then
|
|
error("~lua:" .. message, 0)
|
|
else
|
|
return bytecode(wml.get_child(cfg, "args"))
|
|
end
|
|
end
|
|
|
|
-- Add formula= to [variable]
|
|
-- Doesn't work for array variables though
|
|
local old_variable = wesnoth.wml_conditionals.variable
|
|
function wesnoth.wml_conditionals.variable(cfg)
|
|
if cfg.formula then
|
|
local value = wml.variables[cfg.name]
|
|
if cfg.as_type == 'unit' then
|
|
value = wesnoth.units.create(value)
|
|
elseif cfg.as_type == 'weapon' then
|
|
value = wesnoth.units.create_weapon(value)
|
|
end
|
|
local result = wesnoth.eval_formula(cfg.formula, {value = value})
|
|
-- WFL considers 0 as false; Lua doesn't
|
|
if result == 0 then return false end
|
|
return result
|
|
else
|
|
return old_variable(cfg)
|
|
end
|
|
end
|
|
|
|
function wesnoth.wml_conditionals.has_achievement(cfg)
|
|
return wesnoth.achievements.has(cfg.content_for, cfg.id);
|
|
end
|