Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        public void OnFinishMission(LaunchEvent launch)
        {
            FinishMissionEvent endMission = new FinishMissionEvent();

            Vessel[] vessels = GameObject.FindObjectsOfType <Vessel>();
            Vessel   vessel  = null;

            foreach (var item in vessels)
            {
                if (item.id.ToString() == launch.shipID && item.vesselName == launch.shipName)
                {
                    vessel = item;
                }
            }
            if (vessel == null)
            {
                return;
            }
            float sumMass = 0;

            foreach (var part in vessel.protoVessel.protoPartSnapshots)
            {
                sumMass += part.mass;
            }
            endMission.finalMass   = sumMass;
            endMission.crewMembers = new List <string>();
            foreach (ProtoCrewMember kerbal in vessel.protoVessel.GetVesselCrew())
            {
                endMission.crewMembers.Add(kerbal.name);
            }
            launch.AddEvent(endMission);
        }
Пример #5
0
        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();
        }
Пример #6
0
        public void RecordMaxGee()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            LaunchEvent activeLaunch = GetLaunch(FlightGlobals.ActiveVessel);

            if (activeLaunch != null)
            {
                MaxGeeEvent maxGeeEv = new MaxGeeEvent();
                maxGeeEv.gee = activeLaunch.maxGee;
                if (activeLaunch.maxGee > activeLaunch.GetEventMaxGee())
                {
                    activeLaunch.AddEvent(maxGeeEv);
                }

                foreach (ProtoCrewMember kerbal in FlightGlobals.ActiveVessel.GetVesselCrew())
                {
                    LaunchCrewEvent crewLaunch = GetKerbalLaunch(kerbal.name);
                    if (crewLaunch.maxGee < activeLaunch.maxGee)
                    {
                        MaxGeeCrewEvent geeEv = new MaxGeeCrewEvent();
                        geeEv.gee = activeLaunch.maxGee;
                        if (crewLaunch.GetEventMaxGee() < activeLaunch.maxGee)
                        {
                            crewLaunch.AddEvent(geeEv);
                        }
                    }
                }
            }
        }
Пример #7
0
        internal void OnScienceReceived(float data0, ScienceSubject data1, ProtoVessel data2, bool data3)
        {
            LaunchEvent  launch       = GetLaunchByVesselId(data2.vesselID.ToString());
            ScienceEvent scienceEvent = new ScienceEvent();

            scienceEvent.title         = data1.title;
            scienceEvent.sciencePoints = data0;
            launch.AddEvent(scienceEvent);
        }
Пример #8
0
        internal void UpdateDynamic()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            LaunchEvent activeLaunch = GetLaunch(FlightGlobals.ActiveVessel);

            if (activeLaunch != null)
            {
                ProtoVessel item = FlightGlobals.ActiveVessel.protoVessel;
                double      currentVesselSpeed = item.vesselRef.obt_speed;
                if (item.situation == Vessel.Situations.FLYING || item.situation == Vessel.Situations.PRELAUNCH)
                {
                    currentVesselSpeed = item.vesselRef.srfSpeed;
                }
                if (currentVesselSpeed > activeLaunch.maxSpeed)
                {
                    activeLaunch.maxSpeed = currentVesselSpeed;
                }

                if (activeLaunch.maxGee < FlightGlobals.ActiveVessel.geeForce)
                {
                    activeLaunch.maxGee = FlightGlobals.ActiveVessel.geeForce;
                }
                foreach (ProtoCrewMember kerbal in FlightGlobals.ActiveVessel.GetVesselCrew())
                {
                    LaunchCrewEvent crewLaunch = GetKerbalLaunch(kerbal.name);
                    if (crewLaunch.maxGee < FlightGlobals.ActiveVessel.geeForce)
                    {
                        crewLaunch.maxGee = FlightGlobals.ActiveVessel.geeForce;
                    }
                }

                if (activeLaunch.GetLastEvent() is LandingEvent)
                {
                    double altitude = FlightGlobals.ActiveVessel.RevealAltitude();
                    if (altitude - FlightGlobals.ActiveVessel.terrainAltitude > 10)
                    {
                        activeLaunch.AddEvent(new FlyingEvent());
                    }
                }
                float currentMass = 0;
                foreach (var part in FlightGlobals.ActiveVessel.parts)
                {
                    currentMass += part.GetResourceMass() + part.mass;
                }
                activeLaunch.currentMass = currentMass;
            }
        }
Пример #9
0
        private void RecordLaunch(Vessel vessel)
        {
            LaunchEvent launch = new LaunchEvent();

            launch.shipName = vessel.protoVessel.vesselName;
            if (launch.shipName == null)
            {
                launch.shipName = "Just decoupled";
            }
            launch.shipID     = vessel.id.ToString();
            launch.rootPartID = vessel.rootPart.flightID.ToString();
            launch.time       = GetTimeInTicks();
            launch.parts      = new List <StatisticVehiclePart>();
            float sumCost    = 0;
            float launchMass = 0;

            foreach (var part in vessel.parts)
            {
                sumCost    += part.partInfo.cost;
                launchMass += part.GetResourceMass() + part.mass;
                StatisticVehiclePart vehiclePart = new StatisticVehiclePart();
                vehiclePart.partID = part.flightID.ToString();

                var modules = part.Modules.GetModules <ModuleCommand>();
                if (modules.Count > 0)
                {
                    vehiclePart.partType = PartType.CommandPod;
                    launch.parts.Add(vehiclePart);
                }
                else
                {
                    vehiclePart.partType = PartType.Other;
                    //launch.parts.Add(vehiclePart);
                }
            }
            launch.crewMembers = new List <string>();
            foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
            {
                launch.crewMembers.Add(kerbal.name);
            }
            launch.launchCost = sumCost;
            launch.launchMass = launchMass;

            SOIChangeEvent soiInitial = new SOIChangeEvent();

            soiInitial.mass    = launchMass;
            soiInitial.soiName = vessel.mainBody.name;
            launch.AddEvent(soiInitial);

            launches.Add(launch);
        }
Пример #10
0
        public void RecordOrbitReaching(Vessel vessel)
        {
            OrbitReachingEvent orbitEvent = new OrbitReachingEvent();

            orbitEvent.massOnOrbit = 0;
            foreach (var part in vessel.parts)
            {
                orbitEvent.massOnOrbit += part.GetResourceMass() + part.mass;
            }
            LaunchEvent launch = GetLaunch(vessel);

            if (launch != null)
            {
                launch.AddEvent(orbitEvent);
            }
        }
Пример #11
0
        public void OnVesselSOIChanged(GameEvents.HostedFromToAction <Vessel, CelestialBody> data)
        {
            SOIChangeEvent soiChange = new SOIChangeEvent();

            soiChange.mass = 0;
            foreach (var part in data.host.parts)
            {
                soiChange.mass += part.GetResourceMass() + part.mass;
            }
            soiChange.soiName = data.host.mainBody.name;
            LaunchEvent launch = GetLaunch(data.host);

            if (launch != null)
            {
                launch.AddEvent(soiChange);
            }
        }
Пример #12
0
        public void RecordMaxSpeed()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return;
            }
            LaunchEvent activeLaunch = GetLaunch(FlightGlobals.ActiveVessel);

            if (activeLaunch != null)
            {
                MaxSpeedEvent maxSpEv = new MaxSpeedEvent();
                maxSpEv.speed = activeLaunch.maxSpeed;
                if (activeLaunch.GetEventMaxSpeed() < activeLaunch.maxSpeed)
                {
                    activeLaunch.AddEvent(maxSpEv);
                }
            }
        }
Пример #13
0
        private void RecordStableOrbit(Vessel vessel)
        {
            LaunchEvent launch = GetLaunch(vessel);

            if (launch != null)
            {
                StableOrbitEvent stableEvent = new StableOrbitEvent();
                stableEvent.mass = 0;
                foreach (var part in vessel.parts)
                {
                    stableEvent.mass += part.GetResourceMass() + part.mass;
                }

                launch.AddEvent(stableEvent);
            }

            /*if (FlightGlobals.ActiveVessel == null) return;
             * FlightGlobals.ActiveVessel.*/
        }
Пример #14
0
        internal void OnCrewOnEva(GameEvents.FromToAction <Part, Part> data)
        {
            if (VesselType.EVA != data.to.vessel.vesselType)
            {
                return;
            }
            LaunchCrewEvent crewLaunch   = GetKerbalLaunch(data.to.vessel.vesselName);
            EvaCrewEvent    evaCrewEvent = new EvaCrewEvent();

            crewLaunch.AddEvent(evaCrewEvent);

            LaunchEvent launch = GetLaunch(data.from.vessel);

            if (launch != null)
            {
                EvaEvent evaEvent = new EvaEvent();
                launch.AddEvent(evaEvent);
            }
        }
Пример #15
0
        public void OnPartCouple(GameEvents.FromToAction <Part, Part> action)
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            Part from = action.from;
            Part to   = action.to;

            if (from == null || from.vessel == null || from.vessel.isEVA || from.vessel.parts.Count == 1)
            {
                return;
            }
            if (to == null || to.vessel == null || to.vessel.isEVA || to.vessel.parts.Count == 1)
            {
                return;
            }

            Vessel vessel = action.from.vessel.isActiveVessel ? action.from.vessel : action.to.vessel;

            if (action.from.vessel != null && action.to.vessel != null)
            {
                DockingEvent dockingFrom = new DockingEvent();
                LaunchEvent  launchFrom  = GetLaunch(action.from.vessel);
                if (launchFrom != null)
                {
                    launchFrom.AddEvent(dockingFrom);
                }

                DockingEvent dockingTo = new DockingEvent();
                LaunchEvent  launchTo  = GetLaunch(action.to.vessel);
                if (launchTo != null)
                {
                    launchTo.AddEvent(dockingTo);
                }

                RecordCrewDockingEvent(action.from.vessel, action.to.vessel);
            }
        }
Пример #16
0
        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();
        }
Пример #17
0
        public void RecordLanding(Vessel vessel)
        {
            if (vessel.isEVA)
            {
                return;
            }
            LandingEvent landing = new LandingEvent();

            landing.mainBodyName = vessel.mainBody.name;
            landing.biome        = getBiomeName(vessel.mainBody, vessel.longitude, vessel.latitude);
            LaunchEvent launch = GetLaunch(vessel);

            if (launch != null)
            {
                FlightEvent flightEvent = launch.GetLastEvent();
                if (flightEvent is EvaEvent && (landing.time - flightEvent.time) / TimeSpan.TicksPerSecond < 1)
                {
                    return;
                }
                if (flightEvent is LandingEvent)
                {
                    if (((landing.time - flightEvent.time) / TimeSpan.TicksPerSecond < 2))
                    {
                        return;
                    }
                }
                launch.AddEvent(landing);
            }


            foreach (ProtoCrewMember kerbal in vessel.GetVesselCrew())
            {
                LandingCrewEvent landingCrewEvent = new LandingCrewEvent();
                LaunchCrewEvent  crewLaunch       = GetKerbalLaunch(kerbal.name);
                crewLaunch.AddEvent(landingCrewEvent);
            }
        }