From f2f601b9588da34ca5e1bd4f6d130dc081755c1e Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 27 Feb 2016 13:13:24 +0100 Subject: [PATCH] Implement corpse clearing (Fixes #2363) --- apps/openmw/mwworld/cellstore.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 1572ae1b0..e4bfde04a 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -889,11 +889,19 @@ namespace MWWorld return mFogState.get(); } + void clearCorpse(const MWWorld::Ptr& ptr) + { + const MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); + static const float fCorpseClearDelay = MWBase::Environment::get().getWorld()->getStore().get().find("fCorpseClearDelay")->getFloat(); + if (!ptr.getClass().isPersistent(ptr) && creatureStats.getTimeOfDeath() + fCorpseClearDelay <= MWBase::Environment::get().getWorld()->getTimeStamp()) + MWBase::Environment::get().getWorld()->deleteObject(ptr); + } + void CellStore::respawn() { if (mState == State_Loaded) { - static int iMonthsToRespawn = MWBase::Environment::get().getWorld()->getStore().get().find("iMonthsToRespawn")->getInt(); + static const int iMonthsToRespawn = MWBase::Environment::get().getWorld()->getStore().get().find("iMonthsToRespawn")->getInt(); if (MWBase::Environment::get().getWorld()->getTimeStamp() - mLastRespawn > 24*30*iMonthsToRespawn) { mLastRespawn = MWBase::Environment::get().getWorld()->getTimeStamp(); @@ -907,16 +915,19 @@ namespace MWWorld for (CellRefList::List::iterator it (mCreatures.mList.begin()); it!=mCreatures.mList.end(); ++it) { Ptr ptr (&*it, this); + clearCorpse(ptr); ptr.getClass().respawn(ptr); } for (CellRefList::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it) { Ptr ptr (&*it, this); + clearCorpse(ptr); ptr.getClass().respawn(ptr); } for (CellRefList::List::iterator it (mCreatureLists.mList.begin()); it!=mCreatureLists.mList.end(); ++it) { Ptr ptr (&*it, this); + // no need to clearCorpse, handled as part of mCreatures ptr.getClass().respawn(ptr); } }