Every new run is a scenario: the script harness, the tutorial and main galaxies as scenarios, the New Game submenu and six test arenas
A Scenario is an abstract C# class compiled with the game: Generate picks the galaxy through GalaxyStage (Main or Prelude, at the scenario's seed, the background noise drawn from the same seed), Stage places the run's first entities through ScenarioStage (Fit, Bare, Generated, Preset, Player, Place, Cargo), which collects named failures and admits nothing. RunStart generates the galaxy, the arena under Ambient and admits everything through Zone.Admit, all or nothing. The aetheria.scenario record, ScenarioShip, ScenarioEntity, RunStart.Check and the null-scenario branch are cut. New Game opens a submenu: Tutorial Galaxy and Main Galaxy, then (editor and development builds) Djinni Shakedown, Starved Reactor, Arcs, Duel, Launcher Angles and Long Haul, each with its brief. MainMenu.Launch is the one way into a new run; ActionGameManager.PendingScenario carries the scenario to StartGame once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8a0a29e0de
commit
d0782a7d14
31 changed files with 1173 additions and 611 deletions
|
|
@ -1,131 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CultMath;
|
||||
using static CultMath.math;
|
||||
using float2 = CultMath.float2;
|
||||
using float3 = CultMath.float3;
|
||||
|
||||
// The owner of what a new run starts with (docs/scenarios-cut.md, 2.2): how the arena zone is generated, the player
|
||||
// ship, and a scenario's other entities with their stance, pilot and cargo. A plain New Game is the absent-scenario
|
||||
// case of the same path. Nothing else generates, unpacks or admits a new run's player; everything it stages joins the
|
||||
// arena through Zone.Admit. It holds no Unity type.
|
||||
// The owner of a new run (docs/scenarios-cut.md, R.4). Every new run is a scenario: RunStart generates its galaxy,
|
||||
// generates its arena (the galaxy's entrance zone) under the scenario's Ambient rule, and admits what the scenario
|
||||
// stages through Zone.Admit, all of it or none of it. A scenario only declares; nothing else generates a new run's
|
||||
// galaxy, generates or admits its player, or chooses its hull or faction. It holds no Unity type.
|
||||
public static class RunStart
|
||||
{
|
||||
public sealed class Staged
|
||||
{
|
||||
public Ship Player;
|
||||
public List<Entity> Entities; // the scenario's entities, in its order; empty with no scenario
|
||||
public List<Entity> Entities; // what the scenario placed besides the player, in its order
|
||||
}
|
||||
|
||||
// The scenario's galaxy, at the scenario's seed or, when that is zero, the clock's.
|
||||
public static Galaxy Generate(Scenario scenario, GalaxyStage stage)
|
||||
{
|
||||
stage.SeedFrom(scenario);
|
||||
return scenario.Generate(stage) ?? throw new InvalidOperationException($"Scenario {scenario.Name} generated no galaxy.");
|
||||
}
|
||||
|
||||
// The arena is the galaxy's entrance zone, generated under the scenario's Ambient rule; with no scenario, ambient.
|
||||
public static ZonePack GenerateArena(ItemManager itemManager, ZoneGenerationSettings zoneSettings, Galaxy galaxy, Scenario scenario) =>
|
||||
galaxy.Entrance.PackedContents = ZoneGenerator.GenerateZone(
|
||||
itemManager, zoneSettings, galaxy, galaxy.Entrance, galaxy.IsPrelude, scenario?.Ambient ?? true);
|
||||
itemManager, zoneSettings, galaxy, galaxy.Entrance, galaxy.IsPrelude, scenario.Ambient);
|
||||
|
||||
// The check entry: every failure staging this scenario would hit, found with no zone. With no galaxy there is no
|
||||
// availability to filter by (LoadoutGenerator.IsAvailable), and a scenario's arena is a prelude, which offers every
|
||||
// product anyway. It touches no store, so the menu can call it before it clears the saved run.
|
||||
public static List<string> Check(ItemManager itemManager, Scenario scenario)
|
||||
{
|
||||
var failures = new List<string>();
|
||||
if (scenario != null) Build(itemManager, null, scenario, _ => true, failures);
|
||||
return failures;
|
||||
}
|
||||
|
||||
// Stages a new run into its arena, all-or-nothing: null, with every failure listed and the zone unchanged, unless
|
||||
// everything builds. With no scenario: a generated ship of the startingHull (any ship hull when it is empty) for
|
||||
// defaultFaction, at the origin. With one: its player and entities, each at its authored position and heading with
|
||||
// its cargo, each entity's stance set both ways with the player, and a Minion for each piloted one.
|
||||
// Runs the scenario's Stage, then admits its player and everything it placed: each entity's stance set both ways
|
||||
// with the player, a pilot for each piloted one. Returns null, with every failure listed and the arena unchanged,
|
||||
// unless the whole scenario staged.
|
||||
public static Staged Stage(ItemManager itemManager, Zone arena, Scenario scenario, string startingHull,
|
||||
Faction defaultFaction, List<string> failures)
|
||||
{
|
||||
if (scenario == null)
|
||||
{
|
||||
var generator = new LoadoutGenerator(ref itemManager.Random, itemManager, arena.Galaxy, arena.GalaxyZone, defaultFaction, 2);
|
||||
var pack = generator.GenerateShipLoadout(data => string.IsNullOrEmpty(startingHull) || data.Name == startingHull);
|
||||
if (pack == null)
|
||||
{
|
||||
failures.Add($"player: no ship hull named {startingHull}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var ship = (Ship) EntitySerializer.Unpack(itemManager, arena, pack);
|
||||
ship.IsPlayerShip = true;
|
||||
ship.Position = float3.zero;
|
||||
arena.Admit(ship, piloted: false);
|
||||
return new Staged { Player = ship, Entities = new List<Entity>() };
|
||||
}
|
||||
|
||||
// Presets carry no faction, so availability is the galaxy's alone.
|
||||
var availability = new LoadoutGenerator(ref itemManager.Random, itemManager, arena.Galaxy, arena.GalaxyZone, null, 2);
|
||||
var built = Build(itemManager, arena, scenario, availability.IsAvailable, failures);
|
||||
if (built == null) return null;
|
||||
|
||||
var (player, entities) = built.Value;
|
||||
player.IsPlayerShip = true;
|
||||
arena.Admit(player, piloted: false);
|
||||
for (var i = 0; i < entities.Count; i++)
|
||||
{
|
||||
var hostile = scenario.Entities[i].Stance == ScenarioStance.Hostile;
|
||||
entities[i].SetIff(player, hostile);
|
||||
player.SetIff(entities[i], hostile);
|
||||
arena.Admit(entities[i], scenario.Entities[i].Piloted);
|
||||
}
|
||||
return new Staged { Player = player, Entities = entities };
|
||||
}
|
||||
|
||||
// Everything a scenario places, built and positioned but admitted nowhere; null when anything failed.
|
||||
private static (Ship player, List<Entity> entities)? Build(ItemManager itemManager, Zone zone, Scenario scenario,
|
||||
Predicate<FactionProductData> isAvailable, List<string> failures)
|
||||
TutorialGenerationSettings tutorialGenerationSettings, List<string> failures)
|
||||
{
|
||||
var stage = new ScenarioStage(itemManager, arena, startingHull, tutorialGenerationSettings);
|
||||
scenario.Stage(stage);
|
||||
var reported = failures.Count;
|
||||
Entity player = null;
|
||||
if (scenario.Player == null) failures.Add("player: the scenario places no player");
|
||||
else
|
||||
{
|
||||
player = Place(itemManager, zone, scenario.Player, "player", isAvailable, failures);
|
||||
if (player != null && !(player is Ship)) failures.Add($"player: {player.Name} is not a ship hull");
|
||||
}
|
||||
|
||||
var entities = new List<Entity>();
|
||||
for (var i = 0; i < scenario.Entities.Count; i++)
|
||||
{
|
||||
var where = $"entity {i}";
|
||||
var entity = Place(itemManager, zone, scenario.Entities[i], where, isAvailable, failures);
|
||||
if (entity != null && scenario.Entities[i].Piloted && !(entity is Ship))
|
||||
failures.Add($"{where}: {entity.Name} is not a ship hull, so it cannot be piloted");
|
||||
entities.Add(entity);
|
||||
}
|
||||
return failures.Count > reported ? null : ((Ship) player, entities);
|
||||
}
|
||||
|
||||
private static Entity Place(ItemManager itemManager, Zone zone, ScenarioShip placed, string where,
|
||||
Predicate<FactionProductData> isAvailable, List<string> failures)
|
||||
{
|
||||
var loadout = itemManager.ItemData.Get(placed.Loadout);
|
||||
if (loadout == null)
|
||||
{
|
||||
failures.Add($"{where}: preset {placed.Loadout.Key} is not in the catalog");
|
||||
return null;
|
||||
}
|
||||
|
||||
var reported = failures.Count;
|
||||
var materialized = new List<string>();
|
||||
var entity = Loadouts.Materialize(itemManager, zone, loadout, isAvailable, materialized);
|
||||
failures.AddRange(materialized.Select(failure => $"{where} ({loadout.Name}): {failure}"));
|
||||
var cargo = placed.Cargo.Select(design => Loadouts.Resolve(itemManager, design, isAvailable, $"{where} cargo", failures)).ToList();
|
||||
failures.AddRange(stage.Failures);
|
||||
if (!stage.PlayerPlaced)
|
||||
failures.Add("player: the scenario places no player");
|
||||
if (failures.Count > reported) return null;
|
||||
|
||||
entity.Position.xz = placed.Position;
|
||||
if (lengthsq(placed.Direction) > 0) entity.Direction = normalize(placed.Direction);
|
||||
var bay = entity.CargoBays.FirstOrDefault();
|
||||
foreach (var build in cargo)
|
||||
var player = stage.PlayerShip;
|
||||
player.IsPlayerShip = true;
|
||||
arena.Admit(player, piloted: false);
|
||||
foreach (var placed in stage.Placed)
|
||||
{
|
||||
var item = build();
|
||||
if (bay == null || !bay.TryStore(item))
|
||||
failures.Add($"{where} cargo: no room for {itemManager.GetData(item).Name}");
|
||||
var hostile = placed.Stance == ScenarioStance.Hostile;
|
||||
placed.Entity.SetIff(player, hostile);
|
||||
player.SetIff(placed.Entity, hostile);
|
||||
arena.Admit(placed.Entity, placed.Piloted);
|
||||
}
|
||||
return failures.Count > reported ? null : entity;
|
||||
return new Staged { Player = player, Entities = stage.Placed.Select(placed => placed.Entity).ToList() };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue