Files
Bullosseum/tests/bear_ram_test.gd
T
richard 09d4a60f43 Reorganize into role-based folders and consolidate art
Move every script and scene into role-based directories (actors/, systems/, ui/,
levels/, props/) and all raw art under art/ (grouped by role, snake_case,
Extract-Textures GLBs), dropping Blender version-suffix noise. Filenames are
snake_case (PascalCase reserved for class_name) to avoid case-insensitive
filesystem aliasing on the web/macOS targets. Routes the bull's hits through the
typed DamageEvent pipeline and wires the bull's abilities to the Fx library.
Updates CLAUDE.md's folder-layout overview to match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CCyaJPTHCH9EDthpf4A5Sj
2026-09-08 14:56:22 +03:00

113 lines
4.5 KiB
GDScript

extends SceneTree
## Bear ram test. Running the bull HORNS-FIRST into the bear should wound it. The bear detects this by
## sweeping the bull's actual travel (prev → now) against its body each frame (bear._sweep_bull_ram),
## gated by speed (bear_hit_threshold), reach (bear_ram_reach) and a horns-first cone (bull_gore_arc),
## and edge-triggered so one charge = one wound. This drives passes against a frozen bear and asserts:
## a horns-first charge (even one that tunnels / starts close) wounds it once; a charge moving AWAY
## (bear behind the horns), a pass out of reach, and a too-slow nudge all leave it unharmed.
## Run: godot --headless --script res://tests/bear_ram_test.gd
var _pass := 0
var _fail := 0
func _init() -> void:
_run.call_deferred()
func _ok(c: bool, m: String) -> void:
if c:
_pass += 1
print(" PASS: ", m)
else:
_fail += 1
print(" FAIL: ", m)
func _make_bull() -> CharacterBody3D:
var b := CharacterBody3D.new()
b.set_script(load("res://tests/_fake_bull.gd")) # exposes is_dashing()/is_rolling()
b.collision_layer = 2
b.collision_mask = 0
b.add_to_group(&"player")
var cs := CollisionShape3D.new()
var shape := CapsuleShape3D.new()
shape.radius = 0.75
shape.height = 1.845
cs.shape = shape
b.add_child(cs)
root.add_child(b)
return b
# Sweep the bull from `from` to `to` at `speed` (velocity along the travel), reseting the bear's ram
# edge-state first so each pass is isolated. The prev → now segment is what the bear tests against.
func _ram_pass(bear: Node, bull: CharacterBody3D, speed: float, from: Vector3, to: Vector3) -> void:
bear.set("_bull_prev_seen", false)
bear.set("_bull_ramming", false)
var dir := to - from
dir.y = 0.0
bull.velocity = dir.normalized() * speed if dir.length() > 0.01 else Vector3.ZERO
bull.global_position = from
bear.call("_sweep_bull_ram")
bull.global_position = to
bear.call("_sweep_bull_ram")
func _run() -> void:
var bull := _make_bull()
var bear := (load("res://actors/bear/bear.tscn") as PackedScene).instantiate() as Node3D
root.add_child(bear)
bear.global_position = Vector3.ZERO
bear.set_physics_process(false) # freeze the AI; we drive the ram sweep ourselves
await physics_frame
bear.call("_acquire_bull")
var dp := root.get_node("/root/DP")
var reach: float = dp.f("bear_ram_reach")
var thr: float = dp.f("bear_hit_threshold")
_ok(bear.get("_bull") == bull, "bear acquired the bull")
# (a) Horns-first charge straight through the bear — endpoints (3 m) sit outside the reach, so
# only the swept test catches the pass-through.
var hp0: int = bear.get("_hp")
_ok(3.0 > reach, "test pass tunnels: endpoints (3 m) exceed the ram reach (%.2f m)" % reach)
_ram_pass(bear, bull, 66.0, Vector3(-3, 0, 0), Vector3(3, 0, 0))
_ok(bear.get("_hp") == hp0 - 1, "a horns-first charge wounds the bear once")
# (b) One charge = one wound: sweeping the same charge again without disengaging doesn't re-hit
# mid-contact (edge-triggered). Re-seed as if the bull never left the ram — no reset.
var hp1: int = bear.get("_hp")
bull.velocity = Vector3(66, 0, 0)
bull.global_position = Vector3(0.2, 0, 0) # still on top of the bear, still charging
bear.call("_sweep_bull_ram")
_ok(bear.get("_hp") == hp1, "a sustained charge doesn't drain the bear frame-by-frame")
# (c) Charging AWAY (bear behind the horns) is not a horns-first ram, even up close.
var hp2: int = bear.get("_hp")
_ram_pass(bear, bull, 66.0, Vector3(0.5, 0, 0), Vector3(4, 0, 0))
_ok(bear.get("_hp") == hp2, "a charge moving away from the bear leaves it unharmed")
# (d) A fast pass wide of the bear (out of reach) is spared.
_ram_pass(bear, bull, 66.0, Vector3(-3, 0, 3), Vector3(3, 0, 3))
_ok(bear.get("_hp") == hp2, "a charge that passes wide of the bear is spared")
# (e) A slow nudge below the hit threshold is shrugged off.
_ram_pass(bear, bull, thr - 1.0, Vector3(-3, 0, 0), Vector3(3, 0, 0))
_ok(bear.get("_hp") == hp2, "a nudge below the hit threshold doesn't wound the bear")
# (f) The DASH ability bypasses the horns-first cone: the same charge-away pass that (c) shrugged
# off DOES wound the bear while dashing (a committed lunge rams on contact).
var hp3: int = bear.get("_hp")
bull.set("dashing", true)
_ram_pass(bear, bull, 66.0, Vector3(0.5, 0, 0), Vector3(4, 0, 0))
_ok(bear.get("_hp") == hp3 - 1, "the dash ability rams the bear on contact even when not horns-first")
bull.set("dashing", false)
_finish()
func _finish() -> void:
print("Results: %d passed, %d failed" % [_pass, _fail])
quit(1 if _fail > 0 else 0)