Lua side proxy now has starting_location member (replaces wesnoth.get_starting_location())

This commit is contained in:
Celtic Minstrel 2019-11-23 14:37:41 -05:00
parent 81ee0f0349
commit 930e39422a
5 changed files with 15 additions and 25 deletions

View file

@ -64,6 +64,7 @@
The defense_on and resistance_against functions return the actual values, rather than the raw WML values.
* New function wesnoth.units.chance_to_be_hit is equivalent to deprecated wesonth.units.defense but conveys the meaning better.
* Unit movetype functions (excluding resistance) can take a location instead of a terrain code, for convenience
* Side proxy now has starting_location member
### WFL engine
* New functions resistance_on(), vision_cost(), jamming_cost() that work in gameplay contexts (eg filters)
* Unit object now has resistance, defense, movement_cost, vision_cost, jamming_cost, flying

View file

@ -556,6 +556,11 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
function wesnoth.get_side_variable(side, var)
return wesnoth.sides[side].variables[var]
end
function wesnoth.get_starting_location(side)
local side = side
if type(side) == 'number' then side = wesnoth.sides[side] end
return side.starting_location
end
end
--[========[GUI2 Dialog Manipulations]========]
@ -646,7 +651,7 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
wesnoth.get_recall_units = wesnoth.deprecate_api('wesnoth.get_units', 'wesnoth.units.find_on_recall', 1, nil, wesnoth.units.find_on_recall)
wesnoth.get_side_variable = wesnoth.deprecate_api('wesnoth.get_side_variable', 'wesnoth.sides[].variables', 1, nil, wesnoth.get_side_variable)
wesnoth.set_side_variable = wesnoth.deprecate_api('wesnoth.set_side_variable', 'wesnoth.sides[].variables', 1, nil, wesnoth.set_side_variable)
wesnoth.get_starting_location = wesnoth.deprecate_api('wesnoth.get_starting_location', 'wesnoth.sides.get_starting_location', 1, nil, wesnoth.sides.get_starting_location)
wesnoth.get_starting_location = wesnoth.deprecate_api('wesnoth.get_starting_location', 'wesnoth.sides[].starting_location', 1, nil, wesnoth.get_starting_location)
wesnoth.is_enemy = wesnoth.deprecate_api('wesnoth.is_enemy', 'wesnoth.sides.is_enemy', 1, nil, wesnoth.sides.is_enemy)
wesnoth.match_side = wesnoth.deprecate_api('wesnoth.match_side', 'wesnoth.sides.matches', 1, nil, wesnoth.sides.matches)
wesnoth.set_side_id = wesnoth.deprecate_api('wesnoth.set_side_id', 'wesnoth.sides.set_id', 1, nil, wesnoth.sides.set_id)

View file

@ -1313,28 +1313,6 @@ int game_lua_kernel::intf_get_selected_tile(lua_State *L)
return 2;
}
/**
* Returns the starting position of a side.
* Arg 1: side number
* Ret 1: table with unnamed indices holding wml coordinates x and y
*/
int game_lua_kernel::intf_get_starting_location(lua_State* L)
{
int side;
if(team* t = luaW_toteam(L, 1)) {
side = t->side();
} else {
side = luaL_checkinteger(L, 1);
}
if(side < 1 || static_cast<int>(teams().size()) < side)
return luaL_argerror(L, 1, "out of bounds");
const map_location& starting_pos = board().map().starting_position(side);
if(!board().map().on_board(starting_pos)) return 0;
luaW_pushlocation(L, starting_pos);
return 1;
}
/**
* Gets a table for an era tag.
* - Arg 1: userdata (ignored).
@ -4357,7 +4335,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
// Create sides module
cmd_log_ << "Adding sides module...\n";
static luaL_Reg const side_callbacks[] {
{ "get_starting_location", &dispatch<&game_lua_kernel::intf_get_starting_location> },
{ "is_enemy", &dispatch<&game_lua_kernel::intf_is_enemy> },
{ "matches", &dispatch<&game_lua_kernel::intf_match_side> },
{ "set_id", &dispatch<&game_lua_kernel::intf_set_side_id> },

View file

@ -101,7 +101,6 @@ class game_lua_kernel : public lua_kernel_base
int intf_get_map_size(lua_State *L);
int intf_get_mouseover_tile(lua_State *L);
int intf_get_selected_tile(lua_State *L);
int intf_get_starting_location(lua_State* L);
int impl_game_config_get(lua_State *L) override;
int impl_game_config_set(lua_State *L) override;
int impl_current_get(lua_State *L);

View file

@ -21,6 +21,7 @@
#include "resources.hpp" // for gameboard
#include "game_board.hpp"
#include "game_display.hpp"
#include "map/map.hpp"
#include <string>
@ -111,6 +112,13 @@ static int impl_side_get(lua_State *L)
luaL_setmetatable(L, teamVar);
return 1;
}
if(strcmp(m, "starting_location") == 0) {
const map_location& starting_pos = resources::gameboard->map().starting_position(t.side());
if(!resources::gameboard->map().on_board(starting_pos)) return 0;
luaW_pushlocation(L, starting_pos);
return 1;
}
// These are blocked together because they are all part of the team_data struct.
// Some of these values involve iterating over the units map to calculate them.