Rationalizing the use of scan_radius and making it accessible

This commit is contained in:
2021-11-23 16:10:48 -05:00
parent c75ba3b3a8
commit 8c871a9f40
10 changed files with 109 additions and 110 deletions

View File

@@ -51,6 +51,24 @@ LuaDefine(tangible_setclass, "c") {
return LS.result();
}
LuaDefine(tangible_getclass, "c") {
LuaArg tanobj;
LuaVar mt, classtab;
LuaRet classname;
LuaStack LS(L, tanobj, mt, classtab, classname);
World *w = World::fetch_global_pointer(L);
w->tangible_get(LS, tanobj);
LS.getmetatable(mt, tanobj);
LS.rawget(classtab, mt, "__index");
std::string name = LS.classname(classtab);
if (name == "") {
LS.set(classname, LuaNil);
} else {
LS.set(classname, name);
}
return LS.result();
}
LuaDefine(tangible_delete, "c") {
LuaArg tanobj;
LuaStack LS(L, tanobj);
@@ -179,6 +197,40 @@ LuaDefine(tangible_place, "c") {
return LS.result();
}
LuaDefine(tangible_near, "c") {
LuaArg ltan, lradius, lomit_nowhere, lomit_self;
LuaRet list;
LuaStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, ltan);
double radius = LS.cknumber(lradius);
bool omit_nowhere = LS.ckboolean(lomit_nowhere);
bool omit_self = LS.ckboolean(lomit_self);
const AnimStep &aqback = tan->anim_queue_.back();
util::IdVector idv = w->plane_map_.scan_radius(aqback.plane(), aqback.xyz().x, aqback.xyz().y, radius, omit_nowhere, tan->id(), omit_self);
LS.set(list, LuaNewTable);
int index = 1;
for (int64_t id : idv) LS.rawset(list, index++, id);
return LS.result();
}
LuaDefine(tangible_scan, "c") {
LuaArg lplane, lx, ly, lradius, lomit_nowhere;
LuaRet list;
LuaStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
World *w = World::fetch_global_pointer(L);
std::string plane = LS.ckstring(lplane);
double x = LS.cknumber(lx);
double y = LS.cknumber(ly);
double radius = LS.cknumber(lradius);
bool omit_nowhere = LS.ckboolean(lomit_nowhere);
util::IdVector idv = w->plane_map_.scan_radius(plane, x, y, radius, omit_nowhere, 0, false);
LS.set(list, LuaNewTable);
int index = 1;
for (int64_t id : idv) LS.rawset(list, index++, id);
return LS.result();
}
LuaDefine(world_wait, "f") {
if ((lua_gettop(L) != 1) || (lua_type(L, -1) != LUA_TNUMBER)) {
luaL_error(L, "Argument to wait must be a number.");