X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.cpp;h=b2b4899f9aa6eb7cc1ad83cee23039d073c4b5f4;hb=b3988eb3c4dcb52f99596ed53ce94473219a0940;hp=ffa436b1d6a0c07795bf876d304077bb08a80fcd;hpb=7e27b311e33beda1746eb63e0945633f262427f6;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index ffa436b..b2b4899 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -48,6 +48,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): protocol(p), priority(0), yielding_to(0), + preceding_train(0), cur_blocks_end(blocks.end()), clear_blocks_end(blocks.end()), pending_block(0), @@ -75,7 +76,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): layout.add_train(*this); - layout.get_driver().add_loco(address, protocol); + layout.get_driver().add_loco(address, protocol, loco_type); layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event)); layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event)); @@ -185,10 +186,7 @@ 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); + layout.get_driver().set_loco_function(address, func, state); } float Train::get_control(const string &ctrl) const @@ -677,11 +675,13 @@ void Train::control_changed(const Controller::Control &ctrl) signal_control_changed.emit(ctrl.name, ctrl.value); } -void Train::loco_speed_event(unsigned addr, unsigned speed, bool) +void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev) { if(addr==address) { current_speed_step = speed; + if(rev!=reverse) + layout.get_driver().set_loco_reverse(address, reverse); speed_changing = false; pure_speed = false; } @@ -689,10 +689,8 @@ void Train::loco_speed_event(unsigned addr, unsigned speed, bool) void Train::loco_func_event(unsigned addr, unsigned func, bool state) { - if(addr==address || (addr==address+1 && loco_type.get_max_function()>4)) + if(addr==address) { - if(addr==address+1) - func += 4; if(state) functions |= 1<get_endpoints().size()<2) { if(!blocking_train) + { good_end = blocks.end(); + end_of_route = true; + } break; } @@ -952,10 +954,15 @@ void Train::reserve_more() bool entry_conflict = (block.entry()==other_exit); bool exit_conflict = (exit==static_cast(other_entry)); if(!entry_conflict && !last->get_turnout_id()) + { /* The other train is not coming to the blocks we're holding, so we can keep them. */ good_end = blocks.end(); + if(static_cast(other_entry)==block.entry()) + preceding_train = other_train; + } + int other_prio = other_train->get_priority(); if(!entry_conflict && !exit_conflict && other_priois_active())) // We are blocked, but there's a diversion possibility try_divert = true;