address(a),
priority(0),
pending_block(0),
+ reserving(false),
+ advancing(false),
controller(new AIControl(*this, new SimpleController)),
timetable(0),
active(false),
float d = get_real_speed(current_speed)*(dt/Time::sec);
if(ok)
+ {
+ advancing = true;
vehicle.advance(reverse ? -d : d);
+ advancing = false;
+ }
else if(accurate_position)
{
overshoot_dist += d;
j->block->traverse(j->entry, &block_len);
travel_dist += block_len;
- if(j->block->get_sensor_id()==addr)
+ if(j->block->get_sensor_id()==addr && !advancing)
{
const Block::Endpoint &bep = j->block->get_endpoints()[j->entry];
if(reverse)
unsigned pending_addr = pending_block->get_turnout_id();
bool double_addr = (*pending_block->get_tracks().begin())->get_type().is_double_address();
if(addr==pending_addr || (double_addr && addr==pending_addr+1))
- reserve_more();
+ {
+ if(reserving)
+ pending_block = 0;
+ else
+ reserve_more();
+ }
}
}
}
}
+ reserving = true;
+
bool got_more = false;
BlockRef *good = last;
unsigned good_sens = nsens;
if(path!=static_cast<int>(entry_ep.track->get_active_path()))
{
// The turnout is set to wrong path - switch and wait for it
- link->reserve(0);
pending_block = link;
entry_ep.track->set_active_path(path);
- break;
+ if(pending_block)
+ {
+ link->reserve(0);
+ break;
+ }
}
}
last = &rsv_blocks.back();
}
+ reserving = false;
+
// Make any sensorless blocks at the beginning immediately current
list<BlockRef>::iterator i;
for(i=rsv_blocks.begin(); (i!=rsv_blocks.end() && !i->block->get_sensor_id()); ++i) ;
{
/* Sensor ID under axle has changed. Deduce movement direction by using
the sensor ID under the midpoint of the vehicle. */
+ /* XXX This depends on the simulation running fast enough. Something
+ more robust would be preferable. */
unsigned old = sensor;
sensor = s;
unsigned mid = track_pos.track->get_sensor_id();
if(s && s!=mid)
/* There's a sensor and it's different from mid. We've just entered
that sensor. */
- // XXX The Train will reset the vehicles to the start of the sensor, which is somewhat undesirable
layout.get_driver().set_sensor(sensor, true);
if(old && old!=mid)
/* A sensor was under the axle and it was different from mid. We've