X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fengineer%2Ftrainpanel.cpp;h=97592be1bed92dc2547c5fb79ca3eb2399ca38f2;hb=d0af7846e05691d65d8021e46c8f81e8ca05199a;hp=51e7a88fe8e820f54b76e03a1a0f94749c170365;hpb=34f8bf04e4bdffefeceea59b186386b51c542b9d;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 51e7a88..97592be 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" @@ -72,20 +66,27 @@ 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 = dynamic_cast(train.get_tagged_ai("router")); + if(!router) + { + router = new TrainRouter(train); + router->set_tag("router"); + } + + 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(status.get_status()))); lbl_status->set_style("digital"); lbl_status->set_geometry(GLtk::Geometry(10, 60, geom.w-20, 20)); 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]); @@ -283,6 +284,7 @@ void TrainPanel::go_to(Track *track, unsigned) { pick_conn.disconnect(); - if(!train.go_to(*track)) + TrainRouter *router = dynamic_cast(train.get_tagged_ai("router")); + if(!router || !router->go_to(*track)) engineer.set_status("Could not set route"); }