Beispiel #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]);
        }
Beispiel #2
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]);
        }
Beispiel #3
0
        /// <summary>
        /// Allocates a rest task.
        /// </summary>
        /// <param name="bot">The bot that shall rest.</param>
        /// <param name="restLocationOrder">The order in which the next free resting location is chosen (if the bot already rested before, the same location is used).</param>
        protected void DoRestTask(Bot bot, PrefRestLocationForBot restLocationOrder)
        {
            // Get the last task that was assigned to the bot
            BotTask lastTask = GetLastEnqueuedTask(bot);
            // Choose resting location
            Waypoint restLocation;

            // Check whether the last task was resting too
            if (lastTask != null && lastTask.Type == BotTaskType.Rest && Instance.ResourceManager.IsRestingLocationAvailable((lastTask as RestTask).RestingLocation))
            {
                restLocation = (lastTask as RestTask).RestingLocation;
            }
            else
            {
                restLocation = ChooseRestLocation(bot, restLocationOrder);
            }
            // Submit the task
            EnqueueRest(bot, restLocation);
        }