Aetheria/Assets/Scripts/Gameplay/Weapons/Laser.cs
Meta Vens b7743789c8 Fire control Cut 3: hit authority moves to FireControl
Deletes the Unity physics hit path (HullCollider.Hit/Splash, and the
raycast/shield/SendHit blocks in Projectile, GuidedProjectile, Laser and
Lightning) and replaces it with a single owner in the same cut: FireControl
now decides whether a shot hits, Zone owns the pending-shot lifecycle, and
Entity.DamageSchematic/ApplyHit (moved verbatim from EntityInstance) apply the
result. Presentation subscribes to Zone.ShotCommitted/ShotResolved and applies
nothing.

FireControl.HitProbability is the pure targeting solution (Accuracy * pSensor
* pSpread, gated by detection/range/lock/arc). FireControl.Fire freezes the
weapon's payload and the shooter's resolved targeting stats at the instant the
trigger is pulled (Q6), computes the predicted intercept through the one
shared PredictedIntercept function (CombatState now calls the same function
instead of duplicating first_order_intercept), and queues a PendingShot.
FireControl.Step commits each shot's outcome at ArrivalTime - CommitHorizon --
deviation from the predicted intercept, measured once, live, at that instant
-- and applies it at ArrivalTime. A shot whose flight is shorter than the
horizon commits and resolves in the same tick it fires. Rolls draw from the
shooter's own ItemManager.Random (Q5, seeded and reproducible); an out-of-arc
or otherwise gated shot draws nothing.

Player fire is arc-gated through the same predicate AI and turret fire use
(Weapon.ArcAllowsFire, checked in InstantWeapon.Trigger -- the one point every
shooter's trigger passes through), closing Q2.

Adds GameplaySettings.CommitHorizon, SchematicCellSize and
AgentMinHitProbability (first guesses; the headless suite is the tuning
harness, operator play smoke is the arbiter).

FORK reported, not worked around silently: HullCollider.SendHit/SendSplash
cannot be deleted yet without breaking ConstantLaser.cs, ConstantLightning.cs,
ConstantParticleWeapon.cs, HitscanEffect.cs and Mine.cs, which still call them
from their own live Physics queries -- that's Cut 4's migration. They fire
into the void today: nothing subscribes to Hit/Splash any more for the four
weapon kinds this cut owns.

tests/Aetheria.Shared.Tests/FireAuthorityTests.cs pins the roll's seeding, the
gate-consumes-no-draw rule, resolve-on-arrival, the commit horizon and its
evasion window, short-flight degradation, the frozen-payload snapshot, aimed
hits, the item-then-hull damage order, the planar penetration march and the
shield-absorbs branch. FireControlTests.cs and InputCapacitorTests.cs are
updated for the new AI gate and OnFire(int) signature.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 14:07:07 +02:00

48 lines
1.7 KiB
C#

using UnityEngine;
// Cut 3 (docs/fire-control-cut.md): the raycast, shield branch and SendHit are deleted -- FireControl already
// rolled and, for a velocity-0 weapon like this one, already resolved this shot before the beam was ever
// drawn (a short flight commits and resolves in the same Zone.Update tick as Fire). The beam endpoint is
// presentation, rebuilt from the target's current position rather than a physics hit -- it no longer decides
// anything (R8).
public class Laser : MonoBehaviour
{
public AnimationCurve IntensityCurve;
public float Duration;
public LineRenderer LineRenderer;
public Entity SourceEntity { get; set; }
public float Range { get; set; }
// Cut 3: FireControl.Fire's ShotId. Unused by this simple endpoint-only presentation today, kept so a
// future pass can draw the beam to the exact rolled cell instead of the target's overall position.
public int ShotId { get; set; }
public Transform TargetTransform { get; set; }
private float _startTime;
private readonly Vector3[] _zeros = {Vector3.zero, Vector3.zero};
private void OnEnable()
{
_startTime = Time.time;
LineRenderer.SetPositions(_zeros);
}
private void Update()
{
var lerp = (Time.time - _startTime) / Duration;
if (lerp > 1)
{
GetComponent<Prototype>().ReturnToPool();
return;
}
LineRenderer.SetPosition(0, transform.position);
var endpoint = TargetTransform != null
? TargetTransform.position
: transform.position + transform.forward * Range;
LineRenderer.SetPosition(1, endpoint);
LineRenderer.widthMultiplier = IntensityCurve.Evaluate(lerp);
}
}