process MAKE.FRY
''
'' AUTHOR: Steve Bailey
'' CREATED: 7-25-90
'' DESCRIPTION:
''     This process makes a french fry.  If the number of potential french fry
''     baskets left in the fry catcher is less than 4, then a fry basket is
''     put down.  If a fry basket is down and there are no fries left, 
''     another is put down.
''

define CHOICE as an integer variable
define NEW.FRY as a pointer variable
define FRY.BASKET1, FRY.BASKET2, FRY.VAT as pointer saved variables
define BASKET1.DOWN,BASKET2.DOWN,FRIES.LEFT as integer saved variables
define FRIES.DROPPED as a pointer variable

'' if first time here, create icons
if FRY.BASKET1 eq 0
    create an ICON called FRY.BASKET1
    show FRY.BASKET1 with "frybask.icn"
    create an ICON called FRY.BASKET2
    show FRY.BASKET2 with "frybask.icn"
    create an ICON called FRY.VAT
    show FRY.VAT with "fryvat.icn"
always

'' move a knave to this station
request 1 WORKSTATION(.FRY)
let CHOICE = CHOICE.KNAVE(.FRY)
request 1 KNAVE(CHOICE)
let OCCUPIER(.FRY) = CHOICE

'CHECK.FRIES'

if FRIES.LEFT gt 0 and NEW.FRY eq 0
    subtract 1 from FRIES.LEFT
    if FRIES.LEFT eq 0
        erase FRY.VAT
    always

    '' make the fry
    work .FRY.TIME .SECONDS
    create a FRY called NEW.FRY
    file NEW.FRY in FRY.COUNTER
    display NEW.FRY with "fry.icn" at 
      (.FRY.COUNTERX+N.FRY.COUNTER*.30, .FRY.COUNTERY)

    '' drop another basket if needed
    if FRIES.LEFT lt 4 and BASKET1.DOWN eq 0
        go 'DROP.FRIES'
    always
    go 'DONE'
always

'DROP.FRIES'

'' drop first basket if not down
if BASKET1.DOWN eq 0 
    let BASKET1.DOWN = 1
    let FRIES.DROPPED = FRY.BASKET1
    work .FRY.DROP.TIME .SECONDS
    display FRY.BASKET1 at (.FRY.BASKET1X, .FRY.BASKET1Y)
else
    '' if basket 2 isn't down and there are a lot of orders drop another
    if BASKET2.DOWN eq 0 and N.ORDER.RACK gt 2
        let BASKET2.DOWN = 1
        let FRIES.DROPPED = FRY.BASKET2
        work .FRY.DROP.TIME .SECONDS
        display FRY.BASKET2 at (.FRY.BASKET2X, .FRY.BASKET2Y)
    always
always

'' let the knave and workstation go
relinquish 1 KNAVE(CHOICE)
relinquish 1 WORKSTATION(.FRY)

'' wait until fries are done cooking
if FRIES.DROPPED ne 0
    work .FRY.COOK.TIME .SECONDS
else
    wait 20 .SECONDS
always

'' move a knave to this station
request 1 WORKSTATION(.FRY)
let CHOICE = CHOICE.KNAVE(.FRY)
request 1 KNAVE(CHOICE)
let OCCUPIER(.FRY) = CHOICE

'' dump the cooked fries into the fry vat
if FRIES.DROPPED ne 0
    work .FRY.DUMP.TIME .SECONDS
    erase FRIES.DROPPED
    if FRIES.DROPPED eq FRY.BASKET1
        let BASKET1.DOWN = 0
    else
        let BASKET2.DOWN = 0
    always
    display FRY.VAT at (.FRYVATX, .FRYVATY)
    add 10 to FRIES.LEFT
always

if NEW.FRY eq 0
    go 'CHECK.FRIES'
always

'DONE'

relinquish 1 KNAVE(CHOICE)
relinquish 1 WORKSTATION(.FRY)
 
activate a CALL.ORDERS now

return 
end
