don't require salvage map prototypes to specify their bounds (#17652)

This commit is contained in:
Nemanja
2023-06-25 22:29:45 -04:00
committed by GitHub
parent bf15bf297c
commit 06fc0122fe
4 changed files with 28 additions and 117 deletions

View File

@@ -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();
}
}
}

View File

@@ -1,31 +1,20 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Salvage
{
namespace Content.Server.Salvage;
[Prototype("salvageMap")]
public sealed class SalvageMapPrototype : IPrototype
{
[ViewVariables]
[IdDataField]
public string ID { get; } = default!;
[ViewVariables] [IdDataField] public string ID { get; } = default!;
/// <summary>
/// Relative directory path to the given map, i.e. `Maps/Salvage/template.yml`
/// </summary>
[DataField("mapPath", required: true)]
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;
[DataField("mapPath", required: true)] public ResPath MapPath;
/// <summary>
/// Name for admin use
/// </summary>
[DataField("name")]
public string Name { get; } = "";
}
[DataField("name")] public string Name = string.Empty;
}

View File

@@ -336,47 +336,25 @@ namespace Content.Server.Salvage
{
var salvMap = _mapManager.CreateMap();
Box2 bounds;
EntityUid? salvageEnt = null;
SalvageMapPrototype? salvageProto = null;
EntityUid? salvageEnt;
if (_random.Prob(component.AsteroidChance))
{
var asteroidProto = _prototypeManager.Index<WeightedRandomPrototype>(component.AsteroidPool).Pick(_random);
salvageEnt = Spawn(asteroidProto, new MapCoordinates(0, 0, salvMap));
bounds = Comp<MapGridComponent>(salvageEnt.Value).LocalAABB;
}
else
{
var forcedSalvage = _configurationManager.GetCVar(CCVars.SalvageForced);
salvageProto = string.IsNullOrWhiteSpace(forcedSalvage)
var salvageProto = string.IsNullOrWhiteSpace(forcedSalvage)
? _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList())
: _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
{
Offset = spawnLocation.Position,
Rotation = spawnAngle
Offset = new Vector2(0, 0)
};
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)
{
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-debris-disintegrated");
@@ -386,11 +364,19 @@ namespace Content.Server.Salvage
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;
var gridcomp = EnsureComp<SalvageGridComponent>(salvageEnt.Value);
gridcomp.SpawnerMagnet = uid;

View File

@@ -9,37 +9,31 @@
id: Small1
name: "Small / Engineering Storage 1"
mapPath: /Maps/Salvage/small-1.yml
bounds: "-3,-4,3,3"
- type: salvageMap
id: Small2
name: "Small / Gaming Nook 1"
mapPath: /Maps/Salvage/small-2.yml
bounds: "-4,-4,3,3"
- type: salvageMap
id: Small-ship-1
name: "Small / Ship 1 (Pill)"
mapPath: /Maps/Salvage/small-ship-1.yml
bounds: "-2,-1,2,1"
- type: salvageMap
id: Small3
name: "Small / Laundromat 1"
mapPath: /Maps/Salvage/small-3.yml
bounds: "-4,-4,2,3"
- type: salvageMap
id: SmallAISurveyDrone
name: "Small / AI Survey Drone"
mapPath: /Maps/Salvage/small-ai-survey-drone.yml
bounds: "-4,-4,3,3"
- type: salvageMap
id: Small4
name: "Small / Bar Salvage"
mapPath: /Maps/Salvage/small-4.yml
bounds: "-4,-4,3,3"
# Small - Asteroids
@@ -47,7 +41,6 @@
id: SmallA1
name: "Small / Asteroid 1 Plasmafire"
mapPath: /Maps/Salvage/small-a-1.yml
bounds: "-4,-4,3,3"
# "Medium"-class maps - Max size square: 15x15, indicated size: 7.5
@@ -55,73 +48,61 @@
id: Medium1
name: "Medium / Plasma-Trapped Cache 1"
mapPath: /Maps/Salvage/medium-1.yml
bounds: "-8,-8,7,7"
- type: salvageMap
id: MediumVault1
name: "Medium / Vault 1"
mapPath: /Maps/Salvage/medium-vault-1.yml
bounds: "-8,-8,7,7"
- type: salvageMap
id: MediumOrchestra
name: "Medium / Silent Orchestra"
mapPath: /Maps/Salvage/medium-silent-orchestra.yml
bounds: "-8,-8,7,7"
- type: salvageMap
id: MediumLibraryWreck
name: "Medium / Abandoned Library"
mapPath: /Maps/Salvage/medium-library.yml
bounds: "-9,-9,6,7"
- type: salvageMap
id: MediumCargoWreck
name: "Medium / Cargo Department Wreck"
mapPath: /Maps/Salvage/cargo-1.yml
bounds: "-6,-6,5,9"
- type: salvageMap
id: MediumPirateWreck
name: "Medium / Pirate Barge Fragment"
mapPath: /Maps/Salvage/medium-pirate.yml
bounds: "-4,-10,6,7"
- type: salvageMap
id: TickColony
name: "Space Tick colony"
mapPath: /Maps/Salvage/tick-colony.yml
bounds: "-6,-7,5,7"
- type: salvageMap
id: CargoDock
name: "Asteroid Cargo Dock"
mapPath: /Maps/Salvage/medium-dock.yml
bounds: "-7,-6,4,8"
- type: salvageMap
id: SpaceWaffleHome
name: "Waffle Home"
mapPath: /Maps/Salvage/wh-salvage.yml
bounds: "-13,-12,14,11"
- type: salvageMap
id: MediumShuttleWreck
name: "Medium / Ruined Emergency Shuttle"
mapPath: /Maps/Salvage/medium-ruined-emergency-shuttle.yml
bounds: "-6,-9,5,8"
- type: salvageMap
id: mediumPetHospital
name: "Medium / Pet and Bear Hospital"
mapPath: /Maps/Salvage/medium-pet-hospital.yml
bounds: "-2,-14,16,2"
- type: salvageMap
id: MediumCrashedShuttle
name: "Crashed Shuttle"
mapPath: /Maps/Salvage/medium-crashed-shuttle.yml
bounds: "-7,-8,5,9"
# """Large""" maps
@@ -129,17 +110,14 @@
id: StationStation
name: "StationStation"
mapPath: /Maps/Salvage/stationstation.yml
bounds: "-17,-15,35,29"
- type: salvageMap
id: AsteroidBase
name: "Asteroid Base"
mapPath: /Maps/Salvage/asteroid-base.yml
bounds: "-12,-13,15,11"
- type: salvageMap
id: RuinCargoBase
name: "Ruined Cargo Storage"
mapPath: /Maps/Salvage/ruin-cargo-salvage.yml
bounds: "-15,-13,22,14"