1 #ifndef LIBR2C2_VEHICLE_H_
2 #define LIBR2C2_VEHICLE_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 &);
67 TrackPosition(const TrackIter &, float);
69 TrackPoint get_point() const;
72 const VehicleType &type;
76 TrackPosition track_pos;
77 std::vector<Axle> axles;
78 std::vector<Bogie> bogies;
79 std::vector<Rod> rods;
80 unsigned front_sensor;
84 Vehicle(Layout &, const VehicleType &);
87 virtual Vehicle *clone(Layout * = 0) const;
88 virtual const VehicleType &get_type() const { return type; }
90 void set_train(Train *);
91 Train *get_train() const { return train; }
92 void attach_back(Vehicle &);
93 void attach_front(Vehicle &);
96 Vehicle *get_next() const { return next; }
97 Vehicle *get_previous() const { return prev; }
99 // TODO implement these - should call place() with suitable parameters
100 virtual void set_position(const Vector &) { }
101 virtual void set_rotation(const Angle &) { }
102 virtual void set_tilt(const Angle &) { }
103 void place(const TrackIter &, float, PlaceMode = CENTER);
106 const TrackIter &get_track_iter() const { return track_pos.track; }
107 Track *get_track() const { return track_pos.track.track(); }
108 unsigned get_entry() const { return track_pos.track.entry(); }
109 float get_offset() const { return track_pos.offs; }
110 const Axle &get_fixed_axle(unsigned) const;
111 const Bogie &get_bogie(unsigned) const;
112 const Axle &get_bogie_axle(unsigned, unsigned) const;
113 const Rod &get_rod(unsigned) const;
115 void update_position();
116 void update_position_from(const Vehicle &);
117 void propagate_position();
118 void propagate_forward();
119 void propagate_backward();
120 void check_sensor(float, unsigned &);
121 void turn_axles(float);
124 void adjust_for_distance(TrackPosition &, TrackPosition &, float, float = 0.5) const;
125 TrackPoint get_point(const Vector &, const Vector &, float = 0.5) const;
126 TrackPoint get_point(const TrackPosition &, float, float = 0.5) const;
129 virtual unsigned get_n_link_slots() const;
130 virtual Vehicle *get_link(unsigned) const;
131 virtual int get_link_slot(const Object &) const;