Pioneer
Sensors.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _SENSORS_H
5 #define _SENSORS_H
6 /*
7  * Ship/station subsystem that holds a list of known contacts
8  * and handles IFF
9  * Some ideas:
10  * - targeting should be lost when going out of range
11  * - don't run radar sweep every frame (more of an optimization than simulation)
12  * - allow "pinned" radar contacts (visible at all ranges, for missions)
13  */
14 #include "Body.h"
15 #include "libs.h"
16 
17 class Body;
18 class HudTrail;
19 class Ship;
20 
21 class Sensors {
22 public:
23  enum IFF {
24  IFF_UNKNOWN, //also applies to inert objects
28  };
29 
33  };
34 
35  struct RadarContact {
36  RadarContact();
37  RadarContact(Body *);
38  ~RadarContact();
41  double distance;
43  bool fresh;
44  };
45 
46  typedef std::list<RadarContact> ContactList;
47 
48  static Color IFFColor(IFF);
49  static bool ContactDistanceSort(const RadarContact &a, const RadarContact &b);
50 
51  Sensors(Ship *owner);
52  Body* ChooseTarget(TargetingCriteria, const Body* oldTarget);
53  IFF CheckIFF(Body *other);
54  const ContactList &GetContacts() { return m_radarContacts; }
55  const ContactList &GetStaticContacts() { return m_staticContacts; }
56  void Update(float time);
57  void UpdateIFF(Body *);
58  void ResetTrails();
59 
60 private:
61  Ship *m_owner;
62  ContactList m_radarContacts;
63  ContactList m_staticContacts; //things we know of regardless of range
64 
65  void PopulateStaticContacts();
66 };
67 
68 #endif
Definition: Body.h:57
Definition: HudTrail.h:22
Definition: Sensors.h:21
Sensors(Ship *owner)
Definition: Sensors.cpp:54
std::list< RadarContact > ContactList
Definition: Sensors.h:46
void UpdateIFF(Body *)
Definition: Sensors.cpp:166
IFF CheckIFF(Body *other)
Definition: Sensors.cpp:94
static bool ContactDistanceSort(const RadarContact &a, const RadarContact &b)
Definition: Sensors.cpp:49
IFF
Definition: Sensors.h:23
@ IFF_NEUTRAL
Definition: Sensors.h:25
@ IFF_UNKNOWN
Definition: Sensors.h:24
@ IFF_HOSTILE
Definition: Sensors.h:27
@ IFF_ALLY
Definition: Sensors.h:26
TargetingCriteria
Definition: Sensors.h:30
@ CYCLE_HOSTILE
Definition: Sensors.h:32
@ TARGET_NEAREST_HOSTILE
Definition: Sensors.h:31
Body * ChooseTarget(TargetingCriteria, const Body *oldTarget)
Definition: Sensors.cpp:59
void ResetTrails()
Definition: Sensors.cpp:177
const ContactList & GetStaticContacts()
Definition: Sensors.h:55
const ContactList & GetContacts()
Definition: Sensors.h:54
void Update(float time)
Definition: Sensors.cpp:113
static Color IFFColor(IFF)
Definition: Sensors.cpp:37
Definition: Ship.h:64
Definition: Color.h:66
Definition: Sensors.h:35
double distance
Definition: Sensors.h:41
RadarContact()
Definition: Sensors.cpp:13
IFF iff
Definition: Sensors.h:42
~RadarContact()
Definition: Sensors.cpp:31
Body * body
Definition: Sensors.h:39
bool fresh
Definition: Sensors.h:43
HudTrail * trail
Definition: Sensors.h:40