public virtual void OnAddedToGroup(MyGridLogicalGroupData group) { Debug.Assert(group.TerminalSystem != null, "Terminal system is null!"); TerminalSystem = group.TerminalSystem; ResourceDistributor = group.ResourceDistributor; WeaponSystem = group.WeaponSystem; m_cubeGrid.OnBlockAdded += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved; m_cubeGrid.OnBlockRemoved += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved; ResourceDistributor.AddSink(GyroSystem.ResourceSink); ResourceDistributor.AddSink(ConveyorSystem.ResourceSink); ResourceDistributor.UpdateBeforeSimulation10(); ConveyorSystem.ResourceSink.IsPoweredChanged += ResourceDistributor.ConveyorSystem_OnPoweredChanged; foreach (var g in m_cubeGrid.BlockGroups) { TerminalSystem.AddUpdateGroup(g); } TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded; TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved; foreach (var block in m_cubeGrid.GetFatBlocks()) { if (!block.MarkedForClose) { var functionalBlock = block as MyTerminalBlock; if (functionalBlock != null) { TerminalSystem.Add(functionalBlock); } var producer = block.Components.Get <MyResourceSourceComponent>(); if (producer != null) { ResourceDistributor.AddSource(producer); } var consumer = block.Components.Get <MyResourceSinkComponent>(); if (consumer != null) { ResourceDistributor.AddSink(consumer); } var socketOwner = block as IMyRechargeSocketOwner; if (socketOwner != null) { socketOwner.RechargeSocket.ResourceDistributor = group.ResourceDistributor; } var weapon = block as IMyGunObject <MyDeviceBase>; if (weapon != null) { WeaponSystem.Register(weapon); } } } }
public virtual void OnAddedToGroup(MyGridLogicalGroupData group) { Debug.Assert(group.TerminalSystem != null, "Terminal system is null!"); TerminalSystem = group.TerminalSystem; PowerDistributor = group.PowerDistributor; WeaponSystem = group.WeaponSystem; PowerDistributor.AddConsumer(ThrustSystem); PowerDistributor.AddConsumer(GyroSystem); PowerDistributor.AddConsumer(ConveyorSystem); foreach (var g in m_cubeGrid.BlockGroups) { TerminalSystem.AddUpdateGroup(g); } TerminalSystem.GroupAdded += m_terminalSystem_GroupAdded; TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved; foreach (var block in m_cubeGrid.GetBlocks()) { if (block.FatBlock == null) { continue; } if (!block.FatBlock.MarkedForClose) { var functionalBlock = block.FatBlock as MyTerminalBlock; if (functionalBlock != null) { TerminalSystem.Add(functionalBlock); } var producer = block.FatBlock as IMyPowerProducer; if (producer != null) { PowerDistributor.AddProducer(producer); } var consumer = block.FatBlock as IMyPowerConsumer; if (consumer != null) { PowerDistributor.AddConsumer(consumer); } var socketOwner = block.FatBlock as IMyRechargeSocketOwner; if (socketOwner != null) { socketOwner.RechargeSocket.PowerDistributor = group.PowerDistributor; } var weapon = block.FatBlock as IMyGunObject <MyDeviceBase>; if (weapon != null) { WeaponSystem.Register(weapon); } } } }
public virtual void RegisterInSystems(MyCubeBlock block) { if (ResourceDistributor != null) { var powerProducer = block.Components.Get <MyResourceSourceComponent>(); if (powerProducer != null) { ResourceDistributor.AddSource(powerProducer); } var powerConsumer = block.Components.Get <MyResourceSinkComponent>(); if (!(block is MyThrust) && powerConsumer != null) { ResourceDistributor.AddSink(powerConsumer); } var socketOwner = block as IMyRechargeSocketOwner; if (socketOwner != null) { socketOwner.RechargeSocket.ResourceDistributor = ResourceDistributor; } } if (WeaponSystem != null) { var weapon = block as IMyGunObject <MyDeviceBase>; if (weapon != null) { WeaponSystem.Register(weapon); } } if (TerminalSystem != null) { var functionalBlock = block as MyTerminalBlock; if (functionalBlock != null) { TerminalSystem.Add(functionalBlock); } } // CH: We probably don't need to register controller blocks here. Block that's being added to a grid should not have a controller set var controllableBlock = block as MyShipController; Debug.Assert(controllableBlock == null || controllableBlock.ControllerInfo.Controller == null, "Controller of added block is not null. Call Cestmir"); /*if (ControlSystem != null) * { * var controllableBlock = block as MyShipController; * if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null) * ControlSystem.AddControllerBlock(controllableBlock); * }*/ var inventoryBlock = (block != null && block.HasInventory) ? block : null; if (inventoryBlock != null) { ConveyorSystem.Add(inventoryBlock); } var conveyorBlock = block as IMyConveyorEndpointBlock; if (conveyorBlock != null) { conveyorBlock.InitializeConveyorEndpoint(); ConveyorSystem.AddConveyorBlock(conveyorBlock); } var segmentBlock = block as IMyConveyorSegmentBlock; if (segmentBlock != null) { segmentBlock.InitializeConveyorSegment(); ConveyorSystem.AddSegmentBlock(segmentBlock); } var reflectorLight = block as MyReflectorLight; if (reflectorLight != null) { ReflectorLightSystem.Register(reflectorLight); } if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT) { var wheel = block as MyMotorSuspension; if (wheel != null) { WheelSystem.Register(wheel); } } var landingGear = block as IMyLandingGear; if (landingGear != null) { LandingSystem.Register(landingGear); } var gyro = block as MyGyro; if (gyro != null) { GyroSystem.Register(gyro); } var camera = block as MyCameraBlock; if (camera != null) { CameraSystem.Register(camera); } block.OnRegisteredToGridSystems(); }