public static Action <IMyTerminalBlock> create_manoeuvre_starter(engine_control_unit.ID_manoeuvres manoeuvre) { return(delegate(IMyTerminalBlock controller) { start_manoeuvre(controller.CubeGrid, manoeuvre); }); }
public void start_manoeuvre(engine_control_unit.ID_manoeuvres selection) { if (is_circularisation_avaiable || selection == engine_control_unit.ID_manoeuvres.manoeuvre_off) { _ECU.current_manoeuvre = selection; } }
public static void remote_grid_settings(sync_helper.message_types message_type, object entity, byte[] argument, int length) { var grid = entity as IMyCubeGrid; if (grid == null) { return; } if (message_type == sync_helper.message_types.MANOEUVRE && length == 1) { _current_manoeuvre = (engine_control_unit.ID_manoeuvres)argument[0]; //log_tagger_action("remote_grid_settings", $"received \"{grid.DisplayName}\" M={_current_manoeuvre}"); update_grid_flags(grid, use_remote_manoeuvre: true); } else if (message_type == sync_helper.message_types.GRID_CONTROL_SENSITIVITY && length == 2) { _grid_control_sensitivity = (int)sync_helper.decode_signed(2, argument, 0); //log_tagger_action("remote_grid_settings", $"received \"{grid.DisplayName}\" P={_grid_control_sensitivity / GRID_CONTROL_SENSITIVITY_SCALE}"); update_grid_flags(grid, use_remote_sensitivity: true); } else if (message_type == sync_helper.message_types.GRID_MODES) { if (length == 1) { _grid_switches = argument[0]; //log_tagger_action("remote_grid_settings", $"received \"{grid.DisplayName}\" S={_grid_switches:X}h"); update_grid_flags(grid, use_remote_switches: true); } else if (length == 8 && sync_helper.running_on_server) { update_grid_flags(grid); _message[0] = (byte)_grid_switches; _message[1] = (byte)_current_manoeuvre; sync_helper.encode_signed(_grid_control_sensitivity, 2, _message, 2); ulong recipient = sync_helper.decode_unsigned(8, argument, 0); //log_tagger_action("remote_grid_settings", $"sending \"{grid.DisplayName}\" S={_grid_switches:X}h+M={_current_manoeuvre}+P={_grid_control_sensitivity / GRID_CONTROL_SENSITIVITY_SCALE} to {recipient}"); sync_helper.send_message_to(recipient, sync_helper.message_types.GRID_MODES, grid, _message, 4); } else if (length == 4 && !sync_helper.running_on_server) { _pending_grid_requests.Remove(grid); _have_pending_requests = _pending_thruster_requests != null && _pending_thruster_requests.Count > 0 || _pending_grid_requests != null && _pending_grid_requests.Count > 0; _grid_switches = argument[0]; _current_manoeuvre = (engine_control_unit.ID_manoeuvres)argument[1]; _grid_control_sensitivity = (int)sync_helper.decode_signed(2, argument, 2); //log_tagger_action("remote_grid_settings", $"received \"{grid.DisplayName}\" S={_grid_switches:X}h+M={_current_manoeuvre}+P={_grid_control_sensitivity / GRID_CONTROL_SENSITIVITY_SCALE}"); update_grid_flags(grid, use_remote_switches: true, use_remote_manoeuvre: true, use_remote_sensitivity: true); } } }
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); }
public static void start_manoeuvre(IMyCubeGrid grid, engine_control_unit.ID_manoeuvres manoeuvre) { if (!update_grid_flags(grid)) { return; } if (manoeuvre == _current_manoeuvre) { manoeuvre = engine_control_unit.ID_manoeuvres.manoeuvre_off; } _current_manoeuvre = manoeuvre; store_number(_current_grid_settings, (int)manoeuvre, GRID_MANOEUVRE_FIELD_START, GRID_MANOEUVRE_FIELD_END); _current_grid.Storage[_uuid] = _current_grid_settings.ToString(); _grid_handlers[grid].start_manoeuvre(manoeuvre); _message[0] = (byte)manoeuvre; sync_helper.send_message_to_others(sync_helper.message_types.MANOEUVRE, grid, _message, 1); }
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}"); }
public static Action <IMyTerminalBlock, StringBuilder> create_manoeuvre_indicator(engine_control_unit.ID_manoeuvres manoeuvre) { return(delegate(IMyTerminalBlock controller, StringBuilder status) { status.Clear(); if (!update_grid_flags(controller.CubeGrid)) { return; } if (_current_manoeuvre == manoeuvre) { status.Append("Active"); } }); }
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); }