Ejemplo n.º 1
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);
         }
     }
 }
 public override bool Update(System.Random RND)
 {
     CFG.WarpToNode = true;
     LogStageChange();
     if (target == null)
     {
         Status = "New Target";
         if (!CreateAsteriod(RND))
         {
             return(false);
         }
         CheatOptions.InfinitePropellant = true;
         CFG.AP2.XOn(Autopilot2.Rendezvous);
         MapView.EnterMapView();
         Log("Target: {}", target.vesselName);
         return(true);
     }
     if (VSL == null || VSL.vessel == null ||
         VSL.vessel.state == Vessel.State.DEAD)
     {
         if (!delay.TimePassed)
         {
             return(true);
         }
         LogFlightLog("Vessel was destroyed:");
         Log("Done.");
         return(false);
     }
     if (CFG.AP2[Autopilot2.Rendezvous])
     {
         Status = "Working...";
         if (REN.stage >= RendezvousAutopilot.Stage.MatchOrbits && MapView.MapIsEnabled)
         {
             MapView.ExitMapView();
         }
         if (target.vesselRef != null && target.vesselRef.loaded)
         {
             FlightCameraOverride.Target(FlightCameraOverride.Mode.LookFromTo, VSL.vessel.transform, target.vesselRef.transform, 10);
         }
         delay.Reset();
         return(true);
     }
     if (CFG.AP2)
     {
         FlightCameraOverride.AnchorForSeconds(FlightCameraOverride.Mode.OrbitAround, VSL.vessel.transform, delay.Period);
         CFG.AP2.XOff();
     }
     Status = "Waiting for next iteration";
     if (delay.TimePassed)
     {
         FlightCameraOverride.Deactivate();
         CleanupTarget();
         Log("Done.");
     }
     return(true);
 }
 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);
                 }
             }
         }
     }
 }
        public override bool Update(System.Random RND)
        {
            Status = stage.ToString().Replace("_", " ");
            switch (stage)
            {
            case Stage.LOAD:
                level_loaded = false;
                ScenarioTester.LoadGame("REN ToOrbit");
                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);
                    }
                }
                break;

            case Stage.CREATE_TARGET:
                if (target == null)
                {
                    if (!CreateAsteriod(RND))
                    {
                        return(false);
                    }
                    CheatOptions.InfinitePropellant  = false;
                    CheatOptions.InfiniteElectricity = true;
                    VSL.Engines.ActivateEnginesAndRun(() => 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 (!TrajectoryCalculator.setp_by_step_computation)
                    {
                        if (VSL.LandedOrSplashed && VSL.Info.Countdown > 5 ||
                            REN.stage >= RendezvousAutopilot.Stage.ComputeRendezvou &&
                            REN.stage < RendezvousAutopilot.Stage.MatchOrbits)
                        {
                            if (!MapView.MapIsEnabled)
                            {
                                MapView.EnterMapView();
                            }
                        }
                        else if (MapView.MapIsEnabled)
                        {
                            MapView.ExitMapView();
                        }
                    }
                    if (target.vesselRef != null && target.vesselRef.loaded)
                    {
                        FlightCameraOverride.Target(FlightCameraOverride.Mode.LookFromTo, VSL.vessel.transform, target.vesselRef.transform, 10);
                    }
                    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);
        }
        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);
        }
        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);
        }