/* Given a position and a size this function calculates and pushes * the nearest point to that which will be valid if the boxes are * shrunk by the amount specified. */ void Lua_V1::GetShrinkPos() { lua_Object xObj = lua_getparam(1); lua_Object yObj = lua_getparam(2); lua_Object zObj = lua_getparam(3); lua_Object rObj = lua_getparam(4); if (!lua_isnumber(xObj) || !lua_isnumber(yObj) || !lua_isnumber(zObj) || !lua_isnumber(rObj)) return; float x = lua_getnumber(xObj); float y = lua_getnumber(yObj); float z = lua_getnumber(zObj); float r = lua_getnumber(rObj); Math::Vector3d pos; pos.set(x, y, z); Sector* sector; g_grim->getCurrSet()->shrinkBoxes(r); g_grim->getCurrSet()->findClosestSector(pos, §or, &pos); g_grim->getCurrSet()->unshrinkBoxes(); if (sector) { lua_pushnumber(pos.x()); lua_pushnumber(pos.y()); lua_pushnumber(pos.z()); } else { lua_pushnil(); } }
void Lua_V1::SetSoundPosition() { Math::Vector3d pos; int minVolume = 10; int maxVolume = 127; float someParam = 0; int argId = 1; lua_Object paramObj; if (g_grim->getCurrSet()) { g_grim->getCurrSet()->getSoundParameters(&minVolume, &maxVolume); } lua_Object nameObj = lua_getparam(argId++); if (!lua_isnumber(nameObj) && !lua_isstring(nameObj)) return; lua_Object actorObj = lua_getparam(argId++); if (lua_isuserdata(actorObj) && lua_tag(actorObj) == MKTAG('A','C','T','R')) { Actor *actor = getactor(actorObj); if (!actor) return; pos = actor->getPos(); } else if (lua_isnumber(actorObj)) { float x = lua_getnumber(actorObj); float y = lua_getnumber(argId++); float z = lua_getnumber(argId++); pos.set(x, y, z); } paramObj = (int)lua_getparam(argId++); if (lua_isnumber(paramObj)) { minVolume = (int)lua_getnumber(paramObj); if (minVolume > 127) minVolume = 127; } paramObj = lua_getparam(argId++); if (lua_isnumber(paramObj)) { maxVolume = (int)lua_getnumber(paramObj); if (maxVolume > 127) maxVolume = 127; else if (maxVolume < minVolume) maxVolume = minVolume; } paramObj = lua_getparam(argId++); if (lua_isnumber(paramObj)) { someParam = (int)lua_getnumber(paramObj); if (someParam < 0.0) someParam = 0.0; } if (g_grim->getCurrSet()) { if (lua_isnumber(nameObj)) error("SetSoundPosition: number is not yet supported"); else { const char *soundName = lua_getstring(nameObj); g_grim->getCurrSet()->setSoundPosition(soundName, pos, minVolume, maxVolume); } } }
void Lua_V2::WalkActorToAvoiding() { lua_Object actorObj = lua_getparam(1); lua_Object actor2Obj = lua_getparam(2); lua_Object xObj = lua_getparam(3); lua_Object yObj = lua_getparam(4); lua_Object zObj = lua_getparam(5); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; if (!lua_isuserdata(actor2Obj) || lua_tag(actor2Obj) != MKTAG('A','C','T','R')) return; Math::Vector3d destVec; Actor *actor = getactor(actorObj); if (!lua_isnumber(xObj)) { if (!lua_isuserdata(xObj) || lua_tag(xObj) != MKTAG('A','C','T','R')) return; Actor *destActor = getactor(xObj); destVec = destActor->getPos(); } else { float x = lua_getnumber(xObj); float y = lua_getnumber(yObj); float z = lua_getnumber(zObj); destVec.set(x, y, z); } // TODO: Make this actually avoid the second actor actor->walkTo(destVec); }