]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/train.cpp
New timetable system, which works like an actual timetable
[r2c2.git] / source / libr2c2 / train.cpp
index bb82fe4c34090cf22b53f90cda41aa74478dcc01..34b80ddcc39d213635431e50613ecdce29776d51 100644 (file)
@@ -14,6 +14,7 @@
 #include "route.h"
 #include "simplecontroller.h"
 #include "speedquantizer.h"
+#include "timetable.h"
 #include "trackcircuit.h"
 #include "trackiter.h"
 #include "tracktype.h"
@@ -161,6 +162,18 @@ float Train::get_quantized_speed() const
                return controller->get_speed();
 }
 
+float Train::get_maximum_speed() const
+{
+       float ms = 0;
+       for(vector<Vehicle *>::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
+       {
+               float vms = (*i)->get_type().get_maximum_speed();
+               if(ms<=0 || (vms>0 && vms<ms))
+                       ms = vms;
+       }
+       return ms;
+}
+
 bool Train::get_function(unsigned func) const
 {
        return (functions>>func)&1;
@@ -396,6 +409,12 @@ void Train::save(list<DataFile::Statement> &st) const
                        router->save(ss.sub);
                        st.push_back(ss);
                }
+               else if(Timetable *timetable = dynamic_cast<Timetable *>(*i))
+               {
+                       DataFile::Statement ss("timetable");
+                       timetable->save(ss.sub);
+                       st.push_back(ss);
+               }
        }
 }
 
@@ -565,6 +584,7 @@ Train::Loader::Loader(Train &t):
        add("name",        &Loader::name);
        add("quantized_speed",  &Loader::quantized_speed);
        add("router",      &Loader::router);
+       add("timetable",   &Loader::timetable);
        add("vehicle",     &Loader::vehicle);
 }
 
@@ -600,6 +620,12 @@ void Train::Loader::router()
        load_sub(*rtr);
 }
 
+void Train::Loader::timetable()
+{
+       Timetable *ttbl = new Timetable(obj);
+       load_sub(*ttbl, obj.layout);
+}
+
 void Train::Loader::vehicle(ArticleNumber art_nr)
 {
        const VehicleType &vtype = obj.layout.get_catalogue().get<VehicleType>(art_nr);