- 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());
- train=engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
+ 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(), *dynamic_cast<LocoType *>(i->second), addr);