Move some Station methods into shared (#38976)
This commit is contained in:
@@ -3,20 +3,16 @@ using Content.Server.Chat.Systems;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Events;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Station;
|
||||
using Content.Shared.Station.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameStates;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Station.Systems;
|
||||
@@ -34,7 +30,6 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly MapSystem _map = default!;
|
||||
[Dependency] private readonly PvsOverrideSystem _pvsOverride = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
@@ -42,8 +37,8 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
private ValueList<MapId> _mapIds = new();
|
||||
private ValueList<(Box2Rotated Bounds, MapId MapId)> _gridBounds = new();
|
||||
private ValueList<MapId> _mapIds;
|
||||
private ValueList<(Box2Rotated Bounds, MapId MapId)> _gridBounds;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
@@ -79,6 +74,7 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
return;
|
||||
|
||||
stationData.Grids.Remove(uid);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -193,44 +189,6 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
|
||||
#endregion Event handlers
|
||||
|
||||
/// <summary>
|
||||
/// Gets the largest member grid from a station.
|
||||
/// </summary>
|
||||
public EntityUid? GetLargestGrid(StationDataComponent component)
|
||||
{
|
||||
EntityUid? largestGrid = null;
|
||||
Box2 largestBounds = new Box2();
|
||||
|
||||
foreach (var gridUid in component.Grids)
|
||||
{
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var grid) ||
|
||||
grid.LocalAABB.Size.LengthSquared() < largestBounds.Size.LengthSquared())
|
||||
continue;
|
||||
|
||||
largestBounds = grid.LocalAABB;
|
||||
largestGrid = gridUid;
|
||||
}
|
||||
|
||||
return largestGrid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total number of tiles contained in the station's grids.
|
||||
/// </summary>
|
||||
public int GetTileCount(StationDataComponent component)
|
||||
{
|
||||
var count = 0;
|
||||
foreach (var gridUid in component.Grids)
|
||||
{
|
||||
if (!TryComp<MapGridComponent>(gridUid, out var grid))
|
||||
continue;
|
||||
|
||||
count += _map.GetAllTiles(gridUid, grid).Count();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to retrieve a filter for everything in the station the source is on.
|
||||
/// </summary>
|
||||
@@ -384,6 +342,7 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
var stationMember = EnsureComp<StationMemberComponent>(mapGrid);
|
||||
stationMember.Station = station;
|
||||
stationData.Grids.Add(mapGrid);
|
||||
Dirty(station, stationData);
|
||||
|
||||
RaiseLocalEvent(station, new StationGridAddedEvent(mapGrid, station, false), true);
|
||||
|
||||
@@ -407,6 +366,7 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
|
||||
RemComp<StationMemberComponent>(mapGrid);
|
||||
stationData.Grids.Remove(mapGrid);
|
||||
Dirty(station, stationData);
|
||||
|
||||
RaiseLocalEvent(station, new StationGridRemovedEvent(mapGrid, station), true);
|
||||
_sawmill.Info($"Removing grid {mapGrid} from station {Name(station)} ({station})");
|
||||
@@ -450,110 +410,6 @@ public sealed partial class StationSystem : SharedStationSystem
|
||||
|
||||
QueueDel(station);
|
||||
}
|
||||
|
||||
public EntityUid? GetOwningStation(EntityUid? entity, TransformComponent? xform = null)
|
||||
{
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
return GetOwningStation(entity.Value, xform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the station that "owns" the given entity (essentially, the station the grid it's on is attached to)
|
||||
/// </summary>
|
||||
/// <param name="entity">Entity to find the owner of.</param>
|
||||
/// <param name="xform">Resolve pattern, transform of the entity.</param>
|
||||
/// <returns>The owning station, if any.</returns>
|
||||
/// <remarks>
|
||||
/// This does not remember what station an entity started on, it simply checks where it is currently located.
|
||||
/// </remarks>
|
||||
public EntityUid? GetOwningStation(EntityUid entity, TransformComponent? xform = null)
|
||||
{
|
||||
if (!Resolve(entity, ref xform))
|
||||
throw new ArgumentException("Tried to use an abstract entity!", nameof(entity));
|
||||
|
||||
if (TryComp<StationDataComponent>(entity, out _))
|
||||
{
|
||||
// We are the station, just return ourselves.
|
||||
return entity;
|
||||
}
|
||||
|
||||
if (TryComp<MapGridComponent>(entity, out _))
|
||||
{
|
||||
// We are the station, just check ourselves.
|
||||
return CompOrNull<StationMemberComponent>(entity)?.Station;
|
||||
}
|
||||
|
||||
if (xform.GridUid == EntityUid.Invalid)
|
||||
{
|
||||
Log.Debug("Unable to get owning station - GridUid invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return CompOrNull<StationMemberComponent>(xform.GridUid)?.Station;
|
||||
}
|
||||
|
||||
public List<EntityUid> GetStations()
|
||||
{
|
||||
var stations = new List<EntityUid>();
|
||||
var query = EntityQueryEnumerator<StationDataComponent>();
|
||||
while (query.MoveNext(out var uid, out _))
|
||||
{
|
||||
stations.Add(uid);
|
||||
}
|
||||
|
||||
return stations;
|
||||
}
|
||||
|
||||
public HashSet<EntityUid> GetStationsSet()
|
||||
{
|
||||
var stations = new HashSet<EntityUid>();
|
||||
var query = EntityQueryEnumerator<StationDataComponent>();
|
||||
while (query.MoveNext(out var uid, out _))
|
||||
{
|
||||
stations.Add(uid);
|
||||
}
|
||||
|
||||
return stations;
|
||||
}
|
||||
|
||||
public List<(string Name, NetEntity Entity)> GetStationNames()
|
||||
{
|
||||
var stations = GetStationsSet();
|
||||
var stats = new List<(string Name, NetEntity Station)>();
|
||||
|
||||
foreach (var weh in stations)
|
||||
{
|
||||
stats.Add((MetaData(weh).EntityName, GetNetEntity(weh)));
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first station that has a grid in a certain map.
|
||||
/// If the map has no stations, null is returned instead.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If there are multiple stations on a map it is probably arbitrary which one is returned.
|
||||
/// </remarks>
|
||||
public EntityUid? GetStationInMap(MapId map)
|
||||
{
|
||||
var query = EntityQueryEnumerator<StationDataComponent>();
|
||||
while (query.MoveNext(out var uid, out var data))
|
||||
{
|
||||
foreach (var gridUid in data.Grids)
|
||||
{
|
||||
if (Transform(gridUid).MapID == map)
|
||||
{
|
||||
return uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user