Files
Delta-v/Content.Server/_DV/Planet/PlanetSystem.cs
T
KOTOBandpre-commit-ci[bot] d8cfd70cc8 Akashic Fold Part 0 (#4350)
* lowkey might have messed up lighting

* make it awesome

uncopy code steamhappy

* yuh!

* goidagen

todo: steal EVERYTHING from goob

* goidamerge my beloved

* 1984 goidamerge (for now)

i dont think it worked properly anyways (?)

* chromite weather ops

* sobbing i hate thsi...

* Revert "sobbing i hate thsi..."

This reverts commit 5dff16743f.

* temp base fix

* the great culling

* untouch upstream

* the recommenting

* the great reindenting

* miniscule tweakops

* lgtm

* okay for real this time

* broken lockers

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* got eaten my my revert guh

* i am blind

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-05 08:07:51 +11:00

78 lines
2.6 KiB
C#

using Content.Server.Atmos.EntitySystems;
using Content.Server.Parallax;
using Content.Shared._DV.Planet;
using Content.Shared.Parallax;
using Content.Shared.Parallax.Biomes;
using Robust.Shared.EntitySerialization.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server._DV.Planet;
public sealed class PlanetSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmos = default!;
[Dependency] private readonly BiomeSystem _biome = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
[Dependency] private readonly MetaDataSystem _meta = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private readonly List<(Vector2i, Tile)> _setTiles = new();
/// <summary>
/// Spawn a planet map from a planet prototype.
/// </summary>
public EntityUid SpawnPlanet(ProtoId<PlanetPrototype> id, bool runMapInit = true)
{
var planet = _proto.Index(id);
var map = _map.CreateMap(out _, runMapInit: runMapInit);
_biome.EnsurePlanet(map, _proto.Index(planet.Biome), mapLight: planet.MapLight);
var parallax = EnsureComp<ParallaxComponent>(map);
// add each marker layer
var biome = Comp<BiomeComponent>(map);
foreach (var layer in planet.BiomeMarkerLayers)
{
_biome.AddMarkerLayer(map, biome, layer);
}
if (planet.AddedComponents is {} added)
EntityManager.AddComponents(map, added);
_atmos.SetMapAtmosphere(map, false, planet.Atmosphere);
_meta.SetEntityName(map, Loc.GetString(planet.MapName));
return map;
}
/// <summary>
/// Spawns an initialized planet map from a planet prototype and loads a grid onto it.
/// Returns the map entity if loading succeeded.
/// </summary>
public EntityUid? LoadPlanet(ProtoId<PlanetPrototype> id, ResPath path)
{
var map = SpawnPlanet(id, runMapInit: false);
var mapId = Comp<MapComponent>(map).MapId;
if (!_mapLoader.TryLoadGrid(mapId, path, out var grid))
{
Log.Error($"Failed to load planet grid {path} for planet {id}!");
Del(map);
return null;
}
// don't want rocks spawning inside the base
_setTiles.Clear();
var aabb = Comp<MapGridComponent>(grid.Value).LocalAABB;
_biome.ReserveTiles(map, aabb.Enlarged(0.2f), _setTiles);
_map.InitializeMap(map);
return map;
}
}