]> git.tdb.fi Git - r2c2.git/commitdiff
Use the TrackChain base class as destination in Router
authorMikko Rasa <tdb@tdb.fi>
Sun, 23 Mar 2014 16:48:47 +0000 (18:48 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 26 Mar 2014 00:03:54 +0000 (02:03 +0200)
There's no functional difference between Zones and blocks in this context.
Giving a Route as a destination does not really make sense and may give
unexpected results, but I see no particular reason to exclude them.

source/engineer/routerpanel.cpp
source/libr2c2/timetable.cpp
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouter.cpp
source/libr2c2/trainrouter.h

index 1935bbed1273d6525d5f7a64c4f6b7968c61ed40..d0fea398b2812760d921a811f73a72919ec9e6c9 100644 (file)
@@ -95,7 +95,7 @@ void RouterPanel::button_press(int x, int y, unsigned btn)
                goto_highlight = 0;
 
                if(goto_target && btn==1)
-                       train.ai_message(TrainAI::Message("set-destination-block", goto_target));
+                       train.ai_message(TrainAI::Message("set-destination", goto_target));
        }
 }
 
index f0e49ffb85eac5c0aded58018c5a4c6a289c3490..631f58a0894ec4fa15c8978c8279fbc4f571cb1c 100644 (file)
@@ -150,7 +150,7 @@ void Timetable::update_route()
        {
                if(i->type==ARRIVE)
                {
-                       train.ai_message(Message("set-destination-zone", i->zone));
+                       train.ai_message(Message("set-destination", i->target));
                        break;
                }
                else if(i->type==DEPART)
index 99731c6f45c2068684144dd1e8352f8be7f92b22..a7bb13ee13fa3fc7c0c8852796e4e4ec8266c7d8 100644 (file)
@@ -16,7 +16,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout)
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
                TrainRoutingInfo info(*i->second);
-               if(info.router && info.router->has_destination())
+               if(info.router && info.router->get_destination())
                        routed_trains.push_back(info);
        }
 
index 65a4a24500206cb0286a1f5cb3da4efc22358c7c..b2993ee74ba47d0620234719016ff465f06b7aeb 100644 (file)
@@ -2,9 +2,9 @@
 #include "route.h"
 #include "trackiter.h"
 #include "train.h"
+#include "trackchain.h"
 #include "trainrouteplanner.h"
 #include "trainrouter.h"
-#include "zone.h"
 
 using namespace std;
 using namespace Msp;
@@ -15,8 +15,7 @@ TrainRouter::TrainRouter(Train &t):
        TrainAI(t),
        priority(0),
        arriving(0),
-       dest_zone(0),
-       dest_block(0),
+       destination(0),
        update_pending(false)
 {
        train.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &TrainRouter::block_reserved));
@@ -61,8 +60,7 @@ bool TrainRouter::set_route(const Route *r)
        route, but not when the planner calls this. */
        if(!r)
        {
-               dest_zone = 0;
-               dest_block = 0;
+               destination = 0;
        }
 
        train.refresh_blocks_from(*fncb);
@@ -89,31 +87,16 @@ const Route *TrainRouter::get_route() const
        return routes.front();
 }
 
-void TrainRouter::set_destination(const Zone &zone)
+void TrainRouter::set_destination(const TrackChain &d)
 {
-       dest_zone = &zone;
-       dest_block = 0;
+       destination = &d;
        update_pending = true;
 }
 
-void TrainRouter::set_destination(const Block &block)
-{
-       dest_zone = 0;
-       dest_block = &block;
-       update_pending = true;
-}
-
-bool TrainRouter::has_destination() const
-{
-       return dest_zone || dest_block;
-}
-
 bool TrainRouter::is_destination(Track &track) const
 {
-       if(dest_zone)
-               return dest_zone->has_track(track);
-       else if(dest_block)
-               return dest_block->has_track(track);
+       if(destination)
+               return destination->has_track(track);
        else
                return false;
 }
@@ -135,19 +118,12 @@ void TrainRouter::message(const Message &msg)
        }
        else if(msg.type=="clear-route")
                set_route(0);
-       else if(msg.type=="set-destination-block")
-       {
-               if(msg.value.check_type<Block *>())
-                       set_destination(*msg.value.value<Block *>());
-               else
-                       set_destination(*msg.value.value<const Block *>());
-       }
-       else if(msg.type=="set-destination-zone")
+       else if(msg.type=="set-destination")
        {
-               if(msg.value.check_type<Zone *>())
-                       set_destination(*msg.value.value<Zone *>());
+               if(msg.value.check_type<TrackChain *>())
+                       set_destination(*msg.value.value<TrackChain *>());
                else
-                       set_destination(*msg.value.value<const Zone *>());
+                       set_destination(*msg.value.value<const TrackChain *>());
        }
        else if(msg.type=="set-departure-delay")
                set_departure_delay(msg.value.value<Time::TimeDelta>());
index 28862a221995577d8cb204ca1c546d766fbf8c6b..c518522590bc4fdda11cf330b8a5532ffc4d7d56 100644 (file)
@@ -9,9 +9,8 @@ namespace R2C2 {
 
 class Block;
 class Layout;
-class Route;
 class Track;
-class Zone;
+class TrackChain;
 
 class TrainRouter: public TrainAI
 {
@@ -41,8 +40,7 @@ private:
        int priority;
        RouteList routes;
        unsigned arriving;
-       const Zone *dest_zone;
-       const Block *dest_block;
+       const TrackChain *destination;
        std::list<Wait> waits;
        Msp::Time::TimeDelta delay;
 
@@ -58,9 +56,8 @@ public:
        void add_wait(Block &, Train *);
        const Route *get_route() const;
 
-       void set_destination(const Zone &);
-       void set_destination(const Block &);
-       bool has_destination() const;
+       void set_destination(const TrackChain &);
+       const TrackChain *get_destination() const { return destination; }
        bool is_destination(Track &) const;
        void set_departure_delay(const Msp::Time::TimeDelta &);
        const Msp::Time::TimeDelta &get_departure_delay() const { return delay; }