FS2_Open
Open source remastering of the Freespace 2 engine
autopilot.h
Go to the documentation of this file.
1 // Autopilot.h
2 // Derek Meek
3 // 4-30-2004
4 
5 
6 
7 #if !defined(_AUTOPILOT_H_)
8 #define _AUTOPILOT_H_
9 
10 #include "globalincs/pstypes.h"
11 #include "object/object.h"
12 
13 #include <map>
14 
15 // milliseconds between updates
16 #define NPS_TICKRATE 125
17 
18 #define MAX_NAVPOINTS 8
19 
20 #define NP_WAYPOINT 0x0001 // Nav Point is bound to the position of a single node of a waypoint path
21 #define NP_SHIP 0x0002 // Nav Point is bound to the position of a certain ship
22 #define NP_HIDDEN 0x0004 // Nav Point doesn't show on map and isn't selectable
23 #define NP_NOACCESS 0x0008 // Nav Point isn't selectable
24 #define NP_VISITED 0x0100 // Whether we've been within 1,000 meters of this waypoint
25 
26 #define NP_NOSELECT ( NP_HIDDEN | NP_NOACCESS )
27 #define NP_VALIDTYPE ( NP_WAYPOINT | NP_SHIP )
28 
29 class NavPoint
30 {
31 public:
32  char m_NavName[32];
33  int flags;
34 
35  void *target_obj;
36  int waypoint_num; //only used when flags & NP_WAYPOINT
37 
38  vec3d *GetPosition();
39  char* GetInternalName();
40 
41  void clear()
42  {
43  m_NavName[0] = 0;
44  flags = 0;
45 
46  target_obj = NULL;
47  waypoint_num = -1;
48  }
49 };
50 
51 
52 #define NP_MSG_FAIL_NOSEL 0
53 #define NP_MSG_FAIL_GLIDING 1
54 #define NP_MSG_FAIL_TOCLOSE 2
55 #define NP_MSG_FAIL_HOSTILES 3
56 #define NP_MSG_MISC_LINKED 4
57 #define NP_MSG_FAIL_HAZARD 5
58 #define NP_MSG_FAIL_SUPPORT_PRESENT 6
59 #define NP_MSG_FAIL_SUPPORT_WORKING 7
60 #define NP_NUM_MESSAGES 8
61 
62 struct NavMessage
63 {
64  char message[256];
65  char filename[256]; // can be ""
66 };
67 
68 extern bool AutoPilotEngaged;
69 extern int CurrentNav;
72 extern int LockAPConv;
74 
75 // Cycles through the NavPoint List
76 bool Sel_NextNav();
77 
78 
79 // Tell us if autopilot is allowed
80 // This needs:
81 // * Nav point selected
82 // * No enemies within AutopilotMinEnemyDistance meters
83 // * No asteroids within AutopilotMinAsteroidDistance meters
84 // * Destination > 1,000 meters away
85 // * Support ship not present or is actively leaving
86 bool CanAutopilot(vec3d targetPos, bool send_msg=false);
87 
88 // Check if autopilot is allowed at player's current position
89 // See CanAutopilot(vec3d, bool) for more information
90 inline bool CanAutopilot(bool send_msg=false) { return CanAutopilot(Player_obj->pos, send_msg); }
91 
92 // Engages autopilot
93 // This does:
94 // * Checks if Autopilot is allowed. See CanAutopilot() for conditions.
95 // * Control switched from player to AI
96 // * Time compression to 32x
97 // * Tell AI to fly to targeted Nav Point (for all nav-status wings/ships)
98 // * Sets max waypoint speed to the best-speed of the slowest ship tagged
99 // Returns false if autopilot cannot be started. True otherwise.
100 bool StartAutopilot();
101 
102 // Disengages autopilot
103 // this does:
104 // * Time compression to 1x
105 // * Delete AI nav goal
106 // * Control switched from AI to player
107 void EndAutoPilot();
108 
109 
110 // Checks for changes every NPS_TICKRATE milliseconds
111 // Checks:
112 // * if we've gotten close enough to a nav point for it to be counted as "Visited"
113 // * If we're current AutoNavigating it checks if we need to autodisengage
114 void NavSystem_Do();
115 
116 
117 // Inits the Nav System
118 void NavSystem_Init();
119 
120 // parse autopilot.tbl
121 void parse_autopilot_table(char *filename);
122 
123 // Finds a Nav point by name
124 int FindNav(char *Nav);
125 
126 // Selects a Nav point by name
127 void SelectNav(char *Nav);
128 
129 // Deselects any navpoint selected.
130 void DeselectNav();
131 
132 // Set A Nav point to "ZERO"
133 void ZeroNav(int i);
134 
135 // Removes a Nav
136 bool DelNavPoint(char *Nav);
137 bool DelNavPoint(int nav);
138 
139 // adds a Nav
140 bool AddNav_Ship(char *Nav, char *TargetName, int flags);
141 bool AddNav_Waypoint(char *Nav, char *WP_Path, int node, int flags);
142 
143 //Change Flags
144 bool Nav_Alt_Flags(char *Nav, int flags);
145 
146 // Sexp Accessors
147 bool Nav_Set_Flag(char *Nav, int flag);
148 bool Nav_UnSet_Flag(char *Nav, int flag);
149 
150 bool Nav_Set_Hidden(char *Nav);
151 bool Nav_Set_NoAccess(char *Nav);
152 bool Nav_Set_Visited(char *Nav);
153 
154 bool Nav_UnSet_Hidden(char *Nav);
155 bool Nav_UnSet_NoAccess(char *Nav);
156 bool Nav_UnSet_Visited(char *Nav);
157 
158 // Useful functions
159 unsigned int DistanceTo(char *nav);
160 unsigned int DistanceTo(int nav);
161 
162 bool IsVisited(char *nav);
163 bool IsVisited(int nav);
164 
165 void send_autopilot_msg(char *msg, char *snd=NULL);
166 void send_autopilot_msgID(int msgid);
167 #endif
168 
void DeselectNav()
Definition: autopilot.cpp:1585
bool Nav_UnSet_Flag(char *Nav, int flag)
Definition: autopilot.cpp:1513
int i
Definition: multi_pxo.cpp:466
int LockAPConv
Definition: autopilot.cpp:50
NavPoint Navs[MAX_NAVPOINTS]
Definition: autopilot.cpp:45
bool StartAutopilot()
Definition: autopilot.cpp:230
int flags
Definition: autopilot.h:33
Definition: pstypes.h:88
int waypoint_num
Definition: autopilot.h:36
bool Nav_Set_Flag(char *Nav, int flag)
Definition: autopilot.cpp:1497
bool AddNav_Waypoint(char *Nav, char *WP_Path, int node, int flags)
Definition: autopilot.cpp:1427
bool Nav_Alt_Flags(char *Nav, int flags)
Definition: autopilot.cpp:1465
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: Glext.h:5156
bool AddNav_Ship(char *Nav, char *TargetName, int flags)
Definition: autopilot.cpp:1384
vec3d pos
Definition: object.h:152
char m_NavName[32]
Definition: autopilot.h:32
int CurrentNav
Definition: autopilot.cpp:43
SCP_map< int, int > autopilot_wings
Definition: autopilot.cpp:57
bool Nav_UnSet_Hidden(char *Nav)
Definition: autopilot.cpp:1553
char * filename
int FindNav(char *Nav)
Definition: autopilot.cpp:1342
void NavSystem_Do()
Definition: autopilot.cpp:1065
void send_autopilot_msg(char *msg, char *snd=NULL)
Definition: autopilot.cpp:1222
bool Nav_UnSet_NoAccess(char *Nav)
Definition: autopilot.cpp:1560
char * GetInternalName()
Definition: autopilot.cpp:125
void NavSystem_Init()
Definition: autopilot.cpp:1252
bool AutoPilotEngaged
Definition: autopilot.cpp:40
unsigned int DistanceTo(char *nav)
Definition: autopilot.cpp:1593
void send_autopilot_msgID(int msgid)
Definition: autopilot.cpp:1213
#define MAX_NAVPOINTS
Definition: autopilot.h:18
vec3d * GetPosition()
Definition: autopilot.cpp:111
void ZeroNav(int i)
bool Sel_NextNav()
Definition: autopilot.cpp:75
GLbitfield flags
Definition: Glext.h:6722
bool Nav_UnSet_Visited(char *Nav)
Definition: autopilot.cpp:1567
void parse_autopilot_table(char *filename)
Definition: autopilot.cpp:1272
bool CanAutopilot(vec3d targetPos, bool send_msg=false)
Definition: autopilot.cpp:151
#define NP_NUM_MESSAGES
Definition: autopilot.h:60
bool Nav_Set_Hidden(char *Nav)
Definition: autopilot.cpp:1530
bool DelNavPoint(char *Nav)
Definition: autopilot.cpp:1355
void * target_obj
Definition: autopilot.h:35
bool Nav_Set_NoAccess(char *Nav)
Definition: autopilot.cpp:1538
bool IsVisited(char *nav)
Definition: autopilot.cpp:1610
object * Player_obj
Definition: object.cpp:56
void clear()
Definition: autopilot.h:41
NavMessage NavMsgs[NP_NUM_MESSAGES]
Definition: autopilot.cpp:46
bool Nav_Set_Visited(char *Nav)
Definition: autopilot.cpp:1545
void SelectNav(char *Nav)
Definition: autopilot.cpp:1574
void EndAutoPilot()
Definition: autopilot.cpp:869
char filename[256]
Definition: autopilot.h:65