Fire control Cut 4, part 2: the last five weapon kinds join FireControl

Deletes the last live Physics.* hit queries and every remaining SendHit/
SendSplash call in Assets/Scripts/Gameplay/Weapons: ConstantLaser's
RaycastAll, ConstantLightning's SphereCastAll, ConstantParticleWeapon's
trigger-collider plumbing, HitscanEffect's RaycastAll, and Mine's blast
OverlapSphere. Each becomes presentation only, the same convention Cut 3
gave Projectile/GuidedProjectile/Laser/Lightning: ConstantLaser/
ConstantLightning/HitscanEffect draw to TargetTransform (or out to Range with
no target); ConstantParticleWeapon keeps only its visual emission.
ConstantWeapon.Execute (previous commit) already rolled the damage before any
of these ever draw.

Mine keeps its proximity-arming OverlapSphere (Q7: contact detection, not hit
detection) but Explode() now calls FireControl.Splash instead of walking
colliders and calling SendSplash itself.

HullCollider.Hit/Splash/SendHit/SendSplash and their event-arg classes are
deleted outright -- their last callers are gone. HullCollider is now purely a
physics surface for ship-on-ship collision impulse; no Physics.* query
decides damage anywhere in Assets/Scripts/Gameplay/Weapons except Mine's own
named exception.

Every manager (ConstantLaserManager, ConstantLightningManager,
ConstantParticleWeaponManager, HitscanManager) is updated to match: no more
Damage/Penetration/Spread/DamageType plumbing into a presentation component
that no longer decides anything with it, and HitscanManager now passes
ShotId and TargetTransform the way LaserManager already does.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-19 15:17:17 +02:00
commit 78a4cf36bf
10 changed files with 71 additions and 273 deletions

View file

@ -1,79 +1,17 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using UnityEngine;
using float2 = CultMath.float2;
using CultMath.UnityBridge;
// Cut 3 (docs/fire-control-cut.md) FORK, reported rather than worked around silently: the map's Cut 3 deletion
// list calls for Hit, Splash, SendHit and SendSplash to go away here outright. They cannot, yet, without
// breaking the build -- ConstantLaser.cs, ConstantLightning.cs, ConstantParticleWeapon.cs, HitscanEffect.cs
// and Mine.cs (Cut 4's "unused kinds," R9) still call hull.SendHit/SendSplash from their own live Physics
// queries, and Cut 4 is the cut that migrates them. Deleting these methods now is a compile break in
// out-of-scope files, not a behaviour change in this cut's own scope.
//
// What Cut 3 actually owns and has delivered: nothing in Assets/Scripts/Gameplay/Weapons/{Projectile,
// GuidedProjectile,Laser,Lightning}.cs calls SendHit/SendSplash any more (see those files), and
// EntityInstance.cs no longer subscribes to Hit/Splash at all -- so for the four weapon kinds this cut owns,
// these events have no subscriber and decide nothing. They fire into the void until Cut 4 deletes them
// together with their last remaining callers. OnCollisionEnter stays regardless: ship-on-ship collision
// impulse is a deferred Unity-physics surface, not part of fire control.
// Cut 4 (docs/fire-control-cut.md): Hit, Splash, SendHit and SendSplash are deleted -- their last callers
// (ConstantLaser, ConstantLightning, ConstantParticleWeapon, HitscanEffect, Mine) are gone too (see those
// files and FireControl.Splash). Nothing decides or applies damage through a Unity collider any more (R8):
// this component is now purely a physics surface for ship-on-ship collision impulse and Mine's own proximity
// arming query (Q7), neither of which is hit detection.
public class HullCollider : MonoBehaviour
{
public Subject<HullHitEventArgs> Hit = new Subject<HullHitEventArgs>();
public Subject<HullSplashEventArgs> Splash = new Subject<HullSplashEventArgs>();
public Entity Entity { get; set; }
public void SendHit(float damage, float penetration, float spread, DamageType damageType, Entity source, Vector2 texCoord, Vector3 direction)
{
Hit.OnNext(new HullHitEventArgs
{
Damage = damage,
Penetration = penetration,
Spread = spread,
DamageType = damageType,
Source = source,
TexCoord = texCoord.ToCultMath(),
Direction = direction.ToCultMath()
});
}
public void SendSplash(float damage, DamageType damageType, Entity source, Vector3 direction)
{
Splash.OnNext(new HullSplashEventArgs
{
Damage = damage,
DamageType = damageType,
Source = source,
Direction = direction.ToCultMath()
});
}
private void OnCollisionEnter(Collision other)
{
Entity.Velocity += other.impulse.ToCultMath().xz / Time.deltaTime;
}
public class HullHitEventArgs
{
public float Damage;
public float Penetration;
public float Spread;
public DamageType DamageType;
public Entity Source;
public float2 TexCoord;
public float3 Direction;
}
public class HullSplashEventArgs
{
public float Damage;
public DamageType DamageType;
public Entity Source;
public float3 Direction;
}
}

View file

@ -1,8 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CultMath.math;
// Cut 4 (docs/fire-control-cut.md): the raycast, shield branch and SendHit are deleted -- FireControl already
// rolls this weapon's damage once per GameplaySettings.BeamResolveInterval (ConstantWeapon.Execute) before
// this beam is ever drawn (R8). What is left is pure endpoint presentation, the same convention Laser.cs
// (Cut 3) uses for a discrete shot: draw to the target's current position, or out to Range with no target.
public class ConstantLaser : MonoBehaviour
{
public AnimationCurve StartCurve;
@ -13,13 +16,10 @@ public class ConstantLaser : MonoBehaviour
public float FadeDuration;
public float CycleDuration;
public LineRenderer LineRenderer;
public float Damage { get; set; }
public float Penetration { get; set; }
public float Spread { get; set; }
public DamageType DamageType { get; set; }
public Entity SourceEntity { get; set; }
public float Range { get; set; }
public Transform TargetTransform { get; set; }
private float _intensity;
private float _stopIntensity;
@ -70,45 +70,9 @@ public class ConstantLaser : MonoBehaviour
}
LineRenderer.SetPosition(0, transform.position);
bool hitFound = false;
foreach (var hit in Physics.RaycastAll(new Ray(transform.position, transform.forward), Range, 1 | (1 << 17)))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
{
var shieldBehavior = shield.Entity.Shield;
var shieldActive = shieldBehavior != null && shieldBehavior.Item.Active.Value;
var shieldAbsorbs = shieldActive && shieldBehavior.CanTakeHit(DamageType, Damage);
// F5 (docs/stats-and-power-cut.md, Soul pass 2026-09-19): CanTakeHit is a pure query now -- read
// once into shieldAbsorbs, and break the shield exactly once, right here, at the point this hit
// is actually decided to route past it (to the hull collider RaycastAll returns further down
// this same loop) instead of being absorbed. The hull branch below re-queries CanTakeHit safely
// -- it is side-effect-free -- and will see Broken already true.
if (shieldActive && !shieldAbsorbs) shieldBehavior.Break();
if (!shieldAbsorbs) continue;
if (shield.Entity != SourceEntity)
{
shieldBehavior.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
LineRenderer.SetPosition(1, hit.point);
hitFound = true;
break;
}
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
LineRenderer.SetPosition(1, hit.point);
hitFound = true;
break;
}
}
}
if(!hitFound)
LineRenderer.SetPosition(1, transform.position + transform.forward * Range);
LineRenderer.SetPosition(1, TargetTransform != null
? TargetTransform.position
: transform.position + transform.forward * Range);
}
public void Stop()

View file

@ -19,10 +19,9 @@ public class ConstantLaserManager : ConstantWeaponEffectManager
t.SetParent(barrel);
t.forward = barrel.forward;
t.position = barrel.position;
p.Damage = item.Evaluate(data.Damage);
p.Penetration = item.Evaluate(data.Penetration);
p.Spread = item.Evaluate(data.DamageSpread);
p.DamageType = data.DamageType;
// Cut 4 (docs/fire-control-cut.md): FireControl already rolls this weapon's damage; the presentation
// only needs to know where to draw the beam.
p.TargetTransform = target != null ? target.transform : null;
_lasers.Add(item, p);
}

View file

@ -1,8 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CultMath.math;
// Cut 4 (docs/fire-control-cut.md): the SphereCast, shield branch and SendHit are deleted -- FireControl
// already rolls this weapon's damage once per GameplaySettings.BeamResolveInterval (ConstantWeapon.Execute)
// before this bolt is ever drawn (R8). What is left is pure endpoint presentation: fixed to the target's
// current position when there is one, out to Range otherwise -- the same convention Lightning.cs (Cut 3)
// uses for a discrete shot.
public class ConstantLightning : MonoBehaviour
{
public LightningCompute Lightning;
@ -11,14 +15,11 @@ public class ConstantLightning : MonoBehaviour
public float StartWidth = 1;
public float EndWidth = 1;
public float FadeDuration;
public Transform Barrel { get; set; }
public float Damage { get; set; }
public float Penetration { get; set; }
public float Spread { get; set; }
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public float Range { get; set; }
public Transform TargetTransform { get; set; }
private bool _stopping;
private float _startTime;
@ -50,31 +51,10 @@ public class ConstantLightning : MonoBehaviour
Lightning.EndWidth = EndWidth;
}
Lightning.FixedEndpoint = false;
var hits = Physics.SphereCastAll(Barrel.position, HitRadius, Barrel.forward, Range, 1 | (1 << 17));
foreach (var hit in hits)
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield && (shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (shield.Entity == Source.Entity) continue;
shield.Entity.Shield.TakeHit(DamageType, Damage * Time.deltaTime);
shield.ShowHit(hit.point, sqrt(Damage));
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
if (hull.Entity == Source.Entity) continue;
hull.SendHit(Damage * Time.deltaTime, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
}
Lightning.FixedEndpoint = true;
Lightning.EndPosition = hit.point;
break;
}
if(!Lightning.FixedEndpoint)
Lightning.EndPosition = Barrel.position + Barrel.forward * Range;
Lightning.FixedEndpoint = TargetTransform != null;
Lightning.EndPosition = TargetTransform != null
? TargetTransform.position
: Barrel.position + Barrel.forward * Range;
Lightning.StartPosition = Barrel.position;
}

View file

@ -16,11 +16,10 @@ public class ConstantLightningManager : ConstantWeaponEffectManager
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
var barrel = source.GetBarrel(hp);
p.Barrel = barrel;
p.Damage = item.Evaluate(data.Damage);
p.Range = item.Evaluate(data.Range);
p.Penetration = item.Evaluate(data.Penetration);
p.Spread = item.Evaluate(data.DamageSpread);
p.DamageType = data.DamageType;
// Cut 4 (docs/fire-control-cut.md): FireControl already rolls this weapon's damage; the presentation
// only needs to know where to draw the bolt.
p.TargetTransform = target != null ? target.transform : null;
_bolts.Add(item, p);
}

View file

@ -4,19 +4,19 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
// Cut 4 (docs/fire-control-cut.md): the trigger-collider plumbing and SendSplash are deleted -- FireControl
// already rolls this weapon's damage once per GameplaySettings.BeamResolveInterval (ConstantWeapon.Execute)
// before these particles ever collide with anything (R8). What is left is pure visual emission; nothing here
// decides or applies damage any more.
public class ConstantParticleWeapon : MonoBehaviour
{
public ParticleSystem[] Particles;
public float Damage { get; set; }
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public EntityInstance Target { get; set; }
private bool _stopping;
private float _emission;
private List<ParticleSystem.Particle> _collisionParticles = new List<ParticleSystem.Particle>();
private HullCollider _hull;
private void Start()
{
@ -38,18 +38,10 @@ public class ConstantParticleWeapon : MonoBehaviour
main.simulationSpace = ParticleSystemSimulationSpace.Custom;
main.customSimulationSpace = Source.LocalSpace;
}
var trigger = Particles[0].trigger;
while(trigger.colliderCount > 0)
trigger.RemoveCollider(0);
if (Target == null) return;
foreach (var collider in Target.HullColliders)
{
_hull = collider;
trigger.AddCollider(collider.GetComponent<Collider>());
}
}
private void Update()
@ -62,21 +54,6 @@ public class ConstantParticleWeapon : MonoBehaviour
}
}
private void OnParticleTrigger()
{
if (Target == null || !_hull) return;
_collisionParticles.Clear();
Particles[0].GetTriggerParticles(ParticleSystemTriggerEventType.Enter, _collisionParticles);
if(_collisionParticles.Count > 0)
{
_hull.SendSplash(
Damage * Time.deltaTime,
DamageType,
Source.Entity,
(transform.position - Target.transform.position).normalized);
}
}
public void Stop()
{
foreach(var p in Particles)

View file

@ -19,8 +19,7 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager
t.SetParent(barrel);
t.forward = barrel.forward;
t.position = barrel.position;
p.Damage = item.Evaluate(data.Damage);
p.DamageType = data.DamageType;
// Cut 4 (docs/fire-control-cut.md): FireControl already rolls this weapon's damage.
_weapons.Add(item, p);
p.Initialize();
}

View file

@ -1,8 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CultMath.math;
// Cut 4 (docs/fire-control-cut.md): the raycast, shield branch and SendHit are deleted -- FireControl already
// decided this shot's fate before Fire() was ever called (R8), the same as Laser/Lightning (Cut 3). What is
// left is pure endpoint presentation: draw to the target's current position when there is one, out to Range
// otherwise.
public class HitscanEffect : MonoBehaviour
{
public float Duration;
@ -10,71 +13,31 @@ public class HitscanEffect : MonoBehaviour
public LineRenderer Line;
public ParticleSystem LineEffect;
public Prototype HitEffect;
public Zone Zone { get; set; }
public float Damage { get; set; }
public float Penetration { get; set; }
public float Spread { get; set; }
public DamageType DamageType { get; set; }
// Cut 4: FireControl.Fire's ShotId -- unused by this endpoint-only presentation today, kept so a future
// pass can draw to the exact rolled cell instead of the target's overall position (Laser.ShotId).
public int ShotId { get; set; }
public Entity SourceEntity { get; set; }
public float Range { get; set; }
public Transform TargetTransform { get; set; }
private float _startTime;
private bool _active = false;
public void Fire()
{
_startTime = Time.time;
var hitFound = false;
var ray = new Ray(transform.position, transform.forward);
foreach (var hit in Physics.RaycastAll(ray, Range, 1 | (1 << 17)))
{
var shield = hit.collider.GetComponent<ShieldManager>();
if (shield)
{
if (!(shield.Entity.Shield != null && shield.Entity.Shield.Item.Active.Value && shield.Entity.Shield.CanTakeHit(DamageType, Damage))) continue;
if (shield.Entity != SourceEntity)
{
shield.Entity.Shield.TakeHit(DamageType, Damage);
shield.ShowHit(hit.point, sqrt(Damage));
hitFound = true;
}
}
var hull = hit.collider.GetComponent<HullCollider>();
if (hull)
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
hitFound = true;
}
}
if (hitFound && HitEffect != null)
{
var ht = HitEffect.Instantiate<Transform>();
ht.SetParent(hit.collider.transform);
ht.position = hit.point;
}
var length = (hit.point - transform.position).magnitude;
Line.SetPosition(1, Vector3.forward * length);
var emission = LineEffect.emission;
emission.rateOverTimeMultiplier = length;
var shape = LineEffect.shape;
shape.position = Vector3.forward * (length / 2);
shape.scale = Vector3.one * (length / 2);
}
if(!hitFound)
{
Line.SetPosition(1, Vector3.forward * Range);
var emission = LineEffect.emission;
emission.rateOverTimeMultiplier = Range;
var shape = LineEffect.shape;
shape.position = Vector3.forward * (Range / 2);
shape.scale = Vector3.one * (Range / 2);
}
var length = TargetTransform != null
? Vector3.Distance(transform.position, TargetTransform.position)
: Range;
Line.SetPosition(1, Vector3.forward * length);
var emission = LineEffect.emission;
emission.rateOverTimeMultiplier = length;
var shape = LineEffect.shape;
shape.position = Vector3.forward * (length / 2);
shape.scale = Vector3.one * (length / 2);
LineEffect.Play(true);
_active = true;
}

View file

@ -15,12 +15,9 @@ public class HitscanManager : InstantWeaponEffectManager
t.localPosition = Vector3.zero;
// t.position = barrel.position;
// t.forward = barrel.forward;
p.ShotId = shotId;
p.Range = weapon.Range;
p.Damage = weapon.Damage;
p.Penetration = weapon.Penetration;
p.Spread = weapon.DamageSpread;
p.DamageType = weapon.WeaponData.DamageType;
p.Zone = source.Entity.Zone;
p.TargetTransform = target != null ? target.transform : null;
p.Fire();
}
}

View file

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using CultMath;
using CultMath.UnityBridge;
using static CultMath.math;
using UnityEngine;
using Random = UnityEngine.Random;
@ -86,35 +87,16 @@ public class Mine : MonoBehaviour
_material.SetFloat("_Emission", _emission * EmissionCurve.Evaluate(_pulseLerp));
}
// Cut 4 (docs/fire-control-cut.md, Q7): the arming OverlapSphere above stays -- that is contact detection,
// not hit detection. Blast damage is not: it goes through the same FireControl.Splash every splash-shaped
// weapon uses now, over the zone's own planar entities, not a Unity collider query. Presentation (ShowHit)
// goes with the query it depended on -- nothing here decides who was hit any more, so nothing here can
// point a hit effect at them; a future pass can rebuild that off FireControl-published state if the mine
// ever ships (R9 keeps it regardless).
public void Explode()
{
var position = transform.position;
foreach (var collider in Physics.OverlapSphere(position, BlastRange, 1 | (1 << 17)))
{
var shield = collider.GetComponent<ShieldManager>();
if (shield)
{
var shieldBehavior = shield.Entity.Shield;
var shieldActive = shieldBehavior != null && shieldBehavior.Item.Active.Value;
var shieldAbsorbs = shieldActive && shieldBehavior.CanTakeHit(DamageType, Damage);
// F5 (docs/stats-and-power-cut.md, Soul pass 2026-09-19): CanTakeHit is a pure query now -- read
// once into shieldAbsorbs, and break the shield exactly once, right here, at the point this hit
// is actually decided to route past it (to the hull collider OverlapSphere returns as a
// separate entry in this same loop) instead of being absorbed. The hull branch below re-queries
// CanTakeHit safely -- it is side-effect-free -- and will see Broken already true.
if (shieldActive && !shieldAbsorbs) shieldBehavior.Break();
if (shieldAbsorbs)
{
shieldBehavior.TakeHit(DamageType, Damage);
shield.ShowHit(position, sqrt(Damage));
}
}
var hull = collider.GetComponent<HullCollider>();
if (hull && !(hull.Entity.Shield != null && hull.Entity.Shield.Item.Active.Value && hull.Entity.Shield.CanTakeHit(DamageType, Damage)))
{
hull.SendSplash(Damage, DamageType, Source.Entity, (collider.transform.position - position).normalized);
}
}
FireControl.Splash(Source.Entity.Zone, position.ToCultMath(), BlastRange, Damage, DamageType);
var ht = HitEffect.Instantiate<Transform>();
ht.position = position;