1
0

RadiationRay.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Numerics;
  2. using Content.Shared.Radiation.Components;
  3. using Robust.Shared.Map;
  4. using Robust.Shared.Serialization;
  5. namespace Content.Shared.Radiation.Systems;
  6. /// <summary>
  7. /// Ray emitted by radiation source towards radiation receiver.
  8. /// Contains all information about encountered radiation blockers.
  9. /// </summary>
  10. public struct RadiationRay(
  11. MapId mapId,
  12. EntityUid sourceUid,
  13. Vector2 source,
  14. EntityUid destinationUid,
  15. Vector2 destination,
  16. float rads)
  17. {
  18. /// <summary>
  19. /// Map on which source and receiver are placed.
  20. /// </summary>
  21. public MapId MapId = mapId;
  22. /// <summary>
  23. /// Uid of entity with <see cref="RadiationSourceComponent"/>.
  24. /// </summary>
  25. public EntityUid SourceUid = sourceUid;
  26. /// <summary>
  27. /// World coordinates of radiation source.
  28. /// </summary>
  29. public Vector2 Source = source;
  30. /// <summary>
  31. /// Uid of entity with radiation receiver component.
  32. /// </summary>
  33. public EntityUid DestinationUid = destinationUid;
  34. /// <summary>
  35. /// World coordinates of radiation receiver.
  36. /// </summary>
  37. public Vector2 Destination = destination;
  38. /// <summary>
  39. /// How many rads intensity reached radiation receiver.
  40. /// </summary>
  41. public float Rads = rads;
  42. /// <summary>
  43. /// Has rad ray reached destination or lost all intensity after blockers?
  44. /// </summary>
  45. public bool ReachedDestination => Rads > 0;
  46. /// <summary>
  47. /// All blockers visited by gridcast, used for debug overlays. Key is uid of grid. Values are pairs
  48. /// of tile indices and floats with updated radiation value.
  49. /// </summary>
  50. /// <remarks>
  51. /// Last tile may have negative value if ray has lost all intensity.
  52. /// Grid traversal order isn't guaranteed.
  53. /// </remarks>
  54. public Dictionary<NetEntity, List<(Vector2i, float)>>? Blockers;
  55. }
  56. // Variant of RadiationRay that uses NetEntities.
  57. [Serializable, NetSerializable]
  58. public readonly record struct DebugRadiationRay(
  59. MapId MapId,
  60. NetEntity SourceUid,
  61. Vector2 Source,
  62. NetEntity DestinationUid,
  63. Vector2 Destination,
  64. float Rads,
  65. Dictionary<NetEntity, List<(Vector2i, float)>> Blockers)
  66. {
  67. public bool ReachedDestination => Rads > 0;
  68. }