From e803cdbe7f2ecd062edc0cb6393347366ecc7fed Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 18 Jul 2013 01:13:53 -0700 Subject: [PATCH] Handle swimdeath and missing death animations --- apps/openmw/mwmechanics/character.cpp | 27 +++++++++++++++++++++------ apps/openmw/mwmechanics/character.hpp | 4 ++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index a176c1780a..fc263a8176 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -62,6 +62,7 @@ static const StateInfo sStateList[] = { { CharState_Death3, "death3" }, { CharState_Death4, "death4" }, { CharState_Death5, "death5" }, + { CharState_SwimDeath, "swimdeath" }, }; static const StateInfo *sStateListEnd = &sStateList[sizeof(sStateList)/sizeof(sStateList[0])]; @@ -650,15 +651,30 @@ void CharacterController::kill() if(mPtr.getTypeName() == typeid(ESM::NPC).name()) { - static const CharacterState deathstates[] = { + const StateInfo *state = NULL; + if(MWBase::Environment::get().getWorld()->isSwimming(mPtr)) + { + mDeathState = CharState_SwimDeath; + state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState)); + if(state == sStateListEnd) + throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState)); + } + + static const CharacterState deathstates[5] = { CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, CharState_Death5 }; + std::vector states(&deathstates[0], &deathstates[5]); - mDeathState = deathstates[(int)(rand()/((double)RAND_MAX+1.0)*5.0)]; - const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState)); - if(state == sStateListEnd) - throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState)); + while(states.size() > 1 && (!state || !mAnimation->hasAnimation(state->groupname))) + { + int pos = (int)(rand()/((double)RAND_MAX+1.0)*states.size()); + mDeathState = states[pos]; + states.erase(states.begin()+pos); + state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState)); + if(state == sStateListEnd) + throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState)); + } mCurrentDeath = state->groupname; } else @@ -689,5 +705,4 @@ void CharacterController::resurrect() mDeathState = CharState_None; } - } diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 6dfd7e6ca6..ea354a6d70 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -72,12 +72,12 @@ enum CharacterState { CharState_Jump, - /* Death states must be last! */ CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, - CharState_Death5 + CharState_Death5, + CharState_SwimDeath }; enum WeaponType {