Ashlar checks / tooling (push) Successful in 9s
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>
126 lines
5.1 KiB
Lua
126 lines
5.1 KiB
Lua
-- Ashlar headless movement scenario (CC0). The player stands still, runs forward, stops, runs forward again,
|
|
-- reverses, and then sprints (see PHASES). Every frame it logs the speed the engine reports
|
|
-- (types.Actor.getCurrentSpeed, which includes [Game] movement acceleration and sprint) as a share of run speed,
|
|
-- how far the player actually moved along its facing, and its fatigue ratio. "applied" is how long the current
|
|
-- control has been held, counting only frames the engine has processed.
|
|
local core = require('openmw.core')
|
|
local self = require('openmw.self')
|
|
local types = require('openmw.types')
|
|
local util = require('openmw.util')
|
|
local I = require('openmw.interfaces')
|
|
local Actor = types.Actor
|
|
|
|
local PHASES = {
|
|
{ name = 'settle', at = 0, movement = 0 },
|
|
{ name = 'forward', at = 3, movement = 1 },
|
|
{ name = 'stop', at = 5, movement = 0 },
|
|
{ name = 'forward2', at = 6, movement = 1 },
|
|
{ name = 'reverse', at = 7.5, movement = -1 },
|
|
{ name = 'walkstop', at = 9.5, movement = 0 },
|
|
-- Sprint phases start back at the starting point and circle, so the player stays on land.
|
|
-- Sprint until fatigue runs out; fatigue is set just above [Game] sprint fatigue threshold.
|
|
{ name = 'sprint', at = 10.5, movement = 1, sprint = true, fatigue = 0.11, circle = true },
|
|
-- Below the threshold a new sprint can't start.
|
|
{ name = 'tiredsprint', at = 26, movement = 1, sprint = true, fatigue = 0.05, circle = true },
|
|
-- Rested again; pressing Use with hand-to-hand ready ends the sprint until Sprint is released.
|
|
{ name = 'sprintuse', at = 29, movement = 1, sprint = true, fatigue = 1, use = 1.5, circle = true },
|
|
{ name = 'done', at = 33, movement = 0 },
|
|
}
|
|
|
|
local t = 0
|
|
local phase
|
|
local applied = 0
|
|
local lastPos
|
|
local reachedFull
|
|
local stopped
|
|
local start
|
|
-- Turning rate in sprint phases, radians per second.
|
|
local CIRCLE_RATE = 0.8
|
|
|
|
local function log(fmt, ...)
|
|
print('ASHLAR_MOVE ' .. string.format(fmt, ...))
|
|
end
|
|
|
|
local function fatigueRatio()
|
|
local fatigue = Actor.stats.dynamic.fatigue(self)
|
|
return fatigue.base > 0 and fatigue.current / fatigue.base or 0
|
|
end
|
|
|
|
local function enterPhase(p)
|
|
phase = p
|
|
applied = 0
|
|
reachedFull, stopped = nil, nil
|
|
if p.fatigue then
|
|
local fatigue = Actor.stats.dynamic.fatigue(self)
|
|
fatigue.current = fatigue.base * p.fatigue
|
|
end
|
|
if p.circle and start then
|
|
core.sendGlobalEvent('AshlarMoveReset', { player = self.object, position = start.position,
|
|
rotation = start.rotation })
|
|
lastPos = nil
|
|
end
|
|
if p.name == 'sprintuse' then
|
|
Actor.setStance(self, Actor.STANCE.Weapon)
|
|
end
|
|
log('phase %s fatigue=%.3f', p.name, fatigueRatio())
|
|
end
|
|
|
|
return {
|
|
engineHandlers = {
|
|
onFrame = function(dt)
|
|
if dt <= 0 or (phase and phase.name == 'done') then
|
|
return
|
|
end
|
|
if not phase then
|
|
I.Controls.overrideMovementControls(true)
|
|
I.Controls.overrideCombatControls(true)
|
|
start = { position = self.position, rotation = self.rotation }
|
|
enterPhase(PHASES[1])
|
|
end
|
|
t = t + dt
|
|
|
|
-- What the engine did in the frames up to now.
|
|
local run = Actor.getRunSpeed(self)
|
|
local ratio = run > 0 and Actor.getCurrentSpeed(self) / run or 0
|
|
local facing = self.rotation * util.vector3(0, 1, 0)
|
|
local along = 0
|
|
if lastPos and dt > 0 then
|
|
along = ((self.position - lastPos) * facing) / dt / math.max(run, 1)
|
|
end
|
|
lastPos = self.position
|
|
if phase.name ~= 'settle' then
|
|
log('%s applied=%.3f speed=%.3f along=%.3f fatigue=%.3f', phase.name, applied, ratio, along,
|
|
fatigueRatio())
|
|
if phase.sprint then
|
|
-- Sprint phases only report the speed; full run speed isn't the goal there.
|
|
elseif phase.movement ~= 0 and not reachedFull and ratio > 0.99 then
|
|
reachedFull = applied
|
|
log('%s reached full speed after %.3f s', phase.name, applied)
|
|
elseif phase.movement == 0 and not stopped and ratio < 0.01 then
|
|
stopped = applied
|
|
log('%s stopped after %.3f s', phase.name, applied)
|
|
end
|
|
end
|
|
|
|
local nextPhase = phase
|
|
for _, p in ipairs(PHASES) do
|
|
if t >= p.at then
|
|
nextPhase = p
|
|
end
|
|
end
|
|
if nextPhase ~= phase then
|
|
enterPhase(nextPhase)
|
|
end
|
|
self.controls.movement = phase.movement
|
|
self.controls.sideMovement = 0
|
|
self.controls.run = true
|
|
self.controls.jump = false
|
|
-- Sprint is released for the first moments of each phase, so every sprint phase starts a new sprint.
|
|
self.controls.sprint = (phase.sprint and applied >= 0.3) or false
|
|
self.controls.yawChange = phase.circle and CIRCLE_RATE * dt or 0
|
|
self.controls.use = (phase.use and applied >= phase.use) and 1 or 0
|
|
applied = applied + dt
|
|
end,
|
|
},
|
|
}
|