示例#1
0
        public void ExportSelectedCraft(Vessel vessel)
        {
            CreateFolder();

            string filename = KSPUtil.ApplicationRootPath + "/Ships/export/" + HighLogic.SaveFolder + "_" + vessel.vesselName;

            Log($"Exporting vessel: {vessel.vesselName}\nExporting to file: {filename}");

            ConfigNode nodeToSave = new ConfigNode();

            //save vessel
            ConfigNode  vesselNode = new ConfigNode("VESSEL");
            ProtoVessel pVessel    = vessel.BackupVessel();

            pVessel.Save(vesselNode);
            nodeToSave.AddNode("VESSEL", vesselNode);

            //save active crew member info
            foreach (ProtoCrewMember pcm in pVessel.GetVesselCrew())
            {
                ConfigNode pcmNode = new ConfigNode("CREW");
                pcm.Save(pcmNode);
                nodeToSave.AddNode("CREW", pcmNode);
            }

            nodeToSave.Save(filename);

            ScreenMessage message = new ScreenMessage(vessel.vesselName + " exported to " + filename, 6, ScreenMessageStyle.UPPER_CENTER);

            ScreenMessages.PostScreenMessage(message);
        }
 public void Save()
 {
     if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && (FlightGlobals.fetch.activeVessel != null))
     {
         if (FlightGlobals.fetch.activeVessel.loaded && !FlightGlobals.fetch.activeVessel.packed)
         {
             if (FlightGlobals.fetch.activeVessel.situation != Vessel.Situations.FLYING)
             {
                 savedVessel = new ConfigNode();
                 ProtoVessel tempVessel = new ProtoVessel(FlightGlobals.fetch.activeVessel);
                 tempVessel.Save(savedVessel);
                 savedSubspace = new Subspace();
                 savedSubspace.planetTime = Planetarium.GetUniversalTime();
                 savedSubspace.serverClock = TimeSyncer.fetch.GetServerClock();
                 savedSubspace.subspaceSpeed = 1f;
                 ScreenMessages.PostScreenMessage("Quicksaved!", 3f, ScreenMessageStyle.UPPER_CENTER);
             }
             else
             {
                 ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is in flight!", 3f, ScreenMessageStyle.UPPER_CENTER);
             }
         }
         else
         {
             ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is not loaded!", 3f, ScreenMessageStyle.UPPER_CENTER);
         }
     }
     else
     {
         ScreenMessages.PostScreenMessage("Cannot quicksave - Not in flight!", 3f, ScreenMessageStyle.UPPER_CENTER);
     }
 }
        private static bool PreSerializationChecks(ProtoVessel protoVessel, out ConfigNode configNode)
        {
            configNode = new ConfigNode();

            if (protoVessel == null)
            {
                LunaLog.LogError("[LMP]: Cannot serialize a null protovessel");
                return(false);
            }

            try
            {
                protoVessel.Save(configNode);
            }
            catch (Exception e)
            {
                LunaLog.LogError($"[LMP]: Error while saving vessel: {e}");
                return(false);
            }

            var vesselId = new Guid(configNode.GetValue("pid"));

            //Defend against NaN orbits
            if (VesselCommon.VesselHasNaNPosition(configNode))
            {
                LunaLog.LogError($"[LMP]: Vessel {vesselId} has NaN position");
                return(false);
            }

            //Do not send the maneuver nodes
            RemoveManeuverNodesFromProtoVessel(configNode);
            return(true);
        }
示例#4
0
        private void OnVesselWillDestroy(Vessel vessel)
        {
            if (vesselWorker.VesselRecentlyKilled(vessel.id))
            {
                return;
            }
            bool pilotedByAnotherPlayer = lockSystem.LockExists("control-" + vessel.id) && !lockSystem.LockIsOurs("control-" + vessel.id);
            bool updatedByAnotherPlayer = lockSystem.LockExists("update-" + vessel.id) && !lockSystem.LockIsOurs("update-" + vessel.id);
            bool updatedInTheFuture     = vesselWorker.VesselUpdatedInFuture(vessel.id);

            //Vessel was packed within the last 5 seconds
            if (lastPackTime.ContainsKey(vessel.id) && (Client.realtimeSinceStartup - lastPackTime[vessel.id]) < 5f)
            {
                lastPackTime.Remove(vessel.id);
                if (vessel.situation == Vessel.Situations.FLYING && (pilotedByAnotherPlayer || updatedByAnotherPlayer || updatedInTheFuture))
                {
                    DarkLog.Debug("Hacky load: Saving player vessel getting packed in atmosphere");
                    ProtoVessel pv        = vessel.BackupVessel();
                    ConfigNode  savedNode = new ConfigNode();
                    pv.Save(savedNode);
                    vesselWorker.LoadVessel(savedNode, vessel.id, true);
                }
            }
            if (lastPackTime.ContainsKey(vessel.id))
            {
                lastPackTime.Remove(vessel.id);
            }
        }
示例#5
0
        public NetOutgoingMessage CreateVesselMessage()
        {
            if (HighLogic.LoadedScene != GameScenes.FLIGHT || FlightGlobals.ActiveVessel == null || !FlightGlobals.ActiveVessel.loaded || FlightGlobals.ActiveVessel.packed)
            {
                return(null);
            }

            NetOutgoingMessage netOutgoingMessage = this.m_netClient.CreateMessage();

            ProtoVessel protoVessel = new ProtoVessel(FlightGlobals.fetch.activeVessel); // Get active vessel as a ProtoVessel.
            ConfigNode  configNode  = HighLogic.CurrentGame.config;

            protoVessel.Save(configNode); // Save ProtoVessel in empty node to get data about it and send it later.

            IGameMessage gameMessage = new VesselMessage
            {
                ID   = FlightGlobals.fetch.activeVessel.id.ToString(),
                Name = FlightGlobals.fetch.activeVessel.name,
                Data = configNode.ToString(), // Send data about vessel here.
            };

            netOutgoingMessage.Write((byte)gameMessage.MessageType);
            gameMessage.EncodeMessage(netOutgoingMessage);

            return(netOutgoingMessage);
        }
示例#6
0
 public void Save()
 {
     if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && (FlightGlobals.fetch.activeVessel != null))
     {
         if (FlightGlobals.fetch.activeVessel.loaded && !FlightGlobals.fetch.activeVessel.packed)
         {
             if (FlightGlobals.fetch.activeVessel.situation != Vessel.Situations.FLYING)
             {
                 savedVessel = new ConfigNode();
                 ProtoVessel tempVessel = new ProtoVessel(FlightGlobals.fetch.activeVessel);
                 tempVessel.Save(savedVessel);
                 savedSubspace               = new Subspace();
                 savedSubspace.planetTime    = Planetarium.GetUniversalTime();
                 savedSubspace.serverClock   = TimeSyncer.fetch.GetServerClock();
                 savedSubspace.subspaceSpeed = 1f;
                 ScreenMessages.PostScreenMessage("Quicksaved!", 3f, ScreenMessageStyle.UPPER_CENTER);
             }
             else
             {
                 ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is in flight!", 3f, ScreenMessageStyle.UPPER_CENTER);
             }
         }
         else
         {
             ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is not loaded!", 3f, ScreenMessageStyle.UPPER_CENTER);
         }
     }
     else
     {
         ScreenMessages.PostScreenMessage("Cannot quicksave - Not in flight!", 3f, ScreenMessageStyle.UPPER_CENTER);
     }
 }
示例#7
0
        /// <summary>
        /// Creates a protovessel from a ConfigNode
        /// </summary>
        private static ProtoVessel CreateSafeProtoVesselFromConfigNode(ConfigNode inputNode, Guid protoVesselId)
        {
            try
            {
                var pv = new ProtoVessel(inputNode, HighLogic.CurrentGame);
                var cn = new ConfigNode();
                pv.Save(cn);

                foreach (var pps in pv.protoPartSnapshots)
                {
                    if (ModSystem.Singleton.ModControl != ModControlMode.DISABLED &&
                        !ModSystem.Singleton.AllowedParts.Contains(pps.partName.ToLower()))
                    {
                        var msg = $"[LMP]: WARNING: Protovessel {protoVesselId} ({pv.vesselName}) contains the banned " +
                                  $"part '{pps.partName}'!. Skipping load.";

                        Debug.LogWarning(msg);
                        ChatSystem.Singleton.PmMessageServer(msg);

                        return(null);
                    }
                    if (pps.partInfo == null)
                    {
                        var msg = $"[LMP]: WARNING: Protovessel {protoVesselId} ({pv.vesselName}) contains the missing " +
                                  $"part '{pps.partName}'!. Skipping load.";

                        Debug.LogWarning(msg);
                        ChatSystem.Singleton.PmMessageServer(msg);

                        ScreenMessages.PostScreenMessage($"Cannot load '{pv.vesselName}' - you are missing {pps.partName}", 10f,
                                                         ScreenMessageStyle.UPPER_CENTER);

                        return(null);
                    }

                    var missingeResource = pps.resources
                                           .FirstOrDefault(r => !PartResourceLibrary.Instance.resourceDefinitions.Contains(r.resourceName));

                    if (missingeResource != null)
                    {
                        var msg = $"[LMP]: WARNING: Protovessel {protoVesselId} ({pv.vesselName}) " +
                                  $"contains the missing resource '{missingeResource.resourceName}'!. Skipping load.";

                        Debug.LogWarning(msg);
                        ChatSystem.Singleton.PmMessageServer(msg);

                        ScreenMessages.PostScreenMessage($"Cannot load '{pv.vesselName}' - you are missing the resource " +
                                                         $"{missingeResource.resourceName}", 10f, ScreenMessageStyle.UPPER_CENTER);
                        return(null);
                    }
                }
                return(pv);
            }
            catch (Exception e)
            {
                Debug.LogError($"[LMP]: Damaged vessel {protoVesselId}, exception: {e}");
                return(null);
            }
        }
示例#8
0
        public static ConfigNode vesselSnapshot(Vessel vessel)
        {
            ProtoVessel snapshot = new ProtoVessel(vessel);
            ConfigNode  node     = new ConfigNode("VESSEL");

            snapshot.Save(node);
            return(node);
        }
示例#9
0
        // static functions, that make live a lot easier

        /// <summary>
        /// Stores a Vessel into the specified Hangar
        /// </summary>
        internal static void StoreVessel(Vessel vessel, Hangar hangar)
        {
            StoredVessel storedVessel = new StoredVessel
            {
                uuid       = vessel.protoVessel.vesselID,
                vesselName = vessel.GetDisplayName()
            };

            //get the experience and assign the crew to the rooster
            foreach (Part part in vessel.parts)
            {
                int count = part.protoModuleCrew.Count;

                if (count != 0)
                {
                    ProtoCrewMember[] crewList = part.protoModuleCrew.ToArray();

                    for (int i = 0; i < count; i++)
                    {
                        crewList[i].flightLog.AddEntryUnique(FlightLog.EntryType.Recover);
                        crewList[i].flightLog.AddEntryUnique(FlightLog.EntryType.Land, FlightGlobals.currentMainBody.name);
                        crewList[i].ArchiveFlightLog();

                        // remove the crew from the ship
                        part.RemoveCrewmember(crewList[i]);
                    }
                }
            }


            // save the ship
            storedVessel.vesselNode = new ConfigNode("VESSEL");

            //create a backup of the current state, then save that state
            ProtoVessel backup = vessel.BackupVessel();

            backup.Save(storedVessel.vesselNode);

            // save the stored information in the hangar
            hangar.storedVessels.Add(storedVessel);

            // remove the stored vessel from the game
            vessel.MakeInactive();
            vessel.Unload();
            //vessel.Die();

            FlightGlobals.RemoveVessel(vessel);
            if (vessel != null)
            {
                vessel.protoVessel.Clean();
            }

            //UnityEngine.Object.Destroy(vessel.gameObject);

            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
            HighLogic.LoadScene(GameScenes.SPACECENTER);
        }
示例#10
0
        public void ExportSelectedCraft(Vessel vessel)
        {
            CreateFolder();

            string vname1 = vessel.vesselName;

            string vname = "";

            Localizer.TryGetStringByTag(vname1, out vname);
            if (vname == "" || vname == null)
            {
                vname = vname1;
            }


            string filename = KSPUtil.ApplicationRootPath + "Ships/export/" + HighLogic.SaveFolder + "_" + vname;

            Log($"Exporting vessel: {vessel.vesselName}\nExporting to file: {filename}");

            ConfigNode nodeToSave = new ConfigNode();

            //save vessel
            ConfigNode  vesselNode = new ConfigNode("VESSEL");
            ProtoVessel pVessel    = vessel.BackupVessel();

            pVessel.Save(vesselNode);
            nodeToSave.AddNode("VESSEL", vesselNode);

            //save active crew member info
            foreach (ProtoCrewMember pcm in pVessel.GetVesselCrew())
            {
                ConfigNode pcmNode = new ConfigNode("CREW");
                pcm.Save(pcmNode);
                nodeToSave.AddNode("CREW", pcmNode);
            }

            nodeToSave.Save(filename);

            //ScreenMessage message = new ScreenMessage(vname+" exported to "+filename, 6, ScreenMessageStyle.UPPER_CENTER);
            //ScreenMessages.PostScreenMessage(message);

            PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Export", "Export Complete",
                                         "Vessel has been exported to:\n" + filename,
                                         "Ok", false, HighLogic.UISkin);
        }
示例#11
0
        private static bool PreSerializationChecks(ProtoVessel protoVessel, out ConfigNode configNode)
        {
            configNode = new ConfigNode();

            if (protoVessel == null)
            {
                LunaLog.LogError("[LMP]: Cannot serialize a null protovessel");
                return(false);
            }

            try
            {
                protoVessel.Save(configNode);
            }
            catch (Exception e)
            {
                LunaLog.LogError($"[LMP]: Error while saving vessel: {e}");
                return(false);
            }

            var vesselId = new Guid(configNode.GetValue("pid"));

            //Defend against NaN orbits
            if (VesselCommon.VesselHasNaNPosition(configNode))
            {
                LunaLog.LogError($"[LMP]: Vessel {vesselId} has NaN position");
                return(false);
            }

            //Clean up the vessel so we send only the important data
            CleanUpVesselNode(configNode, vesselId);

            //TODO: Remove tourists from the vessel. This must be done in the CleanUpVesselNode method
            //foreach (var pps in protoVessel.protoPartSnapshots)
            //{
            //    foreach (var pcm in
            //        pps.protoModuleCrew.Where(pcm => pcm.type == ProtoCrewMember.KerbalType.Tourist).ToArray())
            //        pps.protoModuleCrew.Remove(pcm);
            //}

            return(true);
        }
 private void InitKMPVesselUpdate(Vessel _vessel, bool includeProtoVessel)
 {
     pos   = new float[3];
     dir   = new float[3];
     vel   = new float[3];
     o_vel = new double[3];
     s_vel = new double[3];
     w_pos = new double[3];
     rot   = new float[4];
     id    = _vessel.id;
     if (_vessel.packed)
     {
         flightCtrlState = new KMPFlightCtrlState(new FlightCtrlState());
     }
     else
     {
         flightCtrlState = new KMPFlightCtrlState(_vessel.ctrlState);
         if (includeProtoVessel)
         {
             protoVesselNode = new ConfigNode();
             ProtoVessel proto;
             try
             {
                 proto = new ProtoVessel(_vessel);
             }
             catch (Exception e)
             {
                 Log.Debug("Exception thrown in InitKMPVesselUpdate(), catch 1, Exception: {0}", e.ToString());
                 proto = null;
             }
             if (proto != null)
             {
                 foreach (ProtoCrewMember crewMember in proto.GetVesselCrew())
                 {
                     crewMember.KerbalRef = null;
                 }
                 proto.Save(protoVesselNode);
             }
         }
     }
 }
示例#13
0
        public static byte[] SerializeVessel(ProtoVessel protoVessel)
        {
            var vesselNode = new ConfigNode();

            try
            {
                protoVessel.Save(vesselNode);
            }
            catch (Exception)
            {
                LunaLog.LogError("[LMP]: Error while saving vessel");
                return(new byte[0]);
            }

            var vesselId = new Guid(vesselNode.GetValue("pid"));

            //Defend against NaN orbits
            if (VesselHasNaNPosition(vesselNode))
            {
                LunaLog.Log($"[LMP]: Vessel {vesselId} has NaN position");
                return(new byte[0]);
            }

            //Clean up the vessel so we send only the important data
            CleanUpVesselNode(vesselNode, vesselId);

            //TODO: Remove tourists from the vessel. This must be done in the CleanUpVesselNode method
            //foreach (var pps in protoVessel.protoPartSnapshots)
            //{
            //    foreach (var pcm in
            //        pps.protoModuleCrew.Where(pcm => pcm.type == ProtoCrewMember.KerbalType.Tourist).ToArray())
            //        pps.protoModuleCrew.Remove(pcm);
            //}

            return(ConfigNodeSerializer.Serialize(vesselNode));
        }
示例#14
0
 public static ConfigNode vesselSnapshot(Vessel vessel)
 {
     ProtoVessel snapshot = new ProtoVessel(vessel);
     ConfigNode node = new ConfigNode("VESSEL");
     snapshot.Save(node);
     return node;
 }
示例#15
0
 //Called from vesselWorker
 public void SendVesselProtoMessage(ProtoVessel vessel, bool isDockingUpdate)
 {
     ConfigNode vesselNode = new ConfigNode();
     ClientMessage newMessage = new ClientMessage();
     newMessage.type = ClientMessageType.VESSEL_PROTO;
     vessel.Save(vesselNode);
     byte[] vesselBytes = ConvertConfigNodeToByteArray(vesselNode);
     if (vesselBytes != null)
     {
         using (MessageWriter mw = new MessageWriter())
         {
             mw.Write<int>(TimeSyncer.fetch.currentSubspace);
             mw.Write<double>(Planetarium.GetUniversalTime());
             mw.Write<string>(vessel.vesselID.ToString());
             mw.Write<bool>(isDockingUpdate);
             mw.Write<byte[]>(vesselBytes);
             newMessage.data = mw.GetMessageBytes();
         }
         DarkLog.Debug("Sending vessel " + vessel.vesselID + ", name " + vessel.vesselName + ", type: " + vessel.vesselType + ", size: " + newMessage.data.Length);
         sendMessageQueueLow.Enqueue(newMessage);
     }
     else
     {
         DarkLog.Debug("Failed to create byte[] data for " + vessel.vesselID);
     }
 }
 //Called from main
 public void LoadVesselsIntoGame()
 {
     DarkLog.Debug("Loading vessels into game");
     foreach (KeyValuePair<string, Queue<VesselProtoUpdate>> vesselQueue in vesselProtoQueue)
     {
         while (vesselQueue.Value.Count > 0)
         {
             ConfigNode currentNode = vesselQueue.Value.Dequeue().vesselNode;
             if (currentNode != null)
             {
                 DodgeVesselActionGroups(currentNode);
                 DodgeVesselCrewValues(currentNode);
                 RemoveManeuverNodesFromProtoVessel(currentNode);
                 ProtoVessel pv = new ProtoVessel(currentNode, HighLogic.CurrentGame);
                 if (pv != null)
                 {
                     bool protovesselIsOk = true;
                     try
                     {
                         ConfigNode cn = new ConfigNode();
                         pv.Save(cn);
                     }
                     catch
                     {
                         DarkLog.Debug("WARNING: Protovessel " + pv.vesselID + ", name: " + pv.vesselName + " is DAMAGED!. Skipping load.");
                         ChatWorker.fetch.PMMessageServer("WARNING: Protovessel " + pv.vesselID + ", name: " + pv.vesselName + " is DAMAGED!. Skipping load.");
                         protovesselIsOk = false;
                     }
                     if (protovesselIsOk)
                     {
                         RegisterServerVessel(pv.vesselID.ToString());
                         RegisterServerAsteriodIfVesselIsAsteroid(pv);
                         HighLogic.CurrentGame.flightState.protoVessels.Add(pv);
                     }
                 }
             }
         }
     }
     DarkLog.Debug("Vessels loaded into game");
 }
示例#17
0
 private bool isProtoVesselInSafetyBubble(ProtoVessel protovessel)
 {
     //When vessels are landed, position is 0,0,0 - So we need to check lat/long
     ConfigNode protoVesselNode = new ConfigNode();
     protovessel.Save(protoVesselNode);
     CelestialBody kerbinBody = FlightGlobals.Bodies.Find (b => b.name == "Kerbin");
     //If not kerbin, we aren't in the safety bubble.
     if (protoVesselNode.GetNode("ORBIT").GetValue("REF") != "1") {
         return false;
     }
     //If we aren't landed, use the vector3 check above.
     if (!protovessel.landed) {
         return isInSafetyBubble (protovessel.position, kerbinBody, protovessel.altitude);
     }
     //Check our distance
     double protoVesselLat;
     double protoVesselLong;
     Double.TryParse(protoVesselNode.GetValue("lat"), out protoVesselLat);
     Double.TryParse(protoVesselNode.GetValue("long"), out protoVesselLong);
     Vector3d kscPosition = kerbinBody.GetWorldSurfacePosition(-0.102668048654,-74.5753856554,60);
     Vector3d protoVesselPosition = kerbinBody.GetWorldSurfacePosition(protoVesselLat, protoVesselLong, protovessel.altitude);
     double vesselDistance = Vector3d.Distance(kscPosition, protoVesselPosition);
     return vesselDistance < safetyBubbleRadius;
 }
        //Called from vesselWorker
        public void SendVesselProtoMessage(ProtoVessel vessel, bool isDockingUpdate, bool isFlyingUpdate)
        {
            ConfigNode vesselNode = new ConfigNode();
            ClientMessage newMessage = new ClientMessage();
            newMessage.type = ClientMessageType.VESSEL_PROTO;
            vessel.Save(vesselNode);

            byte[] vesselBytes = ConfigNodeSerializer.fetch.Serialize(vesselNode);

            if (vesselBytes != null && vesselBytes.Length > 0)
            {
                UniverseSyncCache.fetch.SaveToCache(vesselBytes);
                using (MessageWriter mw = new MessageWriter())
                {
                    mw.Write<double>(Planetarium.GetUniversalTime());
                    mw.Write<string>(vessel.vesselID.ToString());
                    mw.Write<bool>(isDockingUpdate);
                    mw.Write<bool>(isFlyingUpdate);
                    mw.Write<byte[]>(vesselBytes);
                    newMessage.data = mw.GetMessageBytes();
                }
                DarkLog.Debug("Sending vessel " + vessel.vesselID + ", name " + vessel.vesselName + ", type: " + vessel.vesselType + ", size: " + newMessage.data.Length);
                QueueOutgoingMessage(newMessage, false);
            }
            else
            {
                DarkLog.Debug("Failed to create byte[] data for " + vessel.vesselID);
            }
        }
示例#19
0
        private ProtoVessel CreateSafeProtoVesselFromConfigNode(ConfigNode inputNode, Guid protovesselID)
        {
            ProtoVessel pv = null;
            try
            {
                DodgeVesselActionGroups(inputNode);
                RemoveManeuverNodesFromProtoVessel(inputNode);
                DodgeVesselLandedStatus(inputNode);
                KerbalReassigner.fetch.DodgeKerbals(inputNode, protovesselID);
                pv = new ProtoVessel(inputNode, HighLogic.CurrentGame);
                ConfigNode cn = new ConfigNode();
                pv.Save(cn);
                List<string> partsList = null;
                PartResourceLibrary partResourceLibrary = PartResourceLibrary.Instance;
                if (ModWorker.fetch.modControl != ModControlMode.DISABLED)
                {
                    partsList = ModWorker.fetch.GetAllowedPartsList();
                }

                foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots)
                {
                    if (ModWorker.fetch.modControl != ModControlMode.DISABLED)
                    {
                        if (!partsList.Contains(pps.partName))
                        {
                            DarkLog.Debug("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the banned part '" + pps.partName + "'!. Skipping load.");
                            ChatWorker.fetch.PMMessageServer("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the banned part '" + pps.partName + "'!. Skipping load.");
                            pv = null;
                            break;
                        }
                    }
                    if (pps.partInfo == null)
                    {
                        DarkLog.Debug("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the missing part '" + pps.partName + "'!. Skipping load.");
                        ChatWorker.fetch.PMMessageServer("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the missing part '" + pps.partName + "'!. Skipping load.");
                        ScreenMessages.PostScreenMessage("Cannot load '" + pv.vesselName + "' - you are missing " + pps.partName, 10f, ScreenMessageStyle.UPPER_CENTER);
                        pv = null;
                        break;
                    }
                    foreach (ProtoPartResourceSnapshot resource in pps.resources)
                    {
                        if (!partResourceLibrary.resourceDefinitions.Contains(resource.resourceName))
                        {
                            DarkLog.Debug("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the missing resource '" + resource.resourceName + "'!. Skipping load.");
                            ChatWorker.fetch.PMMessageServer("WARNING: Protovessel " + protovesselID + " (" + pv.vesselName + ") contains the missing resource '" + resource.resourceName + "'!. Skipping load.");
                            ScreenMessages.PostScreenMessage("Cannot load '" + pv.vesselName + "' - you are missing the resource " + resource.resourceName, 10f, ScreenMessageStyle.UPPER_CENTER);
                            pv = null;
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DarkLog.Debug("Damaged vessel " + protovesselID + ", exception: " + e);
                pv = null;
            }
            return pv;
        }
 private void InitKMPVesselUpdate(Vessel _vessel, bool includeProtoVessel)
 {
     pos = new float[3];
     dir = new float[3];
     vel = new float[3];
     o_vel = new double[3];
     s_vel = new double[3];
     w_pos = new double[3];
     rot = new float[4];
     id = _vessel.id;
     if (_vessel.packed)
     {
         flightCtrlState = new KMPFlightCtrlState(new FlightCtrlState());
     }
     else
     {
         flightCtrlState = new KMPFlightCtrlState(_vessel.ctrlState);
     }
     if (includeProtoVessel)
     {
         protoVesselNode = new ConfigNode();
         ProtoVessel proto;
         try
         {
             proto = new ProtoVessel(_vessel);
         }
         catch (Exception e)
         {
             Log.Debug("Exception thrown in InitKMPVesselUpdate(), catch 1, Exception: {0}", e.ToString());
             proto = null;
         }
         if (proto != null)
         {
             foreach (ProtoCrewMember crewMember in proto.GetVesselCrew())
             {
                 crewMember.KerbalRef = null;
             }
             proto.Save(protoVesselNode);
         }
     }
 }
示例#21
0
        /**
         * Don't actually use this!
         * */
        public static ConfigNode ProtoVesselToCraftFile(ProtoVessel vessel)
        {
            ConfigNode craft = new ConfigNode("ShipNode");
            ConfigNode pvNode = new ConfigNode();
            vessel.Save(pvNode);
            //KCTDebug.Log(pvNode);

            craft.AddValue("ship", pvNode.GetValue("name"));
            craft.AddValue("version", Versioning.GetVersionString());
            craft.AddValue("description", "Craft file converted automatically by Kerbal Construction Time.");
            craft.AddValue("type", "VAB");
            ConfigNode[] parts = pvNode.GetNodes("PART");
            foreach (ConfigNode part in parts)
            {
                ConfigNode newPart = new ConfigNode("PART");
                newPart.AddValue("part", part.GetValue("name") + "_" + part.GetValue("uid"));
                newPart.AddValue("partName", "Part");
                newPart.AddValue("pos", part.GetValue("position"));
                newPart.AddValue("rot", part.GetValue("rotation"));
                newPart.AddValue("attRot", part.GetValue("rotation"));
                newPart.AddValue("mir", part.GetValue("mirror"));
                newPart.AddValue("istg", part.GetValue("istg"));
                newPart.AddValue("dstg", part.GetValue("dstg"));
                newPart.AddValue("sidx", part.GetValue("sidx"));
                newPart.AddValue("sqor", part.GetValue("sqor"));
                newPart.AddValue("attm", part.GetValue("attm"));
                newPart.AddValue("modCost", part.GetValue("modCost"));

                foreach (string attn in part.GetValues("attN"))
                {
                    string attach_point = attn.Split(',')[0];
                    if (attach_point == "None")
                        continue;
                    int attachedIndex = int.Parse(attn.Split(',')[1]);
                    string attached = parts[attachedIndex].GetValue("name") + "_" + parts[attachedIndex].GetValue("uid");
                    newPart.AddValue("link", attached);
                    newPart.AddValue("attN", attach_point + "," + attached);
                }

                newPart.AddNode(part.GetNode("EVENTS"));
                newPart.AddNode(part.GetNode("ACTIONS"));
                foreach (ConfigNode mod in part.GetNodes("MODULE"))
                    newPart.AddNode(mod);
                foreach (ConfigNode rsc in part.GetNodes("RESOURCE"))
                    newPart.AddNode(rsc);
                craft.AddNode(newPart);
            }

            return craft;
        }
示例#22
0
 //Called from vesselWorker
 public void SendVesselProtoMessage(ProtoVessel vessel, bool isDockingUpdate)
 {
     ConfigNode currentNode = new ConfigNode();
     ClientMessage newMessage = new ClientMessage();
     newMessage.type = ClientMessageType.VESSEL_PROTO;
     vessel.Save(currentNode);
     string tempFile = Path.GetTempFileName();
     currentNode.Save(tempFile);
     using (StreamReader sr = new StreamReader(tempFile))
     {
         using (MessageWriter mw = new MessageWriter())
         {
             mw.Write<int>(TimeSyncer.fetch.currentSubspace);
             mw.Write<double>(Planetarium.GetUniversalTime());
             mw.Write<string>(vessel.vesselID.ToString());
             mw.Write<bool>(isDockingUpdate);
             mw.Write<byte[]>(File.ReadAllBytes(tempFile));
             newMessage.data = mw.GetMessageBytes();
         }
     }
     File.Delete(tempFile);
     DarkLog.Debug("Sending vessel " + vessel.vesselID + ", name " + vessel.vesselName + ", type: " + vessel.vesselType + ", size: " + newMessage.data.Length);
     sendMessageQueueLow.Enqueue(newMessage);
 }
示例#23
0
 //Called from vesselWorker
 public void SendVesselProtoMessage(ProtoVessel vessel, bool isDockingUpdate, bool isFlyingUpdate)
 {
     //Defend against NaN orbits
     if (VesselHasNaNPosition(vessel))
     {
         DarkLog.Debug("Vessel " + vessel.vesselID + " has NaN position");
         return;
     }
     foreach (ProtoPartSnapshot pps in vessel.protoPartSnapshots)
     {
         foreach (ProtoCrewMember pcm in pps.protoModuleCrew.ToArray())
         {
             if (pcm.type == ProtoCrewMember.KerbalType.Tourist)
             {
                 pps.protoModuleCrew.Remove(pcm);
             }
         }
     }
     ConfigNode vesselNode = new ConfigNode();
     vessel.Save(vesselNode);
     ClientMessage newMessage = new ClientMessage();
     newMessage.type = ClientMessageType.VESSEL_PROTO;
     byte[] vesselBytes = ConfigNodeSerializer.fetch.Serialize(vesselNode);
     File.WriteAllBytes(Path.Combine(KSPUtil.ApplicationRootPath, "lastVessel.txt"), vesselBytes);
     if (vesselBytes != null && vesselBytes.Length > 0)
     {
         UniverseSyncCache.fetch.QueueToCache(vesselBytes);
         using (MessageWriter mw = new MessageWriter())
         {
             mw.Write<double>(Planetarium.GetUniversalTime());
             mw.Write<string>(vessel.vesselID.ToString());
             mw.Write<bool>(isDockingUpdate);
             mw.Write<bool>(isFlyingUpdate);
             mw.Write<byte[]>(Compression.CompressIfNeeded(vesselBytes));
             newMessage.data = mw.GetMessageBytes();
         }
         DarkLog.Debug("Sending vessel " + vessel.vesselID + ", name " + vessel.vesselName + ", type: " + vessel.vesselType + ", size: " + newMessage.data.Length);
         QueueOutgoingMessage(newMessage, false);
     }
     else
     {
         DarkLog.Debug("Failed to create byte[] data for " + vessel.vesselID);
     }
 }
        //Called from vesselWorker
        public void SendVesselProtoMessage(ProtoVessel vessel, bool isDockingUpdate, bool isFlyingUpdate)
        {
            //Defend against NaN orbits
            if (VesselHasNaNPosition(vessel))
            {
                DarkLog.Debug("Vessel " + vessel.vesselID + " has NaN position");
                return;
            }

            bool isContractVessel = false;
            foreach (ProtoPartSnapshot pps in vessel.protoPartSnapshots)
            {
                foreach (ProtoCrewMember pcm in pps.protoModuleCrew.ToArray())
                {
                    if (pcm.type == ProtoCrewMember.KerbalType.Tourist)
                    {
                        isContractVessel = true;
                    }
                }
            }
            if (!AsteroidWorker.fetch.VesselIsAsteroid(vessel) && (DiscoveryLevels)Int32.Parse(vessel.discoveryInfo.GetValue("state")) != DiscoveryLevels.Owned)
            {
                isContractVessel = true;
            }
            ConfigNode vesselNode = new ConfigNode();
            vessel.Save(vesselNode);
            if (isContractVessel)
            {
                ConfigNode dmpNode = new ConfigNode();
                dmpNode.AddValue("contractOwner", Settings.fetch.playerPublicKey);
                vesselNode.AddNode("DarkMultiPlayer", dmpNode);
            }

            ClientMessage newMessage = new ClientMessage();
            newMessage.type = ClientMessageType.VESSEL_PROTO;
            byte[] vesselBytes = ConfigNodeSerializer.fetch.Serialize(vesselNode);
            File.WriteAllBytes(Path.Combine(KSPUtil.ApplicationRootPath, "lastVessel.txt"), vesselBytes);
            if (vesselBytes != null && vesselBytes.Length > 0)
            {
                UniverseSyncCache.fetch.QueueToCache(vesselBytes);
                using (MessageWriter mw = new MessageWriter())
                {
                    mw.Write<double>(Planetarium.GetUniversalTime());
                    mw.Write<string>(vessel.vesselID.ToString());
                    mw.Write<bool>(isDockingUpdate);
                    mw.Write<bool>(isFlyingUpdate);
                    mw.Write<byte[]>(Compression.CompressIfNeeded(vesselBytes));
                    newMessage.data = mw.GetMessageBytes();
                }
                DarkLog.Debug("Sending vessel " + vessel.vesselID + ", name " + vessel.vesselName + ", type: " + vessel.vesselType + ", size: " + newMessage.data.Length);
                QueueOutgoingMessage(newMessage, false);
            }
            else
            {
                DarkLog.Debug("Failed to create byte[] data for " + vessel.vesselID);
            }
        }