internal void OnBeforeSave()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            var         state  = FlightGlobals.ActiveVessel.state;
            LaunchEvent launch = GetLaunchByVesselId(FlightGlobals.ActiveVessel.id.ToString());

            if (launch != null)
            {
                RecordMaxSpeed();
                RecordMaxGee();
            }
            if (launch != null && state == Vessel.State.DEAD)
            {
                if (launch.GetLastEvent() is EndFlightEvent)
                {
                    return;
                }
                VesselDestroyedEvent destroyed = new VesselDestroyedEvent();
                launch.AddEvent(destroyed);

                EndFlightEvent endFlight = new EndFlightEvent();
                endFlight.finalMass   = 0;
                endFlight.crewMembers = new List <string>();
                launch.AddEvent(endFlight);
            }
        }
        internal void OnVesselTerminated(ProtoVessel data)
        {
            LaunchEvent launch = GetLaunchByVesselId(data.vesselID.ToString());

            if (launch != null)
            {
                VesselDestroyedEvent destroyed = new VesselDestroyedEvent();
                launch.AddEvent(destroyed);

                EndFlightEvent endFlight = new EndFlightEvent();
                float          sumMass   = 0;
                foreach (var part in data.protoPartSnapshots)
                {
                    sumMass += part.mass;
                }
                endFlight.finalMass   = sumMass;
                endFlight.crewMembers = new List <string>();
                foreach (ProtoCrewMember kerbal in data.GetVesselCrew())
                {
                    endFlight.crewMembers.Add(kerbal.name);
                }

                launch.AddEvent(endFlight);
            }
        }
        internal void OnCrash(EventReport data)
        {
            LaunchEvent launch = null;

            foreach (var part in data.origin.attachNodes)
            {
                if (launch != null)
                {
                    break;
                }
                launch = GetLaunchByRootPartId(data.origin.flightID.ToString());
            }


            if (launch != null)
            {
                VesselDestroyedEvent destroyed = new VesselDestroyedEvent();
                launch.AddEvent(destroyed);

                EndFlightEvent endFlight = new EndFlightEvent();
                endFlight.finalMass   = 0;
                endFlight.crewMembers = new List <string>();
                launch.AddEvent(endFlight);
            }
        }
        public void OnVesselRecoveryRequested(Vessel vessel)
        {
            long currentEndTime = GetTimeInTicks();

            EndFlightEvent endFlight = new EndFlightEvent();

            endFlight.time      = currentEndTime;
            endFlight.finalMass = 0;

            foreach (var part in vessel.parts)
            {
                endFlight.finalMass += part.GetResourceMass() + part.mass;
            }
            endFlight.crewMembers = new List <string>();
            foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
            {
                endFlight.crewMembers.Add(kerbal.name);
            }

            LaunchEvent launch = GetLaunch(vessel);

            launch.shipID = vessel.id.ToString();
            if (launch != null)
            {
                launch.AddEvent(endFlight);
            }

            foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
            {
                EndFlightCrewEvent crewEndFlight = new EndFlightCrewEvent();
                crewEndFlight.time = currentEndTime;
                GetKerbalLaunch(kerbal.name).AddEvent(crewEndFlight);
            }
            FlightGUI.SaveData();
        }
        internal void OnEndFlight(ProtoVessel protoVessel, bool data1)
        {
            LaunchEvent launch = GetLaunchByVesselId(protoVessel.vesselID.ToString());

            if (launch == null || launch.GetLastEvent() is EndFlightEvent)
            {
                return;
            }
            EndFlightEvent endFlight = new EndFlightEvent();

            endFlight.finalMass = 0;
            foreach (var part in protoVessel.protoPartSnapshots)
            {
                endFlight.finalMass += part.mass;
            }
            endFlight.crewMembers = new List <string>();
            foreach (var kerbal in protoVessel.GetVesselCrew())
            {
                endFlight.crewMembers.Add(kerbal.name);
            }
            launch.AddEvent(endFlight);
            FlightGUI.SaveData();
        }