private void RemoveMasslessPropellantsFromEngine(List <PersistentPropellant> pplist) { var akPropellants = new ConfigNode(); //Get the Ignition state, i.e. is the engine shutdown or activated var ignitionState = engine.getIgnitionState; engine.Shutdown(); foreach (var propellant in pplist) { if (propellant.density == 0) { continue; } var propellantConfig = LoadPropellant(propellant.propellant.name, propellant.propellant.ratio); akPropellants.AddNode(propellantConfig); } engine.Load(akPropellants); if (ignitionState) { engine.Activate(); } }
public static void updateEngineThrust(ModuleEngines engine, float minThrust, float maxThrust) { engine.minThrust = minThrust; engine.maxThrust = maxThrust; ConfigNode updateNode = new ConfigNode("MODULE"); updateNode.AddValue("maxThrust", engine.maxThrust); updateNode.AddValue("minThrust", engine.minThrust); engine.Load(updateNode); }
public static void updateEngineThrust(ModuleEngines engine, float minThrust, float maxThrust) { engine.minThrust = minThrust; engine.maxThrust = maxThrust; ConfigNode updateNode = new ConfigNode("MODULE"); updateNode.AddValue("maxThrust", engine.maxThrust); updateNode.AddValue("minThrust", engine.minThrust); engine.Load(updateNode); }
public int UpdateSymmetryCounterparts() { int i = 0; foreach (Part sPart in part.symmetryCounterparts) { ModuleEngineConfigs engine = (ModuleEngineConfigs)sPart.Modules ["ModuleEngineConfigs"]; if (engine) { i++; engine.configuration = configuration; engine.config = config; engine.modded = true; ModuleEngines thruster = (ModuleEngines)sPart.Modules ["ModuleEngines"]; thruster.Load(engine.config); } } return(i); }
public virtual void UpdateFuel(bool isEditor = false) { Debug.Log("[KSPI] - Update Fuel with " + CurrentActiveConfiguration.fuelConfigurationName); ConfigNode akPropellants = new ConfigNode(); int I = 0; int N = 0; while (I < CurrentActiveConfiguration.Fuels.Length) { if (CurrentActiveConfiguration.Ratios[I] > 0) { Debug.Log("[KSPI] - Load propellant " + CurrentActiveConfiguration.Fuels[I]); akPropellants.AddNode(LoadPropellant(CurrentActiveConfiguration.Fuels[I], CurrentActiveConfiguration.Ratios[I])); } else { N++; } I++; } //if (N + 1 >= akConfig.Fuels.Length) // Fields["selectedFuel"].guiActive = false; akPropellants.AddValue("maxThrust", 1); akPropellants.AddValue("maxFuelFlow", 1); if (curEngineT != null) { curEngineT.Load(akPropellants); curEngineT.atmosphereCurve = CurrentActiveConfiguration.atmosphereCurve; } if (!isEditor) { vessel.ClearStaging(); vessel.ResumeStaging(); } UpdateEngineWarpFuels(); }
public virtual void UpdateFuel(bool isEditor = false) { Debug.Log("Update Fuel"); ConfigNode akPropellants = new ConfigNode(); int I = 0; int N = 0; while (I < ActiveConfiguration.Fuels.Length) { if (ActiveConfiguration.Ratios[I] > 0) { akPropellants.AddNode(LoadPropellant(ActiveConfiguration.Fuels[I], ActiveConfiguration.Ratios[I])); } else { N++; } I++; } if (N + 1 >= ActiveConfiguration.Fuels.Length) { Fields["selectedFuel"].guiActive = false; } akPropellants.AddValue("maxThrust", 1); akPropellants.AddValue("maxFuelFlow", 1); curEngineT.Load(akPropellants); curEngineT.atmosphereCurve = ActiveConfiguration.atmosphereCurve; if (!isEditor) { vessel.ClearStaging(); vessel.ResumeStaging(); } }
public override void OnStart(StartState state) { ConfigNode config = null; if (modded) { config = configs.Find(c => c.GetValue("name").Equals(configuration)); } if (config != null) { ModuleEngines thruster = (ModuleEngines)part.Modules["ModuleEngines"]; ConfigNode newConfig = new ConfigNode("MODULE"); config.CopyTo(newConfig); newConfig.name = "MODULE"; newConfig.SetValue("name", "ModuleEngines"); #if DEBUG print("replacing ModuleEngines with:"); print(newConfig.ToString()); #endif thruster.Load(newConfig); } }
public virtual void UpdateFuel(bool isEditor = false) { Debug.Log("[KSPI]: Update Fuel with " + CurrentActiveConfiguration.fuelConfigurationName); var akPropellants = new ConfigNode(); int I = 0; int N = 0; while (I < CurrentActiveConfiguration.Fuels.Length) { if (CurrentActiveConfiguration.Ratios[I] > 0) { var currentFuel = CurrentActiveConfiguration.Fuels[I]; var propellantConfig = LoadPropellant(currentFuel, CurrentActiveConfiguration.Ratios[I]); akPropellants.AddNode(propellantConfig); } else { N++; } I++; } akPropellants.AddValue("maxThrust", 1); akPropellants.AddValue("maxFuelFlow", 1); if (curEngineT != null) { curEngineT.Load(akPropellants); //bools curEngineT.atmChangeFlow = CurrentActiveConfiguration.atmChangeFlow; curEngineT.clampPropReceived = CurrentActiveConfiguration.clampPropReceived; curEngineT.useEngineResponseTime = CurrentActiveConfiguration.useEngineResponseTime; // floats curEngineT.flowMultCap = CurrentActiveConfiguration.flowMultCap; curEngineT.engineAccelerationSpeed = CurrentActiveConfiguration.engineAccelerationSpeed; curEngineT.engineDecelerationSpeed = CurrentActiveConfiguration.engineDecelerationSpeed; curEngineT.ignitionThreshold = CurrentActiveConfiguration.ignitionThreshold; curEngineT.exhaustDamageMultiplier = CurrentActiveConfiguration.exhaustDamageMultiplier; curEngineT.exhaustDamageDistanceOffset = CurrentActiveConfiguration.exhaustDamageDistanceOffset; curEngineT.useVelCurve = CurrentActiveConfiguration.useVelCurve; if (curEngineT.useVelCurve) { Debug.Log("[KSPI]: UpdateFlightGUI engine load velCurve"); curEngineT.velCurve = CurrentActiveConfiguration.velCurve; } curEngineT.useAtmCurve = CurrentActiveConfiguration.useAtmCurve; if (curEngineT.useAtmCurve) { Debug.Log("[KSPI]: UpdateFlightGUI engine load velCurve"); curEngineT.atmCurve = CurrentActiveConfiguration.atmCurve; } curEngineT.atmosphereCurve = CurrentActiveConfiguration.atmosphereCurve; } if (HighLogic.LoadedSceneIsFlight) { vessel.ClearStaging(); vessel.ResumeStaging(); } UpdateEngineWarpFuels(); }
private void SetupPropellants(bool moveNext) { try { Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault(); if ((Current_propellant.SupportedEngines & type) != type) { _rep++; togglePropellant(moveNext); return; } Propellant new_propellant = Current_propellant.Propellant; List <Propellant> list_of_propellants = new List <Propellant>(); list_of_propellants.Add(new_propellant); // if all propellant exist if (!list_of_propellants.Exists(prop => PartResourceLibrary.Instance.GetDefinition(prop.name) == null)) { //Get the Ignition state, i.e. is the engine shutdown or activated var engineState = _attached_engine.getIgnitionState; _attached_engine.Shutdown(); ConfigNode newPropNode = new ConfigNode(); foreach (var prop in list_of_propellants) { ConfigNode propellantConfigNode = newPropNode.AddNode("PROPELLANT"); propellantConfigNode.AddValue("name", prop.name); propellantConfigNode.AddValue("ratio", prop.ratio); propellantConfigNode.AddValue("DrawGauge", "true"); } _attached_engine.Load(newPropNode); if (engineState == true) { _attached_engine.Activate(); } } else if (_rep < _propellants.Count) { _rep++; togglePropellant(moveNext); return; } if (HighLogic.LoadedSceneIsFlight) { // you can have any fuel you want in the editor but not in flight var allVesselResourcesNames = part.vessel.parts.SelectMany(m => m.Resources).Select(m => m.resourceName).Distinct(); if (!list_of_propellants.All(prop => allVesselResourcesNames.Contains(prop.name.Replace("LqdWater", "Water"))) && _rep < _propellants.Count) { _rep++; togglePropellant(moveNext); return; } } _rep = 0; } catch (Exception e) { UnityEngine.Debug.LogError("[KSPI] - SetupPropellants ElectricEngineControllerFX " + e.Message); } }
/// <summary> /// Update engines effects settings /// </summary> /// <param name="moduleEngine">The engines module to update</param> /// <param name="calledByPlayer">Is the method called by the player -> For custom behavior when the player calls it</param> /// <param name="callingFunction">The function calling the update -> For custom behavior for each calling funciton</param> public void updateEngineModuleEffects(ModuleEngines moduleEngine, bool calledByPlayer, string callingFunction = "player") { if (useEFFECTS) { ConfigNode EngineEffectNode = new ConfigNode(); string usedEffects = string.Empty; Debug.Log( "\nSwitch exhaust effects on: " + moduleEngine.name + "\nPropellants: " + propList[selectedPropellant].Propellants + "\nSemantic Name: " + propList[selectedPropellant].GUIpropellantNames ); if (!runningEffectNameEmpty) { EngineEffectNode.SetValue("runningEffectName", propList[selectedPropellant].runningEffectName, true); usedEffects += propList[selectedPropellant].runningEffectName + ";"; Debug.Log("EngineEffectNode.SetValue('runningEffectName', " + propList[selectedPropellant].runningEffectName + ", true);"); } if (!powerEffectNameEmpty) { EngineEffectNode.SetValue("powerEffectName", propList[selectedPropellant].powerEffectName, true); usedEffects += propList[selectedPropellant].powerEffectName + ";"; Debug.Log("EngineEffectNode.SetValue('powerEffectName', " + propList[selectedPropellant].powerEffectName + ", true);"); } if (!spoolEffectNameEmpty) { EngineEffectNode.SetValue("spoolEffectName", propList[selectedPropellant].spoolEffectName, true); usedEffects += propList[selectedPropellant].spoolEffectName + ";"; Debug.Log("EngineEffectNode.SetValue('spoolEffectName', " + propList[selectedPropellant].spoolEffectName + ", true);"); } if (!engageEffectNameEmpty) { EngineEffectNode.SetValue("engageEffectName", propList[selectedPropellant].engageEffectName, true); usedEffects += propList[selectedPropellant].engageEffectName + ";"; Debug.Log("EngineEffectNode.SetValue('engageEffectName', " + propList[selectedPropellant].engageEffectName + ", true);"); } if (!disengageEffectNameEmpty) { EngineEffectNode.SetValue("disengageEffectName", propList[selectedPropellant].disengageEffectName, true); usedEffects += propList[selectedPropellant].disengageEffectName + ";"; Debug.Log("EngineEffectNode.SetValue('disengageEffectName', " + propList[selectedPropellant].disengageEffectName + ", true);"); } if (!engineSpoolIdleEmpty) { EngineEffectNode.SetValue("engineSpoolIdle", propList[selectedPropellant].engineSpoolIdle, true); Debug.Log("EngineEffectNode.SetValue('engineSpoolIdle', " + propList[selectedPropellant].engineSpoolIdle + ", true);"); } if (!engineSpoolTimeEmpty) { EngineEffectNode.SetValue("engineSpoolTime", propList[selectedPropellant].engineSpoolTime, true); Debug.Log("EngineEffectNode.SetValue('engineSpoolTime', " + propList[selectedPropellant].engineSpoolTime + ", true);"); } //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);"); //} //********** MOVE TO PART LEVEL if (!fx_exhaustFlame_blueEmpty) { EngineEffectNode.SetValue("fx_exhaustFlame_blue", propList[selectedPropellant].fx_exhaustFlame_blue, true); //part Debug.Log("EngineEffectNode.SetValue('fx_exhaustFlame_blue', " + propList[selectedPropellant].fx_exhaustFlame_blue + ", true);"); } if (!fx_exhaustLight_blueEmpty) { EngineEffectNode.SetValue("fx_exhaustLight_blue", propList[selectedPropellant].fx_exhaustLight_blue, true); Debug.Log("EngineEffectNode.SetValue('fx_exhaustLight_blue', " + propList[selectedPropellant].fx_exhaustLight_blue + ", true);"); } if (!fx_smokeTrail_lightEmpty) { EngineEffectNode.SetValue("fx_smokeTrail_light", propList[selectedPropellant].fx_smokeTrail_light, true); Debug.Log("EngineEffectNode.SetValue('fx_smokeTrail_light', " + propList[selectedPropellant].fx_smokeTrail_light + ", true);"); } if (!fx_exhaustSparks_flameoutEmpty) { EngineEffectNode.SetValue("fx_exhaustSparks_flameout", propList[selectedPropellant].fx_exhaustSparks_flameout, true); Debug.Log("EngineEffectNode.SetValue('fx_exhaustSparks_flameout', " + propList[selectedPropellant].fx_exhaustSparks_flameout + ", true);"); } if (!sound_vent_mediumEmpty) { EngineEffectNode.SetValue("sound_vent_medium", propList[selectedPropellant].sound_vent_medium, true); Debug.Log("EngineEffectNode.SetValue('sound_vent_medium', " + propList[selectedPropellant].sound_vent_medium + ", true);"); } if (!sound_rocket_hardEmpty) { EngineEffectNode.SetValue("sound_rocket_hard", propList[selectedPropellant].sound_rocket_hard, true); Debug.Log("EngineEffectNode.SetValue('sound_rocket_hard', " + propList[selectedPropellant].sound_rocket_hard + ", true);"); } if (!sound_vent_softEmpty) { EngineEffectNode.SetValue("sound_vent_soft", propList[selectedPropellant].sound_vent_soft, true); Debug.Log("EngineEffectNode.SetValue('sound_vent_soft', " + propList[selectedPropellant].sound_vent_soft + ", true);"); } if (!sound_explosion_lowEmpty) { EngineEffectNode.SetValue("sound_explosion_low", propList[selectedPropellant].sound_explosion_low, true); Debug.Log("EngineEffectNode.SetValue('sound_explosion_low', " + propList[selectedPropellant].sound_explosion_low + ", true);"); } //ConfigNode myNode = getNode(); // get as appropriate //foreach (ConfigNode.Value val in myNode.values) //foreach (string usedEffect in usedEffects.Split(';')) //foreach (String node in SourceEffectsNode.nodes) //{ // Debug.Log("Write NODES: " + node); // //if (SourceEffectsNode.GetNodes() // //SourceEffectsNode.RemoveValue(""); //} moduleEngine.Load(EngineEffectNode); Debug.Log( "\nthis.name: " + this.name + "\nthis.name: " + this.moduleName ); } //this.part.Modules.GetModule<ModuleEnginesFX>.getno //Debug.Log("moduleEngine.runningGroup.Active: " + moduleEngine.runningGroup.Active); //if (propList[selectedPropellant].runningEffectName == string.Empty) //{ // moduleEngine.DeactivateRunningFX(); //} //if (propList[selectedPropellant].powerEffectName == string.Empty) //{ // moduleEngine.DeactivatePowerFX(); //} //if (propList[selectedPropellant].spoolEffectName == string.Empty) //{ // moduleEngine.DeactivateLoopingFX(); //} //moduleEngine.SetupFXGroups(); //moduleEngine.DeactivateRunningFX(); //moduleEngine.ActivateRunningFX(); //moduleEngine.InitializeFX(); //part.InitializeModules(); //part.InitializeEffects(); //ConfigNode EngineNode = part.partInfo.partConfig.GetNode("MODULE"); //ConfigNode copiedEngineNode = new ConfigNode("MODULE"); //EngineNode.CopyTo(copiedEngineNode); //Debug.Log("foreach (ConfigNode innervalue in copiedEngineNode.values)"); //foreach (var innervalue in copiedEngineNode.values) //{ // //Debug.Log("foreach (ConfigNode innervalue in copiedEngineNode.values)"); // Debug.Log( // "\nid: " + innervalue.ToString() + // "\name: " + innervalue.name // ); // //if (part.partInfo.partConfig.nodes.Contains("ModuleEnginesFX")) // //{ // // Debug.Log("If ModuleEnginesFX"); // // innervalue.Save("Node.txt"); // // Debug.Log( // // "\ninnerNode1.GetValue('name'): " + innervalue.GetValue("name") + // // "\ninnerNode1.GetValue('maxThrust'): " + innervalue.GetValue("maxThrust") // // ); // // //innerNode1.CopyTo(copiedEngineNode); // // break; // //} //} //foreach (ConfigNode innerNode1 in copiedEngineNode.nodes) //{ // Debug.Log("foreach (ConfigNode innerNode1 in copiedEngineNode.nodes)"); // Debug.Log("part.partInfo.partConfig.nodes.Contains('ModuleEnginesFX'): " + part.partInfo.partConfig.nodes.Contains("ModuleEnginesFX")); // Debug.Log("innerNode1.GetNodeID('ModuleEnginesFX'): " + innerNode1.GetNodeID("ModuleEnginesFX")); // Debug.Log("innerNode1.GetValue('name'): " + innerNode1.GetValue("name")); // if (part.partInfo.partConfig.nodes.Contains("ModuleEnginesFX")) // { // Debug.Log("If ModuleEnginesFX"); // innerNode1.Save("Node.txt"); // Debug.Log( // "\ninnerNode1.GetValue('name'): " + innerNode1.GetValue("name") + // "\ninnerNode1.GetValue('maxThrust'): " + innerNode1.GetValue("maxThrust") // ); // //innerNode1.CopyTo(copiedEngineNode); // break; // } //} //ConfigNode effectsNode = part.partInfo.partConfig.GetNode("EFFECTS"); //ConfigNode copiedEffectsNode = new ConfigNode("EFFECTS"); //effectsNode.CopyTo(copiedEffectsNode); //part.Effects.OnLoad(copiedEffectsNode); //EngineNode.CopyTo(copiedEngineNode); //part.Effects.OnLoad(copiedEngineNode); //part.LoadModule(copiedEngineNode); //part.partInfo.partConfig.GetNodes("MODULE"); //part.partInfo.partConfig.GetNode("ModuleEnginesFX"); //moduleEngine.OnLoad(EngineEffectNode); //part.partInfo.partConfig. //part.Effects.Initialize(); //moduleEngine.InitializeFX(); //moduleEngine.FXReset(); //moduleEngine.FXUpdate(); //moduleEngine. //} }