void UnslaveTurrets() { using (var mtc = VesselModuleRegistry.GetModules <ModuleTargetingCamera>(vessel).GetEnumerator()) while (mtc.MoveNext()) { if (mtc.Current == null) { continue; } mtc.Current.slaveTurrets = false; } using (var rad = VesselModuleRegistry.GetModules <ModuleRadar>(vessel).GetEnumerator()) while (rad.MoveNext()) { if (rad.Current == null) { continue; } rad.Current.slaveTurrets = false; } if (weaponManager) { weaponManager.slavingTurrets = false; } slaveTurrets = false; }
public void Update() { if (HighLogic.LoadedSceneIsFlight) { drainDuration -= Time.deltaTime; if (drainDuration <= 0) { using (var intake = VesselModuleRegistry.GetModules <ModuleResourceIntake>(vessel).GetEnumerator()) while (intake.MoveNext()) { if (intake.Current == null) { continue; } intake.Current.intakeEnabled = true; } part.RemoveModule(this); } } if (!initialized) { //Debug.Log("[BDArmory.ModuleDrainIntakes]: " + this.part.name + "choked!"); initialized = true; using (var intake = VesselModuleRegistry.GetModules <ModuleResourceIntake>(vessel).GetEnumerator()) while (intake.MoveNext()) { if (intake.Current == null) { continue; } intake.Current.intakeEnabled = false; } } }
public override void OnStart(StartState state) { if (HighLogic.LoadedSceneIsFlight) { pingsData = new TargetSignatureData[dataCount]; pingWorldPositions = new Vector3[dataCount]; TargetSignatureData.ResetTSDArray(ref pingsData); launchWarnings = new List <TargetSignatureData>(); rwrIconLabelStyle = new GUIStyle(); rwrIconLabelStyle.alignment = TextAnchor.MiddleCenter; rwrIconLabelStyle.normal.textColor = Color.green; rwrIconLabelStyle.fontSize = 12; rwrIconLabelStyle.border = new RectOffset(0, 0, 0, 0); rwrIconLabelStyle.clipping = TextClipping.Overflow; rwrIconLabelStyle.wordWrap = false; rwrIconLabelStyle.fontStyle = FontStyle.Bold; audioSource = gameObject.AddComponent <AudioSource>(); audioSource.minDistance = 500; audioSource.maxDistance = 1000; audioSource.spatialBlend = 1; audioSource.dopplerLevel = 0; audioSource.loop = false; UpdateVolume(); BDArmorySetup.OnVolumeChange += UpdateVolume; if (!WindowRectRWRInitialized) { BDArmorySetup.WindowRectRwr = new Rect(BDArmorySetup.WindowRectRwr.x, BDArmorySetup.WindowRectRwr.y, RwrDisplayRect.height + BorderSize, RwrDisplayRect.height + BorderSize + HeaderSize); // BDArmorySetup.WindowRectRwr = new Rect(40, Screen.height - RwrDisplayRect.height, RwrDisplayRect.height + BorderSize, RwrDisplayRect.height + BorderSize + HeaderSize); WindowRectRWRInitialized = true; } using (var mf = VesselModuleRegistry.GetModules <MissileFire>(vessel).GetEnumerator()) while (mf.MoveNext()) { if (mf.Current == null) { continue; } mf.Current.rwr = this; // Set the rwr on all weapon managers to this. if (!weaponManager) { weaponManager = mf.Current; // Set the first found weapon manager as the one in control. } } //if (rwrEnabled) EnableRWR(); EnableRWR(); } }
private void EnableVessel() { foreach (Part p in vessel.parts) { var engine = p.FindModuleImplementing <ModuleEngines>(); var engineFX = p.FindModuleImplementing <ModuleEnginesFX>(); if (engine != null) { engine.allowRestart = true; } if (engineFX != null) { engineFX.allowRestart = true; } var command = p.FindModuleImplementing <ModuleCommand>(); var weapon = p.FindModuleImplementing <ModuleWeapon>(); if (weapon != null) { weapon.weaponState = ModuleWeapon.WeaponStates.Disabled; //allow weapons to be used again } if (command != null) { command.minimumCrew /= 10; //more elegant than a dict storing every crew part's cap to restore to original amount } var AI = p.FindModuleImplementing <IBDAIControl>(); if (AI != null) { AI.ActivatePilot(); //It's Alive! } var WM = p.FindModuleImplementing <MissileFire>(); if (WM != null) { WM.guardMode = true; WM.debilitated = false; } } vessel.ActionGroups.ToggleGroup(KSPActionGroup.Custom10); // restart engines if (!VesselModuleRegistry.GetModules <ModuleEngines>(vessel).Any(engine => engine.EngineIgnited)) // Find vessels that didn't activate their engines on AG10 and fire their next stage. { foreach (var engine in VesselModuleRegistry.GetModules <ModuleEngines>(vessel)) { engine.Activate(); } } disabled = false; }
public void Fire() { GameObject target = null; if (vessel.targetObject != null) { target = vessel.targetObject.GetVessel().gameObject; } part.decouple(0); foreach (BDModularGuidance bdmm in VesselModuleRegistry.GetModules <BDModularGuidance>(vessel)) { bdmm.HasFired = true; //bdmm.target = target; } // foreach (BDExplosivePart bde in VesselModuleRegistry.GetModules<BDExplosivePart>(vessel)) // { // //bde.target = target; // } }
void CommandButton(CommandFunction func, string buttonLabel, ref float buttonLine, float startY, float margin, float buttonGap, float buttonWidth, float buttonHeight, bool sendToWingmen, bool pressed, object data) { float yPos = startY + margin + ((buttonHeight + buttonGap) * buttonLine); if (GUI.Button(new Rect(margin, yPos, buttonWidth, buttonHeight), buttonLabel, pressed ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button)) { if (sendToWingmen) { if (wingmen.Count > 0) { List <int> .Enumerator index = focusIndexes.GetEnumerator(); while (index.MoveNext()) { func(wingmen[index.Current], index.Current, data); } index.Dispose(); } if (commandSelf) { using (var ai = VesselModuleRegistry.GetModules <IBDAIControl>(vessel).GetEnumerator()) while (ai.MoveNext()) { func(ai.Current, -1, data); // Note: this commands *all* AIs on the vessel. } } } else { func(null, -1, null); } } buttonLine++; }
// [KSPField(isPersistant = true, guiActive = true, guiActiveEditor = true, guiName = "#LOC_BDArmory_EjectOnImpendingDoom", // Eject if doomed // groupName = "pilotAI_Ejection", groupDisplayName = "#LOC_BDArmory_PilotAI_Ejection", groupStartCollapsed = true), // UI_FloatRange(minValue = 0f, maxValue = 1f, stepIncrement = 0.02f, scene = UI_Scene.All)] // public float ejectOnImpendingDoom = 0.2f; // Time to impact at which to eject. #endregion /// <summary> /// Begin managing a crew member in a part. /// </summary> /// <param name="crew">The proto crew member.</param> /// <param name="part">The part.</param> public IEnumerator Configure(ProtoCrewMember crew, Part part) { if (crew == null) { Debug.LogError("[BDArmory.KerbalSafety]: Cannot manage null crew."); Destroy(this); yield break; } if (part == null) { Debug.LogError("[BDArmory.KerbalSafety]: Crew cannot exist outside of a part."); Destroy(this); yield break; } while (part.vessel != null && (!part.vessel.loaded || part.vessel.packed)) { yield return(new WaitForFixedUpdate()); // Wait for the vessel to be loaded. (Avoids kerbals not being registered in seats.) } if (part.vessel == null) { yield break; } kerbalName = crew.displayName; this.crew = crew; switch (BDArmorySettings.KERBAL_SAFETY_INVENTORY) { case 1: this.crew.ResetInventory(true); // Reset the inventory to the default of a chute and a jetpack. break; case 2: this.crew.ResetInventory(false); // Reset the inventory to just a chute. break; } this.part = part; if (part.IsKerbalEVA()) { this.kerbalEVA = part.GetComponent <KerbalEVA>(); if (kerbalEVA.IsSeated()) { bool found = false; foreach (var s in VesselModuleRegistry.GetModules <KerbalSeat>(part.vessel)) { if (s.Occupant == part) { seat = s; found = true; break; } } if (!found) { Debug.LogWarning("[BDArmory.KerbalSafety]: Failed to find the kerbal seat that " + kerbalName + " occupies."); yield break; } } else // Free-falling EVA kerbal. { ejected = true; StartCoroutine(DelayedChuteDeployment()); StartCoroutine(RecoverWhenPossible()); } ConfigureKerbalEVA(kerbalEVA); } AddHandlers(); KerbalSafetyManager.Instance.kerbals.Add(kerbalName, this); if (BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("[BDArmory.KerbalSafety]: Managing the safety of " + kerbalName + (ejected ? " on EVA" : " in " + part.vessel.vesselName) + "."); } OnVesselModified(part.vessel); // Immediately check the vessel. }
public IEnumerator PerformanceTest() { var wait = new WaitForSeconds(0.1f); { // Note: this test has significant GC allocations due to the allocation of an intermediate list. int count = 0; int iters = 100000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { foreach (var mf in FlightGlobals.ActiveVessel.FindPartModulesImplementing <MissileFire>()) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via vessel.FindPartModulesImplementing<MissileFire>()"); } yield return(wait); { int count = 0; int iters = 100000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { if (FlightGlobals.ActiveVessel.FindPartModuleImplementing <MissileFire>() != null) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via vessel.FindPartModuleImplementing<MissileFire>()"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { foreach (var mf in VesselModuleRegistry.GetModules <MissileFire>(FlightGlobals.ActiveVessel)) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetModules<MissileFire>(vessel)"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { foreach (var mf in VesselModuleRegistry.GetMissileFires(FlightGlobals.ActiveVessel)) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetMissileFires(vessel)"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { if (VesselModuleRegistry.GetModule <MissileFire>(FlightGlobals.ActiveVessel) != null) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetModule<MissileFire>(vessel)"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { if (VesselModuleRegistry.GetModule <MissileFire>(FlightGlobals.ActiveVessel, true) != null) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetModule<MissileFire>(vessel, true)"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { if (VesselModuleRegistry.GetMissileFire(FlightGlobals.ActiveVessel) != null) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetMissileFire(vessel)"); } yield return(wait); { int count = 0; int iters = 10000000; var startTime = Time.realtimeSinceStartup; for (int i = 0; i < iters; ++i) { if (VesselModuleRegistry.GetMissileFire(FlightGlobals.ActiveVessel, true) != null) { ++count; } } Debug.Log($"DEBUG {FlightGlobals.ActiveVessel} has {count / iters} weapon managers, checked at {iters / (Time.realtimeSinceStartup - startTime)}/s via VesselModuleRegistry.GetMissileFire(vessel, true)"); } BDACompetitionMode.Instance.competitionStatus.Add("VesselModuleRegistry performance test complete."); }