Files
tbd-station-14/Content.Shared/Explosion/ExplosionPrototype.cs
Leon Friedrich 56168e592e Explosion refactor (#5230)
* Explosions

* fix yaml typo

and prevent silly UI inputs

* oop

* Use modified contains() checks

And remove IEnumerable

* Buff nuke, nerf meteors

* optimize the entity lookup stuff a bit

* fix tile (0,0) error

forgot to do an initial Enumerator.MoveNext(), so the first tile was always the "null" tile.

* remove celebration

* byte -> int

* remove diag edge tile dict

* fix one bug

but there is another

* fix the other bug

turns out dividing a ushort leads to rounding errors.  Why TF is the grid tile size even a ushort in the first place.

* improve edge map

* fix minor bug

If the initial-explosion tile had an airtight entity on it, the tile was processed twice.

* some reviews (transform queries, eye.mapid, and tilesizes in overlays)

* Apply suggestions from code review

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* is map paused

* GetAllTiles ignores space by default

* WriteLine -> WriteError

* First -> FirstOrDefault()

* default prototype const string

* entity query

* misc review changes

* grid edge max distance

* fix fire texture defn

bad use of type serializer and ioc-resolves

* Remove ExplosionLaunched

And allow nukes to throw items towards the outer part of an explosion

* no hot-reload disclaimer

* replace prototype id string with int index

* optimise damage a tiiiiny bit.

* entity queries

* comments

* misc mirror comments

* cvars

* admin logs

* move intensity-per-state to prototype

* update tile event to ECS event

* git mv

* Tweak rpg & minibomb

also fix merge bug

* you don't exist anymore go away

* Fix build

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2022-03-31 21:39:26 -05:00

105 lines
4.1 KiB
C#

using Content.Shared.Damage;
using Content.Shared.Sound;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Explosion;
/// <summary>
/// Explosion Prototype. Determines damage, tile break probabilities, and visuals.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[Prototype("explosion")]
public sealed class ExplosionPrototype : IPrototype
{
[DataField("id", required: true)]
public string ID { get; } = default!;
/// <summary>
/// Damage to deal to entities. This is scaled by the explosion intensity.
/// </summary>
[DataField("damagePerIntensity", required: true)]
public readonly DamageSpecifier DamagePerIntensity = default!;
/// <summary>
/// This set of points, together with <see cref="_tileBreakIntensity"/> define a function that maps the
/// explosion intensity to a tile break chance via linear interpolation.
/// </summary>
[DataField("tileBreakChance")]
private readonly float[] _tileBreakChance = { 0f, 1f };
/// <summary>
/// This set of points, together with <see cref="_tileBreakChance"/> define a function that maps the
/// explosion intensity to a tile break chance via linear interpolation.
/// </summary>
[DataField("tileBreakIntensity")]
private readonly float[] _tileBreakIntensity = {0f, 15f };
/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// If this number is too small, even relatively weak explosions can have a non-zero
/// chance to create a space tile.
/// </remarks>
[DataField("tileBreakRerollReduction")]
public readonly float TileBreakRerollReduction = 10f;
/// <summary>
/// Color emitted by a point light at the center of the explosion.
/// </summary>
[DataField("lightColor")]
public readonly Color LightColor = Color.Orange;
/// <summary>
/// Color used to modulate the fire texture.
/// </summary>
[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");
/// <summary>
/// How intense does the explosion have to be at a tile to advance to the next fire texture state?
/// </summary>
[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;
/// <summary>
/// Basic function for linear interpolation of the _tileBreakChance and _tileBreakIntensity arrays
/// </summary>
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]);
}
}