public override void OnLoad(ConfigNode node) { if (node.CountNodes > 0) // not in prefab { VesselSettings = new VesselSettings(); VesselSettings.Load(node); } }
public static void UpdateVesselSettings(this IList <Part> parts, VesselSettings vesselSettings) { Debug.Log($"[{nameof(AutoAction)}] UpdateVesselSettings"); foreach (ModuleAutoAction module in parts.GetOrAddAutoActionModules()) { module.hasActivated = false; // Storing settings in the first module only module.VesselSettings = vesselSettings; vesselSettings = null; } }
public static VesselSettings GetVesselSettings(this IEnumerable <Part> parts) { Debug.Log($"[{nameof(AutoAction)}] GetVesselSettings"); VesselSettings vesselSettings = parts ?.SelectMany(part => part.Modules.OfType <ModuleAutoAction>()) .Select(module => module.VesselSettings) .OfType <VesselSettings>() .OrderByDescending(s => s.HasNonDefaultValues) .FirstOrDefault(); return(vesselSettings ?? new VesselSettings()); }
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(); } }
IEnumerator <YieldInstruction> ActivateWhenReady() { WaitForFixedUpdate wait = new WaitForFixedUpdate(); while (FlightGlobals.ActiveVessel is null || FlightGlobals.ActiveVessel.HoldPhysics) { yield return(wait); } if (!_hasTriggered) { List <Part> parts = FlightGlobals.ActiveVessel.Parts; bool hasActivated = parts.GetHasActivated(); VesselSettings vesselSettings = parts.GetVesselSettings(); bool isLanded = FlightGlobals.ActiveVessel.Landed; if (_isRollout || isLanded && !hasActivated) { _hasTriggered = true; parts.SetHasActivated(); Activate(vesselSettings); } } }
void SetVesselSettingsFrom(IEnumerable <Part> parts) { _vesselSettings = parts.GetVesselSettings(); _isTrimSectionExpanded = _vesselSettings.HasNonDefaultTrim; _windowRectangle.height = 0; }