]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make the station start with random broken wiring (#26695)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 4 Apr 2024 06:28:09 +0000 (02:28 -0400)
committerGitHub <noreply@github.com>
Thu, 4 Apr 2024 06:28:09 +0000 (17:28 +1100)
Random wire cutting on round start

Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs [new file with mode: 0644]
Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs [new file with mode: 0644]
Content.Server/Wires/CutWireOnMapInitComponent.cs [new file with mode: 0644]
Content.Server/Wires/CutWireOnMapInitSystem.cs [new file with mode: 0644]
Resources/Prototypes/GameRules/roundstart.yml
Resources/Prototypes/GameRules/variation.yml

diff --git a/Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs b/Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs
new file mode 100644 (file)
index 0000000..dc9a582
--- /dev/null
@@ -0,0 +1,29 @@
+using Content.Shared.Whitelist;
+
+namespace Content.Server.GameTicking.Rules.VariationPass.Components;
+
+/// <summary>
+/// Handles cutting a random wire on random devices around the station.
+/// </summary>
+[RegisterComponent]
+public sealed partial class CutWireVariationPassComponent : Component
+{
+    /// <summary>
+    /// Blacklist of hackable entities that should not be chosen to
+    /// have wires cut.
+    /// </summary>
+    [DataField]
+    public EntityWhitelist Blacklist = new();
+
+    /// <summary>
+    /// Chance for an individual wire to be cut.
+    /// </summary>
+    [DataField]
+    public float WireCutChance = 0.05f;
+
+    /// <summary>
+    /// Maximum number of wires that can be cut stationwide.
+    /// </summary>
+    [DataField]
+    public int MaxWiresCut = 10;
+}
diff --git a/Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs b/Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs
new file mode 100644 (file)
index 0000000..fd94c74
--- /dev/null
@@ -0,0 +1,39 @@
+using Content.Server.GameTicking.Rules.VariationPass.Components;
+using Content.Server.Wires;
+using Robust.Shared.Random;
+
+namespace Content.Server.GameTicking.Rules.VariationPass;
+
+/// <summary>
+/// Handles cutting a random wire on random devices around the station.
+/// This system identifies target devices and adds <see cref="CutWireOnMapInitComponent"/> to them.
+/// The actual wire cutting is handled by <see cref="CutWireOnMapInitSystem"/>.
+/// </summary>
+public sealed class CutWireVariationPassSystem : VariationPassSystem<CutWireVariationPassComponent>
+{
+    protected override void ApplyVariation(Entity<CutWireVariationPassComponent> ent, ref StationVariationPassEvent args)
+    {
+        var wiresCut = 0;
+        var query = AllEntityQuery<WiresComponent, TransformComponent>();
+        while (query.MoveNext(out var uid, out _, out var transform))
+        {
+            // Ignore if not part of the station
+            if (!IsMemberOfStation((uid, transform), ref args))
+                continue;
+
+            // Check against blacklist
+            if (ent.Comp.Blacklist.IsValid(uid))
+                continue;
+
+            if (Random.Prob(ent.Comp.WireCutChance))
+            {
+                EnsureComp<CutWireOnMapInitComponent>(uid);
+                wiresCut++;
+
+                // Limit max wires cut
+                if (wiresCut >= ent.Comp.MaxWiresCut)
+                    break;
+            }
+        }
+    }
+}
diff --git a/Content.Server/Wires/CutWireOnMapInitComponent.cs b/Content.Server/Wires/CutWireOnMapInitComponent.cs
new file mode 100644 (file)
index 0000000..4a4345e
--- /dev/null
@@ -0,0 +1,10 @@
+namespace Content.Server.Wires;
+
+/// <summary>
+/// Picks a random wire on the entity's <see cref="WireComponent"/> and cuts it.
+/// Runs at MapInit and removes itself afterwards.
+/// </summary>
+[RegisterComponent]
+public sealed partial class CutWireOnMapInitComponent : Component
+{
+}
diff --git a/Content.Server/Wires/CutWireOnMapInitSystem.cs b/Content.Server/Wires/CutWireOnMapInitSystem.cs
new file mode 100644 (file)
index 0000000..1de1d78
--- /dev/null
@@ -0,0 +1,34 @@
+using Robust.Shared.Random;
+
+namespace Content.Server.Wires;
+
+/// <summary>
+/// Handles cutting a random wire on devices that have <see cref="CutWireOnMapInitComponent"/>.
+/// </summary>
+public sealed partial class CutWireOnMapInitSystem : EntitySystem
+{
+    [Dependency] private readonly IRobustRandom _random = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<CutWireOnMapInitComponent, MapInitEvent>(OnMapInit, after: [typeof(WiresSystem)]);
+    }
+
+    private void OnMapInit(Entity<CutWireOnMapInitComponent> entity, ref MapInitEvent args)
+    {
+        if (TryComp<WiresComponent>(entity, out var panel) && panel.WiresList.Count > 0)
+        {
+            // Pick a random wire
+            var targetWire = _random.Pick(panel.WiresList);
+
+            // Cut the wire
+            if (targetWire.Action == null || targetWire.Action.Cut(EntityUid.Invalid, targetWire))
+                targetWire.IsCut = true;
+        }
+
+        // Our work here is done
+        RemCompDeferred(entity, entity.Comp);
+    }
+}
index 21ad1310de915bc933d081fb4387487b048e2bf6..29ede4fc90c6b33309e6fb0618d4946edc0df07e 100644 (file)
     - id: BasicTrashVariationPass
     - id: SolidWallRustingVariationPass
     - id: ReinforcedWallRustingVariationPass
+    - id: CutWireVariationPass
     - id: BasicPuddleMessVariationPass
       prob: 0.99
       orGroup: puddleMess
index 8721003c832674bea9cd06f44ba81dc3d5091807..7424fc28541e581129b83863cfae14218f89cb41 100644 (file)
     tilesPerSpillAverage: 150
     tilesPerSpillStdDev: 10
     randomPuddleSolutionFill: RandomFillTrashPuddleBloodbath
+
+- type: entity
+  id: CutWireVariationPass
+  parent: BaseVariationPass
+  noSpawn: true
+  components:
+  - type: CutWireVariationPass
+    wireCutChance: 0.01
+    maxWiresCut: 20
+    blacklist:
+      components:
+      - ParticleAcceleratorControlBox