public void InformationTab() { GUILayout.BeginHorizontal(); GUI.skin.label.fontSize = 16; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Vessel Information", GUILayout.Width(290)); GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUI.skin.label.fontSize = 12; GUILayout.EndHorizontal(); GUILayout.BeginVertical(); // 1.5.2 Filtering // GUILayout.Space(3); GUILayout.BeginHorizontal(); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_unmannedtech", false))) { if (FilterTypes.Contains(VesselType.Probe)) { FilterTypes.Remove(VesselType.Probe); } else { FilterTypes.Add(VesselType.Probe); } } GUILayout.Space(3); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_advunmanned", false))) { if (FilterTypes.Contains(VesselType.Relay)) { FilterTypes.Remove(VesselType.Relay); } else { FilterTypes.Add(VesselType.Relay); } } GUILayout.Space(3); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/RDicon_commandmodules", false))) { if (FilterTypes.Contains(VesselType.Ship)) { FilterTypes.Remove(VesselType.Ship); } else { FilterTypes.Add(VesselType.Ship); } } GUILayout.Space(3); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_specializedconstruction", false))) { if (FilterTypes.Contains(VesselType.Station)) { FilterTypes.Remove(VesselType.Station); } else { FilterTypes.Add(VesselType.Station); } } GUILayout.Space(3); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/RDicon_telescope", false))) { if (FilterTypes.Contains(VesselType.SpaceObject)) { FilterTypes.Remove(VesselType.SpaceObject); } else { FilterTypes.Add(VesselType.SpaceObject); } if (FilterTypes.Contains(VesselType.Unknown)) { FilterTypes.Remove(VesselType.Unknown); } else { FilterTypes.Add(VesselType.Unknown); } } GUILayout.Space(3); if (GUILayout.Button(GameDatabase.Instance.GetTexture("Squad/PartList/SimpleIcons/R&D_node_icon_composites", false))) { if (FilterTypes.Contains(VesselType.Debris)) { FilterTypes.Remove(VesselType.Debris); } else { FilterTypes.Add(VesselType.Debris); } } GUILayout.Space(3); GUILayout.EndHorizontal(); GUILayout.Space(3); GUILayout.Label("_______________________________________"); GUILayout.EndVertical(); scrollPosition1 = GUILayout.BeginScrollView(scrollPosition1, GUILayout.Width(290), GUILayout.Height(350)); bool Realistic = Settings.ReadRD(); bool ClockType = Settings.Read24Hr(); //151var Resource = Settings.ReadStationKeepingResource(); foreach (Vessel vessel in FlightGlobals.Vessels) { if (FilterTypes.Contains(vessel.vesselType)) { if (vessel.situation == Vessel.Situations.ORBITING) { string StationKeeping = VesselData.FetchStationKeeping(vessel).ToString(); string StationKeepingFuelRemaining = ResourceManager.GetResources(vessel).ToString("F3"); string Resource = ResourceManager.GetResourceNames(vessel); string ButtonText = ""; double HoursInDay = 6.0; double DaysInYear = 0; bool KerbinTime = GameSettings.KERBIN_TIME; if (KerbinTime) { DaysInYear = 9203545 / (60 * 60 * HoursInDay); } else { DaysInYear = 31557600 / (60 * 60 * HoursInDay); } if (StationKeeping == "True") { ButtonText = "Disable Station Keeping"; } else { ButtonText = "Enable Station Keeping"; } if (ClockType) { HoursInDay = 24.0; } else { HoursInDay = 6.0; } GUILayout.BeginVertical(); // GUILayout.Label("Vessels count" + VesselData.VesselInformation.CountNodes.ToString()); GUILayout.Label("Vessel Name: " + vessel.vesselName); // GUILayout.Label("Vessel Area: " + VesselData.FetchArea(vessel).ToString()); // GUILayout.Label("Vessel Mass: " + VesselData.FetchMass(vessel).ToString()); GUILayout.Space(2); GUILayout.Label("Orbiting Body: " + vessel.orbitDriver.orbit.referenceBody.GetName()); GUILayout.Space(2); if (StationKeeping == "True") { GUILayout.Label("Current Total Decay Rate: Vessel is Station Keeping"); GUILayout.Space(2); } else { double TotalDecayRatePerSecond = Math.Abs(DecayManager.DecayRateAtmosphericDrag(vessel)) + Math.Abs(DecayManager.DecayRateRadiationPressure(vessel)) + Math.Abs(DecayManager.DecayRateYarkovskyEffect(vessel)); //+ Math.Abs(DecayManager.DecayRateGravitationalPertubation(vessel)); double ADDR = DecayManager.DecayRateAtmosphericDrag(vessel); double GPDR = DecayManager.DecayRateGravitationalPertubation(vessel); double PRDR = DecayManager.DecayRateRadiationPressure(vessel); double YEDR = DecayManager.DecayRateYarkovskyEffect(vessel); GUILayout.Label("Current Total Decay Rate: " + FormatDecayRateToString(TotalDecayRatePerSecond)); GUILayout.Space(2); if (GUILayout.Button("Toggle Decay Rate Breakdown")) // Display a new window here? { subwindowVessel = vessel; DecayBreakdownVisible = !DecayBreakdownVisible; } // 1.7.0 maybe? if (Settings.ReadNB()) { GUILayout.Space(2); if (GUILayout.Button("Toggle NBody Breakdown")) // New Window for NBody { subwindowVessel = vessel; NBodyVesselAccelTimes.Clear(); NBodyBreakdownVisible = !NBodyBreakdownVisible; } } GUILayout.Space(2); double TimeUntilDecayInUnits = 0.0; string TimeUntilDecayInDays = ""; if (ADDR != 0) { TimeUntilDecayInUnits = DecayManager.DecayTimePredictionExponentialsVariables(vessel); TimeUntilDecayInDays = FormatTimeUntilDecayInDaysToString(TimeUntilDecayInUnits); } else { TimeUntilDecayInUnits = DecayManager.DecayTimePredictionLinearVariables(vessel); TimeUntilDecayInDays = FormatTimeUntilDecayInSecondsToString(TimeUntilDecayInUnits); } GUILayout.Label("Approximate Time Until Decay: " + TimeUntilDecayInDays); GUILayout.Space(2); } GUILayout.Label("Station Keeping: " + StationKeeping); GUILayout.Space(2); GUILayout.Label("Station Keeping Fuel Remaining: " + StationKeepingFuelRemaining); GUILayout.Space(2); GUILayout.Label("Using Fuel Type: " + Resource); //151 GUILayout.Space(2); //151 if (StationKeeping == "True") { double DecayRateSKL = 0; DecayRateSKL = DecayManager.DecayRateAtmosphericDrag(vessel) + DecayManager.DecayRateRadiationPressure(vessel) + DecayManager.DecayRateYarkovskyEffect(vessel); double StationKeepingLifetime = double.Parse(StationKeepingFuelRemaining) / (DecayRateSKL / TimeWarp.CurrentRate * VesselData.FetchEfficiency(vessel) /*ResourceManager.GetEfficiency(Resource)*/ * Settings.ReadResourceRateDifficulty()) / (60 * 60 * HoursInDay); if (StationKeepingLifetime < -5) // SRP Fixes { GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years."); } else { if (StationKeepingLifetime > 365000 && HoursInDay == 24) { GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years."); } else if (StationKeepingLifetime > 425000 && HoursInDay == 6) { GUILayout.Label("Station Keeping Fuel Lifetime: > 1000 years."); } else { if (StationKeepingLifetime > 425 && HoursInDay == 6) { GUILayout.Label("Station Keeping Fuel Lifetime: " + (StationKeepingLifetime / 425).ToString("F1") + " years."); } else if (StationKeepingLifetime > 365 && HoursInDay == 24) { GUILayout.Label("Station Keeping Fuel Lifetime: " + (StationKeepingLifetime / 365).ToString("F1") + " years."); } else { GUILayout.Label("Station Keeping Fuel Lifetime: " + StationKeepingLifetime.ToString("F1") + " days."); } } } GUILayout.Space(3); } if (GUILayout.Button(ButtonText)) { if (StationKeeping == "True") { VesselData.UpdateStationKeeping(vessel, false); ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + ": Station Keeping Disabled"); } if (StationKeeping == "False") { if (StationKeepingManager.EngineCheck(vessel)) { if (double.Parse(StationKeepingFuelRemaining) > 0.01) // Good enough... { VesselData.UpdateStationKeeping(vessel, true); ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + ": Station Keeping Enabled"); } else { ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + " has no fuel to Station Keep!"); } } else { ScreenMessages.PostScreenMessage("Vessel: " + vessel.vesselName + " has no Engines or RCS modules on board!"); } } } GUILayout.Space(2); GUILayout.Label("_____________________________________"); GUILayout.Space(3); GUILayout.EndVertical(); } } } GUILayout.EndScrollView(); }
public void ToggleSK() { VesselData.UpdateStationKeeping(vessel, VesselData.FetchStationKeeping(vessel)); stationKeepData.IsStationKeeping = !stationKeepData.IsStationKeeping; updatedisplayedData(); }
public void FetchEngineData() { double amount = 0; bool engineIsListed; EngineData.RemoveNodes("ENGINE"); foreach (ModuleEngines module in vessel.FindPartModulesImplementing <ModuleEngines>()) { engineIsListed = false; foreach (ConfigNode engineNode in EngineData.GetNodes()) { //ugly names used - can't find way to get editor part names if (engineNode.GetValue("name") != module.part.protoPartSnapshot.partInfo.title) { continue; } engineIsListed = true; break; } if (module.EngineIgnited && !engineIsListed) { ConfigNode engineNode = new ConfigNode("ENGINE"); engineNode.AddValue("name", module.part.protoPartSnapshot.partInfo.title);//ugly names used - can't find way to get editor part names engineNode.AddValue("ISP", module.atmosphereCurve.Evaluate(0).ToString()); foreach (Propellant propellant in module.propellants) { if (propellant.name == "ElectricCharge") { continue; } ConfigNode propellantNode = new ConfigNode("PROPELLANT"); //amount = module.part.Resources.Get(propellant.id).amount; amount = fetchPartResource(module.part, propellant.id, ResourceFlowMode.STAGE_PRIORITY_FLOW); propellantNode.AddValue("name", propellant.name); propellantNode.AddValue("id", propellant.id.ToString()); propellantNode.AddValue("ratio", propellant.ratio.ToString()); propellantNode.AddValue("Available", amount.ToString()); engineNode.AddNode(propellantNode); } EngineData.AddNode(engineNode); if (!stationKeepData.IsStationKeeping || !(module.currentThrottle > 0.0)) { continue; } ScreenMessages.PostScreenMessage("Warning: Vessel is under thrust, station keeping disabled."); VesselData.UpdateStationKeeping(vessel, false); } } foreach (ModuleRCS module in vessel.FindPartModulesImplementing <ModuleRCS>()) { engineIsListed = false; foreach (ConfigNode engineNode in EngineData.GetNodes()) { if (engineNode.GetValue("name") != module.part.protoPartSnapshot.partInfo.title) { continue; } engineIsListed = true; break; } if (!module.rcsEnabled || engineIsListed) { continue; } ConfigNode newEngineNode = new ConfigNode("ENGINE"); newEngineNode.AddValue("name", module.part.protoPartSnapshot.partInfo.title); newEngineNode.AddValue("ISP", module.atmosphereCurve.Evaluate(0).ToString()); foreach (Propellant propellant in module.propellants) { if (propellant.name == "ElectricCharge") { continue; } ConfigNode newPropellantNode = new ConfigNode("PROPELLANT"); //amount = module.part.Resources.Get(propellant.id).amount //amount = amount = fetchPartResource(module.part, propellant.id, ResourceFlowMode.STAGE_PRIORITY_FLOW); newPropellantNode.AddValue("name", propellant.name); newPropellantNode.AddValue("id", propellant.id.ToString()); newPropellantNode.AddValue("ratio", propellant.ratio.ToString()); newPropellantNode.AddValue("Available", amount.ToString()); newEngineNode.AddNode(newPropellantNode); } EngineData.AddNode(newEngineNode); } }
public override void OnUpdate() { if (stationKeepData.IsStationKeeping && vessel == FlightGlobals.ActiveVessel) { foreach (ModuleEngines module in vessel.FindPartModulesImplementing <ModuleEngines>()) { if (!(module.currentThrottle > 0)) { continue; } ScreenMessages.PostScreenMessage("Warning: Vessel is under thrust, station keeping disabled."); VesselData.UpdateStationKeeping(vessel, false); break; } } if (!(Time.time - lastUpdate > UPTInterval)) { return; } lastUpdate = Time.time; FetchEngineData(); List <string> namelist = new List <string>(); if (EngineData.HasNode("ENGINE")) { foreach (ConfigNode engine in EngineData.GetNodes("ENGINE")) { namelist.Add(engine.GetValue("name")); } EngineList = new string[namelist.Count]; EngineList = namelist.ToArray(); } else { EngineList = new string[] { "None Available" }; } updatedisplayedData(); for (int i = 0; i < stationKeepData.resources.Count(); i++) { float ratio1 = 10 * stationKeepData.ratios[i]; for (int j = 0; j < stationKeepData.resources.Count(); j++) { float ratio2 = 10 * stationKeepData.ratios[j]; if (stationKeepData.amounts[i] / ratio1 < stationKeepData.amounts[j] / ratio2) { stationKeepData.amounts[j] = stationKeepData.amounts[i] / ratio1 * ratio2; } /*equalizing fuel amount to comply with consumption ratios * without mutliplying ratios by 10 result is acurate only to 4th position after digital point * or 7th position in total for huge amounts of fuel * 179.999991330234 instead of 180 - tremendous error, i know ;) * tried casting double type to each variable in equasion * bu multiplying ratios seems to be only working solution * its a math issue/limitation encountered in multiple compilers * *************************************************************/ } } StationKeepResources = ""; amounts = ""; ISP = stationKeepData.ISP; StationKeepResources += stationKeepData.resources[0]; amounts += stationKeepData.amounts[0].ToString("F3"); for (int i = 1; i < stationKeepData.resources.Count(); i++) { StationKeepResources += ' ' + stationKeepData.resources[i]; amounts += ' ' + stationKeepData.amounts[i].ToString("F3"); } }
public static void FuelManager(Vessel vessel) { string ResourceName = ""; ResourceName = ResourceManager.GetResourceNames(vessel); double CurrentFuel = 0; CurrentFuel = ResourceManager.GetResources(vessel); double ResourceEfficiency = VesselData.FetchEfficiency(vessel);// effi calculation based on vessel engine ISP stored in stationKeepData.ISP NEED ballance double LostFuel = 0.0; LostFuel = Math.Abs(DecayManager.DecayRateAtmosphericDrag(vessel) + DecayManager.DecayRateRadiationPressure(vessel) + DecayManager.DecayRateYarkovskyEffect(vessel)) * Settings.ReadResourceRateDifficulty() * ResourceEfficiency; // * Fuel Multiplier double FuelNew = CurrentFuel - LostFuel; // Remote tech compatibility - 1.6.0 // bool RemoteTechInstalled = LoadingCheck.RemoteTechInstalled; bool SignalCheck = false; bool ConnectionToVessel = true; if (RemoteTechInstalled) { // Add Part Module Checks Here // Maybe 1.6.0 if (ConnectionToVessel == false) { SignalCheck = false; ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has no connection to send Station Keeping command!"); VesselData.UpdateStationKeeping(vessel, false); } } else { SignalCheck = true; } if (!SignalCheck) { return; } if (EngineCheck(vessel) == false) // 1.3.0 { ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has no operational Engines or RCS modules, Station Keeping disabled."); VesselData.UpdateStationKeeping(vessel, false); } else if (EngineCheck(vessel)) { if (FuelNew <= 0) { ScreenMessages.PostScreenMessage("Warning: " + vessel.vesselName + " has run out of " + ResourceName + ", Station Keeping disabled."); VesselData.UpdateStationKeeping(vessel, false); VesselData.UpdateVesselFuel(vessel, 0); } else { VesselData.UpdateVesselFuel(vessel, FuelNew); ResourceManager.RemoveResources(vessel, LostFuel); } } }