PredictUserContext *u= c->u;
return u->was_distance - c->distance;
}
+static void qprintf_position(Train *tra,
+ void (*qp)(const char *fmt,...) __attribute__((format(printf,1,2)))) {
+ qp("%s%s:%d+-%d",
+ tra->foredetect->tr_backwards?"-":"",
+ tra->foredetect->i->pname, tra->maxinto, tra->uncertainty);
+}
#define SKELETON_PREDICT_USER_CONTEXT(u,tra) \
(memset(&(u),0,sizeof((u))), \
u.desire_move= desire_move;
u.desire_movposcomb= desire_movposcomb;
- DPRINTF(safety,core," ***predicting*** %s%s %smaxspeed=%f%s stopdist=%d"
- " (speed %f, step %d%s) flags=%c%c%s"
- " desire=%s/%s\n",
- tra->backwards?"-":"",tra->pname,
- u.speed_info_specified ? "specified " : "",
- u.maxspeed, u.stopping ? "(stopping)" : "",
- u.stopping_distance,
- tra->speed.speed, tra->speed.step,
- tra->speed.decel.running ? " decel" : "",
- "-j"[ !!(flags & PREDF_JUSTDET) ],
- "no"[ !!(flags & PREDF_OLDPLAN) ],
- u.stopping ? " stopping" : "",
- u.desire_move ? u.desire_move->i->pname : "",
- u.desire_move ? u.desire_move->i->poscombs[u.desire_movposcomb]
+ if (DEBUGP(safety,core)) {
+ DPRINTF(safety,core," ***predicting*** %s%s ",
+ tra->backwards?"-":"",tra->pname);
+ qprintf_position(tra,DPRINTFA);
+ DPRINTFA(" %smaxspeed=%f%s stopdist=%d (speed %f, step %d%s)"
+ " flags=%c%c%s desire=%s/%s\n",
+ u.speed_info_specified ? "specified " : "",
+ u.maxspeed, u.stopping ? "(stopping)" : "",
+ u.stopping_distance,
+ tra->speed.speed, tra->speed.step,
+ tra->speed.decel.running ? " decel" : "",
+ "-j"[ !!(flags & PREDF_JUSTDET) ],
+ "no"[ !!(flags & PREDF_OLDPLAN) ],
+ u.stopping ? " stopping" : "",
+ u.desire_move ? u.desire_move->i->pname : "",
+ u.desire_move ? u.desire_move->i->poscombs[u.desire_movposcomb]
.pname : "");
+ }
FOR_SEG {
if (!seg->owner || seg->owner == u.train)
/*========== reporting position and ownership ==========*/
void report_train_position(Train *tra) {
- ouprintf("train %s at %s%s:%d+-%d %s\n",
- tra->pname,
- tra->foredetect->tr_backwards?"-":"",
- tra->foredetect->i->pname, tra->maxinto, tra->uncertainty,
- tra->backwards ? "backwards" : "forwards");
+ ouprintf("train %s at ",tra->pname);
+ qprintf_position(tra,ouprintf);
+ ouprintf(" %s\n", tra->backwards ? "backwards" : "forwards");
}
static int report_getmovpos(TrackLocation *t, TrackAdvanceContext *c,
PredictUserContext u;
const SegPosCombInfo *pci;
Segment *oldfdet;
- int oldmaxinto, oldfdet_trbackwards;
+ int oldmaxinto, oldfdet_trbackwards, old_planlookaheadnsegs;
ErrorCode ec, ec2;
int r;
struct timeval tnow;
oldfdet= tra->foredetect;
oldmaxinto= tra->maxinto;
oldfdet_trbackwards= tra->foredetect->tr_backwards;
+ old_planlookaheadnsegs= tra->plan_lookahead_nsegs;
r= trackloc_getlink(&newfdet,&c,&pci,0,-1); assert(!r);
tra->maxinto= pci->dist - newfdet.remain;
tra->backwards ^= 1;
newfdet.seg->tr_backwards ^= 1;
+ tra->plan_lookahead_nsegs= INT_MAX;
- ec= predict(tra,tnow, 0, 0,0, 0,ppc,ppcu);
+ ec= predict(tra,tnow, PREDF_OLDPLAN, 0,0, 0,ppc,ppcu);
if (!ec) {
/* yay! */
report_train_position(tra);
tra->maxinto= oldmaxinto;
tra->backwards ^= 1;
tra->foredetect->tr_backwards= oldfdet_trbackwards;
+ tra->plan_lookahead_nsegs= old_planlookaheadnsegs;
ec2= predict(tra,tnow, PREDF_OLDPLAN,0,0, 0,0,(char*)"abandon reverse");
assert(!ec2);