// Use this for initialization void Start () { status = playerShip.GetComponent<ShipStatus>(); firingSystem = targetingSystem.GetComponent<MissileFire>(); mouseControl = playerShip.GetComponent<SmoothMouseLook>(); showNavComm = false; stateTimerSec = 0.25f; startTime = Time.time; }
void Awake() { if (!vessel) { vessel = GetComponent <Vessel>(); } if (!vessel) { //Debug.Log ("[BDArmory]: TargetInfo was added to a non-vessel"); Destroy(this); return; } //destroy this if a target info is already attached to the vessel IEnumerator otherInfo = vessel.gameObject.GetComponents <TargetInfo>().GetEnumerator(); while (otherInfo.MoveNext()) { if ((object)otherInfo.Current != this) { Destroy(this); return; } } Team = null; bool foundMf = false; List <MissileFire> .Enumerator mf = vessel.FindPartModulesImplementing <MissileFire>().GetEnumerator(); while (mf.MoveNext()) { foundMf = true; Team = mf.Current.Team; weaponManager = mf.Current; break; } mf.Dispose(); if (!foundMf) { List <MissileBase> .Enumerator ml = vessel.FindPartModulesImplementing <MissileBase>().GetEnumerator(); while (ml.MoveNext()) { isMissile = true; MissileBaseModule = ml.Current; Team = ml.Current.Team; break; } ml.Dispose(); } vessel.OnJustAboutToBeDestroyed += AboutToBeDestroyed; //add delegate to peace enable event BDArmorySetup.OnPeaceEnabled += OnPeaceEnabled; //lifeRoutine = StartCoroutine(LifetimeRoutine()); // TODO: CHECK BEHAVIOUR AND SIDE EFFECTS! if (!isMissile && Team != null) { GameEvents.onVesselPartCountChanged.Add(VesselModified); //massRoutine = StartCoroutine(MassRoutine()); // TODO: CHECK BEHAVIOUR AND SIDE EFFECTS! } }
public static List <TargetInfo> GetAllTargetsExcluding(List <TargetInfo> excluding, MissileFire mf) { List <TargetInfo> finalTargets = new List <TargetInfo>(); BDArmorySettings.BDATeams team = BoolToTeam(mf.team); foreach (var target in TargetDatabase[team]) { if (target && target.Vessel && mf.CanSeeTarget(target.Vessel) && !excluding.Contains(target)) { finalTargets.Add(target); } } return(finalTargets); }
public static TargetSignatureData GetHeatTarget(Ray ray, float scanRadius, float highpassThreshold, bool allAspect, MissileFire mf = null) { float minScore = highpassThreshold; float minMass = 0.5f; TargetSignatureData finalData = TargetSignatureData.noTarget; float finalScore = 0; foreach (var vessel in BDATargetManager.LoadedVessels) { if (!vessel || !vessel.loaded) { continue; } TargetInfo tInfo = vessel.gameObject.GetComponent <TargetInfo>(); if (mf == null || !tInfo || !(mf && tInfo.isMissile && tInfo.team != BDATargetManager.BoolToTeam(mf.team) && (tInfo.missileModule.MissileState == MissileLauncher.MissileStates.Boost || tInfo.missileModule.MissileState == MissileLauncher.MissileStates.Cruise))) { if (vessel.GetTotalMass() < minMass) { continue; } } if (RadarUtils.TerrainCheck(ray.origin, vessel.transform.position)) { continue; } float angle = Vector3.Angle(vessel.CoM - ray.origin, ray.direction); if (angle < scanRadius) { float score = 0; foreach (var part in vessel.Parts) { if (!part) { continue; } if (!allAspect) { if (!Misc.CheckSightLineExactDistance(ray.origin, part.transform.position + vessel.rb_velocity, Vector3.Distance(part.transform.position, ray.origin), 5, 5)) { continue; } } float thisScore = (float)(part.thermalInternalFluxPrevious + part.skinTemperature) * (15 / Mathf.Max(15, angle)); thisScore *= Mathf.Pow(1400, 2) / Mathf.Clamp((vessel.CoM - ray.origin).sqrMagnitude, 90000, 36000000); score = Mathf.Max(score, thisScore); } if (vessel.LandedOrSplashed) { score /= 4; } score *= Mathf.Clamp(Vector3.Angle(vessel.transform.position - ray.origin, -VectorUtils.GetUpDirection(ray.origin)) / 90, 0.5f, 1.5f); if (score > finalScore) { finalScore = score; finalData = new TargetSignatureData(vessel, score); } } } heatScore = finalScore; //DEBUG flareScore = 0; //DEBUG foreach (var flare in BDArmorySettings.Flares) { if (!flare) { continue; } float angle = Vector3.Angle(flare.transform.position - ray.origin, ray.direction); if (angle < scanRadius) { float score = flare.thermal * Mathf.Clamp01(15 / angle); score *= Mathf.Pow(1400, 2) / Mathf.Clamp((flare.transform.position - ray.origin).sqrMagnitude, 90000, 36000000); score *= Mathf.Clamp(Vector3.Angle(flare.transform.position - ray.origin, -VectorUtils.GetUpDirection(ray.origin)) / 90, 0.5f, 1.5f); if (score > finalScore) { flareScore = score; //DEBUG finalScore = score; finalData = new TargetSignatureData(flare, score); } } } if (finalScore < minScore) { finalData = TargetSignatureData.noTarget; } return(finalData); }
void OnToggleTeam(MissileFire mf, BDTeam team) { RefreshFriendlies(); RefreshWingmen(); }
private void WindowVesselSwitcher(int id) { GUI.DragWindow(new Rect(0, 0, _windowWidth - _buttonHeight - 4, _titleHeight)); if (GUI.Button(new Rect(_windowWidth - _buttonHeight - 4, 4, _buttonHeight, _buttonHeight), "X", BDArmorySetup.BDGuiSkin.button)) { BDArmorySetup.Instance.showVSGUI = false; return; } float height = 0; float vesselLineA = 0; float vesselLineB = 0; height += _margin + _titleHeight; GUI.Label(new Rect(_margin, height, _windowWidth - 2 * _margin, _buttonHeight), "Team A:", BDArmorySetup.BDGuiSkin.label); height += _buttonHeight; float vesselButtonWidth = _windowWidth - 2 * _margin; vesselButtonWidth -= 3 * _buttonHeight; List <MissileFire> .Enumerator wma = _wmgrsA.GetEnumerator(); while (wma.MoveNext()) { if (wma.Current == null) { continue; } float lineY = height + vesselLineA * (_buttonHeight + _buttonGap); Rect buttonRect = new Rect(_margin, lineY, vesselButtonWidth, _buttonHeight); GUIStyle vButtonStyle = wma.Current.vessel.isActiveVessel ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; string status = UpdateVesselStatus(wma.Current, vButtonStyle); if (GUI.Button(buttonRect, status + wma.Current.vessel.GetName(), vButtonStyle)) { ForceSwitchVessel(wma.Current.vessel); } //guard toggle GUIStyle guardStyle = wma.Current.guardMode ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect guardButtonRect = new Rect(_margin + vesselButtonWidth, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wma.Current.ToggleGuardMode(); } //AI toggle if (wma.Current.AI != null) { GUIStyle aiStyle = wma.Current.AI.pilotEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect aiButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wma.Current.AI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", BDArmorySetup.BDGuiSkin.button)) { _wmToSwitchTeam = wma.Current; _teamSwitchDirty = true; } vesselLineA++; } wma.Dispose(); height += vesselLineA * (_buttonHeight + _buttonGap); height += _margin; GUI.Label(new Rect(_margin, height, _windowWidth - 2 * _margin, _buttonHeight), "Team B:", BDArmorySetup.BDGuiSkin.label); height += _buttonHeight; List <MissileFire> .Enumerator wmb = _wmgrsB.GetEnumerator(); while (wmb.MoveNext()) { if (wmb.Current == null) { continue; } float lineY = height + vesselLineB * (_buttonHeight + _buttonGap); Rect buttonRect = new Rect(_margin, lineY, vesselButtonWidth, _buttonHeight); GUIStyle vButtonStyle = wmb.Current.vessel.isActiveVessel ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; string status = UpdateVesselStatus(wmb.Current, vButtonStyle); if (GUI.Button(buttonRect, status + wmb.Current.vessel.GetName(), vButtonStyle)) { ForceSwitchVessel(wmb.Current.vessel); } //guard toggle GUIStyle guardStyle = wmb.Current.guardMode ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect guardButtonRect = new Rect(_margin + vesselButtonWidth, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wmb.Current.ToggleGuardMode(); } //AI toggle if (wmb.Current.AI != null) { GUIStyle aiStyle = wmb.Current.AI.pilotEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect aiButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wmb.Current.AI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", BDArmorySetup.BDGuiSkin.button)) { _wmToSwitchTeam = wmb.Current; _teamSwitchDirty = true; } vesselLineB++; } height += vesselLineB * (_buttonHeight + _buttonGap); height += _margin; _windowHeight = height; BDGUIUtils.RepositionWindow(ref BDArmorySetup.WindowRectVesselSwitcher); }
void OnToggleTeam(MissileFire mf, BDArmorySettings.BDATeams team) { RefreshFriendlies(); RefreshWingmen(); }
private void WindowVesselSwitcher(int id) { GUI.DragWindow(new Rect(0, 0, _windowWidth - _buttonHeight - 4, _titleHeight)); if (GUI.Button(new Rect(_windowWidth - _buttonHeight - 4, 4, _buttonHeight, _buttonHeight), "X", BDArmorySetup.BDGuiSkin.button)) { BDArmorySetup.Instance.showVSGUI = false; return; } float height = _titleHeight; float vesselButtonWidth = _windowWidth - 2 * _margin - 3 * _buttonHeight; using (var teamManagers = weaponManagers.GetEnumerator()) while (teamManagers.MoveNext()) { height += _margin; GUI.Label(new Rect(_margin, height, _windowWidth - 2 * _margin, _buttonHeight), $"{teamManagers.Current.Key}:", BDArmorySetup.BDGuiSkin.label); height += _buttonHeight; using (var wm = teamManagers.Current.Value.GetEnumerator()) while (wm.MoveNext()) { if (wm.Current == null) { continue; } Rect buttonRect = new Rect(_margin, height, vesselButtonWidth, _buttonHeight); GUIStyle vButtonStyle = wm.Current.vessel.isActiveVessel ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; string status = UpdateVesselStatus(wm.Current, vButtonStyle); if (GUI.Button(buttonRect, status + wm.Current.vessel.GetName(), vButtonStyle)) { ForceSwitchVessel(wm.Current.vessel); } //guard toggle GUIStyle guardStyle = wm.Current.guardMode ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect guardButtonRect = new Rect(_margin + vesselButtonWidth, height, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.Current.ToggleGuardMode(); } //AI toggle if (wm.Current.AI != null) { GUIStyle aiStyle = wm.Current.AI.pilotEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect aiButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, height, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.Current.AI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight * 2, height, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", BDArmorySetup.BDGuiSkin.button)) { if (Event.current.button == 1) { BDTeamSelector.Instance.Open(wm.Current, new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); } else { _wmToSwitchTeam = wm.Current; _teamSwitchDirty = true; } } height += _buttonHeight + _buttonGap; } } height += _margin; _windowHeight = height; BDGUIUtils.RepositionWindow(ref BDArmorySetup.WindowRectVesselSwitcher); }
public static List <TargetInfo> GetAllTargetsExcluding(List <TargetInfo> excluding, MissileFire mf) { List <TargetInfo> finalTargets = new List <TargetInfo>(); List <TargetInfo> .Enumerator target = TargetList(mf.Team).GetEnumerator(); while (target.MoveNext()) { if (target.Current == null) { continue; } if (target.Current && target.Current.Vessel && mf.CanSeeTarget(target.Current) && !excluding.Contains(target.Current)) { finalTargets.Add(target.Current); } } target.Dispose(); return(finalTargets); }
public static TargetSignatureData GetHeatTarget(Vessel sourceVessel, Vessel missileVessel, Ray ray, float scanRadius, float highpassThreshold, bool allAspect, MissileFire mf = null, bool favorGroundTargets = false) { float minMass = 0.05f; //otherwise the RAMs have trouble shooting down incoming missiles TargetSignatureData finalData = TargetSignatureData.noTarget; float finalScore = 0; foreach (Vessel vessel in LoadedVessels) { if (vessel == null) { continue; } if (!vessel || !vessel.loaded) { continue; } if (vessel == sourceVessel || vessel == missileVessel) { continue; } if (favorGroundTargets && !vessel.LandedOrSplashed) { // for AGM heat guidance continue; } TargetInfo tInfo = vessel.gameObject.GetComponent <TargetInfo>(); if (tInfo == null) { return(finalData); } // If no weaponManager or no target or the target is not a missile with engines on..??? and the target weighs less than 50kg, abort. if (mf == null || !tInfo || !(mf && tInfo.isMissile && (tInfo.MissileBaseModule.MissileState == MissileBase.MissileStates.Boost || tInfo.MissileBaseModule.MissileState == MissileBase.MissileStates.Cruise))) { if (vessel.GetTotalMass() < minMass) { continue; } } // Abort if target is friendly. if (mf != null) { if (mf.Team.IsFriendly(tInfo.Team)) { continue; } } float angle = Vector3.Angle(vessel.CoM - ray.origin, ray.direction); if (angle < scanRadius) { if (RadarUtils.TerrainCheck(ray.origin, vessel.transform.position)) { continue; } if (!allAspect) { if (!Misc.Misc.CheckSightLineExactDistance(ray.origin, vessel.CoM + vessel.Velocity(), Vector3.Distance(vessel.CoM, ray.origin), 5, 5)) { continue; } } float score = GetVesselHeatSignature(vessel) * Mathf.Clamp01(15 / angle); score *= Mathf.Pow(1400, 2) / Mathf.Clamp((vessel.CoM - ray.origin).sqrMagnitude, 90000, 36000000); if (vessel.LandedOrSplashed && !favorGroundTargets) { score /= 4; } score *= Mathf.Clamp(Vector3.Angle(vessel.transform.position - ray.origin, -VectorUtils.GetUpDirection(ray.origin)) / 90, 0.5f, 1.5f); if (score > finalScore) { finalScore = score; finalData = new TargetSignatureData(vessel, score); } } } // see if there are flares decoying us: TargetSignatureData flareData = GetFlareTarget(ray, scanRadius, highpassThreshold, allAspect, finalScore); if (finalScore < highpassThreshold) { finalData = TargetSignatureData.noTarget; } // return matching flare if (!flareData.Equals(TargetSignatureData.noTarget)) { return(flareData); } //else return the target: return(finalData); }
private void ListWindow(int id) { GUI.DragWindow(new Rect(0, 0, _windowWidth - _buttonHeight - 4, _titleHeight)); if (GUI.Button(new Rect(_windowWidth - _buttonHeight - 4, 4, _buttonHeight, _buttonHeight), "X", HighLogic.Skin.button)) { BDArmorySettings.Instance.showVSGUI = false; return; } float height = 0; float vesselLineA = 0; float vesselLineB = 0; height += _margin + _titleHeight; GUI.Label(new Rect(_margin, height, _windowWidth - 2 * _margin, _buttonHeight), "Team A:", HighLogic.Skin.label); height += _buttonHeight; var vesselButtonWidth = _windowWidth - 2 * _margin; vesselButtonWidth -= 3 * _buttonHeight; foreach (var wm in _wmgrsA) { var lineY = height + vesselLineA * (_buttonHeight + _buttonGap); var buttonRect = new Rect(_margin, lineY, vesselButtonWidth, _buttonHeight); var vButtonStyle = wm.vessel.isActiveVessel ? HighLogic.Skin.box : HighLogic.Skin.button; var status = UpdateVesselStatus(wm, vButtonStyle); if (GUI.Button(buttonRect, status + wm.vessel.GetName(), vButtonStyle)) { FlightGlobals.ForceSetActiveVessel(wm.vessel); } //guard toggle var guardStyle = wm.guardMode ? HighLogic.Skin.box : HighLogic.Skin.button; var guardButtonRect = new Rect(_margin + vesselButtonWidth, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.ToggleGuardMode(); } //AI toggle if (wm.pilotAI) { var aiStyle = wm.pilotAI.pilotEnabled ? HighLogic.Skin.box : HighLogic.Skin.button; var aiButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.pilotAI.TogglePilot(); } } //team toggle var teamButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", HighLogic.Skin.button)) { _wmToSwitchTeam = wm; _teamSwitchDirty = true; } vesselLineA++; } height += vesselLineA * (_buttonHeight + _buttonGap); height += _margin; GUI.Label(new Rect(_margin, height, _windowWidth - 2 * _margin, _buttonHeight), "Team B:", HighLogic.Skin.label); height += _buttonHeight; foreach (var wm in _wmgrsB) { var lineY = height + vesselLineB * (_buttonHeight + _buttonGap); var buttonRect = new Rect(_margin, lineY, vesselButtonWidth, _buttonHeight); var vButtonStyle = wm.vessel.isActiveVessel ? HighLogic.Skin.box : HighLogic.Skin.button; var status = UpdateVesselStatus(wm, vButtonStyle); if (GUI.Button(buttonRect, status + wm.vessel.GetName(), vButtonStyle)) { FlightGlobals.ForceSetActiveVessel(wm.vessel); } //guard toggle var guardStyle = wm.guardMode ? HighLogic.Skin.box : HighLogic.Skin.button; var guardButtonRect = new Rect(_margin + vesselButtonWidth, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.ToggleGuardMode(); } //AI toggle if (wm.pilotAI) { var aiStyle = wm.pilotAI.pilotEnabled ? HighLogic.Skin.box : HighLogic.Skin.button; var aiButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.pilotAI.TogglePilot(); } } //team toggle var teamButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight + _buttonHeight, lineY, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", HighLogic.Skin.button)) { _wmToSwitchTeam = wm; _teamSwitchDirty = true; } vesselLineB++; } height += vesselLineB * (_buttonHeight + _buttonGap); height += _margin; _windowHeight = height; }
private void WindowVesselSwitcher(int id) { GUI.DragWindow(new Rect(0, 0, _windowWidth - 4 * (_buttonHeight) - _margin, _titleHeight)); // enablge guard mode for all pilots if (GUI.Button(new Rect(_windowWidth - 4 * (_buttonHeight) - _margin, 4, _buttonHeight, _buttonHeight), "G", _guardModeEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button)) { // switch everyon onto different teams ToggleGuardModes(); } // enable autopilot for all if (GUI.Button(new Rect(_windowWidth - 3 * (_buttonHeight) - _margin, 4, _buttonHeight, _buttonHeight), "P", _autoPilotEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button)) { // Toggle autopilots for everyone ToggleAutopilots(); } // toggle between FFA and putting everyone on the same team if (GUI.Button(new Rect(_windowWidth - 2 * (_buttonHeight) - _margin, 4, _buttonHeight, _buttonHeight), "T", _freeForAll ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button)) { // switch everyon onto different teams _teamSwitchDirty = true; _wmToSwitchTeam = null; } // close the window if (GUI.Button(new Rect(_windowWidth - _buttonHeight - _margin, 4, _buttonHeight, _buttonHeight), "X", BDArmorySetup.BDGuiSkin.button)) { BDArmorySetup.Instance.showVSGUI = false; return; } float height = _titleHeight; float vesselButtonWidth = _windowWidth - 2 * _margin - 6 * _buttonHeight; using (var teamManagers = weaponManagers.GetEnumerator()) while (teamManagers.MoveNext()) { height += _margin; using (var wm = teamManagers.Current.Value.GetEnumerator()) while (wm.MoveNext()) { if (wm.Current == null) { continue; } // team at the start of the line GUI.Label(new Rect(_margin, height, _buttonHeight, _buttonHeight), $"{teamManagers.Current.Key}:", BDArmorySetup.BDGuiSkin.label); Rect buttonRect = new Rect(_margin + _buttonHeight, height, vesselButtonWidth, _buttonHeight); GUIStyle vButtonStyle = wm.Current.vessel.isActiveVessel ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; // current target string targetName = ""; Vessel targetVessel = wm.Current.vessel; bool incomingThreat = false; if (wm.Current.incomingThreatVessel != null) { incomingThreat = true; targetName = "<<<" + wm.Current.incomingThreatVessel.GetName(); targetVessel = wm.Current.incomingThreatVessel; } else if (wm.Current.currentTarget) { targetName = ">>>" + wm.Current.currentTarget.Vessel.GetName(); targetVessel = wm.Current.currentTarget.Vessel; } string status = UpdateVesselStatus(wm.Current, vButtonStyle); string vesselName = wm.Current.vessel.GetName(); string postStatus = ""; if (wm.Current.AI != null && wm.Current.AI.currentStatus != null) { postStatus += " " + wm.Current.AI.currentStatus; } float targetDistance = 5000; if (wm.Current.currentTarget != null) { targetDistance = Vector3.Distance(wm.Current.vessel.GetWorldPos3D(), wm.Current.currentTarget.position); } if (targetName != "") { postStatus += " " + targetName; } if (GUI.Button(buttonRect, status + vesselName + postStatus, vButtonStyle)) { ForceSwitchVessel(wm.Current.vessel); } // selects current target if (targetName != "") { Rect targettingButtonRect = new Rect(_margin + vesselButtonWidth + _buttonHeight, height, _buttonHeight, _buttonHeight); GUIStyle targButton = BDArmorySetup.BDGuiSkin.button; if (wm.Current.currentGun != null && wm.Current.currentGun.recentlyFiring) { if (targetDistance < 500) { targButton = redLight; } else if (targetDistance < 1000) { targButton = yellowLight; } else { targButton = blueLight; } } if (GUI.Button(targettingButtonRect, incomingThreat ? "><" : "[]", targButton)) { ForceSwitchVessel(targetVessel); } } //guard toggle GUIStyle guardStyle = wm.Current.guardMode ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button; Rect guardButtonRect = new Rect(_margin + vesselButtonWidth + 2 * _buttonHeight, height, _buttonHeight, _buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.Current.ToggleGuardMode(); } //AI toggle if (wm.Current.AI != null) { GUIStyle aiStyle = new GUIStyle(wm.Current.AI.pilotEnabled ? BDArmorySetup.BDGuiSkin.box : BDArmorySetup.BDGuiSkin.button); if (wm.Current.underFire) { var distance = Vector3.Distance(wm.Current.vessel.GetWorldPos3D(), wm.Current.incomingThreatPosition); if (distance < 500) { aiStyle.normal.textColor = Color.red; } else if (distance < 1000) { aiStyle.normal.textColor = Color.yellow; } else { aiStyle.normal.textColor = Color.blue; } } Rect aiButtonRect = new Rect(_margin + vesselButtonWidth + 3 * _buttonHeight, height, _buttonHeight, _buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.Current.AI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(_margin + vesselButtonWidth + 4 * _buttonHeight, height, _buttonHeight, _buttonHeight); if (GUI.Button(teamButtonRect, "T", BDArmorySetup.BDGuiSkin.button)) { if (Event.current.button == 1) { BDTeamSelector.Instance.Open(wm.Current, new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); } else { _wmToSwitchTeam = wm.Current; _teamSwitchDirty = true; } } // boom Rect killButtonRect = new Rect(_margin + vesselButtonWidth + 5 * _buttonHeight, height, _buttonHeight, _buttonHeight); if (GUI.Button(killButtonRect, "X", BDArmorySetup.BDGuiSkin.button)) { // must use right button if (Event.current.button == 1) { Misc.Misc.ForceDeadVessel(wm.Current.vessel); } } height += _buttonHeight + _buttonGap; } } height += _margin; _windowHeight = height; BDGUIUtils.RepositionWindow(ref BDArmorySetup.WindowRectVesselSwitcher); }
private void OnGUI() { if (_ready) { if (_showGui && BDArmorySetup.GAME_UI_ENABLED) { SetNewHeight(_windowHeight); // this Rect initialization ensures any save issues with height or width of the window are resolved BDArmorySetup.WindowRectVesselSwitcher = new Rect(BDArmorySetup.WindowRectVesselSwitcher.x, BDArmorySetup.WindowRectVesselSwitcher.y, _windowWidth, _windowHeight); BDArmorySetup.WindowRectVesselSwitcher = GUI.Window(10293444, BDArmorySetup.WindowRectVesselSwitcher, WindowVesselSwitcher, Localizer.Format("#LOC_BDArmory_BDAVesselSwitcher_Title"),//"BDA Vessel Switcher" BDArmorySetup.BDGuiSkin.window); Misc.Misc.UpdateGUIRect(BDArmorySetup.WindowRectVesselSwitcher, _guiCheckIndex); } else { Misc.Misc.UpdateGUIRect(new Rect(), _guiCheckIndex); } if (_teamSwitchDirty) { if (_wmToSwitchTeam) { _wmToSwitchTeam.NextTeam(); } else { // if no team is specified toggle between FFA and all friends // FFA button starts timer running //ResetSpeeds(); _freeForAll = !_freeForAll; char T = 'A'; // switch everyone to their own teams var allPilots = new List <MissileFire>(); using (var teamManagers = weaponManagers.GetEnumerator()) while (teamManagers.MoveNext()) { using (var wm = teamManagers.Current.Value.GetEnumerator()) while (wm.MoveNext()) { if (wm.Current == null) { continue; } allPilots.Add(wm.Current); } } foreach (var pilot in allPilots) { Debug.Log("[BDArmory] assigning " + pilot.vessel.GetDisplayName() + " to team " + T.ToString()); pilot.SetTeam(BDTeam.Get(T.ToString())); if (_freeForAll) { T++; } } } _teamSwitchDirty = false; _wmToSwitchTeam = null; } } }
public void Open(MissileFire weaponManager, Vector2 position) { open = true; targetWeaponManager = weaponManager; windowLocation = position; }
/// <summary> /// Scans for targets in direction with field of view. /// Returns the direction scanned for debug /// </summary> /// <returns>The scan direction.</returns> /// <param name="myWpnManager">My wpn manager.</param> /// <param name="directionAngle">Direction angle.</param> /// <param name="referenceTransform">Reference transform.</param> /// <param name="fov">Fov.</param> /// <param name="results">Results.</param> /// <param name="maxDistance">Max distance.</param> public static Vector3 GuardScanInDirection(MissileFire myWpnManager, float directionAngle, Transform referenceTransform, float fov, out ViewScanResults results, float maxDistance) { fov *= 1.1f; results = new ViewScanResults(); results.foundMissile = false; results.foundHeatMissile = false; results.foundRadarMissile = false; results.foundAGM = false; results.firingAtMe = false; results.missileThreatDistance = float.MaxValue; results.threatVessel = null; results.threatWeaponManager = null; if (!myWpnManager || !referenceTransform) { return(Vector3.zero); } Vector3 position = referenceTransform.position; Vector3d geoPos = VectorUtils.WorldPositionToGeoCoords(position, FlightGlobals.currentMainBody); Vector3 forwardVector = referenceTransform.forward; Vector3 upVector = referenceTransform.up; Vector3 lookDirection = Quaternion.AngleAxis(directionAngle, upVector) * forwardVector; foreach (var vessel in BDATargetManager.LoadedVessels) { if (vessel == null) { continue; } if (vessel.loaded) { if (vessel == myWpnManager.vessel) { continue; //ignore self } Vector3 vesselProjectedDirection = Vector3.ProjectOnPlane(vessel.transform.position - position, upVector); Vector3 vesselDirection = vessel.transform.position - position; if (Vector3.Dot(vesselDirection, lookDirection) < 0) { continue; } float vesselDistance = (vessel.transform.position - position).magnitude; if (vesselDistance < maxDistance && Vector3.Angle(vesselProjectedDirection, lookDirection) < fov / 2 && Vector3.Angle(vessel.transform.position - position, -myWpnManager.transform.forward) < myWpnManager.guardAngle / 2) { //Debug.Log("Found vessel: " + vessel.vesselName); if (TerrainCheck(referenceTransform.position, vessel.transform.position)) { continue; //blocked by terrain } BDATargetManager.ReportVessel(vessel, myWpnManager); TargetInfo tInfo; if ((tInfo = vessel.GetComponent <TargetInfo>())) { if (tInfo.isMissile) { MissileLauncher missile; if (missile = tInfo.missileModule) { results.foundMissile = true; results.threatVessel = missile.vessel; Vector3 vectorFromMissile = myWpnManager.vessel.CoM - missile.part.transform.position; Vector3 relV = missile.vessel.srf_velocity - myWpnManager.vessel.srf_velocity; bool approaching = Vector3.Dot(relV, vectorFromMissile) > 0; if (missile.hasFired && missile.timeIndex > 1 && approaching && (missile.targetPosition - (myWpnManager.vessel.CoM + (myWpnManager.vessel.rb_velocity * Time.fixedDeltaTime))).sqrMagnitude < 3600) { if (missile.targetingMode == MissileLauncher.TargetingModes.Heat) { results.foundHeatMissile = true; results.missileThreatDistance = Mathf.Min(results.missileThreatDistance, Vector3.Distance(missile.part.transform.position, myWpnManager.part.transform.position)); results.threatPosition = missile.transform.position; break; } else if (missile.targetingMode == MissileLauncher.TargetingModes.Radar) { results.foundRadarMissile = true; results.missileThreatDistance = Mathf.Min(results.missileThreatDistance, Vector3.Distance(missile.part.transform.position, myWpnManager.part.transform.position)); results.threatPosition = missile.transform.position; } else if (missile.targetingMode == MissileLauncher.TargetingModes.Laser) { results.foundAGM = true; results.missileThreatDistance = Mathf.Min(results.missileThreatDistance, Vector3.Distance(missile.part.transform.position, myWpnManager.part.transform.position)); break; } } else { break; } } } else { //check if its shooting guns at me //if(!results.firingAtMe) //more work, but we can't afford to be incorrect picking the closest threat //{ foreach (var weapon in vessel.FindPartModulesImplementing <ModuleWeapon>()) { if (!weapon.recentlyFiring) { continue; } if (Vector3.Dot(weapon.fireTransforms[0].forward, vesselDirection) > 0) { continue; } if (Vector3.Angle(weapon.fireTransforms[0].forward, -vesselDirection) < 6500 / vesselDistance && (!results.firingAtMe || (weapon.vessel.ReferenceTransform.position - position).magnitude < (results.threatPosition - position).magnitude)) { results.firingAtMe = true; results.threatPosition = weapon.vessel.transform.position; results.threatVessel = weapon.vessel; results.threatWeaponManager = weapon.weaponManager; break; } } //} } } } } } return(lookDirection); }
public static void UpdateRadarLock(MissileFire myWpnManager, float directionAngle, Transform referenceTransform, float fov, Vector3 position, float minSignature, ref TargetSignatureData[] dataArray, float dataPersistTime, bool pingRWR, RadarWarningReceiver.RWRThreatTypes rwrType, bool radarSnapshot) { Vector3d geoPos = VectorUtils.WorldPositionToGeoCoords(position, FlightGlobals.currentMainBody); Vector3 forwardVector = referenceTransform.forward; Vector3 upVector = referenceTransform.up; //VectorUtils.GetUpDirection(position); Vector3 lookDirection = Quaternion.AngleAxis(directionAngle, upVector) * forwardVector; int dataIndex = 0; foreach (var vessel in BDATargetManager.LoadedVessels) { if (vessel == null) { continue; } if (!vessel.loaded) { continue; } if (myWpnManager) { if (vessel == myWpnManager.vessel) { continue; //ignore self } } else if ((vessel.transform.position - position).sqrMagnitude < 3600) { continue; } Vector3 vesselDirection = Vector3.ProjectOnPlane(vessel.CoM - position, upVector); if (Vector3.Angle(vesselDirection, lookDirection) < fov / 2) { if (TerrainCheck(referenceTransform.position, vessel.transform.position)) { continue; //blocked by terrain } float sig = float.MaxValue; if (radarSnapshot && minSignature > 0) { sig = GetModifiedSignature(vessel, position); } RadarWarningReceiver.PingRWR(vessel, position, rwrType, dataPersistTime); float detectSig = sig; VesselECMJInfo vesselJammer = vessel.GetComponent <VesselECMJInfo>(); if (vesselJammer) { sig *= vesselJammer.rcsReductionFactor; detectSig += vesselJammer.jammerStrength; } if (detectSig > minSignature) { if (vessel.vesselType == VesselType.Debris) { vessel.gameObject.AddComponent <TargetInfo>(); } else if (myWpnManager != null) { BDATargetManager.ReportVessel(vessel, myWpnManager); } while (dataIndex < dataArray.Length - 1) { if ((dataArray[dataIndex].exists && Time.time - dataArray[dataIndex].timeAcquired > dataPersistTime) || !dataArray[dataIndex].exists) { break; } dataIndex++; } if (dataIndex >= dataArray.Length) { break; } dataArray[dataIndex] = new TargetSignatureData(vessel, sig); dataIndex++; if (dataIndex >= dataArray.Length) { break; } } } } }
public void Disengage(MissileFire mf) { friendliesEngaging.Remove(mf); }
public static bool CheckMouseIsOnGui() { if (!BDArmorySetup.GAME_UI_ENABLED) { return(false); } if (!BDInputSettingsFields.WEAP_FIRE_KEY.inputString.Contains("mouse")) { return(false); } Vector3 inverseMousePos = new Vector3(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 0); Rect topGui = new Rect(0, 0, Screen.width, 65); if (topGui.Contains(inverseMousePos)) { return(true); } if (BDArmorySetup.windowBDAToolBarEnabled && BDArmorySetup.WindowRectToolbar.Contains(inverseMousePos)) { return(true); } if (ModuleTargetingCamera.windowIsOpen && BDArmorySetup.WindowRectTargetingCam.Contains(inverseMousePos)) { return(true); } if (BDArmorySetup.Instance.ActiveWeaponManager) { MissileFire wm = BDArmorySetup.Instance.ActiveWeaponManager; if (wm.vesselRadarData && wm.vesselRadarData.guiEnabled) { if (BDArmorySetup.WindowRectRadar.Contains(inverseMousePos)) { return(true); } if (wm.vesselRadarData.linkWindowOpen && wm.vesselRadarData.linkWindowRect.Contains(inverseMousePos)) { return(true); } } if (wm.rwr && wm.rwr.rwrEnabled && wm.rwr.displayRWR && BDArmorySetup.WindowRectRwr.Contains(inverseMousePos)) { return(true); } if (wm.wingCommander && wm.wingCommander.showGUI) { if (BDArmorySetup.WindowRectWingCommander.Contains(inverseMousePos)) { return(true); } if (wm.wingCommander.showAGWindow && wm.wingCommander.agWindowRect.Contains(inverseMousePos)) { return(true); } } if (extraGUIRects != null) { for (int i = 0; i < extraGUIRects.Count; i++) { if (extraGUIRects[i].Contains(inverseMousePos)) { return(true); } } } } return(false); }
void Awake() { if (!vessel) { vessel = GetComponent <Vessel>(); } if (!vessel) { Debug.Log("[BDArmory]:TargetInfo was added to a non-vessel"); Destroy(this); return; } //destroy this if a target info is already attached to the vessel foreach (var otherInfo in vessel.gameObject.GetComponents <TargetInfo>()) { if (otherInfo != this) { Destroy(this); return; } } team = BDArmorySettings.BDATeams.None; bool foundMf = false; foreach (var mf in vessel.FindPartModulesImplementing <MissileFire>()) { foundMf = true; team = BDATargetManager.BoolToTeam(mf.team); weaponManager = mf; break; } if (!foundMf) { foreach (var ml in vessel.FindPartModulesImplementing <MissileBase>()) { isMissile = true; MissileBaseModule = ml; team = BDATargetManager.BoolToTeam(ml.Team); break; } } if (team != BDArmorySettings.BDATeams.None) { if (!BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Contains(this)) { BDATargetManager.TargetDatabase[BDATargetManager.OtherTeam(team)].Add(this); } } friendliesEngaging = new List <MissileFire>(); vessel.OnJustAboutToBeDestroyed += AboutToBeDestroyed; lifeRoutine = StartCoroutine(LifetimeRoutine()); //add delegate to peace enable event BDArmorySettings.OnPeaceEnabled += OnPeaceEnabled; if (!isMissile && team != BDArmorySettings.BDATeams.None) { massRoutine = StartCoroutine(MassRoutine()); } }
void RefreshFriendlies() { if (!weaponManager) { return; } friendlies = new List <IBDAIControl>(); List <Vessel> .Enumerator vs = BDATargetManager.LoadedVessels.GetEnumerator(); while (vs.MoveNext()) { if (vs.Current == null) { continue; } if (!vs.Current.loaded || vs.Current == vessel) { continue; } IBDAIControl pilot = null; MissileFire wm = null; List <IBDAIControl> .Enumerator ps = vs.Current.FindPartModulesImplementing <IBDAIControl>().GetEnumerator(); while (ps.MoveNext()) { if (ps.Current == null) { continue; } pilot = ps.Current; break; } ps.Dispose(); if (pilot == null) { continue; } List <MissileFire> .Enumerator ws = vs.Current.FindPartModulesImplementing <MissileFire>().GetEnumerator(); while (ws.MoveNext()) { // TODO: JDK: note that this assigns the last module found. Is that what we want? wm = ws.Current; } ws.Dispose(); if (!wm || wm.Team != weaponManager.Team) { continue; } friendlies.Add(pilot); } vs.Dispose(); //TEMPORARY wingmen = new List <IBDAIControl>(); List <IBDAIControl> .Enumerator fs = friendlies.GetEnumerator(); while (fs.MoveNext()) { if (fs.Current == null) { continue; } wingmen.Add(fs.Current); } fs.Dispose(); }
void ListWindow(int id) { GUI.DragWindow(new Rect(0, 0, windowWidth - buttonHeight - 4, titleHeight)); if (GUI.Button(new Rect(windowWidth - buttonHeight - 4, 4, buttonHeight, buttonHeight), "X", HighLogic.Skin.button)) { BDArmorySettings.Instance.showVSGUI = false; return; } float height = 0; float vesselLineA = 0; float vesselLineB = 0; height += margin + titleHeight; GUI.Label(new Rect(margin, height, windowWidth - (2 * margin), buttonHeight), "Team A:", HighLogic.Skin.label); height += buttonHeight; float vesselButtonWidth = windowWidth - (2 * margin); vesselButtonWidth -= (3 * buttonHeight); foreach (var wm in wmgrsA) { float lineY = height + (vesselLineA * (buttonHeight + buttonGap)); Rect buttonRect = new Rect(margin, lineY, vesselButtonWidth, buttonHeight); GUIStyle vButtonStyle = wm.vessel.isActiveVessel ? HighLogic.Skin.box : HighLogic.Skin.button; var status = UpdateVesselStatus(wm, vButtonStyle); if (GUI.Button(buttonRect, status + wm.vessel.GetName(), vButtonStyle)) { FlightGlobals.ForceSetActiveVessel(wm.vessel); } //guard toggle GUIStyle guardStyle = wm.guardMode ? HighLogic.Skin.box : HighLogic.Skin.button; Rect guardButtonRect = new Rect(margin + vesselButtonWidth, lineY, buttonHeight, buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.ToggleGuardMode(); } //AI toggle if (wm.pilotAI) { GUIStyle aiStyle = wm.pilotAI.pilotEnabled ? HighLogic.Skin.box : HighLogic.Skin.button; Rect aiButtonRect = new Rect(margin + vesselButtonWidth + buttonHeight, lineY, buttonHeight, buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.pilotAI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(margin + vesselButtonWidth + buttonHeight + buttonHeight, lineY, buttonHeight, buttonHeight); if (GUI.Button(teamButtonRect, "T", HighLogic.Skin.button)) { wmToSwitchTeam = wm; teamSwitchDirty = true; } vesselLineA++; } height += (vesselLineA * (buttonHeight + buttonGap)); height += margin; GUI.Label(new Rect(margin, height, windowWidth - (2 * margin), buttonHeight), "Team B:", HighLogic.Skin.label); height += buttonHeight; foreach (var wm in wmgrsB) { float lineY = height + (vesselLineB * (buttonHeight + buttonGap)); Rect buttonRect = new Rect(margin, lineY, vesselButtonWidth, buttonHeight); GUIStyle vButtonStyle = wm.vessel.isActiveVessel ? HighLogic.Skin.box : HighLogic.Skin.button; var status = UpdateVesselStatus(wm, vButtonStyle); if (GUI.Button(buttonRect, status + wm.vessel.GetName(), vButtonStyle)) { FlightGlobals.ForceSetActiveVessel(wm.vessel); } //guard toggle GUIStyle guardStyle = wm.guardMode ? HighLogic.Skin.box : HighLogic.Skin.button; Rect guardButtonRect = new Rect(margin + vesselButtonWidth, lineY, buttonHeight, buttonHeight); if (GUI.Button(guardButtonRect, "G", guardStyle)) { wm.ToggleGuardMode(); } //AI toggle if (wm.pilotAI) { GUIStyle aiStyle = wm.pilotAI.pilotEnabled ? HighLogic.Skin.box : HighLogic.Skin.button; Rect aiButtonRect = new Rect(margin + vesselButtonWidth + buttonHeight, lineY, buttonHeight, buttonHeight); if (GUI.Button(aiButtonRect, "P", aiStyle)) { wm.pilotAI.TogglePilot(); } } //team toggle Rect teamButtonRect = new Rect(margin + vesselButtonWidth + buttonHeight + buttonHeight, lineY, buttonHeight, buttonHeight); if (GUI.Button(teamButtonRect, "T", HighLogic.Skin.button)) { wmToSwitchTeam = wm; teamSwitchDirty = true; } vesselLineB++; } height += (vesselLineB * (buttonHeight + buttonGap)); height += margin; windowHeight = height; }