]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.h
Add TrackIter and BlockIter classes
[r2c2.git] / source / libmarklin / train.h
index 18ad6a1e1407d807330aedd359e686eb30d2e70a..f267263cb9efbfa22cc804c4eb47c50ea5c972d9 100644 (file)
@@ -12,14 +12,15 @@ 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 ControlModel;
-class LocoType;
 class Route;
 class Timetable;
 class Vehicle;
+class VehicleType;
 
 class Train: public sigc::trackable
 {
@@ -28,10 +29,12 @@ public:
        {
        private:
                Block *prev_block;
+               bool blocks_valid;
 
        public:
                Loader(Train &);
        private:
+               virtual void finish();
                void block(unsigned);
                void block_hint(unsigned);
                void name(const std::string &);
@@ -49,13 +52,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
@@ -67,15 +69,21 @@ private:
                void add(float, float);
        };
 
+       typedef std::list<BlockIter> BlockList;
+
        Layout &layout;
-       const LocoType &loco_type;
+       const VehicleType &loco_type;
        unsigned address;
        std::string name;
+       int priority;
+       const Train *yielding_to;
        std::vector<Vehicle *> vehicles;
-       std::list<BlockRef> cur_blocks;
-       std::list<BlockRef> rsv_blocks;
+       BlockList cur_blocks;
+       BlockList rsv_blocks;
        Block *pending_block;
-       ControlModel *control;
+       bool reserving;
+       bool advancing;
+       Controller *controller;
        Timetable *timetable;
        bool active;
        unsigned current_speed;
@@ -83,8 +91,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;
 
@@ -96,16 +103,22 @@ private:
        float overshoot_dist;
 
 public:
-       Train(Layout &, const LocoType &, unsigned);
+       Train(Layout &, const VehicleType &, unsigned);
        ~Train();
 
        Layout &get_layout() const { return layout; }
-       const LocoType &get_locomotive_type() const { return loco_type; }
+       const VehicleType &get_locomotive_type() const { return loco_type; }
        unsigned get_address() const { return address; }
        void set_name(const std::string &);
        const std::string &get_name() const { return name; }
-       ControlModel &get_control() const { return *control; }
-
+       void set_priority(int);
+       void yield_to(const Train &);
+       int get_priority() const { return priority; }
+       Controller &get_controller() const { return *controller; }
+
+       void add_vehicle(const VehicleType &);
+       void remove_vehicle(unsigned);
+       unsigned get_n_vehicles() const;
        Vehicle &get_vehicle(unsigned);
        const Vehicle &get_vehicle(unsigned) const;
 
@@ -113,16 +126,23 @@ public:
        void set_active(bool);
        void set_function(unsigned, bool);
        float get_control(const std::string &) const;
+       float get_speed() const;
        bool is_active() const { return active; }
        bool get_function(unsigned) const;
        unsigned get_functions() const { return functions; }
 
+       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; }
+       void go_to(Track &);
+       bool divert(Track &);
+       const Route *get_route() const;
        void place(Block &, unsigned);
+       void unplace();
        bool is_placed() const { return !cur_blocks.empty(); }
        bool free_block(Block &);
+       void free_noncritical_blocks();
        int get_entry_to_block(Block &) const;
        float get_reserved_distance() const;
 
@@ -132,6 +152,7 @@ public:
 
        void save(std::list<Msp::DataFile::Statement> &) const;
 private:
+       void control_changed(const Controller::Control &);
        void loco_speed_event(unsigned, unsigned, bool);
        void loco_func_event(unsigned, unsigned, bool);
        void sensor_event(unsigned, bool);
@@ -139,13 +160,17 @@ private:
        void halt_event(bool);
        void block_reserved(const Block &, const Train *);
        unsigned reserve_more();
+       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(BlockList &);
+       void release_blocks(BlockList &, 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 &, Track &, unsigned);
 };
 
 } // namespace Marklin