фикс краша локалки из-за автодок системы. фикс наложения гридов при спавне. фикс стыковки несколькох гридов на один док

This commit is contained in:
Vigers Ray 2025-08-18 19:06:38 +03:00
parent b562bdcdc2
commit ae4c9d4a8f
3 changed files with 41 additions and 23 deletions

View file

@ -292,8 +292,19 @@ namespace Content.Server.Shuttles.Systems
// Pre-existing joint so use that.
if (dockA.Comp.DockJointId != null)
{
DebugTools.Assert(dockB.Comp.DockJointId == dockA.Comp.DockJointId);
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, dockA.Comp.DockJointId);
// Sunrise-Start
if (dockB.Comp.DockJointId != dockA.Comp.DockJointId)
{
Log.Error($"DockJointId mismatch: {dockAUid}({dockA.Comp.DockJointId}) <-> {dockBUid}({dockB.Comp.DockJointId}), recreating joint.");
dockA.Comp.DockJointId = null;
dockB.Comp.DockJointId = null;
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, DockingJoint + dockAUid);
}
else
{
joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, dockA.Comp.DockJointId);
}
// Sunrise-End
}
else
{

View file

@ -866,7 +866,7 @@ public sealed partial class ShuttleSystem
/// </summary>
/// <param name="minOffset">Min offset for the final FTL.</param>
/// <param name="maxOffset">Max offset for the final FTL from the box we spawn.</param>
private bool TryGetFTLProximity(
public bool TryGetFTLProximity( // Sunrise-Edit
EntityUid shuttleUid,
EntityCoordinates targetCoordinates,
out EntityCoordinates coordinates, out Angle angle,

View file

@ -6,8 +6,9 @@ using Content.Server.Shuttles.Systems;
using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Content.Shared.Station.Components;
using Robust.Server.GameObjects;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Server._Sunrise.GridDock;
@ -17,7 +18,7 @@ public sealed class GridDockSystem : EntitySystem
[Dependency] private readonly ShuttleSystem _shuttles = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly DockingSystem _dockSystem = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
@ -43,20 +44,23 @@ public sealed class GridDockSystem : EntitySystem
return;
}
var baseOffset = new Vector2(0, 0);
var offsetStep = new Vector2(100, 100);
var index = 0f;
var usedGridDocks = new HashSet<EntityUid>();
var currentOffset = baseOffset;
foreach (var entry in component.Grids)
{
if (!_loader.TryLoadGrid(xformMap.MapID,
entry.GridPath,
out var rootUid,
offset: currentOffset))
{
currentOffset += offsetStep;
out var rootUid))
continue;
}
var grid = Comp<MapGridComponent>(rootUid.Value.Owner);
var width = grid.LocalAABB.Width;
var shuttleCenter = grid.LocalAABB.Center;
var coordinates = new EntityCoordinates(ftlMap, new Vector2(index + width / 2f, 0f) - shuttleCenter);
_transform.SetCoordinates(rootUid.Value.Owner, coordinates);
index += width + 5f;
if (!TryComp<ShuttleComponent>(rootUid.Value.Owner, out var shuttleComp))
continue;
@ -69,6 +73,8 @@ public sealed class GridDockSystem : EntitySystem
int maxNewDocks = 0;
foreach (var cfg in configs)
{
if (cfg.Docks.Any(pair => usedGridDocks.Contains(pair.DockBUid)))
continue;
var newDocks = cfg.Docks.Count(pair => !usedGridDocks.Contains(pair.DockBUid));
if (newDocks > maxNewDocks)
{
@ -77,7 +83,7 @@ public sealed class GridDockSystem : EntitySystem
}
}
if (chosenConfig != null && chosenConfig.Docks.All(pair => !usedGridDocks.Contains(pair.DockBUid)))
if (chosenConfig != null)
{
foreach (var pair in chosenConfig.Docks)
{
@ -88,21 +94,22 @@ public sealed class GridDockSystem : EntitySystem
rootUid.Value.Owner,
shuttleComp,
chosenConfig,
5f,
0f,
30f,
priorityTag: entry.PriorityTag,
ignored: false);
}
else
{
_shuttles.FTLToDock(
rootUid.Value.Owner,
shuttleComp,
target.Value,
5f,
30f,
priorityTag: entry.PriorityTag,
ignored: false);
if (_shuttles.TryGetFTLProximity(rootUid.Value.Owner, new EntityCoordinates(target.Value, Vector2.Zero), out var coords, out var targAngle))
{
_shuttles.FTLToCoordinates(rootUid.Value.Owner,
shuttleComp,
coords,
targAngle,
0f,
30f);
}
}
}
}