1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-28 21:09:40 +00:00

Fallback for short weapon groups

This commit is contained in:
Andrei Kortunov 2019-08-09 12:10:28 +04:00
parent afaff8231d
commit 123ca175c8
3 changed files with 57 additions and 28 deletions

View file

@ -335,17 +335,12 @@ void CharacterController::refreshJumpAnims(const std::string& weapShortGroup, Ju
jumpAnimName += weapShortGroup; jumpAnimName += weapShortGroup;
if(!mAnimation->hasAnimation(jumpAnimName)) if(!mAnimation->hasAnimation(jumpAnimName))
{ {
jumpmask = MWRender::Animation::BlendMask_LowerBody; jumpAnimName = fallbackShortWeaponGroup("jump", &jumpmask);
jumpAnimName = "jump";
// Since we apply movement only for lower body, do not reset idle animations. // If we apply jump only for lower body, do not reset idle animations.
// For upper body there will be idle animation. // For upper body there will be idle animation.
if (idle == CharState_None) if (jumpmask == MWRender::Animation::BlendMask_LowerBody && idle == CharState_None)
idle = CharState_Idle; idle = CharState_Idle;
// For crossbow animations use 1h ones as fallback
if (mWeaponType == ESM::Weapon::MarksmanCrossbow)
jumpAnimName += "1h";
} }
} }
} }
@ -419,6 +414,43 @@ void CharacterController::onClose()
} }
} }
std::string CharacterController::fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask)
{
bool isRealWeapon = mWeaponType != ESM::Weapon::HandToHand && mWeaponType != ESM::Weapon::Spell && mWeaponType != ESM::Weapon::None;
if (!isRealWeapon)
{
if (blendMask != nullptr)
*blendMask = MWRender::Animation::BlendMask_LowerBody;
return baseGroupName;
}
static const std::string oneHandFallback = getWeaponType(ESM::Weapon::LongBladeOneHand)->mShortGroup;
static const std::string twoHandFallback = getWeaponType(ESM::Weapon::LongBladeTwoHand)->mShortGroup;
std::string groupName = baseGroupName;
const ESM::WeaponType* weapInfo = getWeaponType(mWeaponType);
// For real two-handed melee weapons use 2h swords animations as fallback, otherwise use the 1h ones
if (isRealWeapon && weapInfo->mFlags & ESM::WeaponType::TwoHanded && weapInfo->mWeaponClass == ESM::WeaponType::Melee)
groupName += twoHandFallback;
else if (isRealWeapon)
groupName += oneHandFallback;
// Special case for crossbows - we shouls apply 1h animations a fallback only for lower body
if (mWeaponType == ESM::Weapon::MarksmanCrossbow && blendMask != nullptr)
*blendMask = MWRender::Animation::BlendMask_LowerBody;
if (!mAnimation->hasAnimation(groupName))
{
groupName = baseGroupName;
if (blendMask != nullptr)
*blendMask = MWRender::Animation::BlendMask_LowerBody;
}
return groupName;
}
void CharacterController::refreshMovementAnims(const std::string& weapShortGroup, CharacterState movement, CharacterState& idle, bool force) void CharacterController::refreshMovementAnims(const std::string& weapShortGroup, CharacterState movement, CharacterState& idle, bool force)
{ {
if (movement == mMovementState && idle == mIdleState && !force) if (movement == mMovementState && idle == mIdleState && !force)
@ -449,15 +481,12 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
movementAnimName = movestate->groupname; movementAnimName = movestate->groupname;
if (swimpos == std::string::npos) if (swimpos == std::string::npos)
{ {
movemask = MWRender::Animation::BlendMask_LowerBody; movementAnimName = fallbackShortWeaponGroup(movementAnimName, &movemask);
// Since we apply movement only for lower body, do not reset idle animations.
// For upper body there will be idle animation.
if (idle == CharState_None)
idle = CharState_Idle;
// For crossbow animations use 1h ones as fallback // If we apply movement only for lower body, do not reset idle animations.
if (mWeaponType == ESM::Weapon::MarksmanCrossbow) // For upper body there will be idle animation.
movementAnimName += "1h"; if (movemask == MWRender::Animation::BlendMask_LowerBody && idle == CharState_None)
idle = CharState_Idle;
} }
else if (idle == CharState_None) else if (idle == CharState_None)
{ {
@ -493,10 +522,6 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
} }
else else
{ {
// For crossbow animations use 1h ones as fallback
if (mWeaponType == ESM::Weapon::MarksmanCrossbow)
movementAnimName += "1h";
movementAnimName.erase(swimpos, 4); movementAnimName.erase(swimpos, 4);
if (!weapShortGroup.empty()) if (!weapShortGroup.empty())
{ {
@ -504,7 +529,7 @@ void CharacterController::refreshMovementAnims(const std::string& weapShortGroup
if(mAnimation->hasAnimation(weapMovementAnimName)) if(mAnimation->hasAnimation(weapMovementAnimName))
movementAnimName = weapMovementAnimName; movementAnimName = weapMovementAnimName;
else else
movemask = MWRender::Animation::BlendMask_LowerBody; movementAnimName = fallbackShortWeaponGroup(movementAnimName, &movemask);
} }
if (!mAnimation->hasAnimation(movementAnimName)) if (!mAnimation->hasAnimation(movementAnimName))
@ -607,7 +632,9 @@ void CharacterController::refreshIdleAnims(const std::string& weapShortGroup, Ch
{ {
idleGroup += weapShortGroup; idleGroup += weapShortGroup;
if(!mAnimation->hasAnimation(idleGroup)) if(!mAnimation->hasAnimation(idleGroup))
idleGroup = "idle"; {
idleGroup = fallbackShortWeaponGroup("idle");
}
// play until the Loop Stop key 2 to 5 times, then play until the Stop key // play until the Loop Stop key 2 to 5 times, then play until the Stop key
// this replicates original engine behavior for the "Idle1h" 1st-person animation // this replicates original engine behavior for the "Idle1h" 1st-person animation

View file

@ -230,6 +230,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener
bool updateCarriedLeftVisible(int weaptype) const; bool updateCarriedLeftVisible(int weaptype) const;
std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr);
public: public:
CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim); CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim);
virtual ~CharacterController(); virtual ~CharacterController();

View file

@ -68,7 +68,7 @@ namespace MWMechanics
{ {
ESM::Weapon::ShortBladeOneHand, ESM::Weapon::ShortBladeOneHand,
{ {
/* short group */ "1h", /* short group */ "1s",
/* long group */ "weapononehand", /* long group */ "weapononehand",
/* sound ID */ "Item Weapon Shortblade", /* sound ID */ "Item Weapon Shortblade",
/* attach bone */ "Weapon Bone", /* attach bone */ "Weapon Bone",
@ -96,7 +96,7 @@ namespace MWMechanics
{ {
ESM::Weapon::BluntOneHand, ESM::Weapon::BluntOneHand,
{ {
/* short group */ "1h", /* short group */ "1b",
/* long group */ "weapononehand", /* long group */ "weapononehand",
/* sound ID */ "Item Weapon Blunt", /* sound ID */ "Item Weapon Blunt",
/* attach bone */ "Weapon Bone", /* attach bone */ "Weapon Bone",
@ -110,7 +110,7 @@ namespace MWMechanics
{ {
ESM::Weapon::AxeOneHand, ESM::Weapon::AxeOneHand,
{ {
/* short group */ "1h", /* short group */ "1b",
/* long group */ "weapononehand", /* long group */ "weapononehand",
/* sound ID */ "Item Weapon Blunt", /* sound ID */ "Item Weapon Blunt",
/* attach bone */ "Weapon Bone", /* attach bone */ "Weapon Bone",
@ -138,7 +138,7 @@ namespace MWMechanics
{ {
ESM::Weapon::AxeTwoHand, ESM::Weapon::AxeTwoHand,
{ {
/* short group */ "2c", /* short group */ "2b",
/* long group */ "weapontwohand", /* long group */ "weapontwohand",
/* sound ID */ "Item Weapon Blunt", /* sound ID */ "Item Weapon Blunt",
/* attach bone */ "Weapon Bone", /* attach bone */ "Weapon Bone",
@ -152,7 +152,7 @@ namespace MWMechanics
{ {
ESM::Weapon::BluntTwoClose, ESM::Weapon::BluntTwoClose,
{ {
/* short group */ "2c", /* short group */ "2b",
/* long group */ "weapontwohand", /* long group */ "weapontwohand",
/* sound ID */ "Item Weapon Blunt", /* sound ID */ "Item Weapon Blunt",
/* attach bone */ "Weapon Bone", /* attach bone */ "Weapon Bone",
@ -194,7 +194,7 @@ namespace MWMechanics
{ {
ESM::Weapon::MarksmanBow, ESM::Weapon::MarksmanBow,
{ {
/* short group */ "1h", /* short group */ "bow",
/* long group */ "bowandarrow", /* long group */ "bowandarrow",
/* sound ID */ "Item Weapon Bow", /* sound ID */ "Item Weapon Bow",
/* attach bone */ "Weapon Bone Left", /* attach bone */ "Weapon Bone Left",