]> icculus.org git repositories - taylor/freespace2.git/blob - include/sexp.h
fixed demo dogfight multiplayer mission
[taylor/freespace2.git] / include / sexp.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Source$
11  * $Revision$
12  * $Author$
13  * $Date$
14  *
15  * header for sexpression parsing
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:14  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 40    9/07/99 1:05a Andsager
26  * Added team-score sexp for multi team vs team missions
27  * 
28  * 39    9/02/99 7:06p Dave
29  * Bumped MAX_SEXP_NODES to 2200
30  * 
31  * 38    8/27/99 4:07p Andsager
32  * Add is-ship-visible sexp.  Make ship-vanish sexp SINGLE player only
33  * 
34  * 37    8/24/99 4:25p Andsager
35  * Add ship-vanish sexp
36  * 
37  * 36    8/16/99 10:04p Andsager
38  * Add special-warp-dist and special-warpout-name sexp for Knossos device
39  * warpout.
40  * 
41  * 35    8/09/99 2:00p Dave
42  * 2 new sexpressions.
43  * 
44  * 34    8/02/99 4:26p Dave
45  * Added 2 new sexpressions.
46  * 
47  * 33    7/28/99 1:36p Andsager
48  * Modify cargo1 to include flag CARGO_NO_DEPLETE.  Add sexp
49  * cargo-no-deplete (only for BIG / HUGE).  Modify ship struct to pack
50  * better.
51  * 
52  * 32    7/24/99 4:56p Dave
53  * Added 3 new sexpressions.
54  * 
55  * 31    7/21/99 8:10p Dave
56  * First run of supernova effect.
57  * 
58  * 30    7/20/99 9:19p Andsager
59  * Added facing waypoint sexp
60  * 
61  * 29    7/20/99 9:54a Andsager
62  * Add subsys-set-random sexp
63  * 
64  * 28    7/15/99 9:20a Andsager
65  * FS2_DEMO initial checkin
66  * 
67  * 27    7/13/99 3:37p Andsager
68  * Add secondaries-depleted sexp
69  * 
70  * 26    7/08/99 12:06p Andsager
71  * Add turret-tagged-only and turret-tagged-clear sexp.
72  * 
73  * 25    6/28/99 4:51p Andsager
74  * Add ship-guardian sexp (does not allow ship to be killed)
75  * 
76  * 24    6/23/99 5:51p Andsager
77  * Add waypoint-cap-speed.  Checkin stealth ai - inactive.
78  * 
79  * 23    6/16/99 10:21a Dave
80  * Added send-message-list sexpression.
81  * 
82  * 22    6/01/99 8:35p Dave
83  * Finished lockarm weapons. Added proper supercap weapons/damage. Added
84  * awacs-set-radius sexpression.
85  * 
86  * 21    5/24/99 11:28a Dave
87  * Sexpression for adding/removing ships from the hud escort list.
88  * 
89  * 20    4/28/99 9:33a Andsager
90  * Add turret-free and turret-lock (and -all) sexp.  Stargger start time
91  * of beam weapons beam-free and beam-free-all.
92  * 
93  * 19    4/26/99 2:14p Andsager
94  * Add beam-protect-ship and beam-unprotect-ship sexp.
95  * 
96  * 18    4/23/99 9:45a Andsager
97  * Modify rand_sexp to return the same value each time it is called on a
98  * particular node.  This prevents random time delay defaulting to min.
99  * 
100  * 17    4/02/99 9:55a Dave
101  * Added a few more options in the weapons.tbl for beam weapons. Attempt
102  * at putting "pain" packets into multiplayer.
103  * 
104  * 16    3/20/99 3:46p Dave
105  * Added support for model-based background nebulae. Added 3 new
106  * sexpressions.
107  * 
108  * 15    3/04/99 6:09p Dave
109  * Added in sexpressions for firing beams and checking for if a ship is
110  * tagged.
111  * 
112  * 14    2/26/99 6:01p Andsager
113  * Add sexp has-been-tagged-delay and cap-subsys-cargo-known-delay
114  * 
115  * 13    2/11/99 5:22p Andsager
116  * Fixed bugs, generalized block Sexp_variables
117  * 
118  * 12    2/11/99 2:15p Andsager
119  * Add ship explosion modification to FRED
120  * 
121  * 11    1/25/99 4:29p Andsager
122  * Modify sexp_modify_variable() to handle type string. added quick out
123  * for multiplayer_client
124  * 
125  * 10    1/25/99 8:15a Andsager
126  * Format fix
127  * 
128  * 9     1/25/99 8:14a Andsager
129  * Add sexp_modify_variable().  Changed syntax checking to allow, adding
130  * operator return type ambiguous
131  * 
132  * 8     1/24/99 11:37p Dave
133  * First full rev of beam weapons. Very customizable. Removed some bogus
134  * Int3()'s in low level net code.
135  * 
136  * 7     1/20/99 9:37a Andsager
137  * 
138  * 6     1/19/99 3:57p Andsager
139  * Round 2 of variables
140  * 
141  * 5     1/07/99 1:52p Andsager
142  * Initial check in of Sexp_variables
143  * 
144  * 4     12/15/98 3:59p Dan
145  * DA: bumped sexp nodes to 2000 for dan
146  * 
147  * 3     11/05/98 5:55p Dave
148  * Big pass at reducing #includes
149  * 
150  * 2     10/07/98 10:53a Dave
151  * Initial checkin.
152  * 
153  * 1     10/07/98 10:50a Dave
154  * 
155  * 168   9/17/98 9:25p Dave
156  * _really_ upped max sexp nodes to 1800.
157  * 
158  * 167   9/16/98 6:54p Dave
159  * Upped  max sexpression nodes to 1800 (from 1600). Changed FRED to sort
160  * the ship list box. Added code so that tracker stats are not stored with
161  * only 1 player.
162  * 
163  * 166   9/16/98 10:42a Hoffoss
164  * Added sexp node counting to fsm files for end user designers.
165  * 
166  * 165   4/25/98 7:40p Allender
167  * fixd some small hotkey stuff.  Worked on turret orientation being
168  * correct for multiplayer.  new sexpression called end-campaign will will
169  * end the main campaign
170  * 
171  * 164   4/24/98 4:20p Hoffoss
172  * Made the Cond operator an unlisted operator, as using this in Fred with
173  * the sexp trees will cause them to be generated wrong, and then
174  * FreeSpace would pay the price.
175  * 
176  * 163   4/23/98 5:50p Hoffoss
177  * Added tracking of techroom database list info in pilot files, added
178  * sexp to add more to list, made mouse usable on ship listing in tech
179  * room.
180  * 
181  * 162   4/16/98 4:33p Hoffoss
182  * Added support for detecting instructor terminating training due to
183  * player shooting at him.
184  * 
185  * 161   4/15/98 12:58p Lawrance
186  * increase MAX_SEXP_NODES for demo build, needed since training mission
187  * was added
188  * 
189  * 160   4/14/98 5:46p Hoffoss
190  * Added special-check operator.
191  * 
192  * 159   4/14/98 5:24p Hoffoss
193  * Added a custom operator for training handling for Mike K.
194  * 
195  * 158   4/14/98 11:55a Allender
196  * add end-of-campaign sexpression to allow for mission replay at the end
197  * of campaigns
198  * 
199  * 157   4/09/98 4:32p Hoffoss
200  * Fixed several bugs in debriefing.
201  * 
202  * 156   4/06/98 5:37p Hoffoss
203  * Added sexp tree support to briefings in Fred.
204  * 
205  * 155   4/03/98 2:47p Allender
206  * made directives act different when multiple waves of a wing take a long
207  * time to reappear
208  * 
209  * 154   4/03/98 12:18a Allender
210  * new sexpression to detect departed or destroyed.  optionally disallow
211  * support ships.  Allow docking with escape pods 
212  * 
213  * 153   4/02/98 10:13p Lawrance
214  * increase MAX_SEXP_NODES to 1600
215  * 
216  * 152   4/02/98 6:32p Lawrance
217  * reduce MAX_SEXP_NODES if DEMO defined
218  * 
219  * 151   4/02/98 11:40a Lawrance
220  * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
221  * 
222  * 150   4/01/98 8:30p Mike
223  * Reduce MAX_SHIP_SUBOBJECTS and MAX_SEXP_NODES
224  * 
225  * 149   3/17/98 4:29p Allender
226  * allow the warp broken sexpressions
227  * 
228  * 148   3/15/98 3:41p Allender
229  * new sexpression to gauge whether a ship warped out in proximity of jump
230  * node
231  * 
232  * 147   3/09/98 4:31p Allender
233  * multiplayer secondary weapon changes.  red-alert and cargo-known-delay
234  * sexpressions.  Add time cargo revealed to ship structure
235  * 
236  * 146   3/02/98 9:17p Allender
237  * four new sexpressions:  ships-(in)vulnerable.
238  * percent-ships-(destroyed/departed)
239  * 
240  * 145   2/26/98 10:07p Hoffoss
241  * Rewrote state saving and restoring to fix bugs and simplify the code.
242  * 
243  * 144   2/19/98 4:54p Allender
244  * new sexpression to make ships visible/invisible on players sensors
245  * 
246  * 143   2/10/98 8:58p Allender
247  * added hull damage to set/repair/sabotage subsystem
248  * 
249  * 142   1/30/98 4:23p Hoffoss
250  * Added operators for debriefing checking.
251  * 
252  * 141   1/23/98 4:09p Hoffoss
253  * Added a new operator format type to allow ships that aren't player
254  * ships.  Made sabotage, repair and set-subsys-strength utilize it.
255  * 
256  * 140   1/20/98 4:49p Allender
257  * new sexpression to help AI fire huge secondary weapons
258  * 
259  * 139   1/07/98 2:08p Hoffoss
260  * Moved do-nothing operator so it appears last in the catagory's list.
261  * 
262  * 138   1/07/98 2:02p Johnson
263  * Added do-nothing to change catagory.
264  * 
265  * 137   1/07/98 1:48p Hoffoss
266  * Put do-nothing operator into change catagory so designers can make use
267  * of it.
268  * 
269  * 136   1/05/98 4:26p Allender
270  * added sexpression to flash a hud gauge -- a training only operator
271  * 
272  * 135   1/02/98 4:41p Allender
273  * new sexpressions (not allowed yet) for changing warp status of ships
274  * 
275  * 134   12/19/97 2:59p Allender
276  * more stuff to get persistent ships/weapons across campaign missions
277  * 
278  * 133   12/19/97 12:43p Hoffoss
279  * Changed code to allow counts in directives.
280  * 
281  * 132   12/19/97 12:03p Allender
282  * Added GM_CAMPAIGN_MODE to indicate when player is in a campaign or not.
283  * Started adding FreeSpace support for carrying of ship/weapon types
284  * across missions in a campaign.
285  * 
286  */
287
288 #ifndef _SEXP_H
289 #define _SEXP_H
290
291 #include "cfile.h"
292 #include "ship.h"
293
294 #define OPERATOR_LENGTH 24  // if this ever exceeds TOKEN_LENGTH, let JasonH know!
295 #define TOKEN_LENGTH            32
296
297 #ifdef FS2_DEMO
298         #define MAX_SEXP_NODES  1600
299 #else
300         #define MAX_SEXP_NODES  2200    // Reduced from 2000 to 1200 by MK on 4/1/98.
301                                                                                         //      Most used nodes is 698 in sm1-10a.  Sandeep thinks that's the most complex mission.
302                                                                                         // AL 2-4-98: upped to 1600, btm03 ran out of sexps, since campaign took a bunch
303                                                                                         // DA 12/15 bumped up to 2000 - Dan ran out
304 #endif
305
306 #define MAX_SEXP_VARIABLES 100
307
308 #define MAX_SEXP_TEXT   2000
309 #define MAX_OPERATORS   200  // Yes, this is used, but not by the Sexp code.
310
311 // Operator argument formats (data types of an argument)
312 #define OPF_NONE                                        1  // argument cannot exist at this position if it's this
313 #define OPF_NULL                                        2  // no value.  Can still be used for type matching, however
314 #define OPF_BOOL                                        3
315 #define OPF_NUMBER                              4
316 #define OPF_SHIP                                        5
317 #define OPF_WING                                        6
318 #define OPF_SUBSYSTEM                   7
319 #define OPF_POINT                               8  // either a 3d point in space, or a waypoint name
320 #define OPF_IFF                                 9
321 #define OPF_AI_GOAL                             10              // special to match ai goals
322 #define OPF_DOCKER_POINT                11              // docking point on docker ship
323 #define OPF_DOCKEE_POINT                12              // docking point on dockee ship
324 #define OPF_MESSAGE                             13              // the name (id) of a message in Messages[] array
325 #define OPF_WHO_FROM                    14              // who sent the message -- doesn't necessarily have to be a ship!!!
326 #define OPF_PRIORITY                    15              // priority for messages
327 #define OPF_WAYPOINT_PATH               16              // name of a waypoint
328 #define OPF_POSITIVE                    17              // positive number or zero
329 #define OPF_MISSION_NAME                18              // name of a mission for various mission related things
330 #define OPF_SHIP_POINT                  19              // a waypoint or a ship
331 #define OPF_GOAL_NAME                   20              // name of goal (or maybe event?) from a mission
332 #define OPF_SHIP_WING                   21              // either a ship or wing name (they don't conflict)
333 #define OPF_SHIP_WING_POINT     22              // name of a ship, wing, or a point
334 #define OPF_SHIP_TYPE                   23              // type of ship (fighter/bomber/etc)
335 #define OPF_KEYPRESS                    24              // a default key
336 #define OPF_EVENT_NAME                  25              // name of an event
337 #define OPF_AI_ORDER                    26              // a squadmsg order player can give to a ship
338 #define OPF_SKILL_LEVEL         27              // current skill level of the game
339 #define OPF_MEDAL_NAME                  28              // name of medals
340 #define OPF_WEAPON_NAME         29              // name of a weapon
341 #define OPF_SHIP_CLASS_NAME     30              // name of a ship class
342 #define OPF_HUD_GAUGE_NAME      31              // name of HUD gauge
343 #define OPF_HUGE_WEAPON         32              // name of a secondary bomb type weapon
344 #define OPF_SHIP_NOT_PLAYER     33              // a ship, but not a player ship
345 #define OPF_JUMP_NODE_NAME      34              // name of a jump node
346 #define OPF_VARIABLE_NAME               35              // variable name
347 #define OPF_AMBIGUOUS                   36              // type used with variable
348 #define OPF_AWACS_SUBSYSTEM     37              // an awacs subsystem
349
350 // Operand return types
351 #define OPR_NUMBER              1       // returns number
352 #define OPR_BOOL                        2       // returns true/false value
353 #define OPR_NULL                        3  // doesn't return a value
354 #define OPR_AI_GOAL             4  // is an ai operator (doesn't really return a value, but used for type matching)
355 #define OPR_POSITIVE    5  // returns a non-negative number
356 #define OPR_STRING              6  // not really a return type, but used for type matching.
357 #define OPR_AMBIGUOUS   7       // not really a return type, but used for type matching.
358
359 #define OP_INSERT_FLAG                          0x8000
360 #define OP_REPLACE_FLAG                 0x4000
361 #define OP_NONCAMPAIGN_FLAG             0x2000
362 #define OP_CAMPAIGN_ONLY_FLAG   0x1000
363 #define FIRST_OP                                                0x0100
364 #define OP_CATAGORY_MASK                        0x0f00
365
366 #define OP_CATAGORY_OBJECTIVE   0x0100
367 #define OP_CATAGORY_TIME                        0x0200
368 #define OP_CATAGORY_LOGICAL             0x0300
369 #define OP_CATAGORY_ARITHMETIC  0x0400
370 #define OP_CATAGORY_STATUS              0x0500
371 #define OP_CATAGORY_CHANGE              0x0600
372 #define OP_CATAGORY_CONDITIONAL 0x0700
373 #define OP_CATAGORY_DEBUG                       0x0800
374 #define OP_CATAGORY_AI                          0x0900  // used for AI goals
375 #define OP_CATAGORY_TRAINING            0x0a00
376 #define OP_CATAGORY_UNLISTED            0x0b00
377 #define OP_CATAGORY_GOAL_EVENT  0x0c00
378
379 #define OP_PLUS                                                                 (0x0000 | OP_CATAGORY_ARITHMETIC)
380 #define OP_MINUS                                                                        (0x0001 | OP_CATAGORY_ARITHMETIC)
381 #define OP_MOD                                                                  (0x0002 | OP_CATAGORY_ARITHMETIC)
382 #define OP_MUL                                                                  (0x0003 | OP_CATAGORY_ARITHMETIC)
383 #define OP_DIV                                                                  (0x0004 | OP_CATAGORY_ARITHMETIC)
384 #define OP_RAND                                                                 (0x0005 | OP_CATAGORY_ARITHMETIC)
385
386 #define OP_TRUE                                                                 (0x0000 | OP_CATAGORY_LOGICAL)
387 #define OP_FALSE                                                                        (0x0001 | OP_CATAGORY_LOGICAL)
388 #define OP_AND                                                                  (0x0002 | OP_CATAGORY_LOGICAL)
389 #define OP_AND_IN_SEQUENCE                                      (0x0003 | OP_CATAGORY_LOGICAL)
390 #define OP_OR                                                                           (0x0004 | OP_CATAGORY_LOGICAL)
391 #define OP_EQUALS                                                               (0x0005 | OP_CATAGORY_LOGICAL)
392 #define OP_GREATER_THAN                                         (0x0006 | OP_CATAGORY_LOGICAL)
393 #define OP_LESS_THAN                                                    (0x0007 | OP_CATAGORY_LOGICAL)
394 #define OP_IS_IFF                                                               (0x0008 | OP_CATAGORY_LOGICAL | OP_NONCAMPAIGN_FLAG)
395 #define OP_HAS_TIME_ELAPSED                                     (0x0009 | OP_CATAGORY_LOGICAL | OP_NONCAMPAIGN_FLAG)
396 #define OP_NOT                                                                  (0x000a | OP_CATAGORY_LOGICAL)
397
398 #define OP_GOAL_INCOMPLETE                                      (0x0000 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
399 #define OP_GOAL_TRUE_DELAY                                      (0x0001 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
400 #define OP_GOAL_FALSE_DELAY                                     (0x0002 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
401 #define OP_EVENT_INCOMPLETE                                     (0x0003 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
402 #define OP_EVENT_TRUE_DELAY                                     (0x0004 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
403 #define OP_EVENT_FALSE_DELAY                                    (0x0005 | OP_CATAGORY_GOAL_EVENT | OP_NONCAMPAIGN_FLAG)
404 #define OP_PREVIOUS_EVENT_TRUE                          (0x0006 | OP_CATAGORY_GOAL_EVENT)
405 #define OP_PREVIOUS_EVENT_FALSE                         (0x0007 | OP_CATAGORY_GOAL_EVENT)
406 #define OP_PREVIOUS_GOAL_TRUE                           (0x0009 | OP_CATAGORY_GOAL_EVENT)
407 #define OP_PREVIOUS_GOAL_FALSE                          (0x000a | OP_CATAGORY_GOAL_EVENT)
408
409 #define OP_IS_DESTROYED_DELAY                           (0x0008 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
410 #define OP_IS_SUBSYSTEM_DESTROYED_DELAY (0x0009 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
411 #define OP_IS_DISABLED_DELAY                                    (0x000a | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
412 #define OP_IS_DISARMED_DELAY                                    (0x000b | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
413 #define OP_HAS_DOCKED_DELAY                                     (0x000c | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
414 #define OP_HAS_UNDOCKED_DELAY                           (0x000d | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
415 #define OP_HAS_ARRIVED_DELAY                                    (0x000e | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
416 #define OP_HAS_DEPARTED_DELAY                           (0x000f | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
417 #define OP_WAYPOINTS_DONE_DELAY                         (0x0011 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
418 #define OP_SHIP_TYPE_DESTROYED                          (0x0012 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
419 #define OP_PERCENT_SHIPS_DEPARTED                       (0x0013 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
420 #define OP_PERCENT_SHIPS_DESTROYED                      (0x0014 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
421 #define OP_DEPART_NODE_DELAY                                    (0x0015 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
422 #define OP_DESTROYED_DEPARTED_DELAY             (0x0016 | OP_CATAGORY_OBJECTIVE | OP_NONCAMPAIGN_FLAG)
423
424 #define OP_TIME_SHIP_DESTROYED                          (0x0000 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
425 #define OP_TIME_SHIP_ARRIVED                                    (0x0001 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
426 #define OP_TIME_SHIP_DEPARTED                           (0x0002 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
427 #define OP_TIME_WING_DESTROYED                          (0x0003 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
428 #define OP_TIME_WING_ARRIVED                                    (0x0004 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
429 #define OP_TIME_WING_DEPARTED                           (0x0005 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
430 #define OP_MISSION_TIME                                         (0x0006 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
431 #define OP_TIME_DOCKED                                                  (0x0007 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
432 #define OP_TIME_UNDOCKED                                                (0x0008 | OP_CATAGORY_TIME | OP_NONCAMPAIGN_FLAG)
433
434 #define OP_SHIELDS_LEFT                                         (0x0000 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
435 #define OP_HITS_LEFT                                                    (0x0001 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
436 #define OP_HITS_LEFT_SUBSYSTEM                          (0x0002 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
437 #define OP_DISTANCE                                                             (0x0003 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
438 #define OP_LAST_ORDER_TIME                                      (0x0004 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
439 #define OP_NUM_PLAYERS                                                  (0x0005 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
440 #define OP_SKILL_LEVEL_AT_LEAST                         (0x0006 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
441 #define OP_WAS_PROMOTION_GRANTED                        (0x0008 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
442 #define OP_WAS_MEDAL_GRANTED                                    (0x0009 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
443 #define OP_CARGO_KNOWN_DELAY                                    (0x000a | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
444 #define OP_CAP_SUBSYS_CARGO_KNOWN_DELAY (0x000b | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
445 #define OP_HAS_BEEN_TAGGED_DELAY                        (0x000c | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
446 #define OP_IS_TAGGED                                                    (0x000d | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
447 #define OP_NUM_KILLS                                                    (0x000e | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
448 #define OP_NUM_TYPE_KILLS                                               (0x000f | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
449 #define OP_NUM_CLASS_KILLS                                      (0x0010 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
450 #define  OP_SHIELD_RECHARGE_PCT                         (0x0011 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
451 #define  OP_ENGINE_RECHARGE_PCT                         (0x0012 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
452 #define  OP_WEAPON_RECHARGE_PCT                         (0x0013 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
453 #define OP_SHIELD_QUAD_LOW                                      (0x0014 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
454 #define OP_SECONDARY_AMMO_PCT                           (0x0015 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
455 #define OP_IS_SECONDARY_SELECTED                        (0x0016 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
456 #define OP_IS_PRIMARY_SELECTED                          (0x0017 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
457 #define OP_SPECIAL_WARP_DISTANCE                        (0X0018 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
458 #define OP_IS_SHIP_VISIBLE                                      (0X0019 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
459 #define OP_TEAM_SCORE                                                   (0X0020 | OP_CATAGORY_STATUS | OP_NONCAMPAIGN_FLAG)
460
461
462
463 // conditional sexpressions
464 #define OP_WHEN                                                                 (0x0000 | OP_CATAGORY_CONDITIONAL)
465
466 // sexpressions with side-effects
467 #define OP_CHANGE_IFF                                                   (0x0000 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
468 #define OP_REPAIR_SUBSYSTEM                                     (0x0001 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
469 #define OP_SABOTAGE_SUBSYSTEM                                   (0x0002 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
470 #define OP_SET_SUBSYSTEM_STRNGTH                                (0x0003 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
471 #define OP_PROTECT_SHIP                                                 (0x0004 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
472 #define OP_SEND_MESSAGE                                                 (0x0005 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
473 #define OP_SELF_DESTRUCT                                                (0x0006 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
474 #define OP_CLEAR_GOALS                                                  (0x0007 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
475 #define OP_ADD_GOAL                                                             (0x0008 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
476 #define OP_INVALIDATE_GOAL                                              (0x0009 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
477 #define OP_VALIDATE_GOAL                                                (0x000a | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
478 #define OP_SEND_RANDOM_MESSAGE                          (0x000b | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
479 #define OP_TRANSFER_CARGO                                               (0x000c | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
480 #define OP_EXCHANGE_CARGO                                               (0x000d | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
481 #define OP_UNPROTECT_SHIP                                               (0x000e | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
482 #define OP_GOOD_REARM_TIME                                              (0x0010 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
483 #define OP_BAD_REARM_TIME                                               (0x0011 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
484 #define OP_GRANT_PROMOTION                                              (0x0012 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
485 #define OP_GRANT_MEDAL                                                  (0x0013 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
486 #define OP_ALLOW_SHIP                                                   (0x0014 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
487 #define OP_ALLOW_WEAPON                                                 (0x0015 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
488 #define OP_GOOD_SECONDARY_TIME                          (0x0016 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
489 #define OP_WARP_BROKEN                                                  (0x0017 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
490 #define OP_WARP_NOT_BROKEN                                              (0x0018 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
491 #define OP_WARP_NEVER                                                   (0x0019 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
492 #define OP_WARP_ALLOWED                                                 (0x0020 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
493 #define OP_SHIP_INVISIBLE                                               (0x0021 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
494 #define OP_SHIP_VISIBLE                                                 (0x0022 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
495 #define OP_SHIP_INVULNERABLE                                    (0x0023 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
496 #define OP_SHIP_VULNERABLE                                              (0x0024 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
497 #define OP_RED_ALERT                                                            (0x0025 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
498 #define OP_TECH_ADD_SHIP                                                (0x0026 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
499 #define OP_TECH_ADD_WEAPON                                              (0x0027 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
500 #define OP_END_CAMPAIGN                                                 (0x0028 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
501 #define OP_JETTISON_CARGO                                               (0x0029 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
502 #define OP_MODIFY_VARIABLE                                              (0X0030 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
503 #define OP_NOP                                                                          (0x0031 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
504 #define OP_BEAM_FIRE                                                            (0x0032 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
505 #define OP_BEAM_FREE                                                            (0x0033 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
506 #define OP_BEAM_FREE_ALL                                                (0x0034 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
507 #define OP_BEAM_LOCK                                                            (0x0035 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
508 #define OP_BEAM_LOCK_ALL                                                (0x0036 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
509 #define OP_BEAM_PROTECT_SHIP                                    (0x0037 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
510 #define OP_BEAM_UNPROTECT_SHIP                          (0x0038 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
511 #define OP_TURRET_FREE                                                  (0x0039 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
512 #define OP_TURRET_FREE_ALL                                              (0x0040 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
513 #define OP_TURRET_LOCK                                                  (0x0041 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
514 #define OP_TURRET_LOCK_ALL                                              (0x0042 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
515 #define OP_ADD_REMOVE_ESCORT                                    (0x0043 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
516 #define OP_AWACS_SET_RADIUS                                     (0x0044 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
517 #define OP_SEND_MESSAGE_LIST                                    (0x0045 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
518 #define OP_CAP_WAYPOINT_SPEED                                   (0x0046 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
519 #define OP_SHIP_GUARDIAN                                                (0x0047 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
520 #define OP_SHIP_NO_GUARDIAN                                     (0x0048 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
521 #define OP_TURRET_TAGGED_ONLY_ALL                       (0x0049 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
522 #define OP_TURRET_TAGGED_CLEAR_ALL                      (0x0050 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
523 #define OP_SUBSYS_SET_RANDOM                                    (0x0051 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
524 #define OP_SUPERNOVA_START                                              (0x0052 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
525 #define OP_CARGO_NO_DEPLETE                                     (0x0053 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
526 #define OP_SET_SPECIAL_WARPOUT_NAME                     (0X0054 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
527 #define OP_SHIP_VANISH                                                  (0X0055 | OP_CATAGORY_CHANGE | OP_NONCAMPAIGN_FLAG)
528
529
530 // debugging sexpressions
531 #define OP_INT3                                                                 (0x0000 | OP_CATAGORY_DEBUG)
532
533 // defined for AI goals
534 #define OP_AI_CHASE                                                             (0x0000 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
535 #define OP_AI_DOCK                                                              (0x0001 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
536 #define OP_AI_UNDOCK                                                            (0x0002 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
537 #define OP_AI_WARP_OUT                                                  (0x0003 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
538 #define OP_AI_WAYPOINTS                                                 (0x0004 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
539 #define OP_AI_WAYPOINTS_ONCE                                    (0x0005 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
540 #define OP_AI_DESTROY_SUBSYS                                    (0x0006 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
541 #define OP_AI_DISABLE_SHIP                                              (0x0008 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
542 #define OP_AI_DISARM_SHIP                                               (0x0009 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
543 #define OP_AI_GUARD                                                             (0x000a | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
544 #define OP_AI_CHASE_ANY                                                 (0x000b | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
545 #define OP_AI_EVADE_SHIP                                                (0x000d | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
546 #define OP_AI_STAY_NEAR_SHIP                                    (0x000e | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
547 #define OP_AI_KEEP_SAFE_DISTANCE                                (0x000f | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
548 #define OP_AI_IGNORE                                                            (0x0010 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
549 #define OP_AI_STAY_STILL                                                (0x0011 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
550 #define OP_AI_PLAY_DEAD                                                 (0x0012 | OP_CATAGORY_AI | OP_NONCAMPAIGN_FLAG)
551
552 #define OP_GOALS_ID                                                             (0x0001 | OP_CATAGORY_UNLISTED)
553 #define OP_NEXT_MISSION                                                 (0x0002 | OP_CATAGORY_UNLISTED)         // used in campaign files for branching
554 #define OP_IS_DESTROYED                                                 (0x0003 | OP_CATAGORY_UNLISTED)
555 #define OP_IS_SUBSYSTEM_DESTROYED                       (0x0004 | OP_CATAGORY_UNLISTED)
556 #define OP_IS_DISABLED                                                  (0x0005 | OP_CATAGORY_UNLISTED)
557 #define OP_IS_DISARMED                                                  (0x0006 | OP_CATAGORY_UNLISTED)
558 #define OP_HAS_DOCKED                                                   (0x0007 | OP_CATAGORY_UNLISTED)
559 #define OP_HAS_UNDOCKED                                                 (0x0008 | OP_CATAGORY_UNLISTED)
560 #define OP_HAS_ARRIVED                                                  (0x0009 | OP_CATAGORY_UNLISTED)
561 #define OP_HAS_DEPARTED                                                 (0x000a | OP_CATAGORY_UNLISTED)
562 #define OP_WAYPOINTS_DONE                                               (0x000b | OP_CATAGORY_UNLISTED)
563 #define OP_ADD_SHIP_GOAL                                                (0x000c | OP_CATAGORY_UNLISTED)
564 #define OP_CLEAR_SHIP_GOALS                                     (0x000d | OP_CATAGORY_UNLISTED)
565 #define OP_ADD_WING_GOAL                                                (0x000e | OP_CATAGORY_UNLISTED)
566 #define OP_CLEAR_WING_GOALS                                     (0x000f | OP_CATAGORY_UNLISTED)
567 #define OP_AI_CHASE_WING                                                (0x0010 | OP_CATAGORY_UNLISTED)
568 #define OP_AI_GUARD_WING                                                (0x0011 | OP_CATAGORY_UNLISTED)
569 #define OP_EVENT_TRUE                                                   (0x0012 | OP_CATAGORY_UNLISTED)
570 #define OP_EVENT_FALSE                                                  (0x0013 | OP_CATAGORY_UNLISTED)
571 #define OP_PREVIOUS_GOAL_INCOMPLETE                     (0x0014 | OP_CATAGORY_UNLISTED)
572 #define OP_PREVIOUS_EVENT_INCOMPLETE            (0x0015 | OP_CATAGORY_UNLISTED)
573 #define OP_AI_WARP                                                              (0x0016 | OP_CATAGORY_UNLISTED)
574 #define OP_END_MISSION_DELAY                                    (0x0017 | OP_CATAGORY_UNLISTED)
575 #define OP_IS_CARGO_KNOWN                                               (0x001c | OP_CATAGORY_UNLISTED)
576 #define OP_COND                                                                 (0x001e | OP_CATAGORY_UNLISTED)
577 #define OP_END_OF_CAMPAIGN                                              (0x001f | OP_CATAGORY_UNLISTED)
578
579 #define OP_KEY_PRESSED                                                  (0x0000 | OP_CATAGORY_TRAINING)
580 #define OP_KEY_RESET                                                            (0x0001 | OP_CATAGORY_TRAINING)
581 #define OP_TARGETED                                                             (0x0002 | OP_CATAGORY_TRAINING)
582 #define OP_SPEED                                                                        (0x0003 | OP_CATAGORY_TRAINING)
583 #define OP_FACING                                                                       (0x0004 | OP_CATAGORY_TRAINING)
584 #define OP_ORDER                                                                        (0x0005 | OP_CATAGORY_TRAINING)
585 #define OP_WAYPOINT_MISSED                                              (0x0006 | OP_CATAGORY_TRAINING)
586 #define OP_PATH_FLOWN                                                   (0x0007 | OP_CATAGORY_TRAINING)
587 #define OP_WAYPOINT_TWICE                                               (0x0008 | OP_CATAGORY_TRAINING)
588 #define OP_TRAINING_MSG                                                 (0x0009 | OP_CATAGORY_TRAINING)
589 #define OP_FLASH_HUD_GAUGE                                              (0x000a | OP_CATAGORY_TRAINING)
590 #define OP_SPECIAL_CHECK                                                (0x000b | OP_CATAGORY_TRAINING)
591 #define OP_SECONDARIES_DEPLETED                         (0x000c | OP_CATAGORY_TRAINING)
592 #define OP_FACING2                                                              (0x000d | OP_CATAGORY_TRAINING)
593
594 #define OP_SET_TRAINING_CONTEXT_FLY_PATH        (0x0080 | OP_CATAGORY_TRAINING)
595 #define OP_SET_TRAINING_CONTEXT_SPEED           (0x0081 | OP_CATAGORY_TRAINING)
596
597 // defines for string constants
598 #define SEXP_HULL_STRING                        "Hull"
599
600 // macros for accessing sexpression atoms
601 #define CAR(n)          (Sexp_nodes[n].first)
602 #define CDR(n)          (Sexp_nodes[n].rest)
603 #define CADR(n) (Sexp_nodes[Sexp_nodes[n].rest].first)
604 // #define CTEXT(n)     (Sexp_nodes[n].text)
605 char *CTEXT(int n);
606
607 #define REF_TYPE_SHIP           1
608 #define REF_TYPE_WING           2
609 #define REF_TYPE_PLAYER         3
610 #define REF_TYPE_WAYPOINT       4
611 #define REF_TYPE_PATH           5       // waypoint path
612
613 #define SRC_SHIP_ARRIVAL        0x10000
614 #define SRC_SHIP_DEPARTURE      0x20000
615 #define SRC_WING_ARRIVAL        0x30000
616 #define SRC_WING_DEPARTURE      0x40000
617 #define SRC_EVENT                               0x50000
618 #define SRC_MISSION_GOAL        0x60000
619 #define SRC_SHIP_ORDER          0x70000
620 #define SRC_WING_ORDER          0x80000
621 #define SRC_DEBRIEFING          0x90000
622 #define SRC_BRIEFING                    0xa0000
623 #define SRC_UNKNOWN                     0xffff0000
624 #define SRC_MASK                                0xffff0000
625 #define SRC_DATA_MASK           0xffff
626
627 #define SEXP_MODE_GENERAL       0
628 #define SEXP_MODE_CAMPAIGN      1
629
630 // defines for type field of sexp nodes.  The actual type of the node will be stored in the lower
631 // two bytes of the field.  The upper two bytes will be used for flags (bleah...)
632 // Be sure not to conflict with type field of sexp_variable
633 #define SEXP_NOT_USED           0
634 #define SEXP_LIST                               1
635 #define SEXP_ATOM                               2
636
637 // flags for sexpressions -- masked onto the end of the type field
638 #define SEXP_FLAG_PERSISTENT            (1<<31)         // should this sexp node be persistant across missions
639 #define SEXP_FLAG_VARIABLE                      (1<<30)
640
641 // sexp variable definitions
642 #define SEXP_VARIABLE_CHAR                              ('@')
643 // defines for type field of sexp_variable.  Be sure not to conflict with type field of sexp_node
644 #define SEXP_VARIABLE_NUMBER                    (0x0010)
645 #define SEXP_VARIABLE_STRING                    (0x0020)
646 #define SEXP_VARIABLE_UNKNOWN                   (0x0040)
647 #define SEXP_VARIABLE_NOT_USED          (0x0080)
648
649 #define SEXP_VARIABLE_BLOCK                     (0X0001)
650 #define SEXP_VARIABLE_BLOCK_EXP         (0X0002)
651
652 #define BLOCK_EXP_SIZE                                  6
653 #define INNER_RAD                                                       0
654 #define OUTER_RAD                                                       1
655 #define DAMAGE                                                          2
656 #define BLAST                                                           3
657 #define PROPAGATE                                                       4
658 #define SHOCK_SPEED                                             5
659
660
661 #define SEXP_VARIABLE_SET                               (0x0100)
662 #define SEXP_VARIABLE_MODIFIED          (0x0200)
663
664 #define SEXP_TYPE_MASK(t)       (t & 0x00ff)
665 #define SEXP_NODE_TYPE(n)       (Sexp_nodes[n].type & 0x00ff)
666
667 // defines for subtypes of atoms
668 #define SEXP_ATOM_LIST                  0
669 #define SEXP_ATOM_OPERATOR              1
670 #define SEXP_ATOM_NUMBER                2
671 #define SEXP_ATOM_STRING                3
672
673 // defines to short circuit evaluation when possible. Also used then goals can't
674 // be satisfied yet because ship (or wing) hasn't been created yet.
675
676 #define SEXP_TRUE                               1
677 #define SEXP_FALSE                      0
678 #define SEXP_KNOWN_FALSE        -1
679 #define SEXP_KNOWN_TRUE         -2
680 #define SEXP_UNKNOWN                    -3
681 #define SEXP_NAN                                -4  // not a number -- used when ships/wing part of boolean and haven't arrived yet
682 #define SEXP_NAN_FOREVER        -5  // not a number and will never change -- used to falsify boolean sexpressions
683 #define SEXP_CANT_EVAL          -6  // can't evaluate yet for whatever reason (acts like false)
684 #define SEXP_NUM_EVAL           -7       // already completed an arithmetic operation and result is stored
685
686 // defines for check_sexp_syntax
687 #define SEXP_CHECK_NONOP_ARGS                   -1                      // non-operator has arguments
688 #define SEXP_CHECK_OP_EXPTECTED         -2                      // operator expected, but found data instead
689 #define SEXP_CHECK_UNKNOWN_OP                   -3                      // unrecognized operator
690 #define SEXP_CHECK_TYPE_MISMATCH                -4                      // return type or data type mismatch
691 #define SEXP_CHECK_BAD_ARG_COUNT                -5                      // argument count in incorrect
692 #define SEXP_CHECK_UNKNOWN_TYPE         -6                      // unrecognized return type of data type
693
694 #define SEXP_CHECK_INVALID_NUM                                  -101            // number is not valid
695 #define SEXP_CHECK_INVALID_SHIP                                 -102            // invalid ship name
696 #define SEXP_CHECK_INVALID_WING                                 -103            // invalid wing name
697 #define SEXP_CHECK_INVALID_SUBSYS                               -104            // invalid subsystem
698 #define SEXP_CHECK_INVALID_IFF                                  -105            // invalid iff string
699 #define SEXP_CHECK_INVALID_POINT                                        -106            // invalid point
700 #define SEXP_CHECK_NEGATIVE_NUM                                 -107            // negative number wasn't allowed
701 #define SEXP_CHECK_INVALID_SHIP_WING                    -108    // invalid ship/wing
702 #define SEXP_CHECK_INVALID_SHIP_TYPE                    -109    // invalid ship type
703 #define SEXP_CHECK_UNKNOWN_MESSAGE                              -110    // invalid message
704 #define SEXP_CHECK_INVALID_PRIORITY                             -111    // invalid priority for a message
705 #define SEXP_CHECK_INVALID_MISSION_NAME         -112    // invalid mission name
706 #define SEXP_CHECK_INVALID_GOAL_NAME                    -113    // invalid goal name
707 #define SEXP_CHECK_INVALID_LEVEL                                        -114    // mission level too high in campaign
708 #define SEXP_CHECK_INVALID_MSG_SOURCE                   -115    // invalid 'who-from' for a message being sent
709 #define SEXP_CHECK_INVALID_DOCKER_POINT         -116
710 #define SEXP_CHECK_INVALID_DOCKEE_POINT         -117
711 #define SEXP_CHECK_ORDER_NOT_ALLOWED                    -118    // ship goal (order) isn't allowed for given ship
712 #define SEXP_CHECK_DOCKING_NOT_ALLOWED                  -119
713 #define SEXP_CHECK_NUM_RANGE_INVALID                    -120
714 #define SEXP_CHECK_INVALID_EVENT_NAME                   -121
715 #define SEXP_CHECK_INVALID_SKILL_LEVEL                  -122
716 #define SEXP_CHECK_INVALID_MEDAL_NAME                   -123
717 #define SEXP_CHECK_INVALID_WEAPON_NAME                  -124
718 #define SEXP_CHECK_INVALID_SHIP_CLASS_NAME      -125
719 #define SEXP_CHECK_INVALID_GAUGE_NAME                   -126
720 #define SEXP_CHECK_INVALID_JUMP_NODE                    -127
721 #define SEXP_CHECK_INVALID_VARIABLE                             -128
722
723 #define TRAINING_CONTEXT_SPEED          (1<<0)
724 #define TRAINING_CONTEXT_FLY_PATH       (1<<1)
725
726 // numbers used in special_training_check() function
727 #define SPECIAL_CHECK_TRAINING_FAILURE  2000
728
729 typedef struct sexp_ai_goal_link {
730         int ai_goal;
731         int op_code;
732 } sexp_ai_goal_link;
733
734 typedef struct sexp_oper {
735         char    *text;
736         int     value;
737         int     min, max;
738 } sexp_oper;
739
740 typedef struct sexp_node {
741         char    text[TOKEN_LENGTH];
742         int     type;                                           // atom, list, or not used
743         int     subtype;                                        // type of atom or list?
744         int     first;                                  // if first parameter is sexp, index into Sexp_nodes
745         int     rest;                                           // index into Sexp_nodes of rest of parameters
746         int     value;                                  // known to be true, known to be false, or not known
747 } sexp_node;
748
749 typedef struct sexp_variable {
750         int     type;
751         char    text[TOKEN_LENGTH];
752         char    variable_name[TOKEN_LENGTH];
753 } sexp_variable;
754
755 // next define used to eventually mark a directive as satisfied even though there may be more
756 // waves for a wing.  bascially a hack for the directives display.
757 #define DIRECTIVE_WING_ZERO             -999
758
759 extern sexp_oper Operators[];
760 extern sexp_node Sexp_nodes[MAX_SEXP_NODES];
761 extern sexp_variable Sexp_variables[MAX_SEXP_VARIABLES];
762 extern int Num_operators;
763 extern int Locked_sexp_true, Locked_sexp_false;
764 extern int Directive_count;
765 extern int Sexp_useful_number;  // a variable to pass useful info in from external modules
766 extern char *Sexp_string;
767 extern int Training_context;
768 extern int Training_context_speed_min;
769 extern int Training_context_speed_max;
770 extern int Training_context_speed_set;
771 extern int Training_context_speed_timestamp;
772 extern int Training_context_path;
773 extern int Training_context_goal_waypoint;
774 extern int Training_context_at_waypoint;
775 extern float Training_context_distance;
776 extern int Players_target;
777 extern ship_subsys *Players_targeted_subsys;
778 extern int Players_target_timestamp;
779 extern int Sexp_clipboard;  // used by Fred
780
781 extern void init_sexp();
782 extern int alloc_sexp(char *text, int type, int subtype, int first, int rest);
783 extern int find_free_sexp();
784 extern int free_one_sexp(int num);
785 extern int free_sexp(int num);
786 extern int free_sexp2(int num);
787 extern int dup_sexp_chain(int node);
788 extern int cmp_sexp_chains(int node1, int node2);
789 extern int find_sexp_list(int num);
790 extern int find_parent_operator(int num);
791 extern int is_sexp_top_level( int node );
792 extern int identify_operator(char *token);
793 extern int find_operator(char *token);
794 extern int query_sexp_args_count(int index);
795 extern int check_sexp_syntax(int index, int return_type = OPR_BOOL, int recursive = 0, int *bindex = NULL, int mode = 0);
796 extern int get_sexp_main(void); //      Returns start node
797 extern int stuff_sexp_variable_list();
798 extern int eval_sexp(int index);
799 extern int query_operator_return_type(int op);
800 extern int query_operator_argument_type(int op, int argnum);
801 extern void update_sexp_references(char *old_name, char *new_name);
802 extern void update_sexp_references(char *old_name, char *new_name, int format);
803 extern int query_referenced_in_sexp(int mode, char *name, int *node);
804 extern int verify_vector(char *text);
805 extern void skip_white(char **str);
806 extern int validate_float(char **str);
807 extern int build_sexp_string(int cur_node, int level, int mode);
808 extern int sexp_query_type_match(int opf, int opr);
809 extern char *sexp_error_message(int num);
810 extern int count_free_sexp_nodes();
811
812 // functions to change the attributes of an sexpression tree to persistent or not persistent
813 extern void sexp_unmark_persistent( int n );
814 extern void sexp_mark_persistent( int n );
815 extern int waypoint_lookup(char *name);
816 extern int verify_sexp_tree(int node);
817 extern int query_sexp_ai_goal_valid(int sexp_ai_goal, int ship);
818 int query_node_in_sexp(int node, int sexp);
819 void flush_sexp_tree(int node);
820
821 // sexp_variable
822 void sexp_modify_variable(int);
823 void sexp_modify_variable(char *text, int index);
824 int get_index_sexp_variable_name(const char* temp_name);
825 int sexp_variable_count();
826 void sexp_variable_delete(int index);
827 void sexp_variable_sort();
828 void sexp_fred_modify_variable(const char *text, const char *var_name, int index, int type);
829 int sexp_add_variable(const char *text, const char *var_name, int type, int index=-1);
830 int sexp_variable_allocate_block(const char* block_name, int block_type);
831 void sexp_variable_condense_block();
832 void sexp_variable_block_free(const char *ship_name, int start_index, int block_type);
833
834 #endif
835