Main Page   Compound List   File List   Compound Members   File Members  

zsig-t.vtc

00001 /* -*- C -*-
00002  * zsigs-t.vtc: generate Red Line zephyr signatures
00003  * $Id$
00004  */
00005 
00006 
00007 /* Array of stop names. */
00008 redline_stops = alloc(22);
00009 redline_stops[0] = "Alewife";
00010 redline_stops[1] = "Davis Square";
00011 redline_stops[2] = "Porter Square";
00012 redline_stops[3] = "Harvard Square";
00013 redline_stops[4] = "Central Square";
00014 redline_stops[5] = "Kendall/MIT";
00015 redline_stops[6] = "Charles/MGH";
00016 redline_stops[7] = "Park Street";
00017 redline_stops[8] = "Downtown Crossing";
00018 redline_stops[9] = "South Station";
00019 redline_stops[10] = "Broadway";
00020 redline_stops[11] = "Andrew";
00021 redline_stops[12] = "JFK/UMass";
00022 redline_stops[13] = "Savin Hill";
00023 redline_stops[14] = "Fields Corner";
00024 redline_stops[15] = "Shawmut";
00025 redline_stops[16] = "Ashmont";
00026 redline_stops[17] = "North Quincy";
00027 redline_stops[18] = "Wollaston";
00028 redline_stops[19] = "Quincy Center";
00029 redline_stops[20] = "Quincy Adams";
00030 redline_stops[21] = "Braintree";
00031 
00032 /* Array of destinations */
00033 redline_dests = alloc(2);
00034 redline_dests[0] = 16;
00035 redline_dests[1] = 21;
00036 
00037 /* Array of locations.  Each is an array of a stop number and a string. */
00038 redline_num_locs = 0;
00039 redline_locs = alloc(7);
00040 func red_line_add_loc(stop, desc)
00041 {
00042   redline_locs[redline_num_locs] = alloc(2);
00043   redline_locs[redline_num_locs][0] = stop;
00044   redline_locs[redline_num_locs][1] = desc;
00045   redline_num_locs++;
00046 }
00047 
00048 red_line_add_loc(1, "Tufts University");
00049 red_line_add_loc(2, "Change here for the Commuter Rail");
00050 red_line_add_loc(5, "MIT Cambridge Center");
00051 red_line_add_loc(6, "Mass General Hospital");
00052 red_line_add_loc(7, "Change here for the Green Line");
00053 red_line_add_loc(8, "Change here for the Orange Line");
00054 /* South Station is a special case in the code. */
00055 red_line_add_loc(12, "Bayside Exposition Center");
00056 
00057 /* Greg says the low bits of vt's rnd function aren't very random. */
00058 func rl_rnd(n) [const]
00059 {
00060   const = 17;
00061   return (rnd % (const * n)) / const;
00062 }
00063 
00064 Tredline ?:= new_assoc();
00065 
00066 func new_redline() [rl]
00067 {
00068   rl = alloc(6, Tredline);
00069   rl->stop = 0;
00070   rl->dest = 1;
00071   rl->dir = 1;
00072   rl->frame = 7;
00073   rl->msg = "";
00074   rl->win = cur_win;
00075   return rl;
00076 }
00077 
00078 REDLINE ?:= new_redline();
00079 REDLINE_save ?:= new_redline();
00080 
00081 /* State: current location... */
00082 REDLINE->stop = 0;
00083 
00084 /* ...current destination... */
00085 REDLINE->dest = rl_rnd(2);
00086 
00087 /* ...current direction... */
00088 /* Direction 1 is away from Alewife, -1 is towards it. */
00089 REDLINE->dir = 1;
00090 
00091 /* ...current frame. */
00092 /* Frames are:
00093  * 0: Next stop <station>
00094  * 1: Late Destination
00095  * 2: Entering <station>
00096  * 3: Location
00097  * 4: Announcements (1)
00098  * 5: Announcements (2)
00099  * 6: Announcements (3)
00100  * 7: Destination
00101  * 8: Late announcement */
00102 REDLINE->frame = 7;
00103 
00104 func red_line_frame_advance(rl)
00105 {
00106   /* Start by just advancing the frame. */
00107   rl->frame++;
00108   
00109   /* If the frame is '9', reset the frame to '0' and advance the stop. */
00110   if (rl->frame > 8)
00111   {
00112     rl->frame = 0;
00113     red_line_stop_advance(rl);
00114   }
00115 }
00116 
00117 func red_line_stop_advance(rl) [i]
00118 {
00119   /* Assumption: we're not at the end of the line. */
00120   rl->stop = rl->stop + rl->dir;
00121 
00122   /* Check to see if we are at the end of the line. */
00123   /* Check one: are we at Alewife? */
00124   if (rl->stop == 0)
00125   {
00126     /* Pick a destination at random. */
00127     rl->dest = rl_rnd(2);
00128     rl->dir = 1;
00129   }
00130 
00131   /* Check two: are we at our destination? */
00132   if (rl->stop == redline_dests[rl->dest])
00133   {
00134     /* Just turn around. */
00135     rl->dir = -1;
00136   }
00137 
00138   /* If we're on the Braintree branch and we think our next stop is
00139    * Savin Hill, jump to North Quincy.  If we think our next stop is
00140    * Ashmont, jump to JFK/UMass. */
00141   if (rl->dest == 1)
00142   {
00143     if (rl->stop == 13) rl->stop = 17;
00144     if (rl->stop == 16) rl->stop = 12;
00145   }
00146 }
00147 
00148 func red_line_find_loc(rl) [i]
00149 {
00150   for (i = 0; i < redline_num_locs; i++)
00151   {
00152     if (redline_locs[i][0] == rl->stop)
00153       return redline_locs[i][1];
00154   }
00155 
00156   /* South Station is a special case. */
00157   if (rl->stop == 9)
00158   {
00159     if (rl_rnd(2) == 0)
00160     {
00161       return "Change here for the Commuter Rail";
00162     }
00163     else
00164     {
00165       return "Change here for Commuter Rail and Amtrak intercity service";
00166     }    
00167   }
00168   
00169   return 0;
00170 }
00171 
00172 func red_line_find_dest(rl)
00173 {
00174   /* When is there a destination announcement? */
00175   /* There's never a destination announcement at all if we're heading
00176    * towards Alewife, unless we're at Braintree or Ashmont. */
00177   if (rl->dir == -1)
00178   {
00179     if ((rl->stop != 16) && (rl->stop != 21))
00180       return 0;
00181   }
00182   
00183   /* There's only a late destination announcement (after "next stop...")
00184    * between Andrew and one after JFK/UMass.  No announcement if headed
00185    * towards Alewife. */
00186   if (rl->frame == 1)
00187   {
00188     if ((rl->dir == -1) ||
00189         (rl->stop < 11) ||
00190         ((rl->stop > 13) && (rl->stop != 17)))
00191       return 0;
00192   }
00193 
00194   /* There's only a normal destination announcement (at the station, but
00195    * before a late announcement) up until JFK/UMass.  We've already
00196    * dealt with the case where we're headed towards Alewife. */
00197   if ((rl->frame == 7) && (rl->dir == 1))
00198   {
00199     if (rl->stop > 12)
00200       return 0;
00201   }
00202   
00203   return red_line_destination(rl);
00204 }
00205 
00206 func red_line_destination(rl) [dest]
00207 {
00208   return "THE DESTINATION OF THIS TRAIN IS: " + red_line_dest_name(rl);
00209 }
00210 
00211 func red_line_dest_name(rl)
00212 {
00213   if (rl->dir == -1)
00214     return redline_stops[0];
00215   else
00216     return redline_stops[redline_dests[rl->dest]];
00217 }
00218 
00219 func red_line_find_announce(rl)
00220 {
00221   /* At a terminus? */
00222   if (rl->stop == 0 || rl->stop == redline_dests[rl->dest])
00223   {
00224     if (rl->frame == 4)
00225       return "Last stop.";
00226     if (rl->frame == 5)
00227       return "Thank you for riding the T.";
00228     if (rl->frame == 6)
00229       return "Don't forget your belongings.";
00230   }
00231 
00232   /* At Charles/MGH? */
00233   if (rl->stop == 6 && rl->frame == 4 && rl_rnd(4) == 0)
00234   {
00235     return "Mass Eye and Ear Infirmary";
00236   }
00237   
00238   return 0;
00239 }
00240 
00241 func red_line_find_late_announce(rl)
00242 {
00243   /* At Harvard, Andrew, or Fields Corner? */
00244   if ((rl->stop == 3) || (rl->stop == 11) || (rl->stop == 14))
00245     return "No smoking please.";
00246 
00247   return 0;
00248 }
00249 
00250 func red_line_find_zsig(rl) [sig]
00251 {
00252   /* Generate the signature as best as we can. */
00253   if (rl->frame == 0)
00254     sig = "Next stop, " + redline_stops[rl->stop];
00255   else if (rl->frame == 1)
00256     sig = red_line_find_dest(rl);
00257   else if (rl->frame == 2)
00258     sig = "Entering " + redline_stops[rl->stop];
00259   else if (rl->frame == 3)
00260     sig = red_line_find_loc(rl);
00261   else if (rl->frame >= 4 && rl->frame <= 6)
00262     sig = red_line_find_announce(rl);
00263   else if (rl->frame == 7)
00264     sig = red_line_find_dest(rl);
00265   else if (rl->frame == 8)
00266     sig = red_line_find_late_announce(rl);
00267   else
00268     sig = 0;
00269   
00270   return sig;
00271 }
00272 
00273 /* Uses the global REDLINE object. */
00274 func red_line_zsig() [sig]
00275 {
00276   /* Get a zsig.  Advance frames until we see a valid signature. */
00277   do
00278   {
00279     sig = red_line_find_zsig(REDLINE);
00280     red_line_frame_advance(REDLINE);
00281   } while (!sig);
00282   red_line_change_status(REDLINE);
00283   return sig;
00284 }
00285 
00286 func red_line_status_string(rl)
00287 {
00288   return bprintf("[%s:%d->%s]", redline_stops[rl->stop], rl->frame,
00289                  red_line_dest_name(rl));
00290 }
00291 
00292 func red_line_change_status(rl) [str]
00293 {
00294   str = red_line_status_string(rl);
00295   change_status(rl->win, rl->msg, str);
00296   rl->msg = str;
00297 }
00298 
00299 /* Print the status of the global REDLINE object. */
00300 func red_line_status()
00301 {
00302   printf("Stop: %s; frame %d. ", redline_stops[REDLINE->stop], REDLINE->frame);
00303   printf("Destination: %s; direction %d\n",
00304          redline_stops[redline_dests[REDLINE->dest]], REDLINE->dir);
00305 }
00306 add_cmd("rl_status", 0, .red_line_status, "/rl_status");
00307 
00308 /* Save and restore the global REDLINE object. */
00309 func red_line_save() { acopy(base(REDLINE_save), base(REDLINE), 6); }
00310 add_cmd("rl_save", 0, .red_line_save, "/rl_save");
00311 func red_line_restore() { acopy(base(REDLINE), base(REDLINE_save), 4);
00312                           red_line_change_status(REDLINE);}
00313 add_cmd("rl_restore", 0, .red_line_restore, "/rl_restore");

Generated at Mon Aug 13 16:45:52 2001 for dzm-vtc by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001