Skip to content

Commit

Permalink
Default warp point names (#21017)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Oct 16, 2023
1 parent 4225440 commit 1f0c931
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
31 changes: 23 additions & 8 deletions Content.Server/Administration/Commands/WarpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
var currentMap = _entManager.GetComponent<TransformComponent>(playerEntity).MapID;
var currentGrid = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;

var found = _entManager.EntityQuery<WarpPointComponent>(true)
.Where(p => p.Location == location)
.Select(p => (_entManager.GetComponent<TransformComponent>(p.Owner).Coordinates, p.Follow))
var found = GetWarpPointByName(location)
.OrderBy(p => p.Item1, Comparer<EntityCoordinates>.Create((a, b) =>
{
// Sort so that warp points on the same grid/map are first.
Expand Down Expand Up @@ -133,11 +131,28 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)

private IEnumerable<string> GetWarpPointNames()
{
return _entManager.EntityQuery<WarpPointComponent>(true)
.Select(p => p.Location)
.Where(p => p != null)
.OrderBy(p => p)
.Distinct()!;
List<string> points = new(_entManager.Count<WarpPointComponent>());
var query = _entManager.AllEntityQueryEnumerator<WarpPointComponent, MetaDataComponent>();
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<WarpPointComponent, MetaDataComponent, TransformComponent>();
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)
Expand Down
3 changes: 1 addition & 2 deletions Content.Server/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ private IEnumerable<GhostWarp> GetLocationWarps()

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);
}
}

Expand Down
8 changes: 3 additions & 5 deletions Content.Server/Ninja/Systems/SpaceNinjaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,10 @@ private void OnNinjaCreated(EntityUid uid, SpaceNinjaComponent comp, ref Generic

// choose spider charge detonation point
var warps = new List<EntityUid>();
var query = EntityQueryEnumerator<BombingTargetComponent, WarpPointComponent, TransformComponent>();
var map = Transform(uid).MapID;
while (query.MoveNext(out var warpUid, out _, out var warp, out var xform))
var query = EntityQueryEnumerator<BombingTargetComponent, WarpPointComponent>();
while (query.MoveNext(out var warpUid, out _, out var warp))
{
if (warp.Location != null)
warps.Add(warpUid);
warps.Add(warpUid);
}

if (warps.Count > 0)
Expand Down
5 changes: 2 additions & 3 deletions Content.Server/Objectives/Systems/NinjaConditionsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ private string SpiderChargeTitle(EntityUid mindId)
{
if (!TryComp<NinjaRoleComponent>(mindId, out var role) ||
role.SpiderChargeTarget == null ||
!TryComp<WarpPointComponent>(role.SpiderChargeTarget, out var warp) ||
warp.Location == null)
!TryComp<WarpPointComponent>(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
Expand Down
7 changes: 4 additions & 3 deletions Content.Server/Warps/WarpPointComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// If true, ghosts warping to this entity will begin following it.
/// </summary>
[DataField("follow")]
public bool Follow = false;
[DataField]
public bool Follow;
}
}
20 changes: 20 additions & 0 deletions Resources/Prototypes/Entities/Markers/warp_point.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
name: warp point (beacon)
components:
- type: NavMapBeacon
- type: WarpPoint
location: beacon

- type: entity
parent: WarpPoint
Expand All @@ -21,6 +23,8 @@
suffix: ninja bombing target
components:
- type: BombingTarget
- type: WarpPoint
location: bombing target
- type: Sprite
layers:
- state: pink
Expand All @@ -36,6 +40,8 @@
- type: NavMapBeacon
text: bar
color: "#791500"
- type: WarpPoint
location: bar

- type: entity
id: WarpPointBeaconCargo
Expand All @@ -45,6 +51,8 @@
- type: NavMapBeacon
text: cargo
color: "#A46106"
- type: WarpPoint
location: cargo

- type: entity
id: WarpPointBeaconCommand
Expand All @@ -54,6 +62,8 @@
- type: NavMapBeacon
text: command
color: "#334E6D"
- type: WarpPoint
location: command

- type: entity
id: WarpPointBeaconEngineering
Expand All @@ -63,6 +73,8 @@
- type: NavMapBeacon
text: engineering
color: "#EFB341"
- type: WarpPoint
location: engineering

- type: entity
id: WarpPointBeaconMedical
Expand All @@ -72,6 +84,8 @@
- type: NavMapBeacon
text: medical
color: "#52B4E9"
- type: WarpPoint
location: medical

- type: entity
id: WarpPointBeaconNeutral
Expand All @@ -81,6 +95,8 @@
- type: NavMapBeacon
text: neutral
color: "#D4D4D4"
- type: WarpPoint
location: neutral

- type: entity
id: WarpPointBeaconScience
Expand All @@ -90,6 +106,8 @@
- type: NavMapBeacon
text: science
color: "#D381C9"
- type: WarpPoint
location: science

- type: entity
id: WarpPointBeaconService
Expand All @@ -99,3 +117,5 @@
- type: NavMapBeacon
text: service
color: "#9FED58"
- type: WarpPoint
location: service

0 comments on commit 1f0c931

Please sign in to comment.