Exemple #1
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;
            }
        }
    }
Exemple #2
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;
        }
    }
Exemple #3
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);
        }
Exemple #4
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();
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// Draws the content of the window.
        /// </summary>
        /// <param name="windowID">Window I.</param>
        protected override void DrawContent(int windowID)
        {
            GUILayout.BeginVertical();
            {
                // The server name region
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Server Address: ");
                    server = GUILayout.TextField(server);
                }
                GUILayout.EndHorizontal();

                // the user name region
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Surname: ");
                    surnom = GUILayout.TextField(surnom);
                }
                GUILayout.EndHorizontal();

                // the buttons region
                GUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Save", buttonStyles, GUILayout.ExpandWidth(true)))                        //GUILayout.Button is "true" when clicked
                    {
                        Debug.Log("On a cliqué sur le bouton save: " + server);
                        savedServersList.Add(server);
                    }
                    if (GUILayout.Button("Connect", buttonStyles, GUILayout.ExpandWidth(true)))                        //GUILayout.Button is "true" when clicked
                    {
                        Debug.Log("On a cliqué sur le bouton connect: " + server + " avec le surnom: " + surnom);
                        if (server != null && !"".Equals(server) && surnom != null && !"".Equals(surnom))
                        {
                            Debug.Log("Initializing client...");

                            ConnexionUtils.connectTo(server, surnom);
                            if (ConnexionUtils.isConnected())
                            {
                                Debug.Log("on charge le jeu");
                                Game game = GamePersistence.LoadGame("KeronMultiGame", "../GameData/Keron", true, false);
                                game.Load();
                                game.Start();
                            }
                        }
                    }
                    if (GUILayout.Button("Erase", buttonStyles, GUILayout.ExpandWidth(true)))                        //GUILayout.Button is "true" when clicked
                    {
                        Debug.Log("On a cliqué sur le bouton erase");
                        server = "";
                    }
                }
                GUILayout.EndHorizontal();

                // the saved server region
                savedServersList.ForEach(
                    s =>
                {
                    if (GUILayout.Button(s, serverListStyles, GUILayout.ExpandWidth(true)))                                //GUILayout.Button is "true" when clicked
                    {
                        UnityEngine.Debug.Log("On a cliqué sur le bouton : " + s);
                        server = s;
                    }
                }
                    );
            }
            GUILayout.EndVertical();
        }
Exemple #7
0
        /*************************************************************************************************************************/
        public void save_landed_vessel(bool auto_recover_allowed, bool ForceRecover)
        {
            Game               loadgame, savegame;
            Guid               temp_guid;
            int                ReferenceBodyIndex = 0;
            List <Guid>        id_list            = new List <Guid>();
            List <ProtoVessel> vessel_list        = new List <ProtoVessel>();
            Dictionary <Guid, List <ProtoVessel> > vessel_dict = new Dictionary <Guid, List <ProtoVessel> >();
            string message;

            Log.PushStackInfo("FMRS_Core.save_landed_vessel", "entering save_landed_vessel(bool auto_recover_allowed) " + auto_recover_allowed.ToString());
            Log.dbg("save landed vessels");

            if (SwitchedToDropped == false)
            {
                Log.dbg("in Main Save, leaving save_landed_vessel");
                return;
            }

            //GamePersistence.SaveGame("FMRS_quicksave", HighLogic.SaveFolder + "/FMRS", SaveMode.OVERWRITE);
            FMRS_SAVE_Util.Instance.SaveGame("FMRS_Core.save_landed_vessel", "FMRS_quicksave", HighLogic.SaveFolder + "/FMRS", SaveMode.OVERWRITE);
            loadgame = GamePersistence.LoadGame("FMRS_quicksave", HighLogic.SaveFolder + "/FMRS", false, false);
            savegame = GamePersistence.LoadGame("FMRS_main_save", HighLogic.SaveFolder, false, false);

            foreach (Guid id in loaded_vessels)
            {
                if (FlightGlobals.Vessels.Find(v => v.id == id) == null)
                {
                    if (!damaged_vessels.Contains(id))
                    {
                        damaged_vessels.Add(id);
                    }
                }
            }

            foreach (Vessel v in FlightGlobals.Vessels.FindAll(v => v.loaded))
            {
                id_list.Add(v.id);
            }

            vessel_list = loadgame.flightState.protoVessels.FindAll(tpv => id_list.Contains(tpv.vesselID));

            foreach (Guid id in loaded_vessels)
            {
                vessel_dict.Add(id, new List <ProtoVessel>());
            }

            foreach (ProtoVessel pv in vessel_list)
            {
                if (loaded_vessels.Contains(pv.vesselID))
                {
                    vessel_dict[pv.vesselID].Add(pv);
                }
                else
                {
                    foreach (ProtoPartSnapshot ps in pv.protoPartSnapshots)
                    {
                        foreach (ProtoPartModuleSnapshot ppms in ps.modules)
                        {
                            if (ppms.moduleName == "FMRS_PM")
                            {
                                try
                                {
                                    temp_guid = new Guid(ppms.moduleValues.GetValue("parent_vessel"));
                                    if (loaded_vessels.Contains(temp_guid))
                                    {
                                        vessel_dict[temp_guid].Add(pv);
                                    }
                                }
                                catch (Exception)
                                {
                                    Log.info("Exception: save_landed_vessel: temp_guid = new Guid(ppms.moduleValues.GetValue(parent_vessel));");
                                }
                            }
                            break;
                        }
                    }
                }
                ReferenceBodyIndex = pv.orbitSnapShot.ReferenceBodyIndex;
            }

            id_list.Clear();
            foreach (KeyValuePair <Guid, List <ProtoVessel> > kvp in vessel_dict)
            {
                id_list.Add(kvp.Key);
            }
            foreach (Guid id in id_list)
            {
                if (vessel_dict[id].Count == 0)
                {
                    vessel_dict.Remove(id);
                }
            }
            id_list.Clear();
            foreach (KeyValuePair <Guid, List <ProtoVessel> > kvp in vessel_dict)
            {
                id_list.Add(kvp.Key);
            }

            foreach (Guid id in id_list)
            {
                if (id_list.Count == 1 && vessel_dict[id].Count == 0 && get_vessel_state(id) != vesselstate.RECOVERED)
                {
                    set_vessel_state(id, vesselstate.DESTROYED);
                }

                if (get_vessel_state(id) == vesselstate.RECOVERED)
                {
                    vessel_dict.Remove(id);
                }
            }

            if (vessel_dict.Count != 0)
            {
                Log.dbg("save landed vessel or recover");

                foreach (KeyValuePair <Guid, List <ProtoVessel> > kvp in vessel_dict)
                {
                    if ((_SETTING_Auto_Recover || ForceRecover) && auto_recover_allowed && ReferenceBodyIndex == 1)
                    {
                        savegame = recover_vessel(kvp.Key, kvp.Value, loadgame, savegame);
                    }
                    else
                    {
                        ProtoVessel temp_proto_del2 = savegame.flightState.protoVessels.Find(prtv => prtv.vesselID == kvp.Key);
                        if (temp_proto_del2 != null)
                        {
                            savegame.flightState.protoVessels.Remove(temp_proto_del2);
                        }

                        foreach (ProtoVessel pv in kvp.Value)
                        {
                            ProtoVessel temp_proto_del = savegame.flightState.protoVessels.Find(prtv => prtv.vesselID == pv.vesselID);
                            if (temp_proto_del != null)
                            {
                                savegame.flightState.protoVessels.Remove(temp_proto_del);
                            }

                            if (pv.landed || pv.splashed)
                            {
                                savegame.flightState.protoVessels.Add(pv);
                                set_vessel_state(kvp.Key, vesselstate.LANDED);
                            }
                        }
                    }
                }
            }

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                message = "";
                if (contract_complete.Count > 0)
                {
                    foreach (KeyValuePair <Guid, List <Contract> > kvp in contract_complete)
                    {
                        if (loaded_vessels.Contains(kvp.Key))
                        {
                            foreach (Contract c in kvp.Value)
                            {
                                set_recoverd_value("contract", "complete", c.ContractID.ToString());
                                message += c.Title + "@";
                            }
                        }
                    }
                    if (message != "")
                    {
                        set_recoverd_value("message", "FMRS: Completed Contracts", message);
                    }
                }
                foreach (KeyValuePair <Guid, List <ProtoVessel> > kvp in vessel_dict)
                {
                    if (contract_complete.ContainsKey(kvp.Key))
                    {
                        contract_complete.Remove(kvp.Key);
                    }
                }
            }

            foreach (killed_kerbal_str killed in killed_kerbals)
            {
                Log.dbg("Kerbal {0} killed on that flight?", killed.name);

                message = "";

                if (loaded_vessels.Contains(killed.vessel_id))
                {
                    Log.dbg("Kerbal {0} killed", killed.name);

                    foreach (ProtoCrewMember member in savegame.CrewRoster.Crew)
                    {
                        if (member.name == killed.name)
                        {
                            member.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                            set_recoverd_value("kerbal", "kill", killed.rep.ToString());
                            message += killed.name + " killed: " + Math.Round(killed.rep, 2).ToString() + " Reputation@";
                        }
                    }
                }
                if (message != "")
                {
                    set_recoverd_value("message", "FMRS: Kerbal Killed", message);
                }
            }

            if (damaged_buildings.Count > 0)
            {
                message = "";
                foreach (string build in damaged_buildings)
                {
                    set_recoverd_value("building", "destroyed", build);
                    message += build + "@";
                }
                if (message != "")
                {
                    set_recoverd_value("message", "FMRS: Building Destroyed", message);
                }
            }

            //GamePersistence.SaveGame(savegame, "FMRS_main_save", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            FMRS_SAVE_Util.Instance.SaveGame("FMRS_Core.save_landed_vessel", savegame, "FMRS_main_save", HighLogic.SaveFolder, SaveMode.OVERWRITE);

            write_recover_file();
            write_save_values_to_file();

            Log.PopStackInfo("leaving save_landed_vessel(bool auto_recover_allowed)");
        }
Exemple #8
0
        // Deactivates the simulation. Success is destructive to the plugin state,
        // so... no return value
        public void  Deactivate(GameScenes targetScene)
        {
            // This method only does something if the sim is active.
            if (KRASHShelter.persistent.shelterSimulationActive && System.IO.File.Exists(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/" + "KRASHRevert.sfs"))
            {
                // Weird bug can be intorduced by how KSP keeps around KSPAddons until it decides to destroy
                // them. We need to preempt this so extraneous behavior isn't observed

                DestroyModules();

                // Ok, here is where this is tricky. We can't just directly load the save, we need to
                // load the save into a new Game object, re-save that object into the default persistence,
                // and then change the scene. Weird shit, right? This is actually how the vanilla quickload
                // works!

                Game newGame = GamePersistence.LoadGame("KRASHRevert", HighLogic.SaveFolder, true, false);
                GamePersistence.SaveGame(newGame, "persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                System.IO.File.Delete(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/" + "KRASHRevert.sfs");



                newGame.startScene = targetScene;
                // This has to be before... newGame.Start()
                if (targetScene == GameScenes.EDITOR)
                {
                    newGame.editorFacility = KRASHShelter.lastEditor;
                }

                newGame.Start();
                //HoloDeck.instance.SimulationActive = false;

                                #if false
                if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
                {
                    if (KRASHShelter.simCost + KRASHShelter.simSetupCost > 0)
                    {
                        // Need to subtract the funds here, after the save has been loaded
                        Log.Info("simCost: " + KRASHShelter.simCost.ToString());
                        Log.Info("Current funds before simCost: " + Funding.Instance.Funds.ToString());
                        Funding.Instance.AddFunds(-1 * KRASHShelter.simCost, TransactionReasons.RnDs);
                        Log.Info("Current funds after simCost: " + Funding.Instance.Funds.ToString());
                        KRASHShelter.simCost      = 0;
                        KRASHShelter.simSetupCost = 0;
                    }
                }
                                #endif

                // ... And this has to be after. <3 KSP
                if (targetScene == GameScenes.EDITOR)
                {
                    EditorDriver.StartupBehaviour = EditorDriver.StartupBehaviours.LOAD_FROM_CACHE;
                    ShipConstruction.ShipConfig   = KRASHShelter.lastShip;
                }
            }
            //Log.Info ("Total sim cost: " + KRASHShelter.simCost.ToString ());
            //Funding.Instance.AddFunds(-1.0F * KRASHShelter.simCost, TransactionReasons.Any);
            //Log.Info ("Funds: " + Funding.Instance.Funds.ToString ());
            //KRASHShelter.simCost = 0;

            //KRASHShelter.instance.SimulationActive = false;
            //GameObject t = GameObject.Find ("KRASHPersistent");
            //KRASHPersistent k = t.GetComponent<KRASHPersistent> ();
            //if (k != KRASHShelter.persistent) {
            //	Log.Info ("k != KRASHShelter.persistent");
            //}
            KRASHShelter.persistent.shelterSimulationActive = false;

            //KRASHPersistent.shelterSimulationActive = false;
        }
        /*************************************************************************************************************************/
        public void jump_to_vessel(string main)
        {
            Game loadgame;
            int  load_vessel;

#if DEBUG
            // if (Debug_Level_1_Active)
            Log.PushStackInfo("FMRS_Core.jump_to_vessel(string)", "entering jump_to_vessel(string main)");
            if (Debug_Active)
            {
                Log.Info("Jump to Main");
            }
#endif

            if (!_SAVE_Switched_To_Dropped)
            {
                return;
            }

            save_landed_vessel(true, false);

            loadgame = GamePersistence.LoadGame("FMRS_main_save", HighLogic.SaveFolder, false, false);

            if (loadgame != null && loadgame.compatible && loadgame.flightState != null)
            {
#if DEBUG
                if (Debug_Active)
                {
                    Log.Info("try to load gamefile FMRS_main_save");
                }
#endif

                for (load_vessel = 0; load_vessel < loadgame.flightState.protoVessels.Count && loadgame.flightState.protoVessels[load_vessel].vesselID != _SAVE_Main_Vessel; load_vessel++)
                {
                    ;
                }
                if (load_vessel < loadgame.flightState.protoVessels.Count)
                {
#if DEBUG
                    if (Debug_Active)
                    {
                        Log.Info("FMRS_main_save found, main vessel found, try to load");
                    }
#endif
                    _SAVE_Switched_To_Savefile = "FMRS_main_save";
                    _SAVE_Switched_To_Dropped  = false;
                    FMRS_SAVE_Util.Instance.StartAndFocusVessel(loadgame, load_vessel);
//                    FlightDriver.StartAndFocusVessel(loadgame, load_vessel);
                }
#if DEBUG
                else
                if (Debug_Active)
                {
                    Log.Info("main vessel not found in savefile");
                }
#endif
            }
#if DEBUG
            else
            if (Debug_Active)
            {
                Log.Info("Loading gamefile FMRS_main_save failed");
            }

            // if (Debug_Level_1_Active)
            Log.PopStackInfo("leaving jump_to_vessel(string main)");
#endif
        }
        /*************************************************************************************************************************/
        public void jump_to_vessel(Guid vessel_id, bool save_landed)
        {
            int load_vessel;

#if DEBUG
            // if (Debug_Level_1_Active)
            Log.PushStackInfo("FMRS_Core.jump_to_vessel(Guid, bool)", "entering jump_to_vessel(Guid vessel_id) " + vessel_id.ToString() + " " + save_landed.ToString());

            if (Debug_Active)
            {
                Log.Info("Jump to " + vessel_id.ToString());
            }
#endif

            if (save_landed)
            {
                if (FlightGlobals.ActiveVessel.id == _SAVE_Main_Vessel)
                {
                    //GamePersistence.SaveGame("FMRS_main_save", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                    FMRS_SAVE_Util.Instance.SaveGame("FMRS_Core.jump_to_vessel(Guid, bool)", "FMRS_main_save", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                }
                save_landed_vessel(true, false);
            }

            Game loadgame = GamePersistence.LoadGame(get_save_value(save_cat.DROPPED, vessel_id.ToString()), HighLogic.SaveFolder + "/FMRS", false, false);

            if (loadgame != null && loadgame.compatible && loadgame.flightState != null)
            {
#if DEBUG
                if (Debug_Active)
                {
                    Log.Info("try to load gamefile " + get_save_value(save_cat.DROPPED, vessel_id.ToString()));
                }
#endif

                // TODO: semantics refactor. load_vessel is the incentive
                for (load_vessel = 0; load_vessel < loadgame.flightState.protoVessels.Count && loadgame.flightState.protoVessels[load_vessel].vesselID != vessel_id; load_vessel++)
                {
                    ;
                }


                if (load_vessel < loadgame.flightState.protoVessels.Count)
                {
#if DEBUG
                    if (Debug_Active)
                    {
                        Log.Info("FMRS_save found, Vessel found, try to start");
                    }
#endif

                    if (vessel_id != _SAVE_Main_Vessel)
                    {
                        _SAVE_Switched_To_Savefile = get_save_value(save_cat.DROPPED, vessel_id.ToString());
                        Log.Info("sithilfe: " + _SAVE_Switched_To_Savefile);
                        _SAVE_Switched_To_Dropped = true;
                    }
                    else
                    {
                        _SAVE_Switched_To_Dropped = false;
                    }
                    Log.Info("load_vessel: " + load_vessel.ToString());
                    Log.Info("loadgame.flightState.protoVessels.Count: " + loadgame.flightState.protoVessels.Count.ToString());
                    //Log.Info("loadgame: " + loadgame.ToString());
                    Log.Info("File loaded: " + HighLogic.SaveFolder + "/FMRS/" + get_save_value(save_cat.DROPPED, vessel_id.ToString()));

                    Log.ShowStackInfo();
                    // detach_handlers();
                    FMRS_SAVE_Util.Instance.StartAndFocusVessel(loadgame, load_vessel);
//                    FlightDriver.StartAndFocusVessel(loadgame, load_vessel);
                    // attach_handlers();
                    return;
                }
            }

#if DEBUG
            // if (Debug_Level_1_Active)
            Log.PopStackInfo("leaving jump_to_vessel(Guid vessel_id)");
#endif
        }
Exemple #11
0
        public override void AddTo(SharedObjects shared)
        {
            shared.BindingMgr.AddGetter("KUNIVERSE", () => new KUniverseValue(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("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().ToUpper())
                {
                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))
                {
                    switch (TimeWarp.WarpMode)
                    {
                    case TimeWarp.Modes.HIGH:
                        SetWarpRate(newRate, TimeWarp.fetch.warpRates.Length - 1);
                        break;

                    case TimeWarp.Modes.LOW:
                        SetWarpRate(newRate, TimeWarp.fetch.physicsWarpRates.Length - 1);
                        break;

                    default:
                        throw new Exception(string.Format("WARPMODE '{0}' is unknown to kOS, please contact the devs", val));
                    }
                }
            });
            shared.BindingMgr.AddGetter("MAPVIEW", () => MapView.MapIsEnabled);
            shared.BindingMgr.AddSetter("MAPVIEW", val =>
            {
                if (Convert.ToBoolean(val))
                {
                    MapView.EnterMapView();
                }
                else
                {
                    MapView.ExitMapView();
                }
            });
            shared.BindingMgr.AddGetter("CONSTANT", () => new ConstantValue());
            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);
            shared.BindingMgr.AddGetter("SOLARPRIMEVECTOR", () => new Vector(Planetarium.right));
            shared.BindingMgr.AddGetter("ARCHIVE", () => shared.VolumeMgr.GetVolume(Archive.ArchiveName));
        }
Exemple #12
0
        internal static Boolean JumpToVessel(Vessel vTarget)
        {
            Boolean blnJumped = true;

            if (HighLogic.LoadedSceneIsFlight)
            {
                if (BackupSaves() || !HighLogic.CurrentGame.Parameters.CustomParams <RM_1>().CancelFlightModeJumpOnBackupFailure)
                {
                    vesselToJumpTo = vTarget;
                }

                //if(FlightGlobals.SetActiveVessel(vTarget))
                //{
                //    FlightInputHandler.SetNeutralControls();
                //}
                else
                {
                    Main.Log.Info("Not Switching - unable to backup saves");
                    ShowBackupFailedWindow("Not Switching - unable to backup saves");
                    blnJumped = false;
                }
            }
            else
            {
                Main.Log.Info("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 (BackupSaves())
                        {
                            String strret  = GamePersistence.SaveGame("AMJumpToShip", 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);
        }