mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PoliceShip.cpp
Go to the documentation of this file.
1 
6 #include "PoliceShip.h"
7 
8 PoliceShip::PoliceShip(float r, GLuint displayList, std::vector<Vector3> point, PlayerObject* player, float maxSpeed):ForeignSpaceShip(r,displayList)
9 {
10  this->point = point;
11  aim = 0;
12  this->setShoot(false);
13  this->maxSpeed = maxSpeed;
14  this->player = player;
15  this->setPos(point[aim]);
16  this->setSpeed(maxSpeed);
17  m_station_was_hit = false;
18 }
19 
21 {
22 }
23 
25  m_station_was_hit = true;
26 }
27 
28 bool PoliceShip::behindPlayer()
29 {
30  Plane plane = Plane(player->getView(), player->getPos());
31  return ( plane.distance( this->getPos()) < 0);
32 }
33 void PoliceShip::adjust (float t)
34 {
35  if (m_station_was_hit || this->shipWasHitOnce())
36  { // player has shot the ship -> behave like a pirate and chase player
37  Vector3 playerPos = player->getPos();
38  Vector3 myPos = this->getPos();
39 
40  Vector3 desiredView = playerPos - myPos;
41  float distance = desiredView.length();
42 
43  bool behind = this->behindPlayer();
44  float playerSpeed = player->getSpeed();
45 
46  float actualSpeed = this->getSpeed();
47  if (distance < 6)
48  {
49  if (behind) // we are chasing the player
50  this->setSpeed(playerSpeed-0.005); // move slower to get out of range
51  // (or, if playerSpeed negative, move faster backwards)
52  if (!behind) // we are in front of the player
53  this->setSpeed(-playerSpeed-0.005); // our speed must be vise versa
54 
55  this->setShoot(true);
56  }
57  if (distance >=6 && distance <= 8)
58  {
59  if (behind)
60  this->setSpeed( playerSpeed );
61  if (!behind)
62  this->setSpeed( -playerSpeed );
63  this->setShoot(true);
64  }
65  if (distance > 8 && distance <= 15)
66  {
67  if (behind) // we are chasing the player
68  this->setSpeed(playerSpeed+0.005); // move faster to catch him
69  // (or, if playerSpeed negative, move slower backwards)
70  if (!behind) // we are in front of the player
71  this->setSpeed(-playerSpeed+0.005); // our speed must be vise versa
72  this->setShoot(true);
73  }
74  if (distance > 15 && distance <= 250)
75  {
76  this->setSpeed( maxSpeed );
77  if (m_station_was_hit || this->shipWasHitOnce())
78  this->setShoot(true);
79  else
80  this->setShoot(false);
81  }
82 
83  if (distance > 250)
84  {
85  if (m_station_was_hit || this->shipWasHitOnce())
86  {
87  this->setShoot(true);
88  this->setSpeed(maxSpeed);
89  }
90  else
91  {
92  this->setSpeed(0);
93  this->setShoot(false);
94  }
95  }
96 
97  desiredView.normalize();
98  this->setView(desiredView); }
99  else
100  { // guarding something (probably the coriolis station)
101  Vector3 directionToAim = point[aim] - this->getPos();
102  float distanceToAim = directionToAim.length();
103  if (distanceToAim < 0.5)
104  {
105  aim = (aim +1);
106  if (aim >= point.size()) aim = 0;
107  directionToAim = point[aim] - this->getPos();
108  }
109  directionToAim.normalize();
110  this->setView(directionToAim);
111  }
112 
113 }