X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrain.cpp;h=8e10026f182bee49987318eb0daee177ad679873;hb=b51fbe499f1fd68a1abcbdee913cde1ccb580bca;hp=50ad137723d42ec2a8c10775767a3de92c91d745;hpb=b28062f2dc88e082ee5a28b2e1f7c4c8bd989023;p=r2c2.git diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 50ad137..8e10026 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -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" @@ -58,7 +59,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p): layout.add_train(*this); - layout.get_driver().add_loco(address, protocol, loco_type); + loco_id = layout.get_driver().add_loco(address, protocol, loco_type); layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event)); layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event)); @@ -140,7 +141,7 @@ void Train::set_function(unsigned func, bool state) { if(!loco_type.get_functions().count(func)) throw invalid_argument("Train::set_function"); - layout.get_driver().set_loco_function(address, func, state); + layout.get_driver().set_loco_function(loco_id, func, state); } float Train::get_control(const string &ctrl) const @@ -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::const_iterator i=vehicles.begin(); i!=vehicles.end(); ++i) + { + float vms = (*i)->get_type().get_maximum_speed(); + if(ms<=0 || (vms>0 && vms>func)&1; @@ -317,7 +330,7 @@ void Train::tick(const Time::TimeDelta &dt) bool r = reverse; if(loco_type.get_swap_direction()) r = !r; - driver.set_loco_reverse(address, r); + driver.set_loco_reverse(loco_id, r); allocator.reverse(); last_entry_block = BlockIter(); @@ -329,7 +342,7 @@ void Train::tick(const Time::TimeDelta &dt) if(speed_step!=current_speed_step && !speed_changing && !driver.is_halted() && driver.get_power()) { speed_changing = true; - driver.set_loco_speed(address, speed_step); + driver.set_loco_speed(loco_id, speed_step); pure_speed = false; } @@ -396,6 +409,12 @@ void Train::save(list &st) const router->save(ss.sub); st.push_back(ss); } + else if(Timetable *timetable = dynamic_cast(*i)) + { + DataFile::Statement ss("timetable"); + timetable->save(ss.sub); + st.push_back(ss); + } } } @@ -404,24 +423,24 @@ void Train::control_changed(const Controller::Control &ctrl) signal_control_changed.emit(ctrl.name, ctrl.value); } -void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev) +void Train::loco_speed_event(unsigned id, unsigned speed, bool rev) { - if(addr==address) + if(id==loco_id) { current_speed_step = speed; bool r = reverse; if(loco_type.get_swap_direction()) r = !r; if(rev!=r) - layout.get_driver().set_loco_reverse(address, r); + layout.get_driver().set_loco_reverse(loco_id, r); speed_changing = false; pure_speed = false; } } -void Train::loco_func_event(unsigned addr, unsigned func, bool state) +void Train::loco_func_event(unsigned id, unsigned func, bool state) { - if(addr==address) + if(id==loco_id) { if(state) functions |= 1<is_placed()) @@ -565,6 +587,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 +623,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(art_nr);