release_blocks(rsv_blocks);
reverse_blocks(cur_blocks);
-
- // XXX Do something about the vehicles
}
void Train::set_function(unsigned func, bool state)
}
cur_blocks.push_back(BlockRef(&block, entry));
- set_position(block.get_endpoints()[entry]);
+ if(reverse)
+ {
+ unsigned exit = block.traverse(entry);
+ const Block::Endpoint &bep = block.get_endpoints()[exit];
+ Track *track = bep.track->get_link(bep.track_ep);
+ unsigned ep = track->get_endpoint_by_link(*bep.track);
+ vehicles.front()->place(track, ep, 0, Vehicle::FRONT_BUFFER);
+ }
+ else
+ {
+ const Block::Endpoint &bep = block.get_endpoints()[entry];
+ vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
+ }
set_status("Stopped");
}
ok = i->block->get_tracks().count(track);
if(ok)
- vehicles[0]->advance(get_real_speed(current_speed)*(dt/Time::sec));
+ {
+ float d = get_real_speed(current_speed)*(dt/Time::sec);
+ vehicles[0]->advance(reverse ? -d : d);
+ }
}
}
travel_dist += block_len;
if(j->block->get_sensor_id()==addr)
- set_position(j->block->get_endpoints()[j->entry]);
+ {
+ const Block::Endpoint &bep = j->block->get_endpoints()[j->entry];
+ if(reverse)
+ {
+ Track *track = bep.track->get_link(bep.track_ep);
+ unsigned ep = track->get_endpoint_by_link(*bep.track);
+ vehicles.back()->place(track, ep, 0, Vehicle::BACK_AXLE);
+ }
+ else
+ vehicles.front()->place(bep.track, bep.track_ep, 0, Vehicle::FRONT_AXLE);
+ }
}
last_entry_time = Time::now();
pure_speed = true;
signal_status_changed.emit(s);
}
-void Train::set_position(const Block::Endpoint &bep)
-{
- vehicles[0]->place(bep.track, bep.track_ep, 0, Vehicle::FRONT_AXLE);
-}
-
void Train::release_blocks(list<BlockRef> &blocks)
{
release_blocks(blocks, blocks.begin(), blocks.end());
blk.reserve(&obj);
obj.cur_blocks.push_back(BlockRef(&blk, entry));
obj.set_status("Stopped");
- obj.set_position(blk.get_endpoints()[entry]);
+ const Block::Endpoint &bep = blk.get_endpoints()[entry];
+ obj.vehicles.back()->place(bep.track, bep.track_ep, 0, Vehicle::BACK_BUFFER);
+
+ if(blk.get_sensor_id())
+ obj.layout.get_driver().set_sensor(blk.get_sensor_id(), true);
prev_block = &blk;
}
void Vehicle::place(Track *t, unsigned e, float o, PlaceMode m)
{
track_pos = TrackPosition(t, e, o);
+
if(m==FRONT_AXLE)
{
float front = type.get_length()/2;
}
track_pos.advance(-front);
}
+ else if(m==FRONT_BUFFER)
+ track_pos.advance(-type.get_length()/2);
+ else if(m==BACK_AXLE)
+ {
+ float back = type.get_length()/2;
+ if(!type.get_axles().empty())
+ back = type.get_axles().back().position;
+ if(!type.get_bogies().empty())
+ {
+ const VehicleType::Bogie &bogie = type.get_bogies().back();
+ back = min(back, bogie.position+bogie.axles.back().position);
+ }
+ track_pos.advance(-back);
+ }
+ else if(m==BACK_BUFFER)
+ track_pos.advance(type.get_length()/2);
+
update_position();
}