]> git.localhorst.tv Git - space.git/blob - src/ai/Autopilot.h
less sucky autopilot
[space.git] / src / ai / Autopilot.h
1 #ifndef SPACE_AUTOPILOT_H_
2 #define SPACE_AUTOPILOT_H_
3
4 #include "../graphics/Vector.h"
5
6
7 namespace space {
8
9 class Camera;
10 class Canvas;
11 class Ship;
12
13 class Autopilot {
14
15 public:
16         Autopilot(Ship &ctrl, const Vector<float> &target);
17
18 public:
19         void Update(float deltaT);
20
21         void Render(Canvas &, const Camera &) const;
22
23 private:
24         // velocity is so small that the next integration makes no difference
25         bool StandingStill() const;
26         // can halt within the current frame
27         bool ReallySlow() const;
28         // can halt within one second
29         bool Slow() const;
30
31         // pointing exactly at target
32         bool FacingTarget() const;
33         // pointing exactly away from target
34         bool FacingOpposite() const;
35         // ship pointing in direction of given normalized vector
36         bool Facing(Vector<float>) const;
37         bool OnTarget() const;
38
39         float Speed() const;
40         float Distance() const;
41         float DistanceToHalt() const;
42         bool ReallyClose() const;
43         bool InBrakingDistance() const;
44         bool FarAway() const;
45
46         float TargetVelAngle() const;
47
48         // point the ship towards the target
49         void FaceTarget();
50         // point ship into direction of given normalized vector
51         void Face(Vector<float>);
52         // stop the ship asap
53         void Halt();
54         // accelerate if it improves moving in given normalized direction
55         void AccelerateAlong(Vector<float>);
56
57 private:
58         Ship *ctrl;
59         const Vector<float> *target;
60
61         float dt;
62
63         Vector<float> dp;
64         float dist;
65         Vector<float> normDP;
66
67         float speed;
68         Vector<float> normVel;
69
70         Vector<float> proj;
71
72 };
73
74 }
75
76 #endif