RoomSpawner mask (#33110)

* RoolFill can now spaw rooms with any size

* tile ignoring

* upgrade interior

* simplify

* Update DungeonSystem.Rooms.cs

* center rooms

* Update RoomFillComponent.cs

* Update RoomFillComponent.cs

* Update DungeonSystem.Rooms.cs

* Remove roomfillcoponent from integration test

* Update EntityTest.cs

* remove nullable size, replaced with minsize and maxsize

* clear existing logic refactor

* delete this one
This commit is contained in:
Ed
2025-02-12 15:47:48 +03:00
committed by GitHub
parent 0d33e6182c
commit 47cb8a0b08
8 changed files with 1318 additions and 930 deletions

View File

@@ -39,6 +39,7 @@ namespace Content.IntegrationTests.Tests
.Where(p => !p.Abstract)
.Where(p => !pair.IsTestPrototype(p))
.Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise.
.Where(p => !p.Components.ContainsKey("RoomFill")) // This comp can delete all entities, and spawn others
.Select(p => p.ID)
.ToList();
@@ -101,6 +102,7 @@ namespace Content.IntegrationTests.Tests
.Where(p => !p.Abstract)
.Where(p => !pair.IsTestPrototype(p))
.Where(p => !p.Components.ContainsKey("MapGrid")) // This will smash stuff otherwise.
.Where(p => !p.Components.ContainsKey("RoomFill")) // This comp can delete all entities, and spawn others
.Select(p => p.ID)
.ToList();
foreach (var protoId in protoIds)
@@ -341,6 +343,7 @@ namespace Content.IntegrationTests.Tests
"DebugExceptionInitialize",
"DebugExceptionStartup",
"GridFill",
"RoomFill",
"Map", // We aren't testing a map entity in this test
"MapGrid",
"Broadphase",

View File

@@ -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);
}
}
}
}

View File

@@ -1,6 +1,4 @@
using Content.Shared.Procedural;
using Content.Shared.Whitelist;
using Robust.Shared.Prototypes;
namespace Content.Server.Procedural;
@@ -18,10 +16,16 @@ 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.
@@ -33,5 +37,5 @@ public sealed partial class RoomFillComponent : Component
/// Should any existing entities / decals be bulldozed first.
/// </summary>
[DataField]
public bool ClearExisting;
public bool ClearExisting = true;
}

View File

@@ -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,

View File

@@ -1,6 +1,6 @@
using Content.Shared.Maps;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.Utility;
namespace Content.Shared.Procedural;
@@ -10,18 +10,28 @@ public sealed partial class DungeonRoomPrototype : IPrototype
{
[IdDataField] public string ID { get; } = string.Empty;
[ViewVariables(VVAccess.ReadWrite), DataField("tags", customTypeSerializer:typeof(PrototypeIdListSerializer<TagPrototype>))]
public List<string> Tags = new();
[ViewVariables(VVAccess.ReadWrite), DataField]
public List<ProtoId<TagPrototype>> Tags = new();
[DataField("size", required: true)] public Vector2i Size;
[DataField(required: true)]
public Vector2i Size;
/// <summary>
/// Path to the file to use for the room.
/// </summary>
[DataField("atlas", required: true)] public ResPath AtlasPath;
[DataField("atlas", required: true)]
public ResPath AtlasPath;
/// <summary>
/// Tile offset into the atlas to use for the room.
/// </summary>
[DataField("offset", required: true)] public Vector2i Offset;
[DataField(required: true)]
public Vector2i Offset;
/// <summary>
/// These tiles will be ignored when copying from the atlas into the actual game,
/// allowing you to make rooms of irregular shapes that blend seamlessly into their surroundings
/// </summary>
[DataField]
public ProtoId<ContentTileDefinition>? IgnoreTile;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,9 @@
- type: entity
id: BaseRoomMarker
name: Room marker
name: room spawner
parent: MarkerBase
suffix: Weh
components:
- type: RoomFill
size: 5,5
- type: Sprite
layers:
- state: red

View File

@@ -3,6 +3,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 0,0
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -11,6 +12,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 6,0
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -19,6 +21,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 12,0
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -27,6 +30,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 18,0
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -35,6 +39,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 0,6
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -43,6 +48,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 6,6
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -51,6 +57,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 12,6
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -59,6 +66,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 18,6
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -67,6 +75,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 0,12
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -75,6 +84,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 6,12
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -83,6 +93,7 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 12,12
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
@@ -91,6 +102,25 @@
size: 5,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 18,12
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
- type: dungeonRoom
id: VGRoidInterior11x5a
size: 11,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 0,18
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior
- type: dungeonRoom
id: VGRoidInterior11x5b
size: 11,5
atlas: /Maps/Dungeon/vgroidinterior.yml
offset: 12,18
ignoreTile: FloorShuttleOrange
tags:
- VGRoidInterior