X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=0140f439a7a61ba8ec80570f4c42430ae8c64afe;hb=2d9b73acd9653686eb5d9b7e919848895051ab0d;hp=75d746b3c6dd103cd148ae233f90361a189c2328;hpb=3dd660ffad729fbd6e75e6401f5c7f27b9013faf;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 75d746b..0140f43 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -375,7 +375,7 @@ bool TrainRoutePlanner::TrainRoutingState::check_arrival() } } - if(info->first_noncritical->has_track(*track)) + if(info->first_noncritical->has_track(*next_track)) critical = false; return false; @@ -519,23 +519,14 @@ void TrainRoutePlanner::RoutingStep::create_successors(list &new_st const TrackType::Endpoint &entry_ep = train.track.endpoint(); if(train.critical) { - train.path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path()); - train.update_estimate(); - next.update_estimate(); - if(next.is_viable()) - new_steps.push_back(next); + unsigned critical_path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path()); + create_successor(next, train_index, critical_path, new_steps); } else { for(unsigned i=0; entry_ep.paths>>i; ++i) if(entry_ep.has_path(i)) - { - train.path = i; - train.update_estimate(); - next.update_estimate(); - if(next.is_viable()) - new_steps.push_back(next); - } + create_successor(next, train_index, i, new_steps); } new_steps.sort(); @@ -557,6 +548,17 @@ void TrainRoutePlanner::RoutingStep::create_successors(list &new_st } } +void TrainRoutePlanner::RoutingStep::create_successor(RoutingStep &next, unsigned train_index, unsigned path, list &new_steps) +{ + TrainRoutingState &train = next.trains[train_index]; + + train.path = path; + train.update_estimate(); + next.update_estimate(); + if(next.is_viable()) + new_steps.push_back(next); +} + bool TrainRoutePlanner::RoutingStep::update_states() { bool changes = false;