Skip to content

Commit

Permalink
Add wesnoth.select_unit(), deprecate wesnoth.select_hex()
Browse files Browse the repository at this point in the history
wesnoth.select_unit() is also callable as u:select() where u is a unit
  • Loading branch information
CelticMinstrel committed Mar 16, 2016
1 parent d250e04 commit 2e6ad2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion data/lua/wml/object.lua
Expand Up @@ -35,7 +35,8 @@ function wml_actions.object(cfg)
wesnoth.add_modification(unit, "object", helper.parsed(cfg), add)
end

wesnoth.select_hex(unit.x, unit.y, false)
wesnoth.select_unit(unit, false)
wesnoth.highlight_hex(unit.x, unit.y)

-- Mark this item as used up
if obj_id then used_items[obj_id] = true end
Expand Down
25 changes: 21 additions & 4 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -2837,12 +2837,30 @@ int game_lua_kernel::intf_scroll_to_tile(lua_State *L)
return 0;
}

int game_lua_kernel::intf_select_hex(lua_State *L)
{
ERR_LUA << "wesnoth.select_hex is deprecated, use wesnoth.select_unit and/or wesnoth.highlight_hex" << std::endl;

// Need this because check_location may change the stack
// By doing this now, we ensure that it won't do so when
// intf_select_unit and intf_highlight_hex call it.
const map_location loc = luaW_checklocation(L, 1);
luaW_pushlocation(L, loc);
lua_replace(L, 1);

intf_select_unit(L);
if(!lua_isnoneornil(L, 2) && luaW_toboolean(L,2)) {
intf_highlight_hex(L);
}
return 0;
}

/**
* Selects and highlights the given location on the map.
* - Arg 1: location.
* - Args 2,3: booleans
*/
int game_lua_kernel::intf_select_hex(lua_State *L)
int game_lua_kernel::intf_select_unit(lua_State *L)
{
const map_location loc = luaW_checklocation(L, 1);
if(!map().on_board(loc)) return luaL_argerror(L, 1, "not on board");
Expand All @@ -2852,9 +2870,6 @@ int game_lua_kernel::intf_select_hex(lua_State *L)
const bool fire_event = luaW_toboolean(L, 3);
play_controller_.get_mouse_handler_base().select_hex(
loc, false, highlight, fire_event);
if(highlight && game_display_) {
game_display_->highlight_hex(loc);
}
return 0;
}

Expand Down Expand Up @@ -4306,6 +4321,7 @@ game_lua_kernel::game_lua_kernel(CVideo * video, game_state & gs, play_controlle
{ "scroll_to_tile", &dispatch<&game_lua_kernel::intf_scroll_to_tile > },
{ "select_hex", &dispatch<&game_lua_kernel::intf_select_hex > },
{ "deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex > },
{ "select_unit", &dispatch<&game_lua_kernel::intf_select_unit > },
{ "skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages > },
{ "is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages > },
{ "set_end_campaign_credits", &dispatch<&game_lua_kernel::intf_set_end_campaign_credits > },
Expand Down Expand Up @@ -4581,6 +4597,7 @@ int game_lua_kernel::return_unit_method(lua_State *L, char const *m) {
{"jamming", intf_unit_jamming_cost},
{"ability", intf_unit_ability},
{"transform", intf_transform_unit},
{"select", &dispatch<&game_lua_kernel::intf_select_unit>},
};

BOOST_FOREACH(const luaL_Reg& r, methods) {
Expand Down
1 change: 1 addition & 0 deletions src/scripting/game_lua_kernel.hpp
Expand Up @@ -131,6 +131,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_simulate_combat(lua_State *L);
int intf_scroll_to_tile(lua_State *L);
int intf_select_hex(lua_State *L);
int intf_select_unit(lua_State *L);
int intf_deselect_hex(lua_State *L);
int intf_is_skipping_messages(lua_State *L);
int intf_skip_messages(lua_State *L);
Expand Down

0 comments on commit 2e6ad2b

Please sign in to comment.