Skip to content

Commit

Permalink
Merge branch 'wml_tag_porting'
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 27, 2017
2 parents c778a00 + 9802de9 commit 8822dac
Show file tree
Hide file tree
Showing 13 changed files with 684 additions and 492 deletions.
28 changes: 26 additions & 2 deletions changelog
Expand Up @@ -27,8 +27,30 @@ Version 1.13.6+dev:
* Updated translations: British English, Czech, German, Portuguese (Brazil),
Scottish Gaelic
* Lua API:
* New attributes in side proxy:
num_units, num_villages, total_upkeep, expenses, net_income
* New wesnoth.set_side_id function can change flag, color, or both; it automatically
updates cached flag info for you (but you may still need to redraw to see it).
* The wesnoth.place_shroud and wesnoth.clear_shroud functions can alter shroud data
for a single side. They accept a list of locations, a shroud data string, or the
special value "all".
* New wesnoth.is_fogged and wesnoth.is_shrouded calls test the visibility level
of a hex for a particular side.
* New wesnoth.create_animator call produces an object that can be used to run
animations for a group of units
* New Lua API functions for altering AI:
* wesnoth.switch_ai replaces the entire AI with a definition from a file
* wesnoth.append_ai appends AI parameters to the configuation; supports goals,
stages, and simple aspects.
(Aspect tags are not fully parsed; only the id and facet subtags are used.)
* wesnoth.add_ai_component, delete_ai_component, change_ai_component
These do the work of the [modify_ai] tag for a single side.
* Side proxy changes:
* flag and flag_icon are never an empty string
* New mutable keys: suppress_end_turn_confirmation, share_vision
* New read-only keys: share_maps, share_view
num_units, num_villages, total_upkeep, expenses, net_income
* Existing keys made mutable: shroud, fog, flag, flag_icon
* wesnoth.scroll_to_tile now accepts a third boolean argument - if true, the scroll
is skipped when the tile is already visible onscreen.
* User Interface:
* List boxes now keep the selected item visible when you change the sorting
option.
Expand All @@ -41,6 +63,8 @@ Version 1.13.6+dev:
* Add ~CHAN() IPF that allows altering images according to formulas
It takes up to 4 WFL formulas, one for each channel (red, green,
blue, alpha); each works the same as the ~ADJUST_ALPHA() formula.
* New ability_type key in standard unit filters matches if the unit has any
ability of the specified type (tag name).
* Miscellaneous and bug fixes:
* Fixed severe lag/freeze on slow PCs (bug #25356)
* Updated wmlscope to handle the square braces syntax in file paths
Expand Down
203 changes: 193 additions & 10 deletions data/lua/wml-tags.lua
Expand Up @@ -13,6 +13,7 @@ end

wesnoth.require "lua/wml-flow.lua"
wesnoth.require "lua/wml/objectives.lua"
wesnoth.require "lua/wml/animate_unit.lua"
wesnoth.require "lua/wml/items.lua"
wesnoth.require "lua/wml/message.lua"
wesnoth.require "lua/wml/object.lua"
Expand Down Expand Up @@ -632,7 +633,67 @@ function wml_actions.unpetrify(cfg)
end

function wml_actions.heal_unit(cfg)
wesnoth.heal_unit(cfg)
local healers = helper.get_child("filter_second")
if healers then
healers = wesnoth.get_units{
ability_type = "heals",
T["and"](healers)
}
else
healers = {}
end

local who = helper.get_child("filter")
if who then
who = wesnoth.get_units(who)
else
who = wesnoth.get_units{
x = wesnoth.current.event_context.x1,
y = wesnoth.current.event_context.y1
}
end

local heal_full = cfg.amount == "full"
local moves_full = cfg.moves == "full"
local heal_amount_set = false
for i,u in ipairs(who) do
local heal_amount = u.max_hitpoints - u.hitpoints
if heal_full then
u.hitpoints = u.max_hitpoints
else
heal_amount = math.min(math.max(1, cfg.amount), heal_amount)
u.hitpoints = u.hitpoints + heal_amount
end

if moves_full then
u.moves = u.max_moves
else
u.moves = math.min(u.max_moves, u.moves + (cfg.moves or 0))
end

if cfg.restore_attacks then
u.attacks_left = u.max_attacks
end

if cfg.restore_statuses then
u.status.poisoned = false
u.status.petrified = false
u.status.slowed = false
u.status.unhealable = false
end

if not heal_amount_set then
heal_amount_set = true
wesnoth.set_variable("heal_amount", heal_amount)
end

if cfg.animate then
wesnoth.animate_unit{
T.filter(healers),
flag = "healing"
}
end
end
end

function wml_actions.transform_unit(cfg)
Expand Down Expand Up @@ -674,11 +735,36 @@ function wml_actions.store_side(cfg)
end
end

-- This is the port of the old [modify_ai] into lua. It is different from wesnoth.modify_ai in that it uses a standard side filter.
-- I don't know why these functions were made to behave differently, but this seems to be the more powerful and useful one according
-- to mattsc's comments
function wml_actions.modify_ai(cfg)
wesnoth.modify_ai_wml(cfg)
local sides = utils.get_sides(cfg)
local component, final
if cfg.action == "add" or cfg.action == "change" then
local start = string.find(cfg.path, "[a-z_]+%[[a-z0-9_*]*%]$")
final = string.find(cfg.path, '[', start, true) - 1
local comp_type = string.sub(cfg.path, start, final)
component = helper.get_child(cfg, comp_type)
if component == nil then
helper.wml_error("Missing component definition in [modify_ai]")
end
component = helper.parsed(component)
end
for i = 1, #sides do
if cfg.action == "add" then
wesnoth.add_ai_component(sides[i].side, cfg.path, component)
elseif cfg.action == "delete" or cfg.action == "try_delete" then
wesnoth.delete_ai_component(sides[i].side, cfg.path)
elseif cfg.action == "change" then
local id_start = final + 2
local id_final = string.len(cfg.path) - 1
local id = string.sub(cfg.path, id_start, id_final)
if id == "*" then
helper.wml_error("[modify_ai] can only change one component at a time")
elseif not component.id and not id:match("[0-9]+") then
component.id = id
end
wesnoth.change_ai_component(sides[i].side, cfg.path, component)
end
end
end

function wml_actions.add_ai_behavior(cfg)
Expand Down Expand Up @@ -817,10 +903,6 @@ function wml_actions.scroll(cfg)
wesnoth.scroll(cfg)
end

function wml_actions.animate_unit(cfg)
wesnoth.animate_unit(cfg)
end

function wml_actions.color_adjust(cfg)
wesnoth.color_adjust(cfg)
end
Expand Down Expand Up @@ -861,8 +943,109 @@ function wml_actions.label( cfg )
end
end

local side_changes_needing_redraw = {
'shroud', 'fog', 'reset_map', 'reset_view', 'shroud_data',
'share_vision', 'share_maps', 'share_view',
'color', 'flag',
}
function wml_actions.modify_side(cfg)
wesnoth.modify_side(cfg)
local sides = utils.get_sides(cfg)
for i,side in ipairs(sides) do
if cfg.team_name then
side.team_name = cfg.team_name
end
if cfg.user_team_name then
side.user_team_name = cfg.user_team_name
end
if cfg.controller then
side.controller = cfg.controller
end
if cfg.defeat_condition then
side.defeat_condition = cfg.defeat_condition
end
if cfg.recruit then
local recruits = {}
for recruit in utils.split(cfg.recruit) do
table.insert(recruits, recruit)
end
side.recruit = recruits
end
if cfg.village_support then
side.village_support = cfg.village_support
end
if cfg.village_gold then
side.village_gold = cfg.village_gold
end
if cfg.income then
side.base_income = cfg.income
end
if cfg.gold then
side.gold = cfg.gold
end

if cfg.hidden ~= nil then
side.hidden = cfg.hidden
end
if cfg.color or cfg.flag then
wesnoth.set_team_id(side.side, cfg.flag, cfg.color)
end
if cfg.flag_icon then
side.flag_icon = cfg.flag_icon
end
if cfg.suppress_end_turn_confirmation ~= nil then
side.suppress_end_turn_confirmation = cfg.suppress_end_turn_confirmation
end
if cfg.scroll_to_leader ~= nil then
side.scroll_to_leader = cfg.scroll_to_leader
end

if cfg.shroud ~= nil then
side.shroud = cfg.shroud
end
if cfg.reset_maps then
wesnoth.clear_shroud(side.side, "all")
end
if cfg.fog ~= nil then
side.fog = cfg.fog
end
if cfg.reset_view then
wesnoth.add_fog(side.side, {}, true)
end
if cfg.shroud_data then
wesnoth.clear_shroud(side, cfg.shroud_data)
end

if cfg.share_vision then
side.share_vision = cfg.share_vision
end
-- Legacy support
if cfg.share_view ~= nil or cfg.share_maps ~= nil then
if cfg.share_view then
side.share_vision = 'all'
elseif cfg.share_maps then
side.share_vision = 'shroud'
else
side.share_vision = 'none'
end
end

if cfg.switch_ai then
wesnoth.switch_ai(side.side, cfg.switch_ai)
end
local ai = {}
for next_ai in helper.child_range(cfg, "ai") do
table.insert(ai, T.ai(next_ai))
end
if #ai > 0 then
wesnoth.append_ai(side.side, ai)
end
end
for i,key in ipairs(side_changes_needing_redraw) do
if cfg[key] ~= nil then
wml_actions.redraw{}
return
end
end
end

function wml_actions.open_help(cfg)
Expand Down
24 changes: 16 additions & 8 deletions data/lua/wml-utils.lua
Expand Up @@ -50,19 +50,27 @@ function utils.vwriter.write(self, container)
self.index = self.index + 1
end

function utils.get_sides(cfg, key_name, filter_name)
key_name = key_name or "side"
filter_name = filter_name or "filter_side"
local filter = helper.get_child(cfg, filter_name)
if filter then
if cfg[key_name] then
wesnoth.log('warn', "ignoring duplicate side filter information (inline side=)")
end
return wesnoth.get_sides(filter)
else
return wesnoth.get_sides{side = cfg[key_name]}
end
end

function utils.optional_side_filter(cfg, key_name, filter_name)
local key_name = key_name or "side"
local sides = cfg[key_name]
local filter_name = filter_name or "filter_side"
local filter_side = helper.get_child(cfg, filter_name)
if filter_side then
sides = wesnoth.get_sides(filter_side)
elseif sides then
local dummy_cfg = {side=sides}
sides = wesnoth.get_sides(dummy_cfg)
else
if cfg[key_name] == nil and helper.get_child(cfg, filter_name) == nil then
return true
end
local sides = utils.get_sides(cfg, key_name, filter_name)
for index,side in ipairs(sides) do
if side.controller == "human" then
return true
Expand Down

0 comments on commit 8822dac

Please sign in to comment.