X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Ftrain.cpp;h=56832c837542d9447acb3022a8d655e1a8786939;hb=bc8ac89bbe774bb133b758416182aa18e5e0a5a5;hp=5cc47058b19f4d0f124b1af27871fb65f4bb91b5;hpb=212bc6eb3ab2dbad39725984ac715c64f8de29ff;p=r2c2.git diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 5cc4705..56832c8 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -359,11 +359,15 @@ unsigned Train::reserve_more() break; int entry = link->get_endpoint_by_link(*last->block); + if(entry<0) + throw LogicError("Block links are inconsistent!"); if(!link->reserve(this)) { - // If we found another train going in the same direction as us, we can keep the blocks we got + // If we found another train and it's not headed straight for us, we can keep the blocks we got int other_entry = link->get_train()->get_entry_to_block(*link); - if(other_entry==entry || link->traverse(entry)==link->traverse(other_entry)) + if(other_entry<0) + throw LogicError("Block reservation inconsistency"); + if(static_cast(entry)!=link->traverse(other_entry)) { good = last; good_sens = nsens; @@ -377,12 +381,9 @@ unsigned Train::reserve_more() const Block::Endpoint &ep = link->get_endpoints()[entry]; const Endpoint &track_ep = ep.track->get_type().get_endpoints()[ep.track_ep]; - if(track_ep.paths&(track_ep.paths-1)) - { - // We're facing the points - keep the blocks reserved so far - good = last; - good_sens = nsens; - } + // Keep the blocks reserved so far, as either us or the other train can diverge + good = last; + good_sens = nsens; Turnout &turnout = trfc_mgr.get_control().get_turnout(link->get_turnout_id()); @@ -579,7 +580,7 @@ Train::Loader::Loader(Train &t): { add("block", &Loader::block); add("block_hint", &Loader::block_hint); - add("name", &Train::name); + add("name", &Loader::name); add("real_speed", &Loader::real_speed); add("route", &Loader::route); } @@ -595,7 +596,7 @@ void Train::Loader::block(unsigned id) blk.reserve(&obj); obj.cur_blocks.push_back(BlockRef(&blk, entry)); - obj.status = "Stopped"; + obj.set_status("Stopped"); obj.set_position(blk.get_endpoints()[entry]); prev_block = &blk; @@ -606,6 +607,11 @@ void Train::Loader::block_hint(unsigned id) prev_block = &obj.trfc_mgr.get_block(id); } +void Train::Loader::name(const string &n) +{ + obj.set_name(n); +} + void Train::Loader::real_speed(unsigned i, float speed, float weight) { obj.real_speed[i].speed = speed; @@ -614,7 +620,7 @@ void Train::Loader::real_speed(unsigned i, float speed, float weight) void Train::Loader::route(const string &n) { - obj.route = &obj.trfc_mgr.get_layout().get_route(n); + obj.set_route(&obj.trfc_mgr.get_layout().get_route(n)); } } // namespace Marklin