void BlockAllocator::sensor_state_changed(Sensor &sensor, Sensor::State state)
{
- Block *block = 0;
- if(TrackCircuit *tc = dynamic_cast<TrackCircuit *>(&sensor))
- block = &tc->get_block();
- else
- return;
-
- if(block->get_train()!=&train)
+ Block *block = sensor.get_block();
+ if(!block || block->get_train()!=&train)
return;
if(state==Sensor::MAYBE_ACTIVE)
{
if(state==Sensor::ACTIVE)
{
- Block *block = 0;
- if(TrackCircuit *tc = dynamic_cast<TrackCircuit *>(&sensor))
- block = &tc->get_block();
-
+ Block *block = sensor.get_block();
if(block && !block->get_train())
emergency(format("Unreserved sensor %d triggered", sensor.get_address()));
}
namespace R2C2 {
+class Block;
class Layout;
class Sensor: public sigc::trackable
unsigned get_address() const { return address; }
State get_state() const { return state; }
+ virtual Block *get_block() const { return 0; }
void tick(const Msp::Time::TimeDelta &);
public:
TrackCircuit(Layout &, Block &);
- Block &get_block() const { return block; }
+ virtual Block *get_block() const { return █ }
};
} // namespace R2C2
void Train::sensor_state_changed(Sensor &sensor, Sensor::State state)
{
- Block *block = 0;
- if(TrackCircuit *tc = dynamic_cast<TrackCircuit *>(&sensor))
- block = &tc->get_block();
- else
- return;
+ Block *block = sensor.get_block();
- if(block->get_train()==this && state==Sensor::MAYBE_ACTIVE)
+ if(block && block->get_train()==this && state==Sensor::MAYBE_ACTIVE)
{
if(last_entry_block)
{