Exemplo n.º 1
0
        protected string setWaypoint(string resourceName, GoldStrikeLode lode)
        {
            if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH)
            {
                debugLog("Trying to set waypoint");
                string location = string.Format("Lon: {0:f2} Lat: {1:f2}", this.part.vessel.longitude, this.part.vessel.latitude);

                Waypoint waypoint = new Waypoint();
                waypoint.name          = resourceName + " Lode";
                waypoint.isExplored    = true;
                waypoint.isNavigatable = true;
                waypoint.isOnSurface   = true;
                waypoint.celestialName = this.part.vessel.mainBody.name;
                waypoint.longitude     = this.part.vessel.longitude;
                waypoint.latitude      = this.part.vessel.latitude;
                waypoint.seed          = UnityEngine.Random.Range(0, int.MaxValue);
                waypoint.navigationId  = Guid.NewGuid();

                //Add the waypoint to the custom waypoint scenario
                ScenarioCustomWaypoints.AddWaypoint(waypoint);

                //Our icon is not correct, do a quick remove, reset the icon, and add
                WaypointManager.RemoveWaypoint(waypoint);
                waypoint.id           = WBIPathfinderScenario.kLodeIcon;
                waypoint.nodeCaption1 = location;
                WaypointManager.AddWaypoint(waypoint);

                //Record the waypoint info
                lode.navigationID = waypoint.navigationId.ToString();

                //Save the game
                GamePersistence.SaveGame("quicksave", HighLogic.SaveFolder, SaveMode.BACKUP);

                //Done
                return(waypoint.navigationId.ToString());
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        public static void JumpToVessel(Vessel v, bool skipKerbalism = false)
        {
            string saveGame = GamePersistence.SaveGame("PT_Goto_backup", HighLogic.SaveFolder, SaveMode.OVERWRITE);

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

                if (idx != -1)
                {
                    FlightDriver.StartAndFocusVessel(saveGame, idx);
                }
                else
                {
                    UnityEngine.Debug.Log("Invalid vessel Id:" + idx);
                }
            }
        }
Exemplo n.º 3
0
        private void StartGame()
        {
            //Create new game object for our DMP session.
            HighLogic.CurrentGame = CreateBlankGame();

            //Set the game mode
            SetGameMode();

            //Found in KSP's files. Makes a crapton of sense :)
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
            {
                HighLogic.CurrentGame.Parameters.Difficulty.AllowStockVessels = false;
            }
            HighLogic.CurrentGame.flightState.universalTime = TimeSyncer.fetch.GetUniverseTime();

            //Load DMP stuff
            VesselWorker.fetch.LoadKerbalsIntoGame();
            VesselWorker.fetch.LoadVesselsIntoGame();

            //Load the scenarios from the server
            ScenarioWorker.fetch.LoadScenarioDataIntoGame();

            //Load the missing scenarios as well (Eg, Contracts and stuff for career mode
            ScenarioWorker.fetch.LoadMissingScenarioDataIntoGame();

            //This only makes KSP complain
            HighLogic.CurrentGame.CrewRoster.ValidateAssignments(HighLogic.CurrentGame);
            DarkLog.Debug("Starting " + gameMode + " game...");

            //Control locks will bug out the space centre sceen, so remove them before starting.
            DeleteAllTheControlLocksSoTheSpaceCentreBugGoesAway();

            //.Start() seems to stupidly .Load() somewhere - Let's overwrite it so it loads correctly.
            GamePersistence.SaveGame(HighLogic.CurrentGame, "persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            HighLogic.CurrentGame.Start();
            ChatWorker.fetch.display = true;
            DarkLog.Debug("Started!");
        }
Exemplo n.º 4
0
        public void ResetProspects()
        {
            //Since it costs science, ask for confirmation.
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX)
            {
                float scienceCost = GoldStrikeSettings.ProspectResetCost;

                //Confirmed, pay the science cost.
                if (prospectResetConfirmed)
                {
                    ResearchAndDevelopment.Instance.AddScience(-scienceCost, TransactionReasons.Any);
                }

                else
                {
                    prospectResetConfirmed = true;
                    string message = string.Format("It will cost {0:f2} Science to renew your prospecting chances in this biome. Click to confirm.", scienceCost);
                    ScreenMessages.PostScreenMessage(message, kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
            }

            //Reset the chances
            string biomeName = string.Empty;
            int    planetID  = -1;

            GoldStrikeUtils.GetBiomeAndPlanet(out biomeName, out planetID, this.part.vessel, asteroid);
            GoldStrikeChance chance = WBIPathfinderScenario.Instance.GetGoldStrikeChance(planetID, biomeName);

            chance.chancesRemaining = GoldStrikeSettings.ProspectsPerBiome;

            //Hide the reset button
            Events["ResetProspects"].guiActive          = false;
            Events["ResetProspects"].guiActiveUnfocused = false;

            //Save the game
            GamePersistence.SaveGame("quicksave", HighLogic.SaveFolder, SaveMode.BACKUP);
        }
Exemplo n.º 5
0
/*************************************************************************************************************************/
        void FixedUpdate()
        {
            Game        savegame;
            ProtoVessel temp_proto;
            int         load_vessel;

            if (_SAVE_Kick_To_Main)
            {
                if (delay > 0)
                {
                    delay--;
                }
                else
                {
                    Log.dbg("TrackingStation kick to main");

                    _SAVE_Kick_To_Main = false;
                    write_save_values_to_file();

                    savegame   = GamePersistence.LoadGame("FMRS_main_save", HighLogic.SaveFolder, false, false);
                    temp_proto = savegame.flightState.protoVessels.Find(p => p.vesselID == _SAVE_Main_Vessel);

                    if (temp_proto != null)
                    {
                        for (load_vessel = 0; load_vessel < savegame.flightState.protoVessels.Count && savegame.flightState.protoVessels[load_vessel].vesselID.ToString() != temp_proto.vesselID.ToString(); load_vessel++)
                        {
                            ;
                        }

                        if (load_vessel < savegame.flightState.protoVessels.Count)
                        {
                            FMRS_SAVE_Util.Instance.StartAndFocusVessel(savegame, load_vessel);
                        }
//                        FlightDriver.StartAndFocusVessel(savegame, load_vessel);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called each time the game's GUIs are to be refreshed.
        /// </summary>
        public void OnGUI()
        {
            if (_mainGui?.Display() ?? false)
            {
                _config.SetScreenPosition(_mainGui.GuiCoordinates);
            }

            if (_mainGui?.RequestedPlacement == null)
            {
                return;
            }

            "placing kerbal".Debug();
            WalkAboutKspAccess.PlaceKerbal(_mainGui.RequestedPlacement);
            "Saving game".Log();
            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);

            PerformPostPlacementAction();

            _items.UpdateQueueing(_mainGui.RequestedPlacement.Items);
            _map.UpdateQueuing(_mainGui.RequestedPlacement.Location.LocationName);
            _mainGui.RequestedPlacement = null;
        }
Exemplo n.º 7
0
 void OnLoadDialogPipelineFinished(ConfigNode node)
 {
     HighLogic.CurrentGame = GamePersistence.LoadGameCfg(node, game, true, false);
     if (HighLogic.CurrentGame != null)
     {
         if (GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame))
         {
             if (node != null)
             {
                 GameEvents.onGameStatePostLoad.Fire(node);
             }
             GamePersistence.SaveGame(HighLogic.CurrentGame, save, game, SaveMode.OVERWRITE);
         }
         if (HighLogic.CurrentGame.startScene == GameScenes.FLIGHT)
         {
             AutoSwitchVessel.activeVessel = HighLogic.CurrentGame.flightState.activeVesselIdx;
             AutoSwitchVessel.save         = save;
         }
         HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
         HighLogic.SaveFolder             = game;
         HighLogic.CurrentGame.Start();
     }
 }
Exemplo n.º 8
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

                    case VesselType.EVA: continue;                              //Don't spawn rescue Kerbals

                    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);
                CheatOptions.InfiniteFuel = true;
            }
        }
    }
        public GoldStrikeLode AddLode(ModuleAsteroid asteroid, string resourceName, float abundance)
        {
            int    planetID;
            string biomeName;

            GoldStrikeUtils.GetBiomeAndPlanet(out biomeName, out planetID, null, asteroid);
            GoldStrikeLode lode = new GoldStrikeLode();
            Dictionary <string, GoldStrikeLode> lodeMap = null;
            string planetBiomeKey = planetID.ToString() + biomeName;

            //Setup the new lode
            lode.resourceName = resourceName;
            lode.longitude    = 0;
            lode.lattitude    = 0;
            lode.biome        = biomeName;
            lode.abundance    = abundance;
            lode.planetID     = planetID;

            //Get the lode map
            if (goldStrikeLodes.ContainsKey(planetBiomeKey) == false)
            {
                lodeMap = new Dictionary <string, GoldStrikeLode>();
                goldStrikeLodes.Add(planetBiomeKey, lodeMap);
                debugLog("Added new goldStrikeLode with planetBiomeKey: " + planetBiomeKey);
            }
            lodeMap = goldStrikeLodes[planetBiomeKey];

            //Add the new lode
            lodeMap.Add(asteroid.AsteroidName, lode);
            goldStrikeLodes[planetBiomeKey] = lodeMap;
            debugLog("Added new lode: " + lode.ToString());

            //Save the game
            GamePersistence.SaveGame("quicksave", HighLogic.SaveFolder, SaveMode.BACKUP);

            return(lode);
        }
Exemplo n.º 10
0
        static void onPipelineFinished(ConfigNode node, string saveName, Version originalVersion)
        {
            var game = GamePersistence.LoadGameCfg(node, saveName, true, false);

            if (game != null && game.flightState != null)
            {
                if (game.compatible)
                {
                    GamePersistence.UpdateScenarioModules(game);
                    if (node != null)
                    {
                        GameEvents.onGameStatePostLoad.Fire(node);
                    }
                    if (game.startScene != GameScenes.FLIGHT &&
                        originalVersion >= new Version(0, 24, 0))
                    {
                        GamePersistence.SaveGame(game, "persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                        HighLogic.LoadScene(GameScenes.SPACECENTER);
                        return;
                    }
                }
                FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
            }
        }
Exemplo n.º 11
0
    public void Start()
    {
        //only do it on the first entry to the menu
        if (first)
        {
            first = false;
            HighLogic.SaveFolder = "default";
            Game game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);

            if (game != null && game.flightState != null && game.compatible)
            {
                game.Start();

                /*Int32 FirstVessel;
                 * Boolean blnFoundVessel = false;
                 * for (FirstVessel = 0; FirstVessel < game.flightState.protoVessels.Count; FirstVessel++)
                 * {
                 *  //This logic finds the first non-asteroid vessel
                 *  if (game.flightState.protoVessels[FirstVessel].vesselType != VesselType.SpaceObject &&
                 *      game.flightState.protoVessels[FirstVessel].vesselType != VesselType.Unknown)
                 *  {
                 *      ////////////////////////////////////////////////////
                 *      //PUT ANY OTHER LOGIC YOU WANT IN HERE//
                 *      ////////////////////////////////////////////////////
                 *      blnFoundVessel = true;
                 *      break;
                 *  }
                 * }
                 * if (!blnFoundVessel)
                 *  FirstVessel = 0;
                 * FlightDriver.StartAndFocusVessel(game, FirstVessel);*/
            }

            //CheatOptions.InfiniteFuel = true;
        }
    }
Exemplo n.º 12
0
 //WARNING: Called from NetworkWorker.
 public void StartGame()
 {
     HighLogic.CurrentGame             = new Game();
     HighLogic.CurrentGame.flightState = new FlightState();
     HighLogic.CurrentGame.CrewRoster  = new CrewRoster();
     HighLogic.CurrentGame.scenarios   = new List <ProtoScenarioModule>();
     HighLogic.CurrentGame.startScene  = GameScenes.SPACECENTER;
     HighLogic.CurrentGame.flagURL     = Settings.fetch.selectedFlag;
     HighLogic.CurrentGame.Title       = "DarkMultiPlayer";
     HighLogic.CurrentGame.Parameters.Flight.CanQuickLoad = false;
     HighLogic.SaveFolder = "DarkMultiPlayer";
     HighLogic.CurrentGame.flightState.universalTime = TimeSyncer.fetch.GetUniverseTime();
     SetGameMode();
     ScenarioWorker.fetch.LoadScenarioDataIntoGame();
     AsteroidWorker.fetch.LoadAsteroidScenario();
     VesselWorker.fetch.LoadKerbalsIntoGame();
     VesselWorker.fetch.LoadVesselsIntoGame();
     DarkLog.Debug("Starting " + gameMode + " game...");
     HighLogic.CurrentGame.Start();
     DarkLog.Debug("Started!");
     Planetarium.SetUniversalTime(TimeSyncer.fetch.GetUniverseTime());
     GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
     ChatWorker.fetch.display = true;
 }
Exemplo n.º 13
0
 // Método para deletar os registros no sistema
 public void DeleteData()
 {
     // Acessa o método "DeleteAll" da classe
     GamePersistence.DeleteAll();
 }
Exemplo n.º 14
0
    //public int bestScore;


    // Método para gravar os registros no sistema
    public void SingleUpdate()
    {
        // Acessa o método "SaveData" da classe
        GamePersistence.SaveData(GameController.myPoints);
    }
        void generateSave(bool isUpdate)
        {
            #region PARAMETERS
            GameParameters Params = new GameParameters();
            //FLIGHT
            Params.Flight.CanQuickSave         = true;
            Params.Flight.CanQuickLoad         = true;
            Params.Flight.CanAutoSave          = true;
            Params.Flight.CanUseMap            = true;
            Params.Flight.CanSwitchVesselsNear = true;
            Params.Flight.CanSwitchVesselsFar  = false;
            Params.Flight.CanTimeWarpHigh      = true;
            Params.Flight.CanTimeWarpLow       = true;
            Params.Flight.CanEVA                    = true;
            Params.Flight.CanIVA                    = true;
            Params.Flight.CanBoard                  = true;
            Params.Flight.CanRestart                = false;
            Params.Flight.CanLeaveToEditor          = false;
            Params.Flight.CanLeaveToTrackingStation = false;
            Params.Flight.CanLeaveToSpaceCenter     = true;
            Params.Flight.CanLeaveToMainMenu        = false;

            //EDITOR
            Params.Editor.CanSave               = true;
            Params.Editor.CanLoad               = true;
            Params.Editor.CanStartNew           = true;
            Params.Editor.CanLaunch             = false;
            Params.Editor.CanLeaveToSpaceCenter = true;
            Params.Editor.CanLeaveToMainMenu    = false;

            //TRACKINGSTATION
            Params.TrackingStation.CanFlyVessel          = true;
            Params.TrackingStation.CanAbortVessel        = false;
            Params.TrackingStation.CanLeaveToSpaceCenter = true;
            Params.TrackingStation.CanLeaveToMainMenu    = false;

            //SPACECENTER
            Params.SpaceCenter.CanGoInVAB             = true;
            Params.SpaceCenter.CanGoInSPH             = true;
            Params.SpaceCenter.CanGoInTrackingStation = true;
            Params.SpaceCenter.CanLaunchAtPad         = false;
            Params.SpaceCenter.CanLaunchAtRunway      = false;
            Params.SpaceCenter.CanGoToAdmin           = false;
            Params.SpaceCenter.CanGoToAstronautC      = false;
            Params.SpaceCenter.CanGoToMissionControl  = false;
            Params.SpaceCenter.CanGoToRnD             = false;
            Params.SpaceCenter.CanSelectFlag          = true;
            Params.SpaceCenter.CanLeaveToMainMenu     = true;

            //DIFFICULTY
            Params.Difficulty.AutoHireCrews       = false;
            Params.Difficulty.MissingCrewsRespawn = true;
            Params.Difficulty.BypassEntryPurchaseAfterResearch = true;
            Params.Difficulty.AllowStockVessels        = false;
            Params.Difficulty.IndestructibleFacilities = true;
            Params.Difficulty.ResourceAbundance        = 1;
            Params.Difficulty.ReentryHeatScale         = 1;
            Params.Difficulty.EnableCommNet            = true;

            //CAREER
            Params.Career.StartingFunds         = 20000;
            Params.Career.StartingScience       = 0;
            Params.Career.StartingReputation    = 0;
            Params.Career.FundsGainMultiplier   = 1;
            Params.Career.RepGainMultiplier     = 1;
            Params.Career.ScienceGainMultiplier = 1;
            Params.Career.RepLossMultiplier     = 1;
            Params.Career.RepLossDeclined       = 1;
            Params.Career.FundsLossMultiplier   = 1;

            HighLogic.CurrentGame.Parameters = Params;

            ScenarioUpgradeableFacilities.Instance.CheatFacilities();


            if (!isUpdate)
            {
                Funding.Instance.AddFunds(20000 - Funding.Instance.Funds, TransactionReasons.Cheating);
                ResearchAndDevelopment.Instance.AddScience(-ResearchAndDevelopment.Instance.Science, TransactionReasons.Cheating);
                Reputation.Instance.AddReputation(-Reputation.Instance.reputation, TransactionReasons.Cheating);
startfor:
                for (int i = HighLogic.CurrentGame.CrewRoster.Crew.ToList().Count - 1; i >= 0;)
                {
                    ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.Crew.ToList()[i];
                    HighLogic.CurrentGame.CrewRoster.Remove(crew);
                    goto startfor;
                }
            }
            ResearchAndDevelopment.Instance.CheatTechnology();
            ProgressTracking.Instance.CheatProgression();

            #endregion

            if (!isUpdate)
            {
                FlightGlobals.Vessels.Clear();
            }
            #region spawn stations
            //Kerbin
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\big station.craft", FlightGlobals.fetch.bodies.ElementAt(1), 200000, "Kerbin Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 7.craft", FlightGlobals.fetch.bodies.ElementAt(2), 200000, "Mun Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 2.craft", FlightGlobals.fetch.bodies.ElementAt(3), 100000, "Minmus Station");
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 10.craft", FlightGlobals.fetch.bodies.ElementAt(3), 15000, "Minmus Pirate Station");

            //Duna
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 4.craft", FlightGlobals.fetch.bodies.ElementAt(6), 200000, "Duna Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 3.craft", FlightGlobals.fetch.bodies.ElementAt(7), 200000, "Ike Station");

            //Eve
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 9.craft", FlightGlobals.fetch.bodies.ElementAt(5), 300000, "Eve Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 4.craft", FlightGlobals.fetch.bodies.ElementAt(13), 50000, "Gilly Station");
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 2.craft", FlightGlobals.fetch.bodies.ElementAt(13), 15000, "Gilly Pirate Station");

            //Moho
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 1.craft", FlightGlobals.fetch.bodies.ElementAt(4), 200000, "Moho Pirate Station");

            //Dres
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\big pirate station.craft", FlightGlobals.fetch.bodies.ElementAt(15), 200000, "Dres Pirate Station");

            //Eeloo
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 8_1.craft", FlightGlobals.fetch.bodies.ElementAt(16), 150000, "Eeloo Station");

            //Jool
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Space station 2_0.craft", FlightGlobals.fetch.bodies.ElementAt(8), 55000000, "Jool Station");
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Pirate Station 2_0.craft", FlightGlobals.fetch.bodies.ElementAt(8), 3500000, "Jool Pirate Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 6.craft", FlightGlobals.fetch.bodies.ElementAt(9), 300000, "Laythe Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 3.craft", FlightGlobals.fetch.bodies.ElementAt(10), 300000, "Vall Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 5.craft", FlightGlobals.fetch.bodies.ElementAt(12), 400000, "Tylo Station");
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 1.craft", FlightGlobals.fetch.bodies.ElementAt(12), 1000000, "Tylo Pirate Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Medium Outpost 5.craft", FlightGlobals.fetch.bodies.ElementAt(11), 100000, "Bop Pirate Station");

            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Small Outpost 1.craft", FlightGlobals.fetch.bodies.ElementAt(14), 75000, "Pol Station");

            //sun
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Kerbol observation station.craft", FlightGlobals.fetch.bodies.ElementAt(0), 600000000, "Kerbol observation station");
            SpawnVessel("GameData\\KerbalKommander\\Assets\\stations\\Deep space research station 1.craft", FlightGlobals.fetch.bodies.ElementAt(0), 150000000000, "Terminus");

            #endregion

            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            foreach (Vessel vessel in FlightGlobals.Vessels)
            {
                if (isUpdate)
                {
                    if (vessel.vesselType == VesselType.EVA || vessel.vesselType == VesselType.Ship)
                    {
                        FlightDriver.StartAndFocusVessel("persistent", FlightGlobals.Vessels.IndexOf(vessel));
                        GUIUpdate = true;
                        break;
                    }
                }
                else
                {
                    if (vessel.vesselName == "Kerbin Station")
                    {
                        FlightDriver.StartAndFocusVessel("persistent", FlightGlobals.Vessels.IndexOf(vessel));
                        break;
                    }
                }
            }
        }
Exemplo n.º 16
0
        private Boolean JumpToVessel(Vessel vTarget)
        {
            Boolean blnJumped = true;

            if (KACWorkerGameState.CurrentGUIScene == GameScenes.FLIGHT)
            {
                LogFormatted_DebugOnly("Switching in Scene");
                if (KACUtils.BackupSaves() || !KerbalAlarmClock.settings.CancelFlightModeJumpOnBackupFailure)
                {
                    vesselToJumpTo = vTarget;
                }

                //if(FlightGlobals.SetActiveVessel(vTarget))
                //{
                //    FlightInputHandler.SetNeutralControls();
                //}
                else
                {
                    LogFormatted("Not Switching - unable to backup saves");
                    ShowBackupFailedWindow("Not Switching - unable to backup saves");
                    blnJumped = false;
                }
            }
            else
            {
                LogFormatted_DebugOnly("Switching in by Save");

                int intVesselidx = getVesselIdx(vTarget);
                if (intVesselidx < 0)
                {
                    LogFormatted("Couldn't find the index for the vessel {0}({1})", vTarget.vesselName, vTarget.id.ToString());
                    ShowBackupFailedWindow("Not Switching - unable to find vessel index");
                    blnJumped = false;
                }
                else
                {
                    try
                    {
                        if (KACUtils.BackupSaves())
                        {
                            String strret  = GamePersistence.SaveGame("KACJumpToShip", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                            Game   tmpGame = GamePersistence.LoadGame(strret, HighLogic.SaveFolder, false, false);
                            FlightDriver.StartAndFocusVessel(tmpGame, intVesselidx);
                            //if (tmpAlarm.PauseGame)
                            //FlightDriver.SetPause(false);
                            //tmpGame.Start();
                        }
                        else
                        {
                            LogFormatted("Not Switching - unable to backup saves");
                            ShowBackupFailedWindow("Not Switching - unable to backup saves");
                            blnJumped = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        LogFormatted("Unable to save/load for jump to ship: {0}", ex.Message);
                        ShowBackupFailedWindow("Not Switching - failed in loading new position");
                        blnJumped = false;
                    }
                }
            }
            return(blnJumped);
        }
Exemplo n.º 17
0
 public static void SetLastMissionData(this ProtoCrewMember kerbal, double newMissionDuration, double currentTime)
 {
     CrewQueueRoster.Instance.GetExtForKerbal(kerbal).LastMissionDuration = newMissionDuration;
     CrewQueueRoster.Instance.GetExtForKerbal(kerbal).LastMissionEndTime  = currentTime;
     GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
 }
Exemplo n.º 18
0
        protected void drawEmptyBay()
        {
            ShipConstruct ship     = EditorLogic.fetch.ship;
            Color         oldColor = GUI.backgroundColor;

            if (ship.parts.Count > 0)
            {
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                //If the new integration button is pressed then record the info we need
                //to add editor bay data to the database.
                GUI.backgroundColor = XKCDColors.ColorTranslator.FromHtml("#97f5ff");
                if (GUILayout.Button(newIcon, buttonOptions))
                {
                    //Set up a new vehicle integration
                    editorBayItem.Clear();
                    editorBayItem.vesselName = ship.shipName;

                    //Generate snapshot of the vessel
                    ConfigNode shipNode = ship.SaveShip();
                    editorBayItem.vesselFilePath = savesFolder + ship.shipName + isVAB + editorBayItem.editorBayID + ".cfg";
                    debugLog("Vessel file: " + editorBayItem.vesselFilePath);
                    if (File.Exists(editorBayItem.vesselFilePath))
                    {
                        File.Delete(editorBayItem.vesselFilePath);
                    }
                    shipNode.Save(editorBayItem.vesselFilePath);
                    editorBayItem.vesselThumbnail = null;

                    float dryCost, fuelCost;
                    ship.GetShipCosts(out dryCost, out fuelCost);
                    editorBayItem.rushJobCost = dryCost;
                    calculateReliability(editorBayItem, ship);
                    editorBayItem.totalVesselParts = ship.parts.Count;

                    //Generate thumbnail
                    ShipConstruction.CaptureThumbnail(ship, "thumbs", thumbnailBaseFileName + ship.shipName);

                    //Generate the full path to the thumbnail and add it to the editorBayItem
                    editorBayItem.thumbnailPath = thumbnailFullPath + ship.shipName + ".png";

                    //Add workers
                    int availableWorkers = BARISScenario.Instance.GetAvailableWorkers(isVAB);
                    if (availableWorkers >= BARISScenario.MaxWorkersPerBay)
                    {
                        editorBayItem.workerCount = BARISScenario.MaxWorkersPerBay;
                        availableWorkers         -= editorBayItem.workerCount;
                        BARISScenario.Instance.SetAvailableWorkers(availableWorkers, isVAB);
                    }
                    else
                    {
                        editorBayItem.workerCount = availableWorkers;
                        BARISScenario.Instance.SetAvailableWorkers(0, isVAB);
                    }

                    //Generate a KAC alarm (if KAC is installed)
                    setKACAlarm(editorBayItem);

                    //Save the new item
                    BARISScenario.Instance.SetEditorBay(editorBayItem);
                    GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.BACKUP);

                    //Cleanup
                    debugLog(editorBayItem.ToString());
                }
                newIcon             = selectNewIcon();
                GUI.backgroundColor = oldColor;

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();

                //Tooltip
                if (string.IsNullOrEmpty(newToolTip) == false)
                {
                    GUILayout.Label(newToolTip);
                }
                else
                {
                    GUILayout.Label(" ");
                }
            }
        }
Exemplo n.º 19
0
        public void gameSceneEvent(GameScenes scene)
        {
            const string logBlockName = nameof(KCTEvents) + "." + nameof(gameSceneEvent);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                if (scene == GameScenes.MAINMENU)
                {
                    GameStates.reset();
                    GameStates.firstStart = false;
                    InputLockManager.RemoveControlLock("KCTLaunchLock");
                    GameStates.activeKSCName = "Stock";
                    GameStates.ActiveKSC     = new SpaceCenterConstruction("Stock");
                    GameStates.KSCs          = new List <SpaceCenterConstruction>()
                    {
                        GameStates.ActiveKSC
                    };
                    GameStates.LastKnownTechCount = 0;

                    GameStates.PermanentModAddedUpgradesButReallyWaitForTheAPI = 0;
                    GameStates.TemporaryModAddedUpgradesButReallyWaitForTheAPI = 0;

                    if (KCT_PresetManager.Instance != null)
                    {
                        KCT_PresetManager.Instance.ClearPresets();
                        KCT_PresetManager.Instance = null;
                    }

                    return;
                }

                GameStates.MiscellaneousTempUpgrades = 0;

                /*if (HighLogic.LoadedScene == GameScenes.MAINMENU)
                 * {
                 *  if (scene == GameScenes.SPACECENTER)
                 *  {
                 *      KCT_PresetManager.Instance.FindPresetFiles();
                 *      KCT_PresetManager.Instance.LoadPresets();
                 *  }
                 * }*/

                if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                {
                    return;
                }
                List <GameScenes> validScenes = new List <GameScenes> {
                    GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR
                };
                if (validScenes.Contains(scene))
                {
                    TechDisableEventFinal();
                }

                if (HighLogic.LoadedScene == scene && scene == GameScenes.EDITOR) //Fix for null reference when using new or load buttons in editor
                {
                    GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                }

                if (HighLogic.LoadedSceneIsEditor)
                {
                    EditorLogic.fetch.Unlock("KCTEditorMouseLock");
                }
            }
        }
Exemplo n.º 20
0
        private static void DrawBLPlusWindow(int windowID)
        {
            //bLPlusPosition.xMax = buildListWindowPosition.xMin;
            //bLPlusPosition.width = 100;
            bLPlusPosition.yMin   = buildListWindowPosition.yMin;
            bLPlusPosition.height = 225;
            //bLPlusPosition.height = bLPlusPosition.yMax - bLPlusPosition.yMin;
            KCT_BuildListVessel b = KCT_Utilities.FindBLVesselByID(IDSelected);

            GUILayout.BeginVertical();
            if (GUILayout.Button("Scrap"))
            {
                InputLockManager.SetControlLock(ControlTypes.KSC_ALL, "KCTPopupLock");
                DialogOption[] options = new DialogOption[2];
                options[0] = new DialogOption("Yes", ScrapVessel);
                options[1] = new DialogOption("No", DummyVoid);
                MultiOptionDialog diag = new MultiOptionDialog("Are you sure you want to scrap this vessel?", windowTitle: "Scrap Vessel", options: options);
                PopupDialog.SpawnPopupDialog(diag, false, windowSkin);
                showBLPlus = false;
                ResetBLWindow();
            }
            if (GUILayout.Button("Edit"))
            {
                showBLPlus = false;
                editorWindowPosition.height = 1;
                string tempFile = KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/Ships/temp.craft";
                b.shipNode.Save(tempFile);
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                KCT_GameStates.editedVessel          = b;
                KCT_GameStates.EditorShipEditingMode = true;
                KCT_GameStates.delayStart            = true;

                InputLockManager.SetControlLock(ControlTypes.EDITOR_EXIT, "KCTEditExit");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LOAD, "KCTEditLoad");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_NEW, "KCTEditNew");
                InputLockManager.SetControlLock(ControlTypes.EDITOR_LAUNCH, "KCTEditLaunch");

                KCT_GameStates.EditedVesselParts.Clear();
                foreach (ConfigNode node in b.ExtractedPartNodes)
                {
                    string name = KCT_Utilities.PartNameFromNode(node) + KCT_Utilities.GetTweakScaleSize(node);
                    if (!KCT_GameStates.EditedVesselParts.ContainsKey(name))
                    {
                        KCT_GameStates.EditedVesselParts.Add(name, 1);
                    }
                    else
                    {
                        ++KCT_GameStates.EditedVesselParts[name];
                    }
                }

                //EditorDriver.StartAndLoadVessel(tempFile);
                EditorDriver.StartAndLoadVessel(tempFile, b.type == KCT_BuildListVessel.ListType.VAB ? EditorFacility.VAB : EditorFacility.SPH);
            }
            if (GUILayout.Button("Rename"))
            {
                centralWindowPosition.width  = 360;
                centralWindowPosition.x      = (Screen.width - 360) / 2;
                centralWindowPosition.height = 1;
                showBuildList = false;
                showBLPlus    = false;
                showRename    = true;
                newName       = b.shipName;
                //newDesc = b.getShip().shipDescription;
            }
            if (GUILayout.Button("Duplicate"))
            {
                KCT_Utilities.AddVesselToBuildList(b.NewCopy(true), b.InventoryParts.Count > 0);
            }
            if (KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()) != null && GUILayout.Button("Rollback"))
            {
                KCT_GameStates.ActiveKSC.Recon_Rollout.Find(rr => rr.RRType == KCT_Recon_Rollout.RolloutReconType.Rollout && rr.associatedID == b.id.ToString()).SwapRolloutType();
            }
            if (!b.isFinished && GUILayout.Button("Warp To"))
            {
                KCT_GameStates.targetedItem = b;
                KCT_GameStates.canWarp      = true;
                KCT_Utilities.RampUpWarp(b);
                KCT_GameStates.warpInitiated = true;
                showBLPlus = false;
            }
            if (!b.isFinished && GUILayout.Button("Move to Top"))
            {
                if (b.type == KCT_BuildListVessel.ListType.VAB)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.VABList.Insert(0, b);
                }
                else if (b.type == KCT_BuildListVessel.ListType.SPH)
                {
                    b.RemoveFromBuildList();
                    KCT_GameStates.ActiveKSC.SPHList.Insert(0, b);
                }
            }
            if (!b.isFinished && GUILayout.Button("Rush Build 10%\n√" + Math.Round(0.2 * b.GetTotalCost())))
            {
                double cost = b.GetTotalCost();
                cost *= 0.2;
                double remainingBP = b.buildPoints - b.progress;
                if (Funding.Instance.Funds >= cost)
                {
                    b.AddProgress(remainingBP * 0.1);
                    KCT_Utilities.SpendFunds(cost, TransactionReasons.None);
                }
            }
            if (GUILayout.Button("Close"))
            {
                showBLPlus = false;
            }
            GUILayout.EndVertical();
            float width = bLPlusPosition.width;

            bLPlusPosition.x     = buildListWindowPosition.x - width;
            bLPlusPosition.width = width;
        }
Exemplo n.º 21
0
        void DrawSettings(int id)
        {
            Debug.Log("DrawSettings 1");

            GUILayout.BeginVertical();

            if (QFlight.data.PostInitStateIsSaved)
            {
                if (QFlight.data.VesselExists)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Box("Revert Saved", GUILayout.Height(30));
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(Localizer.Format("quickrevert_revertLastV", QFlight.data.pVessel.vesselType, QFlight.data.pVessel.vesselName), GUILayout.Width(400));
                    Debug.Log("DrawSettings 2");
                    //					GUILayout.FlexibleSpace ();
                    if (GUILayout.Button(Localizer.Format("quickrevert_loseIt")))
                    {
                        QFlight.data.Reset();
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    Debug.Log("DrawSettings 3");

                    //					GUILayout.FlexibleSpace ();
                    if (GUILayout.Button(Localizer.Format("quickrevert_gotoV")))
                    {
                        Settings();
                        string _saveGame = GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                        FlightDriver.StartAndFocusVessel(_saveGame, QFlight.data.currentActiveVesselIdx);
                        InputLockManager.ClearControlLocks();
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(5);
                    if (!QFlight.data.PreLaunchStateIsSaved)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(Localizer.Format("quickrevert_onlyRevertLaunch"), GUILayout.Width(500));
                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Box("Options", GUILayout.Height(30));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            QSettings.Instance.EnableRevertLoss = GUILayout.Toggle(QSettings.Instance.EnableRevertLoss, Planetarium.fetch.Home.atmosphere ? Localizer.Format("quickrevert_revertLossAtm") : Localizer.Format("quickrevert_revertLossSOI"), GUILayout.Width(450));
            GUILayout.EndHorizontal();

            Debug.Log("DrawSettings 4");

            //			GUILayout.FlexibleSpace ();
            GUILayout.BeginHorizontal();
            Debug.Log("DrawSettings 5");

            //			GUILayout.FlexibleSpace ();
            if (GUILayout.Button(Localizer.Format("quickrevert_close"), GUILayout.Height(30)))
            {
                Settings();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            Debug.Log("DrawSettings 6");
        }
Exemplo n.º 22
0
 private void Save()
 {
     GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
 }
Exemplo n.º 23
0
 void gotoSPH()
 {
     ClearSpaceCenter();
     GamePersistence.SaveGame(SaveGame, HighLogic.SaveFolder, SaveMode.OVERWRITE);
     StartCoroutine(loadScene(GameScenes.EDITOR, EditorFacility.SPH));
 }
Exemplo n.º 24
0
        IEnumerator <YieldInstruction> store_constructs()
        {
            if (FlightGlobals.fetch == null ||
                FlightGlobals.ActiveVessel == null ||
                packed_constructs.Count == 0)
            {
                yield break;
            }
            //wait for hangar.vessel to be loaded
            VesselWaiter self = new VesselWaiter(vessel);

            while (!self.launched)
            {
                yield return(new WaitForFixedUpdate());
            }
            while (!enabled)
            {
                yield return(new WaitForFixedUpdate());
            }
            //create vessels from constructs and store them
            HangarState cur_state = hangar_state; Deactivate();

            foreach (PackedConstruct pc in packed_constructs.Values)
            {
                remove_construct(pc);
                GetLaunchTransform();
                if (!pc.LoadConstruct())
                {
                    Utils.Log("PackedConstruct: unable to load ShipConstruct {0}. " +
                              "This usually means that some parts are missing " +
                              "or some modules failed to initialize.", pc.name);
                    ScreenMessager.showMessage(string.Format("Unable to load {0}", pc.name), 3);
                    continue;
                }
                ShipConstruction.PutShipToGround(pc.construct, launchTransform);
                ShipConstruction.AssembleForLaunch(pc.construct, "Hangar", pc.flag,
                                                   FlightDriver.FlightStateCache,
                                                   new VesselCrewManifest());
                VesselWaiter vsl = new VesselWaiter(FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1]);
                FlightGlobals.ForceSetActiveVessel(vsl.vessel);
                Staging.beginFlight();
                //wait for vsl to be launched
                while (!vsl.launched)
                {
                    yield return(new WaitForFixedUpdate());
                }
                store_vessel(vsl.vessel, false);
                //wait a 0.1 sec, otherwise the vessel may not be destroyed properly
                yield return(new WaitForSeconds(0.1f));
            }
            stored_mass = Utils.formatMass(vessels_mass);
            if (cur_state == HangarState.Active)
            {
                Activate();
            }
            //save game afterwards
            FlightGlobals.ForceSetActiveVessel(vessel);
            while (!self.launched)
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(0.5f));

            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
        }
Exemplo n.º 25
0
 public SaveableGame(GamePersistence gameDataController)
 {
     GameDataController = gameDataController;
 }
Exemplo n.º 26
0
        public override void AddTo(SharedObjects shared)
        {
            shared.BindingMgr.AddGetter("QUICKSAVE", () =>
            {
                if (!HighLogic.CurrentGame.Parameters.Flight.CanQuickSave)
                {
                    return(false);
                }
                QuickSaveLoad.QuickSave();
                return(true);
            });

            shared.BindingMgr.AddGetter("QUICKLOAD", () =>
            {
                if (!HighLogic.CurrentGame.Parameters.Flight.CanQuickLoad)
                {
                    return(false);
                }
                try
                {
                    GamePersistence.LoadGame("quicksave", HighLogic.SaveFolder, true, false);
                }
                catch (Exception ex)
                {
                    SafeHouse.Logger.Log(ex.Message);
                    return(false);
                }
                return(true);
            });

            shared.BindingMgr.AddSetter("SAVETO", val =>
            {
                if (reservedSaveNames.Contains(val.ToString().ToLower()))
                {
                    return;
                }

                Game game       = HighLogic.CurrentGame.Updated();
                game.startScene = GameScenes.FLIGHT;
                GamePersistence.SaveGame(game, val.ToString(), HighLogic.SaveFolder, SaveMode.OVERWRITE);
            });

            shared.BindingMgr.AddSetter("LOADFROM", val =>
            {
                if (reservedSaveNames.Contains(val.ToString().ToLower()))
                {
                    return;
                }

                var game = GamePersistence.LoadGame(val.ToString(), HighLogic.SaveFolder, true, false);
                if (game == null)
                {
                    return;
                }
                if (game.flightState == null)
                {
                    return;
                }
                if (!game.compatible)
                {
                    return;
                }
                FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
            });

            shared.BindingMgr.AddGetter("LOADDISTANCE", () => Vessel.loadDistance);
            shared.BindingMgr.AddSetter("LOADDISTANCE", val =>
            {
                var distance          = Convert.ToSingle(val);
                Vessel.loadDistance   = distance;
                Vessel.unloadDistance = distance - 250;
            });
            shared.BindingMgr.AddGetter("WARPMODE", () =>
            {
                switch (TimeWarp.WarpMode)
                {
                case TimeWarp.Modes.HIGH:
                    return("RAILS");

                case TimeWarp.Modes.LOW:
                    return("PHYSICS");

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });
            shared.BindingMgr.AddSetter("WARPMODE", val =>
            {
                TimeWarp.Modes toSet;

                switch (val.ToString())
                {
                case "PHYSICS":
                    toSet = TimeWarp.Modes.LOW;
                    break;

                case "RAILS":
                    toSet = TimeWarp.Modes.HIGH;
                    break;

                default:
                    throw new Exception(string.Format("WARPMODE '{0}' is not valid", val));
                }

                TimeWarp.fetch.Mode = toSet;
            });
            shared.BindingMgr.AddGetter("WARP", () => TimeWarp.CurrentRateIndex);
            shared.BindingMgr.AddSetter("WARP", val =>
            {
                int newRate;
                if (int.TryParse(val.ToString(), out newRate))
                {
                    TimeWarp.SetRate(newRate, false);
                }
            });
            shared.BindingMgr.AddGetter("MAPVIEW", () => MapView.MapIsEnabled);
            shared.BindingMgr.AddSetter("MAPVIEW", val =>
            {
                if (Convert.ToBoolean(val))
                {
                    MapView.EnterMapView();
                }
                else
                {
                    MapView.ExitMapView();
                }
            });
            foreach (var body in FlightGlobals.fetch.bodies)
            {
                var cBody = body;
                shared.BindingMgr.AddGetter(body.name, () => new BodyTarget(cBody, shared));
            }

            shared.BindingMgr.AddGetter("VERSION", () => Core.VersionInfo);
        }
Exemplo n.º 27
0
 public static void Save(string name)
 {
     GamePersistence.SaveGame(name, HighLogic.SaveFolder, SaveMode.OVERWRITE);
 }
Exemplo n.º 28
0
        void Awake()
        {
            //load the game only the first time (i.e. at game start)
            if (Loaded)
            {
                return;
            }
            Loaded = true;
            //get the game and the save
            var game = "";
            var save = "";

            if (File.Exists(config))
            {
                var cfg = ConfigNode.Load(config);
                if (cfg != null)
                {
                    var val = cfg.GetValue("game");
                    if (val != null)
                    {
                        game = val;
                    }
                    val = cfg.GetValue("save");
                    if (val != null)
                    {
                        save = val;
                    }
                }
                else
                {
                    Log("LoadTestGame: Configuration file is empty: {0}", config);
                    return;
                }
            }
            else
            {
                Log("LoadTestGame: Configuration file not found: {0}", config);
                return;
            }
            var gamedir = Path.Combine(savesdir, game);

            if (!Directory.Exists(gamedir))
            {
                Log("No game directory: {0}", gamedir);
                return;
            }
            var savefile = Path.Combine(gamedir, save + ".sfs");

            if (!File.Exists(savefile))
            {
                Log("No such file: {0}", savefile);
                return;
            }
            //load the game
            HighLogic.CurrentGame = GamePersistence.LoadGame(save, game, false, false);
            if (HighLogic.CurrentGame != null)
            {
                GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame);
                HighLogic.SaveFolder = game;
                HighLogic.CurrentGame.Start();
            }
        }
Exemplo n.º 29
0
        public void GameSceneEvent(GameScenes scene)
        {
            KCT_GUI.HideAll();
            KCTGameStates.SimulationParams.IsVesselMoved = false;

            if (scene == GameScenes.MAINMENU)
            {
                KCTGameStates.Reset();
                KCTGameStates.IsFirstStart = false;
                Utilities.DisableSimulationLocks();
                InputLockManager.RemoveControlLock(KerbalConstructionTime.KCTLaunchLock);
                KCTGameStates.ActiveKSCName = Utilities._defaultKscId;
                KCTGameStates.ActiveKSC     = new KSCItem(Utilities._defaultKscId);
                KCTGameStates.KSCs          = new List <KSCItem>()
                {
                    KCTGameStates.ActiveKSC
                };
                KCTGameStates.LastKnownTechCount = 0;

                if (PresetManager.Instance != null)
                {
                    PresetManager.Instance.ClearPresets();
                    PresetManager.Instance = null;
                }

                return;
            }

            KCTGameStates.MiscellaneousTempUpgrades = 0;

            if (PresetManager.PresetLoaded() && !PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                return;
            }
            var validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR
            };

            if (validScenes.Contains(scene))
            {
                if (Utilities.SimulationSaveExists())
                {
                    Utilities.LoadSimulationSave(false);
                }
                TechDisableEventFinal();
            }

            if (HighLogic.LoadedScene == scene && scene == GameScenes.EDITOR)    //Fix for null reference when using new or load buttons in editor
            {
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                EditorLogic.fetch.Unlock("KCTEditorMouseLock");
            }

            if (scene == GameScenes.EDITOR && !HighLogic.LoadedSceneIsEditor)
            {
                KCT_GUI.FirstOnGUIUpdate = true;
            }
        }
Exemplo n.º 30
0
        public void gameSceneEvent(GameScenes scene)
        {
            if (scene == GameScenes.MAINMENU)
            {
                KCT_GameStates.reset();
                KCT_GameStates.firstStart = false;
                KCT_Utilities.disableSimulationLocks();
                InputLockManager.RemoveControlLock("KCTLaunchLock");
                KCT_GameStates.activeKSCName = "Stock";
                KCT_GameStates.ActiveKSC     = new KCT_KSC("Stock");
                KCT_GameStates.KSCs          = new List <KCT_KSC>()
                {
                    KCT_GameStates.ActiveKSC
                };
                KCT_GameStates.EditorSimulationCount = 0;
                KCT_GameStates.LastKnownTechCount    = 0;

                KCT_GameStates.PermanentModAddedUpgradesButReallyWaitForTheAPI = 0;
                KCT_GameStates.TemporaryModAddedUpgradesButReallyWaitForTheAPI = 0;

                if (KCT_PresetManager.Instance != null)
                {
                    KCT_PresetManager.Instance.ClearPresets();
                    KCT_PresetManager.Instance = null;
                }

                return;
            }

            KCT_GameStates.MiscellaneousTempUpgrades = 0;

            /*if (HighLogic.LoadedScene == GameScenes.MAINMENU)
             * {
             *  if (scene == GameScenes.SPACECENTER)
             *  {
             *      KCT_PresetManager.Instance.FindPresetFiles();
             *      KCT_PresetManager.Instance.LoadPresets();
             *  }
             * }*/

            if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                return;
            }
            List <GameScenes> validScenes = new List <GameScenes> {
                GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR
            };

            if (validScenes.Contains(scene))
            {
                //Check for simulation save and load it.
                if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs"))
                {
                    KCT_Utilities.LoadSimulationSave(false);
                }
                TechDisableEventFinal();
            }

            /*if (!HighLogic.LoadedSceneIsFlight && scene == GameScenes.FLIGHT && KCT_GameStates.flightSimulated) //Backup save at simulation start
             * {
             *  KCT_Utilities.MakeSimulationSave();
             * }*/

            if (HighLogic.LoadedScene == scene && scene == GameScenes.EDITOR) //Fix for null reference when using new or load buttons in editor
            {
                GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                EditorLogic.fetch.Unlock("KCTEditorMouseLock");
            }

            if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
            {
                KCT_GameStates.EditorSimulationCount = 0;
            }
        }