Mines in the sim: a mine layer lays a free-floating mine body in Zone
MineLayerData (union 40) lays through InstantWeapon -> FireControl.Fire -> Lay; Zone.Mines steps each mine as a KinematicBody after the entity loop, arms it, triggers it on a hostile hull its blast disc touches (FireControl.Touches, the coverage Detonate uses) and detonates it through FireControl.Detonate at the fuse delay or lifetime. Hostile trigger, faction-blind blast, no owner leash. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9f8b3f4536
commit
23aa848315
8 changed files with 782 additions and 2 deletions
|
|
@ -186,6 +186,7 @@ public interface IPowerConsumer
|
|||
// Cut 2 (docs/fire-control-cut.md): 39 is the next free index against this list, not the 39 the
|
||||
// superseded draft quoted -- checked directly here rather than trusted from that document.
|
||||
Union(39, typeof(TargetingSystemData)),
|
||||
Union(40, typeof(MineLayerData)),
|
||||
JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
27
Assets/Scripts/ServerShared/Behaviors/MineLayer.cs
Normal file
27
Assets/Scripts/ServerShared/Behaviors/MineLayer.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
// A weapon that lays a mine instead of firing a round: InstantWeapon pays for it (cooldown, ammo, energy, heat,
|
||||
// wear, visibility) and FireControl.Fire routes it to Lay. The mine's own timings live here until gear supplies
|
||||
// them (ruling missile-stats-now-gear-later). The blast radius is the item's BlastRadius, read through
|
||||
// FireControl.FuseOf like every other blast.
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class MineLayerData : InstantWeaponData
|
||||
{
|
||||
// Seconds after laying before the mine can be triggered.
|
||||
[Inspectable, JsonProperty("armingDelay"), Key(21)]
|
||||
public float ArmingDelay = 2f;
|
||||
|
||||
// Seconds from the trigger to the blast.
|
||||
[Inspectable, JsonProperty("fuseDelay"), Key(22)]
|
||||
public float FuseDelay = 2f;
|
||||
|
||||
// Seconds after laying at which an untriggered mine detonates.
|
||||
[Inspectable, JsonProperty("lifetime"), Key(23)]
|
||||
public float Lifetime = 30f;
|
||||
|
||||
public override Behavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(this, item);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/MineLayer.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/MineLayer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1cc95be85eee47c79199bea20a6d7509
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -84,14 +84,17 @@ public static class FireControl
|
|||
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);
|
||||
return FuseOf(weapon.Item, out _) != null || IsMineLayer(weapon) || 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.Entity).Outcome == FireOutcome.Refused;
|
||||
!IsMineLayer(weapon) && Solve(weapon, weapon.Item, shooter, shooter.Target.Value.Entity).Outcome == FireOutcome.Refused;
|
||||
|
||||
// A mine layer lays a body, not a round: it is never refused, never arc-gated, and Fire routes it to Lay.
|
||||
public static bool IsMineLayer(Weapon weapon) => weapon.WeaponData is MineLayerData;
|
||||
|
||||
// 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
|
||||
|
|
@ -100,6 +103,8 @@ public static class FireControl
|
|||
// never one Solve refuses: a refused weapon is not a weapon it can use.
|
||||
public static bool AgentFires(Weapon weapon, Entity shooter, Entity target)
|
||||
{
|
||||
// A mine layer lays only at a designated target in range, never at nothing and never on a hit probability.
|
||||
if (IsMineLayer(weapon)) return Solve(weapon, weapon.Item, shooter, target).Designated;
|
||||
if (FuseOf(weapon.Item, out _) == null)
|
||||
return HitProbability(weapon, shooter, target) >= shooter.ItemManager.GameplaySettings.AgentMinHitProbability;
|
||||
var solution = Solve(weapon, weapon.Item, shooter, target);
|
||||
|
|
@ -530,6 +535,11 @@ public static class FireControl
|
|||
public static int Fire(Weapon weapon, EquippedItem item, Entity source, float? damageOverride = null)
|
||||
{
|
||||
var zone = source.Zone;
|
||||
if (IsMineLayer(weapon))
|
||||
{
|
||||
Lay(weapon, item, source);
|
||||
return 0;
|
||||
}
|
||||
// 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;
|
||||
|
|
@ -596,6 +606,44 @@ public static class FireControl
|
|||
return shot.ShotId;
|
||||
}
|
||||
|
||||
// Lays a mine for a mine layer: freezes the payload as evaluated now (stats, the item's blast radius, the
|
||||
// layer and its faction) and hands the body to Zone.Lay, the one adder. It launches at the shooter's velocity
|
||||
// plus the mount direction turned by a dice angle within +-Spread/2, times Velocity; the dice are the mine's
|
||||
// own (zone seed, MineStream, body id), so no other roll is perturbed. No target, no PendingShot, no price:
|
||||
// InstantWeapon has already paid. A layer whose item has no blast radius lays nothing.
|
||||
public static void Lay(Weapon weapon, EquippedItem item, Entity source)
|
||||
{
|
||||
var zone = source.Zone;
|
||||
var data = (MineLayerData) weapon.WeaponData;
|
||||
if (FuseOf(item, out var blastRadius) == null)
|
||||
{
|
||||
zone.Log?.Invoke("A mine layer has no blast radius and lays nothing.");
|
||||
return;
|
||||
}
|
||||
|
||||
var id = zone.NextBodyId();
|
||||
var half = weapon.Spread / 2f;
|
||||
var angle = radians(SimulationDice.For(zone.CombatSeed, SimulationDice.MineStream, id.Value).NextFloat(-half, half));
|
||||
var s = sin(angle);
|
||||
var c = cos(angle);
|
||||
var mount = MountDirection(item).xz;
|
||||
var direction = float2(mount.x * c - mount.y * s, mount.x * s + mount.y * c);
|
||||
|
||||
zone.Lay(new Mine
|
||||
{
|
||||
Id = id,
|
||||
Body = new KinematicBody { Position = source.Position.xz, Velocity = source.Velocity + direction * weapon.Velocity },
|
||||
ArmingDelay = data.ArmingDelay,
|
||||
FuseDelay = data.FuseDelay,
|
||||
Lifetime = data.Lifetime,
|
||||
BlastRadius = blastRadius,
|
||||
Damage = weapon.Damage,
|
||||
DamageType = weapon.WeaponData.DamageType,
|
||||
Layer = source,
|
||||
LayerFaction = source.Faction
|
||||
});
|
||||
}
|
||||
|
||||
// Cut 3, R4: ages every shot in the zone, commits the ones that have reached their horizon and resolves
|
||||
// the ones that have arrived. Called from Zone.Update after the entity loop. A shot whose target has left
|
||||
// the zone resolves as a miss and is removed outright (0b table), whichever stage it is at. A round outlives
|
||||
|
|
@ -1405,6 +1453,19 @@ public static class FireControl
|
|||
}
|
||||
}
|
||||
|
||||
// Whether the disc reaches any occupied hull cell of the entity: Detonate's own coverage test (the same
|
||||
// ToSchematicPoint, SchematicCellSize and CircleSquareOverlap), so what triggers a mine and what its blast
|
||||
// reaches are one geometry.
|
||||
public static bool Touches(Entity entity, float2 worldPlanar, float radius)
|
||||
{
|
||||
var rCells = radius / entity.ItemManager.GameplaySettings.SchematicCellSize;
|
||||
var centre = entity.ToSchematicPoint(worldPlanar);
|
||||
var coords = (entity.ItemManager.GetData(entity.Hull) as HullData).Shape.Coordinates;
|
||||
for (var i = 0; i < coords.Length; i++)
|
||||
if (CircleSquareOverlap(centre, rCells, coords[i]) > 0f) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cut 12.4(b) (docs/fire-control-cut.md, "Exact overlap, in float"): the exact area of a unit square,
|
||||
// centred on `cell` (the unit square centred on its integer coordinate, the same convention every other
|
||||
// frame rule uses), that lies inside a disc of radius `r` centred at `diskCentre` -- both in the same
|
||||
|
|
|
|||
25
Assets/Scripts/ServerShared/Mines.cs
Normal file
25
Assets/Scripts/ServerShared/Mines.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// A laid mine: a free-floating body with a frozen payload. Not an Entity, never priced or rolled, never saved.
|
||||
// Zone.Lay is the only adder and Zone's mine step the only remover; every removal is its blast.
|
||||
public sealed class Mine
|
||||
{
|
||||
public FloatingBodyId Id;
|
||||
public KinematicBody Body;
|
||||
public double LaidAt;
|
||||
public float ArmingDelay;
|
||||
public float FuseDelay;
|
||||
public float Lifetime;
|
||||
public float BlastRadius;
|
||||
public float Damage;
|
||||
public DamageType DamageType;
|
||||
// The layer and its faction, frozen at lay (ruling mine-trigger-iff).
|
||||
public Entity Layer;
|
||||
public Faction LayerFaction;
|
||||
// Set once, when an eligible hull first touches the armed disc; the fuse counts from it.
|
||||
public double? TriggeredAt;
|
||||
|
||||
public bool Armed(double now) => now >= LaidAt + ArmingDelay;
|
||||
|
||||
// Ruling mine-trigger-iff: only an entity that is neither the layer nor of the layer's faction triggers it.
|
||||
public bool Triggers(Entity entity) =>
|
||||
entity != Layer && (LayerFaction == null || entity.Faction != LayerFaction);
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Mines.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Mines.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4aea0eb6ee234016a258266945ed2db9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -16,6 +16,10 @@ public class Zone
|
|||
{
|
||||
public Action<string> Log;
|
||||
public ReactiveCollection<Entity> Entities = new ReactiveCollection<Entity>();
|
||||
|
||||
// Laid mines, in lay order. Zone owns their existence: Lay is the one adder, the mine step the one remover,
|
||||
// and every removal is a blast. Runtime state, never saved.
|
||||
public ReactiveCollection<Mine> Mines = new ReactiveCollection<Mine>();
|
||||
public Dictionary<CultRecordKey, BodyData> Planets = new Dictionary<CultRecordKey, BodyData>();
|
||||
public Dictionary<CultRecordKey, Planet> PlanetInstances = new Dictionary<CultRecordKey, Planet>();
|
||||
|
||||
|
|
@ -219,12 +223,47 @@ public class Zone
|
|||
|
||||
foreach (var entity in Entities.ToArray()) entity.Update(deltaTime);
|
||||
|
||||
StepMines(deltaTime);
|
||||
|
||||
// Cut 3: after every entity has had its chance to fire this tick, age and resolve the shots that
|
||||
// firing queued. A shot fired this tick with a flight time shorter than CommitHorizon commits and
|
||||
// resolves in this same call.
|
||||
FireControl.Step(this, deltaTime);
|
||||
}
|
||||
|
||||
public void Lay(Mine mine)
|
||||
{
|
||||
mine.LaidAt = _time;
|
||||
Mines.Add(mine);
|
||||
}
|
||||
|
||||
// After the entity loop and before FireControl.Step, in lay order: each mine drifts as a KinematicBody, is
|
||||
// triggered by the first eligible hull its armed disc touches, and detonates through FireControl.Detonate at
|
||||
// its trigger plus fuse delay or at its lifetime, whatever its layer does (ruling mine-owner-leash). The
|
||||
// blast reads no faction; only the trigger does.
|
||||
private void StepMines(float deltaTime)
|
||||
{
|
||||
if (Mines.Count == 0) return;
|
||||
var settings = _itemManager.GameplaySettings;
|
||||
foreach (var mine in Mines.ToArray())
|
||||
{
|
||||
mine.Body.Step(deltaTime, GetForce(mine.Body.Position), settings);
|
||||
|
||||
if (mine.TriggeredAt == null && mine.Armed(_time))
|
||||
foreach (var entity in Entities.ToArray())
|
||||
if (mine.Triggers(entity) && FireControl.Touches(entity, mine.Body.Position, mine.BlastRadius))
|
||||
{
|
||||
mine.TriggeredAt = _time;
|
||||
break;
|
||||
}
|
||||
|
||||
var fused = mine.TriggeredAt + mine.FuseDelay <= _time;
|
||||
if (!fused && mine.LaidAt + mine.Lifetime > _time) continue;
|
||||
Mines.Remove(mine);
|
||||
FireControl.Detonate(this, mine.Body.Position, mine.BlastRadius, mine.Damage, mine.DamageType);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine orbital position recursively, caching parent positions to avoid repeated calculations
|
||||
public float2 GetOrbitPosition(CultRecordKey orbitID)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue