Skip to content

Commit

Permalink
MappingShmapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonsant committed Jan 6, 2025
1 parent f4eb95f commit b6f7039
Show file tree
Hide file tree
Showing 35 changed files with 774 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Content.Server/Warps/WarpPointComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ namespace Content.Server.Warps
[RegisterComponent]
public sealed partial class WarpPointComponent : Component
{
// Corvax-Next-Warper-Start: Unique (across all loaded maps) identifier for teleporting to warp points.
[ViewVariables(VVAccess.ReadWrite)] [DataField("id")] public string? ID { get; set; }
[ViewVariables(VVAccess.ReadWrite), DataField]
public string? Location;
// Corvax-Next-Warper-End

/// <summary>
/// If true, ghosts warping to this entity will begin following it.
Expand Down
15 changes: 15 additions & 0 deletions Content.Server/Warps/WarpPointSystem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
using System.Linq;
using Content.Shared.Examine;
using Content.Shared.Ghost;

namespace Content.Server.Warps;

public sealed class WarpPointSystem : EntitySystem
{
private Dictionary<string, EntityUid> warpPoints = new Dictionary<string, EntityUid>(); // Corvax-Next-Warper

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WarpPointComponent, ExaminedEvent>(OnWarpPointExamine);
}

// Corvax-Next-Warper-Start
public EntityUid? FindWarpPoint(string id)
{
var entMan = IoCManager.Resolve<IEntityManager>();
var found = entMan.EntityQuery<WarpPointComponent>(true).Where(p => p.ID == id).FirstOrDefault();
if (found is not null)
return found.Owner;
else
return null;
}
// Corvax-Next-Warper-End

private void OnWarpPointExamine(EntityUid uid, WarpPointComponent component, ExaminedEvent args)
{
if (!HasComp<GhostComponent>(args.Examiner))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server._CorvaxNext.AdditionalMap;

[RegisterComponent]
public sealed partial class AdditionalMapFixComponent : Component;
34 changes: 34 additions & 0 deletions Content.Server/_CorvaxNext/AdditionalMap/AdditionalMapFixSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Threading;
using Content.Server.Atmos.Components;
using Content.Server.GameTicking;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Events;
using Robust.Server.Console;
using Timer = Robust.Shared.Timing.Timer;

namespace Content.Server._CorvaxNext.AdditionalMapFix;
public sealed class AdditionalMapFix : EntitySystem
{
[Dependency] private readonly IServerConsoleHost _host = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StationPostInitEvent>(OnStartup, after: new[] { typeof(ShuttleSystem) });
}

private void OnStartup(ref StationPostInitEvent args)
{
Timer.Spawn(TimeSpan.FromSeconds(5), () =>
{
var query = AllEntityQuery<GridAtmosphereComponent, TransformComponent>();

while (query.MoveNext(out var dummyatmos, out var comp))
{
var gridUid = comp.GridUid;
_host.AppendCommand($"fixgridatmos {gridUid}");
Logger.Error($"executed command on {gridUid}");
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* All right reserved to CrystallEdge.
*
* BUT this file is sublicensed under MIT License
*
*/

using Robust.Shared.Utility;

namespace Content.Server._CorvaxNext.AdditionalMap;

/// <summary>
/// Loads additional maps from the list at the start of the round.
/// </summary>
[RegisterComponent, Access(typeof(StationAdditionalMapSystem))]
public sealed partial class StationAdditionalMapComponent : 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,53 @@
/*
* All right reserved to CrystallEdge.
*
* BUT this file is sublicensed under MIT License
*
*/

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._CorvaxNext.AdditionalMap;

public sealed partial class StationAdditionalMapSystem : 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<StationAdditionalMapComponent, StationPostInitEvent>(OnStationPostInit);
}

private void OnStationPostInit(Entity<StationAdditionalMapComponent> 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;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* All right reserved to CrystallEdge.
*
* BUT this file is sublicensed under MIT License
*
*/

using Content.Server._CorvaxNext.BiomeSpawner.EntitySystems;
using Content.Shared.Parallax.Biomes;
using Robust.Shared.Prototypes;

namespace Content.Server._CorvaxNext.BiomeSpawner.Components;

/// <summary>
/// fills the tile in which it is located with the contents of the biome. Includes: tile, decals and entities
/// </summary>
[RegisterComponent, Access(typeof(BiomeSpawnerSystem))]
public sealed partial class BiomeSpawnerComponent : Component
{
[DataField]
public ProtoId<BiomeTemplatePrototype> Biome = "Grasslands";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* All right reserved to CrystallEdge.
*
* BUT this file is sublicensed under MIT License
*
*/

using System.Linq;
using Content.Server._CorvaxNext.BiomeSpawner.Components;
using System.Numerics;
using Content.Server.Decals;
using Content.Server.GameTicking;
using Content.Server.Parallax;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server._CorvaxNext.BiomeSpawner.EntitySystems;

public sealed class BiomeSpawnerSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly BiomeSystem _biome = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly DecalSystem _decals = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IRobustRandom _random = default!;

private int _seed = 27;

public override void Initialize()
{
SubscribeLocalEvent<RoundStartAttemptEvent>(OnRoundStartAttempt);
SubscribeLocalEvent<BiomeSpawnerComponent, MapInitEvent>(OnMapInit);
}

private void OnRoundStartAttempt(RoundStartAttemptEvent ev)
{
_seed = _random.Next(100000);
}

private void OnMapInit(Entity<BiomeSpawnerComponent> ent, ref MapInitEvent args)
{
SpawnBiome(ent);
QueueDel(ent);
}

private void SpawnBiome(Entity<BiomeSpawnerComponent> ent)
{
var biome = _proto.Index(ent.Comp.Biome);
var spawnerTransform = Transform(ent);
if (spawnerTransform.GridUid == null)
return;
var gridUid = spawnerTransform.GridUid.Value;
if (!TryComp<MapGridComponent>(gridUid, out var map))
return;

var vec = _transform.GetGridOrMapTilePosition(ent);
if (!_biome.TryGetTile(vec, biome.Layers, _seed, map, out var tile))
return;

// Set new tile
_maps.SetTile(gridUid, map, vec, tile.Value);
var tileCenterVec = vec + map.TileSizeHalfVector;

// Remove old decals
var oldDecals = _decals.GetDecalsInRange(gridUid, tileCenterVec);
foreach (var (id, _) in oldDecals)
{
_decals.RemoveDecal(gridUid, id);
}

//Add decals
if (_biome.TryGetDecals(vec, biome.Layers, _seed, map, out var decals))
{
foreach (var decal in decals)
{
_decals.TryAddDecal(decal.ID, new EntityCoordinates(gridUid, decal.Position), out _);
}
}

// Remove entities
var oldEntities = _lookup.GetEntitiesInRange(spawnerTransform.Coordinates, 0.48f);
// TODO: Replace this with GetEntitiesInBox2
foreach (var entToRemove in oldEntities.Concat(new[] { ent.Owner })) // Do not remove self
{
QueueDel(entToRemove);
}

if (_biome.TryGetEntity(vec, biome.Layers, tile.Value, _seed, map, out var entityProto))
Spawn(entityProto, new EntityCoordinates(gridUid, tileCenterVec));
}
}
8 changes: 8 additions & 0 deletions Content.Server/_CorvaxNext/Warper/WarperComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Server._CorvaxNext.Warper;

[RegisterComponent]
public sealed partial class WarperComponent : Component
{
/// Warp destination unique identifier.
[ViewVariables(VVAccess.ReadWrite)] [DataField("id")] public string? ID { get; set; }
}
76 changes: 76 additions & 0 deletions Content.Server/_CorvaxNext/Warper/WarperSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Content.Server.Ghost.Components;
using Content.Server.Warps;
using Content.Server.Popups;
using Content.Shared.Ghost;
using Content.Shared.Interaction;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using System.Numerics;

namespace Content.Server._CorvaxNext.Warper;

public class WarperSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly WarpPointSystem _warpPointSystem = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WarperComponent, InteractHandEvent>(OnInteractHand);
}

private void OnInteractHand(EntityUid uid, WarperComponent component, InteractHandEvent args)
{
if (component.ID is null)
{
Logger.DebugS("warper", "Warper has no destination");
_popupSystem.PopupEntity(Loc.GetString("warper-goes-nowhere", ("warper", args.Target)), args.User, Filter.Entities(args.User), true);
return;
}

var dest = _warpPointSystem.FindWarpPoint(component.ID);
if (dest is null)
{
Logger.DebugS("warper", String.Format("Warp destination '{0}' not found", component.ID));
_popupSystem.PopupEntity(Loc.GetString("warper-goes-nowhere", ("warper", args.Target)), args.User, Filter.Entities(args.User), true);
return;
}

var entMan = IoCManager.Resolve<IEntityManager>();
TransformComponent? destXform;
entMan.TryGetComponent<TransformComponent>(dest.Value, out destXform);
if (destXform is null)
{
Logger.DebugS("warper", String.Format("Warp destination '{0}' has no transform", component.ID));
_popupSystem.PopupEntity(Loc.GetString("warper-goes-nowhere", ("warper", args.Target)), args.User, Filter.Entities(args.User), true);
return;
}

// Check that the destination map is initialized and return unless in aghost mode.
var mapMgr = IoCManager.Resolve<IMapManager>();
var destMap = destXform.MapID;
if (!mapMgr.IsMapInitialized(destMap) || mapMgr.IsMapPaused(destMap))
{
if (!entMan.HasComponent<GhostComponent>(args.User))
{
// Normal ghosts cannot interact, so if we're here this is already an admin ghost.
Logger.DebugS("warper", String.Format("Player tried to warp to '{0}', which is not on a running map", component.ID));
_popupSystem.PopupEntity(Loc.GetString("warper-goes-nowhere", ("warper", args.Target)), args.User, Filter.Entities(args.User), true);
return;
}
}

var xform = entMan.GetComponent<TransformComponent>(args.User);
xform.Coordinates = destXform.Coordinates;
xform.AttachToGridOrMap();
if (entMan.TryGetComponent(uid, out PhysicsComponent? phys))
{
_physics.SetLinearVelocity(uid, Vector2.Zero);
}
}
}
2 changes: 1 addition & 1 deletion Content.Shared/Parallax/Biomes/SharedBiomeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ 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)) // Corvax-Next-BiomeSpawner: bandage - replaced from TryGetBiomeTile (not working for biomespawner)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warper-goes-nowhere = {CAPITALIZE($warper)} никуда не ведёт.
Loading

0 comments on commit b6f7039

Please sign in to comment.