From 850e1aa9896c6d6582f1b7e9e41db7cb948857f2 Mon Sep 17 00:00:00 2001 From: metalgearsloth Date: Tue, 18 Jun 2024 14:45:47 +1000 Subject: [PATCH] Revert "Rotate and Offset station CCVar nuke (#26175)" This reverts commit 44b20f60ff178813ebbc5b449229b0bbba81f649. # Conflicts: # Content.Server/Station/Systems/StationSystem.cs # Resources/Prototypes/Maps/europa.yml --- .../StationRandomTransformComponent.cs | 16 ----- .../Station/Systems/StationSystem.cs | 63 ++++++------------- Content.Shared/CCVar/CCVars.cs | 19 ++++++ .../Prototypes/Entities/Stations/base.yml | 6 -- .../Entities/Stations/nanotrasen.yml | 1 - Resources/Prototypes/Maps/europa.yml | 3 - Resources/Prototypes/Maps/train.yml | 2 - 7 files changed, 39 insertions(+), 71 deletions(-) delete mode 100644 Content.Server/Station/Components/StationRandomTransformComponent.cs diff --git a/Content.Server/Station/Components/StationRandomTransformComponent.cs b/Content.Server/Station/Components/StationRandomTransformComponent.cs deleted file mode 100644 index ea0fc5f2696b..000000000000 --- a/Content.Server/Station/Components/StationRandomTransformComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Content.Server.Station.Systems; - -namespace Content.Server.Station.Components; - -/// -/// Stores station parameters that can be randomized by the roundstart -/// -[RegisterComponent, Access(typeof(StationSystem))] -public sealed partial class StationRandomTransformComponent : Component -{ - [DataField] - public float? MaxStationOffset = 100.0f; - - [DataField] - public bool EnableStationRotation = true; -} diff --git a/Content.Server/Station/Systems/StationSystem.cs b/Content.Server/Station/Systems/StationSystem.cs index 88e419ae39af..699a2de52d0d 100644 --- a/Content.Server/Station/Systems/StationSystem.cs +++ b/Content.Server/Station/Systems/StationSystem.cs @@ -1,10 +1,9 @@ using System.Linq; -using System.Numerics; using Content.Server.Chat.Systems; using Content.Server.GameTicking; using Content.Server.Station.Components; using Content.Server.Station.Events; -using Content.Shared.Fax; +using Content.Shared.CCVar; using Content.Shared.Station; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -44,12 +43,17 @@ public override void Initialize() _sawmill = _logManager.GetSawmill("station"); SubscribeLocalEvent(OnRoundEnd); + SubscribeLocalEvent(OnPreGameMapLoad); SubscribeLocalEvent(OnPostGameMapLoad); SubscribeLocalEvent(OnStationAdd); SubscribeLocalEvent(OnStationDeleted); SubscribeLocalEvent(OnStationGridDeleted); SubscribeLocalEvent(OnStationSplitEvent); + Subs.CVar(_configurationManager, CCVars.StationOffset, x => _randomStationOffset = x, true); + Subs.CVar(_configurationManager, CCVars.MaxStationOffset, x => _maxRandomStationOffset = x, true); + Subs.CVar(_configurationManager, CCVars.StationRotation, x => _randomStationRotation = x, true); + _player.PlayerStatusChanged += OnPlayerStatusChanged; } @@ -102,6 +106,19 @@ private void OnStationDeleted(EntityUid uid, StationDataComponent component, Com RaiseNetworkEvent(new StationsUpdatedEvent(GetStationNames()), Filter.Broadcast()); } + private void OnPreGameMapLoad(PreGameMapLoad ev) + { + // this is only for maps loaded during round setup! + if (_gameTicker.RunLevel == GameRunLevel.InRound) + return; + + if (_randomStationOffset) + ev.Options.Offset += _random.NextVector2(_maxRandomStationOffset); + + if (_randomStationRotation) + ev.Options.Rotation = _random.NextAngle(); + } + private void OnPostGameMapLoad(PostGameMapLoad ev) { var dict = new Dictionary>(); @@ -282,51 +299,11 @@ public EntityUid InitializeNewStation(StationConfig stationConfig, IEnumerable(station); name ??= MetaData(station).EntityName; - var entry = gridIds ?? Array.Empty(); - - foreach (var grid in entry) + foreach (var grid in gridIds ?? Array.Empty()) { AddGridToStation(station, grid, null, data, name); } - if (TryComp(station, out var random)) - { - Angle? rotation = null; - Vector2? offset = null; - - if (random.MaxStationOffset != null) - offset = _random.NextVector2(-random.MaxStationOffset.Value, random.MaxStationOffset.Value); - - if (random.EnableStationRotation) - rotation = _random.NextAngle(); - - foreach (var grid in entry) - { - //planetary maps give an error when trying to change from position or rotation. - //This is still the case, but it will be irrelevant after the https://github.com/space-wizards/space-station-14/pull/26510 - if (rotation != null && offset != null) - { - var pos = _transform.GetWorldPosition(grid); - _transform.SetWorldPositionRotation(grid, pos + offset.Value, rotation.Value); - continue; - } - if (rotation != null) - { - _transform.SetWorldRotation(grid, rotation.Value); - continue; - } - if (offset != null) - { - var pos = _transform.GetWorldPosition(grid); - _transform.SetWorldPosition(grid, pos + offset.Value); - continue; - } - } - } - - if (LifeStage(station) < EntityLifeStage.MapInitialized) - throw new Exception($"Station must be man-initialized"); - var ev = new StationPostInitEvent((station, data)); RaiseLocalEvent(station, ref ev, true); diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 7cc1b341a975..0efc78d4274e 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -256,6 +256,25 @@ public static readonly CVarDef public static readonly CVarDef GameCryoSleepRejoining = CVarDef.Create("game.cryo_sleep_rejoining", false, CVar.SERVER | CVar.REPLICATED); + /// + /// Whether a random position offset will be applied to the station on roundstart. + /// + public static readonly CVarDef StationOffset = + CVarDef.Create("game.station_offset", true); + + /// + /// When the default blueprint is loaded what is the maximum amount it can be offset from 0,0. + /// Does nothing without as true. + /// + public static readonly CVarDef MaxStationOffset = + CVarDef.Create("game.maxstationoffset", 1000.0f); + + /// + /// Whether a random rotation will be applied to the station on roundstart. + /// + public static readonly CVarDef StationRotation = + CVarDef.Create("game.station_rotation", true); + /// /// When enabled, guests will be assigned permanent UIDs and will have their preferences stored. /// diff --git a/Resources/Prototypes/Entities/Stations/base.yml b/Resources/Prototypes/Entities/Stations/base.yml index 6a1abdfbe3dc..8a0d6c400304 100644 --- a/Resources/Prototypes/Entities/Stations/base.yml +++ b/Resources/Prototypes/Entities/Stations/base.yml @@ -4,12 +4,6 @@ components: - type: StationData -- type: entity - id: BaseRandomStation - abstract: true - components: - - type: StationRandomTransform - - type: entity id: BaseStationCargo abstract: true diff --git a/Resources/Prototypes/Entities/Stations/nanotrasen.yml b/Resources/Prototypes/Entities/Stations/nanotrasen.yml index 7e650d536f22..ab885b03e537 100644 --- a/Resources/Prototypes/Entities/Stations/nanotrasen.yml +++ b/Resources/Prototypes/Entities/Stations/nanotrasen.yml @@ -25,7 +25,6 @@ - BaseStationSiliconLawCrewsimov - BaseStationAllEventsEligible - BaseStationNanotrasen - - BaseRandomStation noSpawn: true components: - type: Transform diff --git a/Resources/Prototypes/Maps/europa.yml b/Resources/Prototypes/Maps/europa.yml index 412e1b46569f..0aa6e148822d 100644 --- a/Resources/Prototypes/Maps/europa.yml +++ b/Resources/Prototypes/Maps/europa.yml @@ -10,9 +10,6 @@ components: - type: StationBiome biome: Snow - - type: StationRandomTransform - enableStationRotation: false - maxStationOffset: null - type: StationNameSetup mapNameTemplate: '{0} Europa {1}' nameGenerator: diff --git a/Resources/Prototypes/Maps/train.yml b/Resources/Prototypes/Maps/train.yml index 7f24fcdd6771..3435c9730b54 100644 --- a/Resources/Prototypes/Maps/train.yml +++ b/Resources/Prototypes/Maps/train.yml @@ -8,8 +8,6 @@ Train: stationProto: StandardNanotrasenStation components: - - type: StationRandomTransform - enableStationRotation: false - type: StationNameSetup mapNameTemplate: 'Train "Sentipode" {0}-{1}' nameGenerator: