Britbot
void Britbot.Group.CalcPriorities ( CancellationToken  cancellationToken) [inline]

Calculate target priorities for this group.

Parameters:
cancellationToken
Exceptions:
OperationCanceledExceptionThe token has had cancellation requested.

Definition at line 804 of file Group.cs.

        {
            Logger.BeginTime("CalcPriorities");
            //init some lists
            List<ITarget> priorityList = new List<ITarget>();
            List<Score> scores = new List<Score>();

            //Add all targets to the list

            //check if we need to chaise ships, if so add them to calculation
            if (Enemy.ShouldWeTryToCatchEnemyShips())
                priorityList.AddRange(Enemy.Groups);
            priorityList.AddRange(SmartIsland.IslandList);

            //Add a score for each target we got
            foreach (ITarget target in priorityList)
            {
                //Throwing an exception if cancellation was requested.
                cancellationToken.ThrowIfCancellationRequested();

                //calculate the score for this specific target
                Score newScore = target.GetScore(this);
                //check if score wasn't null, meaning if target was disqualified
                if (newScore != null)
                    scores.Add(newScore);
            }

            //set it to this instance of Group
            this.Priorities = scores;

            //check if priorities empty, if so add NoTarget To prevent dimension problem
            if (this.Priorities.Count == 0)
            {
                //create a NoTarget
                NoTarget noTarget = new NoTarget();
                this.Priorities.Add(noTarget.GetScore(this));
            }

            //limit outselfs to so and so targets
            //first sort by something (meanwhile distance)
            this.Priorities = this.Priorities.OrderBy(score => score.Eta).ToList();
            //throw away all but CalcMaxPrioritiesNum
            this.Priorities = this.Priorities.Take(Commander.CalcMaxPrioritiesNum()).ToList();

            Logger.StopTime("CalcPriorities");
        }