Exemplo n.º 1
0
 private void StopSimulationAndRevert()
 {
     sim.SetSimulation(false);
     if (_status != SimVesselStatus.Launched)
     {
         return;
     }
     if (FlightDriver.PreLaunchState == null)
     {
         var configNode = GamePersistence.LoadSFSFile("simulation", HighLogic.SaveFolder);
         if (configNode != null && HighLogic.CurrentGame != null)
         {
             var game = GamePersistence.LoadGameCfg(configNode, "simulation", true, false);
             FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
             _status = SimVesselStatus.Waiting;
             Debug.Log($"[QuickIronMan]({name}) Revert to save");
             return;
         }
         _status = SimVesselStatus.Launched;
         Debug.Log($"[QuickIronMan]({name}) Something seems wrong, no simulation save, can't return before simulation start");
         return;
     }
     FlightDriver.RevertToLaunch();
     Debug.Log($"[QuickIronMan]({name}) Revert to launch");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the simulation with the defined parameters
        /// </summary>
        public void StartSimulation()
        {
            CalculateComplexity(); //make sure it's up to date
            SimuLite.Instance.ActivateSimulation(this);

            setGameUT();
            if (SimType == SimulationType.REGULAR)
            {
                //start new launch on launchpad/runway
                startRegularLaunch();
            }
            else
            {
                //start new launch in spaaaaacccceee
                VesselSpawner.VesselData vessel = makeVessel();
                Guid?id = null;
                if ((id = VesselSpawner.CreateVessel(vessel)) != null)
                {
                    Debug.Log("[SimuLite] Vessel added to world.");
                    //vessel exists, now switch to it
                    FlightDriver.StartAndFocusVessel(HighLogic.CurrentGame, FlightGlobals.Vessels.FindIndex(v => v.id == id));
                }
                else
                {
                    Debug.Log("[SimuLite] Failed to create vessel.");
                }
            }
        }
Exemplo n.º 3
0
 void ShowSaveGameDialog(int id)
 {
     GUILayout.BeginHorizontal();
     GUILayout.Label(Localizer.Format("#autoLOC_417232"), smallText);
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     saveName = GUILayout.TextField(saveName, smallInputText);
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     if (saveName == "")
     {
         GUI.enabled = false;
     }
     if (GUILayout.Button(Localizer.Format("#autoLOC_455877")))
     {
         GamePersistence.SaveGame(saveName, HighLogic.SaveFolder, SaveMode.OVERWRITE);
         showSaveGame = false;
         gamePause    = false;
         FlightDriver.SetPause(false);
     }
     GUI.enabled = true;
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     if (GUILayout.Button(Localizer.Format("autoLOC_455882")))
     {
         showSaveGame = false;
     }
     GUILayout.EndHorizontal();
     GUI.DragWindow();
 }
Exemplo n.º 4
0
        public void Start()
        {
            if (autostart)
            {
                HighLogic.SaveFolder      = save_name;
                DebugToolbar.toolbarShown = true;

                if (mode == "editor")
                {
                    var editor = EditorFacility.VAB;
                    GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
                    if (craft_name != null || craft_name != "")
                    {
                        string path = Paths.joined(KSPUtil.ApplicationRootPath, "saves", save_name, "Ships", "VAB", craft_name + ".craft");
                        EditorDriver.StartAndLoadVessel(path, editor);
                    }
                    else
                    {
                        EditorDriver.StartEditor(editor);
                    }
                }
                else if (mode == "spacecenter")
                {
                    HighLogic.LoadScene(GameScenes.SPACECENTER);
                }
                else if (mode == "flight")
                {
                    FlightDriver.StartAndFocusVessel("quicksave", 1);
                }
            }
        }
        void DisplayTravelBugData(System.Guid vesselID, string vesselName, string keoCacheName, string keoCacheTitle)
        {
            GUILayout.BeginHorizontal();
            GUILayout.TextField(vesselName, GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.TextField(keoCacheName, GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.TextField(keoCacheTitle, GUILayout.Width(175));
            GUILayout.Space(5);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Select", GUILayout.Width(55)))
            {
                visibleTravelBug = false;

                string _saveGame = GamePersistence.SaveGame(SaveGame, HighLogic.SaveFolder, SaveMode.OVERWRITE);

                int _idx = HighLogic.CurrentGame.flightState.protoVessels.FindLastIndex(pv => pv.vesselID == vesselID);
                if (_idx != -1)
                {
                    FlightDriver.StartAndFocusVessel(_saveGame, _idx);
                }
                else
                {
                    //QDebug.Warning("QStart: invalid idx", "QSpaceCenter");
//DestroyThis();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Exemplo n.º 6
0
        public void RevertTo(string editor)
        {
            if (CanRevvertToEditor())
            {
                EditorFacility fac;
                switch (editor.ToUpper())
                {
                case "VAB":
                    fac = EditorFacility.VAB;
                    break;

                case "SPH":
                    fac = EditorFacility.SPH;
                    break;

                default:
                    fac = EditorFacility.None;
                    break;
                }
                FlightDriver.RevertToPrelaunch(fac);
            }
            else
            {
                throw new KOSCommandInvalidHereException("REVERTTO", "When revert is disabled", "When revert is enabled");
            }
        }
Exemplo n.º 7
0
        public void Close()
        {
            if (_activePopup != null)
            {
                _activePopup.Dismiss();
                _activePopup = null;
                Unhide();
            }
            else if (_miniSettings != null)
            {
                // WTF SQUAD?
                _miniSettings.GetType().GetMethod("Dismiss", BindingFlags.NonPublic | BindingFlags.Instance);
            }
            else
            {

                isOpen = false;
                //_display = false;
                InputLockManager.RemoveControlLock("KRASHSimPauseMenu");
                Log.Info("Close:  FlightDriver.SetPause (false)");
                FlightDriver.SetPause(false);
                Log.Info("FlightDriver.Pause: " + FlightDriver.Pause.ToString());

            }
        }
Exemplo n.º 8
0
 private void PerformPostPlacementAction()
 {
     if (HighLogic.CurrentGame.Parameters.CustomParams <WA>().noreload)
     {
         "Suppressed reload of SPACECENTER".Log();
     }
     if (HighLogic.CurrentGame.Parameters.CustomParams <WA>().jumpto)
     {
         var vessel = FindVesselByName(_mainGui.RequestedPlacement.Kerbal.name);
         if (vessel == null)
         {
             $"Unable to jump to vessel - no vessel found".Log();
         }
         else
         {
             $"Loading Flight scene for {vessel.name}".Log();
             FlightDriver.StartAndFocusVessel("persistent", FlightGlobals.Vessels.IndexOf(vessel));
         }
     }
     if (HighLogic.CurrentGame.Parameters.CustomParams <WA>().reload ||
         (!HighLogic.CurrentGame.Parameters.CustomParams <WA>().jumpto&& !HighLogic.CurrentGame.Parameters.CustomParams <WA>().noreload))
     {
         "Reloading SPACECENTER".Log();
         HighLogic.LoadScene(GameScenes.SPACECENTER);
     }
 }
Exemplo n.º 9
0
        public void Start()
        {
            if (!HasRun)
            {
                HighLogic.SaveFolder = "default";
                var game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
                if (game != null && game.flightState != null && game.compatible)
                {
                    HighLogic.CurrentGame = game;
                    HighLogic.CurrentGame.Load();

                    // Get the vessel index of the first vessel
                    bool foundVessel = false;
                    int  vesselIdx   = 0;
                    foreach (var vessel in game.flightState.protoVessels)
                    {
                        if (vessel.vesselType != VesselType.SpaceObject)
                        {
                            foundVessel = true;
                            break;
                        }
                        vesselIdx++;
                    }
                    if (!foundVessel)
                    {
                        return;
                    }

                    // Load the vessel
                    FlightDriver.StartAndFocusVessel(game, vesselIdx);
                    HasRun = true;
                }
            }
        }
Exemplo n.º 10
0
        public static void JumpToVessel(Vessel v)
        {
            string _saveGame = GamePersistence.SaveGame("Goto_" + version.ToString(), HighLogic.SaveFolder, SaveMode.OVERWRITE);

            // Keep until 3 backups of Goto
            if (version++ > 3)
            {
                version = 0;
            }

            if (Lib.IsFlight())
            {
                FlightGlobals.SetActiveVessel(v);
            }
            else
            {
                int _idx = HighLogic.CurrentGame.flightState.protoVessels.FindLastIndex(pv => pv.vesselID == v.id);

                if (_idx != -1)
                {
                    FlightDriver.StartAndFocusVessel(_saveGame, _idx);
                }
                else
                {
                    Lib.Log("Invalid vessel Id:" + _idx);
                }
            }
        }
Exemplo n.º 11
0
 public void LastVessel()
 {
     SavedGoTo = GoTo.None;
     if (CanLastVessel)
     {
         int   _index      = -1;
         QData _lastVessel = LastVesselLastIndex(out _index);
         if (_lastVessel != null)
         {
             int _idx = _lastVessel.idx;
             if (_idx != -1)
             {
                 ClearSpaceCenter();
                 string _saveGame = GamePersistence.SaveGame(SaveGame, HighLogic.SaveFolder, SaveMode.OVERWRITE);
                 Log(GetText(GoTo.LastVessel));
                 FlightDriver.StartAndFocusVessel(_saveGame, _idx);
                 InputLockManager.ClearControlLocks();
                 LastVessels.RemoveAt(_index);
                 Warning("Remove from the last Vessels: " + _lastVessel.protoVessel.vesselName, "QGoTo");
                 return;
             }
         }
     }
     Warning("You can't " + GetText(GoTo.LastVessel), "QGoTo");
     ScreenMessages.PostScreenMessage("You can't " + GetText(GoTo.LastVessel), 10, ScreenMessageStyle.UPPER_RIGHT);
 }
Exemplo n.º 12
0
        void FixedUpdate()
        {
            if (_abortFixedUpdate)
            {
                return;
            }

            try
            {
                _headingController.Update();
                _bankController.Update();

                _altitudeController.Update();
                _vertSpeedController.Update();
                _speedByPitchController.Update();
                _pitchController.Update();

                if (_singleStep)
                {
                    FlightDriver.SetPause(true, postScreenMessage: false);
                }
            }
            catch
            {
                Debug.Log("WAP: Exception occurred in FixedUpdate; stopping.");
                _abortFixedUpdate = true;
                throw;
            }
        }
Exemplo n.º 13
0
        public void Launch(bool fillFuel = false)
        {
            HighLogic.CurrentGame.editorFacility = GetEditorFacility() == EditorFacilities.VAB ? EditorFacility.VAB : EditorFacility.SPH;

            string tempFile = $"{KSPUtil.ApplicationRootPath}saves/{HighLogic.SaveFolder}/Ships/temp.craft";

            UpdateRFTanks();
            if (fillFuel)
            {
                FillUnlockedFuelTanks();
            }
            ShipNode.Save(tempFile);
            string launchSite = LaunchSite;

            if (launchSite == "LaunchPad")
            {
                KCT_LaunchPad pad = null;
                if (LaunchSiteID >= 0)
                {
                    pad = KCTGameStates.ActiveKSC.LaunchPads[LaunchSiteID];
                }
                else
                {
                    pad = KCTGameStates.ActiveKSC.ActiveLPInstance;
                }

                launchSite = pad.launchSiteName;
            }
            FlightDriver.StartWithNewLaunch(tempFile, Flag, launchSite, new VesselCrewManifest());
            if (KCTGameStates.AirlaunchParams != null)
            {
                KCTGameStates.AirlaunchParams.KSPVesselId = null;
            }
        }
Exemplo n.º 14
0
    public void Start()
    {
        if (first)
        {
            first = false;
            HighLogic.SaveFolder = "SCANsat Testing";
            var game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
            if (game != null && game.flightState != null && game.compatible)
            {
                List <ProtoVessel> allVessels = game.flightState.protoVessels;
                int suitableVessel            = 0;

                for (vId = 0; vId < allVessels.Count; vId++)
                {
                    switch (allVessels [vId].vesselType)
                    {
                    case VesselType.SpaceObject:    continue;                              // asteroids

                    case VesselType.Unknown:        continue;                              // asteroids in facepaint

                    default:                                        suitableVessel = vId;
                        break;                                                                         // this one will do
                    }

                    /* If you want a more stringent filter than
                     *   "vessel is not inert ball of space dirt", then you
                     *   will want to do it here.
                     */
                }
                FlightDriver.StartAndFocusVessel(game, suitableVessel);
            }
        }
    }
Exemplo n.º 15
0
        public void RevertTo(StringValue editor)
        {
            if (CanRevvertToEditor())
            {
                EditorFacility fac;
                switch (editor.ToUpper())
                {
                case "VAB":
                    fac = EditorFacility.VAB;
                    break;

                case "SPH":
                    fac = EditorFacility.SPH;
                    break;

                default:
                    fac = EditorFacility.None;
                    break;
                }
                shared.Cpu.GetCurrentOpcode().AbortProgram = true;
                FlightDriver.RevertToPrelaunch(fac);
            }
            else
            {
                throw new KOSCommandInvalidHereException(LineCol.Unknown(), "REVERTTO", "When revert is disabled", "When revert is enabled");
            }
        }
Exemplo n.º 16
0
        private void OnCraftLaunch()
        {
            var game     = GamePersistence.LoadGame(FlightDriver.StateFileToLoad, HighLogic.SaveFolder, true, true);
            var vesselid = game.flightState.protoVessels.FindIndex(v => v.vesselID.Equals(Vesselid));
            var vessel   = game.flightState.protoVessels[vesselid];

            foreach (var crewMember in vessel.GetVesselCrew())
            {
                var part = EditorLogic.fetch.ship.parts.Find(p => p.protoModuleCrew.Count < p.CrewCapacity);
                if (part == null)
                {
                    Debug.LogWarning("We dit not had enough space for this kerbal");
                }
                else
                {
                    part.AddCrewmemberAt(crewMember, part.protoModuleCrew.Count);
                }
            }

            var newVessel = GetVesselFromShipConstruct(EditorLogic.fetch.ship, vessel, game);

            vessel.protoPartSnapshots = newVessel.protoPartSnapshots;

            GamePersistence.SaveGame(game, FlightDriver.StateFileToLoad, HighLogic.SaveFolder, SaveMode.OVERWRITE);
            FlightDriver.StartAndFocusVessel(game, vesselid);
            Debug.Log("Editing Vessel and switching to it");
        }
Exemplo n.º 17
0
        public void Launch(bool fillFuel = false)
        {
            if (GetEditorFacility() == EditorFacilities.VAB)
            {
                HighLogic.CurrentGame.editorFacility = EditorFacility.VAB;
            }
            else
            {
                HighLogic.CurrentGame.editorFacility = EditorFacility.SPH;
            }

            string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft";

            UpdateRFTanks();
            if (fillFuel)
            {
                FillUnlockedFuelTanks();
            }
            shipNode.Save(tempFile);
            FlightDriver.StartWithNewLaunch(tempFile, flag, launchSite, new VesselCrewManifest());
            KCT_GameStates.LaunchFromTS = false;
            if (KCT_GameStates.AirlaunchParams != null)
            {
                KCT_GameStates.AirlaunchParams.KSPVesselId = null;
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets called when the spacecenter scene was loaded
        /// </summary>
        void SceneLoaded(GameScenes scene)
        {
            if (scene == GameScenes.MAINMENU)
            {
                return;
            }
            if (scene == GameScenes.SPACECENTER)
            {
                if (SeedParams.activeSet)
                {
                    HighLogic.CurrentGame.Parameters.CustomParams <PlanetaryDiversity>().active = true;
                }
                SeedParams.activeSet = false;
                if (!HighLogic.CurrentGame.Parameters.CustomParams <PlanetaryDiversity>().active)
                {
                    return;
                }
                // Should we update the Scaled Space?
                if (scene == GameScenes.SPACECENTER && scaledSpaceUpdate.Count != 0)
                {
                    guiEnabled = true;
                    abort      = false;
                    StartCoroutine(UpdateScaledSpace());

                    FlightDriver.SetPause(true, false);
                    InputLockManager.SetControlLock("planetaryDiversityCache");
                }
            }
        }
 private void PreventUnpause()
 {
     if (dialog != null && Input.GetKeyUp(KeyCode.Escape) && !FlightDriver.Pause)
     {
         FlightDriver.SetPause(true, true);
     }
 }
Exemplo n.º 20
0
        void onGamePause()
        {
            SOS.Log.Info("onGamePause");
            if ((BLSGAvailable && BLSG) || GameSettings.MODIFIER_KEY.GetKey(false))
            {
                return;
            }
            if (HighLogic.LoadedSceneIsFlight && FlightDriver.CanRevert && !gamePause /* && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH */)
            {
                PauseMenu.Close();
                _windowRect = new Rect((Screen.width - WIDTH) / 2, (Screen.height - HEIGHT) / 2, WIDTH, HEIGHT);  //new Rect((float)(Screen.width / 2.0 - 125.0), (float)(Screen.height / 2.0 - 70.0), 250f, 130f);

                gamePause = true;
                FlightDriver.SetPause(true);

                axesChanged    = VesselInfo.Instance.AxesChanged;
                actionsChanged = VesselInfo.Instance.ActionsChanged;
                stagingChanged = VesselInfo.Instance.StagingChanged;
            }
            else
            if (!FlightDriver.CanRevert)
            {
                Log.Info("Revert not possible");
            }
        }
Exemplo n.º 21
0
        void OnWindow(int id)
        {
            GUILayout.BeginVertical();

            _bankController.PaintSmallGui();
            _headingController.PaintSmallGui();
            _pitchController.PaintSmallGui();
            _vertSpeedController.PaintSmallGui();
            _altitudeController.PaintSmallGui();
            _speedByPitchController.PaintSmallGui();

#if DEBUG
            GUILayout.BeginHorizontal();
            _singleStep         = GUILayout.Toggle(_singleStep, "DEBUG: Single step");
            DebugLogger.Verbose = _singleStep;
            if (GUILayout.Button("Go"))
            {
                FlightDriver.SetPause(false, postScreenMessage: false);
            }
            GUILayout.EndHorizontal();
#endif

            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, 1000, 1000));
        }
Exemplo n.º 22
0
 public void Display()
 {
     isOpen   = true;
     _display = true;
     InputLockManager.SetControlLock(ControlTypes.PAUSE, "SimulationPauseMenu");
     FlightDriver.SetPause(true);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Wait until pre-flight checks for new vessel are complete.
        /// </summary>
        /// <param name="config">Config.</param>
        static void WaitForVesselPreFlightChecks(LaunchConfig config)
        {
            if (config.error != null)
            {
                throw new InvalidOperationException(config.error);
            }
            if (!config.preFlightChecksComplete)
            {
                throw new YieldException(new ParameterizedContinuationVoid <LaunchConfig>(WaitForVesselPreFlightChecks, config));
            }
            // Check launch site clear
            var vesselsToRecover = ShipConstruction.FindVesselsLandedAt(HighLogic.CurrentGame.flightState, config.LaunchSite);

            if (vesselsToRecover.Any())
            {
                // Recover existing vessels if the launch site is not clear
                if (!config.Recover)
                {
                    throw new InvalidOperationException("Launch site not clear");
                }
                foreach (var vessel in vesselsToRecover)
                {
                    ShipConstruction.RecoverVesselFromFlight(vessel, HighLogic.CurrentGame.flightState, true);
                }
            }
            // Do the actual launch - passed pre-flight checks, and launch site is clear.
            FlightDriver.StartWithNewLaunch(config.Path, EditorLogic.FlagURL, config.LaunchSite, config.manifest);
            throw new YieldException(new ParameterizedContinuationVoid <int>(WaitForVesselSwitch, 0));
        }
Exemplo n.º 24
0
 public void Start()
 {
     if (!HasRun)
     {
         HighLogic.SaveFolder = "default";
         var game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
         if (game != null && game.flightState != null && game.compatible)
         {
             // Check there is a vessel
             if (game.flightState.protoVessels.Count == 0)
             {
                 return;
             }
             // Get the vessel index of the first non-asteroid
             int vesselIdx = 0;
             foreach (var vessel in game.flightState.protoVessels)
             {
                 if (vessel.vesselType != VesselType.SpaceObject)
                 {
                     break;
                 }
                 vesselIdx++;
             }
             // Load the vessel
             FlightDriver.StartAndFocusVessel(game, vesselIdx);
             HasRun = true;
         }
     }
 }
Exemplo n.º 25
0
        public static void LaunchVessel(string craftDirectory, string name, string launchSite)
        {
            var craft = GetFullCraftDirectory(craftDirectory) + "/" + name + ".craft";
            var crew  = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(ConfigNode.Load(craft));

            FlightDriver.StartWithNewLaunch(craft, EditorLogic.FlagURL, launchSite, crew);
            throw new YieldException(new ParameterizedContinuationVoid <int> (WaitForVesselSwitch, 0));
        }
Exemplo n.º 26
0
 void CloseWindow(bool unpause = false)
 {
     gamePause = false;
     if (unpause)
     {
         FlightDriver.SetPause(false);
     }
 }
Exemplo n.º 27
0
        public void Launch()
        {
            KCT_GameStates.flightSimulated = false;
            string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft";

            shipNode.Save(tempFile);
            FlightDriver.StartWithNewLaunch(tempFile, flag, launchSite, new VesselCrewManifest());
        }
Exemplo n.º 28
0
        public static void LaunchVesselFromSPH(string name)
        {
            var craft = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/SPH/" + name + ".craft";
            var crew  = HighLogic.CurrentGame.CrewRoster.DefaultCrewForVessel(ConfigNode.Load(craft));

            FlightDriver.StartWithNewLaunch(craft, EditorLogic.FlagURL, "Runway", crew);
            throw new YieldException(new ParameterizedContinuationVoid <int> (WaitForVesselSwitch, 0));
        }
Exemplo n.º 29
0
 void doStartAndFocusVessel()
 {
     Log.Info("Save: doStartAndFocusVessel, Calling FlightDriver.StartAndFocusVessel 1");
     FlightDriver.StartAndFocusVessel(gameToLoad, vesselToFocus);
     readyToLoad = false;
     gameToLoad  = null;
     //attach_handlers();
 }
Exemplo n.º 30
0
 public void Display()
 {
     isOpen = true;
     //	_display = true;
     InputLockManager.SetControlLock(ControlTypes.PAUSE, "KRASHSimPauseMenu");
     Log.Info("Display:  FlightDriver.SetPause (true)");
     FlightDriver.SetPause(true);
     Log.Info("FlightDriver.Pause: " + FlightDriver.Pause.ToString());
 }