mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-02-15 03:32:07 +01:00
Remove atmos method events (#26402)
* Remove HasAtmosphereMethodEvent * Remove GetTileMixturesMethodEvent * Remove GetTileMixtureMethodEvent * Remove GetAdjacentTilesMethodEvent * Add TileMixtureEnumerator * Remove GetAdjacentTileMixturesMethodEvent * Remove IsTileSpaceMethodEvent * Remove HotspotExposeMethodEvent * Remove pipe net method events * Remove device method events * Use Entity<T> * Misc fixes * A * Theres probably a few more of these * Fix other resolve errors
This commit is contained in:
@@ -4,7 +4,6 @@ using Content.Server.Atmos.Piping.Components;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -49,13 +48,7 @@ public partial class AtmosphereSystem
|
||||
return GetTileMixture(gridUid, mapUid, position, excite);
|
||||
}
|
||||
|
||||
public bool HasAtmosphere(EntityUid gridUid)
|
||||
{
|
||||
var ev = new HasAtmosphereMethodEvent(gridUid);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
|
||||
return ev.Result;
|
||||
}
|
||||
public bool HasAtmosphere(EntityUid gridUid) => _atmosQuery.HasComponent(gridUid);
|
||||
|
||||
public bool SetSimulatedGrid(EntityUid gridUid, bool simulated)
|
||||
{
|
||||
@@ -91,43 +84,60 @@ public partial class AtmosphereSystem
|
||||
entity.Comp.InvalidatedCoords.Add(tile);
|
||||
}
|
||||
|
||||
public GasMixture?[]? GetTileMixtures(EntityUid? gridUid, EntityUid? mapUid, List<Vector2i> tiles, bool excite = false)
|
||||
public GasMixture?[]? GetTileMixtures(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?>? map, List<Vector2i> tiles, bool excite = false)
|
||||
{
|
||||
var ev = new GetTileMixturesMethodEvent(gridUid, mapUid, tiles, excite);
|
||||
GasMixture?[]? mixtures = null;
|
||||
var handled = false;
|
||||
|
||||
// If we've been passed a grid, try to let it handle it.
|
||||
if (gridUid.HasValue)
|
||||
if (grid is {} gridEnt && Resolve(gridEnt, ref gridEnt.Comp))
|
||||
{
|
||||
DebugTools.Assert(_mapManager.IsGrid(gridUid.Value));
|
||||
RaiseLocalEvent(gridUid.Value, ref ev, false);
|
||||
handled = true;
|
||||
mixtures = new GasMixture?[tiles.Count];
|
||||
|
||||
for (var i = 0; i < tiles.Count; i++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
if (!gridEnt.Comp.Tiles.TryGetValue(tile, out var atmosTile))
|
||||
{
|
||||
// need to get map atmosphere
|
||||
handled = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
mixtures[i] = atmosTile.Air;
|
||||
|
||||
if (excite)
|
||||
gridEnt.Comp.InvalidatedCoords.Add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
if (ev.Handled)
|
||||
return ev.Mixtures;
|
||||
if (handled)
|
||||
return mixtures;
|
||||
|
||||
// We either don't have a grid, or the event wasn't handled.
|
||||
// Let the map handle it instead, and also broadcast the event.
|
||||
if (mapUid.HasValue)
|
||||
if (map is {} mapEnt && _mapAtmosQuery.Resolve(mapEnt, ref mapEnt.Comp))
|
||||
{
|
||||
DebugTools.Assert(_mapManager.IsMap(mapUid.Value));
|
||||
RaiseLocalEvent(mapUid.Value, ref ev, true);
|
||||
}
|
||||
else
|
||||
RaiseLocalEvent(ref ev);
|
||||
mixtures ??= new GasMixture?[tiles.Count];
|
||||
for (var i = 0; i < tiles.Count; i++)
|
||||
{
|
||||
mixtures[i] ??= mapEnt.Comp.Mixture;
|
||||
}
|
||||
|
||||
if (ev.Handled)
|
||||
return ev.Mixtures;
|
||||
return mixtures;
|
||||
}
|
||||
|
||||
// Default to a space mixture... This is a space game, after all!
|
||||
ev.Mixtures ??= new GasMixture?[tiles.Count];
|
||||
mixtures ??= new GasMixture?[tiles.Count];
|
||||
for (var i = 0; i < tiles.Count; i++)
|
||||
{
|
||||
ev.Mixtures[i] ??= GasMixture.SpaceGas;
|
||||
mixtures[i] ??= GasMixture.SpaceGas;
|
||||
}
|
||||
return ev.Mixtures;
|
||||
return mixtures;
|
||||
}
|
||||
|
||||
public GasMixture? GetTileMixture (Entity<TransformComponent?> entity, MapGridComponent? grid = null, bool excite = false)
|
||||
public GasMixture? GetTileMixture (Entity<TransformComponent?> entity, bool excite = false)
|
||||
{
|
||||
if (!Resolve(entity.Owner, ref entity.Comp))
|
||||
return null;
|
||||
@@ -136,32 +146,24 @@ public partial class AtmosphereSystem
|
||||
return GetTileMixture(entity.Comp.GridUid, entity.Comp.MapUid, indices, excite);
|
||||
}
|
||||
|
||||
public GasMixture? GetTileMixture(EntityUid? gridUid, EntityUid? mapUid, Vector2i gridTile, bool excite = false)
|
||||
public GasMixture? GetTileMixture(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?>? map, Vector2i gridTile, bool excite = false)
|
||||
{
|
||||
var ev = new GetTileMixtureMethodEvent(gridUid, mapUid, gridTile, excite);
|
||||
|
||||
// If we've been passed a grid, try to let it handle it.
|
||||
if(gridUid.HasValue)
|
||||
if (grid is {} gridEnt
|
||||
&& Resolve(gridEnt, ref gridEnt.Comp, false)
|
||||
&& gridEnt.Comp.Tiles.TryGetValue(gridTile, out var tile))
|
||||
{
|
||||
DebugTools.Assert(_mapManager.IsGrid(gridUid.Value));
|
||||
RaiseLocalEvent(gridUid.Value, ref ev, false);
|
||||
if (excite)
|
||||
gridEnt.Comp.InvalidatedCoords.Add(gridTile);
|
||||
|
||||
return tile.Air;
|
||||
}
|
||||
|
||||
if (ev.Handled)
|
||||
return ev.Mixture;
|
||||
|
||||
// We either don't have a grid, or the event wasn't handled.
|
||||
// Let the map handle it instead, and also broadcast the event.
|
||||
if(mapUid.HasValue)
|
||||
{
|
||||
DebugTools.Assert(_mapManager.IsMap(mapUid.Value));
|
||||
RaiseLocalEvent(mapUid.Value, ref ev, true);
|
||||
}
|
||||
else
|
||||
RaiseLocalEvent(ref ev);
|
||||
if (map is {} mapEnt && _mapAtmosQuery.Resolve(mapEnt, ref mapEnt.Comp, false))
|
||||
return mapEnt.Comp.Mixture;
|
||||
|
||||
// Default to a space mixture... This is a space game, after all!
|
||||
return ev.Mixture ?? GasMixture.SpaceGas;
|
||||
return GasMixture.SpaceGas;
|
||||
}
|
||||
|
||||
public ReactionResult ReactTile(EntityUid gridId, Vector2i tile)
|
||||
@@ -176,66 +178,67 @@ public partial class AtmosphereSystem
|
||||
|
||||
public bool IsTileAirBlocked(EntityUid gridUid, Vector2i tile, AtmosDirection directions = AtmosDirection.All, MapGridComponent? mapGridComp = null)
|
||||
{
|
||||
if (!Resolve(gridUid, ref mapGridComp))
|
||||
if (!Resolve(gridUid, ref mapGridComp, false))
|
||||
return false;
|
||||
|
||||
var data = GetAirtightData(gridUid, mapGridComp, tile);
|
||||
return data.BlockedDirections.IsFlagSet(directions);
|
||||
}
|
||||
|
||||
public bool IsTileSpace(EntityUid? gridUid, EntityUid? mapUid, Vector2i tile, MapGridComponent? mapGridComp = null)
|
||||
public bool IsTileSpace(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?>? map, Vector2i tile)
|
||||
{
|
||||
var ev = new IsTileSpaceMethodEvent(gridUid, mapUid, tile, mapGridComp);
|
||||
if (grid is {} gridEnt && _atmosQuery.Resolve(gridEnt, ref gridEnt.Comp, false)
|
||||
&& gridEnt.Comp.Tiles.TryGetValue(tile, out var tileAtmos))
|
||||
{
|
||||
return tileAtmos.Space;
|
||||
}
|
||||
|
||||
// Try to let the grid (if any) handle it...
|
||||
if (gridUid.HasValue)
|
||||
RaiseLocalEvent(gridUid.Value, ref ev, false);
|
||||
|
||||
// If we didn't have a grid or the event wasn't handled
|
||||
// we let the map know, and also broadcast the event while at it!
|
||||
if (mapUid.HasValue && !ev.Handled)
|
||||
RaiseLocalEvent(mapUid.Value, ref ev, true);
|
||||
|
||||
// We didn't have a map, and the event isn't handled, therefore broadcast the event.
|
||||
else if (!mapUid.HasValue && !ev.Handled)
|
||||
RaiseLocalEvent(ref ev);
|
||||
if (map is {} mapEnt && _mapAtmosQuery.Resolve(mapEnt, ref mapEnt.Comp, false))
|
||||
return mapEnt.Comp.Space;
|
||||
|
||||
// If nothing handled the event, it'll default to true.
|
||||
// Oh well, this is a space game after all, deal with it!
|
||||
return ev.Result;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsTileMixtureProbablySafe(EntityUid? gridUid, EntityUid mapUid, Vector2i tile)
|
||||
public bool IsTileMixtureProbablySafe(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?> map, Vector2i tile)
|
||||
{
|
||||
return IsMixtureProbablySafe(GetTileMixture(gridUid, mapUid, tile));
|
||||
return IsMixtureProbablySafe(GetTileMixture(grid, map, tile));
|
||||
}
|
||||
|
||||
public float GetTileHeatCapacity(EntityUid? gridUid, EntityUid mapUid, Vector2i tile)
|
||||
public float GetTileHeatCapacity(Entity<GridAtmosphereComponent?>? grid, Entity<MapAtmosphereComponent?> map, Vector2i tile)
|
||||
{
|
||||
return GetHeatCapacity(GetTileMixture(gridUid, mapUid, tile) ?? GasMixture.SpaceGas);
|
||||
return GetHeatCapacity(GetTileMixture(grid, map, tile) ?? GasMixture.SpaceGas);
|
||||
}
|
||||
|
||||
public IEnumerable<Vector2i> GetAdjacentTiles(EntityUid gridUid, Vector2i tile)
|
||||
public TileMixtureEnumerator GetAdjacentTileMixtures(Entity<GridAtmosphereComponent?> grid, Vector2i tile, bool includeBlocked = false, bool excite = false)
|
||||
{
|
||||
var ev = new GetAdjacentTilesMethodEvent(gridUid, tile);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
if (!_atmosQuery.Resolve(grid, ref grid.Comp, false))
|
||||
return TileMixtureEnumerator.Empty;
|
||||
|
||||
return ev.Result ?? Enumerable.Empty<Vector2i>();
|
||||
return !grid.Comp.Tiles.TryGetValue(tile, out var atmosTile)
|
||||
? TileMixtureEnumerator.Empty
|
||||
: new(atmosTile.AdjacentTiles);
|
||||
}
|
||||
|
||||
public IEnumerable<GasMixture> GetAdjacentTileMixtures(EntityUid gridUid, Vector2i tile, bool includeBlocked = false, bool excite = false)
|
||||
{
|
||||
var ev = new GetAdjacentTileMixturesMethodEvent(gridUid, tile, includeBlocked, excite);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
|
||||
return ev.Result ?? Enumerable.Empty<GasMixture>();
|
||||
}
|
||||
|
||||
public void HotspotExpose(EntityUid gridUid, Vector2i tile, float exposedTemperature, float exposedVolume,
|
||||
public void HotspotExpose(Entity<GridAtmosphereComponent?> grid, Vector2i tile, float exposedTemperature, float exposedVolume,
|
||||
EntityUid? sparkSourceUid = null, bool soh = false)
|
||||
{
|
||||
var ev = new HotspotExposeMethodEvent(gridUid, sparkSourceUid, tile, exposedTemperature, exposedVolume, soh);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
if (!_atmosQuery.Resolve(grid, ref grid.Comp, false))
|
||||
return;
|
||||
|
||||
if (grid.Comp.Tiles.TryGetValue(tile, out var atmosTile))
|
||||
HotspotExpose(grid.Comp, atmosTile, exposedTemperature, exposedVolume, soh, sparkSourceUid);
|
||||
}
|
||||
|
||||
public void HotspotExpose(TileAtmosphere tile, float exposedTemperature, float exposedVolume,
|
||||
EntityUid? sparkSourceUid = null, bool soh = false)
|
||||
{
|
||||
if (!_atmosQuery.TryGetComponent(tile.GridIndex, out var atmos))
|
||||
return;
|
||||
|
||||
DebugTools.Assert(atmos.Tiles.TryGetValue(tile.GridIndices, out var tmp) && tmp == tile);
|
||||
HotspotExpose(atmos, tile, exposedTemperature, exposedVolume, soh, sparkSourceUid);
|
||||
}
|
||||
|
||||
public void HotspotExtinguish(EntityUid gridUid, Vector2i tile)
|
||||
@@ -253,39 +256,45 @@ public partial class AtmosphereSystem
|
||||
return ev.Result;
|
||||
}
|
||||
|
||||
public void AddPipeNet(EntityUid gridUid, PipeNet pipeNet)
|
||||
public bool AddPipeNet(Entity<GridAtmosphereComponent?> grid, PipeNet pipeNet)
|
||||
{
|
||||
var ev = new AddPipeNetMethodEvent(gridUid, pipeNet);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
return _atmosQuery.Resolve(grid, ref grid.Comp, false) && grid.Comp.PipeNets.Add(pipeNet);
|
||||
}
|
||||
|
||||
public void RemovePipeNet(EntityUid gridUid, PipeNet pipeNet)
|
||||
public bool RemovePipeNet(Entity<GridAtmosphereComponent?> grid, PipeNet pipeNet)
|
||||
{
|
||||
var ev = new RemovePipeNetMethodEvent(gridUid, pipeNet);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
return _atmosQuery.Resolve(grid, ref grid.Comp, false) && grid.Comp.PipeNets.Remove(pipeNet);
|
||||
}
|
||||
|
||||
public bool AddAtmosDevice(EntityUid gridUid, AtmosDeviceComponent device)
|
||||
public bool AddAtmosDevice(Entity<GridAtmosphereComponent?> grid, Entity<AtmosDeviceComponent> device)
|
||||
{
|
||||
// TODO: check device is on grid
|
||||
DebugTools.Assert(device.Comp.JoinedGrid == null);
|
||||
DebugTools.Assert(Transform(device).GridUid == grid);
|
||||
|
||||
var ev = new AddAtmosDeviceMethodEvent(gridUid, device);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
return ev.Result;
|
||||
if (!_atmosQuery.Resolve(grid, ref grid.Comp, false))
|
||||
return false;
|
||||
|
||||
if (!grid.Comp.AtmosDevices.Add(device))
|
||||
return false;
|
||||
|
||||
device.Comp.JoinedGrid = grid;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveAtmosDevice(EntityUid gridUid, AtmosDeviceComponent device)
|
||||
public bool RemoveAtmosDevice(Entity<GridAtmosphereComponent?> grid, Entity<AtmosDeviceComponent> device)
|
||||
{
|
||||
// TODO: check device is on grid
|
||||
DebugTools.Assert(device.Comp.JoinedGrid == grid);
|
||||
|
||||
var ev = new RemoveAtmosDeviceMethodEvent(gridUid, device);
|
||||
RaiseLocalEvent(gridUid, ref ev);
|
||||
return ev.Result;
|
||||
if (!_atmosQuery.Resolve(grid, ref grid.Comp, false))
|
||||
return false;
|
||||
|
||||
if (!grid.Comp.AtmosDevices.Remove(device))
|
||||
return false;
|
||||
|
||||
device.Comp.JoinedGrid = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
[ByRefEvent] private record struct HasAtmosphereMethodEvent
|
||||
(EntityUid Grid, bool Result = false, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct SetSimulatedGridMethodEvent
|
||||
(EntityUid Grid, bool Simulated, bool Handled = false);
|
||||
|
||||
@@ -295,43 +304,12 @@ public partial class AtmosphereSystem
|
||||
[ByRefEvent] private record struct GetAllMixturesMethodEvent
|
||||
(EntityUid Grid, bool Excite = false, IEnumerable<GasMixture>? Mixtures = null, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct GetTileMixturesMethodEvent
|
||||
(EntityUid? GridUid, EntityUid? MapUid, List<Vector2i> Tiles, bool Excite = false, GasMixture?[]? Mixtures = null, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct GetTileMixtureMethodEvent
|
||||
(EntityUid? GridUid, EntityUid? MapUid, Vector2i Tile, bool Excite = false, GasMixture? Mixture = null, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct ReactTileMethodEvent
|
||||
(EntityUid GridId, Vector2i Tile, ReactionResult Result = default, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct IsTileSpaceMethodEvent
|
||||
(EntityUid? Grid, EntityUid? Map, Vector2i Tile, MapGridComponent? MapGridComponent = null, bool Result = true, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct GetAdjacentTilesMethodEvent
|
||||
(EntityUid Grid, Vector2i Tile, IEnumerable<Vector2i>? Result = null, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct GetAdjacentTileMixturesMethodEvent
|
||||
(EntityUid Grid, Vector2i Tile, bool IncludeBlocked, bool Excite,
|
||||
IEnumerable<GasMixture>? Result = null, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct HotspotExposeMethodEvent
|
||||
(EntityUid Grid, EntityUid? SparkSourceUid, Vector2i Tile, float ExposedTemperature, float ExposedVolume, bool soh, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct HotspotExtinguishMethodEvent
|
||||
(EntityUid Grid, Vector2i Tile, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct IsHotspotActiveMethodEvent
|
||||
(EntityUid Grid, Vector2i Tile, bool Result = false, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct AddPipeNetMethodEvent
|
||||
(EntityUid Grid, PipeNet PipeNet, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct RemovePipeNetMethodEvent
|
||||
(EntityUid Grid, PipeNet PipeNet, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct AddAtmosDeviceMethodEvent
|
||||
(EntityUid Grid, AtmosDeviceComponent Device, bool Result = false, bool Handled = false);
|
||||
|
||||
[ByRefEvent] private record struct RemoveAtmosDeviceMethodEvent
|
||||
(EntityUid Grid, AtmosDeviceComponent Device, bool Result = false, bool Handled = false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user