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

@ -144,7 +144,7 @@ upgrades = {
"propane_torch": {
"name": "Propane torch",
"shop": "shed",
"text": "A short-range jet of flame that burns everything in its cone while held",
"text": "A jet of flame that burns everything in a band ahead of you while held",
"track": "Weapon"
},
"pumpkin_bomb": {

View file

@ -4,7 +4,8 @@ extends Node3D
## stingers and outcomes; SFX: everything else; Ambience: the day and night loops). FarmSim
## creates it and setup() connects it to the farm's systems:
## * scarecrow: footsteps, its weapons (a pitchfork's whoosh and what it strikes, corn shots,
## a pumpkin bomb's toss and burst), hurt, fall, fear and fear ready, patching and patched
## the propane torch's roar, a pumpkin bomb's toss and burst), hurt, fall, fear and fear
## ready, patching and patched
## * enemies: crow caws and thieves' / fence breakers' / UFOs' arrivals (from where they come
## in), hits and deaths by type
## * theft: grabbed, dropped, recovered, carried off (with an alarm tone), animals following
@ -41,6 +42,8 @@ const CUES := {
"step": {"files": ["kenney/impact/footstep_grass_00*.ogg"], "db": -15.0, "pitch": 0.08},
"shot": {"files": ["kenney/interface/pluck_00*.ogg"], "db": -9.0, "pitch": 0.12, "max": 3},
"stab": {"files": ["synth/pitchfork_whoosh.wav"], "db": -6.0, "pitch": 0.12, "max": 3},
# The Propane Torch: one roar per tick, each longer than a tick, so a held torch roars on.
"burn": {"files": ["synth/torch_roar.wav"], "db": -7.0, "pitch": 0.08, "gap": 0.1, "max": 3},
"throw": {"files": ["kenney/rpg/cloth*.ogg"], "db": -4.0, "pitch": 0.1},
"boom": {"files": ["synth/pumpkin_boom.wav"], "db": 0.0, "pitch": 0.08, "gap": 0.05, "max": 4},
"hurt": {"files": ["kenney/impact/impactSoft_heavy_00*.ogg"], "db": -1.0, "pitch": 0.1, "gap": 0.1},
@ -299,6 +302,7 @@ func _wire_weapons(combat: ScarecrowCombat, at: Callable) -> void:
var where := func() -> Vector3: return at.call() if at.is_valid() else Vector3.INF
combat.fired.connect(func() -> void: play("shot", where.call()))
combat.stabbed.connect(func(_n: int) -> void: play("stab", where.call()))
combat.burned.connect(func(_n: int) -> void: play("burn", where.call()))
combat.struck.connect(func(p: Vector3, type: int) -> void: play("hit_crow" if type == EnemySystem.TYPE_CROW else "hit", p))
combat.threw.connect(func(_to: Vector3) -> void: play("throw", where.call()))

View file

@ -152,7 +152,7 @@ extends Resource
"pumpkin_bomb": {"name": "Pumpkin bombs", "text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)", "track": "Weapon", "shop": "shed"},
"potato_cannon": {"name": "Potato cannon", "text": "A slow heavy potato shot that hits hard from afar", "track": "Weapon", "shop": "shed"},
"shurikens": {"name": "Shurikens", "text": "Fast, cheap throws for a quick hit", "track": "Weapon", "shop": "shed"},
"propane_torch": {"name": "Propane torch", "text": "A short-range jet of flame that burns everything in its cone while held", "track": "Weapon", "shop": "shed"},
"propane_torch": {"name": "Propane torch", "text": "A jet of flame that burns everything in a band ahead of you while held", "track": "Weapon", "shop": "shed"},
"alien_ray": {"name": "Alien ray", "text": "A salvaged alien weapon: a fast, powerful beam", "track": "Weapon", "shop": "shed", "hidden": true},
"radar": {"name": "Radar", "text": "A minimap showing nearby enemy positions", "track": "Item", "shop": "shed", "hidden": true},
"wide_fear": {"name": "Wide fear", "text": "Fear reaches 30% farther", "track": "Fear", "stat": "fear_radius", "mult": 1.3},
@ -286,12 +286,13 @@ extends Resource
@export var shuriken_speed: float = 34.0
@export var shuriken_lifetime: float = 1.0
@export_range(1, 6) var shuriken_count: int = 1
## Propane Torch (the Propane torch upgrade, bought at the supply shed): a sustained cone while
## held, a tick every torch_tick_interval s, torch_damage each to every enemy within torch_range m
## and torch_arc degrees of the aim (the nearest torch_targets), with a clear line (ScarecrowCombat,
## the same cone test as the pitchfork's).
@export var torch_range: float = 3.5
@export var torch_arc: float = 55.0
## Propane Torch (the Propane torch upgrade, bought at the supply shed): a band of fire while held
## (#17), a tick every torch_tick_interval s, torch_damage each to the enemies in a torch_width m
## wide band along the gun's line, from the scarecrow out to torch_range m past the muzzle (the
## nearest torch_targets), with a clear line (ScarecrowCombat._band_hit). Its flame (TorchFlame)
## is sized to the band.
@export var torch_range: float = 4.5
@export var torch_width: float = 1.6
@export_range(1, 20) var torch_damage: int = 1
@export_range(1, 20) var torch_targets: int = 5
@export var torch_tick_interval: float = 0.2

View file

@ -35,13 +35,18 @@ extends Node3D
## through FarmProjectiles at potato_cannon_speed
## shurikens shuriken_count shuriken_damage throws every shuriken_cooldown, fast
## (shuriken_speed) and cheap
## propane torch a torch_damage tick every torch_tick_interval to every enemy within
## torch_range and torch_arc of the aim (up to torch_targets), with a clear
## line: a sustained cone while held, like the pitchfork's stab
## propane torch a band of fire while held (#17): a torch_damage tick every
## torch_tick_interval to the enemies in a torch_width wide band along the
## gun's line, from the scarecrow out to torch_range past the muzzle (the
## nearest torch_targets), with a clear line (_band_hit), and its flame
## (TorchFlame) lit while fire is held
## alien ray one fast, powerful alien_ray_damage shot every alien_ray_cooldown, through
## FarmProjectiles at alien_ray_speed
## * Every weapon's model on the scarecrow (WeaponModels), an aim marker, and while a pumpkin
## bomb is ready a ring on the ground where one would land, as wide as its blast.
## bomb is ready a ring on the ground where one would land, as wide as its blast. A held
## weapon (the torch) lights its effect on each attack instead of replaying a motion; the
## effect stays lit for HOLD_TICKS of its ticks after the last one (WeaponModels.add_held_effect)
## and goes out at once when fire is let go.
## While attacking, the model faces the aim.
## Co-op: the partner's weapons on the host read its RemoteControls (aim, fire and offhand, and
## its pick of main weapon come from the partner's game); on the partner's machine its own only
@ -56,8 +61,10 @@ enum Weapon { PITCHFORK, CORN_SHOOTER, PUMPKIN_BOMB, POTATO_CANNON, SHURIKENS, P
## A corn shot left the gun (for its sound).
signal fired
## A pitchfork stab (how many it hit), and each enemy it struck (for the sounds).
## A pitchfork stab (how many it hit), a Propane Torch tick (how many it burned), and each enemy
## either struck (for the sounds).
signal stabbed(hits: int)
signal burned(hits: int)
signal struck(at: Vector3, enemy_type: int)
## A pumpkin bomb thrown (where it will land).
signal threw(at: Vector3)
@ -82,7 +89,12 @@ const OFFHAND_WEAPONS: Array[int] = [Weapon.PUMPKIN_BOMB]
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2"]
## Main weapons that fire from the muzzle (SIDE_OFFSET/muzzle_distance), so aiming at a target
## needs the same muzzle correction as the corn shooter's (attack_toward, the mouse in _update_aim).
const MUZZLE_WEAPONS: Array[int] = [Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS, Weapon.ALIEN_RAY]
## The Propane Torch's band runs along the gun's line too (#17).
const MUZZLE_WEAPONS: Array[int] = [Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS, Weapon.PROPANE_TORCH,
Weapon.ALIEN_RAY]
## A held weapon's effect stays lit this many of its tick intervals after its last tick, so it
## burns steadily while fire is held (on the partner's machine too, lit by the attack events).
const HOLD_TICKS := 1.5
## How far ahead a bomb lands when aiming with the stick, and how high it leaves the hand.
const GAMEPAD_THROW := 7.0
const THROW_HEIGHT := 1.6
@ -147,6 +159,8 @@ func setup(cfg: GameConfig, player: PlayerCharacter, camera: Camera3D, shots: Fa
_ray.exclude = [player.get_rid()]
models = WeaponModels.new()
models.setup(player.model, Vector3(SIDE_OFFSET, cfg.combat_height, -cfg.muzzle_distance))
models.add_held_effect(Weapon.PROPANE_TORCH, TorchFlame.new(cfg.torch_range, cfg.torch_width),
cfg.torch_tick_interval * HOLD_TICKS, TorchFlame.LIFETIME)
_build_marker()
@ -233,6 +247,7 @@ func _input(event: InputEvent) -> void:
## mode, no menu open; the partner's pick comes from its game).
func tick(dt: float, can_switch: bool) -> void:
_ticks += 1
models.advance(dt)
bomb_left = maxf(bomb_left - dt, 0.0)
models.set_bomb_charge(1.0 - bomb_left / _cfg.bomb_cooldown if _cfg.bomb_cooldown > 0.0 else 1.0)
if not owns(weapon):
@ -271,6 +286,8 @@ func step(_dt: float) -> void:
if _ticks - _stepped > 1:
_offhand_needs_release = true # couldn't attack last tick (a menu, the partner's build mode)
_stepped = _ticks
if not held:
models.douse() # the torch's flame goes out as soon as fire is let go
if replica:
if held:
_player.face_aim(aim, 0.35)
@ -469,22 +486,21 @@ func _throw_shurikens() -> void:
threw.emit(muzzle)
## The Propane Torch: a sustained cone, like the pitchfork's but its own reach/arc/targets/damage,
## applied every torch_tick_interval s while held (DoT: it stops the moment fire is released).
## The Propane Torch: a band of fire (_band_hit), applied every torch_tick_interval s while held
## (DoT: it stops the moment fire is released), and its flame lit (WeaponModels' held effect).
func _torch_tick() -> int:
torch_ticks += 1
models.attack(Weapon.PROPANE_TORCH)
var hits := _cone_hit(_cfg.torch_range, _cfg.torch_arc, _cfg.torch_targets, _cfg.torch_damage)
stabbed.emit(hits)
var hits := _band_hit(_cfg.torch_range, _cfg.torch_width, _cfg.torch_targets, _cfg.torch_damage)
burned.emit(hits)
return hits
## The nearest few enemies within reach of the aim, in arc, and in the clear take damage (the
## pitchfork's stab and the Propane Torch's tick share this).
## pitchfork's stab).
func _cone_hit(reach: float, arc_deg: float, max_targets: int, damage: int) -> int:
var hits := 0
if enemies == null:
return hits
return 0
var es := enemies
var p := Vector2(_player.global_position.x, _player.global_position.z)
var cos_half := cos(deg_to_rad(arc_deg) * 0.5)
@ -500,6 +516,41 @@ func _cone_hit(reach: float, arc_deg: float, max_targets: int, damage: int) -> i
continue
if _clear_line(p, e):
found.append([dist, d])
return _hit_nearest(found, max_targets, damage)
## The nearest few enemies in a band along the gun's line and in the clear take damage (the
## Propane Torch's tick). The band is width m wide, centered on the line from the muzzle along
## the aim, and runs from the scarecrow's center out to length m past the muzzle; each enemy's hit
## radius widens it and lengthens its far end. It starts at the scarecrow rather than the muzzle
## because an enemy hitting the scarecrow stands closer than the muzzle (melee reach
## enemy_radius + SCARECROW_RADIUS + enemy_attack_reach is under muzzle_distance) and must burn.
func _band_hit(length: float, width: float, max_targets: int, damage: int) -> int:
if enemies == null:
return 0
var es := enemies
var p := Vector2(_player.global_position.x, _player.global_position.z)
var right := Vector2(-aim.y, aim.x)
var muzzle := p + aim * _cfg.muzzle_distance + right * SIDE_OFFSET
var found: Array = [] # [distance along the band, slot]
for d in es.active_count:
if es.alive[d] == 0:
continue
var e := Vector2(es.pos_x[d], es.pos_z[d])
var r := es.t_hit_radius[es.type[d]]
var along := (e - muzzle).dot(aim)
if along < -_cfg.muzzle_distance or along > length + r or absf((e - muzzle).dot(right)) > width * 0.5 + r:
continue
if _clear_line(p, e):
found.append([along, d])
return _hit_nearest(found, max_targets, damage)
## Damages the first max_targets of found ([distance, slot] pairs), nearest first. Returns how many
## it hit.
func _hit_nearest(found: Array, max_targets: int, damage: int) -> int:
var hits := 0
var es := enemies
found.sort_custom(func(a: Array, b: Array) -> bool: return a[0] < b[0])
for k in mini(found.size(), max_targets):
var d: int = found[k][1]

138
game/scripts/torch_flame.gd Normal file
View file

@ -0,0 +1,138 @@
class_name TorchFlame
extends Node3D
## The Propane Torch's flame (#17): a jet of fire particles from the gun's muzzle, sized to the
## band ScarecrowCombat burns (length m past the muzzle, width m across), and a flickering orange
## light. A WeaponModels held effect: it sits at the muzzle facing the way the scarecrow's model
## does (-Z), so it follows the model's yaw, which is all the partner's machine knows of the
## other scarecrow's aim. set_lit() starts and stops the jet; the fire already out keeps flying
## for LIFETIME s after, so the effect fades rather than vanishing.
## Seconds a puff of fire flies: it covers the band's length in that time.
const LIFETIME := 0.35
const PUFFS := 72
## The jet dips this far below level over its length (radians), so the fire washes over the
## enemies in the band rather than flying over their heads from the gun's height.
const DIP := 0.17
## Fire is brighter than white (HDR, which the filmic tonemap rolls off), so it still burns
## through the night look's dimmed, desaturated picture (DayNight's adjustments).
const BRIGHTNESS := 1.4
const LIGHT_ENERGY := 2.4
const LIGHT_COLOR := Color(1.0, 0.55, 0.2)
## The band it was built for (m).
var length: float
var width: float
var lit := false
var _jet: CPUParticles3D
var _light: OmniLight3D
## The light's flicker draws from its own generator, leaving the global one's sequence alone.
var _flicker := RandomNumberGenerator.new()
func _init(p_length: float = 4.5, p_width: float = 1.6) -> void:
length = p_length
width = p_width
name = "TorchFlame"
_jet = _build_jet()
add_child(_jet)
_light = OmniLight3D.new()
_light.name = "Glow"
_light.light_color = LIGHT_COLOR
_light.light_energy = LIGHT_ENERGY
_light.omni_range = length
_light.shadow_enabled = false
_light.position = Vector3(0.0, -0.2, -length * 0.35)
add_child(_light)
set_lit(false)
## Starts the jet (and its light), or stops it: the puffs in the air fly on and fade.
func set_lit(on: bool) -> void:
lit = on
_jet.emitting = on
_light.visible = on
## The jet's direction (unit, world space): forward from the muzzle, dipping.
func direction() -> Vector3:
return (global_basis * _jet.direction).normalized()
func _process(_delta: float) -> void:
if lit:
_light.light_energy = LIGHT_ENERGY * _flicker.randf_range(0.75, 1.15)
func _build_jet() -> CPUParticles3D:
var p := CPUParticles3D.new()
p.name = "Jet"
p.amount = PUFFS
p.lifetime = LIFETIME
p.local_coords = false # puffs already out don't swing with the scarecrow
p.draw_order = CPUParticles3D.DRAW_ORDER_VIEW_DEPTH # blended back to front
p.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
p.emission_sphere_radius = 0.08
p.direction = Vector3(0.0, -sin(DIP), -cos(DIP))
# Wide enough to fill the band's width at its far end; flattened into a horizontal fan.
p.spread = rad_to_deg(atan2(width * 0.5, length)) * 0.8
p.flatness = 0.7
var speed := length / LIFETIME
p.initial_velocity_min = speed * 0.85
p.initial_velocity_max = speed * 1.08
p.gravity = Vector3(0.0, 1.5, 0.0) # flames rise a little
p.angle_min = -180.0
p.angle_max = 180.0
p.angular_velocity_min = -120.0
p.angular_velocity_max = 120.0
p.scale_amount_min = 0.8
p.scale_amount_max = 1.1
var grow := Curve.new()
grow.add_point(Vector2(0.0, 0.22))
grow.add_point(Vector2(0.45, 0.75))
grow.add_point(Vector2(1.0, 1.0))
p.scale_amount_curve = grow
var ramp := Gradient.new()
ramp.set_offset(0, 0.0)
ramp.set_color(0, Color(1.0, 0.8, 0.3, 0.95)) # yellow-hot at the nozzle
ramp.set_offset(1, 1.0)
ramp.set_color(1, Color(0.3, 0.08, 0.04, 0.0)) # smoke, gone
ramp.add_point(0.18, Color(1.0, 0.48, 0.06, 0.95))
ramp.add_point(0.55, Color(0.95, 0.22, 0.02, 0.85))
ramp.add_point(0.8, Color(0.55, 0.08, 0.02, 0.5))
p.color_ramp = ramp
p.hue_variation_min = -0.02
p.hue_variation_max = 0.03
var quad := QuadMesh.new()
quad.size = Vector2.ONE * width * 0.75
quad.material = _puff_material()
p.mesh = quad
p.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
return p
## A soft round puff, colored by the particle (vertex color) and always facing the camera. Plain
## alpha blending, unlit and unfogged, keeps it fire-colored on bright grass by day and through
## the night's fog (additive blending washed it out to white on the grass).
static func _puff_material() -> StandardMaterial3D:
var dot := Gradient.new()
dot.set_color(0, Color(1.0, 1.0, 1.0, 1.0))
dot.set_color(1, Color(1.0, 1.0, 1.0, 0.0))
dot.add_point(0.45, Color(1.0, 1.0, 1.0, 0.6))
var tex := GradientTexture2D.new()
tex.gradient = dot
tex.fill = GradientTexture2D.FILL_RADIAL
tex.fill_from = Vector2(0.5, 0.5)
tex.fill_to = Vector2(1.0, 0.5)
tex.width = 64
tex.height = 64
var mat := StandardMaterial3D.new()
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
mat.disable_fog = true
mat.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
mat.billboard_keep_scale = true
mat.vertex_color_use_as_albedo = true
mat.albedo_color = Color(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS)
mat.albedo_texture = tex
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
return mat

View file

@ -0,0 +1 @@
uid://kiux8igtayou

View file

@ -10,11 +10,20 @@ extends Node3D
## pumpkin bomb in the left hand (the off-hand); after a throw the next one grows back in the
## hand over the recharge (set_bomb_charge)
## attack() plays the weapon's motion (the pumpkin just leaves the hand: the thrown one is
## PumpkinBombs').
## PumpkinBombs'), or lights a held weapon's effect (below).
## Task #7's Potato Cannon, Shurikens, Propane Torch, and Alien Ray have no models of their own
## yet (visuals stay out of scope): each is a placeholder pivot (_add_placeholder) at the corn
## shooter's gun spot, the corn shooter's mesh tinted a different color so they're still tellable
## apart in play; it still kicks back like a gun on each attack.
## apart in play; it kicks back like a gun on each attack, unless it's a held weapon.
## Held weapons (add_held_effect; the Propane Torch's TorchFlame, #17) attack every short tick
## while fire is held, so each attack lights their effect instead of replaying a motion. The
## effect sits at the muzzle facing the model's way and stays lit for its hold s after each
## attack: lit while fire is held, out hold s after the last attack (or at once with douse(),
## when fire is let go). Then it fades for fade s (shown, no longer lit) before it's hidden. The
## timers run on the simulation's clock, advance() from ScarecrowCombat.tick() (hand-stepped tests
## drive it too), or on the physics frames when nothing advances them: in co-op, the other
## scarecrow on the partner's farm is lit by its attack events and stepped by nothing there (and
## after a Game Over nothing ticks).
const PATHS: Array[String] = ["res://assets/weapons/PitchFork.glb", "res://assets/weapons/CornShooter.glb",
"res://assets/weapons/PumpkinBomb.glb"]
@ -36,6 +45,14 @@ var _pivots: Array[Node3D] = []
var _rest: Array[Transform3D] = []
var _attack_t := -1.0
var _bomb_charge := 1.0
## The gameplay muzzle point on the model (setup), where held effects sit.
var _muzzle := Vector3.ZERO
## Held weapons' effects, by Weapon: {"node": a Node3D with set_lit(bool), "hold": s, "fade": s,
## "left": s still lit (> 0), fading (-fade .. 0), or out and hidden (<= -fade)}.
var _held := {}
## Physics frames since advance() was last called (above 1: nothing steps this scarecrow's
## weapons, so its held effects time out on the physics frames instead).
var _undriven: int = 0
## A model's mesh, re-centered (the scene's root node sits where it was in Blender).
@ -52,6 +69,7 @@ static func mesh_of(index: int) -> Mesh:
## gameplay muzzle point on the model (the corn shooter's tip goes there).
func setup(model: Node3D, muzzle: Vector3) -> void:
name = "Weapons"
_muzzle = muzzle
model.add_child(self)
# Pitchfork: tines (the mesh's +Y) forward and a little down, the shaft past the right hip.
_add(0, Transform3D(Basis.from_euler(Vector3(-1.75, 0.0, 0.0)), Vector3(0.32, 1.15, -0.95)))
@ -102,13 +120,17 @@ func _add_placeholder(index: int, rest: Transform3D, tint: Color) -> void:
_rest.append(rest)
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other.
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other (any other
## weapon's held effect goes out and is hidden at once).
func show_weapon(index: int) -> void:
weapon = index
_attack_t = -1.0
for i in ScarecrowCombat.MAIN_WEAPONS:
_pivots[i].visible = i == index
_pivots[i].transform = _rest[i]
for i: int in _held:
if i != index:
_set_held(i, -INF)
## Shows this off-hand weapon in the left hand (-1: none).
@ -118,12 +140,50 @@ func show_offhand(index: int) -> void:
_pivots[i].visible = i == index
## The main weapon's attack motion: a stab or a kick.
## The main weapon's attack motion: a stab or a kick. A held weapon lights its effect instead.
func attack(index: int) -> void:
if index == weapon:
if index != weapon:
return
if _held.has(index):
_set_held(index, float(_held[index]["hold"]))
else:
_attack_t = 0.0
## Adds a held weapon's effect (index: its ScarecrowCombat.Weapon): a Node3D with set_lit(on),
## placed at the muzzle facing the model's way (-Z), out until an attack lights it. hold: s it
## stays lit after each attack (longer than the weapon's tick, so it stays lit while fire is
## held). fade: s it stays shown once out (fire already in the air dying away).
func add_held_effect(index: int, effect: Node3D, hold: float, fade: float = 0.0) -> void:
effect.position = _muzzle
add_child(effect)
_held[index] = {"node": effect, "hold": hold, "fade": fade, "left": 0.0}
_set_held(index, -INF)
## A held weapon's effect (null: none).
func held_effect(index: int) -> Node3D:
return _held[index]["node"] if _held.has(index) else null
## Whether a held weapon's effect is lit: it attacked within its hold, and fire wasn't let go.
func lit(index: int) -> bool:
return _held.has(index) and float(_held[index]["left"]) > 0.0
## Fire let go: the held weapons' effects go out now (then fade as usual), not hold s later.
func douse() -> void:
for i: int in _held:
if float(_held[i]["left"]) > 0.0:
_set_held(i, 0.0)
## Runs the held effects' timers on the simulation's clock (ScarecrowCombat.tick()).
func advance(dt: float) -> void:
_undriven = 0
_advance_held(dt)
## Share of the pumpkin bomb's recharge done (1 = a pumpkin in the hand).
func set_bomb_charge(charge: float) -> void:
_bomb_charge = clampf(charge, 0.0, 1.0)
@ -137,6 +197,31 @@ func _apply_charge() -> void:
_pivots[2].get_child(0).visible = s > 0.05
func _advance_held(dt: float) -> void:
for i: int in _held:
var left := float(_held[i]["left"])
if left > -float(_held[i]["fade"]):
_set_held(i, left - dt)
## Sets a held effect's timer (s still lit; at or below 0 out, at or below -fade hidden) and shows
## it so.
func _set_held(index: int, left: float) -> void:
var h: Dictionary = _held[index]
var was_lit := float(h["left"]) > 0.0
h["left"] = left
var node := h["node"] as Node3D
if (left > 0.0) != was_lit or left == -INF:
node.call(&"set_lit", left > 0.0)
node.visible = left > -float(h["fade"])
func _physics_process(delta: float) -> void:
_undriven += 1
if _undriven > 1 and not _held.is_empty():
_advance_held(delta)
func _process(delta: float) -> void:
if _attack_t < 0.0 or _pivots.is_empty():
return

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

View file

@ -8,6 +8,8 @@ extends SceneTree
## truck_horn.wav beep-beep (the farmers are home)
## pitchfork_whoosh.wav a quick swish through the air (a stab)
## pumpkin_boom.wav a deep thump, a burst of noise, and a wet splat (a pumpkin bomb)
## torch_roar.wav a gas jet's flickering roar and hiss with a few crackles (a propane
## torch tick; back-to-back plays blend into one roar)
## Loops carry a WAV 'smpl' loop point, so the importer's "Detect From WAV" loops them; every
## periodic part of a loop has a whole number of cycles in it and filtered noise is warmed up
## on the loop's own tail, so the seam is silent. Run with the editor closed, then let the
@ -36,6 +38,8 @@ func _initialize() -> void:
_rng.seed = 13
_write("pitchfork_whoosh.wav", _whoosh(0.22), false)
_write("pumpkin_boom.wav", _boom(0.9), false)
_rng.seed = 17 # its own seed, so adding it changed none of the sounds above
_write("torch_roar.wav", _roar(0.42), false)
quit(0)
@ -247,6 +251,29 @@ func _boom(length: float) -> PackedFloat32Array:
return _normalize(buf, 0.85)
## A propane torch: a low roar of noise and a breathy hiss, flickering, with a few crackles. It
## swells in fast and dies away slowly, so plays one torch tick apart (shorter than it) overlap
## into one steady roar while the torch is held.
func _roar(length: float) -> PackedFloat32Array:
var n := int(length * RATE)
var roar := _noise_lowpass(n, 650.0)
var hiss := _noise_lowpass(n, 5200.0)
var hiss_low := _noise_lowpass(n, 1700.0)
var flicker := _noise_lowpass(n, 16.0)
var buf := PackedFloat32Array()
buf.resize(n)
for i in n:
var u := float(i) / n
var env := minf(u / 0.12, 1.0) * minf((1.0 - u) / 0.45, 1.0)
buf[i] = env * (0.75 + 0.25 * flicker[i]) * (roar[i] + 0.4 * (hiss[i] - hiss_low[i]))
for k in 7: # crackles: tiny sharp clicks
var at := _rng.randi_range(int(0.08 * n), int(0.75 * n))
var amp := _rng.randf_range(0.25, 0.55)
for j in int(0.005 * RATE):
buf[at + j] += amp * exp(-float(j) / (0.0012 * RATE)) * _rng.randf_range(-1.0, 1.0)
return _normalize(buf, 0.7)
func _horn() -> PackedFloat32Array:
var n := int(0.9 * RATE)
var buf := PackedFloat32Array()