TrainRoutePlanner::TrainRoutingState::TrainRoutingState(TrainRoutingInfo &inf):
info(&inf),
occupied_tracks(0),
- state(MOVING)
+ state(MOVING),
+ delay(info->router->get_departure_delay())
{
const Vehicle *veh = &info->train->get_vehicle(0);
// TODO margins
Time::TimeDelta TrainRoutePlanner::TrainRoutingState::get_time_to_next_track() const
{
// TODO Consider the speed of the train
- return (track->get_type().get_path_length(path)-offset)*Time::sec;
+ return (track->get_type().get_path_length(path)-offset)*Time::sec+delay;
}
bool TrainRoutePlanner::TrainRoutingState::is_occupied(Track &trk) const
{
time += dt;
for(vector<TrainRoutingState>::iterator i=trains.begin(); i!=trains.end(); ++i)
- if(i->state==MOVING)
+ {
+ if(i->delay)
+ {
+ i->delay -= dt;
+ if(i->delay>Time::zero)
+ continue;
+ i->delay = Time::zero;
+ }
+ else if(i->state==MOVING)
{
float distance = dt/Time::sec;
i->advance(distance);
}
+ }
}
bool TrainRoutePlanner::RoutingStep::is_goal() const