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<int>(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();
info(&inf),
occupied_tracks(0),
state(MOVING),
- delay(info->router->get_departure_delay())
+ delay(info->router->get_departure_delay()),
+ waypoint(info->router->get_n_waypoints() ? 0 : -1)
{
const Vehicle *veh = &info->train->get_vehicle(0);
// TODO margins
occupied_tracks(other.occupied_tracks),
offset(other.offset),
back_offset(other.back_offset),
- state(other.state)
+ state(other.state),
+ waypoint(other.waypoint)
{
++occupied_tracks->refcount;
}
float back_offset;
TrainState state;
Msp::Time::TimeDelta delay;
+ int waypoint;
TrainRoutingState(TrainRoutingInfo &);
TrainRoutingState(const TrainRoutingState &);
if(!r)
{
destination = 0;
+ waypoints.clear();
}
train.refresh_blocks_from(*fncb);
return false;
}
+void TrainRouter::add_waypoint(const TrackChain &wp)
+{
+ waypoints.push_back(&wp);
+ update_pending = true;
+}
+
+bool TrainRouter::is_waypoint(unsigned index, Track &track) const
+{
+ if(index>=waypoints.size())
+ throw out_of_range("TrainRouter::is_waypoint");
+
+ return waypoints[index]->has_track(track);
+}
+
void TrainRouter::set_departure_delay(const Time::TimeDelta &d)
{
delay = d;
else
set_destination(*msg.value.value<const TrackChain *>());
}
+ else if(msg.type=="add-waypoint")
+ {
+ if(msg.value.check_type<TrackChain *>())
+ add_waypoint(*msg.value.value<TrackChain *>());
+ else
+ add_waypoint(*msg.value.value<const TrackChain *>());
+ }
else if(msg.type=="set-departure-delay")
set_departure_delay(msg.value.value<Time::TimeDelta>());
}
RouteList routes;
unsigned arriving;
const TrackChain *destination;
+ std::vector<const TrackChain *> waypoints;
std::list<Wait> waits;
Msp::Time::TimeDelta delay;
void set_destination(const TrackChain &);
const TrackChain *get_destination() const { return destination; }
bool is_destination(Track &) const;
+ void add_waypoint(const TrackChain &);
+ unsigned get_n_waypoints() const { return waypoints.size(); }
+ bool is_waypoint(unsigned, Track &) const;
void set_departure_delay(const Msp::Time::TimeDelta &);
const Msp::Time::TimeDelta &get_departure_delay() const { return delay; }