void CommandAG(BDModulePilotAI wingman, int index, object ag) { //Debug.Log("object to string: "+ag.ToString()); KSPActionGroup actionGroup = (KSPActionGroup)ag; //Debug.Log("ag to string: " + actionGroup.ToString()); wingman.CommandAG(actionGroup); }
void SelectAll(BDModulePilotAI wingman, int index, object data) { for (int i = 0; i < wingmen.Count; i++) { if (!focusIndexes.Contains(i)) { focusIndexes.Add(i); } } }
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 RefreshFriendlies() { if (!weaponManager) { return; } friendlies = new List <BDModulePilotAI>(); foreach (var v in BDATargetManager.LoadedVessels) { if (!v || !v.loaded || v == vessel) { continue; } BDModulePilotAI pilot = null; MissileFire wm = null; foreach (var p in v.FindPartModulesImplementing <BDModulePilotAI>()) { pilot = p; break; } if (!pilot) { continue; } foreach (var w in v.FindPartModulesImplementing <MissileFire>()) { wm = w; } if (!wm || wm.team != weaponManager.team) { continue; } friendlies.Add(pilot); } //TEMPORARY wingmen = new List <BDModulePilotAI>(); foreach (var p in friendlies) { wingmen.Add(p); } }
void CommandFollow(BDModulePilotAI wingman, int index, object data) { wingman.CommandFollow(this, index); }
void CommandRelease(BDModulePilotAI wingman, int index, object data) { wingman.ReleaseCommand(); }
IEnumerator CommandPosition(BDModulePilotAI wingman, BDModulePilotAI.PilotCommands command) { if(focusIndexes.Count == 0 && !commandSelf) { yield break; } DisplayScreenMessage("Select target coordinates.\nRight-click to cancel."); if(command == BDModulePilotAI.PilotCommands.FlyTo) { waitingForFlytoPos = true; } else if(command == BDModulePilotAI.PilotCommands.Attack) { waitingForAttackPos = true; } yield return null; bool waitingForPos = true; drawMouseDiamond = true; while(waitingForPos) { if(Input.GetMouseButtonDown(1)) { break; } if(Input.GetMouseButtonDown(0)) { Vector3 mousePos = new Vector3(Input.mousePosition.x/Screen.width, Input.mousePosition.y/Screen.height, 0); Plane surfPlane = new Plane(vessel.upAxis, vessel.transform.position - (vessel.altitude * vessel.upAxis)); Ray ray = FlightCamera.fetch.mainCamera.ViewportPointToRay(mousePos); float dist; if(surfPlane.Raycast(ray, out dist)) { Vector3 worldPoint = ray.GetPoint(dist); Vector3d gps = VectorUtils.WorldPositionToGeoCoords(worldPoint, vessel.mainBody); if(command == BDModulePilotAI.PilotCommands.FlyTo) { wingman.CommandFlyTo(gps); } else if(command == BDModulePilotAI.PilotCommands.Attack) { wingman.CommandAttack(gps); } StartCoroutine(CommandPositionGUIRoutine(wingman, new GPSTargetInfo(gps, command.ToString()))); } break; } yield return null; } waitingForAttackPos = false; waitingForFlytoPos = false; drawMouseDiamond = false; ScreenMessages.RemoveMessage(screenMessage); }
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 OpenAGWindow(BDModulePilotAI wingman, int index, object data) { showAGWindow = !showAGWindow; }
void CommandRelease(BDModulePilotAI wingman, int index) { wingman.ReleaseCommand(); }
void CommandFlyTo(BDModulePilotAI wingman, int index, object data) { StartCoroutine(CommandPosition(wingman, BDModulePilotAI.PilotCommands.FlyTo)); }
void CommandTakeOff(BDModulePilotAI wingman, int index, object data) { wingman.ActivatePilot(); wingman.standbyMode = false; }
void SelectAll(BDModulePilotAI wingman, int index) { selectAll = true; }
IEnumerator CommandPosition(BDModulePilotAI wingman, BDModulePilotAI.PilotCommands command) { if (focusIndexes.Count == 0 && !commandSelf) { yield break; } DisplayScreenMessage("Select target coordinates.\nRight-click to cancel."); if (command == BDModulePilotAI.PilotCommands.FlyTo) { waitingForFlytoPos = true; } else if (command == BDModulePilotAI.PilotCommands.Attack) { waitingForAttackPos = true; } yield return(null); bool waitingForPos = true; drawMouseDiamond = true; while (waitingForPos) { if (Input.GetMouseButtonDown(1)) { break; } if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = new Vector3(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height, 0); Plane surfPlane = new Plane(vessel.upAxis, vessel.transform.position - (vessel.altitude * vessel.upAxis)); Ray ray = FlightCamera.fetch.mainCamera.ViewportPointToRay(mousePos); float dist; if (surfPlane.Raycast(ray, out dist)) { Vector3 worldPoint = ray.GetPoint(dist); Vector3d gps = VectorUtils.WorldPositionToGeoCoords(worldPoint, vessel.mainBody); if (command == BDModulePilotAI.PilotCommands.FlyTo) { wingman.CommandFlyTo(gps); } else if (command == BDModulePilotAI.PilotCommands.Attack) { wingman.CommandAttack(gps); } StartCoroutine(CommandPositionGUIRoutine(wingman, new GPSTargetInfo(gps, command.ToString()))); } break; } yield return(null); } waitingForAttackPos = false; waitingForFlytoPos = false; drawMouseDiamond = false; ScreenMessages.RemoveMessage(screenMessage); }
public override void OnStart (PartModule.StartState state) { UpdateMaxGuardRange(); startTime = Time.time; UpdateTeamString(); if(HighLogic.LoadedSceneIsFlight) { part.force_activate(); selectionMessage = new ScreenMessage("", 2, ScreenMessageStyle.LOWER_CENTER); UpdateList(); if(weaponArray.Length > 0) selectedWeapon = weaponArray[weaponIndex]; //selectedWeaponString = GetWeaponName(selectedWeapon); cameraTransform = part.FindModelTransform("BDARPMCameraTransform"); part.force_activate(); rippleTimer = Time.time; targetListTimer = Time.time; wingCommander = part.FindModuleImplementing<ModuleWingCommander>(); audioSource = gameObject.AddComponent<AudioSource>(); audioSource.minDistance = 1; audioSource.maxDistance = 500; audioSource.dopplerLevel = 0; audioSource.spatialBlend = 1; warningAudioSource = gameObject.AddComponent<AudioSource>(); warningAudioSource.minDistance = 1; warningAudioSource.maxDistance = 500; warningAudioSource.dopplerLevel = 0; warningAudioSource.spatialBlend = 1; targetingAudioSource = gameObject.AddComponent<AudioSource>(); targetingAudioSource.minDistance = 1; targetingAudioSource.maxDistance = 250; targetingAudioSource.dopplerLevel = 0; targetingAudioSource.loop = true; targetingAudioSource.spatialBlend = 1; StartCoroutine (MissileWarningResetRoutine()); if(vessel.isActiveVessel) { BDArmorySettings.Instance.ActiveWeaponManager = this; } UpdateVolume(); BDArmorySettings.OnVolumeChange += UpdateVolume; BDArmorySettings.OnSavedSettings += ClampVisualRange; StartCoroutine(StartupListUpdater()); GameEvents.onVesselCreate.Add(OnVesselCreate); GameEvents.onPartJointBreak.Add(OnPartJointBreak); GameEvents.onPartDie.Add(OnPartDie); foreach(var aipilot in vessel.FindPartModulesImplementing<BDModulePilotAI>()) { pilotAI = aipilot; break; } } }
void SelectAll(BDModulePilotAI wingman, int index, object data) { for(int i = 0; i < wingmen.Count; i++) { if(!focusIndexes.Contains(i)) { focusIndexes.Add(i); } } }
void CommandAttack(BDModulePilotAI wingman, int index, object data) { StartCoroutine(CommandPosition(wingman, BDModulePilotAI.PilotCommands.Attack)); }
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; }