Files
claudeandClaude Opus 5.5 a691315db7
Ashlar checks / tooling (push) Successful in 9s
Add a stamina-driven sprint
New [Game] sprint setting, on by default, with sprint speed multiplier
(1.4 times run speed), sprint fatigue drain (10 per second on top of
running, halved at Athletics 100) and sprint fatigue threshold (0.1 of
maximum fatigue to start). A sprint ends when fatigue falls below 1% of
maximum; regeneration keeps fatigue just above 0 while running, so
exactly 0 is never reached.

Sprint is engine action 52, Lua input.ACTION.Sprint and the player's
'Sprint' Lua action, with self.controls.sprint. Defaults are Left Alt
and D-pad up, because L3 is already Sneak. Sprinting needs forward
movement within 45 degrees, and isn't possible while sneaking, in the
block stance, swimming, levitating, knocked down or paralyzed. Pressing
Use with a weapon or spell ready ends the sprint until Sprint is
released, so no attack starts while sprinting. A sprint counts as
running for animations, Athletics and the running fatigue cost. AI
doesn't sprint. With the setting off the control does nothing.

The rules are in mwmechanics/sprint.cpp with unit tests. The movement
scenario gains sprint, tiredsprint and sprintuse phases, run in a
circle from the start point so the player stays on land.

Closes #27

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:12:57 -05:00

59 lines
2.4 KiB
C++

#ifndef OPENMW_MECHANICS_SPRINT_H
#define OPENMW_MECHANICS_SPRINT_H
namespace MWWorld
{
class Ptr;
}
namespace MWMechanics
{
// Ashlar sprint. With [Game] sprint on, an NPC (in practice the player) holding the Sprint control while moving
// forward moves at [Game] sprint speed multiplier times its run speed and drains fatigue on top of the running
// cost. A sprint needs [Game] sprint fatigue threshold of fatigue to start and ends when fatigue runs out. It isn't
// possible while sneaking, in the block stance, swimming or flying. Pressing Use ends the sprint until Sprint is
// released, so no attack or spell starts while sprinting. AI doesn't sprint.
/// Share of maximum fatigue below which a sprint counts as out of fatigue. Fatigue regenerates a little every
/// frame, so it never stays at exactly 0 while running.
constexpr float sSprintExhaustedRatio = 0.01f;
struct SprintConditions
{
bool mHeld = false;
bool mMovingForward = false;
bool mSneaking = false;
bool mBlocking = false;
bool mSwimming = false;
bool mFlying = false;
bool mIncapacitated = false;
/// Use was pressed since Sprint was last pressed.
bool mCancelled = false;
bool mWasSprinting = false;
float mCurrentFatigue = 0.f;
float mMaxFatigue = 0.f;
};
/// True if movement with \a forward and \a side controls (-1 to 1) points forward, within 45 degrees.
bool isForwardMovement(float forward, float side);
/// True if an actor in \a conditions sprints this frame. Both need positive fatigue. When the maximum is positive,
/// starting needs a fatigue ratio of at least \a threshold, and carrying on needs at least sSprintExhaustedRatio.
bool canSprint(const SprintConditions& conditions, float threshold);
/// Extra fatigue per second while sprinting at full speed: \a drain, falling with \a athletics to half at 100.
float getSprintFatigueDrain(float drain, float athletics);
/// True if [Game] sprint is on.
bool usesSprint();
/// True if \a actor is sprinting this frame.
bool isSprinting(const MWWorld::Ptr& actor);
/// Updates \a actor's sprint for this frame from its controls and state, and returns whether it sprints.
/// \a forward and \a side are the requested movement controls.
bool updateSprint(const MWWorld::Ptr& actor, float forward, float side, bool sneaking, bool swimming, bool flying);
}
#endif