Radiation rework (#10970)
This commit is contained in:
@@ -1,52 +1,46 @@
|
||||
using Content.Shared.Radiation.Events;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Radiation.Systems;
|
||||
|
||||
public sealed class RadiationSystem : EntitySystem
|
||||
public sealed partial class RadiationSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
|
||||
private const float RadiationCooldown = 1.0f;
|
||||
private float _accumulator;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeCvars();
|
||||
InitRadBlocking();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
UnsubscribeCvars();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
_accumulator += frameTime;
|
||||
if (_accumulator < GridcastUpdateRate)
|
||||
return;
|
||||
|
||||
while (_accumulator > RadiationCooldown)
|
||||
{
|
||||
_accumulator -= RadiationCooldown;
|
||||
|
||||
// All code here runs effectively every RadiationCooldown seconds, so use that as the "frame time".
|
||||
foreach (var comp in EntityManager.EntityQuery<RadiationSourceComponent>())
|
||||
{
|
||||
var ent = comp.Owner;
|
||||
if (Deleted(ent))
|
||||
continue;
|
||||
|
||||
var cords = Transform(ent).MapPosition;
|
||||
IrradiateRange(cords, comp.Range, comp.RadsPerSecond, RadiationCooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void IrradiateRange(MapCoordinates coordinates, float range, float radsPerSecond, float time)
|
||||
{
|
||||
var lookUp = _lookup.GetEntitiesInRange(coordinates, range);
|
||||
foreach (var uid in lookUp)
|
||||
{
|
||||
if (Deleted(uid))
|
||||
continue;
|
||||
|
||||
IrradiateEntity(uid, radsPerSecond, time);
|
||||
}
|
||||
UpdateGridcast();
|
||||
UpdateResistanceDebugOverlay();
|
||||
_accumulator = 0f;
|
||||
}
|
||||
|
||||
public void IrradiateEntity(EntityUid uid, float radsPerSecond, float time)
|
||||
{
|
||||
var msg = new OnIrradiatedEvent(time, radsPerSecond);
|
||||
RaiseLocalEvent(uid, msg, true);
|
||||
RaiseLocalEvent(uid, msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user