public void RemoveSegmentBlock(IMyConveyorSegmentBlock segmentBlock) { if (IsClosing) { return; } if (OnBeforeRemoveSegmentBlock != null) { OnBeforeRemoveSegmentBlock(segmentBlock); } MyConveyorLine oldLine = segmentBlock.ConveyorSegment.ConveyorLine; MyConveyorLine newLine = segmentBlock.ConveyorSegment.ConveyorLine.RemovePortion(segmentBlock.ConveyorSegment.ConnectingPosition1.NeighbourGridPosition, segmentBlock.ConveyorSegment.ConnectingPosition2.NeighbourGridPosition); // Old line or new line can be empty after splitting. If the new line would be empty, Split(...) will return null // We have to unregister only old line if (oldLine.IsDegenerate) { m_lines.Remove(oldLine); } if (newLine == null) { return; } UpdateLineReferences(newLine, newLine); // The new line will always need to be registered Debug.Assert(!newLine.IsDegenerate); m_lines.Add(newLine); }
public void AddSegmentBlock(IMyConveyorSegmentBlock segmentBlock) { // Old line unregistering is done in the internal functions AddSegmentBlockInternal(segmentBlock, segmentBlock.ConveyorSegment.ConnectingPosition1); AddSegmentBlockInternal(segmentBlock, segmentBlock.ConveyorSegment.ConnectingPosition2); // Registering of the new line, if needed (the line can already be registered, if it was created by merging) if (!m_lines.Contains(segmentBlock.ConveyorSegment.ConveyorLine) && segmentBlock.ConveyorSegment.ConveyorLine != null) { m_lines.Add(segmentBlock.ConveyorSegment.ConveyorLine); } }
private void MergeSegmentSegment(IMyConveyorSegmentBlock newSegmentBlock, IMyConveyorSegmentBlock oldSegmentBlock) { MyConveyorLine line1 = newSegmentBlock.ConveyorSegment.ConveyorLine; MyConveyorLine line2 = oldSegmentBlock.ConveyorSegment.ConveyorLine; // Creating a cycle - no need to merge anything if (line1 != line2) { line2.Merge(line1, newSegmentBlock); } UpdateLineReferences(line1, line2); // newSegmentBlock is a newly created block, so we have to update its line reference as well newSegmentBlock.ConveyorSegment.SetConveyorLine(line2); }
public virtual void OnBlockIntegrityChanged(MySlimBlock block) { IMyConveyorEndpointBlock conveyorEndpointBlock = block.FatBlock as IMyConveyorEndpointBlock; if (conveyorEndpointBlock != null) { ConveyorSystem.FlagForRecomputation(); } IMyConveyorSegmentBlock conveyorSegmentBlock = block.FatBlock as IMyConveyorSegmentBlock; if (conveyorSegmentBlock != null) { ConveyorSystem.FlagForRecomputation(); } }
public virtual void OnBlockRemoved(MySlimBlock block) { IMyConveyorEndpointBlock conveyorEndpointBlock = block.FatBlock as IMyConveyorEndpointBlock; if (conveyorEndpointBlock != null) { ConveyorSystem.FlagForRecomputation(); } IMyConveyorSegmentBlock conveyorSegmentBlock = block.FatBlock as IMyConveyorSegmentBlock; if (conveyorSegmentBlock != null) { ConveyorSystem.FlagForRecomputation(); } if (ShipSoundComponent != null && block.FatBlock as MyThrust != null) { ShipSoundComponent.ShipHasChanged = true; } }
/// <summary> /// Tries to merge the conveyor lines of a conveyor block and segment block. /// Also changes the reference in the endpoint block to the correct line. /// </summary> private bool TryMergeEndpointSegment(IMyConveyorEndpointBlock endpoint, IMyConveyorSegmentBlock segmentBlock, ConveyorLinePosition endpointPosition) { MyConveyorLine endpointLine = endpoint.ConveyorEndpoint.GetConveyorLine(endpointPosition); if (endpointLine == null) { return(false); } // The conveyor segment cannot merge with the given endpoint if (!segmentBlock.ConveyorSegment.CanConnectTo(endpointPosition.GetConnectingPosition(), endpointLine.Type)) { return(false); } MyConveyorLine segmentLine = segmentBlock.ConveyorSegment.ConveyorLine; segmentLine.Merge(endpointLine, segmentBlock); endpoint.ConveyorEndpoint.SetConveyorLine(endpointPosition, segmentLine); endpointLine.RecalculateConductivity(); segmentLine.RecalculateConductivity(); return(true); }
private void AddSegmentBlockInternal(IMyConveyorSegmentBlock segmentBlock, ConveyorLinePosition connectingPosition) { var otherBlock = m_grid.GetCubeBlock(connectingPosition.LocalGridPosition); if (otherBlock != null) { if (m_deserializedLines != null && m_deserializedLines.Contains(segmentBlock.ConveyorSegment.ConveyorLine)) { return; } var otherConveyorBlock = otherBlock.FatBlock as IMyConveyorEndpointBlock; var otherSegmentBlock = otherBlock.FatBlock as IMyConveyorSegmentBlock; if (otherSegmentBlock != null) { var oldLine = segmentBlock.ConveyorSegment.ConveyorLine; if (m_lines.Contains(oldLine)) { m_lines.Remove(oldLine); } if (otherSegmentBlock.ConveyorSegment.CanConnectTo(connectingPosition, segmentBlock.ConveyorSegment.ConveyorLine.Type)) { MergeSegmentSegment(segmentBlock, otherSegmentBlock); } } if (otherConveyorBlock != null) { var oldLine = otherConveyorBlock.ConveyorEndpoint.GetConveyorLine(connectingPosition); if (TryMergeEndpointSegment(otherConveyorBlock, segmentBlock, connectingPosition)) { m_lines.Remove(oldLine); } } } }
/// <summary> /// Tries to merge the conveyor lines of a conveyor block and segment block. /// Also changes the reference in the endpoint block to the correct line. /// </summary> private bool TryMergeEndpointSegment(IMyConveyorEndpointBlock endpoint, IMyConveyorSegmentBlock segmentBlock, ConveyorLinePosition endpointPosition) { MyConveyorLine endpointLine = endpoint.ConveyorEndpoint.GetConveyorLine(endpointPosition); if (endpointLine == null) return false; // The conveyor segment cannot merge with the given endpoint if (!segmentBlock.ConveyorSegment.CanConnectTo(endpointPosition.GetConnectingPosition(), endpointLine.Type)) return false; MyConveyorLine segmentLine = segmentBlock.ConveyorSegment.ConveyorLine; segmentLine.Merge(endpointLine, segmentBlock); endpoint.ConveyorEndpoint.SetConveyorLine(endpointPosition, segmentLine); endpointLine.RecalculateConductivity(); segmentLine.RecalculateConductivity(); return true; }
private void AddSegmentBlockInternal(IMyConveyorSegmentBlock segmentBlock, ConveyorLinePosition connectingPosition) { var otherBlock = m_grid.GetCubeBlock(connectingPosition.LocalGridPosition); if (otherBlock != null) { if (m_deserializedLines != null && m_deserializedLines.Contains(segmentBlock.ConveyorSegment.ConveyorLine)) return; var otherConveyorBlock = otherBlock.FatBlock as IMyConveyorEndpointBlock; var otherSegmentBlock = otherBlock.FatBlock as IMyConveyorSegmentBlock; if (otherSegmentBlock != null) { var oldLine = segmentBlock.ConveyorSegment.ConveyorLine; if (m_lines.Contains(oldLine)) { m_lines.Remove(oldLine); } if (otherSegmentBlock.ConveyorSegment.CanConnectTo(connectingPosition, segmentBlock.ConveyorSegment.ConveyorLine.Type)) MergeSegmentSegment(segmentBlock, otherSegmentBlock); } if (otherConveyorBlock != null) { var oldLine = otherConveyorBlock.ConveyorEndpoint.GetConveyorLine(connectingPosition); if (TryMergeEndpointSegment(otherConveyorBlock, segmentBlock, connectingPosition)) { m_lines.Remove(oldLine); } } } }
public void RemoveSegmentBlock(IMyConveyorSegmentBlock segmentBlock) { if (IsClosing) return; if (OnBeforeRemoveSegmentBlock != null) OnBeforeRemoveSegmentBlock(segmentBlock); MyConveyorLine oldLine = segmentBlock.ConveyorSegment.ConveyorLine; MyConveyorLine newLine = segmentBlock.ConveyorSegment.ConveyorLine.RemovePortion(segmentBlock.ConveyorSegment.ConnectingPosition1.NeighbourGridPosition, segmentBlock.ConveyorSegment.ConnectingPosition2.NeighbourGridPosition); // Old line or new line can be empty after splitting. If the new line would be empty, Split(...) will return null // We have to unregister only old line if (oldLine.IsDegenerate) m_lines.Remove(oldLine); if (newLine == null) return; UpdateLineReferences(newLine, newLine); // The new line will always need to be registered Debug.Assert(!newLine.IsDegenerate); m_lines.Add(newLine); }
public virtual void UnregisterFromSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.RemoveSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.RemoveSink(sink, true, false); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = null; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Unregister(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block5 = block as MyTerminalBlock; if (block5 != null) { this.TerminalSystem.Remove(block5); } } if (block.HasInventory) { this.ConveyorSystem.Remove(block); } IMyConveyorEndpointBlock block2 = block as IMyConveyorEndpointBlock; if (block2 != null) { this.ConveyorSystem.RemoveConveyorBlock(block2); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { this.ConveyorSystem.RemoveSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Unregister(reflector); } MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); if (broadcaster != null) { this.RadioSystem.Unregister(broadcaster); } MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); if (reciever != null) { this.RadioSystem.Unregister(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Unregister(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Unregister(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Unregister(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Unregister(camera); } } block.OnUnregisteredFromGridSystems(); }
public virtual void RegisterInSystems(MyCubeBlock block) { if (block.GetType() != typeof(MyCubeBlock)) { MyCubeBlock block1; if (this.ResourceDistributor != null) { MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && (sink != null)) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = this.ResourceDistributor; } } if (this.WeaponSystem != null) { IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } if (this.TerminalSystem != null) { MyTerminalBlock block6 = block as MyTerminalBlock; if (block6 != null) { this.TerminalSystem.Add(block6); } } if ((block == null) || !block.HasInventory) { block1 = null; } else { block1 = block; } MyCubeBlock block2 = block1; if (block2 != null) { this.ConveyorSystem.Add(block2); } IMyConveyorEndpointBlock endpointBlock = block as IMyConveyorEndpointBlock; if (endpointBlock != null) { endpointBlock.InitializeConveyorEndpoint(); this.ConveyorSystem.AddConveyorBlock(endpointBlock); } IMyConveyorSegmentBlock segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); this.ConveyorSystem.AddSegmentBlock(segmentBlock); } MyReflectorLight reflector = block as MyReflectorLight; if (reflector != null) { this.ReflectorLightSystem.Register(reflector); } if (block.Components.Contains(typeof(MyDataBroadcaster))) { MyDataBroadcaster broadcaster = block.Components.Get <MyDataBroadcaster>(); this.RadioSystem.Register(broadcaster); } if (block.Components.Contains(typeof(MyDataReceiver))) { MyDataReceiver reciever = block.Components.Get <MyDataReceiver>(); this.RadioSystem.Register(reciever); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { MyMotorSuspension motor = block as MyMotorSuspension; if (motor != null) { this.WheelSystem.Register(motor); } } IMyLandingGear gear = block as IMyLandingGear; if (gear != null) { this.LandingSystem.Register(gear); } MyGyro gyro = block as MyGyro; if (gyro != null) { this.GyroSystem.Register(gyro); } MyCameraBlock camera = block as MyCameraBlock; if (camera != null) { this.CameraSystem.Register(camera); } } block.OnRegisteredToGridSystems(); }