]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/trainproperties.cpp
Support trains with multiple vehicles
[r2c2.git] / source / engineer / trainproperties.cpp
index 46b9541c4331a7e9e7e951e73a23fa95f8716ffc..96c8313d4800d2809cf5da62021d5f1d9a4ab5a8 100644 (file)
@@ -35,10 +35,13 @@ TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t
        add(*(drp_type=new GLtk::Dropdown(res)));
        drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
 
-       const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
+       const map<unsigned, VehicleType *> &vehs = engineer.get_catalogue().get_vehicles();
        unsigned n = 0;
-       for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n)
+       for(map<unsigned, VehicleType *>::const_iterator i=vehs.begin(); i!=vehs.end(); ++i, ++n)
        {
+               if(!dynamic_cast<LocoType *>(i->second))
+                       continue;
+
                drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
                if(train && i->second==&train->get_locomotive_type())
                        drp_type->set_selected_index(n);
@@ -60,12 +63,20 @@ void TrainProperties::on_ok_clicked()
 {
        if(!train)
        {
-               const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
-               map<unsigned, LocoType *>::const_iterator i = locos.begin();
-               advance(i, drp_type->get_selected_index());
+               const map<unsigned, VehicleType *> &vehs = engineer.get_catalogue().get_vehicles();
+               map<unsigned, VehicleType *>::const_iterator i = vehs.begin();
+               unsigned n = drp_type->get_selected_index();
+               while(!dynamic_cast<LocoType *>(i->second))
+                       ++i;
+               while(n)
+               {
+                       if(dynamic_cast<LocoType *>(i->second))
+                               --n;
+                       ++i;
+               }
 
                unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
-               train = new Train(engineer.get_layout(), *i->second, addr);
+               train = new Train(engineer.get_layout(), *dynamic_cast<LocoType *>(i->second), addr);
        }
 
        train->set_name(ent_name->get_text());