]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
PA control box part detection fix (#24356)
authorMenshin <Menshin@users.noreply.github.com>
Sun, 21 Jan 2024 09:17:17 +0000 (10:17 +0100)
committerGitHub <noreply@github.com>
Sun, 21 Jan 2024 09:17:17 +0000 (20:17 +1100)
* * Fixed rounding errors when the PA control box was checking for parts, sometimes leading to the obscure "port/starboard emitters are not detected".
* Auto-rotated the PA control box toward the fuel box when checking for parts
* Swapped the wired/completed state sprites for the PA control box as it appears they were inverted

* Update Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs
Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.cs
Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/completed.png
Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/wired.png

index abc68543ff3b8404b121dbd4809a2090ffd33994..bdbc7b3f5bc7109dcfa667193037511729b4921e 100644 (file)
@@ -48,12 +48,12 @@ public sealed partial class ParticleAcceleratorSystem
             return;
 
         var gridUid = xform.GridUid;
-        if (gridUid == null || gridUid != xform.ParentUid || !_mapManager.TryGetGrid(gridUid, out var grid))
+        if (gridUid == null || gridUid != xform.ParentUid || !TryComp<MapGridComponent>(gridUid, out var grid))
             return;
 
         // Find fuel chamber first by scanning cardinals.
         var fuelQuery = GetEntityQuery<ParticleAcceleratorFuelChamberComponent>();
-        foreach (var adjacent in grid.GetCardinalNeighborCells(xform.Coordinates))
+        foreach (var adjacent in _mapSystem.GetCardinalNeighborCells(gridUid.Value, grid, xform.Coordinates))
         {
             if (fuelQuery.HasComponent(adjacent)
             && partQuery.TryGetComponent(adjacent, out var partState)
@@ -75,21 +75,23 @@ public sealed partial class ParticleAcceleratorSystem
         // You'll have to take my word for it that that breaks everything, yeah?
         controller.CurrentlyRescanning = true;
 
-        // Align ourselves to match fuel chamber orientation.
-        // This means that if you mess up the orientation of the control box it's not a big deal,
-        // because the sprite is far from obvious about the orientation.
+        // Automatically rotate the control box sprite to face the fuel chamber
         var fuelXform = xformQuery.GetComponent(controller.FuelChamber!.Value);
-        var rotation = fuelXform.LocalRotation;
-        _transformSystem.SetLocalRotation(uid, rotation, xform);
+        var fuelDir = (fuelXform.LocalPosition - xform.LocalPosition).GetDir();
+        _transformSystem.SetLocalRotation(uid, fuelDir.ToAngle(), xform);
 
         // Calculate offsets for each of the parts of the PA.
         // These are all done relative to the fuel chamber BC that is basically the center of the machine.
-        var positionFuelChamber = grid.TileIndicesFor(fuelXform.Coordinates);                           //       //
-        var positionEndCap = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(0, 1));               //   n   // n: End Cap
-        var positionPowerBox = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(0, -1));            //  CF   // C: Control Box, F: Fuel Chamber
-        var positionPortEmitter = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(1, -2));         //   P   // P: Power Box
-        var positionForeEmitter = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(0, -2));         //  EEE  // E: Emitter (Starboard, Fore, Port)
-        var positionStarboardEmitter = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(-1, -2));   //       //
+        var rotation = fuelXform.LocalRotation;
+        var offsetVect = rotation.GetCardinalDir().ToIntVec();
+        var orthoOffsetVect = new Vector2i(-offsetVect.Y, offsetVect.X);
+
+        var positionFuelChamber = _mapSystem.TileIndicesFor(gridUid!.Value, grid, fuelXform.Coordinates); //   n   // n: End Cap
+        var positionEndCap = positionFuelChamber - offsetVect;                                            //  CF   // C: Control Box, F: Fuel Chamber
+        var positionPowerBox = positionFuelChamber + offsetVect;                                          //   P   // P: Power Box
+        var positionPortEmitter = positionFuelChamber + offsetVect * 2 + orthoOffsetVect;                 //  EEE  // E: Emitter (Starboard, Fore, Port)
+        var positionForeEmitter = positionFuelChamber + offsetVect * 2;
+        var positionStarboardEmitter = positionFuelChamber + offsetVect * 2 - orthoOffsetVect;
 
         ScanPart<ParticleAcceleratorEndCapComponent>(gridUid!.Value, positionEndCap, rotation, out controller.EndCap, out var _, grid);
         ScanPart<ParticleAcceleratorPowerBoxComponent>(gridUid!.Value, positionPowerBox, rotation, out controller.PowerBox, out var _, grid);
@@ -137,7 +139,7 @@ public sealed partial class ParticleAcceleratorSystem
         }
 
         var compQuery = GetEntityQuery<T>();
-        foreach (var entity in grid.GetAnchoredEntities(coordinates))
+        foreach (var entity in _mapSystem.GetAnchoredEntities(uid, grid, coordinates))
         {
             if (compQuery.TryGetComponent(entity, out comp)
             && TryComp<ParticleAcceleratorPartComponent>(entity, out var partState) && partState.Master == null
index c50e054281eb5748908682d9b4c249a31007b6ff..ddc7e2a08303444da3bd285a8a6038fcd4471714 100644 (file)
@@ -21,6 +21,7 @@ public sealed partial class ParticleAcceleratorSystem : EntitySystem
     [Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
     [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
     [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
+    [Dependency] private readonly MapSystem _mapSystem = default!;
 
     public override void Initialize()
     {
index 0636a46df9baaafaea66ad875e65680a6ca24945..932eed803e8b9e07262dc372fbb21200cc607978 100644 (file)
Binary files a/Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/completed.png and b/Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/completed.png differ
index 6e0409e9cf04c4f284e295da51f8506d106e3ec6..6e4a695d766babf04099f7cb5d64c5db8315cad9 100644 (file)
Binary files a/Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/wired.png and b/Resources/Textures/Structures/Power/Generation/PA/control_box.rsi/wired.png differ