From 27905bb58a5e2ba7c3b7f483bb13225dee9fc3e2 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Thu, 12 Dec 2024 10:36:14 +1100 Subject: [PATCH 1/9] Add AdvDockingComponent which controls airtightness --- .../Components/AdvDockingComponent.cs | 15 ++ .../Shuttles/Systems/AdvDockingSystem.cs | 187 ++++++++++++++++++ .../Shuttles/Systems/DockingSystem.cs | 10 +- 3 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 Content.Server/Shuttles/Components/AdvDockingComponent.cs create mode 100644 Content.Server/Shuttles/Systems/AdvDockingSystem.cs diff --git a/Content.Server/Shuttles/Components/AdvDockingComponent.cs b/Content.Server/Shuttles/Components/AdvDockingComponent.cs new file mode 100644 index 00000000000..3db3992a580 --- /dev/null +++ b/Content.Server/Shuttles/Components/AdvDockingComponent.cs @@ -0,0 +1,15 @@ +using Content.Shared.Shuttles.Components; +using Content.Server.Shuttles.Systems; + +namespace Content.Server.Shuttles.Components +{ + [RegisterComponent] + [Access(typeof(AdvDockingSystem))] + public sealed partial class AdvDockingComponent : Component + { + [DataField, ViewVariables(VVAccess.ReadWrite)] + public bool Enabled { get; set; } = true; + + public bool IsOn; + } +} diff --git a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs new file mode 100644 index 00000000000..cea8279b886 --- /dev/null +++ b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs @@ -0,0 +1,187 @@ +using System.Numerics; +using Content.Server.Audio; +using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; +using Content.Server.Shuttles.Components; +using Content.Server.Doors.Systems; +using Content.Shared.Damage; +using Content.Shared.Examine; +using Content.Shared.Interaction; +using Content.Shared.Maps; +using Content.Shared.Physics; +using Content.Shared.Shuttles.Components; +using Content.Shared.Temperature; +using Content.Shared.Doors; +using Content.Shared.Doors.Components; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Physics.Collision.Shapes; +using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Events; +using Robust.Shared.Physics.Systems; +using Robust.Shared.Timing; +using Robust.Shared.Utility; +using Content.Shared.Localizations; +using Content.Shared.Power; +using Content.Server.Construction; // Frontier +using Content.Server.DeviceLinking.Events; // Frontier +namespace Content.Server.Shuttles.Systems +{ + + public sealed class AdvDockingSystem : EntitySystem + { + [Dependency] private readonly SharedMapSystem _mapSystem = default!; + [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; + [Dependency] private readonly DoorSystem _doorSystem = default!; + public override void Initialize() + { + SubscribeLocalEvent(OnPowerChange); + SubscribeLocalEvent(OnAnchorChange); + SubscribeLocalEvent(OnShuttleTileChange); + } + + + private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args) + { + // If the old tile was space but the new one isn't then disable all adjacent thrusters + if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager)) + return; + + var tilePos = args.NewTile.GridIndices; + var grid = Comp(uid); + var xformQuery = GetEntityQuery(); + var dockQuery = GetEntityQuery(); + + for (var x = -1; x <= 1; x++) + { + for (var y = -1; y <= 1; y++) + { + if (x != 0 && y != 0) + continue; + + var checkPos = tilePos + new Vector2i(x, y); + var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos); + + while (enumerator.MoveNext(out var ent)) + { + if (!dockQuery.TryGetComponent(ent.Value, out var dock)) + continue; + + // Work out if the dock is facing this direction + var xform = xformQuery.GetComponent(ent.Value); + var direction = xform.LocalRotation.ToWorldVec(); + + if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y)) + continue; + + DisableAirtightness(ent.Value, dock, xform.GridUid); + } + } + } + } + + private void OnPowerChange(EntityUid uid, AdvDockingComponent component, ref PowerChangedEvent args) + { + if (args.Powered && CanEnable(uid, component)) + { + EnableAirtightness(uid, component); + } + else + { + DisableAirtightness(uid, component); + } + } + + private void OnAnchorChange(EntityUid uid, AdvDockingComponent component, ref AnchorStateChangedEvent args) + { + if (args.Anchored && CanEnable(uid, component)) + { + EnableAirtightness(uid, component); + } + else + { + DisableAirtightness(uid, component); + } + } + + + /// + /// Tries to enable the seals and turn it on. If it's already enabled it does nothing. + /// + public void EnableAirtightness(EntityUid uid, AdvDockingComponent component, TransformComponent? xform = null) + { + if (component.IsOn || + !Resolve(uid, ref xform)) + { + return; + } + + component.IsOn = true; + if (TryComp(uid, out DoorComponent? door)) + door.ChangeAirtight = false; + + if (!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent)) + return; + + } + + + public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, TransformComponent? xform = null) + { + if (!Resolve(uid, ref xform)) return; + DisableAirtightness(uid, component, xform.GridUid, xform); + } + + + /// + /// Tries to disable the seals + /// + public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, EntityUid? gridId, TransformComponent? xform = null) + { + if (!component.IsOn || + !Resolve(uid, ref xform)) + { + return; + } + + component.IsOn = false; + if (TryComp(uid, out DoorComponent? door)) + door.ChangeAirtight = true; + + if (!EntityManager.TryGetComponent(gridId, out ShuttleComponent? shuttleComponent)) + return; + } + + public bool CanEnable(EntityUid uid, AdvDockingComponent component) + { + if (!component.Enabled) + return false; + + if (component.LifeStage > ComponentLifeStage.Running) + return false; + + var xform = Transform(uid); + + if (!xform.Anchored || !this.IsPowered(uid, EntityManager)) + { + return false; + } + + return DockExposed(xform); + } + + private bool DockExposed(TransformComponent xform) + { + if (xform.GridUid == null) + return true; + + var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec(); + var mapGrid = Comp(xform.GridUid.Value); + var tile = _mapSystem.GetTileRef(xform.GridUid.Value, mapGrid, new Vector2i((int)Math.Floor(x), (int)Math.Floor(y))); + + return tile.Tile.IsSpace(); + } + + } + +} diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index fcdd6c0c1ae..9977cd3e6ef 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -287,7 +287,7 @@ public void Dock(Entity dockA, Entity dockB) _doorSystem.SetBoltsDown((dockAUid, airlockA), true); } } - doorA.ChangeAirtight = false; + //doorA.ChangeAirtight = false; //testing docked airtightness } if (TryComp(dockBUid, out DoorComponent? doorB)) @@ -299,7 +299,7 @@ public void Dock(Entity dockA, Entity dockB) _doorSystem.SetBoltsDown((dockBUid, airlockB), true); } } - doorB.ChangeAirtight = false; + //doorB.ChangeAirtight = false; //testing docked airtightness } if (_pathfinding.TryCreatePortal(dockAXform.Coordinates, dockBXform.Coordinates, out var handle)) @@ -352,8 +352,10 @@ private void OnUndock(EntityUid dockUid) if (TryComp(dockUid, out var airlock)) _doorSystem.SetBoltsDown((dockUid, airlock), false); - if (TryComp(dockUid, out DoorComponent? door) && _doorSystem.TryClose(dockUid, door)) - door.ChangeAirtight = true; + + + //if (TryComp(dockUid, out DoorComponent? door) && _doorSystem.TryClose(dockUid, door)) + // door.ChangeAirtight = false; } private void OnRequestUndock(EntityUid uid, ShuttleConsoleComponent component, UndockRequestMessage args) From 6c1db1061d58d1b6637ee4a53f6ebe03a813e7fe Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Thu, 12 Dec 2024 18:21:47 +1100 Subject: [PATCH 2/9] fix rotation for isSpace check --- .../Components/AdvDockingComponent.cs | 7 +++- .../Shuttles/Systems/AdvDockingSystem.cs | 37 ++++++++++++------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Content.Server/Shuttles/Components/AdvDockingComponent.cs b/Content.Server/Shuttles/Components/AdvDockingComponent.cs index 3db3992a580..568fce464a1 100644 --- a/Content.Server/Shuttles/Components/AdvDockingComponent.cs +++ b/Content.Server/Shuttles/Components/AdvDockingComponent.cs @@ -8,8 +8,11 @@ namespace Content.Server.Shuttles.Components public sealed partial class AdvDockingComponent : Component { [DataField, ViewVariables(VVAccess.ReadWrite)] - public bool Enabled { get; set; } = true; + public bool IsOn { get; set; } = true; - public bool IsOn; + /// + /// Frontier - Amount of charge this needs from an APC per second to function. + /// + public float OriginalLoad { get; set; } = 0; } } diff --git a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs index cea8279b886..7a662b2b008 100644 --- a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs +++ b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs @@ -4,6 +4,8 @@ using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; using Content.Server.Doors.Systems; +using Content.Server.Atmos.Components; +using Content.Server.Atmos.EntitySystems; using Content.Shared.Damage; using Content.Shared.Examine; using Content.Shared.Interaction; @@ -33,11 +35,28 @@ public sealed class AdvDockingSystem : EntitySystem [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; [Dependency] private readonly DoorSystem _doorSystem = default!; + [Dependency] private readonly AirtightSystem _airtightSystem = default!; public override void Initialize() { SubscribeLocalEvent(OnPowerChange); SubscribeLocalEvent(OnAnchorChange); - SubscribeLocalEvent(OnShuttleTileChange); + //SubscribeLocalEvent(OnShuttleTileChange); + SubscribeLocalEvent(OnDockInit); + } + + private void OnDockInit(EntityUid uid, AdvDockingComponent component, ComponentInit args) + { + if (TryComp(uid, out var apcPower) && component.OriginalLoad == 0) { component.OriginalLoad = apcPower.Load; } // Frontier + + if (!component.IsOn) + { + return; + } + + if (CanEnable(uid, component)) + { + EnableAirtightness(uid, component); + } } @@ -120,9 +139,8 @@ public void EnableAirtightness(EntityUid uid, AdvDockingComponent component, Tra if (TryComp(uid, out DoorComponent? door)) door.ChangeAirtight = false; - if (!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent)) - return; - + if (TryComp(uid, out AirtightComponent? airtight)) + _airtightSystem.SetAirblocked((uid, airtight), true); } @@ -147,19 +165,10 @@ public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, En component.IsOn = false; if (TryComp(uid, out DoorComponent? door)) door.ChangeAirtight = true; - - if (!EntityManager.TryGetComponent(gridId, out ShuttleComponent? shuttleComponent)) - return; } public bool CanEnable(EntityUid uid, AdvDockingComponent component) { - if (!component.Enabled) - return false; - - if (component.LifeStage > ComponentLifeStage.Running) - return false; - var xform = Transform(uid); if (!xform.Anchored || !this.IsPowered(uid, EntityManager)) @@ -175,7 +184,7 @@ private bool DockExposed(TransformComponent xform) if (xform.GridUid == null) return true; - var (x, y) = xform.LocalPosition + xform.LocalRotation.Opposite().ToWorldVec(); + var (x, y) = xform.LocalPosition + xform.LocalRotation.ToWorldVec(); var mapGrid = Comp(xform.GridUid.Value); var tile = _mapSystem.GetTileRef(xform.GridUid.Value, mapGrid, new Vector2i((int)Math.Floor(x), (int)Math.Floor(y))); From d9dcbaafb6c87e9bf208479c8d8dc23697f38ac6 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Wed, 18 Dec 2024 14:30:36 +1100 Subject: [PATCH 3/9] Added behaviour on deactivation to properly vent atmos if the door was open at the time --- Content.Server/Shuttles/Systems/AdvDockingSystem.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs index 7a662b2b008..23355322ab4 100644 --- a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs +++ b/Content.Server/Shuttles/Systems/AdvDockingSystem.cs @@ -164,7 +164,14 @@ public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, En component.IsOn = false; if (TryComp(uid, out DoorComponent? door)) + { door.ChangeAirtight = true; + if (door.State == DoorState.Open && TryComp(uid, out AirtightComponent? airtight)) //If the door's open, goodbye air + { + _airtightSystem.SetAirblocked((uid, airtight), false); + } + } + } public bool CanEnable(EntityUid uid, AdvDockingComponent component) From 100a1be87c5fada70501736f44a26c50dbc57e2d Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 10:16:25 +1100 Subject: [PATCH 4/9] rename to AdvDoorSeal, moved to _NF --- .../Components/AdvDoorSealComponent.cs} | 4 +-- .../Shuttles/Systems/AdvDoorSealSystem.cs} | 32 +++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) rename Content.Server/{Shuttles/Components/AdvDockingComponent.cs => _NF/Shuttles/Components/AdvDoorSealComponent.cs} (81%) rename Content.Server/{Shuttles/Systems/AdvDockingSystem.cs => _NF/Shuttles/Systems/AdvDoorSealSystem.cs} (79%) diff --git a/Content.Server/Shuttles/Components/AdvDockingComponent.cs b/Content.Server/_NF/Shuttles/Components/AdvDoorSealComponent.cs similarity index 81% rename from Content.Server/Shuttles/Components/AdvDockingComponent.cs rename to Content.Server/_NF/Shuttles/Components/AdvDoorSealComponent.cs index 568fce464a1..716916fdfed 100644 --- a/Content.Server/Shuttles/Components/AdvDockingComponent.cs +++ b/Content.Server/_NF/Shuttles/Components/AdvDoorSealComponent.cs @@ -4,8 +4,8 @@ namespace Content.Server.Shuttles.Components { [RegisterComponent] - [Access(typeof(AdvDockingSystem))] - public sealed partial class AdvDockingComponent : Component + [Access(typeof(AdvDoorSealSystem))] + public sealed partial class AdvDoorSealComponent : Component { [DataField, ViewVariables(VVAccess.ReadWrite)] public bool IsOn { get; set; } = true; diff --git a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs similarity index 79% rename from Content.Server/Shuttles/Systems/AdvDockingSystem.cs rename to Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs index 23355322ab4..c99875df9f3 100644 --- a/Content.Server/Shuttles/Systems/AdvDockingSystem.cs +++ b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs @@ -17,20 +17,12 @@ using Content.Shared.Doors.Components; using Robust.Shared.Map; using Robust.Shared.Map.Components; -using Robust.Shared.Physics.Collision.Shapes; -using Robust.Shared.Physics.Components; -using Robust.Shared.Physics.Events; -using Robust.Shared.Physics.Systems; -using Robust.Shared.Timing; -using Robust.Shared.Utility; using Content.Shared.Localizations; using Content.Shared.Power; -using Content.Server.Construction; // Frontier -using Content.Server.DeviceLinking.Events; // Frontier namespace Content.Server.Shuttles.Systems { - public sealed class AdvDockingSystem : EntitySystem + public sealed class AdvDoorSealSystem : EntitySystem { [Dependency] private readonly SharedMapSystem _mapSystem = default!; [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; @@ -38,13 +30,13 @@ public sealed class AdvDockingSystem : EntitySystem [Dependency] private readonly AirtightSystem _airtightSystem = default!; public override void Initialize() { - SubscribeLocalEvent(OnPowerChange); - SubscribeLocalEvent(OnAnchorChange); + SubscribeLocalEvent(OnPowerChange); + SubscribeLocalEvent(OnAnchorChange); //SubscribeLocalEvent(OnShuttleTileChange); - SubscribeLocalEvent(OnDockInit); + SubscribeLocalEvent(OnDockInit); } - private void OnDockInit(EntityUid uid, AdvDockingComponent component, ComponentInit args) + private void OnDockInit(EntityUid uid, AdvDoorSealComponent component, ComponentInit args) { if (TryComp(uid, out var apcPower) && component.OriginalLoad == 0) { component.OriginalLoad = apcPower.Load; } // Frontier @@ -69,7 +61,7 @@ private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref var tilePos = args.NewTile.GridIndices; var grid = Comp(uid); var xformQuery = GetEntityQuery(); - var dockQuery = GetEntityQuery(); + var dockQuery = GetEntityQuery(); for (var x = -1; x <= 1; x++) { @@ -99,7 +91,7 @@ private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref } } - private void OnPowerChange(EntityUid uid, AdvDockingComponent component, ref PowerChangedEvent args) + private void OnPowerChange(EntityUid uid, AdvDoorSealComponent component, ref PowerChangedEvent args) { if (args.Powered && CanEnable(uid, component)) { @@ -111,7 +103,7 @@ private void OnPowerChange(EntityUid uid, AdvDockingComponent component, ref Pow } } - private void OnAnchorChange(EntityUid uid, AdvDockingComponent component, ref AnchorStateChangedEvent args) + private void OnAnchorChange(EntityUid uid, AdvDoorSealComponent component, ref AnchorStateChangedEvent args) { if (args.Anchored && CanEnable(uid, component)) { @@ -127,7 +119,7 @@ private void OnAnchorChange(EntityUid uid, AdvDockingComponent component, ref An /// /// Tries to enable the seals and turn it on. If it's already enabled it does nothing. /// - public void EnableAirtightness(EntityUid uid, AdvDockingComponent component, TransformComponent? xform = null) + public void EnableAirtightness(EntityUid uid, AdvDoorSealComponent component, TransformComponent? xform = null) { if (component.IsOn || !Resolve(uid, ref xform)) @@ -144,7 +136,7 @@ public void EnableAirtightness(EntityUid uid, AdvDockingComponent component, Tra } - public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, TransformComponent? xform = null) + public void DisableAirtightness(EntityUid uid, AdvDoorSealComponent component, TransformComponent? xform = null) { if (!Resolve(uid, ref xform)) return; DisableAirtightness(uid, component, xform.GridUid, xform); @@ -154,7 +146,7 @@ public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, Tr /// /// Tries to disable the seals /// - public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, EntityUid? gridId, TransformComponent? xform = null) + public void DisableAirtightness(EntityUid uid, AdvDoorSealComponent component, EntityUid? gridId, TransformComponent? xform = null) { if (!component.IsOn || !Resolve(uid, ref xform)) @@ -174,7 +166,7 @@ public void DisableAirtightness(EntityUid uid, AdvDockingComponent component, En } - public bool CanEnable(EntityUid uid, AdvDockingComponent component) + public bool CanEnable(EntityUid uid, AdvDoorSealComponent component) { var xform = Transform(uid); From bb3cf957c0f8303a373fff15836078305d747f0a Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 15:34:01 +1100 Subject: [PATCH 5/9] Changed the shuttle tile thruster updating to its own event, UpdateSpacedEvent --- .../Shuttles/Events/UpdateSpacedEvent.cs | 11 +++++ .../Shuttles/Systems/ShuttleSystem.cs | 32 +++++++++++++ .../Shuttles/Systems/ThrusterSystem.cs | 47 ++++++------------- .../_NF/Shuttles/Systems/AdvDoorSealSystem.cs | 13 ++--- 4 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 Content.Server/Shuttles/Events/UpdateSpacedEvent.cs diff --git a/Content.Server/Shuttles/Events/UpdateSpacedEvent.cs b/Content.Server/Shuttles/Events/UpdateSpacedEvent.cs new file mode 100644 index 00000000000..ff8c72c75d3 --- /dev/null +++ b/Content.Server/Shuttles/Events/UpdateSpacedEvent.cs @@ -0,0 +1,11 @@ +using Content.Server.Shuttles.Components; + +namespace Content.Server.Shuttles.Events; + +/// +/// Raised whenever a tile changes from spaced to unspaced or vice versa. +/// +public sealed class UpdateSpacedEvent : EntityEventArgs +{ + +} diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.cs index 4dedf45ce1d..90a7112d6d9 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.cs @@ -5,12 +5,14 @@ using Content.Server.Parallax; using Content.Server.Procedural; using Content.Server.Shuttles.Components; +using Content.Server.Shuttles.Events; // Frontier using Content.Server.Station.Systems; using Content.Server.Stunnable; using Content.Shared.GameTicking; using Content.Shared.Mobs.Systems; using Content.Shared.Shuttles.Systems; using Content.Shared.Throwing; +using Content.Shared.Maps; // Frontier using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.GameStates; @@ -80,6 +82,7 @@ public override void Initialize() SubscribeLocalEvent(OnGridInit); SubscribeLocalEvent(OnGridFixtureChange); + SubscribeLocalEvent(OnShuttleTileChange); // Frontier NfInitialize(); // Frontier Initialization for the ShuttleSystem @@ -100,6 +103,35 @@ private void OnGridFixtureChange(EntityUid uid, FixturesComponent manager, GridF } } + private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args) + { + // Stop checking if the IsSpace didn't change + if (args.NewTile.IsSpace(_tileDefManager) == args.OldTile.IsSpace(_tileDefManager)) + return; + + var tilePos = args.NewTile.GridIndices; + var grid = Comp(uid); + var xformQuery = GetEntityQuery(); + var thrusterQuery = GetEntityQuery(); + + for (var x = -1; x <= 1; x++) + { + for (var y = -1; y <= 1; y++) + { + if (x != 0 && y != 0) + continue; + + var checkPos = tilePos + new Vector2i(x, y); + var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos); + + while (enumerator.MoveNext(out var ent)) + { + RaiseLocalEvent(ent.Value, new UpdateSpacedEvent { }); + } + } + } + } + private void OnGridInit(GridInitializeEvent ev) { if (HasComp(ev.EntityUid)) diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index d8bcded4dd8..75eec5623e5 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; +using Content.Server.Shuttles.Events; // Frontier using Content.Shared.Damage; using Content.Shared.Examine; using Content.Shared.Interaction; @@ -56,7 +57,7 @@ public override void Initialize() SubscribeLocalEvent(OnThrusterExamine); - SubscribeLocalEvent(OnShuttleTileChange); + SubscribeLocalEvent(OnTileChange); // Frontier SubscribeLocalEvent(OnRefreshParts); SubscribeLocalEvent(OnUpgradeExamine); @@ -124,42 +125,22 @@ private void OnIsHotEvent(EntityUid uid, ThrusterComponent component, IsHotEvent args.IsHot = component.Type != ThrusterType.Angular && component.IsOn; } - private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args) + private void OnTileChange(EntityUid uid, ThrusterComponent component, ref UpdateSpacedEvent args) { - // If the old tile was space but the new one isn't then disable all adjacent thrusters - if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager)) - return; - - var tilePos = args.NewTile.GridIndices; - var grid = Comp(uid); - var xformQuery = GetEntityQuery(); - var thrusterQuery = GetEntityQuery(); + var canEnable = CanEnable(uid, component); - for (var x = -1; x <= 1; x++) + // Enable it if it was turned off but new tile is valid + if (!component.IsOn && canEnable) { - for (var y = -1; y <= 1; y++) - { - if (x != 0 && y != 0) - continue; - - var checkPos = tilePos + new Vector2i(x, y); - var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos); - - while (enumerator.MoveNext(out var ent)) - { - if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace) - continue; - - // Work out if the thruster is facing this direction - var xform = xformQuery.GetComponent(ent.Value); - var direction = xform.LocalRotation.ToWorldVec(); - - if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y)) - continue; + EnableThruster(uid, component); + return; + } - DisableThruster(ent.Value, thruster, xform.GridUid); - } - } + // Disable if new tile invalid + if (component.IsOn && !canEnable) + { + DisableThruster(uid, component); + return; } } diff --git a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs index c99875df9f3..94ae833689f 100644 --- a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs +++ b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs @@ -33,21 +33,18 @@ public override void Initialize() SubscribeLocalEvent(OnPowerChange); SubscribeLocalEvent(OnAnchorChange); //SubscribeLocalEvent(OnShuttleTileChange); - SubscribeLocalEvent(OnDockInit); + SubscribeLocalEvent(OnComponentInit); } - private void OnDockInit(EntityUid uid, AdvDoorSealComponent component, ComponentInit args) + private void OnComponentInit(EntityUid uid, AdvDoorSealComponent component, ComponentInit args) { - if (TryComp(uid, out var apcPower) && component.OriginalLoad == 0) { component.OriginalLoad = apcPower.Load; } // Frontier - - if (!component.IsOn) - { - return; - } + if (TryComp(uid, out var apcPower) && component.OriginalLoad == 0) { component.OriginalLoad = apcPower.Load; } if (CanEnable(uid, component)) { EnableAirtightness(uid, component); + } else { + DisableAirtightness(uid, component); } } From 0c829d01b79e9607efb0d9149c8b7f8b269d8323 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 15:47:58 +1100 Subject: [PATCH 6/9] add adjacent tile checks to advDoorSeals --- .../_NF/Shuttles/Systems/AdvDoorSealSystem.cs | 50 +++++-------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs index 94ae833689f..358840ebf0a 100644 --- a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs +++ b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; +using Content.Server.Shuttles.Events; using Content.Server.Doors.Systems; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; @@ -15,6 +16,7 @@ using Content.Shared.Temperature; using Content.Shared.Doors; using Content.Shared.Doors.Components; + using Robust.Shared.Map; using Robust.Shared.Map.Components; using Content.Shared.Localizations; @@ -32,7 +34,7 @@ public override void Initialize() { SubscribeLocalEvent(OnPowerChange); SubscribeLocalEvent(OnAnchorChange); - //SubscribeLocalEvent(OnShuttleTileChange); + SubscribeLocalEvent(OnTileChange); SubscribeLocalEvent(OnComponentInit); } @@ -43,48 +45,22 @@ private void OnComponentInit(EntityUid uid, AdvDoorSealComponent component, Comp if (CanEnable(uid, component)) { EnableAirtightness(uid, component); - } else { + } + else + { DisableAirtightness(uid, component); } } - - private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args) + private void OnTileChange(EntityUid uid, AdvDoorSealComponent component, ref UpdateSpacedEvent args) { - // If the old tile was space but the new one isn't then disable all adjacent thrusters - if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager)) - return; - - var tilePos = args.NewTile.GridIndices; - var grid = Comp(uid); - var xformQuery = GetEntityQuery(); - var dockQuery = GetEntityQuery(); - - for (var x = -1; x <= 1; x++) + if (CanEnable(uid, component)) { - for (var y = -1; y <= 1; y++) - { - if (x != 0 && y != 0) - continue; - - var checkPos = tilePos + new Vector2i(x, y); - var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos); - - while (enumerator.MoveNext(out var ent)) - { - if (!dockQuery.TryGetComponent(ent.Value, out var dock)) - continue; - - // Work out if the dock is facing this direction - var xform = xformQuery.GetComponent(ent.Value); - var direction = xform.LocalRotation.ToWorldVec(); - - if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y)) - continue; - - DisableAirtightness(ent.Value, dock, xform.GridUid); - } - } + EnableAirtightness(uid, component); + } + else + { + DisableAirtightness(uid, component); } } From 123dde859c3f05fff6515ad120863b3c87d548fd Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 16:11:36 +1100 Subject: [PATCH 7/9] added examine ftl entries --- .../_NF/Shuttles/Systems/AdvDoorSealSystem.cs | 28 +++++++++++++++++++ .../en-US/_NF/shuttles/adv-door-seals.ftl | 5 ++++ 2 files changed, 33 insertions(+) create mode 100644 Resources/Locale/en-US/_NF/shuttles/adv-door-seals.ftl diff --git a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs index 358840ebf0a..a5b5d33ae5b 100644 --- a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs +++ b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs @@ -36,6 +36,7 @@ public override void Initialize() SubscribeLocalEvent(OnAnchorChange); SubscribeLocalEvent(OnTileChange); SubscribeLocalEvent(OnComponentInit); + SubscribeLocalEvent(OnDoorExamine); } private void OnComponentInit(EntityUid uid, AdvDoorSealComponent component, ComponentInit args) @@ -89,6 +90,33 @@ private void OnAnchorChange(EntityUid uid, AdvDoorSealComponent component, ref A } + private void OnDoorExamine(EntityUid uid, AdvDoorSealComponent component, ExaminedEvent args) + { + // Powered is already handled by other power components + var enabled = Loc.GetString(component.IsOn ? "adv-door-seal-comp-enabled" : "adv-door-seal-comp-disabled"); + + using (args.PushGroup(nameof(AdvDoorSealComponent))) + { + args.PushMarkup(enabled); + + if (EntityManager.TryGetComponent(uid, out TransformComponent? xform) && xform.Anchored) + { + var doorLocalization = ContentLocalizationManager.FormatDirection(xform.LocalRotation.ToWorldVec().GetDir()).ToLower(); + var doorDir = Loc.GetString("adv-door-seal-comp-door-direction", + ("direction", doorLocalization)); + + args.PushMarkup(doorDir); + + var exposed = DockExposed(xform); + + var doorText = + Loc.GetString(exposed ? "adv-door-seal-comp-door-exposed" : "adv-door-seal-comp-door-not-exposed"); + + args.PushMarkup(doorText); + } + } + } + /// /// Tries to enable the seals and turn it on. If it's already enabled it does nothing. /// diff --git a/Resources/Locale/en-US/_NF/shuttles/adv-door-seals.ftl b/Resources/Locale/en-US/_NF/shuttles/adv-door-seals.ftl new file mode 100644 index 00000000000..ae69d614a41 --- /dev/null +++ b/Resources/Locale/en-US/_NF/shuttles/adv-door-seals.ftl @@ -0,0 +1,5 @@ +adv-door-seal-comp-enabled = The airtight seal system is turned [color=green]on[/color]. +adv-door-seal-comp-disabled = The airtight seal system is turned [color=red]off[/color]. +adv-door-seal-comp-door-direction = The door is facing [color=yellow]{$direction}[/color]. +adv-door-seal-comp-door-exposed = The seals are [color=green]exposed[/color] to space. +adv-door-seal-comp-door-not-exposed = The seals are [color=red]not exposed[/color] to space. From c2882f825f60505009e3666af5f0903238d721a4 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 16:33:27 +1100 Subject: [PATCH 8/9] undo debug changes to DockingSystem --- Content.Server/Shuttles/Systems/DockingSystem.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Content.Server/Shuttles/Systems/DockingSystem.cs b/Content.Server/Shuttles/Systems/DockingSystem.cs index 9977cd3e6ef..fcdd6c0c1ae 100644 --- a/Content.Server/Shuttles/Systems/DockingSystem.cs +++ b/Content.Server/Shuttles/Systems/DockingSystem.cs @@ -287,7 +287,7 @@ public void Dock(Entity dockA, Entity dockB) _doorSystem.SetBoltsDown((dockAUid, airlockA), true); } } - //doorA.ChangeAirtight = false; //testing docked airtightness + doorA.ChangeAirtight = false; } if (TryComp(dockBUid, out DoorComponent? doorB)) @@ -299,7 +299,7 @@ public void Dock(Entity dockA, Entity dockB) _doorSystem.SetBoltsDown((dockBUid, airlockB), true); } } - //doorB.ChangeAirtight = false; //testing docked airtightness + doorB.ChangeAirtight = false; } if (_pathfinding.TryCreatePortal(dockAXform.Coordinates, dockBXform.Coordinates, out var handle)) @@ -352,10 +352,8 @@ private void OnUndock(EntityUid dockUid) if (TryComp(dockUid, out var airlock)) _doorSystem.SetBoltsDown((dockUid, airlock), false); - - - //if (TryComp(dockUid, out DoorComponent? door) && _doorSystem.TryClose(dockUid, door)) - // door.ChangeAirtight = false; + if (TryComp(dockUid, out DoorComponent? door) && _doorSystem.TryClose(dockUid, door)) + door.ChangeAirtight = true; } private void OnRequestUndock(EntityUid uid, ShuttleConsoleComponent component, UndockRequestMessage args) From 6cb3644029240743448f4827faba510881133111 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Fri, 27 Dec 2024 16:36:36 +1100 Subject: [PATCH 9/9] Remove extraneous includes --- .../_NF/Shuttles/Systems/AdvDoorSealSystem.cs | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs index a5b5d33ae5b..51f8c25f6e8 100644 --- a/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs +++ b/Content.Server/_NF/Shuttles/Systems/AdvDoorSealSystem.cs @@ -1,5 +1,3 @@ -using System.Numerics; -using Content.Server.Audio; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; using Content.Server.Shuttles.Components; @@ -7,20 +5,14 @@ using Content.Server.Doors.Systems; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; -using Content.Shared.Damage; using Content.Shared.Examine; -using Content.Shared.Interaction; using Content.Shared.Maps; -using Content.Shared.Physics; -using Content.Shared.Shuttles.Components; -using Content.Shared.Temperature; -using Content.Shared.Doors; using Content.Shared.Doors.Components; - -using Robust.Shared.Map; -using Robust.Shared.Map.Components; using Content.Shared.Localizations; using Content.Shared.Power; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; + namespace Content.Server.Shuttles.Systems { @@ -90,32 +82,32 @@ private void OnAnchorChange(EntityUid uid, AdvDoorSealComponent component, ref A } - private void OnDoorExamine(EntityUid uid, AdvDoorSealComponent component, ExaminedEvent args) - { - // Powered is already handled by other power components - var enabled = Loc.GetString(component.IsOn ? "adv-door-seal-comp-enabled" : "adv-door-seal-comp-disabled"); - - using (args.PushGroup(nameof(AdvDoorSealComponent))) + private void OnDoorExamine(EntityUid uid, AdvDoorSealComponent component, ExaminedEvent args) { - args.PushMarkup(enabled); + // Powered is already handled by other power components + var enabled = Loc.GetString(component.IsOn ? "adv-door-seal-comp-enabled" : "adv-door-seal-comp-disabled"); - if (EntityManager.TryGetComponent(uid, out TransformComponent? xform) && xform.Anchored) + using (args.PushGroup(nameof(AdvDoorSealComponent))) { - var doorLocalization = ContentLocalizationManager.FormatDirection(xform.LocalRotation.ToWorldVec().GetDir()).ToLower(); - var doorDir = Loc.GetString("adv-door-seal-comp-door-direction", - ("direction", doorLocalization)); + args.PushMarkup(enabled); + + if (EntityManager.TryGetComponent(uid, out TransformComponent? xform) && xform.Anchored) + { + var doorLocalization = ContentLocalizationManager.FormatDirection(xform.LocalRotation.ToWorldVec().GetDir()).ToLower(); + var doorDir = Loc.GetString("adv-door-seal-comp-door-direction", + ("direction", doorLocalization)); - args.PushMarkup(doorDir); + args.PushMarkup(doorDir); - var exposed = DockExposed(xform); + var exposed = DockExposed(xform); - var doorText = - Loc.GetString(exposed ? "adv-door-seal-comp-door-exposed" : "adv-door-seal-comp-door-not-exposed"); + var doorText = + Loc.GetString(exposed ? "adv-door-seal-comp-door-exposed" : "adv-door-seal-comp-door-not-exposed"); - args.PushMarkup(doorText); + args.PushMarkup(doorText); + } } } - } /// /// Tries to enable the seals and turn it on. If it's already enabled it does nothing.