# ****************************************************************************
# 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.
# ****************************************************************************

platform_type   BRAWLER_FLIGHT_LEAD    WSF_PLATFORM
   comm datalink WSF_COMM_TRANSCEIVER
      network_name brawler_net
      internal_link data_mgr
      internal_link task_mgr
      internal_link perception
   end_comm
   processor data_mgr WSF_TRACK_PROCESSOR
      master_track_processor
   end_processor
   track_manager
      retain_raw_tracks
      retain_track_history
      uncorrelated_track_drops disable
   end_track_manager
   processor perception WSF_PERCEPTION_PROCESSOR
      asset_perception status_messages
   end_processor

   processor task_mgr WSF_QUANTUM_TASKER_PROCESSOR
      script_variables
         ## for evaluating weapon tasks
         Map<string,int> mKnownTargetTypes = Map<string,int>();
         mKnownTargetTypes["BRAWLER_PLATFORM"] = 1;
      end_script_variables

      script Array<WsfTask> FlightLeadTaskGeneration (Array<WsfLocalTrack> TRACKS, Array<WsfAssetPerception> ASSETS )
         Array<WsfTask> tasks = Array<WsfTask>();
         //if its us, then create weapon tasks for enemy tracks
         writeln_d("TRACKS.Size() = ", TRACKS.Size(), ", ASSETS.Size() = ", ASSETS.Size());
         for (int i=0; i<TRACKS.Size(); i=i+1)
         {
            WsfLocalTrack lt = TRACKS.Get(i);
            if (lt.IsValid() && (!lt.SideValid() || lt.Side() != PLATFORM.Side()))
            {
               if (mKnownTargetTypes.Size() <= 0 || mKnownTargetTypes.Exists(lt.TargetType()))
               {
                  WsfTask task = WsfTask.Construct(1.0, "WEAPON", lt);
                  task.SetTaskType("WEAPON");
                  tasks.PushBack(task);
                  writeln_d("weapon task generated for: ", lt.TargetName(), ", updated time: ", lt.UpdateTime());
               }
            }
         }
         return tasks;
      end_script

      on_initialize
      end_on_initialize

      #debug
      #script_debug_writes on
      #show_task_messages
      reallocation_strategy dynamic
      generator custom FlightLeadTaskGeneration
      evaluator distance
     #allocator greedy_isolated
      allocator optimal_profit
      allocator_extra_assets optimal_profit   #assigns tasks to extra blue guys
      update_interval 0.3 sec
   end_processor

end_platform_type
