Every generated ship carries a tractor beam; AetherDb pickup-catalog turns the Tractor Beam into Pickup gear (group B, code)
GenerateShipLoadout equips one gear whose behaviours include PickupData after the shared outfitting (stations and turrets get none). The pickup-catalog command (retired in the next commit after apply) edits the existing Tractor Beam. PickupTests: two fixes found by group A's run (equip is refused once a ship is deployed, and the freeing tick takes one step). PickupGenerationTests needs the applied catalog and is red until the catalog commit; the catalog itself is not in this commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e7a35135fe
commit
68430771f3
4 changed files with 119 additions and 12 deletions
|
|
@ -54,6 +54,7 @@ public class LoadoutGenerator
|
|||
var entity = new Ship(ItemManager, null, hull, ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
entity.Faction = Faction;
|
||||
OutfitEntity(entity);
|
||||
EquipPickup(entity);
|
||||
StockConsumables(entity, ShipConsumableChance, ShipConsumableUnits);
|
||||
return EntitySerializer.Pack(entity);
|
||||
}
|
||||
|
|
@ -287,6 +288,24 @@ public class LoadoutGenerator
|
|||
FillInterior(entity);
|
||||
}
|
||||
|
||||
// Every ship carries a tractor beam: picking up needs a pickup behaviour (scenarios ruling, "everyone gets tractor
|
||||
// beams"). It goes in after the shared outfitting, which stations and turrets also run and which adds none, into
|
||||
// whatever interior the hull has left; a hull with no cell for one cannot be generated.
|
||||
private void EquipPickup(Entity entity)
|
||||
{
|
||||
var emptyShape = entity.UnoccupiedSpace;
|
||||
var (product, design) = RandomProduct<GearData>(2, item =>
|
||||
item.Behaviors.Any(b => b is PickupData) &&
|
||||
item.Shape.FitsWithin(emptyShape, out _, out _), required: true);
|
||||
if (design == null) throw new InvalidLoadoutException("No compatible tractor beam found for ship!");
|
||||
|
||||
design.Shape.FitsWithin(emptyShape, out var rotation, out var position);
|
||||
var beam = ItemManager.CreateInstance(product) as EquippableItem;
|
||||
beam.Rotation = rotation;
|
||||
if (!entity.TryEquip(beam, position))
|
||||
throw new InvalidLoadoutException("Failed to equip selected tractor beam!");
|
||||
}
|
||||
|
||||
private void EquipHardpoints(Entity entity)
|
||||
{
|
||||
var hullData = ItemManager.GetData(entity.Hull) as HullData;
|
||||
|
|
|
|||
44
tests/Aetheria.Shared.Tests/PickupGenerationTests.cs
Normal file
44
tests/Aetheria.Shared.Tests/PickupGenerationTests.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
// Pickup is a capability (aetheria-release cut loot-2), so a ship that can pick things up carries the gear that grants
|
||||
// it. Generation is the one place a ship's gear is chosen, so this runs the real catalog through it.
|
||||
public sealed partial class RunStartTests
|
||||
{
|
||||
private int PickupGear(EntityPack pack) => EntitySerializer.Items(pack).OfType<EquippableItem>()
|
||||
.Count(item => _items.GetData(item) is GearData gear && gear.Behaviors.Any(b => b is PickupData));
|
||||
|
||||
[Fact]
|
||||
public void EveryGeneratedShipCarriesATractorBeam()
|
||||
{
|
||||
// Every ship hull a product sells.
|
||||
var generator = PreludeGenerator();
|
||||
foreach (var hull in LoadoutGenerator.SoldHulls(_cache).Where(hull => hull.HullType == HullType.Ship))
|
||||
Assert.True(PickupGear(generator.GenerateShipLoadout(candidate => candidate == hull)) == 1, $"a {hull.Name} carries exactly one tractor beam");
|
||||
|
||||
// Ships generated for each faction of a main galaxy, and the starting ship the game stages.
|
||||
var main = Launch(new MainGalaxy(), Inputs(() => GalaxySeed));
|
||||
Assert.Empty(main.failures);
|
||||
var factions = main.galaxy.Factions.ToArray();
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var faction = factions[i % factions.Length];
|
||||
var maker = new LoadoutGenerator(ref _items.Random, _items, main.galaxy, main.galaxy.Entrance, faction, .5f);
|
||||
Assert.True(PickupGear(maker.GenerateShipLoadout()) == 1, $"ship {i} of {faction.Name} carries exactly one tractor beam");
|
||||
}
|
||||
Assert.Equal(1, main.staged.Player.Equipment.Count(item => item.Behaviors.OfType<Pickup>().Any()));
|
||||
Assert.All(main.arena.Pack.Entities.Where(pack => pack is ShipPack), pack => Assert.Equal(1, PickupGear(pack)));
|
||||
|
||||
// Stations and turrets share the interior outfitting and get none.
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.Equal(0, PickupGear(generator.GenerateStationLoadout()));
|
||||
Assert.Equal(0, PickupGear(generator.GenerateTurretLoadout()));
|
||||
}
|
||||
Assert.All(main.arena.Pack.Entities.Where(pack => !(pack is ShipPack)), pack => Assert.Equal(0, PickupGear(pack)));
|
||||
}
|
||||
}
|
||||
|
|
@ -144,19 +144,24 @@ public sealed class PickupTests : IDisposable
|
|||
public void NoPickupBehaviourNoGrab()
|
||||
{
|
||||
using var bag = new CompositeDisposable();
|
||||
|
||||
// The same ship and item, with and without the gear: only the gear grabs.
|
||||
var bare = Build(Beam());
|
||||
var plain = Spawn(bare, float3(0, 0, 0), beam: false);
|
||||
var left = Drift(bare, 40, 0);
|
||||
var plainEvents = Watch(plain, bag);
|
||||
plain.TractorCommand = 1;
|
||||
Tick(bare, 240, 1 / 60f);
|
||||
Assert.Null(left.Holder);
|
||||
Assert.Contains(left, bare.Zone.FloatingItems);
|
||||
Assert.Equal(0f, plain.TractorPower);
|
||||
Assert.Empty(plainEvents);
|
||||
|
||||
var lab = Build(Beam());
|
||||
var ship = Spawn(lab, float3(0, 0, 0), beam: false);
|
||||
var ship = Spawn(lab, float3(0, 0, 0));
|
||||
var item = Drift(lab, 40, 0);
|
||||
var events = Watch(ship, bag);
|
||||
ship.TractorCommand = 1;
|
||||
Tick(lab, 240, 1 / 60f);
|
||||
Assert.Null(item.Holder);
|
||||
Assert.Contains(item, lab.Zone.FloatingItems);
|
||||
Assert.Equal(0f, ship.TractorPower);
|
||||
Assert.Empty(events);
|
||||
|
||||
// The same ship with the beam equipped claims the item.
|
||||
Equip(ship, lab.Make("Tractor"));
|
||||
Tick(lab, 60, 1 / 60f);
|
||||
Assert.Same(ship, item.Holder);
|
||||
Assert.Equal(GrabPhase.Started, events.First().Phase);
|
||||
|
|
@ -271,8 +276,10 @@ public sealed class PickupTests : IDisposable
|
|||
Assert.DoesNotContain(events, e => e.Phase == GrabPhase.Completed);
|
||||
Assert.Null(item.Holder);
|
||||
Assert.Contains(item, lab.Zone.FloatingItems);
|
||||
Assert.Equal(velocity, item.Body.Velocity);
|
||||
Assert.Equal(drift, item.Body.Drift);
|
||||
// (It has taken the one step of its freeing tick, so it is the held velocity less a tick's drag.)
|
||||
Assert.Equal(velocity.x, item.Body.Velocity.x, velocity.x * .01f);
|
||||
Assert.Equal(velocity.y, item.Body.Velocity.y, velocity.y * .01f);
|
||||
Assert.True(velocity.x > 1f);
|
||||
|
||||
// It drifts on with that velocity and expires on the clock it was released on, not from the cancel.
|
||||
var at = item.Body.Position;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public static class Program
|
|||
case "field-kinds": return FieldKindsCatalog(args.Contains("apply"));
|
||||
case "pd-gear": return PdGearCatalog(args.Contains("apply"));
|
||||
case "mine-launcher": return MineLauncherCatalog(args.Contains("apply"));
|
||||
case "pickup-catalog": return PickupCatalog(args.Contains("apply"));
|
||||
case "smoke-hull": return SmokeHullCatalog(args.Contains("apply"));
|
||||
case "smoke-rounds": return SmokeRoundsCatalog(args.Contains("apply"));
|
||||
case "roles-backfill": return RolesBackfill(args.Contains("apply"));
|
||||
|
|
@ -51,7 +52,7 @@ public static class Program
|
|||
return PiratesFaction(args.Contains("apply"));
|
||||
case "verse-grammar": return VerseGrammarCommand.Run(args.Contains("apply"));
|
||||
default:
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], pirates-faction [apply], verse-grammar [apply]");
|
||||
Console.WriteLine("commands: census, factions, station-fit, hardpoint-fit, loadout [seed], save, settings, settings-dump, dangling [clear <Type.Member>]... [apply], shield-migrate [apply], brownout-migrate [apply], roles-migrate [apply], firing-arc-migrate [apply], targeting-catalog [apply], targeting-catalog-6c [apply], targeting-catalog-6d [apply], ship-authoring create|inspect|validate|compose, field-kinds [apply], mine-launcher [apply], pickup-catalog [apply], smoke-hull [apply], smoke-rounds [apply], roles-backfill [apply], pd-gear [apply], consumables-first-set [apply], pirates-faction [apply], verse-grammar [apply]");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1767,6 +1768,42 @@ public static class Program
|
|||
return 0;
|
||||
}
|
||||
|
||||
// loot-2: pickup is a capability. The existing Tractor Beam (a Sensors-hardpoint item with no behaviours) becomes
|
||||
// Tool gear whose one behaviour is Pickup, so a ship carries it in any free interior cell and Zone's pickup needs
|
||||
// it. The numbers are the retired prefab's beam: range 75, beam radius 25; the grab's phase times, the spin-up
|
||||
// rate and the power needed to grab are the cut's. Dry run unless passed "apply".
|
||||
private static int PickupCatalog(bool apply)
|
||||
{
|
||||
const string name = "Tractor Beam";
|
||||
var db = AetherDb.Open(catalogWritable: apply);
|
||||
var beam = db.Cache.GetAll<GearData>().Single(gear => gear.Name == name);
|
||||
if (beam.Hardpoint == HardpointType.Tool && beam.Behaviors.Count == 1 && beam.Behaviors[0] is PickupData)
|
||||
{
|
||||
Console.WriteLine($"\"{name}\" is already authored; nothing to do.");
|
||||
return 0;
|
||||
}
|
||||
if (beam.Behaviors.Count != 0) throw new InvalidOperationException($"\"{name}\" already has behaviours.");
|
||||
Console.WriteLine($"\"{name}\" hardpoint {beam.Hardpoint} -> Tool, no behaviours -> one Pickup (range 75, beam radius 25, grab power .5, extend .3, envelop .2, pull .5, spin rate 2).");
|
||||
if (!apply)
|
||||
{
|
||||
Console.WriteLine("
|
||||
Dry run. Pass \"apply\" to write it.");
|
||||
return 0;
|
||||
}
|
||||
PerformanceStat Constant(float v) => new PerformanceStat { Min = v, Max = v };
|
||||
beam.Hardpoint = HardpointType.Tool;
|
||||
beam.Behaviors.Add(new PickupData
|
||||
{
|
||||
Range = Constant(75), BeamRadius = Constant(25), GrabPower = Constant(.5f), SpinRate = Constant(2),
|
||||
ExtendTime = Constant(.3f), EnvelopTime = Constant(.2f), PullTime = Constant(.5f)
|
||||
});
|
||||
CultRecordRefs.Validate(beam);
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(GearData), beam, db.Cache.RefOf(beam).Key));
|
||||
Console.WriteLine($"
|
||||
Wrote \"{name}\" to Aetheria.cc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sim-mines-presenter: the Mine Launcher item, so a ship can be fitted with the sim's mine layer. Its numbers
|
||||
// are the 2021 record's (GameData/Legacy/AetherDB.2021-03-05.msgpack, recovered in 8c71a637: mass 75, price
|
||||
// 125000, damage 50, range 2000, energy 15, heat 500, visibility 10, magazine 6, reload 5, spread 5, velocity
|
||||
|
|
|
|||
Loading…
Reference in a new issue