Skip to content

Commit

Permalink
Merge pull request #270 from InvalidArgument3/barfork
Browse files Browse the repository at this point in the history
THERE CAN ONLY BE ONE (build and repair turned on in a GridGroup)
  • Loading branch information
InvalidArgument3 authored Dec 2, 2024
2 parents 3fd7eb9 + bc246db commit 6578a49
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -512,6 +525,49 @@ private void UpdateBeforeSimulation10_100(bool fast)
}
}

private bool IsOtherBaRPoweredInGridGroup()
{
var grid = _Welder.CubeGrid;
var groupedGrids = new HashSet<IMyCubeGrid>();
MyAPIGateway.GridGroups.GetGroup(grid, GridLinkTypeEnum.Physical, groupedGrids);

foreach (var connectedGrid in groupedGrids)
{
var blocks = new List<IMySlimBlock>();
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<NanobotBuildAndRepairSystemBlock>();
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);
}
}
}

/// <summary>
/// Try to weld/grind/collect the possible targets
/// </summary>
Expand Down

0 comments on commit 6578a49

Please sign in to comment.