]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix FTLToDock (#25803)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 3 Mar 2024 10:14:16 +0000 (21:14 +1100)
committerGitHub <noreply@github.com>
Sun, 3 Mar 2024 10:14:16 +0000 (21:14 +1100)
* Fix FTLToDock

- Removed Enabled coz unneeded really.
- Fixed SetCoordinates call that got dumped at some point oop.

* Fix this docking check

Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs
Content.Server/Shuttles/Systems/DockingSystem.cs
Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Content.Shared/Shuttles/Components/SharedDockingComponent.cs

index 4ce52947366a1b057108f6591f19f96102dd9bbf..7bc1be02e37ea078a4e34b2e005e1ccb10044665 100644 (file)
@@ -94,12 +94,12 @@ public sealed partial class DockingSystem
        EntityUid gridDockUid,
        DockingComponent gridDock)
    {
-       var shuttleDocks = new List<(EntityUid, DockingComponent)>(1)
+       var shuttleDocks = new List<Entity<DockingComponent>>(1)
        {
            (shuttleDockUid, shuttleDock)
        };
 
-       var gridDocks = new List<(EntityUid, DockingComponent)>(1)
+       var gridDocks = new List<Entity<DockingComponent>>(1)
        {
            (gridDockUid, gridDock)
        };
@@ -149,8 +149,8 @@ public sealed partial class DockingSystem
    private List<DockingConfig> GetDockingConfigs(
        EntityUid shuttleUid,
        EntityUid targetGrid,
-       List<(EntityUid, DockingComponent)> shuttleDocks,
-       List<(EntityUid, DockingComponent)> gridDocks)
+       List<Entity<DockingComponent>> shuttleDocks,
+       List<Entity<DockingComponent>> gridDocks)
    {
        var validDockConfigs = new List<DockingConfig>();
 
@@ -274,8 +274,8 @@ public sealed partial class DockingSystem
    private DockingConfig? GetDockingConfigPrivate(
        EntityUid shuttleUid,
        EntityUid targetGrid,
-       List<(EntityUid, DockingComponent)> shuttleDocks,
-       List<(EntityUid, DockingComponent)> gridDocks,
+       List<Entity<DockingComponent>> shuttleDocks,
+       List<Entity<DockingComponent>> gridDocks,
        string? priorityTag = null)
    {
        var validDockConfigs = GetDockingConfigs(shuttleUid, targetGrid, shuttleDocks, gridDocks);
@@ -345,19 +345,11 @@ public sealed partial class DockingSystem
        return true;
    }
 
-   public List<(EntityUid Uid, DockingComponent Component)> GetDocks(EntityUid uid)
+   public List<Entity<DockingComponent>> GetDocks(EntityUid uid)
    {
-       var result = new List<(EntityUid Uid, DockingComponent Component)>();
-       var query = AllEntityQuery<DockingComponent, TransformComponent>();
+       _dockingSet.Clear();
+       _lookup.GetChildEntities(uid, _dockingSet);
 
-       while (query.MoveNext(out var dockUid, out var dock, out var xform))
-       {
-           if (xform.ParentUid != uid || !dock.Enabled)
-               continue;
-
-           result.Add((dockUid, dock));
-       }
-
-       return result;
+       return _dockingSet.ToList();
    }
 }
index afe03af1bb8886bc0417c82d0d1be9c352cde793..8220818b2311310b52ac7e90b0f27c69ad9e4af5 100644 (file)
@@ -60,10 +60,7 @@ namespace Content.Server.Shuttles.Systems
             SubscribeLocalEvent<ShuttleConsoleComponent, UndockRequestMessage>(OnRequestUndock);
         }
 
-        /// <summary>
-        /// Sets the docks for the provided entity as enabled or disabled.
-        /// </summary>
-        public void SetDocks(EntityUid gridUid, bool enabled)
+        public void UndockDocks(EntityUid gridUid)
         {
             _dockingSet.Clear();
             _lookup.GetChildEntities(gridUid, _dockingSet);
@@ -71,7 +68,6 @@ namespace Content.Server.Shuttles.Systems
             foreach (var dock in _dockingSet)
             {
                 Undock(dock);
-                dock.Comp.Enabled = enabled;
             }
         }
 
@@ -165,8 +161,6 @@ namespace Content.Server.Shuttles.Systems
             if (!EntityManager.GetComponent<TransformComponent>(uid).Anchored)
                 return;
 
-            SetDockingEnabled((uid, component), true);
-
             // This little gem is for docking deserialization
             if (component.DockedWith != null)
             {
@@ -184,16 +178,10 @@ namespace Content.Server.Shuttles.Systems
 
         private void OnAnchorChange(Entity<DockingComponent> entity, ref AnchorStateChangedEvent args)
         {
-            if (args.Anchored)
-            {
-                SetDockingEnabled(entity, true);
-            }
-            else
+            if (!args.Anchored)
             {
-                SetDockingEnabled(entity, false);
+                Undock(entity);
             }
-
-            _console.RefreshShuttleConsoles();
         }
 
         private void OnDockingReAnchor(Entity<DockingComponent> entity, ref ReAnchorEvent args)
@@ -212,19 +200,6 @@ namespace Content.Server.Shuttles.Systems
             _console.RefreshShuttleConsoles();
         }
 
-        public void SetDockingEnabled(Entity<DockingComponent> entity, bool value)
-        {
-            if (entity.Comp.Enabled == value)
-                return;
-
-            entity.Comp.Enabled = value;
-
-            if (!entity.Comp.Enabled && entity.Comp.DockedWith != null)
-            {
-                Undock(entity);
-            }
-        }
-
         /// <summary>
         /// Docks 2 ports together and assumes it is valid.
         /// </summary>
@@ -454,9 +429,7 @@ namespace Content.Server.Shuttles.Systems
         /// </summary>
         public bool CanDock(Entity<DockingComponent> dockA, Entity<DockingComponent> dockB)
         {
-            if (!dockA.Comp.Enabled ||
-                !dockB.Comp.Enabled ||
-                dockA.Comp.DockedWith != null ||
+            if (dockA.Comp.DockedWith != null ||
                 dockB.Comp.DockedWith != null)
             {
                 return false;
@@ -464,6 +437,10 @@ namespace Content.Server.Shuttles.Systems
 
             var xformA = Transform(dockA);
             var xformB = Transform(dockB);
+
+            if (!xformA.Anchored || !xformB.Anchored)
+                return false;
+
             var (worldPosA, worldRotA) = XformSystem.GetWorldPositionRotation(xformA);
             var (worldPosB, worldRotB) = XformSystem.GetWorldPositionRotation(xformB);
 
index 8a935637655b3bc6960a81c3292e6786cd8dfd14..fc01a5d36f9adec752db05f041727c707f56972f 100644 (file)
@@ -316,7 +316,7 @@ public sealed partial class ShuttleSystem
         _thruster.DisableLinearThrusters(shuttle);
         _thruster.EnableLinearThrustDirection(shuttle, DirectionFlag.North);
         _thruster.SetAngularThrust(shuttle, false);
-        _dockSystem.SetDocks(uid, false);
+        _dockSystem.UndockDocks(uid);
 
         component = AddComp<FTLComponent>(uid);
         component.State = FTLState.Starting;
@@ -420,7 +420,6 @@ public sealed partial class ShuttleSystem
         var comp = entity.Comp1;
         DoTheDinosaur(xform);
         _dockSystem.SetDockBolts(entity, false);
-        _dockSystem.SetDocks(entity, true);
 
         _physics.SetLinearVelocity(uid, Vector2.Zero, body: body);
         _physics.SetAngularVelocity(uid, 0f, body: body);
@@ -446,14 +445,24 @@ public sealed partial class ShuttleSystem
                  !HasComp<MapComponent>(target.EntityId))
         {
             var config = _dockSystem.GetDockingConfigAt(uid, target.EntityId, target, entity.Comp1.TargetAngle);
+            MapCoordinates mapCoordinates;
+            Angle targetAngle;
 
             // Couldn't dock somehow so just fallback to regular position FTL.
             if (config == null)
             {
-                _transform.SetCoordinates(uid, xform, target, rotation: entity.Comp1.TargetAngle);
+                mapCoordinates = _transform.ToMapCoordinates(target);
+                targetAngle = entity.Comp1.TargetAngle;
+            }
+            else
+            {
+                mapCoordinates = _transform.ToMapCoordinates(config.Coordinates);
+                targetAngle = config.Angle;
             }
 
-            mapId = target.GetMapId(EntityManager);
+            target = new EntityCoordinates(_mapManager.GetMapEntityId(mapCoordinates.MapId), mapCoordinates.Position);
+            _transform.SetCoordinates(uid, xform, target, rotation: targetAngle);
+            mapId = mapCoordinates.MapId;
         }
         // Position ftl
         else
index 501132f8042c0a43f77fda4ed1a7793b0fd0dfa3..15af045cc4bee8160832b284481be73963b424cf 100644 (file)
@@ -5,9 +5,6 @@ namespace Content.Shared.Shuttles.Components
         // Yes I left this in for now because there's no overhead and we'll need a client one later anyway
         // and I was too lazy to delete it.
 
-        [ViewVariables]
-        public bool Enabled = false;
-
         public abstract bool Docked { get; }
     }
 }