예제 #1
0
 /// <summary>
 /// Requests the station to pick the given item for the given order.
 /// </summary>
 /// <param name="bot">The bot that requests the pick.</param>
 /// <param name="request">The request to handle.</param>
 public void RequestItemTake(Bot bot, ExtractRequest request)
 {
     if (bot.Pod != null && _assignedOrders.Contains(request.Order))
     {
         // Add the request to the list of requests to handle
         _requestsBot.Enqueue(bot);
         _requestsExtract.Enqueue(request);
     }
     else
     {
         // Something went wrong, refuse to handle the request
         request.Abort();
         bot.WaitUntil(Instance.Controller.CurrentTime + Instance.RefusedRequestPenaltyTime);
     }
 }
예제 #2
0
        /// <summary>
        /// Picks the next enqueued item.
        /// </summary>
        /// <param name="currentTime">The current simulation time.</param>
        /// <returns><code>true</code> if there was an item to pick and the operation was successful, <code>false</code> otherwise.</returns>
        protected bool TakeItemFromPod(double currentTime)
        {
            // Keep going through queue until have something to take or done with queue
            while (_requestsExtract.Count > 0)
            {
                // Fetch necessary stuff
                Bot             bot     = _requestsBot.Dequeue();
                Pod             pod     = bot.Pod;
                ExtractRequest  request = _requestsExtract.Dequeue();
                ItemDescription item    = request.Item;

                if (pod.IsContained(item) && GetDistance(pod) < GetInfoRadius())
                {
                    // If order is null, then just choose the first one that fits
                    if (request.Order == null)
                    {
                        foreach (var order in _assignedOrders)
                        {
                            if (order.Serve(item))
                            {
                                // Physically remove the item
                                pod.Remove(item, request);
                                // Block the station for the transfer
                                BlockedUntil = currentTime + ItemTransferTime;
                                // Make the bot wait until completion
                                bot.WaitUntil(currentTime + ItemPickTime);
                                // Count the number of picked items
                                StatNumItemsPicked++;
                                // Keep track of injected item picks
                                if (request.StatInjected)
                                {
                                    StatNumInjectedItemsPicked++;
                                }
                                // Keep track of current number of items to pick
                                StatCurrentlyOpenItems--;
                                // Count pods served if this is a beginning transaction
                                if (_newPodTransaction)
                                {
                                    _newPodTransaction = false;
                                }
                                // Notify instance about the pick
                                Instance.NotifyItemHandled(pod, bot, this, request.Item);
                                Instance.NotifyPodHandled(pod, null, this);
                                // Notify the instance, if the line was completed by the pick
                                if (order.PositionServedCount(item) >= order.PositionOverallCount(item))
                                {
                                    Instance.NotifyLineHandled(this, item, order.PositionOverallCount(item));
                                }
                                // Keep track of the time at which the transaction will be finished
                                _statLastTimeTransactionFinished = currentTime + ItemTransferTime;
                                // Return success
                                return(true);
                            }
                        }
                        // Mark request aborted
                        request.Abort();
                    }
                    else
                    {
                        // Order is specified
                        // If it's at this station and the item can be added, then add it
                        if (_assignedOrders.Contains(request.Order) && request.Order.Serve(item))
                        {
                            // Physically remove the item
                            pod.Remove(item, request);
                            // Block the station for the transfer
                            BlockedUntil = currentTime + ItemTransferTime;
                            // Make the bot wait until completion
                            bot.WaitUntil(currentTime + ItemPickTime);
                            // Count the number of picked items
                            StatNumItemsPicked++;
                            // Keep track of injected item picks
                            if (request.StatInjected)
                            {
                                StatNumInjectedItemsPicked++;
                            }
                            // Keep track of current number of items to pick
                            StatCurrentlyOpenItems--;
                            // Count pods served if this is a beginning transaction
                            if (_newPodTransaction)
                            {
                                _newPodTransaction = false;
                            }
                            // Notify instance about the pick
                            Instance.NotifyItemHandled(pod, bot, this, request.Item);
                            Instance.NotifyPodHandled(pod, null, this);
                            // Notify the instance, if the line was completed by the pick
                            if (request.Order.PositionServedCount(item) >= request.Order.PositionOverallCount(item))
                            {
                                Instance.NotifyLineHandled(this, item, request.Order.PositionOverallCount(item));
                            }
                            // Keep track of the time at which the transaction will be finished
                            _statLastTimeTransactionFinished = currentTime + ItemTransferTime;
                            // Return success
                            return(true);
                        }
                        else
                        {
                            // Mark the request aborted
                            request.Abort();
                        }
                    }
                }
            }
            // Nothing to pick - return unsuccessfully
            return(false);
        }