From 53103af0fd0de88a741a9be8513b58eb325935a3 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Wed, 17 Feb 2021 13:31:53 -0500 Subject: [PATCH] Add on_board and on_border map methods --- src/scripting/game_lua_kernel.cpp | 2 ++ src/scripting/lua_terrainmap.cpp | 19 +++++++++++++++++++ src/scripting/lua_terrainmap.hpp | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 7b9d9873a6b1b..217b31fa29fd9 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -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>}, diff --git a/src/scripting/lua_terrainmap.cpp b/src/scripting/lua_terrainmap.cpp index 6c0c10f7b5966..c485082ef0e78 100644 --- a/src/scripting/lua_terrainmap.cpp +++ b/src/scripting/lua_terrainmap.cpp @@ -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 read_rules_vector(lua_State *L, int index) { std::vector rules; diff --git a/src/scripting/lua_terrainmap.hpp b/src/scripting/lua_terrainmap.hpp index fe2093bd2f9bb..450b539ab2db9 100644 --- a/src/scripting/lua_terrainmap.hpp +++ b/src/scripting/lua_terrainmap.hpp @@ -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);