Remove 700 usages of Component.Owner (#21100)
This commit is contained in:
@@ -32,54 +32,54 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
||||
SubscribeLocalEvent<RadiationSystemUpdatedEvent>(OnUpdate);
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, GeigerComponent component, ActivateInWorldEvent args)
|
||||
private void OnActivate(Entity<GeigerComponent> geiger, ref ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || component.AttachedToSuit)
|
||||
if (args.Handled || geiger.Comp.AttachedToSuit)
|
||||
return;
|
||||
args.Handled = true;
|
||||
|
||||
SetEnabled(uid, component, !component.IsEnabled);
|
||||
SetEnabled(geiger, !geiger.Comp.IsEnabled);
|
||||
}
|
||||
|
||||
private void OnEquipped(EntityUid uid, GeigerComponent component, GotEquippedEvent args)
|
||||
private void OnEquipped(Entity<GeigerComponent> geiger, ref GotEquippedEvent args)
|
||||
{
|
||||
if (component.AttachedToSuit)
|
||||
SetEnabled(uid, component, true);
|
||||
SetUser(component, args.Equipee);
|
||||
if (geiger.Comp.AttachedToSuit)
|
||||
SetEnabled(geiger, true);
|
||||
SetUser(geiger, args.Equipee);
|
||||
}
|
||||
|
||||
private void OnEquippedHand(EntityUid uid, GeigerComponent component, GotEquippedHandEvent args)
|
||||
private void OnEquippedHand(Entity<GeigerComponent> geiger, ref GotEquippedHandEvent args)
|
||||
{
|
||||
if (component.AttachedToSuit)
|
||||
if (geiger.Comp.AttachedToSuit)
|
||||
return;
|
||||
|
||||
SetUser(component, args.User);
|
||||
SetUser(geiger, args.User);
|
||||
}
|
||||
|
||||
private void OnUnequipped(EntityUid uid, GeigerComponent component, GotUnequippedEvent args)
|
||||
private void OnUnequipped(Entity<GeigerComponent> geiger, ref GotUnequippedEvent args)
|
||||
{
|
||||
if (component.AttachedToSuit)
|
||||
SetEnabled(uid, component, false);
|
||||
SetUser(component, null);
|
||||
if (geiger.Comp.AttachedToSuit)
|
||||
SetEnabled(geiger, false);
|
||||
SetUser(geiger, null);
|
||||
}
|
||||
|
||||
private void OnUnequippedHand(EntityUid uid, GeigerComponent component, GotUnequippedHandEvent args)
|
||||
private void OnUnequippedHand(Entity<GeigerComponent> geiger, ref GotUnequippedHandEvent args)
|
||||
{
|
||||
if (component.AttachedToSuit)
|
||||
if (geiger.Comp.AttachedToSuit)
|
||||
return;
|
||||
|
||||
SetUser(component, null);
|
||||
SetUser(geiger, null);
|
||||
}
|
||||
|
||||
private void OnUpdate(RadiationSystemUpdatedEvent ev)
|
||||
{
|
||||
// update only active geiger counters
|
||||
// deactivated shouldn't have rad receiver component
|
||||
var query = EntityQuery<GeigerComponent, RadiationReceiverComponent>();
|
||||
foreach (var (geiger, receiver) in query)
|
||||
var query = EntityQueryEnumerator<GeigerComponent, RadiationReceiverComponent>();
|
||||
while (query.MoveNext(out var uid, out var geiger, out var receiver))
|
||||
{
|
||||
var rads = receiver.CurrentRadiation;
|
||||
SetCurrentRadiation(geiger.Owner, geiger, rads);
|
||||
SetCurrentRadiation(uid, geiger, rads);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,21 +101,22 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
||||
UpdateSound(uid, component);
|
||||
}
|
||||
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void SetUser(GeigerComponent component, EntityUid? user)
|
||||
private void SetUser(Entity<GeigerComponent> component, EntityUid? user)
|
||||
{
|
||||
if (component.User == user)
|
||||
if (component.Comp.User == user)
|
||||
return;
|
||||
|
||||
component.User = user;
|
||||
component.Comp.User = user;
|
||||
Dirty(component);
|
||||
UpdateSound(component.Owner, component);
|
||||
UpdateSound(component, component);
|
||||
}
|
||||
|
||||
private void SetEnabled(EntityUid uid, GeigerComponent component, bool isEnabled)
|
||||
private void SetEnabled(Entity<GeigerComponent> geiger, bool isEnabled)
|
||||
{
|
||||
var component = geiger.Comp;
|
||||
if (component.IsEnabled == isEnabled)
|
||||
return;
|
||||
|
||||
@@ -126,11 +127,11 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
||||
component.DangerLevel = GeigerDangerLevel.None;
|
||||
}
|
||||
|
||||
_radiation.SetCanReceive(uid, isEnabled);
|
||||
_radiation.SetCanReceive(geiger, isEnabled);
|
||||
|
||||
UpdateAppearance(uid, component);
|
||||
UpdateSound(uid, component);
|
||||
Dirty(component);
|
||||
UpdateAppearance(geiger, component);
|
||||
UpdateSound(geiger, component);
|
||||
Dirty(geiger, component);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, GeigerComponent? component = null,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Server.Radiation.Components;
|
||||
using Content.Server.Radiation.Events;
|
||||
@@ -9,7 +10,6 @@ using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Radiation.Systems;
|
||||
|
||||
@@ -31,7 +31,7 @@ public partial class RadiationSystem
|
||||
stopwatch.Start();
|
||||
|
||||
var sources = EntityQueryEnumerator<RadiationSourceComponent, TransformComponent>();
|
||||
var destinations = EntityQuery<RadiationReceiverComponent, TransformComponent>();
|
||||
var destinations = EntityQueryEnumerator<RadiationReceiverComponent, TransformComponent>();
|
||||
var resistanceQuery = GetEntityQuery<RadiationGridResistanceComponent>();
|
||||
var transformQuery = GetEntityQuery<TransformComponent>();
|
||||
var gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
@@ -51,8 +51,8 @@ public partial class RadiationSystem
|
||||
|
||||
// trace all rays from rad source to rad receivers
|
||||
var rays = new List<RadiationRay>();
|
||||
var receiversTotalRads = new ValueList<(RadiationReceiverComponent, float)>();
|
||||
foreach (var (dest, destTrs) in destinations)
|
||||
var receiversTotalRads = new ValueList<(Entity<RadiationReceiverComponent>, float)>();
|
||||
while (destinations.MoveNext(out var destUid, out var dest, out var destTrs))
|
||||
{
|
||||
var destWorld = _transform.GetWorldPosition(destTrs, transformQuery);
|
||||
|
||||
@@ -64,7 +64,7 @@ public partial class RadiationSystem
|
||||
|
||||
// send ray towards destination entity
|
||||
var ray = Irradiate(uid, sourceTrs, sourceWorld,
|
||||
destTrs.Owner, destTrs, destWorld,
|
||||
destUid, destTrs, destWorld,
|
||||
intensity, source.Slope, saveVisitedTiles, resistanceQuery, transformQuery, gridQuery);
|
||||
if (ray == null)
|
||||
continue;
|
||||
@@ -78,9 +78,9 @@ public partial class RadiationSystem
|
||||
}
|
||||
|
||||
// Apply modifier if the destination entity is hidden within a radiation blocking container
|
||||
rads = GetAdjustedRadiationIntensity(dest.Owner, rads);
|
||||
rads = GetAdjustedRadiationIntensity(destUid, rads);
|
||||
|
||||
receiversTotalRads.Add((dest, rads));
|
||||
receiversTotalRads.Add(((destUid, dest), rads));
|
||||
}
|
||||
|
||||
// update information for debug overlay
|
||||
@@ -94,11 +94,11 @@ public partial class RadiationSystem
|
||||
{
|
||||
// update radiation value of receiver
|
||||
// if no radiation rays reached target, that will set it to 0
|
||||
receiver.CurrentRadiation = rads;
|
||||
receiver.Comp.CurrentRadiation = rads;
|
||||
|
||||
// also send an event with combination of total rad
|
||||
if (rads > 0)
|
||||
IrradiateEntity(receiver.Owner, rads, GridcastUpdateRate);
|
||||
IrradiateEntity(receiver, rads, GridcastUpdateRate);
|
||||
}
|
||||
|
||||
// raise broadcast event that radiation system has updated
|
||||
@@ -145,20 +145,21 @@ public partial class RadiationSystem
|
||||
{
|
||||
if (!gridQuery.TryGetComponent(sourceTrs.GridUid.Value, out var gridComponent))
|
||||
return ray;
|
||||
return Gridcast(gridComponent, ray, saveVisitedTiles, resistanceQuery, sourceTrs, destTrs, transformQuery.GetComponent(sourceTrs.GridUid.Value));
|
||||
return Gridcast((sourceTrs.GridUid.Value, gridComponent), ray, saveVisitedTiles, resistanceQuery, sourceTrs, destTrs, transformQuery.GetComponent(sourceTrs.GridUid.Value));
|
||||
}
|
||||
|
||||
// lets check how many grids are between source and destination
|
||||
// do a box intersection test between target and destination
|
||||
// it's not very precise, but really cheap
|
||||
var box = Box2.FromTwoPoints(sourceWorld, destWorld);
|
||||
var grids = _mapManager.FindGridsIntersecting(mapId, box, true);
|
||||
var grids = new List<Entity<MapGridComponent>>();
|
||||
_mapManager.FindGridsIntersecting(mapId, box, ref grids, true);
|
||||
|
||||
// gridcast through each grid and try to hit some radiation blockers
|
||||
// the ray will be updated with each grid that has some blockers
|
||||
foreach (var grid in grids)
|
||||
{
|
||||
ray = Gridcast(grid, ray, saveVisitedTiles, resistanceQuery, sourceTrs, destTrs, transformQuery.GetComponent(grid.Owner));
|
||||
ray = Gridcast(grid, ray, saveVisitedTiles, resistanceQuery, sourceTrs, destTrs, transformQuery.GetComponent(grid));
|
||||
|
||||
// looks like last grid blocked all radiation
|
||||
// we can return right now
|
||||
@@ -169,7 +170,7 @@ public partial class RadiationSystem
|
||||
return ray;
|
||||
}
|
||||
|
||||
private RadiationRay Gridcast(MapGridComponent grid, RadiationRay ray, bool saveVisitedTiles,
|
||||
private RadiationRay Gridcast(Entity<MapGridComponent> grid, RadiationRay ray, bool saveVisitedTiles,
|
||||
EntityQuery<RadiationGridResistanceComponent> resistanceQuery,
|
||||
TransformComponent sourceTrs,
|
||||
TransformComponent destTrs,
|
||||
@@ -198,12 +199,12 @@ public partial class RadiationSystem
|
||||
: gridTrs.InvLocalMatrix.Transform(ray.Destination);
|
||||
|
||||
Vector2i sourceGrid = new(
|
||||
(int) Math.Floor(srcLocal.X / grid.TileSize),
|
||||
(int) Math.Floor(srcLocal.Y / grid.TileSize));
|
||||
(int) Math.Floor(srcLocal.X / grid.Comp.TileSize),
|
||||
(int) Math.Floor(srcLocal.Y / grid.Comp.TileSize));
|
||||
|
||||
Vector2i destGrid = new(
|
||||
(int) Math.Floor(dstLocal.X / grid.TileSize),
|
||||
(int) Math.Floor(dstLocal.Y / grid.TileSize));
|
||||
(int) Math.Floor(dstLocal.X / grid.Comp.TileSize),
|
||||
(int) Math.Floor(dstLocal.Y / grid.Comp.TileSize));
|
||||
|
||||
// iterate tiles in grid line from source to destination
|
||||
var line = new GridLineEnumerator(sourceGrid, destGrid);
|
||||
|
||||
Reference in New Issue
Block a user