1 // Copyright © 2008-2021 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
25 		IFF_NEUTRAL,
26 		IFF_ALLY,
27 		IFF_HOSTILE
28 	};
29 
30 	enum TargetingCriteria {
31 		TARGET_NEAREST_HOSTILE
32 	};
33 
34 	struct RadarContact {
35 		RadarContact();
36 		RadarContact(Body *);
37 		~RadarContact();
38 		Body *body;
39 		HudTrail *trail;
40 		double distance;
41 		IFF iff;
42 		bool fresh;
43 	};
44 
45 	typedef std::list<RadarContact> ContactList;
46 
47 	static Color IFFColor(IFF);
48 	static bool ContactDistanceSort(const RadarContact &a, const RadarContact &b);
49 
50 	Sensors(Ship *owner);
51 	bool ChooseTarget(TargetingCriteria);
52 	IFF CheckIFF(Body *other);
GetContacts()53 	const ContactList &GetContacts() { return m_radarContacts; }
GetStaticContacts()54 	const ContactList &GetStaticContacts() { return m_staticContacts; }
55 	void Update(float time);
56 	void UpdateIFF(Body *);
57 	void ResetTrails();
58 
59 private:
60 	Ship *m_owner;
61 	ContactList m_radarContacts;
62 	ContactList m_staticContacts; //things we know of regardless of range
63 
64 	void PopulateStaticContacts();
65 };
66 
67 #endif
68