From eed560bf3ee8402c5ad150b1246dea6a943cfe19 Mon Sep 17 00:00:00 2001 From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Sat, 11 May 2024 00:00:15 -0700 Subject: [PATCH] Make FTL constants in ShuttleSystem into cvars (#27706) * Make FTL constants in ShuttleSystem into cvars * Fix tests --- .../Tests/Station/EvacShuttleTest.cs | 5 +- .../Salvage/SalvageSystem.Runner.cs | 9 ++-- .../Shuttles/Systems/ArrivalsSystem.cs | 10 ++-- .../Systems/EmergencyShuttleSystem.Console.cs | 7 ++- .../Systems/EmergencyShuttleSystem.cs | 5 +- .../Systems/ShuttleSystem.FasterThanLight.cs | 53 +++++++++++-------- Content.Shared/CCVar/CCVars.cs | 36 +++++++++++++ SpaceStation14.sln.DotSettings | 1 + 8 files changed, 84 insertions(+), 42 deletions(-) diff --git a/Content.IntegrationTests/Tests/Station/EvacShuttleTest.cs b/Content.IntegrationTests/Tests/Station/EvacShuttleTest.cs index 532e481ac2..9e925a451a 100644 --- a/Content.IntegrationTests/Tests/Station/EvacShuttleTest.cs +++ b/Content.IntegrationTests/Tests/Station/EvacShuttleTest.cs @@ -87,8 +87,9 @@ public sealed class EvacShuttleTest Assert.That(LifeStage(salternXform.MapUid.Value), Is.EqualTo(EntityLifeStage.MapInitialized)); // Set up shuttle timing + var shuttleSys = server.System(); var evacSys = server.System(); - evacSys.TransitTime = ShuttleSystem.DefaultTravelTime; // Absolute minimum transit time, so the test has to run for at least this long + evacSys.TransitTime = shuttleSys.DefaultTravelTime; // Absolute minimum transit time, so the test has to run for at least this long // TODO SHUTTLE fix spaghetti var dockTime = server.CfgMan.GetCVar(CCVars.EmergencyShuttleDockTime); @@ -112,7 +113,7 @@ public sealed class EvacShuttleTest Assert.That(shuttleXform.MapUid, Is.EqualTo(ftl.Owner)); // Shuttle should have arrived at centcomm - await pair.RunSeconds(ShuttleSystem.DefaultTravelTime); + await pair.RunSeconds(shuttleSys.DefaultTravelTime); Assert.That(shuttleXform.MapUid, Is.EqualTo(centcommMap)); // Round should be ending now diff --git a/Content.Server/Salvage/SalvageSystem.Runner.cs b/Content.Server/Salvage/SalvageSystem.Runner.cs index e6e29eb577..23607e2bdc 100644 --- a/Content.Server/Salvage/SalvageSystem.Runner.cs +++ b/Content.Server/Salvage/SalvageSystem.Runner.cs @@ -1,9 +1,7 @@ using System.Numerics; using Content.Server.Salvage.Expeditions; -using Content.Server.Salvage.Expeditions.Structure; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; -using Content.Server.Shuttles.Systems; using Content.Server.Station.Components; using Content.Shared.Chat; using Content.Shared.Humanoid; @@ -13,7 +11,6 @@ using Content.Shared.Salvage.Expeditions; using Content.Shared.Shuttles.Components; using Robust.Shared.Map.Components; using Robust.Shared.Player; -using Robust.Shared.Utility; namespace Content.Server.Salvage; @@ -168,16 +165,16 @@ public sealed partial class SalvageSystem Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(5).Minutes))); } // Auto-FTL out any shuttles - else if (remaining < TimeSpan.FromSeconds(ShuttleSystem.DefaultStartupTime) + TimeSpan.FromSeconds(0.5)) + else if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime) + TimeSpan.FromSeconds(0.5)) { var ftlTime = (float) remaining.TotalSeconds; - if (remaining < TimeSpan.FromSeconds(ShuttleSystem.DefaultStartupTime)) + if (remaining < TimeSpan.FromSeconds(_shuttle.DefaultStartupTime)) { ftlTime = MathF.Max(0, (float) remaining.TotalSeconds - 0.5f); } - ftlTime = MathF.Min(ftlTime, ShuttleSystem.DefaultStartupTime); + ftlTime = MathF.Min(ftlTime, _shuttle.DefaultStartupTime); var shuttleQuery = AllEntityQuery(); if (TryComp(comp.Station, out var data)) diff --git a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs index 12df965f45..23f7e10a3e 100644 --- a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs +++ b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs @@ -1,10 +1,10 @@ using System.Linq; using Content.Server.Administration; +using Content.Server.DeviceNetwork.Components; +using Content.Server.DeviceNetwork.Systems; using Content.Server.GameTicking; using Content.Server.GameTicking.Events; using Content.Server.Parallax; -using Content.Server.DeviceNetwork.Components; -using Content.Server.DeviceNetwork.Systems; using Content.Server.Screens.Components; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; @@ -188,7 +188,7 @@ public sealed class ArrivalsSystem : EntitySystem if (TryComp(shuttleUid, out var netComp)) { TryComp(shuttleUid, out var ftlComp); - var ftlTime = TimeSpan.FromSeconds(ftlComp?.TravelTime ?? ShuttleSystem.DefaultTravelTime); + var ftlTime = TimeSpan.FromSeconds(ftlComp?.TravelTime ?? _shuttles.DefaultTravelTime); var payload = new NetworkPayload { @@ -254,7 +254,7 @@ public sealed class ArrivalsSystem : EntitySystem private void OnArrivalsDocked(EntityUid uid, ArrivalsShuttleComponent component, ref FTLCompletedEvent args) { - TimeSpan dockTime = component.NextTransfer - _timing.CurTime + TimeSpan.FromSeconds(ShuttleSystem.DefaultStartupTime); + var dockTime = component.NextTransfer - _timing.CurTime + TimeSpan.FromSeconds(_shuttles.DefaultStartupTime); if (TryComp(uid, out var netComp)) { @@ -420,7 +420,7 @@ public sealed class ArrivalsSystem : EntitySystem if (comp.NextTransfer > curTime || !TryComp(comp.Station, out var data)) continue; - var tripTime = ShuttleSystem.DefaultTravelTime + ShuttleSystem.DefaultStartupTime; + var tripTime = _shuttles.DefaultTravelTime + _shuttles.DefaultStartupTime; // Go back to arrivals source if (xform.MapUid != arrivalsXform.MapUid) diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs index d45c04cdc2..887ee11c63 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs @@ -1,10 +1,8 @@ using System.Threading; -using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.Screens.Components; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; -using Content.Shared.UserInterface; using Content.Shared.Access; using Content.Shared.CCVar; using Content.Shared.Database; @@ -13,6 +11,7 @@ using Content.Shared.Popups; using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.Events; using Content.Shared.Shuttles.Systems; +using Content.Shared.UserInterface; using Robust.Shared.Map; using Robust.Shared.Player; using Timer = Robust.Shared.Timing.Timer; @@ -131,7 +130,7 @@ public sealed partial class EmergencyShuttleSystem private void UpdateEmergencyConsole(float frameTime) { // Add some buffer time so eshuttle always first. - var minTime = -(TransitTime - (ShuttleSystem.DefaultStartupTime + ShuttleSystem.DefaultTravelTime + 1f)); + var minTime = -(TransitTime - (_shuttle.DefaultStartupTime + _shuttle.DefaultTravelTime + 1f)); // TODO: I know this is shit but I already just cleaned up a billion things. @@ -157,7 +156,7 @@ public sealed partial class EmergencyShuttleSystem } // Imminent departure - if (!_launchedShuttles && _consoleAccumulator <= ShuttleSystem.DefaultStartupTime) + if (!_launchedShuttles && _consoleAccumulator <= _shuttle.DefaultStartupTime) { _launchedShuttles = true; diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs index f0256aa15b..9bfe1bf986 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs @@ -200,10 +200,9 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem /// private void OnEmergencyFTL(EntityUid uid, EmergencyShuttleComponent component, ref FTLStartedEvent args) { - TimeSpan ftlTime = TimeSpan.FromSeconds + var ftlTime = TimeSpan.FromSeconds ( - TryComp(uid, out var ftlComp) ? - ftlComp.TravelTime : ShuttleSystem.DefaultTravelTime + TryComp(uid, out var ftlComp) ? ftlComp.TravelTime : _shuttle.DefaultTravelTime ); if (TryComp(uid, out var netComp)) diff --git a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs index a3cc2fde9b..11cc16e0cd 100644 --- a/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs +++ b/Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs @@ -6,6 +6,7 @@ using Content.Server.Shuttles.Events; using Content.Server.Station.Events; using Content.Shared.Body.Components; using Content.Shared.Buckle.Components; +using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.Ghost; using Content.Shared.Maps; @@ -34,18 +35,6 @@ public sealed partial class ShuttleSystem * This is a way to move a shuttle from one location to another, via an intermediate map for fanciness. */ - public const float DefaultStartupTime = 5.5f; - public const float DefaultTravelTime = 20f; - public const float DefaultArrivalTime = 5f; - private const float FTLCooldown = 10f; - public const float FTLMassLimit = 300f; - - // I'm too lazy to make CVars. - // >:( - // Confusingly, some of them already are cvars? - // I.e., shuttle transit time??? - // TODO Shuttle: fix spaghetti - private readonly SoundSpecifier _startupSound = new SoundPathSpecifier("/Audio/Effects/Shuttle/hyperspace_begin.ogg") { Params = AudioParams.Default.WithVolume(-5f), @@ -56,7 +45,12 @@ public sealed partial class ShuttleSystem Params = AudioParams.Default.WithVolume(-5f), }; - private readonly TimeSpan _hyperspaceKnockdownTime = TimeSpan.FromSeconds(5); + public float DefaultStartupTime; + public float DefaultTravelTime; + public float DefaultArrivalTime; + private float FTLCooldown; + public float FTLMassLimit; + private TimeSpan _hyperspaceKnockdownTime = TimeSpan.FromSeconds(5); /// /// Left-side of the station we're allowed to use @@ -94,6 +88,13 @@ public sealed partial class ShuttleSystem _physicsQuery = GetEntityQuery(); _statusQuery = GetEntityQuery(); _xformQuery = GetEntityQuery(); + + _cfg.OnValueChanged(CCVars.FTLStartupTime, time => DefaultStartupTime = time, true); + _cfg.OnValueChanged(CCVars.FTLTravelTime, time => DefaultTravelTime = time, true); + _cfg.OnValueChanged(CCVars.FTLArrivalTime, time => DefaultArrivalTime = time, true); + _cfg.OnValueChanged(CCVars.FTLCooldown, time => FTLCooldown = time, true); + _cfg.OnValueChanged(CCVars.FTLMassLimit, time => FTLMassLimit = time, true); + _cfg.OnValueChanged(CCVars.HyperspaceKnockdownTime, time => _hyperspaceKnockdownTime = TimeSpan.FromSeconds(time), true); } private void OnStationPostInit(ref StationPostInitEvent ev) @@ -215,7 +216,9 @@ public sealed partial class ShuttleSystem return false; } - if (TryComp(shuttleUid, out PhysicsComponent? shuttlePhysics) && shuttlePhysics.Mass > FTLMassLimit) + if (FTLMassLimit > 0 && + TryComp(shuttleUid, out PhysicsComponent? shuttlePhysics) && + shuttlePhysics.Mass > FTLMassLimit) { reason = Loc.GetString("shuttle-console-mass"); return false; @@ -248,15 +251,18 @@ public sealed partial class ShuttleSystem ShuttleComponent component, EntityCoordinates coordinates, Angle angle, - float startupTime = DefaultStartupTime, - float hyperspaceTime = DefaultTravelTime, + float? startupTime = null, + float? hyperspaceTime = null, string? priorityTag = null) { if (!TrySetupFTL(shuttleUid, component, out var hyperspace)) return; - hyperspace.StartupTime = startupTime; - hyperspace.TravelTime = hyperspaceTime; + startupTime ??= DefaultStartupTime; + hyperspaceTime ??= DefaultTravelTime; + + hyperspace.StartupTime = startupTime.Value; + hyperspace.TravelTime = hyperspaceTime.Value; hyperspace.StateTime = StartEndTime.FromStartDuration( _gameTiming.CurTime, TimeSpan.FromSeconds(hyperspace.StartupTime)); @@ -280,16 +286,19 @@ public sealed partial class ShuttleSystem EntityUid shuttleUid, ShuttleComponent component, EntityUid target, - float startupTime = DefaultStartupTime, - float hyperspaceTime = DefaultTravelTime, + float? startupTime = null, + float? hyperspaceTime = null, string? priorityTag = null) { if (!TrySetupFTL(shuttleUid, component, out var hyperspace)) return; + startupTime ??= DefaultStartupTime; + hyperspaceTime ??= DefaultTravelTime; + var config = _dockSystem.GetDockingConfig(shuttleUid, target, priorityTag); - hyperspace.StartupTime = startupTime; - hyperspace.TravelTime = hyperspaceTime; + hyperspace.StartupTime = startupTime.Value; + hyperspace.TravelTime = hyperspaceTime.Value; hyperspace.StateTime = StartEndTime.FromStartDuration( _gameTiming.CurTime, TimeSpan.FromSeconds(hyperspace.StartupTime)); diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 9686589672..912e52c71b 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1381,6 +1381,42 @@ namespace Content.Shared.CCVar public static readonly CVarDef PreloadGrids = CVarDef.Create("shuttle.preload_grids", true, CVar.SERVERONLY); + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef FTLStartupTime = + CVarDef.Create("shuttle.startup_time", 5.5f, CVar.SERVERONLY); + + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef FTLTravelTime = + CVarDef.Create("shuttle.travel_time", 20f, CVar.SERVERONLY); + + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef FTLArrivalTime = + CVarDef.Create("shuttle.arrival_time", 5f, CVar.SERVERONLY); + + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef FTLCooldown = + CVarDef.Create("shuttle.cooldown", 10f, CVar.SERVERONLY); + + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef FTLMassLimit = + CVarDef.Create("shuttle.mass_limit", 300f, CVar.SERVERONLY); + + /// + /// Whether to automatically spawn escape shuttles. + /// + public static readonly CVarDef HyperspaceKnockdownTime = + CVarDef.Create("shuttle.hyperspace_knockdown_time", 5f, CVar.SERVERONLY); + /* * Emergency */ diff --git a/SpaceStation14.sln.DotSettings b/SpaceStation14.sln.DotSettings index 620de42253..0decb9a11b 100644 --- a/SpaceStation14.sln.DotSettings +++ b/SpaceStation14.sln.DotSettings @@ -55,6 +55,7 @@ AL BB CC + FTL GC GD GL -- 2.51.2