Example #1
0
        /// <summary>
        /// This has to be called when the robot aborts its task.
        /// </summary>
        /// <param name="r">The robot that aborted its task.</param>
        /// <param name="t">The task that the robot aborted.</param>
        public void TaskAborted(Bot r, BotTask t)
        {
            if (t == null)
            {
                throw new ArgumentException("No task to abort given!");
            }
            if (_taskQueues[r] == null)
            {
                throw new InvalidOperationException("No task to abort - referenced task was: " + t.ToString());
            }
            if (t.Type != BotTaskType.None && t != _taskQueues[r])
            {
                throw new ArgumentException("Wrong task to cancel - bot was executing another task!");
            }

            // Log warning
            Instance.LogDefault("WARNING! Task aborted: " + t.Type);

            // Cancel the task and remove it
            _taskQueues[r].Cancel();
            _taskQueues[r] = new DummyTask(Instance, r);

            // Change to dummy task
            r.AssignTask(_taskQueues[r]);
        }
Example #2
0
 /// <summary>
 /// Creates a new task allocation manager instance.
 /// </summary>
 /// <param name="instance">The instance the manager belongs to.</param>
 public BotManager(Instance instance)
 {
     // Init if not already done
     Instance      = instance;
     waypointGraph = instance.WaypointGraph;
     foreach (var bot in instance.Bots)
     {
         _taskQueues[bot] = new DummyTask(instance, bot);
     }
     foreach (var bot in instance.Bots)
     {
         _lastTaskEnqueued[bot] = null;
     }
     // Subscribe to order assignment updates (in order to add more work on-the-fly)
     instance.OrderAllocated  += OrderAllocated;
     instance.BundleAllocated += BundleAllocated;
     instance.PodPickup       += PodPickup;
 }
Example #3
0
        /// <summary>
        /// This has to be called when the robot finished its task.
        /// </summary>
        /// <param name="r">The robot that finished its task.</param>
        /// <param name="t">The task that the robot finished.</param>
        public void TaskComplete(Bot r, BotTask t)
        {
            if (t == null)
            {
                return;
            }
            if (t.Type != BotTaskType.None && t != _taskQueues[r])
            {
                throw new ArgumentException("Wrong task to complete - bot was executing another task!");
            }

            // Remove the finished task and free the resources
            _taskQueues[r].Finish();
            _taskQueues[r] = new DummyTask(Instance, r);

            // Change to dummy task
            r.AssignTask(_taskQueues[r]);
        }