+ if(rev==reverse)
+ return;
+
+ if(target_speed)
+ {
+ set_speed(0);
+ return;
+ }
+ else if(stop_timeout)
+ return;
+
+ layout.get_driver().set_loco_reverse(address, rev);
+
+ release_blocks(rsv_blocks);
+ reverse_blocks(cur_blocks);
+
+ if(cur_track)
+ {
+ unsigned path = cur_track->get_active_path();
+ cur_track_ep = cur_track->traverse(cur_track_ep, path);
+ offset = cur_track->get_type().get_path_length(path)-offset;
+ }
+}
+
+void Train::set_function(unsigned func, bool state)
+{
+ if(!loco_type.get_functions().count(func))
+ throw InvalidParameterValue("Invalid function");
+ if(func<5)
+ layout.get_driver().set_loco_function(address, func, state);
+ else
+ layout.get_driver().set_loco_function(address+1, func-4, state);
+}
+
+bool Train::get_function(unsigned func) const
+{
+ return (functions>>func)&1;