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::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); }
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); }
void Lua_V2::setChoreAndCostume(lua_Object choreObj, lua_Object costumeObj, Actor *actor, Costume *&costume, int &chore) { if (lua_isnil(choreObj)) { chore = -1; } else { if (!findCostume(costumeObj, actor, &costume)) return; if (!costume) { costume = actor->getCurrentCostume(); } const char *choreStr = lua_getstring(choreObj); chore = costume->getChoreId(choreStr); } }
// TODO: Implement, verify, and rename unknown 5th parameter void Lua_V2::PlayActorChore() { lua_Object actorObj = lua_getparam(1); lua_Object choreObj = lua_getparam(2); lua_Object costumeObj = lua_getparam(3); lua_Object modeObj = lua_getparam(4); /* lua_Object paramObj = */ lua_getparam(5); if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) return; Actor *actor = getactor(actorObj); if (!lua_isstring(choreObj) || !lua_isstring(costumeObj)) lua_pushnil(); bool mode = false; // float param = 0.0; if (!lua_isnil(modeObj)) { if (lua_getnumber(modeObj) != 0.0) mode = true; //if (!lua_isnil(paramObj)) // if (lua_isnumber(paramObj)) // param = lua_getnumber(paramObj); } const char *choreName = lua_getstring(choreObj); const char *costumeName = lua_getstring(costumeObj); Costume *costume; // If a new wear chore is set and it uses a different costume than the // current one and neither of them is the shadow costume stop all active // chores and remove the old costume before setting the new one. // // This is necessary, because always the last costume on the stack, even // if it is not active, is returned by getCurrentCostume(). This would // cause an issue if the costumes would have different joints and the lua // code would consider a different costume active than the C code. if (0 == strncmp("wear_", choreName, 5)) { if (0 != strncmp("fx/dumbshadow.cos", costumeName, 17)) { if (actor->getCurrentCostume() != NULL && actor->getCurrentCostume()->getFilename() != "fx/dumbshadow.cos" && actor->getCurrentCostume()->getFilename().compareToIgnoreCase(costumeName) != 0) { actor->stopAllChores(); actor->setRestChore(-1, NULL); actor->setWalkChore(-1, NULL); actor->setTurnChores(-1, -1, NULL); actor->setMumbleChore(-1, NULL); actor->popCostume(); } } } if (!findCostume(costumeObj, actor, &costume)) return; EMIChore *chore = (EMIChore *)costume->getChore(choreName); if (0 == strncmp("wear_", choreName, 5)) { actor->setLastWearChore(costume->getChoreId(choreName), costume); } if (mode) { costume->playChoreLooping(choreName); } else { costume->playChore(choreName); } if (chore) { lua_pushusertag(chore->getId(), MKTAG('C','H','O','R')); } else { lua_pushnil(); } }
bool Actor::restoreState(SaveGame *savedState) { for (Common::List<Costume *>::const_iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { delete *i; } _costumeStack.clear(); // load actor name _name = savedState->readString(); _setName = savedState->readString(); _talkColor = savedState->readColor(); _pos = savedState->readVector3d(); _pitch = savedState->readFloat(); _yaw = savedState->readFloat(); _roll = savedState->readFloat(); _walkRate = savedState->readFloat(); _turnRate = savedState->readFloat(); _constrain = savedState->readBool(); _reflectionAngle = savedState->readFloat(); _visible = savedState->readBool(); _lookingMode = savedState->readBool(); _scale = savedState->readFloat(); _timeScale = savedState->readFloat(); _puckOrient = savedState->readBool(); _talkSoundName = savedState->readString(); _talking = savedState->readBool(); _backgroundTalk = savedState->readBool(); if (isTalking()) { g_grim->addTalkingActor(this); } _collisionMode = (CollisionMode)savedState->readLEUint32(); _collisionScale = savedState->readFloat(); if (savedState->readBool()) { Common::String fn = savedState->readString(); _lipSync = g_resourceloader->getLipSync(fn); } else { _lipSync = NULL; } uint32 size = savedState->readLEUint32(); for (uint32 i = 0; i < size; ++i) { Common::String fname = savedState->readString(); const int depth = savedState->readLESint32(); Costume *pc = NULL; if (depth > 0) { //build all the previousCostume hierarchy Common::String *names = new Common::String[depth]; for (int j = 0; j < depth; ++j) { names[j] = savedState->readString(); } for (int j = depth - 1; j >= 0; --j) { pc = findCostume(names[j]); if (!pc) { pc = g_resourceloader->loadCostume(names[j], pc); } } delete[] names; } Costume *c = g_resourceloader->loadCostume(fname, pc); c->restoreState(savedState); _costumeStack.push_back(c); } _turning = savedState->readBool(); _moveYaw = savedState->readFloat(); _walking = savedState->readBool(); _destPos = savedState->readVector3d(); _restChore.restoreState(savedState, this); _walkChore.restoreState(savedState, this); _walkedLast = savedState->readBool(); _walkedCur = savedState->readBool(); _leftTurnChore.restoreState(savedState, this); _rightTurnChore.restoreState(savedState, this); _lastTurnDir = savedState->readLESint32(); _currTurnDir = savedState->readLESint32(); for (int i = 0; i < 10; ++i) { _talkChore[i].restoreState(savedState, this); } _talkAnim = savedState->readLESint32(); _mumbleChore.restoreState(savedState, this); clearShadowPlanes(); for (int i = 0; i < MAX_SHADOWS; ++i) { Shadow &shadow = _shadowArray[i]; shadow.name = savedState->readString(); shadow.pos = savedState->readVector3d(); size = savedState->readLEUint32(); Set *scene = NULL; for (uint32 j = 0; j < size; ++j) { Common::String setName = savedState->readString(); Common::String secName = savedState->readString(); if (!scene || scene->getName() != setName) { scene = g_grim->findSet(setName); } if (scene) { addShadowPlane(secName.c_str(), scene, i); } else { warning("%s: No scene \"%s\" found, cannot restore shadow on sector \"%s\"", getName().c_str(), setName.c_str(), secName.c_str()); } } shadow.shadowMaskSize = savedState->readLESint32(); delete[] shadow.shadowMask; if (shadow.shadowMaskSize > 0) { shadow.shadowMask = new byte[shadow.shadowMaskSize]; savedState->read(shadow.shadowMask, shadow.shadowMaskSize); } else { shadow.shadowMask = NULL; } shadow.active = savedState->readBool(); shadow.dontNegate = savedState->readBool(); } _activeShadowSlot = savedState->readLESint32(); _sayLineText = savedState->readLESint32(); _lookAtVector = savedState->readVector3d(); size = savedState->readLEUint32(); for (uint32 i = 0; i < size; ++i) { _path.push_back(savedState->readVector3d()); } return true; }