diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 902c3ab9e334..5e7c364cd67f 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -1337,3 +1337,12 @@ end function wml_actions.remove_shroud(cfg) wesnoth.remove_shroud(cfg) end + +function wml_actions.time_area(cfg) + local remove = cfg.remove + if remove then + wesnoth.remove_time_area(cfg.id) + else + wesnoth.add_time_area(cfg.id, cfg) + end +end diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index 5e524cd96ab1..6f245c3959e8 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -2283,39 +2283,6 @@ WML_HANDLER_FUNCTION(terrain_mask, /*event_info*/, cfg) resources::screen->needs_rebuild(true); } -/// Adding/removing new time_areas dynamically with Standard Location Filters. -WML_HANDLER_FUNCTION(time_area, /*event_info*/, cfg) -{ - log_scope("time_area"); - - bool remove = cfg["remove"].to_bool(); - std::string ids = cfg["id"]; - - if(remove) { - const std::vector id_list = - utils::split(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY); - BOOST_FOREACH(const std::string& id, id_list) { - resources::tod_manager->remove_time_area(id); - LOG_NG << "event WML removed time_area '" << id << "'\n"; - } - } - else { - std::string id; - if(ids.find(',') != std::string::npos) { - id = utils::split(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front(); - ERR_NG << "multiple ids for inserting a new time_area; will use only the first" << std::endl; - } else { - id = ids; - } - std::set locs; - const terrain_filter filter(cfg, resources::filter_con); - filter.get_locations(locs, true); - config parsed_cfg = cfg.get_parsed_config(); - resources::tod_manager->add_time_area(id, locs, parsed_cfg); - LOG_NG << "event WML inserted time_area '" << id << "'\n"; - } -} - WML_HANDLER_FUNCTION(tunnel, /*event_info*/, cfg) { const bool remove = cfg["remove"].to_bool(false); diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 8538a4c30c20..a581b1b97bde 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -2948,6 +2948,48 @@ int game_lua_kernel::intf_allow_undo(lua_State *) return 0; } +/// Adding new time_areas dynamically with Standard Location Filters. +int game_lua_kernel::intf_add_time_area(lua_State * L) +{ + log_scope("time_area"); + + std::string ids = luaL_checkstring(L, 1); + vconfig cfg(luaW_checkvconfig(L, 2)); + + std::string id; + if(ids.find(',') != std::string::npos) { + id = utils::split(ids,',',utils::STRIP_SPACES | utils::REMOVE_EMPTY).front(); + ERR_LUA << "multiple ids for inserting a new time_area; will use only the first" << std::endl; + } else { + id = ids; + } + + std::set locs; + const terrain_filter filter(cfg, &game_state_); + filter.get_locations(locs, true); + config parsed_cfg = cfg.get_parsed_config(); + tod_man().add_time_area(id, locs, parsed_cfg); + LOG_LUA << "event WML inserted time_area '" << id << "'\n"; + return 0; +} + +/// Removing new time_areas dynamically with Standard Location Filters. +int game_lua_kernel::intf_remove_time_area(lua_State * L) +{ + log_scope("time_area"); + + const char * ids = luaL_checkstring(L, 1); + + const std::vector id_list = + utils::split(ids, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY); + BOOST_FOREACH(const std::string& id, id_list) { + tod_man().remove_time_area(id); + LOG_LUA << "event WML removed time_area '" << id << "'\n"; + } + return 0; +} + + namespace { struct lua_report_generator : reports::generator { diff --git a/src/scripting/game_lua_kernel.hpp b/src/scripting/game_lua_kernel.hpp index aae447567b7d..ba3201f31acc 100644 --- a/src/scripting/game_lua_kernel.hpp +++ b/src/scripting/game_lua_kernel.hpp @@ -72,6 +72,8 @@ class game_lua_kernel : public lua_kernel_base // Private lua callbacks int intf_allow_end_turn(lua_State *); int intf_allow_undo(lua_State *); + int intf_add_time_area(lua_State *); + int intf_remove_time_area(lua_State *); int intf_get_unit(lua_State *); int intf_get_units(lua_State *); int intf_get_displayed_unit(lua_State*);