Complete universe model migration
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using static SpaceGame.Api.Stations.Simulation.InfrastructureSimulationService;
|
||||
|
||||
using SpaceGame.Api.Universe.Scenario;
|
||||
|
||||
namespace SpaceGame.Api.Universe.Simulation;
|
||||
|
||||
internal sealed class OrbitalStateUpdater
|
||||
@@ -223,22 +225,47 @@ internal sealed class OrbitalStateUpdater
|
||||
|
||||
foreach (var station in world.Stations)
|
||||
{
|
||||
if (station.CelestialId is null || !celestialsById.TryGetValue(station.CelestialId, out var anchorCelestial))
|
||||
if (station.AnchorId is not null && world.Anchors.Any(candidate => candidate.Id == station.AnchorId))
|
||||
{
|
||||
continue;
|
||||
station.Position = Vector3.Zero;
|
||||
}
|
||||
|
||||
station.Position = anchorCelestial.Position;
|
||||
}
|
||||
|
||||
foreach (var node in world.Nodes)
|
||||
{
|
||||
if (node.CelestialId is null || !celestialsById.TryGetValue(node.CelestialId, out var anchorCelestial))
|
||||
node.Position = ComputeResourceNodeOffset(node, worldTimeSeconds);
|
||||
}
|
||||
|
||||
var nodeAnchorsById = world.Nodes.ToDictionary(node => node.AnchorId, StringComparer.Ordinal);
|
||||
foreach (var anchor in world.Anchors)
|
||||
{
|
||||
if (string.Equals(anchor.SourceEntityKind, "resource-node", StringComparison.Ordinal))
|
||||
{
|
||||
if (nodeAnchorsById.TryGetValue(anchor.Id, out var node))
|
||||
{
|
||||
if (anchor.ParentAnchorId is not null && celestialsById.TryGetValue(anchor.ParentAnchorId, out var anchorCelestial))
|
||||
{
|
||||
anchor.Position = Add(anchorCelestial.Position, node.Position);
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor.Position = node.Position;
|
||||
}
|
||||
|
||||
anchor.LocalSpaceRadius = node.LocalSpaceRadius;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
node.Position = Add(anchorCelestial.Position, ComputeResourceNodeOffset(node, worldTimeSeconds));
|
||||
if (celestialsById.TryGetValue(anchor.Id, out var celestial))
|
||||
{
|
||||
anchor.Position = celestial.Position;
|
||||
anchor.LocalSpaceRadius = celestial.LocalSpaceRadius;
|
||||
anchor.ParentAnchorId = celestial.ParentAnchorId;
|
||||
anchor.OccupyingStructureId = celestial.OccupyingStructureId;
|
||||
anchor.OrbitReferenceId = celestial.OrbitReferenceId;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ship in world.Ships.Where(ship => ship.DockedStationId is not null))
|
||||
@@ -261,20 +288,29 @@ internal sealed class OrbitalStateUpdater
|
||||
{
|
||||
ship.SpatialState.CurrentSystemId = ship.SystemId;
|
||||
ship.SpatialState.LocalPosition = ship.Position;
|
||||
ship.SpatialState.SystemPosition = ship.Position;
|
||||
if (ship.SpatialState.Transit is not null)
|
||||
{
|
||||
ship.SpatialState.CurrentCelestialId = null;
|
||||
ship.SpatialState.CurrentAnchorId = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
ship.SpatialState.SpaceLayer = SpaceLayerKind.LocalSpace;
|
||||
ship.SpatialState.MovementRegime = MovementRegimeKind.LocalFlight;
|
||||
var nearestCelestial = world.Celestials
|
||||
.Where(candidate => candidate.SystemId == ship.SystemId)
|
||||
.OrderBy(candidate => candidate.Position.DistanceTo(ship.Position))
|
||||
.FirstOrDefault();
|
||||
ship.SpatialState.CurrentCelestialId = nearestCelestial?.Id;
|
||||
var currentAnchor = ship.SpatialState.CurrentAnchorId is not null
|
||||
? world.Anchors.FirstOrDefault(candidate => candidate.Id == ship.SpatialState.CurrentAnchorId)
|
||||
: null;
|
||||
if (currentAnchor is null || !string.Equals(currentAnchor.SystemId, ship.SystemId, StringComparison.Ordinal))
|
||||
{
|
||||
currentAnchor = world.Anchors
|
||||
.Where(candidate => candidate.SystemId == ship.SystemId)
|
||||
.OrderBy(candidate => candidate.Position.DistanceTo(ship.Position))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
ship.SpatialState.CurrentAnchorId = currentAnchor?.Id;
|
||||
ship.SpatialState.SystemPosition = currentAnchor is null
|
||||
? ship.Position
|
||||
: Add(currentAnchor.Position, ship.Position);
|
||||
|
||||
if (ship.DockedStationId is null)
|
||||
{
|
||||
@@ -282,9 +318,9 @@ internal sealed class OrbitalStateUpdater
|
||||
}
|
||||
|
||||
var station = world.Stations.FirstOrDefault(candidate => candidate.Id == ship.DockedStationId);
|
||||
if (station?.CelestialId is not null)
|
||||
if (station is not null)
|
||||
{
|
||||
ship.SpatialState.CurrentCelestialId = station.CelestialId;
|
||||
ship.SpatialState.CurrentAnchorId = station.AnchorId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user