#include "catalogue.h"
#include "driver.h"
#include "layout.h"
-#include "locotype.h"
#include "route.h"
#include "simplephysics.h"
#include "timetable.h"
#include "tracktype.h"
#include "train.h"
#include "vehicle.h"
+#include "vehicletype.h"
using namespace std;
using namespace Msp;
namespace Marklin {
-Train::Train(Layout &l, const LocoType &t, unsigned a):
+Train::Train(Layout &l, const VehicleType &t, unsigned a):
layout(l),
loco_type(t),
address(a),
accurate_position(false),
overshoot_dist(false)
{
+ if(!loco_type.is_locomotive())
+ throw InvalidParameterValue("Initial vehicle must be a locomotive");
+
vehicles.push_back(new Vehicle(layout, loco_type));
layout.add_train(*this);
priority = p;
}
+void Train::add_vehicle(const VehicleType &vt)
+{
+ Vehicle *veh = new Vehicle(layout, vt);
+ vehicles.back()->attach_back(*veh);
+ vehicles.push_back(veh);
+}
+
+void Train::remove_vehicle(unsigned i)
+{
+ if(i>=vehicles.size())
+ throw InvalidParameterValue("Vehicle index out of range");
+ if(i==0)
+ throw InvalidParameterValue("Can't remove the locomotive");
+ delete vehicles[i];
+ vehicles.erase(vehicles.begin()+i);
+ if(i<vehicles.size())
+ vehicles[i-1]->attach_back(*vehicles[i]);
+}
+
+unsigned Train::get_n_vehicles() const
+{
+ return vehicles.size();
+}
+
Vehicle &Train::get_vehicle(unsigned i)
{
if(i>=vehicles.size())