Salvage spawning adjustments and AABBs in prototypes (#10789)
This commit is contained in:
@@ -11,13 +11,25 @@ namespace Content.Server.Salvage
|
||||
public sealed class SalvageMagnetComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Offset relative to magnet that salvage should spawn.
|
||||
/// Keep in sync with marker sprite (if any???)
|
||||
/// Offset relative to magnet used as centre of the placement circle.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offset")]
|
||||
public Vector2 Offset = Vector2.Zero; // TODO: Maybe specify a direction, and find the nearest edge of the magnets grid the salvage can fit at
|
||||
|
||||
/// <summary>
|
||||
/// Minimum distance from the offset position that will be used as a salvage's spawnpoint.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offsetRadiusMin")]
|
||||
public float OffsetRadiusMin = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum distance from the offset position that will be used as a salvage's spawnpoint.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offsetRadiusMax")]
|
||||
public float OffsetRadiusMax = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The entity attached to the magnet
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Server.Salvage
|
||||
{
|
||||
@@ -18,11 +19,11 @@ namespace Content.Server.Salvage
|
||||
public ResourcePath MapPath { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Size *from 0,0* in units of the map (used to determine if it fits)
|
||||
/// Map rectangle in world coordinates (to check if it fits)
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("size", required: true)]
|
||||
public float Size { get; } = 1.0f; // TODO: Find a way to figure out the size automatically
|
||||
[DataField("bounds", required: true)]
|
||||
public Box2 Bounds { get; } = Box2.UnitCentered;
|
||||
|
||||
/// <summary>
|
||||
/// Name for admin use
|
||||
|
||||
70
Content.Server/Salvage/SalvageRulerCommand.cs
Normal file
70
Content.Server/Salvage/SalvageRulerCommand.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
sealed class SalvageRulerCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[Dependency] private readonly IMapManager _maps = default!;
|
||||
|
||||
public string Command => "salvageruler";
|
||||
|
||||
public string Description => Loc.GetString("salvage-ruler-command-description");
|
||||
|
||||
public string Help => Loc.GetString("salvage-ruler-command-help-text", ("command",Command));
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 0)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-only-players-can-run-this-command"));
|
||||
return;
|
||||
}
|
||||
|
||||
var entity = player.AttachedEntity;
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-must-be-attached-to-entity"));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityTransform = _entities.GetComponent<TransformComponent>(entity.Value);
|
||||
var total = Box2.UnitCentered;
|
||||
var first = true;
|
||||
foreach (var mapGrid in _maps.GetAllMapGrids(entityTransform.MapID))
|
||||
{
|
||||
var aabb = mapGrid.WorldAABB;
|
||||
if (first)
|
||||
{
|
||||
total = aabb;
|
||||
}
|
||||
else
|
||||
{
|
||||
total = total.ExtendToContain(aabb.TopLeft);
|
||||
total = total.ExtendToContain(aabb.TopRight);
|
||||
total = total.ExtendToContain(aabb.BottomLeft);
|
||||
total = total.ExtendToContain(aabb.BottomRight);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
shell.WriteLine(total.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace Content.Server.Salvage
|
||||
private static readonly TimeSpan HoldTime = TimeSpan.FromMinutes(4);
|
||||
private static readonly TimeSpan DetachingTime = TimeSpan.FromSeconds(30);
|
||||
private static readonly TimeSpan CooldownTime = TimeSpan.FromMinutes(1);
|
||||
private static readonly int SalvageLocationPlaceAttempts = 16;
|
||||
|
||||
// TODO: This is probably not compatible with multi-station
|
||||
private readonly Dictionary<GridId, SalvageGridState> _salvageGridStates = new();
|
||||
@@ -239,7 +240,6 @@ namespace Content.Server.Salvage
|
||||
private bool SpawnSalvage(SalvageMagnetComponent component)
|
||||
{
|
||||
TryGetSalvagePlacementLocation(component, out var spl, out var spAngle);
|
||||
SalvageMapPrototype? map = null;
|
||||
|
||||
var forcedSalvage = _configurationManager.GetCVar<string>(CCVars.SalvageForced);
|
||||
List<SalvageMapPrototype> allSalvageMaps;
|
||||
@@ -250,28 +250,40 @@ namespace Content.Server.Salvage
|
||||
else
|
||||
{
|
||||
allSalvageMaps = new();
|
||||
if (_prototypeManager.TryIndex<SalvageMapPrototype>(forcedSalvage, out map))
|
||||
if (_prototypeManager.TryIndex<SalvageMapPrototype>(forcedSalvage, out var forcedMap))
|
||||
{
|
||||
allSalvageMaps.Add(map);
|
||||
allSalvageMaps.Add(forcedMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.ErrorS("c.s.salvage", $"Unable to get forced salvage map prototype {forcedSalvage}");
|
||||
}
|
||||
}
|
||||
|
||||
SalvageMapPrototype? map = null;
|
||||
Vector2 spawnLocation = Vector2.Zero;
|
||||
|
||||
for (var i = 0; i < allSalvageMaps.Count; i++)
|
||||
{
|
||||
map = _random.PickAndTake(allSalvageMaps);
|
||||
var box2 = Box2.CenteredAround(spl.Position, new Vector2(map.Size * 2.0f, map.Size * 2.0f));
|
||||
var box2rot = new Box2Rotated(box2, spAngle, spl.Position);
|
||||
|
||||
// This doesn't stop it from spawning on top of random things in space
|
||||
// Might be better like this, ghosts could stop it before
|
||||
if (_mapManager.FindGridsIntersecting(spl.MapId, box2rot).Any())
|
||||
SalvageMapPrototype attemptedMap = _random.PickAndTake(allSalvageMaps);
|
||||
for (var attempt = 0; attempt < SalvageLocationPlaceAttempts; attempt++)
|
||||
{
|
||||
map = null;
|
||||
var randomRadius = _random.NextFloat(component.OffsetRadiusMin, component.OffsetRadiusMax);
|
||||
var randomOffset = _random.NextAngle().ToWorldVec() * randomRadius;
|
||||
spawnLocation = spl.Position + randomOffset;
|
||||
|
||||
var box2 = Box2.CenteredAround(spawnLocation + attemptedMap.Bounds.Center, attemptedMap.Bounds.Size);
|
||||
var box2rot = new Box2Rotated(box2, spAngle, spawnLocation);
|
||||
|
||||
// This doesn't stop it from spawning on top of random things in space
|
||||
// Might be better like this, ghosts could stop it before
|
||||
if (!_mapManager.FindGridsIntersecting(spl.MapId, box2rot).Any())
|
||||
{
|
||||
map = attemptedMap;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (map != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -285,7 +297,7 @@ namespace Content.Server.Salvage
|
||||
|
||||
var opts = new MapLoadOptions
|
||||
{
|
||||
Offset = spl.Position
|
||||
Offset = spawnLocation
|
||||
};
|
||||
|
||||
var (_, salvageEntityId) = _mapLoader.LoadGrid(spl.MapId, map.MapPath.ToString(), opts);
|
||||
|
||||
Reference in New Issue
Block a user