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); } }
internal void Revert() { bool removed = false; long currentTime = GetTimeInTicks(); if (currentTime <= 10000000) { return; } int removedCount = launches.RemoveAll(x => x.time > currentTime); foreach (var launch in launches) { removed = launch.Revert(currentTime); } removedCount += crewLaunches.RemoveAll(x => x.time > currentTime); foreach (var kerbal in crewLaunches) { removed = kerbal.Revert(currentTime) || removed; } if (FlightGlobals.ActiveVessel == null) { return; } LaunchEvent activeLaunch = GetLaunch(FlightGlobals.ActiveVessel); if (activeLaunch != null) { activeLaunch.maxSpeed = activeLaunch.GetEventMaxSpeed(); activeLaunch.maxGee = activeLaunch.GetEventMaxGee(); } }
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); } } } } }
internal void OnVesselSeparate(Vessel vessel) { LaunchEvent launch = GetLaunch(vessel); int cmdPodsCount = 0; foreach (var part in vessel.parts) { var modules = part.Modules.GetModules <ModuleCommand>(); if (modules.Count > 0) { cmdPodsCount++; } } if (launch != null && launch.parts.Count > cmdPodsCount) { foreach (var part in vessel.parts) { var modules = part.Modules.GetModules <ModuleCommand>(); if (modules.Count > 0) { launch.parts.RemoveAll((StatisticVehiclePart statisticPart) => { return(statisticPart.partID == part.flightID.ToString()); }); } } RecordLaunch(vessel); } }
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 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); } }
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); }
internal void OnVesselRename(GameEvents.HostedFromToAction <Vessel, string> data) { LaunchEvent launch = GetLaunch(data.host); if (launch != null) { launch.shipName = data.to; } }
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); }
internal void OnCrewChanged(EventReport killedData) { LaunchEvent launch = GetLaunch(killedData.origin.vessel); if (launch != null) { launch.checkCrew(); } //throw new NotImplementedException(); }
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; } }
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); }
internal void OnCrewChanged(GameEvents.FromToAction <Part, Part> evaBoardData) { LaunchEvent launch = GetLaunch(evaBoardData.from.vessel); if (launch != null) { launch.checkCrew(); } launch = GetLaunch(evaBoardData.to.vessel); if (launch != null) { launch.checkCrew(); } }
internal void OnCrewChanged(GameEvents.HostedFromToAction <ProtoCrewMember, Part> transferredData) { LaunchEvent launch = GetLaunch(transferredData.from.vessel); if (launch != null) { launch.checkCrew(); } launch = GetLaunch(transferredData.to.vessel); if (launch != null) { launch.checkCrew(); } }
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); } }
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); } }
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); } } }
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); } }
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.*/ }
private void ProcessPopup() { string newHover = GUI.tooltip; if (newHover != "") { Debug.Log(newHover); } if (Event.current.type == EventType.Repaint && newHover != hover) { hover = newHover; if (hover == "Masses") { LaunchEvent launch = EventProcessor.Instance.launches[flightIdToShow]; popupTexts = launch.GetMasses(); showPopup = true; } else if (hover == "Biomes") { LaunchEvent launch = EventProcessor.Instance.launches[flightIdToShow]; popupTexts = launch.GetBiomes(); showPopup = true; } else if (hover == "Science points") { LaunchEvent launch = EventProcessor.Instance.launches[flightIdToShow]; popupTexts = launch.GetExperiments(); showPopup = true; } else { showPopup = false; } popupWindowRect.height = 1; popupWindowRect.width = 1; } popupWindowRect.x = Input.mousePosition.x; popupWindowRect.y = Screen.height - Input.mousePosition.y; }
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); } }
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(); }
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); } }
private void DrawFlightWindow(int id) { if (GUI.Button(new Rect(flightWindowRect.width - 28, 2, 25, 16), "X")) { needToShowFlight = false; } List <LaunchEvent> launches = EventProcessor.Instance.launches.GetRange(0, EventProcessor.Instance.launches.Count); /*if (reverseFlights) * launches.Reverse();*/ LaunchEvent launch = launches[flightIdToShow]; if (!(launch.IsMissionFinished() || launch.GetLastEvent() is EndFlightEvent)) { if (GUI.Button(new Rect(5, flightWindowRect.height - 22, 100, 20), "Finish mission")) { EventProcessor.Instance.OnFinishMission(launch); } } Rect captionRect = new Rect(0, 2, flightWindowRect.width, 16); string txt = "Flight №" + launch.posInTable + " - " + launch.shipName; GUIStyle currentStyle; if (FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.id.ToString() == launch.shipID) { currentStyle = activeStyle; } else if (launch.IsDestroyed()) { currentStyle = destroyedStyle; } else if (launch.GetEndDate() != -1) { currentStyle = endedStyle; } else { currentStyle = proceedingStyle; } currentStyle.fontStyle = FontStyle.Bold; currentStyle.alignment = TextAnchor.MiddleCenter; GUI.Label(captionRect, txt, currentStyle); currentStyle.fontStyle = FontStyle.Normal; currentStyle.alignment = TextAnchor.MiddleLeft; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(100)); GUILayout.Label("Vessel", boldtext); GUILayout.Label("Launch date", boldtext); GUILayout.Label("Launch mass", boldtext); GUILayout.Label("Cost", boldtext); hintContent.text = "Close Orbit/SOI masses"; hintContent.tooltip = "Masses"; GUILayout.Label(hintContent, boldtext); GUILayout.Label("Docked", boldtext); GUILayout.Label("EVAs", boldtext); GUILayout.Label("Max speed", boldtext); GUILayout.Label("Max Gee", boldtext); hintContent.text = "Landings"; hintContent.tooltip = "Biomes"; GUILayout.Label(hintContent, boldtext); GUILayout.Label("End date", boldtext); GUILayout.Label("Duration", boldtext); GUILayout.Label("Final mass", boldtext); hintContent.text = "Science points"; hintContent.tooltip = "Science points"; GUILayout.Label(hintContent, boldtext); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Width(400)); GUILayout.Label(launch.shipName); GUILayout.Label(Utils.TicksToDate(launch.time)); GUILayout.Label(Utils.CorrectNumber(launch.launchMass.ToString(), 3)); GUILayout.Label(Utils.CorrectNumber(launch.launchCost.ToString())); float massOnOrbit = launch.GetMassOnOrbit(); string massOnOrbitText = "-"; if (massOnOrbit > 0) { massOnOrbitText = massOnOrbit.ToString(); } hintContent.text = Utils.CorrectNumber(massOnOrbitText); hintContent.tooltip = "Masses"; GUILayout.Label(hintContent); GUILayout.Label(launch.GetDockings().ToString()); GUILayout.Label(launch.GetEvas().ToString()); GUILayout.Label(Utils.CorrectNumber(launch.maxSpeed.ToString()) + "m/s"); GUILayout.Label(Utils.CorrectNumber(launch.maxGee.ToString()) + " G"); hintContent.text = launch.GetLandingsCount().ToString(); hintContent.tooltip = "Biomes"; GUILayout.Label(hintContent); long endDate = launch.GetEndDate(); if (endDate != -1) { GUILayout.Label(Utils.TicksToDate(endDate)); GUILayout.Label(Utils.TicksToTotalTime(launch.GetTotalFlightTime())); } else { GUILayout.Label("-"); GUILayout.Label(Utils.TicksToTotalTime(launch.GetTotalFlightTime())); } GUILayout.Label(Utils.CorrectNumber(launch.GetFinalMass().ToString(), 3)); float sciencePoints = launch.GetSciencePoints(); string sciencePointsText = "-"; if (sciencePoints > 0) { sciencePointsText = Utils.CorrectNumber(sciencePoints.ToString()); } hintContent.text = sciencePointsText; hintContent.tooltip = "Science points"; GUILayout.Label(sciencePointsText); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Box("SOI changes (dates, SOI names)"); scrollViewVector1 = GUILayout.BeginScrollView(scrollViewVector1, GUILayout.Height((flightWindowRect.height - 130) / 3)); List <FlightEvent> sois = launch.GetSOIChanges().ToArray().ToList <FlightEvent>(); sois.AddRange(launch.GetLandings()); sois.Sort(); foreach (FlightEvent record in sois) { if (record is SOIChangeEvent) { GUILayout.Label(Utils.TicksToDate(record.time) + " \t " + (record as SOIChangeEvent).soiName.ToString()); } else { GUILayout.Label(Utils.TicksToDate(record.time) + " \t Land:" + (record as LandingEvent).mainBodyName.ToString() + ":" + (record as LandingEvent).biome.ToString()); } } GUILayout.EndScrollView(); GUILayout.Box("Initial crew"); scrollViewVector2 = GUILayout.BeginScrollView(scrollViewVector2, GUILayout.Height((flightWindowRect.height - 130) / 3)); foreach (string crewMember in launch.crewMembers) { GUILayout.Label(crewMember); } GUILayout.EndScrollView(); GUILayout.Box("Final crew"); scrollViewVector3 = GUILayout.BeginScrollView(scrollViewVector3, GUILayout.Height((flightWindowRect.height - 130) / 3)); foreach (string crewMember in launch.GetFinalCrew()) { GUILayout.Label(crewMember); } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); ProcessPopup(); GUI.DragWindow(new Rect(0, 0, 10000, 20)); }