Choose a random death animation for actors that start the game as dead (Fixes #3397)

coverity_scan^2
scrawl 9 years ago
parent b0180cb6b4
commit 3749821809

@ -629,6 +629,13 @@ void CharacterController::playDeath(float startpoint, CharacterState death)
false, 1.0f, "start", "stop", startpoint, 0);
}
CharacterState CharacterController::chooseRandomDeathState()
{
int selected=0;
chooseRandomGroup("death", &selected);
return static_cast<CharacterState>(CharState_Death1 + (selected-1));
}
void CharacterController::playRandomDeath(float startpoint)
{
if (mPtr == getPlayer())
@ -652,9 +659,7 @@ void CharacterController::playRandomDeath(float startpoint)
}
else
{
int selected=0;
chooseRandomGroup("death", &selected);
mDeathState = static_cast<CharacterState>(CharState_Death1 + (selected-1));
mDeathState = chooseRandomDeathState();
}
playDeath(startpoint, mDeathState);
}
@ -716,7 +721,12 @@ CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Anim
{
// Set the death state, but don't play it yet
// We will play it in the first frame, but only if no script set the skipAnim flag
mDeathState = static_cast<CharacterState>(CharState_Death1 + mPtr.getClass().getCreatureStats(mPtr).getDeathAnimation());
signed char deathanim = mPtr.getClass().getCreatureStats(mPtr).getDeathAnimation();
if (deathanim == -1)
mDeathState = chooseRandomDeathState();
else
mDeathState = static_cast<CharacterState>(CharState_Death1 + deathanim);
mFloatToSurface = false;
}
}

@ -207,6 +207,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener
void updateMagicEffects();
void playDeath(float startpoint, CharacterState death);
CharacterState chooseRandomDeathState();
void playRandomDeath(float startpoint = 0.0f);
/// choose a random animation group with \a prefix and numeric suffix

@ -22,7 +22,7 @@ namespace MWMechanics
mKnockdown(false), mKnockdownOneFrame(false), mKnockdownOverOneFrame(false),
mHitRecovery(false), mBlock(false), mMovementFlags(0),
mFallHeight(0), mRecalcMagicka(false), mLastRestock(0,0), mGoldPool(0), mActorId(-1),
mDeathAnimation(0), mTimeOfDeath(), mLevel (0)
mDeathAnimation(-1), mTimeOfDeath(), mLevel (0)
{
for (int i=0; i<4; ++i)
mAiSettings[i] = 0;
@ -617,12 +617,12 @@ namespace MWMechanics
esm.getHNT(sActorId, "COUN");
}
unsigned char CreatureStats::getDeathAnimation() const
signed char CreatureStats::getDeathAnimation() const
{
return mDeathAnimation;
}
void CreatureStats::setDeathAnimation(unsigned char index)
void CreatureStats::setDeathAnimation(signed char index)
{
mDeathAnimation = index;
}

@ -62,8 +62,8 @@ namespace MWMechanics
int mActorId;
// The index of the death animation that was played
unsigned char mDeathAnimation;
// The index of the death animation that was played, or -1 if none played
signed char mDeathAnimation;
MWWorld::TimeStamp mTimeOfDeath;
@ -258,8 +258,8 @@ namespace MWMechanics
void setGoldPool(int pool);
int getGoldPool() const;
unsigned char getDeathAnimation() const;
void setDeathAnimation(unsigned char index);
signed char getDeathAnimation() const; // -1 means not decided
void setDeathAnimation(signed char index);
MWWorld::TimeStamp getTimeOfDeath() const;

@ -84,7 +84,7 @@ void ESM::CreatureStats::load (ESMReader &esm)
mActorId = -1;
esm.getHNOT (mActorId, "ACID");
mDeathAnimation = 0;
mDeathAnimation = -1;
esm.getHNOT (mDeathAnimation, "DANM");
mTimeOfDeath.mDay = 0;
@ -194,7 +194,7 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
if (mActorId != -1)
esm.writeHNT ("ACID", mActorId);
if (mDeathAnimation)
if (mDeathAnimation != -1)
esm.writeHNT ("DANM", mDeathAnimation);
if (mTimeOfDeath.mHour != 0 && mTimeOfDeath.mDay != 0)
@ -247,6 +247,6 @@ void ESM::CreatureStats::blank()
mFallHeight = 0.f;
mRecalcDynamicStats = false;
mDrawState = 0;
mDeathAnimation = 0;
mDeathAnimation = -1;
mLevel = 1;
}

@ -56,7 +56,7 @@ namespace ESM
std::string mLastHitAttemptObject;
bool mRecalcDynamicStats;
int mDrawState;
unsigned char mDeathAnimation;
signed char mDeathAnimation;
ESM::TimeStamp mTimeOfDeath;
int mLevel;

Loading…
Cancel
Save