Move local RTS level generation into daemon
This commit is contained in:
parent
4f05925bd9
commit
892ab93df4
2 changed files with 472 additions and 438 deletions
|
|
@ -1666,341 +1666,11 @@ static async Task EnsurePlayableRunDocumentsAsync(AetheriaStateNode node, string
|
|||
return;
|
||||
}
|
||||
|
||||
const string runId = "local-rts";
|
||||
var runKey = new CultRecordKey("global:aetheria.run_state.local-rts.v1");
|
||||
var zoneKey = new CultRecordKey("global:aetheria.zone_state.local-rts.0.v1");
|
||||
var entityKeys = Enumerable.Range(0, 8)
|
||||
.Select(index => EntityKey(runId, 0, index))
|
||||
.ToArray();
|
||||
|
||||
settings ??= new AetheriaPlayerSettings();
|
||||
settings.ActiveRunKey = runKey.ToString();
|
||||
settings.PlayerName = string.IsNullOrWhiteSpace(settings.PlayerName) ? "Codex RTS" : settings.PlayerName;
|
||||
settings.TutorialPassed = true;
|
||||
settings.LastUpdatedAtUtc = now;
|
||||
await node.MutableDocument<AetheriaPlayerSettings>(AetheriaStateNode.PlayerSettingsKey)
|
||||
.ReplaceAsync(settings)
|
||||
await AetheriaDaemonZoneGenerator.WritePlayableRunAsync(
|
||||
node,
|
||||
node.RuntimeCatalog().Latest(),
|
||||
now)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await node.MutableDocument<AetheriaRunState>(runKey).ReplaceAsync(new AetheriaRunState
|
||||
{
|
||||
RunId = runId,
|
||||
EntranceZoneIndex = 0,
|
||||
ExitZoneIndex = 0,
|
||||
CurrentZoneIndex = 0,
|
||||
DiscoveredZoneIndices = [0],
|
||||
ZoneKeys = [zoneKey.ToString()],
|
||||
GenerationSeed = 0xA37E_12u,
|
||||
CurrentEntityKey = entityKeys[0],
|
||||
UpdatedAtUtc = now
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
await node.MutableDocument<AetheriaZoneState>(zoneKey).ReplaceAsync(new AetheriaZoneState
|
||||
{
|
||||
Name = "Daemon Local Testbed",
|
||||
Position = Vec2(0, 0),
|
||||
EntityKeys = entityKeys,
|
||||
FactionIndices = [0, 1],
|
||||
OwnerFactionIndex = 0,
|
||||
Orbits =
|
||||
[
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(0, 0)
|
||||
},
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.belt.orbit",
|
||||
ParentOrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(360, -180),
|
||||
Distance = 402,
|
||||
Phase = 0.33
|
||||
},
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.blue.orbit",
|
||||
ParentOrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(-540, 340),
|
||||
Distance = 636,
|
||||
Phase = 2.58
|
||||
},
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.ember.orbit",
|
||||
ParentOrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(-680, -420),
|
||||
Distance = 799,
|
||||
Phase = 3.70
|
||||
},
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.outer.orbit",
|
||||
ParentOrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(780, 420),
|
||||
Distance = 886,
|
||||
Phase = 0.49
|
||||
},
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitKey = "local.lagrange.orbit",
|
||||
ParentOrbitKey = "local.sun.orbit",
|
||||
FixedPosition = Vec2(-160, 620),
|
||||
Distance = 640,
|
||||
Phase = 1.82
|
||||
}
|
||||
],
|
||||
Bodies =
|
||||
[
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.sun",
|
||||
Kind = "sun",
|
||||
Name = "Local Sun",
|
||||
OrbitKey = "local.sun.orbit",
|
||||
Mass = 1000,
|
||||
BodyRadiusMultiplier = 2.2,
|
||||
GravityInfluenceCenterX = 0,
|
||||
GravityInfluenceCenterZ = 0,
|
||||
GravityInfluenceRadius = 900,
|
||||
GravityWellDepth = -80,
|
||||
GravityDepthExponent = 3,
|
||||
GravityWaveRadius = 450,
|
||||
GravityWaveDepth = 10,
|
||||
GravityWaveSpeed = 2,
|
||||
SunVisual = new AetheriaSunVisualState
|
||||
{
|
||||
LightColor = Vec3(1, 0.86, 0.58),
|
||||
FogTintColor = Vec3(0.45, 0.28, 0.16),
|
||||
LightRadiusMultiplier = 1.8
|
||||
}
|
||||
},
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.belt",
|
||||
Kind = "asteroid_belt",
|
||||
Name = "Cinder Belt",
|
||||
OrbitKey = "local.belt.orbit",
|
||||
Mass = 120,
|
||||
BodyRadiusMultiplier = 1.0,
|
||||
GravityInfluenceCenterX = 360,
|
||||
GravityInfluenceCenterZ = -180,
|
||||
GravityInfluenceRadius = 260,
|
||||
GravityWellDepth = -22,
|
||||
GravityDepthExponent = 2.2,
|
||||
GravityWaveRadius = 120,
|
||||
GravityWaveDepth = 4,
|
||||
GravityWaveSpeed = 0.8,
|
||||
Asteroids =
|
||||
[
|
||||
new AetheriaAsteroidSnapshot { Distance = 42, Phase = 0.10, Size = 1.1, RotationSpeed = 0.2 },
|
||||
new AetheriaAsteroidSnapshot { Distance = 78, Phase = 1.70, Size = 0.8, RotationSpeed = -0.1 },
|
||||
new AetheriaAsteroidSnapshot { Distance = 118, Phase = 3.35, Size = 1.6, RotationSpeed = 0.08 }
|
||||
]
|
||||
},
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.blue",
|
||||
Kind = "planet",
|
||||
Name = "Blueglass",
|
||||
OrbitKey = "local.blue.orbit",
|
||||
Mass = 220,
|
||||
BodyRadiusMultiplier = 1.25,
|
||||
GravityInfluenceCenterX = -540,
|
||||
GravityInfluenceCenterZ = 340,
|
||||
GravityInfluenceRadius = 340,
|
||||
GravityWellDepth = -34,
|
||||
GravityDepthExponent = 2.6,
|
||||
GravityWaveRadius = 150,
|
||||
GravityWaveDepth = 5,
|
||||
GravityWaveSpeed = 1.1
|
||||
},
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.ember",
|
||||
Kind = "planet",
|
||||
Name = "Emberhook",
|
||||
OrbitKey = "local.ember.orbit",
|
||||
Mass = 180,
|
||||
BodyRadiusMultiplier = 1.05,
|
||||
GravityInfluenceCenterX = -680,
|
||||
GravityInfluenceCenterZ = -420,
|
||||
GravityInfluenceRadius = 310,
|
||||
GravityWellDepth = -28,
|
||||
GravityDepthExponent = 2.1,
|
||||
GravityWaveRadius = 130,
|
||||
GravityWaveDepth = 4,
|
||||
GravityWaveSpeed = 1.3
|
||||
},
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.outer",
|
||||
Kind = "gas_giant",
|
||||
Name = "Vesper",
|
||||
OrbitKey = "local.outer.orbit",
|
||||
Mass = 260,
|
||||
BodyRadiusMultiplier = 1.45,
|
||||
GravityInfluenceCenterX = 780,
|
||||
GravityInfluenceCenterZ = 420,
|
||||
GravityInfluenceRadius = 420,
|
||||
GravityWellDepth = -38,
|
||||
GravityDepthExponent = 2.4,
|
||||
GravityWaveRadius = 210,
|
||||
GravityWaveDepth = 6,
|
||||
GravityWaveSpeed = 0.7
|
||||
},
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyKey = "local.lagrange",
|
||||
Kind = "moon",
|
||||
Name = "Latch",
|
||||
OrbitKey = "local.lagrange.orbit",
|
||||
Mass = 90,
|
||||
BodyRadiusMultiplier = 0.82,
|
||||
GravityInfluenceCenterX = -160,
|
||||
GravityInfluenceCenterZ = 620,
|
||||
GravityInfluenceRadius = 210,
|
||||
GravityWellDepth = -18,
|
||||
GravityDepthExponent = 2.8,
|
||||
GravityWaveRadius = 95,
|
||||
GravityWaveDepth = 3,
|
||||
GravityWaveSpeed = 1.6
|
||||
}
|
||||
],
|
||||
GravityTerrainRadius = 1450,
|
||||
GravityTerrainDepth = -8,
|
||||
GravityTerrainDepthExponent = 1.2,
|
||||
GravityTerrainWaveFrequency = 0.6
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[0])).ReplaceAsync(SeedEntity(
|
||||
"Anchor Station",
|
||||
"station",
|
||||
Vec3(-220, 0, -90),
|
||||
Vec2(1, 0),
|
||||
Vec2(0, 0),
|
||||
"player",
|
||||
"anchor-station-hull",
|
||||
720,
|
||||
entityKeys[4],
|
||||
[
|
||||
Contact(entityKeys[1], 1, false),
|
||||
Contact(entityKeys[2], 1, false),
|
||||
Contact(entityKeys[3], 1, false),
|
||||
Contact(entityKeys[4], 1, true),
|
||||
Contact(entityKeys[5], 0.8, true),
|
||||
Contact(entityKeys[7], 0.6, false)
|
||||
],
|
||||
["repair-parts", "reactor-fuel", "drone-core"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[1])).ReplaceAsync(SeedEntity(
|
||||
"Vanguard One",
|
||||
"ship",
|
||||
Vec3(-60, 0, -40),
|
||||
Vec2(1, 0.2),
|
||||
Vec2(12, 4),
|
||||
"player",
|
||||
"ship-hull",
|
||||
520,
|
||||
entityKeys[4],
|
||||
[
|
||||
Contact(entityKeys[0], 1, false),
|
||||
Contact(entityKeys[2], 1, false),
|
||||
Contact(entityKeys[4], 1, true),
|
||||
Contact(entityKeys[5], 0.85, true)
|
||||
],
|
||||
["coilgun-ammo", "field-rations"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[2])).ReplaceAsync(SeedEntity(
|
||||
"Wing Two",
|
||||
"ship",
|
||||
Vec3(180, 0, 120),
|
||||
Vec2(-0.4, 0.9),
|
||||
Vec2(-6, 8),
|
||||
"player",
|
||||
"frigate-hull",
|
||||
420,
|
||||
entityKeys[4],
|
||||
[
|
||||
Contact(entityKeys[0], 1, false),
|
||||
Contact(entityKeys[1], 1, false),
|
||||
Contact(entityKeys[4], 0.85, true),
|
||||
Contact(entityKeys[6], 0.6, true)
|
||||
],
|
||||
["sensor-buoy", "shield-cell"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[3])).ReplaceAsync(SeedEntity(
|
||||
"Torch Three",
|
||||
"ship",
|
||||
Vec3(-160, 0, 210),
|
||||
Vec2(0.6, -0.8),
|
||||
Vec2(8, -5),
|
||||
"player",
|
||||
"interceptor-hull",
|
||||
480,
|
||||
entityKeys[5],
|
||||
[
|
||||
Contact(entityKeys[0], 1, false),
|
||||
Contact(entityKeys[1], 1, false),
|
||||
Contact(entityKeys[5], 0.9, true)
|
||||
],
|
||||
["micro-missile", "coolant-pack"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[4])).ReplaceAsync(SeedEntity(
|
||||
"Ash Raider",
|
||||
"ship",
|
||||
Vec3(420, 0, 180),
|
||||
Vec2(-0.8, -0.1),
|
||||
Vec2(-4, -2),
|
||||
"raider",
|
||||
"raider-hull",
|
||||
300,
|
||||
entityKeys[1],
|
||||
[
|
||||
Contact(entityKeys[0], 1, true),
|
||||
Contact(entityKeys[1], 1, true),
|
||||
Contact(entityKeys[2], 0.5, true)
|
||||
],
|
||||
["scrap-metal", "stolen-capacitor"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[5])).ReplaceAsync(SeedEntity(
|
||||
"Cinder Knife",
|
||||
"ship",
|
||||
Vec3(560, 0, -110),
|
||||
Vec2(-0.9, 0.2),
|
||||
Vec2(-7, 1),
|
||||
"raider",
|
||||
"raider-interceptor-hull",
|
||||
260,
|
||||
entityKeys[3],
|
||||
[
|
||||
Contact(entityKeys[0], 0.8, true),
|
||||
Contact(entityKeys[3], 1, true)
|
||||
],
|
||||
["volatile-fuel"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[6])).ReplaceAsync(SeedEntity(
|
||||
"Blackwake",
|
||||
"ship",
|
||||
Vec3(680, 0, 260),
|
||||
Vec2(-0.7, -0.4),
|
||||
Vec2(-4, -3),
|
||||
"raider",
|
||||
"raider-heavy-hull",
|
||||
220,
|
||||
entityKeys[2],
|
||||
[
|
||||
Contact(entityKeys[2], 0.8, true)
|
||||
],
|
||||
["ore-cache", "burned-relay-core"])).ConfigureAwait(false);
|
||||
await node.MutableDocument<AetheriaEntitySnapshot>(new CultRecordKey(entityKeys[7])).ReplaceAsync(SeedEntity(
|
||||
"Derelict Relay",
|
||||
"station",
|
||||
Vec3(-260, 0, 260),
|
||||
Vec2(0, 1),
|
||||
Vec2(0, 0),
|
||||
"neutral",
|
||||
"station-hull",
|
||||
140,
|
||||
"",
|
||||
[],
|
||||
["ancient-transponder"])).ConfigureAwait(false);
|
||||
|
||||
await node.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
static async Task EnsureStarbridgeSessionDocumentsAsync(
|
||||
|
|
@ -2438,103 +2108,13 @@ static bool HasRtsScenario(AetheriaRuntimeRunCheckpointCommit? run)
|
|||
var zones = run?.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>();
|
||||
var entities = zones.SelectMany(zone => zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>()).ToArray();
|
||||
var bodies = zones.SelectMany(zone => zone.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>()).ToArray();
|
||||
return entities.Any(entity => string.Equals(entity.Name, "Anchor Station", StringComparison.Ordinal)) &&
|
||||
return run?.GenerationSeed == AetheriaDaemonZoneGenerator.GenerationSeed &&
|
||||
zones.Any(zone => string.Equals(zone.Name, "Daemon Generated Terminus", StringComparison.Ordinal)) &&
|
||||
entities.Any(entity => string.Equals(entity.Name, "Anchor Station", StringComparison.Ordinal)) &&
|
||||
entities.Count(entity => string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase)) >= 4 &&
|
||||
entities.Count(entity => string.Equals(entity.FactionKey, "raider", StringComparison.OrdinalIgnoreCase)) >= 3 &&
|
||||
bodies.Any(body => string.Equals(body.BodyKey, "local.outer", StringComparison.Ordinal)) &&
|
||||
bodies.Length >= 6;
|
||||
}
|
||||
|
||||
static AetheriaEntitySnapshot SeedEntity(
|
||||
string name,
|
||||
string kind,
|
||||
AetheriaVector3 position,
|
||||
AetheriaVector2 direction,
|
||||
AetheriaVector2 velocity,
|
||||
string factionKey,
|
||||
string hullItemKey,
|
||||
double visibility,
|
||||
string targetEntityKey,
|
||||
AetheriaEntityContactSnapshot[] contacts,
|
||||
string[] cargoItems)
|
||||
{
|
||||
return new AetheriaEntitySnapshot
|
||||
{
|
||||
Name = name,
|
||||
Kind = kind,
|
||||
Position = position,
|
||||
Direction = direction,
|
||||
Velocity = velocity,
|
||||
FactionKey = factionKey,
|
||||
HullItemKey = hullItemKey,
|
||||
IsActive = true,
|
||||
HeatsinksEnabled = true,
|
||||
TractorPower = 1,
|
||||
Visibility = visibility,
|
||||
VisibilitySourceCount = 1,
|
||||
TargetEntityKey = targetEntityKey,
|
||||
Contacts = contacts,
|
||||
StatGrids =
|
||||
[
|
||||
StatGrid("hull", string.Equals(kind, "station", StringComparison.OrdinalIgnoreCase) ? 420 : string.Equals(factionKey, "raider", StringComparison.OrdinalIgnoreCase) ? 80 : 120),
|
||||
StatGrid("shield", string.Equals(kind, "station", StringComparison.OrdinalIgnoreCase) ? 120 : 45),
|
||||
StatGrid("heat", 0)
|
||||
],
|
||||
Equipment =
|
||||
[
|
||||
new AetheriaEntityItemSlot
|
||||
{
|
||||
Position = new AetheriaGridCoord { X = 0, Y = 0 },
|
||||
ItemKey = "sensor-array",
|
||||
Quality = 1,
|
||||
Durability = 1,
|
||||
Quantity = 1,
|
||||
Enabled = true
|
||||
}
|
||||
],
|
||||
CargoContents =
|
||||
[
|
||||
new AetheriaCargoBayLoadout
|
||||
{
|
||||
Items = cargoItems
|
||||
.Select((itemKey, index) => new AetheriaLoadoutItemSlot
|
||||
{
|
||||
Position = new AetheriaGridCoord { X = index % 4, Y = index / 4 },
|
||||
Item = new AetheriaLoadoutItem
|
||||
{
|
||||
ItemKey = itemKey,
|
||||
Quality = 1,
|
||||
Durability = 1,
|
||||
Quantity = 1,
|
||||
Enabled = true
|
||||
}
|
||||
})
|
||||
.ToArray()
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
static AetheriaEntityStatGrid StatGrid(string name, double value)
|
||||
{
|
||||
return new AetheriaEntityStatGrid
|
||||
{
|
||||
Name = name,
|
||||
Width = 1,
|
||||
Height = 1,
|
||||
Values = [value]
|
||||
};
|
||||
}
|
||||
|
||||
static AetheriaEntityContactSnapshot Contact(string targetEntityKey, double infoGathered, bool hostile)
|
||||
{
|
||||
return new AetheriaEntityContactSnapshot
|
||||
{
|
||||
TargetEntityKey = targetEntityKey,
|
||||
InfoGathered = infoGathered,
|
||||
Hostile = hostile,
|
||||
Visible = true
|
||||
};
|
||||
bodies.Length >= 10;
|
||||
}
|
||||
|
||||
static string EntityKey(string runId, int zoneIndex, int entityIndex)
|
||||
|
|
@ -2542,16 +2122,6 @@ static string EntityKey(string runId, int zoneIndex, int entityIndex)
|
|||
return $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
|
||||
}
|
||||
|
||||
static AetheriaVector2 Vec2(double x, double y)
|
||||
{
|
||||
return new AetheriaVector2 { X = x, Y = y };
|
||||
}
|
||||
|
||||
static AetheriaVector3 Vec3(double x, double y, double z)
|
||||
{
|
||||
return new AetheriaVector3 { X = x, Y = y, Z = z };
|
||||
}
|
||||
|
||||
static AetheriaRuntimeLoadoutItemSlotCommit[] ToEntitySlotCommits(
|
||||
IReadOnlyList<AetheriaEntityItemSlot>? slots)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue