diff --git a/DeltaVBaR/Data/Scripts/SKO-Nanobot-BuildAndRepair-System/NanobotBuildAndRepairSystemBlock.cs b/DeltaVBaR/Data/Scripts/SKO-Nanobot-BuildAndRepair-System/NanobotBuildAndRepairSystemBlock.cs index f795af1..90fd40f 100644 --- a/DeltaVBaR/Data/Scripts/SKO-Nanobot-BuildAndRepair-System/NanobotBuildAndRepairSystemBlock.cs +++ b/DeltaVBaR/Data/Scripts/SKO-Nanobot-BuildAndRepair-System/NanobotBuildAndRepairSystemBlock.cs @@ -461,6 +461,19 @@ private void UpdateBeforeSimulation10_100(bool fast) CleanupFriendlyDamage(); } + // Check if other BaR is powered in grid group + if (_Welder.Enabled && IsOtherBaRPoweredInGridGroup()) + { + _Welder.Enabled = false; + NotifyPlayersInRange( + "Only one Build And Repair System can be powered per grid group", + _Welder.GetPosition(), + 100, + "Red" + ); + return; + } + ServerTryWeldingGrindingCollecting(); if (!fast) @@ -512,6 +525,49 @@ private void UpdateBeforeSimulation10_100(bool fast) } } + private bool IsOtherBaRPoweredInGridGroup() + { + var grid = _Welder.CubeGrid; + var groupedGrids = new HashSet(); + MyAPIGateway.GridGroups.GetGroup(grid, GridLinkTypeEnum.Physical, groupedGrids); + + foreach (var connectedGrid in groupedGrids) + { + var blocks = new List(); + connectedGrid.GetBlocks(blocks); + + foreach (var block in blocks) + { + var bar = block.FatBlock as IMyShipWelder; + if (bar != null && bar.BlockDefinition.SubtypeName.Contains("NanobotBuildAndRepairSystem")) + { + var otherSystem = bar.GameLogic.GetAs(); + if (otherSystem != null && otherSystem != this && otherSystem.Welder.IsWorking) + { + return true; + } + } + } + } + + return false; + } + + private void NotifyPlayersInRange(string message, Vector3D position, double radius, string color = "White") + { + var sphere = new BoundingSphereD(position, radius); + var entities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere); + + foreach (var entity in entities) + { + var character = entity as IMyCharacter; + if (character != null && character.IsPlayer) + { + MyAPIGateway.Utilities.ShowNotification(message, 2000, color); + } + } + } + /// /// Try to weld/grind/collect the possible targets ///