]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/vehicletype.cpp
Add a timetable row type to wait for another train
[r2c2.git] / source / libmarklin / vehicletype.cpp
index dd15b48f964794b2291775f98fae9cb6dadc8d44..639415f640317bc87ad4e2299deb36f7c3198a94 100644 (file)
@@ -14,6 +14,7 @@ namespace Marklin {
 
 VehicleType::VehicleType(unsigned n):
        art_nr(n),
+       locomotive(false),
        length(0),
        width(0),
        height(0)
@@ -26,6 +27,32 @@ unsigned VehicleType::get_max_function() const
        return (--functions.end())->first;
 }
 
+float VehicleType::get_front_axle_offset() const
+{
+       float front = length/2;
+       if(!axles.empty())
+               front = axles.front().position;
+       if(!bogies.empty())
+       {
+               const Bogie &bogie = bogies.front();
+               front = max(front, bogie.position+bogie.axles.front().position);
+       }
+       return front;
+}
+
+float VehicleType::get_back_axle_offset() const
+{
+       float back = -length/2;
+       if(!axles.empty())
+               back = axles.back().position;
+       if(!bogies.empty())
+       {
+               const Bogie &bogie = bogies.back();
+               back = min(back, bogie.position+bogie.axles.back().position);
+       }
+       return back;
+}
+
 
 VehicleType::Axle::Axle():
        position(0),
@@ -92,6 +119,7 @@ void VehicleType::Loader::width(float w)
 VehicleType::Axle::Loader::Loader(Axle &a):
        DataFile::ObjectLoader<Axle>(a)
 {
+       add("object",         &Axle::object);
        add("position",       &Loader::position);
        add("powered",        &Axle::powered);
        add("wheel_diameter", &Loader::wheel_diameter);