]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.cpp
Remove status from Train and turn it into a TrainAI
[r2c2.git] / source / network / server.cpp
index b3f4662a05079814bb618062245e0a6215ed8b70..df40b3f11ea23d03bf9ca1cb2bb3cdb36b36d6f5 100644 (file)
@@ -77,6 +77,10 @@ void Server::train_added(Train &train)
        pkt.loco_type = train.get_locomotive_type().get_article_number().str();
        pkt.name = train.get_name();
        send(pkt);
+
+       TrainStatus *status = new TrainStatus(train);
+       status->set_tag("server:status");
+       status->signal_changed.connect(sigc::bind<0>(sigc::mem_fun(this, &Server::train_status_changed), sigc::ref(train)));
 }
 
 void Server::train_control_changed(const Train &train, const string &control, float value)
@@ -194,10 +198,11 @@ void Server::Connection::handshake_done()
                        pkt.functions = train.get_functions();
                        comm.send(pkt);
                }
+               if(TrainStatus *status = dynamic_cast<TrainStatus *>(train.get_tagged_ai("server:status")))
                {
                        TrainStatusPacket pkt;
                        pkt.address = train.get_address();
-                       pkt.status = train.get_status();
+                       pkt.status = status->get_status();
                        comm.send(pkt);
                }
                if(train.get_route())