]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Random emergency shuttle time (#10047)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 31 Mar 2023 04:20:43 +0000 (15:20 +1100)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2023 04:20:43 +0000 (22:20 -0600)
* Random emergency shuttle time

60 to 180 seconds. Rounds up to nearest 10.
All other FTL will go to the default of 30s.

* fix

Content.IntegrationTests/Tests/RoundEndTest.cs
Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs
Content.Shared/CCVar/CCVars.cs
Resources/ConfigPresets/Build/development.toml

index 6a5a0da8c728946bbe4d16aa95a667db4d2b34b0..9e4b71d8c2f48563e469fbf9e2eed40f8f58a56e 100644 (file)
@@ -32,7 +32,7 @@ namespace Content.IntegrationTests.Tests
             await server.WaitAssertion(() =>
             {
                 config.SetCVar(CCVars.GameLobbyEnabled, true);
-                config.SetCVar(CCVars.EmergencyShuttleTransitTime, 1f);
+                config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, 1f);
                 config.SetCVar(CCVars.EmergencyShuttleDockTime, 1f);
 
                 roundEndSystem.DefaultCooldownDuration = TimeSpan.FromMilliseconds(100);
@@ -116,7 +116,7 @@ namespace Content.IntegrationTests.Tests
             await server.WaitAssertion(() =>
             {
                 config.SetCVar(CCVars.GameLobbyEnabled, false);
-                config.SetCVar(CCVars.EmergencyShuttleTransitTime, CCVars.EmergencyShuttleTransitTime.DefaultValue);
+                config.SetCVar(CCVars.EmergencyShuttleMinTransitTime, CCVars.EmergencyShuttleMinTransitTime.DefaultValue);
                 config.SetCVar(CCVars.EmergencyShuttleDockTime, CCVars.EmergencyShuttleDockTime.DefaultValue);
 
                 roundEndSystem.DefaultCooldownDuration = TimeSpan.FromSeconds(30);
index 3bc7264fb3c38b180d99d73e47f8c2fa0ce13333..6e487ee7a3206414cc1ae6b70e82425ed66ad83c 100644 (file)
@@ -41,7 +41,17 @@ public sealed partial class EmergencyShuttleSystem
     private readonly TimeSpan _bufferTime = TimeSpan.FromSeconds(5);
 
     /// <summary>
-    /// <see cref="CCVars.EmergencyShuttleTransitTime"/>
+    /// <see cref="CCVars.EmergencyShuttleMinTransitTime"/>
+    /// </summary>
+    public float MinimumTransitTime { get; private set; }
+
+    /// <summary>
+    /// <see cref="CCVars.EmergencyShuttleMaxTransitTime"/>
+    /// </summary>
+    public float MaximumTransitTime { get; private set; }
+
+    /// <summary>
+    /// How long it will take for the emergency shuttle to arrive at CentComm.
     /// </summary>
     public float TransitTime { get; private set; }
 
@@ -69,7 +79,8 @@ public sealed partial class EmergencyShuttleSystem
 
     private void InitializeEmergencyConsole()
     {
-        _configManager.OnValueChanged(CCVars.EmergencyShuttleTransitTime, SetTransitTime, true);
+        _configManager.OnValueChanged(CCVars.EmergencyShuttleMinTransitTime, SetMinTransitTime, true);
+        _configManager.OnValueChanged(CCVars.EmergencyShuttleMaxTransitTime, SetMaxTransitTime, true);
         _configManager.OnValueChanged(CCVars.EmergencyShuttleAuthorizeTime, SetAuthorizeTime, true);
         SubscribeLocalEvent<EmergencyShuttleConsoleComponent, ComponentStartup>(OnEmergencyStartup);
         SubscribeLocalEvent<EmergencyShuttleConsoleComponent, EmergencyShuttleAuthorizeMessage>(OnEmergencyAuthorize);
@@ -95,15 +106,22 @@ public sealed partial class EmergencyShuttleSystem
         _authorizeTime = obj;
     }
 
-    private void SetTransitTime(float obj)
+    private void SetMinTransitTime(float obj)
+    {
+        MinimumTransitTime = obj;
+        MaximumTransitTime = Math.Max(MaximumTransitTime, MinimumTransitTime);
+    }
+
+    private void SetMaxTransitTime(float obj)
     {
-        TransitTime = obj;
+        MaximumTransitTime = Math.Max(MinimumTransitTime, obj);
     }
 
     private void ShutdownEmergencyConsole()
     {
         _configManager.UnsubValueChanged(CCVars.EmergencyShuttleAuthorizeTime, SetAuthorizeTime);
-        _configManager.UnsubValueChanged(CCVars.EmergencyShuttleTransitTime, SetTransitTime);
+        _configManager.UnsubValueChanged(CCVars.EmergencyShuttleMinTransitTime, SetMinTransitTime);
+        _configManager.UnsubValueChanged(CCVars.EmergencyShuttleMaxTransitTime, SetMaxTransitTime);
     }
 
     private void OnEmergencyStartup(EntityUid uid, EmergencyShuttleConsoleComponent component, ComponentStartup args)
@@ -283,6 +301,9 @@ public sealed partial class EmergencyShuttleSystem
         _consoleAccumulator = float.MinValue;
         EarlyLaunchAuthorized = false;
         EmergencyShuttleArrived = false;
+        TransitTime = MinimumTransitTime + (MaximumTransitTime - MinimumTransitTime) * _random.NextFloat();
+        // Round to nearest 10
+        TransitTime = MathF.Round(TransitTime / 10f) * 10f;
     }
 
     private void UpdateAllEmergencyConsoles()
index 8280d8d294bfaf8884149bf36de4fdc02c763ae3..6b3e6ea2e7bece16e742bbf258fe0fe94ff51f64 100644 (file)
@@ -1108,16 +1108,22 @@ namespace Content.Shared.CCVar
             CVarDef.Create("shuttle.emergency_authorize_time", 10f, CVar.SERVERONLY);
 
         /// <summary>
-        /// How long after the console is authorized for the shuttle to early launch.
+        /// The minimum time for the emergency shuttle to arrive at centcomm.
+        /// </summary>
+        public static readonly CVarDef<float> EmergencyShuttleMinTransitTime =
+            CVarDef.Create("shuttle.emergency_transit_time_min", 60f, CVar.SERVERONLY);
+
+        /// <summary>
+        /// The maximum time for the emergency shuttle to arrive at centcomm.
         /// </summary>
-        public static readonly CVarDef<float> EmergencyShuttleTransitTime =
-            CVarDef.Create("shuttle.emergency_transit_time", 60f, CVar.SERVERONLY);
+        public static readonly CVarDef<float> EmergencyShuttleMaxTransitTime =
+            CVarDef.Create("shuttle.emergency_transit_time_max", 180f, CVar.SERVERONLY);
 
         /// <summary>
         /// Whether the emergency shuttle is enabled or should the round just end.
         /// </summary>
         public static readonly CVarDef<bool> EmergencyShuttleEnabled =
-            CVarDef.Create("shuttle.emergency_enabled", true, CVar.SERVERONLY);
+            CVarDef.Create("shuttle.emergency", true, CVar.SERVERONLY);
 
         /// <summary>
         ///     The percentage of time passed from the initial call to when the shuttle can no longer be recalled.
index 31fccc5b44ec414a9bc34afc56a53a2eec7753b0..aa4172331add18e976dccf431bf03f52541262d1 100644 (file)
@@ -15,5 +15,5 @@ preload = false
 # Wastes startup time
 auto_call_time = 0
 cargo = false
-emergency_enabled = false
+emergency = false
 arrivals = false