mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 11:31:49 +00:00
add pathfinding.set_avoided_tags
This commit is contained in:
parent
5204cfedf5
commit
5e3373313b
7 changed files with 46 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include "api_lua.hpp"
|
||||
|
||||
#include "content/Content.hpp"
|
||||
#include "voxels/Pathfinding.hpp"
|
||||
#include "world/Level.hpp"
|
||||
|
||||
|
|
@ -99,6 +100,27 @@ static int l_set_jump_height(lua::State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_avoided_tags(lua::State* L) {
|
||||
if (auto agent = get_agent(L)) {
|
||||
if (!lua::istable(L, 2)) {
|
||||
throw std::runtime_error("array of tags expected");
|
||||
}
|
||||
agent->avoidTags.clear();
|
||||
int len = lua::objlen(L, 2);
|
||||
for (int i = 1; i <= len; i++) {
|
||||
lua::rawgeti(L, i);
|
||||
if (lua::isstring(L, -1)) {
|
||||
int index = content->getTagIndex(lua::tostring(L, -1));
|
||||
if (index != -1) {
|
||||
agent->avoidTags.insert(index);
|
||||
}
|
||||
}
|
||||
lua::pop(L);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg pathfindinglib[] = {
|
||||
{"create_agent", lua::wrap<l_create_agent>},
|
||||
{"remove_agent", lua::wrap<l_remove_agent>},
|
||||
|
|
@ -109,5 +131,6 @@ const luaL_Reg pathfindinglib[] = {
|
|||
{"pull_route", lua::wrap<l_pull_route>},
|
||||
{"set_max_visited", lua::wrap<l_set_max_visited_blocks>},
|
||||
{"set_jump_height", lua::wrap<l_set_jump_height>},
|
||||
{"set_avoided_tags", lua::wrap<l_set_avoided_tags>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue