Merge cut turret-placement (closing verdicts cut-turret-placement.s1, cut-turret-placement.s2)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
f50c4cb6c9
4 changed files with 319 additions and 25 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -256,45 +256,60 @@ 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, on one side of it (side is -1 behind, +1 ahead), clear of the body inside
|
||||
// it on that side by one of the turret's own radii: its centre sits innerReach + 2 turretReach beyond that
|
||||
// body's. Every body's reach counts, so turrets of differing reach clear each other. Phase is in turns, so the
|
||||
// arc length divides by the orbit's circumference. Returns where the turret sits (signed arc from the station)
|
||||
// and its reach, or null when there is no turret hull to generate, before any orbit is created.
|
||||
(float arc, float reach)? PlaceTurret(OrbitData orbit, LoadoutGenerator loadoutGenerator, float side, float innerArc, float innerReach)
|
||||
{
|
||||
var phase = 20f * distanceMultiplier / orbit.Distance;
|
||||
var turret = loadoutGenerator.GenerateTurretLoadout();
|
||||
if (turret == null) return null;
|
||||
var turretReach = (itemManager.GetData(turret.Hull) as HullData).Reach(itemManager.GameplaySettings.SchematicCellSize);
|
||||
var arc = innerArc + side * (innerReach + 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);
|
||||
return (arc, turretReach);
|
||||
}
|
||||
|
||||
void PlaceTurrets(OrbitData orbit, LoadoutGenerator loadoutGenerator, int count)
|
||||
// Turrets flank the station alternately, behind then ahead, each side growing outward from the station.
|
||||
void PlaceTurrets(OrbitData orbit, LoadoutGenerator loadoutGenerator, int count, float stationReach)
|
||||
{
|
||||
var arcs = new float[2];
|
||||
var reaches = new[] { stationReach, stationReach };
|
||||
for(int t=0; t<count; t++)
|
||||
{
|
||||
var dist = t / 2;
|
||||
if (t % 2 == 0) dist = -dist;
|
||||
PlaceTurret(orbit, loadoutGenerator, dist);
|
||||
var side = t % 2;
|
||||
var placed = PlaceTurret(orbit, loadoutGenerator, side == 0 ? -1f : 1f, arcs[side], reaches[side]);
|
||||
if (placed == null) return;
|
||||
(arcs[side], reaches[side]) = placed.Value;
|
||||
}
|
||||
}
|
||||
|
||||
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 +327,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 +349,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue