Exemple #1
0
 protected void AddDebugMessage(string msg, params object[] args)
 {
     if (UI_Control)
     {
         TCAGui.AddDebugMessage(msg, args);
     }
 }
Exemple #2
0
 protected void ClearStatus()
 {
     if (UI_Control)
     {
         TCAGui.ClearStatus();
     }
 }
Exemple #3
0
 protected void Status(double seconds, ColorSetting color, string msg, params object[] args)
 {
     if (UI_Control)
     {
         TCAGui.Status(seconds, color, msg, args);
     }
 }
Exemple #4
0
 protected void ClearStatus()
 {
     if (VSL.IsActiveVessel)
     {
         TCAGui.ClearStatus();
     }
 }
Exemple #5
0
 protected override void OnLand()
 {
     MOD.UseBrakes = MOD.UseChutes = false;
     if (!TrajectoryCalculator.setp_by_step_computation)
     {
         if (VSL.LandedOrSplashed)
         {
             CFG.BlockThrottle = true;
         }
         if (MOD.stage == BallisticJump.Stage.Wait)
         {
             TCAGui.ClearStatus();
         }
         if (delay.TimePassed && MapView.MapIsEnabled)
         {
             MapView.ExitMapView();
         }
         if (CFG.Target)
         {
             var target = CFG.Target.GetTransform();
             FlightCameraOverride.Target(FlightCameraOverride.Mode.LookFromTo,
                                         VSL.vessel.vesselTransform, target, 10,
                                         target != FlightCameraOverride.target);
         }
     }
 }
Exemple #6
0
 void init()
 {
     if (!TCA_Active)
     {
         return;
     }
     updateCFG();
     VSL = new VesselWrapper(this);
     EnableTCA(VSL.Engines.All.Count > 0 ||
               VSL.Engines.RCS.Count > 0 ||
               VSL.Torque.Wheels.Count > 0);
     if (!TCA_Active)
     {
         VSL = null; return;
     }
     VSL.Init();
     TCAModulesDatabase.InitModules(this);
     VSL.ConnectAutopilotOutput();//should follow module initialization
     vessel.OnPreAutopilotUpdate  += OnPreAutopilotUpdate;
     vessel.OnPostAutopilotUpdate += OnPostAutopilotUpdate;
     TCAGui.Reinitialize(this);
     StartCoroutine(updateUnpackDistance());
     Actions["onActionUpdate"].active = true;
     Actions["ToggleTCA"].actionGroup = CFG.ActionGroup;
     CFG.Resume(this);
 }
Exemple #7
0
 protected void Status(double seconds, string color, string msg, params object[] args)
 {
     if (VSL.IsActiveVessel)
     {
         TCAGui.Status(seconds, color, msg, args);
     }
 }
Exemple #8
0
        void ClearFrameState()
        {
            VSL.ClearFrameState();
            AllModules.ForEach(m => m.ClearFrameState());
#if DEBUG
            if (VSL.IsActiveVessel)
            {
                TCAGui.ClearDebugMessage();
            }
#endif
        }
 protected override void OnLand()
 {
     MOD.UseBrakes = MOD.UseChutes = true;
     if (!TrajectoryCalculator.setp_by_step_computation)
     {
         if (MOD.stage == DeorbitAutopilot.Stage.Wait)
         {
             TCAGui.ClearStatus();
         }
         if (TimeWarp.CurrentRateIndex == 0 &&
             VSL.OnPlanetParams.ParachutesActive && VSL.vessel.srfSpeed < 50 && VSL.Altitude > 100)
         {
             TimeWarp.SetRate(3, false, false);
         }
         else if (TimeWarp.CurrentRateIndex > 0 && VSL.Altitude < 100)
         {
             TimeWarp.SetRate(0, false);
         }
         if (MOD.landing_stage == LandingTrajectoryAutopilot.LandingStage.None &&
             (MOD.stage < DeorbitAutopilot.Stage.Correct || MOD.stage == DeorbitAutopilot.Stage.Wait))
         {
             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 (!MapView.MapIsEnabled)
             {
                 MapView.EnterMapView();
             }
         }
         else
         {
             if (MapView.MapIsEnabled)
             {
                 delay.Restart();
                 MapView.ExitMapView();
             }
             if (delay.TimePassed && CFG.Target)
             {
                 var target = CFG.Target.GetTransform();
                 if (target != null)
                 {
                     FlightCameraOverride.Target(FlightCameraOverride.Mode.LookFromTo,
                                                 VSL.vessel.vesselTransform, target, 10,
                                                 target != FlightCameraOverride.target);
                 }
             }
         }
     }
 }
 static void onToolbarToggle(ClickEvent e)
 {
     if (TCA != null)
     {
         TCAGui.ToggleWithButton(TCAButton);
     }
     else if (HighLogic.LoadedSceneIsEditor && TCAGuiEditor.Available)
     {
         TCAGuiEditor.ToggleWithButton(TCAButton);
     }
     else
     {
         TCAManual.ToggleWithButton(TCAButton);
     }
 }
 static void onToolbarToggle(ClickEvent e)
 {
     if (TCA != null)
     {
         TCAGui.Toggle();
     }
     else if (HighLogic.LoadedSceneIsEditor && EnginesProfileEditor.Available)
     {
         EnginesProfileEditor.Toggle();
     }
     else
     {
         TCAManual.Toggle();
     }
 }
Exemple #12
0
 protected override void onLeftClick()
 {
     if (TCA != null)
     {
         TCAGui.ToggleWithButton(ALButton);
     }
     else if (HighLogic.LoadedSceneIsEditor && TCAGuiEditor.Available)
     {
         TCAGuiEditor.ToggleWithButton(ALButton);
     }
     else
     {
         TCAManual.ToggleWithButton(ALButton);
     }
 }
 void init()
 {
     if (!enabled)
     {
         return;
     }
     updateCFG();
     VSL = new VesselWrapper(this);
     enable_module(VSL.Engines.All.Count > 0 || VSL.Engines.RCS.Count > 0);
     if (!enabled)
     {
         VSL = null; return;
     }
     VSL.Init();
     TCAModulesDatabase.InitModules(this);
     VSL.ConnectAutopilotOutput();            //should follow module initialization
     TCAGui.AttachTCA(this);
     StartCoroutine(updateUnpackDistance());
     Actions["onActionUpdate"].active = true;
     Actions["ToggleTCA"].actionGroup = CFG.ActionGroup;
     CFG.Resume(this);
 }
        IEnumerator <YieldInstruction> measure_area_with_brakes_and_run(Callback action)
        {
            var brakes = VSL.vessel.ActionGroups[KSPActionGroup.Brakes];

            VSL.BrakesOn();
            brakes_measured_timer.Reset();
            AreaWithBrakes = BoundsSideAreas.MinComponentF();
            while (!brakes_measured_timer.TimePassed)
            {
                TCAGui.Status(0.1, "Testing aero-brakes...");
                var min_area = BoundsSideAreas.MinComponentF();
                if (min_area > AreaWithBrakes)
                {
                    AreaWithBrakes = min_area;
                    brakes_measured_timer.Reset();
                }
                yield return(null);
            }
            if (!brakes)
            {
                VSL.BrakesOn(false);
            }
            action();
        }
 private void clearGUIStatus()
 {
     TCAGui.ClearStatus();
     unlockControls();
 }
Exemple #16
0
 void clearGUIStatus() => TCAGui.ClearStatus();
        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);
        }
        public override bool Update(System.Random RND)
        {
            Status = string.Format("{0}: {1}", save, stage.ToString().Replace("_", " "));
            LogStageChange();
            switch (stage)
            {
            case Stage.LOAD:
                level_loaded = false;
                save         = saves[save_i];
                if (!ScenarioTester.LoadGame(save))
                {
                    Utils.Message("Unable to load savegame: {0}", save);
                    return(false);
                }
                save_i = (save_i + 1) % saves.Length;
                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 (GetREN())
                    {
                        stage = Stage.CREATE_TARGET;
                    }
                    else
                    {
                        Utils.Message("No Rendezvous Autopilot installed on the active vessel");
                        return(false);
                    }
                    TCAGui.ShowInstance(true);
                    TCAGui.Instance.ActiveTab = TCAGui.Instance.ORB;
                    ResetFlightCamera();
                }
                break;

            case Stage.CREATE_TARGET:
                if (target == null)
                {
                    if (!CreateAsteriod(RND))
                    {
                        return(false);
                    }
                    CheatOptions.InfinitePropellant  = false;
                    CheatOptions.InfiniteElectricity = true;
                    CFG.AP2.XOn(Autopilot2.Rendezvous);
                    break;
                }
                if (CFG.AP2[Autopilot2.Rendezvous])
                {
                    MapView.EnterMapView();
                    VSL.vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, true);
                    REN.mode = RendezvousAutopilot.Mode.TimeToTarget;
                    stage    = Stage.RENDEZVOUS;
                }
                break;

            case Stage.RENDEZVOUS:
                CFG.WarpToNode = true;
                if (CFG.AP2[Autopilot2.Rendezvous])
                {
                    if (VSL.Engines.NoActiveEngines && !VSL.Engines.HaveNextStageEngines)
                    {
                        Utils.Message("Out of fuel");
                        CFG.AP2.XOff();
                        stage = Stage.FINISH;
                        delay.Reset();
                        break;
                    }
                    if (target.vesselRef != null && target.vesselRef.loaded)
                    {
                        FlightCameraOverride.Target(FlightCameraOverride.Mode.LookFromTo, VSL.vessel.transform, target.vesselRef.transform, 10);
                    }
                    else if (VSL.LandedOrSplashed && VSL.Info.Countdown > 5 ||
                             REN.stage == RendezvousAutopilot.Stage.ToOrbit &&
                             REN.VesselOrbit.ApR > REN.VesselOrbit.MinPeR() ||
                             REN.stage >= RendezvousAutopilot.Stage.ComputeRendezvou &&
                             REN.stage < RendezvousAutopilot.Stage.MatchOrbits)
                    {
                        if (!TrajectoryCalculator.setp_by_step_computation)
                        {
                            if (!MapView.MapIsEnabled)
                            {
                                MapView.EnterMapView();
                            }
                            RotateMapView();
                        }
                    }
                    else
                    {
                        if (MapView.MapIsEnabled)
                        {
                            MapView.ExitMapView();
                            ResetFlightCamera();
                        }
                        FlightCameraOverride.AnchorForSeconds(FlightCameraOverride.Mode.OrbitAround, VSL.vessel.transform, 1);
                    }
                    break;
                }
                CFG.AP2.XOff();
                stage = Stage.FINISH;
                delay.Reset();
                break;

            case Stage.FINISH:
                if (!delay.TimePassed)
                {
                    break;
                }
                Log("Done.");
                CleanupTarget();
                stage = Stage.LOAD;
                break;
            }
            return(true);
        }