Fix exped dungeons (#23654)
mapBounds was null after one of my last changes. I changed the transform so it's just passed in directly as I don't think there was an easy way around it. I checked magnet + roomfills still work.
This commit is contained in:
@@ -66,7 +66,7 @@ public sealed partial class DungeonJob
|
|||||||
visited.Add(seedTile);
|
visited.Add(seedTile);
|
||||||
frontier.Enqueue(seedTile);
|
frontier.Enqueue(seedTile);
|
||||||
area = area.UnionTile(seedTile);
|
area = area.UnionTile(seedTile);
|
||||||
Box2i roomArea = new Box2i(seedTile, seedTile + Vector2i.One);
|
var roomArea = new Box2i(seedTile, seedTile + Vector2i.One);
|
||||||
|
|
||||||
// Time to floodfill again
|
// Time to floodfill again
|
||||||
while (frontier.TryDequeue(out var node) && tileCount < tileCap)
|
while (frontier.TryDequeue(out var node) && tileCount < tileCap)
|
||||||
|
|||||||
@@ -159,7 +159,6 @@ public sealed partial class DungeonJob
|
|||||||
{
|
{
|
||||||
var pack = chosenPacks[i]!;
|
var pack = chosenPacks[i]!;
|
||||||
var packTransform = packTransforms[i];
|
var packTransform = packTransforms[i];
|
||||||
var packRotation = packRotations[i];
|
|
||||||
|
|
||||||
// Actual spawn cud here.
|
// Actual spawn cud here.
|
||||||
// Pickout the room pack template to get the room dimensions we need.
|
// Pickout the room pack template to get the room dimensions we need.
|
||||||
@@ -199,14 +198,25 @@ public sealed partial class DungeonJob
|
|||||||
_sawmill.Debug($"Using rotated variant for room");
|
_sawmill.Debug($"Using rotated variant for room");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var room = roomProto[random.Next(roomProto.Count)];
|
||||||
|
|
||||||
|
if (roomDimensions.X == roomDimensions.Y)
|
||||||
|
{
|
||||||
|
// Give it a random rotation
|
||||||
|
roomRotation = random.Next(4) * Math.PI / 2;
|
||||||
|
}
|
||||||
|
else if (random.Next(2) == 1)
|
||||||
|
{
|
||||||
|
roomRotation += Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
var roomTransform = Matrix3.CreateTransform(roomSize.Center - packCenter, roomRotation);
|
var roomTransform = Matrix3.CreateTransform(roomSize.Center - packCenter, roomRotation);
|
||||||
|
|
||||||
Matrix3.Multiply(roomTransform, packTransform, out matty);
|
Matrix3.Multiply(roomTransform, packTransform, out matty);
|
||||||
Matrix3.Multiply(matty, dungeonTransform, out var dungeonMatty);
|
Matrix3.Multiply(matty, dungeonTransform, out var dungeonMatty);
|
||||||
|
|
||||||
// The expensive bit yippy.
|
// The expensive bit yippy.
|
||||||
var room = roomProto[random.Next(roomProto.Count)];
|
_dungeon.SpawnRoom(gridUid, grid, dungeonMatty, room);
|
||||||
_dungeon.SpawnRoom(gridUid, grid, matty, room, random, rotation: true);
|
|
||||||
|
|
||||||
var roomCenter = (room.Offset + room.Size / 2f) * grid.TileSize;
|
var roomCenter = (room.Offset + room.Size / 2f) * grid.TileSize;
|
||||||
var roomTiles = new HashSet<Vector2i>(room.Size.X * room.Size.Y);
|
var roomTiles = new HashSet<Vector2i>(room.Size.X * room.Size.Y);
|
||||||
@@ -230,9 +240,18 @@ public sealed partial class DungeonJob
|
|||||||
|
|
||||||
var center = Vector2.Zero;
|
var center = Vector2.Zero;
|
||||||
|
|
||||||
foreach (var tile in roomTiles)
|
for (var x = 0; x < room.Size.X; x++)
|
||||||
{
|
{
|
||||||
center += tile + grid.TileSizeHalfVector;
|
for (var y = 0; y < room.Size.Y; y++)
|
||||||
|
{
|
||||||
|
var roomTile = new Vector2i(x + room.Offset.X, y + room.Offset.Y);
|
||||||
|
var tilePos = dungeonMatty.Transform(roomTile + tileOffset);
|
||||||
|
var tileIndex = tilePos.Floored();
|
||||||
|
roomTiles.Add(tileIndex);
|
||||||
|
|
||||||
|
mapBounds = mapBounds?.Union(tileIndex) ?? new Box2i(tileIndex, tileIndex);
|
||||||
|
center += tilePos + grid.TileSizeHalfVector;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
center /= roomTiles.Count;
|
center /= roomTiles.Count;
|
||||||
|
|||||||
@@ -67,46 +67,55 @@ public sealed partial class DungeonSystem
|
|||||||
bool rotation = false)
|
bool rotation = false)
|
||||||
{
|
{
|
||||||
var originTransform = Matrix3.CreateTranslation(origin);
|
var originTransform = Matrix3.CreateTranslation(origin);
|
||||||
SpawnRoom(gridUid, grid, originTransform, room, random, clearExisting, rotation);
|
var roomRotation = Angle.Zero;
|
||||||
|
|
||||||
|
if (rotation)
|
||||||
|
{
|
||||||
|
roomRotation = GetRoomRotation(room, random);
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomTransform = Matrix3.CreateTransform((Vector2) room.Size / 2f, roomRotation);
|
||||||
|
Matrix3.Multiply(roomTransform, originTransform, out var finalTransform);
|
||||||
|
|
||||||
|
SpawnRoom(gridUid, grid, finalTransform, room, clearExisting);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Angle GetRoomRotation(DungeonRoomPrototype room, Random random)
|
||||||
|
{
|
||||||
|
var roomRotation = Angle.Zero;
|
||||||
|
|
||||||
|
if (room.Size.X == room.Size.Y)
|
||||||
|
{
|
||||||
|
// Give it a random rotation
|
||||||
|
roomRotation = random.Next(4) * Math.PI / 2;
|
||||||
|
}
|
||||||
|
else if (random.Next(2) == 1)
|
||||||
|
{
|
||||||
|
roomRotation += Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return roomRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpawnRoom(
|
public void SpawnRoom(
|
||||||
EntityUid gridUid,
|
EntityUid gridUid,
|
||||||
MapGridComponent grid,
|
MapGridComponent grid,
|
||||||
Matrix3 transform,
|
Matrix3 roomTransform,
|
||||||
DungeonRoomPrototype room,
|
DungeonRoomPrototype room,
|
||||||
Random random,
|
bool clearExisting = false)
|
||||||
bool clearExisting = false,
|
|
||||||
bool rotation = false)
|
|
||||||
{
|
{
|
||||||
// Ensure the underlying template exists.
|
// Ensure the underlying template exists.
|
||||||
var roomMap = GetOrCreateTemplate(room);
|
var roomMap = GetOrCreateTemplate(room);
|
||||||
var templateMapUid = _mapManager.GetMapEntityId(roomMap);
|
var templateMapUid = _mapManager.GetMapEntityId(roomMap);
|
||||||
var templateGrid = Comp<MapGridComponent>(templateMapUid);
|
var templateGrid = Comp<MapGridComponent>(templateMapUid);
|
||||||
var roomRotation = Angle.Zero;
|
|
||||||
var roomDimensions = room.Size;
|
var roomDimensions = room.Size;
|
||||||
|
|
||||||
if (rotation)
|
var finalRoomRotation = roomTransform.Rotation();
|
||||||
{
|
|
||||||
if (roomDimensions.X == roomDimensions.Y)
|
|
||||||
{
|
|
||||||
// Give it a random rotation
|
|
||||||
roomRotation = random.Next(4) * Math.PI / 2;
|
|
||||||
}
|
|
||||||
else if (random.Next(2) == 1)
|
|
||||||
{
|
|
||||||
roomRotation += Math.PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var roomTransform = Matrix3.CreateTransform((Vector2) room.Size / 2f, roomRotation);
|
|
||||||
Matrix3.Multiply(roomTransform, transform, out var finalTransform);
|
|
||||||
var finalRoomRotation = finalTransform.Rotation();
|
|
||||||
|
|
||||||
// go BRRNNTTT on existing stuff
|
// go BRRNNTTT on existing stuff
|
||||||
if (clearExisting)
|
if (clearExisting)
|
||||||
{
|
{
|
||||||
var gridBounds = new Box2(transform.Transform(Vector2.Zero), transform.Transform(room.Size));
|
var gridBounds = new Box2(roomTransform.Transform(Vector2.Zero), roomTransform.Transform(room.Size));
|
||||||
_entitySet.Clear();
|
_entitySet.Clear();
|
||||||
// Polygon skin moment
|
// Polygon skin moment
|
||||||
gridBounds = gridBounds.Enlarged(-0.05f);
|
gridBounds = gridBounds.Enlarged(-0.05f);
|
||||||
@@ -138,7 +147,7 @@ public sealed partial class DungeonSystem
|
|||||||
var indices = new Vector2i(x + room.Offset.X, y + room.Offset.Y);
|
var indices = new Vector2i(x + room.Offset.X, y + room.Offset.Y);
|
||||||
var tileRef = _maps.GetTileRef(templateMapUid, templateGrid, indices);
|
var tileRef = _maps.GetTileRef(templateMapUid, templateGrid, indices);
|
||||||
|
|
||||||
var tilePos = finalTransform.Transform(indices + tileOffset);
|
var tilePos = roomTransform.Transform(indices + tileOffset);
|
||||||
var rounded = tilePos.Floored();
|
var rounded = tilePos.Floored();
|
||||||
_tiles.Add((rounded, tileRef.Tile));
|
_tiles.Add((rounded, tileRef.Tile));
|
||||||
}
|
}
|
||||||
@@ -154,7 +163,7 @@ public sealed partial class DungeonSystem
|
|||||||
foreach (var templateEnt in _lookup.GetEntitiesIntersecting(templateMapUid, bounds, LookupFlags.Uncontained))
|
foreach (var templateEnt in _lookup.GetEntitiesIntersecting(templateMapUid, bounds, LookupFlags.Uncontained))
|
||||||
{
|
{
|
||||||
var templateXform = _xformQuery.GetComponent(templateEnt);
|
var templateXform = _xformQuery.GetComponent(templateEnt);
|
||||||
var childPos = finalTransform.Transform(templateXform.LocalPosition - roomCenter);
|
var childPos = roomTransform.Transform(templateXform.LocalPosition - roomCenter);
|
||||||
var childRot = templateXform.LocalRotation + finalRoomRotation;
|
var childRot = templateXform.LocalRotation + finalRoomRotation;
|
||||||
var protoId = _metaQuery.GetComponent(templateEnt).EntityPrototype?.ID;
|
var protoId = _metaQuery.GetComponent(templateEnt).EntityPrototype?.ID;
|
||||||
|
|
||||||
@@ -182,7 +191,7 @@ public sealed partial class DungeonSystem
|
|||||||
// Offset by 0.5 because decals are offset from bot-left corner
|
// Offset by 0.5 because decals are offset from bot-left corner
|
||||||
// So we convert it to center of tile then convert it back again after transform.
|
// So we convert it to center of tile then convert it back again after transform.
|
||||||
// Do these shenanigans because 32x32 decals assume as they are centered on bottom-left of tiles.
|
// Do these shenanigans because 32x32 decals assume as they are centered on bottom-left of tiles.
|
||||||
var position = finalTransform.Transform(decal.Coordinates + Vector2Helpers.Half - roomCenter);
|
var position = roomTransform.Transform(decal.Coordinates + Vector2Helpers.Half - roomCenter);
|
||||||
position -= Vector2Helpers.Half;
|
position -= Vector2Helpers.Half;
|
||||||
|
|
||||||
// Umm uhh I love decals so uhhhh idk what to do about this
|
// Umm uhh I love decals so uhhhh idk what to do about this
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
|
|||||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
|
||||||
private HashSet<EntityUid> _entSet = new();
|
|
||||||
private readonly List<(Vector2i, Tile)> _tiles = new();
|
private readonly List<(Vector2i, Tile)> _tiles = new();
|
||||||
|
|
||||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||||
|
|||||||
@@ -390,7 +390,11 @@ public sealed partial class SalvageSystem
|
|||||||
// This doesn't stop it from spawning on top of random things in space
|
// This doesn't stop it from spawning on top of random things in space
|
||||||
// Might be better like this, ghosts could stop it before
|
// Might be better like this, ghosts could stop it before
|
||||||
if (_mapManager.FindGridsIntersecting(finalCoords.MapId, box2Rot).Any())
|
if (_mapManager.FindGridsIntersecting(finalCoords.MapId, box2Rot).Any())
|
||||||
|
{
|
||||||
|
// Bump it further and further just in case.
|
||||||
|
minActualDistance += 4f;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
coords = finalCoords;
|
coords = finalCoords;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user