]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Move random species selection earlier in player spawning logic (#37258)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 8 May 2025 00:38:56 +0000 (20:38 -0400)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 00:38:56 +0000 (20:38 -0400)
* Select random species earlier in spawning logic

* ternary operator

* Move it even earlier to fix more bugs

Content.Server/GameTicking/GameTicker.Spawning.cs
Content.Server/GameTicking/GameTicker.cs
Content.Server/Station/Systems/StationSpawningSystem.cs

index 624bf35afe4257c190bd522f51cbf58f11479a22..4deacd954f968143b975fc267ec08f0543432bab 100644 (file)
@@ -8,11 +8,16 @@ using Content.Server.Ghost;
 using Content.Server.Spawners.Components;
 using Content.Server.Speech.Components;
 using Content.Server.Station.Components;
+using Content.Shared.CCVar;
 using Content.Shared.Database;
 using Content.Shared.GameTicking;
+using Content.Shared.Humanoid;
+using Content.Shared.Humanoid.Prototypes;
 using Content.Shared.Mind;
 using Content.Shared.Players;
 using Content.Shared.Preferences;
+using Content.Shared.Random;
+using Content.Shared.Random.Helpers;
 using Content.Shared.Roles;
 using Content.Shared.Roles.Jobs;
 using Robust.Shared.Map;
@@ -180,6 +185,36 @@ namespace Content.Server.GameTicking
                 return;
             }
 
+            string speciesId;
+            if (_randomizeCharacters)
+            {
+                var weightId = _cfg.GetCVar(CCVars.ICRandomSpeciesWeights);
+
+                // If blank, choose a round start species.
+                if (string.IsNullOrEmpty(weightId))
+                {
+                    var roundStart = new List<ProtoId<SpeciesPrototype>>();
+
+                    var speciesPrototypes = _prototypeManager.EnumeratePrototypes<SpeciesPrototype>();
+                    foreach (var proto in speciesPrototypes)
+                    {
+                        if (proto.RoundStart)
+                            roundStart.Add(proto.ID);
+                    }
+
+                    speciesId = roundStart.Count == 0
+                        ? SharedHumanoidAppearanceSystem.DefaultSpecies
+                        : _robustRandom.Pick(roundStart);
+                }
+                else
+                {
+                    var weights = _prototypeManager.Index<WeightedRandomSpeciesPrototype>(weightId);
+                    speciesId = weights.Pick(_robustRandom);
+                }
+
+                character = HumanoidCharacterProfile.RandomWithSpecies(speciesId);
+            }
+
             // We raise this event to allow other systems to handle spawning this player themselves. (e.g. late-join wizard, etc)
             var bev = new PlayerBeforeSpawnEvent(player, character, jobId, lateJoin, station);
             RaiseLocalEvent(bev);
index d286fd641eb876d361cddab0ac05e0eeae4ca746..fa8314cd27c58f30dc4723f57dff2bb0debca2cc 100644 (file)
@@ -9,6 +9,7 @@ using Content.Server.Players.PlayTimeTracking;
 using Content.Server.Preferences.Managers;
 using Content.Server.ServerUpdates;
 using Content.Server.Station.Systems;
+using Content.Shared.CCVar;
 using Content.Shared.Chat;
 using Content.Shared.GameTicking;
 using Content.Shared.Mind;
@@ -72,6 +73,8 @@ namespace Content.Server.GameTicking
 
         private ISawmill _sawmill = default!;
 
+        private bool _randomizeCharacters;
+
         public override void Initialize()
         {
             base.Initialize();
@@ -82,6 +85,8 @@ namespace Content.Server.GameTicking
             _sawmill = _logManager.GetSawmill("ticker");
             _sawmillReplays = _logManager.GetSawmill("ticker.replays");
 
+            Subs.CVar(_cfg, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
+
             // Initialize the other parts of the game ticker.
             InitializeStatusShell();
             InitializeCVars();
index 16400039b919851e393327381d0e4a157b8a9f48..924146bc1f9a109ab3b6e3b31f4516fb226eff18 100644 (file)
@@ -14,8 +14,6 @@ using Content.Shared.Humanoid.Prototypes;
 using Content.Shared.PDA;
 using Content.Shared.Preferences;
 using Content.Shared.Preferences.Loadouts;
-using Content.Shared.Random;
-using Content.Shared.Random.Helpers;
 using Content.Shared.Roles;
 using Content.Shared.Station;
 using JetBrains.Annotations;
@@ -23,7 +21,6 @@ using Robust.Shared.Configuration;
 using Robust.Shared.Map;
 using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Random;
 using Robust.Shared.Utility;
 
 namespace Content.Server.Station.Systems;
@@ -44,16 +41,6 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
     [Dependency] private readonly MetaDataSystem _metaSystem = default!;
     [Dependency] private readonly PdaSystem _pdaSystem = default!;
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
-    [Dependency] private readonly IRobustRandom _random = default!;
-
-    private bool _randomizeCharacters;
-
-    /// <inheritdoc/>
-    public override void Initialize()
-    {
-        base.Initialize();
-        Subs.CVar(_configurationManager, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
-    }
 
     /// <summary>
     /// Attempts to spawn a player character onto the given station.
@@ -136,53 +123,13 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
             return jobEntity;
         }
 
-        string speciesId;
-        if (_randomizeCharacters)
-        {
-            var weightId = _configurationManager.GetCVar(CCVars.ICRandomSpeciesWeights);
-
-            // If blank, choose a round start species.
-            if (string.IsNullOrEmpty(weightId))
-            {
-                var roundStart = new List<ProtoId<SpeciesPrototype>>();
-
-                var speciesPrototypes = _prototypeManager.EnumeratePrototypes<SpeciesPrototype>();
-                foreach (var proto in speciesPrototypes)
-                {
-                    if (proto.RoundStart)
-                        roundStart.Add(proto.ID);
-                }
-
-                if (roundStart.Count == 0)
-                    speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
-                else
-                    speciesId = _random.Pick(roundStart);
-            }
-            else
-            {
-                var weights = _prototypeManager.Index<WeightedRandomSpeciesPrototype>(weightId);
-                speciesId = weights.Pick(_random);
-            }
-        }
-        else if (profile != null)
-        {
-            speciesId = profile.Species;
-        }
-        else
-        {
-            speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
-        }
+        string speciesId = profile != null ? profile.Species : SharedHumanoidAppearanceSystem.DefaultSpecies;
 
         if (!_prototypeManager.TryIndex<SpeciesPrototype>(speciesId, out var species))
             throw new ArgumentException($"Invalid species prototype was used: {speciesId}");
 
         entity ??= Spawn(species.Prototype, coordinates);
 
-        if (_randomizeCharacters)
-        {
-            profile = HumanoidCharacterProfile.RandomWithSpecies(speciesId);
-        }
-
         if (profile != null)
         {
             _humanoidSystem.LoadProfile(entity.Value, profile);