* World generation (squash) * Test fixes. * command * o * Access cleanup. * Documentation touchups. * Use a prototype serializer for BiomeSelectionComponent * Struct enumerator in SimpleFloorPlanPopulatorSystem * Safety margins around PoissonDiskSampler, cookie acquisition methodologies * Struct enumerating PoissonDiskSampler; internal side * Struct enumerating PoissonDiskSampler: Finish it * Update WorldgenConfigSystem.cs awa --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: 20kdc <asdd2808@gmail.com>
59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using Content.Server.Worldgen.Components;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.Worldgen.Systems;
|
|
|
|
/// <summary>
|
|
/// This provides some additional functions for world generation systems.
|
|
/// Exists primarily for convenience and to avoid code duplication.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public abstract class BaseWorldSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly WorldControllerSystem _worldController = default!;
|
|
|
|
/// <summary>
|
|
/// Gets a chunk's coordinates in chunk space as an integer value.
|
|
/// </summary>
|
|
/// <param name="ent"></param>
|
|
/// <param name="xform"></param>
|
|
/// <returns>Chunk space coordinates</returns>
|
|
[Pure]
|
|
public Vector2i GetChunkCoords(EntityUid ent, TransformComponent? xform = null)
|
|
{
|
|
if (!Resolve(ent, ref xform))
|
|
throw new Exception("Failed to resolve transform, somehow.");
|
|
|
|
return WorldGen.WorldToChunkCoords(xform.WorldPosition).Floored();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a chunk's coordinates in chunk space as a floating point value.
|
|
/// </summary>
|
|
/// <param name="ent"></param>
|
|
/// <param name="xform"></param>
|
|
/// <returns>Chunk space coordinates</returns>
|
|
[Pure]
|
|
public Vector2 GetFloatingChunkCoords(EntityUid ent, TransformComponent? xform = null)
|
|
{
|
|
if (!Resolve(ent, ref xform))
|
|
throw new Exception("Failed to resolve transform, somehow.");
|
|
|
|
return WorldGen.WorldToChunkCoords(xform.WorldPosition);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to get a chunk, creating it if it doesn't exist.
|
|
/// </summary>
|
|
/// <param name="chunk">Chunk coordinates to get the chunk entity for.</param>
|
|
/// <param name="map">Map the chunk is in.</param>
|
|
/// <param name="controller">The controller this chunk belongs to.</param>
|
|
/// <returns>A chunk, if available.</returns>
|
|
[Pure]
|
|
public EntityUid? GetOrCreateChunk(Vector2i chunk, EntityUid map, WorldControllerComponent? controller = null)
|
|
{
|
|
return _worldController.GetOrCreateChunk(chunk, map, controller);
|
|
}
|
|
}
|
|
|