mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:56:43 +00:00 
			
		
		
		
	Handle swimdeath and missing death animations
This commit is contained in:
		
							parent
							
								
									f01b0b48cc
								
							
						
					
					
						commit
						e803cdbe7f
					
				
					 2 changed files with 23 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -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[] = {
 | 
			
		||||
            CharState_Death1, CharState_Death2, CharState_Death3, CharState_Death4, CharState_Death5
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        mDeathState = deathstates[(int)(rand()/((double)RAND_MAX+1.0)*5.0)];
 | 
			
		||||
        const StateInfo *state = std::find_if(sStateList, sStateListEnd, FindCharState(mDeathState));
 | 
			
		||||
        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<CharacterState> states(&deathstates[0], &deathstates[5]);
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue