Skip to content

Commit

Permalink
Procedural + z-levels refactor (space-wizards#216)
Browse files Browse the repository at this point in the history
* create biome tile spawner

* spawner now spawn decals and entities

* fancy spawners

* remove old decals

* randomize seed

* fix bugs

* update alchemy test map to new system

* update z-level system

* autolink tweak

* add documentation

* Update GravityComponent.cs

* Update GravityComponent.cs
  • Loading branch information
TheShuEd authored and Beridot committed Aug 15, 2024
1 parent 092c458 commit bfe632d
Show file tree
Hide file tree
Showing 11 changed files with 20,059 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Content.Server/_CP14/PortalAutoLink/CP14AutoLinkComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.Map;

namespace Content.Server._CP14.PortalAutoLink;

/// <summary>
/// allows you to automatically link entities to each other, through key matching searches
/// </summary>
[RegisterComponent, Access(typeof(CP14AutoLinkSystem))]
public sealed partial class CP14AutoLinkComponent : Component
{
/// <summary>
/// a key that is used to search for another autolinked entity installed in the worlds
/// </summary>
[DataField]
public string? AutoLinkKey = "Hello";
}
44 changes: 44 additions & 0 deletions Content.Server/_CP14/PortalAutoLink/CP14AutoLinkSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Shared.Interaction;
using Content.Shared.Teleportation.Systems;

namespace Content.Server._CP14.PortalAutoLink;

public sealed partial class CP14AutoLinkSystem : EntitySystem
{
[Dependency] private readonly LinkedEntitySystem _link = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<CP14AutoLinkComponent, MapInitEvent>(OnMapInit);
}

private void OnMapInit(Entity<CP14AutoLinkComponent> autolink, ref MapInitEvent args)
{
TryAutoLink(autolink, out var otherLink);
}
public bool TryAutoLink(Entity<CP14AutoLinkComponent> autolink, out EntityUid? linkedEnt)
{
linkedEnt = null;

var query = EntityQueryEnumerator<CP14AutoLinkComponent>();
while (query.MoveNext(out var uid, out var otherAutolink))
{
if (autolink.Comp == otherAutolink)
continue;

if (autolink.Comp.AutoLinkKey == otherAutolink.AutoLinkKey)
{
if (_link.TryLink(autolink, uid, false))
{
RemComp<CP14AutoLinkComponent>(uid);
RemComp<CP14AutoLinkComponent>(autolink);
return true;
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.Utility;

namespace Content.Server._CP14.StationDungeonMap;

/// <summary>
/// Initializes a procedurally generated world with points of interest
/// </summary>
[RegisterComponent, Access(typeof(CP14StationAdditionalMapSystem))]
public sealed partial class CP14StationAdditionalMapComponent : Component
{
/// <summary>
/// A map paths to load on a new map.
/// </summary>
[DataField]
public List<ResPath> MapPaths = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Server.Parallax;
using Content.Server.Station.Components;
using Content.Server.Station.Events;
using Content.Server.Station.Systems;
using Content.Shared.Teleportation.Systems;
using Robust.Server.GameObjects;
using Robust.Server.Maps;
using Robust.Shared.Prototypes;

namespace Content.Server._CP14.StationDungeonMap;

public sealed partial class CP14StationAdditionalMapSystem : EntitySystem
{
[Dependency] private readonly BiomeSystem _biome = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MapSystem _map = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14StationAdditionalMapComponent, StationPostInitEvent>(OnStationPostInit);
}

private void OnStationPostInit(Entity<CP14StationAdditionalMapComponent> addMap, ref StationPostInitEvent args)
{
if (!TryComp(addMap, out StationDataComponent? dataComp))
return;

foreach (var path in addMap.Comp.MapPaths)
{
var mapUid = _map.CreateMap(out var mapId);
Log.Info($"Created map {mapId} for StationAdditionalMap system");
var options = new MapLoadOptions { LoadMap = true };
if (!_mapLoader.TryLoad(mapId, path.ToString(), out var roots, options))
{
Log.Error($"Failed to load map from {path}!");
Del(mapUid);
return;
}
}
}
}
5 changes: 3 additions & 2 deletions Content.Shared/Parallax/Biomes/SharedBiomeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public bool TryGetTile(Vector2i indices, List<IBiomeLayer> layers, int seed, Map
// Check if the tile is from meta layer, otherwise fall back to default layers.
if (layer is BiomeMetaLayer meta)
{
if (TryGetBiomeTile(indices, ProtoManager.Index<BiomeTemplatePrototype>(meta.Template).Layers, seed, grid, out tile))
if (TryGetTile(indices, ProtoManager.Index<BiomeTemplatePrototype>(meta.Template).Layers, seed, grid, out tile))
//CP14 bandage - replaced from TryGetBiomeTile (not working for biomespawner)
{
return true;
}
Expand Down Expand Up @@ -183,7 +184,7 @@ public bool TryGetEntity(Vector2i indices, BiomeComponent component, MapGridComp
}


private bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, Tile tileRef, int seed, MapGridComponent grid,
public bool TryGetEntity(Vector2i indices, List<IBiomeLayer> layers, Tile tileRef, int seed, MapGridComponent grid,
[NotNullWhen(true)] out string? entity)
{
var tileId = TileDefManager[tileRef.TypeId].ID;
Expand Down
Loading

0 comments on commit bfe632d

Please sign in to comment.