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:
@@ -103,7 +103,7 @@ public sealed partial class AnomalySystem
|
||||
var tile = new Vector2i(randomX, randomY);
|
||||
|
||||
// no air-blocked areas.
|
||||
if (_atmosphere.IsTileSpace(grid, xform.MapUid, tile, mapGridComp: gridComp) ||
|
||||
if (_atmosphere.IsTileSpace(grid, xform.MapUid, tile) ||
|
||||
_atmosphere.IsTileAirBlocked(grid, tile, mapGridComp: gridComp))
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -62,7 +62,7 @@ public sealed class GasProducerAnomalySystem : EntitySystem
|
||||
if (tilerefs.Length == 0)
|
||||
return;
|
||||
|
||||
var mixture = _atmosphere.GetTileMixture((uid, xform), grid, true);
|
||||
var mixture = _atmosphere.GetTileMixture((uid, xform), true);
|
||||
if (mixture != null)
|
||||
{
|
||||
mixture.AdjustMoles(gas, mols);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
if (ev.Handled)
|
||||
return ev.Mixtures;
|
||||
mixtures[i] = atmosTile.Air;
|
||||
|
||||
if (excite)
|
||||
gridEnt.Comp.InvalidatedCoords.Add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (ev.Handled)
|
||||
return ev.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;
|
||||
}
|
||||
return ev.Mixtures;
|
||||
mixtures[i] ??= mapEnt.Comp.Mixture;
|
||||
}
|
||||
|
||||
public GasMixture? GetTileMixture (Entity<TransformComponent?> entity, MapGridComponent? grid = null, bool excite = false)
|
||||
return mixtures;
|
||||
}
|
||||
|
||||
// Default to a space mixture... This is a space game, after all!
|
||||
mixtures ??= new GasMixture?[tiles.Count];
|
||||
for (var i = 0; i < tiles.Count; i++)
|
||||
{
|
||||
mixtures[i] ??= GasMixture.SpaceGas;
|
||||
}
|
||||
return mixtures;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public sealed partial class AtmosphereSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tile.Immutable && !IsTileSpace(euid, transform.MapUid, indices, gridComp))
|
||||
if (tile.Immutable && !IsTileSpace(euid, transform.MapUid, indices))
|
||||
{
|
||||
tile = new GasMixture(tile.Volume) { Temperature = tile.Temperature };
|
||||
tileMain.Air = tile;
|
||||
|
||||
@@ -20,22 +20,11 @@ public sealed partial class AtmosphereSystem
|
||||
|
||||
#region Atmos API Subscriptions
|
||||
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, HasAtmosphereMethodEvent>(GridHasAtmosphere);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, IsSimulatedGridMethodEvent>(GridIsSimulated);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, GetAllMixturesMethodEvent>(GridGetAllMixtures);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, GetTileMixtureMethodEvent>(GridGetTileMixture);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, GetTileMixturesMethodEvent>(GridGetTileMixtures);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, ReactTileMethodEvent>(GridReactTile);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, IsTileSpaceMethodEvent>(GridIsTileSpace);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, GetAdjacentTilesMethodEvent>(GridGetAdjacentTiles);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, GetAdjacentTileMixturesMethodEvent>(GridGetAdjacentTileMixtures);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, HotspotExposeMethodEvent>(GridHotspotExpose);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, HotspotExtinguishMethodEvent>(GridHotspotExtinguish);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, IsHotspotActiveMethodEvent>(GridIsHotspotActive);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, AddPipeNetMethodEvent>(GridAddPipeNet);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, RemovePipeNetMethodEvent>(GridRemovePipeNet);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, AddAtmosDeviceMethodEvent>(GridAddAtmosDevice);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, RemoveAtmosDeviceMethodEvent>(GridRemoveAtmosDevice);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -120,15 +109,6 @@ public sealed partial class AtmosphereSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void GridHasAtmosphere(EntityUid uid, GridAtmosphereComponent component, ref HasAtmosphereMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Result = true;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridIsSimulated(EntityUid uid, GridAtmosphereComponent component, ref IsSimulatedGridMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
@@ -167,48 +147,6 @@ public sealed partial class AtmosphereSystem
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridGetTileMixture(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref GetTileMixtureMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.Tiles.TryGetValue(args.Tile, out var tile))
|
||||
return; // Do NOT handle the event if we don't have that tile, the map will handle it instead.
|
||||
|
||||
if (args.Excite)
|
||||
component.InvalidatedCoords.Add(args.Tile);
|
||||
|
||||
args.Mixture = tile.Air;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridGetTileMixtures(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref GetTileMixturesMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
args.Mixtures = new GasMixture?[args.Tiles.Count];
|
||||
|
||||
for (var i = 0; i < args.Tiles.Count; i++)
|
||||
{
|
||||
var tile = args.Tiles[i];
|
||||
if (!component.Tiles.TryGetValue(tile, out var atmosTile))
|
||||
{
|
||||
// need to get map atmosphere
|
||||
args.Handled = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args.Excite)
|
||||
component.InvalidatedCoords.Add(tile);
|
||||
|
||||
args.Mixtures[i] = atmosTile.Air;
|
||||
}
|
||||
}
|
||||
|
||||
private void GridReactTile(EntityUid uid, GridAtmosphereComponent component, ref ReactTileMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
@@ -221,67 +159,6 @@ public sealed partial class AtmosphereSystem
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridIsTileSpace(EntityUid uid, GridAtmosphereComponent component, ref IsTileSpaceMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// We don't have that tile, so let the map handle it.
|
||||
if (!component.Tiles.TryGetValue(args.Tile, out var tile))
|
||||
return;
|
||||
|
||||
args.Result = tile.Space;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridGetAdjacentTiles(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref GetAdjacentTilesMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.Tiles.TryGetValue(args.Tile, out var tile))
|
||||
return;
|
||||
|
||||
IEnumerable<Vector2i> EnumerateAdjacent(GridAtmosphereComponent grid, TileAtmosphere t)
|
||||
{
|
||||
foreach (var adj in t.AdjacentTiles)
|
||||
{
|
||||
if (adj == null)
|
||||
continue;
|
||||
|
||||
yield return adj.GridIndices;
|
||||
}
|
||||
}
|
||||
|
||||
args.Result = EnumerateAdjacent(component, tile);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridGetAdjacentTileMixtures(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref GetAdjacentTileMixturesMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.Tiles.TryGetValue(args.Tile, out var tile))
|
||||
return;
|
||||
|
||||
IEnumerable<GasMixture> EnumerateAdjacent(GridAtmosphereComponent grid, TileAtmosphere t)
|
||||
{
|
||||
foreach (var adj in t.AdjacentTiles)
|
||||
{
|
||||
if (adj?.Air == null)
|
||||
continue;
|
||||
|
||||
yield return adj.Air;
|
||||
}
|
||||
}
|
||||
|
||||
args.Result = EnumerateAdjacent(component, tile);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update array of adjacent tiles and the adjacency flags. Optionally activates all tiles with modified adjacencies.
|
||||
/// </summary>
|
||||
@@ -357,18 +234,6 @@ public sealed partial class AtmosphereSystem
|
||||
return (air, map.Space);
|
||||
}
|
||||
|
||||
private void GridHotspotExpose(EntityUid uid, GridAtmosphereComponent component, ref HotspotExposeMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.Tiles.TryGetValue(args.Tile, out var tile))
|
||||
return;
|
||||
|
||||
HotspotExpose(component, tile, args.ExposedTemperature, args.ExposedVolume, args.soh, args.SparkSourceUid);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GridHotspotExtinguish(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref HotspotExtinguishMethodEvent args)
|
||||
{
|
||||
@@ -445,49 +310,6 @@ public sealed partial class AtmosphereSystem
|
||||
tile.Air.Temperature = totalTemperature / count;
|
||||
}
|
||||
|
||||
private void GridAddPipeNet(EntityUid uid, GridAtmosphereComponent component, ref AddPipeNetMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = component.PipeNets.Add(args.PipeNet);
|
||||
}
|
||||
|
||||
private void GridRemovePipeNet(EntityUid uid, GridAtmosphereComponent component, ref RemovePipeNetMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = component.PipeNets.Remove(args.PipeNet);
|
||||
}
|
||||
|
||||
private void GridAddAtmosDevice(Entity<GridAtmosphereComponent> grid, ref AddAtmosDeviceMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!grid.Comp.AtmosDevices.Add((args.Device.Owner, args.Device)))
|
||||
return;
|
||||
|
||||
args.Device.JoinedGrid = grid;
|
||||
args.Handled = true;
|
||||
args.Result = true;
|
||||
}
|
||||
|
||||
private void GridRemoveAtmosDevice(EntityUid uid, GridAtmosphereComponent component,
|
||||
ref RemoveAtmosDeviceMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
if (!component.AtmosDevices.Remove((args.Device.Owner, args.Device)))
|
||||
return;
|
||||
|
||||
args.Device.JoinedGrid = null;
|
||||
args.Handled = true;
|
||||
args.Result = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Repopulates all tiles on a grid atmosphere.
|
||||
/// </summary>
|
||||
|
||||
@@ -12,9 +12,6 @@ public partial class AtmosphereSystem
|
||||
{
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentInit>(OnMapStartup);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentRemove>(OnMapRemove);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, IsTileSpaceMethodEvent>(MapIsTileSpace);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, GetTileMixtureMethodEvent>(MapGetTileMixture);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, GetTileMixturesMethodEvent>(MapGetTileMixtures);
|
||||
SubscribeLocalEvent<MapAtmosphereComponent, ComponentGetState>(OnMapGetState);
|
||||
SubscribeLocalEvent<GridAtmosphereComponent, EntParentChangedMessage>(OnGridParentChanged);
|
||||
}
|
||||
@@ -31,37 +28,6 @@ public partial class AtmosphereSystem
|
||||
RefreshAllGridMapAtmospheres(uid);
|
||||
}
|
||||
|
||||
private void MapIsTileSpace(EntityUid uid, MapAtmosphereComponent component, ref IsTileSpaceMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Result = component.Space;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void MapGetTileMixture(EntityUid uid, MapAtmosphereComponent component, ref GetTileMixtureMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Mixture = component.Mixture;
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void MapGetTileMixtures(EntityUid uid, MapAtmosphereComponent component, ref GetTileMixturesMethodEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
args.Handled = true;
|
||||
args.Mixtures ??= new GasMixture?[args.Tiles.Count];
|
||||
|
||||
for (var i = 0; i < args.Tiles.Count; i++)
|
||||
{
|
||||
args.Mixtures[i] ??= component.Mixture;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapGetState(EntityUid uid, MapAtmosphereComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new MapAtmosphereComponentState(component.Overlay);
|
||||
|
||||
@@ -42,6 +42,7 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
|
||||
private float _exposedTimer = 0f;
|
||||
|
||||
private EntityQuery<GridAtmosphereComponent> _atmosQuery;
|
||||
private EntityQuery<MapAtmosphereComponent> _mapAtmosQuery;
|
||||
private EntityQuery<AirtightComponent> _airtightQuery;
|
||||
private EntityQuery<FirelockComponent> _firelockQuery;
|
||||
private HashSet<EntityUid> _entSet = new();
|
||||
@@ -59,6 +60,7 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
|
||||
InitializeGridAtmosphere();
|
||||
InitializeMap();
|
||||
|
||||
_mapAtmosQuery = GetEntityQuery<MapAtmosphereComponent>();
|
||||
_atmosQuery = GetEntityQuery<GridAtmosphereComponent>();
|
||||
_airtightQuery = GetEntityQuery<AirtightComponent>();
|
||||
_firelockQuery = GetEntityQuery<FirelockComponent>();
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed partial class AtmosDeviceComponent : Component
|
||||
/// <summary>
|
||||
/// If non-null, the grid that this device is part of.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[ViewVariables]
|
||||
public EntityUid? JoinedGrid = null;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Atmos.Piping.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Atmos.Piping.EntitySystems
|
||||
{
|
||||
@@ -32,6 +34,14 @@ namespace Content.Server.Atmos.Piping.EntitySystems
|
||||
|
||||
public void JoinAtmosphere(Entity<AtmosDeviceComponent> ent)
|
||||
{
|
||||
if (ent.Comp.JoinedGrid != null)
|
||||
{
|
||||
DebugTools.Assert(HasComp<GridAtmosphereComponent>(ent.Comp.JoinedGrid));
|
||||
DebugTools.Assert(Transform(ent).GridUid == ent.Comp.JoinedGrid);
|
||||
DebugTools.Assert(ent.Comp.RequireAnchored == Transform(ent).Anchored);
|
||||
return;
|
||||
}
|
||||
|
||||
var component = ent.Comp;
|
||||
var transform = Transform(ent);
|
||||
|
||||
@@ -39,7 +49,7 @@ namespace Content.Server.Atmos.Piping.EntitySystems
|
||||
return;
|
||||
|
||||
// Attempt to add device to a grid atmosphere.
|
||||
bool onGrid = (transform.GridUid != null) && _atmosphereSystem.AddAtmosDevice(transform.GridUid!.Value, component);
|
||||
bool onGrid = (transform.GridUid != null) && _atmosphereSystem.AddAtmosDevice(transform.GridUid!.Value, ent);
|
||||
|
||||
if (!onGrid && component.JoinSystem)
|
||||
{
|
||||
@@ -55,7 +65,7 @@ namespace Content.Server.Atmos.Piping.EntitySystems
|
||||
{
|
||||
var component = ent.Comp;
|
||||
// Try to remove the component from an atmosphere, and if not
|
||||
if (component.JoinedGrid != null && !_atmosphereSystem.RemoveAtmosDevice(component.JoinedGrid.Value, component))
|
||||
if (component.JoinedGrid != null && !_atmosphereSystem.RemoveAtmosDevice(component.JoinedGrid.Value, ent))
|
||||
{
|
||||
// The grid might have been removed but not us... This usually shouldn't happen.
|
||||
component.JoinedGrid = null;
|
||||
|
||||
@@ -77,7 +77,8 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|
||||
return;
|
||||
|
||||
// Scrub adjacent tiles too.
|
||||
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true))
|
||||
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true);
|
||||
while (enumerator.MoveNext(out var adjacent))
|
||||
{
|
||||
Scrub(timeDelta, scrubber, adjacent, outlet);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ namespace Content.Server.Atmos.Portable
|
||||
if (!running)
|
||||
return;
|
||||
// widenet
|
||||
foreach (var adjacent in _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true))
|
||||
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true);
|
||||
while (enumerator.MoveNext(out var adjacent))
|
||||
{
|
||||
Scrub(timeDelta, component, adjacent);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Content.Server.Atmos.Reactions
|
||||
var mixTemperature = mixture.Temperature;
|
||||
if (mixTemperature > Atmospherics.FireMinimumTemperatureToExist)
|
||||
{
|
||||
atmosphereSystem.HotspotExpose(location.GridIndex, location.GridIndices, mixTemperature, mixture.Volume);
|
||||
atmosphereSystem.HotspotExpose(location, mixTemperature, mixture.Volume);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Content.Server.Atmos.Reactions
|
||||
temperature = mixture.Temperature;
|
||||
if (temperature > Atmospherics.FireMinimumTemperatureToExist)
|
||||
{
|
||||
atmosphereSystem.HotspotExpose(location.GridIndex, location.GridIndices, temperature, mixture.Volume);
|
||||
atmosphereSystem.HotspotExpose(location, temperature, mixture.Volume);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
Content.Server/Atmos/TileMixtureEnumerator.cs
Normal file
29
Content.Server/Atmos/TileMixtureEnumerator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.Atmos;
|
||||
|
||||
public struct TileMixtureEnumerator
|
||||
{
|
||||
public readonly TileAtmosphere?[] Tiles;
|
||||
public int Index = 0;
|
||||
|
||||
public static readonly TileMixtureEnumerator Empty = new(Array.Empty<TileAtmosphere>());
|
||||
|
||||
internal TileMixtureEnumerator(TileAtmosphere?[] tiles)
|
||||
{
|
||||
Tiles = tiles;
|
||||
}
|
||||
|
||||
public bool MoveNext([NotNullWhen(true)] out GasMixture? mix)
|
||||
{
|
||||
while (Index < Tiles.Length)
|
||||
{
|
||||
mix = Tiles[Index++]?.Air;
|
||||
if (mix != null)
|
||||
return true;
|
||||
}
|
||||
|
||||
mix = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -119,8 +119,7 @@ public abstract partial class GameRuleSystem<T> where T: IComponent
|
||||
var randomY = RobustRandom.Next((int) aabb.Bottom, (int) aabb.Top);
|
||||
|
||||
tile = new Vector2i(randomX, randomY);
|
||||
if (_atmosphere.IsTileSpace(targetGrid, Transform(targetGrid).MapUid, tile,
|
||||
mapGridComp: gridComp)
|
||||
if (_atmosphere.IsTileSpace(targetGrid, Transform(targetGrid).MapUid, tile)
|
||||
|| _atmosphere.IsTileAirBlocked(targetGrid, tile, mapGridComp: gridComp))
|
||||
{
|
||||
continue;
|
||||
|
||||
@@ -88,7 +88,11 @@ namespace Content.Server.Lathe
|
||||
|
||||
if (xform.GridUid != null)
|
||||
{
|
||||
_environments.AddRange(_atmosphere.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true));
|
||||
var enumerator = _atmosphere.GetAdjacentTileMixtures(xform.GridUid.Value, position, false, true);
|
||||
while (enumerator.MoveNext(out var mix))
|
||||
{
|
||||
_environments.Add(mix);
|
||||
}
|
||||
}
|
||||
|
||||
if (_environments.Count > 0)
|
||||
|
||||
@@ -28,10 +28,10 @@ public sealed class TemperatureArtifactSystem : EntitySystem
|
||||
|
||||
if (component.AffectAdjacentTiles && transform.GridUid != null)
|
||||
{
|
||||
var adjacent = _atmosphereSystem.GetAdjacentTileMixtures(transform.GridUid.Value,
|
||||
var enumerator = _atmosphereSystem.GetAdjacentTileMixtures(transform.GridUid.Value,
|
||||
_transformSystem.GetGridOrMapTilePosition(uid, transform), excite: true);
|
||||
|
||||
foreach (var mixture in adjacent)
|
||||
while (enumerator.MoveNext(out var mixture))
|
||||
{
|
||||
UpdateTileTemperature(component, mixture);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user