Fix Soul s1: boss presets refused, refusal restores the item stream, anchor must be the player ship, drop the dead stocking-order claim

Nothing at admission or activation reads cargo (ammunition is read at fire time), so the comment's ordering rule is removed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-20 01:14:15 +01:00
commit 0c9ab54048
2 changed files with 91 additions and 8 deletions

View file

@ -108,9 +108,18 @@ public class ZoneStage
public ScenarioFit Preset(string name)
{
var preset = _items.ItemData.GetAll<Loadout>().FirstOrDefault(loadout => loadout.Name == name);
if (preset != null) return new ScenarioFit(preset);
_failures.Add($"preset {name}: no such preset");
return null;
if (preset == null)
{
_failures.Add($"preset {name}: no such preset");
return null;
}
// A faction's boss is the zone generator's to place (boss-hulls-exclusive): Loadouts.BossOf owns which loadout it is.
if (_items.ItemData.GetAll<Faction>().Any(faction => Loadouts.BossOf(_items.ItemData, faction, out _)?.Name == preset.Name))
{
_failures.Add($"preset {name}: a faction's boss loadout is placed only by the zone generator");
return null;
}
return new ScenarioFit(preset);
}
// Anything else in the arena. A stance holds both ways between it and the player. A piloted ship gets the zone's
@ -192,19 +201,30 @@ public class ZoneStage
// Places ships into a running zone through the admission a run start uses: the script places with the stage's verbs,
// and the entities join with their stance toward the player, a pilot when piloted and the knowledge the script stated.
// Returns the placed entities in order, or null with every failure listed and the zone unchanged. It draws from the
// live item stream and does not reseed (a reseed would give every summon the same fits).
// Returns the placed entities in order, or null with every failure listed and the zone and the item stream unchanged.
// It draws from the live item stream and does not reseed (a reseed would give every summon the same fits). The anchor
// is the player's ship: the stance is written against it.
public static IReadOnlyList<Entity> Summon(ItemManager items, Zone zone, Ship player, Action<ZoneStage> script, List<string> failures)
{
if (player == null || !player.IsPlayerShip)
{
failures.Add("summon: the anchor is not the player's ship");
return null;
}
if (!zone.Entities.Contains(player))
{
failures.Add("summon: the player is not in this zone");
return null;
}
var stream = items.Random;
var stage = new ZoneStage(items, zone);
script(stage);
failures.AddRange(stage._failures);
if (stage._failures.Count > 0) return null;
if (stage._failures.Count > 0)
{
items.Random = stream; // a refusal draws nothing: the fits it built are discarded with it
return null;
}
stage.StockUnauthoredAmmunition();
stage.AdmitPlaced(player);
return stage._placed.Select(placed => placed.Entity).ToList();
@ -284,8 +304,9 @@ public sealed class ScenarioStage : ZoneStage
return null;
}
// Run start's admission, in this order: stock unauthored ammunition (Activate reads cargo-driven behaviours, so it
// comes before admission), the player, then everything placed.
// Run start's admission: stock unauthored ammunition, the player, then everything placed. Nothing at admission or
// activation reads cargo (ammunition is read when a weapon fires), so stocking is not ordered by admission; it keeps
// the run start's order.
internal void Admit()
{
StockUnauthoredAmmunition();

View file

@ -469,6 +469,68 @@ public sealed partial class RunStartTests
SafeAssert.Unchanged(zone, entities, agents);
}
// A refused summon leaves the item stream where it was, so a refusal is not a draw: the next fit is the one it would have been.
// Kills: a summon that keeps the draws of the fits it built before refusing.
[Fact]
public void ARefusedSummonLeavesTheItemStream()
{
var zone = Arena(true);
var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player;
var before = _items.Random;
var failures = new List<string>();
Assert.Null(ZoneStage.Summon(_items, zone, player, stage =>
{
stage.Place(stage.Generated("Longinus"), float2(400, 0));
stage.Place(stage.Bare("No Such Hull"), float2(-400, 0));
}, failures));
var after = _items.Random;
Assert.Equal(before.NextUInt(), after.NextUInt());
}
// The anchor of a summon is the player's ship, not any ship in the zone. Kills: a summon that takes any zone member as the player.
[Fact]
public void ASummonNeedsThePlayersShipAsItsAnchor()
{
var zone = Arena(true);
var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player;
var other = zone.Entities.OfType<Ship>().First(ship => !ship.IsPlayerShip);
var entities = zone.Entities.ToList();
var agents = zone.Agents.ToList();
var failures = new List<string>();
Assert.Null(ZoneStage.Summon(_items, zone, other, stage => stage.Place(stage.Bare("Longinus"), float2(400, 0), stance: ScenarioStance.Hostile), failures));
Assert.Equal(new[] { "summon: the anchor is not the player's ship" }, failures);
SafeAssert.Unchanged(zone, entities, agents);
}
// A faction's boss is the zone generator's to place (boss-hulls-exclusive): a preset naming the loadout Loadouts.BossOf
// returns is refused, through a summon as through a run start. Kills: a Preset that places any catalog loadout.
[Fact]
public void APresetCannotPlaceAFactionsBoss()
{
var zone = Arena(true);
var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player;
var boss = _cache.GetAll<Faction>().Select(faction => Loadouts.BossOf(_cache, faction, out _)).First(loadout => loadout != null);
var entities = zone.Entities.ToList();
var agents = zone.Agents.ToList();
var failures = new List<string>();
Assert.Null(ZoneStage.Summon(_items, zone, player, stage =>
stage.Place(stage.Preset(boss.Name), float2(400, 0), stance: ScenarioStance.Hostile, piloted: true), failures));
Assert.Contains(failures, failure => failure.Contains(boss.Name) && failure.Contains("boss"));
SafeAssert.Unchanged(zone, entities, agents);
var started = Refused(Arena(true), new Scripted(true, stage =>
{
stage.Player(stage.Bare("Djinni"), float2(0, 0));
stage.Place(stage.Preset(boss.Name), float2(400, 0));
}));
Assert.Contains(started, failure => failure.Contains("boss"));
}
// A stance lasts the sitting: the player docking and undocking leaves it standing both ways. It goes with an entity
// gone for good: once an entity is destroyed, the player holds no stance toward it.
[Fact]