private void StringToGPSList(string listString) { if (GPSTargets == null) { GPSTargets = new Dictionary <BDArmorySettings.BDATeams, List <GPSTargetInfo> >(); } GPSTargets.Clear(); GPSTargets.Add(BDArmorySettings.BDATeams.A, new List <GPSTargetInfo>()); GPSTargets.Add(BDArmorySettings.BDATeams.B, new List <GPSTargetInfo>()); if (listString == null || listString == string.Empty) { Debug.Log("=== GPS List string was empty or null ==="); return; } string[] teams = listString.Split(new char[] { ':' }); Debug.Log("==== Loading GPS Targets. Number of teams: " + teams.Length); if (teams[0] != null && teams[0].Length > 0 && teams[0] != "null") { string[] teamACoords = teams[0].Split(new char[] { ';' }); for (int i = 0; i < teamACoords.Length; i++) { if (teamACoords[i] != null && teamACoords[i].Length > 0) { string[] data = teamACoords[i].Split(new char[] { ',' }); string name = data[0]; double lat = double.Parse(data[1]); double longi = double.Parse(data[2]); double alt = double.Parse(data[3]); GPSTargetInfo newInfo = new GPSTargetInfo(new Vector3d(lat, longi, alt), name); GPSTargets[BDArmorySettings.BDATeams.A].Add(newInfo); } } } if (teams[1] != null && teams[1].Length > 0 && teams[1] != "null") { string[] teamBCoords = teams[1].Split(new char[] { ';' }); for (int i = 0; i < teamBCoords.Length; i++) { if (teamBCoords[i] != null && teamBCoords[i].Length > 0) { string[] data = teamBCoords[i].Split(new char[] { ',' }); string name = data[0]; double lat = double.Parse(data[1]); double longi = double.Parse(data[2]); double alt = double.Parse(data[3]); GPSTargetInfo newInfo = new GPSTargetInfo(new Vector3d(lat, longi, alt), name); GPSTargets[BDArmorySettings.BDATeams.B].Add(newInfo); } } } }
IEnumerator CommandPositionGUIRoutine(BDModulePilotAI wingman, GPSTargetInfo tInfo) { //RemoveCommandPos(tInfo); commandedPositions.Add(tInfo); yield return(new WaitForSeconds(0.25f)); while (Vector3d.Distance(wingman.commandGPS, tInfo.gpsCoordinates) < 0.01f && (wingman.currentCommand == BDModulePilotAI.PilotCommands.Attack || wingman.currentCommand == BDModulePilotAI.PilotCommands.FlyTo)) { yield return(null); } RemoveCommandPos(tInfo); }
void RemoveCommandPos(GPSTargetInfo tInfo) { commandedPositions.RemoveAll(t => t.EqualsTarget(tInfo)); }
private void StringToGPSList(string listString) { if(GPSTargets == null) { GPSTargets = new Dictionary<BDArmorySettings.BDATeams, List<GPSTargetInfo>>(); } GPSTargets.Clear(); GPSTargets.Add(BDArmorySettings.BDATeams.A, new List<GPSTargetInfo>()); GPSTargets.Add(BDArmorySettings.BDATeams.B, new List<GPSTargetInfo>()); if(listString == null || listString == string.Empty) { Debug.Log("=== GPS List string was empty or null ==="); return; } string[] teams = listString.Split(new char[]{ ':' }); Debug.Log("==== Loading GPS Targets. Number of teams: " + teams.Length); if(teams[0] != null && teams[0].Length > 0 && teams[0] != "null") { string[] teamACoords = teams[0].Split(new char[]{ ';' }); for(int i = 0; i < teamACoords.Length; i++) { if(teamACoords[i] != null && teamACoords[i].Length > 0) { string[] data = teamACoords[i].Split(new char[]{ ',' }); string name = data[0]; double lat = double.Parse(data[1]); double longi = double.Parse(data[2]); double alt = double.Parse(data[3]); GPSTargetInfo newInfo = new GPSTargetInfo(new Vector3d(lat, longi, alt), name); GPSTargets[BDArmorySettings.BDATeams.A].Add(newInfo); } } } if(teams[1] != null && teams[1].Length > 0 && teams[1] != "null") { string[] teamBCoords = teams[1].Split(new char[]{ ';' }); for(int i = 0; i < teamBCoords.Length; i++) { if(teamBCoords[i] != null && teamBCoords[i].Length > 0) { string[] data = teamBCoords[i].Split(new char[]{ ',' }); string name = data[0]; double lat = double.Parse(data[1]); double longi = double.Parse(data[2]); double alt = double.Parse(data[3]); GPSTargetInfo newInfo = new GPSTargetInfo(new Vector3d(lat, longi, alt), name); GPSTargets[BDArmorySettings.BDATeams.B].Add(newInfo); } } } }
IEnumerator CommandPositionGUIRoutine(BDModulePilotAI wingman, GPSTargetInfo tInfo) { //RemoveCommandPos(tInfo); commandedPositions.Add(tInfo); yield return new WaitForSeconds(0.25f); while(Vector3d.Distance(wingman.commandGPS, tInfo.gpsCoordinates) < 0.01f && (wingman.currentCommand == BDModulePilotAI.PilotCommands.Attack || wingman.currentCommand == BDModulePilotAI.PilotCommands.FlyTo)) { yield return null; } RemoveCommandPos(tInfo); }
IEnumerator GuardMissileRoutine() { MissileLauncher ml = currentMissile; if(ml && !guardFiringMissile) { guardFiringMissile = true; if(BDArmorySettings.ALLOW_LEGACY_TARGETING) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName() + ", (legacy targeting)"); } ml.FireMissileOnTarget(guardTarget); UpdateList(); } else if(ml.targetingMode == MissileLauncher.TargetingModes.Radar && radar) { if(!radar.locked || (radar.lockedTarget.predictedPosition - guardTarget.transform.position).magnitude > 40) { radar.TryLockTarget(guardTarget.transform.position); yield return new WaitForSeconds(Mathf.Clamp(2, 0.2f, targetScanInterval / 2)); } if(ml && pilotAI && guardTarget && radar.locked) { float LAstartTime = Time.time; while(Time.time-LAstartTime < 3 && pilotAI && !pilotAI.GetLaunchAuthorization(guardTarget, this)) { yield return new WaitForFixedUpdate(); } } if(ml && guardTarget && radar.locked && (!pilotAI || pilotAI.GetLaunchAuthorization(guardTarget, this))) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName()); } FireCurrentMissile(true); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.Heat) { float attemptStartTime = Time.time; float attemptDuration = targetScanInterval * 0.75f; while(ml && Time.time - attemptStartTime < attemptDuration && (!heatTarget.exists || (heatTarget.predictedPosition - guardTarget.transform.position).magnitude >40)) { yield return new WaitForFixedUpdate(); } //try uncaged IR lock with radar if(guardTarget && !heatTarget.exists && radar && radar.radarEnabled) { if(!radar.locked || (radar.lockedTarget.predictedPosition - guardTarget.transform.position).magnitude > 40) { radar.TryLockTarget(guardTarget.transform.position); yield return new WaitForSeconds(Mathf.Clamp(1, 0.1f, (targetScanInterval * 0.25f) / 2)); } } if(guardTarget && ml && heatTarget.exists && pilotAI) { float LAstartTime = Time.time; while(Time.time-LAstartTime < 3 && pilotAI && !pilotAI.GetLaunchAuthorization(guardTarget, this)) { yield return new WaitForFixedUpdate(); } } if(guardTarget && ml && heatTarget.exists && (!pilotAI || pilotAI.GetLaunchAuthorization(guardTarget, this))) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName()); } FireCurrentMissile(true); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.GPS) { designatedGPSInfo = new GPSTargetInfo(VectorUtils.WorldPositionToGeoCoords(guardTarget.CoM, vessel.mainBody), guardTarget.vesselName.Substring(0, Mathf.Min(12, guardTarget.vesselName.Length))); FireCurrentMissile(true); } else if(ml.targetingMode == MissileLauncher.TargetingModes.AntiRad) { if(rwr) { rwr.EnableRWR(); } float attemptStartTime = Time.time; float attemptDuration = targetScanInterval * 0.75f; while(Time.time - attemptStartTime < attemptDuration && (!antiRadTargetAcquired || (antiRadiationTarget - guardTarget.CoM).magnitude > 20)) { yield return new WaitForFixedUpdate(); } if(ml && antiRadTargetAcquired && (antiRadiationTarget - guardTarget.CoM).magnitude < 20) { FireCurrentMissile(true); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.Laser) { if(targetingPods.Count > 0) //if targeting pods are available, slew them onto target and lock. { foreach(var tgp in targetingPods) { tgp.EnableCamera(); yield return StartCoroutine(tgp.PointToPositionRoutine(guardTarget.CoM)); if(tgp) { if(tgp.groundStabilized && (tgp.groundTargetPosition - guardTarget.transform.position).magnitude < 20) { break; } else { tgp.DisableCamera(); } } } } //search for a laser point that corresponds with target vessel float attemptStartTime = Time.time; float attemptDuration = targetScanInterval * 0.75f; while(Time.time - attemptStartTime < attemptDuration && (!laserPointDetected || (foundCam && (foundCam.groundTargetPosition - guardTarget.CoM).magnitude >20))) { yield return new WaitForFixedUpdate(); } if(ml && laserPointDetected && foundCam && (foundCam.groundTargetPosition - guardTarget.CoM).magnitude < 20) { FireCurrentMissile(true); } } guardFiringMissile = false; } }
public bool EqualsTarget(GPSTargetInfo other) { return((name == other.name) && (gpsCoordinates == other.gpsCoordinates)); }
IEnumerator GuardBombRoutine() { guardFiringMissile = true; bool hasSetCargoBays = false; float bombStartTime = Time.time; float bombAttemptDuration = Mathf.Max(targetScanInterval, 12f); float radius = currentMissile.blastRadius * Mathf.Min((1 + ((float)maxMissilesOnTarget/2f)), 1.5f); if(currentMissile.targetingMode == MissileLauncher.TargetingModes.GPS && Vector3.Distance(designatedGPSInfo.worldPos, guardTarget.CoM) > currentMissile.blastRadius) { //check database for target first float twoxsqrRad = 4f * radius * radius; bool foundTargetInDatabase = false; foreach(var gps in BDATargetManager.GPSTargets[BDATargetManager.BoolToTeam(team)]) { if((gps.worldPos - guardTarget.CoM).sqrMagnitude < twoxsqrRad) { designatedGPSInfo = gps; foundTargetInDatabase = true; break; } } //no target in gps database, acquire via targeting pod if(!foundTargetInDatabase) { ModuleTargetingCamera tgp = null; foreach(var t in targetingPods) { if(t) tgp = t; } if(tgp) { tgp.EnableCamera(); yield return StartCoroutine(tgp.PointToPositionRoutine(guardTarget.CoM)); if(tgp) { if(guardTarget && tgp.groundStabilized && Vector3.Distance(tgp.groundTargetPosition, guardTarget.transform.position) < currentMissile.blastRadius) { radius = 500; designatedGPSInfo = new GPSTargetInfo(tgp.bodyRelativeGTP, "Guard Target"); bombStartTime = Time.time; } else//failed to acquire target via tgp, cancel. { tgp.DisableCamera(); designatedGPSInfo = new GPSTargetInfo(); guardFiringMissile = false; yield break; } } else//no gps target and lost tgp, cancel. { guardFiringMissile = false; yield break; } } else //no gps target and no tgp, cancel. { guardFiringMissile = false; yield break; } } } bool doProxyCheck = true; float prevDist = 2 * radius; radius = Mathf.Max(radius, 50f); while(guardTarget && Time.time-bombStartTime < bombAttemptDuration && weaponIndex > 0 && weaponArray[weaponIndex].GetWeaponClass()==WeaponClasses.Bomb && missilesAway < maxMissilesOnTarget) { float targetDist = Vector3.Distance(bombAimerPosition, guardTarget.CoM); if(targetDist < (radius * 20f) && !hasSetCargoBays) { SetCargoBays(); hasSetCargoBays = true; } if(targetDist > radius) { if(targetDist < Mathf.Max(radius * 2, 800f) && Vector3.Dot(guardTarget.CoM - bombAimerPosition, guardTarget.CoM - transform.position) < 0) { pilotAI.RequestExtend(guardTarget.CoM); break; } yield return null; } else { if(doProxyCheck) { if(targetDist - prevDist > 0) { doProxyCheck = false; } else { prevDist = targetDist; } } if(!doProxyCheck) { FireCurrentMissile(true); timeBombReleased = Time.time; yield return new WaitForSeconds(rippleFire ? 60f / rippleRPM : 0.06f); if(missilesAway >= maxMissilesOnTarget) { yield return new WaitForSeconds(1f); if(pilotAI) { pilotAI.RequestExtend(guardTarget.CoM); } } } else { yield return null; } } } designatedGPSInfo = new GPSTargetInfo(); guardFiringMissile = false; }
IEnumerator GuardMissileRoutine() { MissileLauncher ml = currentMissile; if(ml && !guardFiringMissile) { guardFiringMissile = true; if(BDArmorySettings.ALLOW_LEGACY_TARGETING) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName() + ", (legacy targeting)"); } if(ml.missileTurret) { ml.missileTurret.PrepMissileForFire(ml); ml.FireMissileOnTarget(guardTarget); ml.missileTurret.UpdateMissileChildren(); } else { ml.FireMissileOnTarget(guardTarget); } StartCoroutine(MissileAwayRoutine(ml)); UpdateList(); } else if(ml.targetingMode == MissileLauncher.TargetingModes.Radar && vesselRadarData) { float attemptLockTime = Time.time; while((!vesselRadarData.locked || (vesselRadarData.lockedTargetData.vessel != guardTarget)) && Time.time-attemptLockTime < 2) { if(vesselRadarData.locked) { vesselRadarData.UnlockAllTargets(); yield return null; } //vesselRadarData.TryLockTarget(guardTarget.transform.position+(guardTarget.rb_velocity*Time.fixedDeltaTime)); vesselRadarData.TryLockTarget(guardTarget); yield return new WaitForSeconds(0.25f); } if(ml && pilotAI && guardTarget && vesselRadarData.locked) { SetCargoBays(); float LAstartTime = Time.time; while(guardTarget && Time.time-LAstartTime < 3 && pilotAI && !pilotAI.GetLaunchAuthorization(guardTarget, this)) { yield return new WaitForFixedUpdate(); } yield return new WaitForSeconds(0.5f); } //wait for missile turret to point at target if(guardTarget && ml && ml.missileTurret && vesselRadarData.locked) { vesselRadarData.SlaveTurrets(); float turretStartTime = Time.time; while(Time.time - turretStartTime < 5) { float angle = Vector3.Angle(ml.missileTurret.finalTransform.forward, ml.missileTurret.slavedTargetPosition - ml.missileTurret.finalTransform.position); if(angle < 1) { turretStartTime -= 2 * Time.fixedDeltaTime; } yield return new WaitForFixedUpdate(); } } yield return null; if(ml && guardTarget && vesselRadarData.locked && (!pilotAI || pilotAI.GetLaunchAuthorization(guardTarget, this))) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName()); } FireCurrentMissile(true); StartCoroutine(MissileAwayRoutine(ml)); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.Heat) { if(vesselRadarData && vesselRadarData.locked) { vesselRadarData.UnlockAllTargets(); vesselRadarData.UnslaveTurrets(); } float attemptStartTime = Time.time; float attemptDuration = Mathf.Max(targetScanInterval * 0.75f, 5f); SetCargoBays(); while(ml && Time.time - attemptStartTime < attemptDuration && (!heatTarget.exists || (heatTarget.predictedPosition - guardTarget.transform.position).magnitude >40)) { //try using missile turret to lock target if(ml.missileTurret) { ml.missileTurret.slaved = true; ml.missileTurret.slavedTargetPosition = guardTarget.CoM; ml.missileTurret.SlavedAim(); } yield return new WaitForFixedUpdate(); } //try uncaged IR lock with radar if(guardTarget && !heatTarget.exists && vesselRadarData && vesselRadarData.radarCount > 0) { if(!vesselRadarData.locked || (vesselRadarData.lockedTargetData.targetData.predictedPosition - guardTarget.transform.position).magnitude > 40) { //vesselRadarData.TryLockTarget(guardTarget.transform.position); vesselRadarData.TryLockTarget(guardTarget); yield return new WaitForSeconds(Mathf.Min(1, (targetScanInterval * 0.25f))); } } if(guardTarget && ml && heatTarget.exists && pilotAI) { float LAstartTime = Time.time; while(Time.time-LAstartTime < 3 && pilotAI && !pilotAI.GetLaunchAuthorization(guardTarget, this)) { yield return new WaitForFixedUpdate(); } yield return new WaitForSeconds(0.5f); } //wait for missile turret to point at target if(ml && ml.missileTurret && heatTarget.exists) { float turretStartTime = attemptStartTime; while(heatTarget.exists && Time.time - turretStartTime < Mathf.Max(targetScanInterval/2f, 2)) { float angle = Vector3.Angle(ml.missileTurret.finalTransform.forward, ml.missileTurret.slavedTargetPosition - ml.missileTurret.finalTransform.position); ml.missileTurret.slaved = true; ml.missileTurret.slavedTargetPosition = MissileGuidance.GetAirToAirFireSolution(ml, heatTarget.predictedPosition, heatTarget.velocity); ml.missileTurret.SlavedAim(); if(angle < 1) { turretStartTime -= 3 * Time.fixedDeltaTime; } yield return new WaitForFixedUpdate(); } } yield return null; if(guardTarget && ml && heatTarget.exists && (!pilotAI || pilotAI.GetLaunchAuthorization(guardTarget, this))) { if(BDArmorySettings.DRAW_DEBUG_LABELS) { Debug.Log("Firing on target: " + guardTarget.GetName()); } FireCurrentMissile(true); StartCoroutine(MissileAwayRoutine(ml)); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.GPS) { designatedGPSInfo = new GPSTargetInfo(VectorUtils.WorldPositionToGeoCoords(guardTarget.CoM, vessel.mainBody), guardTarget.vesselName.Substring(0, Mathf.Min(12, guardTarget.vesselName.Length))); FireCurrentMissile(true); } else if(ml.targetingMode == MissileLauncher.TargetingModes.AntiRad) { if(rwr) { rwr.EnableRWR(); } float attemptStartTime = Time.time; float attemptDuration = targetScanInterval * 0.75f; while(Time.time - attemptStartTime < attemptDuration && (!antiRadTargetAcquired || (antiRadiationTarget - guardTarget.CoM).magnitude > 20)) { yield return new WaitForFixedUpdate(); } if(SetCargoBays()) { yield return new WaitForSeconds(1f); } if(ml && antiRadTargetAcquired && (antiRadiationTarget - guardTarget.CoM).magnitude < 20) { FireCurrentMissile(true); StartCoroutine(MissileAwayRoutine(ml)); } } else if(ml.targetingMode == MissileLauncher.TargetingModes.Laser) { if(targetingPods.Count > 0) //if targeting pods are available, slew them onto target and lock. { foreach(var tgp in targetingPods) { tgp.EnableCamera(); yield return StartCoroutine(tgp.PointToPositionRoutine(guardTarget.CoM)); if(tgp) { if(tgp.groundStabilized && (tgp.groundTargetPosition - guardTarget.transform.position).magnitude < 20) { break; } else { tgp.DisableCamera(); } } } } //search for a laser point that corresponds with target vessel float attemptStartTime = Time.time; float attemptDuration = targetScanInterval * 0.75f; while(Time.time - attemptStartTime < attemptDuration && (!laserPointDetected || (foundCam && (foundCam.groundTargetPosition - guardTarget.CoM).magnitude >20))) { yield return new WaitForFixedUpdate(); } if(SetCargoBays()) { yield return new WaitForSeconds(1f); } if(ml && laserPointDetected && foundCam && (foundCam.groundTargetPosition - guardTarget.CoM).magnitude < 20) { FireCurrentMissile(true); StartCoroutine(MissileAwayRoutine(ml)); } } guardFiringMissile = false; } }
public bool EqualsTarget(GPSTargetInfo other) { return (name == other.name) && (gpsCoordinates == other.gpsCoordinates); }