u.desire_move= desire_move;
u.desire_movposcomb= desire_movposcomb;
+ Distance detectable= ceil(tra->detectable * MARGIN_TRAINLENGTH);
+
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)"
+ DPRINTFA(" det.able=%d %smaxspeed=%f%s stopdist=%d (speed %f, step %d%s)"
" flags=%c%c%s desire=%s/%s\n",
+ detectable,
u.speed_info_specified ? "specified " : "",
u.maxspeed, u.stopping ? "(stopping)" : "",
u.stopping_distance,
* so we must instead extend our idea of the length of the train.
*/
- int tail_walkback= MARGIN_NOSE + tail_length(tra) +
- ceil(tra->detectable * MARGIN_TRAINLENGTH);
- int tail_advance_delaydist= MARGIN_TAIL;
+ int effective_uncertainty= tra->uncertainty;
+ int effective_length= MARGIN_NOSE + tail_length(tra) + detectable;
- int effective_into_fdet= tra->maxinto - tra->uncertainty;
- if (effective_into_fdet < 0) {
- tail_advance_delaydist += effective_into_fdet;
- effective_into_fdet -= effective_into_fdet;
- assert(!effective_into_fdet);
+ if (effective_uncertainty > tra->maxinto) {
+ effective_length += tra->uncertainty - tra->maxinto;
+ effective_uncertainty= tra->maxinto;
}
-
+
+ int effective_into_fdet= tra->maxinto - effective_uncertainty;
+ int tail_advance_delaydist= MARGIN_TAIL;
+
+ DPRINTF(safety,core," predict eff.uncert=%d eff.len=%d"
+ " eff.into_fdet=%d tail.adv.delay=%d\n",
+ effective_uncertainty, effective_length,
+ effective_into_fdet, tail_advance_delaydist);
+
u.fdetc.u= &u;
u.fdetc.getmovpos= pred_getmovpos;
u.tailc.getmovpos= pred_getmovpos;
u.tailc.nextseg= initpresent_nextseg;
u.tailc.trackend= pred_trackend_panic;
- u.tailc.distance= tail_walkback;
+ u.tailc.distance= effective_length;
u.tail= u.fdet;
/* we actually know exactly where we are */
u.fdetc.distance= 0;
} else { /* stopping, but we're mid-segment */
- u.fdetc.distance= tra->uncertainty;
+ u.fdetc.distance= effective_uncertainty;
}
u.elapsed= -u.fdetc.distance / u.maxspeed; /* imagine we're already there */
u.fdetc.distance += u.stopping_distance + MARGIN_NOSE;