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

@@ -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));