From 0e7275a74ce267c6cba1adb071fb058bd57c6e9e Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 12 Dec 2023 20:20:33 +1100 Subject: [PATCH] Restricted range cleanup (#22402) --- .../Gateway/Systems/GatewayGeneratorSystem.cs | 27 +++++--------- .../Salvage/RestrictedRangeSystem.cs | 35 +++++++++++++++++++ .../Shuttles/Systems/ArrivalsSystem.cs | 11 ++++-- .../Salvage/RestrictedRangeComponent.cs | 3 ++ 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/Content.Server/Gateway/Systems/GatewayGeneratorSystem.cs b/Content.Server/Gateway/Systems/GatewayGeneratorSystem.cs index 9adf3092c0..3bee8a6569 100644 --- a/Content.Server/Gateway/Systems/GatewayGeneratorSystem.cs +++ b/Content.Server/Gateway/Systems/GatewayGeneratorSystem.cs @@ -3,6 +3,7 @@ using System.Numerics; using Content.Server.Gateway.Components; using Content.Server.Parallax; using Content.Server.Procedural; +using Content.Server.Salvage; using Content.Shared.CCVar; using Content.Shared.Dataset; using Content.Shared.Movement.Components; @@ -36,11 +37,10 @@ public sealed class GatewayGeneratorSystem : EntitySystem [Dependency] private readonly ITileDefinitionManager _tileDefManager = default!; [Dependency] private readonly BiomeSystem _biome = default!; [Dependency] private readonly DungeonSystem _dungeon = default!; - [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly GatewaySystem _gateway = default!; [Dependency] private readonly MetaDataSystem _metadata = default!; + [Dependency] private readonly RestrictedRangeSystem _restricted = default!; [Dependency] private readonly SharedMapSystem _maps = default!; - [Dependency] private readonly SharedPhysicsSystem _physics = default!; [ValidatePrototypeId] private const string PlanetNames = "names_borer"; @@ -120,8 +120,12 @@ public sealed class GatewayGeneratorSystem : EntitySystem _metadata.SetEntityName(mapUid, gatewayName); var origin = new Vector2i(random.Next(-MaxOffset, MaxOffset), random.Next(-MaxOffset, MaxOffset)); - var restriction = AddComp(mapUid); - restriction.Origin = origin; + var restricted = new RestrictedRangeComponent + { + Origin = origin + }; + AddComp(mapUid, restricted); + _biome.EnsurePlanet(mapUid, _protoManager.Index("Continental"), seed); var grid = Comp(mapUid); @@ -145,21 +149,6 @@ public sealed class GatewayGeneratorSystem : EntitySystem genDest.Seed = seed; genDest.Generator = uid; - // Enclose the area - var boundaryUid = Spawn(null, originCoords); - var boundaryPhysics = AddComp(boundaryUid); - var cShape = new ChainShape(); - // Don't need it to be a perfect circle, just need it to be loosely accurate. - cShape.CreateLoop(Vector2.Zero, restriction.Range + 1f, false, count: 4); - _fixtures.TryCreateFixture( - boundaryUid, - cShape, - "boundary", - collisionLayer: (int) (CollisionGroup.HighImpassable | CollisionGroup.Impassable | CollisionGroup.LowImpassable), - body: boundaryPhysics); - _physics.WakeBody(boundaryUid, body: boundaryPhysics); - AddComp(boundaryUid); - // Create the gateway. var gatewayUid = SpawnAtPosition(generator.Proto, originCoords); var gatewayComp = Comp(gatewayUid); diff --git a/Content.Server/Salvage/RestrictedRangeSystem.cs b/Content.Server/Salvage/RestrictedRangeSystem.cs index bc8b6931d2..b7a35fb1ce 100644 --- a/Content.Server/Salvage/RestrictedRangeSystem.cs +++ b/Content.Server/Salvage/RestrictedRangeSystem.cs @@ -1,8 +1,43 @@ +using System.Numerics; +using Content.Shared.Physics; using Content.Shared.Salvage; +using Robust.Shared.Map; +using Robust.Shared.Physics.Collision.Shapes; +using Robust.Shared.Physics.Components; +using Robust.Shared.Physics.Systems; namespace Content.Server.Salvage; public sealed class RestrictedRangeSystem : SharedRestrictedRangeSystem { + [Dependency] private readonly FixtureSystem _fixtures = default!; + [Dependency] private readonly SharedPhysicsSystem _physics = default!; + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnRestrictedMapInit); + } + + private void OnRestrictedMapInit(EntityUid uid, RestrictedRangeComponent component, MapInitEvent args) + { + component.BoundaryEntity = CreateBoundary(new EntityCoordinates(uid, component.Origin), component.Range); + } + + public EntityUid CreateBoundary(EntityCoordinates coordinates, float range) + { + var boundaryUid = Spawn(null, coordinates); + var boundaryPhysics = AddComp(boundaryUid); + var cShape = new ChainShape(); + // Don't need it to be a perfect circle, just need it to be loosely accurate. + cShape.CreateLoop(Vector2.Zero, range + 0.25f, false, count: 4); + _fixtures.TryCreateFixture( + boundaryUid, + cShape, + "boundary", + collisionLayer: (int) (CollisionGroup.HighImpassable | CollisionGroup.Impassable | CollisionGroup.LowImpassable), + body: boundaryPhysics); + _physics.WakeBody(boundaryUid, body: boundaryPhysics); + return boundaryUid; + } } diff --git a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs index 53ede9b924..79d26ea14f 100644 --- a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs +++ b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs @@ -1,8 +1,10 @@ using System.Linq; +using System.Numerics; using Content.Server.Administration; using Content.Server.GameTicking; using Content.Server.GameTicking.Events; using Content.Server.Parallax; +using Content.Server.Salvage; using Content.Server.Shuttles.Components; using Content.Server.Shuttles.Events; using Content.Server.Spawners.Components; @@ -44,6 +46,7 @@ public sealed class ArrivalsSystem : EntitySystem [Dependency] private readonly BiomeSystem _biomes = default!; [Dependency] private readonly GameTicker _ticker = default!; [Dependency] private readonly MapLoaderSystem _loader = default!; + [Dependency] private readonly RestrictedRangeSystem _restricted = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly ShuttleSystem _shuttles = default!; [Dependency] private readonly StationSpawningSystem _stationSpawning = default!; @@ -429,9 +432,11 @@ public sealed class ArrivalsSystem : EntitySystem { var template = _random.Pick(_arrivalsBiomeOptions); _biomes.EnsurePlanet(mapUid, _protoManager.Index(template)); - var range = AddComp(mapUid); - range.Range = 32f; - Dirty(mapUid, range); + var restricted = new RestrictedRangeComponent + { + Range = 32f + }; + AddComp(mapUid, restricted); } _mapManager.DoMapInitialize(mapId); diff --git a/Content.Shared/Salvage/RestrictedRangeComponent.cs b/Content.Shared/Salvage/RestrictedRangeComponent.cs index 01eaa80040..92d3c3d392 100644 --- a/Content.Shared/Salvage/RestrictedRangeComponent.cs +++ b/Content.Shared/Salvage/RestrictedRangeComponent.cs @@ -14,4 +14,7 @@ public sealed partial class RestrictedRangeComponent : Component [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] public Vector2 Origin; + + [DataField] + public EntityUid BoundaryEntity; }