home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1B / DATAFILE_PDCD1B.iso / _pocketbk / pocketbook / 004 / laptimer_z / LAPTIMER.OPL < prev    next >
Text File  |  1992-08-05  |  14KB  |  699 lines

  1. REM -----------------------------
  2. REM     Author          Jonathan Simpson
  3. REM     Date                    17 April 1992
  4. REM     Version                               1.00
  5. REM     Title                          Lap Timer
  6. REM     CIX User                  @jsimpsonb
  7. REM     Uses           Utils.opl,jsname.pic
  8. REM                                          car1.pic
  9. REM -----------------------------
  10.  
  11. PROC LapTimer:
  12.  
  13. REM Application 
  14. GLOBAL event%(6), filestr$(128)
  15. GLOBAL lpathn%(128), spathn%(7)
  16.  
  17. REM small font
  18. GLOBAL fsx%, fsy%
  19. GLOBAL fsxpo%, fsypo%
  20.  
  21. GLOBAL driver%(10) :REM sorted driver order
  22. GLOBAL lapcnt%(11)  :REM lap count
  23. GLOBAL split%(10)    :REM split times
  24. GLOBAL times%(10)    :REM combined lap/split
  25. GLOBAL vcl$(7,7)
  26. GLOBAL nullstr$(30), bitname$(10)
  27.  
  28. REM Procedures
  29. GLOBAL route$(30,8), k$(30)
  30.  
  31. REM Heats / Rounds / Names
  32. GLOBAL noheat%, minheat%, maxheat%
  33. GLOBAL nornd%, minrnd%, maxrnd%
  34. GLOBAL maxnlen%
  35. GLOBAL names$(150,12), maxname%,namect%
  36. GLOBAL ftdl%(150),ftds%(150)
  37. GLOBAL heatno%,rndno%
  38. GLOBAL hclst%(15)
  39.  
  40. REM windows
  41. GLOBAL carid%, gwindid%, maxw%
  42. GLOBAL workid%,resid%
  43.  
  44. GLOBAL carw%, carh%, lcrxpos%
  45.  
  46. REM race control
  47. GLOBAL cdown%
  48. GLOBAL maxlaps% ,secdur%
  49. GLOBAL maxsplt%, durn%
  50. GLOBAL fonth%,   fontw%
  51.  
  52. GLOBAL noprint
  53. GLOBAL incr, carxpos
  54.  
  55. LOCAL k%, ps%, md%
  56.   
  57. Header:
  58. Initial:
  59. SetTimes:
  60. k%=13
  61.  
  62. WHILE k%<>%x
  63.  k%=MainMnu%:
  64.  IF k%
  65.   ps%=LOC(k$,CHR$(k%))
  66.   IF ps% <> 0
  67.    @(route$(ps%)):
  68.   ENDIF 
  69.  ENDIF
  70. ENDWH
  71. CLS
  72. ENDP
  73.  
  74. PROC MainMnu%:
  75.   mINIt
  76.   mCARD "Main Menu","Start Race",%S,"Set All",%A,"Last Results",%L,"Overall",%O,"Terminate",%X
  77.   mCARD "Configure","No. of Heats",%H,"No. of Rounds",%R,"Edit Times",%T
  78.   mCARD "Names","Enter Names",%N,"Change Name",%C
  79.   RETURN MENU
  80. ENDP
  81.  
  82. PROC Header:
  83.  CLS
  84.  SCREEN 40,8,1,1
  85.  gAT 80,30
  86.  gxPRINT "Stop Watch Timer",2
  87. ENDP
  88.  
  89. PROC TestPr:
  90. LOCAL ret%,err%
  91.  noprint=0
  92.  TRAP LOPEN "PAR:A"
  93.  err%=ERR
  94.  IF err%
  95.   noprint=1
  96.  ENDIF
  97. ENDP
  98.  
  99.  
  100. PROC Initial:
  101. LOCAL hc%,dc%,t%
  102.  ESCAPE OFF
  103.  TestPr:
  104.  fsx%=3 : fsy%=5
  105.  fsxpo%=fsx%+1 : fsypo%=fsy%+1
  106.  resid%=gCREATE( 0, 0, gWIDTH,gHEIGHT,1)
  107.  workid%=gLOADBIT("smallfnt",0,0)
  108.  durn% = 5*60
  109.  maxsplt% = 25
  110.  cdown% = 5
  111.  maxlaps%=30
  112.  maxw%=240
  113.  nullstr$=REPT$("",maxlaps%)
  114.  noheat%=5
  115.  TrakInit:
  116.  minheat%=1
  117.  maxheat%=15
  118.  nornd%=4
  119.  minrnd%=1
  120.  maxrnd%=5
  121.  maxname%=150
  122.  maxnlen%=12
  123.  namect%=0
  124.  heatno%=0
  125.  rndno%=1
  126.  
  127.  k$="" 
  128.  k$=k$+"S" : route$(1)="RunRace"
  129.  k$=k$+"H" : route$(2)="SetHeats"
  130.  k$=k$+"R" : route$(3)="SetRnds"
  131.  k$=k$+"T" : route$(4)="SetTimes"
  132.  k$=k$+"N" : route$(5)="SetNames"
  133.  k$=k$+"A" : route$(6)="SetAll"
  134.  k$=k$+"C" : route$(7)="ChgName"
  135.  k$=k$+"L" : route$(8)="ShowRes"
  136.  k$=k$+"O" : route$(9)="SortOvr"
  137.  k$=k$+"X" : route$(10)="Exit"
  138.  
  139.  vcl$(1)="Pro 10"
  140.  vcl$(2)="Buggy"
  141.  vcl$(3)="Mini"
  142.  vcl$(4)="Monster"
  143.  vcl$(5)="IC"
  144.  vcl$(6)="4_WD"
  145.  vcl$(7)="2_WD"
  146.  
  147.  hc%=0
  148.  WHILE hc% < maxheat%
  149.   dc%=1
  150.   WHILE dc% <= 10
  151.    t%=(hc%*10)+dc%
  152.    names$(t%)="Dr_"+FIX$(dc%,0,2)+"  Ht_"+FIX$(hc%+1,0,2)
  153.    ftdl%(t%)=0 : ftds%(t%)=59
  154.    dc%=dc%+1
  155.   ENDWH
  156.   hc%=hc%+1
  157.  ENDWH
  158. ENDP
  159.  
  160. PROC SetHeats:
  161. LOCAL ht,hb%,lc%,lhis%,lc2%,lcmo%
  162.  dINIT "Number of Heats"
  163.  ht=noheat%
  164.  dFLOAT ht,"No. ",minheat%,maxheat%
  165.  IF DIALOG
  166.   noheat%=ht
  167.  ENDIF
  168.  REM select class of heats
  169.  hb%=(noheat%/5)+1
  170.  lc%=1
  171.  WHILE lc% <= hb%
  172.   lcmo%=lc%-1
  173.   IF 5*lc% > noheat%
  174.    lhis%=noheat%-(5*lcmo%)
  175.   ELSE
  176.    lhis%=5
  177.   ENDIF
  178.   dINIT "Select Class Heats "+FIX$((lcmo%*5)+1,0,2)+" to "+FIX$((lcmo%*5)+lhis%,0,2)
  179.   lc2%=1
  180.   WHILE lc2% <= lhis%
  181.    dCHOICE hclst%((lcmo%*5)+lc2%),"Heat "+FIX$(((lcmo%*5)+lc2%),0,2), "Pro 10,Buggy,Mini,Monster,IC,2_WD,4_WD"
  182.    lc2%=lc2%+1
  183.   ENDWH
  184.   DIALOG
  185.   lc%=lc%+1
  186.  ENDWH
  187. ENDP
  188.  
  189. PROC SetRnds:
  190. LOCAL nr
  191.  nr=nornd%
  192.  dINIT "Number of Rounds"
  193.  dFLOAT nr,"No. ",minrnd%,maxrnd%
  194.  IF DIALOG
  195.   nornd%=nr
  196.  ENDIF
  197. ENDP
  198.  
  199. PROC SetTimes:
  200. LOCAL fd,fs,fc
  201.  fd=FLT(durn%)/60.0
  202.  fs=maxsplt%
  203.  fc=cdown%
  204.  dINIT "Race Times"
  205.  dFLOAT fd,"Minute Duration",1,10
  206.  dFLOAT fs,"Second Split Time",1,59
  207.  dFLOAT fc,"Second Countdown",1,30
  208.  DIALOG
  209.  durn%=60*fd
  210.  maxsplt%=fs
  211.  incr=FLT(maxw%)/FLT(durn%)
  212.  cdown%=fc
  213. ENDP
  214.  
  215. PROC SetNames:
  216. LOCAL hc%,pc%,nip%
  217.  hc%=0
  218.  WHILE hc%<noheat%
  219.   pc%=0
  220.   WHILE pc%<2
  221.    nip%=1
  222.    dINIT "Heat Number "+FIX$(hc%+1,0,2)
  223.    WHILE nip%<6
  224.     dEDIT names$((hc%*10)+(pc%*5)+nip%),"Name ",maxnlen%
  225.     nip%=nip%+1
  226.    ENDWH
  227.    DIALOG
  228.    pc%=pc%+1
  229.   ENDWH
  230.   hc%=hc%+1
  231.  ENDWH
  232.  
  233. ENDP
  234.  
  235. PROC SetAll:
  236.  SetTimes:
  237.  SetHeats:
  238.  SetRnds:
  239.  SetNames: 
  240. ENDP
  241.  
  242. PROC ChgName:
  243. LOCAL ht,no,ht%,no%
  244.  dINIT "Change Driver Name"
  245.  dFLOAT ht,"Which Heat ",minheat%,maxheat%
  246.  dFLOAT no,"Car Number",1,10
  247.  IF DIALOG
  248.   ht%=ht : no%=no
  249.   dINIT "Edit Name for   Heat "+FIX$( ht%,0,2 ) + " Car " + FIX$( no%,0,2 )
  250.   dEDIT names$(((ht%-1)*10)+no%),"New Name",maxnlen%
  251.   DIALOG
  252.  ENDIF
  253. ENDP
  254.  
  255. PROC Exit:
  256.  
  257. ENDP
  258.  
  259.  
  260. PROC RaceInit:
  261. LOCAL lc1%
  262.  
  263.  lc1%=1
  264.  WHILE lc1%<11
  265.   driver%( lc1% ) = lc1%
  266.   lapcnt%( lc1% ) = 0
  267.   split%( lc1% ) = 0
  268.   times%( lc1% ) = 0
  269.   lc1%=lc1%+1
  270.  ENDWH
  271.  lcrxpos%=0
  272.  carxpos=0.0
  273. ENDP
  274.  
  275. PROC CntDown:(secdur%)
  276. LOCAL timect%
  277.  
  278.  gUSE 1
  279.  gFONT 1
  280.  gORDER 1,1
  281.  
  282.  timect%=secdur%
  283.  gCLS
  284.  gAT 0,0
  285.  gBORDER 0,240,70
  286.  AT 12,4
  287.  PRINT "Countdown [     ]"
  288.  DO
  289.   AT 24,4
  290.   PRINT timect%;" "
  291.   timect%=timect%-1
  292.   BEEP 2,300-(20*timect%)
  293.   PAUSE 20
  294.  UNTIL timect% < 1
  295.  BEEP 2,100
  296. ENDP
  297.  
  298. PROC RunRace:
  299. LOCAL ch,cr
  300.  heatno%=heatno%+1
  301.  IF heatno%>noheat%
  302.   heatno%=1
  303.   rndno%=rndno%+1
  304.  ENDIF
  305.  ch=heatno%
  306.  cr=rndno%
  307.  dINIT "Next Race"
  308.  dFLOAT ch,"Heat Number",minheat%,maxheat%
  309.  dFLOAT cr,"Round Number",minrnd%,maxrnd%
  310.  IF DIALOG
  311.   heatno%=ch
  312.   rndno%=cr
  313.   CntDown:( cdown% )
  314.   SecTime:
  315.   SortArr:
  316.   ShowRes:
  317.  ENDIF
  318. ENDP
  319.  
  320. PROC SecTime:
  321.  fonth%=10
  322.  fontw%=gTWIDTH("0")
  323.  
  324.  CLS
  325.  gAT 0,0
  326.  gBORDER 0,240,70
  327.  RaceHdr:
  328.  RaceInit:
  329.  DrawTrak:( gwindid%, carh%+2, maxw%)
  330.  TimeRace:(durn%)
  331.  SplTime:(maxsplt%)
  332.  GetTimes:(maxsplt%)
  333. ENDP
  334.  
  335. PROC RaceHdr:
  336. LOCAL ct%
  337.  
  338. ct%=1
  339. gUPDATE OFF
  340. gUSE 1
  341. gORDER 1,1
  342. gAT 1*fontw%,1*fonth%
  343. gPRINT "Time: M       S           Split:"
  344. gAT 25*fontw%,1*fonth%
  345. gPRINT "Heat "+FIX$( heatno%,0,2 )+"  Round "+FIX$( rndno%,0,2)
  346. gAT 11*fontw%,2*fonth%
  347. gXPRINT " D r i v e r   N a m e s ",5
  348.  
  349. gFONT 3
  350. DO
  351.  SmlTxtAt:(2+((ct%-1)*6*fsxpo%),3*fonth%,LEFT$(names$(((heatno%-1)*10)+ct%),5))
  352.  SmlTxtAt:(2+((ct%-1)*6*fsxpo%),(3*fonth%)+fsypo%,"No."+FIX$(ct%,0,2))
  353.  gAT 2+((ct%-1)*4*fontw%),5*fonth%
  354.  gPRINT "0" 
  355.  ct%=ct%+1
  356. UNTIL ct%>10
  357. gUPDATE ON
  358. ENDP  
  359.  
  360. PROC DrawTrak:(windid%, height%, width%)
  361. LOCAL lc1%
  362.  
  363.   lc1%=0
  364.   
  365.   gORDER windid%,1
  366.   gUSE windid%  
  367.   gAT 0,height%
  368.   gLINEBY width%, 0
  369.   WHILE lc1% < width%
  370.    gAT lc1%,height%-2
  371.    gLINEBY 0,2
  372.    lc1%=lc1%+10
  373.   ENDWH
  374.   gUSE 1
  375. ENDP
  376.  
  377.  
  378. PROC MoveCar:(windid%, carx%,carid%,carw%,carh%)
  379.    gUSE windid%
  380.    gAT carx%,1
  381.    gCOPY carid%,0,0,carw%,carh%,3
  382.    gUSE 1
  383. ENDP
  384.  
  385. PROC TrakInit:
  386.     maxw%=240
  387.     bitname$="car1"
  388.     carw%=20 : carh%=6
  389.     carid%=gLOADBIT( bitname$, 0 )
  390.   gwindid%=gCREATE( 0, 70, maxw%, carh%+3,1)
  391. ENDP
  392.  
  393. PROC TimeRace:(maxtime%)
  394.  
  395. LOCAL timect%, last%, start%, lc%, big%
  396. LOCAL sectik%, lockey%,txpos%,lhp%
  397.  
  398. sectik% = 0 : timect% = 0 : lhp%=0
  399. last%    = 0 : start%  = SECOND
  400. gTMODE 3
  401. DO
  402.  DO 
  403.   timect%=start%-SECOND
  404.   lockey%=GetKey%:
  405.   IF lockey%<>999
  406.    lapcnt%(lockey%)=lapcnt%(lockey%)+1
  407.    lc%=1
  408.    WHILE (lc% < lockey%) AND (lapcnt%(lockey%) > lapcnt%(lc%))
  409.     lc%=lc%+1
  410.    ENDWH
  411.    IF lc%=lockey%
  412.     lc%=lc%+1
  413.     WHILE (lc% < 11) AND (lapcnt%(lockey%) > lapcnt%(lc%))
  414.      lc%=lc%+1
  415.     ENDWH
  416.    ENDIF
  417.    IF lc% < 11
  418.     gAT ((lockey%-1)*4*fontw%)+2,5*fonth%
  419.     gXPRINT FIX$(lapcnt%(lockey%),0,2),5
  420.    ELSE
  421.     IF lhp% <> 0
  422.      gAT ((lhp%-1)*4*fontw%)+2,5*fonth%
  423.      gXPRINT FIX$(lapcnt%(lhp%),0,2),5
  424.     ENDIF
  425.     lhp%=lockey%
  426.     gAT ((lockey%-1)*4*fontw%)+2,5*fonth%
  427.     gXPRINT FIX$(lapcnt%(lockey%),0,2),2
  428.    ENDIF
  429.    BEEP 1,(lockey%*10)+70
  430.   ENDIF
  431.  UNTIL timect%<>last%
  432.  last% =timect%
  433.  sectik%=sectik%+1
  434.  carxpos=carxpos+incr
  435.  txpos%=INT(carxpos)
  436.  WHILE lcrxpos% < txpos%
  437.   MoveCar:( gwindid%, lcrxpos% , carid%, carw%,carh%)
  438.   lcrxpos%=lcrxpos%+