TrainRouter::TrainRouter(Train &t):
TrainAI(t),
priority(0),
- arriving(false),
+ arriving(0),
dest_zone(0),
dest_block(0),
update_pending(false)
bool TrainRouter::set_route(const Route *r)
{
- train.free_noncritical_blocks();
+ BlockIter fncb = train.get_first_noncritical_block();
Route *lead = 0;
if(r && train.is_placed())
{
const BlockAllocator &allocator = train.get_block_allocator();
TrackIter first = allocator.first().track_iter();
- TrackIter next = allocator.last().next().track_iter();
+ TrackIter next = fncb.track_iter();
if(!r->has_track(*next))
{
lead = Route::find(next, *r);
if(r)
routes.push_back(r);
train.stop_at(0);
- arriving = false;
+ arriving = 0;
- train.reserve_more();
+ train.refresh_blocks_from(*fncb);
const Route *route = get_route();
signal_route_changed.emit(route);
if(update_pending)
create_plans(train.get_layout());
- if(arriving && !train.get_speed())
+ if(arriving==1 && !train.get_speed())
{
- train.set_active(false);
signal_arrived.emit();
signal_event.emit(Message("arrived"));
- set_route(0);
+ arriving = 2;
}
+ else if(arriving==2 && !train.get_block_allocator().is_active())
+ set_route(0);
}
void TrainRouter::save(list<DataFile::Statement> &st) const
if(advance_route(route, block))
{
// Check if the block is a turnout and set it to proper path
- if(unsigned tid = block.get_turnout_id())
+ if(unsigned taddr = block.get_turnout_address())
{
- int path = (*route)->get_turnout(tid);
+ int path = (*route)->get_turnout(taddr);
if(path>=0)
b_iter.track_iter()->set_active_path(path);
}
{
b_iter = b_iter.next();
if(b_iter && !is_on_route(*b_iter))
- arriving = true;
+ arriving = 1;
}
}