]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/train.cpp
Make AIControl states clearer
[r2c2.git] / source / libr2c2 / train.cpp
index ffa436b1d6a0c07795bf876d304077bb08a80fcd..0cbe306234c09b11a9535f1e21fe71673e4bed2e 100644 (file)
@@ -48,6 +48,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p):
        protocol(p),
        priority(0),
        yielding_to(0),
+       preceding_train(0),
        cur_blocks_end(blocks.end()),
        clear_blocks_end(blocks.end()),
        pending_block(0),
@@ -841,6 +842,7 @@ void Train::reserve_more()
        BlockIter start = blocks.back();
 
        pending_block = 0;
+       preceding_train = 0;
 
        // See how many sensor blocks and how much track we already have
        unsigned nsens = 0;
@@ -952,10 +954,15 @@ void Train::reserve_more()
                        bool entry_conflict = (block.entry()==other_exit);
                        bool exit_conflict = (exit==static_cast<unsigned>(other_entry));
                        if(!entry_conflict && !last->get_turnout_id())
+                       {
                                /* The other train is not coming to the blocks we're holding, so we
                                can keep them. */
                                good_end = blocks.end();
 
+                               if(static_cast<unsigned>(other_entry)==block.entry())
+                                       preceding_train = other_train;
+                       }
+
                        int other_prio = other_train->get_priority();
 
                        if(!entry_conflict && !exit_conflict && other_prio<priority)