Skip to content

Commit

Permalink
For consistency, mapgen should also expose a matches function
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 23, 2021
1 parent 218bbb2 commit 1c73c93
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/scripting/lua_terrainfilter.cpp
Expand Up @@ -718,9 +718,9 @@ static int intf_mg_get_locations_part2(lua_State* L, gamemap_base& m, lua_mapgen
return 1;

}

int intf_mg_get_locations(lua_State* L)
{
//todo: create filter form table if needed
LOG_LMG << "map:get_locations\n";
gamemap_base& m = luaW_checkterrainmap(L, 1);
if(luaW_is_mgfilter(L, 2)) {
Expand All @@ -736,6 +736,24 @@ int intf_mg_get_locations(lua_State* L)
}
}

int intf_mg_match_location(lua_State* L)
{
LOG_LMG << "map:match_location\n";
gamemap_base& m = luaW_checkterrainmap(L, 1);
map_location loc = luaW_checklocation(L, 2);
if(luaW_is_mgfilter(L, 3)) {
lua_mapgen::filter& f = luaW_check_mgfilter(L, 3);
lua_pushboolean(L, f.matches(m, loc));
} else if (lua_istable(L, 3)) {
lua_mapgen::filter f(L, 3, 0);
lua_pushboolean(L, f.matches(m, loc));
}
else {
return luaW_type_error(L, 3, "terrainfilter");
}
return 1;
}

int intf_mg_get_tiles_radius(lua_State* L)
{
gamemap_base& m = luaW_checkterrainmap(L, 1);
Expand Down
1 change: 1 addition & 0 deletions src/scripting/lua_terrainfilter.hpp
Expand Up @@ -66,6 +66,7 @@ void lua_mgfilter_setmetatable(lua_State *L);

int intf_terrainfilter_create(lua_State *L);

int intf_mg_match_location(lua_State* L);
int intf_mg_get_locations(lua_State* L);
int intf_mg_get_tiles_radius(lua_State* L);

Expand Down
1 change: 1 addition & 0 deletions src/scripting/mapgen_lua_kernel.cpp
Expand Up @@ -234,6 +234,7 @@ mapgen_lua_kernel::mapgen_lua_kernel(const config* vars)

static luaL_Reg const map_callbacks[] {
// Map methods
{ "matches", &intf_mg_match_location },
{ "find", &intf_mg_get_locations },
{ "find_in_radius", &intf_mg_get_tiles_radius },
// Static functions
Expand Down

0 comments on commit 1c73c93

Please sign in to comment.