#include <msp/strings/format.h>
+#include "aicontrol.h"
#include "clock.h"
#include "layout.h"
#include "timetable.h"
#include "train.h"
+#include "trainrouter.h"
#include "zone.h"
using namespace std;
current_row(rows.end()),
update_pending(false)
{
+ if(!train.get_ai_of_type<AIControl>())
+ new AIControl(train);
+ if(!train.get_ai_of_type<TrainRouter>())
+ new TrainRouter(train);
+
train.signal_ai_event.connect(sigc::mem_fun(this, &Timetable::event));
}
dt /= clock.get_rate();
train.ai_message(Message("set-departure-delay", dt));
}
+ else if(i->type==THROUGH)
+ train.ai_message(Message("add-waypoint", i->target));
}
}
if(msg.type=="arrived")
{
if(current_row->type==ARRIVE)
+ record_time();
+ update_pending = true;
+ }
+ else if(msg.type=="waypoint-reached")
+ {
+ const TrackChain *wp = msg.value.value<const TrackChain *>();
+ if(current_row->type==THROUGH && current_row->target==wp)
{
- current_row->time = train.get_layout().get_clock().get_current_time();
- unsigned i = distance(rows.begin(), current_row);
- signal_row_modified.emit(i, *current_row);
+ record_time();
+ ++current_row;
}
- update_pending = true;
}
}
+void Timetable::record_time()
+{
+ current_row->time = train.get_layout().get_clock().get_current_time();
+ unsigned i = distance(rows.begin(), current_row);
+ signal_row_modified.emit(i, *current_row);
+}
+
Timetable::Row::Row():
type(ARRIVE),
{
case Timetable::ARRIVE: conv.result("ARRIVE"); return;
case Timetable::DEPART: conv.result("DEPART"); return;
+ case Timetable::THROUGH: conv.result("THROUGH"); return;
default: throw lexical_error(format("conversion of RowType(%d) to string", rt));
}
}
rt = Timetable::ARRIVE;
else if(conv.get()=="DEPART")
rt = Timetable::DEPART;
+ else if(conv.get()=="THROUGH")
+ rt = Timetable::THROUGH;
else
throw lexical_error(format("conversion of '%s' to RowType", conv.get()));
}