X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=e6a91a8f6dc1c2b272fa38adb88c4a3adc62c165;hb=54392d65e2053d1eacb4cfcc435f1013993f2973;hp=813a53417452b43807650df9035e1b2ad34227b3;hpb=d3a7a9e9ad694d52ccca8b6038501772fdc1dfd5;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 813a534..e6a91a8 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -1,15 +1,9 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include -#include +#include #include "libr2c2/aicontrol.h" #include "libr2c2/timetable.h" #include "libr2c2/trackiter.h" +#include "libr2c2/trainrouter.h" #include "libr2c2/vehicletype.h" #include "engineer.h" #include "routeselect.h" @@ -25,6 +19,7 @@ using namespace R2C2; TrainPanel::TrainPanel(Engineer &e, Train &t): engineer(e), train(t), + status(train), expanded(false) { set_size(200, 65); @@ -71,20 +66,24 @@ TrainPanel::TrainPanel(Engineer &e, Train &t): pnl_extra->set_geometry(GLtk::Geometry(0, 10, geom.w, 135)); pnl_extra->set_visible(false); - const Route *route = train.get_route(); + TrainRouter *router = train.get_ai_of_type(); + if(!router) + router = new TrainRouter(train); + + const Route *route = router->get_route(); pnl_extra->add(*(lbl_route = new GLtk::Label((route ? route->get_name() : "Free run")))); lbl_route->set_style("digital"); lbl_route->set_geometry(GLtk::Geometry(10, 85, geom.w-20, 20)); - train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::train_route_changed)); + router->signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::train_route_changed)); - pnl_extra->add(*(lbl_status = new GLtk::Label(train.get_status()))); + pnl_extra->add(*(lbl_status = new GLtk::Label(status.get_status()))); lbl_status->set_style("digital"); lbl_status->set_geometry(GLtk::Geometry(10, 60, geom.w-20, 20)); - train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed)); + status.signal_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed)); - const map &funcs = train.get_locomotive_type().get_functions(); + const VehicleType::FunctionMap &funcs = train.get_locomotive_type().get_functions(); unsigned x = 10; - for(map::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=36) + for(VehicleType::FunctionMap::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=36) { string fname = i->second; fname[0] = toupper(fname[0]); @@ -157,7 +156,7 @@ void TrainPanel::ai_event(const TrainAI::Message &msg) lbl_speed->set_text(format("%3.0f", speed)); } else if(msg.type=="reverse-changed") - tgl_forward->set_value(msg.value.value()); + tgl_forward->set_value(!msg.value.value()); } void TrainPanel::train_function_changed(unsigned func, bool value) @@ -213,12 +212,9 @@ void TrainPanel::goto_clicked() void TrainPanel::timetable_clicked() { - Timetable *timetable = dynamic_cast(train.get_tagged_ai("timetable")); + Timetable *timetable = train.get_ai_of_type(); if(!timetable) - { timetable = new Timetable(train); - timetable->set_tag("timetable"); - } TimetableDialog *dialog = new TimetableDialog(*timetable); engineer.get_root().add(*dialog); @@ -257,31 +253,16 @@ void TrainPanel::place(Track *track, unsigned ep) { pick_conn.disconnect(); - Block &block = track->get_block(); - TrackIter iter(track, ep); - - while(block.has_track(*iter)) - { - const vector &eps = block.get_endpoints(); - bool ok = false; - for(unsigned i=0; (!ok && i(); + if(router) + router->set_destination(track->get_block()); }