//float currentThrottleState; private void updateEngineModule(bool calledByPlayer, string callingFunction = "player") { string[] arrtargetPropellants, arrtargetRatios, arrtargetIgnoreForISP, arrtargetDrawGuage; float targetRatio; bool targetIgnoreForISP; float maxISP = 0; float floatParseResult; ConfigNode newPropNode = new ConfigNode(); Utilities MiscFx = new Utilities(); PhysicsUtilities EngineCalc = new PhysicsUtilities(); writeScreenMessage(); foreach (var moduleEngine in ModuleEngines) { //Debug.Log("moduleEngine.isEnabled: " + moduleEngine.isEnabled); //moduleEngine.isEnabled = !moduleEngine.isEnabled; //Debug.Log("moduleEngine.isEnabled: " + moduleEngine.isEnabled); //bool engineState = false; //float ThrottleState; currentModuleEngine = moduleEngine; //Get the Ignition state, i.e. is the engine shutdown or activated currentEngineState = currentModuleEngine.getIgnitionState; ShutdownEngine(); //Deactivate effects to force KSP to update them as intended //currentModuleEngine.DeactivateLoopingFX(); //currentModuleEngine.DeactivatePowerFX(); //currentModuleEngine.DeactivateRunningFX(); //currentThrottleState = FlightInputHandler.state.mainThrottle; //FlightInputHandler.state.mainThrottle = 0f; //currentModuleEngine.useEngineResponseTime = false; //moduleEngine.maxFuelFlow = 0f; //Invoke("ShutdownEngine",2f); ////Get the Ignition state, i.e. is the engine shutdown or activated //engineState = currentModuleEngine.getIgnitionState; ////Shutdown the engine --> Removes the gauges, and make sense to do before changing propellant ////Debug.Log("engine shutdown"); //currentModuleEngine.Shutdown(); ////Debug.Log("1) FlightInputHandler.state.mainThrottle : " + FlightInputHandler.state.mainThrottle); //ThrottleState = FlightInputHandler.state.mainThrottle; //FlightInputHandler.state.mainThrottle = 0f; //StartCoroutine(wait()); //Debug.Log("2) FlightInputHandler.state.mainThrottle : " + FlightInputHandler.state.mainThrottle); moduleEngine.Flameout( message: "Switch Engine State", statusOnly: false, showFX: false); //Invoke("shortwait", 2f); //Debug.Log("engine shutdown completed"); //Split cfg subsettings into arrays arrtargetPropellants = propList[selectedPropellant].Propellants.Split(','); arrtargetRatios = propList[selectedPropellant].PropRatios.Split(','); arrtargetIgnoreForISP = propList[selectedPropellant].propIgnoreForISP.Split(','); arrtargetDrawGuage = propList[selectedPropellant].propDrawGauge.Split(','); //Create new propellent nodes by looping them in. for (int i = 0; i < arrtargetPropellants.Length; i++) { //Get and convert ratios to floats. They should already have been verified in the CustomTypes.PropellantList class targetRatio = Convert.ToSingle(arrtargetRatios[i]); //if ignoreForISP have been set wrong or not at all, then we config it to false if (arrtargetIgnoreForISP.Length == arrtargetPropellants.Length) { if (!bool.TryParse(arrtargetIgnoreForISP[i], out targetIgnoreForISP)) { targetIgnoreForISP = false; } //targetIgnoreForISP = arrtargetIgnoreForISP[i]; } else { targetIgnoreForISP = false; } //Debug.Log("!bool.TryParse(arrtargetIgnoreForISP[i], out targetIgnoreForISP)\ntargetIgnoreForISP: " + targetIgnoreForISP); ConfigNode propNode = newPropNode.AddNode("PROPELLANT"); propNode.AddValue("name", arrtargetPropellants[i]); propNode.AddValue("ratio", targetRatio); propNode.AddValue("ignoreForIsp", targetIgnoreForISP); //For now we assume all is counted for ISP //targetIgnoreForISP[i] propNode.AddValue("DrawGauge", arrtargetDrawGuage[i]); //I think the gauge should always be shown } //Update the engine with new propellant configuration //NOTICE: The original propellant nodes are overwritten, so we do not need to delete them moduleEngine.Load(newPropNode); //Debug.Log("Start of curve editing"); //Change the atmosphere curve (ISP) if (!atmosphereCurveEmpty) { //Debug.Log("Setting atmosphere Curve (ISP) " + atmosphereCurveKeys); moduleEngine.atmosphereCurve.Curve.keys = MiscFx.KeyFrameFromString( inKeys: propList[selectedPropellant].atmosphereCurve, iniKeys: moduleEngine.atmosphereCurve.Curve.keys ); } //Change the Velocity curve if (!velCurveEmpty) //(string.IsNullOrEmpty(velCurveKeys) || velCurveKeys.Trim().Length == 0)) { //Debug.Log("Setting Velocity Curve " + velCurveKeys); moduleEngine.velCurve.Curve.keys = MiscFx.KeyFrameFromString( inKeys: propList[selectedPropellant].velCurve, iniKeys: moduleEngine.velCurve.Curve.keys ); } //Change the Atm curve if (!atmCurveEmpty) //(string.IsNullOrEmpty(atmCurveKeys) || atmCurveKeys.Trim().Length == 0)) { //Debug.Log("Setting Atm Curve: "+ atmCurveKeys); moduleEngine.atmCurve.Curve.keys = MiscFx.KeyFrameFromString( inKeys: propList[selectedPropellant].atmCurve, iniKeys: moduleEngine.atmCurve.Curve.keys ); } //Set which curves to use if (!atmChangeFlowsEmpty) { moduleEngine.atmChangeFlow = bool.Parse(propList[selectedPropellant].atmChangeFlow); } if (!useVelCurvesEmpty) { moduleEngine.useVelCurve = bool.Parse(propList[selectedPropellant].useVelCurve); } if (!useAtmCurvesEmpty) { moduleEngine.useAtmCurve = bool.Parse(propList[selectedPropellant].useAtmCurve); } //Get maxISP from the atmosphere curve maxISP = MiscFx.KeyFrameGetMaxValue(moduleEngine.atmosphereCurve.Curve.keys); //moduleEngine.atmosphereCurve.FindMinMaxValue //Set max Thrust and the corresponding fuelflow if (!MaxThrustEmpty) { moduleEngine.maxThrust = propList[selectedPropellant].maxThrust; } //maxFuelFlow = engine.maxThrust / (engine.atmosphereCurve.Evaluate(0f) * engine.g) moduleEngine.maxFuelFlow = EngineCalc.calcFuelFlow( Thrust: moduleEngine.maxThrust, //Thrust: propList[selectedPropellant].maxThrust, //Density: propList[selectedPropellant].propDensity, ISP: maxISP ); if (Single.TryParse(propList[selectedPropellant].heatProduction, out floatParseResult) && !heatProductionEmpty) { moduleEngine.heatProduction = floatParseResult; } //Set the engine type //[LiquidFuel, Nuclear, SolidBooster, Turbine, MonoProp, ScramJet, Electric, Generic, Piston] if (!EngineTypesEmpty) { switch (propList[selectedPropellant].engineType) { case "LiquidFuel": moduleEngine.engineType = EngineType.LiquidFuel; break; case "Nuclear": moduleEngine.engineType = EngineType.Nuclear; break; case "SolidBooster": moduleEngine.engineType = EngineType.SolidBooster; break; case "Turbine": moduleEngine.engineType = EngineType.Turbine; break; case "MonoProp": moduleEngine.engineType = EngineType.MonoProp; break; case "ScramJet": moduleEngine.engineType = EngineType.ScramJet; break; case "Electric": moduleEngine.engineType = EngineType.Electric; break; case "Generic": moduleEngine.engineType = EngineType.Generic; break; case "Piston": moduleEngine.engineType = EngineType.Piston; break; default: moduleEngine.engineType = EngineType.LiquidFuel; break; } } moduleEngine.useEngineResponseTime = useEngineResponseTimeEmpty ? false : bool.Parse(propList[selectedPropellant].useEngineResponseTime); moduleEngine.engineAccelerationSpeed = engineAccelerationSpeedEmpty ? 0 : Single.Parse(propList[selectedPropellant].engineAccelerationSpeed); moduleEngine.engineDecelerationSpeed = engineDecelerationSpeedEmpty ? 0 : Single.Parse(propList[selectedPropellant].engineDecelerationSpeed); //if (!useEngineResponseTimeEmpty) //{ // EngineEffectNode.SetValue("useEngineResponseTime", propList[selectedPropellant].useEngineResponseTime, true); // Debug.Log("EngineEffectNode.SetValue('useEngineResponseTime', " + propList[selectedPropellant].useEngineResponseTime + ", true);"); //} //if (!engineAccelerationSpeedEmpty) //{ // EngineEffectNode.SetValue("engineAccelerationSpeed", propList[selectedPropellant].engineAccelerationSpeed, true); // Debug.Log("EngineEffectNode.SetValue('engineAccelerationSpeed', " + propList[selectedPropellant].engineAccelerationSpeed + ", true);"); //} //if (!engineDecelerationSpeedEmpty) //{ // EngineEffectNode.SetValue("engineDecelerationSpeed", propList[selectedPropellant].engineDecelerationSpeed, true); // Debug.Log("EngineEffectNode.SetValue('engineDecelerationSpeed', " + propList[selectedPropellant].engineDecelerationSpeed + ", true);"); //} //Update the effects //updateEngineModuleEffects( // calledByPlayer: calledByPlayer, // callingFunction: callingFunction, // moduleEngine: moduleEngine); //Write the propellant setup to the right click GUI GUIpropellantNames = propList[selectedPropellant].Propellants.Replace(",", ", "); if (iniGUIpropellantNamesEmpty) { //Default naming if no user defined names are found GUIpropellantNames = "[" + selectedPropellant + "] " + propList[selectedPropellant].Propellants.Replace(",", ", "); } else { //User defined names GUIpropellantNames = propList[selectedPropellant].GUIpropellantNames; //iniGUIpropellantNames.Trim().Split(';')[selectedPropellant]; } //Write on screen message //ScreenMessages.PostScreenMessage("message", 3f, ScreenMessageStyle.UPPER_LEFT); ScreenMessages.PostScreenMessage(propList[selectedPropellant].GUIpropellantNames, 1.5f, ScreenMessageStyle.UPPER_CENTER); //Restart engine if it was on before switching //moduleEngine.Flameout("Switch Engine State", false, false); currentModuleEngine.UnFlameout(false); //FlightInputHandler.state.mainThrottle = currentThrottleState; //Invoke("ActivateEngine", 0f); //ActivateEngine(); if (currentEngineState) { moduleEngine.Activate(); } } }
public void DEBUG_ENGINESSWITCH() { InitializeSettings(); PhysicsUtilities Calc = new PhysicsUtilities(); Utilities MiscFx = new Utilities(); //System.Text.StringBuilder BuildString = new System.Text.StringBuilder(); float Density = propList[selectedPropellant].propDensity; //int i = 0; foreach (var moduleEngine in ModuleEngines) { moduleEngine.Events["Activate"].active = !moduleEngine.Events["Activate"].active; moduleEngine.Events["Shutdown"].active = !moduleEngine.Events["Activate"].active; moduleEngine.Events["Activate"].guiActive = moduleEngine.Events["Activate"].active; moduleEngine.Events["Shutdown"].guiActive = !moduleEngine.Events["Activate"].active; //if (moduleEngine.Events["Activate"].active) //{ // //moduleEngine.Events["Activate"].active = false; // moduleEngine.Events["Shutdown"].active = false; // moduleEngine.Events["Activate"].guiActive = false; // moduleEngine.Events["Shutdown"].guiActive = false; //} //else //{ // //moduleEngine.Events["Activate"].active = true; // moduleEngine.Events["Shutdown"].active = true; // moduleEngine.Events["Activate"].guiActive = true; // moduleEngine.Events["Shutdown"].guiActive = true; //} //Debug.Log("CGF velCurveKeys: " + velCurveKeys); //Debug.Log("CGF atmCurveKeys: " + atmCurveKeys); Debug.Log( "requestedThrottle: " + moduleEngine.requestedThrottle * 100 + "%" + "\nmaxThrust: " + moduleEngine.maxThrust + "\nresultingThrust: " + moduleEngine.resultingThrust + "\nmaxFuelFlow: " + moduleEngine.maxFuelFlow + "\nrequestedMassFlow: " + moduleEngine.requestedMassFlow + "\nmaxFuelRate (calc): " + Calc.calcFuelRateFromFuelFlow(moduleEngine.maxFuelFlow, Density) + "\nFuelRate (calc): " + Calc.calcFuelRateFromFuelFlow(moduleEngine.requestedMassFlow, Density) + "\nWeighted Density of " + propList[selectedPropellant].Propellants + " is " + Density + "Kg/L" ); foreach (var propellant in moduleEngine.propellants) { Debug.Log( "foreach(var propellant in moduleEngine.propellants)" + "\nPropellant: " + propellant.name + "\nratio: " + propellant.ratio + "\ndrawStackGauge: " + propellant.drawStackGauge + "\nignoreForISP: " + propellant.ignoreForIsp); } //for (int j = 0; j < moduleEngine.atmosphereCurve.Curve.length; j++) //{ // Debug.Log(moduleEngine.atmosphereCurve.Curve[j].time + ", " + moduleEngine.atmosphereCurve.Curve[j].value); //} //DEBUG /*i = 0; * float CurveTimeValue = 0; * foreach (Keyframe key in moduleEngine.atmosphereCurve.Curve.keys) * { * Debug.Log("atmosphereKey[" + i + "]: " + key.time + " " + key.value + " " + key.inTangent + " " + key.outTangent); * if (CurveTimeValue < key.value) { CurveTimeValue = key.value; } * i++; * }*/ Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.atmosphereCurve.Curve.keys, "atmosphereKeys --> ")); /*Debug.Log( * "ISP: " + CurveTimeValue + * "\nmaxFuelRate should be: " + Calc.calcFuelFlow(moduleEngine.maxThrust, Density, CurveTimeValue) * );*/ Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.atmCurve.Curve.keys, "atmCurveKeys --> ")); Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.velCurve.Curve.keys, "velCurveKeys --> ")); foreach (var engineEvent in moduleEngine.Events) { Debug.Log("moduleEngine.Events" + "\nGUIName: " + engineEvent.GUIName + "\nid: " + engineEvent.id + "\nname: " + engineEvent.name + "\nactive: " + engineEvent.active + "\nassigned: " + engineEvent.assigned + "\ncategory: " + engineEvent.category + "\nexternalToEVAOnly: " + engineEvent.externalToEVAOnly + "\nguiActive: " + engineEvent.guiActive + "\nguiActiveEditor: " + engineEvent.guiActiveEditor + "\nguiActiveUncommand: " + engineEvent.guiActiveUncommand + "\nguiActiveUnfocused: " + engineEvent.guiActiveUnfocused + "\nguiIcon: " + engineEvent.guiIcon + "\nunfocusedRange: " + engineEvent.unfocusedRange); } } /* * foreach (var bodyItem in FlightGlobals.Bodies) * { * Debug.Log("Planet stats -->" + * "\nBodyName: " + bodyItem.bodyName + * "\nRadius: " + bodyItem.Radius + * "\nsphereOfInfluence: " + bodyItem.sphereOfInfluence + * "\nGetInstanceID: " + bodyItem.GetInstanceID() + * "\natmospherePressureCurve:" + MiscFx.KeyFrameGetToCFG(bodyItem.atmospherePressureCurve.Curve.keys, "bodyItem.atmospherePressureCurve.Curve.keys --> ") * ); * * //Clear string Builder * //BuildString.Length = 0; * //BuildString.Capacity = 16; * } */ }
public void DEBUG_ENGINESSWITCH() { initializeSettings(); PhysicsUtilities Calc = new PhysicsUtilities(); Utilities MiscFx = new Utilities(); //System.Text.StringBuilder BuildString = new System.Text.StringBuilder(); //float Density = propList[selectedPropellant].propDensity; //int i = 0; foreach (var moduleEngine in ModuleEngines) { //Debug.Log("CGF velCurveKeys: " + velCurveKeys); //Debug.Log("CGF atmCurveKeys: " + atmCurveKeys); Debug.Log( "\nSome key information on moduleengine: " + moduleEngine.GUIName + "\nrequestedThrottle: " + moduleEngine.requestedThrottle * 100 + "%" + "\nmaxThrust: " + moduleEngine.maxThrust + "\nresultingThrust: " + moduleEngine.resultingThrust + "\nmaxFuelFlow: " + moduleEngine.maxFuelFlow + "\nrequestedMassFlow: " + moduleEngine.requestedMassFlow //"\nmaxFuelRate (calc): " + Calc.calcFuelRateFromfuelFlow(moduleEngine.maxFuelFlow, Density) + //"\nFuelRate (calc): " + Calc.calcFuelRateFromfuelFlow(moduleEngine.requestedMassFlow, Density) //"\nWeighted Density of " + propList[selectedPropellant].Propellants + " is " + Density + "Kg/L" ); foreach (var propellant in moduleEngine.propellants) { Debug.Log( "\nforeach(var propellant in moduleEngine.propellants)" + "\nPropellant: " + propellant.name + "\nratio: " + propellant.ratio + "\ndrawStackGauge: " + propellant.drawStackGauge + "\nignoreForISP: " + propellant.ignoreForIsp); } //for (int j = 0; j < moduleEngine.atmosphereCurve.Curve.length; j++) //{ // Debug.Log(moduleEngine.atmosphereCurve.Curve[j].time + ", " + moduleEngine.atmosphereCurve.Curve[j].value); //} //DEBUG /*i = 0; * float CurveTimeValue = 0; * foreach (Keyframe key in moduleEngine.atmosphereCurve.Curve.keys) * { * Debug.Log("atmosphereKey[" + i + "]: " + key.time + " " + key.value + " " + key.inTangent + " " + key.outTangent); * if (CurveTimeValue < key.value) { CurveTimeValue = key.value; } * i++; * }*/ Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.atmosphereCurve.Curve.keys, "atmosphereKeys --> ")); /*Debug.Log( * "ISP: " + CurveTimeValue + * "\nmaxFuelRate should be: " + Calc.calcFuelFlow(moduleEngine.maxThrust, Density, CurveTimeValue) * );*/ Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.atmCurve.Curve.keys, "atmCurveKeys --> ")); Debug.Log(MiscFx.KeyFrameGetToCFG(moduleEngine.velCurve.Curve.keys, "velCurveKeys --> ")); Debug.Log( "Events for the following engine" + "\nmoduleEngine.GUIName" + moduleEngine.GUIName ); foreach (var engineEvent in moduleEngine.Events) { Debug.Log( "\nmoduleEngine.Events" + "\nGUIName: " + engineEvent.GUIName + "\nid: " + engineEvent.id + "\nname: " + engineEvent.name + "\nactive: " + engineEvent.active + "\nassigned: " + engineEvent.assigned + "\ncategory: " + engineEvent.category + "\nexternalToEVAOnly: " + engineEvent.externalToEVAOnly + "\nguiActive: " + engineEvent.guiActive + "\nguiActiveEditor: " + engineEvent.guiActiveEditor + "\nguiActiveUncommand: " + engineEvent.guiActiveUncommand + "\nguiActiveUnfocused: " + engineEvent.guiActiveUnfocused + "\nguiIcon: " + engineEvent.guiIcon + "\nunfocusedRange: " + engineEvent.unfocusedRange + "\n"); } for (int i = 0; i < moduleEngine.Fields.Count; i++) { //moduleEngine.Fields[i].guiName; if (moduleEngine.Fields[i].guiActive) { Debug.Log( "\nmoduleEngine.Fields[" + i + "]" + "\nguiName: " + moduleEngine.Fields[i].guiName + "\nname: " + moduleEngine.Fields[i].name + "\noriginalValue: " + moduleEngine.Fields[i].originalValue + "\nisPersistant: " + moduleEngine.Fields[i].isPersistant + "\nguiActive: " + moduleEngine.Fields[i].guiActive + "\nguiActiveEditor: " + moduleEngine.Fields[i].guiActiveEditor + "\nguiFormat: " + moduleEngine.Fields[i].guiFormat + "\nguiUnits: " + moduleEngine.Fields[i].guiUnits + "\nHasInterface: " + moduleEngine.Fields[i].HasInterface + "\nhost: " + moduleEngine.Fields[i].host + "\nuiControlEditor: " + moduleEngine.Fields[i].uiControlEditor + "\nuiControlFlight: " + moduleEngine.Fields[i].uiControlFlight + "\nuiControlOnly: " + moduleEngine.Fields[i].uiControlOnly + "\n"); } } for (int i = 0; i < moduleEngine.Actions.Count; i++) { //moduleEngine.Fields[i].guiName; //if (moduleEngine.Actions[i].active) //{ Debug.Log( "\nmoduleEngine.Actions[" + i + "]" + "\nguiName: " + moduleEngine.Actions[i].guiName + "\nname: " + moduleEngine.Actions[i].name + "\noriginalValue: " + moduleEngine.Actions[i].actionGroup + "\nisPersistant: " + moduleEngine.Actions[i].active + "\nguiActive: " + moduleEngine.Actions[i].defaultActionGroup + "\nguiActiveEditor: " + moduleEngine.Actions[i].listParent + "\n"); //} } //foreach (var engineField in moduleEngine.Fields) //{ // Debug.Log("moduleEngine.Fields" + // "\nengineField: " + engineField // ); //} } /* * foreach (var bodyItem in FlightGlobals.Bodies) * { * Debug.Log("Planet stats -->" + * "\nBodyName: " + bodyItem.bodyName + * "\nRadius: " + bodyItem.Radius + * "\nsphereOfInfluence: " + bodyItem.sphereOfInfluence + * "\nGetInstanceID: " + bodyItem.GetInstanceID() + * "\natmospherePressureCurve:" + MiscFx.KeyFrameGetToCFG(bodyItem.atmospherePressureCurve.Curve.keys, "bodyItem.atmospherePressureCurve.Curve.keys --> ") * ); * * //Clear string Builder * //BuildString.Length = 0; * //BuildString.Capacity = 16; * } */ }