From 38e44ea385135094c2f6e2f6e1c4066b4d5d9bd0 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Sun, 15 Dec 2024 01:20:14 -0600 Subject: [PATCH] make sure the gateway doesn't teleport itself or its own grid group --- .../TeleportGateway/TeleportGateway.cs | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Ringway/Data/Scripts/TeleportGateway/TeleportGateway.cs b/Ringway/Data/Scripts/TeleportGateway/TeleportGateway.cs index d83a174..a8e1c92 100644 --- a/Ringway/Data/Scripts/TeleportGateway/TeleportGateway.cs +++ b/Ringway/Data/Scripts/TeleportGateway/TeleportGateway.cs @@ -902,6 +902,10 @@ public static void ProcessJumpRequest(long gatewayId, string link) return; } + // Get the gateway's GridGroup + List gatewayGridGroup = new List(); + MyAPIGateway.GridGroups.GetGroup(sourceGateway.CubeGrid, GridLinkTypeEnum.Physical, gatewayGridGroup); + // Schedule the actual teleport MyAPIGateway.Utilities.InvokeOnGameThread(() => { @@ -924,27 +928,39 @@ public static void ProcessJumpRequest(long gatewayId, string link) } else if (grid != null && sourceGatewayLogic.Settings.AllowShips) { - if (!grid.IsStatic && grid.EntityId != sourceGateway.CubeGrid.EntityId) + // Check 1: Skip if grid is static + if (grid.IsStatic) { - List landingGears = new List(); - grid.GetBlocks(landingGears, b => b.FatBlock is SpaceEngineers.Game.ModAPI.Ingame.IMyLandingGear); - bool hasLockedGear = false; + MyLogger.Log($"TPGate: ProcessJumpRequest: Skipping static grid {grid.DisplayName}"); + continue; + } - foreach (var gear in landingGears) - { - var landingGear = gear.FatBlock as SpaceEngineers.Game.ModAPI.Ingame.IMyLandingGear; - if (landingGear != null && landingGear.IsLocked) - { - hasLockedGear = true; - break; - } - } + // Check 2: Skip if grid is part of the gateway's GridGroup + if (gatewayGridGroup.Contains(grid)) + { + MyLogger.Log($"TPGate: ProcessJumpRequest: Skipping grid {grid.DisplayName} as it's part of the gateway's GridGroup"); + continue; + } + + // Additional existing checks + List landingGears = new List(); + grid.GetBlocks(landingGears, b => b.FatBlock is SpaceEngineers.Game.ModAPI.Ingame.IMyLandingGear); + bool hasLockedGear = false; - if (!hasLockedGear) + foreach (var gear in landingGears) + { + var landingGear = gear.FatBlock as SpaceEngineers.Game.ModAPI.Ingame.IMyLandingGear; + if (landingGear != null && landingGear.IsLocked) { - shouldTeleport = true; + hasLockedGear = true; + break; } } + + if (!hasLockedGear) + { + shouldTeleport = true; + } } if (shouldTeleport)