using Content.Shared.Damage; using Content.Shared.Sound; using Robust.Shared.Prototypes; using Robust.Shared.Utility; namespace Content.Shared.Explosion; /// /// Explosion Prototype. Determines damage, tile break probabilities, and visuals. /// /// /// Does not currently support prototype hot-reloading. The explosion-intensity required to destroy airtight /// entities is evaluated and stored by the explosion system. Adding or removing a prototype would require updating /// that map of airtight entities. This could be done, but is just not yet implemented. /// [Prototype("explosion")] public sealed class ExplosionPrototype : IPrototype { [DataField("id", required: true)] public string ID { get; } = default!; /// /// Damage to deal to entities. This is scaled by the explosion intensity. /// [DataField("damagePerIntensity", required: true)] public readonly DamageSpecifier DamagePerIntensity = default!; /// /// This set of points, together with define a function that maps the /// explosion intensity to a tile break chance via linear interpolation. /// [DataField("tileBreakChance")] private readonly float[] _tileBreakChance = { 0f, 1f }; /// /// This set of points, together with define a function that maps the /// explosion intensity to a tile break chance via linear interpolation. /// [DataField("tileBreakIntensity")] private readonly float[] _tileBreakIntensity = {0f, 15f }; /// /// When a tile is broken by an explosion, the intensity is reduced by this amount and is used to try and /// break the tile a second time. This is repeated until a roll fails or the tile has become space. /// /// /// If this number is too small, even relatively weak explosions can have a non-zero /// chance to create a space tile. /// [DataField("tileBreakRerollReduction")] public readonly float TileBreakRerollReduction = 10f; /// /// Color emitted by a point light at the center of the explosion. /// [DataField("lightColor")] public readonly Color LightColor = Color.Orange; /// /// Color used to modulate the fire texture. /// [DataField("fireColor")] public readonly Color? FireColor; [DataField("Sound")] public readonly SoundSpecifier Sound = new SoundCollectionSpecifier("explosion"); [DataField("texturePath")] public readonly ResourcePath TexturePath = new("/Textures/Effects/fire.rsi"); /// /// How intense does the explosion have to be at a tile to advance to the next fire texture state? /// [DataField("intensityPerState")] public float IntensityPerState = 12; // Theres probably a better way to do this. Currently Atmos just hard codes a constant int, so I have no one to // steal code from. [DataField("fireStates")] public readonly int FireStates = 3; /// /// Basic function for linear interpolation of the _tileBreakChance and _tileBreakIntensity arrays /// public float TileBreakChance(float intensity) { if (_tileBreakChance.Length == 0 || _tileBreakChance.Length != _tileBreakIntensity.Length) { Logger.Error($"Malformed tile break chance definitions for explosion prototype: {ID}"); return 0; } if (intensity >= _tileBreakIntensity[^1] || _tileBreakIntensity.Length == 1) return _tileBreakChance[^1]; if (intensity <= _tileBreakIntensity[0]) return _tileBreakChance[0]; int i = Array.FindIndex(_tileBreakIntensity, k => k >= intensity); var slope = (_tileBreakChance[i] - _tileBreakChance[i - 1]) / (_tileBreakIntensity[i] - _tileBreakIntensity[i - 1]); return _tileBreakChance[i - 1] + slope * (intensity - _tileBreakIntensity[i - 1]); } }