]> git.tdb.fi Git - r2c2.git/commitdiff
Tinker with arrival logic
authorMikko Rasa <tdb@tdb.fi>
Tue, 15 Apr 2014 19:20:10 +0000 (22:20 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 15 Apr 2014 19:20:10 +0000 (22:20 +0300)
source/libr2c2/trainrouter.cpp
source/libr2c2/trainrouter.h

index c55105026e3710e859692c934a3a1353f3fb5662..959eba2393df2d3c5443670e239b91e0e449e159 100644 (file)
@@ -15,7 +15,7 @@ namespace R2C2 {
 TrainRouter::TrainRouter(Train &t):
        TrainAI(t),
        priority(0),
-       arriving(0),
+       arrival(ON_THE_WAY),
        destination(0),
        destination_changed(false),
        metrics_stale(false),
@@ -105,6 +105,7 @@ void TrainRouter::route_changed()
 
        if(!already_at_end)
        {
+               arrival = ON_THE_WAY;
                train.stop_at(0);
                train.refresh_blocks_from(*fncb);
        }
@@ -233,13 +234,13 @@ void TrainRouter::tick(const Time::TimeDelta &dt)
                sequence_check_pending = false;
        }
 
-       if(arriving==1 && !train.get_speed())
+       if(arrival==RESERVED_TO_END && !train.get_speed())
        {
                signal_arrived.emit(destination);
                signal_event.emit(Message("arrived", destination));
-               arriving = 2;
+               arrival = ARRIVED;
        }
-       else if(arriving==2 && !train.get_block_allocator().is_active())
+       else if(arrival==ARRIVED && !train.get_block_allocator().is_active())
                set_route(0);
 }
 
@@ -301,6 +302,7 @@ void TrainRouter::block_reserved(Block &block, Train *t)
        if(reserving_route==routes.end() || !(*reserving_route)->has_track(*track))
        {
                reserving_route = routes.begin();
+               arrival = ON_THE_WAY;
                track = t->get_block_allocator().first().track_iter();
                for(; track; track=track.next())
                {
@@ -316,6 +318,7 @@ void TrainRouter::block_reserved(Block &block, Train *t)
        {
                if(!advance_to_track(reserving_route, *track))
                {
+                       arrival = RESERVED_TO_END;
                        train.stop_at(&block);
                        return;
                }
@@ -376,13 +379,6 @@ void TrainRouter::train_advanced(Block &block)
                        }
                }
        }
-
-       if(!routes.empty())
-       {
-               b_iter = b_iter.next();
-               if(b_iter && !is_on_route(*b_iter))
-                       arriving = 1;
-       }
 }
 
 void TrainRouter::create_metrics()
index 27307e7849a885569b358d8bb8f2bcff49f4ac80..589c7297d648858472026be5ef8b42dc1459f948 100644 (file)
@@ -40,6 +40,13 @@ public:
 private:
        typedef std::list<const Route *> RouteList;
 
+       enum ArrivalState
+       {
+               ON_THE_WAY,
+               RESERVED_TO_END,
+               ARRIVED
+       };
+
 public:
        sigc::signal<void, const Route *> signal_route_changed;
        sigc::signal<void, const TrackChain *> signal_arrived;
@@ -49,7 +56,7 @@ private:
        int priority;
        RouteList routes;
        RouteList::iterator reserving_route;
-       unsigned arriving;
+       ArrivalState arrival;
        const TrackChain *destination;
        std::vector<const TrackChain *> waypoints;
        bool destination_changed;