const TrackLocation *before) {
PredictUserContext *u= c->u;
pred_callback_debug(" initpresent_nextseg",t,c,before);
+
+ /* it had better be set for where we came from */
+ if (before) {
+ assert(SOMEP(*mpc_io));
+ const SegPosCombInfo *pci= &t->seg->i->poscombs[*mpc_io];
+ const SegmentLinkInfo *link= &pci->link[!t->backwards];
+ if (!SOMEP(link->next) || &segments[link->next] != before->seg)
+ return predict_problem(u, t->seg, "route set against proposed location");
+ }
+
t->seg->now_present= t->seg->pred_present= t->seg->will_polarise= 1;
t->seg->tr_backwards= !t->backwards;
t->seg->until= 0;
u.tail= u.fdet;
ec= trackloc_reverse_exact(&u.tail,&u.tailc); assert(!ec);
- ec= trackloc_advance(&u.tail,&u.tailc); assert(!ec);
+
+ ec= trackloc_advance(&u.tail,&u.tailc);
+ if (ec) { assert(flags & PREDF_INITQUEST); return ec; }
+
ec= trackloc_reverse_exact(&u.tail,&u.tailc); assert(!ec);
u.hindmost= u.tail.seg;
newfdet.seg->tr_backwards ^= 1;
tra->plan_lookahead_nsegs= INT_MAX;
- ec= predict(tra,tnow, PREDF_OLDPLAN, 0,0, 0,ppc,ppcu);
+ ec= predict(tra,tnow, PREDF_OLDPLAN|PREDF_INITQUEST, 0,0, 0,ppc,ppcu);
if (!ec) {
/* yay! */
report_train_position(tra);
#define PREDF_OLDPLAN 002u
/* the old plan is necessarily sufficient as we are not intending
* to accelerate, change a movpos, etc. */
+#define PREDF_INITQUEST 004u
+ /* the initial location is questionable (ie, the initial present
+ * marking is allowed to fail) */
typedef struct {
unsigned stopping:1;