(cherry picked from commit d5caf492621fd45366da3b01bac18133f4e3414f)
This commit is contained in:
VMSolidus
2025-03-18 23:41:48 -04:00
committed by Spatison
parent c60a484a96
commit d0736f1343
3 changed files with 40 additions and 46 deletions

View File

@@ -205,47 +205,30 @@ 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;
var mass2 = 1f;
if (_physicsQuery.TryComp(uid, out var physics) && _physicsQuery.TryComp(otherUid, out var otherPhys))
{
// 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))
{
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;
mass1 = physics.Mass;
mass2 = otherPhys.Mass;
}
// 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);
// 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 + otherFlammable.FireStacks) / total;
// 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, ignite: true);
AdjustFireStacks(otherUid, dest * avg * mass1, otherFlammable, ignite: true);
}
private void OnIsHot(EntityUid uid, FlammableComponent flammable, IsHotEvent args)
@@ -283,20 +266,28 @@ namespace Content.Server.Atmos.EntitySystems
_appearance.SetData(uid, ToggleableLightVisuals.Enabled, flammable.OnFire, appearance);
}
public void AdjustFireStacks(EntityUid uid, float relativeFireStacks, FlammableComponent? flammable = null)
public void AdjustFireStacks(EntityUid uid, float relativeFireStacks, FlammableComponent? flammable = null, bool ignite = false)
{
if (!Resolve(uid, ref flammable))
return;
if (relativeFireStacks > 0)
relativeFireStacks *= flammable.FireStackIncreaseMultiplier;
SetFireStacks(uid, flammable.FireStacks + relativeFireStacks, flammable, ignite);
}
flammable.FireStacks = MathF.Min(MathF.Max(flammable.MinimumFireStacks, flammable.FireStacks + relativeFireStacks), flammable.MaximumFireStacks);
public void SetFireStacks(EntityUid uid, float stacks, FlammableComponent? flammable = null, bool ignite = false)
{
if (!Resolve(uid, ref flammable))
return;
if (flammable.OnFire && flammable.FireStacks <= 0)
flammable.FireStacks = MathF.Min(MathF.Max(flammable.MinimumFireStacks, stacks), flammable.MaximumFireStacks);
if (flammable.FireStacks <= 0)
Extinguish(uid, flammable);
else
{
flammable.OnFire = ignite;
UpdateAppearance(uid, flammable);
}
}
public void Extinguish(EntityUid uid, FlammableComponent? flammable = null)

View File

@@ -13,8 +13,9 @@ namespace Content.Server.EntityEffects.Effects
[DataField]
public float Multiplier = 0.05f;
// The fire stack multiplier if fire stacks already exist on target, only works if 0 or greater
[DataField]
public float MultiplierOnExisting = 1f;
public float MultiplierOnExisting = -1f;
public override bool ShouldLog => true;
@@ -28,7 +29,8 @@ namespace Content.Server.EntityEffects.Effects
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out FlammableComponent? flammable))
return;
var multiplier = flammable.FireStacks == 0f ? Multiplier : MultiplierOnExisting;
// Sets the multiplier for FireStacks to MultiplierOnExisting is 0 or greater and target already has FireStacks
var multiplier = flammable.FireStacks != 0f && MultiplierOnExisting >= 0 ? MultiplierOnExisting : Multiplier;
var quantity = 1f;
if (args is EntityEffectReagentArgs reagentArgs)
{
@@ -36,7 +38,8 @@ namespace Content.Server.EntityEffects.Effects
reagentArgs.EntityManager.System<FlammableSystem>().AdjustFireStacks(args.TargetEntity, quantity * multiplier, flammable);
if (reagentArgs.Reagent != null)
reagentArgs.Source?.RemoveReagent(reagentArgs.Reagent.ID, reagentArgs.Quantity);
} else
}
else
{
args.EntityManager.System<FlammableSystem>().AdjustFireStacks(args.TargetEntity, multiplier, flammable);
}

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;