Radiation rework (#10970)

This commit is contained in:
Alex Evgrashin
2022-10-11 05:09:10 +02:00
committed by GitHub
parent 667fc1970d
commit 7d882f22c9
34 changed files with 1010 additions and 46 deletions

View File

@@ -1,3 +1,5 @@
namespace Content.Shared.Radiation.Components;
/// <summary>
/// Irradiate all objects in range.
/// </summary>
@@ -5,16 +7,20 @@
public sealed class RadiationSourceComponent : Component
{
/// <summary>
/// How many rads per second receive irradiated object.
/// Radiation intensity in center of the source in rads per second.
/// From there radiation rays will travel over distance and loose intensity
/// when hit radiation blocker.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("radsPerSecond")]
public float RadsPerSecond = 1;
[DataField("intensity")]
public float Intensity = 1;
/// <summary>
/// Radius of radiation source.
/// Defines how fast radiation rays will loose intensity
/// over distance. The bigger the value, the shorter range
/// of radiation source will be.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("range")]
public float Range = 5f;
[DataField("slope")]
public float Slope = 0.5f;
}

View File

@@ -0,0 +1,81 @@
using Content.Shared.Radiation.Components;
using Content.Shared.Radiation.Systems;
using Robust.Shared.Serialization;
namespace Content.Shared.Radiation.Events;
/// <summary>
/// Raised on server as networked event when radiation system update its state
/// and emitted all rays from rad sources towards rad receivers.
/// Contains debug information about rad rays and all blockers on their way.
/// </summary>
/// <remarks>
/// Will be sent only to clients that activated radiation view using console command.
/// </remarks>
[Serializable, NetSerializable]
public sealed class OnRadiationOverlayUpdateEvent : EntityEventArgs
{
/// <summary>
/// Total time in milliseconds that server took to do radiation processing.
/// Exclude time of entities reacting to <see cref="OnIrradiatedEvent"/>.
/// </summary>
public readonly double ElapsedTimeMs;
/// <summary>
/// Total count of entities with <see cref="RadiationSourceComponent"/> on all maps.
/// </summary>
public readonly int SourcesCount;
/// <summary>
/// Total count of entities with radiation receiver on all maps.
/// </summary>
public readonly int ReceiversCount;
/// <summary>
/// All radiation rays that was processed by radiation system.
/// </summary>
public readonly List<RadiationRay> Rays;
public OnRadiationOverlayUpdateEvent(double elapsedTimeMs, int sourcesCount, int receiversCount, List<RadiationRay> rays)
{
ElapsedTimeMs = elapsedTimeMs;
SourcesCount = sourcesCount;
ReceiversCount = receiversCount;
Rays = rays;
}
}
/// <summary>
/// Raised when server enabled/disabled radiation debug view for client.
/// After that client will start/stop receiving <see cref="OnRadiationOverlayUpdateEvent"/>.
/// </summary>
[Serializable, NetSerializable]
public sealed class OnRadiationOverlayToggledEvent : EntityEventArgs
{
/// <summary>
/// Does debug radiation view enabled.
/// </summary>
public readonly bool IsEnabled;
public OnRadiationOverlayToggledEvent(bool isEnabled)
{
IsEnabled = isEnabled;
}
}
/// <summary>
/// Raised when grid resistance was update for radiation overlay visualization.
/// </summary>
[Serializable, NetSerializable]
public sealed class OnRadiationOverlayResistanceUpdateEvent : EntityEventArgs
{
/// <summary>
/// Key is grids uid. Values are tiles with their rad resistance.
/// </summary>
public readonly Dictionary<EntityUid, Dictionary<Vector2i, float>> Grids;
public OnRadiationOverlayResistanceUpdateEvent(Dictionary<EntityUid, Dictionary<Vector2i, float>> grids)
{
Grids = grids;
}
}

View File

@@ -0,0 +1,64 @@
using Content.Shared.Radiation.Components;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Radiation.Systems;
/// <summary>
/// Ray emitted by radiation source towards radiation receiver.
/// Contains all information about encountered radiation blockers.
/// </summary>
[Serializable, NetSerializable]
public sealed class RadiationRay
{
/// <summary>
/// Map on which source and receiver are placed.
/// </summary>
public MapId MapId;
/// <summary>
/// Uid of entity with <see cref="RadiationSourceComponent"/>.
/// </summary>
public EntityUid SourceUid;
/// <summary>
/// World coordinates of radiation source.
/// </summary>
public Vector2 Source;
/// <summary>
/// Uid of entity with radiation receiver component.
/// </summary>
public EntityUid DestinationUid;
/// <summary>
/// World coordinates of radiation receiver.
/// </summary>
public Vector2 Destination;
/// <summary>
/// How many rads intensity reached radiation receiver.
/// </summary>
public float Rads;
/// <summary>
/// Has rad ray reached destination or lost all intensity after blockers?
/// </summary>
public bool ReachedDestination => Rads > 0;
/// <summary>
/// All blockers visited by gridcast. Key is uid of grid. Values are pairs
/// of tile indices and floats with updated radiation value.
/// </summary>
/// <remarks>
/// Last tile may have negative value if ray has lost all intensity.
/// Grid traversal order isn't guaranteed.
/// </remarks>
public Dictionary<EntityUid, List<(Vector2i, float)>> Blockers = new();
public RadiationRay(MapId mapId, EntityUid sourceUid, Vector2 source,
EntityUid destinationUid, Vector2 destination, float rads)
{
MapId = mapId;
SourceUid = sourceUid;
Source = source;
DestinationUid = destinationUid;
Destination = destination;
Rads = rads;
}
}

View File

@@ -25,8 +25,8 @@ public sealed class RadiationPulseSystem : EntitySystem
}
// try to get radiation range or keep default visual range
if (TryComp<RadiationSourceComponent>(uid, out var radSource))
{
component.VisualRange = radSource.Range;
{
component.VisualRange = radSource.Intensity / radSource.Slope;
}
}
}