void InitializeFacility() { _currentFacility = EditorDriver.editorFacility; if (_currentFacility == EditorFacility.VAB) { _facilityDefaultsTitle = "#ModAutoAction_VabDefaults"; _facilitySettings = _settings.VabSettings; } else { _facilityDefaultsTitle = "#ModAutoAction_SphDefaults"; _facilitySettings = _settings.SphSettings; } }
void Activate(VesselSettings vessel) { Debug.Log($"[{nameof(AutoAction)}] flight: Activate"); // Loading facility default settings FacilitySettings facility = GetFacilitySettings(); // Selecting action set if (vessel.ActionSet is int set) { Static.Vessel.SetGroupOverride(FlightGlobals.ActiveVessel, set); } // Activating standard action groups ActionGroupList actionGroups = FlightGlobals.ActiveVessel.ActionGroups; actionGroups.SetGroup(KSPActionGroup.SAS, vessel.ActivateSAS ?? facility.ActivateSAS); actionGroups.SetGroup(KSPActionGroup.RCS, vessel.ActivateRCS ?? facility.ActivateRCS); actionGroups.SetGroup(KSPActionGroup.Brakes, vessel.ActivateBrakes ?? facility.ActivateBrakes); actionGroups.SetGroup(KSPActionGroup.Abort, vessel.ActivateAbort ?? facility.ActivateAbort); // Special treatment for the groups with the initial state determined by the part state SetAutoInitializingGroup(KSPActionGroup.Gear, vessel.ActivateGear); SetAutoInitializingGroup(KSPActionGroup.Light, vessel.ActivateLights); // Activating custom action groups foreach (int customGroup in vessel.CustomGroups.OfType <int>()) { ActivateCustomActionGroup(customGroup); } // Setting precision control SetPrecisionMode(vessel.SetPrecCtrl ?? facility.SetPrecCtrl); // Setting throttle FlightInputHandler.state.mainThrottle = Mathf.Max(0, Mathf.Min(1, (vessel.SetThrottle ?? facility.SetThrottle) / 100F)); // Setting trim FlightInputHandler.state.pitchTrim = TrimStep * vessel.SetPitchTrim; FlightInputHandler.state.yawTrim = TrimStep * vessel.SetYawTrim; FlightInputHandler.state.rollTrim = TrimStep * vessel.SetRollTrim; FlightInputHandler.state.wheelThrottleTrim = TrimStep * vessel.SetWheelMotorTrim; FlightInputHandler.state.wheelSteerTrim = -TrimStep * vessel.SetWheelSteerTrim; // inverted // Staging if (vessel.Stage ?? facility.Stage) { StageManager.ActivateNextStage(); } }