Skip to content

Commit

Permalink
Mirror: haunted dungeon template (#321)
Browse files Browse the repository at this point in the history
## Mirror of PR #23768: [haunted dungeon
template](space-wizards/space-station-14#23768)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `952b7f4c4e8e957c0c3765f7b20f2745c9297e27`

PR opened by <img
src="https://avatars.githubusercontent.com/u/99158783?v=4"
width="16"/><a href="https://github.com/Emisse"> Emisse</a> at
2024-01-09 07:36:29 UTC

---

PR changed 17 files with 4009 additions and 67 deletions.

The PR had the following labels:


---

<details open="true"><summary><h1>Original Body</h1></summary>

> also for sloth when he gets to it
> 
> Requires space-wizards/RobustToolbox#4980


</details>

Co-authored-by: SimpleStation14 <Unknown>
  • Loading branch information
SimpleStation14 authored May 12, 2024
1 parent d19e5bb commit 3b635f1
Show file tree
Hide file tree
Showing 17 changed files with 4,009 additions and 67 deletions.
53 changes: 53 additions & 0 deletions Content.Server/Procedural/DungeonJob.CorridorClutterPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Threading.Tasks;
using Content.Shared.Procedural;
using Content.Shared.Procedural.PostGeneration;
using Content.Shared.Storage;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;

namespace Content.Server.Procedural;

public sealed partial class DungeonJob
{
private async Task PostGen(CorridorClutterPostGen gen, Dungeon dungeon, EntityUid gridUid, MapGridComponent grid,
Random random)
{
var physicsQuery = _entManager.GetEntityQuery<PhysicsComponent>();
var count = (int) Math.Ceiling(dungeon.CorridorTiles.Count * gen.Chance);

while (count > 0)
{
var tile = random.Pick(dungeon.CorridorTiles);

var enumerator = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, tile);
var blocked = false;

while (enumerator.MoveNext(out var ent))
{
if (!physicsQuery.TryGetComponent(ent, out var physics) ||
!physics.CanCollide ||
!physics.Hard)
{
continue;
}

blocked = true;
break;
}

if (blocked)
continue;

count--;

var protos = EntitySpawnCollection.GetSpawns(gen.Contents, random);
var coords = _maps.ToCenterCoordinates(_gridUid, tile, _grid);
_entManager.SpawnEntities(coords, protos);
await SuspendIfOutOfTime();

if (!ValidateResume())
return;
}
}
}
89 changes: 53 additions & 36 deletions Content.Server/Procedural/DungeonJob.PostGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed partial class DungeonJob

private bool HasWall(MapGridComponent grid, Vector2i tile)
{
var anchored = grid.GetAnchoredEntitiesEnumerator(tile);
var anchored = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, tile);

while (anchored.MoveNext(out var uid))
{
Expand All @@ -52,7 +52,7 @@ private async Task PostGen(AutoCablingPostGen gen, Dungeon dungeon, EntityUid gr
// Gather existing nodes
foreach (var tile in allTiles)
{
var anchored = grid.GetAnchoredEntitiesEnumerator(tile);
var anchored = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, tile);

while (anchored.MoveNext(out var anc))
{
Expand Down Expand Up @@ -186,7 +186,9 @@ private async Task PostGen(BoundaryWallPostGen gen, Dungeon dungeon, EntityUid g
// - Tiles first
foreach (var neighbor in dungeon.RoomExteriorTiles)
{
if (dungeon.RoomTiles.Contains(neighbor))
DebugTools.Assert(!dungeon.RoomTiles.Contains(neighbor));

if (dungeon.Entrances.Contains(neighbor))
continue;

if (!_anchorable.TileFree(grid, neighbor, DungeonSystem.CollisionLayer, DungeonSystem.CollisionMask))
Expand Down Expand Up @@ -265,7 +267,6 @@ private async Task PostGen(CornerClutterPostGen gen, Dungeon dungeon, EntityUid
Random random)
{
var physicsQuery = _entManager.GetEntityQuery<PhysicsComponent>();
var tagQuery = _entManager.GetEntityQuery<TagComponent>();

foreach (var tile in dungeon.CorridorTiles)
{
Expand Down Expand Up @@ -771,7 +772,7 @@ private async Task PostGen(CorridorPostGen gen, Dungeon dungeon, EntityUid gridU
{
for (var y = -expansion; y <= expansion; y++)
{
var neighbor = new Vector2i(tile.X + x, tile.Y + y);
var neighbor = new Vector2(tile.X + x, tile.Y + y).Floored();

if (dungeon.RoomTiles.Contains(neighbor) ||
dungeon.RoomExteriorTiles.Contains(neighbor) ||
Expand Down Expand Up @@ -817,6 +818,52 @@ private async Task PostGen(CorridorPostGen gen, Dungeon dungeon, EntityUid gridU
return mod;
});

WidenCorridor(dungeon, gen.Width, corridorTiles);

var setTiles = new List<(Vector2i, Tile)>();
var tileDef = _prototype.Index(gen.Tile);

foreach (var tile in corridorTiles)
{
setTiles.Add((tile, _tile.GetVariantTile(tileDef, random)));
}

grid.SetTiles(setTiles);
dungeon.CorridorTiles.UnionWith(corridorTiles);
BuildCorridorExterior(dungeon);
}

private void BuildCorridorExterior(Dungeon dungeon)
{
var exterior = dungeon.CorridorExteriorTiles;

// Just ignore entrances or whatever for now.
foreach (var tile in dungeon.CorridorTiles)
{
for (var x = -1; x <= 1; x++)
{
for (var y = -1; y <= 1; y++)
{
var neighbor = new Vector2i(tile.X + x, tile.Y + y);

if (dungeon.CorridorTiles.Contains(neighbor) ||
dungeon.RoomExteriorTiles.Contains(neighbor) ||
dungeon.RoomTiles.Contains(neighbor) ||
dungeon.Entrances.Contains(neighbor))
{
continue;
}

exterior.Add(neighbor);
}
}
}
}

private void WidenCorridor(Dungeon dungeon, float width, ICollection<Vector2i> corridorTiles)
{
var expansion = width - 2;

// Widen the path
if (expansion >= 1)
{
Expand All @@ -831,7 +878,7 @@ private async Task PostGen(CorridorPostGen gen, Dungeon dungeon, EntityUid gridU
{
for (var y = -expansion; y <= expansion; y++)
{
var neighbor = new Vector2i(node.X + x, node.Y + y);
var neighbor = new Vector2(node.X + x, node.Y + y).Floored();

// Diagonals still matter here.
if (dungeon.RoomTiles.Contains(neighbor) ||
Expand All @@ -852,36 +899,6 @@ private async Task PostGen(CorridorPostGen gen, Dungeon dungeon, EntityUid gridU
corridorTiles.Add(node);
}
}

var setTiles = new List<(Vector2i, Tile)>();
var tileDef = _prototype.Index(gen.Tile);

foreach (var tile in corridorTiles)
{
setTiles.Add((tile, _tile.GetVariantTile(tileDef, random)));
}

grid.SetTiles(setTiles);
dungeon.CorridorTiles.UnionWith(corridorTiles);

var exterior = dungeon.CorridorExteriorTiles;

// Just ignore entrances or whatever for now.
foreach (var tile in dungeon.CorridorTiles)
{
for (var x = -1; x <= 1; x++)
{
for (var y = -1; y <= 1; y++)
{
var neighbor = new Vector2i(tile.X + x, tile.Y + y);

if (dungeon.CorridorTiles.Contains(neighbor))
continue;

exterior.Add(neighbor);
}
}
}
}

private async Task PostGen(EntranceFlankPostGen gen, Dungeon dungeon, EntityUid gridUid, MapGridComponent grid,
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Procedural/DungeonJob.PrefabDunGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ private async Task<Dungeon> GeneratePrefabDungeon(PrefabDunGen prefab, EntityUid
var dungeonRotation = _dungeon.GetDungeonRotation(seed);
var dungeonTransform = Matrix3.CreateTransform(_position, dungeonRotation);
var roomPackProtos = new Dictionary<Vector2i, List<DungeonRoomPackPrototype>>();
var fallbackTile = new Tile(_tileDefManager[prefab.Tile].TileId);

foreach (var pack in _prototype.EnumeratePrototypes<DungeonRoomPackPrototype>())
{
Expand Down Expand Up @@ -325,6 +324,7 @@ private void SetDungeonEntrance(Dungeon dungeon, DungeonRoom room, Random random
}

room.Entrances.Add(entrancePos);
dungeon.Entrances.Add(entrancePos);
break;
}
}
Expand Down
Loading

0 comments on commit 3b635f1

Please sign in to comment.