]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make FTL constants in ShuttleSystem into cvars (#27706)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Sat, 11 May 2024 07:00:15 +0000 (00:00 -0700)
committerGitHub <noreply@github.com>
Sat, 11 May 2024 07:00:15 +0000 (00:00 -0700)
* Make FTL constants in ShuttleSystem into cvars

* Fix tests

Content.IntegrationTests/Tests/Station/EvacShuttleTest.cs
Content.Server/Salvage/SalvageSystem.Runner.cs
Content.Server/Shuttles/Systems/ArrivalsSystem.cs
Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs
Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs
Content.Server/Shuttles/Systems/ShuttleSystem.FasterThanLight.cs
Content.Shared/CCVar/CCVars.cs
SpaceStation14.sln.DotSettings

index 532e481ac29574843a3856023d09ece86335bd83..9e925a451a5338e485f74300ec9775b1582e5cce 100644 (file)
@@ -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<ShuttleSystem>();
         var evacSys = server.System<EmergencyShuttleSystem>();
-        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
index e6e29eb577500134032c08b27022f775fe39d65d..23607e2bdc55bb30a35199c8cbf87aa8ce3d891f 100644 (file)
@@ -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<ShuttleComponent, TransformComponent>();
 
                 if (TryComp<StationDataComponent>(comp.Station, out var data))
index 12df965f45a0578a61119f542722689a7d8b32f9..23f7e10a3e328c9af8b72850fcad8022f3229c9d 100644 (file)
@@ -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<DeviceNetworkComponent>(shuttleUid, out var netComp))
         {
             TryComp<FTLComponent>(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<DeviceNetworkComponent>(uid, out var netComp))
         {
@@ -420,7 +420,7 @@ public sealed class ArrivalsSystem : EntitySystem
                 if (comp.NextTransfer > curTime || !TryComp<StationDataComponent>(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)
index d45c04cdc28e25f51402dedfb677bda618ac90b9..887ee11c63d9ac0d0821e11429bb967536eb0165 100644 (file)
@@ -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;
 
index f0256aa15b9a07931241920f40b4e9a0c684ec1f..9bfe1bf98666efa9919a1c9254a6389bc0ea6675 100644 (file)
@@ -200,10 +200,9 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
     /// </summary>
     private void OnEmergencyFTL(EntityUid uid, EmergencyShuttleComponent component, ref FTLStartedEvent args)
     {
-        TimeSpan ftlTime = TimeSpan.FromSeconds
+        var ftlTime = TimeSpan.FromSeconds
         (
-            TryComp<FTLComponent>(uid, out var ftlComp) ?
-            ftlComp.TravelTime : ShuttleSystem.DefaultTravelTime
+            TryComp<FTLComponent>(uid, out var ftlComp) ? ftlComp.TravelTime : _shuttle.DefaultTravelTime
         );
 
         if (TryComp<DeviceNetworkComponent>(uid, out var netComp))
index a3cc2fde9b8dea682a31bb2d8591a614d69d9edd..11cc16e0cd09c64c3f70eafcb77739805825d6f4 100644 (file)
@@ -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);
 
     /// <summary>
     /// Left-side of the station we're allowed to use
@@ -94,6 +88,13 @@ public sealed partial class ShuttleSystem
         _physicsQuery = GetEntityQuery<PhysicsComponent>();
         _statusQuery = GetEntityQuery<StatusEffectsComponent>();
         _xformQuery = GetEntityQuery<TransformComponent>();
+
+        _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));
index 9686589672ebea3cdc5ae7a211247481c7de3256..912e52c71b1fe46e9504233ce51f27d547069c8b 100644 (file)
@@ -1381,6 +1381,42 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<bool> PreloadGrids =
             CVarDef.Create("shuttle.preload_grids", true, CVar.SERVERONLY);
 
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> FTLStartupTime =
+            CVarDef.Create("shuttle.startup_time", 5.5f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> FTLTravelTime =
+            CVarDef.Create("shuttle.travel_time", 20f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> FTLArrivalTime =
+            CVarDef.Create("shuttle.arrival_time", 5f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> FTLCooldown =
+            CVarDef.Create("shuttle.cooldown", 10f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> FTLMassLimit =
+            CVarDef.Create("shuttle.mass_limit", 300f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// Whether to automatically spawn escape shuttles.
+        /// </summary>
+        public static readonly CVarDef<float> HyperspaceKnockdownTime =
+            CVarDef.Create("shuttle.hyperspace_knockdown_time", 5f, CVar.SERVERONLY);
+
         /*
          * Emergency
          */
index 620de4225321b15861c7eb906b8689fc508cede8..0decb9a11b22e6791d012377b51551087d5157b3 100644 (file)
@@ -55,6 +55,7 @@
        <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AL/@EntryIndexedValue">AL</s:String>
        <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BB/@EntryIndexedValue">BB</s:String>
        <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CC/@EntryIndexedValue">CC</s:String>
+       <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FTL/@EntryIndexedValue">FTL</s:String>
        <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GC/@EntryIndexedValue">GC</s:String>
     <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GD/@EntryIndexedValue">GD</s:String>
     <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GL/@EntryIndexedValue">GL</s:String>