]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.h
Ignore the click that causes manipulator to finish
[r2c2.git] / source / libmarklin / train.h
index f00d0fceec719d37b51242bddb6671394ab1c407..5f852564074f37b5247c29f0e04a8974e569341f 100644 (file)
@@ -12,10 +12,12 @@ Distributed under the GPL
 #include <sigc++/trackable.h>
 #include <msp/time/timestamp.h>
 #include "block.h"
+#include "blockiter.h"
 #include "controller.h"
 
 namespace Marklin {
 
+class ArticleNumber;
 class Route;
 class Timetable;
 class Vehicle;
@@ -40,7 +42,7 @@ public:
                void real_speed(unsigned, float, float);
                void route(const std::string &);
                void timetable();
-               void vehicle(unsigned);
+               void vehicle(ArticleNumber);
        };
 
        sigc::signal<void, const std::string &> signal_name_changed;
@@ -51,13 +53,12 @@ public:
        sigc::signal<void, const std::string &> signal_status_changed;
 
 private:
-       struct BlockRef
+       struct RouteRef
        {
-               Block *block;
-               unsigned entry;
+               const Route *route;
+               unsigned diversion;
 
-               BlockRef(Block *, unsigned);
-               BlockRef next() const;
+               RouteRef(const Route *, unsigned = 0);
        };
 
        struct RealSpeed
@@ -69,6 +70,8 @@ private:
                void add(float, float);
        };
 
+       typedef std::list<BlockIter> BlockList;
+
        Layout &layout;
        const VehicleType &loco_type;
        unsigned address;
@@ -76,8 +79,9 @@ private:
        int priority;
        const Train *yielding_to;
        std::vector<Vehicle *> vehicles;
-       std::list<BlockRef> cur_blocks;
-       std::list<BlockRef> rsv_blocks;
+       BlockList blocks;
+       BlockList::iterator cur_blocks_end;
+       BlockList::iterator clear_blocks_end;
        Block *pending_block;
        bool reserving;
        bool advancing;
@@ -89,8 +93,7 @@ private:
        bool reverse;
        Msp::Time::TimeStamp stop_timeout;
        unsigned functions;
-       const Route *route;
-       const Route *next_route;
+       std::list<RouteRef> routes;
        bool end_of_route;
        std::string status;
 
@@ -133,12 +136,15 @@ public:
        void set_timetable(Timetable *);
        Timetable *get_timetable() { return timetable; }
 
-       void set_route(const Route *);
-       void go_to(const Track &);
-       const Route *get_route() const { return route; }
+       bool set_route(const Route *);
+       bool go_to(Track &);
+       bool divert(Track &);
+       const Route *get_route() const;
        void place(Block &, unsigned);
-       bool is_placed() const { return !cur_blocks.empty(); }
+       void unplace();
+       bool is_placed() const { return !blocks.empty(); }
        bool free_block(Block &);
+       void free_noncritical_blocks();
        int get_entry_to_block(Block &) const;
        float get_reserved_distance() const;
 
@@ -152,18 +158,22 @@ private:
        void loco_speed_event(unsigned, unsigned, bool);
        void loco_func_event(unsigned, unsigned, bool);
        void sensor_event(unsigned, bool);
-       void turnout_event(unsigned, bool);
+       void turnout_path_changed(Track &);
        void halt_event(bool);
        void block_reserved(const Block &, const Train *);
-       unsigned reserve_more();
+       void reserve_more();
+       void check_turnout_paths(bool);
        float get_reserved_distance_until(const Block *, bool) const;
        float get_real_speed(unsigned) const;
        unsigned find_speed(float) const;
        float get_travel_speed() const;
        void set_status(const std::string &);
-       void release_blocks(std::list<BlockRef> &);
-       void release_blocks(std::list<BlockRef> &, std::list<BlockRef>::iterator, std::list<BlockRef>::iterator);
-       void reverse_blocks(std::list<BlockRef> &) const;
+       void release_blocks();
+       void release_blocks(BlockList::iterator, BlockList::iterator);
+       void reverse_blocks(BlockList &) const;
+       bool advance_route(std::list<RouteRef>::iterator &, Track &);
+       Route *create_lead_route(Route *, const Route *);
+       bool is_valid_diversion(const Route &, const TrackIter &);
 };
 
 } // namespace Marklin