void EMICostume::saveState(SaveGame *state) const { Costume::saveState(state); for (int i = 0; i < _numChores; ++i) { EMIChore *chore = (EMIChore *)_chores[i]; state->writeLESint32(chore->getId()); } state->writeLESint32(_wearChore ? _wearChore->getChoreId() : -1); }
bool EMICostume::restoreState(SaveGame *state) { bool ret = Costume::restoreState(state); if (ret) { if (state->saveMinorVersion() >= 11) { EMIChore::Pool &pool = EMIChore::getPool(); for (int i = 0; i < _numChores; ++i) { EMIChore *chore = (EMIChore *)_chores[i]; int id = state->readLESint32(); pool.removeObject(chore->getId()); EMIChore* oldChore = pool.getObject(id); if (oldChore) { pool.removeObject(id); oldChore->setId(chore->getId()); pool.addObject(oldChore); } chore->setId(id); pool.addObject(chore); } } if (state->saveMinorVersion() < 13) { // Used to be active texture IDs for materials. Materials are now // managed by the owner Actor of this Costume. for (uint i = 0; i < _materials.size(); ++i) { state->readLESint32(); } } int id = state->readLESint32(); if (id >= 0) { EMIChore *chore = static_cast<EMIChore *>(_chores[id]); setWearChore(chore); } } return ret; }
// 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(); } }