1 #ifndef LIBR2C2_VEHICLE_H_
2 #define LIBR2C2_VEHICLE_H_
6 #include "trackoffsetiter.h"
7 #include "vehicleplacement.h"
8 #include "vehicletype.h"
15 class attachment_error: public std::logic_error
18 attachment_error(const std::string &w): std::logic_error(w) { }
19 virtual ~attachment_error() throw() { }
23 class Vehicle: public Object
28 const VehicleType::Axle *type;
31 Axle(const VehicleType::Axle &);
36 const VehicleType::Bogie *type;
38 std::vector<Axle *> axles;
40 Bogie(const VehicleType::Bogie &);
45 const VehicleType::Rod *type;
49 Rod(const VehicleType::Rod &);
53 const VehicleType &type;
57 VehiclePlacement placement;
58 std::vector<Axle> axles;
59 std::vector<Axle *> fixed_axles;
60 std::vector<Bogie> bogies;
61 std::vector<Rod> rods;
62 unsigned front_sensor;
66 Vehicle(Layout &, const VehicleType &);
69 virtual Vehicle *clone(Layout * = 0) const;
70 virtual const VehicleType &get_type() const { return type; }
72 void set_train(Train *);
73 Train *get_train() const { return train; }
74 void attach_back(Vehicle &);
75 void attach_front(Vehicle &);
78 Vehicle *get_next() const { return next; }
79 Vehicle *get_previous() const { return prev; }
81 // TODO implement these - should call place() with suitable parameters
82 virtual void set_position(const Vector &) { }
83 virtual void set_rotation(const Angle &) { }
84 virtual void set_tilt(const Angle &) { }
85 void place(const TrackOffsetIter &, VehiclePlacement::Anchor = VehiclePlacement::CENTER);
88 const VehiclePlacement &get_placement() const { return placement; }
89 bool is_placed() const { return placement.is_placed(); }
90 const Axle &get_axle(unsigned) const;
91 const Axle &get_fixed_axle(unsigned) const;
92 const Bogie &get_bogie(unsigned) const;
93 const Axle &get_bogie_axle(unsigned, unsigned) const;
94 const Rod &get_rod(unsigned) const;
96 void update_position(int);
97 void update_position_from(const Vehicle &);
98 void propagate_position();
99 void propagate_forward();
100 void propagate_backward();
101 void check_sensor(const TrackOffsetIter &, unsigned &, bool);
102 void turn_axles(float);
104 float resolve_rod_constraint(Rod &, const VehicleType::RodConstraint &);
107 virtual unsigned get_n_link_slots() const;
108 virtual Vehicle *get_link(unsigned) const;
109 virtual int get_link_slot(const Object &) const;
111 virtual bool collide_ray(const Ray &, float * = 0) const;