From b6c1c34e89e599db0d5719cc348ebac2f54b38cc Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:06:30 -0400 Subject: [PATCH] hopefully make salvage more reliable (#17712) --- Content.Server/Salvage/SalvageSystem.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Content.Server/Salvage/SalvageSystem.cs b/Content.Server/Salvage/SalvageSystem.cs index 2e971d6014..d3cff13629 100644 --- a/Content.Server/Salvage/SalvageSystem.cs +++ b/Content.Server/Salvage/SalvageSystem.cs @@ -19,7 +19,6 @@ using Content.Server.Parallax; using Content.Server.Procedural; using Content.Server.Shuttles.Systems; using Content.Server.Station.Systems; -using Content.Server.Worldgen.Systems; using Content.Shared.CCVar; using Content.Shared.Random; using Content.Shared.Random.Helpers; @@ -51,7 +50,7 @@ namespace Content.Server.Salvage [Dependency] private readonly StationSystem _station = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; - private const int SalvageLocationPlaceAttempts = 16; + private const int SalvageLocationPlaceAttempts = 25; // TODO: This is probably not compatible with multi-station private readonly Dictionary _salvageGridStates = new(); @@ -307,8 +306,13 @@ namespace Content.Server.Salvage private bool TryGetSalvagePlacementLocation(EntityUid uid, SalvageMagnetComponent component, Box2 bounds, out MapCoordinates coords, out Angle angle) { var xform = Transform(uid); + var smallestBound = (bounds.Height < bounds.Width + ? bounds.Height + : bounds.Width) / 2f; + var maxRadius = component.OffsetRadiusMax + smallestBound; + angle = Angle.Zero; - coords = new EntityCoordinates(uid, new Vector2(0, -component.OffsetRadiusMax)).ToMap(EntityManager, _transform); + coords = new EntityCoordinates(uid, new Vector2(0, -maxRadius)).ToMap(EntityManager, _transform); if (xform.GridUid is not null) angle = _transform.GetWorldRotation(Transform(xform.GridUid.Value)); @@ -316,8 +320,8 @@ namespace Content.Server.Salvage for (var i = 0; i < SalvageLocationPlaceAttempts; i++) { var randomRadius = _random.NextFloat(component.OffsetRadiusMax); - var randomOffset = _random.NextAngle().ToWorldVec() * randomRadius; - var finalCoords = coords.Offset(randomOffset); + var randomOffset = _random.NextAngle().ToVec() * randomRadius; + var finalCoords = new MapCoordinates(coords.Position + randomOffset, coords.MapId); var box2 = Box2.CenteredAround(finalCoords.Position, bounds.Size); var box2Rot = new Box2Rotated(box2, angle, finalCoords.Position);