chiark / gitweb /
get directions right (for the benefit of setdirection)
authorian <ian>
Sun, 20 Jul 2008 17:37:18 +0000 (17:37 +0000)
committerian <ian>
Sun, 20 Jul 2008 17:37:18 +0000 (17:37 +0000)
hostside/safety.c

index a8b2abd4656296d9c68cd42f549200456d397e01..39043b0c6038fde089d18c8aa8b42934ffecc2ae 100644 (file)
@@ -427,6 +427,7 @@ static int initpresent_nextseg(TrackLocation *t, TrackAdvanceContext *c,
   PredictUserContext *u= c->u;
   pred_callback_debug(" initpresent_nextseg",t,c,before);
   t->seg->now_present= t->seg->pred_present= t->seg->will_polarise= 1;
+  t->seg->tr_backwards= !t->backwards;
   t->seg->until= 0;
   if (!t->seg->i->invertible)
     u->noninv_tally[!t->backwards]++; /* ! since going backwards along train */
@@ -1120,8 +1121,11 @@ ErrorCode safety_setdirection(Train *tra, int backwards,
   oldmaxinto= tra->maxinto;
 
   r= trackloc_getlink(&newfdet,&c,&pci,0,-1);  assert(!r);
+
   tra->foredetect= newfdet.seg;
   tra->maxinto= pci->dist - newfdet.remain;
+  tra->backwards ^= 1;
+  newfdet.seg->tr_backwards ^= 1;
   
   ec= predict(tra,tnow, PREDF_NEWPLAN,0,0, ppc,ppcu);
   if (!ec) {
@@ -1136,6 +1140,9 @@ ErrorCode safety_setdirection(Train *tra, int backwards,
 
   tra->foredetect= oldfdet;
   tra->maxinto= oldmaxinto;
+  tra->backwards ^= 1;
+  newfdet.seg->tr_backwards ^= 1; /* in case it's the same as oldfdet */
+
   ec2= predict(tra,tnow, 0,0,0, 0,(char*)"abandon reverse");
   assert(!ec2);