Skip to content

Commit

Permalink
Add wesnoth.map.get_hexes_in_radius
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 28, 2021
1 parent f8f4910 commit 5a129cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -546,6 +546,7 @@ lua_kernel_base::lua_kernel_base()
{ "rotate_right_around_center", &lua_map_location::intf_rotate_right_around_center },
{ "are_hexes_adjacent", &lua_map_location::intf_tiles_adjacent },
{ "get_adjacent_hexes", &lua_map_location::intf_get_adjacent_tiles },
{ "get_hexes_in_radius", &lua_map_location::intf_get_tiles_in_radius },
{ "distance_between", &lua_map_location::intf_distance_between },
{ "get_in_basis_N_NE", &lua_map_location::intf_get_in_basis_N_NE },
{ "get_relative_dir", &lua_map_location::intf_get_relative_dir },
Expand Down
26 changes: 24 additions & 2 deletions src/scripting/lua_map_location_ops.cpp
Expand Up @@ -14,8 +14,10 @@

#include "scripting/lua_map_location_ops.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/push_check.hpp"

#include "map/location.hpp"
#include "pathutils.hpp"

#include <string>
#include <utility>
Expand Down Expand Up @@ -87,7 +89,7 @@ int intf_vector_diff(lua_State* L)
{
map_location l1, l2;
if(!luaW_tolocation(L, 1, l1) || !luaW_tolocation(L, 2, l2)) {
lua_pushstring(L, "vector_sum: requires two locations");
lua_pushstring(L, "vector_diff: requires two locations");
return lua_error(L);
}

Expand Down Expand Up @@ -137,7 +139,7 @@ int intf_tiles_adjacent(lua_State* L)
{
map_location l1, l2;
if(!luaW_tolocation(L, 1, l1) || !luaW_tolocation(L, 2, l2)) {
lua_pushstring(L, "vector_sum: requires two locations");
lua_pushstring(L, "tiles_adjacent: requires two locations");
return lua_error(L);
}

Expand All @@ -164,6 +166,26 @@ int intf_get_adjacent_tiles(lua_State* L)
return 6;
}

/**
* Expose map_location get_tiles_in_radius
* - Arg 1: A location
* - Ret: The locations
*/
int intf_get_tiles_in_radius(lua_State* L)
{
map_location l1;
if(!luaW_tolocation(L, 1, l1)) {
return luaL_argerror(L, 1, "expected a location");
}
int radius = luaL_checkinteger(L, 2);

std::vector<map_location> locs;
get_tiles_in_radius(l1, radius, locs);
lua_push(L, locs);

return 1;
}

/**
* Expose map_location distance_between
* - Args 1, 2: Two locations
Expand Down
1 change: 1 addition & 0 deletions src/scripting/lua_map_location_ops.hpp
Expand Up @@ -30,6 +30,7 @@ int intf_vector_negation(lua_State*);
int intf_rotate_right_around_center(lua_State*);
int intf_tiles_adjacent(lua_State*);
int intf_get_adjacent_tiles(lua_State*);
int intf_get_tiles_in_radius(lua_State*);
int intf_distance_between(lua_State*);
int intf_get_in_basis_N_NE(lua_State*);
int intf_get_relative_dir(lua_State*);
Expand Down

0 comments on commit 5a129cb

Please sign in to comment.