Allowed events to be fired conditionally via[event][condition]...

...(see FutureWML). Ment to be used when values of variables unrelated
to filtered units shall be queried, otherwise lua_function would need
to be misused for this. Allows for simplification/splitting up into
events for events with structure [event][if][variable][then][else].
This commit is contained in:
Anonymissimus 2010-09-23 14:20:09 +00:00
parent e7d337a676
commit da636556bd
2 changed files with 9 additions and 1 deletions

View file

@ -208,7 +208,7 @@ local function handle_event_commands(cfg)
for i = 1, #cfg do for i = 1, #cfg do
local v = cfg[i] local v = cfg[i]
local cmd = v[1] local cmd = v[1]
if not string.find(cmd, "^filter") then if not string.find(cmd, "^filter") and cmd ~= "condition" then
cmd = wml_actions[cmd] or cmd = wml_actions[cmd] or
helper.wml_error(string.format("[%s] not supported", cmd)) helper.wml_error(string.format("[%s] not supported", cmd))
cmd(v[2]) cmd(v[2])

View file

@ -2864,6 +2864,14 @@ static bool process_event(game_events::event_handler& handler, const game_events
scoped_weapon_info second_weapon("second_weapon", ev.data.child("second")); scoped_weapon_info second_weapon("second_weapon", ev.data.child("second"));
vconfig filters(handler.get_config()); vconfig filters(handler.get_config());
foreach (const vconfig &condition, filters.get_children("condition"))
{
if (!game_events::conditional_passed(condition)) {
return false;
}
}
foreach (const vconfig &f, filters.get_children("filter")) foreach (const vconfig &f, filters.get_children("filter"))
{ {
if (unit1 == units->end() || !game_events::unit_matches_filter(*unit1, f)) { if (unit1 == units->end() || !game_events::unit_matches_filter(*unit1, f)) {