public EngineModule(Part part) { // RAPIERs have two engine modules - they share an emissive texture, but not a throttle value modules = part.FindModulesImplementing <ModuleEngines>(); // do it once, do it in the right place moduleCount = modules.Count; if (moduleCount < 1) { throw new Exception("could not locate an engine on part: " + part.name); } foreach (var module in modules) { if (module == null) // this is how much I trust the KSP API... { throw new Exception("could not really locate an engine on part: " + part.name); } } hasEmissive = false; try { // should pretty reliably test that we can read from the emissive engineEmissiveModule = part.FindModuleImplementing <FXModuleAnimateThrottle>(); float emissive = 1 + engineEmissiveModule.animState; // should throw nullref on no emissive if (emissive >= 1) { hasEmissive = true; } } catch (Exception) { /* nothing to do - no emissive isn't a big deal really */ } }
static Vector3d FixedUpdateFor(WarpableEngine warpableEngine, float throttle) { // Need to calculate resource consumption, calculate thrust and finally apply the acceleration. Vector3d finalAcc = new Vector3d(); if (warpableEngine.isEngineFX == false && warpableEngine.engine != null) { warpableEngine.engine.requestedThrottle = warpableEngine.engine.currentThrottle = throttle / 100.0f; warpableEngine.engine.GetType().GetMethod("UpdatePropellantStatus", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(warpableEngine.engine, null); warpableEngine.engine.finalThrust = warpableEngine.engine.CalculateThrust(); try { if (warpableEngine.engine.flameout || warpableEngine.engine.engineShutdown) { warpableEngine.engine.DeactivatePowerFX(); warpableEngine.engine.DeactivateRunningFX(); warpableEngine.engine.finalThrust = 0.0f; } else { warpableEngine.engine.ActivatePowerFX(); warpableEngine.engine.ActivateRunningFX(); warpableEngine.engine.part.findFxGroup("power").SetPower(warpableEngine.engine.finalThrust / warpableEngine.engine.maxThrust); warpableEngine.engine.part.findFxGroup("running").SetPower(warpableEngine.engine.finalThrust / warpableEngine.engine.maxThrust); if (warpableEngine.engine.part.Modules.Contains("FXModuleAnimateThrottle")) { FXModuleAnimateThrottle m = warpableEngine.engine.part.Modules["FXModuleAnimateThrottle"] as FXModuleAnimateThrottle; //m.isEnabled = false; if (m.animation.IsPlaying(m.animationName) == false) { m.animation.Play(m.animationName); } m.animation[m.animationName].normalizedTime = throttle; m.gameObject.SampleAnimation(m.animation[m.animationName].clip, throttle / m.animation[m.animationName].clip.length); } } } catch (Exception e) { } Vector3d averageThrustVector = new Vector3d(); foreach (Transform tf in warpableEngine.engine.thrustTransforms) { averageThrustVector += tf.forward * -1; } averageThrustVector /= warpableEngine.engine.thrustTransforms.Count; finalAcc = averageThrustVector.normalized * warpableEngine.engine.finalThrust / warpableEngine.vessel.GetTotalMass(); return(finalAcc); } else if (warpableEngine.isEngineFX == true && warpableEngine.engineFX != null) { warpableEngine.engineFX.requestedThrottle = warpableEngine.engineFX.currentThrottle = throttle / 100.0f; warpableEngine.engineFX.GetType().GetMethod("UpdatePropellantStatus", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(warpableEngine.engineFX, null); warpableEngine.engineFX.finalThrust = warpableEngine.engineFX.CalculateThrust(); try { if (warpableEngine.engineFX.flameout || warpableEngine.engineFX.engineShutdown) { warpableEngine.engineFX.part.Effect(warpableEngine.engineFX.powerEffectName, 0.0f); warpableEngine.engineFX.part.Effect(warpableEngine.engineFX.runningEffectName, 0.0f); warpableEngine.engineFX.finalThrust = 0.0f; } else { warpableEngine.engineFX.part.Effect(warpableEngine.engineFX.powerEffectName, warpableEngine.engineFX.finalThrust / warpableEngine.engineFX.maxThrust); warpableEngine.engineFX.part.Effect(warpableEngine.engineFX.runningEffectName, warpableEngine.engineFX.finalThrust / warpableEngine.engineFX.maxThrust); if (warpableEngine.engineFX.part.Modules.Contains("FXModuleAnimateThrottle")) { FXModuleAnimateThrottle m = warpableEngine.engineFX.part.Modules["FXModuleAnimateThrottle"] as FXModuleAnimateThrottle; //m.isEnabled = false; if (m.animation.IsPlaying(m.animationName) == false) { m.animation.Play(m.animationName); } m.animation[m.animationName].normalizedTime = throttle; m.gameObject.SampleAnimation(m.animation[m.animationName].clip, throttle / m.animation[m.animationName].clip.length); } } } catch (Exception e) { } Vector3d averageThrustVector = new Vector3d(); foreach (Transform tf in warpableEngine.engineFX.thrustTransforms) { averageThrustVector += tf.forward * -1; } averageThrustVector /= warpableEngine.engineFX.thrustTransforms.Count; finalAcc = averageThrustVector.normalized * warpableEngine.engineFX.finalThrust / warpableEngine.vessel.GetTotalMass(); return(finalAcc); } else { return(Vector3d.zero); } }