 script_variables
    Array<string> mZoneNames = Array<string>();
    Map<string, WsfRIPRJob> mZoneJobMap = Map<string, WsfRIPRJob>();
    Map<string, double> mZonePriority = Map<string, double>();
    Map<string, int> mZoneNumThreats = Map<string, int>();
    Map<string, WsfGeoPoint> mZonePoint = Map<string, WsfGeoPoint>();
    Map<string, double> mZoneBearing = Map<string, double>();
    Map<string, bool> mZoneBearingValid = Map<string, bool>();
    Map<string, double> mZoneTrackValue = Map<string, double>();

    Map<string, WsfGeoPoint> mClusterMeanPoint   = Map<string, WsfGeoPoint>();
    Map<string, double> mClusterMeanBearing = Map<string, double>();

    Map<int, int> mJobToWinnerMap = Map<int, int>();
    Map<int, int> mFlankToClusterMap = Map<int, int>();
    Map<int, int> mClusterToFlankMap = Map<int, int>();
    Array<string> mCompletedFlanks = Array<string>();
    //Array<int> mCompletedFlanks = Array<string>();
    Map<string, double> mFlankNameToTimeCompleteMap = Map<string, double>();

    //Map<int, WsfRIPRJob> mFlankJobMap = Map<int, WsfRIPRJob>();

    int mMaxTotalFlankJobsEverToCreate = 1;
    int mMaxJobWinnersForFlank = 1;
    int mFlankJobsCreated = 0;
    int mFlankJobsCompleted = 0;
    double mFlankJobPriorityScale = 0.75; // make > 1 for more important than clusters
    double mFlankDistance = 60.0; //flank towards a point approximately this many nm to the side of target

    //after a completed flank on a cluster, don't do another on that same cluster until this time passes
    double mFlankRepeatDelay = 300.0; //in units of seconds

    int mMaxJobWinnersForGciZone = 1;
    int mLastNumClusters = 0;
    // the following ints are really pointers in C++, so don't change their values!
    int  riprInputLink = 0;
    int  riprOutputLink = 0;
    int  riprInputJob = 0;
    
    WsfClusterManager cManager;
    
    WsfDraw draw = WsfDraw();

  end_script_variables



  script void draw_cluster_hull(WsfCluster cluster)
     Array<WsfGeoPoint> pts = cluster.ConvexHull();
     //writeln_d("   ~~~ aigci cluster convex hull pts: ", pts.Size());
     if (pts.Size() <= 0)
     {
        return;
     }
     WsfGeoPoint first = pts.Get(0);
     draw.SetColor(1.0,0.5,0.0);  //orange?
     draw.SetLineStyle("solid");
     draw.SetLineSize(2);
     draw.SetDuration(3);
     draw.BeginPolyline();
       for (int j = 0; j < pts.Size(); j = j + 1 )
       {
          WsfGeoPoint pt = pts.Get(j);
          draw.Vertex(pt);
          //writeln_d("   ~~~ aigci cluster convex hull pt ", j+1, ": ", pt.Latitude(), ", ", pt.Longitude());
       }
       draw.Vertex(first);
     draw.End();
  end_script




  script void aigci_update_with_clusters(WsfLocalTrackList localTracks)

    //writeln_d("   ~~~ aigci tracklist count:       ", localTracks.Count());

    cManager.UpdateClusters(TIME_NOW,localTracks);    
    int NumClusters = cManager.Count();

    for (int i = 0; i < NumClusters; i = i + 1 )
    {
      WsfCluster cluster = cManager.Entry(i);
      string ClusterName = PLATFORM.Name() + "_" + (string)i;
      cluster.UpdatePlatformZone(PLATFORM,ClusterName,(5.0/60.0));   //5 minutes (1/12th of a degree)

      if (mDrawClusters == true)
      {
        draw_cluster_hull(cluster);
      }

      WsfGeoPoint clusterPoint = cluster.MeanLocation();
      double clusterBearing = cluster.Bearing();
      bool clusterBearingValid = cluster.BearingValid();

      //writeln_d("~~~ aiGCI - cluster ", ClusterName, ", BEARING ", clusterBearing, " bearing valid: ", clusterBearingValid );

      int occupants = cluster.Count();
      double ClusterPriority = (double)occupants;

      if( occupants > 0 )
      {
        if( mZoneJobMap.Exists( ClusterName ) )
        {
          //writeln_d("~~~ aiGCI, updating job for cluster: ", ClusterName);
          
          //job exists for zone with threats, update job priority
          WsfRIPRJob temp = mZoneJobMap.Get( ClusterName );
          //job priority could have changed, set it
          temp.SetPriority( ClusterPriority );
          temp.SetData( "ZonePoint", clusterPoint );
          temp.SetData( "ZoneBearing", clusterBearing );
          temp.SetData( "ZoneBearingValid", clusterBearingValid );
          //number of threats inside zone could have changed, set it
          temp.SetData( "ZoneNumThreats", occupants );

          Array<string> arr = Array<string>();
          for (int i = 0; i < occupants; i = i + 1 )
          {
             arr.PushBack(cluster.Entry(i).TargetName());
          }
          temp.SetData( "ZoneThreatNameArray", arr );
        }
        else
        {
          //zone just became hot, job not created yet, create one
          WsfRIPRJob temp = WsfRIPRJob.Create( PROCESSOR,
                                               "zone",
                                               "zone-" + ClusterName,
                                               ClusterPriority,
                                               mMaxJobWinnersForGciZone );
          temp.SetData( "ZoneName", ClusterName );
          temp.SetData( "ZonePoint", clusterPoint );
          temp.SetData( "ZoneBearing", clusterBearing );
          temp.SetData( "ZoneBearingValid", clusterBearingValid );
          temp.SetData( "ZoneNumThreats", occupants );
          temp.SetData( "for_air", 1 );

          Array<string> arr = Array<string>();
          for (int i = 0; i < occupants; i = i + 1 )
          {
             arr.PushBack(cluster.Entry(i).TargetName());
          }
          temp.SetData( "ZoneThreatNameArray", arr );

          AddJob(temp);
          mZoneJobMap.Set( ClusterName, temp );
          
          //writeln_d("~~~ aiGCI, creating job for cluster: ", ClusterName);
          writeln_d("~~~ ", PLATFORM.Name(), " job change, ADD: ", temp.Name() );
        }
      }
      else
      {
        //no threats in cluster, make sure job for cluster doesn't exist or is deleted
        if( mZoneJobMap.Exists( ClusterName ) )
        {
          //writeln_d("~~~ aiGCI, removing job for empty cluster: ", ClusterName);
          writeln_d("~~~ ", PLATFORM.Name(), " job change, REMOVE: ", mZoneJobMap.Get(ClusterName).Name() );
          RemoveJob( mZoneJobMap.Get(ClusterName) );
          //mZoneJobMap.Erase( ClusterName );
          mZoneJobMap.Remove( ClusterName );
        }
      }
    }

    //remove any additional clusters    
    for( int j = NumClusters; j < mLastNumClusters; j = j+1 )
    {
      string ClusterName = PLATFORM.Name() + "_" + (string)j;
      if( mZoneJobMap.Exists( ClusterName ) )
      {
        //writeln_d("~~~ aiGCI, removing job for empty cluster: ", ClusterName);
        writeln_d("~~~ ", PLATFORM.Name(), " job change, REMOVE: ", mZoneJobMap.Get(ClusterName).Name() );
        RemoveJob( mZoneJobMap.Get(ClusterName) );
        //mZoneJobMap.Erase( ClusterName );
        mZoneJobMap.Remove( ClusterName );
      }
    }

    mLastNumClusters = NumClusters;

  end_script



  script void aigci_update_with_zones()

    extern string DetermineTrackCategory(WsfTrack);

    WsfLocalTrackList localTracks;
    localTracks = FlightTrackList();

    writeln_d("~~~  localTracks.Count() = ", localTracks.Count());

    mZonePoint.Clear();
    mZoneBearing.Clear();
    mZoneBearingValid.Clear();
    mZonePriority.Clear();
    mZoneTrackValue.Clear();
    mZoneNumThreats.Clear();

    writeln_d("~~~  mZonePriority.Size() = ", mZonePriority.Size());

    foreach (WsfTrack track in localTracks)
    {
      //writeln_d("~~~ Considering: ", track.TargetName());
      // if the track is not a foe, we'll ignore it
      if (!(track.IsValid()) || !track.IFF_Foe())
      {
        //writeln("~~~ Need to remove track: ", !(track.IsValid()), "- ", !track.IFF_Foe());
        continue;
      }
      
      extern bool TestTrackCategory(WsfTrack,string);
      if( TestTrackCategory(track,"unknown") )
      {
         continue;
      }

      if( track.LocationValid() )
      {
        writeln_d("~~~ Considering: ", track.TrackId().Name(), ".", track.TrackId().Number(), " -> ", track.TargetName());
      }

      int NumZonesInside = 0;
      //zones can overlap, so check all zones for each track
      foreach( string zName in mZoneNames )
      {
        if( track.WithinZoneOf( PLATFORM, zName ) )
        {
          NumZonesInside = NumZonesInside + 1;

          if( ! mZonePriority.Exists(zName) )
          {
            mZonePriority.Set( zName, 1.0 );
          }

          //update total zone priority
          string trgtType = DetermineTrackCategory(track);
          double ThreatPriority = ThreatTypePriority.Get(trgtType);
          double CurZonePriority = ThreatPriority + mZonePriority.Get(zName);
          mZonePriority.Set( zName, CurZonePriority );

          writeln_d("~~~  ", track.TargetName(), " of type ", trgtType, " inside of ", zName, "-> score increased: ", ThreatPriority );
          writeln_d("~~~  mZonePriority.Size() = ", mZonePriority.Size());

          //update number of threats in zone
          int CurZoneNumThreats = 1;
          if( mZoneNumThreats.Exists(zName) )
          {
            CurZoneNumThreats = CurZoneNumThreats + mZoneNumThreats.Get(zName);
          }
          mZoneNumThreats.Set( zName, CurZoneNumThreats );

          writeln_d("~~~ Track: ", track.TargetName(), " inside GCI zone: ", zName );

          if( !mZoneTrackValue.Exists( zName ) ||
              mZoneTrackValue.Get( zName ) < ThreatPriority )
          {
            mZoneTrackValue.Set( zName, ThreatPriority );
            WsfGeoPoint point = track.CurrentLocation();
            if( ! track.ElevationValid() )
            {
              double DefaultAltitude = 10000.0;
              point.Set( point.Latitude(), point.Longitude(), DefaultAltitude );
            }
            mZonePoint.Set( zName, point );

            double bearing = track.Bearing();
            if( ! track.BearingValid() )
            {
              //if track has no bearing, assume its headed straight for the GCI commander platform
              bearing = MATH.NormalizeAngle0_360( PLATFORM.TrueBearingTo(track) - 180.0 );
            }
            mZoneBearing.Set( zName, bearing );
            mZoneBearingValid.Set( zName, track.BearingValid() );
          }
        }
      }

      if( NumZonesInside <= 0 )
      {
        writeln_d("~~~ Track: ", track.TargetName(), " not inside ANY GCI zones!!!");
      }
    }

    foreach( string zName in mZoneNames )
    {
      if( mZonePriority.Exists(zName) )
      {
        double ZoneJobPriority = mZonePriority.Get( zName );

        if( mZoneJobMap.Exists( zName ) )
        {
          //writeln_d("~~~ aiGCI, updating job for zone: ", zName);

          //job exists for zone with threats, update job priority
          WsfRIPRJob temp = mZoneJobMap.Get( zName );
          //job priority could have changed, set it
          temp.SetPriority( ZoneJobPriority );
          temp.SetData( "ZonePoint", mZonePoint.Get( zName ) );
          temp.SetData( "ZoneBearing", mZoneBearing.Get( zName ) );
          temp.SetData( "ZoneBearingValid", mZoneBearingValid.Get( zName ) );

          //number of threats inside zone could have changed, set it
          temp.SetData( "ZoneNumThreats", mZoneNumThreats.Get( zName ) );
        }
        else
        {
          //zone just became hot, job not created yet, create one

          WsfRIPRJob temp = WsfRIPRJob.Create( PROCESSOR,
                              "zone",
                              "zone-" + zName,
                              ZoneJobPriority,
                              mMaxJobWinnersForGciZone );
          temp.SetData( "ZoneName", zName );
          temp.SetData( "ZonePoint", mZonePoint.Get( zName ) );
          temp.SetData( "ZoneBearing", mZoneBearing.Get( zName ) );
          temp.SetData( "ZoneBearingValid", mZoneBearingValid.Get( zName ) );
          temp.SetData( "ZoneNumThreats", mZoneNumThreats.Get( zName ) );
          temp.SetData( "for_air", 1 );

          AddJob(temp);
          mZoneJobMap.Set( zName, temp );

          //writeln_d("~~~ aiGCI, creating job for zone: ", zName);
          writeln_d("~~~ ", PLATFORM.Name(), " job change, ADD: ", temp.Name() );
        }
      }
      else
      {
        //no threats in zone, make sure job for zone doesn't exist or is deleted
        if( mZoneJobMap.Exists( zName ) )
        {
          //writeln_d("~~~ aiGCI, removing job for empty zone: ", zName);
          writeln_d("~~~ ", PLATFORM.Name(), " job change, REMOVE: ", mZoneJobMap.Get(zName).Name() );
          RemoveJob( mZoneJobMap.Get(zName) );
          //mZoneJobMap.Erase( zName );
          mZoneJobMap.Remove( zName );
        }
      }
    }

  end_script


  script void aigci_flank_complete(int jobID)
    //save job in completed array
    //remove job from created array
    WsfRIPRJob aJob = GetJobById( jobID );
    writeln_d("~~~ Flank Job Completed: ", aJob.GetDescription());
    mCompletedFlanks.PushBack( aJob.Name() );

    mFlankNameToTimeCompleteMap.Set( aJob.Name(), TIME_NOW );

    int clusterId = mFlankToClusterMap.Get( jobID );
    mFlankToClusterMap.Erase( jobID );
    mClusterToFlankMap.Erase( clusterId );

    //mFlankJobMap.Remove( jobID );

    mFlankJobsCompleted = mFlankJobsCompleted + 1;
  end_script


  script void aigci_update_flanks()

    //check if this gci is done creating & updating the flank jobs
    if( mFlankJobsCompleted >= mMaxTotalFlankJobsEverToCreate )
    {
      writeln_d( "~~~ aiGCI - Max Flank Jobs Completed, return now!" );
      return;
    }

    //check for clusters that went away & thus we can't flank them anymore
    //otherwise, update the flank job
    foreach( int flankJobId : int clusterJobId in mFlankToClusterMap )
    {
      WsfRIPRJob flankJob   = GetJobById( flankJobId );
      WsfRIPRJob clusterJob = GetJobById( clusterJobId );

      if( clusterJob.IsValid() )
      {
        if( flankJob.IsValid() )
        {
          writeln_d( "~~~ aiGCI - updating flank job ", flankJob.Name(), " with cluster ", clusterJob.Name(), "!!!" );

          WsfGeoPoint point = (WsfGeoPoint)clusterJob.GetData().Get("ZonePoint");
          double bearing = (double)clusterJob.GetData().Get("ZoneBearing");
          bool bearingValid = (bool)clusterJob.GetData().Get("ZoneBearingValid");
          //writeln_d( "~~~ aiGCI - flank job BEARING: ", bearing );

          string flankZoneName = "flank" + clusterJob.Name();
          UpdateFlankZone( TIME_NOW, flankZoneName, point, bearing, mFlankDistance );

          //update the flank job with relevant cluster information
          flankJob.SetPriority( (mFlankJobPriorityScale * clusterJob.GetPriority()) );
          flankJob.SetData( "ZonePoint", point );
          flankJob.SetData( "ZoneBearing", bearing );
          flankJob.SetData( "ZoneBearingValid", bearingValid );
          flankJob.SetData( "ZoneNumThreats", (int)clusterJob.GetData().Get("ZoneNumThreats") );
        }
        else
        {
          writeln_d( "~~~ aiGCI - cluster valid, but flank not valid!" );
        }
      }
      else
      {
        //remove flank job, cluster went away
        WsfRIPRJob tJob = GetJobById( flankJobId );
        
        //writeln_d( "~~~ aiGCI - removing a flank job because the cluster is gone!" );
        writeln_d("~~~ ", PLATFORM.Name(), " job change, REMOVE: ", tJob.Name() );
        
        mFlankToClusterMap.Remove( flankJobId );
        mClusterToFlankMap.Remove( clusterJobId );
        RemoveJob( tJob );
        //mFlankJobMap.Remove( flankJobId );

        if( mFlankJobsCreated > 0 )
        {
          mFlankJobsCreated = mFlankJobsCreated - 1;
        }
      }
    }

    //check if only the updates were needed, or if we can create more flank jobs
    if( mFlankJobsCreated >= mMaxTotalFlankJobsEverToCreate )
    {
      writeln_d( "~~~ aiGCI - max flank jobs created, no need for more!" );
      return;  
    }

    //create a new flank job if a cluster exists that never had one
    
    double DistClosestCluster = MATH.DOUBLE_MAX();
    WsfRIPRJob JobWithClusterToFlank;
    Array<WsfRIPRJob> jobs = GetJobs();
    foreach (WsfRIPRJob aJob in jobs)
    {
      //if job is a cluster job (not a flank job) & is not being flanked already
      //then consider it as a candidate for flanking, else continue
      if( mFlankToClusterMap.Exists( aJob.GetId() ) || mClusterToFlankMap.Exists( aJob.GetId() ) )
      {
        //writeln_d( "~~~ aiGCI - job ", aJob.Name(), " is either a flank job or a zone thats already being flanked!" );
        continue;
      }

      //if enough time hasn't elapsed since the last flank performed on this cluster, then continue
      string newFlankName = "flank" + aJob.Name();
      if( mFlankNameToTimeCompleteMap.Exists( newFlankName ) )
      {
        double lastFlankTime = mFlankNameToTimeCompleteMap.Get( newFlankName );
        if( TIME_NOW < (lastFlankTime + mFlankRepeatDelay) )
        {
          continue;
        }
      }

      WsfGeoPoint cPoint = (WsfGeoPoint)aJob.GetData().Get("ZonePoint");
      double dist = PLATFORM.GroundRangeTo(cPoint);
      if( dist < DistClosestCluster )
      {
        JobWithClusterToFlank = aJob;
      }
    }

    //if no flank job exists yet, and there is a cluster to flank, create job
    if( JobWithClusterToFlank.IsValid() )
    {
      WsfGeoPoint clusterPoint = (WsfGeoPoint)JobWithClusterToFlank.GetData().Get("ZonePoint");
      double clusterBearing = (double)JobWithClusterToFlank.GetData().Get("ZoneBearing");
      bool clusterBearingValid = (bool)JobWithClusterToFlank.GetData().Get("ZoneBearingValid");
      int clusterOccupants = (int)JobWithClusterToFlank.GetData().Get("ZoneNumThreats");
      string clusterZoneName = (string)JobWithClusterToFlank.GetData().Get("ZoneName");

      string flankZoneName = "flank" + JobWithClusterToFlank.Name();


      WsfRIPRJob NewFlankJob = WsfRIPRJob.Create( PROCESSOR,
                                                  "flank",
                                                  flankZoneName,
                                                  (mFlankJobPriorityScale * JobWithClusterToFlank.GetPriority()),
                                                  mMaxJobWinnersForFlank );
      NewFlankJob.SetData( "ZoneName", clusterZoneName );
      NewFlankJob.SetData( "ZonePoint", clusterPoint );
      NewFlankJob.SetData( "ZoneBearing", clusterBearing );
      NewFlankJob.SetData( "ZoneBearingValid", clusterBearingValid );
      NewFlankJob.SetData( "ZoneNumThreats", clusterOccupants );
      double FlankDistanceMeters = mFlankDistance * 1852.0; // 1852 meters per nm
      NewFlankJob.SetData( "FlankDistance", (0.9 * FlankDistanceMeters) );  //pursue a point 10% inside the flank zone
      NewFlankJob.SetData( "OnJobComplete", "aigci_flank_complete" );
      NewFlankJob.SetData( "for_air", 1 );
      AddJob(NewFlankJob);

      //writeln_d( "~~~ aiGCI - creating flank job, new name: ", flankZoneName );
      writeln_d("~~~ ", PLATFORM.Name(), " job change, ADD: ", NewFlankJob.Name() );
          
      //mFlankJobMap.Set( NewFlankJob.GetId(), NewFlankJob );

      mFlankJobsCreated = mFlankJobsCreated + 1;
      //save link between the flank & the cluster thats being flanked
      mFlankToClusterMap.Set( NewFlankJob.GetId(), JobWithClusterToFlank.GetId() );
      mClusterToFlankMap.Set( JobWithClusterToFlank.GetId(), NewFlankJob.GetId() );

      UpdateFlankZone( TIME_NOW, flankZoneName, clusterPoint, clusterBearing, mFlankDistance );
    }

  end_script


  script void aigci_draw_cluster_star(WsfCluster cluster)

     int trackCount = cluster.Count();
     WsfGeoPoint center = cluster.MeanLocation();

     //draw.SetId("cluster-lines");
     draw.SetLineStyle("solid");
     draw.BeginLines();
       draw.SetColor(1.0,1.0,0.0);
       for (int j = 0; j < trackCount; j = j + 1 )
       {
          WsfTrack t = cluster.Entry(j);
          draw.SetDuration(1.0);
          draw.Vertex(center);
          draw.Vertex(t.CurrentLocation());
       }
     draw.End();
     
  end_script


  script void aigci_draw_raw_tracks(WsfLocalTrackList aList)
     
     draw.SetColor(1.0,1.0,0.0);  //yellow
     draw.SetPointSize(5);
     draw.SetDuration(0.5);

     draw.BeginPoints();
     foreach (WsfLocalTrack t in aList)
     {
        for (int j = 0; j < t.RawTrackCount(); j = j + 1 )
        {
           WsfTrack raw = t.RawTrack(j);
           draw.Vertex(raw.ReportedLocation());
        }
     }
     draw.End();
     
  end_script
  


  script void aigci_update()
  
    //double duration = 0.0;         
    //double lStartTime = GetWallClockTime();
    


    if( GetRIPRCommanderProcessor().IsValid() )
    {
      //if the gci has a commander, then let its subordinates win jobs from the commander
      //the commander should create the same kinds of jobs that the gci would have created
      //these kinds include zone (cluster) jobs, or maybe even flank jobs
      SetJobPassThrough(true);
      writeln_d( "~~~ aigci is a job pass through now. time: ", TIME_NOW);
    }
    else
    {
      SetJobPassThrough(false);
      if( mZoneNames.Size() > 0 )
      {
        aigci_update_with_zones();

        writeln_d( "~~~ aigci_update w zones: ", PLATFORM.Name(), "- time: ", TIME_NOW);
      }
      else
      {
        WsfLocalTrackList localTracks;
        localTracks = FlightTrackList();
        aigci_update_with_clusters(localTracks);
        writeln_d( "~~~ aigci_update w clusters: ", PLATFORM.Name(), "- time: ", TIME_NOW);
      }
      
      if (mCreateFlankJobs == true)
      {
        aigci_update_flanks();
      }

      Array<WsfRIPRJob> jobs = GetJobs();
      foreach( WsfRIPRJob aJob in jobs )
      {
        if( ! mJobToWinnerMap.Exists( aJob.GetId() ) )
        {
          mJobToWinnerMap.Set( aJob.GetId(), 0 );        
        }
        else
        {
          int currWinners = aJob.GetNumWinners();
          int lastWinners = mJobToWinnerMap.Get( aJob.GetId() );
          if( currWinners != lastWinners )
          {
            string NewComment = "AIGCI - Sub took a job: " + aJob.Name() + " - " + aJob.GetDescription();
            PLATFORM.Comment(NewComment);
            mJobToWinnerMap.Set( aJob.GetId(), currWinners );        
          }
        }
      }
    }

    //duration = GetWallClockTime() - lStartTime;
    //writeln_d("~~~ on_update GCI Platform: ", PLATFORM.Name(), "- Process Time: ", duration);

  end_script


  script void aigci_initialize()

    //cManager = ClusterManager();  //gets the aigci owned cluster manager

    cManager = cManager.Construct();                     //creates a cluster manager owned by this script
    cManager.SetClusterMethod("H_TREE_MAX");             //default is: "K_MEANS"
    cManager.SetDistanceFunction("POSITION_VELOCITY");   //default is: "POSITION_ONLY"
  //cManager.SetDistanceLimit(46300);                    //default is: 100 meters, set to ~25 nautical miles
    cManager.SetDistanceLimit(92600);                    //default is: 100 meters, set to ~50 nautical miles

    //mFlankJobMap     = Map<int, WsfRIPRJob>();
    mJobToWinnerMap    = Map<int, int>();
    mFlankToClusterMap = Map<int, int>();
    mClusterToFlankMap = Map<int, int>();
    mCompletedFlanks = Array<string>();
    mFlankNameToTimeCompleteMap = Map<string, double>();


    mZoneJobMap = Map<string, WsfRIPRJob>();
    mZonePriority = Map<string, double>();
    mZoneNumThreats = Map<string, int>();
    mZonePoint = Map<string, WsfGeoPoint>();
    mZoneBearing = Map<string, double>();
    mZoneBearingValid = Map<string, bool>();

    mZoneTrackValue = Map<string, double>();

    Array<WsfZone> zonesList = PLATFORM.Zones();
    foreach (WsfZone x in zonesList )
    {
       mZoneNames.push_back(x.Name());
    }
    
    foreach( string x in mZoneNames )
    {
      writeln_d("~~~ GCI now monitoring retrived zone: ", x );
    }

    if( mZoneNames.Size() == 0 )
    {
      writeln_d( "~~~ No GCI zones defined, using Dynamic Clustering!" );
    }

  end_script
