1 #ifndef LIBR2C2_VEHICLE_H_
2 #define LIBR2C2_VEHICLE_H_
6 #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 &);
67 TrackPosition(Track *, unsigned, float);
69 TrackPoint get_point() const;
72 const VehicleType &type;
75 TrackPosition track_pos;
76 std::vector<Axle> axles;
77 std::vector<Bogie> bogies;
78 std::vector<Rod> rods;
79 unsigned front_sensor;
83 Vehicle(Layout &, const VehicleType &);
86 virtual Vehicle *clone(Layout * = 0) const;
87 virtual const VehicleType &get_type() const { return type; }
89 void attach_back(Vehicle &);
90 void attach_front(Vehicle &);
93 Vehicle *get_next() const { return next; }
94 Vehicle *get_previous() const { return prev; }
96 // TODO implement these - should call place() with suitable parameters
97 virtual void set_position(const Vector &) { }
98 virtual void set_rotation(float) { }
99 void place(Track &, unsigned, float, PlaceMode = CENTER);
102 Track *get_track() const { return track_pos.track; }
103 unsigned get_entry() const { return track_pos.ep; }
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;
128 virtual bool collide_ray(const Vector &, const Vector &) const { return false; }