Merge pull request #698 from GregoryLundberg/GL_role

New features for [role]
This commit is contained in:
Celtic Minstrel 2016-07-29 22:53:58 -04:00 committed by GitHub
commit e8d148bec4
5 changed files with 56 additions and 8 deletions

View file

@ -3,6 +3,11 @@ Version 1.13.5+dev:
* Trait descriptions in the help are now generated. (This makes user-defined
traits show up in the help as well.)
* WML Engine:
* New attributes for [role]:
- search_recall_list=yes|no|only(default yes) controls where to look
- reassign=yes|no(default yes) if no, check for a unit and do not assign to another
- [auto_recall] sub-tag, if assigned to recall list, gives [recall] attributes (no SUF)
- [else] sub-tag, WML to execute if no unit found for the role
* New help_text= key for [trait] to set the description displayed in the help.
Version 1.13.5:

View file

@ -11,7 +11,7 @@
#define RECALL_ADVISOR
[role]
role=advisor
auto_recall=yes
[auto_recall][/auto_recall]
search_recall_list=yes
side=1
@ -35,7 +35,6 @@
#define PROMOTE_ADVISOR
[role]
role=advisor
auto_recall=no
search_recall_list=no
side=1
@ -49,7 +48,7 @@
#define RECALL_MAGE
[role]
role=mage
auto_recall=yes
[auto_recall][/auto_recall]
search_recall_list=yes
side=1

View file

@ -172,7 +172,7 @@
[role]
type=Huntsman,Ranger,Fugitive,Highwayman,Outlaw,Trapper,Bandit,Footpad,Poacher,Thug
role=Advisor
auto_recall=yes
[auto_recall][/auto_recall]
[not]
id=Harper,Baldras
[/not]

View file

@ -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
@ -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

View file

@ -426,6 +426,8 @@ WML_HANDLER_FUNCTION(move_units_fake,, cfg)
}
/// If we should recall units that match a certain description.
// If you change attributes specific to [recall] (that is, not a Standard Unit Filter)
// be sure to update data/lua/wml_tag, auto_recall feature for [role] to reflect your changes.
WML_HANDLER_FUNCTION(recall,, cfg)
{
LOG_NG << "recalling unit...\n";