count_time:1,
accelerating:1,
usecurrentposn:1, /* for pred_getmovpos */
- forceusemotions:1, /* for report_train_ownerships only */
+ alwaysusemotions:1, /* for report_train_ownerships only */
walk_compute_polarise:1, /* nose_nextseg still needs to worry */
need_polarise:1, /* when we commit */
train_polarity_inverted:1, /* right now, or if know_best, the best */
TrackAdvanceContext nosec, tailc, fdetc;
TimeInterval elapsed; /* from now, minimum */
Distance was_distance;
- Segment *furthest;
+ Segment *hindmost;
PredictionProblemCallback *problem_callback;
void *problem_callback_u;
PredictUserContext *u= c->u;
oprintf(DUPO("safety") " predict %s"
- " %s%s until=%ld dist=%d (was %d) %c%c%c.%c %c%c%c%c.%c%c%c%c"
+ " %s%s until=%ld dist=%d (was %d) %c%c%c.%c %c%c%c.%c%c%c%c"
" elapsed=%ld nit=%d,%d\n",
what,
t->backwards?"-":"", t->seg->i->pname, (long)t->seg->until,
"-t"[ u->count_time ],
"-a"[ u->accelerating ],
"-c"[ u->usecurrentposn ],
- "-f"[ u->forceusemotions ],
"-w"[ u->walk_compute_polarise ],
"-n"[ u->need_polarise ],
t->seg->tr_backwards= t->backwards;
t->seg->pred_present= 1;
t->seg->until= u->elapsed;
- u->furthest= t->seg;
return 0; /* yay! */
}
int r;
if (t->seg->owner != u->train) return -1;
- if (t->seg == u->furthest) {
- /* We've gone back past our own tail into the place where our
- * head is going to be in the far future. */
+ if (t->seg == u->hindmost && t->seg->tr_backwards == t->backwards) {
+ /* We've looped the loop. */
oprintf(UPO, " ...");
return -1;
}
strcat(flags,".");
if (t->seg == u->train->foredetect) {
strcat(flags,"!");
- u->usecurrentposn=u->forceusemotions;
+ u->usecurrentposn= 0;
}
- oprintf(UPO," %s%s", t->seg->tr_backwards?"-":"", t->seg->i->pname);
+ oprintf(UPO," %s%s", t->backwards?"-":"", t->seg->i->pname);
if (t->seg->i->n_poscombs > 1) {
r= pred_getmovpos(t,c,mpc); assert(!r); assert(*mpc>=0);
return 0;
}
-void report_train_ownerships(Train *tra, Segment *furthest,
- int force_use_motions) {
+void report_train_ownerships(Train *tra, Segment *hindmost,
+ int always_use_motions) {
PredictUserContext u;
MovPosComb mpc;
int r;
memset(&u,0,sizeof(u));
u.train= tra;
- u.furthest= 0;
- u.usecurrentposn= 0;
- u.forceusemotions= force_use_motions;
+ u.hindmost= 0;
+ u.alwaysusemotions= always_use_motions;
+ u.usecurrentposn= !always_use_motions;
- /* Walk backwards along the train printing its segments: */
+ /* Walk along the train printing its segments: */
oprintf(UPO, "train %s has", tra->pname);
- u.tail.seg= furthest;
- u.tail.remain= 0;
- u.tail.backwards= !u.tail.seg->tr_backwards;
+ u.nose.seg= hindmost;
+ u.nose.remain= 0;
+ u.nose.backwards= hindmost->tr_backwards;
- u.tailc.distance= TL_DIST_INF;;
- u.tailc.nextseg= report_nextseg;
- u.tailc.getmovpos= pred_getmovpos;
- u.tailc.u= &u;
+ u.nosec.distance= TL_DIST_INF;;
+ u.nosec.nextseg= report_nextseg;
+ u.nosec.getmovpos= pred_getmovpos;
+ u.nosec.u= &u;
- mpc= furthest->movposcomb;
- r= report_nextseg(&u.tail,&u.tailc,&mpc,0); assert(!r);
+ mpc= u.nose.seg->movposcomb;
+ r= report_nextseg(&u.nose,&u.nosec,&mpc,0); assert(!r);
- u.furthest= furthest;
- trackloc_advance(&u.tail,&u.tailc);
+ u.hindmost= hindmost;
+ trackloc_advance(&u.nose,&u.nosec);
oprintf(UPO, "\n");
}
u.accelerating= accelerate;
u.walk_compute_polarise= 1;
u.train_polarity_inverted= foredet->seg_inverted ^ foredet->tr_backwards;
- u.furthest= tra->foredetect;
u.usecurrentposn= 1;
u.fdetc.getmovpos= pred_getmovpos;
ec= trackloc_advance(&u.tail,&u.tailc); assert(!ec);
trackloc_reverse_exact(&u.tail,0);
+ u.hindmost= u.tail.seg;
+
/* find the train's nose */
u.nose= u.fdet;
if (u.need_polarise)
actual_inversions_done();
- report_train_ownerships(tra,u.furthest,0);
+ report_train_ownerships(tra,u.hindmost,0);
return 0;
xproblem: