Skip to content

Commit

Permalink
make sure the gateway doesn't teleport itself or its own grid group
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Dec 15, 2024
1 parent 341f933 commit 38e44ea
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions Ringway/Data/Scripts/TeleportGateway/TeleportGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ public static void ProcessJumpRequest(long gatewayId, string link)
return;
}

// Get the gateway's GridGroup
List<IMyCubeGrid> gatewayGridGroup = new List<IMyCubeGrid>();
MyAPIGateway.GridGroups.GetGroup(sourceGateway.CubeGrid, GridLinkTypeEnum.Physical, gatewayGridGroup);

// Schedule the actual teleport
MyAPIGateway.Utilities.InvokeOnGameThread(() =>
{
Expand All @@ -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<IMySlimBlock> landingGears = new List<IMySlimBlock>();
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<IMySlimBlock> landingGears = new List<IMySlimBlock>();
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)
Expand Down

0 comments on commit 38e44ea

Please sign in to comment.