From 1f0c9314fd791ce14d14ccfd8f8419a9c473e151 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:39:39 +1100 Subject: [PATCH] Default warp point names (#21017) --- .../Administration/Commands/WarpCommand.cs | 31 ++++++++++++++----- Content.Server/Ghost/GhostSystem.cs | 3 +- .../Ninja/Systems/SpaceNinjaSystem.cs | 8 ++--- .../Systems/NinjaConditionsSystem.cs | 5 ++- Content.Server/Warps/WarpPointComponent.cs | 7 +++-- .../Entities/Markers/warp_point.yml | 20 ++++++++++++ 6 files changed, 53 insertions(+), 21 deletions(-) diff --git a/Content.Server/Administration/Commands/WarpCommand.cs b/Content.Server/Administration/Commands/WarpCommand.cs index 5c61208b5b..30a6d127aa 100644 --- a/Content.Server/Administration/Commands/WarpCommand.cs +++ b/Content.Server/Administration/Commands/WarpCommand.cs @@ -59,9 +59,7 @@ namespace Content.Server.Administration.Commands var currentMap = _entManager.GetComponent(playerEntity).MapID; var currentGrid = _entManager.GetComponent(playerEntity).GridUid; - var found = _entManager.EntityQuery(true) - .Where(p => p.Location == location) - .Select(p => (_entManager.GetComponent(p.Owner).Coordinates, p.Follow)) + var found = GetWarpPointByName(location) .OrderBy(p => p.Item1, Comparer.Create((a, b) => { // Sort so that warp points on the same grid/map are first. @@ -133,11 +131,28 @@ namespace Content.Server.Administration.Commands private IEnumerable GetWarpPointNames() { - return _entManager.EntityQuery(true) - .Select(p => p.Location) - .Where(p => p != null) - .OrderBy(p => p) - .Distinct()!; + List points = new(_entManager.Count()); + var query = _entManager.AllEntityQueryEnumerator(); + while (query.MoveNext(out _, out var warp, out var meta)) + { + points.Add(warp.Location ?? meta.EntityName); + } + + points.Sort(); + return points; + } + + private List<(EntityCoordinates, bool)> GetWarpPointByName(string name) + { + List<(EntityCoordinates, bool)> points = new(); + var query = _entManager.AllEntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var warp, out var meta, out var xform)) + { + if (name == (warp.Location ?? meta.EntityName)) + points.Add((xform.Coordinates, warp.Follow)); + } + + return points; } public CompletionResult GetCompletion(IConsoleShell shell, string[] args) diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index 7881803901..064e25957a 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -297,8 +297,7 @@ namespace Content.Server.Ghost while (allQuery.MoveNext(out var uid, out var warp)) { - if (warp.Location != null) - yield return new GhostWarp(GetNetEntity(uid), warp.Location, true); + yield return new GhostWarp(GetNetEntity(uid), warp.Location ?? Name(uid), true); } } diff --git a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs index 8f19850c70..6de2d7dee0 100644 --- a/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs +++ b/Content.Server/Ninja/Systems/SpaceNinjaSystem.cs @@ -170,12 +170,10 @@ public sealed class SpaceNinjaSystem : SharedSpaceNinjaSystem // choose spider charge detonation point var warps = new List(); - var query = EntityQueryEnumerator(); - var map = Transform(uid).MapID; - while (query.MoveNext(out var warpUid, out _, out var warp, out var xform)) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var warpUid, out _, out var warp)) { - if (warp.Location != null) - warps.Add(warpUid); + warps.Add(warpUid); } if (warps.Count > 0) diff --git a/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs b/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs index eaf97e97e0..24eeb0542e 100644 --- a/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs +++ b/Content.Server/Objectives/Systems/NinjaConditionsSystem.cs @@ -58,14 +58,13 @@ public sealed class NinjaConditionsSystem : EntitySystem { if (!TryComp(mindId, out var role) || role.SpiderChargeTarget == null || - !TryComp(role.SpiderChargeTarget, out var warp) || - warp.Location == null) + !TryComp(role.SpiderChargeTarget, out var warp)) { // this should never really happen but eh return Loc.GetString("objective-condition-spider-charge-title-no-target"); } - return Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location)); + return Loc.GetString("objective-condition-spider-charge-title", ("location", warp.Location ?? Name(role.SpiderChargeTarget.Value))); } // steal research diff --git a/Content.Server/Warps/WarpPointComponent.cs b/Content.Server/Warps/WarpPointComponent.cs index 19c38493ef..ce169f2e19 100644 --- a/Content.Server/Warps/WarpPointComponent.cs +++ b/Content.Server/Warps/WarpPointComponent.cs @@ -6,12 +6,13 @@ namespace Content.Server.Warps [RegisterComponent] public sealed partial class WarpPointComponent : Component { - [ViewVariables(VVAccess.ReadWrite)] [DataField("location")] public string? Location { get; set; } + [ViewVariables(VVAccess.ReadWrite), DataField] + public string? Location; /// /// If true, ghosts warping to this entity will begin following it. /// - [DataField("follow")] - public bool Follow = false; + [DataField] + public bool Follow; } } diff --git a/Resources/Prototypes/Entities/Markers/warp_point.yml b/Resources/Prototypes/Entities/Markers/warp_point.yml index d7651e1245..8e15994dc5 100644 --- a/Resources/Prototypes/Entities/Markers/warp_point.yml +++ b/Resources/Prototypes/Entities/Markers/warp_point.yml @@ -13,6 +13,8 @@ name: warp point (beacon) components: - type: NavMapBeacon + - type: WarpPoint + location: beacon - type: entity parent: WarpPoint @@ -21,6 +23,8 @@ suffix: ninja bombing target components: - type: BombingTarget + - type: WarpPoint + location: bombing target - type: Sprite layers: - state: pink @@ -36,6 +40,8 @@ - type: NavMapBeacon text: bar color: "#791500" + - type: WarpPoint + location: bar - type: entity id: WarpPointBeaconCargo @@ -45,6 +51,8 @@ - type: NavMapBeacon text: cargo color: "#A46106" + - type: WarpPoint + location: cargo - type: entity id: WarpPointBeaconCommand @@ -54,6 +62,8 @@ - type: NavMapBeacon text: command color: "#334E6D" + - type: WarpPoint + location: command - type: entity id: WarpPointBeaconEngineering @@ -63,6 +73,8 @@ - type: NavMapBeacon text: engineering color: "#EFB341" + - type: WarpPoint + location: engineering - type: entity id: WarpPointBeaconMedical @@ -72,6 +84,8 @@ - type: NavMapBeacon text: medical color: "#52B4E9" + - type: WarpPoint + location: medical - type: entity id: WarpPointBeaconNeutral @@ -81,6 +95,8 @@ - type: NavMapBeacon text: neutral color: "#D4D4D4" + - type: WarpPoint + location: neutral - type: entity id: WarpPointBeaconScience @@ -90,6 +106,8 @@ - type: NavMapBeacon text: science color: "#D381C9" + - type: WarpPoint + location: science - type: entity id: WarpPointBeaconService @@ -99,3 +117,5 @@ - type: NavMapBeacon text: service color: "#9FED58" + - type: WarpPoint + location: service