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 void place(const TrackIter &, float, PlaceMode = CENTER);
105 const TrackIter &get_track_iter() const { return track_pos.track; }
106 Track *get_track() const { return track_pos.track.track(); }
107 unsigned get_entry() const { return track_pos.track.entry(); }
108 float get_offset() const { return track_pos.offs; }
109 const Axle &get_fixed_axle(unsigned) const;
110 const Bogie &get_bogie(unsigned) const;
111 const Axle &get_bogie_axle(unsigned, unsigned) const;
112 const Rod &get_rod(unsigned) const;
114 void update_position();
115 void update_position_from(const Vehicle &);
116 void propagate_position();
117 void propagate_forward();
118 void propagate_backward();
119 void check_sensor(float, unsigned &);
120 void turn_axles(float);
123 void adjust_for_distance(TrackPosition &, TrackPosition &, float, float = 0.5) const;
124 TrackPoint get_point(const Vector &, const Vector &, float = 0.5) const;
125 TrackPoint get_point(const TrackPosition &, float, float = 0.5) const;
128 virtual unsigned get_n_link_slots() const;
129 virtual Vehicle *get_link(unsigned) const;
130 virtual int get_link_slot(const Object &) const;