void SendGPS() { if (groundStabilized && weaponManager) { BDATargetManager.GPSTargets[BDATargetManager.BoolToTeam(weaponManager.team)].Add(new GPSTargetInfo(bodyRelativeGTP, "Target")); } }
public TargetSignatureData(Vessel v, float _signalStrength) { velocity = v.srf_velocity; geoPos = VectorUtils.WorldPositionToGeoCoords(v.CoM, v.mainBody); acceleration = v.acceleration; exists = true; timeAcquired = Time.time; signalStrength = _signalStrength; targetInfo = v.gameObject.GetComponent <TargetInfo> (); team = BDArmorySettings.BDATeams.None; if (targetInfo) { team = targetInfo.team; } else { foreach (var mf in v.FindPartModulesImplementing <MissileFire>()) { team = BDATargetManager.BoolToTeam(mf.team); break; } } vesselJammer = v.gameObject.GetComponent <VesselECMJInfo>(); pingPosition = Vector2.zero; }
protected void AddTargetInfoToVessel() { TargetInfo info = vessel.gameObject.AddComponent <TargetInfo>(); info.team = BDATargetManager.BoolToTeam(Team); info.isMissile = true; info.MissileBaseModule = this; }
public TargetSignatureData(Vessel v, float _signalStrength) { /* * if(v.situation == Vessel.Situations.SUB_ORBITAL || v.situation == Vessel.Situations.ESCAPING || v.situation == Vessel.Situations.SUB_ORBITAL) * { * velocity = v.obt_velocity; * orbit = v.orbit; * orbital = true; * } * else * { */ orbital = false; orbit = null; velocity = v.srf_velocity; //} vessel = v; geoPos = VectorUtils.WorldPositionToGeoCoords(v.CoM, v.mainBody); acceleration = v.acceleration; exists = true; timeAcquired = Time.time; signalStrength = _signalStrength; targetInfo = v.gameObject.GetComponent <TargetInfo> (); team = BDArmorySettings.BDATeams.None; if (targetInfo) { team = targetInfo.team; } else { foreach (var mf in v.FindPartModulesImplementing <MissileFire>()) { team = BDATargetManager.BoolToTeam(mf.team); break; } } vesselJammer = v.gameObject.GetComponent <VesselECMJInfo>(); pingPosition = Vector2.zero; lockedByRadar = null; }
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 AutoPilot(FlightCtrlState s) { if (!vessel || !vessel.transform || vessel.packed || !vessel.mainBody) { return; } vesselTransform = vessel.ReferenceTransform; //default brakes off full throttle //s.mainThrottle = 1; //vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); AdjustThrottle(maxSpeed, true); useAB = true; useBrakes = true; vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); steerMode = SteerModes.NormalFlight; GetGuardTarget(); if (vessel.Landed && standbyMode && weaponManager && BDATargetManager.TargetDatabase[BDATargetManager.BoolToTeam(weaponManager.team)].Count == 0) { //s.mainThrottle = 0; //vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); AdjustThrottle(0, true); return; } //upDirection = -FlightGlobals.getGeeForceAtPosition(transform.position).normalized; upDirection = VectorUtils.GetUpDirection(vessel.transform.position); debugString = string.Empty; if (MissileGuidance.GetRadarAltitude(vessel) < minAltitude) { startedLanded = true; } if (startedLanded) { TakeOff(s); turningTimer = 0; } else { if (FlyAvoidCollision(s)) { turningTimer = 0; } else if (command != PilotCommands.Free) { UpdateCommand(s); } else { UpdateAI(s); } } //brake and cut throttle if exceeding max speed /* * if(vessel.srfSpeed > maxSpeed) * { * vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true); * s.mainThrottle = 0; * } */ debugString += "\nthreatLevel: " + threatLevel; }
void Awake() { if (!vessel) { vessel = GetComponent <Vessel>(); } if (!vessel) { Debug.Log("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 <MissileLauncher>()) { isMissile = true; missileModule = 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()); } }
IEnumerator DogfightCompetitionModeRoutine(float distance) { competitionStarting = true; competitionStatus = "Competition: Pilots are taking off."; Dictionary <BDArmorySettings.BDATeams, List <BDModulePilotAI> > pilots = new Dictionary <BDArmorySettings.BDATeams, List <BDModulePilotAI> >(); pilots.Add(BDArmorySettings.BDATeams.A, new List <BDModulePilotAI>()); pilots.Add(BDArmorySettings.BDATeams.B, new List <BDModulePilotAI>()); foreach (var v in BDATargetManager.LoadedVessels) { if (!v || !v.loaded) { continue; } BDModulePilotAI pilot = null; foreach (var p in v.FindPartModulesImplementing <BDModulePilotAI>()) { pilot = p; break; } if (!pilot || !pilot.weaponManager) { continue; } pilots[BDATargetManager.BoolToTeam(pilot.weaponManager.team)].Add(pilot); pilot.ActivatePilot(); pilot.standbyMode = false; if (pilot.weaponManager.guardMode) { pilot.weaponManager.ToggleGuardMode(); } } //clear target database so pilots don't attack yet BDATargetManager.ClearDatabase(); if (pilots[BDArmorySettings.BDATeams.A].Count == 0 || pilots[BDArmorySettings.BDATeams.B].Count == 0) { Debug.Log("Unable to start competition mode - one or more teams is empty"); competitionStatus = "Competition: Failed! One or more teams is empty."; yield return(new WaitForSeconds(2)); competitionStarting = false; yield break; } BDModulePilotAI aLeader = pilots[BDArmorySettings.BDATeams.A][0]; BDModulePilotAI bLeader = pilots[BDArmorySettings.BDATeams.B][0]; aLeader.weaponManager.wingCommander.CommandAllFollow(); bLeader.weaponManager.wingCommander.CommandAllFollow(); //wait till the leaders are airborne while (aLeader && bLeader && (aLeader.vessel.LandedOrSplashed || bLeader.vessel.LandedOrSplashed)) { yield return(null); } if (!aLeader || !bLeader) { StopCompetition(); } competitionStatus = "Competition: Sending pilots to start position."; Vector3 aDirection = Vector3.ProjectOnPlane(aLeader.vessel.CoM - bLeader.vessel.CoM, aLeader.vessel.upAxis).normalized; Vector3 bDirection = Vector3.ProjectOnPlane(bLeader.vessel.CoM - aLeader.vessel.CoM, bLeader.vessel.upAxis).normalized; Vector3 center = (aLeader.vessel.CoM + bLeader.vessel.CoM) / 2f; Vector3 aDestination = center + (aDirection * (distance + 1250f)); Vector3 bDestination = center + (bDirection * (distance + 1250f)); aDestination = VectorUtils.WorldPositionToGeoCoords(aDestination, FlightGlobals.currentMainBody); bDestination = VectorUtils.WorldPositionToGeoCoords(bDestination, FlightGlobals.currentMainBody); aLeader.CommandFlyTo(aDestination); bLeader.CommandFlyTo(bDestination); Vector3 centerGPS = VectorUtils.WorldPositionToGeoCoords(center, FlightGlobals.currentMainBody); //wait till everyone is in position bool waiting = true; while (waiting) { waiting = false; if (!aLeader || !bLeader) { StopCompetition(); } if (Vector3.Distance(aLeader.transform.position, bLeader.transform.position) < distance * 1.95f) { waiting = true; } else { foreach (var t in pilots.Keys) { foreach (var p in pilots[t]) { if (p.currentCommand == BDModulePilotAI.PilotCommands.Follow && Vector3.Distance(p.vessel.CoM, p.commandLeader.vessel.CoM) > 1000f) { competitionStatus = "Competition: Waiting for teams to get in position."; waiting = true; } } } } yield return(null); } //start the match foreach (var t in pilots.Keys) { foreach (var p in pilots[t]) { if (!p) { continue; } //enable guard mode if (!p.weaponManager.guardMode) { p.weaponManager.ToggleGuardMode(); } //report all vessels if (BDATargetManager.BoolToTeam(p.weaponManager.team) == BDArmorySettings.BDATeams.B) { BDATargetManager.ReportVessel(p.vessel, aLeader.weaponManager); } else { BDATargetManager.ReportVessel(p.vessel, bLeader.weaponManager); } //release command p.ReleaseCommand(); p.defaultOrbitCoords = centerGPS; } } competitionStatus = "Competition starting! Good luck!"; yield return(new WaitForSeconds(2)); competitionStarting = false; }