]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Restricted range cleanup (#22402)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Tue, 12 Dec 2023 09:20:33 +0000 (20:20 +1100)
committerGitHub <noreply@github.com>
Tue, 12 Dec 2023 09:20:33 +0000 (20:20 +1100)
Content.Server/Gateway/Systems/GatewayGeneratorSystem.cs
Content.Server/Salvage/RestrictedRangeSystem.cs
Content.Server/Shuttles/Systems/ArrivalsSystem.cs
Content.Shared/Salvage/RestrictedRangeComponent.cs

index 9adf3092c0c8d74bf6a5daff5a7763a09cb32e7d..3bee8a6569481dda27f0706345e622c052e73019 100644 (file)
@@ -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<DatasetPrototype>]
     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<RestrictedRangeComponent>(mapUid);
-        restriction.Origin = origin;
+        var restricted = new RestrictedRangeComponent
+        {
+            Origin = origin
+        };
+        AddComp(mapUid, restricted);
+
         _biome.EnsurePlanet(mapUid, _protoManager.Index<BiomeTemplatePrototype>("Continental"), seed);
 
         var grid = Comp<MapGridComponent>(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<PhysicsComponent>(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<BoundaryComponent>(boundaryUid);
-
         // Create the gateway.
         var gatewayUid = SpawnAtPosition(generator.Proto, originCoords);
         var gatewayComp = Comp<GatewayComponent>(gatewayUid);
index bc8b6931d28d9065e7d808b5c36efa616bd0b3a2..b7a35fb1ce43b943b55216ed64a9f7c618c2ef08 100644 (file)
@@ -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<RestrictedRangeComponent, MapInitEvent>(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<PhysicsComponent>(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;
+    }
 }
index 53ede9b9245f7c07c9c2ada533dc27a1e793e23e..79d26ea14fad51ed7cc41419df6ff7ac9afe656b 100644 (file)
@@ -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<RestrictedRangeComponent>(mapUid);
-            range.Range = 32f;
-            Dirty(mapUid, range);
+            var restricted = new RestrictedRangeComponent
+            {
+                Range = 32f
+            };
+            AddComp(mapUid, restricted);
         }
 
         _mapManager.DoMapInitialize(mapId);
index 01eaa800404a1b0840866a5d452091a003a16d3c..92d3c3d392943aa822f3a9c11cb93ef93a8109fe 100644 (file)
@@ -14,4 +14,7 @@ public sealed partial class RestrictedRangeComponent : Component
 
     [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
     public Vector2 Origin;
+
+    [DataField]
+    public EntityUid BoundaryEntity;
 }