private static void SaveGame(string seed, string filename, string subfolder = "", bool printVessels = true) { // Expand subfolder if (subfolder == "") { subfolder = HighLogic.SaveFolder; } else { subfolder = Path.Combine(HighLogic.SaveFolder, subfolder); } // Make sure everyone is on the same page Game savedGame = HighLogic.CurrentGame.Updated(); GamePersistence.SaveGame(savedGame, filename, subfolder, SaveMode.OVERWRITE); // Log all vessels in the current seed if (printVessels) { Debugger.Log("Vessels in save " + seed + ":"); } foreach (ProtoVessel v in HighLogic.CurrentGame.flightState.protoVessels) { if (printVessels) { Debugger.Log(v.vesselName); } // All this does is makes sure all the loaded vessels are internally set to the new seed VesselManager.LoadPersistentVessel(seed, v); } ForceTrackingStationUpdate(); }
/// <summary> /// Class constructor. /// </summary> /// <param name="aPlayerModel">PlayerModel class stored in this class from ClientMain.</param> /// <param name="ServerIP">Server IP to connect on it.</param> /// <param name="ServerPort">Server port to connect on it.</param> public ClientNetwork(PlayerModel aPlayerModel, string ServerIP, int ServerPort) { this.m_netConfiguration = new NetPeerConfiguration("LOGMultiplayer"); this.m_netClient = new NetClient(m_netConfiguration); this.m_netClient.Start(); // Start netClient. this.m_playerModel = aPlayerModel; NetOutgoingMessage netOutgoingMessage = this.m_netClient.CreateMessage(); IGameMessage gameMessage = new ConnectionApprovalRequestMessage { Version = APIMain.Version, Username = this.m_playerModel.Username }; netOutgoingMessage.Write((byte)gameMessage.MessageType); gameMessage.EncodeMessage(netOutgoingMessage); this.m_netClient.Connect(ServerIP, Convert.ToInt32(ServerPort), netOutgoingMessage); this.m_vesselManager = new VesselManager(this.m_netClient); this.m_playerModel.messageHandler.OnVesselUpdateState += this.m_vesselManager.HandleVesselMessage; }
public static Vessel PerformBuildFromString(bool requireSource, string buildString, string designation, List <Vessel> sourceVessels) { string[] inputWords = buildString.Split(' '); List <VesselPart> parts = PartsListFromBuildString(buildString); string spriteName = inputWords[1]; float size = float.Parse(inputWords[2]); float durability = float.Parse(inputWords[3]); return(VesselManager.Instance().BuildVessel(requireSource, sourceVessels, spriteName, size, durability, designation, parts)); }
public void SpawnEnemies() { Vessel enemy = VesselManager.Instance().BuildVessel(false, new List <Vessel>(), "enemy_vessel_name_0", "enemy1"); VesselManager.Instance().GetMind("enemy1").AddBehavior(0, new AttackPlayerKingBehavior()); enemy.transform.position = new Vector2(2, 2); }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
private void KeyboardStuff() { if (king == null) { return; } for (int i = 0; i < engineKeyCodes.Length; i++) { UnityEngine.KeyCode keyCode = engineKeyCodes[i]; if (UnityEngine.Input.GetKeyDown(keyCode)) { king.IgniteEngines(new int[1] { i }); } if (UnityEngine.Input.GetKeyUp(keyCode)) { king.QuenchEngines(new int[1] { i }); } } for (int i = 0; i < launcherKeyCodes.Length; i++) { UnityEngine.KeyCode keyCode = launcherKeyCodes[i]; if (UnityEngine.Input.GetKeyDown(keyCode)) { king.Fire(new int[1] { i }); } } for (int i = 0; i < teamNames.Count; i++) { UnityEngine.KeyCode keyCode = bayKeyCodes[i]; if (UnityEngine.Input.GetKeyDown(keyCode)) { VesselManager.Instance().BuildVessel(true, new List <Vessel>() { king }, teamNames[i], teamNames[i]); } } }
public static void ClearSystemVessels(string oldSeed, string newSeed, Guid doNotFlush) { Debugger.Log("Flushing vessel cache for seed " + oldSeed + "."); // Remove all old vessels VesselManager.FlushVesselCache(oldSeed, doNotFlush); // Warp any ignored vessels to the new system if (doNotFlush != Guid.Empty) { PersistentVessel currentVessel = VesselManager.GetPersistentVessel(doNotFlush); if (currentVessel != null) { Debugger.Log("Warping " + currentVessel.name + " to seed " + newSeed); currentVessel.Warp(newSeed); } } ForceTrackingStationUpdate(); }
// Start is called before the first frame update void Start() { instance = this; vesselNamesToBuildstrings = GameStringsHelper.AllSavedNamesToBuildstrings(); }
public void SpawnKing(string vesselName) { king = VesselManager.Instance().BuildVessel(false, new List <Vessel>(), vesselName, "king"); }
public void SpawnKing(string spriteName, List <VesselPart> parts) { king = VesselManager.Instance().BuildVessel(false, new List <Vessel>(), spriteName, 1f, 1f, "king", parts); }
public VesselServices() { _vesselManager = new VesselManager(); }
/// <summary> /// Adds in the vessels from the new seed and saves the new seed to file. /// </summary> /// <param name="oldSeed">The seed we are leaving.</param> /// <param name="newSeed">The seed we are going to.</param> public static void AddPersistenceVessels(string oldSeed, string newSeed) { if (newSeed == AstroUtils.KERBIN_SYSTEM_COORDS && !WarpDrivers.WarpDrive.needsPurge) { // Don't need to merge, we never left Kerbol return; } string persistence = FindPersistenceFile(); if (string.IsNullOrEmpty(persistence)) { Debugger.LogError("Could not find persistence file!"); return; } // Check to see if we already have a persistence file for this system if (SystemPersistenceExists(persistence, newSeed)) { // Load the game // We don't actually have to load the WHOLE game, just the vessels Debugger.Log("Loading existing system at " + newSeed); string path = Path.Combine(KSPUtil.ApplicationRootPath, "saves"); path = Path.Combine(path, HighLogic.SaveFolder); path = Path.Combine(path, AstroUtils.STAR_SYSTEM_FOLDER_NAME); path = Path.Combine(path, newSeed + AstroUtils.SEED_PERSISTENCE + AstroUtils.SFS); // Generate root node from persistence file ConfigNode root = ConfigNode.Load(path).GetNode("GAME"); if (root == null) { throw new PlanetRandomizerException("Could not load save file because the root node could not be found."); } // Find FLIGHTSTATE node in the root node ConfigNode flightStateNode = root.GetNode("FLIGHTSTATE"); // Generate new FlightState from the root FlightState flightState = new FlightState(flightStateNode, HighLogic.CurrentGame); // Load each ProtoVessel in the FlightState List <ProtoVessel> spawnedVessels = new List <ProtoVessel> (); List <Vessel> activeVessels = new List <Vessel> (); Debugger.Log(flightState.protoVessels.Count + " vessels in " + newSeed + "."); foreach (ProtoVessel proto in flightState.protoVessels) { Vessel vessel = VesselManager.LoadVessel(newSeed, proto); if (vessel == null) { Debugger.LogError(proto.vesselName + " was not spawned!"); } else { Debugger.Log(vessel.vesselName + " is now in seed " + newSeed + "."); spawnedVessels.Add(proto); activeVessels.Add(vessel); } } flightState.protoVessels = spawnedVessels; HighLogic.CurrentGame.flightState = flightState; FlightGlobals.Vessels.Clear(); FlightGlobals.Vessels.AddRange(activeVessels); if (newSeed == AstroUtils.KERBIN_SYSTEM_COORDS) { // We've now purged the system of all the "old" data WarpDrivers.WarpDrive.needsPurge = false; } } else { // Create a blank FlightState for the new system HighLogic.CurrentGame.flightState = new FlightState(); Debugger.LogWarning("Created a blank star system for seed " + newSeed); } Debugger.Log("All vessels have been merged."); SavePersistence(); }