Skip to content

Commit

Permalink
metal foam grenades (space-wizards#29428)
Browse files Browse the repository at this point in the history
* metal foam grenades

* wow okay

* meh

* bruh

* test

* push
  • Loading branch information
EmoGarbage404 authored and themias committed Aug 9, 2024
1 parent c9bdf14 commit 44f8728
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 14 deletions.
10 changes: 7 additions & 3 deletions Content.Server/EntityEffects/Effects/AreaReactionEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Fluids.EntitySystems;
using Content.Server.Spreader;
using Content.Shared.Audio;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Database;
Expand Down Expand Up @@ -64,16 +65,19 @@ public override void Effect(EntityEffectBaseArgs args)
var transform = reagentArgs.EntityManager.GetComponent<TransformComponent>(reagentArgs.TargetEntity);
var mapManager = IoCManager.Resolve<IMapManager>();
var mapSys = reagentArgs.EntityManager.System<MapSystem>();
var sys = reagentArgs.EntityManager.System<TransformSystem>();
var spreaderSys = args.EntityManager.System<SpreaderSystem>();
var sys = args.EntityManager.System<TransformSystem>();
var mapCoords = sys.GetMapCoordinates(reagentArgs.TargetEntity, xform: transform);

if (!mapManager.TryFindGridAt(mapCoords, out var gridUid, out var grid) ||
!mapSys.TryGetTileRef(gridUid, grid, transform.Coordinates, out var tileRef) ||
tileRef.Tile.IsSpace())
!mapSys.TryGetTileRef(gridUid, grid, transform.Coordinates, out var tileRef))
{
return;
}

if (spreaderSys.RequiresFloorToSpread(_prototypeId) && tileRef.Tile.IsSpace())
return;

var coords = mapSys.MapToGrid(gridUid, mapCoords);
var ent = reagentArgs.EntityManager.SpawnEntity(_prototypeId, coords.SnapToGrid());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Shared.Explosion.Components;
using Content.Shared.Explosion.EntitySystems;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Spreader;
using Content.Shared.Chemistry.Components;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Maps;
Expand All @@ -17,6 +18,7 @@ public sealed class SmokeOnTriggerSystem : SharedSmokeOnTriggerSystem
[Dependency] private readonly IMapManager _mapMan = default!;
[Dependency] private readonly SmokeSystem _smoke = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SpreaderSystem _spreader = default!;

public override void Initialize()
{
Expand All @@ -31,11 +33,14 @@ private void OnTrigger(EntityUid uid, SmokeOnTriggerComponent comp, TriggerEvent
var mapCoords = _transform.GetMapCoordinates(uid, xform);
if (!_mapMan.TryFindGridAt(mapCoords, out _, out var grid) ||
!grid.TryGetTileRef(xform.Coordinates, out var tileRef) ||
tileRef.Tile.IsSpace())
tileRef.Tile.IsEmpty)
{
return;
}

if (_spreader.RequiresFloorToSpread(comp.SmokePrototype.ToString()) && tileRef.Tile.IsSpace())
return;

var coords = grid.MapToGrid(mapCoords);
var ent = Spawn(comp.SmokePrototype, coords.SnapToGrid());
if (!TryComp<SmokeComponent>(ent, out var smoke))
Expand Down
17 changes: 15 additions & 2 deletions Content.Server/Spreader/SpreaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Atmos.EntitySystems;
using Content.Server.Shuttles.Components;
using Content.Shared.Atmos;
using Content.Shared.Maps;
using Content.Shared.Spreader;
using Content.Shared.Tag;
using Robust.Shared.Collections;
Expand Down Expand Up @@ -175,11 +176,12 @@ private void Spread(EntityUid uid, TransformComponent xform, ProtoId<EdgeSpreade
/// </summary>
public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpreaderPrototype> prototype, out ValueList<(MapGridComponent, TileRef)> freeTiles, out ValueList<Vector2i> occupiedTiles, out ValueList<EntityUid> neighbors)
{
// TODO remove occupiedTiles -- its currently unused and just slows this method down.
DebugTools.Assert(_prototype.HasIndex(prototype));
freeTiles = [];
occupiedTiles = [];
neighbors = [];
// TODO remove occupiedTiles -- its currently unused and just slows this method down.
if (!_prototype.TryIndex(prototype, out var spreaderPrototype))
return;

if (!TryComp<MapGridComponent>(comp.GridUid, out var grid))
return;
Expand Down Expand Up @@ -244,6 +246,9 @@ public void GetNeighbors(EntityUid uid, TransformComponent comp, ProtoId<EdgeSpr
if (!_map.TryGetTileRef(neighborEnt, neighborGrid, neighborPos, out var tileRef) || tileRef.Tile.IsEmpty)
continue;

if (spreaderPrototype.PreventSpreadOnSpaced && tileRef.Tile.IsSpace())
continue;

var directionEnumerator = _map.GetAnchoredEntitiesEnumerator(neighborEnt, neighborGrid, neighborPos);
var occupied = false;

Expand Down Expand Up @@ -335,4 +340,12 @@ public void ActivateSpreadableNeighbors(EntityUid uid, (EntityUid Grid, Vector2i
}
}
}

public bool RequiresFloorToSpread(EntProtoId<EdgeSpreaderComponent> spreader)
{
if (!_prototype.Index(spreader).TryGetComponent<EdgeSpreaderComponent>(out var spreaderComp, EntityManager.ComponentFactory))
return false;

return _prototype.Index(spreaderComp.Id).PreventSpreadOnSpaced;
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Spreader/EdgeSpreaderPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ public sealed partial class EdgeSpreaderPrototype : IPrototype
{
[IdDataField] public string ID { get; } = string.Empty;
[DataField(required:true)] public int UpdatesPerSecond;

/// <summary>
/// If true, this spreader can't spread onto spaced tiles like lattice.
/// </summary>
[DataField]
public bool PreventSpreadOnSpaced = true;
}
36 changes: 36 additions & 0 deletions Content.Shared/Tiles/ReplaceFloorOnSpawnComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Content.Shared.Maps;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.Tiles;

/// <summary>
/// Replaces floor tiles around this entity when it spawns
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(ReplaceFloorOnSpawnSystem))]
public sealed partial class ReplaceFloorOnSpawnComponent : Component
{
/// <summary>
/// The floor tiles that will be replaced. If null, will replace all.
/// </summary>
[DataField]
public List<ProtoId<ContentTileDefinition>>? ReplaceableTiles = new();

/// <summary>
/// The tiles that it will replace. Randomly picked from the list.
/// </summary>
[DataField]
public List<ProtoId<ContentTileDefinition>> ReplacementTiles = new();

/// <summary>
/// Whether or not there has to be a tile in the location to be replaced.
/// </summary>
[DataField]
public bool ReplaceSpace = true;

/// <summary>
/// List of offsets from the base tile, used to determine which tiles will be replaced.
/// </summary>
[DataField]
public List<Vector2i> Offsets = new() { Vector2i.Up, Vector2i.Down, Vector2i.Left, Vector2i.Right, Vector2i.Zero };
}
48 changes: 48 additions & 0 deletions Content.Shared/Tiles/ReplaceFloorOnSpawnSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Shared.Tiles;

public sealed class ReplaceFloorOnSpawnSystem : EntitySystem
{
[Dependency] private readonly ITileDefinitionManager _tile = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedMapSystem _map = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ReplaceFloorOnSpawnComponent, MapInitEvent>(OnMapInit);
}

private void OnMapInit(Entity<ReplaceFloorOnSpawnComponent> ent, ref MapInitEvent args)
{
var xform = Transform(ent);
if (xform.GridUid is not { } grid || !TryComp<MapGridComponent>(grid, out var gridComp))
return;

if (ent.Comp.ReplaceableTiles != null && ent.Comp.ReplaceableTiles.Count == 0)
return;

var tileIndices = _map.LocalToTile(grid, gridComp, xform.Coordinates);

foreach (var offset in ent.Comp.Offsets)
{
var actualIndices = tileIndices + offset;

if (!_map.TryGetTileRef(grid, gridComp, actualIndices, out var tile))
continue;

if (ent.Comp.ReplaceableTiles != null &&
!tile.Tile.IsEmpty &&
!ent.Comp.ReplaceableTiles.Contains(_tile[tile.Tile.TypeId].ID))
continue;

var tileToSet = _random.Pick(ent.Comp.ReplacementTiles);
_map.SetTile(grid, gridComp, tile.GridIndices, new Tile(_prototype.Index(tileToSet).TileId));
}
}
}
3 changes: 2 additions & 1 deletion Resources/Locale/en-US/tiles/tiles.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ tiles-gold-tile = gold tile
tiles-silver-tile = silver tile
tiles-glass-floor = glass floor
tiles-reinforced-glass-floor = reinforced glass floor
tiles-metal-foam = metal foam floor
tiles-green-circuit-floor = green circuit floor
tiles-blue-circuit-floor = blue circuit floor
tiles-snow = snow
Expand Down Expand Up @@ -126,4 +127,4 @@ tiles-mowed-astro-grass = mowed astro-grass
tiles-jungle-astro-grass = jungle astro-grass
tiles-astro-ice = astro-ice
tiles-astro-snow = astro-snow
tiles-wood-large = large wood
tiles-wood-large = large wood
10 changes: 10 additions & 0 deletions Resources/Prototypes/Catalog/Cargo/cargo_engineering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
category: cargoproduct-category-name-engineering
group: market

- type: cargoProduct
id: EngineeringFoamGrenade
icon:
sprite: Objects/Weapons/Grenades/metalfoam.rsi
state: icon
product: CrateEngineeringFoamGrenade
cost: 2500
category: cargoproduct-category-name-engineering
group: market

- type: cargoProduct
id: EngineeringCableBulk
icon:
Expand Down
11 changes: 11 additions & 0 deletions Resources/Prototypes/Catalog/Fills/Crates/engineering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
- id: CableHVStack
amount: 3

- type: entity
id: CrateEngineeringFoamGrenade
parent: CrateEngineeringSecure
name: sealant grenade crate
description: 5 metal foam sealant grenades.
components:
- type: StorageFill
contents:
- id: MetalFoamGrenade
amount: 5

- type: entity
id: CrateEngineeringCableBulk
parent: CrateElectrical
Expand Down
11 changes: 10 additions & 1 deletion Resources/Prototypes/Entities/Effects/chemistry_effects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
state: m_foam-north
- map: [ "enum.EdgeLayer.West" ]
state: m_foam-west
- type: EdgeSpreader
id: MetalFoam
- type: FoamVisuals
animationTime: 0.6
animationState: m_foam-dissolve
Expand Down Expand Up @@ -135,7 +137,7 @@
- type: RCDDeconstructable
cost: 2
delay: 2
fx: EffectRCDDeconstruct2
fx: EffectRCDDeconstruct2
- type: Clickable
- type: InteractionOutline
- type: Sprite
Expand All @@ -159,6 +161,13 @@
- type: Transform
anchored: true
- type: Airtight
- type: ReplaceFloorOnSpawn
replaceableTiles:
- Plating
- Lattice
- TrainLattice
replacementTiles:
- FloorMetalFoam
- type: Damageable
damageContainer: Inorganic
damageModifierSet: Metallic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,21 @@
- ReagentId: TearGas
Quantity: 50

- type: entity
parent: SmokeGrenade
id: MetalFoamGrenade
name: metal foam grenade
description: An emergency tool used for patching up holes. Almost as good as real walls.
components:
- type: Sprite
sprite: Objects/Weapons/Grenades/metalfoam.rsi
- type: SmokeOnTrigger
duration: 10
spreadAmount: 13
smokePrototype: AluminiumMetalFoam
- type: StaticPrice
price: 350

# Non-explosive "dummy" grenades to use as a distraction.

- type: entity
Expand Down
17 changes: 16 additions & 1 deletion Resources/Prototypes/Tiles/floors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
collection: FootstepHull
itemDrop: FloorTileItemBrassFilled
heatCapacity: 10000

- type: tile
id: FloorBrassReebe
name: tiles-brass-floor-reebe
Expand Down Expand Up @@ -1391,6 +1391,21 @@
itemDrop: SheetRGlass1
heatCapacity: 10000

- type: tile
id: FloorMetalFoam
name: tiles-metal-foam
sprite: /Textures/Tiles/foammetal.png
variants: 1
placementVariants:
- 1.0
baseTurf: Plating
isSubfloor: false
deconstructTools: [ Prying ]
footstepSounds:
collection: FootstepHull
itemDrop: SheetSteel1
heatCapacity: 10000

# Circuits
- type: tile
id: FloorGreenCircuit
Expand Down
5 changes: 5 additions & 0 deletions Resources/Prototypes/edge_spreaders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
- type: edgeSpreader
id: Smoke
updatesPerSecond: 8

- type: edgeSpreader
id: MetalFoam
updatesPerSecond: 16
preventSpreadOnSpaced: false
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Created by EmoGarbage404",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
},
{
"name": "primed",
"delays": [
[
0.2,
0.1
]
]
},
{
"name": "equipped-BELT",
"directions": 4
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 44f8728

Please sign in to comment.