Merge task #17: Propane Torch sprays a band of fire

Band hit test from the scarecrow along the aim (torch_width, longer
torch_range), a particle flame held lit while firing (and on the
partner's screen via attack events), reusable held-effect pattern in
WeaponModels, torch roar cue. Resolved farm_audio.gd header with #19.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:15:17 -04:00
commit 51b553bba8
12 changed files with 483 additions and 37 deletions

View file

@ -10,7 +10,8 @@ extends RefCounted
## weapon in hand, both at once, held, not with the right click that leaves build mode); a bomb's
## throw (at the aim, its range clamped), flight, and burst (everything in its radius, crows too,
## nothing beyond, not the scarecrow), its recharge and the morning refill; the models on the
## scarecrow; and the HUD's weapon panel.
## scarecrow; the HUD's weapon panel; the shed's other weapons; and the Propane Torch's band of
## fire and its flame (#17).
const DT := 1.0 / 60.0
const AT := Vector2(0.0, 6.0) # open ground south-west of the pen
@ -39,6 +40,7 @@ func run(r: GameTestRunner) -> void:
_bombs(r, sim)
_hud(r, farm, sim)
_shed_weapons(r, farm, sim)
await _torch(r, farm, sim)
sim.enemies.behavior = keep
farm.queue_free()
await r.process_frame
@ -354,21 +356,134 @@ func _shed_weapons(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
_buy_equip_hit(r, farm, sim, "potato_cannon", W.POTATO_CANNON, cfg.potato_cannon_speed)
_buy_equip_hit(r, farm, sim, "shurikens", W.SHURIKENS, cfg.shuriken_speed)
_buy_equip_hit(r, farm, sim, "alien_ray", W.ALIEN_RAY, cfg.alien_ray_speed)
# Propane Torch: a sustained cone, not a projectile, so its tick lands the same step.
c.equip(W.PITCHFORK)
## The Propane Torch (#17): bought at the supply shed, a band of fire along the gun's line
## (torch_width wide, from the scarecrow out to torch_range past the muzzle). An enemy in the band
## burns; one beside, behind, or beyond it doesn't. Held, it ticks every torch_tick_interval and
## stops on release. Its flame, sized to the band and facing the model's way, is lit only while
## fire is held: on its own machine, for the partner's replica, and on the partner's machine (lit
## by attack events, which nothing steps there) where it goes out by itself.
func _torch(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var c := sim.combat
var cfg := sim.config
var s := sim.campaign.state
var es := sim.enemies
var panel := farm.get_node("Hud/ShedPanel") as UpgradePanel
var at := Vector2(sim.player.global_position.x, sim.player.global_position.z) # (AT, give or take)
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999}
r.check(not c.owns(W.PROPANE_TORCH), "the propane torch isn't owned yet")
panel._buy("propane_torch")
r.check(Upgrades.owned(s, "propane_torch") and c.owns(W.PROPANE_TORCH), "it's purchasable at the supply shed")
r.check(c.equip(W.PROPANE_TORCH) and c.weapon == W.PROPANE_TORCH, "and equippable")
var target := es.spawn(THIEF, AT.x + cfg.torch_range - 0.5, AT.y, Vector2.LEFT)
_step(sim, 1)
var hp := _hp(es, target)
var flame := c.models.held_effect(W.PROPANE_TORCH) as TorchFlame
r.check(flame != null and not flame.visible and not c.models.lit(W.PROPANE_TORCH), "its flame is out until it fires")
r.check(is_equal_approx(flame.length, cfg.torch_range) and is_equal_approx(flame.width, cfg.torch_width),
"the flame is sized to the band (%.1f m long, %.1f m wide)" % [flame.length, flame.width])
# One tick aimed east (spawned and burned on the same step, so nobody gets a swing in first).
# The gun's line runs SIDE_OFFSET south of the scarecrow's, bent onto the aim point.
var reach := cfg.muzzle_distance + cfg.torch_range # from the scarecrow's center
var far_in := es.spawn(THIEF, at.x + reach - 0.2, at.y, Vector2.LEFT)
var side_in := es.spawn(THIEF, at.x + 2.5, at.y + 0.95, Vector2.LEFT)
var beside := es.spawn(THIEF, at.x + 2.5, at.y + 2.3, Vector2.LEFT)
var beside2 := es.spawn(THIEF, at.x + 3.5, at.y - 1.9, Vector2.LEFT)
var behind := es.spawn(THIEF, at.x - 1.5, at.y, Vector2.RIGHT)
var beyond := es.spawn(THIEF, at.x + reach + 1.0, at.y, Vector2.LEFT)
var full := es.t_hp[THIEF]
c.reset()
var ticks := c.torch_ticks
r.check(c.attack_toward(AT + Vector2(cfg.torch_range + 1.0, 0.0)) and c.torch_ticks == ticks + 1, "it fires its first tick")
var d := es.resolve_handle(target)
r.check(d < 0 or es.health[d] < hp, "and burns the nearest enemy in its cone for torch_damage")
var played := sim.audio.played if sim.audio != null else {}
var roars := int(played.get("burn", 0))
var stabs := int(played.get("stab", 0))
r.check(c.attack_toward(at + Vector2(8.0, 0.0)) and c.torch_ticks == ticks + 1, "it fires its first tick")
r.check(sim.audio == null or (int(played.get("burn", 0)) == roars + 1 and int(played.get("stab", 0)) == stabs),
"with a roar (its own sound, not the pitchfork's whoosh)")
r.check(_hp(es, far_in) == full - cfg.torch_damage and _hp(es, side_in) == full - cfg.torch_damage,
"an enemy in the band burns for %d: %.1f m past the muzzle, and off its center line" % [cfg.torch_damage, cfg.torch_range - 0.2])
r.check(_hp(es, beside) == full and _hp(es, beside2) == full, "one beside the band, either side, doesn't")
r.check(_hp(es, behind) == full and _hp(es, beyond) == full, "nor one behind the scarecrow, nor one beyond the band's end")
r.check(c.models._attack_t < 0.0 and c.models.lit(W.PROPANE_TORCH) and flame.visible,
"a tick lights the flame instead of replaying the gun's kick")
_clear(sim)
var hugger := es.spawn(THIEF, at.x + 0.7, at.y, Vector2.LEFT)
c.reset()
c.attack_toward(at + Vector2(0.7, 0.0))
r.check(_hp(es, hugger) == full - cfg.torch_damage,
"a thief pressed against the scarecrow, aimed at, burns too (it stands inside the muzzle)")
_clear(sim)
# Held: a tick every torch_tick_interval, the flame lit throughout; let go, both stop.
var tough := es.spawn(THIEF, at.x + 3.5, at.y, Vector2.LEFT)
es.health[es.resolve_handle(tough)] = 99
c.device = ScarecrowCombat.Device.GAMEPAD # keeps the aim it's given
c.aim = Vector2(1.0, 0.0)
c.reset()
_step(sim, 1) # fire not held: the reset's release is seen
r.check(not c.models.lit(W.PROPANE_TORCH), "(the flame went out: fire isn't held)")
ticks = c.torch_ticks
var burns: Array[int] = []
var on_burn := func(n: int) -> void: burns.append(n)
c.burned.connect(on_burn)
var intervals := 5
var lit_throughout := true
Input.action_press("fire")
for i in c.torch_interval_ticks() * intervals:
_step(sim, 1)
lit_throughout = lit_throughout and c.models.lit(W.PROPANE_TORCH) and flame.lit and flame.visible
var held_ticks := c.torch_ticks - ticks
var burned := 99 - _hp(es, tough)
Input.action_release("fire")
_step(sim, 1)
var out_at_once := not c.models.lit(W.PROPANE_TORCH) and not flame.lit and flame.visible
var after := c.torch_ticks
_step(sim, c.torch_interval_ticks() * 3)
r.check(held_ticks == intervals and burned == intervals * cfg.torch_damage and burns.size() == intervals,
"holding fire burns every %.1f s: %d ticks in %.1f s, %d damage" % [cfg.torch_tick_interval, held_ticks, intervals * cfg.torch_tick_interval, burned])
r.check(c.torch_ticks == after and 99 - _hp(es, tough) == burned, "letting go stops it")
r.check(lit_throughout, "the flame stays lit the whole time fire is held, between ticks too")
r.check(out_at_once and not flame.visible, "and goes out when fire is let go (the fire in the air fades, then it's hidden)")
c.burned.disconnect(on_burn)
# The flame comes from the gun and faces the model's way (all the partner's machine knows of
# the other scarecrow's aim).
var model := sim.player.model
var yaw := model.rotation.y
model.rotation.y = 1.0
var dir := flame.direction()
var facing := Vector2(-sin(1.0), -cos(1.0))
r.check(Vector2(dir.x, dir.z).normalized().dot(facing) > 0.999 and dir.y < 0.0,
"the flame points the way the model faces (dipping toward the band)")
model.rotation.y = yaw
# The partner's own scarecrow on its machine (a replica: the host burns for it) shows the
# flame while fire is held there.
c.replica = true
Input.action_press("fire")
_step(sim, c.torch_interval_ticks() * 2)
var replica_lit := c.models.lit(W.PROPANE_TORCH) and flame.visible and c.torch_ticks == after
Input.action_release("fire")
_step(sim, 1)
c.replica = false
r.check(replica_lit and not c.models.lit(W.PROPANE_TORCH), "a replica's flame is lit while fire is held there, and burns nothing")
# The other scarecrow on the partner's machine: lit by its attack events (CoopSession: show the
# weapon, then models.attack), one per tick, and stepped by nothing there, so its flame times
# out on the physics frames.
_step(sim, ceili(TorchFlame.LIFETIME * 60.0) + 2)
var events_lit := true
for k in 3:
c.show_weapon(W.PROPANE_TORCH)
c.models.attack(W.PROPANE_TORCH)
for i in c.torch_interval_ticks():
await r.physics_frame
events_lit = events_lit and c.models.lit(W.PROPANE_TORCH) and flame.visible
var hold := cfg.torch_tick_interval * ScarecrowCombat.HOLD_TICKS
for i in ceili((hold + TorchFlame.LIFETIME) * Engine.physics_ticks_per_second) + 6:
await r.physics_frame
r.check(events_lit and not c.models.lit(W.PROPANE_TORCH) and not flame.visible,
"on the partner's machine, attack events keep the flame lit, and it goes out by itself once they stop")
c.models.attack(W.PROPANE_TORCH)
c.equip(W.PITCHFORK)
r.check(not flame.visible and not c.models.lit(W.PROPANE_TORCH), "switching weapons puts it out at once")
c.device = ScarecrowCombat.Device.MOUSE
_clear(sim)
## Buys id at the supply shed, equips w, and checks that a shot fired at a thief some meters off