From 386f29bf0d9c78f520402352357353380bb8b758 Mon Sep 17 00:00:00 2001 From: Nibu Date: Wed, 11 Nov 2026 02:55:39 +0000 Subject: [PATCH] Generated ships carry the crates their weapons reload from; Missiles gets a cargo shape; comment and lore fixes LoadoutGenerator.GenerateShipLoadout, the one owner of NPC and generated-scenario fitting, now stocks AmmunitionCrates (3) of every distinct AmmoType the ship's weapons draw, after the consumable roll and without touching the random stream; it logs and goes on if no hold takes them. Missiles is authored with Ammo's 1x1 shape and a stack of 5 (a shapeless commodity cannot be stored at all). Tests: generated ships hold exactly the crates they draw and none of an ammunition they do not; a magazine weapon with no AmmoType still reloads free. weapon-ammo moves so RangeFalloff keeps its doc comment; the Munitions comment and lore now match the recipe (warhead and motor, magazines 2 to 288). Co-Authored-By: Claude Sonnet 5.5 --- .../Scripts/ServerShared/LoadoutGenerator.cs | 17 +++++++++ .../AmmunitionStockingTests.cs | 38 +++++++++++++++++++ .../FireControlPerWeaponTests.cs | 14 +++++++ tools/AetherDb/Economy/Munitions.cs | 18 +++++---- tools/AetherDb/Program.cs | 10 ++--- 5 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs diff --git a/Assets/Scripts/ServerShared/LoadoutGenerator.cs b/Assets/Scripts/ServerShared/LoadoutGenerator.cs index 9f4829eee..c82ec1300 100644 --- a/Assets/Scripts/ServerShared/LoadoutGenerator.cs +++ b/Assets/Scripts/ServerShared/LoadoutGenerator.cs @@ -24,6 +24,10 @@ public class LoadoutGenerator public const float ShipConsumableChance = .1f; public const int ShipConsumableUnits = 1; + // Ammunition-fed weapons reload from cargo (ruling ballistics-real-ammo), so a generated ship carries this many crates of every + // distinct AmmoType its weapons draw: enough to fight on past the first magazine, few enough to leave the rest of the hold. + public const int AmmunitionCrates = 3; + public LoadoutGenerator( ref Random random, ItemManager itemManager, @@ -56,6 +60,7 @@ public class LoadoutGenerator OutfitEntity(entity); EquipPickup(entity); StockConsumables(entity, ShipConsumableChance, ShipConsumableUnits); + StockAmmunition(entity); return EntitySerializer.Pack(entity); } @@ -162,6 +167,18 @@ public class LoadoutGenerator } } + // The crates the ship's weapons reload from: AmmunitionCrates of each distinct AmmoType, stopping when no hold takes another. + // Draws nothing from the random stream, so adding it moves no other roll. + private void StockAmmunition(Entity entity) + { + foreach (var key in entity.Weapons.Select(weapon => weapon.WeaponData.AmmoType).Where(type => type.IsSet()).Select(type => type.Key).Distinct()) + { + var crates = new SimpleCommodity { Data = new CultRecordRef(key), Quantity = AmmunitionCrates }; + if (!entity.CargoBays.Any(bay => bay.TryStore(crates))) + ItemManager.Log($"{entity.Name}: no room for {AmmunitionCrates} crates of {key.Value}."); + } + } + private static bool IsHeater(GearData item) => item.HardpointType == HardpointType.Tool && item.Behaviors.Any(b => b is ThermotoggleData { HighPass: false }) && diff --git a/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs b/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs new file mode 100644 index 000000000..1fd278bfe --- /dev/null +++ b/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs @@ -0,0 +1,38 @@ +using System.Linq; +using Xunit; + +// Ruling ballistics-real-ammo: generation stocks combatants with rounds, because a magazine weapon reloads from cargo and a ship with +// no crates fires one magazine and goes quiet. Measured on ships the production generator returns, over the shipped catalog. +public sealed partial class RunStartTests +{ + // Every generated ship whose weapons draw an ammunition type carries crates of each such type; a ship whose weapons draw none + // carries none of an ammunition commodity it does not draw. Kills: generation that stocks nothing (every NPC gun dies after one magazine), + // that stocks only one of several types, or that stocks ships with no use for them. + [Fact] + public void GeneratedShipsCarryTheAmmunitionTheirWeaponsDraw() + { + var generator = new LoadoutGenerator(ref _items.Random, _items, _galaxy, _galaxy.Entrance, _protagonist, .5f); + var shipHulls = LoadoutGenerator.SoldHulls(_cache).Where(h => h.HullType == HullType.Ship).Select(h => h.Name).ToList(); + var ammunition = _cache.GetAll().SelectMany(i => i.Behaviors.OfType()).Where(w => w.AmmoType.IsSet()) + .Select(w => w.AmmoType.Key).Distinct().ToArray(); + Assert.NotEmpty(ammunition); + var fed = 0; + foreach (var name in shipHulls) + for (var i = 0; i < 12; i++) + { + var pack = generator.GenerateShipLoadout(h => h.Name == name); + if (pack == null) continue; + var ship = EntitySerializer.Unpack(_items, null, pack); + var drawn = ship.Weapons.Select(w => w.WeaponData.AmmoType).Where(t => t.IsSet()).Select(t => t.Key).Distinct().ToArray(); + foreach (var key in drawn) + { + Assert.True(ship.CountItemsInCargo(key) > 0, $"{name}: a weapon draws {key.Value} and the hold has none"); + Assert.Equal(LoadoutGenerator.AmmunitionCrates, ship.CountItemsInCargo(key)); + } + foreach (var key in ammunition.Except(drawn)) + Assert.True(ship.CountItemsInCargo(key) == 0, $"{name}: no weapon draws {key.Value} and the hold carries it"); + if (drawn.Length > 0) fed++; + } + Assert.True(fed > 0, "fixture: some generated ship carries an ammunition-fed weapon"); + } +} diff --git a/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs b/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs index 0b5faa343..690bd27d3 100644 --- a/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlPerWeaponTests.cs @@ -1392,4 +1392,18 @@ public sealed class FireControlPerWeaponTests : IDisposable var r = Build(magazine: 2); Assert.Equal(0, r.Gun.Weapon.Reserve); } + + // A magazine weapon that names no ammunition still reloads free and keeps firing: only an AmmoType makes a reload cost a crate. + // Kills: TakeReloadRound refusing when AmmoType is unset, which would silence every unfed magazine gun after one magazine. + [Fact] + public void AMagazineWeaponWithNoAmmunitionTypeStillReloadsFree() + { + var r = Build(fuse: WeaponFuse.Proximity, blast: 30f, range: 40f, magazine: 2, auto: true, reload: 3f); + r.Shooter.SetTarget(TargetRef.None); + Aim(r, float2(0, 1)); + var shots = 0; + r.Zone.ShotCommitted.Subscribe(_ => shots++); + Run(r, 30f); + Assert.True(shots > 4, $"an unfed magazine weapon fires past its first magazine, fired {shots}"); + } } diff --git a/tools/AetherDb/Economy/Munitions.cs b/tools/AetherDb/Economy/Munitions.cs index 2630c2dac..83cbee2f2 100644 --- a/tools/AetherDb/Economy/Munitions.cs +++ b/tools/AetherDb/Economy/Munitions.cs @@ -141,12 +141,16 @@ public sealed class Munitions : EconomyBatch "The same powder as a gun charge, shaped to burn for seconds instead of milliseconds: missile stocks and gun stocks compete for one powder train.", new[] { "thruster" }, (powder, 2), (steel, 1)); - // Missiles: the crate a launcher design reloads from. One crate is one magazine reload (UseAmmo removes one unit of the weapon's - // AmmoType at an empty magazine), the same convention as Ammo for guns. A crate is a warhead and a motor per two missiles' worth - // of magazine; the guidance package (seeker and fin actuators) waits on the electronics chain, so the recipe does not yet draw it. - var missiles = Simple("missiles", "Missiles", "Crated guided munitions: a high-explosive warhead mated to a rocket motor on a launch rail. The crate a launcher reloads from; the rounds are real, only the reactor energy of the launch is not.", 8f, 1800); - Recipe(missiles, "munitions-works", 1200, 24, 2, - "A missile crate is a warhead, a motor and a seeker in one box, and the box is the arsenal's most counted object: Zhestokost ties each launcher crew's allowance to a serial range, so a cache of loose crates is either a deserter's or a quartermaster's crime.", + // Missiles: the crate a launcher design reloads from. One crate is one magazine reload (the reload takes one unit of the weapon's + // AmmoType), the same convention as Ammo for guns, whatever the magazine holds (2 to 288 rounds across the five designs). A crate is + // a warhead and a motor; the guidance package (seeker and fin actuators) waits on the electronics chain, so the recipe does not + // yet draw it. Shape and stack match Ammo's, so a hold takes crates cell for cell. + var missiles = new SimpleCommodityData { Name = "Missiles", Shape = new Shape(), MaxStack = 5, Mass = 8f, Price = 1800, + Description = "Crated guided munitions: a high-explosive warhead mated to a rocket motor on a launch rail. The crate a launcher reloads from; the rounds are real, only the reactor energy of the launch is not." }; + _a.Put(missiles, CommodityKey("missiles")); + var missilesRef = new CultRecordRef(CommodityKey("missiles")); + Recipe(missilesRef, "munitions-works", 1200, 24, 2, + "A missile crate is a warhead and a motor in one box, and the box is the arsenal's most counted object: Zhestokost ties each launcher crew's allowance to a serial range, so a cache of loose crates is either a deserter's or a quartermaster's crime.", new string[0], (warhead, 1), (motor, 1)); var dispenser = Compound("mine-dispenser", "Mine Dispenser", "A rack and ejector that lays mines in a pattern.", 20f, 1600); @@ -165,7 +169,7 @@ public sealed class Munitions : EconomyBatch foreach (var launcher in new[] { "Guided Missile Launcher", "Long-Range Missile Rack", "Short-Range Missile Rack", "Incendiary Rocket Pod", "Swarm Rocket Pod" }) _a.Edit(launcher, w => { - foreach (var data in w.Behaviors.OfType()) data.AmmoType = new CultRecordRef(missiles.Key); + foreach (var data in w.Behaviors.OfType()) data.AmmoType = new CultRecordRef(CommodityKey("missiles")); }); } diff --git a/tools/AetherDb/Program.cs b/tools/AetherDb/Program.cs index 50f97c019..5d3d18e93 100644 --- a/tools/AetherDb/Program.cs +++ b/tools/AetherDb/Program.cs @@ -1105,11 +1105,6 @@ public static class Program return 0; } - // Damage falloff (aetheria-release, damage-curve-fate-ruled): every gun and beam authors an effective range at a - // fraction of its Range (Min and Max scaled, Terms copied so the effective range wears and heats as the range does) - // and a damage multiplier at maximum range. Guided weapons, lock weapons and mine layers keep the unauthored - // defaults (no falloff). The command upserts every weapon design, which is also what drops the retired damage curve - // (key 7) from the stored records. Idempotent: the values are functions of Range alone. Dry run unless "apply". // Read-only: what every weapon design draws per shot (reactor energy, magazine, rounds), so ammunition rulings are audited // against the catalog and not against names. private static int WeaponAmmo() @@ -1123,6 +1118,11 @@ public static class Program return 0; } + // Damage falloff (aetheria-release, damage-curve-fate-ruled): every gun and beam authors an effective range at a + // fraction of its Range (Min and Max scaled, Terms copied so the effective range wears and heats as the range does) + // and a damage multiplier at maximum range. Guided weapons, lock weapons and mine layers keep the unauthored + // defaults (no falloff). The command upserts every weapon design, which is also what drops the retired damage curve + // (key 7) from the stored records. Idempotent: the values are functions of Range alone. Dry run unless "apply". private static int RangeFalloff(string[] args) { var apply = args.Contains("apply");