PA control box part detection fix (#24356)

* * 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>
This commit is contained in:
Menshin
2024-01-21 10:17:17 +01:00
committed by GitHub
parent 8c5898b006
commit eb0a54fef2
4 changed files with 17 additions and 14 deletions

View File

@@ -48,12 +48,12 @@ public sealed partial class ParticleAcceleratorSystem
return; return;
var gridUid = xform.GridUid; 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; return;
// Find fuel chamber first by scanning cardinals. // Find fuel chamber first by scanning cardinals.
var fuelQuery = GetEntityQuery<ParticleAcceleratorFuelChamberComponent>(); 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) if (fuelQuery.HasComponent(adjacent)
&& partQuery.TryGetComponent(adjacent, out var partState) && 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? // You'll have to take my word for it that that breaks everything, yeah?
controller.CurrentlyRescanning = true; controller.CurrentlyRescanning = true;
// Align ourselves to match fuel chamber orientation. // Automatically rotate the control box sprite to face the fuel chamber
// 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.
var fuelXform = xformQuery.GetComponent(controller.FuelChamber!.Value); var fuelXform = xformQuery.GetComponent(controller.FuelChamber!.Value);
var rotation = fuelXform.LocalRotation; var fuelDir = (fuelXform.LocalPosition - xform.LocalPosition).GetDir();
_transformSystem.SetLocalRotation(uid, rotation, xform); _transformSystem.SetLocalRotation(uid, fuelDir.ToAngle(), xform);
// Calculate offsets for each of the parts of the PA. // 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. // 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 rotation = fuelXform.LocalRotation;
var positionEndCap = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(0, 1)); // n // n: End Cap var offsetVect = rotation.GetCardinalDir().ToIntVec();
var positionPowerBox = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(0, -1)); // CF // C: Control Box, F: Fuel Chamber var orthoOffsetVect = new Vector2i(-offsetVect.Y, offsetVect.X);
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 positionFuelChamber = _mapSystem.TileIndicesFor(gridUid!.Value, grid, fuelXform.Coordinates); // n // n: End Cap
var positionStarboardEmitter = positionFuelChamber + (Vector2i) rotation.RotateVec(new Vector2(-1, -2)); // // 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<ParticleAcceleratorEndCapComponent>(gridUid!.Value, positionEndCap, rotation, out controller.EndCap, out var _, grid);
ScanPart<ParticleAcceleratorPowerBoxComponent>(gridUid!.Value, positionPowerBox, rotation, out controller.PowerBox, 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>(); 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) if (compQuery.TryGetComponent(entity, out comp)
&& TryComp<ParticleAcceleratorPartComponent>(entity, out var partState) && partState.Master == null && TryComp<ParticleAcceleratorPartComponent>(entity, out var partState) && partState.Master == null

View File

@@ -21,6 +21,7 @@ public sealed partial class ParticleAcceleratorSystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!; [Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!; [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly MapSystem _mapSystem = default!;
public override void Initialize() public override void Initialize()
{ {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB