Merge branch 'master' into mathmerge
This commit is contained in:
@@ -138,7 +138,7 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
public class FillGas : IClientCommand
|
||||
public class FillGas : IClientCommand
|
||||
{
|
||||
public string Command => "fillgas";
|
||||
public string Description => "Adds gas to all tiles in a grid.";
|
||||
|
||||
@@ -20,14 +20,16 @@ namespace Content.Server.Atmos
|
||||
return coordinates.GetTileAtmosphere()?.Air;
|
||||
}
|
||||
|
||||
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [NotNullWhen(true)] out TileAtmosphere atmosphere)
|
||||
public static bool TryGetTileAtmosphere(this GridCoordinates coordinates, [MaybeNullWhen(false)] out TileAtmosphere atmosphere)
|
||||
{
|
||||
return (atmosphere = coordinates.GetTileAtmosphere()!) != default;
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(atmosphere = coordinates.GetTileAtmosphere()!, default);
|
||||
}
|
||||
|
||||
public static bool TryGetTileAir(this GridCoordinates coordinates, [NotNullWhen(true)] out GasMixture air)
|
||||
public static bool TryGetTileAir(this GridCoordinates coordinates, [MaybeNullWhen(false)] out GasMixture air)
|
||||
{
|
||||
return !(air = coordinates.GetTileAir()!).Equals(default);
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(air = coordinates.GetTileAir()!, default);
|
||||
}
|
||||
|
||||
public static TileAtmosphere? GetTileAtmosphere(this MapIndices indices, GridId gridId)
|
||||
@@ -43,14 +45,16 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
|
||||
public static bool TryGetTileAtmosphere(this MapIndices indices, GridId gridId,
|
||||
[NotNullWhen(true)] out TileAtmosphere atmosphere)
|
||||
[MaybeNullWhen(false)] out TileAtmosphere atmosphere)
|
||||
{
|
||||
return (atmosphere = indices.GetTileAtmosphere(gridId)!) != default;
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(atmosphere = indices.GetTileAtmosphere(gridId)!, default);
|
||||
}
|
||||
|
||||
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [NotNullWhen(true)] out GasMixture air)
|
||||
public static bool TryGetTileAir(this MapIndices indices, GridId gridId, [MaybeNullWhen(false)] out GasMixture air)
|
||||
{
|
||||
return !(air = indices.GetTileAir(gridId)!).Equals(default);
|
||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
return !Equals(air = indices.GetTileAir(gridId)!, default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
74
Content.Server/Atmos/GasSprayerComponent.cs
Normal file
74
Content.Server/Atmos/GasSprayerComponent.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Pointing;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
|
||||
namespace Content.Server.Atmos
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GasSprayerComponent : Component, IAfterInteract
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
|
||||
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
|
||||
#pragma warning restore 649
|
||||
|
||||
//TODO: create a function that can create a gas based on a solution mix
|
||||
public override string Name => "GasSprayer";
|
||||
|
||||
private string _spraySound;
|
||||
private string _sprayType;
|
||||
private string _fuelType;
|
||||
private string _fuelName;
|
||||
private int _fuelCost;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _spraySound, "spraySound", string.Empty);
|
||||
serializer.DataField(ref _sprayType, "sprayType", string.Empty);
|
||||
serializer.DataField(ref _fuelType, "fuelType", string.Empty);
|
||||
serializer.DataField(ref _fuelName, "fuelName", "fuel");
|
||||
serializer.DataField(ref _fuelCost, "fuelCost", 50);
|
||||
}
|
||||
|
||||
public void AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out SolutionComponent tank))
|
||||
return;
|
||||
|
||||
if (tank.Solution.GetReagentQuantity(_fuelType) == 0)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner, eventArgs.User,
|
||||
Loc.GetString("{0:theName} is out of {1}!", Owner, _fuelName));
|
||||
}
|
||||
else
|
||||
{
|
||||
tank.TryRemoveReagent(_fuelType, ReagentUnit.New(_fuelCost));
|
||||
|
||||
var playerPos = eventArgs.User.Transform.GridPosition;
|
||||
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;
|
||||
playerPos.Offset(direction/2);
|
||||
|
||||
var spray = _serverEntityManager.SpawnEntity(_sprayType, playerPos);
|
||||
spray.GetComponent<AppearanceComponent>()
|
||||
.SetData(ExtinguisherVisuals.Rotation, direction.ToAngle().Degrees);
|
||||
spray.GetComponent<GasVaporComponent>().StartMove(direction, 5);
|
||||
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity(_spraySound, Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
Content.Server/Atmos/GasVaporComponent.cs
Normal file
120
Content.Server/Atmos/GasVaporComponent.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using Content.Shared.Physics;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Atmos;
|
||||
|
||||
namespace Content.Server.Atmos
|
||||
{
|
||||
[RegisterComponent]
|
||||
class GasVaporComponent : Component, ICollideBehavior, IGasMixtureHolder
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
public override string Name => "GasVapor";
|
||||
|
||||
[ViewVariables] public GasMixture Air { get; set; }
|
||||
|
||||
private bool _running;
|
||||
private Vector2 _direction;
|
||||
private float _velocity;
|
||||
private float _disspateTimer = 0;
|
||||
private float _dissipationInterval;
|
||||
private Gas _gas;
|
||||
private float _gasVolume;
|
||||
private float _gasTemperature;
|
||||
private float _gasAmount;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Air = new GasMixture(_gasVolume){Temperature = _gasTemperature};
|
||||
Air.SetMoles(_gas,_gasAmount);
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataField(ref _dissipationInterval, "dissipationInterval", 1);
|
||||
serializer.DataField(ref _gas, "gas", Gas.WaterVapor);
|
||||
serializer.DataField(ref _gasVolume, "gasVolume", 200);
|
||||
serializer.DataField(ref _gasTemperature, "gasTemperature", Atmospherics.T20C);
|
||||
serializer.DataField(ref _gasAmount, "gasAmount", 20);
|
||||
}
|
||||
|
||||
public void StartMove(Vector2 dir, float velocity)
|
||||
{
|
||||
_running = true;
|
||||
_direction = dir;
|
||||
_velocity = velocity;
|
||||
|
||||
if (Owner.TryGetComponent(out ICollidableComponent collidable))
|
||||
{
|
||||
var controller = collidable.EnsureController<GasVaporController>();
|
||||
controller.Move(_direction, _velocity);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (!_running)
|
||||
return;
|
||||
|
||||
if (Owner.TryGetComponent(out ICollidableComponent collidable))
|
||||
{
|
||||
var worldBounds = collidable.WorldAABB;
|
||||
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
|
||||
var tiles = mapGrid.GetTilesIntersecting(worldBounds);
|
||||
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
var pos = tile.GridIndices.ToGridCoordinates(_mapManager, tile.GridIndex);
|
||||
var atmos = AtmosHelpers.GetTileAtmosphere(pos);
|
||||
|
||||
if (atmos.Air == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (atmos.Air.React(this) != ReactionResult.NoReaction)
|
||||
{
|
||||
Owner.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_disspateTimer += frameTime;
|
||||
if (_disspateTimer > _dissipationInterval)
|
||||
{
|
||||
Air.SetMoles(_gas, Air.TotalMoles/2 );
|
||||
}
|
||||
|
||||
if (Air.TotalMoles < 1)
|
||||
{
|
||||
Owner.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
void ICollideBehavior.CollideWith(IEntity collidedWith)
|
||||
{
|
||||
// Check for collision with a impassable object (e.g. wall) and stop
|
||||
if (collidedWith.TryGetComponent(out ICollidableComponent collidable) &&
|
||||
(collidable.CollisionLayer & (int) CollisionGroup.Impassable) != 0 &&
|
||||
collidable.Hard &&
|
||||
Owner.TryGetComponent(out ICollidableComponent coll))
|
||||
{
|
||||
var controller = coll.EnsureController<GasVaporController>();
|
||||
controller.Stop();
|
||||
Owner.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Atmos
|
||||
/// State for the fire sprite.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int State;
|
||||
public byte State;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Runtime.CompilerServices;
|
||||
using Content.Server.Atmos.Reactions;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.EntitySystems.Atmos;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Audio;
|
||||
@@ -332,32 +333,40 @@ namespace Content.Server.Atmos
|
||||
var tile = tiles[i];
|
||||
tile._tileAtmosInfo.FastDone = true;
|
||||
if (!(tile._tileAtmosInfo.MoleDelta > 0)) continue;
|
||||
var eligibleDirections = new List<Direction>();
|
||||
var amtEligibleAdj = 0;
|
||||
var eligibleDirections = ArrayPool<Direction>.Shared.Rent(4);
|
||||
var eligibleDirectionCount = 0;
|
||||
foreach (var direction in Cardinal)
|
||||
{
|
||||
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||
|
||||
// skip anything that isn't part of our current processing block. Original one didn't do this unfortunately, which probably cause some massive lag.
|
||||
// skip anything that isn't part of our current processing block.
|
||||
if (tile2._tileAtmosInfo.FastDone || tile2._tileAtmosInfo.LastQueueCycle != queueCycle)
|
||||
continue;
|
||||
|
||||
eligibleDirections.Add(direction);
|
||||
amtEligibleAdj++;
|
||||
eligibleDirections[eligibleDirectionCount++] = direction;
|
||||
}
|
||||
|
||||
if (amtEligibleAdj <= 0)
|
||||
if (eligibleDirectionCount <= 0)
|
||||
continue; // Oof we've painted ourselves into a corner. Bad luck. Next part will handle this.
|
||||
|
||||
var molesToMove = tile._tileAtmosInfo.MoleDelta / amtEligibleAdj;
|
||||
var molesToMove = tile._tileAtmosInfo.MoleDelta / eligibleDirectionCount;
|
||||
foreach (var direction in Cardinal)
|
||||
{
|
||||
if (eligibleDirections.Contains(direction) ||
|
||||
!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||
var hasDirection = false;
|
||||
for (var j = 0; j < eligibleDirectionCount; j++)
|
||||
{
|
||||
if (eligibleDirections[j] != direction) continue;
|
||||
hasDirection = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasDirection || !tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||
tile.AdjustEqMovement(direction, molesToMove);
|
||||
tile._tileAtmosInfo.MoleDelta -= molesToMove;
|
||||
tile2._tileAtmosInfo.MoleDelta += molesToMove;
|
||||
}
|
||||
|
||||
ArrayPool<Direction>.Shared.Return(eligibleDirections);
|
||||
}
|
||||
|
||||
giverTilesLength = 0;
|
||||
@@ -446,7 +455,7 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(queue, true);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -516,7 +525,7 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(queue, true);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(queue);
|
||||
}
|
||||
|
||||
for (var i = 0; i < tileCount; i++)
|
||||
@@ -537,9 +546,9 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
}
|
||||
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(tiles, true);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(giverTiles, true);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(takerTiles, true);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(tiles);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(giverTiles);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(takerTiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +746,7 @@ namespace Content.Server.Atmos
|
||||
}
|
||||
else
|
||||
{
|
||||
Hotspot.State = Hotspot.Volume > Atmospherics.CellVolume * 0.4f ? 2 : 1;
|
||||
Hotspot.State = (byte) (Hotspot.Volume > Atmospherics.CellVolume * 0.4f ? 2 : 1);
|
||||
}
|
||||
|
||||
if (Hotspot.Temperature > MaxFireTemperatureSustained)
|
||||
@@ -925,16 +934,22 @@ namespace Content.Server.Atmos
|
||||
public void ExplosivelyDepressurize(int cycleNum)
|
||||
{
|
||||
if (Air == null) return;
|
||||
|
||||
const int limit = Atmospherics.ZumosTileLimit;
|
||||
|
||||
var totalGasesRemoved = 0f;
|
||||
var queueCycle = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
||||
var tiles = new List<TileAtmosphere>();
|
||||
var spaceTiles = new List<TileAtmosphere>();
|
||||
tiles.Add(this);
|
||||
var tiles = ArrayPool<TileAtmosphere>.Shared.Rent(limit);
|
||||
var spaceTiles = ArrayPool<TileAtmosphere>.Shared.Rent(limit);
|
||||
|
||||
var tileCount = 0;
|
||||
var spaceTileCount = 0;
|
||||
|
||||
tiles[tileCount++] = this;
|
||||
|
||||
ResetTileAtmosInfo();
|
||||
_tileAtmosInfo.LastQueueCycle = queueCycle;
|
||||
|
||||
var tileCount = 1;
|
||||
for (var i = 0; i < tileCount; i++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
@@ -942,40 +957,44 @@ namespace Content.Server.Atmos
|
||||
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
||||
if (tile.Air.Immutable)
|
||||
{
|
||||
spaceTiles.Add(tile);
|
||||
spaceTiles[spaceTileCount++] = tile;
|
||||
tile.PressureSpecificTarget = tile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i > Atmospherics.ZumosTileLimit) continue;
|
||||
foreach (var direction in Cardinal)
|
||||
{
|
||||
if (!tile._adjacentTiles.TryGetValue(direction, out var tile2)) continue;
|
||||
if (tile2?.Air == null) continue;
|
||||
if (tile2.Air == null) continue;
|
||||
if (tile2._tileAtmosInfo.LastQueueCycle == queueCycle) continue;
|
||||
|
||||
tile.ConsiderFirelocks(tile2);
|
||||
if (tile._adjacentTiles[direction]?.Air != null)
|
||||
{
|
||||
tile2.ResetTileAtmosInfo();
|
||||
tile2._tileAtmosInfo.LastQueueCycle = queueCycle;
|
||||
tiles.Add(tile2);
|
||||
tileCount++;
|
||||
}
|
||||
|
||||
// The firelocks might have closed on us.
|
||||
if (tile._adjacentTiles[direction]?.Air == null) continue;
|
||||
tile2.ResetTileAtmosInfo();
|
||||
tile2._tileAtmosInfo.LastQueueCycle = queueCycle;
|
||||
tiles[tileCount++] = tile2;
|
||||
}
|
||||
}
|
||||
|
||||
if (tileCount >= limit || spaceTileCount >= limit)
|
||||
break;
|
||||
}
|
||||
|
||||
var queueCycleSlow = ++_gridAtmosphereComponent.EqualizationQueueCycleControl;
|
||||
var progressionOrder = new List<TileAtmosphere>();
|
||||
foreach (var tile in spaceTiles)
|
||||
var progressionOrder = ArrayPool<TileAtmosphere>.Shared.Rent(limit * 2);
|
||||
var progressionCount = 0;
|
||||
|
||||
for (var i = 0; i < spaceTileCount; i++)
|
||||
{
|
||||
progressionOrder.Add(tile);
|
||||
var tile = spaceTiles[i];
|
||||
progressionOrder[progressionCount++] = tile;
|
||||
tile._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
||||
tile._tileAtmosInfo.CurrentTransferDirection = Direction.Invalid;
|
||||
}
|
||||
|
||||
var progressionCount = progressionOrder.Count;
|
||||
for (int i = 0; i < progressionCount; i++)
|
||||
for (var i = 0; i < progressionCount; i++)
|
||||
{
|
||||
var tile = progressionOrder[i];
|
||||
foreach (var direction in Cardinal)
|
||||
@@ -988,8 +1007,7 @@ namespace Content.Server.Atmos
|
||||
tile2._tileAtmosInfo.CurrentTransferAmount = 0;
|
||||
tile2.PressureSpecificTarget = tile.PressureSpecificTarget;
|
||||
tile2._tileAtmosInfo.LastSlowQueueCycle = queueCycleSlow;
|
||||
progressionOrder.Add(tile2);
|
||||
progressionCount++;
|
||||
progressionOrder[progressionCount++] = tile2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,6 +1035,10 @@ namespace Content.Server.Atmos
|
||||
tile.UpdateVisuals();
|
||||
tile.HandleDecompressionFloorRip(sum);
|
||||
}
|
||||
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(tiles);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(spaceTiles);
|
||||
ArrayPool<TileAtmosphere>.Shared.Return(progressionOrder);
|
||||
}
|
||||
|
||||
private void HandleDecompressionFloorRip(float sum)
|
||||
@@ -1029,7 +1051,6 @@ namespace Content.Server.Atmos
|
||||
private void ConsiderFirelocks(TileAtmosphere other)
|
||||
{
|
||||
// TODO ATMOS firelocks!
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void React()
|
||||
|
||||
Reference in New Issue
Block a user