Пример #1
0
        private void initialise_ECU_and_physics()
        {
            var grid_movement = new gravity_and_physics(_grid);

            _ECU          = new engine_control_unit(_grid, grid_movement);
            _grid_physics = grid_movement;
        }
Пример #2
0
        private static bool update_thruster_flags(IMyTerminalBlock thruster, bool use_remote_switches = false, bool use_remote_manual_throttle = false)
        {
            if (!(thruster is IMyThrust) || !_thruster_hosts.ContainsKey(thruster))
            {
                _current_thruster          = null;
                _current_thruster_settings = null;
                _current_active_control_on = _current_anti_slip_on = _current_disable_linear = _current_thrust_limiter_on = false;
                _manual_throttle           = 0;
                return(false);
            }
            if (thruster == _current_thruster && !use_remote_switches && !use_remote_manual_throttle)
            {
                return(true);
            }

            _current_thruster          = thruster;
            _current_thruster_settings = _thruster_settings[thruster];
            thruster.RefreshCustomInfo();
            if (!use_remote_switches)
            {
                _thruster_switches = parse_number(_current_thruster_settings, THRUSTER_MODE_FIELD_START, THRUSTER_MODE_FIELD_END);
            }
            else
            {
                store_number(_current_thruster_settings, _thruster_switches, THRUSTER_MODE_FIELD_START, THRUSTER_MODE_FIELD_END);
                thruster.Storage[_uuid] = _current_thruster_settings.ToString();
            }
            if (!use_remote_manual_throttle)
            {
                _manual_throttle = parse_number(_current_thruster_settings, MANUAL_THROTTLE_FIELD_START, MANUAL_THROTTLE_FIELD_END);
            }
            else
            {
                store_number(_current_thruster_settings, _manual_throttle, MANUAL_THROTTLE_FIELD_START, MANUAL_THROTTLE_FIELD_END);
                thruster.Storage[_uuid] = _current_thruster_settings.ToString();
            }
            _current_active_control_on = (_thruster_switches & STEERING) != 0;
            _current_anti_slip_on      = (_thruster_switches & THRUST_TRIM) != 0;
            _current_thrust_limiter_on = (_thruster_switches & THRUST_LIMIT) != 0;
            _current_disable_linear    = (_thruster_switches & LINEAR_OFF) != 0;

            if (use_remote_switches)
            {
                engine_control_unit host = _thruster_hosts[thruster];
                long thruster_entity_id  = thruster.EntityId;
                host.set_thruster_steering(thruster_entity_id, _current_active_control_on);
                host.set_thruster_trim(thruster_entity_id, _current_anti_slip_on);
                host.set_thruster_limiter(thruster_entity_id, _current_thrust_limiter_on);
                host.set_thruster_linear_input(thruster_entity_id, _current_disable_linear);
            }
            if (use_remote_manual_throttle)
            {
                _thruster_hosts[thruster].set_manual_throttle(thruster.EntityId, _manual_throttle / MANUAL_THROTTLE_SCALE);
            }

            return(true);
        }
Пример #3
0
        internal static void I_terms_handler(sync_helper.message_types message_type, object entity, byte[] argument, int length)
        {
            if (length != 18 || sync_helper.running_on_server)
            {
                return;
            }

            var instance = entity as grid_logic;

            if (instance == null || instance._disposed)
            {
                return;
            }

            engine_control_unit current_ECU = instance._ECU;

            current_ECU.current_trim    = structurise_vector(argument, 0);
            current_ECU.aux_trim        = structurise_vector(argument, 6);
            current_ECU.linear_integral = structurise_vector(argument, 12);
        }
Пример #4
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)
                {
                    log_grid_action("on_block_added", thruster.BlockDefinition.SubtypeName);
                    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);
                }
            }
        }
Пример #5
0
        public static void attach_ECU(IMyTerminalBlock thruster, engine_control_unit ECU)
        {
            sync_helper.register_entity(sync_helper.message_types.THRUSTER_MODES, thruster, thruster.EntityId);
            sync_helper.register_entity(sync_helper.message_types.MANUAL_THROTTLE, thruster, thruster.EntityId);
            _thruster_hosts   [thruster] = ECU;
            _thruster_settings[thruster] = new StringBuilder(new string('0', THRUSTER_FIELDS_LENGTH));

            if (thruster.Storage == null)
            {
                thruster.Storage = new MyModStorageComponent();
            }

            if (!sync_helper.running_on_server)
            {
                //log_tagger_action("attach_ECU", $"queueing \"{thruster.CustomName}\" state for player {screen_info.local_player.SteamUserId}");
                if (_pending_thruster_requests == null)
                {
                    _pending_thruster_requests = new HashSet <IMyTerminalBlock>();
                }
                _pending_thruster_requests.Add(thruster);
                _have_pending_requests = true;
                return;
            }

            string thruster_data;

            if (!thruster.Storage.TryGetValue(_uuid, out thruster_data) || thruster_data.Length < THRUSTER_FIELDS_LENGTH)
            {
                _thruster_switches = _manual_throttle = 0;
            }
            else
            {
                _thruster_switches = parse_number(thruster_data, THRUSTER_MODE_FIELD_START, THRUSTER_MODE_FIELD_END);
                _manual_throttle   = parse_number(thruster_data, MANUAL_THROTTLE_FIELD_START, MANUAL_THROTTLE_FIELD_END);
            }
            update_thruster_flags(thruster, use_remote_switches: true, use_remote_manual_throttle: true);
        }