Skip to content

Commit

Permalink
move the place, remove shroud WML tags to lua implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Dec 24, 2014
1 parent f836758 commit 0d76ac3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 41 deletions.
8 changes: 8 additions & 0 deletions data/lua/wml-tags.lua
Expand Up @@ -1313,3 +1313,11 @@ end
function wml_actions.set_menu_item(cfg)
wesnoth.set_menu_item(cfg.id, cfg)
end

function wml_actions.place_shroud(cfg)
wesnoth.place_shroud(cfg)
end

function wml_actions.remove_shroud(cfg)
wesnoth.remove_shroud(cfg)
end
41 changes: 0 additions & 41 deletions src/game_events/action_wml.cpp
Expand Up @@ -472,37 +472,6 @@ namespace { // Support functions
resources::screen->invalidate_all();
}

void toggle_shroud(const bool remove, const vconfig& cfg)
{
// Filter the sides.
std::vector<int> sides = get_sides_vector(cfg);
size_t index;

// Filter the locations.
std::set<map_location> locs;
const terrain_filter filter(cfg, resources::filter_con);
filter.get_locations(locs, true);

BOOST_FOREACH(const int &side_num, sides)
{
index = side_num - 1;
team &t = (*resources::teams)[index];

BOOST_FOREACH(map_location const &loc, locs)
{
if (remove) {
t.clear_shroud(loc);
} else {
t.place_shroud(loc);
}
}
}

resources::screen->labels().recalculate_shroud();
resources::screen->recalculate_minimap();
resources::screen->invalidate_all();
}

void handle_event_commands(const queued_event& event_info, const vconfig &cfg) {
assert(resources::lua_kernel);
resources::lua_kernel->run_wml_action("command", cfg, event_info);
Expand Down Expand Up @@ -1482,11 +1451,6 @@ WML_HANDLER_FUNCTION(open_help, /*event_info*/, cfg)
help::show_help(screen, topic_id.to_serialized());
}

WML_HANDLER_FUNCTION(place_shroud, /*event_info*/,cfg)
{
toggle_shroud(false,cfg );
}

WML_HANDLER_FUNCTION(print, /*event_info*/, cfg)
{
// Remove any old message.
Expand Down Expand Up @@ -1623,11 +1587,6 @@ WML_HANDLER_FUNCTION(redraw, /*event_info*/, cfg)
screen.draw(true,true);
}

WML_HANDLER_FUNCTION(remove_shroud, /*event_info*/, cfg)
{
toggle_shroud(true,cfg);
}

WML_HANDLER_FUNCTION(remove_sound_source, /*event_info*/, cfg)
{
resources::soundsources->remove(cfg["id"]);
Expand Down
57 changes: 57 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -150,6 +150,25 @@ void game_lua_kernel::lua_chat(std::string const &caption, std::string const &ms
}
}

/**
* Gets a vector of sides from side= attribute in a given config node.
* Promotes consistent behavior.
*/
std::vector<int> game_lua_kernel::get_sides_vector(const vconfig& cfg)
{
const config::attribute_value sides = cfg["side"];
const vconfig &ssf = cfg.child("filter_side");

if (!ssf.null()) {
if(!sides.empty()) { WRN_LUA << "ignoring duplicate side filter information (inline side=)" << std::endl; }
side_filter filter(ssf, &game_state_);
return filter.get_teams();
}

side_filter filter(sides.str(), &game_state_);
return filter.get_teams();
}


namespace {
/**
Expand Down Expand Up @@ -764,6 +783,42 @@ int game_lua_kernel::intf_set_menu_item(lua_State *L)
return 0;
}

int game_lua_kernel::intf_shroud_op(lua_State *L, bool place_shroud)
{
vconfig cfg = luaW_checkvconfig(L, 1);

// Filter the sides.
std::vector<int> sides = get_sides_vector(cfg);
size_t index;

// Filter the locations.
std::set<map_location> locs;
const terrain_filter filter(cfg, &game_state_);
filter.get_locations(locs, true);

BOOST_FOREACH(const int &side_num, sides)
{
index = side_num - 1;
team &t = teams()[index];

BOOST_FOREACH(map_location const &loc, locs)
{
if (place_shroud) {
t.place_shroud(loc);
} else {
t.clear_shroud(loc);
}
}
}

game_display_->labels().recalculate_shroud();
game_display_->recalculate_minimap();
game_display_->invalidate_all();

return 0;
}


/**
* Highlights the given location on the map.
* - Args 1,2: location.
Expand Down Expand Up @@ -3032,8 +3087,10 @@ game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state &
{ "match_unit", boost::bind(&game_lua_kernel::intf_match_unit, this, _1) },
{ "message", boost::bind(&game_lua_kernel::intf_message, this, _1) },
{ "play_sound", boost::bind(&game_lua_kernel::intf_play_sound, this, _1) },
{ "place_shroud", boost::bind(&game_lua_kernel::intf_shroud_op, this, _1, true) },
{ "put_recall_unit", boost::bind(&game_lua_kernel::intf_put_recall_unit, this, _1) },
{ "put_unit", boost::bind(&game_lua_kernel::intf_put_unit, this, _1) },
{ "remove_shroud", boost::bind(&game_lua_kernel::intf_shroud_op, this, _1, false) },
{ "remove_tile_overlay", boost::bind(&game_lua_kernel::intf_remove_tile_overlay, this, _1) },
{ "scroll_to_tile", boost::bind(&game_lua_kernel::intf_scroll_to_tile, this, _1) },
{ "select_hex", boost::bind(&game_lua_kernel::intf_select_hex, this, _1) },
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/game_lua_kernel.hpp
Expand Up @@ -106,6 +106,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_find_vacant_tile(lua_State *L);
int intf_float_label(lua_State *L);
int intf_set_menu_item(lua_State *L);
int intf_shroud_op(lua_State *L, bool place_shroud);
int intf_simulate_combat(lua_State *L);
int intf_scroll_to_tile(lua_State *L);
int intf_select_hex(lua_State *L);
Expand All @@ -128,6 +129,7 @@ class game_lua_kernel : public lua_kernel_base
//private helpers
std::string synced_state();
void lua_chat(std::string const &caption, std::string const &msg);
std::vector<int> get_sides_vector(const vconfig& cfg);

public:
game_lua_kernel(const config &, CVideo *, game_state &, play_controller &, reports &);
Expand Down

0 comments on commit 0d76ac3

Please sign in to comment.