X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=d6066cb1c5a962e489032b4d9d8eda0ef6bbc7d5;hb=54d520566470a4b21b2a6eac3e2943d6305dcfa1;hp=10208bfda73aab3fb974facf08d269eef55dd247;hpb=84f8ba5112467ef87c92953b40ef9b22a6fd28b5;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 10208bf..d6066cb 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,11 +66,15 @@ 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(status.get_status()))); lbl_status->set_style("digital"); @@ -214,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); @@ -283,6 +278,7 @@ void TrainPanel::go_to(Track *track, unsigned) { pick_conn.disconnect(); - if(!train.go_to(*track)) + TrainRouter *router = train.get_ai_of_type(); + if(!router || !router->go_to(*track)) engineer.set_status("Could not set route"); }