From d82d68e1f186aa1d7830b92071f9241fe8bddf66 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Wed, 4 Aug 2010 19:37:24 +0000 Subject: [PATCH] Moved [hide_unit] and [unhide_unit] implementations to Lua. Added support for standard unit filters along the way. (Partial fix for bug #16358.) --- data/lua/wml-tags.lua | 14 ++++++++++++++ src/game_events.cpp | 23 ----------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 8ce6349826f..6638a950a11 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -452,3 +452,17 @@ function wml_actions.store_locations(cfg) wesnoth.set_variable(string.format("%s[%d]", var, i - 1), res) end end + +function wml_actions.hide_unit(cfg) + for i,u in ipairs(wesnoth.get_units(cfg)) do + u.hidden = true + end + wml_actions.redraw {} +end + +function wml_actions.unhide_unit(cfg) + for i,u in ipairs(wesnoth.get_units(cfg)) do + u.hidden = false + end + wml_actions.redraw {} +end diff --git a/src/game_events.cpp b/src/game_events.cpp index 1ed92b7e35f..1f491ae2993 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -1604,29 +1604,6 @@ WML_HANDLER_FUNCTION(removeitem, event_info, cfg) } } -WML_HANDLER_FUNCTION(hide_unit, /*event_info*/, cfg) -{ - // Hiding units - const map_location loc = cfg_to_loc(cfg); - unit_map::iterator u = resources::units->find(loc); - if (u.valid()) { - u->set_hidden(true); - resources::screen->invalidate(loc); - resources::screen->draw(); - } -} - -WML_HANDLER_FUNCTION(unhide_unit, /*event_info*/, cfg) -{ - const map_location loc = cfg_to_loc(cfg); - // Unhide all for backward compatibility - foreach (unit &u, *resources::units) { - u.set_hidden(false); - resources::screen->invalidate(loc); - resources::screen->draw(); - } -} - // Adding new items WML_HANDLER_FUNCTION(item, /*event_info*/, cfg) {