]> git.tdb.fi Git - r2c2.git/commitdiff
Remember the states of locomotive functions
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 Apr 2015 16:12:35 +0000 (19:12 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 4 Apr 2015 16:12:35 +0000 (19:12 +0300)
source/libr2c2/train.cpp
source/libr2c2/train.h

index b1fbc6a76ebb1bf4ad02f85d981f465fef1a1759..43723779fbb89f2cfba327659f81aa4410883a38 100644 (file)
@@ -417,6 +417,10 @@ void Train::save(list<DataFile::Statement> &st) const
                st.push_back(ss);
        }
 
+       const VehicleType::FunctionMap &func_map = loco_type.get_functions();
+       for(VehicleType::FunctionMap::const_iterator i=func_map.begin(); i!=func_map.end(); ++i)
+               st.push_back((DataFile::Statement("function"), i->first, static_cast<bool>(functions&(1<<i->first))));
+
        // XXX Need more generic way of saving AI state
        for(list<TrainAI *>::const_iterator i=ais.begin(); i!=ais.end(); ++i)
        {
@@ -593,6 +597,7 @@ Train::Loader::Loader(Train &t):
        blocks_valid(true)
 {
        add("blocks",      &Loader::blocks);
+       add("function",    &Loader::function);
        add("name",        &Loader::name);
        add("quantized_speed",  &Loader::quantized_speed);
        add("router",      &Loader::router);
@@ -615,6 +620,11 @@ void Train::Loader::blocks()
        load_sub(obj.allocator);
 }
 
+void Train::Loader::function(unsigned f, bool s)
+{
+       obj.set_function(f, s);
+}
+
 void Train::Loader::name(const string &n)
 {
        obj.set_name(n);
index dff9aae666fa3f301b02bf21203024c578a677dc..9b228c026a791374f26de248f1a04fab3f8e95a4 100644 (file)
@@ -32,6 +32,7 @@ public:
        private:
                virtual void finish();
                void blocks();
+               void function(unsigned, bool);
                void name(const std::string &);
                void quantized_speed();
                void router();