+ BlockList::iterator end;
+ if(block)
+ end = find_if(cur_blocks_end, blocks.end(), BlockMatch(*block));
+ else
+ end = blocks.end();
+
+ SetFlag setf(advancing);
+ BlockList::iterator i = cur_blocks_end;
+ // Update cur_blocks_end first to keep things consistent.
+ cur_blocks_end = end;
+ for(; i!=end; ++i)
+ train.signal_advanced.emit(**i);
+}
+
+void BlockAllocator::advance_front(const Sensor *sensor)
+{
+ advance_front(sensor ? sensor->get_block() : 0);
+}
+
+void BlockAllocator::advance_back()
+{
+ const Vehicle &veh = train.get_vehicle(train.get_controller().get_reverse() ? 0 : train.get_n_vehicles()-1);
+ const Block &veh_block = veh.get_track()->get_block();
+
+ /* Sensors aren't guaranteed to be detriggered in order. Go through the
+ block list and locate the first sensor that's still active. */
+ Sensor *last_inactive = 0;
+ for(BlockList::iterator i=blocks.begin(); (i!=cur_blocks_end && i->block()!=&veh_block); ++i)
+ if(Sensor *sensor = (*i)->get_sensor())