From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Mon, 22 Apr 2024 08:42:26 +0000 (+0000) Subject: make fire spreading scale with mass (#27202) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=fcf5057b61321920826b630384e0dc6ff5de55e8;p=space-station-14.git make fire spreading scale with mass (#27202) * make fire spreading scale with mass * realer --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index 53fcb72076..058faf443e 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -47,6 +47,8 @@ namespace Content.Server.Atmos.EntitySystems [Dependency] private readonly AudioSystem _audio = default!; [Dependency] private readonly IRobustRandom _random = default!; + private EntityQuery _physicsQuery; + public const float MinimumFireStacks = -10f; public const float MaximumFireStacks = 20f; private const float UpdateTime = 1f; @@ -62,6 +64,8 @@ namespace Content.Server.Atmos.EntitySystems { UpdatesAfter.Add(typeof(AtmosphereSystem)); + _physicsQuery = GetEntityQuery(); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnCollide); @@ -203,7 +207,17 @@ namespace Content.Server.Atmos.EntitySystems if (flammable.OnFire && otherFlammable.OnFire) { // Both are on fire -> equalize fire stacks. - var avg = (flammable.FireStacks + otherFlammable.FireStacks) / 2; + // Weight each thing's firestacks by its mass + var mass1 = 1f; + var mass2 = 1f; + if (_physicsQuery.TryComp(uid, out var physics) && _physicsQuery.TryComp(otherUid, out var otherPhys)) + { + mass1 = physics.Mass; + mass2 = otherPhys.Mass; + } + + var total = mass1 + mass2; + var avg = (flammable.FireStacks * mass1 + otherFlammable.FireStacks * mass2) / total; flammable.FireStacks = flammable.CanExtinguish ? avg : Math.Max(flammable.FireStacks, avg); otherFlammable.FireStacks = otherFlammable.CanExtinguish ? avg : Math.Max(otherFlammable.FireStacks, avg); UpdateAppearance(uid, flammable); @@ -212,25 +226,24 @@ namespace Content.Server.Atmos.EntitySystems } // Only one is on fire -> attempt to spread the fire. - if (flammable.OnFire) + var (srcUid, srcFlammable, destUid, destFlammable) = flammable.OnFire + ? (uid, flammable, otherUid, otherFlammable) + : (otherUid, otherFlammable, uid, flammable); + + // if the thing on fire has less mass, spread less firestacks and vice versa + var ratio = 0.5f; + if (_physicsQuery.TryComp(srcUid, out var srcPhysics) && _physicsQuery.TryComp(destUid, out var destPhys)) { - otherFlammable.FireStacks += flammable.FireStacks / 2; - Ignite(otherUid, uid, otherFlammable); - if (flammable.CanExtinguish) - { - flammable.FireStacks /= 2; - UpdateAppearance(uid, flammable); - } + ratio *= srcPhysics.Mass / destPhys.Mass; } - else + + var lost = srcFlammable.FireStacks * ratio; + destFlammable.FireStacks += lost; + Ignite(destUid, srcUid, destFlammable); + if (srcFlammable.CanExtinguish) { - flammable.FireStacks += otherFlammable.FireStacks / 2; - Ignite(uid, otherUid, flammable); - if (otherFlammable.CanExtinguish) - { - otherFlammable.FireStacks /= 2; - UpdateAppearance(otherUid, otherFlammable); - } + srcFlammable.FireStacks -= lost; + UpdateAppearance(srcUid, srcFlammable); } }