1 #ifndef LIBR2C2_VEHICLE_H_
2 #define LIBR2C2_VEHICLE_H_
6 #include "trackoffsetiter.h"
7 #include "vehicletype.h"
14 class attachment_error: public std::logic_error
17 attachment_error(const std::string &w): std::logic_error(w) { }
18 virtual ~attachment_error() throw() { }
22 class Vehicle: public Object
36 const VehicleType::Axle *type;
39 Axle(const VehicleType::Axle &);
44 const VehicleType::Bogie *type;
46 std::vector<Axle *> axles;
48 Bogie(const VehicleType::Bogie &);
53 const VehicleType::Rod *type;
57 Rod(const VehicleType::Rod &);
61 const VehicleType &type;
65 TrackOffsetIter track;
66 std::vector<Axle> axles;
67 std::vector<Axle *> fixed_axles;
68 std::vector<Bogie> bogies;
69 std::vector<Rod> rods;
70 unsigned front_sensor;
74 Vehicle(Layout &, const VehicleType &);
77 virtual Vehicle *clone(Layout * = 0) const;
78 virtual const VehicleType &get_type() const { return type; }
80 void set_train(Train *);
81 Train *get_train() const { return train; }
82 void attach_back(Vehicle &);
83 void attach_front(Vehicle &);
86 Vehicle *get_next() const { return next; }
87 Vehicle *get_previous() const { return prev; }
89 // TODO implement these - should call place() with suitable parameters
90 virtual void set_position(const Vector &) { }
91 virtual void set_rotation(const Angle &) { }
92 virtual void set_tilt(const Angle &) { }
93 void place(const TrackIter &, float, PlaceMode = CENTER);
96 const TrackOffsetIter &get_track_iter() const { return track; }
97 Track *get_track() const { return track.track(); }
98 unsigned get_entry() const { return track.entry(); }
99 float get_offset() const { return track.offset(); }
100 const Axle &get_axle(unsigned) const;
101 const Axle &get_fixed_axle(unsigned) const;
102 const Bogie &get_bogie(unsigned) const;
103 const Axle &get_bogie_axle(unsigned, unsigned) const;
104 const Rod &get_rod(unsigned) const;
106 void update_position();
107 void update_position_from(const Vehicle &);
108 void propagate_position();
109 void propagate_forward();
110 void propagate_backward();
111 void check_sensor(float, unsigned &);
112 void turn_axles(float);
115 void adjust_for_distance(TrackOffsetIter &, TrackOffsetIter &, float, float = 0.5) const;
116 OrientedPoint get_point(const Vector &, const Vector &, float = 0.5) const;
117 OrientedPoint get_point(const TrackOffsetIter &, float, float = 0.5) const;
120 virtual unsigned get_n_link_slots() const;
121 virtual Vehicle *get_link(unsigned) const;
122 virtual int get_link_slot(const Object &) const;