]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/vehicle.h
Add vehicles
[r2c2.git] / source / libmarklin / vehicle.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_VEHICLE_H_
9 #define LIBMARKLIN_VEHICLE_H_
10
11 #include "geometry.h"
12
13 namespace Marklin {
14
15 class Layout;
16 class Track;
17 class VehicleType;
18
19 class Vehicle
20 {
21 public:
22         enum PlaceMode
23         {
24                 CENTER,
25                 FRONT_AXLE
26         };
27
28 private:
29         struct TrackPosition
30         {
31                 Track *track;
32                 unsigned ep;
33                 float offs;
34
35                 TrackPosition();
36                 TrackPosition(Track *, unsigned, float);
37                 void advance(float);
38                 TrackPoint get_point() const;
39         };
40
41         Layout &layout;
42         const VehicleType &type;
43         Vehicle *next;
44         Vehicle *prev;
45         TrackPosition track_pos;
46         Point position;
47         float direction;
48
49 public:
50         Vehicle(Layout &, const VehicleType &);
51         ~Vehicle();
52
53         const VehicleType &get_type() const { return type; }
54
55         void place(Track *, unsigned, float, PlaceMode = CENTER);
56         void advance(float);
57         Track *get_track() const { return track_pos.track; }
58         const Point &get_position() const { return position; }
59         float get_direction() const { return direction; }
60 private:
61         void update_position();
62         TrackPoint get_position(float, float, const TrackPosition &);
63 };
64
65 } // namespace Marklin
66
67 #endif