]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Rotate and Offset station CCVar nuke (#26175)
authorEd <96445749+TheShuEd@users.noreply.github.com>
Sun, 14 Apr 2024 14:26:28 +0000 (17:26 +0300)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 14:26:28 +0000 (00:26 +1000)
* no content

* add noRot to Europa

* bruh. and this

* yay

* fix

Content.Server/Station/Components/StationRandomTransformComponent.cs [new file with mode: 0644]
Content.Server/Station/Systems/StationSystem.cs
Content.Shared/CCVar/CCVars.cs
Resources/Prototypes/Entities/Stations/base.yml
Resources/Prototypes/Entities/Stations/nanotrasen.yml
Resources/Prototypes/Maps/europa.yml
Resources/Prototypes/Maps/train.yml

diff --git a/Content.Server/Station/Components/StationRandomTransformComponent.cs b/Content.Server/Station/Components/StationRandomTransformComponent.cs
new file mode 100644 (file)
index 0000000..ea0fc5f
--- /dev/null
@@ -0,0 +1,16 @@
+using Content.Server.Station.Systems;
+
+namespace Content.Server.Station.Components;
+
+/// <summary>
+/// Stores station parameters that can be randomized by the roundstart
+/// </summary>
+[RegisterComponent, Access(typeof(StationSystem))]
+public sealed partial class StationRandomTransformComponent : Component
+{
+    [DataField]
+    public float? MaxStationOffset = 100.0f;
+
+    [DataField]
+    public bool EnableStationRotation = true;
+}
index 492f15c8e2b1b31cca2f226544bd195891f14da4..408b3ebc55512f06be30446df7bab7da8161cca8 100644 (file)
@@ -1,9 +1,10 @@
 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.CCVar;
+using Content.Shared.Fax;
 using Content.Shared.Station;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
@@ -49,17 +50,12 @@ public sealed class StationSystem : EntitySystem
         _sawmill = _logManager.GetSawmill("station");
 
         SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRoundEnd);
-        SubscribeLocalEvent<PreGameMapLoad>(OnPreGameMapLoad);
         SubscribeLocalEvent<PostGameMapLoad>(OnPostGameMapLoad);
         SubscribeLocalEvent<StationDataComponent, ComponentStartup>(OnStationAdd);
         SubscribeLocalEvent<StationDataComponent, ComponentShutdown>(OnStationDeleted);
         SubscribeLocalEvent<StationMemberComponent, ComponentShutdown>(OnStationGridDeleted);
         SubscribeLocalEvent<StationMemberComponent, PostGridSplitEvent>(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;
     }
 
@@ -112,19 +108,6 @@ public sealed class StationSystem : EntitySystem
         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<string, List<EntityUid>>();
@@ -311,6 +294,8 @@ public sealed class StationSystem : EntitySystem
         // Use overrides for setup.
         var station = EntityManager.SpawnEntity(stationConfig.StationPrototype, MapCoordinates.Nullspace, stationConfig.StationComponentOverrides);
 
+
+
         if (name is not null)
             RenameStation(station, name, false);
 
@@ -319,11 +304,48 @@ public sealed class StationSystem : EntitySystem
         var data = Comp<StationDataComponent>(station);
         name ??= MetaData(station).EntityName;
 
-        foreach (var grid in gridIds ?? Array.Empty<EntityUid>())
+        var entry = gridIds ?? Array.Empty<EntityUid>();
+
+        foreach (var grid in entry)
         {
             AddGridToStation(station, grid, null, data, name);
         }
 
+        if (TryComp<StationRandomTransformComponent>(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;
+                }
+            }
+        }
+
         var ev = new StationPostInitEvent((station, data));
         RaiseLocalEvent(station, ref ev, true);
 
index aa14c565a014ef3b00fafa929418c55d0f2d2cbd..94f9e218b88805ab7510ea2de2a83f9218944d60 100644 (file)
@@ -229,25 +229,6 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<bool>
             GameCryoSleepRejoining = CVarDef.Create("game.cryo_sleep_rejoining", false, CVar.SERVER | CVar.REPLICATED);
 
-        /// <summary>
-        ///     Whether a random position offset will be applied to the station on roundstart.
-        /// </summary>
-        public static readonly CVarDef<bool> StationOffset =
-            CVarDef.Create("game.station_offset", true);
-
-        /// <summary>
-        /// When the default blueprint is loaded what is the maximum amount it can be offset from 0,0.
-        /// Does nothing without <see cref="StationOffset"/> as true.
-        /// </summary>
-        public static readonly CVarDef<float> MaxStationOffset =
-            CVarDef.Create("game.maxstationoffset", 1000.0f);
-
-        /// <summary>
-        ///     Whether a random rotation will be applied to the station on roundstart.
-        /// </summary>
-        public static readonly CVarDef<bool> StationRotation =
-            CVarDef.Create("game.station_rotation", true);
-
         /// <summary>
         ///     When enabled, guests will be assigned permanent UIDs and will have their preferences stored.
         /// </summary>
index c3fbb998b28802b6cf05619392d1d1d04bafc6f5..dcaa3d747a0de079235a68c84bb69326613fb72d 100644 (file)
@@ -4,6 +4,12 @@
   components:
     - type: StationData
 
+- type: entity
+  id: BaseRandomStation
+  abstract: true
+  components:
+    - type: StationRandomTransform
+
 - type: entity
   id: BaseStationCargo
   abstract: true
index ab885b03e53727b142a8bb59ed36c3af42748822..7e650d536f224e033f1891223e8cf71be60ae577 100644 (file)
@@ -25,6 +25,7 @@
     - BaseStationSiliconLawCrewsimov
     - BaseStationAllEventsEligible
     - BaseStationNanotrasen
+    - BaseRandomStation
   noSpawn: true
   components:
     - type: Transform
index 5b824bd3512b5e63c2fc2f139fc55a7c3b1d9ce4..33c69d64b3a905439e30e748b9396f4c6f185dc0 100644 (file)
@@ -8,6 +8,9 @@
     Europa:
       stationProto: StandardNanotrasenStation
       components:
+        - type: StationRandomTransform
+          enableStationRotation: false
+          maxStationOffset: null
         - type: StationNameSetup
           mapNameTemplate: '{0} Europa {1}'
           nameGenerator:
index 57b1ded749b2f00993a86d22d89b44dff077ca59..f500d85af93282a0e5127da2cc7572b7e6ccb9f3 100644 (file)
@@ -8,6 +8,8 @@
     Train:
       stationProto: StandardNanotrasenStation
       components:
+        - type: StationRandomTransform
+          enableStationRotation: false
         - type: StationNameSetup
           mapNameTemplate: 'Train "Sentipode" {0}-{1}'
           nameGenerator: