Merge branch 'master' of https://github.com/space-wizards/space-station-14 into map-load-refactor
This commit is contained in:
@@ -17,9 +17,20 @@ public sealed partial class DungeonSystem
|
||||
private readonly List<DungeonRoomPrototype> _availableRooms = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random dungeon room matching the specified area and whitelist.
|
||||
/// Gets a random dungeon room matching the specified area, whitelist and size.
|
||||
/// </summary>
|
||||
public DungeonRoomPrototype? GetRoomPrototype(Vector2i size, Random random, EntityWhitelist? whitelist = null)
|
||||
{
|
||||
return GetRoomPrototype(random, whitelist, minSize: size, maxSize: size);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random dungeon room matching the specified area and whitelist and size range
|
||||
/// </summary>
|
||||
public DungeonRoomPrototype? GetRoomPrototype(Random random,
|
||||
EntityWhitelist? whitelist = null,
|
||||
Vector2i? minSize = null,
|
||||
Vector2i? maxSize = null)
|
||||
{
|
||||
// Can never be true.
|
||||
if (whitelist is { Tags: null })
|
||||
@@ -31,7 +42,10 @@ public sealed partial class DungeonSystem
|
||||
|
||||
foreach (var proto in _prototype.EnumeratePrototypes<DungeonRoomPrototype>())
|
||||
{
|
||||
if (proto.Size != size)
|
||||
if (minSize is not null && (proto.Size.X < minSize.Value.X || proto.Size.Y < minSize.Value.Y))
|
||||
continue;
|
||||
|
||||
if (maxSize is not null && (proto.Size.X > maxSize.Value.X || proto.Size.Y > maxSize.Value.Y))
|
||||
continue;
|
||||
|
||||
if (whitelist == null)
|
||||
@@ -115,29 +129,6 @@ public sealed partial class DungeonSystem
|
||||
|
||||
var finalRoomRotation = roomTransform.Rotation();
|
||||
|
||||
// go BRRNNTTT on existing stuff
|
||||
if (clearExisting)
|
||||
{
|
||||
var gridBounds = new Box2(Vector2.Transform(-room.Size/2, roomTransform), Vector2.Transform(room.Size/2, roomTransform));
|
||||
_entitySet.Clear();
|
||||
// Polygon skin moment
|
||||
gridBounds = gridBounds.Enlarged(-0.05f);
|
||||
_lookup.GetLocalEntitiesIntersecting(gridUid, gridBounds, _entitySet, LookupFlags.Uncontained);
|
||||
|
||||
foreach (var templateEnt in _entitySet)
|
||||
{
|
||||
Del(templateEnt);
|
||||
}
|
||||
|
||||
if (TryComp(gridUid, out DecalGridComponent? decalGrid))
|
||||
{
|
||||
foreach (var decal in _decals.GetDecalsIntersecting(gridUid, gridBounds, decalGrid))
|
||||
{
|
||||
_decals.RemoveDecal(gridUid, decal.Index, decalGrid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var roomCenter = (room.Offset + room.Size / 2f) * grid.TileSize;
|
||||
var tileOffset = -roomCenter + grid.TileSizeHalfVector;
|
||||
_tiles.Clear();
|
||||
@@ -156,7 +147,22 @@ public sealed partial class DungeonSystem
|
||||
if (!clearExisting && reservedTiles?.Contains(rounded) == true)
|
||||
continue;
|
||||
|
||||
if (room.IgnoreTile is not null)
|
||||
{
|
||||
if (_maps.TryGetTileDef(templateGrid, indices, out var tileDef) && room.IgnoreTile == tileDef.ID)
|
||||
continue;
|
||||
}
|
||||
|
||||
_tiles.Add((rounded, tileRef.Tile));
|
||||
|
||||
if (clearExisting)
|
||||
{
|
||||
var anchored = _maps.GetAnchoredEntities((gridUid, grid), rounded);
|
||||
foreach (var ent in anchored)
|
||||
{
|
||||
QueueDel(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Procedural;
|
||||
|
||||
@@ -18,20 +16,26 @@ public sealed partial class RoomFillComponent : Component
|
||||
public bool Rotation = true;
|
||||
|
||||
/// <summary>
|
||||
/// Size of the room to fill.
|
||||
/// Min size of the possible selected room.
|
||||
/// </summary>
|
||||
[DataField(required: true)]
|
||||
public Vector2i Size;
|
||||
[DataField]
|
||||
public Vector2i MinSize = new (3, 3);
|
||||
|
||||
/// <summary>
|
||||
/// Max size of the possible selected room.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public Vector2i MaxSize = new (10, 10);
|
||||
|
||||
/// <summary>
|
||||
/// Rooms allowed for the marker.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityWhitelist? RoomWhitelist;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Should any existing entities / decals be bulldozed first.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool ClearExisting;
|
||||
public bool ClearExisting = true;
|
||||
}
|
||||
|
||||
@@ -15,16 +15,12 @@ public sealed class RoomFillSystem : EntitySystem
|
||||
|
||||
private void OnRoomFillMapInit(EntityUid uid, RoomFillComponent component, MapInitEvent args)
|
||||
{
|
||||
// Just test things.
|
||||
if (component.Size == Vector2i.Zero)
|
||||
return;
|
||||
|
||||
var xform = Transform(uid);
|
||||
|
||||
if (xform.GridUid != null)
|
||||
{
|
||||
var random = new Random();
|
||||
var room = _dungeon.GetRoomPrototype(component.Size, random, component.RoomWhitelist);
|
||||
var room = _dungeon.GetRoomPrototype(random, component.RoomWhitelist, component.MinSize, component.MaxSize);
|
||||
|
||||
if (room != null)
|
||||
{
|
||||
@@ -32,7 +28,7 @@ public sealed class RoomFillSystem : EntitySystem
|
||||
_dungeon.SpawnRoom(
|
||||
xform.GridUid.Value,
|
||||
mapGrid,
|
||||
_maps.LocalToTile(xform.GridUid.Value, mapGrid, xform.Coordinates),
|
||||
_maps.LocalToTile(xform.GridUid.Value, mapGrid, xform.Coordinates) - new Vector2i(room.Size.X/2,room.Size.Y/2),
|
||||
room,
|
||||
random,
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user