Fluid spread refactor (#11908)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Fix undefined
This commit is contained in:
@@ -1,83 +1,14 @@
|
||||
using Content.Shared.Maps;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Directions
|
||||
namespace Content.Shared.Directions;
|
||||
|
||||
public static class SharedDirectionExtensions
|
||||
{
|
||||
public static class SharedDirectionExtensions
|
||||
public static EntityCoordinates Offset(this EntityCoordinates coordinates, Direction direction)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets random directions until none are left
|
||||
/// </summary>
|
||||
/// <returns>An enumerable of the directions.</returns>
|
||||
public static IEnumerable<Direction> RandomDirections()
|
||||
{
|
||||
var directions = new[]
|
||||
{
|
||||
Direction.East,
|
||||
Direction.SouthEast,
|
||||
Direction.South,
|
||||
Direction.SouthWest,
|
||||
Direction.West,
|
||||
Direction.NorthWest,
|
||||
Direction.North,
|
||||
Direction.NorthEast,
|
||||
};
|
||||
|
||||
var robustRandom = IoCManager.Resolve<IRobustRandom>();
|
||||
var n = directions.Length;
|
||||
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
var k = robustRandom.Next(n + 1);
|
||||
var value = directions[k];
|
||||
directions[k] = directions[n];
|
||||
directions[n] = value;
|
||||
}
|
||||
|
||||
foreach (var direction in directions)
|
||||
{
|
||||
yield return direction;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets tiles in random directions from the given one.
|
||||
/// </summary>
|
||||
/// <returns>An enumerable of the adjacent tiles.</returns>
|
||||
public static IEnumerable<TileRef> AdjacentTilesRandom(this TileRef tile, bool ignoreSpace = false)
|
||||
{
|
||||
return tile.GridPosition().AdjacentTilesRandom(ignoreSpace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets tiles in random directions from the given one.
|
||||
/// </summary>
|
||||
/// <returns>An enumerable of the adjacent tiles.</returns>
|
||||
public static IEnumerable<TileRef> AdjacentTilesRandom(this EntityCoordinates coordinates, bool ignoreSpace = false)
|
||||
{
|
||||
foreach (var direction in RandomDirections())
|
||||
{
|
||||
var adjacent = coordinates.Offset(direction).GetTileRef();
|
||||
|
||||
if (adjacent == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ignoreSpace && adjacent.Value.Tile.IsEmpty)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return adjacent.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityCoordinates Offset(this EntityCoordinates coordinates, Direction direction)
|
||||
{
|
||||
return coordinates.Offset(direction.ToVec());
|
||||
}
|
||||
return coordinates.Offset(direction.ToVec());
|
||||
}
|
||||
}
|
||||
|
||||
50
Content.Shared/Fluids/SharedPuddleDebugOverlaySystem.cs
Normal file
50
Content.Shared/Fluids/SharedPuddleDebugOverlaySystem.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Fluids;
|
||||
|
||||
public abstract class SharedPuddleDebugOverlaySystem : EntitySystem
|
||||
{
|
||||
protected const float LocalViewRange = 16;
|
||||
protected TimeSpan? NextTick = null;
|
||||
protected TimeSpan Cooldown = TimeSpan.FromSeconds(0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message for disable puddle overlay
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PuddleOverlayDisableMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Message for puddle overlay display data
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PuddleOverlayDebugMessage : EntityEventArgs
|
||||
{
|
||||
public PuddleDebugOverlayData[] OverlayData { get; }
|
||||
|
||||
public EntityUid GridUid { get; }
|
||||
|
||||
|
||||
public PuddleOverlayDebugMessage(EntityUid gridUid, PuddleDebugOverlayData[] overlayData)
|
||||
{
|
||||
GridUid = gridUid;
|
||||
OverlayData = overlayData;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public readonly struct PuddleDebugOverlayData
|
||||
{
|
||||
public readonly Vector2i Pos;
|
||||
public readonly FixedPoint2 CurrentVolume;
|
||||
|
||||
public PuddleDebugOverlayData(Vector2i pos, FixedPoint2 currentVolume)
|
||||
{
|
||||
CurrentVolume = currentVolume;
|
||||
Pos = pos;
|
||||
}
|
||||
}
|
||||
28
Content.Shared/SharedArrayExtension.cs
Normal file
28
Content.Shared/SharedArrayExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared;
|
||||
|
||||
public static class SharedArrayExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Randomizes the array mutating it in the process
|
||||
/// </summary>
|
||||
/// <param name="array">array being randomized</param>
|
||||
/// <param name="random">source of randomization</param>
|
||||
/// <typeparam name="T">type of array element</typeparam>
|
||||
public static void Shuffle<T>(this Span<T> array, IRobustRandom? random = null)
|
||||
{
|
||||
var n = array.Length;
|
||||
if (n <= 1)
|
||||
return;
|
||||
IoCManager.Resolve(ref random);
|
||||
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
var k = random.Next(n + 1);
|
||||
(array[k], array[n]) =
|
||||
(array[n], array[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,14 @@ namespace Content.Shared.Slippery
|
||||
_adminLogger.Add(LogType.Slip, LogImpact.Low,
|
||||
$"{ToPrettyString(other):mob} slipped on collision with {ToPrettyString(component.Owner):entity}");
|
||||
}
|
||||
|
||||
public void CopyConstruct(EntityUid destUid, SlipperyComponent srcSlip)
|
||||
{
|
||||
var destEvaporation = EntityManager.EnsureComponent<SlipperyComponent>(destUid);
|
||||
destEvaporation.SlipSound = srcSlip.SlipSound;
|
||||
destEvaporation.ParalyzeTime = srcSlip.ParalyzeTime;
|
||||
destEvaporation.LaunchForwardsMultiplier = srcSlip.LaunchForwardsMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -176,6 +176,20 @@ public sealed class StepTriggerSystem : EntitySystem
|
||||
component.Active = active;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor to copy initial fields from source to destination.
|
||||
/// </summary>
|
||||
/// <param name="destUid">Entity to which we copy <paramref name="srcStep"/> properties</param>
|
||||
/// <param name="srcStep">Component that contains relevant properties</param>
|
||||
public void CopyConstruct(EntityUid destUid, StepTriggerComponent srcStep)
|
||||
{
|
||||
var destTrigger = EntityManager.EnsureComponent<StepTriggerComponent>(destUid);
|
||||
destTrigger.Active = srcStep.Active;
|
||||
destTrigger.IntersectRatio = srcStep.IntersectRatio;
|
||||
destTrigger.RequiredTriggerSpeed = srcStep.RequiredTriggerSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
|
||||
Reference in New Issue
Block a user