From 7e77720f01b627244cf4ccd503d2572a0618a714 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Thu, 7 Sep 2023 22:59:08 +0100 Subject: [PATCH] Scale radiation intensity with stack size (#19869) --- .../Systems/RadiationSystem.GridCast.cs | 21 ++++++++++++------- .../Entities/Objects/Materials/materials.yml | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Content.Server/Radiation/Systems/RadiationSystem.GridCast.cs b/Content.Server/Radiation/Systems/RadiationSystem.GridCast.cs index c4a6a67033..8edb6c1455 100644 --- a/Content.Server/Radiation/Systems/RadiationSystem.GridCast.cs +++ b/Content.Server/Radiation/Systems/RadiationSystem.GridCast.cs @@ -3,6 +3,7 @@ using Content.Server.Radiation.Components; using Content.Server.Radiation.Events; using Content.Shared.Radiation.Components; using Content.Shared.Radiation.Systems; +using Content.Shared.Stacks; using Robust.Shared.Collections; using Robust.Shared.Map; using Robust.Shared.Map.Components; @@ -14,6 +15,8 @@ namespace Content.Server.Radiation.Systems; // main algorithm that fire radiation rays to target public partial class RadiationSystem { + [Dependency] private readonly SharedStackSystem _stack = default!; + private void UpdateGridcast() { // should we save debug information into rays? @@ -23,19 +26,20 @@ public partial class RadiationSystem var stopwatch = new Stopwatch(); stopwatch.Start(); - var sources = EntityQuery(); + var sources = EntityQueryEnumerator(); var destinations = EntityQuery(); var resistanceQuery = GetEntityQuery(); var transformQuery = GetEntityQuery(); var gridQuery = GetEntityQuery(); + var stackQuery = GetEntityQuery(); // precalculate world positions for each source // so we won't need to calc this in cycle over and over again - var sourcesData = new ValueList<(RadiationSourceComponent, TransformComponent, Vector2)>(); - foreach (var (source, sourceTrs) in sources) + var sourcesData = new ValueList<(EntityUid, RadiationSourceComponent, TransformComponent, Vector2)>(); + while (sources.MoveNext(out var uid, out var source, out var sourceTrs)) { var worldPos = _transform.GetWorldPosition(sourceTrs, transformQuery); - var data = (source, sourceTrs, worldPos); + var data = (uid, source, sourceTrs, worldPos); sourcesData.Add(data); } @@ -47,12 +51,15 @@ public partial class RadiationSystem var destWorld = _transform.GetWorldPosition(destTrs, transformQuery); var rads = 0f; - foreach (var (source, sourceTrs, sourceWorld) in sourcesData) + foreach (var (uid, source, sourceTrs, sourceWorld) in sourcesData) { + stackQuery.TryGetComponent(uid, out var stack); + var intensity = source.Intensity * _stack.GetCount(uid, stack); + // send ray towards destination entity - var ray = Irradiate(sourceTrs.Owner, sourceTrs, sourceWorld, + var ray = Irradiate(uid, sourceTrs, sourceWorld, destTrs.Owner, destTrs, destWorld, - source.Intensity, source.Slope, saveVisitedTiles, resistanceQuery, transformQuery, gridQuery); + intensity, source.Slope, saveVisitedTiles, resistanceQuery, transformQuery, gridQuery); if (ray == null) continue; diff --git a/Resources/Prototypes/Entities/Objects/Materials/materials.yml b/Resources/Prototypes/Entities/Objects/Materials/materials.yml index 59bfb21373..35b90996fa 100644 --- a/Resources/Prototypes/Entities/Objects/Materials/materials.yml +++ b/Resources/Prototypes/Entities/Objects/Materials/materials.yml @@ -415,7 +415,7 @@ - bananium - bananium_1 - type: RadiationSource - intensity: 0.3 + intensity: 0.1 - type: FlavorProfile flavors: - banana -- 2.51.2