/// <summary> /// Start up the module and initialize it /// </summary> /// <param name="state">The start state of the module</param> public override void OnStart(StartState state) { base.OnStart(state); rotationTransforms = part.FindModelTransforms(transformName); //find the engine for this part if (engineName != string.Empty) { for (int i = 0; i < part.Modules.Count; i++) { if ((part.Modules[i] is ModuleEngines) && (((ModuleEngines)part.Modules[i]).engineID == engineName)) { engine = (ModuleEngines)part.Modules[i]; //Debug.Log("[ENGINE ANIMATION] Found ModuleEngines"); } if (part.Modules[i] is ModuleKerbetrotterEngine) { kEngine = (ModuleKerbetrotterEngine)part.Modules[i]; //Debug.Log("[ENGINE ANIMATION] Found ModuleKerbetrotterEngine"); break; } } } minDegSec = 360 * minRotationSpeed; maxDegSec = 360 * maxRotationSpeed; valid = (rotationTransforms != null) & (rotationTransforms.Length > 0) && ((engine != null) || (kEngine != null)); }
private void updateAltitudeEngines() { if (altitudeEngines.Count > 0) { //get the center of the engines Vector3 center = new Vector3(); for (int i = 0; i < altitudeEngines.Count; i++) { center += altitudeEngines[i].heightTransform.position; } center /= altitudeEngines.Count; float heightSum = 0; int heightNum = 0; for (int i = 0; i < altitudeEngines.Count; i++) { ModuleKerbetrotterEngine engine = altitudeEngines[i]; float distance = engine.getAltitude(); if (!float.IsNaN(distance)) { heightSum += distance; heightNum++; } } float height = heightSum / heightNum; for (int i = 0; i < altitudeEngines.Count; i++) { altitudeEngines[i].setHoverHeight(height); } } }
//Update the status of the engines when an engine was added or removed from the list of active hovering engines private void updateEngines() { //distances.Clear(); if (engines.Count > 0) { //get the center of the engines Vector3 center = new Vector3(); float maxHoverHeight = float.PositiveInfinity; float minHoverHeight = float.NegativeInfinity; for (int i = 0; i < engines.Count; i++) { center += engines[i].heightTransform.position; maxHoverHeight = Math.Min(maxHoverHeight, engines[i].maxHoverHeight); minHoverHeight = Math.Max(minHoverHeight, engines[i].minHoverHeight); } center /= engines.Count; double terrainHeight = FlightGlobals.ActiveVessel.pqsAltitude; bool valid = ((terrainHeight < 0) && ((vessel.mainBody.ocean)))? FlightGlobals.ActiveVessel.altitude < (maxHoverHeight + 1) : ((FlightGlobals.ActiveVessel.altitude - terrainHeight) < (maxHoverHeight + 1)); //when we just switched to hovering, set the height if (!valid) { double height = vessel.mainBody.ocean ? FlightGlobals.ActiveVessel.altitude : (FlightGlobals.ActiveVessel.altitude - FlightGlobals.ActiveVessel.pqsAltitude); ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_KERBETROTTER.engine.hoverfail", maxHoverHeight), 2f, ScreenMessageStyle.UPPER_CENTER)); for (int i = 0; i < engines.Count; i++) { engines[i].setHoverEnabled(false, false); } engines.Clear(); } else { float heightSum = 0; int heightNum = 0; for (int i = 0; i < engines.Count; i++) { ModuleKerbetrotterEngine engine = engines[i]; float distance = engine.getSurfaceDistance(); if (!float.IsNaN(distance)) { heightSum += distance; heightNum++; } } float height = Mathf.Clamp(heightSum / heightNum, minHoverHeight, maxHoverHeight); for (int i = 0; i < engines.Count; i++) { ModuleKerbetrotterEngine engine = engines[i]; engine.setHoverHeight(height); } } } }
//event when an engine is added to the hover list private void onEngineHoverChange(ModuleKerbetrotterEngine engine, bool hoverActive) { if (engine.vessel == vessel) { if ((hoverActive) && !engines.Contains(engine)) { engines.Add(engine); changed = true; return; } if ((!hoverActive) && engines.Contains(engine)) { engines.Remove(engine); changed = true; return; } } }
/// <summary> /// Start up the module and initialize it /// </summary> /// <param name="state">The start state of the module</param> public override void OnStart(StartState state) { base.OnStart(state); //referenceTransformID = vessel.referenceTransformId; thrustTransform = part.FindModelTransform(thrustTransformName.Trim()); referenceTransform = part.FindModelTransform(referenceTransformName.Trim()); //updateMajorAxis(); updateAndvanceControlVisibility(); //find the engine for this part if (engineName != string.Empty) { for (int i = 0; i < part.Modules.Count; i++) { if ((part.Modules[i] is ModuleKerbetrotterEngine) && (((ModuleKerbetrotterEngine)part.Modules[i]).EngineName == engineName)) { engine = (ModuleKerbetrotterEngine)part.Modules[i]; break; } } } //find a corresponding animation if specified if (animationID != string.Empty) { for (int i = 0; i < part.Modules.Count; i++) { if ((part.Modules[i] is ModuleAnimateGeneric) && (((ModuleAnimateGeneric)part.Modules[i]).moduleID == animationID)) { anim = (ModuleAnimateGeneric)part.Modules[i]; break; } } } }
/// <summary> /// Start up the module and initialize it /// </summary> /// <param name="state">The start state of the module</param> public override void OnStart(StartState state) { base.OnStart(state); rotationTransforms = part.FindModelTransforms(transformName); //find the engine for this part if (engineName != string.Empty) { for (int i = 0; i < part.Modules.Count; i++) { if ((part.Modules[i] is ModuleKerbetrotterEngine) && (((ModuleKerbetrotterEngine)part.Modules[i]).EngineName == engineName)) { engine = (ModuleKerbetrotterEngine)part.Modules[i]; break; } } } minDegSec = 360 * minRotationSpeed; maxDegSec = 360 * maxRotationSpeed; valid = (rotationTransforms != null) & (rotationTransforms.Length > 0) & (engine != null); }
/// <summary> /// Free all resources when the part is destroyed /// </summary> public void OnDestroy() { engine = null; rotationTransforms = null; }
/// <summary> /// Free all resources when the part is destroyed /// </summary> public void OnDestroy() { anim = null; engine = null; }
//event when an engine is added to the hover list private void onEngineHoverChange(ModuleKerbetrotterEngine engine, bool hoverActive, bool holdAltitude) { if (engine.vessel == vessel) { if (hoverActive) { if (holdAltitude) { //see if the terrain engines contain this engine if (terrainEngines.Contains(engine)) { terrainEngines.Remove(engine); terrainEnginesChanged = true; } //see if the engine needs to be added to the altitude engines if (!altitudeEngines.Contains(engine)) { altitudeEngines.Add(engine); altitudeEnginesChanged = true; } } else { bool fromAltitude = false; //see if the engine needs to be added to the altitude engines if (altitudeEngines.Contains(engine)) { altitudeEngines.Remove(engine); altitudeEnginesChanged = true; fromAltitude = true; } //see if the terrain engines contain this engine if (!terrainEngines.Contains(engine)) { if (fromAltitude) { switchToTerrainEngines.Add(engine); altitudeEnginesSwitched = true; } else { terrainEngines.Add(engine); terrainEnginesChanged = true; } } } } else { //remove the engine from the terrain engines if (terrainEngines.Contains(engine)) { terrainEngines.Remove(engine); terrainEnginesChanged = true; } //remove the engine from the altitude engines if (altitudeEngines.Contains(engine)) { altitudeEngines.Remove(engine); altitudeEnginesChanged = true; } } } }