Beispiel #1
0
 public static AcceptorTask GetPair(PerformerTask task, DNA.Paths.PathElement acceptor, bool mustBeEnabled = true)
 {
     try {
         return(GetPair(task, ((ITaskAcceptor)acceptor.Object), mustBeEnabled));
     } catch {
         throw new System.Exception(acceptor.Object + " does not implement the ITaskAcceptor interface");
     }
 }
Beispiel #2
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);
        }
Beispiel #3
0
        public int GetPerformCount(PerformerTask p)
        {
            IInventoryHolder h = p.Performer as IInventoryHolder;

            if (h == null)
            {
                return(0);
            }

            return(PerformCount(h.Inventory));
        }
Beispiel #4
0
 public static AcceptorTask GetAcceptor(PerformerTask task, ITaskAcceptor acceptor)
 {
     // TODO: linq
     foreach (var acceptorTask in acceptor.AcceptableTasks.EnabledTasks)
     {
         AcceptorTask a = acceptorTask.Value;
         if (task.GetType() == a.AcceptedTask)
         {
             return(a);
         }
     }
     return(null);
 }
Beispiel #5
0
        public static void Set(PerformerTask newTask)
        {
            if (!newTask.Enabled)
            {
                return;
            }

            task     = newTask;
            roadTask = task is ConstructRoad;
            bool seedTask = task is PlantSeed;

            System.Type[] taskTypes;
            if (roadTask)
            {
                taskTypes = new [] { typeof(Road) };
            }
            else if (seedTask)
            {
                taskTypes = new [] { typeof(Seed) };
            }
            else
            {
                taskTypes = task.GetType().GetGenericArguments();
            }

            if (taskTypes.Length > 0)
            {
                string renderer = UnitRenderer.GetRenderer(DataManager.GetUnitSymbol(taskTypes[0]));
                visual = ObjectPool.Instantiate(renderer) as UnitRenderer;
                visual.SetAlpha(0.33f);
                GameCursor.Instance.SetVisual(task, visual);
            }

            GameCursor.Instance.onClick += OnClick;

            if (roadTask)
            {
                Events.instance.AddListener <ClickConnectionEvent> (OnClickConnectionEvent);
                Events.instance.AddListener <MouseEnterConnectionEvent> (OnMouseEnterConnectionEvent);
                Events.instance.AddListener <MouseExitConnectionEvent> (OnMouseExitConnectionEvent);
            }
            else
            {
                Events.instance.AddListener <ClickPointEvent> (OnClickPointEvent);
                Events.instance.AddListener <MouseEnterPointEvent> (OnMouseEnterPointEvent);
                Events.instance.AddListener <MouseExitPointEvent> (OnMouseExitPointEvent);
            }
        }
Beispiel #6
0
        public static AcceptorTask GetPair(PerformerTask task, ITaskAcceptor acceptor, bool mustBeEnabled = true)
        {
            // TODO: linq
            Dictionary <System.Type, AcceptorTask> tasks = mustBeEnabled
                                ? acceptor.AcceptableTasks.EnabledTasks
                                : acceptor.AcceptableTasks.ActiveTasks;

            foreach (var acceptorTask in tasks)
            {
                AcceptorTask a = acceptorTask.Value;
                if (a.GetType() == task.Settings.Pair)
                {
                    return(a);
                }
            }
            return(null);
        }
Beispiel #7
0
            public void Add(PerformerTask task, int bindLimit)
            {
                // Ignore if no BindLimit has been set
                if (bindLimit == 0)
                {
                    task.OnBind();
                    return;
                }

                if (active.Count < bindLimit)
                {
                    Bind(task);
                }
                else
                {
                    queued.Enqueue(task);
                    task.OnQueue();
                }
            }
Beispiel #8
0
            public void Remove(PerformerTask task, int bindLimit)
            {
                // Ignore if no BindLimit has been set
                if (bindLimit == 0)
                {
                    return;
                }

                try {
                    active.Remove(task);
                } catch {
                    throw new System.Exception("The PerformerTask '" + task + "' has not been bound to the AcceptorTask '" + task + "'");
                }

                if (queued.Count > 0)
                {
                    PerformerTask newTask = queued.Dequeue();
                    Add(newTask, bindLimit);
                }
            }
Beispiel #9
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));
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public static void Remove()
        {
            if (task != null)
            {
                task = null;

                GameCursor.Instance.Target   = null;
                GameCursor.Instance.onClick -= OnClick;
                GameCursor.Instance.RemoveVisual();

                Events.instance.RemoveListener <ClickConnectionEvent> (OnClickConnectionEvent);
                Events.instance.RemoveListener <MouseEnterConnectionEvent> (OnMouseEnterConnectionEvent);
                Events.instance.RemoveListener <MouseExitConnectionEvent> (OnMouseExitConnectionEvent);

                Events.instance.RemoveListener <ClickPointEvent> (OnClickPointEvent);
                Events.instance.RemoveListener <MouseEnterPointEvent> (OnMouseEnterPointEvent);
                Events.instance.RemoveListener <MouseExitPointEvent> (OnMouseExitPointEvent);
            }

            if (onRemove != null)
            {
                onRemove();
            }
        }
Beispiel #12
0
 public MatchResult(PerformerTask match, bool needsPair, AcceptorTask acceptor)
 {
     Match     = match;
     NeedsPair = needsPair;
     Acceptor  = acceptor;
 }
Beispiel #13
0
 void Bind(PerformerTask task)
 {
     active.Add(task);
     task.OnBind();
 }