public virtual void OnAddedToGroup(MyGridLogicalGroupData group) { this.TerminalSystem = group.TerminalSystem; this.ResourceDistributor = group.ResourceDistributor; this.WeaponSystem = group.WeaponSystem; if (string.IsNullOrEmpty(this.ResourceDistributor.DebugName)) { this.ResourceDistributor.DebugName = this.m_cubeGrid.ToString(); } this.m_cubeGrid.OnFatBlockAdded += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.m_cubeGrid.OnFatBlockRemoved += new Action <MyCubeBlock>(this.ResourceDistributor.CubeGrid_OnFatBlockAddedOrRemoved); this.ResourceDistributor.AddSink(this.GyroSystem.ResourceSink); this.ResourceDistributor.AddSink(this.ConveyorSystem.ResourceSink); this.ConveyorSystem.ResourceSink.IsPoweredChanged += new Action(this.ResourceDistributor.ConveyorSystem_OnPoweredChanged); foreach (MyBlockGroup group2 in this.m_cubeGrid.BlockGroups) { this.TerminalSystem.AddUpdateGroup(group2, false, false); } this.TerminalSystem.GroupAdded += this.m_terminalSystem_GroupAdded; this.TerminalSystem.GroupRemoved += this.m_terminalSystem_GroupRemoved; foreach (MyCubeBlock block in this.m_cubeGrid.GetFatBlocks()) { if (!block.MarkedForClose) { MyTerminalBlock block2 = block as MyTerminalBlock; if (block2 != null) { this.TerminalSystem.Add(block2); } MyResourceSourceComponent source = block.Components.Get <MyResourceSourceComponent>(); if (source != null) { this.ResourceDistributor.AddSource(source); } MyResourceSinkComponent sink = block.Components.Get <MyResourceSinkComponent>(); if (sink != null) { this.ResourceDistributor.AddSink(sink); } IMyRechargeSocketOwner owner = block as IMyRechargeSocketOwner; if (owner != null) { owner.RechargeSocket.ResourceDistributor = group.ResourceDistributor; } IMyGunObject <MyDeviceBase> gun = block as IMyGunObject <MyDeviceBase>; if (gun != null) { this.WeaponSystem.Register(gun); } } } MyResourceDistributorComponent resourceDistributor = this.ResourceDistributor; resourceDistributor.OnPowerGenerationChanged = (Action <bool>)Delegate.Combine(resourceDistributor.OnPowerGenerationChanged, new Action <bool>(this.OnPowerGenerationChanged)); this.TerminalSystem.BlockManipulationFinishedFunction(); this.ResourceDistributor.UpdateBeforeSimulation(); }
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(); }