ScenarioStage: names are designs or products, one Resolve path with the generator's chooser; rigs pin today's brands; Crossing back to 1216

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-16 22:10:58 +02:00
commit 7bbaa26675
13 changed files with 114 additions and 112 deletions

View file

@ -9,11 +9,11 @@ using float3 = CultMath.float3;
// The run half of a scenario's vocabulary (docs/scenarios-cut.md, R.4). A scenario's Stage builds its fits and places
// them here; nothing joins the arena until Stage returns with no failure, and then RunStart admits it all at once.
// Every verb names what it could not do instead of throwing, so one bad name in a script lists every bad name.
// Designs and hulls are named as the catalog names them. Only RunStart builds a stage.
// Designs, hulls and products are named as the catalog names them. Only RunStart builds a stage.
public sealed class ScenarioStage
{
private readonly ItemManager _items;
private readonly Predicate<FactionProductData> _available;
private readonly Func<CraftedItemData, FactionProductData> _choose;
private readonly List<string> _failures = new List<string>();
private readonly List<Placement> _placed = new List<Placement>();
private int _placements;
@ -25,8 +25,9 @@ public sealed class ScenarioStage
StartingHull = startingHull;
TutorialGenerationSettings = tutorialGenerationSettings;
Credits = items.GameplaySettings.StartingCredits;
// A fit names designs, not manufacturers, so what the galaxy offers decides which product builds each one.
_available = new LoadoutGenerator(ref items.Random, items, arena.Galaxy, arena.GalaxyZone, null, 2).IsAvailable;
// A design named without a product is chosen by the generator's ChooseProduct. The stage outfits with no faction,
// so every maker is reachable and the run's seed draws.
_choose = new LoadoutGenerator(ref items.Random, items, arena.Galaxy, arena.GalaxyZone, null, 2).ChooseProduct;
}
public Galaxy Galaxy => Arena.Galaxy;
@ -49,18 +50,24 @@ public sealed class ScenarioStage
public bool Piloted;
}
// A hull fitted slot by slot: each slot a design, the hull cell it goes in, and its rotation.
// A hull fitted slot by slot: each slot a design or a product, the hull cell it goes in, and its rotation. A name is
// a design (open: the stage chooses its product) or a product (pinned: that brand).
public ScenarioFit Fit(string hull, params (string design, int2 cell, ItemRotation rotation)[] slots)
{
var where = $"fit {hull}";
var hullData = Named<HullData>(hull, where);
var (hullData, hullProduct) = NamedOrProduct<HullData>(hull, where);
var loadout = new Loadout { Name = hull, WeaponGroups = new int[0][] };
if (hullData != null) loadout.Hull = _items.ItemData.RefOf(hullData);
if (hullProduct != null) loadout.HullProduct = _items.ItemData.RefOf(hullProduct);
foreach (var (design, cell, rotation) in slots)
{
var data = Named<EquippableItemData>(design, where);
var (data, product) = NamedOrProduct<EquippableItemData>(design, where);
if (data == null) continue;
loadout.Slots.Add(new LoadoutSlot { Design = _items.ItemData.RefOf(data), Position = cell, Rotation = rotation });
loadout.Slots.Add(new LoadoutSlot
{
Design = _items.ItemData.RefOf(data), Position = cell, Rotation = rotation,
Product = product == null ? default : _items.ItemData.RefOf(product)
});
}
return hullData != null && loadout.Slots.Count == slots.Length ? new ScenarioFit(loadout) : null;
}
@ -119,38 +126,22 @@ public sealed class ScenarioStage
return entity;
}
// Items in the entity's first cargo bay, one per design named. A name is an equippable design (built as a fit
// builds it) or a consumable design (built from its first available product in key order, as a generated hold is
// stocked); a name that is neither is a failure.
public void Cargo(Entity entity, params string[] designs)
// Items in the entity's first cargo bay, one per name. A name is an equippable or consumable design (open: the stage
// chooses its product) or a product of one (pinned); a name that is neither is a failure.
public void Cargo(Entity entity, params string[] names)
{
if (entity == null) return;
var where = $"cargo of {entity.Name}";
var bay = entity.CargoBays.FirstOrDefault();
foreach (var design in designs)
foreach (var name in names)
{
var data = Named<CraftedItemData>(design, where, found => found is EquippableItemData || found is ConsumableItemData);
var (data, product) = NamedOrProduct<CraftedItemData>(name, where, found => found is EquippableItemData || found is ConsumableItemData);
if (data == null) continue;
Func<CraftedItemInstance> build;
if (data is ConsumableItemData)
{
var key = _items.ItemData.RefOf(data).Key;
var product = Loadouts.ProductsInKeyOrder(_items.ItemData).Where(p => p.Design.Key.Equals(key)).FirstOrDefault(p => _available(p));
if (product == null)
{
_failures.Add($"{where}: no product offers {design}");
continue;
}
build = () => _items.CreateInstance(product);
}
else
{
var equippable = Loadouts.Resolve(_items, _items.ItemData.RefOf((EquippableItemData) data), _available, where, _failures);
if (equippable == null) continue;
build = equippable;
}
var build = Loadouts.Resolve(_items, _items.ItemData.RefOf(data),
product == null ? default : _items.ItemData.RefOf(product), _choose, where, _failures);
if (build == null) continue;
if (bay == null || !bay.TryStore(build()))
_failures.Add($"{where}: no room for {design}");
_failures.Add($"{where}: no room for {name}");
}
}
@ -163,7 +154,7 @@ public sealed class ScenarioStage
else
{
var failures = new List<string>();
entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _available, failures);
entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _choose, failures);
_failures.AddRange(failures.Select(failure => $"{where} ({fit.Loadout.Name}): {failure}"));
if (entity == null) return null;
}
@ -173,6 +164,17 @@ public sealed class ScenarioStage
return entity;
}
// A name is a design, or else exactly one product (names are unique) whose design is a T passing among: the design
// and that product. Neither is Named's failure.
private (T design, FactionProductData product) NamedOrProduct<T>(string name, string where, Func<T, bool> among = null) where T : CraftedItemData
{
var cache = _items.ItemData;
var products = cache.GetAll<FactionProductData>().Where(p => p.Name == name && cache.Get(p.Design) is T design && (among == null || among(design))).Take(2).ToArray();
if (products.Length == 1 && !cache.GetAll<T>().Any(data => data.Name == name && (among == null || among(data))))
return ((T) cache.Get(products[0].Design), products[0]);
return (Named(name, where, among), null);
}
private T Named<T>(string name, string where, Func<T, bool> among = null) where T : CraftedItemData
{
var named = _items.ItemData.GetAll<T>().Where(data => data.Name == name && (among == null || among(data))).Take(2).ToArray();

View file

@ -26,8 +26,8 @@ public sealed class AiFusedDiscipline : Scenario
(weapon, int2(1, 8), None),
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise)); // Fire Control Array
stage.Player(stage.Generated("Djinni"), float2(0, 0));
stage.Place(Armed("Smoke Refused"), Hostile, facing: float2(0, -1), stance: ScenarioStance.Hostile, piloted: true);

View file

@ -30,25 +30,25 @@ public sealed class Arcs : Scenario
("Rugged Drive", int2(4, 14), CounterClockwise),
("Rugged Drive", int2(5, 14), Clockwise),
("Compact Reactor", int2(4, 4), None),
("Guided Missile Launcher", int2(2, 5), None),
("Guided Missile Launcher", int2(7, 5), None),
("Cell Blaster", int2(3, 8), None),
("Cell Blaster", int2(6, 8), None),
("GT 3K", int2(2, 5), None), // Guided Missile Launcher
("GT 3K", int2(7, 5), None), // Guided Missile Launcher
("FastBlast+-", int2(3, 8), None), // Cell Blaster
("FastBlast+-", int2(6, 8), None), // Cell Blaster
("Radiator", int2(4, 2), CounterClockwise),
("Radiator", int2(5, 2), Clockwise),
("Compact Sensor", int2(5, 10), None),
("Fire Control Array", int2(3, 6), Clockwise),
("Autocannon", int2(8, 4), Clockwise),
("Charged Scatter Blaster", int2(0, 4), CounterClockwise));
("not if i see you first", int2(5, 10), None), // Compact Sensor
("Panopticon Prime", int2(3, 6), Clockwise), // Fire Control Array
("🫳🔫", int2(8, 4), Clockwise), // Autocannon
("ChargeBlast SG", int2(0, 4), CounterClockwise)); // Charged Scatter Blaster
var turret = stage.Fit("Turret",
("Light Machine Gun", int2(1, 2), None),
("Light Machine Gun", int2(5, 2), None),
("ClearPath", int2(1, 2), None), // Light Machine Gun
("ClearPath", int2(5, 2), None), // Light Machine Gun
("Long Radiator", int2(0, 2), CounterClockwise),
("Long Radiator", int2(7, 2), Clockwise),
("Compact Reactor", int2(3, 3), None),
("Turret Control Module", int2(3, 5), None),
("Compact Sensor", int2(4, 5), None),
("Fire Control Array", int2(3, 6), None));
("not if i see you first", int2(4, 5), None), // Compact Sensor
("Panopticon Prime", int2(3, 6), None)); // Fire Control Array
stage.Player(fighter, float2(0, 0), facing: float2(0, 1));
stage.Place(stage.Bare("Longinus"), Bow);

View file

@ -26,14 +26,14 @@ public sealed class Belt : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Guided Missile Launcher", int2(5, 5), None),
("Lightning Projector", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("GT 3K", int2(5, 5), None), // Guided Missile Launcher
("DragOnBreath", int2(1, 8), None), // Lightning Projector
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise)); // Fire Control Array
// The belt is a ring about its parent's position at the belt orbit's distance. The player stands 100 m outside
// it, at the point nearest the origin, facing along the ring.

View file

@ -22,7 +22,7 @@ public sealed class Crossing : Scenario
// The waiting Djinni sits inside the Lightning Projector's arc at 80% of its Range.
public static readonly CultMath.float2 Origin = float2(724, 124);
public static readonly CultMath.float2 CrosserAt = Origin + float2(-128, 45), CrosserFacing = float2(1, 0), CrosserVelocity = float2(50, 0);
public const float ProjectorRange = 948f; // the Lightning Projector's Range in metres, 948.8 as the fit stands settled at rest (the first product of the design by key, NiteLife's Static Shock)
public const float ProjectorRange = 1216f; // the Lightning Projector's Range in metres, 1216.4 as the fit stands settled at rest
public static readonly CultMath.float2 Waiting = Origin + float2(0, ProjectorRange * .8f);
public override Galaxy Generate(GalaxyStage stage) => stage.Prelude(DemoTerminus.Cast);
@ -36,14 +36,14 @@ public sealed class Crossing : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Guided Missile Launcher", int2(5, 5), None),
("Lightning Projector", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("GT 3K", int2(5, 5), None), // Guided Missile Launcher
("DragOnBreath", int2(1, 8), None), // Lightning Projector
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise)); // Fire Control Array
stage.Player(fighter, Origin, facing: float2(0, 1));
stage.Place(stage.Generated("Djinni"), CrosserAt, facing: CrosserFacing, stance: ScenarioStance.Hostile, velocity: CrosserVelocity);

View file

@ -20,19 +20,19 @@ public sealed class Duel : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Guided Missile Launcher", int2(5, 5), None),
("Cell Blaster", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("GT 3K", int2(5, 5), None), // Guided Missile Launcher
("FastBlast+-", int2(1, 8), None), // Cell Blaster
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Capacitor", int2(1, 5), None),
("Fire Control Array", int2(1, 6), Clockwise),
("Cargo Bay", int2(2, 8), None));
("Panopticon Prime", int2(1, 6), Clockwise), // Fire Control Array
("Store-All Plus", int2(2, 8), None)); // Cargo Bay
stage.Player(fighter, float2(0, 0));
var rival = stage.Place(fighter, float2(0, 900), facing: float2(0, -1), stance: ScenarioStance.Hostile, piloted: true);
stage.Cargo(rival, "Light Laser");
stage.Cargo(rival, "Spectra");
}
}

View file

@ -35,11 +35,11 @@ public sealed class FusedRounds : Scenario
("Compact Reactor", int2(4, 4), None),
("Smoke Proximity", int2(3, 8), None),
("Smoke Delayed", int2(6, 8), None),
("Cluster Cannon", int2(5, 17), None),
("DeathCluster", int2(5, 17), None), // Cluster Cannon
("Radiator", int2(4, 2), CounterClockwise),
("Radiator", int2(5, 2), Clockwise),
("Compact Sensor", int2(5, 10), None),
("Fire Control Array", int2(3, 6), Clockwise));
("not if i see you first", int2(5, 10), None), // Compact Sensor
("Panopticon Prime", int2(3, 6), Clockwise)); // Fire Control Array
stage.Player(shooter, float2(0, 0), facing: float2(0, 1));
stage.Place(stage.Bare("Longinus"), Mid, stance: ScenarioStance.Hostile);

View file

@ -20,14 +20,14 @@ public sealed class LauncherAngles : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Swarm Rocket Pod", int2(5, 5), None),
("Cell Blaster", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("Leonid", int2(5, 5), None), // Swarm Rocket Pod
("FastBlast+-", int2(1, 8), None), // Cell Blaster
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise)); // Fire Control Array
stage.Player(launcher, float2(0, 0));
stage.Place(stage.Bare("Longinus"), float2(0, 900), facing: float2(1, 0), stance: ScenarioStance.Hostile);

View file

@ -29,16 +29,16 @@ public sealed class LockOn : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Guided Missile Launcher", int2(5, 5), None),
("Cell Blaster", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("GT 3K", int2(5, 5), None), // Guided Missile Launcher
("FastBlast+-", int2(1, 8), None), // Cell Blaster
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Capacitor", int2(1, 5), None),
("Fire Control Array", int2(1, 6), Clockwise),
("Cargo Bay", int2(2, 8), None));
("Panopticon Prime", int2(1, 6), Clockwise), // Fire Control Array
("Store-All Plus", int2(2, 8), None)); // Cargo Bay
stage.Player(fighter, float2(0, 0), facing: float2(0, 1));
stage.Place(fighter, HostileAt, facing: normalize(-HostileAt), stance: ScenarioStance.Hostile, piloted: true);

View file

@ -26,15 +26,15 @@ public sealed class Pursuit : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Mine Launcher", int2(0, 5), None),
("Swarm Rocket Pod", int2(5, 5), None),
("Cell Blaster", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("parting gift", int2(0, 5), None), // Mine Launcher
("Leonid", int2(5, 5), None), // Swarm Rocket Pod
("FastBlast+-", int2(1, 8), None), // Cell Blaster
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise),
("Cargo Bay", int2(2, 8), None));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise), // Fire Control Array
("Store-All Plus", int2(2, 8), None)); // Cargo Bay
var pursuer = stage.Fit("Longinus",
("Cockpit 2x2", int2(2, 6), None),
("Large Drive", int2(1, 0), Reversed),
@ -42,19 +42,19 @@ public sealed class Pursuit : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Compact Reactor", int2(2, 4), None),
("Guided Missile Launcher", int2(0, 5), None),
("Guided Missile Launcher", int2(5, 5), None),
("Cell Blaster", int2(1, 8), None),
("Cell Blaster", int2(4, 8), None),
("GT 3K", int2(0, 5), None), // Guided Missile Launcher
("GT 3K", int2(5, 5), None), // Guided Missile Launcher
("FastBlast+-", int2(1, 8), None), // Cell Blaster
("FastBlast+-", int2(4, 8), None), // Cell Blaster
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Capacitor", int2(1, 5), None),
("Fire Control Array", int2(1, 6), Clockwise),
("Cargo Bay", int2(2, 8), None));
("Panopticon Prime", int2(1, 6), Clockwise), // Fire Control Array
("Store-All Plus", int2(2, 8), None)); // Cargo Bay
var player = stage.Player(layer, float2(0, 0), facing: float2(0, 1));
stage.Cargo(player, "Coolant Vent", "Coolant Vent", "Coolant Vent", "Thruster Overdrive", "Thruster Overdrive");
stage.Cargo(player, "Morning Fog", "Morning Fog", "Morning Fog", "send it", "send it");
stage.Place(pursuer, float2(0, -Astern), facing: float2(0, 1), stance: ScenarioStance.Hostile, piloted: true);
}
}

View file

@ -28,11 +28,11 @@ public sealed class RefusedRounds : Scenario
("Smoke Refused", int2(3, 8), None),
("Smoke Refused Beam", int2(6, 8), None),
("Smoke Refused Charge", int2(3, 17), None),
("Autocannon", int2(5, 17), None),
("🫳🔫", int2(5, 17), None), // Autocannon
("Radiator", int2(4, 2), CounterClockwise),
("Radiator", int2(5, 2), Clockwise),
("Compact Sensor", int2(5, 10), None),
("Fire Control Array", int2(3, 6), Clockwise));
("not if i see you first", int2(5, 10), None), // Compact Sensor
("Panopticon Prime", int2(3, 6), Clockwise)); // Fire Control Array
stage.Player(shooter, float2(0, 0), facing: float2(0, 1));
stage.Place(stage.Bare("Longinus"), Target);

View file

@ -20,12 +20,12 @@ public sealed class StarvedReactor : Scenario
("Rugged Drive", int2(2, 14), CounterClockwise),
("Rugged Drive", int2(3, 14), Clockwise),
("Muon Fusion Reactor", int2(2, 4), None),
("Light Laser", int2(1, 8), None),
("Light Laser", int2(4, 8), None),
("Spectra", int2(1, 8), None), // Light Laser
("Spectra", int2(4, 8), None), // Light Laser
("Radiator", int2(2, 2), CounterClockwise),
("Radiator", int2(3, 2), Clockwise),
("Compact Sensor", int2(3, 10), None),
("Fire Control Array", int2(1, 6), Clockwise));
("not if i see you first", int2(3, 10), None), // Compact Sensor
("Panopticon Prime", int2(1, 6), Clockwise)); // Fire Control Array
stage.Player(starved, float2(0, 0));
stage.Place(stage.Bare("Longinus"), float2(0, 400));
}

View file

@ -24,13 +24,13 @@ public sealed class WeaponFeel : Scenario
("Rugged Drive", int2(4, 14), CounterClockwise),
("Rugged Drive", int2(5, 14), Clockwise),
("Compact Reactor", int2(4, 4), None),
("Charged Scatter Blaster", int2(3, 17), None),
("Autocannon", int2(5, 17), None),
("Cell Blaster", int2(3, 8), None),
("ChargeBlast SG", int2(3, 17), None), // Charged Scatter Blaster
("🫳🔫", int2(5, 17), None), // Autocannon
("FastBlast+-", int2(3, 8), None), // Cell Blaster
("Radiator", int2(4, 2), CounterClockwise),
("Radiator", int2(5, 2), Clockwise),
("Compact Sensor", int2(5, 10), None),
("Fire Control Array", int2(3, 6), Clockwise));
("not if i see you first", int2(5, 10), None), // Compact Sensor
("Panopticon Prime", int2(3, 6), Clockwise)); // Fire Control Array
stage.Player(shooter, float2(0, 0), facing: float2(0, 1));
stage.Place(stage.Bare("Longinus"), Target);