protected void setupEngines() { //See if we have multiple engines that we need to support engineSwitcher = this.part.FindModuleImplementing <MultiModeEngine>(); if (engineSwitcher != null) { List <ModuleEnginesFX> engines = this.part.FindModulesImplementing <ModuleEnginesFX>(); foreach (ModuleEnginesFX multiEngine in engines) { multiModeEngines.Add(multiEngine.engineID, multiEngine); } if (engineSwitcher.runningPrimary) { engine = multiModeEngines[engineSwitcher.primaryEngineID]; } else { engine = multiModeEngines[engineSwitcher.secondaryEngineID]; } return; } //Normal case: we only have one engine to support engine = this.part.FindModuleImplementing <ModuleEnginesFX>(); }
public void Start() { animationControl = SSTUAnimateControlled.locateAnimationController(part, animationID, onAnimationStatusChanged); engineModule = (ModuleEnginesFX)part.Modules[engineModuleIndex];//unsafe, but intend it to crash if setup improperly setupEngineModuleGui(); setupGuiFields(animationControl.getAnimationState(), engineModule.EngineIgnited); }
void GetEngineType(PartModule m, ref string engineType) { if (m is ModuleEngines) { ModuleEngines me = (ModuleEngines)m; engineType = me.GetEngineType() + ": "; foreach (var p in me.propellants.OrderBy(n => n.displayName)) { if (engineType.Substring(engineType.Length - 2) != ": ") { engineType += ", "; } engineType += p.displayName; } } if (m is ModuleEnginesFX && m.isEnabled) // Squad, y u have separate module for NASA engines? :c { ModuleEnginesFX me = (ModuleEnginesFX)m; engineType = me.GetEngineType() + ": "; foreach (var p in me.propellants.OrderBy(n => n.displayName)) { if (engineType.Substring(engineType.Length - 2) != ": ") { engineType += ", "; } engineType += p.displayName; } } if (engineType != "") { Log.Info("GetEnginetype, engineType: " + engineType); } }
public override void OnStart(PartModule.StartState state) { fxCenter = part.FindModelTransform(PulseTransformName); engineModule = part.GetComponent <ModuleEnginesFX>(); if (engineModule == null) { Utils.LogError("[ModulePulseEngineAnimator]: No ModuleEnginesFX found on part!"); } // Set up animations if (PulseAnimation != "") { pulseStates = Utils.SetUpAnimation(PulseAnimation, part); foreach (AnimationState pulseState in pulseStates) { pulseState.layer = 1; } } if (InitiateAnimation != "") { initStates = Utils.SetUpAnimation(InitiateAnimation, part); foreach (AnimationState initState in initStates) { initState.layer = 2; } } }
public override void OnStart(PartModule.StartState state) { String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT }; attachedEngine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; this.resources_to_supply = resources_to_supply; propellants = getPropellants(); base.OnStart(state); if (state == StartState.Editor) { if (this.HasTechsRequiredToUpgrade()) { upgradePartModule(); } return; } if (this.HasTechsRequiredToUpgrade()) { hasrequiredupgrade = true; } if (attachedEngine != null) { attachedEngine.Fields["finalThrust"].guiFormat = "F5"; } fuel_gauge = part.stackIcon.DisplayInfo(); current_propellant = fuel_mode < propellants.Count ? propellants[fuel_mode] : propellants.FirstOrDefault(); setupPropellants(); }
protected bool engineIsRunning() { //If we have multiple engines, make sure we have the current one. if (engineSwitcher != null) { if (engineSwitcher.runningPrimary) { engine = multiModeEngines[engineSwitcher.primaryEngineID]; } else { engine = multiModeEngines[engineSwitcher.secondaryEngineID]; } } //No engine? Then it's clearly not running... if (engine == null) { return(false); } //Check operation status if (!engine.isOperational || !engine.EngineIgnited) { return(false); } else { return(true); } }
private object GetEngineFxSuffix(string suffixName, ModuleEnginesFX moduleEngines) { switch (suffixName) { case "MAXTHRUST": return moduleEngines.maxThrust; case "THRUST": return moduleEngines.finalThrust; case "FUELFLOW": return moduleEngines.fuelFlowGui; case "ISP": return moduleEngines.realIsp; case "FLAMEOUT": return moduleEngines.getFlameoutState; case "IGNITION": return moduleEngines.getIgnitionState; case "ALLOWRESTART": return moduleEngines.allowRestart; case "ALLOWSHUTDOWN": return moduleEngines.allowShutdown; case "THROTTLELOCK": return moduleEngines.throttleLocked; case "THRUSTLIMIT": return moduleEngines.thrustPercentage; } return base.GetSuffix(suffixName); }
public FSengineWrapper(Part part) { engine = part.Modules.OfType <ModuleEngines>().FirstOrDefault(); if (engine != null) { type = EngineType.ModuleEngine; } else { engineFX = part.Modules.OfType <ModuleEnginesFX>().FirstOrDefault(); if (engineFX != null) { type = EngineType.ModuleEngineFX; } else { fsengine = part.Modules.OfType <FSengine>().FirstOrDefault(); if (fsengine != null) { type = EngineType.FSengine; } } } //Debug.Log("FSengineWrapper: engine type is " + type.ToString()); }
public override void OnStart(PartModule.StartState state) { engineStates = SetUpAnimation(EngineAnimationName, this.part); foreach (var me in this.part.FindModulesImplementing <ModuleEngines>()) { engineIsOn = me.EngineIgnited; modEng = me; engineIsFX = false; } foreach (var me in this.part.FindModulesImplementing <ModuleEnginesFX>()) { engineIsOn = me.EngineIgnited; modEngFX = me; engineIsFX = true; } foreach (var anim in engineStates) { if (engineIsOn) { anim.normalizedTime = 1; } else { anim.normalizedTime = 0; } } }
public EngineModuleWrapper(Part part, int index) { List <ModuleEngines> engines = null; List <ModuleEnginesFX> enginesFX = null; engineType = EngineModuleType.UNKNOWN; engine = null; engineFX = null; if (part.Modules.Contains("ModuleEngines")) { engines = part.Modules.OfType <ModuleEngines>().ToList(); if (index < engines.Count) { engine = engines[index]; engineFX = null; engineType = EngineModuleType.ENGINE; } } if (part.Modules.Contains("ModuleEnginesFX")) { enginesFX = part.Modules.OfType <ModuleEnginesFX>().ToList(); if (index < enginesFX.Count) { engine = null; engineFX = enginesFX[index]; engineType = EngineModuleType.ENGINEFX; } } }
public override void OnStart(PartModule.StartState state) { var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT); // calculate WasteHeat Capacity if (wasteheatPowerResource != null) { var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount; wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio; } if (state == StartState.Editor) return; _attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; if (_attached_engine != null) _attached_engine.Fields["finalThrust"].guiFormat = "F5"; else UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!"); _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1); if (_attached_reactor == null) UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!"); }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) { return; } List<ModuleEnginesFX> mefxs = part.FindModulesImplementing<ModuleEnginesFX>().Where(e => e.engineID == "AirBreathing").ToList(); List<ModuleEngines> mes = part.FindModulesImplementing<ModuleEngines>().ToList(); rapier_engine = mefxs.FirstOrDefault(); rapier_engine2 = mes.FirstOrDefault(); }
List <Propellant> GetEnginePropellants(PartModule engine) { string typename = engine.GetType().ToString(); if (typename.Equals("ModuleEnginesFX")) { ModuleEnginesFX e = (ModuleEnginesFX)engine; return(e.propellants); } else if (typename.Equals("ModuleEngines")) { ModuleEngines e = (ModuleEngines)engine; return(e.propellants); } else if (typename.Equals("ModuleRCSFX")) { ModuleRCS e = (ModuleRCS)engine; return(e.propellants); } else if (typename.Equals("ModuleRCS")) { ModuleRCS e = (ModuleRCS)engine; return(e.propellants); } return(null); }
public override void OnStart(PartModule.StartState state) { animStates = Utils.SetUpAnimation(ThrustAnimationName, this.part); foreach (ModuleEngines me in this.part.FindModulesImplementing <ModuleEngines>()) { modEng = me; isEngineFX = false; break; } foreach (ModuleEnginesFX me in this.part.FindModulesImplementing <ModuleEnginesFX>()) { modEngFX = me; isEngineFX = true; break; } HideGimbalButtons(); part.OnEditorAttach += new Callback(HideGimbalButtons); if (disableGimbalToggle) { Actions["AGToggleGimbal"].active = true; Events["GuiToggleGimbal"].guiActive = true; Events["GuiToggleGimbal"].guiActiveEditor = true; foreach (ModuleGimbal mgg in this.part.FindModulesImplementing <ModuleGimbal>()) { gimbalStatus = !mgg.gimbalLock; } } else { Actions["AGToggleGimbal"].active = false; } }
public void SetupEngine(int engineIndex, bool isInFlight) { ModuleEnginesFX previousEngine = currentEngine; //Get the new current engine currentEngineIndex = engineIndex; currentEngine = engineList[currentEngineIndex]; currentEngineID = currentEngine.engineID; int count = engineList.Count; for (int index = 0; index < count; index++) { engineList[index].manuallyOverridden = true; engineList[index].isEnabled = false; engineList[index].Shutdown(); } //In-flight stuff if (isInFlight) { currentEngine.Activate(); currentEngine.currentThrottle = previousEngine.currentThrottle; } //Enable current engine currentEngine.manuallyOverridden = false; currentEngine.isEnabled = true; }
public FSengineWrapper(Part part) { engine = part.Modules.OfType<ModuleEngines>().FirstOrDefault(); if (engine != null) { type = EngineType.ModuleEngine; } else { engineFX = part.Modules.OfType<ModuleEnginesFX>().FirstOrDefault(); if (engineFX != null) { type = EngineType.ModuleEngineFX; } else { fsengine = part.Modules.OfType<FSengine>().FirstOrDefault(); if (fsengine != null) { type = EngineType.FSengine; } } } //Debug.Log("FSengineWrapper: engine type is " + type.ToString()); }
// Sets the engine mode private void SetMode() { if (multiEngine.runningPrimary) { EngineModeID = 0; } else { EngineModeID = 1; } Utils.Log("VariableIspEngine: Changing mode to " + engineModes[EngineModeID].name); CurrentEngineID = engineModes[EngineModeID].name; engine = engines[EngineModeID]; for (int i = 0; i < engine.propellants.Count; i++) { if (engine.propellants[i].name != "ElectricCharge") { fuelPropellant = engine.propellants[i]; } else { ecPropellant = engine.propellants[i]; } } //Utils.Log("VariableIspEngine: Changed mode to " + engine.engineID); //Utils.Log("VariableIspEngine: Fuel: " + fuelPropellant.name); //Utils.Log("VariableIspEngine: Thrust Curve: " + ThrustCurve.Evaluate(0f) + " to " + ThrustCurve.Evaluate(1f)); //Utils.Log("VariableIspEngine: Isp Curve: " + IspCurve.Evaluate(0f) + " to " + IspCurve.Evaluate(1f)); AdjustVariableThrust(); }
public override void OnStart(StartState state) { isRunning = isEngineRunning(); MerillData.log("enginestart: is started? " + isRunning); if (part.Modules.OfType <ModuleEngines>().ToList().Capacity > 0) { engine = part.Modules.OfType <ModuleEngines>().ToList()[0]; realMaxThrust = engine.maxThrust; realMinThrust = engine.minThrust; } if (part.Modules.OfType <ModuleEnginesFX>().ToList().Capacity > 0) { engineFX = part.Modules.OfType <ModuleEnginesFX>().ToList()[0]; realMaxThrust = engine.maxThrust; realMinThrust = engineFX.minThrust; } // if at "load", the engine is activated but at 0 thrust, be sure to set the engine to really 0 thrust if (isEngineShutdown()) { isRunning = false; if (engine == null) { engineFX.minThrust = 0; } else { engine.minThrust = 0; } } }
public EngineWrapper(IEngineStatus engine_status) { engineS = engine_status; engine = engineS as ModuleEngines; engineFX = engineS as ModuleEnginesFX; eFX = engineFX != null; }
public EngineWrapper(Part part) { engine = (ModuleEngines)part.Modules["ModuleEngines"]; if (engine != null) { type = EngineType.ModuleEngine; } else { engineFX = (ModuleEnginesFX)part.Modules["ModuleEnginesFX"]; if (engineFX != null) { type = EngineType.ModuleEngineFX; } else { // fsengine = (Firespitter.engine.FSengine)part.Modules["FSengine"]; // if (fsengine != null) { // type = EngineType.FSengine; } } } Debug.Log("EngineWrapper: engine type is " + type.ToString()); }
public override void OnStart(PartModule.StartState state) { animStates = Utils.SetUpAnimation(ThrustAnimationName, this.part); foreach(ModuleEngines me in this.part.FindModulesImplementing<ModuleEngines>()) { modEng = me; isEngineFX = false; break; } foreach(ModuleEnginesFX me in this.part.FindModulesImplementing<ModuleEnginesFX>()) { modEngFX = me; isEngineFX = true; break; } HideGimbalButtons(); part.OnEditorAttach += new Callback(HideGimbalButtons); if(disableGimbalToggle) { Actions["AGToggleGimbal"].active = true; Events["GuiToggleGimbal"].guiActive = true; Events["GuiToggleGimbal"].guiActiveEditor = true; foreach(ModuleGimbal mgg in this.part.FindModulesImplementing<ModuleGimbal>()) { gimbalStatus = !mgg.gimbalLock; } } else { Actions["AGToggleGimbal"].active = false; } }
public void Start() { engineStates = SetUpAnimation(EngineAnimationName, this.part); if(HighLogic.LoadedSceneIsFlight) { foreach (var me in this.part.FindModulesImplementing<ModuleEngines>()) { engineIsOn = me.EngineIgnited; modEng = me; engineIsFX = false; } foreach (var me in this.part.FindModulesImplementing<ModuleEnginesFX>()) { engineIsOn = me.EngineIgnited; modEngFX = me; engineIsFX = true; } } foreach(var anim in engineStates) { if (engineIsOn) { anim.normalizedTime = 1; } else { anim.normalizedTime = 0; } } }
public override void OnStart(PartModule.StartState state) { g0 = PluginHelper.GravityConstant; modifiedEngineBaseISP = baseISP * PluginHelper.ElectricEngineIspMult; String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT }; _attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; this.resources_to_supply = resources_to_supply; _propellants = getPropellantsEngineType(); base.OnStart(state); if (state == StartState.Editor) { if (this.HasTechsRequiredToUpgrade()) { upgradePartModule(); } return; } if (this.HasTechsRequiredToUpgrade()) { _hasrequiredupgrade = true; } if (_attached_engine != null) { _attached_engine.Fields["finalThrust"].guiFormat = "F5"; } fuel_gauge = part.stackIcon.DisplayInfo(); Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault(); setupPropellants(); }
void Start() { if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { engine = this.GetComponent <ModuleEnginesFX>(); SetupUI(); if (PowerGeneratedOffline) { if (powerInputs == null || powerOutputs.Count == 0) { ConfigNode node = GameDatabase.Instance.GetConfigs("PART"). Single(c => part.partInfo.name == c.name).config. GetNodes("MODULE").Single(n => n.GetValue("name") == moduleName); OnLoad(node); } } } if (HighLogic.LoadedSceneIsFlight) { if (CurrentCharge >= ChargeGoal) { SetEngineUI(true); } else { SetEngineUI(false); } } }
public void Start() { Fields["SkinTemp"].guiUnits = "K/" + this.part.maxTemp.ToString() + "K"; try { engine = this.part.Modules.GetModule <ModuleEnginesFX>(); } catch { Debug.LogError(("BeamedPowerPropulsion.AblativeEngine : ModuleEnginesFX not found on part-" + this.part.partName)); } receiver = new ReceivedPower(); try { // editing engine's thrust limiter field's gui engine.Fields["thrustPercentage"].guiName = Localizer.Format("#LOC_BeamedPower_PercentMaxThrust"); engine.Fields["thrustPercentage"].guiUnits = "%"; ((UI_FloatRange)engine.Fields["thrustPercentage"].uiControlFlight).scene = UI_Scene.Flight; engine.Fields["thrustPercentage"].guiActiveEditor = false; } catch { Debug.LogWarning("BeamedPowerPropulsion.AblativeEngine : Unable to edit engine module Field"); } SetLocalization(); }
public void Start() { animationControl = SSTUAnimateControlled.locateAnimationController(part, animationID, onAnimationStatusChanged); engineModule = null; ModuleEnginesFX[] engines = part.GetComponents <ModuleEnginesFX>(); int len = engines.Length; for (int i = 0; i < len; i++) { if (engines[i].engineID == engineID) { engineModule = engines[i]; } } if (engineModule == null) { MonoBehaviour.print("ERROR: Could not locate engine by ID: " + engineID + " for part: " + part + " for SSTUAnimateEngineHeat. This will cause errors during gameplay. Setting engine to first engine module (if present)"); if (engines.Length > 0) { engineModule = engines[0]; } } setupEngineModuleGui(); setupGuiFields(animationControl.getAnimationState(), engineModule.EngineIgnited); }
// Make "engine" and "engineFX" fields refer to the ModuleEngines and ModuleEnginesFX modules in part.Modules void FindModuleEngines() { foreach (PartModule pm in part.Modules) { if (pm is ModuleEngines) { engine = pm as ModuleEngines; IsPersistentEngine = true; } if (pm is ModuleEnginesFX) { engineFX = pm as ModuleEnginesFX; } } if (engineFX != null) { if (string.IsNullOrEmpty(powerEffectName)) { powerEffectName = engineFX.powerEffectName; } engineFX.powerEffectName = ""; if (string.IsNullOrEmpty(runningEffectName)) { runningEffectName = engineFX.runningEffectName; } engineFX.runningEffectName = ""; } }
public FSengineWrapper(Part part, string name) { engineFX = part.Modules.OfType<ModuleEnginesFX>().Where(p => p.engineID == name).FirstOrDefault(); if (engineFX != null) type = EngineType.ModuleEngineFX; //Debug.Log("FSengineWrapper: engine type is " + type.ToString()); }
int CurrentActiveMode() { int cnt = 0; foreach (PartModule pm in part.Modules) //change from part to partmodules { if (pm.moduleName == "ModuleEngines") //find partmodule engine on the part { ModuleEngines em = pm as ModuleEngines; cnt++; if (em.EngineIgnited) { break; } } if (pm.moduleName == "ModuleEnginesFX") //find partmodule engine on the part { cnt++; ModuleEnginesFX emfx = pm as ModuleEnginesFX; if (emfx.EngineIgnited == true) { break; } } } return(cnt - 1); }
private void SetupEngines() { engine = this.GetComponent <ModuleEnginesFX>(); if (engine == null) { Utils.LogWarning(String.Format("[ModuleMultiLengthEngine]: Could not find engine Module")); } }
public void FindEngine() { foreach (ModuleEnginesFX me in part.GetComponentsInChildren<ModuleEnginesFX>()) { KFLog.Log("Found an engine module."); thisEngine = me; } }
public override void OnStart(PartModule.StartState state) { // calculate WasteHeat Capacity var wasteheatPowerResource = part.Resources.FirstOrDefault(r => r.resourceName == ResourceManager.FNRESOURCE_WASTEHEAT); if (wasteheatPowerResource != null) { var wasteheat_ratio = Math.Min(wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount, 0.95); wasteheatPowerResource.maxAmount = part.mass * 2.0e+4 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * wasteheat_ratio; } if (state == StartState.Editor) { return; } _attached_engine = this.part.FindModuleImplementing <ModuleEnginesFX>(); _attached_warpable_engine = _attached_engine as ModuleEnginesWarp; if (_attached_engine != null) { _attached_engine.Fields["finalThrust"].guiFormat = "F5"; } else { Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!"); } // first try to look in part _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>(); // try to find nearest if (_attached_reactor == null) { _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1); } if (_attached_reactor == null) { Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!"); return; } double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor; calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant; minimum_isp = calculatedIsp * _attached_reactor.MinimumChargdIspMult; maximum_isp = calculatedIsp * _attached_reactor.MaximumChargedIspMult; max_power_multiplier = Math.Log10(maximum_isp / minimum_isp); throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult)); exchanger_thrust_divisor = radius > _attached_reactor.Radius ? _attached_reactor.Radius * _attached_reactor.Radius / radius / radius : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius; }
//Returns the intake air required by all engines in the vessel //Intake air calculation courtesy of FAR and a.g. public static double getRequiredAir(Vessel v, out double airReq, out double airAvailable) { double dt = TimeWarp.fixedDeltaTime; //if (SteamGauges.debug) Debug.Log("dT: " + Math.Round(dt, 3)); airReq = airAvailable = 0; foreach (Part P in v.parts) { foreach (PartModule PM in P.Modules) { if (PM is ModuleEngines) { ModuleEngines ME = PM as ModuleEngines; if (ME.engineShutdown || !ME.EngineIgnited) { continue; } foreach (Propellant Pro in ME.propellants) { if (Pro.name.Equals("IntakeAir")) { //if (SteamGauges.debug) Debug.Log("Air Req: " + Math.Round(Pro.currentRequirement,2)); airReq += Pro.currentRequirement; } } } else if (PM is ModuleEnginesFX) //tricky RAPIERs! { ModuleEnginesFX MFX = PM as ModuleEnginesFX; if (MFX.engineShutdown || !MFX.EngineIgnited) { continue; } foreach (Propellant Pro in MFX.propellants) { if (Pro.name.Equals("IntakeAir")) { //if (SteamGauges.debug) Debug.Log("Air Req: " + Math.Round(Pro.currentRequirement, 2)); airReq += Pro.currentRequirement; } } } else if (PM is ModuleResourceIntake) { ModuleResourceIntake MRI = PM as ModuleResourceIntake; if (MRI.intakeEnabled && MRI.resourceName.Equals("IntakeAir")) { //if (SteamGauges.debug) Debug.Log("Air In: " + Math.Round(MRI.airFlow*dt, 2)); airAvailable += MRI.airFlow * dt; } } } } //Debug.Log("Calc Air: " + Math.Round(airAvailable/airReq, 2)); //Debug.Log("Sim Air: " + Math.Round(SteamShip.AirPercent, 2)); //if (SteamGauges.debug) Debug.Log("Air Req: " + Math.Round(airReq, 2) + " In: " + Math.Round(airAvailable, 2)); return(airReq); }
/// <summary> /// Update propulsion /// </summary> public override void updateMultiMode(bool silentUpdate = false) { //initializeSettings(); GTIDebug.Log("GTI_MultiModeEngine: updatePropulsion() --> ChooseOption = " + ChooseOption, iDebugLevel.High); if (currentModuleEngine != null) { currentEngineState = currentModuleEngine.getIgnitionState; } else { GTIDebug.Log("updateMultiMode() --> currentModuleEngine is null", iDebugLevel.Low); } //FindSelectedMode(); //irrelevant when inheritting from the base class writeScreenMessage(); if (ModuleEngines == null) { GTIDebug.Log("updateMultiMode() --> ModuleEngines is null", iDebugLevel.Low); } foreach (ModuleEnginesFX moduleEngine in ModuleEngines) { #region NOTES /* Stock GUI Elements * fuelFlowGui * finalThrust * realIsp * status * thrustPercentage */ #endregion if (moduleEngine.engineID == ChooseOption) { GTIDebug.Log("GTI_MultiModeEngine: Set currentModuleEngine " + moduleEngine.engineID, iDebugLevel.High); currentModuleEngine = moduleEngine; //Reactivate engine if it was active if (currentEngineState) { GTIDebug.Log("GTI_MultiModeEngine: Activate() " + moduleEngine.engineID, iDebugLevel.High); moduleEngine.Activate(); } moduleEngine.manuallyOverridden = false; moduleEngine.isEnabled = true; } else { GTIDebug.Log("GTI_MultiModeEngine: Shutdown() " + moduleEngine.engineID, iDebugLevel.High); moduleEngine.Shutdown(); moduleEngine.manuallyOverridden = true; moduleEngine.isEnabled = false; } } } //END OF updatePropulsion()
public override void OnStart(StartState state) { Debug.Log(string.Format("{0} ModulePebkacLesPitchControl.OnStart", _myModTag)); _pitchEngine = GetPitchEngine(); _deployAnimation = GetDeployAnimation(); _liftingSurface = GetLiftingSurface(); base.OnStart(state); }
public EngineWrapper(Part part) { if ((mEFX = part.transform.GetComponent<ModuleEnginesFX>()) != null) type = ModuleType.MODULEENGINESFX; else if ((mE = part.transform.GetComponent<ModuleEngines>()) != null) type = ModuleType.MODULEENGINES; else throw new ArgumentException("Unable to find engine-like module"); }
void Awake() { module = GetComponent <ModuleEnginesFX> (); if (module == null) { throw new Exception("Missing ModuleEnginesFX component."); } base.Awake(module); }
public SMIengineWrapper(Part part, string name) { engineFX = part.Modules.OfType <ModuleEnginesFX>().Where(p => p.engineID == name).FirstOrDefault(); if (engineFX != null) { type = EngineType.ModuleEngineFX; } //Debug.Log("SMIengineWrapper: engine type is " + type.ToString()); }
internal static Engine Normalise(ModuleEnginesFX engine) { return Engine.CreateEngineWithName(Part.FromGO(engine.gameObject).partInfo.title) .WithMode(x => { x.SeaLevelISP = engine.atmosphereCurve.Evaluate(1.0f); x.VacuumISP = engine.atmosphereCurve.Evaluate(0.0f); }); }
public FSengineWrapper(Part part, string name) { engineFX = part.Modules.OfType <ModuleEnginesFX>().Where(p => p.engineID == name).FirstOrDefault(); if (engineFX != null) { type = EngineType.ModuleEngineFX; } Log.dbg("FSengineWrapper: engine type is {0}", type); }
internal static Engine Normalise(ModuleEnginesFX engine) { return(Engine.CreateEngineWithName(Part.FromGO(engine.gameObject).partInfo.title) .WithMode(x => { x.SeaLevelISP = engine.atmosphereCurve.Evaluate(1.0f); x.VacuumISP = engine.atmosphereCurve.Evaluate(0.0f); })); }
private void setLimit(ChangeModes c, float f, KSPActionParam p) { foreach (PartModule m in this.part.Modules) { if (m is ModuleEngines) { ModuleEngines me = (ModuleEngines)m; if (!me.isOperational) { continue; } if (c == ChangeModes.DECREASE && me.thrustPercentage == 0f || c == ChangeModes.INCREASE && me.thrustPercentage == 100f) // 1.0.1: Fix for engines going >100 or <0 { continue; } if (c == ChangeModes.DECREASE) { me.thrustPercentage -= f; } else if (c == ChangeModes.INCREASE) { me.thrustPercentage += f; } else { me.thrustPercentage = f; } } else if (m is ModuleEnginesFX && m.isEnabled) // Squad, y u have separate module for NASA engines? :c { ModuleEnginesFX me = (ModuleEnginesFX)m; if (!me.isOperational) { continue; } if (c == ChangeModes.DECREASE && me.thrustPercentage == 0f || c == ChangeModes.INCREASE && me.thrustPercentage == 100f) // 1.0.1: Fix for engines going >100 or <0 { continue; } if (c == ChangeModes.DECREASE) { me.thrustPercentage -= f; } else if (c == ChangeModes.INCREASE) { me.thrustPercentage += f; } else { me.thrustPercentage = f; } } } }
public override void OnStartFinished(StartState state) { engineModule = part.GetComponents <ModuleEnginesFX>().Where(x => x.engineID == engineID).FirstOrDefault(); if (engineModule == null) { engineModule = part.GetComponents <ModuleEnginesFX>().FirstOrDefault(); ROLLog.error($"ROLDeployableEngine.OnStartFinished(): Could not locate engine by ID: {engineID} on part {part}. This will cause errors during gameplay. Trying default: {engineModule}"); } SetupEngineModuleGui(); }
public override void OnStart(PartModule.StartState state) { if (state == StartState.Editor) return; _attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; if (_attached_engine != null) _attached_engine.Fields["finalThrust"].guiFormat = "F5"; List<IChargedParticleSource> source_list = part.attachNodes.Where(atn => atn.attachedPart != null).SelectMany(atn => atn.attachedPart.FindModulesImplementing<IChargedParticleSource>()).ToList(); _attached_reactor = source_list.FirstOrDefault(); }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); engine = part.GetComponent<ModuleEnginesFX>(); Propellant fuelPropellant = new Propellant(); foreach (Propellant prop in engine.propellants) { if (prop.name != "ElectricCharge") fuelPropellant = prop; } ThrustCurve = new FloatCurve(); ThrustCurve.Add(0f, engine.maxThrust); ThrustCurve.Add(minPressure, minThrust); AtmoCurve = new FloatCurve(); AtmoCurve.Add(0f, engine.atmosphereCurve.Evaluate(0f)); float rate = FindFlowRate (engine.maxThrust,engine.atmosphereCurve.Evaluate(0f),fuelPropellant); AtmoCurve.Add(1f,FindIsp(minThrust,rate,fuelPropellant)); }
// Finds ModuleEnginesFX on the part private void LoadEngineModules() { engine = part.GetComponent<ModuleEnginesFX>(); }
public EngineData(ModuleEnginesFX e, float ispCutoff, float thrustCutoff) { //Do nothing if the engine has an AJEModule if (e.part.Modules.Contains("AJEModule")) { doNotCorrect = true; } //This makes sure that jet engines are handled differently foreach (Propellant p in e.propellants) if (p.name == "IntakeAir") { doNotCorrect = true; break; } if (doNotCorrect) return; //Both cutoffs enabled, both must be satisfied for atm rating if (ispCutoff != -1 && thrustCutoff != -1) { if ((e.atmosphereCurve.Evaluate(0) <= ispCutoff && e.maxThrust >= thrustCutoff)) { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(1) * e.g); } else { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(0) * e.g); } } //No cutoffs; all engines vacuum rated else if (ispCutoff == -1 && thrustCutoff == -1) { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(0) * e.g); } //No Isp Cutoff, but there is a thrust cutoff else if (ispCutoff == -1) { if (e.maxThrust >= thrustCutoff) { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(1) * e.g); } else { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(0) * e.g); } } //No thrust cutoff, but there is an Isp cutoff else { if (e.atmosphereCurve.Evaluate(0) <= ispCutoff) { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(1) * e.g); } else { mDot = e.maxThrust / (e.atmosphereCurve.Evaluate(0) * e.g); } } }
public override void OnStart(PartModule.StartState state) { engineType = originalName; // check whether we have the technologies available to be able to perform an upgrade if (state == StartState.Editor) { if (this.HasTechsRequiredToUpgrade()) { isupgraded = true; upgradePartModule(); } return; } fuel_gauge = part.stackIcon.DisplayInfo(); myAttachedEngine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; // if engine isn't already initialised, initialise it if (engineInit == false) { engineInit = true; } // if we can upgrade, let's do so if (isupgraded && isJet) { upgradePartModule (); } else { propellants = getPropellants (isJet); } // find attached thermal source foreach (AttachNode attach_node in part.attachNodes) { if (attach_node.attachedPart != null) { List<IThermalSource> sources = attach_node.attachedPart.FindModulesImplementing<IThermalSource> (); if (sources.Count > 0) { myAttachedReactor = sources.First (); if (myAttachedReactor != null) { break; } } } } setupPropellants(); hasstarted = true; //print ("Start Complete"); }
protected override void Init() { module = GetComponent<ModuleEnginesFX> (); if (module == null) { throw new Exception ("Missing ModuleEnginesFX component."); } GimbalRotation.addTo (gameObject); }
public EngineValue(global::Part part, ModuleEnginesFX enginefFx) : base(part) { this.enginefFx = enginefFx; }
public ModuleEngineAdapter(ModuleEnginesFX engineModuleFx) { this.engineModuleFx = engineModuleFx; engineType = EngineType.EngineFx; }
// Support for the new ModuleEnginesFX - lack of common interface between the 2 engins type is not fun // I can't even just copy ModuleEngines to a ModuleEnginesFX and use the same function since some field are readonly public void AddNewEngine(ModuleEnginesFX e) { if ((!e.EngineIgnited) || (!e.isEnabled)) { return; } // Compute the resource requirement at full thrust. // mdot = maxthrust / (Isp * g0) in tonnes per second // udot = mdot / mixdensity in units per second of propellant per ratio unit // udot * ratio_i : units per second of propellant i // Choose the worse Isp between now and after one timestep. // TODO: actually, pressure should be for the engine part, not for the spacecraft. // The pressure can easily vary by 1% from top to bottom of a spacecraft. // We'd need to compute the position of the part, which seems like a pain. float Isp0 = e.atmosphereCurve.Evaluate(atmP0); float Isp1 = e.atmosphereCurve.Evaluate(atmP1); double Isp = Math.Min(Isp0, Isp1); double udot = e.maxThrust / (Isp * 9.82 * e.mixtureDensity); // Tavert Issue #163 foreach (var propellant in e.propellants) { double maxreq = udot * propellant.ratio; addResource(propellant.id, propellant.currentRequirement, maxreq); } if (!e.getFlameoutState) { var thrustDirectionVector = new Vector3d(); foreach (var xform in e.thrustTransforms) { // The rotation makes a +z vector point in the direction that molecules are ejected // from the engine. The resulting thrust force is in the opposite direction. thrustDirectionVector += xform.rotation * new Vector3d(0, 0, -1d / (double)e.thrustTransforms.Count); } double cosineLosses = Vector3d.Dot(thrustDirectionVector, e.part.vessel.GetTransform().up); double usableFraction = e.thrustPercentage / 100f; if (e.useVelocityCurve) { usableFraction = e.velocityCurve.Evaluate((float)(e.part.vessel.orbit.GetVel() - e.part.vessel.mainBody.getRFrmVel(CoM)).magnitude); } double eMaxThrust = e.maxThrust * usableFraction * cosineLosses; double eMinThrust = e.throttleLocked ? eMaxThrust : (e.minThrust * usableFraction * cosineLosses); double eCurrentThrust = eMaxThrust * e.currentThrottle + eMinThrust * (1 - e.currentThrottle); thrustCurrent += eCurrentThrust * thrustDirectionVector; thrustMax += eMaxThrust * thrustDirectionVector; thrustMin += eMinThrust * thrustDirectionVector; Part p = e.part; ModuleGimbal gimbal = p.Modules.OfType<ModuleGimbal>().FirstOrDefault(); if (gimbal != null && !gimbal.gimbalLock) { double gimbalRange = gimbal.gimbalRange; torqueThrustPYAvailable += Math.Sin(Math.Abs(gimbalRange) * Math.PI / 180) * eCurrentThrust * (p.Rigidbody.worldCenterOfMass - CoM).magnitude; // TODO: close enough? } } }
public override void OnStart(PartModule.StartState state) { var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT); // calculate WasteHeat Capacity if (wasteheatPowerResource != null) { var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount; wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio; } if (state == StartState.Editor) return; _attached_engine = this.part.FindModuleImplementing<ModuleEnginesFX>(); //this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; _attached_warpable_engine = _attached_engine as ModuleEnginesWarp; if (_attached_engine != null) _attached_engine.Fields["finalThrust"].guiFormat = "F5"; else UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!"); // first try to look in part _attached_reactor = this.part.FindModuleImplementing<IChargedParticleSource>(); // try to find nearest if (_attached_reactor == null) _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1); if (_attached_reactor == null) { UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!"); return; } double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor; calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant; throtleExponent = Mathf.Abs(Mathf.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult)); exchanger_thrust_divisor = radius > _attached_reactor.GetRadius() ? _attached_reactor.GetRadius() * _attached_reactor.GetRadius() / radius / radius : radius * radius / _attached_reactor.GetRadius() / _attached_reactor.GetRadius(); // Does this really need to be done each update? Or at all since it uses particles instead of thermal power? }
private void BindEngine() { engine = null; engineFX = null; foreach (PartModule module in this.part.Modules) { if (module is ModuleEngines) { engine = module as ModuleEngines; break; } else if (module is ModuleEnginesFX) { engineFX = module as ModuleEnginesFX; break; } } }
public EngineBaseData(ModuleEnginesFX fx, FloatCurve isp, float thrust) { engineFX = fx; maxThrust = thrust; ispCurve = isp; }
public override void OnStart(PartModule.StartState state) { _g0 = PluginHelper.GravityConstant; _hasGearTechnology = String.IsNullOrEmpty(gearsTechReq) || PluginHelper.upgradeAvailable(gearsTechReq); _modifiedEngineBaseISP = baseISP * PluginHelper.ElectricEngineIspMult; //_attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX; _attached_engine = this.part.FindModuleImplementing<ModuleEnginesFX>(); var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT); // calculate WasteHeat Capacity if (wasteheatPowerResource != null) { var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount; wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier; wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio; } String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT }; this.resources_to_supply = resources_to_supply; _propellants = getPropellantsEngineType(); base.OnStart(state); if (state == StartState.Editor) { if (this.HasTechsRequiredToUpgrade()) upgradePartModule(); return; } if (this.HasTechsRequiredToUpgrade()) _hasrequiredupgrade = true; if (_attached_engine != null) _attached_engine.Fields["finalThrust"].guiFormat = "F5"; fuel_gauge = part.stackIcon.DisplayInfo(); Current_propellant = fuel_mode < _propellants.Count ? _propellants[fuel_mode] : _propellants.FirstOrDefault(); setupPropellants(); }
private bool SetEngineFxSuffix(string suffixName, object value, ModuleEnginesFX moduleEnginesFx) { switch (suffixName) { case "ACTIVE": var activate = (bool) value; if (activate) { moduleEnginesFx.Activate(); } else { moduleEnginesFx.Shutdown(); } return true; case "THRUSTLIMIT": var throttlePercent = (float) value; moduleEnginesFx.thrustPercentage = throttlePercent; return false; } return base.SetSuffix(suffixName, value); }
public EngineWrapper(ModuleEnginesFX mod) { mEFX = mod; type = ModuleType.MODULEENGINESFX; }
public override void OnAwake() { engine = part.FindModuleImplementing<ModuleEnginesFX>(); }
// Make "engine" and "engineFX" fields refer to the ModuleEngines and ModuleEnginesFX modules in part.Modules void FindModuleEngines() { foreach (PartModule pm in part.Modules) { if (pm is ModuleEngines) { engine = pm as ModuleEngines; IsPersistentEngine = true; } else { Debug.Log("No ModuleEngine found."); } if (pm is ModuleEnginesFX) { engineFX = pm as ModuleEnginesFX; } } }