Ejemplo n.º 1
0
        private int get_current_ID_mode(IMyTerminalBlock controller)
        {
            grid_logic controller_grid = _grids[controller.CubeGrid];

            engine_control_unit.ID_manoeuvres current_manoeuvre = controller_grid.current_manoeuvre;

            if (current_manoeuvre != engine_control_unit.ID_manoeuvres.manoeuvre_off)
            {
                return((int)current_manoeuvre + 1);
            }
            return(controller_grid.circularise ? 1 : 0);
        }
Ejemplo n.º 2
0
 private void activate_grid(IMyCubeGrid grid)
 {
     if (_inactive_grids.Contains(grid))
     {
         _inactive_grids.Remove(grid);
         var new_grid_logic = new grid_logic(grid);
         _grids_handle_60Hz                 += new_grid_logic.handle_60Hz;
         _grids_handle_4Hz_foreground       += new_grid_logic.handle_4Hz_foreground;
         _grids_handle_2s_period_foreground += new_grid_logic.handle_2s_period_foreground;
         _grids_handle_4Hz_background       += new_grid_logic.handle_4Hz_background;
         _grids_handle_2s_period_background += new_grid_logic.handle_2s_period_background;
         _grids_perform_calibration         += new_grid_logic.perform_individual_calibration;
         _grids.Add(grid, new_grid_logic);
     }
 }
Ejemplo n.º 3
0
 private void deactivate_grid(IMyCubeGrid grid)
 {
     if (_grids.ContainsKey(grid))
     {
         grid_logic grid_logic_to_remove = _grids[grid];
         _grids_handle_60Hz                 -= grid_logic_to_remove.handle_60Hz;
         _grids_handle_4Hz_foreground       -= grid_logic_to_remove.handle_4Hz_foreground;
         _grids_handle_2s_period_foreground -= grid_logic_to_remove.handle_2s_period_foreground;
         _grids_handle_4Hz_background       -= grid_logic_to_remove.handle_4Hz_background;
         _grids_handle_2s_period_background -= grid_logic_to_remove.handle_2s_period_background;
         _grids_perform_calibration         -= grid_logic_to_remove.perform_individual_calibration;
         grid_logic_to_remove.Dispose();
         _grids.Remove(grid);
         _inactive_grids.Add(grid);
     }
 }
Ejemplo n.º 4
0
        public static void load_grid_settings(IMyCubeGrid grid, grid_logic grid_handler)
        {
            sync_helper.register_entity(sync_helper.message_types.GRID_MODES, grid, grid.EntityId);
            sync_helper.register_entity(sync_helper.message_types.MANOEUVRE, grid, grid.EntityId);
            sync_helper.register_entity(sync_helper.message_types.GRID_CONTROL_SENSITIVITY, grid, grid.EntityId);
            _grid_handlers[grid] = grid_handler;
            _grid_settings[grid] = new StringBuilder(new string('0', GRID_FIELDS_LENGTH));

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

            if (!sync_helper.running_on_server)
            {
                //log_tagger_action("load_grid_settings", $"queueing \"{grid.DisplayName}\" state for player {screen_info.local_player.SteamUserId}");
                if (_pending_grid_requests == null)
                {
                    _pending_grid_requests = new HashSet <IMyCubeGrid>();
                }
                _pending_grid_requests.Add(grid);
                _have_pending_requests = true;
                return;
            }

            string grid_data = grid.Storage.ContainsKey(_uuid) ? grid.Storage[_uuid] : "";

            _grid_switches     = (grid_data.Length > GRID_MODE_FIELD_END) ? parse_number(grid_data, GRID_MODE_FIELD_START, GRID_MODE_FIELD_END) : 0;
            _current_manoeuvre = (grid_data.Length > GRID_MANOEUVRE_FIELD_END)
                ? ((engine_control_unit.ID_manoeuvres)parse_number(grid_data, GRID_MANOEUVRE_FIELD_START, GRID_MANOEUVRE_FIELD_END))
                : engine_control_unit.ID_manoeuvres.manoeuvre_off;
            _grid_control_sensitivity = (grid_data.Length > GRID_CONTROL_SENSITIVITY_FIELD_END)
                ? parse_number(grid_data, GRID_CONTROL_SENSITIVITY_FIELD_START, GRID_CONTROL_SENSITIVITY_FIELD_END)
                : ((int)(5.0f * GRID_CONTROL_SENSITIVITY_SCALE));
            update_grid_flags(grid, use_remote_switches: true, use_remote_manoeuvre: true, use_remote_sensitivity: true);
            //log_tagger_action("load_grid_settings", $"\"{grid.DisplayName}\" S={_grid_switches:X}h M={_current_manoeuvre} P={_grid_control_sensitivity}");
        }
Ejemplo n.º 5
0
        private static bool update_grid_flags(IMyCubeGrid grid, bool use_remote_switches = false, bool use_remote_manoeuvre = false,
                                              bool use_remote_sensitivity = false)
        {
            if (!_grid_handlers.ContainsKey(grid))
            {
                return(false);
            }

            if (grid == _current_grid && !use_remote_switches && !use_remote_manoeuvre && !use_remote_sensitivity)
            {
                return(true);
            }

            _current_grid          = grid;
            _current_grid_settings = _grid_settings[grid];
            if (!use_remote_switches)
            {
                _grid_switches = parse_number(_current_grid_settings, GRID_MODE_FIELD_START, GRID_MODE_FIELD_END);
            }
            else
            {
                store_number(_current_grid_settings, _grid_switches, GRID_MODE_FIELD_START, GRID_MODE_FIELD_END);
                grid.Storage[_uuid] = _current_grid_settings.ToString();
            }
            if (!use_remote_manoeuvre)
            {
                _current_manoeuvre = (engine_control_unit.ID_manoeuvres)parse_number(_current_grid_settings, GRID_MANOEUVRE_FIELD_START, GRID_MANOEUVRE_FIELD_END);
            }
            else
            {
                store_number(_current_grid_settings, (int)_current_manoeuvre, GRID_MANOEUVRE_FIELD_START, GRID_MANOEUVRE_FIELD_END);
                grid.Storage[_uuid] = _current_grid_settings.ToString();
            }
            if (!use_remote_sensitivity)
            {
                _grid_control_sensitivity = parse_number(_current_grid_settings, GRID_CONTROL_SENSITIVITY_FIELD_START, GRID_CONTROL_SENSITIVITY_FIELD_END);
            }
            else
            {
                store_number(_current_grid_settings, _grid_control_sensitivity, GRID_CONTROL_SENSITIVITY_FIELD_START, GRID_CONTROL_SENSITIVITY_FIELD_END);
                grid.Storage[_uuid] = _current_grid_settings.ToString();
            }
            _CoT_mode_on               = (_grid_switches & COT_MODE) != 0;
            _touchdown_mode_on         = (_grid_switches & TOUCHDOWN_MODE) != 0;
            _rotational_damping_on     = (_grid_switches & ROTATIONAL_DAMNPING_OFF) == 0;
            _individual_calibration_on = (_grid_switches & INDIVIDUAL_CALIBRATION) != 0;
            _circularisation_on        = (_grid_switches & ID_CIRCULARISE) != 0;

            if (use_remote_switches)
            {
                grid_logic grid_handler = _grid_handlers[grid];
                grid_handler.set_CoT_mode(_CoT_mode_on);
                grid_handler.set_rotational_damping(_rotational_damping_on);
                grid_handler.set_touchdown_mode(_touchdown_mode_on);
                grid_handler.set_individual_calibration_use(_individual_calibration_on);
                grid_handler.set_circularisation(_circularisation_on);
                grid_handler.set_damper_enabled_axes(
                    (_grid_switches & IDO_FORE_AFT) == 0,
                    (_grid_switches & IDO_PORT_STARBOARD) == 0,
                    (_grid_switches & IDO_DORSAL_VENTRAL) == 0);
            }
            if (use_remote_manoeuvre)
            {
                _grid_handlers[grid].start_manoeuvre(_current_manoeuvre);
            }
            if (use_remote_sensitivity)
            {
                _grid_handlers[grid].set_thrust_control_sensitivity(_grid_control_sensitivity / GRID_CONTROL_SENSITIVITY_SCALE);
            }

            return(true);
        }