X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=97f1cf6c8501af801a42b2123768503c929e7b14;hb=44e13f6732f206aa72ff7b001d77fe59bf2830ee;hp=d9eedd2d4daccd0d33224548325c594859c7777a;hpb=cac4176a9685e8b39147d1e18d969b3bee052b03;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index d9eedd2..97f1cf6 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -505,6 +505,16 @@ void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path) offset = 0; } +void TrainRoutePlanner::TrainRoutingState::set_path(unsigned p) +{ + path = p; + OccupiedTrack *next_occ = occupied_tracks->next; + if(!--occupied_tracks->refcount) + delete occupied_tracks; + occupied_tracks = new OccupiedTrack(*track, path, next_occ); + update_estimate(); +} + void TrainRoutePlanner::TrainRoutingState::update_estimate() { TrackIter iter = track.reverse(path); @@ -604,8 +614,7 @@ void TrainRoutePlanner::RoutingStep::create_successor(RoutingStep &next, unsigne { TrainRoutingState &train = next.trains[train_index]; - train.path = path; - train.update_estimate(); + train.set_path(path); next.update_estimate(); if(next.is_viable()) new_steps.push_back(next);