]> git.tdb.fi Git - r2c2.git/commitdiff
Utilize maximum speed information in planning routes
authorMikko Rasa <tdb@tdb.fi>
Sat, 29 Mar 2014 13:22:22 +0000 (15:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 29 Mar 2014 13:22:22 +0000 (15:22 +0200)
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index cc69e3c2020bf856cd705200124fe9cff29e1c4a..809bb3e5c665967a9a6d6d890d7eb58f582c6e15 100644 (file)
@@ -1,3 +1,4 @@
+#include "catalogue.h"
 #include "layout.h"
 #include "route.h"
 #include "train.h"
@@ -194,9 +195,14 @@ void TrainRoutePlanner::create_routes(RoutingStep &goal)
 
 TrainRoutePlanner::TrainRoutingInfo::TrainRoutingInfo(Train &t):
        train(&t),
+       speed(train->get_maximum_speed()),
        router(train->get_ai_of_type<TrainRouter>()),
        route(0)
-{ }
+{
+       // If no maximum speed is specified, use a sensible default
+       if(!speed)
+               speed = 20*train->get_layout().get_catalogue().get_scale();
+}
 
 
 TrainRoutePlanner::OccupiedTrack::OccupiedTrack(Track &t, unsigned p, OccupiedTrack *n):
@@ -279,8 +285,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+delay;
+       return ((track->get_type().get_path_length(path)-offset)/info->speed)*Time::sec+delay;
 }
 
 bool TrainRoutePlanner::TrainRoutingState::is_occupied(Track &trk) const
@@ -348,10 +353,7 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
                        i->delay = Time::zero;
                }
                else if(i->state==MOVING)
-               {
-                       float distance = dt/Time::sec;
-                       i->advance(distance);
-               }
+                       i->advance(i->info->speed*(dt/Time::sec));
        }
 }
 
index 21da3bbd2b16d770987da0267e4432c5bfcd6c5b..2ae7dc4ef6e502d6f27f263cb67c24a453321a8d 100644 (file)
@@ -22,6 +22,7 @@ private:
        struct TrainRoutingInfo
        {
                Train *train;
+               float speed;
                TrainRouter *router;
                Route *route;
                std::list<TrainRoutingState *> waits;