AtmosphereSystem no longer creates a component manually. (#3839)
- Maps get SpaceGridAtmosphereComponent added automatically
This commit is contained in:
committed by
GitHub
parent
30d5b58319
commit
c17426dfa7
@@ -1,172 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Atmos;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Atmos
|
||||
{
|
||||
[TestFixture]
|
||||
[TestOf(typeof(AtmosHelpersTest))]
|
||||
public class AtmosHelpersTest : ContentIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public async Task GetTileAtmosphereEntityCoordinatesNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
|
||||
var entityManager = server.ResolveDependency<IEntityManager>();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var atmosphere1 = default(EntityCoordinates).GetTileAtmosphere();
|
||||
var atmosphere2 = default(EntityCoordinates).GetTileAtmosphere(entityManager);
|
||||
|
||||
Assert.NotNull(atmosphere1);
|
||||
Assert.NotNull(atmosphere2);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTileAirEntityCoordinatesNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var air = default(EntityCoordinates).GetTileAir();
|
||||
|
||||
Assert.NotNull(air);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryGetTileAtmosphereEntityCoordinatesNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAtmosphere = default(EntityCoordinates).TryGetTileAtmosphere(out var atmosphere);
|
||||
|
||||
Assert.True(hasAtmosphere);
|
||||
Assert.NotNull(atmosphere);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TryGetTileTileAirEntityCoordinatesNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAir = default(EntityCoordinates).TryGetTileAir(out var air);
|
||||
|
||||
Assert.True(hasAir);
|
||||
Assert.NotNull(air);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[Test]
|
||||
public async Task GetTileAtmosphereVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var atmosphere = default(Vector2i).GetTileAtmosphere(default);
|
||||
|
||||
Assert.NotNull(atmosphere);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[Test]
|
||||
public async Task GetTileAirVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var air = default(Vector2i).GetTileAir(default);
|
||||
|
||||
Assert.NotNull(air);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[Test]
|
||||
public async Task TryGetTileAtmosphereVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAtmosphere = default(Vector2i).TryGetTileAtmosphere(default, out var atmosphere);
|
||||
|
||||
Assert.True(hasAtmosphere);
|
||||
Assert.NotNull(atmosphere);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[Test]
|
||||
public async Task TryGetTileAirVector2iNotNullTest()
|
||||
{
|
||||
var server = StartServerDummyTicker();
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
var hasAir = default(Vector2i).TryGetTileAir(default, out var air);
|
||||
|
||||
Assert.True(hasAir);
|
||||
Assert.NotNull(air);
|
||||
});
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
@@ -40,11 +41,10 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapId = new MapId(0);
|
||||
mapManager.CreateNewMapEntity(mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", MapCoordinates.Nullspace);
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndAppearanceDummy", new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(human.TryGetComponent(out IBody body));
|
||||
Assert.That(human.TryGetComponent(out appearance));
|
||||
|
||||
@@ -57,11 +57,11 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
mapManager.CreateNewMapEntity(MapId.Nullspace);
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", MapCoordinates.Nullspace);
|
||||
var human = entityManager.SpawnEntity("HumanBodyAndBloodstreamDummy", new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(human.TryGetComponent(out IBody body));
|
||||
Assert.That(body.TryGetMechanismBehaviors(out List<LungBehavior> lungs));
|
||||
|
||||
@@ -9,6 +9,7 @@ using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
@@ -122,11 +123,10 @@ namespace Content.IntegrationTests.Tests.Body
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
|
||||
var mapId = new MapId(0);
|
||||
mapManager.CreateNewMapEntity(mapId);
|
||||
var mapId = mapManager.CreateMap();
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
var human = entityManager.SpawnEntity("HumanBodyDummy", MapCoordinates.Nullspace);
|
||||
var human = entityManager.SpawnEntity("HumanBodyDummy", new MapCoordinates(Vector2.Zero, mapId));
|
||||
|
||||
Assert.That(human.TryGetComponent(out IBody? body));
|
||||
Assert.NotNull(body);
|
||||
|
||||
@@ -10,6 +10,7 @@ using Robust.Server.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
|
||||
{
|
||||
@@ -52,15 +53,16 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
|
||||
server.Assert(() =>
|
||||
{
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
mapManager.CreateNewMapEntity(MapId.Nullspace);
|
||||
var mapId = mapManager.CreateMap();
|
||||
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
// Spawn the entities
|
||||
human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace);
|
||||
otherHuman = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace);
|
||||
cuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace);
|
||||
secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", MapCoordinates.Nullspace);
|
||||
human = entityManager.SpawnEntity("HumanDummy", coordinates);
|
||||
otherHuman = entityManager.SpawnEntity("HumanDummy", coordinates);
|
||||
cuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
|
||||
secondCuffs = entityManager.SpawnEntity("HandcuffsDummy", coordinates);
|
||||
|
||||
human.Transform.WorldPosition = otherHuman.Transform.WorldPosition;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using NUnit.Framework;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.Interaction
|
||||
{
|
||||
@@ -44,8 +45,8 @@ namespace Content.IntegrationTests.Tests.Interaction
|
||||
|
||||
server.Assert(() =>
|
||||
{
|
||||
mapManager.CreateNewMapEntity(MapId.Nullspace);
|
||||
var coordinates = MapCoordinates.Nullspace;
|
||||
var mapId = mapManager.CreateMap();
|
||||
var coordinates = new MapCoordinates(Vector2.Zero, mapId);
|
||||
|
||||
origin = entityManager.SpawnEntity(HumanId, coordinates);
|
||||
other = entityManager.SpawnEntity(HumanId, coordinates);
|
||||
|
||||
@@ -3,26 +3,20 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.Atmos
|
||||
{
|
||||
public static class AtmosHelpers
|
||||
{
|
||||
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
||||
public static TileAtmosphere? GetTileAtmosphere(this EntityCoordinates coordinates)
|
||||
{
|
||||
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GetGridId(entityManager));
|
||||
|
||||
return gridAtmos.GetTile(coordinates);
|
||||
return EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates).GetTile(coordinates);
|
||||
}
|
||||
|
||||
public static GasMixture? GetTileAir(this EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
||||
{
|
||||
return coordinates.GetTileAtmosphere(entityManager)?.Air;
|
||||
return coordinates.GetTileAtmosphere()?.Air;
|
||||
}
|
||||
|
||||
public static bool TryGetTileAtmosphere(this EntityCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere? atmosphere)
|
||||
@@ -54,36 +48,6 @@ namespace Content.Server.Atmos
|
||||
return true;
|
||||
}
|
||||
|
||||
public static TileAtmosphere? GetTileAtmosphere(this Vector2i indices, GridId gridId)
|
||||
{
|
||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(gridId);
|
||||
|
||||
return gridAtmos.GetTile(indices);
|
||||
}
|
||||
|
||||
public static GasMixture? GetTileAir(this Vector2i indices, GridId gridId)
|
||||
{
|
||||
return indices.GetTileAtmosphere(gridId)?.Air;
|
||||
}
|
||||
|
||||
public static bool TryGetTileAtmosphere(this Vector2i indices, GridId gridId,
|
||||
[NotNullWhen(true)] out TileAtmosphere? atmosphere)
|
||||
{
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId), default);
|
||||
}
|
||||
|
||||
public static bool TryGetTileAir(this Vector2i indices, GridId gridId, [NotNullWhen(true)] out GasMixture? air)
|
||||
{
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(air = indices.GetTileAir(gridId), default);
|
||||
}
|
||||
|
||||
public static bool InvalidateTileAir(this ITransformComponent transform, AtmosphereSystem? atmosSystem = null)
|
||||
{
|
||||
return InvalidateTileAir(transform.Coordinates);
|
||||
}
|
||||
|
||||
public static bool InvalidateTileAir(this EntityCoordinates coordinates)
|
||||
{
|
||||
if (!coordinates.TryGetTileAtmosphere(out var tileAtmos))
|
||||
|
||||
@@ -157,6 +157,11 @@ namespace Content.Server.Atmos
|
||||
|
||||
void RepopulateTiles();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a dictionary of adjacent TileAtmospheres.
|
||||
/// </summary>
|
||||
Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a dictionary of adjacent TileAtmospheres.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.Atmos;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -18,7 +19,7 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
{
|
||||
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero;
|
||||
var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex);
|
||||
var tileAtmos = tile.GridPosition().GetTileAtmosphere();
|
||||
if (tileAtmos == null || !tileAtmos.Hotspot.Valid || tileAtmos.Air == null) return ReagentUnit.Zero;
|
||||
tileAtmos.Air.Temperature =
|
||||
MathF.Max(MathF.Min(tileAtmos.Air.Temperature - (_coolingTemperature * 1000f),
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Content.Server.Atmos;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Interfaces.Chemistry;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -17,7 +18,7 @@ namespace Content.Server.Chemistry.TileReactions
|
||||
public ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume)
|
||||
{
|
||||
if (reactVolume <= ReagentUnit.Zero || tile.Tile.IsEmpty) return ReagentUnit.Zero;
|
||||
var tileAtmos = tile.GridIndices.GetTileAtmosphere(tile.GridIndex);
|
||||
var tileAtmos = tile.GridPosition().GetTileAtmosphere();
|
||||
if (tileAtmos?.Air == null || !tileAtmos.Hotspot.Valid) return ReagentUnit.Zero;
|
||||
tileAtmos.Air.Temperature *= MathF.Max(_temperatureMultiplier * reactVolume.Float(), 1f);
|
||||
tileAtmos.Air.React(tileAtmos);
|
||||
|
||||
@@ -141,7 +141,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
|
||||
|
||||
if (_fixVacuum)
|
||||
_atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1).FixVacuum(_lastPosition.Item2);
|
||||
{
|
||||
_atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTransformMove()
|
||||
@@ -165,8 +167,8 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId);
|
||||
|
||||
gridAtmos.UpdateAdjacentBits(pos);
|
||||
gridAtmos.Invalidate(pos);
|
||||
gridAtmos?.UpdateAdjacentBits(pos);
|
||||
gridAtmos?.Invalidate(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (IsHoldingPressure())
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("A gush of air blows in your face... Maybe you should reconsider."));
|
||||
@@ -76,15 +76,12 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
|
||||
if (!Owner.Transform.Coordinates.TryGetTileAtmosphere(out var tileAtmos))
|
||||
return false;
|
||||
|
||||
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID);
|
||||
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates);
|
||||
|
||||
var minMoles = float.MaxValue;
|
||||
var maxMoles = 0f;
|
||||
|
||||
foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
|
||||
foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(Owner.Transform.Coordinates))
|
||||
{
|
||||
// includeAirBlocked remains false, and therefore Air must be present
|
||||
var moles = adjacent.Air!.TotalMoles;
|
||||
@@ -107,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
if (tileAtmos.Hotspot.Valid)
|
||||
return true;
|
||||
|
||||
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID);
|
||||
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.Coordinates);
|
||||
|
||||
foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
|
||||
{
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
// Already get the pressure before Dirty(), because we can't get the EntitySystem in that thread or smth
|
||||
var pressure = 0f;
|
||||
var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.GridID);
|
||||
var gam = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(Owner.Transform.Coordinates);
|
||||
var tile = gam?.GetTile(Owner.Transform.Coordinates)?.Air;
|
||||
if (tile != null)
|
||||
{
|
||||
@@ -185,7 +185,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
}
|
||||
|
||||
var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
var gam = atmosSystem.GetGridAtmosphere(pos.GetGridId(Owner.EntityManager));
|
||||
var gam = atmosSystem.GetGridAtmosphere(pos);
|
||||
var tile = gam.GetTile(pos)?.Air;
|
||||
if (tile == null)
|
||||
{
|
||||
|
||||
@@ -514,6 +514,11 @@ namespace Content.Server.GameObjects.Components.Atmos
|
||||
return _mapGridComponent.Grid.GetTileRef(indices).IsSpace();
|
||||
}
|
||||
|
||||
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(EntityCoordinates coordinates, bool includeAirBlocked = false)
|
||||
{
|
||||
return GetAdjacentTiles(coordinates.ToVector2i(_serverEntityManager, _mapManager), includeAirBlocked);
|
||||
}
|
||||
|
||||
public Dictionary<AtmosDirection, TileAtmosphere> GetAdjacentTiles(Vector2i indices, bool includeAirBlocked = false)
|
||||
{
|
||||
var sides = new Dictionary<AtmosDirection, TileAtmosphere>();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
|
||||
private void JoinGridAtmos()
|
||||
{
|
||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>()
|
||||
.GetGridAtmosphere(Owner.Transform.GridID);
|
||||
.GetGridAtmosphere(Owner.Transform.Coordinates);
|
||||
JoinedGridAtmos = gridAtmos;
|
||||
JoinedGridAtmos.AddPipeNetDevice(this);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Scrubbers
|
||||
if (!SiphonEnabled)
|
||||
return;
|
||||
|
||||
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager);
|
||||
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere();
|
||||
|
||||
if (_scrubberOutlet == null || tileAtmos == null || tileAtmos.Air == null)
|
||||
return;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping.Vents
|
||||
if (!VentEnabled)
|
||||
return;
|
||||
|
||||
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere(Owner.EntityManager);
|
||||
var tileAtmos = Owner.Transform.Coordinates.GetTileAtmosphere();
|
||||
|
||||
if (_ventInlet == null || tileAtmos == null || tileAtmos.Air == null)
|
||||
return;
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IGridAtmosphereComponent))]
|
||||
public class SpaceGridAtmosphereComponent : UnsimulatedGridAtmosphereComponent
|
||||
{
|
||||
public override string Name => "SpaceGridAtmosphere";
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
|
||||
var atmosSystem = EntitySystem.Get<AtmosphereSystem>();
|
||||
atmosSystem
|
||||
.GetGridAtmosphere(Owner.Transform.GridID)?
|
||||
.GetGridAtmosphere(Owner.Transform.Coordinates)?
|
||||
.Invalidate(tileAtmos.GridIndices);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
// creadth: everything exposable by atmos should be updated as well
|
||||
foreach (var atmosExposedComponent in EntityManager.ComponentManager.EntityQuery<AtmosExposedComponent>(true))
|
||||
{
|
||||
var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere(EntityManager);
|
||||
var tile = atmosExposedComponent.Owner.Transform.Coordinates.GetTileAtmosphere();
|
||||
if (tile == null) continue;
|
||||
atmosExposedComponent.Update(tile, _lastUpdate);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
|
||||
using Content.Shared;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.GameObjects.EntitySystems.Atmos;
|
||||
@@ -31,7 +32,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
private GasReactionPrototype[] _gasReactions = Array.Empty<GasReactionPrototype>();
|
||||
|
||||
private SpaceGridAtmosphereComponent _spaceAtmos = default!;
|
||||
private GridTileLookupSystem? _gridTileLookup = null;
|
||||
|
||||
/// <summary>
|
||||
@@ -51,10 +51,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
_gasReactions = _protoMan.EnumeratePrototypes<GasReactionPrototype>().ToArray();
|
||||
Array.Sort(_gasReactions, (a, b) => b.Priority.CompareTo(a.Priority));
|
||||
|
||||
_spaceAtmos = new SpaceGridAtmosphereComponent();
|
||||
_spaceAtmos.Initialize();
|
||||
IoCManager.InjectDependencies(_spaceAtmos);
|
||||
|
||||
_mapManager.MapCreated += OnMapCreated;
|
||||
_mapManager.TileChanged += OnTileChanged;
|
||||
|
||||
Array.Resize(ref _gasSpecificHeats, MathHelper.NextMultipleOf(Atmospherics.TotalNumberOfGases, 4));
|
||||
@@ -116,6 +113,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
_mapManager.MapCreated -= OnMapCreated;
|
||||
|
||||
EntityManager.EventBus.UnsubscribeEvent<RotateEvent>(EventSource.Local, this);
|
||||
}
|
||||
|
||||
@@ -127,18 +126,39 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
public IGridAtmosphereComponent GetGridAtmosphere(GridId gridId)
|
||||
public IGridAtmosphereComponent? GetGridAtmosphere(GridId gridId)
|
||||
{
|
||||
if (!gridId.IsValid())
|
||||
return null;
|
||||
|
||||
if (!_mapManager.TryGetGrid(gridId, out var grid))
|
||||
return null;
|
||||
|
||||
return ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? gridAtmosphere)
|
||||
? gridAtmosphere : null;
|
||||
}
|
||||
|
||||
public IGridAtmosphereComponent GetGridAtmosphere(EntityCoordinates coordinates)
|
||||
{
|
||||
return GetGridAtmosphere(coordinates.ToMap(EntityManager));
|
||||
}
|
||||
|
||||
public IGridAtmosphereComponent GetGridAtmosphere(MapCoordinates coordinates)
|
||||
{
|
||||
if (coordinates.MapId == MapId.Nullspace)
|
||||
{
|
||||
return _spaceAtmos;
|
||||
throw new ArgumentException($"Coordinates cannot be in nullspace!", nameof(coordinates));
|
||||
}
|
||||
|
||||
var grid = _mapManager.GetGrid(gridId);
|
||||
if (_mapManager.TryFindGridAt(coordinates, out var grid))
|
||||
{
|
||||
if (ComponentManager.TryGetComponent(grid.GridEntityId, out IGridAtmosphereComponent? atmos))
|
||||
{
|
||||
return atmos;
|
||||
}
|
||||
}
|
||||
|
||||
if (!EntityManager.TryGetEntity(grid.GridEntityId, out var gridEnt)) return _spaceAtmos;
|
||||
|
||||
return gridEnt.TryGetComponent(out IGridAtmosphereComponent? atmos) ? atmos : _spaceAtmos;
|
||||
return _mapManager.GetMapEntity(coordinates.MapId).GetComponent<IGridAtmosphereComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -164,7 +184,18 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
return;
|
||||
}
|
||||
|
||||
GetGridAtmosphere(eventArgs.NewTile.GridIndex)?.Invalidate(eventArgs.NewTile.GridIndices);
|
||||
GetGridAtmosphere(eventArgs.NewTile.GridPosition(_mapManager))?.Invalidate(eventArgs.NewTile.GridIndices);
|
||||
}
|
||||
|
||||
private void OnMapCreated(object? sender, MapEventArgs e)
|
||||
{
|
||||
if (e.Map == MapId.Nullspace)
|
||||
return;
|
||||
|
||||
var map = _mapManager.GetMapEntity(e.Map);
|
||||
|
||||
if (!map.HasComponent<IGridAtmosphereComponent>())
|
||||
map.AddComponent<SpaceGridAtmosphereComponent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user