Scale radiation intensity with stack size (#19869)

This commit is contained in:
deltanedas
2023-09-07 22:59:08 +01:00
committed by GitHub
parent ad9c4433f4
commit 7e77720f01
2 changed files with 15 additions and 8 deletions

View File

@@ -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<RadiationSourceComponent, TransformComponent>();
var sources = EntityQueryEnumerator<RadiationSourceComponent, TransformComponent>();
var destinations = EntityQuery<RadiationReceiverComponent, TransformComponent>();
var resistanceQuery = GetEntityQuery<RadiationGridResistanceComponent>();
var transformQuery = GetEntityQuery<TransformComponent>();
var gridQuery = GetEntityQuery<MapGridComponent>();
var stackQuery = GetEntityQuery<StackComponent>();
// 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;

View File

@@ -415,7 +415,7 @@
- bananium
- bananium_1
- type: RadiationSource
intensity: 0.3
intensity: 0.1
- type: FlavorProfile
flavors:
- banana