destination = 0;
waypoints.clear();
}
+ sequence_points.clear();
+ pending_sequence_checks.clear();
+ current_sequence = 0;
train.refresh_blocks_from(*fncb);
return true;
}
-void TrainRouter::add_wait(Block &block, Train *tr)
-{
- Wait wait;
- wait.block = █
- wait.train = tr;
- waits.push_back(wait);
-}
-
const Route *TrainRouter::get_route() const
{
if(routes.empty())
return routes.front();
}
+void TrainRouter::add_sequence_point(Block &b, unsigned o)
+{
+ sequence_points.push_back(SequencePoint(b, o));
+}
+
+void TrainRouter::add_sequence_point(Block &b, Train &t, unsigned i, unsigned o)
+{
+ SequencePoint sp(b, o);
+ sp.preceding_train = &t;
+ sp.sequence_in = i;
+ sequence_points.push_back(sp);
+}
+
void TrainRouter::set_destination(const TrackChain &d)
{
destination = &d;
if(update_pending)
create_plans(train.get_layout());
+ for(list<SequencePoint *>::iterator i=pending_sequence_checks.begin(); i!=pending_sequence_checks.end(); ++i)
+ if((*i)->preceding_train->get_ai_of_type<TrainRouter>()->get_current_sequence()>=(*i)->sequence_in)
+ {
+ (*i)->preceding_train = 0;
+ if(*i==&sequence_points.front())
+ train.stop_at(0);
+ }
+ pending_sequence_checks.clear();
+
if(arriving==1 && !train.get_speed())
{
signal_arrived.emit(destination);
{
if(t!=&train)
{
- if(!waits.empty() && waits.front().block==&block)
+ if(!t)
+ return;
+
+ TrainRouter *other_router = 0;
+ for(list<SequencePoint>::iterator i=sequence_points.begin(); i!=sequence_points.end(); ++i)
+ if(i->block==&block && i->preceding_train==t)
+ {
+ if(!other_router)
+ other_router = t->get_ai_of_type<TrainRouter>();
+ if(other_router->get_current_sequence()>=i->sequence_in)
+ {
+ i->preceding_train = 0;
+ if(i==sequence_points.begin())
+ train.stop_at(0);
+ }
+ else
+ pending_sequence_checks.push_back(&*i);
+ }
+
+ return;
+ }
+
+ if(!sequence_points.empty())
+ {
+ SequencePoint &sp = sequence_points.front();
+ if(sp.block==&block)
{
- train.stop_at(0);
- waits.pop_front();
+ current_sequence = sp.sequence_out;
+ sequence_points.pop_front();
}
- return;
}
BlockIter b_iter = t->get_block_allocator().iter_for(block);
return;
}
- if(!waits.empty() && waits.front().block==b_iter_next.block())
- train.stop_at(&block);
+ if(!sequence_points.empty())
+ {
+ SequencePoint &sp = sequence_points.front();
+ if(sp.preceding_train && sp.block==b_iter_next.block())
+ train.stop_at(&block);
+ }
}
}
}
-TrainRouter::Wait::Wait():
- block(0),
- train(0)
+TrainRouter::SequencePoint::SequencePoint(Block &b, unsigned o):
+ block(&b),
+ preceding_train(0),
+ sequence_in(0),
+ sequence_out(o)
{ }