/// <summary> /// Test stock engines implementing standard modules ModuleEnginesFX and ModuleEngines /// </summary> /// <returns></returns> private EngineTestResult CheckStockEngines() { double powerRequired = 0; double maxThrustSum = 0; propellants.Clear(); // Get jet engines' modules List <Part> jets = new List <Part>(); for (int i = 0; i < vessel.parts.Count; i++) { var part = vessel.parts[i]; if (part.Modules.Contains("ModuleEnginesFX")) { jets.Add(part); } } for (int i = 0; i < jets.Count; i++) { List <ModuleEnginesFX> enginesFx = jets[i].FindModulesImplementing <ModuleEnginesFX>(); if (enginesFx != null) { for (int k = 0; k < enginesFx.Count; k++) { if (!enginesFx[k].engineShutdown && enginesFx[k].isOperational) { // Max thrust maxThrustSum += enginesFx[k].maxThrust * enginesFx[k].thrustPercentage / 100; // Propellants used in ISP computation - what is not used is usually air for (int p = 0; p < enginesFx[k].propellants.Count; p++) { if (!enginesFx[k].propellants[p].ignoreForIsp) { // For electric engines - save required power and don't add it to propellants if (enginesFx[k].propellants[p].name == "ElectricCharge") { powerRequired += enginesFx[k].getMaxFuelFlow(enginesFx[k].propellants[p]) * enginesFx[k].thrustPercentage / 100; continue; } var ir = propellants.Find(x => x.Name == enginesFx[k].propellants[p].name); if (ir == null) { ir = new Fuel(); ir.Name = enginesFx[k].propellants[p].name; propellants.Add(ir); } ir.FuelFlow += enginesFx[k].getMaxFuelFlow(enginesFx[k].propellants[p]) * enginesFx[k].thrustPercentage / 100; } } } } } } // Get rocket engines' modules List <Part> rockets = new List <Part>(); for (int i = 0; i < vessel.parts.Count; i++) { var part = vessel.parts[i]; if (part.Modules.Contains("ModuleEngines")) { rockets.Add(part); } } for (int i = 0; i < rockets.Count; i++) { List <ModuleEngines> engines = rockets[i].FindModulesImplementing <ModuleEngines>(); for (int k = 0; k < engines.Count; k++) { if (!engines[k].engineShutdown && engines[k].isOperational) { // Max thrust maxThrustSum += engines[k].MaxThrustOutputAtm(false, true, Convert.ToSingle(vessel.mainBody.atmPressureASL), vessel.atmosphericTemperature, vessel.mainBody.atmDensityASL); // Propellants used in ISP computation - what is not used is usually air for (int p = 0; p < engines[k].propellants.Count; p++) { if (!engines[k].propellants[p].ignoreForIsp) { var ir = propellants.Find(x => x.Name == engines[k].propellants[p].name); if (ir == null) { ir = new Fuel(); ir.Name = engines[k].propellants[p].name; propellants.Add(ir); } ir.FuelFlow += engines[k].getMaxFuelFlow(engines[k].propellants[p]) * engines[k].thrustPercentage / 100; } } } } } return(new EngineTestResult(maxThrustSum, powerRequired)); }
/// <summary> /// Load scenario details for each vessel with BV controller /// </summary> public void LoadScenario() { if (scenarioNode != null) { var controllers = BonVoyage.Instance.BVControllers; int count = controllers.Count; for (int i = 0; i < count; i++) { BVController controller = controllers[i]; if (controller.vessel != null) { ConfigNode controllerNode = scenarioNode.GetNode("CONTROLLER", "vesselId", controller.vessel.id.ToString()); if (controllerNode != null) { ConfigNode subNode = controllerNode.GetNode("BATTERIES"); if (subNode != null) { controller.batteries.UseBatteries = Convert.ToBoolean(subNode.GetValue("useBatteries")); controller.batteries.MaxUsedEC = Convert.ToDouble(subNode.GetValue("maxUsedEC")); controller.batteries.ECPerSecondConsumed = Convert.ToDouble(subNode.GetValue("ecPerSecondConsumed")); controller.batteries.ECPerSecondGenerated = Convert.ToDouble(subNode.GetValue("ecPerSecondGenerated")); controller.batteries.CurrentEC = Convert.ToDouble(subNode.GetValue("currentEC")); } subNode = controllerNode.GetNode("FUEL_CELLS"); if (subNode != null) { controller.fuelCells.Use = Convert.ToBoolean(subNode.GetValue("useFuelCells")); controller.fuelCells.OutputValue = Convert.ToDouble(subNode.GetValue("outputEC")); var resources = subNode.GetNodes("RESOURCE"); controller.fuelCells.InputResources.Clear(); for (int r = 0; r < resources.Length; r++) { Resource ir = new Resource(); ir.Name = resources[r].GetValue("name"); ir.Ratio = Convert.ToDouble(resources[r].GetValue("ratio")); ir.MaximumAmountAvailable = Convert.ToDouble(resources[r].GetValue("maximumAmount")); ir.CurrentAmountUsed = Convert.ToDouble(resources[r].GetValue("currentAmount")); controller.fuelCells.InputResources.Add(ir); } } subNode = controllerNode.GetNode("PROPELLANTS"); if (subNode != null) { var propellants = subNode.GetNodes("FUEL"); controller.propellants.Clear(); for (int r = 0; r < propellants.Length; r++) { Fuel ir = new Fuel(); ir.Name = propellants[r].GetValue("name"); ir.FuelFlow = Convert.ToDouble(propellants[r].GetValue("fuelFlow")); ir.MaximumAmountAvailable = Convert.ToDouble(propellants[r].GetValue("maximumAmount")); ir.CurrentAmountUsed = Convert.ToDouble(propellants[r].GetValue("currentAmount")); controller.propellants.Add(ir); } } } } } } }