From: Mikko Rasa Date: Mon, 23 Feb 2015 10:14:58 +0000 (+0200) Subject: Consider train length when calculating wait time estimate X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=54cb832334a83fc266b59e2c9b60ee936db7118f;p=r2c2.git Consider train length when calculating wait time estimate This allows also estimating wait time when a train is blocked. --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 87b7cb5..e42e618 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -237,6 +237,7 @@ void TrainRoutePlanner::finalize_plan() TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t): train(&t), + length(0), speed(train->get_maximum_speed()), first_noncritical(train->get_last_critical_block().next().block()), router(train->get_ai_of_type()), @@ -254,6 +255,10 @@ TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t): has_duration = router->get_trip_duration(); } + unsigned n_vehs = train->get_n_vehicles(); + for(unsigned i=0; iget_vehicle(i).get_type().get_length(); + // If no maximum speed is specified, use a sensible default if(!speed) speed = 20*train->get_layout().get_catalogue().get_scale(); @@ -358,13 +363,18 @@ Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_next_track() c Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_pass(Track &trk) const { if(is_occupying(trk)) - return Time::zero; + { + float passed_length = 0; + for(const OccupiedTrack *occ=occupied_tracks; (occ && occ->track!=&trk); occ=occ->next) + passed_length += occ->path_length; + return (max(info->length-passed_length, 0.0f)/info->speed)*Time::sec+delay; + } for(unsigned wp=waypoint; wpwaypoints.size(); ++wp) { float distance = info->metrics[wp]->get_distance_from(trk); if(distance>=0 && distancespeed)*Time::sec+delay; + return ((remaining_estimate-distance+info->length)/info->speed)*Time::sec+delay; } return Time::day; @@ -622,6 +632,9 @@ bool TrainRoutePlanner::RoutingStep::update_states() if(i->info->first_noncritical->has_track(*next_track)) i->critical = false; + if(i->state!=BLOCKED) + i->estimated_wait = trains[i->blocked_by].get_time_to_pass(*next_track); + /* Trains in the WAITING state will also transition to BLOCKED and then to MOVING when the other train has passed. */ i->state = BLOCKED; diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index 5d52f10..79a6036 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -31,6 +31,7 @@ private: struct TrainRoutingInfo { Train *train; + float length; float speed; Block *first_noncritical; TrainRouter *router;