public void Test(System.Random rnd) { if (tgt_ast == null) { var obt = CreateRandomOrbitNearby(VesselOrbit); var seed = (uint)rnd.Next(); tgt_ast = DiscoverableObjectsUtil.SpawnAsteroid("REN Test " + seed, obt, seed, UntrackedObjectClass.C, 5e5, 1e6); if (tgt_ast.vesselRef != null) { tgt_ast.vesselRef.DiscoveryInfo.SetLevel(DiscoveryLevels.Owned); CheatOptions.InfinitePropellant = true; SetTarget(tgt_ast.vesselRef); CFG.AP2.XOn(Autopilot2.Rendezvous); } return; } if (CFG.AP2[Autopilot2.Rendezvous]) { delay.Reset(); return; } CFG.AP2.XOff(); if (!delay.TimePassed) { return; } if (tgt_ast != null) { if (tgt_ast.vesselRef != null) { tgt_ast.vesselRef.Die(); } tgt_ast = null; } }
public void Test(System.Random rnd = null) { VSL.Info.AddCustopWaypoint(new Coordinates(0,0,0), "Zero"); VSL.Info.AddCustopWaypoint(new Coordinates(90,0,0), "North"); VSL.Info.AddCustopWaypoint(new Coordinates(-90,0,0), "South"); VSL.Info.AddCustopWaypoint(new Coordinates(0,90,0), "90 deg"); VSL.Info.AddCustopWaypoint(new Coordinates(0,180,0), "180 deg"); VSL.Info.AddCustopWaypoint(new Coordinates(0,270,0), "270 deg"); if(CFG.Target == null) { var c = Coordinates.SurfacePoint(rnd.NextDouble()*180-90, //30+60, //5+85, rnd.NextDouble()*360, Body); SetTarget(new WayPoint(c)); CFG.AP2.XOnIfNot(Autopilot2.Deorbit); } if(CFG.AP2[Autopilot2.Deorbit] && !CFG.AP1[Autopilot1.Maneuver]) { delay.Reset(); return; } CFG.AP2.XOff(); if(!delay.TimePassed) return; CFG.Target = null; }
IEnumerable wait_for_ground_contact(string wait_message) { settled_timer.Reset(); while (!settled_timer.RunIf(part.GroundContact && kit_is_settled)) { if (!part.GroundContact) { message_damper.Run(() => Utils.Message(1, "{0} Kit: no ground contact!", kit.Name)); } else if (!kit_is_settled) { message_damper.Run(() => Utils.Message(1, "{0} Kit is moving...", kit.Name)); } else { message_damper.Run(() => Utils.Message(1, "{0} {1:F1}s", wait_message, settled_timer.Remaining)); } yield return(null); } }
public override bool Update(System.Random RND) { Status = stage.ToString().Replace("_", " "); switch (stage) { case Stage.LOAD: level_loaded = false; ScenarioTester.LoadGame(Save); stage = Stage.WAIT_FOR_LEVEL; delay.Reset(); break; case Stage.WAIT_FOR_LEVEL: if (level_loaded && FlightGlobals.ready && FlightGlobals.ActiveVessel != null && !FlightGlobals.ActiveVessel.packed) { if (!delay.TimePassed) { break; } if (!GetTCA()) { Utils.Message("TCA is not installed/enabled on the ship"); return(false); } if (!GetModule()) { Utils.Message("{0} module is not installed on the ship", program); return(false); } VSL.SetTarget(null); Debug.ClearDeveloperConsole(); stage = Stage.CREATE_TARGET; } break; case Stage.CREATE_TARGET: if (CFG.Target == null) { CreateTarget(RND); CheatOptions.InfinitePropellant = false; CheatOptions.InfiniteElectricity = true; Log("Target: {}", CFG.Target); MOD.UseBrakes = true; MOD.UseChutes = true; VSL.Geometry .MeasureAreaWithBrakesAndRun(() => VSL.Engines .ActivateEnginesAndRun(() => CFG.AP2.XOn(program))); break; } if (CFG.AP2[program]) { MapView.EnterMapView(); VSL.vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true); delay.Reset(); stage = Stage.LAND; } break; case Stage.LAND: CFG.WarpToNode = true; if (VSL == null || VSL.vessel == null || VSL.vessel.state == Vessel.State.DEAD) { LogFlightLog("Vessel was destroyed:"); stage = Stage.FINISH; delay.Reset(); break; } if (CFG.AP2[program]) { OnLand(); break; } FlightCameraOverride.AnchorForSeconds(FlightCameraOverride.Mode.OrbitAround, VSL.vessel.transform, delay.Period + 1, true); CFG.AP2.XOff(); stage = Stage.FINISH; delay.Reset(); break; case Stage.FINISH: if (!delay.TimePassed) { break; } Log("Done."); Cleanup(); Setup(); break; } return(true); }
public override bool Update(System.Random RND) { Status = stage.ToString().Replace("_", " "); switch (stage) { case Stage.LOAD: level_loaded = false; ScenarioTester.LoadGame(Save); stage = Stage.WAIT_FOR_LEVEL; delay.Reset(); break; case Stage.WAIT_FOR_LEVEL: if (level_loaded && FlightGlobals.ready && FlightGlobals.ActiveVessel != null && !FlightGlobals.ActiveVessel.packed) { if (!delay.TimePassed) { break; } if (!GetTCA()) { Utils.Message("TCA is not installed/enabled on the ship"); return(false); } if (!GetModule()) { Utils.Message("{0} module is not installed on the ship", typeof(ToOrbitAutopilot).Name); return(false); } VSL.SetTarget(null); Debug.ClearDeveloperConsole(); orbit_set_up = false; stage = Stage.SETUP; } break; case Stage.SETUP: if (!orbit_set_up) { ResetFlightCamera(); TCAGui.ShowInstance(true); TCAGui.Instance.ActiveTab = TCAGui.Instance.ORB; ORB.TargetOrbit.RetrogradeOrbit = RND.NextDouble() > 0.5? true : false; ORB.TargetOrbit.DescendingNode = RND.NextDouble() > 0.5? true : false; ORB.TargetOrbit.UpdateValues(); ORB.TargetOrbit.Inclination.Value = (float)RND.NextDouble() * 90; ORB.TargetOrbit.Inclination.ClampValue(); inclination = ORB.TargetOrbit.Inclination; abs_inclination = (float)ORB.TargetOrbit.TargetInclination; ORB.TargetOrbit.ApA.Value = (float)(ORB.MinR + 1000 + RND.NextDouble() * 500000 - VSL.Body.Radius) / 1000; ORB.TargetOrbit.ApA.ClampValue(); ApA = ORB.TargetOrbit.ApA * 1000; ORB.ShowOptions = true; VSL.vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true); VSL.vessel.ActionGroups.SetGroup(KSPActionGroup.Light, true); CFG.AP2.XOn(Autopilot2.ToOrbit); orbit_set_up = true; Log("TargetOrbit: {}", ORB.TargetOrbit); Log("TargetInclination: {}", ORB.TargetOrbit.TargetInclination); break; } if (CFG.AP2[Autopilot2.ToOrbit]) { delay.Reset(); stage = Stage.TO_ORBIT; } break; case Stage.TO_ORBIT: CFG.WarpToNode = true; if (VSL == null || VSL.vessel == null || VSL.vessel.state == Vessel.State.DEAD) { LogFlightLog("Vessel was destroyed:"); stage = Stage.FINISH; delay.Reset(); break; } if (CFG.AP2[Autopilot2.ToOrbit]) { if (ORB.stage >= ToOrbitAutopilot.Stage.ChangeApA) { if (!MapView.MapIsEnabled) { MapView.EnterMapView(); } RotateMapView(); } else { FlightCameraOverride.AnchorForSeconds(FlightCameraOverride.Mode.OrbitAround, VSL.vessel.transform, 1); } break; } Log("Achived Orbit: {}", VSL.vessel.orbit); var dApA = VSL.vessel.orbit.ApA - ApA; Log("ApA Error: {} m {} %", dApA, dApA / ApA * 100); var dInc = VSL.vessel.orbit.inclination - abs_inclination; Log("Inclination Error: {} deg {} %", dInc, dInc / inclination * 100); CFG.AP2.XOff(); stage = Stage.FINISH; delay.Reset(); break; case Stage.FINISH: if (!delay.TimePassed) { break; } Log("Done."); Cleanup(); Setup(); break; } return(true); }
void DrawMainWindow(int windowID) { //help button if (GUI.Button(new Rect(0, 0f, 20f, 18f), Collapsed? uncollapse_button : collapse_button, Styles.label)) { Collapsed = !Collapsed; draw_main_window = Collapsed; if (Collapsed) { ShowOnHover_fade_in_timer.Reset(); ShowOnHover_fade_out_timer.Reset(); update_collapsed_rect(); } } if (GUI.Button(new Rect(WindowPos.width - 20f, 0f, 20f, 18f), help_button, Styles.label)) { TCAManual.ToggleInstance(); } //vessel switching if (HaveRemoteControl) { if (GUI.Button(new Rect(22, 0f, 20f, 18f), prev_vessel_button, Styles.label)) { switch_vessel(FlightGlobals.Vessels.Next); } if (RemoteControl && GUI.Button(new Rect(44, 0f, 20f, 18f), active_vessel_button, Styles.label)) { onVesselChange(ActiveVesselTCA.vessel); } if (RemoteControl && GUI.Button(new Rect(WindowPos.width - 64f, 0f, 20f, 18f), switch_vessel_button, Styles.label)) { FlightGlobals.SetActiveVessel(vessel); } if (GUI.Button(new Rect(WindowPos.width - 42f, 0f, 20f, 18f), next_vessel_button, Styles.label)) { switch_vessel(FlightGlobals.Vessels.Prev); } } if (TCA.IsControllable) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //tca toggle var enabled_style = Styles.inactive_button; if (CFG.Enabled) { enabled_style = Styles.enabled_button; } else if (!VSL.LandedOrSplashed && EnabledBlinker.On) { enabled_style = Styles.danger_button; } if (GUILayout.Button("Enabled", enabled_style, GUILayout.Width(70))) { TCA.ToggleTCA(); } #if DEBUG if (GUILayout.Button("ReGlobals", Styles.active_button, GUILayout.ExpandWidth(false))) { Globals.Load(); Styles.ConfigureButtons(); TCA.OnReloadGlobals(); } #endif //squad mode switch if (SQD != null) { SQD.Draw(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(Styles.white, GUILayout.MinHeight(ControlsHeight), GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)); if (ActiveTab != null) { ActiveTab.Draw(); } GUILayout.EndVertical(); tabs_scroll = GUILayout.BeginScrollView(tabs_scroll, Styles.white, GUILayout.ExpandHeight(true), GUILayout.Width(55)); for (int i = 0, AllTabsCount = AllTabs.Count; i < AllTabsCount; i++) { var t = AllTabs[i]; if (t.DrawTabButton(t == ActiveTab)) { ActiveTab = t; CFG.ActiveTab = i; } } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); } else { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); VSL.Info.Draw(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Label("Vessel is Uncontrollable", Styles.label, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.EndVertical(); } TooltipsAndDragWindow(); }