#include <msp/time/utils.h>
#include "control.h"
#include "except.h"
+#include "layout.h"
#include "route.h"
#include "tracktype.h"
#include "trafficmanager.h"
for(unsigned i=0; i<=14; ++i)
if(real_speed[i].weight)
st.push_back((DataFile::Statement("real_speed"), i, real_speed[i].speed, real_speed[i].weight));
+ if(route)
+ st.push_back((DataFile::Statement("route"), route->get_name()));
+
+ if(!cur_blocks.empty())
+ {
+ list<BlockRef> blocks = cur_blocks;
+ if(loco.get_reverse())
+ reverse_blocks(blocks);
+
+ Block *prev = blocks.front().block->get_endpoints()[blocks.front().entry].link;
+ st.push_back((DataFile::Statement("block_hint"), prev->get_id()));
+
+ for(list<BlockRef>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
+ st.push_back((DataFile::Statement("block"), i->block->get_id()));
+ }
}
void Train::locomotive_reverse_changed(bool)
for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)
i->block->reserve(0);
rsv_blocks.clear();
- cur_blocks.reverse();
- for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
- i->entry = i->block->traverse(i->entry);
+ reverse_blocks(cur_blocks);
reserve_more();
if(cur_track)
blocks.clear();
}
+void Train::reverse_blocks(list<BlockRef> &blocks) const
+{
+ blocks.reverse();
+ for(list<BlockRef>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
+ i->entry = i->block->traverse(i->entry);
+}
+
Train::RealSpeed::RealSpeed():
speed(0),
Train::Loader::Loader(Train &t):
- DataFile::BasicLoader<Train>(t)
+ DataFile::BasicLoader<Train>(t),
+ prev_block(0)
{
+ add("block", &Loader::block);
+ add("block_hint", &Loader::block_hint);
add("name", &Train::name);
add("real_speed", &Loader::real_speed);
+ add("route", &Loader::route);
+}
+
+void Train::Loader::block(unsigned id)
+{
+ Block &blk = obj.trfc_mgr.get_block(id);
+ int entry = -1;
+ if(prev_block)
+ entry = blk.get_endpoint_by_link(*prev_block);
+ if(entry<0)
+ entry = 0;
+
+ blk.reserve(&obj);
+ obj.cur_blocks.push_back(BlockRef(&blk, entry));
+ obj.status = "Stopped";
+ obj.set_position(blk.get_endpoints()[entry]);
+
+ prev_block = &blk;
+}
+
+void Train::Loader::block_hint(unsigned id)
+{
+ prev_block = &obj.trfc_mgr.get_block(id);
}
void Train::Loader::real_speed(unsigned i, float speed, float weight)
obj.real_speed[i].weight = weight;
}
+void Train::Loader::route(const string &n)
+{
+ obj.route = &obj.trfc_mgr.get_layout().get_route(n);
+}
+
} // namespace Marklin