layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Train::sensor_event));
layout.get_driver().signal_turnout.connect(sigc::mem_fun(this, &Train::turnout_event));
+ layout.get_driver().signal_halt.connect(sigc::mem_fun(this, &Train::halt_event));
+
control->signal_control_changed.connect(signal_control_changed);
}
const VehicleType &vtype = veh.get_type();
Track *track = veh.get_track();
+ if(!track)
+ return 0;
unsigned entry = veh.get_entry();
float result = -vtype.get_length()/2;
result += track->get_type().get_path_length(track->get_active_path());
first = false;
+ if(track->get_type().get_endpoints().size()<2)
+ return result;
+
unsigned exit = track->traverse(entry);
Track *next = track->get_link(exit);
{
overshoot_dist += d;
if(overshoot_dist>40*layout.get_catalogue().get_scale())
+ {
layout.emergency(name+" has not arrived at sensor");
+ accurate_position = false;
+ }
}
}
else if(end_of_route)
set_route(0);
+
+ if(!cur_blocks.empty() && !cur_blocks.front().block->get_sensor_id())
+ {
+ Vehicle &veh = *(reverse ? vehicles.front() : vehicles.back());
+
+ list<BlockRef>::iterator i = cur_blocks.begin();
+ const Block::Endpoint &bep = i->block->get_endpoints()[i->entry];
+
+ Track *track = bep.track;
+ unsigned entry = bep.track_ep;
+
+ bool found = false;
+ float dist = veh.get_offset()-veh.get_type().get_length()/2;
+ while(1)
+ {
+ if(track==veh.get_track())
+ {
+ found = true;
+ break;
+ }
+
+ if(i!=cur_blocks.begin())
+ {
+ float path_len = track->get_type().get_path_length(track->get_active_path());
+ dist += path_len;
+ }
+
+ unsigned exit = track->traverse(entry);
+ Track *next = track->get_link(exit);
+ entry = next->get_endpoint_by_link(*track);
+ track = next;
+
+ if(!i->block->get_tracks().count(track))
+ {
+ ++i;
+ if(i==cur_blocks.end())
+ break;
+ }
+ }
+
+ if(found && i!=cur_blocks.begin() && dist>10*layout.get_catalogue().get_scale())
+ {
+ cur_blocks.front().block->reserve(0);
+ cur_blocks.erase(cur_blocks.begin());
+ }
+ }
}
void Train::save(list<DataFile::Statement> &st) const
}
if(route)
- st.push_back((DataFile::Statement("route"), route->get_name()));
+ {
+ if(!route->is_temporary())
+ st.push_back((DataFile::Statement("route"), route->get_name()));
+ else if(next_route && !next_route->is_temporary())
+ st.push_back((DataFile::Statement("route"), next_route->get_name()));
+ }
if(timetable)
{
if(layout.get_driver().get_sensor(i->block->get_sensor_id()))
break;
else
+ {
end = i;
+ ++end;
+ }
}
if(end!=cur_blocks.begin())
- {
// Free blocks up to the last inactive sensor
- ++end;
release_blocks(cur_blocks, cur_blocks.begin(), end);
- }
}
}
}
}
+void Train::halt_event(bool h)
+{
+ if(h)
+ accurate_position = false;
+}
+
void Train::block_reserved(const Block &block, const Train *train)
{
if(&block==pending_block && !train)
unsigned good_sens = nsens;
while(good_sens<3)
{
+ if(last->block->get_endpoints().size()<2)
+ {
+ good = last;
+ good_sens = nsens;
+ break;
+ }
+
// Traverse to the next block
unsigned exit = last->block->traverse(last->entry);
Block *link = last->block->get_link(exit);