X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibr2c2%2Ftrainrouteplanner.cpp;h=cc69e3c2020bf856cd705200124fe9cff29e1c4a;hb=ab92a81163a62348b0f3708ac642e6cfcf64d8d5;hp=770c0ea537897a01ee0f3a70ae5418f6aa78927d;hpb=18c529dfdd34e07f4f6021151ddce29fa85437bc;p=r2c2.git diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index 770c0ea..cc69e3c 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); } @@ -121,13 +121,20 @@ void TrainRoutePlanner::add_steps(RoutingStep &step, unsigned train_index) RoutingStep next(&step); next.advance(dt); TrainRouter &router = *train.info->router; - if(router.is_destination(*train.track) && !router.is_destination(*next_track)) + if(train.waypoint<0 && router.is_destination(*train.track) && !router.is_destination(*next_track)) { next.trains[train_index].state = ARRIVED; new_steps.push_back(next); } else { + if(train.waypoint>=0 && router.is_waypoint(train.waypoint, *train.track) && !router.is_waypoint(train.waypoint, *next_track)) + { + ++next.trains[train_index].waypoint; + if(next.trains[train_index].waypoint>=static_cast(router.get_n_waypoints())) + next.trains[train_index].waypoint = -1; + } + next.trains[train_index].advance_track(0); const TrackType::Endpoint &next_entry_ep = next_track.endpoint(); @@ -157,6 +164,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 +231,9 @@ TrainRoutePlanner::OccupiedTrack::~OccupiedTrack() TrainRoutePlanner::TrainRoutingState::TrainRoutingState(TrainRoutingInfo &inf): info(&inf), occupied_tracks(0), - state(MOVING) + state(MOVING), + delay(info->router->get_departure_delay()), + waypoint(info->router->get_n_waypoints() ? 0 : -1) { const Vehicle *veh = &info->train->get_vehicle(0); // TODO margins @@ -254,7 +264,9 @@ TrainRoutePlanner::TrainRoutingState::TrainRoutingState(const TrainRoutingState occupied_tracks(other.occupied_tracks), offset(other.offset), back_offset(other.back_offset), - state(other.state) + state(other.state), + delay(other.delay), + waypoint(other.waypoint) { ++occupied_tracks->refcount; } @@ -268,7 +280,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 +339,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