From: Mikko Rasa Date: Sat, 29 Mar 2014 13:22:22 +0000 (+0200) Subject: Utilize maximum speed information in planning routes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=055d7e80b68c8f77ebf226ffd48c37a7e504940c;p=r2c2.git Utilize maximum speed information in planning routes --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index cc69e3c..809bb3e 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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()), 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)); } } diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index 21da3bb..2ae7dc4 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -22,6 +22,7 @@ private: struct TrainRoutingInfo { Train *train; + float speed; TrainRouter *router; Route *route; std::list waits;