Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SteerAI.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: SteerAI.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Steering (low-level) Artifical Intelligence class
13 */
14 
15 #ifndef SteerAI_h
16 #define SteerAI_h
17 
18 #include "Types.h"
19 #include "SimObject.h"
20 #include "Director.h"
21 #include "Geometry.h"
22 
23 // +--------------------------------------------------------------------+
24 
25 class System;
26 
27 // +--------------------------------------------------------------------+
28 
29 struct Steer
30 {
31  Steer() : yaw(0), pitch(0), roll(0), brake(0), stop(0) { }
32  Steer(double y, double p, double r, double b=0) : yaw(y), pitch(p), roll(r), brake(b), stop(0) { }
33  Steer(const Steer& s) : yaw(s.yaw), pitch(s.pitch), roll(s.roll), brake(s.brake), stop(s.stop) { }
34 
35  Steer& operator = (const Steer& s) { yaw=s.yaw; pitch=s.pitch; roll=s.roll; brake = s.brake; stop = s.stop; return *this; }
36 
37  Steer operator+(const Steer& s) const;
38  Steer operator-(const Steer& s) const;
39  Steer operator*(double f) const;
40  Steer operator/(double f) const;
41 
42  Steer& operator+=(const Steer& s);
43  Steer& operator-=(const Steer& s);
44 
45  double Magnitude() const;
46 
47  void Clear() { yaw=0; pitch=0; roll=0; brake=0; stop=0; }
48 
49  double yaw, pitch, roll;
50  double brake;
51  int stop;
52 };
53 
54 // +--------------------------------------------------------------------+
55 
56 class SteerAI : public Director, public SimObserver
57 {
58 public:
59  enum Type { SEEKER = 1000, FIGHTER, STARSHIP, GROUND };
60 
61  SteerAI(SimObject* self);
62  virtual ~SteerAI();
63 
64  static Director* Create(SimObject*, int type);
65 
66  virtual void SetTarget(SimObject* targ, System* sub=0);
67  virtual SimObject* GetTarget() const { return target; }
68  virtual System* GetSubTarget() const { return subtarget; }
69  virtual void DropTarget(double drop_time=1.5);
70  virtual int Type() const { return ai_type; }
71 
72  virtual bool Update(SimObject* obj);
73  virtual const char* GetObserverName() const;
74 
75  // debug:
76  virtual Point GetObjective() const { return obj_w; }
77  virtual SimObject* GetOther() const { return other; }
78 
79 protected:
80 
81  // accumulate behaviors:
82  virtual void Navigator();
83  virtual int Accumulate(const Steer& steer);
84 
85  // steering functions:
86  virtual Steer Seek(const Point& point);
87  virtual Steer Flee(const Point& point);
88  virtual Steer Avoid(const Point& point, float radius);
89  virtual Steer Evade(const Point& point, const Point& vel);
90 
91  // compute the goal point based on target stats:
92  virtual void FindObjective();
93  virtual Point ClosingVelocity();
94 
95  virtual Point Transform(const Point& pt);
96  virtual Point AimTransform(const Point& pt);
97 
98  int seeking;
99 
100  SimObject* self;
104 
107 
108  double distance;
109  double az[3], el[3];
110 
112  double magnitude;
113  DWORD evade_time;
114 
115  double seek_gain;
116  double seek_damp;
117 
118  int ai_type;
119 };
120 
121 
122 // +--------------------------------------------------------------------+
123 
124 #endif SteerAI_h
125