ZoneGenerator: an unbuildable boss Loadout restores itemManager.Random, so the zone's later draws equal the no-boss zone's

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-19 00:21:11 +02:00
commit af993acf07
2 changed files with 20 additions and 0 deletions

View file

@ -433,9 +433,11 @@ public static class ZoneGenerator
continue;
}
var failures = new List<string>();
var streamBefore = itemManager.Random;
var entity = Loadouts.Materialize(itemManager, null, loadout, GetLoadoutGenerator(bossFaction).ChooseProduct, failures);
if (entity == null)
{
itemManager.Random = streamBefore; // a failed fit has drawn lots; an unbuildable boss draws nothing, as a refused one does
itemManager.Log($"{bossFaction.Name}'s boss Loadout {loadout.Name} cannot be built: {string.Join("; ", failures)}");
continue;
}

View file

@ -629,4 +629,22 @@ public sealed partial class RunStartTests
Assert.Empty(failures);
Assert.Equal(expected.Random.NextFloat(), next);
}
[Fact]
public void An_unbuildable_boss_loadout_draws_nothing()
{
var galaxy = DemoGalaxy(1);
var loadout = GiveAntagonistABoss(galaxy);
loadout.Slots[0].Position = new int2(999, 999);
StoreLoadout(loadout);
var items = LoggingItems(new List<string>());
var pack = BossZonePack(galaxy, items, galaxy.Exit);
Assert.False(pack.BossSpawned);
var next = items.Random.NextFloat();
galaxy.BossZones.Clear();
var bareItems = LoggingItems(new List<string>());
var bare = BossZonePack(galaxy, bareItems, galaxy.Exit);
Assert.Equal(Roster(bareItems, bare), Roster(items, pack));
Assert.Equal(bareItems.Random.NextFloat(), next);
}
}