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:
39
Content.Server/_CP14/Temperature/CPFireSpreadComponent.cs
Normal file
39
Content.Server/_CP14/Temperature/CPFireSpreadComponent.cs
Normal 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;
|
||||
}
|
||||
60
Content.Server/_CP14/Temperature/CPFireSpreadSystem.cs
Normal file
60
Content.Server/_CP14/Temperature/CPFireSpreadSystem.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user