extends SceneTree ## Charge-reliability test. A fast bull (dash ≈ 66 m/s ≈ 1.1 m/frame) moves far enough per physics ## frame to tunnel clean through the matador's thin HitArea, so the Area's body_entered never fires ## — "my charge goes right through them." matador.gd now sweeps the bull's actual travel (prev → now) ## each frame and gores any matador on the path (_sweep_bull_gore), and a committed charge pierces the ## survival roll (mat_charge_pierce). This drives a tunnelling pass whose endpoints both sit OUTSIDE ## the gore radius — so only the swept test can catch it — and asserts: (a) the charge still connects, ## (b) a full-speed charge gores (kills) rather than being rolled off, and (c) a slow bump at the hit ## threshold still lets the matador roll clear. ## Run: godot --headless --script res://tests/matador_charge_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 bull := CharacterBody3D.new() bull.set_script(load("res://tests/_fake_bull.gd")) # exposes is_dashing()/is_rolling() bull.collision_layer = 2 bull.collision_mask = 0 bull.add_to_group(&"player") var cs := CollisionShape3D.new() var shape := CapsuleShape3D.new() shape.radius = 0.75 shape.height = 1.845 cs.shape = shape bull.add_child(cs) root.add_child(bull) return bull func _make_matador(_bull: CharacterBody3D) -> CharacterBody3D: var mat := (load("res://Matador.tscn") as PackedScene).instantiate() as CharacterBody3D root.add_child(mat) mat.global_position = Vector3.ZERO mat.set_physics_process(false) # we drive the swept gore ourselves, isolated from the AI await physics_frame mat.call("_acquire_bull") return mat # Sweep the bull straight across the matador at `speed`: seed the previous position at from_x (too # far to gore), then teleport to to_x so the prev → now segment passes through the matador at x=0. func _charge_pass(mat: CharacterBody3D, bull: CharacterBody3D, speed: float, from_x: float, to_x: float) -> void: bull.global_position = Vector3(from_x, 0.0, 0.0) bull.velocity = Vector3(speed, 0.0, 0.0) mat.call("_sweep_bull_gore") bull.global_position = Vector3(to_x, 0.0, 0.0) mat.call("_sweep_bull_gore") func _run() -> void: var dp := root.get_node("/root/DP") var gore_r: float = dp.f("mat_charge_gore_radius") var thr: float = dp.f("mat_hit_threshold") _ok(2.0 > gore_r, "test pass tunnels: endpoints (2 m) sit outside the gore radius (%.2f m)" % gore_r) # One shared bull — matadors acquire the sole node in the "player" group, so every scenario # sweeps the same body (a second bull would leave later matadors reading the wrong, stale one). var bull := _make_bull() # (a) A dash-speed pass that leaps clean over the HitArea must still connect. Force the roll so # the reaction is a clean, ragdoll-free state change proving detection. dp.call("set_value", "mat_charge_pierce", 0.0) dp.call("set_value", "mat_roll_chance", 1.0) var mat_a: CharacterBody3D = await _make_matador(bull) _charge_pass(mat_a, bull, 66.0, -2.0, 2.0) _ok(mat_a.call("ai_state_name") == "ROLL", "a dash that tunnels the HitArea still connects (matador reacts)") # (b) A full-speed charge pierces the survival roll and gores — even forced roll_chance can't save it. dp.call("set_value", "mat_charge_pierce", 1.0) dp.call("set_value", "mat_roll_chance", 1.0) var mat_b: CharacterBody3D = await _make_matador(bull) _charge_pass(mat_b, bull, 66.0, -2.0, 2.0) _ok(mat_b.call("ai_state_name") == "RAGDOLL", "a full-speed charge pierces the roll and gores the matador") # (c) The pierce only bites at speed: a slow bump at the hit threshold still lets them roll clear. var mat_c: CharacterBody3D = await _make_matador(bull) _charge_pass(mat_c, bull, thr, -2.0, 2.0) _ok(mat_c.call("ai_state_name") == "ROLL", "a slow bump at the threshold still rolls clear") # (d) Horns-first only: a fast pass with the matador BEHIND the bull's heading (it charges away, # 0.5 → 3, matador at 0) doesn't gore, even though the swept path passes within reach. dp.call("set_value", "mat_charge_pierce", 0.0) dp.call("set_value", "mat_roll_chance", 1.0) var mat_d: CharacterBody3D = await _make_matador(bull) _charge_pass(mat_d, bull, 66.0, 0.5, 3.0) _ok(mat_d.call("ai_state_name") == "WANDER", "a charge moving away from the matador doesn't gore (horns-first)") # (e) The DASH ability is a committed lunge: even the not-horns-first pass connects (is_dashing # bypasses the cone) AND is a guaranteed kill — roll_chance forced to 1.0 still RAGDOLLS, not rolls. dp.call("set_value", "mat_roll_chance", 1.0) dp.call("set_value", "mat_charge_pierce", 0.0) bull.set("dashing", true) var mat_e: CharacterBody3D = await _make_matador(bull) _charge_pass(mat_e, bull, 66.0, 0.5, 3.0) _ok(mat_e.call("ai_state_name") == "RAGDOLL", "a dash connect is a guaranteed kill (no survival roll)") bull.set("dashing", false) _finish() func _finish() -> void: print("Results: %d passed, %d failed" % [_pass, _fail]) quit(1 if _fail > 0 else 0)