Turret placement: stations at L4/L5 in turns, turrets flank by hull reach

CreateLagrangeOrbit adds one sixth of a turn (was PI / 3 on a turns field).
PlaceTurret spaces turrets by k * (stationReach + 2 * turretReach) arcs,
k = -1, +1, -2, +2 (was t / 2 integer division putting two turrets on the
station, and radians-per-arc arithmetic on turns). Contacts.Radius moves to
HullData.Reach. Not yet verified on Yggdrasil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-16 02:29:57 +02:00
commit 089c3ecad1
4 changed files with 213 additions and 27 deletions

View file

@ -33,19 +33,7 @@ public readonly struct ContactEvent
public static class Contacts
{
// The farthest corner of any occupied hull cell from the centre of mass the schematic frame uses, in world
// units: a true bound on how far the hull reaches from Position (the half-diagonal of the bounding box is not,
// as FireControl.Detonate's comment records). A cell at (x, y) spans x +/- .5 and y +/- .5.
public static float Radius(Entity e)
{
var shape = e.HullData.Shape;
var com = shape.CenterOfMass;
var far = 0f;
foreach (var c in shape.Coordinates)
foreach (var (dx, dy) in new[] { (-.5f, -.5f), (.5f, -.5f), (-.5f, .5f), (.5f, .5f) })
far = max(far, length(float2(c.x + dx, c.y + dy) - com));
return far * e.ItemManager.GameplaySettings.SchematicCellSize;
}
public static float Radius(Entity e) => e.HullData.Reach(e.ItemManager.GameplaySettings.SchematicCellSize);
// For each unordered pair of the zone's entities, in list order: if their discs touch and are closing along
// the normal, the impulse moves each one's velocity along the normal only (the tangent components are

View file

@ -536,6 +536,19 @@ public class HullData : EquippableItemData
[Inspectable, JsonProperty("visual"), Key(32)]
public CultRecordRef<ShipAuthoring> Visual;
// The farthest corner of any occupied hull cell from the centre of mass the schematic frame uses, in world
// units: a true bound on how far the hull reaches from its position (the half-diagonal of the bounding box is not,
// as FireControl.Detonate's comment records). A cell at (x, y) spans x +/- .5 and y +/- .5.
public float Reach(float cellSize)
{
var com = Shape.CenterOfMass;
var far = 0f;
foreach (var c in Shape.Coordinates)
foreach (var (dx, dy) in new[] { (-.5f, -.5f), (.5f, -.5f), (-.5f, .5f), (.5f, .5f) })
far = max(far, length(float2(c.x + dx, c.y + dy) - com));
return far * cellSize;
}
[IgnoreMember]
public Shape InteriorCells
{

View file

@ -256,45 +256,51 @@ public static class ZoneGenerator
return loadoutGenerators[faction];
}
// L4 or L5: 60 degrees (one sixth of a turn) ahead of or behind the planet on its orbit. Phase is in turns.
OrbitData CreateLagrangeOrbit(OrbitData baseOrbit)
{
var lagrangeOrbit = new OrbitData
{
Parent = baseOrbit.Parent,
Distance = baseOrbit.Distance,
Phase = baseOrbit.Phase + PI / 3 * sign(random.NextFloat() - .5f),
Phase = baseOrbit.Phase + sign(random.NextFloat() - .5f) / 6f,
};
pack.Orbits.Add(cache.Upsert(lagrangeOrbit));
return lagrangeOrbit;
}
void PlaceTurret(OrbitData orbit, LoadoutGenerator loadoutGenerator, int distanceMultiplier)
// A turret co-orbits with its station, k arcs along the orbit (k is signed: behind the station when negative).
// One arc is the station's reach plus two of the turret's: the first turret's disc clears the station's by one
// turret radius, and turrets step by the same arc, which also clears each other (stationReach + 2 turretReach
// is more than 2 turretReach). Phase is in turns, so the arc length divides by the orbit's circumference.
void PlaceTurret(OrbitData orbit, LoadoutGenerator loadoutGenerator, int k, float stationReach)
{
var phase = 20f * distanceMultiplier / orbit.Distance;
var turret = loadoutGenerator.GenerateTurretLoadout();
if (turret == null) return;
var turretReach = (itemManager.GetData(turret.Hull) as HullData).Reach(itemManager.GameplaySettings.SchematicCellSize);
var arc = k * (stationReach + 2 * turretReach);
var turretOrbit = new OrbitData
{
Parent = orbit.Parent,
Distance = orbit.Distance,
Phase = orbit.Phase + phase
Phase = orbit.Phase + arc / (2 * PI * orbit.Distance)
};
pack.Orbits.Add(cache.Upsert(turretOrbit));
var turret = loadoutGenerator.GenerateTurretLoadout();
if (turret == null) return;
turret.Orbit = cache.RefOf(turretOrbit);
pack.Entities.Add(turret);
}
void PlaceTurrets(OrbitData orbit, LoadoutGenerator loadoutGenerator, int count)
// Turrets flank the station alternately: k runs -1, +1, -2, +2, ...
void PlaceTurrets(OrbitData orbit, LoadoutGenerator loadoutGenerator, int count, float stationReach)
{
for(int t=0; t<count; t++)
{
var dist = t / 2;
if (t % 2 == 0) dist = -dist;
PlaceTurret(orbit, loadoutGenerator, dist);
}
PlaceTurret(orbit, loadoutGenerator, (t / 2 + 1) * (t % 2 == 0 ? -1 : 1), stationReach);
}
float StationReach(OrbitalEntityPack station) =>
(itemManager.GetData(station.Hull) as HullData).Reach(itemManager.GameplaySettings.SchematicCellSize);
for (var i = 0; i < storyStations.Length; i++)
{
var story = storyStations[i];
@ -312,7 +318,7 @@ public static class ZoneGenerator
station.Story = i;
pack.Entities.Add(station);
if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(story.Faction), story.Turrets);
if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(story.Faction), story.Turrets, StationReach(station));
}
for (var i = storyStations.Length; i < selectedStationOrbits.Length; i++)
@ -334,7 +340,7 @@ public static class ZoneGenerator
station.SecurityRadius = pack.Radius;
pack.Entities.Add(station);
if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(nearestFaction), 2);
if (ambient) PlaceTurrets(lagrangeOrbit, GetLoadoutGenerator(nearestFaction), 2, StationReach(station));
}
// A boss zone gets its faction's boss whether or not the zone is ambient: the boss is the run's goal, not