]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
FTL + AI fixes (#31952)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 8 Sep 2024 08:12:23 +0000 (18:12 +1000)
committerGitHub <noreply@github.com>
Sun, 8 Sep 2024 08:12:23 +0000 (18:12 +1000)
Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Content.Shared/Shuttles/Components/FTLSmashImmuneComponent.cs [new file with mode: 0644]
Content.Shared/Shuttles/Components/NoFTLComponent.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Markers/shuttle.yml
Resources/Prototypes/Entities/Mobs/Player/observer.yml
Resources/Prototypes/Entities/Mobs/Player/silicon.yml

index 8da7aaa641e55a630fe1e7abaca67a874e25aaac..5917267a74dc00b4aad0389e97732232abd60f96 100644 (file)
@@ -70,11 +70,11 @@ public sealed partial class ShuttleSystem
 
     private readonly HashSet<EntityUid> _lookupEnts = new();
     private readonly HashSet<EntityUid> _immuneEnts = new();
+    private readonly HashSet<Entity<NoFTLComponent>> _noFtls = new();
 
     private EntityQuery<BodyComponent> _bodyQuery;
     private EntityQuery<BuckleComponent> _buckleQuery;
-    private EntityQuery<FTLBeaconComponent> _beaconQuery;
-    private EntityQuery<GhostComponent> _ghostQuery;
+    private EntityQuery<FTLSmashImmuneComponent> _immuneQuery;
     private EntityQuery<PhysicsComponent> _physicsQuery;
     private EntityQuery<StatusEffectsComponent> _statusQuery;
     private EntityQuery<TransformComponent> _xformQuery;
@@ -86,8 +86,7 @@ public sealed partial class ShuttleSystem
 
         _bodyQuery = GetEntityQuery<BodyComponent>();
         _buckleQuery = GetEntityQuery<BuckleComponent>();
-        _beaconQuery = GetEntityQuery<FTLBeaconComponent>();
-        _ghostQuery = GetEntityQuery<GhostComponent>();
+        _immuneQuery = GetEntityQuery<FTLSmashImmuneComponent>();
         _physicsQuery = GetEntityQuery<PhysicsComponent>();
         _statusQuery = GetEntityQuery<StatusEffectsComponent>();
         _xformQuery = GetEntityQuery<TransformComponent>();
@@ -102,7 +101,7 @@ public sealed partial class ShuttleSystem
 
     private void OnFtlShutdown(Entity<FTLComponent> ent, ref ComponentShutdown args)
     {
-        Del(ent.Comp.VisualizerEntity);
+        QueueDel(ent.Comp.VisualizerEntity);
         ent.Comp.VisualizerEntity = null;
     }
 
@@ -404,7 +403,12 @@ public sealed partial class ShuttleSystem
         // Offset the start by buffer range just to avoid overlap.
         var ftlStart = new EntityCoordinates(ftlMap, new Vector2(_index + width / 2f, 0f) - shuttleCenter);
 
+        // Store the matrix for the grid prior to movement. This means any entities we need to leave behind we can make sure their positions are updated.
+        // Setting the entity to map directly may run grid traversal (at least at time of writing this).
+        var oldMapUid = xform.MapUid;
+        var oldGridMatrix = _transform.GetWorldMatrix(xform);
         _transform.SetCoordinates(entity.Owner, ftlStart);
+        LeaveNoFTLBehind((entity.Owner, xform), oldGridMatrix, oldMapUid);
 
         // Reset rotation so they always face the same direction.
         xform.LocalRotation = Angle.Zero;
@@ -476,6 +480,9 @@ public sealed partial class ShuttleSystem
 
         MapId mapId;
 
+        QueueDel(entity.Comp1.VisualizerEntity);
+        entity.Comp1.VisualizerEntity = null;
+
         if (!Exists(entity.Comp1.TargetCoordinates.EntityId))
         {
             // Uhh good luck
@@ -628,6 +635,31 @@ public sealed partial class ShuttleSystem
         }
     }
 
+    private void LeaveNoFTLBehind(Entity<TransformComponent> grid, Matrix3x2 oldGridMatrix, EntityUid? oldMapUid)
+    {
+        if (oldMapUid == null)
+            return;
+
+        _noFtls.Clear();
+        var oldGridRotation = oldGridMatrix.Rotation();
+        _lookup.GetGridEntities(grid.Owner, _noFtls);
+
+        foreach (var childUid in _noFtls)
+        {
+            if (!_xformQuery.TryComp(childUid, out var childXform))
+                continue;
+
+            // If we're not parented directly to the grid the matrix may be wrong.
+            var relative = _physics.GetRelativePhysicsTransform(childUid.Owner, (grid.Owner, grid.Comp));
+
+            _transform.SetCoordinates(
+                childUid,
+                childXform,
+                new EntityCoordinates(oldMapUid.Value,
+                Vector2.Transform(relative.Position, oldGridMatrix)), rotation: relative.Quaternion2D.Angle + oldGridRotation);
+        }
+    }
+
     private void KnockOverKids(TransformComponent xform, ref ValueList<EntityUid> toKnock)
     {
         // Not recursive because probably not necessary? If we need it to be that's why this method is separate.
@@ -926,7 +958,8 @@ public sealed partial class ShuttleSystem
             _biomes.ReserveTiles(xform.MapUid.Value, aabb, tileSet);
             _lookupEnts.Clear();
             _immuneEnts.Clear();
-            _lookup.GetEntitiesIntersecting(xform.MapUid.Value, aabb, _lookupEnts, LookupFlags.Uncontained);
+            // TODO: Ideally we'd query first BEFORE moving grid but needs adjustments above.
+            _lookup.GetEntitiesIntersecting(xform.MapID, fixture.Shape, transform, _lookupEnts, LookupFlags.Uncontained);
 
             foreach (var ent in _lookupEnts)
             {
@@ -935,7 +968,13 @@ public sealed partial class ShuttleSystem
                     continue;
                 }
 
-                if (_ghostQuery.HasComponent(ent) || _beaconQuery.HasComponent(ent))
+                // If it's on our grid ignore it.
+                if (!_xformQuery.TryComp(ent, out var childXform) || childXform.GridUid == uid)
+                {
+                    continue;
+                }
+
+                if (_immuneQuery.HasComponent(ent))
                 {
                     continue;
                 }
@@ -949,9 +988,6 @@ public sealed partial class ShuttleSystem
                     continue;
                 }
 
-                if (HasComp<FTLBeaconComponent>(ent))
-                    continue;
-
                 QueueDel(ent);
             }
         }
diff --git a/Content.Shared/Shuttles/Components/FTLSmashImmuneComponent.cs b/Content.Shared/Shuttles/Components/FTLSmashImmuneComponent.cs
new file mode 100644 (file)
index 0000000..9ed7ee0
--- /dev/null
@@ -0,0 +1,9 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Shuttles.Components;
+
+/// <summary>
+/// Makes the entity immune to FTL arrival landing AKA smimsh.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class FTLSmashImmuneComponent : Component;
diff --git a/Content.Shared/Shuttles/Components/NoFTLComponent.cs b/Content.Shared/Shuttles/Components/NoFTLComponent.cs
new file mode 100644 (file)
index 0000000..d48ba33
--- /dev/null
@@ -0,0 +1,12 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Shuttles.Components;
+
+/// <summary>
+/// Prevents the attached entity from taking FTL.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class NoFTLComponent : Component
+{
+
+}
index 0e9117951ce11496913f511985bf4426c1149882..66e2bc39b7f4c3193a481edbb63b0d03b9c14749 100644 (file)
@@ -3,6 +3,7 @@
   parent: MarkerBase
   name: FTL point
   components:
+    - type: FTLSmashImmune
     - type: FTLBeacon
     - type: Sprite
       state: pink
index 5ceac9e773e06abce669749af8bd43c5a76496e1..c02629c4d6fd81f50eb99d0d7723e08f3d8ec432 100644 (file)
@@ -8,6 +8,7 @@
     noRot: true
     overrideContainerOcclusion: true # Always show up regardless of where they're contained.
     drawdepth: Ghosts
+  - type: FTLSmashImmune
   - type: CargoSellBlacklist
   - type: MovementSpeedModifier
     baseSprintSpeed: 12
index 45c1fef541e8297d557a29eb7e590b8c2c36f912..2c6a8bd43008254b9a867bb8274a87832d9858a1 100644 (file)
     state: std_mod
   - type: SiliconLawProvider
     laws: PaladinLawset
-    
+
 - type: entity
   id: LiveLetLiveCircuitBoard
   parent: BaseElectronics
     state: std_mod
   - type: SiliconLawProvider
     laws: LiveLetLiveLaws
-    
+
 - type: entity
   id: StationEfficiencyCircuitBoard
   parent: BaseElectronics
     state: std_mod
   - type: SiliconLawProvider
     laws: RobocopLawset
-    
+
 - type: entity
   id: OverlordCircuitBoard
   parent: BaseElectronics
     state: std_mod
   - type: SiliconLawProvider
     laws: OverlordLawset
-    
+
 - type: entity
   id: DungeonMasterCircuitBoard
   parent: BaseElectronics
     state: std_mod
   - type: SiliconLawProvider
     laws: AntimovLawset
-    
+
 - type: entity
   id: NutimovCircuitBoard
   parent: BaseElectronics
   noSpawn: true
   suffix: DO NOT MAP
   components:
+  - type: NoFTL
   - type: WarpPoint
     follow: true
   - type: Eye