Scenario fits are stocked unless the scenario authors their cargo

Materialize takes stockAmmunition (default true: boss, console ship). ScenarioStage
passes false and stocks at the end of staging only the fitted entities whose cargo
the scenario did not author with Cargo, so a scenario that names what a hold
carries gets exactly that. A packed (saved) fit is never stocked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-11 03:40:33 +00:00
commit ded74e8b10
4 changed files with 32 additions and 4 deletions

View file

@ -157,11 +157,12 @@ public static class Loadouts
// spawner is to pass LoadoutGenerator.ChooseProduct, with no fallback to any manufacturer; RunStart does, and so does the
// boss in ZoneGenerator, which is built here too from its faction's Loadout (Loadouts.BossOf). The hull's type
// picks the entity: a ship hull builds a Ship, a turret hull an OrbitalEntity with no orbit, which stays where it is
// put; a station hull is refused. The entity always gets exactly WeaponGroupCount groups; a loadout with fewer is
// put; a station hull is refused. The entity is stocked with the crates its weapons draw (StockAmmunition) unless the caller
// authors the cargo itself and passes stockAmmunition false. The entity always gets exactly WeaponGroupCount groups; a loadout with fewer is
// padded with empty groups. A stated quality mints every lot of the fit at it, drawing nothing (a scenario states
// one for a fit its checks rest on).
public static Entity Materialize(ItemManager itemManager, Zone liveZone, Loadout loadout,
Func<CraftedItemData, FactionProductData> choose, List<string> failures, float? quality = null)
Func<CraftedItemData, FactionProductData> choose, List<string> failures, float? quality = null, bool stockAmmunition = true)
{
var cache = itemManager.ItemData;
var reported = failures.Count;
@ -202,7 +203,7 @@ public static class Loadouts
built[g] = (items.Select(item => item.GetBehavior<Weapon>()).ToList(), items);
}
entity.WeaponGroups = built;
StockAmmunition(itemManager, entity);
if (stockAmmunition) StockAmmunition(itemManager, entity);
return entity;
}

View file

@ -44,6 +44,7 @@ public static class RunStart
if (!stage.PlayerPlaced)
failures.Add("player: the scenario places no player");
if (failures.Count > reported) return null;
stage.StockUnauthoredAmmunition();
var player = stage.PlayerShip;
player.IsPlayerShip = true;

View file

@ -18,6 +18,10 @@ public sealed class ScenarioStage
private readonly List<string> _failures = new List<string>();
private readonly List<Placement> _placed = new List<Placement>();
private int _placements;
// The entities this stage built from a fit (a packed fit is a saved ship, whose cargo is its own) and those whose cargo the scenario
// authored with Cargo: the rest are stocked with the crates their weapons draw when staging ends (StockUnauthoredAmmunition).
private readonly HashSet<Entity> _fitted = new HashSet<Entity>();
private readonly HashSet<Entity> _cargoAuthored = new HashSet<Entity>();
internal ScenarioStage(ItemManager items, Zone arena, string startingHull, TutorialGenerationSettings tutorialGenerationSettings)
{
@ -40,6 +44,14 @@ public sealed class ScenarioStage
public int Credits { get; set; }
internal IReadOnlyList<string> Failures => _failures;
// Staging's last step: a fitted entity whose cargo the scenario did not author gets the crates its weapons draw, like every other
// newly built armed entity (Loadouts.StockAmmunition). Draws nothing, so it moves no item roll.
internal void StockUnauthoredAmmunition()
{
foreach (var entity in _fitted.Where(entity => !_cargoAuthored.Contains(entity)))
Loadouts.StockAmmunition(_items, entity);
}
internal bool PlayerPlaced { get; private set; }
internal Ship PlayerShip { get; private set; }
internal IReadOnlyList<Placement> Placed => _placed;
@ -160,6 +172,7 @@ public sealed class ScenarioStage
public void Cargo(Entity entity, params string[] names)
{
if (entity == null) return;
_cargoAuthored.Add(entity);
var where = $"cargo of {entity.Name}";
var bay = entity.CargoBays.FirstOrDefault();
foreach (var name in names)
@ -183,7 +196,8 @@ public sealed class ScenarioStage
else
{
var failures = new List<string>();
entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _choose, failures, fit.Quality);
entity = Loadouts.Materialize(_items, Arena, fit.Loadout, _choose, failures, fit.Quality, stockAmmunition: false);
if (entity != null) _fitted.Add(entity);
_failures.AddRange(failures.Select(failure => $"{where} ({fit.Loadout.Name}): {failure}"));
if (entity == null) return null;
}