Rename existing map functions in the map generation kernel
This commit is contained in:
parent
2d5ea6312e
commit
7e1414e249
6 changed files with 42 additions and 18 deletions
|
@ -123,4 +123,17 @@ 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)
|
||||
end
|
||||
end
|
||||
|
||||
if wesnoth.kernel_type() == "Mapgen Lua Kernel" then
|
||||
-- More map module stuff
|
||||
wesnoth.create_filter = wesnoth.deprecate_api('wesnoth.create_filter', 'wesnoth.map.filter', 1, nil, wesnoth.map.filter)
|
||||
wesnoth.create_map = wesnoth.deprecate_api('wesnoth.create_map', 'wesnoth.map.create', 1, nil, wesnoth.map.create)
|
||||
wesnoth.default_generate_height_map = wesnoth.deprecate_api('wesnoth.default_generate_height_map', 'wesnoth.map.generate_height_map', 1, nil, wesnoth.map.generate_height_map)
|
||||
wesnoth.generate_default_map = wesnoth.deprecate_api('wesnoth.generate_default_map', 'wesnoth.map.generate', 1, nil, wesnoth.map.generate)
|
||||
-- These were originally only on the map metatable, so the deprecated versions also need to be in the map module
|
||||
wesnoth.map.get_locations = wesnoth.deprecate_api('map:get_locations', 'map:find', 1, nil, wesnoth.map.find)
|
||||
wesnoth.map.get_tiles_radius = wesnoth.deprecate_api('map:get_tiles_radius', 'map:find_in_radius', 1, nil, function(map, locs, filter, radius)
|
||||
return wesnoth.map.find_in_radius(map, locs, radius, filter)
|
||||
end, 'The filter is now the last parameter, instead of the radius')
|
||||
end
|
||||
|
|
|
@ -4068,7 +4068,7 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
|
|||
cmd_log_ << lua_unit_type::register_table(L);
|
||||
|
||||
// Create the unit_types table
|
||||
cmd_log_ << lua_terrainmap::register_metatables(L, false);
|
||||
cmd_log_ << lua_terrainmap::register_metatables(L);
|
||||
|
||||
// Create the ai elements table.
|
||||
cmd_log_ << "Adding ai elements table...\n";
|
||||
|
|
|
@ -184,6 +184,11 @@ static int luaW_push_locationset(lua_State* L, const std::set<map_location>& loc
|
|||
static std::set<map_location> luaW_to_locationset(lua_State* L, int index)
|
||||
{
|
||||
std::set<map_location> res;
|
||||
map_location single;
|
||||
if(luaW_tolocation(L, index, single)) {
|
||||
res.insert(single);
|
||||
return res;
|
||||
}
|
||||
lua_pushvalue(L, index);
|
||||
size_t len = lua_rawlen(L, -1);
|
||||
for(size_t i = 0; i != len; ++i) {
|
||||
|
@ -734,10 +739,10 @@ int intf_mg_get_locations(lua_State* L)
|
|||
int intf_mg_get_tiles_radius(lua_State* L)
|
||||
{
|
||||
gamemap_base& m = luaW_checkterrainmap(L, 1);
|
||||
lua_mapgen::filter& f = luaW_check_mgfilter(L, 3);
|
||||
location_set s = luaW_to_locationset(L, 2);
|
||||
int r = luaL_checkinteger(L, 3);
|
||||
lua_mapgen::filter& f = luaW_check_mgfilter(L, 4);
|
||||
location_set res;
|
||||
int r = luaL_checkinteger(L, 4);
|
||||
get_tiles_radius(std::move(s), r, res,
|
||||
[&](const map_location& l) {
|
||||
return m.on_board_with_border(l);
|
||||
|
|
|
@ -491,7 +491,7 @@ static int impl_replace_if_failed_tostring(lua_State* L)
|
|||
}
|
||||
|
||||
namespace lua_terrainmap {
|
||||
std::string register_metatables(lua_State* L, bool use_tf)
|
||||
std::string register_metatables(lua_State* L)
|
||||
{
|
||||
std::ostringstream cmd_out;
|
||||
|
||||
|
@ -506,13 +506,6 @@ namespace lua_terrainmap {
|
|||
lua_setfield(L, -2, "__newindex");
|
||||
lua_pushstring(L, terrainmapKey);
|
||||
lua_setfield(L, -2, "__metatable");
|
||||
// terrainmap methods
|
||||
if(use_tf) {
|
||||
lua_pushcfunction(L, intf_mg_get_locations);
|
||||
lua_setfield(L, -2, "get_locations");
|
||||
lua_pushcfunction(L, intf_mg_get_tiles_radius);
|
||||
lua_setfield(L, -2, "get_tiles_radius");
|
||||
}
|
||||
|
||||
luaL_newmetatable(L, mapReplaceIfFailedKey);
|
||||
lua_pushcfunction(L, impl_replace_if_failed_tostring);
|
||||
|
|
|
@ -60,5 +60,5 @@ int intf_terrainmap_get(lua_State *L);
|
|||
int intf_replace_if_failed(lua_State* L);
|
||||
|
||||
namespace lua_terrainmap {
|
||||
std::string register_metatables(lua_State *L, bool use_tf);
|
||||
std::string register_metatables(lua_State *L);
|
||||
}
|
||||
|
|
|
@ -222,10 +222,6 @@ mapgen_lua_kernel::mapgen_lua_kernel(const config* vars)
|
|||
static luaL_Reg const callbacks[] {
|
||||
{ "find_path", &intf_find_path },
|
||||
{ "random", &intf_random },
|
||||
{ "create_filter", &intf_terrainfilter_create },
|
||||
{ "create_map", &intf_terrainmap_create },
|
||||
{ "default_generate_height_map", &intf_default_generate_height_map },
|
||||
{ "generate_default_map", &intf_default_generate },
|
||||
{ "get_variable", &dispatch<&mapgen_lua_kernel::intf_get_variable> },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
@ -236,8 +232,25 @@ mapgen_lua_kernel::mapgen_lua_kernel(const config* vars)
|
|||
lua_pop(L, 1);
|
||||
assert(lua_gettop(L) == 0);
|
||||
|
||||
static luaL_Reg const map_callbacks[] {
|
||||
// Map methods
|
||||
{ "find", &intf_mg_get_locations },
|
||||
{ "find_in_radius", &intf_mg_get_tiles_radius },
|
||||
// Static functions
|
||||
{ "filter", &intf_terrainfilter_create },
|
||||
{ "create", &intf_terrainmap_create },
|
||||
{ "generate_height_map", &intf_default_generate_height_map },
|
||||
{ "generate", &intf_default_generate },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
cmd_log_ << lua_terrainmap::register_metatables(L, true);
|
||||
luaW_getglobal(L, "wesnoth", "map");
|
||||
assert(lua_istable(L,-1));
|
||||
luaL_setfuncs(L, map_callbacks, 0);
|
||||
lua_pop(L, 1);
|
||||
assert(lua_gettop(L) == 0);
|
||||
|
||||
cmd_log_ << lua_terrainmap::register_metatables(L);
|
||||
cmd_log_ << lua_terrainfilter::register_metatables(L);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue