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<TrainRouter>()),
has_duration = router->get_trip_duration();
}
+ unsigned n_vehs = train->get_n_vehicles();
+ for(unsigned i=0; i<n_vehs; ++i)
+ length += train->get_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();
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; wp<info->waypoints.size(); ++wp)
{
float distance = info->metrics[wp]->get_distance_from(trk);
if(distance>=0 && distance<remaining_estimate)
- return ((remaining_estimate-distance)/info->speed)*Time::sec+delay;
+ return ((remaining_estimate-distance+info->length)/info->speed)*Time::sec+delay;
}
return Time::day;
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;