Skip to content

Commit d5e9bd1

Browse files
Fix and improve world ping bugs
- Prevent pinging invalid locations - This includes trying to ping space or planet locations that aren't part of playable world - When finding a tile under a mouse failed, attempt again but snap to expandable world objects - This will properly handle finding world objects in space - This doesn't allow pinging empty locations in space, as `GenWorld.MouseTile` cannot select those - Prevent drawing pings from planet layers that aren't currently active - When sending map location, use `PlanetTile.Invalid` rather than a surface tile with ID of 0. - When receiving pings, make sure that we received a valid ping location before accepting it
1 parent 6bc95f2 commit d5e9bd1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Source/Client/UI/DrawPingPlanet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ static void Postfix()
1616
{
1717
if (ping.mapId != -1) continue;
1818
if (ping.PlayerInfo is not { } player) continue;
19+
// Only display pings on the current layer
20+
if (ping.planetTile.Layer != Find.WorldSelector.SelectedLayer) continue;
1921

2022
var tileCenter = GenWorldUI.WorldToUIPosition(Find.WorldGrid.GetTileCenter(ping.planetTile));
2123
const float size = 30f;

Source/Client/UI/LocationPings.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using Multiplayer.Client.Util;
34
using Multiplayer.Common.Networking.Packet;
45
using RimWorld;
@@ -23,9 +24,19 @@ public void UpdatePing()
2324
if (MultiplayerStatic.PingKeyDef.JustPressed || KeyDown(Multiplayer.settings.sendPingButton))
2425
{
2526
if (WorldRendererUtility.WorldSelected)
26-
PingLocation(-1, GenWorld.MouseTile(), Vector3.zero);
27+
{
28+
// Grab the tile under mouse
29+
var tile = GenWorld.MouseTile();
30+
// If the tile is not valid, snap to expandable world objects (handles orbital locations)
31+
if (!tile.Valid)
32+
tile = GenWorld.MouseTile(true);
33+
34+
// Make sure the tile is valid and that we didn't ping with the mouse outside of map bounds or in space
35+
if (tile.Valid)
36+
PingLocation(-1, tile, Vector3.zero);
37+
}
2738
else if (Find.CurrentMap != null)
28-
PingLocation(Find.CurrentMap.uniqueID, 0, UI.MouseMapPosition());
39+
PingLocation(Find.CurrentMap.uniqueID, PlanetTile.Invalid, UI.MouseMapPosition());
2940
}
3041

3142
for (int i = pings.Count - 1; i >= 0; i--)
@@ -69,11 +80,16 @@ public void ReceivePing(ServerPingLocPacket packet)
6980
if (!Multiplayer.settings.enablePings) return;
7081

7182
var data = packet.data;
83+
var planetTile = new PlanetTile(data.planetTileId, data.planetTileLayer);
84+
// Return early if both the map and planet tile are invalid
85+
if (data.mapId == -1 && !planetTile.Valid)
86+
return;
87+
7288
pings.RemoveAll(p => p.player == packet.playerId);
7389
pings.Add(new PingInfo {
7490
player = packet.playerId,
7591
mapId = data.mapId,
76-
planetTile = new PlanetTile(data.planetTileId, data.planetTileLayer),
92+
planetTile = planetTile,
7793
mapLoc = new Vector3(data.x, data.y, data.z)
7894
});
7995
alertHidden = false;

0 commit comments

Comments
 (0)