Skip to content

Commit

Permalink
New features for [role]
Browse files Browse the repository at this point in the history
Add search_recall_list=only to search the recall list, but not the map
This is intended as a more clear way of doing 'x,y=recall,recall' and omitting search_recall_list. Note that search_recall_list=no with x,y=recall,recall produces a useless [role] which only runs the [else] block(s).

Add reassign attribute
Optional attribute, default 'yes'. If 'no' then do not re-assign the role if a unit already has the role. If 'no' and no unit has the role, the role is still assigned.

Refactor auto_recall as a sub-tag
Instead of a yes|no attribute, if there is an [auto_recall] sub-tag then recall the unit from the recall list. This acts as a [recall] tag without any StandardUnitFilterto which we add id=$unit.id and issue the recall.
  • Loading branch information
GregoryLundberg committed Jul 29, 2016
1 parent 7ca8897 commit b064328
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions data/lua/wml-tags.lua
Expand Up @@ -910,10 +910,51 @@ function wml_actions.role(cfg)
end

filter.role, filter.type = nil, nil
local search_map, search_recall = true, true
if cfg.search_recall_list ~= nil then
local search_map, search_recall, reassign = true, true, true
if cfg.search_recall_list == "only" then
search_map = false
elseif cfg.search_recall_list ~= nil then
search_recall = not not cfg.search_recall_list
end
if cfg.reassign ~= nil then
reassign = not not cfg.reassign
end

-- pre-build a new [recall] from the [auto_recall]
-- copy only recall-specific attributes, no SUF at all
-- the SUF will be id= which we will add in a moment
-- keep this in sync with the C++ recall function!!!
local recall = nil
local child = helper.get_child(cfg, "auto_recall")
if child ~= nil then
if helper.get_nth_child(cfg, "auto_recall", 2) ~= nil then
wesnoth.log("debug", "More than one [auto_recall] found within [role]", true)
end
local original = helper.shallow_literal(child)
recall = {}
recall.x = original.x
recall.y = original.y
recall.show = original.show
recall.fire_event = original.fire_event
recall.check_passability = original.check_passability
end

if not reassign then
if search_map then
local unit = wesnoth.get_units{role=role}[1]
if unit then
return
end
end
if recall and search_recall then
local unit = wesnoth.get_recall_units{role=role}[1]
if unit then
recall.id = unit.id
wml_actions.recall(recall)
return
end
end
end

if search_map then
-- first attempt to match units on the map
Expand Down Expand Up @@ -942,8 +983,9 @@ function wml_actions.role(cfg)
local unit = wesnoth.get_recall_units(filter)[1]
if unit then
unit.role = role
if cfg.auto_recall then
wml_actions.recall{role=role}
if recall then
recall.id = unit.id
wml_actions.recall(recall)
end
return
end
Expand Down

0 comments on commit b064328

Please sign in to comment.