main
''
'' AUTHOR: Steve Bailey
'' CREATED: 7-25-90
'' DESCRIPTION:
''     main routine for SIMFOOD.  See preamble for description.
''

define FORM as a pointer variable
define I as an integer variable

'' assign global parameters to simulation
let STOP.TIME = 15 * 60
let N.KNAVE = 4
let N.ORDER.TAKER = 2
let N.WORKSTATION = .NUM.STATIONS
let BURGER.PRICE = 1.99
let SHAKE.PRICE = .99
let FRY.PRICE = .99

'' bring up the dialog to let the user decide prices, and number of workers
show FORM with "food.frm"
select case ACCEPT.F(FORM, 0)
  case "OK"
    let STOP.TIME = 60 * DDVAL.A(DFIELD.F("STOP TIME", FORM))
    let N.KNAVE = DDVAL.A(DFIELD.F("NUM KNAVES", FORM))
    let N.ORDER.TAKER = DDVAL.A(DFIELD.F("NUM ORDER TAKERS", FORM))
    let BURGER.PRICE = DDVAL.A(DFIELD.F("BURGER PRICE", FORM))
    let SHAKE.PRICE = DDVAL.A(DFIELD.F("SHAKE PRICE", FORM))
    let FRY.PRICE = DDVAL.A(DFIELD.F("FRY PRICE", FORM))
    let TIMESCALE = 100 / DDVAL.A(DFIELD.F("SPEED", FORM)) 
    let COMPRESS.TIME = DDVAL.A(DFIELD.F("COMPRESS TIME", FORM)) 
  default
endselect

'' initialize graphics
''call SET.ANIMATION.R(1)
let VXFORM.V = 1
let TIMESYNC.V = 'CLOCK'
call SETWORLD.R(0.0,20.0,-5.0,20.0)
create an ICON
display ICON with "floor.icn" at (10.0, 7.0)
display CLOCK.TIME with "fclock.grf"

'' init knave resources
create every KNAVE
for each KNAVE do
    let U.KNAVE(KNAVE) = 1
    create an ICON called KNAVE.ICON(KNAVE)
    show KNAVE.ICON(KNAVE) with "knave.icn"
loop

'' init order taker resources
create every ORDER.TAKER
for each ORDER.TAKER do
    let U.ORDER.TAKER(ORDER.TAKER) = 1
    create an ICON called ORDER.TAKER.ICON(ORDER.TAKER)
    show ORDER.TAKER.ICON(ORDER.TAKER) with "ot.icn"
loop

'' init workstation resources
open unit 1 for input, name is "worksta.dat"
use unit 1 for input
create every WORKSTATION
for each WORKSTATION do
    let U.WORKSTATION(WORKSTATION) = 1
    read XLOC(WORKSTATION), YLOC(WORKSTATION), SIDE.OF.BROILER(WORKSTATION)
    create an ICON
    display ICON with "worksta.icn" at (XLOC(WORKSTATION), YLOC(WORKSTATION))
loop
close unit 1

'' broil 4 burgers to start off with to fill up the steamer
for I = 1 to 4 do
    activate a BROIL.BURGER now
loop

'' start generating customers after weve had a chance to set up
activate a GENERATOR in .BROIL.TIME + 4 * (.CATCH.TIME + .SEND.TIME) .SECONDS
activate a STOP.SIM in STOP.TIME .SECONDS

start simulation

stop
end
