1 #ifndef LIBR2C2_VEHICLE_H_
2 #define LIBR2C2_VEHICLE_H_
7 #include "vehicletype.h"
13 class attachment_error: public std::logic_error
16 attachment_error(const std::string &w): std::logic_error(w) { }
17 virtual ~attachment_error() throw() { }
21 class Vehicle: public Object
35 const VehicleType::Axle *type;
38 Axle(const VehicleType::Axle &);
43 const VehicleType::Bogie *type;
45 std::vector<Axle> axles;
47 Bogie(const VehicleType::Bogie &);
52 const VehicleType::Rod *type;
56 Rod(const VehicleType::Rod &);
66 TrackPosition(const TrackIter &, float);
68 TrackPoint get_point() const;
71 const VehicleType &type;
74 TrackPosition track_pos;
75 std::vector<Axle> axles;
76 std::vector<Bogie> bogies;
77 std::vector<Rod> rods;
78 unsigned front_sensor;
82 Vehicle(Layout &, const VehicleType &);
85 virtual Vehicle *clone(Layout * = 0) const;
86 virtual const VehicleType &get_type() const { return type; }
88 void attach_back(Vehicle &);
89 void attach_front(Vehicle &);
92 Vehicle *get_next() const { return next; }
93 Vehicle *get_previous() const { return prev; }
95 // TODO implement these - should call place() with suitable parameters
96 virtual void set_position(const Vector &) { }
97 virtual void set_rotation(const Angle &) { }
98 void place(const TrackIter &, float, PlaceMode = CENTER);
101 const TrackIter &get_track_iter() const { return track_pos.track; }
102 Track *get_track() const { return track_pos.track.track(); }
103 unsigned get_entry() const { return track_pos.track.entry(); }
104 float get_offset() const { return track_pos.offs; }
105 const Axle &get_fixed_axle(unsigned) const;
106 const Bogie &get_bogie(unsigned) const;
107 const Axle &get_bogie_axle(unsigned, unsigned) const;
108 const Rod &get_rod(unsigned) const;
110 void update_position();
111 void update_position_from(const Vehicle &);
112 void propagate_position();
113 void propagate_forward();
114 void propagate_backward();
115 void check_sensor(float, unsigned &);
116 void turn_axles(float);
119 void adjust_for_distance(TrackPosition &, TrackPosition &, float, float = 0.5) const;
120 TrackPoint get_point(const Vector &, const Vector &, float = 0.5) const;
121 TrackPoint get_point(const TrackPosition &, float, float = 0.5) const;
124 virtual unsigned get_n_link_slots() const;
125 virtual Vehicle *get_link(unsigned) const;
126 virtual int get_link_slot(const Object &) const;