コード例 #1
0
        public grid_logic(IMyCubeGrid new_grid)
        {
            _grid = new_grid;
            _grid.OnBlockAdded   += on_block_added;
            _grid.OnBlockRemoved += on_block_removed;
            sync_helper.register_logic_object(this, _grid.EntityId);
            _ID_on = ((MyObjectBuilder_CubeGrid)_grid.GetObjectBuilder()).DampenersEnabled;

            var block_list = new List <IMySlimBlock>();

            _grid.GetBlocks(block_list,
                            delegate(IMySlimBlock block)
            {
                return(block.FatBlock is IMyThrust || block.FatBlock is IMyGyro);
            }
                            );
            if (block_list.Count > 0)
            {
                _ECU = new engine_control_unit(_grid);
                foreach (var cur_block in block_list)
                {
                    var thruster = cur_block.FatBlock as IMyThrust;
                    var gyro     = cur_block.FatBlock as IMyGyro;
                    if (thruster != null)
                    {
                        _ECU.assign_thruster(thruster);
                        ++_num_thrusters;
                    }
                    if (gyro != null)
                    {
                        _ECU.assign_gyroscope(gyro);
                    }
                }
            }


            block_list.Clear();
            _grid.GetBlocks(block_list,
                            delegate(IMySlimBlock block)
            {
                return(block.FatBlock is IMyCockpit || block.FatBlock is IMyRemoteControl);
            }
                            );
            foreach (var cur_controller in block_list)
            {
                _ship_controllers.Add((IMyControllableEntity)cur_controller.FatBlock);
                var RC_block = cur_controller.FatBlock as IMyRemoteControl;
                if (RC_block != null)
                {
                    _RC_blocks.Add(RC_block);
                }
            }
        }
コード例 #2
0
        private void on_block_added(IMySlimBlock block)
        {
            check_disposed();
            IMyCubeBlock entity = block.FatBlock;

            if (entity != null)
            {
                var controller = entity as IMyControllableEntity;
                if (controller != null)
                {
                    _ship_controllers.Add(controller);
                }
                var RC_block = entity as IMyRemoteControl;
                if (RC_block != null)
                {
                    _RC_blocks.Add(RC_block);
                }

                var thruster = entity as IMyThrust;
                if (thruster != null)
                {
                    if (_ECU == null)
                    {
                        _ECU = new engine_control_unit(_grid);
                    }
                    _ECU.assign_thruster(thruster);
                    ++_num_thrusters;
                }
                var gyro = entity as IMyGyro;
                if (gyro != null)
                {
                    if (_ECU == null)
                    {
                        _ECU = new engine_control_unit(_grid);
                    }
                    _ECU.assign_gyroscope(gyro);
                }
            }
        }