diff --git a/Content.Server/GameTicking/GameTicker.GameRule.cs b/Content.Server/GameTicking/GameTicker.GameRule.cs index c1d8e3b31e..cf1d6eb1a8 100644 --- a/Content.Server/GameTicking/GameTicker.GameRule.cs +++ b/Content.Server/GameTicking/GameTicker.GameRule.cs @@ -309,7 +309,7 @@ public sealed partial class GameTicker } /// - /// Gets all the gamerule entities which are currently active. + /// Gets all the gamerule entities that have been added. /// public IEnumerable GetAddedGameRules() { @@ -321,6 +321,20 @@ public sealed partial class GameTicker } } + /// + /// Gets all the gamerule entities with {T} component that have been added. + /// + public IEnumerable> GetAddedGameRules() where T : Component + { + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp, out var ruleData)) + { + if (IsGameRuleAdded(uid, ruleData)) + yield return (uid, comp); + } + } + + /// /// Gets all the gamerule entities which are currently active. /// @@ -333,6 +347,18 @@ public sealed partial class GameTicker } } + /// + /// Gets all the gamerule entities with {T} component that are currently active. + /// + public IEnumerable> GetActiveGameRules() where T : Component + { + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp, out _, out _)) + { + yield return (uid, comp); + } + } + /// /// Gets all gamerule prototypes /// diff --git a/Content.Server/Pinpointer/StationMapSystem.cs b/Content.Server/Pinpointer/StationMapSystem.cs index bf2d2e2817..1e5fa74b7c 100644 --- a/Content.Server/Pinpointer/StationMapSystem.cs +++ b/Content.Server/Pinpointer/StationMapSystem.cs @@ -22,9 +22,11 @@ public sealed class StationMapSystem : EntitySystem SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnUserParentChanged); - SubscribeLocalEvent(OnNukeopsStationSelected); + SubscribeLocalEvent(OnNukeOpsStationMap); + SubscribeLocalEvent(OnNukeopsStationSelected); - Subs.BuiEvents(StationMapUiKey.Key, subs => + Subs.BuiEvents(StationMapUiKey.Key, + subs => { subs.Event(OnStationMapOpened); subs.Event(OnStationMapClosed); @@ -36,18 +38,13 @@ public sealed class StationMapSystem : EntitySystem if (!ent.Comp.InitializeWithStation) return; - // If we ever find a need to make more exceptions like this, just turn this into an event. - if (HasComp(ent)) + var ev = new ChooseStationMapEvent(); + RaiseLocalEvent(ent, ref ev); + if (ev.Handled) { - foreach (var rule in _gameTicker.GetActiveGameRules()) - { - if (TryComp(rule, out var nukeopsRule) && nukeopsRule.TargetStation != null) - { - ent.Comp.TargetGrid = _station.GetLargestGrid((nukeopsRule.TargetStation.Value, null)); - Dirty(ent); - return; - } - } + ent.Comp.TargetGrid = ev.TargetGrid; + Dirty(ent); + return; } var station = _station.GetStationInMap(_xform.GetMapId(ent.Owner)); @@ -80,18 +77,50 @@ public sealed class StationMapSystem : EntitySystem comp.Map = uid; } - private void OnNukeopsStationSelected(Entity ent, ref NukeopsTargetStationSelectedEvent args) + private void OnNukeOpsStationMap(Entity entity, ref ChooseStationMapEvent args) { - if (args.TargetStation == null) + // If we have this component, we don't want a fallback map! + args.Handle(); + + foreach (var rule in _gameTicker.GetActiveGameRules()) + { + if (rule.Comp.TargetStation == null) + continue; + + args.TargetGrid = _station.GetLargestGrid((rule.Comp.TargetStation.Value, null)); + return; + } + } + + private void OnNukeopsStationSelected(ref NukeopsTargetStationSelectedEvent args) + { + if (args.TargetStation == null || !TryComp(args.RuleEntity, out var ruleGrids)) return; - if (!TryComp(ent, out var stationMap) || !TryComp(args.RuleEntity, out var ruleGrids)) - return; + var mapquery = EntityQueryEnumerator(); + while (mapquery.MoveNext(out var uid, out _, out var map)) + { + if (Transform(uid).MapID != ruleGrids.Map) + continue; - if (Transform(ent).MapID != ruleGrids.Map) - return; - - stationMap.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null)); - Dirty(ent); + map.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null)); + Dirty(uid, map); + } + } +} + +/// +/// Selects an alternative target for our station map! +/// If handled, this will not get the map of the current station. +/// +[ByRefEvent] +public record struct ChooseStationMapEvent +{ + public EntityUid? TargetGrid; + public bool Handled { get; private set; } + + public void Handle() + { + Handled = true; } }