public override void RepairPart() { engine = part.FindModuleImplementing <ModuleEngines>(); switch (failureType) { case "Fuel Flow Failure": engine.Activate(); Debug.Log("[OhScrap]: Re-activated " + SYP.ID); break; case "Underthrust": engine.thrustPercentage = originalThrust; Debug.Log("[OhScrap]: Reset Thrust on " + SYP.ID); break; case "Gimbal Failure": gimbal.gimbalLock = false; break; case "Fuel Line Leak": CancelInvoke("LeakFuel"); break; default: return; } }
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 override void OnUpdate() { if (!HighLogic.LoadedSceneIsFlight || !autoJettison) { return; } if (decoupler != null && !decoupler.isDecoupled) { double g = part.vessel.geeForce; geeForceDisplay = g; if (g < geeForce) { gTime = Planetarium.GetUniversalTime(); } else if (gTime + 0.25 < Planetarium.GetUniversalTime()) { decoupler.Decouple(); ModuleEngines e = part.FindModuleImplementing <ModuleEngines>(); if (e != null) { e.Activate(); } } } }
public override void OnUpdate() { if (sequentialFire != saveSequentialFire) { UpdateSequentialFire(); } if (!sequentialFire) { return; } if (running && sequence == 1) { if (!engine.EngineIgnited) { engine.Activate(); } if (jettison != null && !jettison.isJettisoned) { jettison.Jettison(); } double r = part.Resources["SolidFuel"].amount / part.Resources["SolidFuel"].maxAmount; if (r <= overlap) { sequence--; foreach (Part counterpart in this.part.symmetryCounterparts) { counterpart.Modules.OfType <ModuleBdbSequentialFire>().FirstOrDefault().sequence--; } } } }
public override void RepairPart() { switch (failureType) { case "Fuel Flow Failure": engine.Activate(); Debug.Log("[OhScrap]: Re-activated " + SYP.ID); break; case "Underthrust": case "Stable Underthrust": fuelFlowMultiplier = 1f; engineWrapper.SetFuelFlowMult(1f); Debug.Log("[OhScrap]: Reset Thrust on " + SYP.ID); break; case "Gimbal Failure": gimbal.gimbalLock = false; break; case "Fuel Line Leak": CancelInvoke("LeakFuel"); break; case "Performance Loss": engineWrapper.SetFuelIspMult(1f); Debug.Log("[OhScrap]: Reset Isp on " + SYP.ID); break; default: return; } }
private void ActivateEscapeEngine() { if (escapeEngineStartTime <= 0) { escapeEngineStartTime = Planetarium.GetUniversalTime(); escapeEngine.Activate(); } }
private void ActivatePitchEngine() { if (pitchEngineStartTime <= 0) { pitchEngineStartTime = Planetarium.GetUniversalTime(); pitchEngine.Activate(); } }
private void ActivateJettisonEngine() { if (jettisonEngineStartTime <= 0) { jettisonEngineStartTime = Planetarium.GetUniversalTime(); jettisonEngine.Activate(); } }
internal override void Toggle() { if (GetState()) { if (engineModule.allowShutdown && (action == ActionType.Toggle || action == ActionType.Deactivate)) { engineModule.Shutdown(); } } else { if (/*engineModule.allowRestart &&*/ (action == ActionType.Toggle || action == ActionType.Activate)) { engineModule.Activate(); } } }
private void ActivateEngine() { if (currentEngineState == true) { currentModuleEngine.Activate(); } //currentModuleEngine.useEngineResponseTime = true; }
public override void OnUpdate() { if (!engineIsFX) { engineIsOn = modEng.EngineIgnited; } else { engineIsOn = modEngFX.EngineIgnited; } foreach (var anim in engineStates) { if (engineIsOn && anim.normalizedTime < WaitForAnimation) { anim.speed = 1; if (engineIsFX) { modEngFX.Shutdown(); } else { modEng.Shutdown(); } } if (anim.normalizedTime >= WaitForAnimation && anim.speed > 0) { if (engineIsFX) { modEngFX.Activate(); } else { modEng.Activate(); } } if (anim.normalizedTime >= 1) { anim.speed = 0; anim.normalizedTime = 1; } if (anim.normalizedTime >= 1 && !engineIsOn) { anim.speed = -1; } if (anim.normalizedTime < 0) { anim.speed = 0; anim.normalizedTime = 0; } } }
/// <summary> /// Toggles all of the engines in the selected group that can be toggled /// (activates them if they're deactivated, shuts them off if they're active). /// /// Note that, unlike the core `fc` version of this method, it is possible /// to activate engines that are not in the current stage using this method. /// </summary> /// <param name="groupId">A number from 1 to 31 (inclusive) to select a specific group, or 0 to select all groups.</param> /// <param name="newState">When true, activates engines in the group. When false, deactivates them.</param> /// <returns>1 if any engines were toggled, 0 otherwise.</returns> public double SetEnginesEnabled(double groupId, bool newState) { int id = (int)groupId; double anyChanged = 0.0; if (id == 0) { for (int i = 0; i < vc.engineGroup.Length; ++i) { ModuleEngines me = vc.engineGroup[i].engine; Part thatPart = me.part; if (thatPart.inverseStage == StageManager.CurrentStage || !newState) { if (me.EngineIgnited != newState) { if (newState && me.allowRestart) { me.Activate(); anyChanged = 1.0; } else if (me.allowShutdown) { me.Shutdown(); anyChanged = 1.0; } } } } } else { for (int i = 0; i < vc.engineGroup.Length; ++i) { if (vc.engineGroup[i].partId == id) { ModuleEngines me = vc.engineGroup[i].engine; if (me.EngineIgnited != newState) { if (newState && me.allowRestart) { me.Activate(); anyChanged = 1.0; } else if (me.allowShutdown) { me.Shutdown(); anyChanged = 1.0; } } } } } return(anyChanged); }
public void StartEngine() { reactorState = EReactorStates.Charged; currentElectricCharge = 0f; Events["ChargeCapacitor"].guiName = kShutdownEngine; getCurrentEngine(); engine.Activate(); engine.part.force_activate(); }
private void ActivatePitchEngine() { if (_pitchEngineStartTime <= 0) { _pitchEngineStartTime = Planetarium.GetUniversalTime(); if (_pitchEngine != null) { _pitchEngine.Activate(); } } }
private void ActivateEscapeEngine() { if (_escapeEngineStartTime <= 0) { _escapeEngineStartTime = Planetarium.GetUniversalTime(); if (_escapeEngine != null) { _escapeEngine.Activate(); } } }
public void DoJettison() { if (!escapeEngine.flameout) { escapeEngine.Activate(); } else { jettisonEngine.Activate(); } if (part.Modules.Contains("ModuleDecouple")) { part.FindModulesImplementing <ModuleDecouple>().FirstOrDefault().Decouple(); } }
public void Activate() { switch (engineType) { case EngineType.Engine: engineModule.Activate(); break; case EngineType.EngineFx: engineModuleFx.Activate(); break; default: throw new ArgumentOutOfRangeException(); } }
public override void RepairPart() { engine = part.FindModuleImplementing <ModuleEngines>(); if (engine == null) { engineFX = part.FindModuleImplementing <ModuleEnginesFX>(); } switch (failureType) { case "Fuel Flow Failure": if (engine != null) { engine.Activate(); } else { engineFX.Activate(); } Debug.Log("[UPFM]: Re-activated " + SYP.ID); break; case "Underthrust": if (engine != null) { engine.thrustPercentage = 100; } else { engineFX.thrustPercentage = 100; } Debug.Log("[UPFM]: Reset Thrust on " + SYP.ID); break; case "Gimbal Failure": gimbal.gimbalLock = false; break; case "Fuel Line Leak": CancelInvoke("LeakFuel"); break; default: return; } }
// Restore engines control without reactivating them private void ActivateEngines() { foreach (Part p in FlightGlobals.ActiveVessel.Parts) { foreach (PartModule pm in p.Modules) { if (!(pm is ModuleEngines)) continue; ModuleEngines eng = (ModuleEngines) pm; if (eng.engineType == EngineType.LiquidFuel | eng.engineType == EngineType.Nuclear) { eng.Events["Activate"].guiActive = true; } if (!deactivatedEngines.Contains(eng)) continue; eng.Activate(); deactivatedEngines.Remove(eng); } } }
private bool SetEngineSuffix(string suffixName, object value, ModuleEngines moduleEngines) { switch (suffixName) { case "ACTIVE": var activate = Convert.ToBoolean(value); if (activate) { moduleEngines.Activate(); } else { moduleEngines.Shutdown(); } return(true); case "THRUSTLIMIT": var throttlePercent = (float)Convert.ToDouble(value); moduleEngines.thrustPercentage = throttlePercent; return(true); } return(base.SetSuffix(suffixName, value)); }
private bool SetEngineSuffix(string suffixName, object value, ModuleEngines moduleEngines) { switch (suffixName) { case "ACTIVE": var activate = (bool) value; if (activate) { moduleEngines.Activate(); } else { moduleEngines.Shutdown(); } return true; case "THRUSTLIMIT": var throttlePercent = (float) value; moduleEngines.thrustPercentage = throttlePercent; return false; } return base.SetSuffix(suffixName, value); }
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); } }
void Update() { if (!gameObject.activeInHierarchy || !HighLogic.LoadedSceneIsFlight || BDArmorySetup.GameIsPaused) { return; } transform.rotation = Quaternion.FromToRotation(Vector3.up, -FlightGlobals.getGeeForceAtPosition(transform.position)); fuel = parentPart.Resources.Where(pr => pr.resourceName == "LiquidFuel").FirstOrDefault(); if (disableTime < 0) //only have fire do it's stuff while burning and not during FX timeout { if (!surfaceFire) //is fire inside tank, or an incendiary substance on the part's surface? { if (!lookedForEngine) { engine = parentPart.FindModuleImplementing <ModuleEngines>(); lookedForEngine = true; //have this only called once, not once per update tick } if (engine != null) { if (engine.throttleLocked && !engine.allowShutdown) //likely a SRB { if (parentPart.RequestResource("SolidFuel", (double)(burnRate * TimeWarp.deltaTime)) <= 0) { hasFuel = false; } solid = parentPart.Resources.Where(pr => pr.resourceName == "SolidFuel").FirstOrDefault(); if (solid != null) { if (solid.amount < solid.maxAmount * 0.66f) { engine.Activate(); //SRB lights from unintended ignition source } if (solid.amount < solid.maxAmount * 0.15f) { tntMassEquivilent += Mathf.Clamp((float)solid.amount, ((float)solid.maxAmount * 0.05f), ((float)solid.maxAmount * 0.2f)); Detonate(); //casing's full of holes and SRB fuel's burnt to the point it can easily start venting through those holes } } } else { if (engine.EngineIgnited) { if (parentPart.RequestResource("LiquidFuel", (double)(burnRate * TimeWarp.deltaTime)) <= 0) { hasFuel = false; } } else { hasFuel = false; } } } else { if (fuel != null) { if (fuel.amount > (fuel.maxAmount * 0.15f) || (fuel.amount > 0 && fuel.amount < (fuel.maxAmount * 0.10f))) { fuel.amount -= (burnRate * Mathf.Clamp((float)((1 - (fuel.amount / fuel.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 4 * BDArmorySettings.BD_TANK_LEAK_RATE) * TimeWarp.deltaTime); burnScale = Mathf.Clamp((float)((1 - (fuel.amount / fuel.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 2 * BDArmorySettings.BD_TANK_LEAK_RATE); } else if (fuel.amount < (fuel.maxAmount * 0.15f) && fuel.amount > (fuel.maxAmount * 0.10f)) { Detonate(); } else { hasFuel = false; } } ox = parentPart.Resources.Where(pr => pr.resourceName == "Oxidizer").FirstOrDefault(); if (ox != null) { if (ox.amount > 0) { ox.amount -= (burnRate * Mathf.Clamp((float)((1 - (ox.amount / ox.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 4 * BDArmorySettings.BD_TANK_LEAK_RATE) * TimeWarp.deltaTime); } else { hasFuel = false; } } mp = parentPart.Resources.Where(pr => pr.resourceName == "MonoPropellant").FirstOrDefault(); if (mp != null) { if (mp.amount > (mp.maxAmount * 0.15f) || (mp.amount > 0 && mp.amount < (mp.maxAmount * 0.10f))) { mp.amount -= (burnRate * Mathf.Clamp((float)((1 - (mp.amount / mp.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 4 * BDArmorySettings.BD_TANK_LEAK_RATE) * TimeWarp.deltaTime); if (burnScale < 0) { burnScale = Mathf.Clamp((float)((1 - (mp.amount / mp.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 2 * BDArmorySettings.BD_TANK_LEAK_RATE); } } else if (mp.amount < (mp.maxAmount * 0.15f) && mp.amount > (mp.maxAmount * 0.10f)) { Detonate(); } else { hasFuel = false; } } ec = parentPart.Resources.Where(pr => pr.resourceName == "ElectricCharge").FirstOrDefault(); if (ec != null) { if (ec.amount > 0) { ec.amount -= (burnRate * TimeWarp.deltaTime); Mathf.Clamp((float)ec.amount, 0, Mathf.Infinity); if (burnScale < 0) { burnScale = 1; } } if ((Time.time - startTime > 30) && engine == null) { Detonate(); } } } } if (BDArmorySettings.BD_FIRE_HEATDMG) { if (parentPart.temperature < 1300) { if (fuel != null) { parentPart.temperature += burnRate * Mathf.Clamp((float)((1 - (fuel.amount / fuel.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 4 * BDArmorySettings.BD_TANK_LEAK_RATE) * Time.deltaTime; } else if (mp != null) { parentPart.temperature += burnRate * Mathf.Clamp((float)((1 - (mp.amount / mp.maxAmount)) * 4), 0.1f * BDArmorySettings.BD_TANK_LEAK_RATE, 4 * BDArmorySettings.BD_TANK_LEAK_RATE) * Time.deltaTime; } else if (ec != null || ox != null) { parentPart.temperature += burnRate * BDArmorySettings.BD_FIRE_DAMAGE * Time.deltaTime; } } } if (BDArmorySettings.BATTLEDAMAGE && BDArmorySettings.BD_FIRE_DOT) { if (BDArmorySettings.BD_FIRE_HEATDMG) { if (parentPart.temperature > 1000) { parentPart.AddDamage(BDArmorySettings.BD_FIRE_DAMAGE * Time.deltaTime); } } else { parentPart.AddDamage(BDArmorySettings.BD_FIRE_DAMAGE * Time.deltaTime); } //////////////////////////////////////////////// ScoreAccumulator = 0; var aName = SourceVessel; var tName = parentPart.vessel.GetName(); if (aName != null && tName != null && aName != tName && BDACompetitionMode.Instance.Scores.ContainsKey(aName) && BDACompetitionMode.Instance.Scores.ContainsKey(tName)) { if (BDArmorySettings.REMOTE_LOGGING_ENABLED) { BDAScoreService.Instance.TrackDamage(aName, tName, BDArmorySettings.BD_FIRE_DAMAGE); } // Track damage. Moving this here to properly track damage per tick var tData = BDACompetitionMode.Instance.Scores[tName]; if (tData.damageFromBullets.ContainsKey(aName)) { tData.damageFromBullets[aName] += BDArmorySettings.BD_FIRE_DAMAGE; } else { tData.damageFromBullets.Add(aName, BDArmorySettings.BD_FIRE_DAMAGE); } if (ScoreAccumulator >= 1) //could be reduced, gaining +1 hit per sec, per fire seems high { var aData = BDACompetitionMode.Instance.Scores[aName]; aData.Score += 1; if (parentPart.vessel.GetName() == "Pinata") { aData.PinataHits++; } tData.lastPersonWhoHitMe = aName; tData.lastHitTime = Planetarium.GetUniversalTime(); tData.everyoneWhoHitMe.Add(aName); // Track hits if (tData.hitCounts.ContainsKey(aName)) { ++tData.hitCounts[aName]; } else { tData.hitCounts.Add(aName, 1); } } } else { ScoreAccumulator += 1 * Time.deltaTime; } } } if ((!hasFuel && disableTime < 0 && burnTime < 0) || (burnTime > 0 && disableTime < 0 && Time.time - startTime > burnTime)) { disableTime = Time.time; //grab time when emission stops foreach (var pe in pEmitters) { if (pe != null) { pe.emit = false; } } } else { foreach (var pe in pEmitters) { pe.maxSize = burnScale; pe.minSize = burnScale * 1.2f; } } if (disableTime > 0 && Time.time - disableTime > _highestEnergy) //wait until last emitted particle has finished { gameObject.SetActive(false); } if (engine != null && enginerestartTime > 0 && Time.time - 10 > enginerestartTime) { engine.Activate(); enginerestartTime = -1; } //////////////////////////////////////////// }
public override void StartEngine() { currentEngine.Activate(); }
public void Fire() { Debug.Log("<color=#FF8C00ff>Comfortable Landing:</color>Landing Burn!"); ScreenMessages.PostScreenMessage("<color=#00ff00ff>[ComfortableLanding]Landing Burn!</color>", 3f, ScreenMessageStyle.UPPER_CENTER); engine.Activate(); }
virtual internal void fire() { log.debug("Firing engine"); engine.Activate(); status = Status.Firing; }
public void AbortAction(KSPActionParam param) { aborting = true; escapeEngine.Activate(); }
void FixedUpdate() { //todo: check if vtolengines are attached if (HighLogic.LoadedSceneIsFlight) { vtolEngines = vessel.FindPartModulesImplementing <BDVTOLAnimator>(); } BDVTOLAnimator controllerVTOL = null; foreach (var vtol in vtolEngines) { if (vtol != null) { controllerVTOL = vtol; } } if (controllerVTOL != null) { if (HighLogic.LoadedSceneIsFlight && engine.EngineIgnited != controllerVTOL.part.FindModuleImplementing <ModuleEngines>().EngineIgnited) { if (controllerVTOL.part.FindModuleImplementing <ModuleEngines>().EngineIgnited) { engine.Activate(); } else { engine.Shutdown(); } } float vtolEnginesTorque = 0; foreach (var vtolEngine in vtolEngines) { if (HighLogic.LoadedSceneIsFlight) { vtolEnginesTorque += Mathf.Abs(Mathf.Sin(vtolEngine.currentAngle * Mathf.Deg2Rad) * vtolEngine.part.FindModuleImplementing <ModuleEngines>().finalThrust *Vector3.Distance(vtolEngine.thrustPosition, vessel.findWorldCenterOfMass())); } else { //vtolEnginesTorque += Mathf.Sin(vtolEngine.currentAngle * vtolEngine.part.FindModuleImplementing<ModuleEngines>().maxThrust * Vector3.Distance(vtolEngine.thrustPosition, vessel.findWorldCenterOfMass())); } } if (HighLogic.LoadedSceneIsFlight) { float engineThrust = vtolEnginesTorque / Vector3.Distance(part.FindModelTransform(engine.thrustVectorTransformName).position, vessel.findWorldCenterOfMass()); engine.minThrust = engineThrust; engine.maxThrust = engineThrust; } foreach (var anim in deployStates) { if (controllerVTOL.vtolModeEnabled && anim.normalizedTime < 1) { anim.speed = 1; } else if (controllerVTOL.vtolModeEnabled) { anim.speed = 0; anim.normalizedTime = 1; } else if (anim.normalizedTime > 0) { anim.speed = -1; } else { anim.speed = 0; anim.normalizedTime = 0; } } } }