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

pull/1/head
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); 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) void CharacterController::playRandomDeath(float startpoint)
{ {
if (mPtr == getPlayer()) if (mPtr == getPlayer())
@ -652,9 +659,7 @@ void CharacterController::playRandomDeath(float startpoint)
} }
else else
{ {
int selected=0; mDeathState = chooseRandomDeathState();
chooseRandomGroup("death", &selected);
mDeathState = static_cast<CharacterState>(CharState_Death1 + (selected-1));
} }
playDeath(startpoint, mDeathState); 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 // 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 // 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; mFloatToSurface = false;
} }
} }

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

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

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

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

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

Loading…
Cancel
Save