Skip to content

Commit

Permalink
Add on_board and on_border map methods
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 20, 2021
1 parent 76dd132 commit 05283b5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -4136,6 +4136,8 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
static luaL_Reg const map_callbacks[] {
// Map methods
{"terrain_mask", &intf_terrain_mask},
{"on_board", &intf_on_board},
{"on_border", &intf_on_border},
// Shroud operations
{"place_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, true>},
{"remove_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, false>},
Expand Down
19 changes: 19 additions & 0 deletions src/scripting/lua_terrainmap.cpp
Expand Up @@ -345,6 +345,25 @@ static int impl_terrainmap_set(lua_State *L)
return luaL_argerror(L, 2, err_msg.c_str());
}

static int intf_on_board(lua_State* L)
{
gamemap_base& tm = luaW_checkterrainmap(L, 1);
map_location loc = luaW_checklocation(L, 2);
bool with_border = luaL_opt(L, luaW_toboolean, 3, false);

lua_pushboolean(L, with_border ? tm.on_board_with_border(loc) : tm.on_board(loc));
return 1;
}

static int intf_on_border(lua_State* L)
{
gamemap_base& tm = luaW_checkterrainmap(L, 1);
map_location loc = luaW_checklocation(L, 2);

lua_pushboolean(L, tm.on_board_with_border(loc) && !tm.on_board(loc));
return 1;
}

static std::vector<gamemap::overlay_rule> read_rules_vector(lua_State *L, int index)
{
std::vector<gamemap::overlay_rule> rules;
Expand Down
2 changes: 2 additions & 0 deletions src/scripting/lua_terrainmap.hpp
Expand Up @@ -58,6 +58,8 @@ int intf_terrainmap_create(lua_State *L);
int intf_terrainmap_get(lua_State *L);

int intf_replace_if_failed(lua_State* L);
int intf_on_board(lua_State* L);
int intf_on_border(lua_State* L);

namespace lua_terrainmap {
std::string register_metatables(lua_State *L);
Expand Down

0 comments on commit 05283b5

Please sign in to comment.