train.signal_advanced.connect(sigc::mem_fun(this, &Timetable::train_advanced));
train.signal_arrived.connect(sigc::mem_fun(this, &Timetable::train_arrived));
Layout &layout = train.get_layout();
- layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Timetable::sensor_event));
+ layout.signal_block_state_changed.connect(sigc::mem_fun(this, &Timetable::block_state_changed));
layout.signal_block_reserved.connect(sigc::mem_fun(this, &Timetable::block_reserved));
}
set_enabled(false);
break;
case TRAVEL_TO:
- pending_block = &get_sensor(row.get_param<unsigned>(0)).get_block();
- pending_train = &train;
- executing = false;
+ {
+ Block *block = &get_sensor(row.get_param<unsigned>(0)).get_block();
+ if(block->get_train()!=&train || block->get_state()<Block::MAYBE_ACTIVE)
+ {
+ pending_block = block;
+ pending_train = &train;
+ executing = false;
+ }
+ }
break;
case TRAVEL_PAST:
pending_block = &get_turnout(row.get_param<unsigned>(0)).get_block();
}
break;
case WAIT_TRAIN:
- pending_train = &train.get_layout().get_train(row.get_param<unsigned>(0));
- pending_block = &get_sensor(row.get_param<unsigned>(1)).get_block();
- executing = false;
+ {
+ Train *other_train = &train.get_layout().get_train(row.get_param<unsigned>(0));
+ Block *block = &get_sensor(row.get_param<unsigned>(1)).get_block();
+ if(block->get_train()!=other_train || block->get_state()<Block::MAYBE_ACTIVE)
+ {
+ pending_train = other_train;
+ pending_block = block;
+ executing = false;
+ }
+ }
break;
case ARRIVE:
if(!arrived)
return train.get_layout().get_zone(name.substr(0, space), number);
}
-void Timetable::sensor_event(unsigned addr, bool state)
+void Timetable::block_state_changed(Block &block, Block::State state)
{
- if(pending_block && pending_block->get_train()==pending_train && addr==pending_block->get_sensor_id() && state)
+ if(rows.empty() || !enabled)
+ return;
+
+ if(&block==pending_block && block.get_train()==pending_train && state>=Block::MAYBE_ACTIVE)
{
pending_block = 0;
current_row = (current_row+1)%rows.size();
void Timetable::block_reserved(Block &block, Train *trn)
{
+ if(rows.empty() || !enabled)
+ return;
+
if(&block==pending_block && trn==pending_train)
{
Row &row = rows[current_row];
void Timetable::train_advanced(Block &block)
{
+ if(rows.empty() || !enabled)
+ return;
+
Row &row = rows[current_row];
if(row.type==TRAVEL_PAST && &block==pending_block && pending_train)
pending_train = 0;
void Timetable::train_arrived()
{
+ if(rows.empty() || !enabled)
+ return;
+
Row &row = rows[current_row];
if(row.type==ARRIVE)
{
case WAIT_UNTIL:
return format("wait until %d mod %d seconds", get_param<unsigned>(0), get_param<unsigned>(1));
case WAIT_TRAIN:
- return format("wait for train %d at %s", get_param<unsigned>(0), get_param<string>(1));
+ return format("wait for train %d at sensor %d", get_param<unsigned>(0), get_param<unsigned>(1));
case ARRIVE:
return "travel until arrival";
case SPEED:
#include <vector>
#include <sigc++/trackable.h>
#include <msp/datafile/objectloader.h>
+#include "block.h"
#include "trainai.h"
namespace R2C2 {
-class Block;
class Track;
class Train;
class Zone;
Track &get_sensor(unsigned);
Track &get_turnout(unsigned);
Zone &get_zone(const std::string &);
- void sensor_event(unsigned, bool);
+ void block_state_changed(Block &, Block::State);
void block_reserved(Block &, Train *);
void train_advanced(Block &);
void train_arrived();