X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=a7bb13ee13fa3fc7c0c8852796e4e4ec8266c7d8;hb=a7b4305930090851623da7e02e21650510ce7dae;hp=770c0ea537897a01ee0f3a70ae5418f6aa78927d;hpb=18c529dfdd34e07f4f6021151ddce29fa85437bc;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 770c0ea..a7bb13e 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -16,7 +16,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout) for(map::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); } @@ -157,6 +157,7 @@ void TrainRoutePlanner::create_routes(RoutingStep &goal) { i->route = new Route(i->train->get_layout()); i->route->set_name("Router"); + i->route->set_temporary(true); } for(RoutingStep *i=&goal; i; i=i->prev) @@ -223,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 @@ -268,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 @@ -327,11 +329,20 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt) { time += dt; for(vector::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