1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 09:23:53 +00:00

Merge branch 'bootlegcharacter' into 'master'

Nitpicking in CharacterController::update()

See merge request OpenMW/openmw!2460
This commit is contained in:
psi29a 2022-10-10 07:27:07 +00:00
commit c562b0b72c
2 changed files with 102 additions and 109 deletions

View file

@ -1424,8 +1424,7 @@ namespace MWMechanics
if (isWerewolf) if (isWerewolf)
{ {
if (stats.getStance(MWMechanics::CreatureStats::Stance_Run) && mHasMovedInXY && !world->isSwimming(mPtr) if (isRunning() && !world->isSwimming(mPtr) && mWeaponType == ESM::Weapon::None)
&& mWeaponType == ESM::Weapon::None)
{ {
if (!sndMgr->getSoundPlaying(mPtr, "WolfRun")) if (!sndMgr->getSoundPlaying(mPtr, "WolfRun"))
sndMgr->playSound3D(mPtr, "WolfRun", 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop); sndMgr->playSound3D(mPtr, "WolfRun", 1.0f, 1.0f, MWSound::Type::Sfx, MWSound::PlayMode::Loop);
@ -1856,8 +1855,6 @@ namespace MWMechanics
else if (!cls.getCreatureStats(mPtr).isDead()) else if (!cls.getCreatureStats(mPtr).isDead())
{ {
bool onground = world->isOnGround(mPtr); bool onground = world->isOnGround(mPtr);
bool incapacitated = ((!godmode && cls.getCreatureStats(mPtr).isParalyzed())
|| cls.getCreatureStats(mPtr).getKnockedDown());
bool inwater = world->isSwimming(mPtr); bool inwater = world->isSwimming(mPtr);
bool flying = world->isFlying(mPtr); bool flying = world->isFlying(mPtr);
bool solid = world->isActorCollisionEnabled(mPtr); bool solid = world->isActorCollisionEnabled(mPtr);
@ -1872,7 +1869,7 @@ namespace MWMechanics
bool isMoving bool isMoving
= (std::abs(movementSettings.mPosition[0]) > .5 || std::abs(movementSettings.mPosition[1]) > .5); = (std::abs(movementSettings.mPosition[0]) > .5 || std::abs(movementSettings.mPosition[1]) > .5);
if (!inwater && !flying && solid) if (!inwater && !flying)
{ {
// Force Jump // Force Jump
if (stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceJump)) if (stats.getMovementFlag(MWMechanics::CreatureStats::Flag_ForceJump))
@ -1987,18 +1984,18 @@ namespace MWMechanics
vec.x() *= speed; vec.x() *= speed;
vec.y() *= speed; vec.y() *= speed;
if (mHitState != CharState_None && mHitState != CharState_Block && mJumpState == JumpState_None) if (isKnockedOut() || isKnockedDown() || isRecovery())
vec = osg::Vec3f(); vec = osg::Vec3f();
CharacterState movestate = CharState_None; CharacterState movestate = CharState_None;
CharacterState idlestate = CharState_None; CharacterState idlestate = CharState_None;
JumpingState jumpstate = JumpState_None; JumpingState jumpstate = JumpState_None;
mHasMovedInXY = std::abs(vec.x()) + std::abs(vec.y()) > 0.0f; const MWWorld::Store<ESM::GameSetting>& gmst = world->getStore().get<ESM::GameSetting>();
isrunning = isrunning && mHasMovedInXY; if (vec.x() != 0.f || vec.y() != 0.f)
{
// advance athletics // advance athletics
if (mHasMovedInXY && isPlayer) if (isPlayer)
{ {
if (inwater) if (inwater)
{ {
@ -2020,9 +2017,10 @@ namespace MWMechanics
} }
} }
if (!godmode)
{
// reduce fatigue // reduce fatigue
const MWWorld::Store<ESM::GameSetting>& gmst = world->getStore().get<ESM::GameSetting>(); float fatigueLoss = 0.f;
float fatigueLoss = 0;
static const float fFatigueRunBase = gmst.find("fFatigueRunBase")->mValue.getFloat(); static const float fFatigueRunBase = gmst.find("fFatigueRunBase")->mValue.getFloat();
static const float fFatigueRunMult = gmst.find("fFatigueRunMult")->mValue.getFloat(); static const float fFatigueRunMult = gmst.find("fFatigueRunMult")->mValue.getFloat();
static const float fFatigueSwimWalkBase = gmst.find("fFatigueSwimWalkBase")->mValue.getFloat(); static const float fFatigueSwimWalkBase = gmst.find("fFatigueSwimWalkBase")->mValue.getFloat();
@ -2053,40 +2051,38 @@ namespace MWMechanics
fatigueLoss *= duration; fatigueLoss *= duration;
fatigueLoss *= movementSettings.mSpeedFactor; fatigueLoss *= movementSettings.mSpeedFactor;
DynamicStat<float> fatigue = cls.getCreatureStats(mPtr).getFatigue(); DynamicStat<float> fatigue = cls.getCreatureStats(mPtr).getFatigue();
if (!godmode)
{
fatigue.setCurrent(fatigue.getCurrent() - fatigueLoss, fatigue.getCurrent() < 0); fatigue.setCurrent(fatigue.getCurrent() - fatigueLoss, fatigue.getCurrent() < 0);
cls.getCreatureStats(mPtr).setFatigue(fatigue); cls.getCreatureStats(mPtr).setFatigue(fatigue);
} }
}
float z = cls.getJump(mPtr); bool inJump = false;
if (sneak || inwater || flying || incapacitated || !solid || z <= 0) if (!inwater && !flying && solid)
vec.z() = 0.0f;
bool inJump = true;
bool playLandingSound = false;
if (!onground && !flying && !inwater && solid)
{ {
// In the air (either getting up —ascending part of jump— or falling). // In the air (either getting up —ascending part of jump— or falling).
if (!onground)
{
inJump = true;
jumpstate = JumpState_InAir; jumpstate = JumpState_InAir;
static const float fJumpMoveBase = gmst.find("fJumpMoveBase")->mValue.getFloat(); static const float fJumpMoveBase = gmst.find("fJumpMoveBase")->mValue.getFloat();
static const float fJumpMoveMult = gmst.find("fJumpMoveMult")->mValue.getFloat(); static const float fJumpMoveMult = gmst.find("fJumpMoveMult")->mValue.getFloat();
float factor float factor = fJumpMoveBase
= fJumpMoveBase + fJumpMoveMult * mPtr.getClass().getSkill(mPtr, ESM::Skill::Acrobatics) / 100.f; + fJumpMoveMult * mPtr.getClass().getSkill(mPtr, ESM::Skill::Acrobatics) / 100.f;
factor = std::min(1.f, factor); factor = std::min(1.f, factor);
vec.x() *= factor; vec.x() *= factor;
vec.y() *= factor; vec.y() *= factor;
vec.z() = 0.0f; vec.z() = 0.0f;
} }
else if (vec.z() > 0.0f && mJumpState != JumpState_InAir)
{
// Started a jump. // Started a jump.
if (z > 0) else if (mJumpState != JumpState_InAir && vec.z() > 0.f && !sneak)
{ {
float z = cls.getJump(mPtr);
if (z > 0.f)
{
inJump = true;
if (vec.x() == 0 && vec.y() == 0) if (vec.x() == 0 && vec.y() == 0)
vec = osg::Vec3f(0.0f, 0.0f, z); vec.z() = z;
else else
{ {
osg::Vec3f lat(vec.x(), vec.y(), 0.0f); osg::Vec3f lat(vec.x(), vec.y(), 0.0f);
@ -2095,7 +2091,9 @@ namespace MWMechanics
} }
} }
} }
else }
if (!inJump)
{ {
if (mJumpState == JumpState_InAir && !flying && solid) if (mJumpState == JumpState_InAir && !flying && solid)
{ {
@ -2135,7 +2133,18 @@ namespace MWMechanics
} }
if (mPtr.getClass().isNpc()) if (mPtr.getClass().isNpc())
playLandingSound = true; {
std::string_view sound;
osg::Vec3f pos(mPtr.getRefData().getPosition().asVec3());
if (world->isUnderwater(mPtr.getCell(), pos) || world->isWalkingOnWater(mPtr))
sound = "DefaultLandWater";
else if (onground)
sound = "DefaultLand";
if (!sound.empty())
sndMgr->playSound3D(
mPtr, sound, 1.f, 1.f, MWSound::Type::Foot, MWSound::PlayMode::NoPlayerLocal);
}
} }
if (mAnimation->isPlaying(mCurrentJump)) if (mAnimation->isPlaying(mCurrentJump))
@ -2145,8 +2154,6 @@ namespace MWMechanics
vec.y() *= scale; vec.y() *= scale;
vec.z() = 0.0f; vec.z() = 0.0f;
inJump = false;
if (movementSettings.mIsStrafing) if (movementSettings.mIsStrafing)
{ {
if (vec.x() > 0.0f) if (vec.x() > 0.0f)
@ -2187,19 +2194,6 @@ namespace MWMechanics
} }
} }
if (playLandingSound)
{
std::string_view sound;
osg::Vec3f pos(mPtr.getRefData().getPosition().asVec3());
if (world->isUnderwater(mPtr.getCell(), pos) || world->isWalkingOnWater(mPtr))
sound = "DefaultLandWater";
else if (onground)
sound = "DefaultLand";
if (!sound.empty())
sndMgr->playSound3D(mPtr, sound, 1.f, 1.f, MWSound::Type::Foot, MWSound::PlayMode::NoPlayerLocal);
}
if (turnToMovementDirection && !isFirstPersonPlayer if (turnToMovementDirection && !isFirstPersonPlayer
&& (movestate == CharState_SwimRunForward || movestate == CharState_SwimWalkForward && (movestate == CharState_SwimRunForward || movestate == CharState_SwimWalkForward
|| movestate == CharState_SwimRunBack || movestate == CharState_SwimWalkBack)) || movestate == CharState_SwimRunBack || movestate == CharState_SwimWalkBack))

View file

@ -147,7 +147,6 @@ namespace MWMechanics
std::string mCurrentMovement; std::string mCurrentMovement;
float mMovementAnimSpeed{ 0.f }; float mMovementAnimSpeed{ 0.f };
bool mAdjustMovementAnimSpeed{ false }; bool mAdjustMovementAnimSpeed{ false };
bool mHasMovedInXY{ false };
bool mMovementAnimationControlled{ true }; bool mMovementAnimationControlled{ true };
CharacterState mDeathState{ CharState_None }; CharacterState mDeathState{ CharState_None };