process CALL.ORDERS
''
'' AUTHOR: Steve Bailey
'' CREATED: 7-25-90
'' DESCRIPTION:
''    This process runs continuously looking for completed orders that
''    need to be given to customers.   
''

define CURRENT.ORDER as a pointer variable
define CHOICE as an integer variable
define STATION as an integer variable

'' get a workstation and order taker
let STATION = CHOICE.WORKSTATION(.PICKUP1, .PICKUP2, .PICKUP3)
request 1 WORKSTATION(STATION)
let CHOICE = CHOICE.ORDER.TAKER(STATION)
request 1 ORDER.TAKER(CHOICE)
let OCCUPIER(STATION) = CHOICE

if ORDER.RACK not empty

    '' remove the first order and see if there is enough food for it
    remove first CURRENT.ORDER from ORDER.RACK
    work .CHECK.ORDER.TIME .SECONDS
    if NUM.BURGERS(CURRENT.ORDER) le N.HEAT.RACK and
       NUM.SHAKES(CURRENT.ORDER) le N.SHAKE.COUNTER and
       NUM.FRIES(CURRENT.ORDER) le N.FRY.COUNTER

        '' get the burgers off the rack
        for I = 1 to NUM.BURGERS(CURRENT.ORDER) do
            remove first BURGER from HEAT.RACK
            destroy this BURGER   '' put in bag
        loop

        '' get the fries off the counter
        for I = 1 to NUM.FRIES(CURRENT.ORDER) do
            remove first FRY from FRY.COUNTER
            destroy this FRY   '' put in bag
        loop

        
        '' get the shakes off the counter
        for I = 1 to NUM.SHAKES(CURRENT.ORDER) do
            remove first SHAKE from SHAKE.COUNTER
            destroy this SHAKE   '' put in bag
        loop

        '' bag the order
        work .BAG.ORDER.TIME .SECONDS

        '' add up number of burgers and shakes sold
        add NUM.BURGERS(CURRENT.ORDER) to BURGERS.SOLD
        add NUM.SHAKES(CURRENT.ORDER) to SHAKES.SOLD
	add NUM.FRIES(CURRENT.ORDER) to FRIES.SOLD

        relinquish 1 WORKSTATION(STATION)

        '' move to the order giving station
        let STATION = .GIVE.ORDER
        request 1 WORKSTATION(STATION)
        erase CURRENT.ORDER
        let OCCUPIER(STATION) = CHOICE

        '' put bag onto counter
        file CURRENT.ORDER in BAG.COUNTER
        display CURRENT.ORDER with "bag.icn" at 
          (.BAG.COUNTERX+N.BAG.COUNTER*.4, .BAG.COUNTERY)
        work .GIVE.ORDER.TIME .SECONDS

        '' tell the customer that his food is ready
        reactivate this CUSTOMER called CUSTOMER.WAITING(CURRENT.ORDER) now
    else
        '' put back the order
        file CURRENT.ORDER first in ORDER.RACK
    always
always

relinquish 1 ORDER.TAKER(CHOICE)
relinquish 1 WORKSTATION(STATION)

return
end
