// 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); }
// 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); }
// 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); }
// 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)); }
// 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); }