]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trainrouteplanner.cpp
Use the TrackChain base class as destination in Router
[r2c2.git] / source / libr2c2 / trainrouteplanner.cpp
index c5455899e6befc6f9f7e7c6830e7234d1357e5f5..a7bb13ee13fa3fc7c0c8852796e4e4ec8266c7d8 100644 (file)
@@ -16,7 +16,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout)
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
                TrainRoutingInfo info(*i->second);
-               if(info.router && info.router->has_destination())
+               if(info.router && info.router->get_destination())
                        routed_trains.push_back(info);
        }
 
@@ -224,7 +224,8 @@ TrainRoutePlanner::OccupiedTrack::~OccupiedTrack()
 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
@@ -269,7 +270,7 @@ TrainRoutePlanner::TrainRoutingState::~TrainRoutingState()
 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
@@ -328,11 +329,20 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
 {
        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