target_speed = speed;
if(!target_speed)
{
- // XXX We might roll onto a new sensor and get confused - should delay freeing blocks a bit
- for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
- i->block->reserve(0);
- rsv_blocks.clear();
+ trfc_mgr.get_control().set_timer(3*Time::sec).signal_timeout.connect(
+ sigc::bind_return(sigc::mem_fun(this, &Train::release_reserved_blocks), false));
}
else
reserve_more();
else
{
for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
- if(i->block->get_sensor_id()==addr)
+ if(unsigned b_addr = i->block->get_sensor_id())
{
- ++i;
- for(list<BlockRef>::iterator j=cur_blocks.begin(); j!=i; ++j)
- j->block->reserve(0);
- cur_blocks.erase(cur_blocks.begin(), i);
+ if(b_addr==addr)
+ {
+ ++i;
+ for(list<BlockRef>::iterator j=cur_blocks.begin(); j!=i; ++j)
+ j->block->reserve(0);
+ cur_blocks.erase(cur_blocks.begin(), i);
+ }
break;
}
pos = cur_track->get_endpoint_position(cur_track_ep);
}
+void Train::release_reserved_blocks()
+{
+ for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
+ i->block->reserve(0);
+ rsv_blocks.clear();
+}
+
Train::Loader::Loader(Train &t):
DataFile::BasicLoader<Train>(t)