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
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
{
time += dt;
for(vector<TrainRoutingState>::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
float offset;
float back_offset;
TrainState state;
+ Msp::Time::TimeDelta delay;
TrainRoutingState(TrainRoutingInfo &);
TrainRoutingState(const TrainRoutingState &);
return false;
}
+void TrainRouter::set_departure_delay(const Time::TimeDelta &d)
+{
+ delay = d;
+ update_pending = true;
+}
+
void TrainRouter::message(const Message &msg)
{
if(msg.type=="set-route")
else
set_destination(*msg.value.value<const Zone *>());
}
+ else if(msg.type=="set-departure-delay")
+ set_departure_delay(msg.value.value<Time::TimeDelta>());
}
-void TrainRouter::tick(const Time::TimeDelta &)
+void TrainRouter::tick(const Time::TimeDelta &dt)
{
+ if(delay)
+ {
+ delay -= dt;
+ if(delay<=Time::zero)
+ delay = Time::zero;
+ }
+
if(update_pending)
create_plans(train.get_layout());
const Zone *dest_zone;
const Block *dest_block;
std::list<Wait> waits;
+ Msp::Time::TimeDelta delay;
bool update_pending;
void set_destination(const Block &);
bool has_destination() const;
bool is_destination(Track &) const;
+ void set_departure_delay(const Msp::Time::TimeDelta &);
+ const Msp::Time::TimeDelta &get_departure_delay() const { return delay; }
virtual void message(const Message &);
virtual void tick(const Msp::Time::TimeDelta &);