Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
track.cpp
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 
3 #include <algorithm>
4 #include "gfxlib.h"
5 #include "cmd/unit_generic.h"
6 #include "cmd/planet_generic.h"
7 #include "cmd/unit_util.h"
8 #include "track.h"
9 
10 namespace Radar
11 {
12 
13 Track::Track(Unit *player, Unit *target)
14  : player(player),
15  target(target),
16  distance(0.0)
17 {
18  position = player->LocalCoordinates(target);
19  distance = UnitUtil::getDistance(player, target);
20  type = IdentifyType();
21 }
22 
23 Track::Track(Unit *player, Unit *target, const Vector& position)
24  : player(player),
25  target(target),
26  position(position)
27 {
28  distance = UnitUtil::getDistance(player, target);
29  type = IdentifyType();
30 }
31 
32 Track::Track(Unit *player, Unit *target, const Vector& position, float distance)
33  : player(player),
34  target(target),
35  position(position),
36  distance(distance)
37 {
38  type = IdentifyType();
39 }
40 
41 const Vector& Track::GetPosition() const
42 {
43  return position;
44 }
45 
46 float Track::GetDistance() const
47 {
48  return distance;
49 }
50 
52 {
53  return type;
54 }
55 
56 float Track::GetSize() const
57 {
58  assert(target);
59 
60  return target->rSize();
61 }
62 
63 bool Track::IsExploding() const
64 {
65  assert(target);
66 
67  return target->IsExploding();
68 }
69 
71 {
72  assert(IsExploding());
73 
74  return target->ExplodingProgress();
75 }
76 
77 bool Track::HasWeapons() const
78 {
79  assert(target);
80 
81  return (target->GetNumMounts() > 0);
82 }
83 
84 bool Track::HasTurrets() const
85 {
86  assert(target);
87 
88  return !(target->SubUnits.empty());
89 }
90 
91 bool Track::HasActiveECM() const
92 {
93  assert(target);
94 
95  return (UnitUtil::getECM(target) > 0);
96 }
97 
98 bool Track::HasLock() const
99 {
100  assert(player);
101  assert(target);
102 
103  return (player == target->Target());
104 }
105 
107 {
108  assert(target);
109 
110  return (HasLock() && target->TargetLocked());
111 }
112 
114 {
115  assert(target);
116 
117  switch (target->isUnit())
118  {
119  case NEBULAPTR:
120  return Type::Nebula;
121 
122  case PLANETPTR:
123  {
124  Planet *planet = static_cast<Planet *>(target);
125  if (planet->isJumppoint())
126  return Type::JumpPoint;
127 
128  if (planet->hasLights())
129  return Type::Star;
130 
131  if (planet->isAtmospheric())
132  return Type::Planet;
133 
134  return Type::DeadPlanet;
135  }
136  break;
137 
138  case ASTEROIDPTR:
139  return Type::Asteroid;
140 
141  case BUILDINGPTR:
142  // FIXME: Can this ever happen?
143  return Type::Unknown;
144 
145  case UNITPTR:
146  {
147  if (target->IsBase())
148  return Type::Base;
149 
151  return Type::CapitalShip;
152 
153  return Type::Ship;
154  }
155 
156  case ENHANCEMENTPTR:
157  return Type::Cargo;
158 
159  case MISSILEPTR:
160  // FIXME: Is this correct?
162  return Type::Cargo;
163 
164  return Type::Missile;
165 
166  default:
167  assert(false);
168  return Type::Unknown;
169  }
170 }
171 
173 {
174  assert(player);
175  assert(target);
176 
177  const float relation = player->getRelation(target);
178  if (relation > 0)
179  return Relation::Friend;
180 
181  if (relation < 0)
182  return Relation::Enemy;
183 
184  return Relation::Neutral;
185 }
186 
187 } // namespace Radar