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:
parent
3cf4603475
commit
b7743789c8
25 changed files with 1092 additions and 432 deletions
|
|
@ -1,14 +1,16 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using CultMath;
|
||||
using CultMath.UnityBridge;
|
||||
using static CultMath.math;
|
||||
using Random = UnityEngine.Random;
|
||||
using static Noise1D;
|
||||
using float3 = CultMath.float3;
|
||||
|
||||
// Cut 3 (docs/fire-control-cut.md): the raycast, shield branch and SendHit are deleted -- FireControl already
|
||||
// decided this shot's fate before this object was ever spawned (R8). The homing/guidance flight (the whole
|
||||
// point of this presentation) is untouched; children spawned on split carry no damage of their own to apply
|
||||
// either, since they never did anything but inherit their parent's now-deleted fields.
|
||||
public class GuidedProjectile : MonoBehaviour
|
||||
{
|
||||
public Prototype HitEffect;
|
||||
|
|
@ -27,22 +29,20 @@ public class GuidedProjectile : MonoBehaviour
|
|||
public float TopSpeed;
|
||||
public Transform Source;
|
||||
public Func<Vector3> TargetPosition;
|
||||
|
||||
|
||||
private float _phase;
|
||||
private float _prevDist;
|
||||
private bool _active;
|
||||
private bool _alive;
|
||||
private Vector3 _targetVelocity;
|
||||
private Vector3 _previousTargetPosition;
|
||||
|
||||
|
||||
// Cut 3: FireControl.Fire's ShotId -- this missile's handle onto Zone.ShotCommitted/ShotResolved.
|
||||
public int ShotId { get; set; }
|
||||
public Transform Target { get; set; }
|
||||
public float3 StartPosition { get; set; }
|
||||
public float Range { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
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 event Action OnKill;
|
||||
|
|
@ -112,10 +112,6 @@ public class GuidedProjectile : MonoBehaviour
|
|||
var perpendicularRandom = randomDirection.x * right + randomDirection.y * up;
|
||||
child.Velocity = (normalize(lerp(perpendicularRandom, dir.ToCultMath(), SplitSeparationForwardness)) * length(Velocity.ToCultMath()) * SplitSeparationVelocity).ToUnity();
|
||||
child.Range = Range;
|
||||
child.Damage = Damage / Children;
|
||||
child.Penetration = Penetration;
|
||||
child.Spread = Spread;
|
||||
child.DamageType = DamageType;
|
||||
child.Source = Source;
|
||||
child.Target = Target;
|
||||
child.SourceEntity = SourceEntity;
|
||||
|
|
@ -149,53 +145,6 @@ public class GuidedProjectile : MonoBehaviour
|
|||
|
||||
if(_alive)
|
||||
{
|
||||
var ray = new Ray(t.position, Velocity);
|
||||
foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 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));
|
||||
}
|
||||
}
|
||||
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, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, transform.forward);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
}
|
||||
else// if (hit.transform.gameObject.layer == 1)
|
||||
{
|
||||
StartCoroutine(Kill());
|
||||
return;
|
||||
}
|
||||
|
||||
if (HitEffect != null)
|
||||
{
|
||||
var ht = HitEffect.Instantiate<Transform>();
|
||||
ht.SetParent(hit.collider.transform);
|
||||
ht.position = hit.point;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
t.position += Velocity * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,13 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
|
||||
public Subject<(Entity source, Transform target, GuidedProjectile missile)> OnFireGuided = new Subject<(Entity source, Transform target, GuidedProjectile missile)>();
|
||||
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
if(weapon.Data is LauncherData launcher)
|
||||
{
|
||||
if (target == null) return;
|
||||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.ShotId = shotId;
|
||||
p.Source = source.transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Target = target.transform;
|
||||
|
|
@ -26,11 +27,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.GuidanceCurve = launcher.GuidanceCurve.ToCurve();
|
||||
p.LiftCurve = launcher.LiftCurve.ToCurve();
|
||||
p.ThrustCurve = launcher.ThrustCurve.ToCurve();
|
||||
|
|
@ -42,17 +39,14 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
else if(weapon.Data is GuidedWeaponData guidance)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.ShotId = shotId;
|
||||
p.Source = source.transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Frequency = guidance.DodgeFrequency;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.StartPosition = (p.transform.position = barrel.position).ToCultMath();
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.GuidanceCurve = guidance.GuidanceCurve.ToCurve();
|
||||
p.LiftCurve = guidance.LiftCurve.ToCurve();
|
||||
p.ThrustCurve = guidance.ThrustCurve.ToCurve();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using UnityEngine;
|
|||
public class HitscanManager : InstantWeaponEffectManager
|
||||
{
|
||||
public Prototype Prototype;
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = Prototype.Instantiate<HitscanEffect>();
|
||||
p.SourceEntity = source.Entity;
|
||||
|
|
|
|||
|
|
@ -4,5 +4,8 @@ using UnityEngine;
|
|||
|
||||
public abstract class InstantWeaponEffectManager : MonoBehaviour
|
||||
{
|
||||
public abstract void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target);
|
||||
// Cut 3 (docs/fire-control-cut.md): shotId is FireControl.Fire's ShotId (docs/fire-control-cut.md, 0b
|
||||
// table) -- the presentation's handle onto Zone.ShotCommitted / ShotResolved for this specific shot.
|
||||
// Implementations apply nothing; they perform whatever the shot's outcome says once it resolves.
|
||||
public abstract void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId);
|
||||
}
|
||||
|
|
@ -1,22 +1,24 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static CultMath.math;
|
||||
|
||||
// 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 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; }
|
||||
|
||||
// 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};
|
||||
|
||||
|
|
@ -34,47 +36,12 @@ public class Laser : MonoBehaviour
|
|||
GetComponent<Prototype>().ReturnToPool();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
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 / Duration), 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);
|
||||
var endpoint = TargetTransform != null
|
||||
? TargetTransform.position
|
||||
: transform.position + transform.forward * Range;
|
||||
LineRenderer.SetPosition(1, endpoint);
|
||||
|
||||
LineRenderer.widthMultiplier = IntensityCurve.Evaluate(lerp);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ public class LaserManager : InstantWeaponEffectManager
|
|||
{
|
||||
public Prototype ProjectilePrototype;
|
||||
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Laser>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
|
|
@ -15,11 +15,9 @@ public class LaserManager : InstantWeaponEffectManager
|
|||
t.SetParent(barrel);
|
||||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
p.ShotId = shotId;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.TargetTransform = target != null ? target.transform : null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +1,30 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using CultMath;
|
||||
using static CultMath.math;
|
||||
using Random = UnityEngine.Random;
|
||||
using static CultMath.math;
|
||||
|
||||
// Cut 3 (docs/fire-control-cut.md): the SphereCast, shield branch and SendHit are deleted -- FireControl
|
||||
// already rolled and resolved this shot before Fire() below ever ran (a velocity-0 weapon like this one
|
||||
// commits and resolves in the same tick it fires). The endpoint capture stays as a visual: it now just tracks
|
||||
// the target's transform instead of a physics hit (R8).
|
||||
public class Lightning : MonoBehaviour
|
||||
{
|
||||
public LightningCompute LightningCompute;
|
||||
public float HitRadius;
|
||||
|
||||
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 EntityInstance Target { get; set; }
|
||||
public Transform Barrel { get; set; }
|
||||
|
||||
private bool _colliderHit;
|
||||
private Vector3 _colliderLocalPosition;
|
||||
private Transform _colliderTransform;
|
||||
// Cut 3: FireControl.Fire's ShotId. Unused by this simple endpoint-only presentation today, kept so a
|
||||
// future pass can draw to the exact rolled cell instead of the target's overall position.
|
||||
public int ShotId { get; set; }
|
||||
|
||||
private Vector3 _endpoint;
|
||||
|
||||
public void Fire()
|
||||
{
|
||||
_colliderHit = false;
|
||||
LightningCompute.OnLeaderComplete = null;
|
||||
LightningCompute.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)
|
||||
{
|
||||
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 SphereCastAll returns as a
|
||||
// separate entry 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)
|
||||
{
|
||||
if (shield.Entity == Source.Entity) continue;
|
||||
LightningCompute.OnLeaderComplete = () =>
|
||||
{
|
||||
shieldBehavior.TakeHit(DamageType, Damage);
|
||||
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;
|
||||
LightningCompute.OnLeaderComplete = () =>
|
||||
hull.SendHit(Damage, Penetration, Spread, DamageType, Source.Entity, hit.textureCoord, Barrel.forward);
|
||||
}
|
||||
|
||||
_colliderHit = true;
|
||||
_colliderLocalPosition = hit.collider.transform.InverseTransformPoint(hit.point);
|
||||
_colliderTransform = hit.collider.transform;
|
||||
LightningCompute.FixedEndpoint = true;
|
||||
break;
|
||||
}
|
||||
LightningCompute.OnPulseComplete = () =>
|
||||
LightningCompute.FixedEndpoint = Target != null;
|
||||
LightningCompute.OnPulseComplete = () =>
|
||||
GetComponent<Prototype>().ReturnToPool();
|
||||
LightningCompute.StartAnimation();
|
||||
_endpoint = Barrel.position + Barrel.forward * Range;
|
||||
|
|
@ -80,10 +34,7 @@ public class Lightning : MonoBehaviour
|
|||
{
|
||||
if (Barrel == null) return;
|
||||
|
||||
if (_colliderHit)
|
||||
{
|
||||
if (_colliderTransform) _endpoint = _colliderTransform.TransformPoint(_colliderLocalPosition);
|
||||
}
|
||||
if (Target != null) _endpoint = Target.transform.position;
|
||||
|
||||
LightningCompute.EndPosition = _endpoint;
|
||||
LightningCompute.StartPosition = Barrel.position;
|
||||
|
|
|
|||
|
|
@ -6,18 +6,15 @@ public class LightningGunManager : InstantWeaponEffectManager
|
|||
{
|
||||
public Prototype Prototype;
|
||||
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = Prototype.Instantiate<Lightning>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.ShotId = shotId;
|
||||
p.Barrel = barrel;
|
||||
p.Source = source;
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.Target = target;
|
||||
p.Fire();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class MineManager : InstantWeaponEffectManager
|
|||
public Prototype ProjectilePrototype;
|
||||
public bool InheritVelocity;
|
||||
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Mine>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
|
|
|
|||
|
|
@ -1,41 +1,32 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using CultMath;
|
||||
using static CultMath.math;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
using static CultMath.math;
|
||||
|
||||
// Cut 3 (docs/fire-control-cut.md): the raycast, shield branch and SendHit are deleted -- FireControl already
|
||||
// decided this shot's fate before this object was ever spawned (R8). What is left is pure flight-path
|
||||
// presentation: fly, and disappear at Range or ShotId's resolution, whichever comes first. Airburst
|
||||
// (AirburstDistance/AirburstRange) is Cut 4's -- untouched here.
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
public TrailRenderer Trail;
|
||||
public float Gravity;
|
||||
public float Drag = .1f;
|
||||
public Prototype HitEffect;
|
||||
|
||||
|
||||
public float AirburstDistance;
|
||||
public float AirburstRange;
|
||||
public float DirectHitDamageMultiplier = 1;
|
||||
|
||||
|
||||
private bool _alive;
|
||||
|
||||
|
||||
// Cut 3: FireControl.Fire's ShotId -- this projectile's handle onto Zone.ShotCommitted/ShotResolved.
|
||||
public int ShotId { get; set; }
|
||||
public Zone Zone { get; set; }
|
||||
|
||||
|
||||
public Vector3 StartPosition { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
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; }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_alive = true;
|
||||
|
|
@ -45,81 +36,18 @@ public class Projectile : MonoBehaviour
|
|||
void Update()
|
||||
{
|
||||
if (SourceEntity == null) return;
|
||||
|
||||
|
||||
if(_alive)
|
||||
{
|
||||
var t = transform;
|
||||
var position = t.position;
|
||||
Velocity -= Vector3.up * (Gravity * Time.deltaTime);
|
||||
Velocity *= max(0, 1 - Drag * Time.deltaTime);
|
||||
var forward = Velocity.normalized;
|
||||
t.forward = forward;
|
||||
var ray = new Ray(position, Velocity);
|
||||
foreach (var hit in Physics.RaycastAll(ray, Velocity.magnitude * Time.deltaTime, 1 | (1 << 17)))
|
||||
{
|
||||
var shield = hit.collider.GetComponent<ShieldManager>();
|
||||
var hull = hit.collider.GetComponent<HullCollider>();
|
||||
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
|
||||
// as a separate entry 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*DirectHitDamageMultiplier);
|
||||
shield.ShowHit(hit.point, sqrt(Damage * DirectHitDamageMultiplier));
|
||||
}
|
||||
}
|
||||
else 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*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit.textureCoord, forward);
|
||||
transform.position = hit.point;
|
||||
StartCoroutine(Kill());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(Kill());
|
||||
return;
|
||||
}
|
||||
|
||||
if (HitEffect != null)
|
||||
{
|
||||
var ht = HitEffect.Instantiate<Transform>();
|
||||
ht.SetParent(hit.collider.transform);
|
||||
ht.position = hit.point;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
t.forward = Velocity.normalized;
|
||||
|
||||
transform.position += Velocity * Time.deltaTime;
|
||||
var distanceTraveled = (transform.position - StartPosition).magnitude;
|
||||
if(distanceTraveled > Range)
|
||||
StartCoroutine(Kill());
|
||||
if (AirburstRange > 1 && distanceTraveled > AirburstDistance)
|
||||
{
|
||||
StartCoroutine(Kill());
|
||||
var ht = HitEffect.Instantiate<Transform>();
|
||||
ht.position = t.position;
|
||||
foreach (var collider in Physics.OverlapSphere(t.position, AirburstRange, 1))
|
||||
{
|
||||
var hull = collider.GetComponent<HullCollider>();
|
||||
if (hull)
|
||||
{
|
||||
hull.SendSplash(Damage, DamageType, SourceEntity, (collider.transform.position - t.position).normalized);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,27 +10,24 @@ public class ProjectileManager : InstantWeaponEffectManager
|
|||
public Prototype ProjectilePrototype;
|
||||
public bool InheritVelocity;
|
||||
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target)
|
||||
public override void Fire(InstantWeapon weapon, EquippedItem item, EntityInstance source, EntityInstance target, int shotId)
|
||||
{
|
||||
var p = ProjectilePrototype.Instantiate<Projectile>();
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var angle = weapon.Spread / 2;
|
||||
p.ShotId = shotId;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.Velocity = Quaternion.Euler(
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle)) *
|
||||
barrel.forward *
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle),
|
||||
Random.Range(-angle, angle)) *
|
||||
barrel.forward *
|
||||
weapon.Velocity;
|
||||
p.StartPosition = p.transform.position = barrel.position + p.Velocity * (Random.value * Time.deltaTime);
|
||||
if(InheritVelocity)
|
||||
p.Velocity += new Vector3(source.Entity.Velocity.x, 0, source.Entity.Velocity.y);
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
p.Spread = weapon.DamageSpread;
|
||||
p.DamageType = weapon.WeaponData.DamageType;
|
||||
p.Zone = source.Entity.Zone;
|
||||
p.AirburstDistance = target != null ? length(source.Entity.Position - target.Entity.Position) : (weapon.Range * .75f);
|
||||
p.Trail.Clear();
|
||||
|
|
|
|||
Loading…
Reference in a new issue