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:
@@ -204,47 +204,30 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (!flammable.OnFire && !otherFlammable.OnFire)
|
if (!flammable.OnFire && !otherFlammable.OnFire)
|
||||||
return; // Neither are on fire
|
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;
|
||||||
|
var mass2 = 1f;
|
||||||
|
if (_physicsQuery.TryComp(uid, out var physics) && _physicsQuery.TryComp(otherUid, out var otherPhys))
|
||||||
{
|
{
|
||||||
// Both are on fire -> equalize fire stacks.
|
mass1 = physics.Mass;
|
||||||
// Weight each thing's firestacks by its mass
|
mass2 = otherPhys.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);
|
|
||||||
UpdateAppearance(otherUid, otherFlammable);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only one is on fire -> attempt to spread the fire.
|
// when the thing on fire is more massive than the other, the following happens:
|
||||||
var (srcUid, srcFlammable, destUid, destFlammable) = flammable.OnFire
|
// - the thing on fire loses a small number of firestacks
|
||||||
? (uid, flammable, otherUid, otherFlammable)
|
// - the other thing gains a large number of firestacks
|
||||||
: (otherUid, otherFlammable, uid, flammable);
|
// 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 + otherFlammable.FireStacks) / total;
|
||||||
|
|
||||||
// if the thing on fire has less mass, spread less firestacks and vice versa
|
// swap the entity losing stacks depending on whichever has the most firestack kilos
|
||||||
var ratio = 0.5f;
|
var (src, dest) = flammable.FireStacks * mass1 > otherFlammable.FireStacks * mass2
|
||||||
if (_physicsQuery.TryComp(srcUid, out var srcPhysics) && _physicsQuery.TryComp(destUid, out var destPhys))
|
? (-1f, 1f)
|
||||||
{
|
: (1f, -1f);
|
||||||
ratio *= srcPhysics.Mass / destPhys.Mass;
|
// 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);
|
||||||
var lost = srcFlammable.FireStacks * ratio;
|
|
||||||
destFlammable.FireStacks += lost;
|
|
||||||
Ignite(destUid, srcUid, destFlammable);
|
|
||||||
if (srcFlammable.CanExtinguish)
|
|
||||||
{
|
|
||||||
srcFlammable.FireStacks -= lost;
|
|
||||||
UpdateAppearance(srcUid, srcFlammable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIsHot(EntityUid uid, FlammableComponent flammable, IsHotEvent args)
|
private void OnIsHot(EntityUid uid, FlammableComponent flammable, IsHotEvent args)
|
||||||
@@ -287,12 +270,25 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (!Resolve(uid, ref flammable))
|
if (!Resolve(uid, ref flammable))
|
||||||
return;
|
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);
|
Extinguish(uid, flammable);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
flammable.OnFire = true;
|
||||||
UpdateAppearance(uid, flammable);
|
UpdateAppearance(uid, flammable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Extinguish(EntityUid uid, FlammableComponent? flammable = null)
|
public void Extinguish(EntityUid uid, FlammableComponent? flammable = null)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public sealed class IgnitionSourceSystem : EntitySystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
|
public void SetIgnited(Entity<IgnitionSourceComponent?> ent, bool ignited = true)
|
||||||
{
|
{
|
||||||
if (!Resolve(ent, ref ent.Comp))
|
if (!Resolve(ent, ref ent.Comp, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ent.Comp.Ignited = ignited;
|
ent.Comp.Ignited = ignited;
|
||||||
|
|||||||
Reference in New Issue
Block a user