Mining Cut 3: a chunk is a target, detected by reflected light
- Entity.Target is one slot of TargetRef, read-only from outside (IReadOnlyReactiveProperty); Entity.SetTarget is its one writer. A chunk is taken only while the entity can see it, so a rock in darkness cannot be picked. Every handler, agent, turret and test writes through SetTarget. - Entity.ChunkInfo (Q14 A): the value the per-tick sensor rule settles at, computed on demand through Sensor.PassiveRate/Sensor.Gain -- sum of the active sensors' passive rates over (sensors x TargetInfoDecay), capped at 1. Stored nowhere; no per-tick loop over chunks. ChunkVisible is the detection threshold through the chunk path. - The lost-track rule reads through the chunk path: Activate's reconciliation and a per-tick check of the one slot drop a chunk target that has gone dark. - Entity.VisibleChunksInReach (Q13 A): visible chunks within the longest range among active weapons -- the one reach rule for cycling and programmatic picks. - Entity-only readers take .Entity: TargetedBy/TargetedByCount, target items, the stance gate (a chunk has no stance), lock (Q12 A: never on a chunk), turrets, Combat, Minion, FireControl (a chunk fires untargeted until Cut 4). TargetRange and the arc gate read a chunk's planar position. - ActionGameManager: the reticle and next/previous offer visible ships and visible chunks in reach; nearest stays enemies-only; the target panel, indicator and fire-control debug take TargetRef. EntityInstance reads .Entity. - MiningCut3Tests pin parity, darkness, monotone brightness, wear and break, reach, the chunk query, target survival and loss, TargetRef equality, lock, and field-kind assignment at generation and first load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d76756fd68
commit
15723f4037
29 changed files with 712 additions and 142 deletions
|
|
@ -362,19 +362,22 @@ public class ActionGameManager : MonoBehaviour
|
|||
// reads as non-hostile here, so the first press declares hostile.
|
||||
Input.Player.ToggleStance.performed += context =>
|
||||
{
|
||||
var target = CurrentEntity.Target.Value;
|
||||
var target = CurrentEntity.Target.Value.Entity;
|
||||
if (target == null) return;
|
||||
CurrentEntity.SetIff(target, !CurrentEntity.IsHostileTo(target));
|
||||
};
|
||||
|
||||
#region Targeting
|
||||
|
||||
// Mining Cut 3 (docs/mining-cut-refresh.md): the reticle and cycling offer visible ships and the visible
|
||||
// chunks within reach (Entity.VisibleChunksInReach, Q13), through the one writer, Entity.SetTarget.
|
||||
Input.Player.TargetReticle.performed += context =>
|
||||
{
|
||||
if (!CurrentEntity.VisibleEntities.Any()) return;
|
||||
var underReticle = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity)
|
||||
.MaxBy(x => dot(normalize(x.Position - CurrentEntity.Position), CurrentEntity.LookDirection));
|
||||
CurrentEntity.Target.Value = CurrentEntity.Target.Value == underReticle ? null : underReticle;
|
||||
var candidates = TargetCandidates();
|
||||
if (candidates.Length == 0) return;
|
||||
var underReticle = candidates
|
||||
.MaxBy(x => dot(normalize(x.position - CurrentEntity.Position), CurrentEntity.LookDirection)).target;
|
||||
CurrentEntity.SetTarget(CurrentEntity.Target.Value.Equals(underReticle) ? TargetRef.None : underReticle);
|
||||
};
|
||||
|
||||
// Nearest is enemies-only (it drives weapon lock), and picks the closest target, not the farthest.
|
||||
|
|
@ -382,33 +385,33 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
if(CurrentEntity.VisibleEnemies.Any())
|
||||
{
|
||||
CurrentEntity.Target.Value = CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity)
|
||||
.MinBy(x => length(x.Position - CurrentEntity.Position));
|
||||
CurrentEntity.SetTarget(CurrentEntity.VisibleEnemies.Where(x => x != CurrentEntity)
|
||||
.MinBy(x => length(x.Position - CurrentEntity.Position)));
|
||||
}
|
||||
};
|
||||
|
||||
Input.Player.TargetNext.performed += context =>
|
||||
{
|
||||
if (!CurrentEntity.VisibleEntities.Any()) return;
|
||||
var targets = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray();
|
||||
var targets = TargetCandidates().OrderBy(x => length(x.position - CurrentEntity.Position)).Select(x => x.target).ToArray();
|
||||
if (targets.Length == 0) return;
|
||||
var currentTargetIndex = Array.IndexOf(targets, CurrentEntity.Target.Value);
|
||||
CurrentEntity.Target.Value = targets[(currentTargetIndex + 1) % targets.Length];
|
||||
CurrentEntity.SetTarget(targets[(currentTargetIndex + 1) % targets.Length]);
|
||||
};
|
||||
|
||||
Input.Player.TargetPrevious.performed += context =>
|
||||
{
|
||||
if (!CurrentEntity.VisibleEntities.Any()) return;
|
||||
var targets = CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity).OrderBy(x => length(x.Position - CurrentEntity.Position)).ToArray();
|
||||
var targets = TargetCandidates().OrderBy(x => length(x.position - CurrentEntity.Position)).Select(x => x.target).ToArray();
|
||||
if (targets.Length == 0) return;
|
||||
var currentTargetIndex = Array.IndexOf(targets, CurrentEntity.Target.Value);
|
||||
CurrentEntity.Target.Value = targets[(currentTargetIndex + targets.Length - 1) % targets.Length];
|
||||
CurrentEntity.SetTarget(targets[(currentTargetIndex + targets.Length - 1) % targets.Length]);
|
||||
};
|
||||
|
||||
// Cut 2 (docs/fire-control-cut.md): cycles the aim point among the current target's revealed
|
||||
// subsystems -- decides nothing itself, only calls the one writer (TrySelectTargetItem), same
|
||||
// predicate (FireControl.IsRevealed) the AI path uses.
|
||||
// predicate (FireControl.IsRevealed) the AI path uses. Entity-only: a chunk has no subsystems.
|
||||
Input.Player.CycleTargetItem.performed += context =>
|
||||
{
|
||||
var target = CurrentEntity.Target.Value;
|
||||
var target = CurrentEntity.Target.Value.Entity;
|
||||
if (target == null) return;
|
||||
var revealed = target.Equipment.Where(x => FireControl.IsRevealed(CurrentEntity, x)).ToArray();
|
||||
if (revealed.Length == 0)
|
||||
|
|
@ -595,7 +598,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
ConsoleController.AddCommand("iff", args =>
|
||||
{
|
||||
var console = ConsoleController.Instance;
|
||||
var target = _currentEntity?.Target.Value;
|
||||
var target = _currentEntity?.Target.Value.Entity;
|
||||
if (target == null) { console.AppendLogLine("iff: no target selected"); return; }
|
||||
var mode = args.Length > 0 ? args[0] : "";
|
||||
if (mode != "hostile" && mode != "neutral" && mode != "clear")
|
||||
|
|
@ -1076,9 +1079,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
_targetSubscriptions.Clear();
|
||||
|
||||
UpdateTargetPanel(target);
|
||||
if (target != null)
|
||||
var targetEntity = target.Entity;
|
||||
if (targetEntity != null)
|
||||
{
|
||||
if (target.Shield != null)
|
||||
if (targetEntity.Shield != null)
|
||||
{
|
||||
TargetShieldsBackground.color = new Color(ShieldColor.r, ShieldColor.g, ShieldColor.b, .4f);
|
||||
TargetShieldsIcon.color = ShieldColor;
|
||||
|
|
@ -1092,7 +1096,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
|
||||
// Subscribe to incoming hits from the player ship to display the hit marker
|
||||
_targetSubscriptions.Add(target.IncomingHit.Where(e => e == CurrentEntity).Subscribe(_ =>
|
||||
_targetSubscriptions.Add(targetEntity.IncomingHit.Where(e => e == CurrentEntity).Subscribe(_ =>
|
||||
{
|
||||
HitMarker.SetActive(true);
|
||||
_hitMarkerTime = HitMarkerDuration;
|
||||
|
|
@ -1152,17 +1156,37 @@ public class ActionGameManager : MonoBehaviour
|
|||
SchematicDisplay.ShowShip(CurrentEntity);
|
||||
}
|
||||
|
||||
private void UpdateTargetPanel(Entity target)
|
||||
// Mining Cut 3: any target gets the indicator; only a ship target gets the ship panel.
|
||||
private void UpdateTargetPanel(TargetRef target)
|
||||
{
|
||||
TargetIndicator.gameObject.SetActive(target != null);
|
||||
TargetShipPanel.gameObject.SetActive(target != null);
|
||||
if (target != null)
|
||||
TargetIndicator.gameObject.SetActive(!target.IsNone);
|
||||
TargetShipPanel.gameObject.SetActive(target.Entity != null);
|
||||
if (target.Entity != null)
|
||||
{
|
||||
TargetShipPanel.Display(target, true);
|
||||
TargetSchematicDisplay.ShowShip(target, CurrentEntity);
|
||||
TargetShipPanel.Display(target.Entity, true);
|
||||
TargetSchematicDisplay.ShowShip(target.Entity, CurrentEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Mining Cut 3: what the reticle and cycling can pick -- visible ships, and visible chunks within reach -- each
|
||||
// with a world position to measure bearing and distance against.
|
||||
private readonly List<ChunkId> _chunksInReach = new List<ChunkId>();
|
||||
private (TargetRef target, float3 position)[] TargetCandidates()
|
||||
{
|
||||
CurrentEntity.VisibleChunksInReach(_chunksInReach);
|
||||
return CurrentEntity.VisibleEntities.Where(x => x != CurrentEntity)
|
||||
.Select(x => (target: (TargetRef) x, position: x.Position))
|
||||
.Concat(_chunksInReach.Select(chunk => (target: (TargetRef) chunk, position: ChunkWorldPosition(chunk))))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// A chunk's simulated position is planar (Zone.ChunkPose); the renderer draws it at the asteroid layer's height.
|
||||
private float3 ChunkWorldPosition(ChunkId chunk)
|
||||
{
|
||||
var pose = CurrentEntity.Zone.ChunkPose(chunk.Field, chunk.Index);
|
||||
return float3(pose.x, Settings.PlanetSettings.AsteroidVerticalOffset, pose.y);
|
||||
}
|
||||
|
||||
private void Die(CauseOfDeath cause)
|
||||
{
|
||||
var deathTime = Time.time;
|
||||
|
|
@ -1246,7 +1270,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
foreach (var indicator in _visibleHostileIndicators)
|
||||
{
|
||||
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value);
|
||||
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value.Entity);
|
||||
indicator.Value.Place.Target = indicator.Key.Position.ToUnity();
|
||||
if (!indicator.Key.Active)
|
||||
indicator.Value.Fill.enabled = false;
|
||||
|
|
@ -1261,7 +1285,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
foreach (var indicator in _visibleFriendlyIndicators)
|
||||
{
|
||||
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value);
|
||||
indicator.Value.gameObject.SetActive(indicator.Key!=CurrentEntity.Target.Value.Entity);
|
||||
indicator.Value.Place.Target = indicator.Key.Position.ToUnity();
|
||||
if (!indicator.Key.Active)
|
||||
indicator.Value.Fill.enabled = false;
|
||||
|
|
@ -1288,8 +1312,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
ship.MovementDirection = Input.Player.Move.ReadValue<Vector2>().ToCultMath();
|
||||
}
|
||||
|
||||
var target = CurrentEntity.Target.Value;
|
||||
UpdateFireControlDebug(target);
|
||||
UpdateFireControlDebug(CurrentEntity.Target.Value);
|
||||
var target = CurrentEntity.Target.Value.Entity;
|
||||
if (target != null)
|
||||
{
|
||||
var threshold = Settings.GameplaySettings.TargetDetectionInfoThreshold;
|
||||
|
|
@ -1314,7 +1338,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
_ => "MISS"
|
||||
};
|
||||
|
||||
private void UpdateFireControlDebug(Entity target)
|
||||
private void UpdateFireControlDebug(TargetRef target)
|
||||
{
|
||||
if (DebugInfoText == null) return;
|
||||
|
||||
|
|
@ -1335,7 +1359,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
return;
|
||||
}
|
||||
|
||||
var d = FireControl.Inspect(selectedWeapon, CurrentEntity, target);
|
||||
// Mining Cut 3: fire control prices ships; a chunk target reads as none there until Cut 4.
|
||||
var d = FireControl.Inspect(selectedWeapon, CurrentEntity, target.Entity);
|
||||
var pendingLine = "pending: none";
|
||||
for (var i = CurrentEntity.Zone.PendingShots.Count - 1; i >= 0; i--)
|
||||
{
|
||||
|
|
@ -1358,7 +1383,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
var lastLine = _debugLastShots.TryGetValue(selectedItem, out var lastShot)
|
||||
? $"last {lastShot.ShotId}: {ResultLabel(lastShot.Result)} cell {lastShot.Cell.x},{lastShot.Cell.y}"
|
||||
: "last: none";
|
||||
var gates = target == null
|
||||
var gates = target.Chunk.HasValue ? "target: chunk"
|
||||
: target.Entity == null
|
||||
? "target: none"
|
||||
: $"gates designated {d.Designated} arc {d.InArc}";
|
||||
|
||||
|
|
@ -1389,8 +1415,11 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (CurrentEntity == null || CurrentEntity.Parent != null) return;
|
||||
|
||||
ViewDot.Target = ZoneRenderer.EntityInstances[CurrentEntity].LookAtPoint.position;
|
||||
if (CurrentEntity.Target.Value != null)
|
||||
TargetIndicator.Target = CurrentEntity.Target.Value.Position.ToUnity();
|
||||
var target = CurrentEntity.Target.Value;
|
||||
if (target.Chunk is ChunkId chunk)
|
||||
TargetIndicator.Target = ChunkWorldPosition(chunk).ToUnity();
|
||||
else if (target.Entity != null)
|
||||
TargetIndicator.Target = target.Entity.Position.ToUnity();
|
||||
var distance = length(ViewDot.Target.ToCultMath() - CurrentEntity.Position);
|
||||
foreach (var (_, barrels, crosshair) in _articulationGroups)
|
||||
{
|
||||
|
|
@ -1403,11 +1432,11 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
foreach (var (targetLock, indicator, spin) in _lockingIndicators)
|
||||
{
|
||||
var showLockingIndicator = targetLock.Lock > .01f && CurrentEntity.Target.Value != null && CurrentEntity.IsHostileTo(CurrentEntity.Target.Value);
|
||||
var showLockingIndicator = targetLock.Lock > .01f && CurrentEntity.Target.Value.Entity != null && CurrentEntity.IsHostileTo(CurrentEntity.Target.Value.Entity);
|
||||
indicator.gameObject.SetActive(showLockingIndicator);
|
||||
if(showLockingIndicator)
|
||||
{
|
||||
indicator.Target = CurrentEntity.Target.Value.Position.ToUnity();
|
||||
indicator.Target = CurrentEntity.Target.Value.Entity.Position.ToUnity();
|
||||
indicator.NoiseAmplitude = Settings.GameplaySettings.LockIndicatorNoiseAmplitude * (1 - targetLock.Lock);
|
||||
indicator.NoiseFrequency = Settings.GameplaySettings.LockIndicatorFrequency.Evaluate(targetLock.Lock);
|
||||
spin.Speed = Settings.GameplaySettings.LockSpinSpeed.Evaluate(targetLock.Lock);
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ public class EntityInstance : MonoBehaviour
|
|||
}
|
||||
|
||||
constantWeapon.OnStartFiring += () =>
|
||||
_constantWeaponManagers[data].StartFiring(data, item, this, entity.Target.Value != null ? ZoneRenderer.EntityInstances[entity.Target.Value] : null);
|
||||
_constantWeaponManagers[data].StartFiring(data, item, this, entity.Target.Value.Entity != null ? ZoneRenderer.EntityInstances[entity.Target.Value.Entity] : null);
|
||||
constantWeapon.OnStopFiring += () =>
|
||||
_constantWeaponManagers[data].StopFiring(item);
|
||||
}
|
||||
|
|
@ -410,7 +410,7 @@ public class EntityInstance : MonoBehaviour
|
|||
}
|
||||
|
||||
LookAtPoint.position = transform.position + Entity.LookDirection.ToUnity() *
|
||||
(Entity.Target.Value != null ? max(Entity.TargetRange,Entity.ItemManager.GameplaySettings.ConvergenceMinimumDistance) : 10000);
|
||||
(!Entity.Target.Value.IsNone ? max(Entity.TargetRange,Entity.ItemManager.GameplaySettings.ConvergenceMinimumDistance) : 10000);
|
||||
LocalSpace.localPosition = transform.position = Entity.Position.ToUnity();
|
||||
if (_influenceInstance)
|
||||
_influenceInstance.position = new Vector3(Entity.Position.x, 0, Entity.Position.z);
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ public class Minion : Agent
|
|||
() => Task is PatrolOrbitsTask,
|
||||
() => patrolState.Task = Task as PatrolOrbitsTask);
|
||||
|
||||
Ship.VisibleEnemies.ObserveAdd().Where(_ => Ship.Target.Value == null).Subscribe(add => Ship.Target.Value = add.Value);
|
||||
Ship.VisibleEnemies.ObserveAdd().Where(_ => Ship.Target.Value.IsNone).Subscribe(add => Ship.SetTarget(add.Value));
|
||||
|
||||
var combatState = new CombatState(this);
|
||||
_rootState.AddTransition(combatState,
|
||||
() => Ship.Target.Value != null, null, true, _rootState);
|
||||
() => Ship.Target.Value.Entity != null, null, true, _rootState);
|
||||
|
||||
combatState.AddTransition(_rootState,
|
||||
() => Ship.Target.Value == null, null, true, _rootState);
|
||||
() => Ship.Target.Value.Entity == null, null, true, _rootState);
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ public class CombatState : BaseState
|
|||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
var target = _agent.Ship.Target.Value;
|
||||
var target = _agent.Ship.Target.Value.Entity;
|
||||
if (target == null) return;
|
||||
|
||||
_availableGroups.Clear();
|
||||
|
|
|
|||
|
|
@ -77,13 +77,16 @@ public class LockWeapon : InstantWeapon
|
|||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
if (_target != Entity.Target.Value)
|
||||
// Mining Cut 3 (Q12 A): lock builds on an entity only. A chunk target reads as no target here, so a
|
||||
// launcher never locks a rock.
|
||||
var target = Entity.Target.Value.Entity;
|
||||
if (_target != target)
|
||||
{
|
||||
_lock = 0;
|
||||
_target = Entity.Target.Value;
|
||||
_target = target;
|
||||
}
|
||||
|
||||
if (Entity.Target.Value != null && Entity.IsHostileTo(Entity.Target.Value))
|
||||
if (target != null && Entity.IsHostileTo(target))
|
||||
{
|
||||
LockSpeed = Evaluate(_data.LockSpeed);
|
||||
SensorImpact = Evaluate(_data.SensorImpact);
|
||||
|
|
@ -91,11 +94,11 @@ public class LockWeapon : InstantWeapon
|
|||
DirectionImpact = Evaluate(_data.DirectionImpact);
|
||||
Decay = Evaluate(_data.Decay);
|
||||
|
||||
var degrees = acos(dot(normalize(Entity.Target.Value.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f;
|
||||
var degrees = acos(dot(normalize(target.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f;
|
||||
if (degrees < LockAngle)
|
||||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * dt * LockSpeed * pow(Entity.EntityInfoGathered[Entity.Target.Value], SensorImpact));
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * dt * LockSpeed * pow(Entity.EntityInfoGathered[target], SensorImpact));
|
||||
}
|
||||
else _lock = saturate(_lock - dt * Decay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,16 +57,18 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
|
||||
public override bool Execute(float dt)
|
||||
{
|
||||
if (Entity.Target.Value != null)
|
||||
// Mining Cut 3: a turret engages entities only; it never picks a chunk, and reads one as no target.
|
||||
var target = Entity.Target.Value.Entity;
|
||||
if (target != null)
|
||||
{
|
||||
var diff = Entity.Target.Value.Position - Entity.Position;
|
||||
var diff = target.Position - Entity.Position;
|
||||
if (_predictShots)
|
||||
{
|
||||
var targetHullData = Entity.ItemManager.GetData(Entity.Target.Value.Hull) as HullData;
|
||||
var targetVelocity = float3(Entity.Target.Value.Velocity.x, 0, Entity.Target.Value.Velocity.y);
|
||||
var targetHullData = Entity.ItemManager.GetData(target.Hull) as HullData;
|
||||
var targetVelocity = float3(target.Velocity.x, 0, target.Velocity.y);
|
||||
var predictedPosition = first_order_intercept(
|
||||
Entity.Position, float3.zero, _shotSpeed,
|
||||
Entity.Target.Value.Position, targetVelocity
|
||||
target.Position, targetVelocity
|
||||
);
|
||||
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
||||
Entity.LookDirection = normalize(predictedPosition - Entity.Position);
|
||||
|
|
@ -78,7 +80,7 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
{
|
||||
// The same per-weapon decision Combat.cs makes; the range test is part of it (a shot out of range
|
||||
// is not designated and prices at zero).
|
||||
if (FireControl.AgentFires(x, Entity, Entity.Target.Value))
|
||||
if (FireControl.AgentFires(x, Entity, target))
|
||||
{
|
||||
x.Activate();
|
||||
}
|
||||
|
|
@ -93,7 +95,7 @@ public class TurretController : Behavior, IInitializableBehavior
|
|||
if (x.Firing)
|
||||
x.Deactivate();
|
||||
}
|
||||
Entity.Target.Value = Entity.VisibleEnemies.FirstOrDefault(e => e is Ship);
|
||||
Entity.SetTarget(Entity.VisibleEnemies.FirstOrDefault(e => e is Ship));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,9 @@ public abstract class Weapon : Behavior, IActivatedBehavior
|
|||
|
||||
// Single shared fire gate for player and AI shooters alike: weapons are safed by the
|
||||
// shooter's OWN declared stance toward its target, not the target's stance toward the shooter.
|
||||
// With no target set, behaviour is unchanged (nothing to be safe about).
|
||||
public bool StanceAllowsFire => Entity.Target.Value == null || Entity.IsHostileTo(Entity.Target.Value);
|
||||
// With no target set, behaviour is unchanged (nothing to be safe about). Mining Cut 3: a chunk has no stance,
|
||||
// so a weapon is never safed against one.
|
||||
public bool StanceAllowsFire => Entity.Target.Value.Entity == null || Entity.IsHostileTo(Entity.Target.Value.Entity);
|
||||
|
||||
// Cut 3 (docs/fire-control-cut.md, Q2): player fire is arc-gated like everyone else's. This is the same
|
||||
// predicate (FireControl.InArc) Combat.cs and TurretController.cs gate AI and turret fire with, read at
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ public abstract class Entity
|
|||
|
||||
public Entity Parent;
|
||||
public List<Entity> Children = new List<Entity>();
|
||||
public ReactiveProperty<Entity> Target = new ReactiveProperty<Entity>((Entity)null);
|
||||
// Mining Cut 3 (docs/mining-cut-refresh.md): the one target slot -- an entity, a chunk, or none. Read-only from
|
||||
// outside: SetTarget is its one writer, for the player's handlers and the agents alike.
|
||||
private readonly ReactiveProperty<TargetRef> _target = new ReactiveProperty<TargetRef>(TargetRef.None);
|
||||
public IReadOnlyReactiveProperty<TargetRef> Target => _target;
|
||||
|
||||
// Cut 2 (docs/fire-control-cut.md): the stored aim-point slot. Written only by TrySelectTargetItem
|
||||
// below, and nulled whenever Target changes (subscribed in Activate). Do not read this field directly
|
||||
|
|
@ -198,7 +201,7 @@ public abstract class Entity
|
|||
}));
|
||||
_subscriptions.Add(Zone.Entities.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
if (Target.Value == remove.Value) Target.Value = null;
|
||||
if (Target.Value.Entity == remove.Value) SetTarget(TargetRef.None);
|
||||
EntityInfoGathered.Remove(remove.Value);
|
||||
EntityHostility.Remove(remove.Value);
|
||||
VisibleEntities.Remove(remove.Value);
|
||||
|
|
@ -224,13 +227,14 @@ public abstract class Entity
|
|||
_subscriptions.Add(_iffOverrides.ObserveRemove().Subscribe(remove => RefreshHostilityFromOverride(remove.Key)));
|
||||
_subscriptions.Add(VisibleEnemies.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
if (Target.Value == remove.Value) Target.Value = null;
|
||||
if (Target.Value.Entity == remove.Value) SetTarget(TargetRef.None);
|
||||
}));
|
||||
_subscriptions.Add(Target.Subscribe(entity => entity?.TargetedBy.OnNext(this)));
|
||||
// Only an entity is ever targeted by: a chunk has no one to tell.
|
||||
_subscriptions.Add(Target.Subscribe(target => target.Entity?.TargetedBy.OnNext(this)));
|
||||
_subscriptions.Add(TargetedBy.Subscribe(enemy =>
|
||||
{
|
||||
TargetedByCount.Value++;
|
||||
enemy.Target.Where(t => t != this).Take(1).Subscribe(_ => TargetedByCount.Value--);
|
||||
enemy.Target.Where(t => t.Entity != this).Take(1).Subscribe(_ => TargetedByCount.Value--);
|
||||
}));
|
||||
|
||||
//
|
||||
|
|
@ -295,8 +299,11 @@ public abstract class Entity
|
|||
// Deactivate nulling Target outright, because nulling on every dock would throw away a target
|
||||
// that is still alive and simply never changed while docked -- the common case, and not the one
|
||||
// that crashed.
|
||||
if (Target.Value != null && !EntityInfoGathered.ContainsKey(Target.Value))
|
||||
Target.Value = null;
|
||||
// Mining Cut 3: a chunk target is held to the same "still tracked" test through the chunk path -- kept
|
||||
// while this entity can see it, dropped once it cannot (a broken chunk is dark, so it is dropped too).
|
||||
if (Target.Value.Entity != null && !EntityInfoGathered.ContainsKey(Target.Value.Entity) ||
|
||||
Target.Value.Chunk is ChunkId heldChunk && !ChunkVisible(heldChunk))
|
||||
SetTarget(TargetRef.None);
|
||||
|
||||
if(WeaponGroups.All(wg=>!wg.items.Any()))
|
||||
GenerateWeaponGroups();
|
||||
|
|
@ -314,7 +321,8 @@ public abstract class Entity
|
|||
return true;
|
||||
}
|
||||
|
||||
if (Target.Value == null || item.Entity != Target.Value || !FireControl.IsRevealed(this, item))
|
||||
// Mining Cut 3: entity-only. A chunk has no items, so an item never belongs to a chunk target.
|
||||
if (Target.Value.Entity == null || item.Entity != Target.Value.Entity || !FireControl.IsRevealed(this, item))
|
||||
return false;
|
||||
|
||||
TargetItem.Value = item;
|
||||
|
|
@ -325,10 +333,62 @@ public abstract class Entity
|
|||
// revealed to this entity, or no longer belongs to the current Target, even though nothing wrote
|
||||
// TargetItem.Value at the moment that became true. Re-checked on every call; never cached.
|
||||
public EquippedItem ResolvedTargetItem =>
|
||||
TargetItem.Value != null && Target.Value == TargetItem.Value.Entity && FireControl.IsRevealed(this, TargetItem.Value)
|
||||
TargetItem.Value != null && Target.Value.Entity == TargetItem.Value.Entity && FireControl.IsRevealed(this, TargetItem.Value)
|
||||
? TargetItem.Value
|
||||
: null;
|
||||
|
||||
// Mining Cut 3 (docs/mining-cut-refresh.md): the one writer of Target, called by the player's handlers and the
|
||||
// agents alike. A chunk is taken only while this entity can see it, so a rock in darkness cannot be picked; an
|
||||
// entity is written as given, as every handler wrote it before. Returns whether the write took effect.
|
||||
public bool SetTarget(TargetRef target)
|
||||
{
|
||||
if (target.Chunk is ChunkId chunk && !ChunkVisible(chunk)) return false;
|
||||
_target.Value = target;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mining Cut 3 (Q14 A): this entity's info on a chunk, computed when asked and stored nowhere. It is the value
|
||||
// the per-tick sensor rule (Sensor.Execute, through Sensor.Gain) would settle at for a target this bright,
|
||||
// here, now. Each active sensor applies x <- saturate(x + G_i dt)(1 - k dt) every tick, so with n sensors the
|
||||
// info settles where the gain balances the decay: sum(G_i) / (n k), capped at 1. A ping adds nothing that
|
||||
// lasts, so only the passive gain enters.
|
||||
public float ChunkInfo(ChunkId chunk)
|
||||
{
|
||||
var visibility = Zone.ChunkVisibility(chunk);
|
||||
if (visibility <= 0f) return 0f;
|
||||
var position = Zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
var rate = 0f;
|
||||
var sensors = 0;
|
||||
foreach (var sensor in ActiveSensors())
|
||||
{
|
||||
rate += sensor.PassiveRate(visibility, position);
|
||||
sensors++;
|
||||
}
|
||||
return sensors == 0 ? 0f : saturate(rate / (sensors * ItemManager.GameplaySettings.TargetInfoDecay));
|
||||
}
|
||||
|
||||
// Mining Cut 3: the detection threshold, read through the chunk path. A chunk is visible exactly as an entity
|
||||
// enters VisibleEntities: its info exceeds TargetDetectionInfoThreshold.
|
||||
public bool ChunkVisible(ChunkId chunk) => ChunkInfo(chunk) > ItemManager.GameplaySettings.TargetDetectionInfoThreshold;
|
||||
|
||||
// Mining Cut 3 (Q13 A): the reach for picking a chunk -- the longest range among this entity's active weapons.
|
||||
// Every visible chunk within it, written into `into` (cleared first). Cycling and any programmatic chunk pick
|
||||
// read this, so there is one reach rule.
|
||||
public void VisibleChunksInReach(List<ChunkId> into)
|
||||
{
|
||||
var reach = 0f;
|
||||
foreach (var weapon in _weapons)
|
||||
if (weapon.Item == null || weapon.Item.Active.Value)
|
||||
reach = max(reach, weapon.Range);
|
||||
Zone.ChunksNear(Position.xz, reach, into);
|
||||
into.RemoveAll(chunk => !ChunkVisible(chunk));
|
||||
}
|
||||
|
||||
// Every sensor behaviour that runs this tick: those on active equipment, and those of active consumables.
|
||||
private IEnumerable<Sensor> ActiveSensors() =>
|
||||
Equipment.Where(item => item.Active.Value).SelectMany(item => item.Behaviors).OfType<Sensor>()
|
||||
.Concat(_activeConsumables.SelectMany(effect => effect.Behaviors).OfType<Sensor>());
|
||||
|
||||
// Cut 12.3 (docs/fire-control-cut.md): "armour absorbs first" -- the per-cell armour phase, split out of
|
||||
// what used to be Absorb's own first half (moved verbatim from DamageSchematic's per-cell body, Cut 3) so
|
||||
// Cut 12.3's fix batch (proportional multi-lane item absorption, below) can call the armour phase once per
|
||||
|
|
@ -1075,7 +1135,12 @@ public abstract class Entity
|
|||
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
|
||||
TargetRange = Target.Value == null ? -1 : length(Position - Target.Value.Position);
|
||||
// Mining Cut 3: a chunk target is lost the moment this entity can no longer see it -- the lost-track rule
|
||||
// through the chunk path. One check of the one slot per tick, not a detection loop over chunks.
|
||||
if (Target.Value.Chunk is ChunkId trackedChunk && !ChunkVisible(trackedChunk)) SetTarget(TargetRef.None);
|
||||
TargetRange = Target.Value.Chunk is ChunkId rangedChunk
|
||||
? length(Position.xz - Zone.ChunkPose(rangedChunk.Field, rangedChunk.Index).xy)
|
||||
: Target.Value.Entity == null ? -1 : length(Position - Target.Value.Entity.Position);
|
||||
|
||||
var localSecurityLevel = Zone.GetSecurityLevel(Position.xz);
|
||||
if (CurrentSecurityLevel.Value != localSecurityLevel) CurrentSecurityLevel.Value = localSecurityLevel;
|
||||
|
|
|
|||
|
|
@ -72,18 +72,26 @@ public static class FireControl
|
|||
// (Fire; operator ruling 2026-09-30, "the user is hoping that the arc gets the weapon close enough to still
|
||||
// splash some damage"). A weapon that only hits what it fires at still refuses. Fire reads InArc itself to
|
||||
// choose that flight, so the two share the one bearing test and differ only in this exemption.
|
||||
// Mining Cut 3: a chunk target bears through its own position, on the plane the bearing test reads.
|
||||
public static bool ArcPermitsFire(Weapon weapon, Entity shooter)
|
||||
{
|
||||
var target = shooter.Target.Value;
|
||||
if (target == null) return true;
|
||||
return FuseOf(weapon.Item, out _) != null || InArc(weapon.Item, target.Position - shooter.Position);
|
||||
if (target.IsNone) return true;
|
||||
float3 toTarget;
|
||||
if (target.Chunk is ChunkId chunk)
|
||||
{
|
||||
var at = shooter.Zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
toTarget = float3(at.x, 0, at.y) - shooter.Position;
|
||||
}
|
||||
else toTarget = target.Entity.Position - shooter.Position;
|
||||
return FuseOf(weapon.Item, out _) != null || InArc(weapon.Item, toTarget);
|
||||
}
|
||||
|
||||
// Whether the shooter's next round from this weapon is refused: the weapons ask before they spend anything, so
|
||||
// a refused round costs no ammo, energy, sound, heat, wear or visibility (operator ruling 2026-09-30). The
|
||||
// answer is Solve's own -- there is no second copy of the arming test.
|
||||
public static bool Refuses(Weapon weapon, Entity shooter) =>
|
||||
Solve(weapon, weapon.Item, shooter, shooter.Target.Value).Outcome == FireOutcome.Refused;
|
||||
Solve(weapon, weapon.Item, shooter, shooter.Target.Value.Entity).Outcome == FireOutcome.Refused;
|
||||
|
||||
// The agents' trigger decision (Combat, TurretController), one weapon at a time (operator ruling 2026-09-30).
|
||||
// A weapon that fires at what it hits fires when the shot is worth taking. A fused weapon fires whenever its
|
||||
|
|
@ -522,7 +530,8 @@ public static class FireControl
|
|||
public static int Fire(Weapon weapon, EquippedItem item, Entity source, float? damageOverride = null)
|
||||
{
|
||||
var zone = source.Zone;
|
||||
var target = source.Target.Value;
|
||||
// Mining Cut 3: a chunk target fires as an untargeted round until Cut 4 routes shots at chunks.
|
||||
var target = source.Target.Value.Entity;
|
||||
var now = zone.Time;
|
||||
|
||||
// R1's engage gate and the shooter-side probability, evaluated now and frozen: nothing at commit time
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class Ship : Entity
|
|||
|
||||
public void EnterWormhole(float2 wormholePosition)
|
||||
{
|
||||
Target.Value = null;
|
||||
SetTarget(TargetRef.None);
|
||||
_wormholeAnimationProgress = 0;
|
||||
_enteringWormhole = true;
|
||||
_wormholeEntryPosition = Position.xz;
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ public sealed class FireAuthorityTests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ public sealed class FireControlCut11Tests : IDisposable
|
|||
|
||||
shooter.Position = float3(37, 0, -11);
|
||||
target.Position = float3(37, 0, 89); // 100 units straight ahead of the shooter
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
if (equipShield) target.Shield.Item.Enabled.Value = true;
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ public sealed class FireControlCut123Tests : IDisposable
|
|||
shooter.Position = float3(37, 0, -11);
|
||||
target.Position = float3(37, 0, 89); // 100 units straight ahead of the shooter -- travel direction is exactly (0,1)
|
||||
if (targetFacing != null) target.Direction = targetFacing.Value;
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
shooter.Position = float3(-53, 0, -101);
|
||||
target.Position = shooter.Position + float3(0, 0, targetRange);
|
||||
if (targetFacing != null) target.Direction = normalize(targetFacing.Value);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
@ -1176,7 +1176,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: fuse, blastRadius: 4f, penetration: 1f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
Aim(e, float2(2, 1));
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
var burst = AimLine(e);
|
||||
var onLine = AddShip(e, burst, 1f, 300);
|
||||
var offLine = AddShip(e, burst + float3(-30, 0, 30), 1f, 302);
|
||||
|
|
@ -1201,7 +1201,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
Aim(e, float2(2, 1));
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
|
||||
FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter);
|
||||
|
||||
|
|
@ -1252,7 +1252,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(side, -1));
|
||||
var edge = float2(side * sin(radians(85f)), cos(radians(85f)));
|
||||
var onEdge = AddShip(e, PointAlong(e, edge, NoLockRange), 1f, 300);
|
||||
|
|
@ -1273,7 +1273,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
var mount = float2(0, 1);
|
||||
var aim = normalize(float2(2, 1));
|
||||
var onAim = AddShip(e, PointAlong(e, aim, NoLockRange), 1f, 300);
|
||||
|
|
@ -1659,7 +1659,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void AContactRoundNeverStopsNearerThanItsArmingDistance()
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
AddShip(e, PointAlong(e, float2(0, 1), 6f), 1f, 300);
|
||||
ShotOutcome outcome = null;
|
||||
|
|
@ -1682,7 +1682,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
var column = new Shape(1, 22);
|
||||
foreach (var y in new[] { 0, 1, 2, 18, 19, 20, 21 }) column[new int2(0, y)] = true;
|
||||
var e = Build(TestSettings(), column, velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var offset = e.Target.ToWorldPoint(float2(0, 2)) - e.Target.Position.xz;
|
||||
e.Target.Position = float3(e.Shooter.Position.x - offset.x, 0, e.Shooter.Position.z - offset.y);
|
||||
|
|
@ -1708,7 +1708,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 30f, damage: 100f,
|
||||
weaponRange: range, rangeTerm: starvedOfPower ? StatSource.PowerSupply : (StatSource?) null);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
if (starvedOfPower)
|
||||
{
|
||||
|
|
@ -1730,7 +1730,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void ARangeExactlyEqualToTheArmingDistanceFires()
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 30f, damage: 100f, weaponRange: 30f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
|
||||
Assert.True(FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter) != 0, "a Range equal to the arming distance must fire");
|
||||
|
|
@ -1745,7 +1745,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void ARefusedRoundIsNotAnnounced(float range, int fired)
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 30f, damage: 100f, weaponRange: range);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var announced = 0;
|
||||
var committed = 0;
|
||||
|
|
@ -1918,7 +1918,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: fuse, blastRadius: 4f, penetration: 1f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300);
|
||||
var atMaxRange = AddShip(e, PointAlong(e, float2(0, 1), NoLockRange), 1f, 302);
|
||||
|
|
@ -1944,7 +1944,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var targetBefore = e.Target.Hull.Durability;
|
||||
var shooterHit = 0f;
|
||||
|
|
@ -1970,7 +1970,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300);
|
||||
ShotOutcome outcome = null;
|
||||
|
|
@ -1999,7 +1999,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var witness = AddShip(e, PointAlong(e, float2(0, 1), NoLockRange), 1f, 300);
|
||||
|
||||
|
|
@ -2061,7 +2061,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 0, fuse: WeaponFuse.Proximity, blastRadius: 4f, damage: 100f,
|
||||
weaponRange: NoLockRange);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(2, 1));
|
||||
ShotOutcome committed = null, resolved = null;
|
||||
using var c = e.Zone.ShotCommitted.Subscribe(o => committed = o);
|
||||
|
|
@ -2162,7 +2162,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void AContactRoundIgnoresAHullThatCrossesItsLineAfterFire()
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: 60f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f) + float3(300, 0, 0), 1f, 300);
|
||||
ShotOutcome committed = null;
|
||||
|
|
@ -2183,7 +2183,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void AContactRoundStillBurstsAtAHullThatLeavesItsLineAfterFire()
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: 60f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var blocker = AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300);
|
||||
var atMaxRange = AddShip(e, PointAlong(e, float2(0, 1), 60f), 1f, 302);
|
||||
|
|
@ -2209,7 +2209,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void AShooterMovingAfterFireDoesNotMoveTheContactPoint(bool withBlocker)
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: 60f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var origin = e.Shooter.Position;
|
||||
if (withBlocker) AddShip(e, PointAlong(e, float2(0, 1), 25f), 1f, 300);
|
||||
|
|
@ -2230,7 +2230,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void AContactRoundIgnoresAHullBehindTheMuzzle()
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: WeaponFuse.Contact, blastRadius: 4f, damage: 100f, weaponRange: 60f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
AddShip(e, PointAlong(e, float2(0, -1), 25f), 1f, 300);
|
||||
ShotOutcome committed = null;
|
||||
|
|
@ -2294,7 +2294,7 @@ public sealed class FireControlCut124Tests : IDisposable
|
|||
public void ANoLockRoundStillBurstsAfterItsShooterIsDestroyed(WeaponFuse fuse)
|
||||
{
|
||||
var e = Build(TestSettings(), SolidShape(5, 4), velocity: 20f, fuse: fuse, blastRadius: 4f, damage: 100f, weaponRange: 60f);
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(e, float2(0, 1));
|
||||
var witness = AddShip(e, PointAlong(e, float2(0, 1), 60f), 1f, 300);
|
||||
var resolved = new List<ShotOutcome>();
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ public sealed class FireControlCut12Tests : IDisposable
|
|||
shooter.Position = float3(37, 0, -11);
|
||||
target.Position = float3(37, 0, 89); // 100 units straight ahead of the shooter
|
||||
if (targetFacing != null) target.Direction = targetFacing.Value;
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
if (equipShield)
|
||||
|
|
@ -390,7 +390,7 @@ public sealed class FireControlCut12Tests : IDisposable
|
|||
|
||||
// No target: Fire's own null-target branch must use the fallback directly, not call TravelDirection
|
||||
// (which reads target.Position and would NRE).
|
||||
e.Shooter.Target.Value = null;
|
||||
e.Shooter.SetTarget(TargetRef.None);
|
||||
var noTargetId = FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter);
|
||||
var noTarget = e.Zone.PendingShots.Single(s => s.ShotId == noTargetId);
|
||||
Assert.Equal(0f, noTarget.TravelDirection.x);
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ public sealed class FireControlCut4Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = targetPosition;
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
@ -449,7 +449,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
// The shared path: Weapon.ArcAllowsFire (the trigger gate every shooter passes through) must agree,
|
||||
// now that it no longer carries its own special case and defers to InArc entirely.
|
||||
var weapon = (Weapon) weaponItem.Behaviors.Single(b => b is Weapon);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
Assert.True(weapon.ArcAllowsFire);
|
||||
}
|
||||
|
||||
|
|
@ -465,7 +465,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
var (_, shooter, target, weaponItem) = BuildPointBlank(settings);
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(100, 0, 0); // directly abeam
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
|
||||
var weapon = (Weapon) weaponItem.Behaviors.Single(b => b is Weapon);
|
||||
Assert.False(weapon.ArcAllowsFire);
|
||||
|
|
@ -488,7 +488,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
var e = Build(settings, damage: 10, velocity: 0, accuracy: 1, resolution: 1, spread: 0, targetRange: 100);
|
||||
e.Shooter.Position = float3.zero;
|
||||
e.Target.Position = float3(100, 0, 0); // abeam -- outside the narrow 60-degree arc
|
||||
e.Shooter.Target.Value = e.Target;
|
||||
e.Shooter.SetTarget(e.Target);
|
||||
|
||||
var resolvedCount = 0;
|
||||
e.Zone.ShotResolved.Subscribe(_ => resolvedCount++);
|
||||
|
|
@ -590,7 +590,7 @@ public sealed class FireControlCut5Tests : IDisposable
|
|||
var observer = new Ship(items, target.Zone, new EquippableItem { Data = observerHullRef, Durability = 1000, Lot = 1 }, new EntitySettings());
|
||||
target.Zone.Entities.Add(observer);
|
||||
observer.Activate();
|
||||
observer.Target.Value = target;
|
||||
observer.SetTarget(target);
|
||||
|
||||
// With both items alive: Big (index 0) reveals at .2, Medium (index 1) at .8.
|
||||
observer.EntityInfoGathered[target] = .3f;
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public sealed class FireControlCut6Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public sealed class FireControlCut6cTests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
zone.Update(0f); // warm-up: resolves the targeting system's stats before HitProbability reads them
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public sealed class FireControlCut6dTests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, true);
|
||||
shooter.EntityInfoGathered[target] = 1f; // full reveal: pSensor = 1
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public sealed class FireControlCut7Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, 100);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
zone.Update(0f); // warm-up: resolves weapon/targeting stats before Fire reads them
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public sealed class FireControlCut8Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, 100);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ public sealed class FireControlCut8Tests : IDisposable
|
|||
locker.Position = float3.zero;
|
||||
bystander.Position = float3(0, 0, 100);
|
||||
locker.LookDirection = float3(0, 0, 1);
|
||||
locker.Target.Value = bystander;
|
||||
locker.SetTarget(bystander);
|
||||
locker.EntityInfoGathered[bystander] = 1f;
|
||||
locker.SetIff(bystander, true);
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ public sealed class FireControlCut8Tests : IDisposable
|
|||
public void DeadEntityDoesNotUpdate()
|
||||
{
|
||||
var e = Build(TestSettings());
|
||||
e.Target.Target.Value = e.Shooter; // give the target its own TargetRange to freeze
|
||||
e.Target.SetTarget(e.Shooter); // give the target its own TargetRange to freeze
|
||||
e.Zone.Update(.1f);
|
||||
var rangeBeforeDeath = e.Target.TargetRange;
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ public sealed class FireControlCut8Tests : IDisposable
|
|||
s.Locker.Deactivate();
|
||||
Assert.False(s.Locker.Active);
|
||||
Assert.DoesNotContain(s.Bystander, s.Locker.EntityInfoGathered.Keys);
|
||||
Assert.Equal(s.Bystander, s.Locker.Target.Value); // Deactivate does not null the entity's own Target
|
||||
Assert.Same(s.Bystander, s.Locker.Target.Value.Entity); // Deactivate does not null the entity's own Target
|
||||
|
||||
var ex = Record.Exception(() => s.Locker.Update(.1f));
|
||||
Assert.Null(ex);
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ public sealed class FireControlCut9Tests : IDisposable
|
|||
|
||||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, 100);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, true);
|
||||
shooter.EntityInfoGathered[target] = 1f; // full reveal: pSensor = 1
|
||||
|
||||
|
|
@ -561,7 +561,7 @@ public sealed class FireControlCut9Tests : IDisposable
|
|||
locker.Position = float3.zero;
|
||||
bystander.Position = float3(0, 0, 100);
|
||||
locker.LookDirection = float3(0, 0, 1);
|
||||
locker.Target.Value = bystander;
|
||||
locker.SetTarget(bystander);
|
||||
locker.EntityInfoGathered[bystander] = 1f;
|
||||
locker.SetIff(bystander, true);
|
||||
|
||||
|
|
@ -596,7 +596,7 @@ public sealed class FireControlCut9Tests : IDisposable
|
|||
// Assert.Null(entity) would hand a live Entity into xUnit's reflection-based failure formatter,
|
||||
// which recurses through Zone -> Entities -> Ship -> Zone forever; a plain boolean with its own
|
||||
// message sidesteps that entirely.
|
||||
Assert.True(s.Locker.Target.Value == null, "the invariant: an active entity's Target is always a live entity it has info on -- a stale reference to the departed Bystander survived Activate's reconciliation");
|
||||
Assert.True(s.Locker.Target.Value.IsNone, "the invariant: an active entity's Target is always a live entity it has info on -- a stale reference to the departed Bystander survived Activate's reconciliation");
|
||||
|
||||
var ex = Record.Exception(() => s.Locker.Update(.1f));
|
||||
Assert.Null(ex);
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
|
||||
shooter.Position = float3(-53, 0, -101);
|
||||
target.Position = shooter.Position + float3(0, 0, targetRange);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.EntityInfoGathered[target] = 1f;
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
|
|
@ -371,10 +371,10 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void TheForecastIsTheOutcomeFireDelivers(float targetRange, float range, bool noTarget, bool outOfArc, FireOutcome outcome, float reach)
|
||||
{
|
||||
var r = Build(outOfArc ? SideMount : null, fuse: WeaponFuse.Proximity, blast: 30f, range: range, targetRange: targetRange);
|
||||
if (noTarget) r.Shooter.Target.Value = null;
|
||||
if (noTarget) r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
|
||||
var d = FireControl.Inspect(r.Gun.Weapon, r.Shooter, r.Shooter.Target.Value);
|
||||
var d = FireControl.Inspect(r.Gun.Weapon, r.Shooter, r.Shooter.Target.Value.Entity);
|
||||
var shotId = FireControl.Fire(r.Gun.Weapon, r.Gun.Item, r.Shooter);
|
||||
|
||||
Assert.Equal(outcome, d.Outcome);
|
||||
|
|
@ -417,7 +417,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
private Costs Pull(float range, bool single, bool viaTrigger, bool staleRange = false, bool auto = false)
|
||||
{
|
||||
var r = Build(fuse: WeaponFuse.Proximity, blast: 30f, range: range, energy: 50f, heat: 5000f, visibility: 100f, magazine: 5, singleAmmoBurst: single, auto: auto);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (InstantWeapon) r.Gun.Weapon;
|
||||
var capacitor = (InputCapacitor) typeof(InstantWeapon).GetField("_capacitor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(weapon);
|
||||
|
|
@ -496,7 +496,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
private (int Shots, int Wears, float Request, bool Visible, float Heat, int Stops, bool Firing) Burn(float range)
|
||||
{
|
||||
var r = Build(beam: true, fuse: WeaponFuse.Proximity, blast: 30f, range: range, energy: 50f, heat: 5000f, visibility: 100f);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (ConstantWeapon) r.Gun.Weapon;
|
||||
var wears = 0;
|
||||
|
|
@ -543,7 +543,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void ARefusedBeamNeverStarts(float range, int starts)
|
||||
{
|
||||
var r = Build(beam: true, fuse: WeaponFuse.Proximity, blast: 30f, range: range);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (ConstantWeapon) r.Gun.Weapon;
|
||||
var started = 0;
|
||||
|
|
@ -666,7 +666,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
private (int Starts, int Sounds, float Heat, bool Charging) Charge(float range)
|
||||
{
|
||||
var r = Build(charged: true, fuse: WeaponFuse.Proximity, blast: 30f, range: range);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (ChargedWeapon) r.Gun.Weapon;
|
||||
r.Gun.Item.SoundBank = new WwiseMetaSoundBank { IncludedEvents = new[] { new WwiseMetaObject { Id = 7, Name = "gun_charge_play" } } };
|
||||
|
|
@ -701,7 +701,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void ATriggeredBurstIsNotReadyBeforeItsFirstRound()
|
||||
{
|
||||
var r = Build(range: 100f);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (InstantWeapon) r.Gun.Weapon;
|
||||
r.Zone.Update(.01f); // resolves the gun's stats, which size the burst
|
||||
|
|
@ -719,7 +719,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void AChargedWeaponPressedAgainBeforeItsReleasedRoundFliesStartsNoSecondCharge()
|
||||
{
|
||||
var r = Build(charged: true, range: 100f);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (ChargedWeapon) r.Gun.Weapon;
|
||||
var starts = 0;
|
||||
|
|
@ -747,7 +747,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void AHeldTriggerFiresOncePerCooldownAndARefusedBurstLeavesNone(float range, int shots)
|
||||
{
|
||||
var r = Build(fuse: WeaponFuse.Proximity, blast: 30f, range: range);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (InstantWeapon) r.Gun.Weapon;
|
||||
var fired = 0;
|
||||
|
|
@ -772,7 +772,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void ABurstTriggeredAfterAFiredOneIsNotReadyBeforeItsFirstRound()
|
||||
{
|
||||
var r = Build(range: 100f);
|
||||
r.Shooter.Target.Value = null;
|
||||
r.Shooter.SetTarget(TargetRef.None);
|
||||
Aim(r, float2(0, 1));
|
||||
var weapon = (InstantWeapon) r.Gun.Weapon;
|
||||
r.Zone.Update(.25f);
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ public sealed class FireControlTests : IDisposable
|
|||
shooter.Position = float3.zero;
|
||||
target.Position = float3(0, 0, 10); // dead ahead of the None-rotation hardpoint, well within range and arc
|
||||
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
// Cut 3: CombatState now gates on FireControl.HitProbability, which is zero for an undetected target
|
||||
// (the target is not in VisibleEntities) regardless of arc -- cross TargetDetectionInfoThreshold
|
||||
// directly, the same way a Sensor's own info accrual eventually would.
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
var target = NewShip(items, zone, new Faction { Name = "Target" });
|
||||
var weapon = (InstantWeapon) shooter.Equipment.Single(e => e.Behaviors.Any(b => b is Weapon)).Behaviors.Single(b => b is Weapon);
|
||||
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, false); // explicitly neutral
|
||||
|
||||
weapon.Execute(.01f); // resolves the gun's stats: a burst has no rounds before the first tick
|
||||
|
|
@ -263,7 +263,7 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
var target = NewShip(items, zone, new Faction { Name = "Target" });
|
||||
var weapon = (InstantWeapon) shooter.Equipment.Single(e => e.Behaviors.Any(b => b is Weapon)).Behaviors.Single(b => b is Weapon);
|
||||
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
shooter.SetIff(target, true);
|
||||
|
||||
weapon.Execute(.01f); // resolves the gun's stats: a burst has no rounds before the first tick
|
||||
|
|
@ -319,7 +319,7 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
};
|
||||
var gunItem = shooter.Equipment.Single(e => e.Behaviors.Any(b => b is Weapon));
|
||||
var lockWeapon = new LockWeapon(lockWeaponData, gunItem);
|
||||
shooter.Target.Value = target;
|
||||
shooter.SetTarget(target);
|
||||
|
||||
lockWeapon.Execute(1f);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,9 +77,23 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
public Zone Zone;
|
||||
public HullData Hull;
|
||||
public GearData Eye;
|
||||
public ZonePack Pack;
|
||||
public List<CultRecordKey> Belts = new List<CultRecordKey>();
|
||||
public List<FieldKindData> Kinds = new List<FieldKindData>();
|
||||
}
|
||||
|
||||
private Scene BuildScene()
|
||||
// A belt around the sun: its chunks orbit the origin at their own distances, so at zone time 0 a chunk of
|
||||
// phase p sits at distance × (cos 2πp, sin 2πp). `kind` null leaves the belt kindless, for the zone to assign.
|
||||
private sealed class BeltSpec
|
||||
{
|
||||
public Asteroid[] Asteroids;
|
||||
public FieldKindData Kind;
|
||||
}
|
||||
|
||||
private static Asteroid Rock(float distance, float phase = 0f, float size = .5f) =>
|
||||
new Asteroid { Distance = distance, Phase = phase, Size = size, RotationSpeed = .1f };
|
||||
|
||||
private Scene BuildScene(FieldKindData[] kinds = null, params BeltSpec[] belts)
|
||||
{
|
||||
var dir = Path.Combine(_root, $"scene{_fixtureCount++}");
|
||||
Directory.CreateDirectory(dir);
|
||||
|
|
@ -101,6 +115,7 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
PingCooldown = Constant(4f)
|
||||
});
|
||||
cache.Upsert(eye);
|
||||
foreach (var kind in kinds ?? new FieldKindData[0]) cache.Upsert(kind);
|
||||
var items = new ItemManager(cache, new ProvenanceLedger(), GameSettings(), _ => { });
|
||||
|
||||
var sunOrbit = cache.Upsert(new OrbitData()).Key;
|
||||
|
|
@ -113,8 +128,35 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
Mass = 10000f,
|
||||
Time = 0
|
||||
};
|
||||
var zone = new Zone(items, PlanetSettings(), pack, new GalaxyZone { Name = "MiningCut3", Owner = null }, null);
|
||||
return new Scene { Cache = cache, Items = items, Zone = zone, Hull = hull, Eye = eye };
|
||||
var scene = new Scene { Cache = cache, Items = items, Hull = hull, Eye = eye, Pack = pack };
|
||||
scene.Kinds.AddRange(kinds ?? new FieldKindData[0]);
|
||||
foreach (var spec in belts)
|
||||
{
|
||||
var beltOrbit = cache.Upsert(new OrbitData { Parent = new CultRecordRef<OrbitData>(sunOrbit), Distance = 150f }).Key;
|
||||
var belt = new AsteroidBeltData { Orbit = new CultRecordRef<OrbitData>(beltOrbit), Asteroids = spec.Asteroids };
|
||||
if (spec.Kind != null) belt.Kind = cache.RefOf(spec.Kind);
|
||||
var key = cache.Upsert(belt).Key;
|
||||
pack.Orbits.Add(new CultRecordRef<OrbitData>(beltOrbit));
|
||||
pack.Planets.Add(new CultRecordRef<BodyData>(key));
|
||||
scene.Belts.Add(key);
|
||||
}
|
||||
scene.Zone = new Zone(items, PlanetSettings(), pack, new GalaxyZone { Name = "MiningCut3", Owner = null }, null);
|
||||
return scene;
|
||||
}
|
||||
|
||||
private static FieldKindData Kind(string name, float crossSection, float weight = 1f) =>
|
||||
new FieldKindData { Name = name, CrossSection = crossSection, GenerationWeight = weight };
|
||||
|
||||
private static BeltSpec Belt(FieldKindData kind, params Asteroid[] asteroids) => new BeltSpec { Kind = kind, Asteroids = asteroids };
|
||||
|
||||
// A chunk's planar position now (zone time never advances in these tests).
|
||||
private static float2 At(Scene s, ChunkId chunk) => s.Zone.ChunkPose(chunk.Field, chunk.Index).xy;
|
||||
|
||||
// The rule as the map states it: kind cross-section × area in schematic cells (cell 2) × the light on it.
|
||||
private static float ExpectedVisibility(Scene s, ChunkId chunk, FieldKindData kind)
|
||||
{
|
||||
var cells = s.Zone.ChunkRadius(chunk) / 2f;
|
||||
return kind.CrossSection * PI * cells * cells * s.Zone.GetLight(At(s, chunk));
|
||||
}
|
||||
|
||||
private static GearData Gear(string name, BehaviorData behavior) => new GearData
|
||||
|
|
@ -132,8 +174,9 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
};
|
||||
|
||||
// A ship held at a planar position, facing +z. `sensor` fits the scene's sensor; `crossSection` fits a
|
||||
// reflector of that cross-section (its own design, so ships in one scene can differ).
|
||||
private Ship SpawnShip(Scene s, float2 at, bool sensor = false, float crossSection = 0f)
|
||||
// reflector of that cross-section (its own design, so ships in one scene can differ); each of `weaponRanges`
|
||||
// fits a gun of that range.
|
||||
private Ship SpawnShip(Scene s, float2 at, bool sensor = false, float crossSection = 0f, params float[] weaponRanges)
|
||||
{
|
||||
var ship = new Ship(s.Items, s.Zone, Mint(s, s.Hull), new EntitySettings());
|
||||
if (sensor) Assert.True(ship.TryEquip(Mint(s, s.Eye)));
|
||||
|
|
@ -143,6 +186,12 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
s.Cache.Upsert(mirror);
|
||||
Assert.True(ship.TryEquip(Mint(s, mirror)));
|
||||
}
|
||||
foreach (var range in weaponRanges)
|
||||
{
|
||||
var gun = Gear($"Gun {range}", new InstantWeaponData { Range = Constant(range) });
|
||||
s.Cache.Upsert(gun);
|
||||
Assert.True(ship.TryEquip(Mint(s, gun)));
|
||||
}
|
||||
s.Zone.Entities.Add(ship);
|
||||
Hold(ship, at);
|
||||
ship.LookDirection = float3(0, 0, 1);
|
||||
|
|
@ -202,4 +251,416 @@ public sealed class MiningCut3Tests : IDisposable
|
|||
var hash = Convert.ToHexString(SHA256.HashData(trace.ToArray()));
|
||||
Assert.True(hash == Golden, $"the EntityInfoGathered trace changed: hash {hash}");
|
||||
}
|
||||
|
||||
// Q14 A's parity: one rule, two integrators. A ship carrying a reflector of the chunk's own cross-section
|
||||
// (the kind's per-cell reflectivity × the chunk's area in cells), held still where the chunk is, settles under
|
||||
// the per-tick loop at the value ChunkInfo returns on demand. The discrete loop's fixed point sits one decay
|
||||
// step below the continuous one, exactly: x* (1 - k dt). The observer is off the sensor's axis, so the
|
||||
// bearing term is live.
|
||||
[Fact]
|
||||
public void ChunkInfoMatchesAnEntityHeldStill()
|
||||
{
|
||||
var kind = Kind("Asteroid", 1f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f)));
|
||||
var chunk = new ChunkId(s.Belts[0], 0);
|
||||
var chunkAt = At(s, chunk);
|
||||
var eyeAt = float2(50, -150);
|
||||
var observer = SpawnShip(s, eyeAt, sensor: true);
|
||||
var cells = s.Zone.ChunkRadius(chunk) / 2f;
|
||||
var rock = SpawnShip(s, chunkAt, crossSection: kind.CrossSection * PI * cells * cells);
|
||||
|
||||
for (var tick = 0; tick < 600; tick++) Tick((rock, chunkAt), (observer, eyeAt));
|
||||
|
||||
var settled = observer.ChunkInfo(chunk);
|
||||
var perTick = observer.EntityInfoGathered[rock];
|
||||
Assert.InRange(settled, .12f, .9f); // visible, unsaturated: the balance, not the cap, decides it
|
||||
var discrete = settled * (1f - GameSettings().TargetInfoDecay * Dt);
|
||||
Assert.True(abs(perTick - discrete) <= 1e-3f * settled,
|
||||
$"per-tick loop settled at {perTick}, the on-demand value implies {discrete} (settled {settled})");
|
||||
}
|
||||
|
||||
// A chunk outside every sun's light is dark: no visibility, no info, and it cannot be picked, while a lit
|
||||
// chunk of the same belt and kind can.
|
||||
[Fact]
|
||||
public void AChunkInDarknessIsNotVisible()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f), Rock(700f, .5f)));
|
||||
var lit = new ChunkId(s.Belts[0], 0);
|
||||
var dark = new ChunkId(s.Belts[0], 1);
|
||||
Assert.Equal(0f, s.Zone.GetLight(At(s, dark)));
|
||||
|
||||
var inTheDark = SpawnShip(s, At(s, dark) + float2(0, -30), sensor: true, weaponRanges: 300f);
|
||||
Tick((inTheDark, At(s, dark) + float2(0, -30)));
|
||||
Assert.Equal(0f, s.Zone.ChunkVisibility(dark));
|
||||
Assert.Equal(0f, inTheDark.ChunkInfo(dark));
|
||||
Assert.False(inTheDark.SetTarget(dark));
|
||||
Assert.True(inTheDark.Target.Value.IsNone);
|
||||
var reachable = new List<ChunkId>();
|
||||
inTheDark.VisibleChunksInReach(reachable);
|
||||
Assert.DoesNotContain(dark, reachable);
|
||||
|
||||
var inTheLight = SpawnShip(s, At(s, lit) + float2(0, -30), sensor: true);
|
||||
Assert.True(inTheLight.SetTarget(lit));
|
||||
Assert.True(inTheLight.Target.Value.Equals(new TargetRef(lit)));
|
||||
}
|
||||
|
||||
// Visibility is the kind's reflectivity × the chunk's area in cells × the light on it: linear in
|
||||
// cross-section, quadratic in radius, linear in light. Info follows visibility, so a brighter chunk is seen
|
||||
// further off.
|
||||
[Fact]
|
||||
public void ABrighterOrBiggerChunkIsSeenFurther()
|
||||
{
|
||||
var dim = Kind("Dim", 1f);
|
||||
var bright = Kind("Bright", 2f);
|
||||
var s = BuildScene(new[] { dim, bright },
|
||||
Belt(dim, Rock(150f, 0f, .2f), Rock(150f, .25f, .8f), Rock(250f, .5f, .2f)),
|
||||
Belt(bright, Rock(150f, 0f, .2f)));
|
||||
var small = new ChunkId(s.Belts[0], 0);
|
||||
var big = new ChunkId(s.Belts[0], 1);
|
||||
var far = new ChunkId(s.Belts[0], 2);
|
||||
var brightTwin = new ChunkId(s.Belts[1], 0);
|
||||
|
||||
foreach (var (chunk, kind) in new[] { (small, dim), (big, dim), (far, dim), (brightTwin, bright) })
|
||||
Assert.Equal(ExpectedVisibility(s, chunk, kind), s.Zone.ChunkVisibility(chunk), 4);
|
||||
|
||||
var vSmall = s.Zone.ChunkVisibility(small);
|
||||
Assert.Equal(2f, s.Zone.ChunkVisibility(brightTwin) / vSmall, 4);
|
||||
var radiusRatio = s.Zone.ChunkRadius(big) / s.Zone.ChunkRadius(small);
|
||||
Assert.True(radiusRatio > 1.5f);
|
||||
Assert.Equal(radiusRatio * radiusRatio, s.Zone.ChunkVisibility(big) / vSmall, 3);
|
||||
var lightRatio = s.Zone.GetLight(At(s, far)) / s.Zone.GetLight(At(s, small));
|
||||
Assert.InRange(lightRatio, .01f, .9f);
|
||||
Assert.Equal(lightRatio, s.Zone.ChunkVisibility(far) / vSmall, 3);
|
||||
|
||||
// Seen further: from 180 away the dim twin is below the detection threshold and the bright one above it.
|
||||
var eyeAt = At(s, small) + float2(0, -180);
|
||||
var observer = SpawnShip(s, eyeAt, sensor: true);
|
||||
Tick((observer, eyeAt));
|
||||
Assert.Equal(2f, observer.ChunkInfo(brightTwin) / observer.ChunkInfo(small), 3);
|
||||
Assert.False(observer.ChunkVisible(small));
|
||||
Assert.True(observer.ChunkVisible(brightTwin));
|
||||
}
|
||||
|
||||
// A worn chunk shrinks, so it dims by exactly its smaller area; a broken chunk has no size and is dark.
|
||||
[Fact]
|
||||
public void AWornChunkDims()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f)));
|
||||
var chunk = new ChunkId(s.Belts[0], 0);
|
||||
var whole = s.Zone.ChunkVisibility(chunk);
|
||||
var hitpoints = PlanetSettings().AsteroidHitpoints.Evaluate(.5f);
|
||||
|
||||
Assert.False(s.Zone.Wear(chunk, hitpoints * .5f));
|
||||
var worn = s.Zone.ChunkVisibility(chunk);
|
||||
Assert.InRange(worn, whole * .05f, whole * .95f);
|
||||
Assert.Equal(ExpectedVisibility(s, chunk, kind), worn, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ABrokenChunkIsInvisible()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f)));
|
||||
var chunk = new ChunkId(s.Belts[0], 0);
|
||||
var eyeAt = At(s, chunk) + float2(0, -100);
|
||||
var observer = SpawnShip(s, eyeAt, sensor: true);
|
||||
Assert.True(observer.ChunkVisible(chunk));
|
||||
|
||||
Assert.True(s.Zone.Wear(chunk, PlanetSettings().AsteroidHitpoints.Evaluate(.5f) * 2f));
|
||||
Assert.Equal(0f, s.Zone.ChunkVisibility(chunk));
|
||||
Assert.Equal(0f, observer.ChunkInfo(chunk));
|
||||
Assert.False(observer.SetTarget(chunk));
|
||||
}
|
||||
|
||||
// Q13 A: the reach for offering a chunk is the longest range among the entity's ACTIVE weapons. Two visible
|
||||
// chunks, 200 and about 300 away; guns of 120, 250 and 350, the last switched off.
|
||||
[Fact]
|
||||
public void CyclingReachIsTheLongestActiveWeaponRange()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind },
|
||||
Belt(kind, Rock(150f), Rock(length(float2(150, 100)), atan2(100f, 150f) / (2 * PI))));
|
||||
var near = new ChunkId(s.Belts[0], 0);
|
||||
var farther = new ChunkId(s.Belts[0], 1);
|
||||
var eyeAt = float2(150, -200);
|
||||
var observer = SpawnShip(s, eyeAt, sensor: true, weaponRanges: new[] { 120f, 250f, 350f });
|
||||
Tick((observer, eyeAt)); // weapons read their ranges when they run
|
||||
Assert.Equal(200f, length(At(s, near) - eyeAt), 2);
|
||||
Assert.Equal(300f, length(At(s, farther) - eyeAt), 2);
|
||||
Assert.True(observer.ChunkVisible(near));
|
||||
Assert.True(observer.ChunkVisible(farther));
|
||||
|
||||
EquippedItem Gun(float range) => observer.Equipment.Single(item => item.Data.Name == $"Gun {range}");
|
||||
var offered = new List<ChunkId>();
|
||||
|
||||
Gun(350f).Enabled.Value = false;
|
||||
observer.VisibleChunksInReach(offered);
|
||||
Assert.Equal(new[] { near }, offered);
|
||||
|
||||
Gun(250f).Enabled.Value = false;
|
||||
observer.VisibleChunksInReach(offered);
|
||||
Assert.Empty(offered);
|
||||
|
||||
Gun(350f).Enabled.Value = true;
|
||||
observer.VisibleChunksInReach(offered);
|
||||
Assert.Equal(2, offered.Count);
|
||||
Assert.Contains(near, offered);
|
||||
Assert.Contains(farther, offered);
|
||||
}
|
||||
|
||||
// The chunk query returns exactly the chunks within range, from inside the belt's hole, from within the
|
||||
// annulus and from outside it -- the belt skip never drops a chunk the brute-force answer would keep -- and it
|
||||
// leaves out a broken chunk.
|
||||
[Fact]
|
||||
public void TheChunkQueryFindsExactlyTheChunksInRange()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var rocks = Enumerable.Range(0, 12).Select(i => Rock(200f + i * 15f, i / 12f)).ToArray();
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, rocks));
|
||||
var belt = s.Belts[0];
|
||||
Assert.True(s.Zone.Wear(new ChunkId(belt, 5), 1e6f)); // broken
|
||||
|
||||
var found = new List<ChunkId>();
|
||||
var sawSome = false;
|
||||
foreach (var (from, range) in new[]
|
||||
{
|
||||
(float2(0, 0), 150f), (float2(0, 0), 230f), (float2(0, 0), 400f),
|
||||
(float2(220, 0), 40f), (float2(-300, 50), 120f), (float2(600, 0), 360f), (float2(600, 0), 200f)
|
||||
})
|
||||
{
|
||||
s.Zone.ChunksNear(from, range, found);
|
||||
var expected = Enumerable.Range(0, rocks.Length)
|
||||
.Where(i => i != 5 && length(At(s, new ChunkId(belt, i)) - from) <= range)
|
||||
.Select(i => new ChunkId(belt, i)).ToArray();
|
||||
Assert.Equal(expected, found);
|
||||
sawSome |= expected.Length > 0;
|
||||
}
|
||||
Assert.True(sawSome);
|
||||
}
|
||||
|
||||
// The negative for Activate's "still tracked" reconciliation (Entity.Activate) and the per-tick lost-track
|
||||
// check: a visible chunk target survives ticks and a dock/undock, and reads its range through the chunk.
|
||||
[Fact]
|
||||
public void AChunkTargetSurvivesTheInfoPassWhileSeen()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f)));
|
||||
var chunk = new ChunkId(s.Belts[0], 0);
|
||||
var eyeAt = At(s, chunk) + float2(30, -100);
|
||||
var observer = SpawnShip(s, eyeAt, sensor: true);
|
||||
Assert.True(observer.SetTarget(chunk));
|
||||
|
||||
for (var tick = 0; tick < 5; tick++) Tick((observer, eyeAt));
|
||||
Assert.True(observer.Target.Value.Equals(new TargetRef(chunk)));
|
||||
Assert.Equal(length(float2(30, -100)), observer.TargetRange, 3);
|
||||
|
||||
observer.Deactivate();
|
||||
observer.Activate();
|
||||
Assert.True(observer.Target.Value.Equals(new TargetRef(chunk)));
|
||||
}
|
||||
|
||||
// The lost-track rule through the chunk path: a chunk target is dropped once this entity cannot see it --
|
||||
// on the next tick, or at Activate when it went dark while docked.
|
||||
[Fact]
|
||||
public void AChunkTargetIsDroppedWhenItGoesDark()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f), Rock(150f, .25f), Rock(150f, .5f)));
|
||||
var eyeAt = float2(0, 0);
|
||||
|
||||
// Its own sensor goes off: nothing sees the chunk, and the next tick drops it.
|
||||
var blinded = SpawnShip(s, eyeAt, sensor: true);
|
||||
var first = new ChunkId(s.Belts[0], 0);
|
||||
Assert.True(blinded.SetTarget(first));
|
||||
blinded.Equipment.Single(item => item.Data.Name == "Eye").Enabled.Value = false;
|
||||
Tick((blinded, eyeAt));
|
||||
Assert.True(blinded.Target.Value.IsNone);
|
||||
|
||||
// The chunk breaks: it is dark to everyone, and the next tick drops it.
|
||||
var watcher = SpawnShip(s, eyeAt, sensor: true);
|
||||
var second = new ChunkId(s.Belts[0], 1);
|
||||
Assert.True(watcher.SetTarget(second));
|
||||
Tick((watcher, eyeAt));
|
||||
Assert.False(watcher.Target.Value.IsNone);
|
||||
Assert.True(s.Zone.Wear(second, 1e6f));
|
||||
Tick((watcher, eyeAt));
|
||||
Assert.True(watcher.Target.Value.IsNone);
|
||||
|
||||
// It breaks while the holder is docked: Activate drops it before any tick runs.
|
||||
var docked = SpawnShip(s, eyeAt, sensor: true);
|
||||
var third = new ChunkId(s.Belts[0], 2);
|
||||
Assert.True(docked.SetTarget(third));
|
||||
docked.Deactivate();
|
||||
Assert.True(s.Zone.Wear(third, 1e6f));
|
||||
docked.Activate();
|
||||
Assert.True(docked.Target.Value.IsNone);
|
||||
}
|
||||
|
||||
// One slot, two kinds, value equality: the same chunk is the same target, a chunk is never an entity, and an
|
||||
// empty target is None whichever way it was made.
|
||||
[Fact]
|
||||
public void TargetRefEquality()
|
||||
{
|
||||
var s = BuildScene();
|
||||
var ship = SpawnShip(s, float2(0, 0));
|
||||
var other = SpawnShip(s, float2(10, 0));
|
||||
var field = new CultRecordKey("field");
|
||||
var chunk = new ChunkId(field, 3);
|
||||
|
||||
Assert.True(new TargetRef(chunk).Equals(new TargetRef(new ChunkId(new CultRecordKey("field"), 3))));
|
||||
Assert.Equal(new TargetRef(chunk).GetHashCode(), new TargetRef(new ChunkId(new CultRecordKey("field"), 3)).GetHashCode());
|
||||
Assert.False(new TargetRef(chunk).Equals(new TargetRef(new ChunkId(field, 4))));
|
||||
Assert.False(new TargetRef(chunk).Equals(new TargetRef(new ChunkId(new CultRecordKey("other"), 3))));
|
||||
|
||||
Assert.True(new TargetRef(ship).Equals(new TargetRef(ship)));
|
||||
Assert.False(new TargetRef(ship).Equals(new TargetRef(other)));
|
||||
Assert.False(new TargetRef(ship).Equals(new TargetRef(chunk)));
|
||||
Assert.False(new TargetRef(chunk).Equals(new TargetRef(ship)));
|
||||
Assert.False(new TargetRef(ship).Equals(TargetRef.None));
|
||||
|
||||
Assert.True(TargetRef.None.IsNone);
|
||||
Assert.True(new TargetRef((Entity) null).IsNone);
|
||||
Assert.True(new TargetRef((Entity) null).Equals(TargetRef.None));
|
||||
Assert.False(new TargetRef(default(ChunkId)).IsNone);
|
||||
Assert.False(new TargetRef(default(ChunkId)).Equals(TargetRef.None));
|
||||
Assert.False(new TargetRef(ship).IsNone);
|
||||
Assert.True(((object) new TargetRef(chunk)).Equals(new TargetRef(chunk)));
|
||||
}
|
||||
|
||||
// Q12 A: a launcher never locks a chunk. The same lock weapon, geometry and detection build lock on a
|
||||
// hostile ship; switched to a chunk, the lock drops to zero and stays there.
|
||||
[Fact]
|
||||
public void ChunkTargetIsNeverLocked()
|
||||
{
|
||||
var kind = Kind("Asteroid", 4f);
|
||||
var s = BuildScene(new[] { kind }, Belt(kind, Rock(150f)));
|
||||
var chunk = new ChunkId(s.Belts[0], 0);
|
||||
var eyeAt = At(s, chunk) + float2(0, -100);
|
||||
var shooter = SpawnShip(s, eyeAt, sensor: true, weaponRanges: 300f);
|
||||
var enemy = SpawnShip(s, eyeAt + float2(0, 50));
|
||||
shooter.SetIff(enemy, true);
|
||||
shooter.EntityInfoGathered[enemy] = 1;
|
||||
shooter.LookDirection = float3(0, 0, 1);
|
||||
var launcher = new LockWeapon(new LockWeaponData
|
||||
{
|
||||
LockSpeed = Constant(.5f),
|
||||
LockAngle = Constant(180f),
|
||||
DirectionImpact = Constant(1f)
|
||||
}, shooter.Equipment.Single(item => item.Behaviors.Any(b => b is Weapon)));
|
||||
|
||||
Assert.True(shooter.SetTarget(enemy));
|
||||
launcher.Execute(1f);
|
||||
Assert.True(launcher.Lock > 0f, "positive control: the launcher locks a hostile ship");
|
||||
|
||||
Assert.True(shooter.SetTarget(chunk));
|
||||
launcher.Execute(1f);
|
||||
Assert.Equal(0f, launcher.Lock);
|
||||
launcher.Execute(1f);
|
||||
Assert.Equal(0f, launcher.Lock);
|
||||
}
|
||||
|
||||
// Q16 B, the pick itself: a weighted choice by the belt's key -- the same key always gives the same kind, a
|
||||
// kind of weight zero is never chosen, and the others come up in proportion to their weights.
|
||||
[Fact]
|
||||
public void FieldKindAssignmentIsAWeightedPickByKey()
|
||||
{
|
||||
var light = Kind("Light", 1f, 1f);
|
||||
var never = Kind("Never", 1f, 0f);
|
||||
var heavy = Kind("Heavy", 1f, 3f);
|
||||
var s = BuildScene(new[] { light, never, heavy });
|
||||
var counts = new Dictionary<string, int> { ["Light"] = 0, ["Never"] = 0, ["Heavy"] = 0 };
|
||||
for (var i = 0; i < 2000; i++)
|
||||
{
|
||||
var key = new CultRecordKey($"belt-{i}");
|
||||
var picked = FieldKinds.Assign(key, s.Cache);
|
||||
Assert.True(picked.Key.Equals(FieldKinds.Assign(key, s.Cache).Key));
|
||||
counts[s.Cache.Get(picked).Name]++;
|
||||
}
|
||||
Assert.Equal(0, counts["Never"]);
|
||||
Assert.InRange(counts["Heavy"] / 2000f, .7f, .8f);
|
||||
|
||||
var empty = BuildScene(new[] { never });
|
||||
Assert.False(FieldKinds.Assign(new CultRecordKey("belt-0"), empty.Cache).IsSet());
|
||||
}
|
||||
|
||||
// Q16 B, first load: a belt saved before field kinds existed gets its kind when a zone first loads it, by the
|
||||
// same function generation uses, and the assignment is saved -- so a later catalog edit that would pick a
|
||||
// different kind for that belt changes nothing about it.
|
||||
[Fact]
|
||||
public void FieldKindAssignmentIsOneFunction()
|
||||
{
|
||||
var a = Kind("A", 1f, 1f);
|
||||
var b = Kind("B", 2f, 1f);
|
||||
var s = BuildScene(new[] { a, b }, Belt(null, Rock(150f)));
|
||||
var beltKey = s.Belts[0];
|
||||
var belt = (AsteroidBeltData) s.Zone.Planets[beltKey];
|
||||
Assert.True(belt.Kind.IsSet());
|
||||
Assert.True(belt.Kind.Key.Equals(FieldKinds.Assign(beltKey, s.Cache).Key));
|
||||
var assigned = belt.Kind.Key;
|
||||
|
||||
// Saved: a fresh open of the same stores reads the kind back.
|
||||
s.Cache.FlushAsync().Wait();
|
||||
s.Cache.Dispose();
|
||||
_caches.Remove(s.Cache);
|
||||
var dir = Path.Combine(_root, $"scene{_fixtureCount - 1}");
|
||||
var reopened = AetheriaStores.Open(Path.Combine(dir, "Aetheria.cc"), Path.Combine(dir, "run.cc"), catalogWritable: true);
|
||||
_caches.Add(reopened);
|
||||
Assert.True(((AsteroidBeltData) reopened.Get(beltKey)).Kind.Key.Equals(assigned));
|
||||
|
||||
// Kept: a new, overwhelmingly weighted kind now wins the pick for this belt, yet loading it again leaves it.
|
||||
reopened.Upsert(Kind("Overwhelming", 9f, 1e6f));
|
||||
Assert.False(FieldKinds.Assign(beltKey, reopened).Key.Equals(assigned));
|
||||
var items = new ItemManager(reopened, new ProvenanceLedger(), GameSettings(), _ => { });
|
||||
var reloaded = new Zone(items, PlanetSettings(), s.Pack, new GalaxyZone { Name = "MiningCut3Reload", Owner = null }, null);
|
||||
Assert.True(((AsteroidBeltData) reloaded.Planets[beltKey]).Kind.Key.Equals(assigned));
|
||||
}
|
||||
|
||||
// Q16 B, generation: every belt ZoneGenerator makes carries its kind already, chosen by FieldKinds.Assign on
|
||||
// the belt's own key. Runs against a scratch copy of the shipped catalog with three kinds of different
|
||||
// weights, so a pick by any other rule would disagree on some belt.
|
||||
[Fact]
|
||||
public void GenerationChoosesTheKindByTheSameFunction()
|
||||
{
|
||||
var shipped = Path.Combine(RestoredHullsTests.FindRepoRoot(), "GameData", "Aetheria.cc");
|
||||
var belts = 0;
|
||||
for (uint seed = 1; seed <= 25 && belts < 3; seed++)
|
||||
{
|
||||
var dir = Path.Combine(_root, $"gen{seed}");
|
||||
Directory.CreateDirectory(dir);
|
||||
var catalog = Path.Combine(dir, "Aetheria.cc");
|
||||
File.Copy(shipped, catalog);
|
||||
using var cache = AetheriaStores.Open(catalog, Path.Combine(dir, "run.cc"), catalogWritable: true);
|
||||
foreach (var existing in cache.GetAll<FieldKindData>().ToArray())
|
||||
{
|
||||
existing.GenerationWeight = 0f;
|
||||
cache.Upsert(existing);
|
||||
}
|
||||
cache.Upsert(Kind("Gen A", 1f, 1f));
|
||||
cache.Upsert(Kind("Gen B", 1f, 2f));
|
||||
cache.Upsert(Kind("Gen C", 1f, 4f));
|
||||
|
||||
Galaxy galaxy;
|
||||
try
|
||||
{
|
||||
galaxy = new Galaxy(RestoredHullsTests.TutorialGalaxySettings(), RestoredHullsTests.TutorialBackgroundSettings(),
|
||||
RestoredHullsTests.TutorialNameSettings(), cache, new PlayerSettings(), new DirectoryInfo(dir), _ => { }, null, seed);
|
||||
}
|
||||
catch (Exception) { continue; } // Galaxy's own seed-dependent flakiness (RestoredHullsTests)
|
||||
var items = new ItemManager(cache, new ProvenanceLedger(), GameSettings(), _ => { });
|
||||
foreach (var zone in galaxy.Zones.Take(4))
|
||||
{
|
||||
var pack = ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), galaxy, zone, isTutorial: zone == galaxy.Entrance);
|
||||
foreach (var body in pack.Planets)
|
||||
{
|
||||
if (!(cache.Get(body) is AsteroidBeltData belt)) continue;
|
||||
belts++;
|
||||
Assert.True(belt.Kind.IsSet());
|
||||
Assert.True(belt.Kind.Key.Equals(FieldKinds.Assign(body.Key, cache).Key));
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(belts > 0, "no seed generated a belt; the generation path went unexercised");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public sealed class RestoredHullsTests
|
|||
return cache;
|
||||
}
|
||||
|
||||
private static string FindRepoRoot()
|
||||
internal static string FindRepoRoot()
|
||||
{
|
||||
for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir != null; dir = dir.Parent)
|
||||
if (File.Exists(Path.Combine(dir.FullName, "Aetheria.Shared", "Aetheria.Shared.csproj")))
|
||||
|
|
@ -59,7 +59,7 @@ public sealed class RestoredHullsTests
|
|||
// Shared tutorial-galaxy construction settings (Assets/Resources/Settings.asset's own values), factored out
|
||||
// so every test that needs a real tutorial Galaxy -- not just EntranceZoneAlwaysGetsADockedStationAcrossSeeds
|
||||
// -- builds it the same way instead of re-inlining the same ~20 fields.
|
||||
private static ZoneGenerationSettings TutorialZoneSettings() => new ZoneGenerationSettings
|
||||
internal static ZoneGenerationSettings TutorialZoneSettings() => new ZoneGenerationSettings
|
||||
{
|
||||
PlanetSafetyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 2.5f, Constant = 0 },
|
||||
MassFloor = 1, SunMass = 5000, GasGiantMass = 1000, PlanetMass = 100,
|
||||
|
|
@ -80,19 +80,19 @@ public sealed class RestoredHullsTests
|
|||
NameData = new string[0],
|
||||
};
|
||||
|
||||
private static TutorialGenerationSettings TutorialGalaxySettings() => new TutorialGenerationSettings
|
||||
internal static TutorialGenerationSettings TutorialGalaxySettings() => new TutorialGenerationSettings
|
||||
{
|
||||
ProtagonistFaction = "Miss", AntagonistFaction = "Zhe", BufferFaction = "Luc",
|
||||
NeutralFactions = new[] { "Aero", "Finch" }, QuestFaction = "Adras", LinkDensity = .5f, ZoneCount = 64,
|
||||
};
|
||||
|
||||
private static SectorBackgroundSettings TutorialBackgroundSettings() => new SectorBackgroundSettings
|
||||
internal static SectorBackgroundSettings TutorialBackgroundSettings() => new SectorBackgroundSettings
|
||||
{
|
||||
NoiseAmplitude = 1, NoiseOffset = .3f, NoiseGain = .7f, NoiseLacunarity = 2, NoiseFrequency = .1f,
|
||||
NoisePosition = 536.5106f, CloudExponent = 10, CloudAmplitude = .01f,
|
||||
};
|
||||
|
||||
private static NameGeneratorSettings TutorialNameSettings() =>
|
||||
internal static NameGeneratorSettings TutorialNameSettings() =>
|
||||
new NameGeneratorSettings { NameGeneratorMinLength = 5, NameGeneratorMaxLength = 10, NameGeneratorOrder = 3 };
|
||||
|
||||
// A station's orbit is a copy of its source planet's own (Parent, Distance) (ZoneGenerator.CreateLagrangeOrbit),
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ public sealed class TargetingSystemTests : IDisposable
|
|||
{
|
||||
var (items, target, weapon, _, _, _) = BuildTarget(TestSettings());
|
||||
var observer = BuildObserver(items, target.Zone);
|
||||
observer.Target.Value = target;
|
||||
observer.SetTarget(target);
|
||||
|
||||
observer.EntityInfoGathered[target] = .29f; // below the single item's own tier (Armor, N==1)
|
||||
Assert.False(observer.TrySelectTargetItem(weapon));
|
||||
|
|
@ -186,12 +186,12 @@ public sealed class TargetingSystemTests : IDisposable
|
|||
Assert.Same(weapon, observer.ResolvedTargetItem);
|
||||
|
||||
// A Target change nulls the aim point.
|
||||
observer.Target.Value = null;
|
||||
observer.SetTarget(TargetRef.None);
|
||||
Assert.Null(observer.TargetItem.Value);
|
||||
|
||||
// Decay: re-select, then let info fall back below tier without touching TargetItem.Value at all --
|
||||
// the raw field still holds the item (no loop cleared it), but the read accessor drops it.
|
||||
observer.Target.Value = target;
|
||||
observer.SetTarget(target);
|
||||
Assert.True(observer.TrySelectTargetItem(weapon));
|
||||
observer.EntityInfoGathered[target] = .1f;
|
||||
Assert.Same(weapon, observer.TargetItem.Value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue