home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 16 / pascal / rally.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-05-13  |  60.9 KB  |  1,941 lines

  1. PROGRAM Rally(Input,Output,Rally_File);
  2.  
  3. {  A program to keep track of fun car rallys.  First create a file, then load
  4. it.  You may then edit the data, adding team names and info into the array.
  5. The array is saved using the Save file feature.  To score the results you
  6. MUST enter the Set scoring menu and access all entries.  Only the Points/}
  7. {question item must have a number entered however.  This way, rallys that do
  8. not count off for mileage, time, etc, can use the system.  When all Set Scoring
  9. item have been entered, Compute Scores will become active.  After compute
  10. scores is executed, Show Places will be activated (shows up next to the score
  11. in the edit dialog box.) and the Winners feature will be active.  }
  12. {  The program will always show a place, if Show Places is turned on.  If no
  13. score has been computed for a team, the place is the same as the team number.
  14. Winners will only show those teams that have a name other than Not Used ....
  15. Ties are not shown as such, but revert to the order of team number for the
  16. order of finish (Check the score shown to be sure you don't have a tie.}
  17. {  Groupings allows a group of cars to compete against another group of cars.
  18. The average score of all the cars in a grouping is used in determining the
  19. group finish order.  There is a max of 8 groupings allowed.  Only the first
  20. three and last place are shown.}
  21.  
  22. { Address any comments to:
  23.      David Chiquelin
  24.      501 Woodbine Circle
  25.      Papillion, NE  68128
  26.  
  27.      CIS  71336,1443
  28.      Delphi DCHIQUELIN
  29.      ANALOG TCS 1099
  30.      GENIE D.CHIQUELIN
  31.           or
  32.      Atari-O! BBS (402) 592-4435  300/1200 baud
  33.      (Sysop)  }
  34.  
  35. {P.S.  There is a bug that causes the mouse control to not work properly for
  36. several 'clicks' after exiting the program.  If you can fix this, let me know!
  37. I have also figured out a way with to reduce the size of the program, which I
  38. intend to use on my next project, a golf handicap program.  But this one works,
  39. so I didn't go back to modify it...}
  40.  
  41.  
  42. CONST
  43.   {$I GEMCONST.PAS}
  44.   max_participants = 60;
  45.  
  46. TYPE
  47.   {$I gemtype.pas}
  48.  
  49.   rally_record = RECORD
  50.       team_name           : STRING[25]; {Below comments are for the first rec}
  51.       driver              : STRING[25]; {only! ... it is called Official}
  52.       nav                 : STRING[25];
  53.       obs1                : STRING[25]; {Points lost for being late to start}
  54.       obs2                : STRING[25]; {Points lost for help calls}
  55.       time_position       : STRING[25]; {Points lost for car inspec violations}
  56.       division            : STRING[25];
  57.       correct             : INTEGER;    {Points/question answered correctly}
  58.       calls               : INTEGER;    {Miles for first rate of points/mile}
  59.       late_to_position    : INTEGER;    {points/mile at first rate}
  60.       violation           : INTEGER;    {points/mile after first rate ends}
  61.       start_time          : STRING[25];
  62.       end_time            : STRING[25]; {Official time for course}
  63.       total_time          : STRING[25];
  64.       total_secs          : INTEGER;    {Official time in secs}
  65.       start_miles         : REAL;       {Official mileage for course}
  66.       end_miles           : REAL;       {Seconds at first points/sec rate}
  67.       total_miles         : REAL;       {points/sec at first rate}
  68.       total_score         : INTEGER     {points/sec after first rate}
  69.   END;  {file_record description}
  70.  
  71.   place_record = RECORD
  72.       score        : INTEGER;
  73.       team_number  : INTEGER;
  74.       used         : BOOLEAN
  75.   END;
  76.  
  77.   place_array = ARRAY[1 .. max_participants] OF place_record;
  78.  
  79.   division_type = RECORD
  80.       name    : STRING[4];
  81.       total   : LONG_INTEGER;
  82.       number  : INTEGER;
  83.       average : INTEGER
  84.   END;
  85.  
  86. VAR
  87.   menu,
  88.   which_menu,
  89.   menu2,
  90.   menu3  : Menu_Ptr;
  91.  
  92.   dummy,
  93.   file_title,
  94.   score_title,
  95.   quit_title,
  96.   set_scoring_title,
  97.   data1_title,
  98.   data2_title,
  99.   data3_title,
  100.   data4_title,
  101.   exit_title,
  102.   create_item,
  103.   old_item,
  104.   enter_results_item,
  105.   save_data_item,
  106.   show_place_item,
  107.   winner_item,
  108.   official_miles_item,
  109.   official_time_item,
  110.   points_per_question_item,
  111.   points_sub_miles_item,
  112.   points_lost_time_item,
  113.   points_late_item,
  114.   points_calls_item,
  115.   points_violat_item,
  116.   quit_item,
  117.   comp_scores_item,
  118.   exit_item,
  119.   ok_btn,
  120.   cancel_btn,
  121.   button,
  122.   name_item,
  123.   driver_item,
  124.   nav_item,
  125.   obs1_item,
  126.   obs2_item,
  127.   pos_time_item,
  128.   division_item,
  129.   correct_item,
  130.   calls_item,
  131.   late_item,
  132.   violate_item,
  133.   st_time_item,
  134.   overall_title,
  135.   first_o_item,
  136.   second_o_item,
  137.   third_o_item,
  138.   last_o_item,
  139.   time_title,
  140.   first_t_item,
  141.   second_t_item,
  142.   third_t_item,
  143.   last_t_item,
  144.   miles_title,
  145.   first_m_item,
  146.   second_m_item,
  147.   third_m_item,
  148.   last_m_item,
  149.   exit2_title,
  150.   exit2_item,
  151.   div_title,
  152.   div1_item,
  153.   div2_item,
  154.   div3_item,
  155.   div4_item  : INTEGER;
  156.  
  157.   data1_item : ARRAY[1..15] OF INTEGER;
  158.   data2_item : ARRAY[1..15] OF INTEGER;
  159.   data3_item : ARRAY[1..15] OF INTEGER;
  160.   data4_item : ARRAY[1..15] OF INTEGER;
  161.  
  162.   edit : ARRAY[20..88] OF INTEGER;
  163.  
  164.   quit,
  165.   win_enable,
  166.   place_show,
  167.   group_enable  : BOOLEAN;
  168.  
  169.   alert : Str255;
  170.  
  171.   path : Path_Name;
  172.   dialog : Dialog_Ptr;
  173.  
  174.   rally_file : FILE OF rally_record;
  175.   printer_file : FILE OF char;
  176.  
  177.   rally_data    : ARRAY[1..60] OF rally_record;
  178.   score_places  : place_array;
  179.   time_places   : place_array;
  180.   miles_places : place_array;
  181.  
  182.   score_ability : ARRAY[1..8] OF BOOLEAN;
  183.  
  184.   temp_data : rally_record;
  185.   official  : rally_record; { Used to hold 'official' data }
  186.  
  187.   division_array : ARRAY[1..9] OF division_type;
  188.  
  189. {$I gemsubs}
  190.  
  191. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  192.  
  193. Procedure Menu_Set2;
  194.  
  195. BEGIN
  196.   menu3 := New_Menu( 24, '  Road Rally ' );
  197.   overall_title := Add_MTitle( menu3, ' Overall ' );
  198.   time_title := Add_MTitle( menu3, ' Time ' );
  199.   miles_title := Add_MTitle( menu3, ' Mileage ' );
  200.   div_title := Add_MTitle( menu3, ' Groupings ' );
  201.   exit2_title:=Add_MTitle( menu3, ' Exit ');
  202.  
  203.   first_o_item  := Add_MItem( menu3,overall_title, ' First Place ...  ' );
  204.   second_o_item := Add_MItem( menu3,overall_title, ' Second Place ... ' );
  205.   third_o_item  := Add_MItem( menu3,overall_title, ' Third Place ...  ' );
  206.   last_o_item   := Add_MItem( menu3,overall_title, ' Last Place ...   ' );
  207.   first_t_item  := Add_MItem( menu3, time_title, ' First Place ...  ' );
  208.   second_t_item := Add_MItem( menu3, time_title, ' Second Place ... ' );
  209.   third_t_item  := Add_MItem( menu3, time_title, ' Third Place ...  ' );
  210.   last_t_item   := Add_MItem( menu3, time_title, ' Last Place ...   ' );
  211.   first_m_item  := Add_MItem( menu3,miles_title, ' First Place ...  ' );
  212.   second_m_item := Add_MItem( menu3,miles_title, ' Second Place ... ' );
  213.   third_m_item  := Add_MItem( menu3,miles_title, ' Third Place ...  ' );
  214.   last_m_item   := Add_MItem( menu3,miles_title, ' Last Place ...   ' );
  215.   div1_item  := Add_MItem( menu3,div_title, ' First Place ...  ' );
  216.   div2_item  := Add_MItem( menu3,div_title, ' Second Place ... ' );
  217.   div3_item  := Add_MItem( menu3,div_title, ' Third Place ...  ' );
  218.   div4_item  := Add_MItem( menu3,div_title, ' Last Place ...   ' );
  219.   exit2_item := Add_MItem( menu3, exit2_title,   ' Exit to main menu ... ')
  220. END;
  221.  
  222. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  223.  
  224. Procedure Menu_Setup;
  225.  
  226. VAR
  227.   count : INTEGER;
  228.  
  229. BEGIN
  230.   menu := New_Menu( 40, '  Road Rally ' );
  231.   file_title := Add_MTitle( menu, ' File ' );
  232.   score_title := Add_MTitle( menu, ' Score ' );
  233.   quit_title:= Add_MTitle(menu,' Quit ');
  234.   set_scoring_title:=Add_MTitle(menu,' Set Scoring ');
  235.   create_item  := Add_MItem( menu, file_title, ' Create File ...    ' );
  236.   old_item := Add_MItem (menu, file_title, ' Load Data File ... ' );
  237.   enter_results_item := Add_MItem( menu, file_title, ' Edit Data  ...     ');
  238.   save_data_item := Add_MItem( menu, file_title,' Save Data File ... ');
  239.   show_place_item   := Add_MItem( menu, score_title, '  Show Places? ...   ' );
  240.   winner_item   := Add_MItem( menu, score_title, '  Winners ...        ' );
  241.   comp_scores_item := Add_MItem( menu, score_title, '  Compute Scores ... ' );
  242.   quit_item:=Add_Mitem(menu,quit_title, ' Quit ');
  243.   official_miles_item:=Add_MItem( menu, set_scoring_title,
  244.      '  Official Mileage ...     ');
  245.   official_time_item:=Add_MItem( menu, set_scoring_title,
  246.      '  Official Time ...        ');
  247.   points_per_question_item:=Add_MItem( menu, set_scoring_title,
  248.      '  Points/Question ...      ');
  249.   points_sub_miles_item:=Add_MItem( menu, set_scoring_title,
  250.      '  Points/Mile Lost ...     ');
  251.   points_lost_time_item:=Add_MItem( menu, set_scoring_title,
  252.      '  Points/Second Lost ...   ');
  253.   points_late_item:=Add_MItem( menu, set_scoring_title,
  254.      '  Points/Minute Late ...   ');
  255.   points_calls_item:=Add_MItem( menu, set_scoring_title,
  256.      '  Points/Call Lost ...     ');
  257.   points_violat_item:=Add_MItem( menu, set_scoring_title,
  258.      '  Points/Car Violation ... ');
  259.   menu2 := New_Menu( 70, '  Road Rally ' );
  260.   data1_title:= Add_MTitle( menu2,' Data 1 ');
  261.   data2_title:=Add_MTitle( menu2, ' Data 2 ');
  262.   data3_title:=Add_MTitle( menu2, ' Data 3 ');
  263.   data4_title:=Add_MTitle( menu2, ' Data 4 ');
  264.   exit_title:=Add_MTitle( menu2, ' Exit ');
  265.   FOR count:=1 TO 15 DO
  266.   BEGIN
  267.     data1_item[count]:=Add_MItem( menu2, data1_title,
  268.       '  .........................');
  269.     edit[data1_item[count]]:=count
  270.   END;
  271.   FOR count:=1 TO 15 DO
  272.   BEGIN
  273.     data2_item[count]:=Add_MItem( menu2, data2_title,
  274.       '  .........................');
  275.     edit[data2_item[count]]:=count+15
  276.   END;
  277.   FOR count:=1 TO 15 DO
  278.   BEGIN
  279.     data3_item[count]:=Add_MItem( menu2, data3_title,
  280.     '  .........................');
  281.     edit[data3_item[count]]:=count+30
  282.   END;
  283.   FOR count:=1 TO 15 DO
  284.   BEGIN
  285.     data4_item[count]:=Add_MItem( menu2, data4_title,
  286.     '  .........................');
  287.     edit[data4_item[count]]:=count+45
  288.   END;
  289.   exit_item:=Add_MItem( menu2, exit_title, ' Exit to main menu ');
  290.   Menu_Set2
  291. END;
  292.  
  293. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  294.  
  295. Procedure Make_Integer(str : STR25 ; VAR intgr : INTEGER);
  296.  
  297. VAR
  298.   X    : INTEGER;
  299.   A    : CHAR;
  300.   num  : INTEGER;
  301.   size : INTEGER;
  302.  
  303. BEGIN
  304.   intgr := 0;
  305.   size:=Length(str);
  306.   FOR X:=size DOWNTO 1 DO
  307.   BEGIN
  308.     A:=str[size+1-X];
  309.     CASE A OF
  310.       '0' : num:=0;
  311.       '1' : num:=1;
  312.       '2' : num:=2;
  313.       '3' : num:=3;
  314.       '4' : num:=4;
  315.       '5' : num:=5;
  316.       '6' : num:=6;
  317.       '7' : num:=7;
  318.       '8' : num:=8;
  319.       '9' : num:=9
  320.     END;
  321.   intgr:=intgr+TRUNC((num*PwrOfTen(X-1)))
  322.   END  { FOR loop }
  323. END;
  324.  
  325. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  326.  
  327. Procedure Check_Data;
  328.  
  329. VAR
  330.   count,
  331.   num_correct,
  332.   X : INTEGER;
  333.   test : BOOLEAN;
  334.  
  335. BEGIN
  336.   count:=0;
  337.   num_correct:=0;
  338.   For X:=1 TO max_participants DO
  339.     WITH rally_data[X] DO
  340.     BEGIN
  341.       test:=FALSE;
  342.       IF team_name <> 'Not Used ... ' THEN
  343.       BEGIN
  344.         count:=count+1;
  345.         IF correct<>0 THEN
  346.         IF total_secs<>9999 THEN
  347.         IF TRUNC(total_miles)<>999 THEN
  348.         BEGIN
  349.           num_correct:=num_correct+1;
  350.           test:=TRUE
  351.         END;
  352.       END;
  353.     IF X<16 THEN Menu_Check(menu2,data1_item[X],test)
  354.     ELSE IF X<31 THEN Menu_Check(menu2,data2_item[X-15],test)
  355.     ELSE IF X<46 THEN Menu_Check(menu2,data3_item[X-30],test)
  356.     ELSE Menu_Check(menu2,data4_item[X-45],test)
  357.     END;
  358.  
  359.   IF num_correct<count THEN
  360.   BEGIN
  361.     alert := '[1][All entries are not complete][ OK ]';
  362.     dummy := Do_Alert( alert, 1)
  363.   END
  364. END;
  365.  
  366. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  367.  
  368. Procedure Do_Score( X : INTEGER);
  369.  
  370. VAR
  371.   counter,
  372.   seconds,
  373.   switch_secs,
  374.   time1_points,
  375.   late,
  376.   call,
  377.   violate  : INTEGER;
  378.   miles : REAL;
  379.  
  380. BEGIN
  381.   switch_secs:=TRUNC(official.end_miles+0.1);
  382.   time1_points:=TRUNC(official.total_miles+0.1);
  383.   Make_Integer(official.obs1,late);
  384.   Make_Integer(official.obs2,call);
  385.   Make_Integer(official.time_position,violate);
  386.   WITH rally_data[X] DO
  387.   BEGIN
  388.     total_score:=correct*official.correct-(violation*violate)
  389.       -(late_to_position*late)-(calls*call);
  390.  
  391.     IF total_secs<official.total_secs THEN
  392.       seconds:=official.total_secs-total_secs
  393.     ELSE seconds:=total_secs-official.total_secs;
  394.  
  395.     FOR counter:=1 TO max_participants DO        {Use to determine best time}
  396.     IF time_places[counter].team_number = X THEN
  397.     BEGIN
  398.       time_places[counter].score:=seconds*(-1);
  399.       time_places[counter].used:=TRUE
  400.     END;
  401.  
  402.     IF seconds>=switch_secs THEN
  403.     BEGIN
  404.       total_score:=total_score-(switch_secs*time1_points);
  405.       seconds:=seconds-switch_secs;
  406.       total_score:=total_score-(seconds*official.total_score)
  407.     END
  408.     ELSE total_score:=total_score-(seconds*time1_points);
  409.  
  410.     IF total_miles<official.start_miles THEN
  411.       miles:=official.start_miles-total_miles
  412.     ELSE miles:=total_miles-official.start_miles;
  413.  
  414.     FOR counter:=1 TO max_participants DO      {Use to determine best mileage}
  415.     IF miles_places[counter].team_number = X THEN
  416.     BEGIN
  417.       miles_places[counter].score:=TRUNC(miles*10+0.1)*(-1);
  418.       miles_places[counter].used:=TRUE
  419.     END;
  420.  
  421.     IF miles>=official.calls THEN
  422.     BEGIN
  423.       total_score:=total_score-(official.calls*official.late_to_position*10);
  424.       miles:=miles-official.calls;
  425.       total_score:=total_score-TRUNC((miles*official.violation*10)+0.1)
  426.     END
  427.     ELSE total_score:=total_score-TRUNC((miles*official.late_to_position*10)
  428.       +0.1);
  429.  
  430.   END; {WITH rally_data DO}
  431.   FOR counter:=1 TO max_participants DO
  432.   IF score_places[counter].team_number = X THEN
  433.   BEGIN
  434.     score_places[counter].score:=rally_data[X].total_score;
  435.     score_places[counter].used:=TRUE
  436.   END
  437. END;
  438.  
  439. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  440.  
  441. Procedure Do_Order(VAR temp_p : place_array);
  442.  
  443. {A bubble sort of the order of the contestants}
  444.  
  445. VAR
  446.   p_loop : INTEGER;
  447.   done : BOOLEAN;
  448.   temp_p2 : place_record;
  449.  
  450. BEGIN
  451.   REPEAT;
  452.     done:=TRUE;
  453.     FOR p_loop:=1 TO (max_participants-1) DO
  454.     IF temp_p[p_loop].score<temp_p[p_loop+1].score THEN
  455.     BEGIN
  456.       temp_p2:=temp_p[p_loop+1];
  457.       temp_p[p_loop+1]:=temp_p[p_loop];
  458.       temp_p[p_loop]:=temp_p2;
  459.       done:=FALSE
  460.     END;
  461.   UNTIL done
  462. END;
  463.  
  464. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  465.  
  466. Procedure Compute_Score;
  467.  
  468. VAR
  469.   X,
  470.   i  : INTEGER;
  471.   init : BOOLEAN;
  472.   d_name : STRING[3];
  473.  
  474. BEGIN
  475.   FOR X:=1 TO 9 DO {clear out the division array to start anew}
  476.   BEGIN
  477.     division_array[X].name:='    ';
  478.     division_array[X].total:=0;
  479.     division_array[X].number:=0;
  480.     division_array[X].average:=0
  481.   END;
  482.  
  483.   FOR X:=1 TO max_participants DO
  484.   WITH rally_data[X] DO
  485.     IF team_name <> 'Not Used ... ' THEN
  486.     BEGIN
  487.       IF correct<>0 THEN
  488.       IF total_secs<>9999 THEN
  489.       IF TRUNC(total_miles)<>999 THEN
  490.       BEGIN
  491.         IF division<>'' THEN group_enable:=TRUE;
  492.         Do_Score(X);
  493.         d_name:=Copy(division,1,Length(division));
  494.         init:=FALSE;
  495.         FOR i:=1 TO 8 DO
  496.           IF division_array[i].name=d_name THEN init:=TRUE;
  497.         IF NOT init THEN
  498.         BEGIN
  499.           i:=0;
  500.           REPEAT
  501.             i:=i+1;
  502.             IF division_array[i].name='    ' THEN
  503.               division_array[i].name:=d_name;
  504.           UNTIL ((division_array[i].name=d_name) OR (i=9));
  505.         END; {NOT init}
  506.         i:=0;
  507.         REPEAT
  508.           i:=i+1;
  509.         UNTIL ((division_array[i].name=d_name) OR (i=9));
  510.         IF division_array[i].name<>d_name THEN
  511.         BEGIN
  512.           alert := '[1][Too many divisions! Max is 8.][ OK ]';
  513.           dummy := Do_Alert( alert, 1)
  514.         END
  515.         ELSE WITH division_array[i] DO
  516.         BEGIN
  517.           total:=total+total_score;
  518.           number:=number+1;
  519.           average:=Int(total DIV number)
  520.         END;
  521.         IF win_enable=FALSE THEN
  522.         BEGIN
  523.           win_enable:=TRUE;
  524.           Menu_Enable(menu,winner_item);
  525.           Menu_Enable(menu,show_place_item);
  526.         END;
  527.         IF group_enable THEN
  528.         BEGIN
  529.           Menu_Enable(menu3,div1_item);
  530.           Menu_Enable(menu3,div2_item);
  531.           Menu_Enable(menu3,div3_item);
  532.           Menu_Enable(menu3,div4_item)
  533.         END;
  534.       END {processing of correct entry}
  535.     END;{FOR and IF loop}
  536.  
  537.   Check_Data;
  538.   Do_Order(score_places);
  539.   Do_Order(time_places);
  540.   Do_Order(miles_places)
  541. END;
  542.  
  543. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  544.  
  545. Procedure Mark_Scoring;
  546.  
  547. VAR
  548.   X :INTEGER;
  549.   test : BOOLEAN;
  550.  
  551. BEGIN
  552.   test := TRUE;
  553.   FOR X := 1 TO 8 DO
  554.   BEGIN
  555.     Menu_Check( menu , official_miles_item-1+X, score_ability[X] );
  556.     IF score_ability[X] = FALSE THEN test:=FALSE
  557.   END;
  558.   IF test = TRUE THEN Menu_Enable( menu , comp_scores_item )
  559.   ELSE Menu_Disable( menu , comp_scores_item )
  560. END;
  561.  
  562. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  563.  
  564. Procedure Display_Winners( title : INTEGER);
  565.  
  566. BEGIN
  567.   Menu_Normal(menu, title);
  568.   Erase_Menu( menu );
  569.   Draw_Menu( menu3 );
  570.   which_menu:=menu3 ;
  571. END;
  572.  
  573. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  574.  
  575. Procedure Enter_Data(title : INTEGER);
  576.  
  577. BEGIN
  578.   Menu_Normal(menu, title);
  579.   Erase_Menu( menu );
  580.   Draw_Menu( menu2 );
  581.   which_menu:=menu2 ;
  582. END;
  583.  
  584. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  585.  
  586. Procedure Store_Data;
  587.  
  588. VAR
  589.   valid : BOOLEAN;
  590.   count : INTEGER;
  591.  
  592. BEGIN
  593.   valid:=FALSE;
  594.   valid := Get_Out_File( 'Name of file to store this data in',path);
  595.     {path is the filename of the output file.  It is a VAR so can be
  596.      changed by the user}
  597.   IF NOT valid THEN
  598.   BEGIN
  599.     alert := '[1][Error in opening file][ OK ]';
  600.     dummy := Do_Alert( alert, 1)
  601.   END
  602.   ELSE
  603.   BEGIN
  604.     Set_Mouse( M_Bee);
  605.     REWRITE (rally_file,path);
  606.     rally_file^:=official;
  607.     PUT (rally_file);   {Use this first record to hold 'official' data}
  608.     FOR count := 1 TO max_participants DO
  609.     BEGIN
  610.       rally_file^:=rally_data[count];
  611.       PUT (rally_file)
  612.     END;
  613.     CLOSE(rally_file);
  614.     Set_Mouse( M_Arrow )
  615.   END
  616. END;
  617.  
  618. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  619.  
  620. Procedure Load_Data;
  621.  
  622. VAR
  623.   valid : BOOLEAN;
  624.   count   : INTEGER;
  625.   default : Path_Name;
  626.   m_item : STRING[27];
  627.  
  628. BEGIN
  629.   win_enable:=FALSE;
  630.   group_enable:=FALSE;
  631.   FOR count:=1 TO 8 DO
  632.     score_ability[count]:=FALSE;
  633.   default := 'A:\*.DAT';
  634.   valid:=FALSE;
  635.   valid:=Get_In_File(default,path);
  636.   IF valid THEN
  637.   BEGIN
  638.     Set_Mouse( M_Bee );
  639.     RESET(rally_file,path);
  640.     official:=rally_file^; { Get the 'official' data }
  641.  
  642.     WITH official DO
  643.     BEGIN
  644.       IF total_secs=9999 THEN total_secs:=0;
  645.       IF total_miles=999.9 THEN total_miles:=0.0;
  646.       IF time_position='120000' THEN time_position:='';
  647.       IF start_miles<>0.0 THEN score_ability[1]:=TRUE;
  648.       IF total_secs<>0 THEN score_ability[2]:=TRUE;
  649.       IF correct<>0 THEN score_ability[3]:=TRUE;
  650.       IF calls<>0 THEN score_ability[4]:=TRUE;
  651.       IF total_score<>0 THEN score_ability[5]:=TRUE;
  652.       IF obs1<>'' THEN score_ability[6]:=TRUE;
  653.       IF obs2<>'' THEN score_ability[7]:=TRUE;
  654.       IF time_position<>'' THEN score_ability[8]:=TRUE
  655.     END; {WITH official}
  656.     FOR count:=1 TO 15 DO
  657.     BEGIN
  658.       GET(rally_file);
  659.       rally_data[count]:=rally_file^;
  660.       m_item:=CONCAT('  ',rally_file^.team_name);
  661.       Menu_Text ( menu2, data1_item[count], m_item)
  662.     END;  {FOR count 1 TO 15 }
  663.     FOR count:=16 TO 30 DO
  664.     BEGIN
  665.       GET(rally_file);
  666.       m_item:=CONCAT('  ',rally_file^.team_name);
  667.       rally_data[count]:=rally_file^;
  668.       Menu_Text ( menu2, data2_item[count-15], m_item)
  669.     END;  {FOR count 16 TO 30 }
  670.     FOR count:=31 TO 45 DO
  671.     BEGIN
  672.       GET(rally_file);
  673.       m_item:=CONCAT('  ',rally_file^.team_name);
  674.       rally_data[count]:=rally_file^;
  675.       Menu_Text ( menu2, data3_item[count-30], m_item)
  676.     END;  {FOR count 31 TO 45 }
  677.     FOR count:=46 TO max_participants DO
  678.     BEGIN
  679.       GET(rally_file);
  680.       m_item:=CONCAT('  ',rally_file^.team_name);
  681.       rally_data[count]:=rally_file^;
  682.       Menu_Text ( menu2, data4_item[count-45], m_item)
  683.     END;  {FOR count 46 TO 60 }
  684.     CLOSE(rally_file);
  685.     Set_Mouse( M_Arrow );
  686.  
  687. {Set up a connection between the places arrays and the rally_data array}
  688.     FOR count:= 1 TO max_participants DO
  689.     BEGIN
  690.       score_places[count].team_number:=count;
  691.       score_places[count].score:=rally_data[count].total_score;
  692.       score_places[count].used:=FALSE;
  693.       IF score_places[count].score<>0 THEN score_places[count].used:=TRUE
  694.     END;
  695.  
  696.     FOR count:= 1 TO max_participants DO
  697.     BEGIN
  698.       time_places[count].team_number:=count;
  699.       time_places[count].score:=rally_data[count].total_secs*(-1);
  700.       time_places[count].used:=FALSE;
  701.       IF time_places[count].score<>-9999 THEN time_places[count].used:=TRUE
  702.     END;
  703.  
  704.     FOR count:= 1 TO max_participants DO
  705.     BEGIN
  706.       miles_places[count].team_number:=count;
  707.       miles_places[count].score:=TRUNC(rally_data[count].total_miles*10)*(-1);
  708.       miles_places[count].used:=FALSE;
  709.       IF miles_places[count].score<>-9999 THEN miles_places[count].used:=TRUE
  710.     END;
  711.  
  712.     Menu_Enable( menu , enter_results_item );
  713.     Menu_Enable( menu , save_data_item );
  714.     Menu_Enable( menu , official_miles_item);
  715.     Menu_Enable( menu , official_time_item );
  716.     Menu_Enable( menu , points_per_question_item );
  717.     Menu_Enable( menu , points_sub_miles_item );
  718.     Menu_Enable( menu , points_lost_time_item );
  719.     Menu_Enable( menu , points_late_item );
  720.     Menu_Enable( menu , points_calls_item );
  721.     Menu_Enable( menu , points_violat_item );
  722.     Menu_Disable( menu , winner_item );
  723.     Menu_Disable( menu , show_place_item );
  724.     Mark_Scoring;
  725.     Check_Data
  726.   END {Valid filename was used}
  727. END;
  728.  
  729. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  730.  
  731. Procedure New_File;
  732.  
  733. VAR
  734.   valid : Boolean;
  735.   count : INTEGER;
  736.  
  737. BEGIN
  738.   path:='A:\RALLY.DAT';
  739.   valid := Get_Out_File( 'Name of file to use for rally data',path);
  740.   {path is the filename of the output file.  It is a VAR so can be
  741.    changed by the user}
  742.   IF NOT valid THEN
  743.     BEGIN
  744.       alert := '[1][Error in opening file][ OK ]';
  745.       dummy := Do_Alert( alert, 1)
  746.     END
  747.   ELSE {Valid file name selected}
  748.   BEGIN
  749.     Set_Mouse( M_Bee );
  750.     REWRITE (rally_file,path);
  751.     FOR count := 1 TO max_participants+1 DO
  752.     BEGIN
  753.       WITH rally_file^ DO
  754.       BEGIN
  755.         team_name        := 'Not Used ... ';
  756.         driver           := '';
  757.         nav              := '';
  758.         obs1             := '';
  759.         obs2             := '';
  760.         time_position    := '120000';
  761.         division         := '';
  762.         correct          := 0;
  763.         calls            := 0;
  764.         late_to_position := 0;
  765.         violation        := 0;
  766.         start_time       := '000000';
  767.         end_time         := '000000';
  768.         total_time       := '00:00:00';
  769.         total_secs       := 9999;
  770.         start_miles      := 0.0;
  771.         end_miles        := 0.0;
  772.         total_miles      := 999.9;
  773.         total_score      := 0
  774.       END;      {WITH rally_file DO}
  775.       PUT(rally_file)
  776.     END;          {FOR count ...}
  777.     CLOSE(rally_file);
  778.     Set_Mouse( M_Arrow )
  779.   END
  780. END;
  781.  
  782. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  783.  
  784. Procedure Get_Integer_String(number:INTEGER ; VAR str : STR25);
  785.  
  786. {convert the number to a string}
  787.  
  788. VAR
  789.   temp,
  790.   temp2 : INTEGER;
  791.  
  792. BEGIN
  793.   str:='0000';
  794.   str[1]:=Chr(48+(number DIV 1000));
  795.   temp2:=number MOD 1000;
  796.   temp:=temp2 DIV 100;
  797.   str[2]:=Chr(48+temp);
  798.   number:=temp2 MOD 100;
  799.   temp:=number DIV 10;
  800.   str[3]:=Chr(48+temp);
  801.   temp2:=number MOD 10;
  802.   str[4]:=Chr(48+temp2)
  803. END;
  804.  
  805. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  806.  
  807. Procedure Get_Real_String(miles : REAL; VAR str : STR25);
  808.  
  809. VAR
  810.   temp,
  811.   temp2,
  812.   number : LONG_INTEGER;
  813.  
  814. BEGIN
  815.   str:='000000';
  816.   number:=LONG_TRUNC(miles);
  817.   miles:=miles-number;
  818.   str[1]:=Chr(48+(number DIV 10000));
  819.   temp2:=number MOD 10000;
  820.   temp:=temp2 DIV 1000;
  821.   str[2]:=Chr(48+temp);
  822.   number:=temp2 MOD 1000;
  823.   temp:=number DIV 100;
  824.   temp2:=number MOD 100;
  825.   str[3]:=Chr(48+temp);
  826.   temp:=temp2 DIV 10;
  827.   str[4]:=Chr(48+temp);
  828.   number:=temp2 MOD 10;
  829.   str[5]:=Chr(48+number);
  830.   temp:=LONG_TRUNC((miles+0.01)*10);
  831.   str[6]:=Chr(48+temp)
  832. END;
  833.  
  834. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  835.  
  836. Procedure Make_Real(str : STR25 ; VAR float : REAL);
  837.  
  838. VAR
  839.   X,
  840.   size : INTEGER;
  841.   A    : CHAR;
  842.   num  : LONG_INTEGER;
  843.  
  844. BEGIN
  845.   float := 0.0;
  846.   size:=Length(str);
  847.   FOR X:=size DOWNTO 1 DO
  848.   BEGIN
  849.     A:=str[size+1-X];
  850.     CASE A OF
  851.       '0' : num:=0;
  852.       '1' : num:=1;
  853.       '2' : num:=2;
  854.       '3' : num:=3;
  855.       '4' : num:=4;
  856.       '5' : num:=5;
  857.       '6' : num:=6;
  858.       '7' : num:=7;
  859.       '8' : num:=8;
  860.       '9' : num:=9
  861.     END;
  862.   float:=float+(LONG_TRUNC(num*PwrOfTen(X-1)))/10;
  863.   END  { FOR loop }
  864. END;
  865.  
  866. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  867.  
  868. Procedure Compute_Secs(start,end_s:STR25; VAR total : INTEGER;
  869.                        VAR valid : BOOLEAN);
  870.  
  871. VAR
  872.   time : STRING[25];
  873.   temp_int,
  874.   star_sec,
  875.   end_sec : INTEGER;
  876.  
  877. BEGIN
  878.   star_sec:=0;
  879.   end_sec:=0;
  880.   total:=0;
  881.   valid:=TRUE;
  882.   time:=Copy(start,1,2);
  883.   Make_Integer(time,temp_int);
  884.   star_sec:=temp_int*60*60;
  885.   time:=Copy(start,3,2);
  886.   Make_Integer(time,temp_int);
  887.   star_sec:=star_sec+temp_int*60;
  888.   time:=Copy(start,5,2);
  889.   Make_Integer(time,temp_int);
  890.   star_sec:=star_sec+temp_int;
  891.  
  892.   time:=Copy(end_s,1,2);
  893.   Make_Integer(time,temp_int);
  894.   end_sec:=temp_int*60*60;
  895.   time:=Copy(end_s,3,2);
  896.   Make_Integer(time,temp_int);
  897.   end_sec:=end_sec+temp_int*60;
  898.   time:=Copy(end_s,5,2);
  899.   Make_Integer(time,temp_int);
  900.   end_sec:=end_sec+temp_int;
  901.  
  902.  
  903.   IF end_sec>star_sec THEN total:=end_sec-star_sec;
  904. END;
  905.  
  906. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  907.  
  908. Procedure Compute_Time;
  909.  
  910. VAR
  911.   time,
  912.   time2,
  913.   time3 : STRING[25];
  914.   colon : STRING[1];
  915.   seconds,
  916.   temp_int,
  917.   star_sec,
  918.   end_sec,
  919.   hrs,
  920.   mins : INTEGER;
  921.   ok : BOOLEAN;
  922.  
  923. BEGIN
  924.   ok:=TRUE;
  925.   colon:=':';
  926.   Compute_Secs(temp_data.start_time,temp_data.end_time,temp_data.total_secs,
  927.     ok);
  928.   IF ok THEN
  929.   BEGIN
  930.     seconds:=temp_data.total_secs;
  931.     hrs:=seconds DIV 3600;
  932.     seconds:=seconds MOD 3600;
  933.     mins:= seconds DIV 60;
  934.     seconds:=seconds MOD 60;
  935.  
  936.     Get_Integer_String(hrs, time);
  937.     Delete(time,1,2);
  938.     time3:=time;
  939.     time2:=time;
  940.     Get_Integer_String(mins, time);
  941.     Delete(time,1,2);
  942.     time3:=Concat(time2,colon,time);
  943.     time2:=time3;
  944.     Get_Integer_String(seconds, time);
  945.     Delete(time,1,2);
  946.     time3:=Concat(time2,colon,time);
  947.     temp_data.total_time:=time3
  948.   END;
  949. END;
  950.  
  951. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  952.  
  953. Procedure Hide_Menu;
  954.  
  955. VAR
  956.   count : INTEGER;
  957.  
  958. BEGIN
  959.   Menu_Disable( menu , enter_results_item );
  960.   Menu_Disable( menu , save_data_item );
  961.   Menu_Disable( menu , show_place_item );
  962.   Menu_Disable( menu , winner_item );
  963.   Menu_Disable( menu , comp_scores_item );
  964.   Menu_Disable( menu , official_miles_item );
  965.   Menu_Disable( menu , official_time_item );
  966.   Menu_Disable( menu , points_per_question_item );
  967.   Menu_Disable( menu , points_sub_miles_item );
  968.   Menu_Disable( menu , points_lost_time_item );
  969.   Menu_Disable( menu , points_late_item );
  970.   Menu_Disable( menu , points_calls_item );
  971.   Menu_Disable( menu , points_violat_item );
  972.   Menu_Disable( menu3 , div1_item );
  973.   Menu_Disable( menu3 , div2_item );
  974.   Menu_Disable( menu3 , div3_item );
  975.   Menu_Disable( menu3 , div4_item )
  976. END;
  977.  
  978. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  979.  
  980. Procedure O_Mileage(title,item :INTEGER);
  981.  
  982. VAR
  983.   o_m_item,
  984.   text_item,
  985.   dash_item,
  986.   q_btn,
  987.   c_btn : INTEGER;
  988.   transfer : STRING[25];
  989.  
  990. BEGIN
  991.   dialog:=New_Dialog(6,0,0,42,8);
  992.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  993.   Set_Dtext(dialog,text_item,'Please enter the Official Mileage below.',
  994.     System_Font,TE_Center);
  995.   dash_item:=Add_DItem(dialog,G_Text,none,1,2,40,1,0,$1180);
  996.   Obj_SetState(dialog,dash_item,Disabled,False);
  997.   Set_Dtext(dialog,dash_item,'----------------------------------------',
  998.     System_Font,TE_Center);
  999.   Get_Real_String(official.start_miles,transfer);
  1000.   o_m_item:=Add_DItem(dialog,G_FText,Editable,2,3,25,1,0,$1180);
  1001.   Set_DEdit(dialog,o_m_item,' Official Miles > _____._','999999',
  1002.     transfer,System_Font,TE_Left);
  1003.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1004.     11,5,8,2,3,(4096*Green+256*Black+128));
  1005.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1006.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1007.     23,5,8,2,2,(4096*Red+256*Black+128));
  1008.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1009.   Center_Dialog(dialog);
  1010.   button:=Do_Dialog(dialog,o_m_item);
  1011.   IF button=q_btn THEN
  1012.   BEGIN
  1013.     Get_DEdit(dialog,o_m_item,transfer);
  1014.     Make_Real(transfer,official.start_miles);
  1015.     score_ability[1]:=TRUE;
  1016.     Mark_Scoring
  1017.   END;
  1018.   End_Dialog(dialog);
  1019.   Delete_Dialog(dialog)
  1020. END;
  1021.  
  1022. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1023.  
  1024. Procedure O_Time(title,item :INTEGER);
  1025.  
  1026. VAR
  1027.   o_t_item,
  1028.   text_item,
  1029.   dash_item,
  1030.   q_btn,
  1031.   c_btn : INTEGER;
  1032.   ok : BOOLEAN;
  1033.  
  1034. BEGIN
  1035.   ok:=TRUE;
  1036.   dialog:=New_Dialog(6,0,0,42,8);
  1037.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1038.   Set_Dtext(dialog,text_item,'Please enter the Official Time below.',
  1039.     System_Font,TE_Center);
  1040.   dash_item:=Add_DItem(dialog,G_Text,none,1,2,40,1,0,$1180);
  1041.   Obj_SetState(dialog,dash_item,Disabled,False);
  1042.   Set_Dtext(dialog,dash_item,'----------------------------------------',
  1043.     System_Font,TE_Center);
  1044.   o_t_item:=Add_DItem(dialog,G_FText,Editable,2,3,24,1,0,$1180);
  1045.   Set_DEdit(dialog,o_t_item,'Official Time > __:__:__','999999',
  1046.     official.end_time,System_Font,TE_Left);
  1047.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1048.     11,5,8,2,3,(4096*Green+256*Black+128));
  1049.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1050.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1051.     23,5,8,2,2,(4096*Red+256*Black+128));
  1052.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1053.   Center_Dialog(dialog);
  1054.   button:=Do_Dialog(dialog,o_t_item);
  1055.   IF button=q_btn THEN
  1056.   BEGIN
  1057.     Get_DEdit(dialog,o_t_item,official.end_time);
  1058.     Compute_Secs('000000',official.end_time,official.total_secs,ok);
  1059.     IF ok THEN score_ability[2]:=TRUE;
  1060.     Mark_Scoring
  1061.   END;
  1062.   End_Dialog(dialog);
  1063.   Delete_Dialog(dialog)
  1064. END;
  1065.  
  1066. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1067.  
  1068. Procedure P_P_Question(title, item : INTEGER);
  1069.  
  1070. VAR
  1071.   transfer : STRING[25];
  1072.   text_item,
  1073.   dash_item,
  1074.   p_p_item,
  1075.   q_btn,
  1076.   c_btn  : INTEGER;
  1077.  
  1078. BEGIN
  1079.   dialog:=New_Dialog(6,0,0,42,8);
  1080.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1081.   Set_Dtext(dialog,text_item,'Please enter the points/question below.',
  1082.     System_Font,TE_Center);
  1083.   dash_item:=Add_DItem(dialog,G_Text,none,1,2,40,1,0,$1180);
  1084.   Obj_SetState(dialog,dash_item,Disabled,False);
  1085.   Set_Dtext(dialog,dash_item,'----------------------------------------',
  1086.     System_Font,TE_Center);
  1087.   p_p_item:=Add_DItem(dialog,G_FText,Editable,2,3,22,1,0,$1180);
  1088.   Get_Integer_String(official.correct,transfer);
  1089.   Set_DEdit(dialog,p_p_item,'Points/question > ____','9999',
  1090.     transfer,System_Font,TE_Left);
  1091.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1092.     11,5,8,2,3,(4096*Green+256*Black+128));
  1093.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1094.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1095.     23,5,8,2,2,(4096*Red+256*Black+128));
  1096.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1097.   Center_Dialog(dialog);
  1098.   button:=Do_Dialog(dialog,p_p_item);
  1099.   IF button=q_btn THEN
  1100.   BEGIN
  1101.     Get_DEdit(dialog,p_p_item,transfer);               {Check that some value}
  1102.     Make_Integer(transfer,official.correct);           {was entered for the}
  1103.     score_ability[3]:=TRUE;                            {points/question.  If}
  1104.     IF official.correct=0 THEN score_ability[3]:=FALSE;{so, then enable and}
  1105.     mark_scoring                                       {check the menu item.}
  1106.   END;
  1107.   End_Dialog(dialog);
  1108.   Delete_Dialog(dialog)
  1109. END;
  1110.  
  1111. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1112.  
  1113. Procedure P_S_Miles(title, item : INTEGER);
  1114.  
  1115. VAR
  1116.   transfer : STRING[25];
  1117.   text_item,
  1118.   text2_item,
  1119.   dash_item,
  1120.   p_s_item,
  1121.   p_s2_item,
  1122.   p_s3_item,
  1123.   q_btn,
  1124.   c_btn  : INTEGER;
  1125.  
  1126. BEGIN
  1127.   dialog:=New_Dialog(9,0,0,53,10);
  1128.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1129.   Set_Dtext(dialog,text_item,'Please enter the points to be subtracted for',
  1130.     System_Font,TE_Center);
  1131.   text2_item:=Add_DItem(dialog,G_String,none,2,2,0,0,0,0);
  1132.   Set_Dtext(dialog,text2_item,'each 1/10 mile off from the official mileage.',
  1133.     System_Font,TE_Center);
  1134.   dash_item:=Add_DItem(dialog,G_Text,none,1,3,51,1,0,$1180);
  1135.   Obj_SetState(dialog,dash_item,Disabled,False);
  1136.   Set_Dtext(dialog,dash_item,
  1137.     '---------------------------------------------------',
  1138.     System_Font,TE_Center);
  1139.   p_s_item:=Add_DItem(dialog,G_FText,Editable,2,4,35,1,0,$1180);
  1140.   Get_Integer_String(official.calls,transfer);
  1141.   Set_DEdit(dialog,p_s_item,'Points per 1/10 mile for first ____',
  1142.     '9999',transfer,System_Font,TE_Left);
  1143.   p_s2_item:=Add_DItem(dialog,G_FText,Editable,37,4,15,1,0,$1180);
  1144.   Get_Integer_String(official.late_to_position,transfer);
  1145.   Set_DEdit(dialog,p_s2_item,' mile(s) > ____','9999'
  1146.     ,transfer,System_Font,TE_Left);
  1147.   p_s3_item:=Add_DItem(dialog,G_FText,Editable,2,5,39,1,0,$1180);
  1148.   Get_Integer_String(official.violation,transfer);
  1149.   Set_DEdit(dialog,p_s3_item,'Points per 1/10 mile after above > ____',
  1150.     '9999',transfer,System_Font,TE_Left);
  1151.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1152.     14,7,8,2,3,(4096*Green+256*Black+128));
  1153.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1154.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1155.     32,7,8,2,2,(4096*Red+256*Black+128));
  1156.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1157.   Center_Dialog(dialog);
  1158.   button:=Do_Dialog(dialog,p_s_item);
  1159.   IF button=q_btn THEN
  1160.   BEGIN
  1161.     Get_DEdit(dialog,p_s_item,transfer);
  1162.     Make_Integer(transfer,official.calls);
  1163.     Get_DEdit(dialog,p_s2_item,transfer);
  1164.     Make_Integer(transfer,official.late_to_position);
  1165.     Get_DEdit(dialog,p_s3_item,transfer);
  1166.     Make_Integer(transfer,official.violation);
  1167.     score_ability[4]:=TRUE;
  1168.     Mark_Scoring
  1169.   END;
  1170.   End_Dialog(dialog);
  1171.   Delete_Dialog(dialog)
  1172. END;
  1173.  
  1174. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1175.  
  1176. Procedure P_L_Time;
  1177.  
  1178. VAR
  1179.   transfer : STRING[25];
  1180.   text_item,
  1181.   text2_item,
  1182.   dash_item,
  1183.   p_l_item,
  1184.   p_l2_item,
  1185.   p_l3_item,
  1186.   q_btn,
  1187.   c_btn,
  1188.   int1  : INTEGER;
  1189.  
  1190. BEGIN
  1191.   dialog:=New_Dialog(9,0,0,55,10);
  1192.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1193.   Set_Dtext(dialog,text_item,
  1194.     'Please enter the points to be subtracted for each',
  1195.     System_Font,TE_Center);
  1196.   text2_item:=Add_DItem(dialog,G_String,none,2,2,0,0,0,0);
  1197.   Set_Dtext(dialog,text2_item,'second off from the official time.',
  1198.     System_Font,TE_Center);
  1199.   dash_item:=Add_DItem(dialog,G_Text,none,1,3,53,1,0,$1180);
  1200.   Obj_SetState(dialog,dash_item,Disabled,False);
  1201.   Set_Dtext(dialog,dash_item,
  1202.     '-----------------------------------------------------',
  1203.     System_Font,TE_Center);
  1204.   p_l_item:=Add_DItem(dialog,G_FText,Editable,2,4,37,1,0,$1180);
  1205.   Get_Integer_String(TRUNC(official.end_miles+0.1),transfer);
  1206.   Set_DEdit(dialog,p_l_item,'Points lost per second for first ____',
  1207.     '9999',transfer,System_Font,TE_Left);
  1208.   p_l2_item:=Add_DItem(dialog,G_FText,Editable,39,4,15,1,0,$1180);
  1209.   Get_Integer_String(TRUNC(official.total_miles+0.1),transfer);
  1210.   Set_DEdit(dialog,p_l2_item,' seconds > ____','9999'
  1211.     ,transfer,System_Font,TE_Left);
  1212.   p_l3_item:=Add_DItem(dialog,G_FText,Editable,2,5,39,1,0,$1180);
  1213.   Get_Integer_String(official.total_score,transfer);
  1214.   Set_DEdit(dialog,p_l3_item,'Points per second after above > ____',
  1215.     '9999',transfer,System_Font,TE_Left);
  1216.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1217.     14,7,8,2,3,(4096*Green+256*Black+128));
  1218.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1219.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1220.     33,7,8,2,2,(4096*Red+256*Black+128));
  1221.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1222.   Center_Dialog(dialog);
  1223.   button:=Do_Dialog(dialog,p_l_item);
  1224.   IF button=q_btn THEN
  1225.   BEGIN
  1226.     Get_DEdit(dialog,p_l_item,transfer);
  1227.     Make_Integer(transfer,int1);
  1228.     official.end_miles:=int1;
  1229.     Get_DEdit(dialog,p_l2_item,transfer);
  1230.     Make_Integer(transfer,int1);
  1231.     official.total_miles:=int1;
  1232.     Get_DEdit(dialog,p_l3_item,transfer);
  1233.     Make_Integer(transfer,official.total_score);
  1234.     score_ability[5]:=TRUE;
  1235.     Mark_Scoring
  1236.   END;
  1237.   End_Dialog(dialog);
  1238.   Delete_Dialog(dialog)
  1239. END;
  1240.  
  1241.  
  1242. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1243.  
  1244. Procedure P_L_Late;
  1245.  
  1246. VAR
  1247.   text_item,
  1248.   text2_item,
  1249.   dash_item,
  1250.   p_l_item,
  1251.   q_btn,
  1252.   c_btn  : INTEGER;
  1253.  
  1254. BEGIN
  1255.   dialog:=New_Dialog(9,0,0,46,10);
  1256.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1257.   Set_Dtext(dialog,text_item,'Please enter the points to be subtracted',
  1258.     System_Font,TE_Center);
  1259.   text2_item:=Add_DItem(dialog,G_String,none,2,2,0,0,0,0);
  1260.   Set_Dtext(dialog,text2_item,'for each minute late for the position time.',
  1261.     System_Font,TE_Center);
  1262.   dash_item:=Add_DItem(dialog,G_Text,none,1,3,42,1,0,$1180);
  1263.   Obj_SetState(dialog,dash_item,Disabled,False);
  1264.   Set_Dtext(dialog,dash_item,
  1265.     '------------------------------------------',
  1266.     System_Font,TE_Center);
  1267.   p_l_item:=Add_DItem(dialog,G_FText,Editable,2,4,34,1,0,$1180);
  1268.   Set_DEdit(dialog,p_l_item,'Points lost per minute late > ____',
  1269.     '9999',official.obs1,System_Font,TE_Left);
  1270.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1271.     10,6,8,2,3,(4096*Green+256*Black+128));
  1272.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1273.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1274.     30,6,8,2,2,(4096*Red+256*Black+128));
  1275.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1276.   Center_Dialog(dialog);
  1277.   button:=Do_Dialog(dialog,p_l_item);
  1278.   IF button=q_btn THEN
  1279.   BEGIN
  1280.     Get_DEdit(dialog,p_l_item,official.obs1);
  1281.     score_ability[6]:=TRUE;
  1282.     Mark_Scoring
  1283.   END;
  1284.   End_Dialog(dialog);
  1285.   Delete_Dialog(dialog)
  1286. END;
  1287.  
  1288. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1289.  
  1290. Procedure P_L_Calls;
  1291.  
  1292. VAR
  1293.   text_item,
  1294.   text2_item,
  1295.   dash_item,
  1296.   p_l_item,
  1297.   q_btn,
  1298.   c_btn  : INTEGER;
  1299.  
  1300. BEGIN
  1301.   dialog:=New_Dialog(9,0,0,44,10);
  1302.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1303.   Set_Dtext(dialog,text_item,
  1304.     'Please enter the points to be subtracted',
  1305.     System_Font,TE_Center);
  1306.   text2_item:=Add_DItem(dialog,G_String,none,2,2,0,0,0,0);
  1307.   Set_Dtext(dialog,text2_item,'for each help call made.',
  1308.     System_Font,TE_Center);
  1309.   dash_item:=Add_DItem(dialog,G_Text,none,1,3,42,1,0,$1180);
  1310.   Obj_SetState(dialog,dash_item,Disabled,False);
  1311.   Set_Dtext(dialog,dash_item,
  1312.     '------------------------------------------',
  1313.     System_Font,TE_Center);
  1314.   p_l_item:=Add_DItem(dialog,G_FText,Editable,2,4,27,1,0,$1180);
  1315.   Set_DEdit(dialog,p_l_item,'Points per help call > ____',
  1316.     '9999',official.obs2,System_Font,TE_Left);
  1317.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1318.     9,6,8,2,3,(4096*Green+256*Black+128));
  1319.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1320.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1321.     29,6,8,2,2,(4096*Red+256*Black+128));
  1322.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1323.   Center_Dialog(dialog);
  1324.   button:=Do_Dialog(dialog,p_l_item);
  1325.   IF button=q_btn THEN
  1326.   BEGIN
  1327.     Get_DEdit(dialog,p_l_item,official.obs2);
  1328.     score_ability[7]:=TRUE;
  1329.     Mark_Scoring
  1330.   END;
  1331.   End_Dialog(dialog);
  1332.   Delete_Dialog(dialog)
  1333. END;
  1334.  
  1335. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1336.  
  1337. Procedure P_L_Violation;
  1338.  
  1339. VAR
  1340.   text_item,
  1341.   text2_item,
  1342.   dash_item,
  1343.   p_l_item,
  1344.   q_btn,
  1345.   c_btn  : INTEGER;
  1346.  
  1347. BEGIN
  1348.   dialog:=New_Dialog(9,0,0,44,10);
  1349.   text_item:=Add_DItem(dialog,G_String,none,2,1,0,0,0,0);
  1350.   Set_Dtext(dialog,text_item,
  1351.     'Please enter the points to be subtracted',
  1352.     System_Font,TE_Center);
  1353.   text2_item:=Add_DItem(dialog,G_String,none,2,2,0,0,0,0);
  1354.   Set_Dtext(dialog,text2_item,'for each car safety inspection violation.',
  1355.     System_Font,TE_Center);
  1356.   dash_item:=Add_DItem(dialog,G_Text,none,1,3,42,1,0,$1180);
  1357.   Obj_SetState(dialog,dash_item,Disabled,False);
  1358.   Set_Dtext(dialog,dash_item,
  1359.     '------------------------------------------',
  1360.     System_Font,TE_Center);
  1361.   p_l_item:=Add_DItem(dialog,G_FText,Editable,2,4,32,1,0,$1180);
  1362.   Set_DEdit(dialog,p_l_item,'Points lost per violation > ____',
  1363.     '9999',official.time_position,System_Font,TE_Left);
  1364.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1365.     9,6,8,2,3,(4096*Green+256*Black+128));
  1366.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1367.   c_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1368.     29,6,8,2,2,(4096*Red+256*Black+128));
  1369.   Set_DText(dialog,c_btn,'Cancel',System_Font,TE_Center);
  1370.   Center_Dialog(dialog);
  1371.   button:=Do_Dialog(dialog,p_l_item);
  1372.   IF button=q_btn THEN
  1373.   BEGIN
  1374.     Get_DEdit(dialog,p_l_item,official.time_position);
  1375.     score_ability[8]:=TRUE;
  1376.     Mark_Scoring
  1377.   END;
  1378.   End_Dialog(dialog);
  1379.   Delete_Dialog(dialog)
  1380. END;
  1381.  
  1382. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1383.  
  1384. PROCEDURE Do_Menu( title: INTEGER;VAR item : INTEGER );
  1385.  
  1386. BEGIN
  1387.   IF title = file_title THEN
  1388.     IF item = create_item THEN New_File
  1389.     ELSE IF item = old_item THEN Load_Data
  1390.     ELSE IF item = enter_results_item THEN Enter_Data(title)
  1391.     ELSE IF item = save_data_item THEN Store_Data;
  1392.   IF title = score_title THEN
  1393.     IF item = show_place_item THEN
  1394.       IF place_show=FALSE THEN
  1395.         place_show:=TRUE
  1396.       ELSE
  1397.         place_show:=FALSE;
  1398.     Menu_Check(menu,show_place_item,place_show);
  1399.     IF item = winner_item THEN Display_Winners(title)
  1400.     ELSE IF item = comp_scores_item THEN Compute_Score;
  1401.   IF title = set_scoring_title THEN
  1402.     IF item = official_miles_item THEN O_Mileage(title,item)
  1403.     ELSE IF item = official_time_item THEN O_Time(title,item)
  1404.     ELSE IF item = points_per_question_item THEN P_P_Question(title,item)
  1405.     ELSE IF item = points_sub_miles_item THEN P_S_Miles(title,item)
  1406.     ELSE IF item = points_lost_time_item THEN P_L_Time
  1407.     ELSE IF item = points_late_item THEN P_L_Late
  1408.     ELSE IF item = points_calls_item THEN P_L_Calls
  1409.     ELSE IF item = points_violat_item THEN P_L_Violation;
  1410.   IF title = quit_title THEN
  1411.     BEGIN
  1412.       alert :=
  1413.        '[2][QUIT - Are you sure?| |(Have you saved your data?)][ OK | Abort ]';
  1414.       dummy := Do_Alert(alert, 2 );
  1415.       IF dummy = 2 THEN item:=quit_item+1 {don't end}
  1416.     END; {quit}
  1417.   Menu_Normal( menu, title )
  1418. END;
  1419.  
  1420. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1421.  
  1422. Procedure Get_Place(item : INTEGER);
  1423.  
  1424. VAR
  1425.   x,
  1426.   place,
  1427.   p_item,
  1428.   p2_item : INTEGER;
  1429.   transfer : str25;
  1430.  
  1431. BEGIN
  1432.   place:=-1;
  1433.   FOR x:=1 TO max_participants DO
  1434.     IF score_places[x].team_number=edit[item] THEN place:=x;
  1435.   IF place<>-1 THEN
  1436.   BEGIN
  1437.     p_item:=Add_DItem(dialog,G_Text,None,25,11,14,1,0,$1180);
  1438.     Set_DText(dialog,p_item,'Place > ',System_Font,TE_Left);
  1439.     p2_item:=Add_DItem(dialog,G_Text,None,33,11,5,1,0,$1180);
  1440.     Get_Integer_String(place,transfer);
  1441.     Set_DText(dialog,p2_item,transfer,System_Font,TE_Left)
  1442.   END
  1443. END;
  1444.  
  1445. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1446.  
  1447. Procedure Edit2(title, item : INTEGER);
  1448.  
  1449. { This procedure is to draw the second edit dialog box}
  1450.  
  1451. VAR
  1452.   cancel : BOOLEAN;
  1453.   transfer : STRING[25];
  1454.   dash_item,
  1455.   start_item,
  1456.   end_item,
  1457.   total_time_item,
  1458.   actual_t_item,
  1459.   start_m_item,
  1460.   end_m_item,
  1461.   total_m_item,
  1462.   actual_m_item,
  1463.   s_text_item,
  1464.   s_dash_item,
  1465.   score_item    : INTEGER;
  1466.  
  1467. BEGIN
  1468.   Hide_Mouse;
  1469.   dialog:=New_Dialog(16,0,0,39,16);
  1470.   name_item:=Add_DItem(dialog,G_Text,None,2,1,34,1,0,$1180);
  1471.   Set_DText(dialog, name_item, temp_data.team_name, System_Font,TE_Center);
  1472.   dash_item:=Add_DItem(dialog,G_Text,None,1,2,37,1,0,$1180);
  1473.   Obj_SetState(dialog,dash_item,Disabled,False);
  1474.   Set_DText(dialog,dash_item,'-------------------------------------',
  1475.     System_Font,TE_Center);
  1476.   Get_Integer_string(temp_data.violation,transfer);
  1477.   violate_item:=Add_DItem(dialog,G_FText,Editable,2,3,25,1,0,$1180);
  1478.   Set_DEdit(dialog,violate_item,'Vehicle violations > ____',
  1479.     '9999',transfer, System_Font,TE_Left);
  1480.   start_item:=Add_DItem(dialog,G_FText,Editable,2,4,28,1,0,$1180);
  1481.   Set_DEdit(dialog,start_item,'Actual start time > __:__:__',
  1482.     '999999',temp_data.start_time,System_Font,TE_Left);
  1483.   end_item:=Add_DItem(dialog,G_FText,Editable,2,5,28,1,0,$1180);
  1484.   Set_DEdit(dialog,end_item,'Actual end time   > __:__:__',
  1485.     '999999',temp_data.end_time,System_Font,TE_Left);
  1486.   total_time_item:=Add_DItem(dialog,G_Text,None,2,6,20,1,0,$1180);
  1487.   Set_DText(dialog,total_time_item,'Total time        > ',System_Font,TE_Left);
  1488.   actual_t_item:=Add_DItem(dialog,G_Text,None,22,6,23,1,0,$1180);
  1489.   Set_DText(dialog,actual_t_item,temp_data.total_time,System_Font,TE_Left);
  1490.   Get_Real_String(temp_data.start_miles,transfer);
  1491.   start_m_item:=Add_DItem(dialog,G_FText,Editable,2,7,31,1,0,$1180);
  1492.   Set_DEdit(dialog,start_m_item,'Actual start mileage  > _____._',
  1493.     '999999',transfer,System_Font,TE_Left);
  1494.   Get_Real_String(temp_data.end_miles,transfer);
  1495.   end_m_item:=Add_DItem(dialog,G_FText,Editable,2,8,31,1,0,$1180);
  1496.   Set_DEdit(dialog,end_m_item,'Actual ending mileage > _____._',
  1497.     '999999',transfer,System_Font,TE_Left);
  1498.   actual_m_item:=Add_DItem(dialog,G_FText,Editable,2,9,31,1,0,$1180);
  1499.   IF TRUNC(temp_data.total_miles)=999 THEN temp_data.total_miles:=0.0;
  1500.   Get_Real_String(temp_data.total_miles,transfer);
  1501.   Set_DEdit(dialog,actual_m_item,'Total miles           > _____._','999999',
  1502.     transfer,System_Font,TE_Left);
  1503.   IF TRUNC(temp_data.total_miles)=0 THEN temp_data.total_miles:=999.9;
  1504.   s_dash_item:=Add_DItem(dialog,G_Text,None,1,10,37,1,0,$1180);
  1505.   Obj_SetState(dialog,s_dash_item,Disabled,False);
  1506.   Set_DText(dialog,s_dash_item,'-------------------------------------',
  1507.     System_Font,TE_Center);
  1508.   s_text_item:=Add_DItem(dialog,G_Text,None,2,11,14,1,0,$1180);
  1509.   Set_DText(dialog,s_text_item,'Total Score > ',System_Font,TE_Left);
  1510.   score_item:=Add_DItem(dialog,G_Text,None,16,11,5,1,0,$1180);
  1511.   IF temp_data.total_score<0 THEN temp_data.total_score:=0;
  1512.   Get_Real_string(temp_data.total_score,transfer);
  1513.   Set_DText(dialog,score_item,transfer,System_Font,TE_Left);
  1514.   IF place_show=TRUE THEN Get_Place(item);
  1515.  
  1516.   ok_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1517.     7,13,8,2,3,(4096*Green+256*Black+128));
  1518.   Set_DText(dialog,ok_btn,'OK',System_Font,TE_Center);
  1519.   cancel_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1520.     22,13,8,2,2,(4096*Red+256*Black+128));
  1521.   Set_DText(dialog,cancel_btn,'Cancel',System_Font,TE_Center);
  1522.   Show_Mouse;
  1523.   Center_Dialog(dialog);
  1524.   button:=Do_Dialog(dialog,violate_item);
  1525.   cancel:=FALSE;
  1526.   IF button=cancel_btn THEN cancel:=TRUE;
  1527.   Get_DEdit(dialog,violate_item,transfer);
  1528.   Make_Integer(transfer,temp_data.violation);
  1529.   Get_DEdit(dialog,start_item,temp_data.start_time);
  1530.   Get_DEdit(dialog,end_item,temp_data.end_time);
  1531.   Get_DEdit(dialog,start_m_item,transfer);
  1532.   Make_Real(transfer,temp_data.start_miles);
  1533.   Get_DEdit(dialog,end_m_item,transfer);
  1534.   Make_Real(transfer,temp_data.end_miles);
  1535.   IF temp_data.end_miles>temp_data.start_miles THEN
  1536.     temp_data.total_miles:=temp_data.end_miles-temp_data.start_miles;
  1537.   End_Dialog(dialog);
  1538.   Delete_Dialog(dialog);
  1539.   IF NOT cancel THEN
  1540.   BEGIN
  1541.     IF temp_data.end_time<>'000000' THEN Compute_Time;
  1542.     rally_data[edit[item]]:=temp_data
  1543.   END;
  1544. END;
  1545.  
  1546. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1547.  
  1548. Procedure Edit_Data(title, item : INTEGER);
  1549.  
  1550. { This procedure will draw the first main edit dialog box.  It may be
  1551.   exited without changing the contents, save the contents and return
  1552.   to the menu, or save and go to the second edit screen}
  1553.  
  1554. VAR
  1555.   cancel : BOOLEAN;
  1556.   transfer : STRING[25];
  1557.   m_item : STRING[27];
  1558.   dash_item,
  1559.   next_btn : INTEGER;
  1560.  
  1561. BEGIN
  1562.   temp_data:=rally_data[edit[item]];
  1563.   Hide_Mouse;
  1564.   dialog:=New_Dialog(15,0,0,39,16);
  1565.   name_item:=Add_DItem(dialog,G_FText,Editable,2,1,34,1,0,$1180);
  1566.   Set_DEdit(dialog,name_item,'Team   > _________________________',
  1567.     'XXXXXXXXXXXXXXXXXXXXXXXXX',temp_data.team_name,
  1568.     System_Font,TE_Left);
  1569.   dash_item:=Add_DItem(dialog,G_Text,None,1,2,37,1,0,$1180);
  1570.   Obj_SetState(dialog,dash_item,Disabled,False);
  1571.   Set_DText(dialog,dash_item,'-------------------------------------',
  1572.     System_Font,TE_Center);
  1573.   driver_item:=Add_DItem(dialog,G_FText,Editable,2,3,34,1,0,$1180);
  1574.   Set_DEdit(dialog,driver_item,'Driver > _________________________',
  1575.     'XXXXXXXXXXXXXXXXXXXXXXXXX',temp_data.driver,
  1576.     System_Font,TE_Left);
  1577.   nav_item:=Add_DItem(dialog,G_FText,Editable,2,4,34,1,0,$1180);
  1578.   Set_DEdit(dialog,nav_item,'Nav    > _________________________',
  1579.     'XXXXXXXXXXXXXXXXXXXXXXXXX',temp_data.nav,
  1580.     System_Font,TE_Left);
  1581.   obs1_item:=Add_DItem(dialog,G_FText,Editable,2,5,34,1,0,$1180);
  1582.   Set_DEdit(dialog,obs1_item,'Obs1   > _________________________',
  1583.     'XXXXXXXXXXXXXXXXXXXXXXXXX',temp_data.obs1,
  1584.     System_Font,TE_Left);
  1585.   obs2_item:=Add_DItem(dialog,G_FText,Editable,2,6,34,1,0,$1180);
  1586.   Set_DEdit(dialog,obs2_item,'Obs2   > _________________________',
  1587.     'XXXXXXXXXXXXXXXXXXXXXXXXX',temp_data.obs2,
  1588.     System_Font,TE_Left);
  1589.   pos_time_item:=Add_DItem(dialog,G_FText,Editable,2,7,21,1,0,$1180);
  1590.   Set_DEdit(dialog,pos_time_item,'Position Time > __:__',
  1591.     '9999',temp_data.time_position, System_Font,TE_Left);
  1592.   division_item:=Add_DItem(dialog,G_FText,Editable,2,8,15,1,0,$1180);
  1593.   Set_DEdit(dialog,division_item,'Grouping > ____',
  1594.     'nnnn',temp_data.division, System_Font,TE_Left);
  1595.   Get_Integer_string(temp_data.correct,transfer);
  1596.   correct_item:=Add_DItem(dialog,G_FText,Editable,2,9,14,1,0,$1180);
  1597.   Set_DEdit(dialog,correct_item,'Correct > ____',
  1598.     '9999',transfer, System_Font,TE_Left);
  1599.   Get_Integer_string(temp_data.calls,transfer);
  1600.   calls_item:=Add_DItem(dialog,G_FText,Editable,2,10,17,1,0,$1180);
  1601.   Set_DEdit(dialog,calls_item,'Help Calls > ____',
  1602.     '9999',transfer, System_Font,TE_Left);
  1603.   Get_Integer_string(temp_data.late_to_position,transfer);
  1604.   late_item:=Add_DItem(dialog,G_FText,Editable,2,11,31,1,0,$1180);
  1605.   Set_DEdit(dialog,late_item,'Minutes late to position > ____',
  1606.     '9999',transfer, System_Font,TE_Left);
  1607.   ok_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn,
  1608.     3,13,8,2,2,(4096*Green+256*Black+128));
  1609.   Set_DText(dialog,ok_btn,'OK',System_Font,TE_Center);
  1610.   next_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1611.     16,13,8,2,4,(4096*Blue+256*Black+128));
  1612.   Set_DText(dialog,next_btn,'Cont',System_Font,TE_Center);
  1613.   cancel_btn:=Add_DItem(dialog,G_BoxText,Selectable|Exit_Btn,
  1614.     28,13,8,2,2,(4096*Red+256*Black+128));
  1615.   Set_DText(dialog,cancel_btn,'Cancel',System_Font,TE_Center);
  1616.   Show_Mouse;
  1617.   Center_Dialog(dialog);
  1618.   button:=Do_Dialog(dialog,name_item);
  1619.   cancel:=FALSE;
  1620.   IF button=cancel_btn THEN cancel:=TRUE;
  1621.   Get_DEdit(dialog,name_item,temp_data.team_name);
  1622.   Get_DEdit(dialog,driver_item,temp_data.driver);
  1623.   Get_DEdit(dialog,nav_item,temp_data.nav);
  1624.   Get_DEdit(dialog,obs1_item,temp_data.obs1);
  1625.   Get_DEdit(dialog,obs2_item,temp_data.obs2);
  1626.   Get_DEdit(dialog,pos_time_item,temp_data.time_position);
  1627.   Get_DEdit(dialog,division_item,temp_data.division);
  1628.   Get_DEdit(dialog,correct_item,transfer);
  1629.   Make_Integer(transfer,temp_data.correct);
  1630.   Get_DEdit(dialog,calls_item,transfer);
  1631.   Make_Integer(transfer,temp_data.calls);
  1632.   Get_DEdit(dialog,late_item,transfer);
  1633.   Make_Integer(transfer,temp_data.late_to_position);
  1634.   End_Dialog(dialog);
  1635.   Delete_Dialog(dialog);
  1636.   IF NOT cancel THEN
  1637.   BEGIN
  1638.     rally_data[edit[item]]:=temp_data;
  1639.     m_item:=CONCAT('  ',temp_data.team_name);
  1640.     Menu_Text(menu2,item,m_item)
  1641.   END;
  1642.   IF button=next_btn THEN Edit2(title, item);
  1643. END;
  1644.  
  1645. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1646.  
  1647. PROCEDURE Do_Menu2( title , item : INTEGER );
  1648.  
  1649. BEGIN
  1650.   IF title = data1_title THEN Edit_Data(title, item);
  1651.   IF title = data2_title THEN Edit_Data(title, item);
  1652.   IF title = data3_title THEN Edit_Data(title, item);
  1653.   IF title = data4_title THEN Edit_Data(title, item);
  1654.   IF title = exit_title THEN
  1655.   BEGIN
  1656.     Menu_Normal(menu2, title);
  1657.     Erase_Menu( menu2 );
  1658.     Draw_Menu( menu );
  1659.     which_menu:=menu;
  1660.   END
  1661.   ELSE Menu_Normal(menu2, title);
  1662. END;
  1663.  
  1664. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1665.  
  1666. Procedure Sw_Place(place : INTEGER; str,str2,str3 : str25);
  1667.  
  1668. VAR
  1669.   color,
  1670.   text_item,
  1671.   text2_item,
  1672.   dash_item,
  1673.   cat_item,
  1674.   place_item,
  1675.   name_item,
  1676.   score_item,
  1677.   q_btn : INTEGER;
  1678.   pstring,
  1679.   pstrng1,
  1680.   pstrng2,
  1681.   pstrng3,
  1682.   pstrng4 :STRING[42];
  1683.  
  1684. BEGIN
  1685.   pstrng1:='The FIRST place winner for the category';
  1686.   pstrng2:='The SECOND place finisher for the category';
  1687.   pstrng3:='The THIRD place finisher for the category';
  1688.   pstrng4:='The LAST place finisher for the category';
  1689.   IF place = 1 THEN pstring:=pstrng1;
  1690.   IF place = 2 THEN pstring:=pstrng2;
  1691.   IF place = 3 THEN pstring:=pstrng3;
  1692.   IF place = 4 THEN pstring:=pstrng4;
  1693.  
  1694.   dialog:=New_Dialog(8,0,0,44,13);
  1695.   IF place<>4 THEN color:=Green*4096+Black*256+128+4*16+Green
  1696.     ELSE color:=Red*4096+Black*256+128+4*16+Red;
  1697.   text_item:=Add_DItem(dialog,G_BoxText,none,1,1,42,2,-2,color);
  1698.   Set_Dtext(dialog,text_item,' DISPLAY RESULTS! ',
  1699.     System_Font,TE_Center);
  1700.   dash_item:=Add_DItem(dialog,G_Text,none,1,4,42,1,0,$1180);
  1701.   Obj_SetState(dialog,dash_item,Disabled,False);
  1702.   Set_Dtext(dialog,dash_item,'--======================================--',
  1703.     System_Font,TE_Center);
  1704.   place_item:=Add_DItem(dialog,G_Text,none,1,5,42,1,0,$1180);
  1705.   Set_Dtext(dialog,place_item,pstring,System_Font,TE_Center);
  1706.   cat_item:=Add_DItem(dialog,G_Text,none,1,6,42,1,0,$1180);
  1707.   Set_Dtext(dialog,cat_item,str,System_Font,TE_Center);
  1708.   name_item:=Add_DItem(dialog,G_BoxText,none,6,7,32,1,-1,color);
  1709.   Set_DText(dialog,name_item,str2,System_Font,TE_Center);
  1710.   score_item:=Add_DItem(dialog,G_Text,none,1,9,42,1,0,$1180);
  1711.   Set_Dtext(dialog,score_item,str3,System_Font,TE_Center);
  1712.   q_btn:=Add_DItem(dialog,G_BoxText,Selectable|exit_btn|Default,
  1713.     19,10,6,2,3,(4096*Green+256*Black+128));
  1714.   Set_DText(dialog,q_btn,'OK',System_Font,TE_Center);
  1715.   Center_Dialog(dialog);
  1716.   button:=Do_Dialog(dialog,0);
  1717.   End_Dialog(dialog);
  1718.   Delete_Dialog(dialog)
  1719. END;
  1720.  
  1721. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1722.  
  1723. Procedure Do_Last(title : INTEGER; VAR str : str25;
  1724.                   temp_array : place_array ; VAR count : INTEGER);
  1725.  
  1726. BEGIN
  1727.   count:=max_participants+1;
  1728.   REPEAT
  1729.     count:=count-1;
  1730.     IF temp_array[count].used=TRUE THEN
  1731.       str:=rally_data[temp_array[count].team_number].team_name;
  1732.   UNTIL temp_array[count].used=TRUE;
  1733. END;
  1734.  
  1735. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1736.  
  1737. Procedure Do_Menu3( title, item : INTEGER );
  1738.  
  1739. VAR
  1740.   place,
  1741.   count : INTEGER;
  1742.   str,
  1743.   str2,
  1744.   str3  : STRING[25];
  1745.   temp_arr : place_array;
  1746.   period : CHAR;
  1747.  
  1748. BEGIN
  1749.   IF title = overall_title THEN
  1750.   BEGIN
  1751.     IF item = first_o_item THEN place:=1
  1752.       ELSE IF item = second_o_item THEN place:=2
  1753.       ELSE IF item = third_o_item THEN place:=3
  1754.       ELSE IF item = last_o_item THEN place:=4;
  1755.     str:='OVERALL';
  1756.     str2:=rally_data[score_places[place].team_number].team_name;
  1757.     Get_Real_String(rally_data[score_places[place].team_number].total_score,
  1758.       str3);
  1759.     IF place = 4 THEN
  1760.     BEGIN
  1761.       Do_Last(title,str2,score_places,count);
  1762.       Get_Real_String(rally_data[score_places[count].team_number].total_score,
  1763.         str3)
  1764.     END;
  1765.     Delete(str3,6,1);
  1766.     Sw_Place(place,str,str2,str3)
  1767.   END;
  1768.  
  1769.   IF title = time_title THEN
  1770.   BEGIN
  1771.     IF item = first_t_item THEN place:=1
  1772.       ELSE IF item = second_t_item THEN place:=2
  1773.       ELSE IF item = third_t_item THEN place:=3
  1774.       ELSE IF item = last_t_item THEN place:=4;
  1775.     str:='TIME';
  1776.     str2:=rally_data[time_places[place].team_number].team_name;
  1777.     str3:=rally_data[time_places[place].team_number].total_time;
  1778.     IF place = 4 THEN
  1779.     BEGIN
  1780.       Do_Last(title,str2,time_places,count);
  1781.       str3:=rally_data[time_places[count].team_number].total_time
  1782.     END;
  1783.     Sw_Place(place,str,str2,str3)
  1784.   END;
  1785.  
  1786.   IF title = miles_title THEN
  1787.   BEGIN
  1788.     IF item = first_m_item THEN place:=1
  1789.       ELSE IF item = second_m_item THEN place:=2
  1790.       ELSE IF item = third_m_item THEN place:=3
  1791.       ELSE IF item = last_m_item THEN place:=4;
  1792.     str:='MILEAGE';
  1793.     str2:=rally_data[miles_places[place].team_number].team_name;
  1794.     Get_Real_String(rally_data[miles_places[place].team_number].total_miles,
  1795.       str3);
  1796.     IF place = 4 THEN
  1797.     BEGIN
  1798.       Do_Last(title,str2,miles_places,count);
  1799.       Get_Real_String(rally_data[miles_places[count].team_number].total_miles,
  1800.         str3)
  1801.     END;
  1802.     period:='.';
  1803.     Insert(period,str3,Length(str3));
  1804.     Sw_Place(place,str,str2,str3)
  1805.   END;
  1806.  
  1807.   IF title = div_title THEN
  1808.   BEGIN
  1809.     IF item = div1_item THEN place:=1
  1810.       ELSE IF item = div2_item THEN place:=2
  1811.       ELSE IF item = div3_item THEN place:=3
  1812.       ELSE IF item = div4_item THEN place:=4;
  1813.     str:='BY GROUPING';
  1814.     FOR count:=1 TO max_participants DO
  1815.     BEGIN
  1816.       temp_arr[count].used:=FALSE;
  1817.       temp_arr[count].score:=0;
  1818.       temp_arr[count].team_number:=count
  1819.     END;
  1820.     FOR count:=1 TO 8 DO
  1821.     BEGIN
  1822.       temp_arr[count].score:=division_array[count].average;
  1823.       IF division_array[count].name<>'    ' THEN temp_arr[count].used:=TRUE;
  1824.     END;
  1825.     Do_Order(temp_arr);
  1826.     Get_Real_String(temp_arr[place].score, str3);
  1827.     str2:=division_array[temp_arr[place].team_number].name;
  1828.     IF place = 4 THEN
  1829.     BEGIN
  1830.       Do_Last(title,str2,temp_arr,count);
  1831.       Get_Real_String(temp_arr[count].score, str3);
  1832.       str2:=division_array[temp_arr[count].team_number].name
  1833.     END;
  1834.     Delete(str3,6,1);
  1835.     Sw_Place(place,str,str2,str3)
  1836.   END;
  1837.  
  1838.   Menu_Normal(menu3, title);
  1839.   IF title = exit2_title THEN
  1840.   BEGIN
  1841.     Erase_Menu( menu3 );
  1842.     Draw_Menu( menu );
  1843.     which_menu:=menu
  1844.   END
  1845. END;
  1846.  
  1847. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1848.  
  1849. PROCEDURE Event_Loop;
  1850.  
  1851. VAR
  1852.    which : INTEGER;
  1853.    msg : Message_Buffer;
  1854.  
  1855. BEGIN
  1856.   REPEAT
  1857.     which := Get_Event( E_Message , 0, 0, 0, 0,
  1858.              false, 0, 0, 0, 0, false, 0, 0, 0, 0, msg,
  1859.              dummy, dummy, dummy, dummy, dummy, dummy );
  1860.        { Since we only asked for message events, we don't need to check that
  1861.          we did, indeed, get a message event. }
  1862.     IF which_menu=menu THEN
  1863.     BEGIN
  1864.       Do_Menu( msg[3], msg[4] );
  1865.       IF msg[4]=quit_item THEN quit:=TRUE
  1866.     END
  1867.     ELSE IF which_menu=menu2 THEN Do_Menu2( msg[3], msg[4] )
  1868.     ELSE IF which_menu=menu3 THEN Do_Menu3( msg[3], msg[4] );
  1869.     UNTIL quit = TRUE
  1870. END;
  1871.  
  1872. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1873.  
  1874. Procedure Display_Intro;
  1875.  
  1876. VAR
  1877.   d_box : Dialog_Ptr;
  1878.   text1,
  1879.   text2,
  1880.   text3,
  1881.   text4,
  1882.   text5,
  1883.   dash,
  1884.   q_btn  : INTEGER;
  1885.  
  1886. BEGIN
  1887.   d_box:=New_Dialog(8,0,0,50,11);
  1888.   text1:=Add_DItem( d_box, G_BoxText,none,1,1,48,2,1,(4096*Green)+
  1889.     (256*Black)+128+(16*7)+Green);
  1890.   Set_DText(d_box,text1,' Car ''Fun'' Rally Scoring Program ',System_Font,
  1891.     TE_Center);
  1892.   text2:=Add_DItem( d_box,G_Text,none,0,3,50,1,0,$1180);
  1893.   Set_DText(d_box,text2,'by ',System_Font,TE_Center);
  1894.   text3:=Add_DItem(d_box,G_Text,none,0,4,50,1,0,$1180);
  1895.   Set_DText(d_box,text3,'David B. Chiquelin',System_Font,TE_Center);
  1896.   dash:=Add_DItem(d_box,G_Text,none,1,5,48,1,0,$1180);
  1897.   OBJ_SetState(d_box,dash,Disabled,FALSE);
  1898.   Set_DText(d_box,dash,'--===========================--',
  1899.     System_Font,TE_Center);
  1900.   text4:=Add_DItem(d_box,G_Text,none,0,6,50,1,0,$1180);
  1901.   Set_DText(d_box,text4,'Portions of this product are Copyright (c) 1986,',
  1902.     System_Font,TE_Center);
  1903.   text5:=Add_DItem(d_box,G_Text,none,0,7,50,1,0,$1180);
  1904.   Set_DText(d_box,text5,'OSS and CCD.  Used by permission of OSS.',
  1905.     System_Font,TE_Center);
  1906.   q_btn:=Add_DItem(d_box,G_Button,Selectable|Default|Exit_Btn,
  1907.     23,9,5,1,0,$1180);
  1908.   Set_DText(d_box,q_btn,'OK',System_Font,TE_Center);
  1909.   Center_Dialog(d_box);
  1910.   dummy:=Do_Dialog(d_box,0);
  1911.   End_Dialog(d_box);
  1912.   Delete_Dialog(d_box)
  1913. END;
  1914.  
  1915. { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
  1916.  
  1917. BEGIN {Main Program}
  1918.   quit:=FALSE;
  1919.   place_show:=FALSE;
  1920.   FOR dummy:=1 TO 8 DO
  1921.     score_ability[dummy]:=FALSE;
  1922.   IF Init_Gem >= 0 THEN
  1923.   BEGIN
  1924.     Init_Mouse;
  1925.     Menu_Setup;
  1926.     which_menu:=menu;
  1927.     Draw_Menu( menu );
  1928.     Hide_Menu;
  1929.     Display_Intro;
  1930.     Event_Loop;
  1931.     Erase_Menu( menu );
  1932.     Erase_Menu( menu2 );
  1933.     Erase_Menu( menu3 );
  1934.     Delete_Menu( menu );
  1935.     Delete_Menu( menu2 );
  1936.     Delete_Menu( menu3 );
  1937.     Exit_Gem
  1938.   END {Init_Gem}
  1939. END.
  1940.  
  1941.