Fire spreading (#92)

* fire update

* add flammable to more ent, add floors

* add cool fire sprites, noSpawn tiles

* fix floor collider

* floor resprite

* Update floors.yml

* fixes

* Update tables.yml
This commit is contained in:
Ed
2024-04-14 18:31:23 +03:00
committed by GitHub
parent 3dff87b3e1
commit 635c0ce99c
22 changed files with 451 additions and 36 deletions

View File

@@ -0,0 +1,39 @@
namespace Content.Server._CP14.Temperature;
/// <summary>
/// A component that allows fire to spread to nearby objects. The basic mechanics of a spreading fire
/// </summary>
[RegisterComponent, Access(typeof(CPFireSpreadSystem))]
public sealed partial class CPFireSpreadComponent : Component
{
/// <summary>
/// radius of ignition of neighboring objects
/// </summary>
[DataField]
public float Radius = 1f;
/// <summary>
/// chance of spreading to neighboring properties
/// </summary>
[DataField]
public float Prob = 0.5f;
/// <summary>
/// how often objects will try to set the neighbors on fire. In Seconds
/// </summary>
[DataField]
public float SpreadCooldownMin = 3f;
/// <summary>
/// how often objects will try to set the neighbors on fire. In Seconds
/// </summary>
[DataField]
public float SpreadCooldownMax = 7f;
/// <summary>
/// the time of the next fire spread
/// </summary>
[DataField]
public TimeSpan NextSpreadTime { get; set; } = TimeSpan.Zero;
}

View File

@@ -0,0 +1,60 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.CrystallPunk.Temperature;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server._CP14.Temperature;
public sealed partial class CPFireSpreadSystem : EntitySystem
{
[Dependency] private readonly FlammableSystem _flammable = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
SubscribeLocalEvent <CPFireSpreadComponent, OnFireChangedEvent>(OnCompInit);
}
private void OnCompInit(Entity<CPFireSpreadComponent> ent, ref OnFireChangedEvent args)
{
if (!args.OnFire)
return;
var cooldown = _random.NextFloat(ent.Comp.SpreadCooldownMin, ent.Comp.SpreadCooldownMax);
ent.Comp.NextSpreadTime = _gameTiming.CurTime + TimeSpan.FromSeconds(cooldown);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CPFireSpreadComponent, FlammableComponent>();
while (query.MoveNext(out var uid, out var spread, out var flammable))
{
if (!flammable.OnFire)
continue;
if (spread.NextSpreadTime < _gameTiming.CurTime) // Spread
{
var targets = _lookup.GetEntitiesInRange<FlammableComponent>(_transform.GetMapCoordinates(uid), spread.Radius);
foreach (var target in targets)
{
if (!_random.Prob(spread.Prob))
continue;
_flammable.Ignite(target, uid);
var cooldown = _random.NextFloat(spread.SpreadCooldownMin, spread.SpreadCooldownMax);
spread.NextSpreadTime = _gameTiming.CurTime + TimeSpan.FromSeconds(cooldown);
}
}
}
}
}