Make FTL constants in ShuttleSystem into cvars (#27706)

* Make FTL constants in ShuttleSystem into cvars

* Fix tests
This commit is contained in:
DrSmugleaf
2024-05-11 00:00:15 -07:00
committed by GitHub
parent c81c1c1f1e
commit eed560bf3e
8 changed files with 84 additions and 42 deletions

View File

@@ -87,8 +87,9 @@ public sealed class EvacShuttleTest
Assert.That(LifeStage(salternXform.MapUid.Value), Is.EqualTo(EntityLifeStage.MapInitialized)); Assert.That(LifeStage(salternXform.MapUid.Value), Is.EqualTo(EntityLifeStage.MapInitialized));
// Set up shuttle timing // Set up shuttle timing
var shuttleSys = server.System<ShuttleSystem>();
var evacSys = server.System<EmergencyShuttleSystem>(); 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 // TODO SHUTTLE fix spaghetti
var dockTime = server.CfgMan.GetCVar(CCVars.EmergencyShuttleDockTime); var dockTime = server.CfgMan.GetCVar(CCVars.EmergencyShuttleDockTime);
@@ -112,7 +113,7 @@ public sealed class EvacShuttleTest
Assert.That(shuttleXform.MapUid, Is.EqualTo(ftl.Owner)); Assert.That(shuttleXform.MapUid, Is.EqualTo(ftl.Owner));
// Shuttle should have arrived at centcomm // Shuttle should have arrived at centcomm
await pair.RunSeconds(ShuttleSystem.DefaultTravelTime); await pair.RunSeconds(shuttleSys.DefaultTravelTime);
Assert.That(shuttleXform.MapUid, Is.EqualTo(centcommMap)); Assert.That(shuttleXform.MapUid, Is.EqualTo(centcommMap));
// Round should be ending now // Round should be ending now

View File

@@ -1,9 +1,7 @@
using System.Numerics; using System.Numerics;
using Content.Server.Salvage.Expeditions; using Content.Server.Salvage.Expeditions;
using Content.Server.Salvage.Expeditions.Structure;
using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events; using Content.Server.Shuttles.Events;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Components; using Content.Server.Station.Components;
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.Humanoid; using Content.Shared.Humanoid;
@@ -13,7 +11,6 @@ using Content.Shared.Salvage.Expeditions;
using Content.Shared.Shuttles.Components; using Content.Shared.Shuttles.Components;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.Salvage; 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))); Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(5).Minutes)));
} }
// Auto-FTL out any shuttles // 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; 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.Max(0, (float) remaining.TotalSeconds - 0.5f);
} }
ftlTime = MathF.Min(ftlTime, ShuttleSystem.DefaultStartupTime); ftlTime = MathF.Min(ftlTime, _shuttle.DefaultStartupTime);
var shuttleQuery = AllEntityQuery<ShuttleComponent, TransformComponent>(); var shuttleQuery = AllEntityQuery<ShuttleComponent, TransformComponent>();
if (TryComp<StationDataComponent>(comp.Station, out var data)) if (TryComp<StationDataComponent>(comp.Station, out var data))

View File

@@ -1,10 +1,10 @@
using System.Linq; using System.Linq;
using Content.Server.Administration; using Content.Server.Administration;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.GameTicking; using Content.Server.GameTicking;
using Content.Server.GameTicking.Events; using Content.Server.GameTicking.Events;
using Content.Server.Parallax; using Content.Server.Parallax;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Screens.Components; using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events; using Content.Server.Shuttles.Events;
@@ -188,7 +188,7 @@ public sealed class ArrivalsSystem : EntitySystem
if (TryComp<DeviceNetworkComponent>(shuttleUid, out var netComp)) if (TryComp<DeviceNetworkComponent>(shuttleUid, out var netComp))
{ {
TryComp<FTLComponent>(shuttleUid, out var ftlComp); 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 var payload = new NetworkPayload
{ {
@@ -254,7 +254,7 @@ public sealed class ArrivalsSystem : EntitySystem
private void OnArrivalsDocked(EntityUid uid, ArrivalsShuttleComponent component, ref FTLCompletedEvent args) 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)) 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)) if (comp.NextTransfer > curTime || !TryComp<StationDataComponent>(comp.Station, out var data))
continue; continue;
var tripTime = ShuttleSystem.DefaultTravelTime + ShuttleSystem.DefaultStartupTime; var tripTime = _shuttles.DefaultTravelTime + _shuttles.DefaultStartupTime;
// Go back to arrivals source // Go back to arrivals source
if (xform.MapUid != arrivalsXform.MapUid) if (xform.MapUid != arrivalsXform.MapUid)

View File

@@ -1,10 +1,8 @@
using System.Threading; using System.Threading;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Components;
using Content.Server.Screens.Components; using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Events; using Content.Server.Shuttles.Events;
using Content.Shared.UserInterface;
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Database; using Content.Shared.Database;
@@ -13,6 +11,7 @@ using Content.Shared.Popups;
using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Events; using Content.Shared.Shuttles.Events;
using Content.Shared.Shuttles.Systems; using Content.Shared.Shuttles.Systems;
using Content.Shared.UserInterface;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player; using Robust.Shared.Player;
using Timer = Robust.Shared.Timing.Timer; using Timer = Robust.Shared.Timing.Timer;
@@ -131,7 +130,7 @@ public sealed partial class EmergencyShuttleSystem
private void UpdateEmergencyConsole(float frameTime) private void UpdateEmergencyConsole(float frameTime)
{ {
// Add some buffer time so eshuttle always first. // 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. // 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 // Imminent departure
if (!_launchedShuttles && _consoleAccumulator <= ShuttleSystem.DefaultStartupTime) if (!_launchedShuttles && _consoleAccumulator <= _shuttle.DefaultStartupTime)
{ {
_launchedShuttles = true; _launchedShuttles = true;

View File

@@ -200,10 +200,9 @@ public sealed partial class EmergencyShuttleSystem : EntitySystem
/// </summary> /// </summary>
private void OnEmergencyFTL(EntityUid uid, EmergencyShuttleComponent component, ref FTLStartedEvent args) private void OnEmergencyFTL(EntityUid uid, EmergencyShuttleComponent component, ref FTLStartedEvent args)
{ {
TimeSpan ftlTime = TimeSpan.FromSeconds var ftlTime = TimeSpan.FromSeconds
( (
TryComp<FTLComponent>(uid, out var ftlComp) ? TryComp<FTLComponent>(uid, out var ftlComp) ? ftlComp.TravelTime : _shuttle.DefaultTravelTime
ftlComp.TravelTime : ShuttleSystem.DefaultTravelTime
); );
if (TryComp<DeviceNetworkComponent>(uid, out var netComp)) if (TryComp<DeviceNetworkComponent>(uid, out var netComp))

View File

@@ -6,6 +6,7 @@ using Content.Server.Shuttles.Events;
using Content.Server.Station.Events; using Content.Server.Station.Events;
using Content.Shared.Body.Components; using Content.Shared.Body.Components;
using Content.Shared.Buckle.Components; using Content.Shared.Buckle.Components;
using Content.Shared.CCVar;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Ghost; using Content.Shared.Ghost;
using Content.Shared.Maps; 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. * 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") private readonly SoundSpecifier _startupSound = new SoundPathSpecifier("/Audio/Effects/Shuttle/hyperspace_begin.ogg")
{ {
Params = AudioParams.Default.WithVolume(-5f), Params = AudioParams.Default.WithVolume(-5f),
@@ -56,7 +45,12 @@ public sealed partial class ShuttleSystem
Params = AudioParams.Default.WithVolume(-5f), 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> /// <summary>
/// Left-side of the station we're allowed to use /// Left-side of the station we're allowed to use
@@ -94,6 +88,13 @@ public sealed partial class ShuttleSystem
_physicsQuery = GetEntityQuery<PhysicsComponent>(); _physicsQuery = GetEntityQuery<PhysicsComponent>();
_statusQuery = GetEntityQuery<StatusEffectsComponent>(); _statusQuery = GetEntityQuery<StatusEffectsComponent>();
_xformQuery = GetEntityQuery<TransformComponent>(); _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) private void OnStationPostInit(ref StationPostInitEvent ev)
@@ -215,7 +216,9 @@ public sealed partial class ShuttleSystem
return false; 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"); reason = Loc.GetString("shuttle-console-mass");
return false; return false;
@@ -248,15 +251,18 @@ public sealed partial class ShuttleSystem
ShuttleComponent component, ShuttleComponent component,
EntityCoordinates coordinates, EntityCoordinates coordinates,
Angle angle, Angle angle,
float startupTime = DefaultStartupTime, float? startupTime = null,
float hyperspaceTime = DefaultTravelTime, float? hyperspaceTime = null,
string? priorityTag = null) string? priorityTag = null)
{ {
if (!TrySetupFTL(shuttleUid, component, out var hyperspace)) if (!TrySetupFTL(shuttleUid, component, out var hyperspace))
return; return;
hyperspace.StartupTime = startupTime; startupTime ??= DefaultStartupTime;
hyperspace.TravelTime = hyperspaceTime; hyperspaceTime ??= DefaultTravelTime;
hyperspace.StartupTime = startupTime.Value;
hyperspace.TravelTime = hyperspaceTime.Value;
hyperspace.StateTime = StartEndTime.FromStartDuration( hyperspace.StateTime = StartEndTime.FromStartDuration(
_gameTiming.CurTime, _gameTiming.CurTime,
TimeSpan.FromSeconds(hyperspace.StartupTime)); TimeSpan.FromSeconds(hyperspace.StartupTime));
@@ -280,16 +286,19 @@ public sealed partial class ShuttleSystem
EntityUid shuttleUid, EntityUid shuttleUid,
ShuttleComponent component, ShuttleComponent component,
EntityUid target, EntityUid target,
float startupTime = DefaultStartupTime, float? startupTime = null,
float hyperspaceTime = DefaultTravelTime, float? hyperspaceTime = null,
string? priorityTag = null) string? priorityTag = null)
{ {
if (!TrySetupFTL(shuttleUid, component, out var hyperspace)) if (!TrySetupFTL(shuttleUid, component, out var hyperspace))
return; return;
startupTime ??= DefaultStartupTime;
hyperspaceTime ??= DefaultTravelTime;
var config = _dockSystem.GetDockingConfig(shuttleUid, target, priorityTag); var config = _dockSystem.GetDockingConfig(shuttleUid, target, priorityTag);
hyperspace.StartupTime = startupTime; hyperspace.StartupTime = startupTime.Value;
hyperspace.TravelTime = hyperspaceTime; hyperspace.TravelTime = hyperspaceTime.Value;
hyperspace.StateTime = StartEndTime.FromStartDuration( hyperspace.StateTime = StartEndTime.FromStartDuration(
_gameTiming.CurTime, _gameTiming.CurTime,
TimeSpan.FromSeconds(hyperspace.StartupTime)); TimeSpan.FromSeconds(hyperspace.StartupTime));

View File

@@ -1381,6 +1381,42 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> PreloadGrids = public static readonly CVarDef<bool> PreloadGrids =
CVarDef.Create("shuttle.preload_grids", true, CVar.SERVERONLY); 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 * Emergency
*/ */

View 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/=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/=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/=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/=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/=GD/@EntryIndexedValue">GD</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GL/@EntryIndexedValue">GL</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GL/@EntryIndexedValue">GL</s:String>