]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make fire leave burnt decals on the tiles (#31939)
authorWinkarst <74284083+Winkarst-cpu@users.noreply.github.com>
Thu, 19 Sep 2024 00:23:50 +0000 (03:23 +0300)
committerGitHub <noreply@github.com>
Thu, 19 Sep 2024 00:23:50 +0000 (10:23 +1000)
* Make fire leave burnt decals on the tiles

* License

* Yes

* Update

* Spelling error

* Prototypes reload support

* To array

Content.Server/Atmos/EntitySystems/AtmosphereSystem.Hotspot.cs
Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs
Resources/Prototypes/Decals/burnt.yml [new file with mode: 0644]
Resources/Textures/Decals/burnt.rsi/burnt1.png [new file with mode: 0644]
Resources/Textures/Decals/burnt.rsi/burnt2.png [new file with mode: 0644]
Resources/Textures/Decals/burnt.rsi/burnt3.png [new file with mode: 0644]
Resources/Textures/Decals/burnt.rsi/burnt4.png [new file with mode: 0644]
Resources/Textures/Decals/burnt.rsi/meta.json [new file with mode: 0644]

index db952237338f79e86e88572be49f88ef6700a34a..a03f27b561ae9054a4509dabe15d4bd2133a30a5 100644 (file)
@@ -1,19 +1,21 @@
 using Content.Server.Atmos.Components;
-using Content.Server.Atmos.Reactions;
+using Content.Server.Decals;
 using Content.Shared.Atmos;
 using Content.Shared.Atmos.Components;
 using Content.Shared.Atmos.Reactions;
-using Content.Shared.Audio;
 using Content.Shared.Database;
 using Robust.Shared.Audio;
 using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
-using Robust.Shared.Player;
+using Robust.Shared.Random;
 
 namespace Content.Server.Atmos.EntitySystems
 {
     public sealed partial class AtmosphereSystem
     {
+        [Dependency] private readonly DecalSystem _decalSystem = default!;
+        [Dependency] private readonly IRobustRandom _random = default!;
+
         private const int HotspotSoundCooldownCycles = 200;
 
         private int _hotspotSoundCooldown = 0;
@@ -56,7 +58,30 @@ namespace Content.Server.Atmos.EntitySystems
             if (tile.Hotspot.Bypassing)
             {
                 tile.Hotspot.State = 3;
-                // TODO ATMOS: Burn tile here
+
+                var gridUid = ent.Owner;
+                var tilePos = tile.GridIndices;
+
+                // Get the existing decals on the tile
+                var tileDecals = _decalSystem.GetDecalsInRange(gridUid, tilePos);
+
+                // Count the burnt decals on the tile
+                var tileBurntDecals = 0;
+
+                foreach (var set in tileDecals)
+                {
+                    if (Array.IndexOf(_burntDecals, set.Decal.Id) == -1)
+                        continue;
+
+                    tileBurntDecals++;
+
+                    if (tileBurntDecals > 4)
+                        break;
+                }
+
+                // Add a random burned decal to the tile only if there are less than 4 of them
+                if (tileBurntDecals < 4)
+                    _decalSystem.TryAddDecal(_burntDecals[_random.Next(_burntDecals.Length)], new EntityCoordinates(gridUid, tilePos), out _, cleanable: true);
 
                 if (tile.Air.Temperature > Atmospherics.FireMinimumTemperatureToSpread)
                 {
index 44bfa4cc10c7518d1aab7286c0606e60b24a0378..13d8f73dc56bd8893c6cf66facf3efae2875daa2 100644 (file)
@@ -4,6 +4,7 @@ using Content.Server.Body.Systems;
 using Content.Server.Fluids.EntitySystems;
 using Content.Server.NodeContainer.EntitySystems;
 using Content.Shared.Atmos.EntitySystems;
+using Content.Shared.Decals;
 using Content.Shared.Doors.Components;
 using Content.Shared.Maps;
 using JetBrains.Annotations;
@@ -12,7 +13,9 @@ using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
 using Robust.Shared.Map;
 using Robust.Shared.Physics.Systems;
+using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
+using System.Linq;
 
 namespace Content.Server.Atmos.EntitySystems;
 
@@ -36,6 +39,7 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
     [Dependency] private readonly SharedTransformSystem _transformSystem = default!;
     [Dependency] private readonly TileSystem _tile = default!;
     [Dependency] private readonly MapSystem _map = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] public readonly PuddleSystem Puddle = default!;
 
     private const float ExposedUpdateDelay = 1f;
@@ -47,6 +51,8 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
     private EntityQuery<FirelockComponent> _firelockQuery;
     private HashSet<EntityUid> _entSet = new();
 
+    private string[] _burntDecals = [];
+
     public override void Initialize()
     {
         base.Initialize();
@@ -66,7 +72,9 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
         _firelockQuery = GetEntityQuery<FirelockComponent>();
 
         SubscribeLocalEvent<TileChangedEvent>(OnTileChanged);
+        SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);
 
+        CacheDecals();
     }
 
     public override void Shutdown()
@@ -81,6 +89,12 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
         InvalidateTile(ev.NewTile.GridUid, ev.NewTile.GridIndices);
     }
 
+    private void OnPrototypesReloaded(PrototypesReloadedEventArgs ev)
+    {
+        if (ev.WasModified<DecalPrototype>())
+            CacheDecals();
+    }
+
     public override void Update(float frameTime)
     {
         base.Update(frameTime);
@@ -107,4 +121,9 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
 
         _exposedTimer -= ExposedUpdateDelay;
     }
+
+    private void CacheDecals()
+    {
+        _burntDecals = _prototypeManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("burnt")).Select(x => x.ID).ToArray();
+    }
 }
diff --git a/Resources/Prototypes/Decals/burnt.yml b/Resources/Prototypes/Decals/burnt.yml
new file mode 100644 (file)
index 0000000..d9d500e
--- /dev/null
@@ -0,0 +1,31 @@
+- type: decal
+  id: burnt1
+  tags: ["burnt"]
+  defaultCleanable: true
+  sprite:
+    sprite: Decals/burnt.rsi
+    state: burnt1
+
+- type: decal
+  id: burnt2
+  tags: ["burnt"]
+  defaultCleanable: true
+  sprite:
+    sprite: Decals/burnt.rsi
+    state: burnt2
+
+- type: decal
+  id: burnt3
+  tags: ["burnt"]
+  defaultCleanable: true
+  sprite:
+    sprite: Decals/burnt.rsi
+    state: burnt3
+
+- type: decal
+  id: burnt4
+  tags: ["burnt"]
+  defaultCleanable: true
+  sprite:
+    sprite: Decals/burnt.rsi
+    state: burnt4
diff --git a/Resources/Textures/Decals/burnt.rsi/burnt1.png b/Resources/Textures/Decals/burnt.rsi/burnt1.png
new file mode 100644 (file)
index 0000000..3fcb7a4
Binary files /dev/null and b/Resources/Textures/Decals/burnt.rsi/burnt1.png differ
diff --git a/Resources/Textures/Decals/burnt.rsi/burnt2.png b/Resources/Textures/Decals/burnt.rsi/burnt2.png
new file mode 100644 (file)
index 0000000..01f8f22
Binary files /dev/null and b/Resources/Textures/Decals/burnt.rsi/burnt2.png differ
diff --git a/Resources/Textures/Decals/burnt.rsi/burnt3.png b/Resources/Textures/Decals/burnt.rsi/burnt3.png
new file mode 100644 (file)
index 0000000..e9dcbe3
Binary files /dev/null and b/Resources/Textures/Decals/burnt.rsi/burnt3.png differ
diff --git a/Resources/Textures/Decals/burnt.rsi/burnt4.png b/Resources/Textures/Decals/burnt.rsi/burnt4.png
new file mode 100644 (file)
index 0000000..f1db063
Binary files /dev/null and b/Resources/Textures/Decals/burnt.rsi/burnt4.png differ
diff --git a/Resources/Textures/Decals/burnt.rsi/meta.json b/Resources/Textures/Decals/burnt.rsi/meta.json
new file mode 100644 (file)
index 0000000..48a8f33
--- /dev/null
@@ -0,0 +1,27 @@
+{
+    "version": 1,
+    "size": {
+        "x": 32,
+        "y": 32
+    },
+    "license": "CC-BY-SA-3.0",
+    "copyright": "From https://github.com/BeeStation/BeeStation-Hornet/blob/master/icons/turf/turf_damage.dmi at f2d6fbdf36aa0951049498cf28e028a38e32fe0b",
+    "states": [
+        {
+            "name": "burnt1"
+
+        },
+        {
+            "name": "burnt2"
+
+        },
+        {
+            "name": "burnt3"
+
+        },
+        {
+            "name": "burnt4"
+
+        }
+    ]
+}