diff --git a/Content.Server/GameTicking/GameTicker.CVars.cs b/Content.Server/GameTicking/GameTicker.CVars.cs index f8cd9faea6..a00299df4b 100644 --- a/Content.Server/GameTicking/GameTicker.CVars.cs +++ b/Content.Server/GameTicking/GameTicker.CVars.cs @@ -21,14 +21,22 @@ namespace Content.Server.GameTicking [ViewVariables] public bool DisallowLateJoin { get; private set; } = false; + [ViewVariables] + public bool StationOffset { get; private set; } = false; + + [ViewVariables] + public float MaxStationOffset { get; private set; } = 0f; + private void InitializeCVars() { _configurationManager.OnValueChanged(CCVars.GameLobbyEnabled, value => LobbyEnabled = value, true); _configurationManager.OnValueChanged(CCVars.GameDummyTicker, value => DummyTicker = value, true); _configurationManager.OnValueChanged(CCVars.GameMap, value => ChosenMap = value, true); _configurationManager.OnValueChanged(CCVars.GameLobbyDuration, value => LobbyDuration = TimeSpan.FromSeconds(value), true); - _configurationManager.OnValueChanged(CCVars.GameDisallowLateJoins, invokeImmediately:true, - onValueChanged:value => { DisallowLateJoin = value; UpdateLateJoinStatus(); UpdateJobsAvailable(); }); + _configurationManager.OnValueChanged(CCVars.GameDisallowLateJoins, + value => { DisallowLateJoin = value; UpdateLateJoinStatus(); UpdateJobsAvailable(); }, true); + _configurationManager.OnValueChanged(CCVars.StationOffset, value => StationOffset = value, true); + _configurationManager.OnValueChanged(CCVars.MaxStationOffset, value => MaxStationOffset = value, true); } } } diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index a7e8223bb9..e65c191f1c 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -63,10 +63,13 @@ namespace Content.Server.GameTicking throw new InvalidOperationException($"No grid found for map {map}"); } - var maxStationOffset = _configurationManager.GetCVar(CCVars.MaxStationOffset); - var x = _robustRandom.NextFloat() * maxStationOffset * 2 - maxStationOffset; - var y = _robustRandom.NextFloat() * maxStationOffset * 2 - maxStationOffset; - _entityManager.GetEntity(grid.GridEntityId).Transform.LocalPosition = new Vector2(x, y); + if (StationOffset) + { + // Apply a random offset to the station grid entity. + var x = _robustRandom.NextFloat() * MaxStationOffset * 2 - MaxStationOffset; + var y = _robustRandom.NextFloat() * MaxStationOffset * 2 - MaxStationOffset; + EntityManager.GetEntity(grid.GridEntityId).Transform.LocalPosition = new Vector2(x, y); + } DefaultGridId = grid.Index; _spawnPoint = grid.ToCoordinates(); @@ -286,7 +289,7 @@ namespace Content.Server.GameTicking } // Delete all entities. - foreach (var entity in _entityManager.GetEntities().ToList()) + foreach (var entity in EntityManager.GetEntities().ToList()) { // TODO: Maybe something less naive here? // FIXME: Actually, definitely. diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index 840af56302..cab3c3c1d1 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -155,7 +155,7 @@ namespace Content.Server.GameTicking private IEntity SpawnPlayerMob(Job job, HumanoidCharacterProfile? profile, bool lateJoin = true) { var coordinates = lateJoin ? GetLateJoinSpawnPoint() : GetJobSpawnPoint(job.Prototype.ID); - var entity = _entityManager.SpawnEntity(PlayerPrototypeName, coordinates); + var entity = EntityManager.SpawnEntity(PlayerPrototypeName, coordinates); if (job.StartingGear != null) { @@ -175,7 +175,7 @@ namespace Content.Server.GameTicking private IEntity SpawnObserverMob() { var coordinates = GetObserverSpawnPoint(); - return _entityManager.SpawnEntity(ObserverPrototypeName, coordinates); + return EntityManager.SpawnEntity(ObserverPrototypeName, coordinates); } #endregion @@ -189,7 +189,7 @@ namespace Content.Server.GameTicking var equipmentStr = startingGear.GetGear(slot, profile); if (equipmentStr != string.Empty) { - var equipmentEntity = _entityManager.SpawnEntity(equipmentStr, entity.Transform.Coordinates); + var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, entity.Transform.Coordinates); inventory.Equip(slot, equipmentEntity.GetComponent()); } } @@ -200,7 +200,7 @@ namespace Content.Server.GameTicking var inhand = startingGear.Inhand; foreach (var (hand, prototype) in inhand) { - var inhandEntity = _entityManager.SpawnEntity(prototype, entity.Transform.Coordinates); + var inhandEntity = EntityManager.SpawnEntity(prototype, entity.Transform.Coordinates); handsComponent.TryPickupEntity(hand, inhandEntity, checkActionBlocker: false); } } diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index 5400e0348a..9ed3eda9da 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -72,7 +72,6 @@ namespace Content.Server.GameTicking UpdateRoundFlow(frameTime); } - [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapLoader _mapLoader = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index c4b1cd403c..450cc14727 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -55,6 +55,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef GameMap = CVarDef.Create("game.map", "Maps/saltern.yml", CVar.SERVERONLY); + /// + /// Whether a random position offset will be applied to the station on roundstart. + /// + public static readonly CVarDef StationOffset = + CVarDef.Create("game.station_offset", false); + /// /// When the default blueprint is loaded what is the maximum amount it can be offset from 0,0. ///