2026-10-09 20:19:23 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using UniRx;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2026-10-09 23:27:22 +02:00
|
|
|
|
// A ballistic round, drawn by DrawAhead.Round from what the simulation publishes and deciding nothing. The simulation
|
|
|
|
|
|
// owns the round's facts (the PendingShot copy taken at spawn, replaced by the sim's record at ShotCommitted, and the
|
|
|
|
|
|
// outcome it publishes), so this object stores no motion state of its own and computes no position, time, range or
|
|
|
|
|
|
// impact point: each frame it asks DrawAhead.Round where the round is at sim time plus the clock's Lead (the same
|
|
|
|
|
|
// draw-ahead ships use). The round ends on the sim's word: ShotResolved ends one that hit or burst, and
|
2026-10-09 22:35:46 +02:00
|
|
|
|
// DrawAhead.RoundOver ends one the sim published as a miss. The barrel is only where the round is first seen: its
|
2026-10-09 23:27:22 +02:00
|
|
|
|
// offset from the drawn line decays to zero over BlendTime sim seconds. The trail's fade after the end stays real time
|
2026-10-09 22:35:46 +02:00
|
|
|
|
// (pure presentation, ruling sim-speed-presentation).
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public class Projectile : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public TrailRenderer Trail;
|
|
|
|
|
|
public Prototype HitEffect;
|
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
|
|
|
|
|
2026-10-09 20:19:23 +02:00
|
|
|
|
// Sim seconds over which the barrel's offset from the sim line decays to nothing.
|
|
|
|
|
|
public float BlendTime = .1f;
|
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
|
|
|
|
|
2026-10-09 20:19:23 +02:00
|
|
|
|
private PendingShot _shot;
|
|
|
|
|
|
private Zone _zone;
|
2026-10-09 22:35:46 +02:00
|
|
|
|
private CultMath.float3 _barrel;
|
2026-10-09 23:27:22 +02:00
|
|
|
|
private ShotOutcome _known;
|
2026-10-09 20:19:23 +02:00
|
|
|
|
private bool _alive;
|
2026-10-09 22:35:46 +02:00
|
|
|
|
private CompositeDisposable _binding;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
2026-10-09 22:35:46 +02:00
|
|
|
|
// Takes the shot as the sim holds it, the zone whose sim time it is drawn at, and where the barrel is as this round is first seen.
|
2026-10-09 20:19:23 +02:00
|
|
|
|
public void Launch(Zone zone, PendingShot shot, Vector3 barrel)
|
2026-08-10 14:57:50 +01:00
|
|
|
|
{
|
2026-10-09 20:19:23 +02:00
|
|
|
|
_zone = zone;
|
|
|
|
|
|
_shot = shot;
|
2026-10-09 22:35:46 +02:00
|
|
|
|
_barrel = new CultMath.float3(barrel.x, barrel.y, barrel.z);
|
|
|
|
|
|
_known = null;
|
2026-10-09 20:19:23 +02:00
|
|
|
|
_binding?.Dispose();
|
2026-10-09 22:35:46 +02:00
|
|
|
|
_binding = new CompositeDisposable(
|
|
|
|
|
|
zone.ShotCommitted.Where(o => o.ShotId == shot.ShotId).Subscribe(Committed),
|
|
|
|
|
|
zone.ShotResolved.Where(o => o.ShotId == shot.ShotId).Subscribe(Resolve));
|
2026-08-10 14:57:50 +01:00
|
|
|
|
_alive = true;
|
2026-10-09 20:19:23 +02:00
|
|
|
|
transform.forward = new Vector3(shot.TravelDirection.x, 0, shot.TravelDirection.y);
|
2026-10-09 22:35:46 +02:00
|
|
|
|
Draw();
|
2026-10-09 20:19:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-09 22:35:46 +02:00
|
|
|
|
void Update()
|
2026-10-09 20:19:23 +02:00
|
|
|
|
{
|
2026-10-09 22:35:46 +02:00
|
|
|
|
if (_alive) Draw();
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-09 22:35:46 +02:00
|
|
|
|
private void Draw()
|
2026-08-10 14:57:50 +01:00
|
|
|
|
{
|
2026-10-09 23:27:22 +02:00
|
|
|
|
var lead = ActionGameManager.Clock.Lead;
|
|
|
|
|
|
transform.position = V(DrawAhead.Round(_shot, _known, _barrel, BlendTime, _zone.Time, lead));
|
|
|
|
|
|
if (DrawAhead.RoundOver(_shot, _known, _zone.Time, lead)) Finish();
|
2026-10-09 22:35:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The sim's commit: the record it holds now (a contact burst's arrival is shortened here) and what it decided.
|
|
|
|
|
|
private void Committed(ShotOutcome outcome)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_zone.TryGetShot(outcome.ShotId, out var record)) _shot = record;
|
2026-10-09 23:27:22 +02:00
|
|
|
|
_known = outcome;
|
2026-10-09 20:19:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-09 23:27:22 +02:00
|
|
|
|
// The simulation's verdict. A round that hit or burst is drawn at its end and stops; a miss keeps flying.
|
2026-10-09 20:19:23 +02:00
|
|
|
|
private void Resolve(ShotOutcome outcome)
|
|
|
|
|
|
{
|
2026-10-09 22:35:46 +02:00
|
|
|
|
if (!_alive) return;
|
2026-10-09 23:27:22 +02:00
|
|
|
|
_known = outcome;
|
2026-10-09 22:35:46 +02:00
|
|
|
|
if (outcome.Result == ShotResult.Miss) return;
|
2026-10-09 23:27:22 +02:00
|
|
|
|
Draw();
|
2026-10-09 20:19:23 +02:00
|
|
|
|
if (HitEffect != null) HitEffect.Instantiate<Transform>().position = transform.position;
|
|
|
|
|
|
Finish();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-09 22:35:46 +02:00
|
|
|
|
private static Vector3 V(CultMath.float3 p) => new Vector3(p.x, p.y, p.z);
|
|
|
|
|
|
|
2026-10-09 20:19:23 +02:00
|
|
|
|
private void Finish()
|
|
|
|
|
|
{
|
|
|
|
|
|
_alive = false;
|
|
|
|
|
|
_binding?.Dispose();
|
|
|
|
|
|
_binding = null;
|
|
|
|
|
|
StartCoroutine(Fade());
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-09 20:19:23 +02:00
|
|
|
|
void OnDisable()
|
2026-08-10 14:57:50 +01:00
|
|
|
|
{
|
|
|
|
|
|
_alive = false;
|
2026-10-09 20:19:23 +02:00
|
|
|
|
_binding?.Dispose();
|
|
|
|
|
|
_binding = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator Fade()
|
|
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var startTime = Time.time;
|
|
|
|
|
|
var lifetime = Trail.time;
|
|
|
|
|
|
while (Time.time - startTime < lifetime)
|
|
|
|
|
|
yield return null;
|
|
|
|
|
|
GetComponent<Prototype>().ReturnToPool();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|