#46: sprint becomes a permanent speed upgrade

Owning the Sprint upgrade now multiplies the scarecrow's speed by
sprint_speed_mult (1.25) all the time, walking and running, on every
platform; the run clip speeds up to match. The hold-to-sprint burst is
gone: sprint_time, sprint_cooldown, the stamina state in PlayerCharacter
(can_sprint is now has_sprint), and the HUD's stamina bar. The upgrade
keeps its id, cost, and name; its text is "Run 25% faster, always".
The sprint input action stays in project.godot, unused.

Tests: test_scarecrow's sprint checks cover 1x without it, x1.25 with it
(run and walk, clip speed, network strength), 30 s with no time limit,
no cooldown, the next morning, and no platform dependence; test_nights
checks it after the retry and a loaded save; test_economy checks the
text matches the multiplier, the menu row, and that an old save's
{"sprint": 1} still owns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 14:32:39 -04:00
parent f0291133fd
commit 962c7b0b93
9 changed files with 138 additions and 149 deletions

View file

@ -4,16 +4,18 @@ extends RefCounted
## not through cover, not while fleeing), fear (only thieves in range flee, carriers drop their
## crop, thieves mid-steal lose their progress, the cooldown, thieves come back afterwards),
## patching up (heals after the full channel while rooted; release, a hit, or fear cancel it;
## not at full health), sprint (only with the Sprint upgrade: faster while held and moving, 3 s at
## most, then a 10 s recharge; letting go or stopping ends it early; the HUD line), defeat (Game
## Over ahead of a stripped farm, the fall, the end panel and its Retry), the morning revive, and
## the new input actions.
## not at full health), Sprint (#46: the upgrade makes it sprint_speed_mult times as fast for
## good, walking and running, with nothing to hold, no time limit, no cooldown, and no stamina
## bar), defeat (Game Over ahead of a stripped farm, the fall, the end panel and its Retry), the
## morning revive, and the new input actions.
const S := LootSystem.Status
const T := ThiefBehavior.State
const DT := 1.0 / 60.0
const AWAY := Vector3(-11.0, 0.0, 13.0)
const SPOT := Vector2(8.0, -10.0) # open ground between the pen, the shed, and the field
## A light stick: it walks (under run_threshold even with the Sprint upgrade).
const WALK_STICK := 0.4
func run(r: GameTestRunner) -> void:
@ -40,7 +42,7 @@ func run(r: GameTestRunner) -> void:
func _input_actions(r: GameTestRunner) -> void:
for action in ["fear", "patch", "interact", "build_mode", "rotate_left", "rotate_right", "cancel", "pause", "sprint"]:
for action in ["fear", "patch", "interact", "build_mode", "rotate_left", "rotate_right", "cancel", "pause"]:
var keyboard := false
var pad := false
if InputMap.has_action(action):
@ -184,59 +186,90 @@ func _patch(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
_heal(sim)
## Sprint (#46): owning the upgrade makes the scarecrow sprint_speed_mult times as fast for good,
## walking and running alike, on desktop and phones. Nothing is held (the old sprint key does
## nothing), and there's no time limit, no cooldown, and no stamina bar.
func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: ScarecrowHud) -> void:
var cfg := sim.config
var mult := cfg.sprint_speed_mult
var s := sim.campaign.state
var start := Vector3(0.0, 0.0, 6.0) # the open ground south-west of the pen
s.upgrades.erase("sprint")
hud._process(0.0)
r.check(not player.can_sprint() and not hud.stamina_shown(), "no sprint before the upgrade (and no stamina bar on the HUD)")
# On the real body, over physics frames: the open ground south-west of the pen.
player.global_position = Vector3(0.0, 0.0, 6.0)
player.velocity = Vector3.ZERO
Input.action_press("move_right")
Input.action_press("sprint")
await _frames(r, 30)
var speed := Vector2(player.velocity.x, player.velocity.z).length()
r.check(not player.sprinting and speed <= player.run_speed + 0.05, "without it, holding sprint just runs (%.1f m/s)" % speed)
r.check(not player.has_sprint() and player.speed_factor() == 1.0 and not hud.has_method(&"stamina"),
"no Sprint before the upgrade: 1x speed (and the HUD has no stamina bar)")
# On the real body, over physics frames: a full stick runs, a light one walks.
var old_key := InputMap.has_action("sprint")
if old_key:
Input.action_press("sprint") # the old hold-to-sprint key
var run0: float = await _speed_after(r, player, start, 1.0)
var walk0: float = await _speed_after(r, player, start, WALK_STICK)
if old_key:
Input.action_release("sprint")
r.check(absf(run0 - player.run_speed) < 0.05, "without it, it runs at %.2f m/s, even holding the old sprint key" % run0)
s.upgrades["sprint"] = 1
await _frames(r, 30)
speed = Vector2(player.velocity.x, player.velocity.z).length()
r.check(player.sprinting and absf(speed - player.run_speed * cfg.sprint_speed_mult) < 0.1,
"with the Sprint upgrade, holding sprint while moving sprints: %.1f m/s (runs at %.1f)" % [speed, player.run_speed])
r.check(player.animation_player.current_animation == player.run_animation and player.animation_player.speed_scale > 1.5,
"the run clip plays faster (x%.2f)" % player.animation_player.speed_scale)
r.check(player.move_strength() > 1.5, "the partner's machine is told it's sprinting (strength %.2f)" % player.move_strength())
r.check(hud.stamina_shown() and hud.stamina() < 1.0 and is_equal_approx(hud.stamina(), player.sprint_left / cfg.sprint_time),
"the HUD's stamina bar appears, and drains while sprinting (%.2f)" % hud.stamina())
var run1: float = await _speed_after(r, player, start, 1.0)
r.check(absf(run1 - player.run_speed * mult) < 0.05,
"with the Sprint upgrade it runs x%.2f with nothing held: %.2f m/s (%.2f without)" % [mult, run1, run0])
r.check(player.animation_player.current_animation == player.run_animation and absf(player.animation_player.speed_scale - mult) < 0.02,
"the run clip plays x%.2f to match" % player.animation_player.speed_scale)
r.check(absf(player.move_strength() - mult) < 0.02, "the partner's machine is told it's faster (strength %.2f)" % player.move_strength())
var walk1: float = await _speed_after(r, player, start, WALK_STICK)
r.check(walk0 > 0.5 and absf(walk1 - walk0 * mult) < 0.05 and player.animation_player.current_animation == player.walk_animation,
"walking (a light stick) is x%.2f too: %.2f m/s (%.2f without), on the walk clip" % [walk1 / maxf(walk0, 0.001), walk1, walk0])
# No time limit: 30 s of moving without a stop, the body stepped tick by tick inside one physics
# frame and put back on the open ground each second.
Input.action_press("move_right")
await r.physics_frame
var span := _hand_step(player, start, 30.0)
var last := Vector2(player.velocity.x, player.velocity.z).length()
r.check(absf(span.x - run1) < 0.05 and absf(span.y - run1) < 0.05 and absf(last - run1) < 0.05,
"no time limit: after 30 s of moving it still runs %.2f m/s (%.2f..%.2f m/s throughout)" % [last, span.x, span.y])
# No cooldown: stop, then go again.
Input.action_release("move_right")
await _frames(r, 2)
r.check(not player.sprinting and player.sprint_recharge > cfg.sprint_cooldown - 0.1, "stopping ends it, and the recharge starts")
r.check(hud.stamina() < 0.1, "and starts filling back as it recharges (%.2f)" % hud.stamina())
Input.action_release("sprint")
var stopped := _hand_step(player, start, 1.0)
Input.action_press("move_right")
var again := _hand_step(player, start, 0.5)
r.check(stopped.y < 0.05 and absf(again.x - run1) < 0.05 and absf(again.y - run1) < 0.05,
"no cooldown: stopped, then off again at once at %.2f m/s" % again.y)
Input.action_release("move_right")
sim.scarecrow.reset_for_morning()
r.check(is_equal_approx(player.speed_factor(), mult), "a new morning keeps it (x%.2f)" % player.speed_factor())
# Phones: the speed path never asks the platform, so MobilePort.active() makes no difference.
var asks := false
for script: GDScript in [player.get_script(), load("res://game/scripts/upgrades.gd")]:
asks = asks or script.source_code.contains("MobilePort")
r.check(not asks, "the speed doesn't depend on the platform (PlayerCharacter and Upgrades never ask MobilePort; phone mode here: %s)" % MobilePort.active())
s.upgrades.erase("sprint")
await _frames(r, 30)
player.velocity = Vector3.ZERO
player.global_position = Vector3(SPOT.x, 0.0, SPOT.y)
# The timing, tick by tick.
player.reset_sprint()
var ticks := 0
player.step_sprint(DT, true, true)
while player.sprinting and ticks < 1200:
player.step_sprint(DT, true, true)
ticks += 1
r.check(absf(ticks * DT - cfg.sprint_time) < DT * 2.0, "held, a sprint lasts %.1f s" % (ticks * DT))
ticks = 0
while not player.sprinting and ticks < 1200:
player.step_sprint(DT, true, true)
ticks += 1
r.check(absf(ticks * DT - cfg.sprint_cooldown) < DT * 2.0, "then %.1f s to recharge, and still held it starts again" % (ticks * DT))
player.step_sprint(1.0, true, true)
player.step_sprint(DT, false, true)
r.check(not player.sprinting and is_equal_approx(player.sprint_recharge, cfg.sprint_cooldown), "letting go early ends it, and the full recharge starts")
player.step_sprint(DT, true, false)
r.check(not player.sprinting, "and it doesn't start standing still")
sim.scarecrow.reset_for_morning()
r.check(player.sprint_recharge == 0.0 and hud.stamina() == 1.0, "a new morning has it ready (a full bar)")
s.upgrades.erase("sprint")
## Puts the scarecrow at a spot at rest, holds move_right at a stick strength for 30 physics
## frames, and returns its speed (m/s). move_right stays held.
func _speed_after(r: GameTestRunner, player: PlayerCharacter, at: Vector3, strength: float) -> float:
player.global_position = at
player.velocity = Vector3.ZERO
Input.action_press("move_right", strength)
await _frames(r, 30)
return Vector2(player.velocity.x, player.velocity.z).length()
## Steps the body by hand for that many seconds of 60 Hz ticks (call it right after awaiting
## physics_frame, so move_and_slide moves by DT), putting it back at the spot every second so it
## stays on open ground. Returns the lowest and highest speed (m/s) over the ticks after the
## first quarter second (the speed-up).
func _hand_step(player: PlayerCharacter, at: Vector3, seconds: float) -> Vector2:
var span := Vector2(INF, 0.0)
var ticks := roundi(seconds / DT)
for i in ticks:
if i % 60 == 0:
player.global_position = at
player._physics_process(DT)
if i >= 15:
var v := Vector2(player.velocity.x, player.velocity.z).length()
span = Vector2(minf(span.x, v), maxf(span.y, v))
return span
func _frames(r: GameTestRunner, n: int) -> void: