fix fire spread round removal (#27986)

* fix a resolve debug assert

* rewrite fire spread

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2024-05-13 21:49:44 +00:00
committed by GitHub
parent d68186ff5c
commit 4b2193a8a0
2 changed files with 36 additions and 40 deletions

View File

@@ -204,8 +204,6 @@ namespace Content.Server.Atmos.EntitySystems
if (!flammable.OnFire && !otherFlammable.OnFire)
return; // Neither are on fire
if (flammable.OnFire && otherFlammable.OnFire)
{
// Both are on fire -> equalize fire stacks.
// Weight each thing's firestacks by its mass
var mass1 = 1f;
@@ -216,35 +214,20 @@ namespace Content.Server.Atmos.EntitySystems
mass2 = otherPhys.Mass;
}
// when the thing on fire is more massive than the other, the following happens:
// - the thing on fire loses a small number of firestacks
// - the other thing gains a large number of firestacks
// so a person on fire engulfs a mouse, but an engulfed mouse barely does anything to a person
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);
UpdateAppearance(otherUid, otherFlammable);
return;
}
var avg = (flammable.FireStacks + otherFlammable.FireStacks) / total;
// Only one is on fire -> attempt to spread the fire.
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))
{
ratio *= srcPhysics.Mass / destPhys.Mass;
}
var lost = srcFlammable.FireStacks * ratio;
destFlammable.FireStacks += lost;
Ignite(destUid, srcUid, destFlammable);
if (srcFlammable.CanExtinguish)
{
srcFlammable.FireStacks -= lost;
UpdateAppearance(srcUid, srcFlammable);
}
// swap the entity losing stacks depending on whichever has the most firestack kilos
var (src, dest) = flammable.FireStacks * mass1 > otherFlammable.FireStacks * mass2
? (-1f, 1f)
: (1f, -1f);
// bring each entity to the same firestack mass, firestacks being scaled by the other's mass
AdjustFireStacks(uid, src * avg * mass2, flammable);
AdjustFireStacks(otherUid, dest * avg * mass1, otherFlammable);
}
private void OnIsHot(EntityUid uid, FlammableComponent flammable, IsHotEvent args)
@@ -287,13 +270,26 @@ namespace Content.Server.Atmos.EntitySystems
if (!Resolve(uid, ref flammable))
return;
flammable.FireStacks = MathF.Min(MathF.Max(flammable.MinimumFireStacks, flammable.FireStacks + relativeFireStacks), flammable.MaximumFireStacks);
SetFireStacks(uid, flammable.FireStacks + relativeFireStacks, flammable);
}
if (flammable.OnFire && flammable.FireStacks <= 0)
public void SetFireStacks(EntityUid uid, float stacks, FlammableComponent? flammable = null)
{
if (!Resolve(uid, ref flammable))
return;
flammable.FireStacks = MathF.Min(MathF.Max(flammable.MinimumFireStacks, stacks), flammable.MaximumFireStacks);
if (flammable.FireStacks <= 0)
{
Extinguish(uid, flammable);
}
else
{
flammable.OnFire = true;
UpdateAppearance(uid, flammable);
}
}
public void Extinguish(EntityUid uid, FlammableComponent? flammable = null)
{

View File

@@ -36,7 +36,7 @@ public sealed class IgnitionSourceSystem : EntitySystem
/// </summary>
public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
{
if (!Resolve(ent, ref ent.Comp))
if (!Resolve(ent, ref ent.Comp, false))
return;
ent.Comp.Ignited = ignited;