From 35fa50f2561aef083dc9817ecbba772ebe9a1b6a Mon Sep 17 00:00:00 2001 From: Nibu Date: Wed, 11 Nov 2026 03:12:36 +0000 Subject: [PATCH] Generated turrets are stocked with the crates their weapons reload from GenerateTurretLoadout calls the same StockAmmunition as ships; an ammo-fed turret otherwise went quiet after one magazine. Test: generated turrets hold exactly the crates for each ammunition type they draw. Co-Authored-By: Claude Sonnet 5.5 --- .../Scripts/ServerShared/LoadoutGenerator.cs | 1 + .../AmmunitionStockingTests.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Assets/Scripts/ServerShared/LoadoutGenerator.cs b/Assets/Scripts/ServerShared/LoadoutGenerator.cs index c82ec1300..93c00aff9 100644 --- a/Assets/Scripts/ServerShared/LoadoutGenerator.cs +++ b/Assets/Scripts/ServerShared/LoadoutGenerator.cs @@ -76,6 +76,7 @@ public class LoadoutGenerator var entity = new OrbitalEntity(ItemManager, null, hull, default, ItemManager.GameplaySettings.DefaultEntitySettings); entity.Faction = Faction; OutfitEntity(entity); + StockAmmunition(entity); return EntitySerializer.Pack(entity) as OrbitalEntityPack; } diff --git a/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs b/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs index 1fd278bfe..d1d0f1317 100644 --- a/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs +++ b/tests/Aetheria.Shared.Tests/AmmunitionStockingTests.cs @@ -35,4 +35,23 @@ public sealed partial class RunStartTests } Assert.True(fed > 0, "fixture: some generated ship carries an ammunition-fed weapon"); } + + // A generated turret reloads from its own hold like a ship: every ammunition type its weapons draw has crates in it. Kills: a turret + // path that skips StockAmmunition, which leaves an ammo-fed turret quiet after one magazine. + [Fact] + public void GeneratedTurretsCarryTheAmmunitionTheirWeaponsDraw() + { + var generator = new LoadoutGenerator(ref _items.Random, _items, _galaxy, _galaxy.Entrance, _protagonist, .5f); + var fed = 0; + for (var i = 0; i < 60; i++) + { + var turret = EntitySerializer.Unpack(_items, null, generator.GenerateTurretLoadout()); + foreach (var key in turret.Weapons.Select(w => w.WeaponData.AmmoType).Where(t => t.IsSet()).Select(t => t.Key).Distinct()) + { + fed++; + Assert.Equal(LoadoutGenerator.AmmunitionCrates, turret.CountItemsInCargo(key)); + } + } + Assert.True(fed > 0, "fixture: some generated turret carries an ammunition-fed weapon"); + } }