Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_next_track() const
{
- return ((occupied_tracks->path_length-offset)/info->speed)*Time::sec+delay;
+ return ((occupied_tracks->path_length-offset)/info->speed)*Time::sec+delay+estimated_wait;
}
Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_pass(Track &trk) const
{
if(is_occupying(trk))
{
+ if(state==ARRIVED && info->has_duration)
+ return duration;
+
float passed_length = 0;
for(const OccupiedTrack *occ=occupied_tracks; (occ && occ->track!=&trk); occ=occ->next)
passed_length += occ->path_length;
Time::TimeDelta min_dt;
int next_train = -1;
for(unsigned i=0; i<trains.size(); ++i)
+ {
+ Time::TimeDelta dt;
if(trains[i].state==MOVING || (trains[i].state==BLOCKED && prev && prev->trains[i].state==MOVING))
+ dt = trains[i].get_time_to_next_track();
+ else if(trains[i].state==BLOCKED && trains[trains[i].blocked_by].state==ARRIVED)
+ dt = trains[i].estimated_wait;
+ else
+ continue;
+
+ if(dt<min_dt || next_train<0)
{
- Time::TimeDelta dt = trains[i].get_time_to_next_track();
- if(dt<min_dt || next_train<0)
- {
- min_dt = dt;
- next_train = i;
- }
+ min_dt = dt;
+ next_train = i;
}
+ }
return next_train;
}