Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror: haunted dungeon template #321

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading