예제 #1
0
        // Finds a match on the given path element
        // (optional) if mustBeEnabled is false, also searches for disabled tasks
        public bool TaskFromPathElement(PathElement elem, out MatchResult result, bool mustBeEnabled = true)
        {
            ITaskAcceptor acceptor = elem.Object as ITaskAcceptor;

            result = (acceptor == null)
                                ? null
                                : TaskMatcher.GetPerformable(performer, acceptor, mustBeEnabled);
            return(result != null);
        }
예제 #2
0
        // Checks if the match exists on the given path element
        // Finding none, looks for any other matches
        public bool TaskFromMatch(PathElement elem, MatchResult match, out MatchResult result)
        {
            ITaskAcceptor acceptor = elem.Object as ITaskAcceptor;

            result = (match == null || acceptor == null)
                                ? null
                                : TaskMatcher.GetPerformable(match, performer, acceptor);
            return(result != null);
        }
예제 #3
0
        // Finds the nearest path element that pairs with the given task
        public bool NearestPathElementWithPair(PathElement origin, PerformerTask task, out PathElement destination)
        {
            GridPoint point = ConnectionToPoint(origin);

            destination = Pathfinder.FindNearestPoint(
                point,
                (GridPoint p) => { return(TaskMatcher.GetPair(task, p) != null); }
                );
            return(destination != null);
        }
예제 #4
0
        // Finds a pair for the given task
        public bool PairFromTask(PerformerTask task, PathElement currentElement, PathElement previousElement, out PathElement destination)
        {
            // Early out if task does not require a pair
            if (task.Settings.Pair == null)
            {
                destination = null;
                return(false);
            }

            bool gotoPrevious = !task.Settings.AlwaysPairNearest &&
                                previousElement != null &&
                                TaskMatcher.GetPair(task, previousElement) != null;

            if (gotoPrevious)
            {
                destination = previousElement;
                return(true);
            }

            return(NearestPathElementWithPair(currentElement, task, out destination));
        }
예제 #5
0
        // Finds the nearest path element with the given task
        public bool NearestPathElementWithTask(PathElement origin, PerformerTask task, out PathElement destination)
        {
            System.Type taskType = task.GetType();
            GridPoint   point    = ConnectionToPoint(origin);

            destination = Pathfinder.FindNearestPoint(
                point,
                (GridPoint p) => {
                if (TaskMatcher
                    .GetEnabled(performer, p.Object as ITaskAcceptor)
                    .Find(x => x.GetType() == taskType) != null)
                {
                    return(true);
                }

                foreach (Connection c in p.Connections)
                {
                    ITaskAcceptor acceptor = c.Object as ITaskAcceptor;
                    if (acceptor == null)
                    {
                        continue;
                    }

                    if (TaskMatcher
                        .GetEnabled(performer, acceptor)
                        .Find(x => x.GetType() == taskType) != null)
                    {
                        return(true);
                    }
                }

                return(false);
            }
                );
            return(destination != null);
        }