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>
This commit is contained in:
Meta Vens 2026-09-19 14:07:07 +02:00
commit b7743789c8
25 changed files with 1092 additions and 432 deletions

View file

@ -316,6 +316,85 @@ public abstract class Entity
? TargetItem.Value
: null;
// Cut 3 (docs/fire-control-cut.md): the damage rule moved verbatim from EntityInstance.cs's Unity
// HullCollider subscription (DamageSchematic) -- same arithmetic, same order, same thresholds. The only
// thing that changed is the owner: this entity's own schematic, armor and hull, not a Unity component
// reacting to a physics collision.
public void DamageSchematic(float damage, Shape hitShape)
{
var hullData = ItemManager.GetData(Hull) as HullData;
foreach (var v in hitShape.Coordinates)
hitShape[v] = hitShape[v] && hullData.Shape[v];
float hullDamage = 0;
var damagePerCell = damage / hitShape.Coordinates.Length;
foreach (var v in hitShape.Coordinates)
{
var d = damagePerCell;
// Subtract surface damage from armor, passing on the remainder to the item and then to the hull
var prev = Armor[v.x, v.y];
Armor[v.x, v.y] = max(prev - d, 0);
ArmorDamage.OnNext((v, d));
d = max(d - prev, 0);
if (d > 0.1f)
{
var item = GearOccupancy[v.x, v.y];
if (item != null)
{
prev = item.EquippableItem.Durability;
item.EquippableItem.Durability = max(prev - d, 0);
ItemDamage.OnNext((item, d));
d = max(d - prev, 0);
}
}
hullDamage += d;
}
if (hullDamage > .1f)
{
Hull.Durability -= hullDamage;
HullDamage.OnNext(hullDamage);
}
}
// Cut 3: the shape construction moved from EntityInstance.cs's Unity HullCollider subscription, with two
// changes forced by R7 (the simulation is 2D): the hit cell is the rolled Cell FireControl already chose,
// not a UV texture coordinate; and the penetration march rotates the firer-to-target direction into this
// entity's own frame with a planar rotation by -Direction, in place of transform.InverseTransformDirection
// -- no 3D transform anywhere in the march. `hitDirection` is the planar (x,z) firer-to-target unit vector.
public void ApplyHit(Entity source, int2 cell, float spread, float penetration, float damage, float2 hitDirection)
{
IncomingHit.OnNext(source);
var hullData = ItemManager.GetData(Hull) as HullData;
var hitShape = new Shape(hullData.Shape.Width, hullData.Shape.Height);
hitShape[cell] = true;
for (var i = 0; i < (int) floor(spread + .5f); i++)
hitShape = hitShape.Expand();
if (penetration > .5f)
{
var forward = normalize(Direction);
var right = float2(forward.y, -forward.x);
var penetrationVector = normalize(float2(dot(hitDirection, right), dot(hitDirection, forward)));
var penetrationPoint = (float2) cell + float2(.5f);
var penetrationDistance = 0f;
while (penetrationDistance < penetration && hullData.Shape[int2(penetrationPoint)])
{
penetrationDistance += .5f;
hitShape[int2(penetrationPoint)] = true;
penetrationPoint += penetrationVector * .5f;
}
}
DamageSchematic(damage, hitShape);
}
// Another entity's stance toward THIS one, as far as this entity can perceive it: unknown (null)
// until this entity detects them, mirroring the existing detection model (VisibleEntities, driven
// by EntityInfoGathered crossing TargetDetectionInfoThreshold). Detected but not yet hostility-rated