hopefully make salvage more reliable (#17712)

This commit is contained in:
Nemanja
2023-06-28 14:06:30 -04:00
committed by GitHub
parent 5bbe13a073
commit b6c1c34e89

View File

@@ -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<EntityUid, SalvageGridState> _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);