# **************************************************************************** # CUI # # The Advanced Framework for Simulation, Integration, and Modeling (AFSIM) # # The use, dissemination or disclosure of data in this file is subject to # limitation or restriction. See accompanying README and LICENSE for details. # **************************************************************************** // converted BRAWLER v7.5 aslct7.f and akshn7.f // Replicates the missile fire 7,3,1,x alternative behavior include_once BrawlerScriptUtil.txt behavior weapon_decision_missile script_debug_writes off script_variables WsfQuantumTaskerProcessor processor; //**********************************************************************// //** debugging parameters **// //**********************************************************************// bool mDrawSteering = false; //**********************************************************************// //** alternative parameters **// //**********************************************************************// // Flag used to enable/disable this alternative // Takes the place of production rules bool mAlternative7311Enabled = true; // Alternative ID int ilevel = 7; int kalt = 3; int icall = 1; // Weapon number, for missiles 1 - 6 int lcall = 1; // Max/Min range for a SRM (meters) double mMaxRange = 25000 * Math.M_PER_FT(); double mMinRange = 4000 * Math.M_PER_FT(); // Maximum angle a shot can be taken at (degrees) double mMaxFiringAngle = 15.0; // Percent range is reduced by for simple envelope double mPercentRange = 0.2; // Maximum number of missiles on a target int mTargetSaturation = 1; // Required track quality for a shot double mRequiredTrackQuality = 0.8; //**********************************************************************// //********* VARIABLES BELOW THIS LINE ARE NOT FOR USER EDITING *********// //**********************************************************************// double grav = 32.17405; // From pcon.fi end_script_variables on_init if (PROCESSOR.IsA_TypeOf("WSF_QUANTUM_TASKER_PROCESSOR")) { processor = (WsfQuantumTaskerProcessor)PROCESSOR; } end_on_init // Replicates the checks done in canfirm.f // Return true if the missile can be fired // Sets the string to the fail reason script bool canfirm(WsfLocalTrack target, string failMsg) /* cnfire = .false. --MISSILE COMING OFF RAIL if (lnchng) then rsfail = 'MISL COMING OFF RAIL' return endif --SWITCHOLOGY DELAYS pswtch = (time .ge. timemf) if (.not. pswtch)then rsfail = 'SWITCHOLOGY' return endif --CHECK IF TARGET IS IN ENVELOPE --NOTE THAT SOME PPM... VARIABLES ARE RECALCULATED. call mslenv_typ_mm(ppmiac,renv_typ) call mslenv(iacid,xp(1,me),vp(1,me),ap(1,me), 1 alphap,xp(1,ppmiac),vp(1,ppmiac),ap(1,ppmiac), 2 ppmptr, rbep, rwep, ext_mle, .true., renv_typ, ppmrmn, ppmrmx, 3 ppmapt, ppmse, ppmaof, ppmenv, ppmtrk, ppmohr,l_config) if (.not. ppmenv)then rsfail = 'TGT NOT IN ENV' return endif --Does pilot beleive that target is within max range (R (mMaxRange - mMaxRange * mPercentRange) || absRelativeBearing >= mMaxFiringAngle ) { #writeln("absRelativeBearing = ", absRelativeBearing, ", range = ", range); #failMsg = "TGT NOT IN ENV"; target.SetAuxData("msg", "TGT NOT IN ENV"); return false; } // Does pilot beleive that target is within max range (R= mTargetSaturation) { //lfire = true; writeln_d(" ", PLATFORM.Name(), " shouldn't fire ", target.TargetName(), " saturated"); failMsg = "MXTGT_AC LIMIT"; return false; } if (target.TrackQuality() < mRequiredTrackQuality) { failMsg = "NO WEAPON QUAL TRK"; return false; } return true; end_script precondition #writeln_d(PLATFORM.Name(), " precondition weapon_decision_missile, T=", TIME_NOW); ### Evaluate conditions that would prevent behavior alternative from running if (!PROCESSOR.IsA_TypeOf("WSF_QUANTUM_TASKER_PROCESSOR")) { writeln_d("not a quantum tasker!"); return Failure("behavior not attached to a WSF_QUANTUM_TASKER_PROCESSOR"); } // aslct7.f line 123 - 132 # --CHECK IF TARGET SELECTED # if (ppmiac .eq. 0 .and. .not.dewvmsl)then # rsfail = 'NO TARGET SELECTED' # goto 800 # endif # --CHECK IF WEAPON SELECTED # if (ppmptr .eq. 0)then # rsfail = 'NO WEAPON SELECTED' # goto 800 # endif WsfTaskList tasks = processor.TasksReceivedOfType("WEAPON"); if(tasks.Count() <= 0) { return Failure("no tasks"); } // Assuming 1v1 and first and only task is the one we want WsfLocalTrack targetTrack = PLATFORM.MasterTrackList().FindTrack(tasks.Entry(0).LocalTrackId()); if(tasks.Count() <= 0 || targetTrack.IsNull() || !targetTrack.IsValid()) { writeln_d(" ", PLATFORM.Name(), " no target selected at time: ", TIME_NOW); return Failure("no target selected"); } // Weapon selection done in selwpn.f (called from aslct2.f) // checks weapon inventory. Use a similar check here as a replacement if (!PLATFORM.Weapon("srm").IsValid() || PLATFORM.Weapon("srm").QuantityRemaining() <= 0) { writeln_d(" ", PLATFORM.Name(), " no weapon selected at time: ", TIME_NOW); return Failure("no weapon selected"); } // aslct7() calls canfir(). // canfir.f checks production rules and GCI inhibit // just doing a simple flag for now if (!mAlternative7311Enabled) { writeln_d("behavior not enabled!"); return Failure("behavior alternative not enabled"); } //canfir.f calls canfirm() string msg = ""; if (!canfirm(targetTrack, msg)) { msg = targetTrack.AuxDataString("msg"); writeln_d(" ", PLATFORM.Name(), " couldn't fire at time: ", TIME_NOW, " ", msg); return Failure(msg); } // aslct7 line 199 - 205 // if undamaged calls shldfr(). // if we are damaged skip checks and fire now if (PLATFORM.DamageFactor() <= 0.0) { // shldfr.f just calls the specific weapon type if (!shldfrm(targetTrack, msg)) { writeln_d(" ", PLATFORM.Name(), " shouldn't fire at time: ", TIME_NOW, " ", msg); return Failure(msg); } } // aslct7 creates and alternative to evaluate. // The alternative has no projection and always // evaluates to 1, so skip that processing // All conditions pass, weapon can fire return true; end_precondition execute // Replicates akshn7.f // We don't need to do all the bookeeping that BRAWLER // does. Just launch the weapon. WsfTaskList tasks = processor.TasksReceivedOfType("WEAPON"); // Assuming 1v1 and first and only task is the one we want WsfLocalTrack targetTrack = PLATFORM.MasterTrackList().FindTrack(tasks.Entry(0).LocalTrackId()); //Assuming weapon name, checked in precondition WsfWeapon weapon = PLATFORM.Weapon("srm"); bool launched = weapon.FireSalvo(targetTrack, 1); // Always firing one for now if (!launched) { writeln_d(" ", PLATFORM.Name(), " could NOT fire at track: ", targetTrack.TargetName(), " at time: ", TIME_NOW); } end_execute end_behavior