1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Handle swimdeath and missing death animations

This commit is contained in:
Chris Robinson 2013-07-18 01:13:53 -07:00
parent f01b0b48cc
commit e803cdbe7f
2 changed files with 23 additions and 8 deletions

View File

@ -62,6 +62,7 @@ static const StateInfo sStateList[] = {
{ CharState_Death3, "death3" }, { CharState_Death3, "death3" },
{ CharState_Death4, "death4" }, { CharState_Death4, "death4" },
{ CharState_Death5, "death5" }, { CharState_Death5, "death5" },
{ CharState_SwimDeath, "swimdeath" },
}; };
static const StateInfo *sStateListEnd = &sStateList[sizeof(sStateList)/sizeof(sStateList[0])]; static const StateInfo *sStateListEnd = &sStateList[sizeof(sStateList)/sizeof(sStateList[0])];
@ -650,15 +651,30 @@ void CharacterController::kill()
if(mPtr.getTypeName() == typeid(ESM::NPC).name()) 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 CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, CharState_Death5
}; };
std::vector<CharacterState> states(&deathstates[0], &deathstates[5]);
mDeathState = deathstates[(int)(rand()/((double)RAND_MAX+1.0)*5.0)]; while(states.size() > 1 && (!state || !mAnimation->hasAnimation(state->groupname)))
const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState)); {
if(state == sStateListEnd) int pos = (int)(rand()/((double)RAND_MAX+1.0)*states.size());
throw std::runtime_error("Failed to find character state "+Ogre::StringConverter::toString(mDeathState)); 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; mCurrentDeath = state->groupname;
} }
else else
@ -689,5 +705,4 @@ void CharacterController::resurrect()
mDeathState = CharState_None; mDeathState = CharState_None;
} }
} }

View File

@ -72,12 +72,12 @@ enum CharacterState {
CharState_Jump, CharState_Jump,
/* Death states must be last! */
CharState_Death1, CharState_Death1,
CharState_Death2, CharState_Death2,
CharState_Death3, CharState_Death3,
CharState_Death4, CharState_Death4,
CharState_Death5 CharState_Death5,
CharState_SwimDeath
}; };
enum WeaponType { enum WeaponType {