Files
space-station-14/Content.Server/Pinpointer/StationMapSystem.cs
SlamBamActionman 435b7d5cf8 Add the ability for station maps to track grids they are not on (#41248)
* Initial commit

* Accidentally included the nukie map changes

* Fix the gridcheck

* Addressing review

* Review change

* Review comments
2026-01-12 02:47:47 +00:00

98 lines
3.5 KiB
C#

using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.PowerCell;
using Content.Shared.Pinpointer;
using Content.Shared.Station;
using Robust.Server.GameObjects;
namespace Content.Server.Pinpointer;
public sealed class StationMapSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly PowerCellSystem _cell = default!;
[Dependency] private readonly SharedStationSystem _station = default!;
[Dependency] private readonly SharedTransformSystem _xform = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StationMapComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
SubscribeLocalEvent<NukeopsStationMapComponent, NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
{
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
});
}
private void OnMapInit(Entity<StationMapComponent> ent, ref MapInitEvent args)
{
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<NukeopsStationMapComponent>(ent))
{
foreach (var rule in _gameTicker.GetActiveGameRules())
{
if (TryComp<NukeopsRuleComponent>(rule, out var nukeopsRule) && nukeopsRule.TargetStation != null)
{
ent.Comp.TargetGrid = _station.GetLargestGrid((nukeopsRule.TargetStation.Value, null));
Dirty(ent);
return;
}
}
}
var station = _station.GetStationInMap(_xform.GetMapId(ent.Owner));
if (station != null)
{
ent.Comp.TargetGrid = _station.GetLargestGrid((station.Value, null));
Dirty(ent);
}
}
private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args)
{
if (!Equals(args.UiKey, StationMapUiKey.Key))
return;
RemCompDeferred<StationMapUserComponent>(args.Actor);
}
private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
{
_ui.CloseUi(component.Map, StationMapUiKey.Key, uid);
}
private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
{
if (!_cell.TryUseActivatableCharge(uid))
return;
var comp = EnsureComp<StationMapUserComponent>(args.Actor);
comp.Map = uid;
}
private void OnNukeopsStationSelected(Entity<NukeopsStationMapComponent> ent, ref NukeopsTargetStationSelectedEvent args)
{
if (args.TargetStation == null)
return;
if (!TryComp<StationMapComponent>(ent, out var stationMap) || !TryComp<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
return;
if (Transform(ent).MapID != ruleGrids.Map)
return;
stationMap.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null));
Dirty(ent);
}
}