Fix Nuke Target Station Map (#43583)

flukies begone

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs 2026-04-13 06:25:50 -07:00 • committed by GitHub
parent ee0f4050ef
commit a363a61007
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 78 additions and 23 deletions

View file

@ -309,7 +309,7 @@ public sealed partial class GameTicker
}
/// <summary>
/// Gets all the gamerule entities which are currently active.
/// Gets all the gamerule entities that have been added.
/// </summary>
public IEnumerable<EntityUid> GetAddedGameRules()
{
@ -321,6 +321,20 @@ public sealed partial class GameTicker
}
}
/// <summary>
/// Gets all the gamerule entities with {T} component that have been added.
/// </summary>
public IEnumerable<Entity<T>> GetAddedGameRules<T>() where T : Component
{
var query = EntityQueryEnumerator<T, GameRuleComponent>();
while (query.MoveNext(out var uid, out var comp, out var ruleData))
{
if (IsGameRuleAdded(uid, ruleData))
yield return (uid, comp);
}
}
/// <summary>
/// Gets all the gamerule entities which are currently active.
/// </summary>
@ -333,6 +347,18 @@ public sealed partial class GameTicker
}
}
/// <summary>
/// Gets all the gamerule entities with {T} component that are currently active.
/// </summary>
public IEnumerable<Entity<T>> GetActiveGameRules<T>() where T : Component
{
var query = EntityQueryEnumerator<T, ActiveGameRuleComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var comp, out _, out _))
{
yield return (uid, comp);
}
}
/// <summary>
/// Gets all gamerule prototypes
/// </summary>

View file

@ -22,9 +22,11 @@ public sealed class StationMapSystem : EntitySystem
SubscribeLocalEvent<StationMapComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
SubscribeLocalEvent<NukeopsStationMapComponent, NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
SubscribeLocalEvent<NukeopsStationMapComponent, ChooseStationMapEvent>(OnNukeOpsStationMap);
SubscribeLocalEvent<NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key,
subs =>
{
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
subs.Event<BoundUIClosedEvent>(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<NukeopsStationMapComponent>(ent))
var ev = new ChooseStationMapEvent();
RaiseLocalEvent(ent, ref ev);
if (ev.Handled)
{
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;
}
}
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<NukeopsStationMapComponent> ent, ref NukeopsTargetStationSelectedEvent args)
private void OnNukeOpsStationMap(Entity<NukeopsStationMapComponent> 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<NukeopsRuleComponent>())
{
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<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
return;
if (!TryComp<StationMapComponent>(ent, out var stationMap) || !TryComp<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
return;
var mapquery = EntityQueryEnumerator<NukeopsStationMapComponent, StationMapComponent>();
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);
}
}
}
/// <summary>
/// Selects an alternative target for our station map!
/// If handled, this will not get the map of the current station.
/// </summary>
[ByRefEvent]
public record struct ChooseStationMapEvent
{
public EntityUid? TargetGrid;
public bool Handled { get; private set; }
public void Handle()
{
Handled = true;
}
}