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
37 const VehicleType::Axle *type;
40 Axle(const VehicleType::Axle &);
45 const VehicleType::Bogie *type;
47 std::vector<Axle *> axles;
49 Bogie(const VehicleType::Bogie &);
54 const VehicleType::Rod *type;
58 Rod(const VehicleType::Rod &);
62 const VehicleType &type;
66 VehiclePlacement placement;
67 std::vector<Axle> axles;
68 std::vector<Axle *> fixed_axles;
69 std::vector<Bogie> bogies;
70 std::vector<Rod> rods;
71 unsigned front_sensor;
75 Vehicle(Layout &, const VehicleType &);
78 virtual Vehicle *clone(Layout * = 0) const;
79 virtual const VehicleType &get_type() const { return type; }
81 void set_train(Train *);
82 Train *get_train() const { return train; }
83 void attach_back(Vehicle &);
84 void attach_front(Vehicle &);
87 Vehicle *get_next() const { return next; }
88 Vehicle *get_previous() const { return prev; }
90 // TODO implement these - should call place() with suitable parameters
91 virtual void set_position(const Vector &) { }
92 virtual void set_rotation(const Angle &) { }
93 virtual void set_tilt(const Angle &) { }
94 void place(const TrackOffsetIter &, VehiclePlacement::Anchor = VehiclePlacement::CENTER);
97 const VehiclePlacement &get_placement() const { return placement; }
98 bool is_placed() const { return placement.is_placed(); }
99 const Axle &get_axle(unsigned) const;
100 const Axle &get_fixed_axle(unsigned) const;
101 const Bogie &get_bogie(unsigned) const;
102 const Axle &get_bogie_axle(unsigned, unsigned) const;
103 const Rod &get_rod(unsigned) const;
105 void update_position(int);
106 void update_position_from(const Vehicle &);
107 void propagate_position();
108 void propagate_forward();
109 void propagate_backward();
110 void check_sensor(const TrackOffsetIter &, unsigned &, bool);
111 void turn_axles(float);
115 virtual unsigned get_n_link_slots() const;
116 virtual Vehicle *get_link(unsigned) const;
117 virtual int get_link_slot(const Object &) const;