Skip to content

Commit

Permalink
Critical bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
13lackHawk committed May 3, 2024
1 parent a8ac129 commit 46e118e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void AddSmiteVerbs(GetVerbsEvent<Verb> args)
Act = () =>
{
// Fuck you. Burn Forever.
flammable.FireStacks = FlammableSystem.MaximumFireStacks;
flammable.FireStacks = flammable.MaximumFireStacks;
_flammableSystem.Ignite(args.Target, args.User);
var xform = Transform(args.Target);
_popupSystem.PopupEntity(Loc.GetString("admin-smite-set-alight-self"), args.Target,
Expand Down
34 changes: 25 additions & 9 deletions Content.Server/Atmos/Components/FlammableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,65 @@ public sealed partial class FlammableComponent : Component

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool OnFire { get; set; }
public bool OnFire;

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float FireStacks { get; set; }
public float FireStacks;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("fireSpread")]
[DataField]
public float MaximumFireStacks = 10f;

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float MinimumFireStacks = -10f;

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public string FlammableFixtureID = "flammable";

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float MinIgnitionTemperature = 373.15f;

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public bool FireSpread { get; private set; } = false;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("canResistFire")]
[DataField]
public bool CanResistFire { get; private set; } = false;

[DataField("damage", required: true)]
[DataField(required: true)]
[ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier Damage = new(); // Empty by default, we don't want any funny NREs.

/// <summary>
/// Used for the fixture created to handle passing firestacks when two flammable objects collide.
/// </summary>
[DataField("flammableCollisionShape")]
[DataField]
public IPhysShape FlammableCollisionShape = new PhysShapeCircle(0.35f);

/// <summary>
/// Should the component be set on fire by interactions with isHot entities
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("alwaysCombustible")]
[DataField]
public bool AlwaysCombustible = false;

/// <summary>
/// Can the component anyhow lose its FireStacks?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("canExtinguish")]
[DataField]
public bool CanExtinguish = true;

/// <summary>
/// How many firestacks should be applied to component when being set on fire?
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("firestacksOnIgnite")]
[DataField]
public float FirestacksOnIgnite = 2.0f;

/// <summary>
Expand Down
68 changes: 37 additions & 31 deletions Content.Server/Atmos/EntitySystems/FlammableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ public sealed class FlammableSystem : EntitySystem
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly IRobustRandom _random = default!;

public const float MinimumFireStacks = -10f;
public const float MaximumFireStacks = 20f;
private const float UpdateTime = 1f;
private EntityQuery<PhysicsComponent> _physicsQuery;

public const float MinIgnitionTemperature = 373.15f;
public const string FlammableFixtureID = "flammable";
// This should probably be moved to the component, requires a rewrite, all fires tick at the same time
private const float UpdateTime = 1f;

private float _timer;

Expand All @@ -62,6 +60,8 @@ public override void Initialize()
{
UpdatesAfter.Add(typeof(AtmosphereSystem));

_physicsQuery = GetEntityQuery<PhysicsComponent>();

SubscribeLocalEvent<FlammableComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<FlammableComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<FlammableComponent, StartCollideEvent>(OnCollide);
Expand Down Expand Up @@ -130,7 +130,7 @@ private void OnMapInit(EntityUid uid, FlammableComponent component, MapInitEvent
if (!TryComp<PhysicsComponent>(uid, out var body))
return;

_fixture.TryCreateFixture(uid, component.FlammableCollisionShape, FlammableFixtureID, hard: false,
_fixture.TryCreateFixture(uid, component.FlammableCollisionShape, component.FlammableFixtureID, hard: false,
collisionMask: (int) CollisionGroup.FullTileLayer, body: body);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ private void OnCollide(EntityUid uid, FlammableComponent flammable, ref StartCol

// Normal hard collisions, though this isn't generally possible since most flammable things are mobs
// which don't collide with one another, shouldn't work here.
if (args.OtherFixtureId != FlammableFixtureID && args.OurFixtureId != FlammableFixtureID)
if (args.OtherFixtureId != flammable.FlammableFixtureID && args.OurFixtureId != flammable.FlammableFixtureID)
return;

if (!flammable.FireSpread)
Expand All @@ -203,7 +203,17 @@ private void OnCollide(EntityUid uid, FlammableComponent flammable, ref StartCol
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);
Expand All @@ -212,25 +222,24 @@ private void OnCollide(EntityUid uid, FlammableComponent flammable, ref StartCol
}

// 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);
}
}

Expand All @@ -241,7 +250,7 @@ private void OnIsHot(EntityUid uid, FlammableComponent flammable, IsHotEvent arg

private void OnTileFire(Entity<FlammableComponent> ent, ref TileFireEvent args)
{
var tempDelta = args.Temperature - MinIgnitionTemperature;
var tempDelta = args.Temperature - ent.Comp.MinIgnitionTemperature;

_fireEvents.TryGetValue(ent, out var maxTemp);

Expand Down Expand Up @@ -274,7 +283,7 @@ public void AdjustFireStacks(EntityUid uid, float relativeFireStacks, FlammableC
if (!Resolve(uid, ref flammable))
return;

flammable.FireStacks = MathF.Min(MathF.Max(MinimumFireStacks, flammable.FireStacks + relativeFireStacks), MaximumFireStacks);
flammable.FireStacks = MathF.Min(MathF.Max(flammable.MinimumFireStacks, flammable.FireStacks + relativeFireStacks), flammable.MaximumFireStacks);

if (flammable.OnFire && flammable.FireStacks <= 0)
Extinguish(uid, flammable);
Expand Down Expand Up @@ -426,13 +435,10 @@ public override void Update(float frameTime)
EnsureComp<IgnitionSourceComponent>(uid);
_ignitionSourceSystem.SetIgnited(uid);

//var damageScale = MathF.Min( flammable.FireStacks, 5);
var damageScale = 0; // A-13 fix

if (TryComp(uid, out TemperatureComponent? temp))
_temperatureSystem.ChangeHeat(uid, 12500 * damageScale, false, temp);
_temperatureSystem.ChangeHeat(uid, 12500 * flammable.FireStacks, false, temp);

_damageableSystem.TryChangeDamage(uid, flammable.Damage * damageScale, interruptsDoAfters: false);
_damageableSystem.TryChangeDamage(uid, flammable.Damage * flammable.FireStacks, interruptsDoAfters: false);

AdjustFireStacks(uid, flammable.FirestackFade * (flammable.Resisting ? 10f : 1f), flammable);
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/StepTrigger/Systems/StepTriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private bool Update(EntityUid uid, StepTriggerComponent component, TransformComp

if (component.Blacklist != null && TryComp<MapGridComponent>(transform.GridUid, out var grid))
{
var positon = _map.LocalToTile(uid, grid, transform.Coordinates);
var positon = _map.LocalToTile(transform.GridUid.Value, grid, transform.Coordinates);
var anch = _map.GetAnchoredEntitiesEnumerator(uid, grid, positon);

while (anch.MoveNext(out var ent))
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Mobs/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
canResistFire: true
damage: #per second, scales with number of fire 'stacks'
types:
Heat: 3
Heat: 1.5
- type: FireVisuals
sprite: Mobs/Effects/onfire.rsi
normalState: Generic_mob_burning
Expand Down

0 comments on commit 46e118e

Please sign in to comment.