Don't load cargo shuttle by default (#9194)

* Don't load cargo shuttle by default

Realistically only I am going to care and it wastes a few seconds per test / debugging locally.

* Make it a general cvar instead

* a
This commit is contained in:
metalgearsloth
2022-06-27 14:58:40 +10:00
committed by GitHub
parent 2ae4e80732
commit e72e060972
3 changed files with 77 additions and 25 deletions

View File

@@ -10,12 +10,14 @@ using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.CCVar;
using Content.Shared.Dataset;
using Content.Shared.GameTicking;
using Content.Shared.MobState.Components;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -30,6 +32,7 @@ public sealed partial class CargoSystem
* Handles cargo shuttle mechanics, including cargo shuttle consoles.
*/
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IMapLoader _loader = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -50,8 +53,20 @@ public sealed partial class CargoSystem
private int _index;
/// <summary>
/// Whether cargo shuttles are enabled at all. Mainly used to disable cargo shuttle loading for performance reasons locally.
/// </summary>
private bool _enabled;
private void InitializeShuttle()
{
#if !FULL_RELEASE
_configManager.OverrideDefault(CCVars.CargoShuttles, false);
#endif
_enabled = _configManager.GetCVar(CCVars.CargoShuttles);
// Don't want to immediately call this as shuttles will get setup in the natural course of things.
_configManager.OnValueChanged(CCVars.CargoShuttles, SetCargoShuttleEnabled);
SubscribeLocalEvent<CargoShuttleComponent, MoveEvent>(OnCargoShuttleMove);
SubscribeLocalEvent<CargoShuttleConsoleComponent, ComponentStartup>(OnCargoShuttleConsoleStartup);
SubscribeLocalEvent<CargoShuttleConsoleComponent, CargoCallShuttleMessage>(OnCargoShuttleCall);
@@ -66,6 +81,31 @@ public sealed partial class CargoSystem
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
}
private void ShutdownShuttle()
{
_configManager.UnsubValueChanged(CCVars.CargoShuttles, SetCargoShuttleEnabled);
}
private void SetCargoShuttleEnabled(bool value)
{
if (_enabled == value) return;
_enabled = value;
if (value)
{
Setup();
foreach (var station in EntityQuery<StationCargoOrderDatabaseComponent>(true))
{
AddShuttle(station);
}
}
else
{
CleanupShuttle();
}
}
#region Cargo Pilot Console
private void OnCargoPilotConsoleOpen(EntityUid uid, CargoPilotConsoleComponent component, AfterActivatableUIOpenEvent args)
@@ -245,31 +285,30 @@ public sealed partial class CargoSystem
{
Setup();
if (CargoMap == null || component.Shuttle != null) return;
if (CargoMap == null ||
component.Shuttle != null ||
component.CargoShuttleProto == null) return;
if (component.CargoShuttleProto != null)
{
var prototype = _protoMan.Index<CargoShuttlePrototype>(component.CargoShuttleProto);
var possibleNames = _protoMan.Index<DatasetPrototype>(prototype.NameDataset).Values;
var name = _random.Pick(possibleNames);
var prototype = _protoMan.Index<CargoShuttlePrototype>(component.CargoShuttleProto);
var possibleNames = _protoMan.Index<DatasetPrototype>(prototype.NameDataset).Values;
var name = _random.Pick(possibleNames);
var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString());
var shuttleUid = _mapManager.GetGridEuid(gridId!.Value);
var xform = Transform(shuttleUid);
MetaData(shuttleUid).EntityName = name;
var (_, gridId) = _loader.LoadBlueprint(CargoMap.Value, prototype.Path.ToString());
var shuttleUid = _mapManager.GetGridEuid(gridId!.Value);
var xform = Transform(shuttleUid);
MetaData(shuttleUid).EntityName = name;
// TODO: Something better like a bounds check.
xform.LocalPosition += 100 * _index;
var comp = EnsureComp<CargoShuttleComponent>(shuttleUid);
comp.Station = component.Owner;
comp.Coordinates = xform.Coordinates;
// TODO: Something better like a bounds check.
xform.LocalPosition += 100 * _index;
var comp = EnsureComp<CargoShuttleComponent>(shuttleUid);
comp.Station = component.Owner;
comp.Coordinates = xform.Coordinates;
component.Shuttle = shuttleUid;
comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown);
UpdateShuttleCargoConsoles(comp);
_index++;
_sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}");
}
component.Shuttle = shuttleUid;
comp.NextCall = _timing.CurTime + TimeSpan.FromSeconds(comp.Cooldown);
UpdateShuttleCargoConsoles(comp);
_index++;
_sawmill.Info($"Added cargo shuttle to {ToPrettyString(shuttleUid)}");
}
private void SellPallets(CargoShuttleComponent component, StationBankAccountComponent bank)
@@ -490,10 +529,10 @@ public sealed partial class CargoSystem
private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
Cleanup();
CleanupShuttle();
}
private void Cleanup()
private void CleanupShuttle()
{
if (CargoMap == null || !_mapManager.MapExists(CargoMap.Value))
{
@@ -508,13 +547,20 @@ public sealed partial class CargoSystem
// Shuttle may not have been in the cargo dimension (e.g. on the station map) so need to delete.
foreach (var comp in EntityQuery<CargoShuttleComponent>())
{
if (TryComp<StationCargoOrderDatabaseComponent>(comp.Station, out var station))
{
station.Shuttle = null;
}
QueueDel(comp.Owner);
}
}
private void Setup()
{
if (CargoMap != null && _mapManager.MapExists(CargoMap.Value)) return;
if (!_enabled || CargoMap != null && _mapManager.MapExists(CargoMap.Value))
{
return;
}
// It gets mapinit which is okay... buuutt we still want it paused to avoid power draining.
CargoMap = _mapManager.CreateMap();