Exemple #1
0
        private static void OnEnteredSpaceCenter()
        {
            string warpSeed = WarpDrive.seedString;

            if (warpSeed != AstroUtils.KERBIN_SYSTEM_COORDS)
            {
                // Load the Kerbin snapshot
                PersistenceGenerator.LoadSnapshot(warpSeed, AstroUtils.KERBIN_SYSTEM_COORDS);
            }
        }
 /// <summary>
 /// Warps to the current seed.
 /// </summary>
 public static void Warp(bool processActions, string theSeed, bool savePersistence = true)
 {
     Debugger.Log("Beginning warp to " + theSeed);
     // Replace any newline or tab characters.
     theSeed = Regex.Replace(theSeed, "[^ -~]+", string.Empty, RegexOptions.Multiline);
     // Make sure the seed is valid
     if (string.IsNullOrEmpty(theSeed))
     {
         ScreenMessages.PostScreenMessage("Invalid coordinates.", 3.0f, ScreenMessageStyle.UPPER_CENTER);
         return;
     }
     // Set the seeds
     lastSeed   = seedString;
     seedString = theSeed;
     try
     {
         // Create the RNG
         Randomizers.WarpRNG.ReSeed(seedString);
         // Create and randomize the system
         SolarData.CreateSystem(seedString);
         // Write the current seed to file
         SeedTracker.Jump();
     }
     catch (System.Exception e)
     {
         // Catch all exceptions so users know if something goes wrong
         ScreenMessages.PostScreenMessage("Warp Drive failed due to " + e.GetType() + ".");
         Debugger.LogException("Unable to jump to system!", e);
         return;
     }
     if (seedString != AstroUtils.KERBIN_SYSTEM_COORDS)
     {
         // We've left Kerbol, so we need to purge the Kerbol vessels
         needsPurge = true;
     }
     if (processActions)
     {
         // Call each post-warp action
         foreach (OnWarpDelegate onWarp in nextWarpActions)
         {
             onWarp();
         }
         // Clear the list of methods
         nextWarpActions.Clear();
     }
     if (savePersistence)
     {
         PersistenceGenerator.SavePersistence();
     }
     if (hasInit)
     {
         instance.Invoke("PostWarp", Time.deltaTime);
     }
     Debugger.LogWarning("Created system " + currentSystem.name + " from string " + seedString + ".");
 }
 private static void OnWindow(int windowID)
 {
     // Start a new GUILayout
     GUILayout.BeginVertical(GUILayout.Width(250.0f));
     // Create the text field
     GUI.SetNextControlName("Warp TextField");
     currentSeed = GUILayout.TextField(currentSeed);
     // Select the text in the text field
     GUI.FocusControl("Warp TextField");
     // Make the button
     if (GUILayout.Button("Start Warp Drive") || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
     {
         // User has hit the button or pressed enter
         Warp(true, currentSeed, false);
         PersistenceGenerator.WarpSingleVessel(lastSeed, seedString, FlightGlobals.ActiveVessel);
         RenderingManager.RemoveFromPostDrawQueue(0, OnDraw);
         InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
     }
     GUILayout.EndVertical();
     // Allow the window to be draggable
     GUI.DragWindow();
 }
Exemple #4
0
        public static void FlushVesselCache(string unloadedSeed, Guid unloadIgnoreID)
        {
            // Save a snapshot
            PersistenceGenerator.SaveSnapshot(unloadedSeed);
            // Cache the current system
            Vessel[]      allVessels         = GameObject.FindObjectsOfType <Vessel> ();
            List <Vessel> unclearableVessels = new List <Vessel> ();

            // Despawn all vessels
            Debugger.Log(allVessels.Length + " vessels need to be despawed.");
            if (unloadIgnoreID != Guid.Empty)
            {
                Debugger.Log("Vessel with ID " + unloadIgnoreID.ToString() + " will be ignored.");
            }
            for (int i = 0; i < allVessels.Length; i++)
            {
                Vessel vessel = allVessels [i];
                // Clear the vessel unless we are asked to ignore it
                if (vessel.id != unloadIgnoreID || unloadIgnoreID == Guid.Empty)
                {
                    vesselSeeds [vessel.id] = unloadedSeed;
                    if (!RemoveVesselFromSystem(vessel))
                    {
                        Debugger.LogWarning("Could not unload " + vessel.name);
                        unclearableVessels.Add(vessel);
                    }
                }
            }
            // Clear the vessel cache
            FlightGlobals.Vessels.Clear();
            HighLogic.CurrentGame.flightState.protoVessels.Clear();
            // If we couldn't unload something, ensure it's not duplicated
            foreach (Vessel vessel in unclearableVessels)
            {
                FlightGlobals.Vessels.Add(vessel);
                HighLogic.CurrentGame.flightState.protoVessels.Add(vessel.BackupVessel());
            }
        }
Exemple #5
0
 private void Start()
 {
     PersistenceGenerator.SavePersistence();
 }
 /// <summary>
 /// Automatically jumps to kerbol.
 /// </summary>
 public static void JumpToKerbol(bool processActions, Vessel warpVessel)
 {
     currentSeed = AstroUtils.KERBIN_SYSTEM_COORDS;
     Warp(processActions, currentSeed, false);
     PersistenceGenerator.WarpSingleVessel(lastSeed, seedString, warpVessel);
 }