Skip to content

Commit

Permalink
Add a wesnoth.terrain_types table
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 21, 2021
1 parent aa768b7 commit 9a547e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/lua/core/map.lua
Expand Up @@ -244,6 +244,7 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
return wesnoth.map.find{gives_income = true, wml.tag["and"](cfg)}
end)
wesnoth.match_location = wesnoth.deprecate_api('wesnoth.match_location', 'wesnoth.map.matches', 1, nil, wesnoth.map.matches)
wesnoth.get_terrain_info = wesnoth.deprecate_api('wesnoth.get_terrain_info', 'wesnoth.terrain_types', 1, nil, function(t) return wesnoth.terrain_types[t] end)
end

if wesnoth.kernel_type() == "Mapgen Lua Kernel" then
Expand Down
18 changes: 15 additions & 3 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -868,9 +868,9 @@ int game_lua_kernel::intf_lock_view(lua_State *L)
* - Arg 1: terrain code string.
* - Ret 1: table.
*/
int game_lua_kernel::intf_get_terrain_info(lua_State *L)
int game_lua_kernel::impl_get_terrain_info(lua_State *L)
{
char const *m = luaL_checkstring(L, 1);
char const *m = luaL_checkstring(L, 2);
t_translation::terrain_code t = t_translation::read_terrain_code(m);
if (t == t_translation::NONE_TERRAIN) return 0;
const terrain_type& info = board().map().tdata()->get_terrain_info(t);
Expand Down Expand Up @@ -4037,7 +4037,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars > },
{ "get_end_level_data", &dispatch<&game_lua_kernel::intf_get_end_level_data > },
{ "get_sound_source", &dispatch<&game_lua_kernel::intf_get_sound_source > },
{ "get_terrain_info", &dispatch<&game_lua_kernel::intf_get_terrain_info > },
{ "get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day > },
{ "get_max_liminal_bonus", &dispatch<&game_lua_kernel::intf_get_max_liminal_bonus > },
{ "get_variable", &dispatch<&game_lua_kernel::intf_get_variable > },
Expand Down Expand Up @@ -4106,6 +4105,19 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
// Create the unit_types table
cmd_log_ << lua_terrainmap::register_metatables(L);

// Create the unit_types table
cmd_log_ << "Adding terrain_types table...\n";
lua_getglobal(L, "wesnoth");
lua_newuserdatauv(L, 0, 0);
lua_createtable(L, 0, 2);
lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_info>);
lua_setfield(L, -2, "__index");
lua_pushstring(L, "terrain types");
lua_setfield(L, -2, "__metatable");
lua_setmetatable(L, -2);
lua_setfield(L, -2, "terrain_types");
lua_pop(L, 1);

// Create the ai elements table.
cmd_log_ << "Adding ai elements table...\n";

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/game_lua_kernel.hpp
Expand Up @@ -92,7 +92,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_unit_ability(lua_State *L);
int intf_view_locked(lua_State *L);
int intf_lock_view(lua_State *L);
int intf_get_terrain_info(lua_State *L);
int impl_get_terrain_info(lua_State *L);
int intf_get_time_of_day(lua_State *L);
int intf_get_max_liminal_bonus(lua_State *L);
int intf_get_village_owner(lua_State *L);
Expand Down

0 comments on commit 9a547e6

Please sign in to comment.