From fa53fde7a7cc8ca1fffc2d26606687b15c19dc20 Mon Sep 17 00:00:00 2001 From: fox Date: Fri, 5 Jul 2024 18:28:12 +0300 Subject: [PATCH] It is done --- .../Station/Systems/StationDampeningSystem.cs | 28 +++++++++++++++++++ .../Physics/FrictionRemoverSystem.cs | 13 +++++++-- .../Physics/PassiveDampeningComponent.cs | 18 ++++++++++++ Resources/Maps/Shuttles/trading_outpost.yml | 3 ++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 Content.Server/Station/Systems/StationDampeningSystem.cs create mode 100644 Content.Shared/Physics/PassiveDampeningComponent.cs diff --git a/Content.Server/Station/Systems/StationDampeningSystem.cs b/Content.Server/Station/Systems/StationDampeningSystem.cs new file mode 100644 index 00000000000..f499127031e --- /dev/null +++ b/Content.Server/Station/Systems/StationDampeningSystem.cs @@ -0,0 +1,28 @@ +using Content.Server.Station.Events; +using Content.Shared.Physics; + +namespace Content.Server.Station.Systems; + +public sealed class StationDampeningSystem : EntitySystem +{ + public override void Initialize() + { + SubscribeLocalEvent(OnInitStation); + } + + private void OnInitStation(ref StationPostInitEvent ev) + { + foreach (var grid in ev.Station.Comp.Grids) + { + // If the station grid doesn't have defined dampening, give it a small dampening by default + // This will ensure cargo tech pros won't fling the station 1000 megaparsec away from the galaxy + if (!TryComp(grid, out var dampening)) + { + dampening = AddComp(grid); + dampening.Enabled = true; + dampening.LinearDampening = 0.01f; + dampening.AngularDampening = 0.01f; + } + } + } +} diff --git a/Content.Shared/Physics/FrictionRemoverSystem.cs b/Content.Shared/Physics/FrictionRemoverSystem.cs index 65bbe9e4d23..c8d7521eb01 100644 --- a/Content.Shared/Physics/FrictionRemoverSystem.cs +++ b/Content.Shared/Physics/FrictionRemoverSystem.cs @@ -1,3 +1,4 @@ +using Robust.Shared.Map.Components; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Systems; @@ -19,7 +20,15 @@ public override void Initialize() private void RemoveDampening(EntityUid uid, PhysicsComponent component, PhysicsSleepEvent args) { - _physics.SetAngularDamping(uid, component, 0f, false); - _physics.SetLinearDamping(uid, component, 0f); + var linear = 0f; + var angular = 0f; + if (TryComp(uid, out var dampening) && dampening.Enabled) + { + linear = dampening.LinearDampening; + angular = dampening.AngularDampening; + } + + _physics.SetAngularDamping(uid, component, angular, false); + _physics.SetLinearDamping(uid, component, linear); } } diff --git a/Content.Shared/Physics/PassiveDampeningComponent.cs b/Content.Shared/Physics/PassiveDampeningComponent.cs new file mode 100644 index 00000000000..834569195ee --- /dev/null +++ b/Content.Shared/Physics/PassiveDampeningComponent.cs @@ -0,0 +1,18 @@ +namespace Content.Shared.Physics; + +/// +/// A component that allows an entity to have friction (linear and angular dampening) +/// even when not being affected by gravity. +/// +[RegisterComponent] +public sealed partial class PassiveDampeningComponent : Component +{ + [DataField] + public bool Enabled = true; + + [DataField] + public float LinearDampening = 0.2f; + + [DataField] + public float AngularDampening = 0.2f; +} diff --git a/Resources/Maps/Shuttles/trading_outpost.yml b/Resources/Maps/Shuttles/trading_outpost.yml index f040d58253d..7b968b5c13d 100644 --- a/Resources/Maps/Shuttles/trading_outpost.yml +++ b/Resources/Maps/Shuttles/trading_outpost.yml @@ -60,6 +60,9 @@ entities: linearDamping: 0.05 fixedRotation: False bodyType: Dynamic + - type: PassiveDampening # To prevent cargotechs from flingling it away. + linearDampening: 0.01 + angularDampening: 0.01 - type: Fixtures fixtures: {} - type: OccluderTree