void Lua_V2::AttachActor() { // Missing lua parts lua_Object attachedObj = lua_getparam(1); lua_Object actorObj = lua_getparam(2); lua_Object jointObj = lua_getparam(3); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A', 'C', 'T', 'R')) return; Actor *actor = getactor(actorObj); if (!actor) return; if (!lua_isuserdata(attachedObj) || lua_tag(attachedObj) != MKTAG('A', 'C', 'T', 'R')) return; Actor *attached = getactor(attachedObj); if (!attached) return; const char *joint = NULL; if (!lua_isnil(jointObj)) { joint = lua_getstring(jointObj); } attached->attachToActor(actor, joint); warning("Lua_V2::AttachActor: attaching %s to %s (on %s)", attached->getName().c_str(), actor->getName().c_str(), joint ? joint : "(none)"); g_emi->invalidateSortOrder(); }
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); }
void Lua_V1::SayLine() { int vol = 127, buffer = 64, paramId = 1, x = -1, y = -1; bool background = true; const char *msgId = NULL;; Common::String msg; lua_Object paramObj = lua_getparam(paramId++); if ((lua_isuserdata(paramObj) && lua_tag(paramObj) == MKTAG('A','C','T','R')) || lua_isstring(paramObj) || lua_istable(paramObj)) { Actor *actor = NULL;//some_Actor, maybe some current actor if (lua_isuserdata(paramObj) && lua_tag(paramObj) == MKTAG('A','C','T','R')) { actor = getactor(paramObj); paramObj = lua_getparam(paramId++); } if (actor) { while (!lua_isnil(paramObj)) { if (!lua_isstring(paramObj) && !lua_isnumber(paramObj) && !lua_istable(paramObj)) break; if (lua_istable(paramObj)) parseSayLineTable(paramObj, &background, &vol, &buffer, &x, &y); else { if (lua_isnumber(paramObj)) background = false; else { msgId = lua_getstring(paramObj); } } paramObj = lua_getparam(paramId++); } actor->sayLine(msgId, background); //background, vol, pan, x, y } } }
void L1_typeOverride() { lua_Object data = lua_getparam(1); if (lua_isuserdata(data)) { switch (lua_tag(data)) { case MKTAG('A','C','T','R'): lua_pushstring("actor"); lua_pushnumber(lua_tag(data)); return; case MKTAG('C','O','S','T'): lua_pushstring("costume"); lua_pushnumber(lua_tag(data)); return; case MKTAG('S','E','T',' '): lua_pushstring("set"); lua_pushnumber(lua_tag(data)); return; case MKTAG('K','E','Y','F'): lua_pushstring("keyframe"); lua_pushnumber(lua_tag(data)); return; default: break; } } lua_pushobject(data); lua_callfunction(lua_getref(refTypeOverride)); lua_Object param1 = lua_getresult(1); lua_Object param2 = lua_getresult(2); lua_pushobject(param1); lua_pushobject(param2); }
static int32 ishandler(lua_Object f) { if (lua_isuserdata(f)) { if (lua_tag(f) == gettag(CLOSEDTAG)) lua_error("cannot access a closed file"); return lua_tag(f) == gettag(IOTAG); } else return 0; }
void callHook(lua_Function func, const char *filename, int32 line) { const char *name, *type; FILE *output = stdout; int i; type = lua_getobjname(func, &name); if (func == LUA_NOOBJECT) { fprintf(output, "%s\n", filename); return; } switch (*type) { case 'g': fprintf(output, "function: %s(", name); for (i = 1; ; i++) { if (lua_getparam(i) == LUA_NOOBJECT) break; if (lua_isnil(lua_getparam(i))) fprintf(output, "nil"); else if (lua_istable(lua_getparam(i))) fprintf(output, "{...}"); else if (lua_isuserdata(lua_getparam(i))) { if (lua_tag(lua_getparam(i)) == MKTAG('A','C','T','R')) { Actor *a = Actor::getPool().getObject(lua_getuserdata(lua_getparam(i))); fprintf(output, "<actor \"%s\">", a->getName().c_str()); } else if (lua_tag(lua_getparam(i)) == MKTAG('C','O','L','R')) { Color c(lua_getuserdata(lua_getparam(i))); fprintf(output, "<color #%02x%02x%02x>", c.getRed(), c.getGreen(), c.getBlue()); } else fprintf(output, "<userdata %d>", lua_getuserdata(lua_getparam(i))); } else if (lua_isfunction(lua_getparam(i))) { fprintf(output, "<function>"); } else if (lua_isnumber(lua_getparam(i))) fprintf(output, "%g", lua_getnumber(lua_getparam(i))); else if (lua_isstring(lua_getparam(i))) fprintf(output, "\"%s\"", lua_getstring(lua_getparam(i))); else fprintf(output, "<unknown>"); if (lua_getparam(i + 1) != LUA_NOOBJECT) fprintf(output, ", "); } fprintf(output, ")"); break; case 't': fprintf(output, "`%s' tag method", name); break; default: { if (line == 0) fprintf(output, "{START SCRIPT: %s}", filename); else if (line < 0) { fprintf(output, "%s", filename); } else fprintf(output, "function (%s:%d)", filename, line); } } fprintf(output, "\n"); }
void Lua_V2::SetActorTalkChore() { lua_Object actorObj = lua_getparam(1); lua_Object indexObj = lua_getparam(2); lua_Object choreObj = lua_getparam(3); lua_Object costumeObj = lua_getparam(4); Costume *costume; int chore; if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R') || !lua_isnumber(indexObj) || (!lua_isstring(choreObj) && !lua_isnil(choreObj))) { return; } int index = (int)lua_getnumber(indexObj); if (index < 1 || index > 16) return; Actor *actor = getactor(actorObj); if (!findCostume(costumeObj, actor, &costume)) return; if (lua_isnil(choreObj)) { chore = -1; } else { const char * choreStr = lua_getstring(choreObj); chore = costume->getChoreId(choreStr); } actor->setTalkChore(index, chore, costume); }
static void io_writeto() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FOUTPUT); setreturn(2, FOUTPUT); } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current->isOpen()) { pushresult(0); return; } setreturn(id, FOUTPUT); } else { Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\'); LuaFile *current; Common::WriteStream *outFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); outFile = saveFileMan->openForSaving(s); if (!outFile) { pushresult(0); return; } current = new LuaFile(); current->_out = outFile; current->_filename = s; setreturn(addfile(current), FOUTPUT); } }
static int luaB_tostring (lua_State *L) { char buff[64]; switch (lua_type(L, 1)) { case LUA_TNUMBER: lua_pushstring(L, lua_tostring(L, 1)); return 1; case LUA_TSTRING: lua_pushvalue(L, 1); return 1; case LUA_TTABLE: sprintf(buff, "table: %p", lua_topointer(L, 1)); break; case LUA_TFUNCTION: sprintf(buff, "function: %p", lua_topointer(L, 1)); break; case LUA_TUSERDATA: sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); break; case LUA_TNIL: lua_pushstring(L, "nil"); return 1; default: luaL_argerror(L, 1, "value expected"); } lua_pushstring(L, buff); return 1; }
void Lua_V1::SendObjectToBack() { lua_Object param = lua_getparam(1); if (lua_isuserdata(param) && lua_tag(param) == MKTAG('S','T','A','T')) { ObjectState *state = getobjectstate(param); g_grim->getCurrSet()->moveObjectStateToBack(state); } }
void Lua_V2::SetActorTurnChores() { lua_Object actorObj = lua_getparam(1); lua_Object leftChoreObj = lua_getparam(2); lua_Object rightChoreObj = lua_getparam(3); lua_Object costumeObj = lua_getparam(4); Costume *costume; if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) { return; } else if (!lua_isnil(leftChoreObj) && !lua_isstring(leftChoreObj)) { return; } else if (!lua_isnil(rightChoreObj) && !lua_isstring(rightChoreObj)) { return; } Actor *actor = getactor(actorObj); if (!findCostume(costumeObj, actor, &costume)) return; if (!costume) { costume = actor->getCurrentCostume(); } int leftChore = costume->getChoreId(lua_getstring(leftChoreObj)); int rightChore = costume->getChoreId(lua_getstring(rightChoreObj)); actor->setTurnChores(leftChore, rightChore, costume); }
void Lua_V2::PutActorInSet() { lua_Object actorObj = lua_getparam(1); lua_Object setObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); if (!lua_isstring(setObj) && !lua_isnil(setObj)) { lua_pushnil(); return; } const char *set = lua_getstring(setObj); // FIXME verify adding actor to set if (!set) { actor->putInSet(""); lua_pushnil(); } else { if (!actor->isInSet(set)) { actor->putInSet(set); actor->playLastWearChore(); } lua_pushnumber(1.0); } }
void Lua_V1::FreeImage() { lua_Object param = lua_getparam(1); if (!lua_isuserdata(param) || lua_tag(param) != MKTAG('V','B','U','F')) return; Bitmap *bitmap = getbitmap(param); delete bitmap; }
void Lua_V2::GetActorPuckVector() { lua_Object actorObj = lua_getparam(1); lua_Object addObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) { lua_pushnil(); return; } Actor *actor = getactor(actorObj); // Note: The wear chore of dumbshadow.cos is only started from Lua if // GetActorPuckVector returns a non-nil value. The original engine seems // to return nil for all actors that have never followed walkboxes. if (!actor || !actor->hasFollowedBoxes()) { lua_pushnil(); return; } Math::Vector3d result = actor->getPuckVector(); if (!lua_isnil(addObj)) result += actor->getPos(); lua_pushnumber(result.x()); lua_pushnumber(result.y()); lua_pushnumber(result.z()); }
void Lua_V2::PlayLoadedSound() { lua_Object idObj = lua_getparam(1); lua_Object loopingObj = lua_getparam(2); lua_Object volumeObj = lua_getparam(3); /* FIXME: unknown parameter */ /*lua_Object bool2Obj =*/ lua_getparam(4); if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F')) { error("Lua_V2::PlayLoadedSound - ERROR: Unknown parameters"); return; } bool looping = !lua_isnil(loopingObj); PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj)); if (!sound) { warning("Lua_V2::PlayLoadedSound: can't find requested sound object"); return; } int volume = MAX_EMI_VOLUME; if (!lua_isnumber(volumeObj)) { // In the demo when the dart hits the balloon in the scumm bar, nil is passed // to the volume parameter. warning("Lua_V2::PlayLoadedSound - Unexpected parameter found, using default volume"); } else { volume = (int)lua_getnumber(volumeObj); } sound->setVolume(convertEmiVolumeToMixer(volume)); sound->play(looping); }
void Lua_V2::FreeSound() { lua_Object idObj = lua_getparam(1); if (!lua_isuserdata(idObj) || lua_tag(idObj) != MKTAG('A', 'I', 'F', 'F')) return; PoolSound *sound = PoolSound::getPool().getObject(lua_getuserdata(idObj)); delete sound; }
void Lua_V2::SetActorMumblechore() { lua_Object actorObj = lua_getparam(1); lua_Object choreObj = lua_getparam(2); lua_Object costumeObj = lua_getparam(3); Costume *costume; int chore; if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R') || (!lua_isstring(choreObj) && !lua_isnil(choreObj))) { return; } Actor *actor = getactor(actorObj); if (!findCostume(costumeObj, actor, &costume)) return; if (lua_isnil(choreObj)) { chore = -1; } else { const char * choreStr = lua_getstring(choreObj); chore = costume->getChoreId(choreStr); } actor->setMumbleChore(chore, costume); }
/* Destroy a text object since we don't need it anymore * note that the menu creates more objects than it needs, * so it deletes some objects right after creating them */ void Lua_V1::KillTextObject() { lua_Object textObj = lua_getparam(1); if (lua_isuserdata(textObj) && lua_tag(textObj) == MKTAG('T', 'E', 'X', 'T')) { delete gettextobject(textObj); } }
int luaCompat_newTypedObject(lua_State* L, void* object) { /* lua4 */ int newreference = 0; int tag = 0; LUASTACK_SET(L); luaL_checktype(L, -1, LUA_TNUMBER); tag = (int) lua_tonumber(L, -1); lua_pop(L, 1); /* pushes userdata */ lua_pushusertag(L, object, LUA_ANYTAG); if(lua_tag(L, -1) != tag) { /* this is the first userdata with this value, so corrects the tag */ lua_settag(L, tag); newreference = 1; } LUASTACK_CLEAN(L, 0); return newreference; }
void Lua_V2::GetActorChores() { lua_Object actorObj = lua_getparam(1); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); Costume *costume = actor->getCurrentCostume(); lua_Object result = lua_createtable(); lua_pushobject(result); if (!costume) { lua_pushstring("count"); lua_pushnumber(0); lua_settable(); lua_pushobject(result); return; } int num = costume->getNumChores(); lua_pushstring("count"); lua_pushnumber(num); lua_settable(); for (int i = 0; i < num; ++i) { lua_pushobject(result); lua_pushnumber(i); lua_pushusertag(((EMIChore *)costume->getChore(i))->getId(), MKTAG('C','H','O','R')); lua_settable(); } lua_pushobject(result); }
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::SetActorLighting() { lua_Object actorObj = lua_getparam(1); lua_Object lightModeObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); if (!actor) return; if (lua_isnil(lightModeObj) || !lua_isnumber(lightModeObj)) return; int lightMode = (int)lua_getnumber(lightModeObj); if (lightMode != 0) { if (lightMode == 1) { //FIXME actor-> warning("Lua_V2::SetActorLighting: case param 1(LIGHT_FASTDYN), actor: %s", actor->getName().c_str()); } else if (lightMode == 2) { //FIXME actor-> warning("Lua_V2::SetActorLighting: case param 2(LIGHT_NORMDYN), actor: %s", actor->getName().c_str()); } else { actor->setGlobalAlpha(0.0f); actor->setAlphaMode(Grim::Actor::AlphaReplace); } } else { //FIXME actor-> warning("Lua_V2::SetActorLighting: case param 0(LIGHT_STATIC), actor: %s", actor->getName().c_str()); } }
void Lua_V2::SetActorCollisionMode() { lua_Object actorObj = lua_getparam(1); lua_Object modeObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); assert(actor); int mode = (int)lua_getnumber(modeObj); Actor::CollisionMode m; switch (mode) { case Actor::CollisionOff: m = Actor::CollisionOff; break; case Actor::CollisionBox: m = Actor::CollisionBox; break; case Actor::CollisionSphere: m = Actor::CollisionSphere; break; default: warning("Lua_V2::SetActorCollisionMode(): wrong collisionmode: %d, using default 0", mode); m = Actor::CollisionOff; } actor->setCollisionMode(m); }
void L1_SendObjectToFront() { lua_Object param = lua_getparam(1); if (lua_isuserdata(param) && lua_tag(param) == MKTAG('S','T','A','T')) { ObjectState *state = getobjectstate(param); g_grim->getCurrScene()->moveObjectStateToFront(state); } }
static int toluaI_get_array (lua_State* L) { void* self = tolua_getuserdata(L,1,0); const char* field = tolua_getstring(L,2,0); if (!field) tolua_error(L,"invalid 'field' in accessing array"); if (!self) { static char msg[BUFSIZ]; sprintf(msg,"invalid 'self' in accessing array '%s'",field); tolua_error(L,msg); } toluaI_getregistry(L,"tolua_tbl_itype"); lua_pushnumber(L,lua_tag(L,1)); lua_gettable(L,-2); lua_getglobal(L,lua_tostring(L,-1)); lua_pushstring(L,".array"); lua_gettable(L,-2); lua_pushvalue(L,2); /* field */ lua_gettable(L,-2); lua_pushstring(L,".self"); lua_pushvalue(L,1); /* self */ lua_rawset(L,-3); return 1; }
static void L2_SetActorGlobalAlpha() { lua_Object actorObj = lua_getparam(1); // lua_Object alphaModeObj = lua_getparam(2); // lua_Object valueObj = lua_getparam(3); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); if (!actor) return; warning("L2_SetActorGlobalAlpha: actor: %s", actor->getName().c_str()); /* Only when actor has primitives if (!actor->primities) return; if (lua_isnumber(alphaModeObj) { int alphaMode = (int)lua_getnumber(alphaModeObj); if (!lua_isnil(valueObj) && lua_isstring(valueObj)) { // TODO: missing part } // TODO } */ }
void L1_IsActorInSector() { lua_Object actorObj = lua_getparam(1); lua_Object nameObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; if (!lua_isstring(nameObj)) { lua_pushnil(); return; } Actor *actor = getactor(actorObj); const char *name = lua_getstring(nameObj); int numSectors = g_grim->getCurrScene()->getSectorCount(); for (int i = 0; i < numSectors; i++) { Sector *sector = g_grim->getCurrScene()->getSectorBase(i); if (strstr(sector->getName(), name)) { if (sector->isPointInSector(actor->getPos())) { lua_pushnumber(sector->getSectorId()); lua_pushstring(sector->getName()); lua_pushnumber(sector->getType()); return; } } } lua_pushnil(); }
static void L2_SetActorLighting() { lua_Object actorObj = lua_getparam(1); lua_Object lightModeObj = lua_getparam(2); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); if (!actor) return; if (lua_isnil(lightModeObj) || !lua_isnumber(lightModeObj)) return; int lightMode = (int)lua_getnumber(lightModeObj); if (lightMode != 0) { if (lightMode == 1) { //FIXME actor-> warning("L2_SetActorLighting: case param 1(LIGHT_FASTDYN), actor: %s", actor->getName().c_str()); } else if (lightMode == 2) { //FIXME actor-> warning("L2_SetActorLighting: case param 2(LIGHT_NORMDYN), actor: %s", actor->getName().c_str()); } else { //FIXME actor-> warning("L2_SetActorLighting: case param %d(LIGHT_NONE), actor: %s", lightMode, actor->getName().c_str()); } } else { //FIXME actor-> warning("L2_SetActorLighting: case param 0(LIGHT_STATIC), actor: %s", actor->getName().c_str()); } }
/* Make changes to a text object based on the parameters passed * in the table in the LUA parameter 2. */ void Lua_V1::ChangeTextObject() { const char *line; lua_Object textObj = lua_getparam(1); int paramId = 2; if (lua_isuserdata(textObj) && lua_tag(textObj) == MKTAG('T', 'E', 'X', 'T')) { TextObject *textObject = gettextobject(textObj); for (;;) { lua_Object paramObj = lua_getparam(paramId++); if (!paramObj) break; if (!lua_isstring(paramObj)) { if (!lua_istable(paramObj)) break; setTextObjectParams(textObject, paramObj); textObject->reposition(); textObject->destroy(); } else { line = lua_getstring(paramObj); textObject->setText(line); lua_getstring(paramObj); } lua_pushnumber(textObject->getBitmapWidth()); lua_pushnumber(textObject->getBitmapHeight()); } } }
static void io_readfrom() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FINPUT); setreturn(1, FINPUT); } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current) { pushresult(0); return; } setreturn(id, FINPUT); } else { const char *s = luaL_check_string(FIRSTARG); LuaFile *current; Common::SeekableReadStream *inFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); inFile = saveFileMan->openForLoading(s); if (!inFile) current = g_resourceloader->openNewStreamLuaFile(s); else { current = new LuaFile(); current->_in = inFile; current->_filename = s; } if (!current) { delete current; pushresult(0); } else { setreturn(addfile(current), FINPUT); } } }