mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-24 18:39:59 +00:00
Query the number of animation groups for death/hit animations, since they can vary a lot (argonian/khajiit, creatures, first person..)
This commit is contained in:
parent
05e75e1214
commit
fec26342cd
@ -62,26 +62,6 @@ struct StateInfo {
|
|||||||
const char groupname[32];
|
const char groupname[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string sDeathList[] = {
|
|
||||||
"death1" ,
|
|
||||||
"death2" ,
|
|
||||||
"death3" ,
|
|
||||||
"death4" ,
|
|
||||||
"death5" ,
|
|
||||||
"swimdeath",
|
|
||||||
};
|
|
||||||
static const int sDeathListSize = sizeof(sDeathList)/sizeof(sDeathList[0]);
|
|
||||||
|
|
||||||
static const std::string sHitList[] = {
|
|
||||||
"hit1" ,
|
|
||||||
"hit2" ,
|
|
||||||
"hit3" ,
|
|
||||||
"hit4" ,
|
|
||||||
"hit5" ,
|
|
||||||
"knockdown" ,
|
|
||||||
};
|
|
||||||
static const int sHitListSize = sizeof(sHitList)/sizeof(sHitList[0]);
|
|
||||||
|
|
||||||
static const StateInfo sMovementList[] = {
|
static const StateInfo sMovementList[] = {
|
||||||
{ CharState_WalkForward, "walkforward" },
|
{ CharState_WalkForward, "walkforward" },
|
||||||
{ CharState_WalkBack, "walkback" },
|
{ CharState_WalkBack, "walkback" },
|
||||||
@ -154,6 +134,17 @@ public:
|
|||||||
{ return weap.type == type; }
|
{ return weap.type == type; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string CharacterController::chooseRandomGroup (const std::string& prefix, int* num)
|
||||||
|
{
|
||||||
|
int numAnims=0;
|
||||||
|
while (mAnimation->hasAnimation(prefix + Ogre::StringConverter::toString(numAnims+1)))
|
||||||
|
++numAnims;
|
||||||
|
|
||||||
|
int roll = std::rand()/ (static_cast<double> (RAND_MAX) + 1) * numAnims + 1; // [1, numAnims]
|
||||||
|
if (num)
|
||||||
|
*num = roll;
|
||||||
|
return prefix + Ogre::StringConverter::toString(roll);
|
||||||
|
}
|
||||||
|
|
||||||
void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force)
|
void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterState movement, bool force)
|
||||||
{
|
{
|
||||||
@ -167,20 +158,13 @@ void CharacterController::refreshCurrentAnims(CharacterState idle, CharacterStat
|
|||||||
if(knockdown)
|
if(knockdown)
|
||||||
{
|
{
|
||||||
mHitState = CharState_KnockDown;
|
mHitState = CharState_KnockDown;
|
||||||
mCurrentHit = sHitList[sHitListSize-1];
|
mCurrentHit = "knockdown";
|
||||||
mAnimation->play(mCurrentHit, Priority_Knockdown, MWRender::Animation::Group_All, true, 1, "start", "stop", 0.0f, 0);
|
mAnimation->play(mCurrentHit, Priority_Knockdown, MWRender::Animation::Group_All, true, 1, "start", "stop", 0.0f, 0);
|
||||||
}
|
}
|
||||||
else if (recovery)
|
else if (recovery)
|
||||||
{
|
{
|
||||||
mHitState = CharState_Hit;
|
mHitState = CharState_Hit;
|
||||||
int iHit = rand() % (sHitListSize-1);
|
mCurrentHit = chooseRandomGroup("hit");
|
||||||
mCurrentHit = sHitList[iHit];
|
|
||||||
if(mPtr.getRefData().getHandle()=="player" && !mAnimation->hasAnimation(mCurrentHit))
|
|
||||||
{
|
|
||||||
//only 3 different hit animations if player is in 1st person
|
|
||||||
int iHit = rand() % (sHitListSize-3);
|
|
||||||
mCurrentHit = sHitList[iHit];
|
|
||||||
}
|
|
||||||
mAnimation->play(mCurrentHit, Priority_Hit, MWRender::Animation::Group_All, true, 1, "start", "stop", 0.0f, 0);
|
mAnimation->play(mCurrentHit, Priority_Hit, MWRender::Animation::Group_All, true, 1, "start", "stop", 0.0f, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,28 +371,20 @@ MWWorld::ContainerStoreIterator getActiveWeapon(CreatureStats &stats, MWWorld::I
|
|||||||
|
|
||||||
void CharacterController::playRandomDeath(float startpoint)
|
void CharacterController::playRandomDeath(float startpoint)
|
||||||
{
|
{
|
||||||
if(MWWorld::Class::get(mPtr).isNpc())
|
if(MWBase::Environment::get().getWorld()->isSwimming(mPtr) && mAnimation->hasAnimation("swimdeath"))
|
||||||
{
|
{
|
||||||
if(MWBase::Environment::get().getWorld()->isSwimming(mPtr))
|
mDeathState = CharState_SwimDeath;
|
||||||
{
|
mCurrentDeath = "swimdeath";
|
||||||
mDeathState = CharState_SwimDeath;
|
|
||||||
mCurrentDeath = sDeathList[sDeathListSize-1]; //last in the list is 'swimdeath'
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int num = rand() % (sDeathListSize-1);
|
|
||||||
mDeathState = static_cast<CharacterState>(CharState_Death1 + num);
|
|
||||||
mCurrentDeath = sDeathList[num];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mDeathState = CharState_Death1;
|
int selected=0;
|
||||||
mCurrentDeath = "death1";
|
mCurrentDeath = chooseRandomGroup("death", &selected);
|
||||||
|
mDeathState = static_cast<CharacterState>(CharState_Death1 + (selected-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAnimation->play(mCurrentDeath, Priority_Death, MWRender::Animation::Group_All,
|
mAnimation->play(mCurrentDeath, Priority_Death, MWRender::Animation::Group_All,
|
||||||
false, 1.0f, "start", "stop", 0.0f, 0);
|
false, 1.0f, "start", "stop", startpoint, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim)
|
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim)
|
||||||
|
@ -177,6 +177,10 @@ class CharacterController
|
|||||||
|
|
||||||
void playRandomDeath(float startpoint = 0.0f);
|
void playRandomDeath(float startpoint = 0.0f);
|
||||||
|
|
||||||
|
/// choose a random animation group with \a prefix and numeric suffix
|
||||||
|
/// @param num if non-NULL, the chosen animation number will be written here
|
||||||
|
std::string chooseRandomGroup (const std::string& prefix, int* num = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim);
|
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim);
|
||||||
virtual ~CharacterController();
|
virtual ~CharacterController();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user