Merge eureka/aetheria-release-run-seed (head cb1c093e)
Reports cut-run-seed h1/h2; Soul verdicts s1, s2 hold. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
5a050f0fca
12 changed files with 246 additions and 24 deletions
|
|
@ -775,7 +775,7 @@ public static class FireControl
|
|||
// Lays a mine for a mine layer: freezes the payload as evaluated now (stats, the item's blast radius, the
|
||||
// layer and its faction) and hands the body to Zone.Lay, the one adder. It launches at the shooter's velocity
|
||||
// plus the mount direction turned by a dice angle within +-Spread/2, times Velocity; the dice are the mine's
|
||||
// own (zone seed, MineStream, body id), so no other roll is perturbed. No target, no PendingShot, no price:
|
||||
// own (the zone's DropSeed, MineStream, body id), so no other roll is perturbed. No target, no PendingShot, no price:
|
||||
// InstantWeapon has already paid. A layer whose item has no blast radius lays nothing.
|
||||
public static void Lay(Weapon weapon, EquippedItem item, Entity source)
|
||||
{
|
||||
|
|
@ -789,7 +789,7 @@ public static class FireControl
|
|||
|
||||
var id = zone.NextBodyId();
|
||||
var half = weapon.Spread / 2f;
|
||||
var angle = radians(SimulationDice.For(zone.CombatSeed, SimulationDice.MineStream, id.Value).NextFloat(-half, half));
|
||||
var angle = radians(SimulationDice.For(zone.DropSeed, SimulationDice.MineStream, id.Value).NextFloat(-half, half));
|
||||
var s = sin(angle);
|
||||
var c = cos(angle);
|
||||
var mount = MountDirection(item).xz;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public class Galaxy
|
|||
private Action<string> Log { get; }
|
||||
public bool IsPrelude { get; }
|
||||
|
||||
// The seed this galaxy was generated at, which also seeds its run's item draws (RunStart); zero for a galaxy
|
||||
// restored from a save.
|
||||
// The run's seed, minted once by GalaxyStage.SeedFrom and carried by the save (SavedGame.Seed). It seeds
|
||||
// generation, the run's item draws (RunStart) and the zone's drop dice (Zone.DropSeed).
|
||||
public uint Seed { get; }
|
||||
|
||||
private GalaxyZone[] _exitPath;
|
||||
|
|
@ -51,6 +51,7 @@ public class Galaxy
|
|||
_cache = cultCache;
|
||||
Log = log;
|
||||
Background = savedGame.Background;
|
||||
Seed = savedGame.Seed;
|
||||
|
||||
Factions = savedGame.Factions.Select(faction => cultCache.Get(faction)).ToArray();
|
||||
for (var i = 0; i < Factions.Length; i++)
|
||||
|
|
@ -96,15 +97,15 @@ public class Galaxy
|
|||
SectorBackgroundSettings background,
|
||||
CultCache cache,
|
||||
Action<string> log,
|
||||
Action<string> progressCallback = null,
|
||||
uint seed = 0)
|
||||
Action<string> progressCallback,
|
||||
uint seed)
|
||||
{
|
||||
_cache = cache;
|
||||
IsPrelude = false;
|
||||
Background = background;
|
||||
Log = log;
|
||||
var factions = cache.GetAll<Faction>();
|
||||
Seed = seed == 0 ? (uint) (DateTime.Now.Ticks % uint.MaxValue) : seed;
|
||||
Seed = seed != 0 ? seed : throw new ArgumentOutOfRangeException(nameof(seed), "a generated galaxy takes its run's seed from GalaxyStage, never zero");
|
||||
var random = new Random(Seed);
|
||||
Factions = factions.OrderBy(x => random.NextFloat()).Take(settings.MegaCount).ToArray();
|
||||
foreach (var f in Factions) FactionRelationships[f] = FactionRelationship.Neutral;
|
||||
|
|
@ -163,15 +164,15 @@ public class Galaxy
|
|||
PlayerSettings playerSettings,
|
||||
DirectoryInfo narrativeDirectory,
|
||||
Action<string> log,
|
||||
Action<string> progressCallback = null,
|
||||
uint seed = 0)
|
||||
Action<string> progressCallback,
|
||||
uint seed)
|
||||
{
|
||||
_cache = cache;
|
||||
IsPrelude = true;
|
||||
|
||||
Background = background;
|
||||
Log = log;
|
||||
Seed = seed == 0 ? (uint) (DateTime.Now.Ticks % uint.MaxValue) : seed;
|
||||
Seed = seed != 0 ? seed : throw new ArgumentOutOfRangeException(nameof(seed), "a generated galaxy takes its run's seed from GalaxyStage, never zero");
|
||||
var random = new Random(Seed);
|
||||
|
||||
var factions = new List<Faction>();
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ public sealed class GalaxyStage
|
|||
_clock = clock ?? (() => (uint) (DateTime.Now.Ticks % uint.MaxValue));
|
||||
}
|
||||
|
||||
// The seed this generation runs at, never zero: the scenario's, or the clock's when the scenario's is zero.
|
||||
// The run's one minter: the scenario's seed, or the clock's when the scenario's is zero, never zero. Galaxy carries
|
||||
// what it mints and SavedGame keeps it, so Continue rolls the same drops.
|
||||
public uint Seed { get; private set; }
|
||||
|
||||
internal void SeedFrom(Scenario scenario)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ public class SavedGame
|
|||
|
||||
[Key(13)]
|
||||
public int Credits;
|
||||
|
||||
// The run's seed (Galaxy.Seed), minted once by GalaxyStage.SeedFrom. Written only by RunSave.Capture and read only
|
||||
// by Galaxy's save constructor; 0 in a save written before run-seed, which then rolls name-only drops.
|
||||
[Key(14)]
|
||||
public uint Seed;
|
||||
}
|
||||
|
||||
// The run's lifecycle over the run store. Only Commit creates SavedGame, SavedZone and ProvenanceLedger records;
|
||||
|
|
@ -79,7 +84,8 @@ public static class RunSave
|
|||
Exit = Array.IndexOf(galaxy.Zones, galaxy.Exit),
|
||||
IsTutorial = galaxy.IsPrelude,
|
||||
ActionBarBindings = actionBar,
|
||||
Credits = credits
|
||||
Credits = credits,
|
||||
Seed = galaxy.Seed
|
||||
};
|
||||
|
||||
// A zone generated earlier but not loaded this session has no live Contents; its packed contents carry over.
|
||||
|
|
|
|||
|
|
@ -126,11 +126,15 @@ public class Zone
|
|||
// of touching a shared stream.
|
||||
public uint CombatSeed { get; }
|
||||
|
||||
// The zone's drop dice (loot and mine scatter): CombatSeed mixed with its run's seed (ruling loot-seed-in-save), so a
|
||||
// new game drops differently and a reloaded save repeats. Mix(0) is 0, so a zone with no galaxy rolls on CombatSeed.
|
||||
public uint DropSeed { get; }
|
||||
|
||||
// The one source of floating item and mine ids: zone-scoped, from 1, never reused. Runtime state, not saved.
|
||||
private uint _lastBodyId;
|
||||
public FloatingBodyId NextBodyId() => new FloatingBodyId(++_lastBodyId);
|
||||
|
||||
// The death ordinal of the loot dice: the nth death in this zone rolls on SimulationDice.For(CombatSeed, LootStream, n).
|
||||
// The death ordinal of the loot dice: the nth death in this zone rolls on SimulationDice.For(DropSeed, LootStream, n).
|
||||
private uint _deaths;
|
||||
|
||||
// The zone-scoped agent ordinal, from 1, never reused: the key of a pilot's own dice.
|
||||
|
|
@ -152,6 +156,7 @@ public class Zone
|
|||
Settings = settings;
|
||||
_orbitPositionAt = OrbitPositionAt;
|
||||
CombatSeed = galaxyZone?.Name.StableHash() ?? 1337u;
|
||||
DropSeed = CombatSeed ^ SimulationDice.Mix(galaxy?.Seed ?? 0u);
|
||||
var cache = itemManager.ItemData;
|
||||
|
||||
// Cut 5, 5.6 (docs/fire-control-cut.md, Soul finding 7; operator ruling Q3): death removes the ship,
|
||||
|
|
@ -452,7 +457,7 @@ public class Zone
|
|||
private void DropLoot(Entity dead)
|
||||
{
|
||||
var settings = _itemManager.GameplaySettings;
|
||||
var random = SimulationDice.For(CombatSeed, SimulationDice.LootStream, ++_deaths);
|
||||
var random = SimulationDice.For(DropSeed, SimulationDice.LootStream, ++_deaths);
|
||||
var at = new float2(dead.Position.x, dead.Position.z);
|
||||
float2 Heading() { var angle = random.NextFloat() * 2f * PI; return float2(cos(angle), sin(angle)); }
|
||||
foreach (var equipped in dead.Equipment.ToArray())
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public sealed class ConsumableAiTests : IDisposable
|
|||
public GearData HeavyGun;
|
||||
public CultRecordRef<Faction> Maker;
|
||||
public float Optimum;
|
||||
public CultRecordKey[] Circuit;
|
||||
|
||||
public void Store(ConsumableItemData design) =>
|
||||
Assert.True(Hold.TryStore((ItemInstance) Items.CreateInstance(Items.CreateLot(design, Maker, .5f))));
|
||||
|
|
@ -97,9 +98,9 @@ public sealed class ConsumableAiTests : IDisposable
|
|||
}
|
||||
};
|
||||
|
||||
private Scene Build(bool carryVent = false, bool carryOverdrive = false, bool carryDecoy = false, int stackableVents = 0, float effective = 500f)
|
||||
private Scene Build(bool carryVent = false, bool carryOverdrive = false, bool carryDecoy = false, int stackableVents = 0, float effective = 500f, uint? runSeed = null, int orbits = 1)
|
||||
{
|
||||
var cache = AetheriaStores.Open(Path.Combine(_root, Guid.NewGuid().ToString("N") + ".cc"), catalogWritable: true);
|
||||
var cache = AetheriaStores.Open(Path.Combine(_root, Guid.NewGuid().ToString("N") + ".cc"), Path.Combine(_root, Guid.NewGuid().ToString("N") + ".run.cc"), catalogWritable: true);
|
||||
_caches.Add(cache);
|
||||
cache.Upsert(new VerseGrammar { Revision = 1 });
|
||||
cache.Upsert(new Faction { Name = "Maker", ShortName = "MKR" });
|
||||
|
|
@ -150,7 +151,10 @@ public sealed class ConsumableAiTests : IDisposable
|
|||
var maker = cache.RefOf(cache.GetByName<Faction>("Maker"));
|
||||
EquippableItem Make<T>(string name) where T : CraftedItemData =>
|
||||
(EquippableItem) items.CreateInstance(items.CreateLot(cache.GetByName<T>(name), maker, .5f));
|
||||
var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null);
|
||||
var galaxy = runSeed.HasValue ? RunSeedFixture.Continue(cache, "Test Zone", runSeed.Value) : null;
|
||||
var zone = galaxy != null
|
||||
? new Zone(items, new PlanetSettings(), new ZonePack(), galaxy.Zones[0], galaxy)
|
||||
: new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null);
|
||||
Ship NewShip(string gear)
|
||||
{
|
||||
var ship = new Ship(items, zone, Make<HullData>("Skiff"), new EntitySettings())
|
||||
|
|
@ -174,8 +178,10 @@ public sealed class ConsumableAiTests : IDisposable
|
|||
// The agent joins as the zone admits a piloted ship (its Minion and CombatState come from production); the
|
||||
// locker is a gun ship nobody pilots.
|
||||
// One fixed orbit far from the fight, before the agent joins: a pilot that is not engaged patrols it, as production's would.
|
||||
zone.Orbits.Add(new CultRecordKey("test-orbit"), new Orbit(new OrbitData { FixedPosition = float2(0, 5000) }));
|
||||
for (var i = 0; i < orbits; i++)
|
||||
zone.Orbits.Add(new CultRecordKey(orbits == 1 ? "test-orbit" : "test-orbit-" + i), new Orbit(new OrbitData { FixedPosition = float2(0, 5000) }));
|
||||
zone.Admit(scene.Agent, piloted: true);
|
||||
scene.Circuit = ((PatrolOrbitsTask) zone.Agents.Single().Task).Circuit;
|
||||
zone.Admit(scene.Prey, piloted: false);
|
||||
zone.Admit(scene.Locker, piloted: false);
|
||||
// The flight is the only writer of the agent's Target: the agent senses the prey and holds a grudge on it, so the
|
||||
|
|
@ -356,6 +362,25 @@ public sealed class ConsumableAiTests : IDisposable
|
|||
// The production path for the optimum: a ship the zone admits as piloted derives it from its gun's live stats
|
||||
// before it needs it, and re-derives it when its loadout changes. The gun's effective range is 500 and the
|
||||
// heavy gun's is 800, so the optimum moves with the weapons it has now.
|
||||
// The run seed feeds drops and mines only (ruling run-seed-drops-only): the same pilot in the same zone samples its
|
||||
// range with the same offset and draws the same patrol circuit at every run seed. Kills: the combat-sample dice or
|
||||
// the patrol dice read DropSeed.
|
||||
[Theory]
|
||||
[InlineData(1u, 2u)]
|
||||
[InlineData(0xC0FFEE42u, 0x2468ACE1u)]
|
||||
public void ThePilotsDiceDoNotMoveWithTheRunSeed(uint first, uint second)
|
||||
{
|
||||
var a = Build(runSeed: first, orbits: 8);
|
||||
var b = Build(runSeed: second, orbits: 8);
|
||||
a.AssertInCombat();
|
||||
b.AssertInCombat();
|
||||
Assert.NotEqual(a.Zone.DropSeed, b.Zone.DropSeed);
|
||||
Assert.Equal(a.Zone.CombatSeed, b.Zone.CombatSeed);
|
||||
Assert.Equal(a.Optimum, b.Optimum);
|
||||
Assert.Equal(4, a.Circuit.Length);
|
||||
Assert.Equal(a.Circuit, b.Circuit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ASpawnedShipsOptimumFollowsItsWeaponsAndNeverReadsZero()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ public sealed partial class RunStartTests
|
|||
var (game, zones) = RunSave.Capture(_cache, galaxy, arena, staged.Player, new SavedActionBarBinding[0], 0);
|
||||
RunSave.Commit(_cache, game, zones, _items.Lots);
|
||||
var restored = new Galaxy(_cache, _cache.GetGlobal<SavedGame>(), _ => { });
|
||||
Assert.NotEqual(0u, galaxy.Seed);
|
||||
Assert.Equal(galaxy.Seed, restored.Seed);
|
||||
|
||||
Dictionary<string, FactionRelationship> Standing(Galaxy g) => g.Factions.ToDictionary(faction => faction.Name, faction => g.FactionRelationships[faction]);
|
||||
Assert.Equal(new Dictionary<string, FactionRelationship>
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public sealed class LootTests : IDisposable
|
|||
}
|
||||
|
||||
private Lab Build(string zoneName = "Loot", float probability = .5f, float lifetime = 30f, float velocity = 25f,
|
||||
bool well = false, float spread = 0f)
|
||||
bool well = false, float spread = 0f, uint? runSeed = null)
|
||||
{
|
||||
var settings = new GameplaySettings
|
||||
{
|
||||
|
|
@ -104,6 +104,7 @@ public sealed class LootTests : IDisposable
|
|||
cache.Upsert(new CargoBayData { Name = "Crate", Shape = new Shape(), InteriorShape = Solid(4, 4), Durability = 4 });
|
||||
cache.Upsert(new SimpleCommodityData { Name = "Ore", Shape = Solid(1, 1), MaxStack = 100 });
|
||||
cache.FlushAsync().Wait();
|
||||
var galaxy = runSeed.HasValue ? RunSeedFixture.Continue(cache, zoneName, runSeed.Value) : null;
|
||||
|
||||
var ledger = new ProvenanceLedger();
|
||||
for (var i = 1; i <= 9000; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = 1 };
|
||||
|
|
@ -111,7 +112,9 @@ public sealed class LootTests : IDisposable
|
|||
var planets = new PlanetSettings();
|
||||
var pack = new ZonePack { Radius = well ? 1000 : 0 };
|
||||
if (well) WellFixture.Dig(cache, pack, planets, 300, 100);
|
||||
var zone = new Zone(items, planets, pack, new GalaxyZone { Name = zoneName, Owner = null }, null);
|
||||
var zone = galaxy != null
|
||||
? new Zone(items, planets, pack, galaxy.Zones[0], galaxy)
|
||||
: new Zone(items, planets, pack, new GalaxyZone { Name = zoneName, Owner = null }, null);
|
||||
return new Lab { Items = items, Zone = zone };
|
||||
}
|
||||
|
||||
|
|
@ -209,6 +212,61 @@ public sealed class LootTests : IDisposable
|
|||
Assert.True(Differ(dropsA, Released(first, count)));
|
||||
}
|
||||
|
||||
private List<(string Item, float2 Position, float2 Velocity)> DropsAt(string zoneName, uint runSeed)
|
||||
{
|
||||
var lab = Build(zoneName, runSeed: runSeed);
|
||||
Kill(Spawn(lab, float3(31, 0, -17)));
|
||||
return Released(lab, 0);
|
||||
}
|
||||
|
||||
// A new game rolls different drops from other games: the same ship, killed in the same zone, at another run seed.
|
||||
[Fact]
|
||||
public void ANewGameRollsDifferentDrops()
|
||||
{
|
||||
var one = DropsAt("Dice", 1);
|
||||
Assert.True(one.Count > 2, "the fixture must drop enough for a draw to show");
|
||||
Assert.True(Differ(one, DropsAt("Dice", 2)));
|
||||
}
|
||||
|
||||
// Reloading one save repeats its drops, and the run's other zones still roll on their own names.
|
||||
[Fact]
|
||||
public void ReloadingASaveRepeatsItsDrops()
|
||||
{
|
||||
var first = DropsAt("Dice", 7);
|
||||
Assert.True(first.Count > 2, "the fixture must drop enough for a draw to show");
|
||||
AssertSameDrops(first, DropsAt("Dice", 7));
|
||||
Assert.True(Differ(first, DropsAt("Other dice", 7)));
|
||||
}
|
||||
|
||||
// Pinned at eb27ced1, before run-seed: a zone with no galaxy, and a zone of a save written before run-seed (seed 0),
|
||||
// roll on the zone's name alone and drop exactly what they dropped.
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void AZoneWithoutARunSeedKeepsItsDrops(bool restoredFromAnOldSave)
|
||||
{
|
||||
var drops = restoredFromAnOldSave ? DropsAt("Dice", 0) : Released(KillInNewLab("Dice"), 0);
|
||||
Assert.Equal(new[] { "Spare", "Spare", "Spare", "Orex7", "Spare" }, drops.Select(d => d.Item));
|
||||
Assert.All(drops, d => Assert.Equal(new float2(31, -17), d.Position));
|
||||
var velocities = new[]
|
||||
{
|
||||
float2(-14.870228f, -20.096674f), float2(-4.9265895f, -24.509768f), float2(-17.977364f, 17.372805f),
|
||||
float2(-5.908107f, 24.291857f), float2(-24.228783f, -6.1616626f)
|
||||
};
|
||||
for (var i = 0; i < velocities.Length; i++)
|
||||
{
|
||||
Assert.Equal(velocities[i].x, drops[i].Velocity.x, 3);
|
||||
Assert.Equal(velocities[i].y, drops[i].Velocity.y, 3);
|
||||
}
|
||||
}
|
||||
|
||||
private Lab KillInNewLab(string zoneName)
|
||||
{
|
||||
var lab = Build(zoneName);
|
||||
Kill(Spawn(lab, float3(31, 0, -17)));
|
||||
return lab;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GearDropsByProbabilityCargoAlways()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public sealed class MineTests : IDisposable
|
|||
private Lab Build(float blast = 4f, float arming = 2f, float fuse = 2f, float life = 30f, float spread = 0f, float velocity = 0f,
|
||||
float damage = 100f, float range = 1000f, float cooldown = 1000f, Faction layerFaction = null,
|
||||
WeaponFuse? fuseKind = WeaponFuse.Proximity, bool well = false, float3? layerAt = null, int magazine = 100,
|
||||
float minRange = 0f)
|
||||
float minRange = 0f, uint? runSeed = null)
|
||||
{
|
||||
var settings = new GameplaySettings
|
||||
{
|
||||
|
|
@ -114,6 +114,7 @@ public sealed class MineTests : IDisposable
|
|||
cache.Upsert(Gear("Shield", new ShieldData { Efficiency = Constant(1), EnergyUsage = Constant(1), Capacity = Constant(1000000), RefillDuration = Constant(.01f), RestoreDuration = Constant(.01f) }, 10));
|
||||
cache.Upsert(Gear("TinyShield", new ShieldData { Efficiency = Constant(1), EnergyUsage = Constant(1), Capacity = Constant(.001f), RefillDuration = Constant(.01f), RestoreDuration = Constant(.01f) }, 10));
|
||||
cache.FlushAsync().Wait();
|
||||
var galaxy = runSeed.HasValue ? RunSeedFixture.Continue(cache, "Mines", runSeed.Value) : null;
|
||||
|
||||
var ledger = new ProvenanceLedger();
|
||||
for (var i = 1; i <= 500; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = 1 };
|
||||
|
|
@ -121,7 +122,9 @@ public sealed class MineTests : IDisposable
|
|||
var planets = new PlanetSettings();
|
||||
var pack = new ZonePack { Radius = well ? 1000 : 0 };
|
||||
if (well) WellFixture.Dig(cache, pack, planets, 300, 100);
|
||||
var zone = new Zone(items, planets, pack, new GalaxyZone { Name = "Mines", Owner = null }, null);
|
||||
var zone = galaxy != null
|
||||
? new Zone(items, planets, pack, galaxy.Zones[0], galaxy)
|
||||
: new Zone(items, planets, pack, new GalaxyZone { Name = "Mines", Owner = null }, null);
|
||||
var lab = new Lab { Items = items, Zone = zone, Data = data, ItemData = cache.GetByName<WeaponItemData>("Mine Layer") };
|
||||
|
||||
var layerRef = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<HullData>("Layer"));
|
||||
|
|
@ -683,6 +686,35 @@ public sealed class MineTests : IDisposable
|
|||
Assert.False(FireControl.Refuses(lab.Weapon, lab.Layer));
|
||||
}
|
||||
|
||||
// A new game scatters its mines differently: the same lay, at another run seed, launches at another velocity.
|
||||
[Fact]
|
||||
public void ANewGameScattersMinesDifferently()
|
||||
{
|
||||
Assert.NotEqual(LaunchAt(1), LaunchAt(2));
|
||||
}
|
||||
|
||||
private float2 LaunchAt(uint? runSeed)
|
||||
{
|
||||
var lab = Build(spread: 40f, velocity: 5f, layerFaction: A, runSeed: runSeed);
|
||||
var atLay = default(KinematicBody);
|
||||
using var sub = lab.Zone.Mines.ObserveAdd().Subscribe(e => atLay = e.Value.Body);
|
||||
lab.Layer.Direction = normalize(float2(1, 2));
|
||||
LayOne(lab);
|
||||
return atLay.Velocity;
|
||||
}
|
||||
|
||||
// Pinned at eb27ced1, before run-seed: a zone with no galaxy, and a zone of a save written before run-seed (seed 0),
|
||||
// scatter their mines on the zone's name alone.
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void AZoneWithoutARunSeedKeepsItsMineScatter(bool restoredFromAnOldSave)
|
||||
{
|
||||
var velocity = LaunchAt(restoredFromAnOldSave ? 0u : (uint?) null);
|
||||
Assert.Equal(3.2546253f, velocity.x, 3);
|
||||
Assert.Equal(3.795711f, velocity.y, 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheLaunchAngleIsTheMinesOwnDice()
|
||||
{
|
||||
|
|
@ -697,9 +729,9 @@ public sealed class MineTests : IDisposable
|
|||
|
||||
var mine = LayOne(lab);
|
||||
|
||||
// The angle is the first draw of (zone seed, mine stream, body id), in +-Spread/2, turning the mount
|
||||
// The angle is the first draw of (the zone's DropSeed, mine stream, body id), in +-Spread/2, turning the mount
|
||||
// counterclockwise in the (x, y) plane.
|
||||
var degreesTurned = SimulationDice.For(lab.Zone.CombatSeed, SimulationDice.MineStream, mine.Id.Value).NextFloat(-20f, 20f);
|
||||
var degreesTurned = SimulationDice.For(lab.Zone.DropSeed, SimulationDice.MineStream, mine.Id.Value).NextFloat(-20f, 20f);
|
||||
var a = radians(degreesTurned);
|
||||
var m = FireControl.MountDirection(lab.WeaponItem).xz;
|
||||
var turned = float2(m.x * cos(a) - m.y * sin(a), m.x * sin(a) + m.y * cos(a));
|
||||
|
|
|
|||
|
|
@ -170,6 +170,50 @@ public sealed class RunSaveTests : IDisposable
|
|||
Assert.Equal(4242, cache.GetGlobal<SavedGame>().Credits);
|
||||
}
|
||||
|
||||
// The run's seed rides the save: Continue restores it, Capture writes it back, and a save from before run-seed
|
||||
// restores zero.
|
||||
[Fact]
|
||||
public void TheRunSeedRidesTheSave()
|
||||
{
|
||||
using (var cache = Open())
|
||||
{
|
||||
var game = Game(cache);
|
||||
game.Seed = 0xC0FFEE42u;
|
||||
RunSave.Commit(cache, game, Zones(2, StageZoneContents(cache), 0), new ProvenanceLedger());
|
||||
}
|
||||
|
||||
using (var cache = Open())
|
||||
{
|
||||
var galaxy = new Galaxy(cache, cache.GetGlobal<SavedGame>(), _ => { });
|
||||
Assert.Equal(0xC0FFEE42u, galaxy.Seed);
|
||||
var itemManager = new ItemManager(cache, new ProvenanceLedger(), TestSettings(), _ => { });
|
||||
galaxy.Zones[0].Contents = new Zone(itemManager, new PlanetSettings(), new ZonePack(), galaxy.Zones[0], galaxy);
|
||||
// The zone's drop dice are its name's seed mixed with the run's.
|
||||
Assert.Equal("Zone 0".StableHash() ^ SimulationDice.Mix(0xC0FFEE42u), galaxy.Zones[0].Contents.DropSeed);
|
||||
var (game, zones) = RunSave.Capture(cache, galaxy, galaxy.Zones[0].Contents, null, new SavedActionBarBinding[0], 0);
|
||||
Assert.Equal(0xC0FFEE42u, game.Seed);
|
||||
RunSave.Commit(cache, game, zones, RunSave.Lots(cache));
|
||||
}
|
||||
|
||||
using (var cache = Open())
|
||||
Assert.Equal(0xC0FFEE42u, cache.GetGlobal<SavedGame>().Seed);
|
||||
|
||||
// A save written before run-seed holds no seed, and continues on name-only drops.
|
||||
using (var cache = Open())
|
||||
RunSave.Commit(cache, Game(cache), Zones(2, StageZoneContents(cache), 0), new ProvenanceLedger());
|
||||
|
||||
using (var cache = Open())
|
||||
{
|
||||
Assert.Equal(0u, cache.GetGlobal<SavedGame>().Seed);
|
||||
var galaxy = new Galaxy(cache, cache.GetGlobal<SavedGame>(), _ => { });
|
||||
Assert.Equal(0u, galaxy.Seed);
|
||||
var itemManager = new ItemManager(cache, new ProvenanceLedger(), TestSettings(), _ => { });
|
||||
var zone = new Zone(itemManager, new PlanetSettings(), new ZonePack(), galaxy.Zones[0], galaxy);
|
||||
Assert.Equal("Zone 0".StableHash(), zone.CombatSeed);
|
||||
Assert.Equal(zone.CombatSeed, zone.DropSeed);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearRemovesEveryRunRecord()
|
||||
{
|
||||
|
|
|
|||
26
tests/Aetheria.Shared.Tests/RunSeedFixture.cs
Normal file
26
tests/Aetheria.Shared.Tests/RunSeedFixture.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
using GameCult.Caching;
|
||||
|
||||
// A fixture's run at a fixed seed, restored as Continue restores it: one zone, committed through RunSave.Commit and
|
||||
// read back by the Galaxy save constructor, so a test's galaxy carries the seed the way a real run's does.
|
||||
internal static class RunSeedFixture
|
||||
{
|
||||
public static Galaxy Continue(CultCache cache, string zoneName, uint seed)
|
||||
{
|
||||
var game = new SavedGame
|
||||
{
|
||||
Seed = seed,
|
||||
Factions = new CultRecordRef<Faction>[0],
|
||||
Relationships = new FactionRelationship[0],
|
||||
HomeZones = new Dictionary<int, int>(),
|
||||
BossZones = new Dictionary<int, int>(),
|
||||
DiscoveredZones = new[] { 0 },
|
||||
ActionBarBindings = new SavedActionBarBinding[0],
|
||||
Entrance = 0,
|
||||
Exit = -1
|
||||
};
|
||||
var zone = new SavedZone { Name = zoneName, AdjacentZones = new int[0], Factions = new int[0], Owner = -1 };
|
||||
RunSave.Commit(cache, game, new[] { zone }, new ProvenanceLedger());
|
||||
return new Galaxy(cache, cache.GetGlobal<SavedGame>(), _ => { });
|
||||
}
|
||||
}
|
||||
|
|
@ -115,6 +115,28 @@ public sealed partial class RunStartTests : IDisposable
|
|||
|
||||
private const float Freezing = 273.15f;
|
||||
|
||||
// One minter: a generated galaxy never reads the clock, so seed 0 is refused by both generation constructors, naming
|
||||
// the field and echoing no input (no ActualValue). The settings are the authored ones: a galaxy that stops refusing must be able to
|
||||
// finish generating, so the test fails by assertion rather than wedging in the generator.
|
||||
[Fact]
|
||||
public void AGeneratedGalaxyRefusesSeedZero()
|
||||
{
|
||||
var authored = AuthoredSettings.Load(FindRepoRoot());
|
||||
var background = authored.Read<SectorBackgroundSettings>("SectorBackgroundSettings");
|
||||
var sector = authored.Read<SectorGenerationSettings>("SectorGenerationSettings");
|
||||
sector.ZoneCount = 8;
|
||||
var tutorial = authored.Read<TutorialGenerationSettings>("TutorialGenerationSettings");
|
||||
|
||||
var main = Assert.Throws<ArgumentOutOfRangeException>(() => new Galaxy(sector, background, _cache, _ => { }, null, 0));
|
||||
var prelude = Assert.Throws<ArgumentOutOfRangeException>(() =>
|
||||
new Galaxy(tutorial, background, _cache, new PlayerSettings(), new DirectoryInfo(_root), _ => { }, null, 0));
|
||||
foreach (var refusal in new[] { main, prelude })
|
||||
{
|
||||
Assert.Equal("seed", refusal.ParamName);
|
||||
Assert.Null(refusal.ActualValue);
|
||||
}
|
||||
}
|
||||
|
||||
// A main-sector galaxy: each station's gear must come from manufacturers its faction can reach, the makers its
|
||||
// allegiance names, present in the galaxy or not.
|
||||
private Galaxy MainSectorGalaxy()
|
||||
|
|
|
|||
Loading…
Reference in a new issue