예제 #1
0
        /// <summary> Called by GameEvents.onVesselsUndocking, just after 2 vessels have undocked </summary>
        internal static void OnDecoupleOrUndock(Vessel oldVessel, Vessel newVessel)
        {
            Lib.LogDebug("Decoupling vessel '{0}' from vessel '{1}'", newVessel.vesselName, oldVessel.vesselName);

            VesselData oldVD = oldVessel.KerbalismData();
            VesselData newVD = newVessel.KerbalismData();

            // remove all partdata on the new vessel
            newVD.parts.Clear();

            foreach (Part part in newVessel.Parts)
            {
                PartData pd;
                // for all parts in the new vessel, move the corresponding partdata from the old vessel to the new vessel
                if (oldVD.parts.TryGetValue(part.flightID, out pd))
                {
                    newVD.parts.Add(part.flightID, pd);
                    oldVD.parts.Remove(part.flightID);
                }
            }

            newVD.UpdateOnVesselModified();
            oldVD.UpdateOnVesselModified();

            Lib.LogDebug("Decoupling complete for new vessel, vd.partcount={1}, v.partcount={2} ({0})", newVessel.vesselName, newVD.parts.Count, newVessel.parts.Count);
            Lib.LogDebug("Decoupling complete for old vessel, vd.partcount={1}, v.partcount={2} ({0})", oldVessel.vesselName, oldVD.parts.Count, oldVessel.parts.Count);
        }
예제 #2
0
        internal static void OnPartWillDie(Part part)
        {
            VesselData vd = part.vessel.KerbalismData();

            vd.parts.Remove(part.flightID);
            vd.UpdateOnVesselModified();
            Lib.LogDebug("Removing dead part, vd.partcount={0}, v.partcount={1} (part '{2}' in vessel '{3}')", vd.parts.Count, part.vessel.parts.Count, part.partInfo.title, part.vessel.vesselName);
        }
예제 #3
0
        // This is for mods (KIS), won't be used in a stock game (the docking is handled in the OnDock method
        internal static void OnPartCouple(GameEvents.FromToAction <Part, Part> data)
        {
            Lib.LogDebug("Coupling part '{0}' from vessel '{1}' to vessel '{2}'", data.from.partInfo.title, data.from.vessel.vesselName, data.to.vessel.vesselName);

            Vessel fromVessel = data.from.vessel;
            Vessel toVessel   = data.to.vessel;

            VesselData fromVD = fromVessel.KerbalismData();
            VesselData toVD   = toVessel.KerbalismData();

            // GameEvents.onPartCouple may be fired by mods (KIS) that add new parts to an existing vessel
            // In the case of KIS, the part vessel is already set to the destination vessel when the event is fired
            // so we just add the part.
            if (fromVD == toVD)
            {
                if (!toVD.parts.ContainsKey(data.from.flightID))
                {
                    toVD.parts.Add(data.from.flightID, new PartData(data.from));
                    Lib.LogDebug("VesselData : newly created part '{0}' added to vessel '{1}'", data.from.partInfo.title, data.to.vessel.vesselName);
                }
                return;
            }

            // add all partdata of the docking vessel to the docked to vessel
            foreach (PartData partData in fromVD.parts.Values)
            {
                toVD.parts.Add(partData.FlightId, partData);
            }
            // remove all partdata from the docking vessel
            fromVD.parts.Clear();

            // reset a few things on the docked to vessel
            toVD.supplies.Clear();
            toVD.scansat_id.Clear();
            toVD.UpdateOnVesselModified();

            Lib.LogDebug("Coupling complete to   vessel, vd.partcount={1}, v.partcount={2} ({0})", toVessel.vesselName, toVD.parts.Count, toVessel.parts.Count);
            Lib.LogDebug("Coupling complete from vessel, vd.partcount={1}, v.partcount={2} ({0})", fromVessel.vesselName, fromVD.parts.Count, fromVessel.parts.Count);
        }