mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
136 lines
4.7 KiB
C#
136 lines
4.7 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Shared.Station.Components;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Collections;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
|
|
namespace Content.Shared.Station.Systems;
|
|
|
|
public abstract partial class StationSystem
|
|
{
|
|
/// <summary>
|
|
/// Utility function for finding a random event-eligible station entity
|
|
/// TODO: Make calls of this use the below method with T = StationEventEligibleComponent and make this a lookup for NO T versions of stations!!!
|
|
/// </summary>
|
|
[PublicAPI]
|
|
[Obsolete($"Use TryGetRandomStation<T> instead using {nameof(StationEventEligibleComponent)}!")]
|
|
public bool TryGetRandomStation([NotNullWhen(true)] out Entity<StationDataComponent>? station, Func<EntityUid, bool>? filter = null)
|
|
{
|
|
var stations = new ValueList<Entity<StationDataComponent>>(Count<StationEventEligibleComponent>());
|
|
|
|
filter ??= _ => true;
|
|
var query = AllEntityQuery<StationEventEligibleComponent, StationDataComponent>();
|
|
|
|
while (query.MoveNext(out var uid, out _, out var data))
|
|
{
|
|
if (!filter(uid))
|
|
continue;
|
|
|
|
stations.Add((uid, data));
|
|
}
|
|
|
|
if (stations.Count == 0)
|
|
{
|
|
station = null;
|
|
return false;
|
|
}
|
|
|
|
// TODO: Engine PR.
|
|
station = stations[Random.Next(stations.Count)];
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to get a random station with a given component.
|
|
/// </summary>
|
|
/// <param name="station">Station we are returning.</param>
|
|
/// <param name="filter">Optional filter.</param>
|
|
/// <typeparam name="T">Component we are querying for.</typeparam>
|
|
/// <returns>Station Entity if it exists</returns>
|
|
[PublicAPI]
|
|
public bool TryGetRandomStation<T>([NotNullWhen(true)] out Entity<StationDataComponent, T>? station, Func<EntityUid, bool>? filter = null) where T : IComponent
|
|
{
|
|
var stations = new ValueList<Entity<StationDataComponent, T>>(Count<T>());
|
|
|
|
filter ??= _ => true;
|
|
var query = AllEntityQuery<T, StationDataComponent>();
|
|
|
|
while (query.MoveNext(out var uid, out var comp, out var data))
|
|
{
|
|
if (!filter(uid))
|
|
continue;
|
|
|
|
stations.Add((uid, data, comp));
|
|
}
|
|
|
|
if (stations.Count == 0)
|
|
{
|
|
station = null;
|
|
return false;
|
|
}
|
|
|
|
// TODO: Engine PR.
|
|
station = stations[Random.Next(stations.Count)];
|
|
return true;
|
|
}
|
|
|
|
[PublicAPI]
|
|
public bool TryFindRandomTile(out Vector2i tile,
|
|
[NotNullWhen(true)] out Entity<StationDataComponent>? targetStation,
|
|
[NotNullWhen(true)] out Entity<MapGridComponent>? targetGrid,
|
|
out EntityCoordinates targetCoords)
|
|
{
|
|
tile = default;
|
|
targetStation = null;
|
|
targetGrid = null;
|
|
targetCoords = EntityCoordinates.Invalid;
|
|
if (TryGetRandomStation(out targetStation))
|
|
{
|
|
return TryFindRandomTileOnStation(targetStation.Value,
|
|
out tile,
|
|
out targetGrid,
|
|
out targetCoords);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a random tile on a random station with the given T component.
|
|
/// </summary>
|
|
/// <param name="tile">Tile returned.</param>
|
|
/// <param name="targetStation">Station returned</param>
|
|
/// <param name="targetGrid">Station grid with the tile.</param>
|
|
/// <param name="targetCoords">Coordinates of the tile.</param>
|
|
/// <typeparam name="T">Component we query for the station!</typeparam>
|
|
/// <returns>True if all of the above were found</returns>
|
|
[PublicAPI]
|
|
public bool TryFindRandomTile<T>(out Vector2i tile,
|
|
[NotNullWhen(true)] out Entity<StationDataComponent, T>? targetStation,
|
|
[NotNullWhen(true)] out Entity<MapGridComponent>? targetGrid,
|
|
out EntityCoordinates targetCoords) where T : IComponent
|
|
{
|
|
tile = default;
|
|
targetStation = null;
|
|
targetGrid = null;
|
|
targetCoords = EntityCoordinates.Invalid;
|
|
return TryGetRandomStation(out targetStation) && TryFindRandomTileOnStation(targetStation.Value,
|
|
out tile,
|
|
out targetGrid,
|
|
out targetCoords);
|
|
}
|
|
|
|
[PublicAPI]
|
|
public virtual bool TryFindRandomTileOnStation(Entity<StationDataComponent> station,
|
|
out Vector2i tile,
|
|
[NotNullWhen(true)] out Entity<MapGridComponent>? targetGrid,
|
|
out EntityCoordinates targetCoords,
|
|
int numAttempts = 10)
|
|
{
|
|
tile = default;
|
|
targetCoords = EntityCoordinates.Invalid;
|
|
targetGrid = null;
|
|
return false;
|
|
}
|
|
}
|