don't require salvage map prototypes to specify their bounds (#17652)
This commit is contained in:
@@ -1,42 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using Content.Server.Salvage;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Map.Components;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.IntegrationTests.Tests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public sealed class SalvageTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public async Task SalvageGridBoundsTest()
|
|
||||||
{
|
|
||||||
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true});
|
|
||||||
var server = pairTracker.Pair.Server;
|
|
||||||
await server.WaitIdleAsync();
|
|
||||||
|
|
||||||
var mapMan = server.ResolveDependency<IMapManager>();
|
|
||||||
var protoManager = server.ResolveDependency<IPrototypeManager>();
|
|
||||||
var entManager = server.ResolveDependency<IEntityManager>();
|
|
||||||
var mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
|
|
||||||
|
|
||||||
await server.WaitAssertion(() =>
|
|
||||||
{
|
|
||||||
foreach (var salvage in protoManager.EnumeratePrototypes<SalvageMapPrototype>())
|
|
||||||
{
|
|
||||||
var mapId = mapMan.CreateMap();
|
|
||||||
mapLoader.TryLoad(mapId, salvage.MapPath.ToString(), out var rootUids);
|
|
||||||
Assert.That(rootUids is { Count: 1 }, $"Salvage map {salvage.ID} does not have a single grid");
|
|
||||||
var grid = rootUids[0];
|
|
||||||
Assert.That(entManager.TryGetComponent<MapGridComponent>(grid, out var gridComp), $"Salvage {salvage.ID}'s grid does not have GridComponent.");
|
|
||||||
Assert.That(gridComp.LocalAABB, Is.EqualTo(salvage.Bounds), $"Salvage {salvage.ID}'s bounds {gridComp.LocalAABB} are not equal to the bounds on the prototype {salvage.Bounds}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await pairTracker.CleanReturnAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,20 @@
|
|||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.Salvage
|
namespace Content.Server.Salvage;
|
||||||
{
|
|
||||||
[Prototype("salvageMap")]
|
[Prototype("salvageMap")]
|
||||||
public sealed class SalvageMapPrototype : IPrototype
|
public sealed class SalvageMapPrototype : IPrototype
|
||||||
{
|
{
|
||||||
[ViewVariables]
|
[ViewVariables] [IdDataField] public string ID { get; } = default!;
|
||||||
[IdDataField]
|
|
||||||
public string ID { get; } = default!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Relative directory path to the given map, i.e. `Maps/Salvage/template.yml`
|
/// Relative directory path to the given map, i.e. `Maps/Salvage/template.yml`
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("mapPath", required: true)]
|
[DataField("mapPath", required: true)] public ResPath MapPath;
|
||||||
public ResPath MapPath { get; } = default!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Map rectangle in world coordinates (to check if it fits)
|
|
||||||
/// </summary>
|
|
||||||
[DataField("bounds", required: true)]
|
|
||||||
public Box2 Bounds { get; } = Box2.UnitCentered;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Name for admin use
|
/// Name for admin use
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("name")]
|
[DataField("name")] public string Name = string.Empty;
|
||||||
public string Name { get; } = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,47 +336,25 @@ namespace Content.Server.Salvage
|
|||||||
{
|
{
|
||||||
var salvMap = _mapManager.CreateMap();
|
var salvMap = _mapManager.CreateMap();
|
||||||
|
|
||||||
Box2 bounds;
|
EntityUid? salvageEnt;
|
||||||
EntityUid? salvageEnt = null;
|
|
||||||
SalvageMapPrototype? salvageProto = null;
|
|
||||||
if (_random.Prob(component.AsteroidChance))
|
if (_random.Prob(component.AsteroidChance))
|
||||||
{
|
{
|
||||||
var asteroidProto = _prototypeManager.Index<WeightedRandomPrototype>(component.AsteroidPool).Pick(_random);
|
var asteroidProto = _prototypeManager.Index<WeightedRandomPrototype>(component.AsteroidPool).Pick(_random);
|
||||||
salvageEnt = Spawn(asteroidProto, new MapCoordinates(0, 0, salvMap));
|
salvageEnt = Spawn(asteroidProto, new MapCoordinates(0, 0, salvMap));
|
||||||
bounds = Comp<MapGridComponent>(salvageEnt.Value).LocalAABB;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var forcedSalvage = _configurationManager.GetCVar(CCVars.SalvageForced);
|
var forcedSalvage = _configurationManager.GetCVar(CCVars.SalvageForced);
|
||||||
salvageProto = string.IsNullOrWhiteSpace(forcedSalvage)
|
var salvageProto = string.IsNullOrWhiteSpace(forcedSalvage)
|
||||||
? _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList())
|
? _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList())
|
||||||
: _prototypeManager.Index<SalvageMapPrototype>(forcedSalvage);
|
: _prototypeManager.Index<SalvageMapPrototype>(forcedSalvage);
|
||||||
|
|
||||||
bounds = salvageProto.Bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TryGetSalvagePlacementLocation(uid, component, bounds, out var spawnLocation, out var spawnAngle))
|
|
||||||
{
|
|
||||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
|
|
||||||
_mapManager.DeleteMap(salvMap);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (salvageEnt is { } ent)
|
|
||||||
{
|
|
||||||
var salvXForm = Transform(ent);
|
|
||||||
_transform.SetParent(ent, salvXForm, _mapManager.GetMapEntityId(spawnLocation.MapId));
|
|
||||||
_transform.SetWorldPosition(salvXForm, spawnLocation.Position);
|
|
||||||
}
|
|
||||||
else if (salvageProto != null)
|
|
||||||
{
|
|
||||||
var opts = new MapLoadOptions
|
var opts = new MapLoadOptions
|
||||||
{
|
{
|
||||||
Offset = spawnLocation.Position,
|
Offset = new Vector2(0, 0)
|
||||||
Rotation = spawnAngle
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!_map.TryLoad(spawnLocation.MapId, salvageProto.MapPath.ToString(), out var roots, opts) ||
|
if (!_map.TryLoad(salvMap, salvageProto.MapPath.ToString(), out var roots, opts) ||
|
||||||
roots.FirstOrNull() is not { } root)
|
roots.FirstOrNull() is not { } root)
|
||||||
{
|
{
|
||||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-debris-disintegrated");
|
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-debris-disintegrated");
|
||||||
@@ -386,11 +364,19 @@ namespace Content.Server.Salvage
|
|||||||
|
|
||||||
salvageEnt = root;
|
salvageEnt = root;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
var bounds = Comp<MapGridComponent>(salvageEnt.Value).LocalAABB;
|
||||||
|
if (!TryGetSalvagePlacementLocation(uid, component, bounds, out var spawnLocation, out var spawnAngle))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("No asteroid generated and no salvage prototype present.");
|
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
|
||||||
|
_mapManager.DeleteMap(salvMap);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var salvXForm = Transform(salvageEnt.Value);
|
||||||
|
_transform.SetParent(salvageEnt.Value, salvXForm, _mapManager.GetMapEntityId(spawnLocation.MapId));
|
||||||
|
_transform.SetWorldPosition(salvXForm, spawnLocation.Position);
|
||||||
|
|
||||||
component.AttachedEntity = salvageEnt;
|
component.AttachedEntity = salvageEnt;
|
||||||
var gridcomp = EnsureComp<SalvageGridComponent>(salvageEnt.Value);
|
var gridcomp = EnsureComp<SalvageGridComponent>(salvageEnt.Value);
|
||||||
gridcomp.SpawnerMagnet = uid;
|
gridcomp.SpawnerMagnet = uid;
|
||||||
|
|||||||
@@ -9,37 +9,31 @@
|
|||||||
id: Small1
|
id: Small1
|
||||||
name: "Small / Engineering Storage 1"
|
name: "Small / Engineering Storage 1"
|
||||||
mapPath: /Maps/Salvage/small-1.yml
|
mapPath: /Maps/Salvage/small-1.yml
|
||||||
bounds: "-3,-4,3,3"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: Small2
|
id: Small2
|
||||||
name: "Small / Gaming Nook 1"
|
name: "Small / Gaming Nook 1"
|
||||||
mapPath: /Maps/Salvage/small-2.yml
|
mapPath: /Maps/Salvage/small-2.yml
|
||||||
bounds: "-4,-4,3,3"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: Small-ship-1
|
id: Small-ship-1
|
||||||
name: "Small / Ship 1 (Pill)"
|
name: "Small / Ship 1 (Pill)"
|
||||||
mapPath: /Maps/Salvage/small-ship-1.yml
|
mapPath: /Maps/Salvage/small-ship-1.yml
|
||||||
bounds: "-2,-1,2,1"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: Small3
|
id: Small3
|
||||||
name: "Small / Laundromat 1"
|
name: "Small / Laundromat 1"
|
||||||
mapPath: /Maps/Salvage/small-3.yml
|
mapPath: /Maps/Salvage/small-3.yml
|
||||||
bounds: "-4,-4,2,3"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: SmallAISurveyDrone
|
id: SmallAISurveyDrone
|
||||||
name: "Small / AI Survey Drone"
|
name: "Small / AI Survey Drone"
|
||||||
mapPath: /Maps/Salvage/small-ai-survey-drone.yml
|
mapPath: /Maps/Salvage/small-ai-survey-drone.yml
|
||||||
bounds: "-4,-4,3,3"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: Small4
|
id: Small4
|
||||||
name: "Small / Bar Salvage"
|
name: "Small / Bar Salvage"
|
||||||
mapPath: /Maps/Salvage/small-4.yml
|
mapPath: /Maps/Salvage/small-4.yml
|
||||||
bounds: "-4,-4,3,3"
|
|
||||||
|
|
||||||
# Small - Asteroids
|
# Small - Asteroids
|
||||||
|
|
||||||
@@ -47,7 +41,6 @@
|
|||||||
id: SmallA1
|
id: SmallA1
|
||||||
name: "Small / Asteroid 1 Plasmafire"
|
name: "Small / Asteroid 1 Plasmafire"
|
||||||
mapPath: /Maps/Salvage/small-a-1.yml
|
mapPath: /Maps/Salvage/small-a-1.yml
|
||||||
bounds: "-4,-4,3,3"
|
|
||||||
|
|
||||||
# "Medium"-class maps - Max size square: 15x15, indicated size: 7.5
|
# "Medium"-class maps - Max size square: 15x15, indicated size: 7.5
|
||||||
|
|
||||||
@@ -55,73 +48,61 @@
|
|||||||
id: Medium1
|
id: Medium1
|
||||||
name: "Medium / Plasma-Trapped Cache 1"
|
name: "Medium / Plasma-Trapped Cache 1"
|
||||||
mapPath: /Maps/Salvage/medium-1.yml
|
mapPath: /Maps/Salvage/medium-1.yml
|
||||||
bounds: "-8,-8,7,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumVault1
|
id: MediumVault1
|
||||||
name: "Medium / Vault 1"
|
name: "Medium / Vault 1"
|
||||||
mapPath: /Maps/Salvage/medium-vault-1.yml
|
mapPath: /Maps/Salvage/medium-vault-1.yml
|
||||||
bounds: "-8,-8,7,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumOrchestra
|
id: MediumOrchestra
|
||||||
name: "Medium / Silent Orchestra"
|
name: "Medium / Silent Orchestra"
|
||||||
mapPath: /Maps/Salvage/medium-silent-orchestra.yml
|
mapPath: /Maps/Salvage/medium-silent-orchestra.yml
|
||||||
bounds: "-8,-8,7,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumLibraryWreck
|
id: MediumLibraryWreck
|
||||||
name: "Medium / Abandoned Library"
|
name: "Medium / Abandoned Library"
|
||||||
mapPath: /Maps/Salvage/medium-library.yml
|
mapPath: /Maps/Salvage/medium-library.yml
|
||||||
bounds: "-9,-9,6,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumCargoWreck
|
id: MediumCargoWreck
|
||||||
name: "Medium / Cargo Department Wreck"
|
name: "Medium / Cargo Department Wreck"
|
||||||
mapPath: /Maps/Salvage/cargo-1.yml
|
mapPath: /Maps/Salvage/cargo-1.yml
|
||||||
bounds: "-6,-6,5,9"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumPirateWreck
|
id: MediumPirateWreck
|
||||||
name: "Medium / Pirate Barge Fragment"
|
name: "Medium / Pirate Barge Fragment"
|
||||||
mapPath: /Maps/Salvage/medium-pirate.yml
|
mapPath: /Maps/Salvage/medium-pirate.yml
|
||||||
bounds: "-4,-10,6,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: TickColony
|
id: TickColony
|
||||||
name: "Space Tick colony"
|
name: "Space Tick colony"
|
||||||
mapPath: /Maps/Salvage/tick-colony.yml
|
mapPath: /Maps/Salvage/tick-colony.yml
|
||||||
bounds: "-6,-7,5,7"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: CargoDock
|
id: CargoDock
|
||||||
name: "Asteroid Cargo Dock"
|
name: "Asteroid Cargo Dock"
|
||||||
mapPath: /Maps/Salvage/medium-dock.yml
|
mapPath: /Maps/Salvage/medium-dock.yml
|
||||||
bounds: "-7,-6,4,8"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: SpaceWaffleHome
|
id: SpaceWaffleHome
|
||||||
name: "Waffle Home"
|
name: "Waffle Home"
|
||||||
mapPath: /Maps/Salvage/wh-salvage.yml
|
mapPath: /Maps/Salvage/wh-salvage.yml
|
||||||
bounds: "-13,-12,14,11"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumShuttleWreck
|
id: MediumShuttleWreck
|
||||||
name: "Medium / Ruined Emergency Shuttle"
|
name: "Medium / Ruined Emergency Shuttle"
|
||||||
mapPath: /Maps/Salvage/medium-ruined-emergency-shuttle.yml
|
mapPath: /Maps/Salvage/medium-ruined-emergency-shuttle.yml
|
||||||
bounds: "-6,-9,5,8"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: mediumPetHospital
|
id: mediumPetHospital
|
||||||
name: "Medium / Pet and Bear Hospital"
|
name: "Medium / Pet and Bear Hospital"
|
||||||
mapPath: /Maps/Salvage/medium-pet-hospital.yml
|
mapPath: /Maps/Salvage/medium-pet-hospital.yml
|
||||||
bounds: "-2,-14,16,2"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: MediumCrashedShuttle
|
id: MediumCrashedShuttle
|
||||||
name: "Crashed Shuttle"
|
name: "Crashed Shuttle"
|
||||||
mapPath: /Maps/Salvage/medium-crashed-shuttle.yml
|
mapPath: /Maps/Salvage/medium-crashed-shuttle.yml
|
||||||
bounds: "-7,-8,5,9"
|
|
||||||
|
|
||||||
# """Large""" maps
|
# """Large""" maps
|
||||||
|
|
||||||
@@ -129,17 +110,14 @@
|
|||||||
id: StationStation
|
id: StationStation
|
||||||
name: "StationStation"
|
name: "StationStation"
|
||||||
mapPath: /Maps/Salvage/stationstation.yml
|
mapPath: /Maps/Salvage/stationstation.yml
|
||||||
bounds: "-17,-15,35,29"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: AsteroidBase
|
id: AsteroidBase
|
||||||
name: "Asteroid Base"
|
name: "Asteroid Base"
|
||||||
mapPath: /Maps/Salvage/asteroid-base.yml
|
mapPath: /Maps/Salvage/asteroid-base.yml
|
||||||
bounds: "-12,-13,15,11"
|
|
||||||
|
|
||||||
- type: salvageMap
|
- type: salvageMap
|
||||||
id: RuinCargoBase
|
id: RuinCargoBase
|
||||||
name: "Ruined Cargo Storage"
|
name: "Ruined Cargo Storage"
|
||||||
mapPath: /Maps/Salvage/ruin-cargo-salvage.yml
|
mapPath: /Maps/Salvage/ruin-cargo-salvage.yml
|
||||||
bounds: "-15,-13,22,14"
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user