Debian Codegraph @

scripts/DallasFuncs.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Data/scripts/DallasFuncs.cpp $
21 * $Revision: 1.1 $
22 * $Date: 2000-04-18 01:45:34 $
23 * $Author: icculus $
24 *
25 * Definitions for the D3 actions & queries for Dallas
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 214 10/27/99 4:19p Josh
30 * upped timer handle count once again to 50
31 *
32 * 213 10/23/99 2:56p Chris
33 * Fixed the place object on object goal
34 *
35 * 212 10/23/99 2:42a Chris
36 * Added the PutObjectOnObject AI Goal
37 *
38 * 211 10/17/99 9:04p Samir
39 * added a complex cinematic function for moving camera to position from
40 * position on the clipboard.
41 *
42 * 210 10/16/99 9:56p Jeff
43 * added a way to strip all players of all weapons and energy
44 *
45 * 209 10/16/99 8:44p Jeff
46 * created an action to remove all powerups from a room. Created an
47 * action to strip a player of all weapons
48 *
49 * 208 10/15/99 6:05p Samir
50 * added a query for max speed of an object.
51 *
52 * 207 10/12/99 12:43p Jeff
53 * added actions and queries for virus infection and negative light
54 *
55 * 206 10/08/99 4:15p Samir
56 * added frametime query
57 *
58 * 205 5/20/99 4:11p Jeff
59 * null terminate string for message when adding to inventory correctly
60 * (\0 not 0)
61 *
62 * 204 5/20/99 3:12p Chris
63 * Fixed bug in blockage code
64 *
65 * 203 5/19/99 4:57p Matt
66 * Added an action & a query.
67 *
68 * 202 5/19/99 2:55p Chris
69 * Fixed bug with aAISetTarget
70 *
71 * 201 5/19/99 12:25p Chris
72 * Added new functions
73 *
74 * 200 5/19/99 11:25a Matt
75 * Added multisafe functions & Dallas actions for showing a timer on the
76 * screen and adding custom HUD messages.
77 *
78 * 199 5/11/99 5:17p Jeff
79 * added query to get difficulty level
80 *
81 * 198 5/11/99 11:49a Matt
82 * Added the ability to specify a name when adding an item to the
83 * inventory.
84 *
85 * 197 5/08/99 10:10p Nate
86 * Fixed Level Goal Item index problem
87 *
88 * 196 5/08/99 2:39p Chris
89 * Added a new function for dallas
90 *
91 * 195 5/07/99 11:56p Matt
92 * Added an action to give a player an "invisible" key -- one that doesn't
93 * get added to the inventory or shown on the HUD.
94 *
95 * 194 5/07/99 8:22p 3dsmax
96 * Fixed goal query bugs
97 *
98 * 193 5/07/99 7:22p Chris
99 * Added some level goal querys
100 *
101 * 192 5/07/99 2:58p Matt
102 * Increased the maximum number of timer handles from 20 to 40.
103 *
104 * 191 5/06/99 4:11a Jeff
105 * created multisafe function to destroy robots in the level (helps boss
106 * fights)
107 *
108 * 190 5/04/99 6:52p Jeff
109 * added new canned cinematic to fade screen to white and endlevel. Fixed
110 * crash bug with invalid player path for canned cine with player paths
111 *
112 * 189 5/04/99 12:13p Matt
113 * Renamed fire-flare symbol to fire-weapon.
114 *
115 * 188 5/04/99 1:05a Matt
116 * Added new fire weapon function, and added a #define to make the old
117 * fire flare function use it.
118 *
119 * 187 5/02/99 1:36a Jason
120 * added moving object lighting viseffects
121 *
122 * 186 4/30/99 6:52p Matt
123 * Changed comment
124 *
125 * 185 4/30/99 6:51p Matt
126 * Added a query to check if an object is on the terrain.
127 *
128 * 184 4/30/99 4:32p Matt
129 * Added a Dallas action to fire a flare from an object.
130 *
131 * 183 4/29/99 4:50p Jeff
132 * fixed evil evil merge problems
133 *
134 * 182 4/29/99 12:30p Chris
135 * Dumb bug (Follow path simple now takes and USES the priority field)
136 *
137 * 181 4/29/99 1:59a Chris
138 * Added the portal blockage support
139 *
140 * 179 4/28/99 7:34p Matt
141 * Increased the number of spew handles from 20 to 50.
142 *
143 * 178 4/28/99 5:15p Jeff
144 * fixed bug with adding items to inventory...should not timeout on spew
145 * for spewable
146 *
147 * 177 4/27/99 5:37p Matt
148 * Added action to set/clear physics flags for an object.
149 *
150 * 176 4/26/99 10:35p Chris
151 *
152 * 175 4/26/99 1:43p Chris
153 *
154 * 174 4/26/99 1:40p Nate
155 * Fixed bug with undeclared 'ctype' identifier
156 *
157 * 173 4/26/99 11:11a Chris
158 * Added a new function
159 *
160 * 172 4/25/99 10:37p Matt
161 * Changes in death flags
162 *
163 * 171 4/25/99 3:06p Matt
164 * Increased the max number of spew handles from 10 to 20.
165 *
166 * 170 4/24/99 2:18a Chris
167 * Added some new functions.
168 *
169 * 169 4/19/99 6:14p Chris
170 * Added two new AI Queries for Nate
171 *
172 * 168 4/07/99 11:25a Matt
173 * Added fail level action
174 *
175 * 167 4/07/99 3:05a Chris
176 * Improved the team stuff and fixed a compile bug in
177 * LightningCreateGunpoints
178 *
179 * 166 4/06/99 11:44p Matt
180 * Added action to create a lighting bolt between two gunpoints on the
181 * same object, and queries to return an object's original shields and to
182 * multiply a percent times a float.
183 *
184 * 165 4/06/99 8:44p Matt
185 * Added a couple actions for Mark's energy/shield collector
186 *
187 * 164 4/06/99 11:00a Jeff
188 *
189 * 163 4/05/99 5:44p Chris
190 * Added a drop all objects functions
191 *
192 * 162 4/05/99 1:07p Chris
193 * Added a goal failed state
194 *
195 * 161 4/04/99 6:20p Matt
196 * Added distance-based shake Dallas action.
197 *
198 * 160 4/03/99 3:51p Chris
199 *
200 * 159 4/03/99 3:16p Chris
201 *
202 * 158 4/03/99 2:49p Chris
203 * Fixed a bug with the ScriptedDeath DALLAS func.
204 *
205 * 157 4/03/99 1:12a Jeff
206 * added multisafe/dallas actions to set an object on fire
207 *
208 * 156 4/02/99 6:41p Matt
209 * Added query to find the closest player to an object.
210 *
211 * 155 4/02/99 1:20p Nate
212 * Fixed dallas syntax bug with qGetAttachedChild
213 *
214 * 154 4/02/99 12:57p Chris
215 * Added 2 new DALLAS actions for Nate
216 *
217 * 153 4/02/99 11:27a Nate
218 * Upped the SavedObjectHandle limit to 20
219 *
220 * 152 4/02/99 11:24a Matt
221 * Added kill object action that allows the caller to specify the death.
222 *
223 * 151 3/31/99 11:40a Jason
224 * added support for attached thick lightning
225 *
226 * 150 3/30/99 7:40p Chris
227 *
228 * 149 3/30/99 7:39p Chris
229 *
230 * 148 3/30/99 7:25p Chris
231 * Make the weath_lightning stuff more flexable
232 *
233 * 147 3/29/99 8:41p Nate
234 * Jason fix
235 *
236 * 146 3/29/99 8:02p Nate
237 * Added qObjCanSeePlayerAdvancedWithStore
238 *
239 * 145 3/29/99 7:30p Jason
240 * added cool new energy effect
241 *
242 * 144 3/29/99 6:04p Nate
243 * Changed aLightningCreate header for new abilities.
244 *
245 * 143 3/29/99 5:26p Chris
246 * Added the unattach form object and the set max speed functions to
247 * DALLAS
248 *
249 * 142 3/29/99 11:11a Jeff
250 * fixed fvi calls for view cone functions (hit_none is a valid hit)
251 *
252 * 141 3/28/99 6:47p Matt
253 * Added default value for spark rate
254 *
255 * 140 3/28/99 5:56p Matt
256 * Added Dallas action to turn on object sparking
257 *
258 * 139 3/28/99 3:29p Sean
259 * Jeff: Fixed misnamed dallas func
260 *
261 * 138 3/27/99 9:14p Jeff
262 * added advanced object view cones dallas funcs
263 *
264 * 137 3/27/99 7:22p Jeff
265 * fixed cinematics when going from one cut to another immediatly. Added
266 * start transition
267 *
268 * 136 3/26/99 12:38p Jeff
269 * added cloak predefs
270 *
271 * 135 3/25/99 9:09p Nate
272 * Fixed Land On Object action
273 *
274 * 134 3/25/99 4:56p Chris
275 * Added code for the land on object DALLAS goal
276 *
277 * 133 3/24/99 10:02a Matt
278 * Added Dallas action to set music region for all players
279 *
280 * 132 3/23/99 6:42p Chris
281 * Added the Get to Object Goal for DALLAS
282 *
283 * 131 3/23/99 4:30p Chris
284 * Fixed a bug in the AIGoalGoToRoom() (parameters where out of order)
285 *
286 * 130 3/22/99 6:35p Matt
287 * Added Dallas action to create a lightning bolt between two objects.
288 * Jason will implement this.
289 *
290 * 129 3/22/99 1:59p Matt
291 * Added break glass Dallas action
292 *
293 * 128 3/04/99 6:13p Matt
294 * Pass second game message string in message2. Also changed color of the
295 * HUD message.
296 *
297 * 127 3/03/99 3:02p Matt
298 * Added Game Message action in Dallas
299 *
300 * 126 3/02/99 11:19a Jeff
301 * added comment
302 *
303 * 125 2/28/99 11:24p Matt
304 * Changed a literal to a symbolic constant
305 *
306 * 124 2/28/99 8:31p Jeff
307 * added fade and move player dallas action. Fixed the end-level sequence
308 * changing view back to player for split second.
309 *
310 * 123 2/27/99 1:41p Matt
311 * Added saved object handles to savegame read/write functions.
312 *
313 * 122 2/26/99 1:57a Jeff
314 * added text to end level sequence
315 *
316 * 121 2/25/99 8:53p Jeff
317 * Inventory supports level change persistant items. Inventory supports
318 * time-out objects. Inventory Reset changed (takes a level of reset
319 * now). Quad lasers stay across level change (single player). Guidebot
320 * bug fixed (now back in ship on level start). Quads time out when
321 * spewed. Invulnerability and cloak powerups no longer use game
322 * event/callbacks, so they can be saved in game saves (moved to
323 * MakePlayerInvulnerable and MakeObjectInvisible)
324 *
325 * 120 2/23/99 7:34p Jeff
326 * save out position clipboard, fixed up add inventory item
327 *
328 * 119 2/23/99 7:23p Matt
329 * Fixed function parms for new types.
330 *
331 * 118 2/23/99 11:09a Matt
332 * Fixed level goal actions/queries
333 *
334 * 117 2/22/99 10:21p Matt
335 * Added (but did not test) several actions and queries for level goals.
336 *
337 * 116 2/22/99 10:53a Matt
338 * Added a version of the streaming audio action that takes a text string,
339 * for sounds that aren't in the table file.
340 *
341 * 115 2/22/99 10:40a Luke
342 * fixed aAIGoalFollowPath with new data types
343 *
344 * 114 2/22/99 1:19a Jeff
345 * added support for inventory (simple) in dallas. Moved end-level
346 * sequence to use IGC. Add position clipboard stuff for dallas. Fixed
347 * some inventory bug with storing object handles
348 *
349 * 113 2/21/99 8:35p Jeff
350 * misc changes to handle new matcen and path types of dallas
351 *
352 * 112 2/21/99 6:35p Matt
353 * Finished action for setting object movement type, and fixed the attach
354 * new object action.
355 *
356 * 111 2/21/99 6:05p Matt
357 * Use new types for matcens, paths, & streaming audio.
358 *
359 * 110 2/21/99 5:49p Matt
360 * Added Dallas action to set an object's volume
361 *
362 * 109 2/21/99 4:55p Matt
363 * Added actions to set an object's movement type and to enable/disable
364 * gravity for a object.
365 *
366 * 108 2/19/99 6:44p Chris
367 *
368 * 107 2/16/99 9:36p Jeff
369 * added low text layout for cinematics
370 *
371 * 106 2/16/99 12:37a Matt
372 * Added set object velocity action
373 *
374 * 105 2/15/99 9:57p Matt
375 * Several small changes
376 *
377 * 104 2/15/99 3:30p Dan
378 * Fixed typo
379 *
380 * 103 2/15/99 3:19p Dan
381 * Added integer add & subtract queries (MattT on Dan's machine)
382 *
383 * 102 2/15/99 11:09a Matt
384 * Added function to count the number of a certain type of object in the
385 * level. (Also added HUD actions to print an int and float.)
386 *
387 * 101 2/14/99 4:27a Jeff
388 * forgot to unset a flag when ending a custom cinematic. and set a flag
389 * when starting a custom cinematic.
390 *
391 * 100 2/13/99 8:44p Jeff
392 * made intro cinematic into a 'canned' cinematic. Added ability to
393 * create custom in-game cinematics (SUPER powerful)
394 *
395 * 99 2/13/99 5:33p Matt
396 * Changed pathname in endlevel sequence from string to specific string
397 *
398 * 98 2/12/99 6:14p Matt
399 * Added object is type query
400 *
401 * 97 2/12/99 4:17p Matt
402 * Added key name & HUD message to give key action
403 *
404 * 96 2/12/99 12:07p Matt
405 * Make region action use enumerated type
406 *
407 * 95 2/11/99 1:07p Matt
408 * Added action to enable/disable triggers
409 *
410 * 94 2/11/99 2:53a Jeff
411 * improvements to introcam
412 *
413 * 93 2/10/99 4:06p Matt
414 * Changed the object type name parameter to the attach action to a
415 * specific string.
416 *
417 * 92 2/10/99 2:56p Matt
418 * Fixed typo
419 *
420 * 91 2/10/99 2:31p Matt
421 * Added Enable/Disable Matcen action.
422 *
423 * 90 2/10/99 1:47p Matt
424 * Changed object handle symbolic constants
425 *
426 * 89 2/10/99 1:21p Matt
427 * Added UserFlags and a query to return a user var as an integer.
428 *
429 * 88 2/09/99 1:29p Matt
430 * Added Matcen IDs, object handle saves, random value query, player in
431 * room query.
432 *
433 * 87 2/08/99 5:08p Matt
434 * Added MatcenID user type, and added No Reorientation flag to flag masks
435 * for all the AI actions.
436 *
437 * 86 2/08/99 3:10a Jeff
438 * added a multisafe type for player control type setting. Improved intro
439 * cinematic action function, player now follows path.
440 *
441 * 85 2/06/99 10:03p Matt
442 * Added keys system
443 *
444 * 84 2/06/99 1:52a Matt
445 * Added a bunch of Dallas funcs, mostly for Sean
446 *
447 * 83 2/05/99 5:51p Chris
448 * Added rereorienation to ai goal flags
449 *
450 * 82 2/05/99 1:29p Matt
451 * Changed wind to use direction vector & speed instead of velocity
452 * vector, and added some defaults to some actions.
453 *
454 * 81 2/04/99 3:24p Matt
455 * Increased the number of user vars to 25, and added save/load code for
456 * user vars and sound & spew handles.
457 *
458 * 80 2/03/99 5:48p Matt
459 * Added room damage system
460 *
461 * 79 2/03/99 2:56a Jeff
462 * ship permission actions and queries
463 *
464 * 78 2/03/99 12:24a Matt
465 * Got HUD message, 2D sound, streaming sound, and player-is-visible all
466 * working correctly in multiplayer.
467 *
468 * 77 2/02/99 3:58p Jeff
469 * started to implement level intro cinematic (need ai functions first).
470 * No longer need camera object to do cinematic (auto-created)...path
471 * cameras use speed based on distance needed to travel.
472 *
473 * 76 2/02/99 3:38p Luke
474 * Changed Matcen names to take direct string input instead of using
475 * messages
476 *
477 * 75 2/02/99 12:35p Jeff
478 * changed cinematic path parameter to use a instead of s
479 *
480 * 74 2/01/99 2:08p Kevin
481 * Fixed parameter order for qObjCanSeeObj
482 *
483 * 73 2/01/99 1:11p Matt
484 * Changed a bunch of stuff to work with object handles instead of player
485 * numbers. Also fixed the view cone action, which ignored distance.
486 *
487 * 72 2/01/99 12:41p Kevin
488 * Moved some functions into the training system script
489 *
490 * 71 1/31/99 11:06p Matt
491 * Changed timers from handles to IDs, and implemented music region set.
492 *
493 * 70 1/31/99 9:00p Jeff
494 * added new in game cinematics system
495 *
496 * 69 1/31/99 8:11p Matt
497 * Added player visible query, and made zoom work with popup cameras.
498 *
499 * 68 1/31/99 7:15p Matt
500 * Added physics flags for spew
501 *
502 * 67 1/30/99 7:54p Chris
503 *
504 * 66 1/30/99 3:46p Luke
505 * Changed two boolean parameters to be FALSE by default (0 didn't work)
506 *
507 * 65 1/30/99 3:19p Matt
508 * Made Dallas spews work from object centers in addition to gunpoints
509 *
510 * 64 1/29/99 3:14p Matt
511 * Deleted some obsolete Dallas actions, and made the player controls
512 * actions take player numbers instead of the player object.
513 *
514 * 63 1/29/99 2:50p Luke
515 * Added a bunch of default values to help designers and fixed a few
516 * parameter listings, but modified no actual code
517 *
518 * 62 1/29/99 12:57p Kevin
519 * Added cone to ObjCanSeeObj
520 *
521 * 61 1/29/99 12:49p Matt
522 * Added door actions & queries, chagned the working of the math queries,
523 * adding math queries for percentages, and reworded a few other queries.
524 *
525 * 60 1/26/99 6:39p Kevin
526 * Added energy get/set
527 *
528 * 59 1/26/99 5:17p Matt
529 * Added user types and stop object sound action.
530 *
531 * 58 1/26/99 12:53p Kevin
532 * Added SetTeam function
533 *
534 * 57 1/26/99 10:51a Matt
535 * Fixed stupid oversight.
536 *
537 * 56 1/25/99 6:32p Matt
538 * A bunch of stuff: sounds, goal flag masks, pick up with radius.
539 *
540 * 55 1/25/99 12:19p Matt
541 * Fixed stupid bugs
542 *
543 * 54 1/25/99 11:13a Matt
544 * Changed a bunch of actions to use enums for On/Off, Enable/Disable,
545 * etc. instead of bools. Also changed the Player controls action to use
546 * flags.
547 *
548 * 53 1/25/99 10:15a Matt
549 * AI Goal stuff
550 *
551 * 52 1/25/99 7:23a Chris
552 * Added the GUID (Goal Unique Id) and added the ability for weapon
553 * batteries to always fire exactly forward.
554 *
555 * 51 1/24/99 6:28p Matt
556 * Added path follow action
557 *
558 * 50 1/23/99 5:37p Matt
559 * Deleted AI goal flags that the user won't be using
560 *
561 * 49 1/23/99 5:19p Matt
562 * Added AI goal flags
563 *
564 * 48 1/23/99 4:48p Matt
565 * Added some default parameter values
566 *
567 * 47 1/23/99 2:56a Jeff
568 * added target field to boss intro struct
569 *
570 * 46 1/22/99 7:50p Kevin
571 * Training mission additions..
572 *
573 * 45 1/22/99 5:42p Matt
574 * Added a couple AI actions, though I haven't tested them fully yet.
575 *
576 * 44 1/22/99 3:09p Matt
577 * Added forcefield state query
578 *
579 * 43 1/21/99 7:03p Matt
580 * Added action to set/clear secret flag
581 *
582 * 42 1/20/99 9:30p Matt
583 * Got AISetMode action working
584 *
585 * 41 1/20/99 6:26p Matt
586 * Added several actions
587 *
588 * 40 1/20/99 3:49p Kevin
589 * Added some glue functions
590 *
591 * 39 1/20/99 3:44a Jeff
592 * created functions and struct for boss introduction cinematic sequence
593 *
594 * 38 1/19/99 6:54p Matt
595 * Added queries to add & subtract floats
596 *
597 * 37 1/19/99 6:13p Matt
598 * Added an action & query for lighting distance
599 *
600 * 36 1/19/99 3:43p Kevin
601 * Added msafe functionality to set an object to render type RT_NONE
602 *
603 * 35 1/19/99 12:16p Matt
604 * Added start endlevel sequence action
605 *
606 * 34 1/19/99 10:33a Kevin
607 *
608 * 33 1/19/99 10:02a Matt
609 * Added unfinished sound action
610 *
611 * 32 1/18/99 7:31p Matt
612 * Added a bunch of Dallas actions
613 *
614 * 31 1/18/99 6:18p Kevin
615 * Added controller masking to DALLAS
616 *
617 * 30 1/18/99 3:30p Matt
618 * Added some default values and ranges
619 *
620 * 29 1/15/99 5:02p Matt
621 * Got activate/deactive matcen actions working
622 *
623 * 28 1/15/99 11:04a Matt
624 * Added actions for matcens (not working) and fog (working)
625 *
626 * 27 1/13/99 5:48p Nate
627 * Fixed "Sheild" in function prototypes
628 *
629 * 26 1/13/99 12:42p Matt
630 * Added an action to close a popup view
631 *
632 * 25 1/11/99 8:43p Nate
633 * Added custom DALLAS queries
634 *
635 * 24 1/11/99 6:23p Nate
636 * Fixed two broken queries, some spelling errors, and made "Obj type"
637 * return an ObjectType (specific enumerated type)
638 *
639 * 23 1/11/99 4:53p Matt
640 * Change spew action to use enum, and added real values for SpewType
641 *
642 * 22 1/11/99 2:14p Chris
643 * Massive work on OSIRIS and AI
644 *
645 * 21 1/11/99 10:43a Matt
646 * Made forcefield on/off/toggle optionally do both sides of a portal
647 *
648 * 20 1/11/99 10:25a Matt
649 * Added spew handles and got spew off working. Also added functions to
650 * init, load, & save variables.
651 *
652 * 19 1/08/99 6:07p Matt
653 * Added some comments
654 *
655 * 18 1/08/99 4:33p Matt
656 * Got popup views working in Dallas
657 *
658 * 17 1/08/99 3:00p Luke
659 * (Jeff) fixed ObjPlayAnim bug (never filled in objhandle)
660 *
661 * 16 1/06/99 12:02p Matt
662 * Fixed some function name mismatches
663 *
664 * 15 1/05/99 6:53p Jeff
665 * fixed hud message color
666 *
667 * 14 1/05/99 6:38p Jeff
668 * fixed spew errors, added some defines
669 *
670 * 13 1/05/99 4:31p Matt
671 * Added a bunch more actions
672 *
673 * 12 1/05/99 3:41p Jeff
674 * added spew create and stop functions
675 *
676 * 11 1/04/99 11:03p Matt
677 * Added a bunch of actions & queries, and renamed a bunch of others
678 *
679 * 10 1/02/99 3:50p Matt
680 * Added ENUM defines to comment block, and made aShowHUDMessage() take
681 * var args.
682 *
683 * 9 1/01/99 3:25p Matt
684 * Fixed lightning actions
685 *
686 * 8 12/30/98 6:56p Matt
687 * Added a bunch more actions and queries
688 *
689 * 7 12/23/98 6:43p Nate
690 * Fixed the category for the qIsPlayerWeapon Query
691 *
692 * 6 12/23/98 6:10p Matt
693 * Added toggle forcefield action
694 *
695 * 5 12/23/98 4:29p Matt
696 * Un-did hack from previous version. Now works w/ scripts.
697 *
698 * 4 12/23/98 3:02p Luke
699 * Nate: temp fix so that editor will compile
700 *
701 * 3 12/23/98 1:46p Matt
702 * Renamed the portal render/forcefield actions
703 *
704 * 2 12/23/98 1:39p Matt
705 * Added DallasFuncs.cpp to project
706 *
707 * 1 12/23/98 1:36p Matt
708 *
709 */
710
711 #include <cstdio>
712 #include <cstring>
713 #include <cstdarg>
714 #include <cfloat>
715
716 #include "osiris_vector.h"
717
718 // These should really be included, I think, but there's a problem with osiris_import.h being included twice
719 // #include "osiris_import.h"
720 // #include "osiris_common.h"
721
722 /*
723
724 Dallas types:
725
726 ID Name How passed
727 o object object handle
728 d door handle of door object
729 r room integer room number
730 t trigger integer trigger number
731 i int integer
732 b bool usigned byte
733 f float single-precision float (4 bytes)
734 p percentage single-precision float in range 0.0 - 1.0
735 v vector pointer to triplet of floats
736 s string pointer to null-terminated string
737 e enum integer
738 a name a specific (non-localizable) name, as of a matcen. Does not appear in the
739 message file. n sound sound name h path integer path number m matcen
740 integer matcen numer l level goal integer level goal number z streaming audio pointer to null-terminated name
741 of audio file
742
743
744
745 Dallas Action Categories. Used by Dallas to build the action list.
746
747 $$CATEGORIES
748 Objects
749 Players
750 Doors
751 Rooms
752 Triggers
753 Spew
754 Weather
755 AI
756 Sound && Music
757 Timer
758 Level Goals
759 Mission
760 Math
761 User Vars
762 Misc
763 Scripts
764 Cinematics
765 Custom
766 $$END
767
768
769 Enumerated types:
770
771 $$ENUM Axis
772 0:X
773 1:Y
774 2:Z
775 $$END
776
777 $$ENUM SpewType
778 0:Explosion0
779 1:Explosion1
780 2:Explosion2
781 3:Explosion3
782 4:Explosion4
783 5:Explosion5
784 6:Explosion6
785 7:Grey Smoke
786 8:Black Smoke
787 15:Red Spark
788 16:Blue Spark
789 23:Napalm
790 28:Raindrop
791 35:Corona0
792 36:Corona1
793 37:Corona2
794 38:Corona3
795 39:Snowflake
796 41:Blue Fire
797 $$END
798
799 //I've just defined the flags that spew needs, but feel free to define others if you need them
800 $$FLAG PhysicsFlags
801 128:Gravity
802 2048:Fixed Velocity
803 32768:Reverse Gravity
804 65536:No Collide
805 2097152:Ignore Concussive Force
806 8388608:Lock X
807 16777216:Lock Y
808 33554432:Lock Z
809 $$END
810
811 $$FLAG FVIHitFlags
812 1:Check against objects
813 2:Hit backfaces of poly objects
814 4:Go through transparent walls if hit
815 8:Ignore powerups
816 16:Check for collisions with backfaces (default ignored)
817 32:Solid Portals
818 256:Ignore Moving Objects
819 512:Ignore Non-Lightmap Objects
820 1024:Ignore all objects besides players
821 2048:Ignore all walls
822 4096:Check terrain ceiling
823 8192:Ignore all objects but doors
824 524288:Ignore external rooms
825 1048576:Ignore weapons
826 2097152:Ignore terrain
827 4194304:Treat players as spheres
828 8388608:Treat Robots as spheres
829 $$END
830 Total: 16269119
831
832 $$ENUM ObjectType
833 2:Robot
834 4:Player
835 5:Weapon
836 6:Viewer
837 7:Powerup
838 8:Debris
839 10:Shockwave
840 11:Clutter
841 16:Building
842 17:Door
843 $$END
844
845 $$FLAG PlayerControl
846 1:Forward Thrust
847 2:Reverse Thrust
848 4:Slide Left
849 8:Slide Right
850 16:Slide Up
851 32:Slide Down
852 64:Pitch Up
853 128:Pitch Down
854 256:Heading Left
855 512:Heading Right
856 1024:Roll Left
857 2048:Roll Right
858 4096:Primary
859 8192:Secondary
860 16384:Afterburner
861 $$END
862
863 $$ENUM Enabled/Disabled
864 0:DISABLED
865 1:ENABLED
866 $$END
867
868 $$ENUM Enable/Disable
869 0:DISABLE
870 1:ENABLE
871 $$END
872
873 $$ENUM Completed
874 0:NOT COMPLETED
875 1:COMPLETED
876 $$END
877
878 $$ENUM Failed
879 0:NOT FAILED
880 1:FAILED
881 $$END
882
883 $$ENUM Can/Cannot
884 0:CANNOT
885 1:CAN
886 $$END
887
888 $$ENUM On/Off
889 0:OFF
890 1:ON
891 $$END
892
893 $$ENUM Yes/No
894 0:NO
895 1:YES
896 $$END
897
898 $$ENUM Activate/Deactivate
899 0:DEACTIVATE
900 1:ACTIVATE
901 $$END
902
903 $$ENUM Teams
904 0:PTMC
905 65536:Rebel
906 131072:Hostile
907 196608:Neutral
908 $$END
909
910 */
911
912 //
913 // Variables
914 //
915
916 #define MAX_USER_VARS 25 // make sure this value matches the USERTYPE definition
917 float User_vars[MAX_USER_VARS];
918
919 #define MAX_SPEW_HANDLES 50 // make sure this value matches the USERTYPE definition
920 int Spew_handles[MAX_SPEW_HANDLES];
921
922 #define MAX_SOUND_HANDLES 10 // make sure this value matches the USERTYPE definition
923 int Sound_handles[MAX_SOUND_HANDLES];
924
925 #define MAX_SAVED_OBJECT_HANDLES 20 // make sure this value matches the USERTYPE definition
926 int Saved_object_handles[MAX_SAVED_OBJECT_HANDLES];
927
928 int User_flags;
929
930 class cPositionClipboard {
931 public:
932 cPositionClipboard() { has_pos = false; }
933 bool has_pos;
934 int room;
935 vector pos;
936 matrix orient;
937 };
938 cPositionClipboard PositionClipboard;
939
940 #define SOUND_INVALID_HANDLE -1
941 #define SPEW_INVALID_HANDLE -1
942
943 /*
944 Tell Dallas about our handles
945
946 $$USERTYPE UserVar:24
947 $$USERTYPE UserFlag:31
948 $$USERTYPE SpewHandle:49
949 $$USERTYPE TimerID:49
950 $$USERTYPE SavedObjectSlot:19
951 */
952
953 // TEMP!!!
954 #ifndef OBJECT_HANDLE_NONE
955 #define OBJECT_HANDLE_NONE -1
956 #endif
957
958 //
959 // System functions
960 //
961
962 // Initialize vars
963 void dfInit() {
964 int i;
965
966 for (i = 0; i < MAX_SPEW_HANDLES; i++)
967 Spew_handles[i] = SPEW_INVALID_HANDLE;
968
969 for (i = 0; i < MAX_SOUND_HANDLES; i++)
970 Sound_handles[i] = SOUND_INVALID_HANDLE;
971
972 for (i = 0; i < MAX_USER_VARS; i++)
973 User_vars[i] = 0.0;
974
975 for (i = 0; i < MAX_SAVED_OBJECT_HANDLES; i++)
976 Saved_object_handles[i] = OBJECT_HANDLE_NONE;
977
978 User_flags = 0;
979 }
980
981 // Save vars
982 void dfSave(void *fileptr) {
983 int i;
984
985 for (i = 0; i < MAX_SPEW_HANDLES; i++)
986 File_WriteInt(Spew_handles[i], fileptr);
987
988 for (i = 0; i < MAX_SOUND_HANDLES; i++)
989 File_WriteInt(Sound_handles[i], fileptr);
990
991 for (i = 0; i < MAX_USER_VARS; i++)
992 File_WriteFloat(User_vars[i], fileptr);
993
994 for (i = 0; i < MAX_SAVED_OBJECT_HANDLES; i++)
995 File_WriteInt(Saved_object_handles[i], fileptr);
996
997 File_WriteInt(User_flags, fileptr);
998
999 File_WriteByte(PositionClipboard.has_pos, fileptr);
1000 File_WriteInt(PositionClipboard.room, fileptr);
1001 File_WriteFloat(PositionClipboard.pos.x, fileptr);
1002 File_WriteFloat(PositionClipboard.pos.y, fileptr);
1003 File_WriteFloat(PositionClipboard.pos.z, fileptr);
1004 File_WriteFloat(PositionClipboard.orient.fvec.x, fileptr);
1005 File_WriteFloat(PositionClipboard.orient.fvec.y, fileptr);
1006 File_WriteFloat(PositionClipboard.orient.fvec.z, fileptr);
1007 File_WriteFloat(PositionClipboard.orient.uvec.x, fileptr);
1008 File_WriteFloat(PositionClipboard.orient.uvec.y, fileptr);
1009 File_WriteFloat(PositionClipboard.orient.uvec.z, fileptr);
1010 File_WriteFloat(PositionClipboard.orient.rvec.x, fileptr);
1011 File_WriteFloat(PositionClipboard.orient.rvec.y, fileptr);
1012 File_WriteFloat(PositionClipboard.orient.rvec.z, fileptr);
1013 }
1014
1015 // Restore vars
1016 void dfRestore(void *fileptr) {
1017 int i;
1018
1019 for (i = 0; i < MAX_SPEW_HANDLES; i++)
1020 Spew_handles[i] = File_ReadInt(fileptr);
1021
1022 for (i = 0; i < MAX_SOUND_HANDLES; i++)
1023 Sound_handles[i] = File_ReadInt(fileptr);
1024
1025 for (i = 0; i < MAX_USER_VARS; i++)
1026 User_vars[i] = File_ReadFloat(fileptr);
1027
1028 for (i = 0; i < MAX_SAVED_OBJECT_HANDLES; i++)
1029 Saved_object_handles[i] = File_ReadInt(fileptr);
1030
1031 User_flags = File_ReadInt(fileptr);
1032
1033 PositionClipboard.has_pos = (File_ReadByte(fileptr)) ? true : false;
1034 PositionClipboard.room = File_ReadInt(fileptr);
1035 PositionClipboard.pos.x = File_ReadFloat(fileptr);
1036 PositionClipboard.pos.y = File_ReadFloat(fileptr);
1037 PositionClipboard.pos.z = File_ReadFloat(fileptr);
1038 PositionClipboard.orient.fvec.x = File_ReadFloat(fileptr);
1039 PositionClipboard.orient.fvec.y = File_ReadFloat(fileptr);
1040 PositionClipboard.orient.fvec.z = File_ReadFloat(fileptr);
1041 PositionClipboard.orient.uvec.x = File_ReadFloat(fileptr);
1042 PositionClipboard.orient.uvec.y = File_ReadFloat(fileptr);
1043 PositionClipboard.orient.uvec.z = File_ReadFloat(fileptr);
1044 PositionClipboard.orient.rvec.x = File_ReadFloat(fileptr);
1045 PositionClipboard.orient.rvec.y = File_ReadFloat(fileptr);
1046 PositionClipboard.orient.rvec.z = File_ReadFloat(fileptr);
1047 }
1048
1049 int dfGetPlayer(int objhandle) {
1050 msafe_struct mstruct;
1051 mstruct.objhandle = objhandle;
1052 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
1053
1054 if (mstruct.type == OBJ_WEAPON) {
1055 MSafe_GetValue(MSAFE_OBJECT_PARENT, &mstruct);
1056 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
1057
1058 if (mstruct.type == OBJ_PLAYER || mstruct.type == OBJ_OBSERVER || mstruct.type == OBJ_GHOST) {
1059 return mstruct.objhandle;
1060 } else {
1061 mprintf(0, "---------------------NOT A PLAYER OR PLAYER WEAPON!!!!!!!!!-------------\n");
1062 return objhandle;
1063 }
1064
1065 } else if (mstruct.type == OBJ_PLAYER || mstruct.type == OBJ_OBSERVER || mstruct.type == OBJ_GHOST) {
1066 return objhandle;
1067 } else {
1068 mprintf(0, "---------------------NOT A PLAYER OR PLAYER WEAPON!!!!!!!!!-------------\n");
1069 }
1070
1071 return objhandle;
1072 }
1073
1074 //
1075 // D3 actions
1076 //
1077
1078 /*
1079 $$ACTION
1080 Rooms
1081 [e:Enable/Disable] forcefield at portal [i:PortalNum] in room [r:Room]; Double-sided = [b:DoublesidedFlag=1]
1082 aPortalRenderSet
1083 Enable/Disable forcefield
1084 Turns on or off the specified forcefield
1085
1086 Parameters:
1087 Room: The room the forcefield is in
1088 PortalNum: The portal number of the forcefield
1089 $$END
1090 */
1091 void aPortalRenderSet(int state, int portalnum, int roomnum, bool doublesided) {
1092 msafe_struct mstruct;
1093
1094 mstruct.roomnum = roomnum;
1095 mstruct.portalnum = portalnum;
1096 mstruct.flags = doublesided ? 1 : 0;
1097 mstruct.state = state;
1098
1099 MSafe_CallFunction(MSAFE_ROOM_PORTAL_RENDER, &mstruct);
1100 }
1101
1102 /*
1103 $$ACTION
1104 Rooms
1105 [e:Enable/Disable] Blockage at portal [i:PortalNum] in room [r:Room]
1106 aPortalBlockageSet
1107 Enable/Disable Blockage
1108 Turns on or off the blockage at a specified portal
1109
1110 Parameters:
1111 Room: The room the blockage is in
1112 PortalNum: The portal number of the blockage
1113 $$END
1114 */
1115 void aPortalBlockageSet(int state, int portalnum, int roomnum) {
1116 msafe_struct mstruct;
1117
1118 mstruct.roomnum = roomnum;
1119 mstruct.portalnum = portalnum;
1120 mstruct.state = state;
1121
1122 MSafe_CallFunction(MSAFE_ROOM_PORTAL_BLOCK, &mstruct);
1123 }
1124
1125 /*
1126 $$ACTION
1127 Rooms
1128 Toggle forcefield at portal [i:PortalNum] in room [r:Room]; Double-sided = [b:DoublesidedFlag=1]
1129 aPortalRenderToggle
1130 Toggle forcefield
1131 Turns off the specified forcefield if it's on, and on if it's off
1132
1133 Parameters:
1134 Room: The room the forcefield is in
1135 PortalNum: The portal number of the forcefield
1136 $$END
1137 */
1138 void aPortalRenderToggle(int portalnum, int roomnum, bool doublesided) {
1139 msafe_struct mstruct;
1140
1141 mstruct.roomnum = roomnum;
1142 mstruct.portalnum = portalnum;
1143
1144 MSafe_GetValue(MSAFE_ROOM_PORTAL_RENDER, &mstruct);
1145
1146 mstruct.flags = doublesided ? 1 : 0;
1147 mstruct.state = !mstruct.state;
1148 MSafe_CallFunction(MSAFE_ROOM_PORTAL_RENDER, &mstruct);
1149 }
1150
1151 /*
1152 $$ACTION
1153 Rooms
1154 Break glass at portal [i:PortalNum] in room [r:Room]
1155 aPortalBreakGlass
1156 Break glass
1157 Breaks the glass in the specified portal
1158
1159 Parameters:
1160 PortalNum: The portal number of the forcefield
1161 Room: The room the forcefield is in
1162 $$END
1163 */
1164 void aPortalBreakGlass(int portalnum, int roomnum) {
1165 msafe_struct mstruct;
1166
1167 mstruct.roomnum = roomnum;
1168 mstruct.portalnum = portalnum;
1169
1170 MSafe_CallFunction(MSAFE_ROOM_BREAK_GLASS, &mstruct);
1171 }
1172
1173 /*
1174 Damage sound types
1175 $$ENUM DamageSoundType
1176 0:None
1177 1:Energy Weapon
1178 2:Matter Weapon
1179 3:Melee Attach
1180 4:Concussive Force
1181 5:Wall Hit
1182 $$END
1183 */
1184
1185 /*
1186 $$ACTION
1187 Rooms
1188 Set room [r:Room] damage to [f:Damage] with sound type [e:DamageSoundType]
1189 aRoomSetDamage
1190 Set room damage
1191 Sets the sepecifed room to damage the player
1192
1193 Parameters:
1194 Room: The room that will cause the damage
1195 Damage: the damage rate, in shield units per second
1196 $$END
1197 */
1198 void aRoomSetDamage(int roomnum, float damage, int soundtype) {
1199 msafe_struct mstruct;
1200
1201 mstruct.roomnum = roomnum;
1202 mstruct.amount = damage;
1203 mstruct.index = soundtype;
1204
1205 MSafe_CallFunction(MSAFE_ROOM_DAMAGE, &mstruct);
1206 }
1207
1208 /*
1209 $$ACTION
1210 Misc
1211 Show HUD message [s:Message]
1212 aShowHUDMessage
1213 Show HUD message
1214 Shows a HUD message for all players
1215
1216 Parameters:
1217 Message: The message to show
1218 $$END
1219 */
1220 void aShowHUDMessage(const char *format, ...) {
1221 msafe_struct mstruct;
1222 va_list args;
1223
1224 va_start(args, format);
1225 std::vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
1226 va_end(args);
1227 mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
1228
1229 mstruct.state = 0; // means all players
1230 mstruct.color = GR_RGB(0, 255, 0);
1231
1232 MSafe_CallFunction(MSAFE_MISC_HUD_MESSAGE, &mstruct);
1233 }
1234
1235 /*
1236 $$ACTION
1237 Misc
1238 Show HUD message [s:Message] for player [o:PlayerObject=IT]
1239 aShowHUDMessageObj
1240 Show HUD message
1241 Shows a HUD message for a specific player
1242
1243 Parameters:
1244 Message: The message to show
1245 PlayerObject: The player who sees the object
1246 $$END
1247 */
1248 void aShowHUDMessageObj(const char *format, int objhandle, ...) {
1249 msafe_struct mstruct;
1250 va_list args;
1251
1252 va_start(args, objhandle);
1253 std::vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
1254 va_end(args);
1255 mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
1256
1257 mstruct.state = 1; // means specific player
1258 mstruct.objhandle = dfGetPlayer(objhandle);
1259 mstruct.color = GR_RGB(0, 255, 0);
1260
1261 MSafe_CallFunction(MSAFE_MISC_HUD_MESSAGE, &mstruct);
1262 }
1263
1264 /*
1265 $$ACTION
1266 Misc
1267 Show Colored HUD message of color [i:Red] [i:Green] [i:Blue] saying [s:Message]
1268 aShowColoredHUDMessage
1269 Show Colored HUD message
1270 Shows a colored HUD message for all players
1271
1272 Parameters:
1273 Red: Red component of color (0-255)
1274 Green: Green component of color (0-255)
1275 Blue: Blue component of color (0-255)
1276 Message: The message to show
1277 $$END
1278 */
1279 void aShowColoredHUDMessage(int red, int green, int blue, const char *format, ...) {
1280 msafe_struct mstruct;
1281 va_list args;
1282
1283 va_start(args, format);
1284 std::vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
1285 va_end(args);
1286 mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
1287
1288 mstruct.state = 0; // means all players
1289 mstruct.color = GR_RGB((uint8_t)red, (uint8_t)green, (uint8_t)blue);
1290
1291 MSafe_CallFunction(MSAFE_MISC_HUD_MESSAGE, &mstruct);
1292 }
1293
1294 /*
1295 $$ACTION
1296 Misc
1297 Show Colored HUD message of color [i:Red] [i:Green] [i:Blue] saying [s:Message] for player [o:PlayerObject=IT]
1298 aShowColoredHUDMessageObj
1299 Show Colored HUD message
1300 Shows a colored HUD message for a specific player
1301
1302 Parameters:
1303 Red: Red component of color (0-255)
1304 Green: Green component of color (0-255)
1305 Blue: Blue component of color (0-255)
1306 Message: The message to show
1307 PlayerObject: The player who sees the object
1308 $$END
1309 */
1310 void aShowColoredHUDMessageObj(int red, int green, int blue, const char *format, int objhandle, ...) {
1311 msafe_struct mstruct;
1312 va_list args;
1313
1314 va_start(args, objhandle);
1315 std::vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
1316 va_end(args);
1317 mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
1318
1319 mstruct.state = 1;
1320 mstruct.objhandle = dfGetPlayer(objhandle);
1321 mstruct.color = GR_RGB((uint8_t)red, (uint8_t)green, (uint8_t)blue);
1322
1323 MSafe_CallFunction(MSAFE_MISC_HUD_MESSAGE, &mstruct);
1324 }
1325
1326 /*
1327 $$ACTION
1328 Misc
1329 Add Game Message [s:GameMessage] with HUD mesage [s:HUDMessage]
1330 aAddGameMessage
1331 Add Game Message
1332 Adds a message to the game message log, and shows another message on the HUD
1333
1334 Parameters:
1335 GameMessage: The message that's added to the game message log
1336 HUDMessage: The message that's displayed on the HUD
1337 $$END
1338 */
1339 void aAddGameMessage(const char *game_message, const char *hud_message) {
1340 msafe_struct mstruct;
1341
1342 strncpy(mstruct.message, game_message, sizeof(mstruct.message));
1343 mstruct.message[sizeof(mstruct.message) - 1] = 0;
1344
1345 strncpy(mstruct.message2, hud_message, sizeof(mstruct.message2));
1346 mstruct.message[sizeof(mstruct.message) - 1] = 0;
1347
1348 mstruct.color = GR_RGB(0, 242, 148);
1349 mstruct.state = 0; // means all players
1350
1351 MSafe_CallFunction(MSAFE_MISC_GAME_MESSAGE, &mstruct);
1352 }
1353
1354 /*
1355 $$ACTION
1356 Weather
1357 Turn rain ON with density = [p:Density=0.5:0.0|1.0]
1358 aRainTurnOn
1359 Turn rain ON
1360 Turns on the rain
1361
1362 Parameters:
1363 ??
1364 $$END
1365 */
1366 void aRainTurnOn(float density) {
1367 msafe_struct mstruct;
1368
1369 mstruct.scalar = density;
1370 mstruct.state = true;
1371
1372 MSafe_CallFunction(MSAFE_WEATHER_RAIN, &mstruct);
1373 }
1374
1375 /*
1376 $$ACTION
1377 Weather
1378 Turn rain OFF
1379 aRainTurnOff
1380 Turn rain OFF
1381 Turns off the rain
1382
1383 Parameters:
1384 None.
1385 $$END
1386 */
1387 void aRainTurnOff() {
1388 msafe_struct mstruct;
1389
1390 mstruct.state = false;
1391
1392 MSafe_CallFunction(MSAFE_WEATHER_RAIN, &mstruct);
1393 }
1394
1395 /*
1396 $$ACTION
1397 Weather
1398 Turn snow ON with density = [p:Density=0.5:0.0|1.0]
1399 aSnowTurnOn
1400 Turn snow ON
1401 Turns on the snow
1402
1403 Parameters:
1404 ??
1405 $$END
1406 */
1407 void aSnowTurnOn(float density) {
1408 msafe_struct mstruct;
1409
1410 mstruct.scalar = density;
1411 mstruct.state = true;
1412
1413 MSafe_CallFunction(MSAFE_WEATHER_SNOW, &mstruct);
1414 }
1415
1416 /*
1417 $$ACTION
1418 Weather
1419 Turn snow OFF
1420 aSnowTurnOff
1421 Turn snow OFF
1422 Turns off the snow
1423
1424 Parameters:
1425 None
1426 $$END
1427 */
1428 void aSnowTurnOff() {
1429 msafe_struct mstruct;
1430
1431 mstruct.state = false;
1432
1433 MSafe_CallFunction(MSAFE_WEATHER_SNOW, &mstruct);
1434 }
1435
1436 /*
1437 $$ACTION
1438 Weather
1439 Turn lightning ON with frequency of [f:Seconds=5.0] and probability of [p:Probability=0.5]
1440 aLightningTurnOn
1441 Turn lightning ON
1442 Turns on the lightning
1443
1444 Parameters:
1445 Seconds: How often to check to create lightning
1446 Probability: The chance of creating lightning at each check
1447 $$END
1448 */
1449 void aLightningTurnOn(float check_delay, float prob) {
1450 msafe_struct mstruct;
1451
1452 mstruct.state = true;
1453 mstruct.scalar = check_delay;
1454 mstruct.randval = static_cast<int>(prob * static_cast<float>(RAND_MAX));
1455
1456 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING, &mstruct);
1457 }
1458
1459 /*
1460 $$ACTION
1461 Weather
1462 Turn lightning OFF
1463 aLightningTurnOff
1464 Turn lightning OFF
1465 Turns off the lightning
1466
1467 Parameters:
1468 None
1469 $$END
1470 */
1471 void aLightningTurnOff() {
1472 msafe_struct mstruct;
1473
1474 mstruct.state = false;
1475
1476 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING, &mstruct);
1477 }
1478
1479 /*
1480 $$ACTION
1481 Weather
1482 Create lighting between [o:Object1] and [o:Object2]; with [f:Lifetime=1.0], [f:Thickness=1.0], [i:NumTiles=1],
1483 [u:Texture], [f:SlideTime=0], [i:TimesDrawn=1], and color=[i:Red=255],[i:Green=255],[i:Blue=255],
1484 AutoTile=[b:AutoTile=false] aLightningCreate Create lighting between two objects Creates a lighting effect between two
1485 specified obejcts
1486
1487 Parameters:
1488 Object1, Object2: Where the lighting is created
1489 Lifetime: How long the lighting lasts
1490 Thickness: How thick the lightning is
1491 NumTiles: How many times to tile the texture within the bolt
1492 Texture: The texture to be used for the lighting
1493 SlideTime: The time it will take to slide the entire bolt once
1494 TimesDrawn: The number of times to draw the bolt (saturation)
1495 Red, Green, Blue: The color of the lighting (0-255)
1496 AutoTile - For automatic UV tiling based on the length of the bolt
1497 $$END
1498 */
1499 void aLightningCreate(int objhandle1, int objhandle2, float lifetime, float thickness, int numtiles, int texture_id,
1500 float slidetime, int timesdrawn, int red, int green, int blue, bool autotile) {
1501 msafe_struct mstruct;
1502 int type;
1503
1504 Obj_Value(objhandle1, VF_GET, OBJV_I_TYPE, &type);
1505 if (type == OBJ_NONE)
1506 return;
1507
1508 Obj_Value(objhandle2, VF_GET, OBJV_I_TYPE, &type);
1509 if (type == OBJ_NONE)
1510 return;
1511
1512 Obj_Value(objhandle1, VF_GET, OBJV_I_ROOMNUM, &mstruct.roomnum);
1513 Obj_Value(objhandle1, VF_GET, OBJV_V_POS, &mstruct.pos);
1514 Obj_Value(objhandle2, VF_GET, OBJV_V_POS, &mstruct.pos2);
1515
1516 mstruct.objhandle = objhandle1;
1517 mstruct.ithandle = objhandle2;
1518 mstruct.lifetime = lifetime;
1519 mstruct.size = thickness;
1520
1521 mstruct.interval = slidetime;
1522 mstruct.count = timesdrawn;
1523 mstruct.index = numtiles;
1524 mstruct.texnum = texture_id;
1525 mstruct.color = ((red >> 3) << 10) | ((green >> 3) << 5) | (blue >> 3);
1526
1527 if (autotile)
1528 mstruct.state = 1;
1529 else
1530 mstruct.state = 0;
1531
1532 mstruct.flags = 0;
1533
1534 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
1535 }
1536
1537 /*
1538 $$ACTION
1539 Weather
1540 Create lighting between gunpoints [i:Gunpoint1=0] & [i:Gunpoint2=1] of [o:Object=OWNER]; with [f:Lifetime=1.0],
1541 [f:Thickness=1.0], [i:NumTiles=1], [u:Texture], [f:SlideTime=0], [i:TimesDrawn=1], and
1542 color=[i:Red=255],[i:Green=255],[i:Blue=255], AutoTile=[b:AutoTile=false] aLightningCreateGunpoints Create lighting
1543 between gunpoints Creates a lighting effect between two specified gunpoints on an object
1544
1545 Parameters:
1546 Object: Where the lighting is created
1547 Gunpoint1,Gunpoint2: The points between which the lightning is created
1548 Lifetime: How long the lighting lasts
1549 Thickness: How thick the lightning is
1550 NumTiles: How many times to tile the texture within the bolt
1551 Texture: The texture to be used for the lighting
1552 SlideTime: The time it will take to slide the entire bolt once
1553 TimesDrawn: The number of times to draw the bolt (saturation)
1554 Red, Green, Blue: The color of the lighting (0-255)
1555 AutoTile - For automatic UV tiling based on the length of the bolt
1556 $$END
1557 */
1558 void aLightningCreateGunpoints(int gunpoint1, int gunpoint2, int objhandle, float lifetime, float thickness,
1559 int numtiles, int texture_id, float slidetime, int timesdrawn, int red, int green,
1560 int blue, bool autotile) {
1561 msafe_struct mstruct;
1562
1563 mstruct.objhandle = objhandle;
1564 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
1565 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
1566 if (mstruct.roomnum == -1)
1567 return;
1568
1569 mstruct.g1 = gunpoint1;
1570 mstruct.g2 = gunpoint2;
1571
1572 mstruct.lifetime = lifetime;
1573 mstruct.size = thickness;
1574 mstruct.interval = slidetime;
1575 mstruct.count = timesdrawn;
1576 mstruct.index = numtiles;
1577 mstruct.texnum = texture_id;
1578 mstruct.color = ((red >> 3) << 10) | ((green >> 3) << 5) | (blue >> 3);
1579
1580 if (autotile)
1581 mstruct.state = 1;
1582 else
1583 mstruct.state = 0;
1584
1585 mstruct.flags = 1;
1586
1587 MSafe_CallFunction(MSAFE_WEATHER_LIGHTNING_BOLT, &mstruct);
1588 }
1589
1590 /*
1591 $$ACTION
1592 User Vars
1593 Set user flag [e:UserFlag] to [b:True/False]
1594 aUserFlagSet
1595 Set user flag
1596 Set a flag to true or flase
1597
1598 Parameters:
1599 UserFlag: The variable to set
1600 True/False: What to set the flag to
1601 $$END
1602 */
1603 void aUserFlagSet(int flagnum, bool state) {
1604 if ((flagnum >= 0) && (flagnum < 32)) {
1605 int bit = 1 << flagnum;
1606 if (state)
1607 User_flags |= bit;
1608 else
1609 User_flags &= ~bit;
1610 }
1611 }
1612
1613 /*
1614 $$ACTION
1615 User Vars
1616 Set user var [e:UserVar] to [f:value]
1617 aUserVarSet
1618 Set user var
1619 Set a user variable to specific value
1620
1621 Parameters:
1622 UserVar: The variable to set
1623 Value: The value assigned to the variable
1624 $$END
1625 */
1626 void aUserVarSet(int varnum, float value) {
1627 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
1628 User_vars[varnum] = value;
1629 }
1630
1631 /*
1632 $$ACTION
1633 User Vars
1634 Increment user var [e:UserVar]
1635 aUserVarInc
1636 Increment user var
1637 Adds one to a user variable
1638
1639 Parameters:
1640 UserVar: The variable to increment
1641 $$END
1642 */
1643 void aUserVarInc(int varnum) {
1644 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
1645 User_vars[varnum]++;
1646 }
1647
1648 /*
1649 $$ACTION
1650 User Vars
1651 Decrement user var [e:UserVar]
1652 aUserVarDec
1653 Decrement user var
1654 Subtracts one to a user variable
1655
1656 Parameters:
1657 UserVar: The variable to decrement
1658 $$END
1659 */
1660 void aUserVarDec(int varnum) {
1661 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
1662 User_vars[varnum]--;
1663 }
1664
1665 /*
1666 $$ACTION
1667 User Vars
1668 Add [f:value] to user var [e:UserVar]
1669 aUserVarAdd
1670 Add to user var
1671 Adds to a user variable
1672
1673 Parameters:
1674 Value: The amount to add to the user variable
1675 UserVar: The variable to be modified
1676 $$END
1677 */
1678 void aUserVarAdd(float value, int varnum) {
1679 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
1680 User_vars[varnum] += value;
1681 }
1682
1683 /*
1684 $$ACTION
1685 User Vars
1686 Subtract [f:value] from user var [e:UserVar]
1687 aUserVarSub
1688 Subtract from user var
1689 Subtracts from a user variable
1690
1691 Parameters:
1692 Value: The amount to subtract from the user variable
1693 UserVar: The variable to be modified
1694 $$END
1695 */
1696 void aUserVarSub(float value, int varnum) {
1697 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
1698 User_vars[varnum] -= value;
1699 }
1700
1701 /*
1702 $$ENUM Lock/Unlock
1703 0:UNLOCK
1704 1:LOCK
1705 $$END
1706 */
1707
1708 /*
1709 $$ACTION
1710 Doors
1711 [e:Lock/Unlock] door [d:DoorName]
1712 aDoorLockUnlock
1713 Lock/Unlock door
1714 Locks or unlocks the specified door
1715
1716 Parameters:
1717 DoorName: the object name of the door to be locked or unlocked
1718 $$END
1719 */
1720 void aDoorLockUnlock(int state, int objref) {
1721 msafe_struct mstruct;
1722
1723 mstruct.objhandle = objref;
1724 mstruct.state = state;
1725
1726 MSafe_CallFunction(MSAFE_DOOR_LOCK_STATE, &mstruct);
1727 }
1728
1729 /*
1730 $$ACTION
1731 Doors
1732 Activate door [d:Door]
1733 aDoorActivate
1734 Activate door
1735 Activates (i.e. opens and possibly closes) the specified door
1736
1737 Parameters:
1738 Door: the object of the door to be activated
1739 $$END
1740 */
1741 void aDoorActivate(int objref) {
1742 msafe_struct mstruct;
1743
1744 mstruct.objhandle = objref;
1745
1746 MSafe_CallFunction(MSAFE_DOOR_ACTIVATE, &mstruct);
1747 }
1748
1749 /*
1750 $$ACTION
1751 Doors
1752 Set door [d:Door] position to [p:Position]
1753 aDoorSetPos
1754 Set door position
1755 Moves the door to the specified position
1756
1757 Parameters:
1758 Door: the object of the door to be set
1759 Position: the position of the door, with 0% being fully closed and 100% fully open
1760 $$END
1761 */
1762 void aDoorSetPos(int objhandle, float pos) {
1763 msafe_struct mstruct;
1764
1765 mstruct.objhandle = objhandle;
1766 mstruct.scalar = pos;
1767
1768 MSafe_CallFunction(MSAFE_DOOR_POSITION, &mstruct);
1769 }
1770
1771 /*
1772 $$ACTION
1773 Doors
1774 Stop door [d:Door]
1775 aDoorStop
1776 Stop door
1777 Stops the specified door if it's animating
1778
1779 Parameters:
1780 Door: the object of the door to stop
1781 $$END
1782 */
1783 void aDoorStop(int objhandle) {
1784 msafe_struct mstruct;
1785
1786 mstruct.objhandle = objhandle;
1787
1788 MSafe_CallFunction(MSAFE_DOOR_STOP, &mstruct);
1789 }
1790
1791 /*
1792 $$ACTION
1793 Misc
1794 Create Popup View at gunpoint [i:GunPoint] of [o:Object] for [f:Time=10.0] seconds with zoom [f:Zoom=1.0]
1795 aCreatePopupView
1796 Creates a temorary view window
1797
1798 Parameters:
1799 GunPoint: the gun number where the viewer should be placed
1800 Object: the object that is the viewer
1801 Time: how long the view lasts. If time set to 0, popup stays up until explicitly closed.
1802 Zoom: the relative zoom of the viewer camera. 1.0 is the normal zoom.
1803 $$END
1804 */
1805 void aCreatePopupView(int gunpoint, int objref, float time, float zoom) {
1806 msafe_struct mstruct;
1807
1808 mstruct.objhandle = objref;
1809 mstruct.interval = time;
1810 mstruct.gunpoint = gunpoint;
1811 mstruct.scalar = zoom;
1812
1813 MSafe_CallFunction(MSAFE_MISC_POPUP_CAMERA, &mstruct);
1814 }
1815
1816 /*
1817 $$ACTION
1818 Misc
1819 Close the popup view
1820 aClosePopupView
1821 Closes the popup view, if it's up
1822
1823 Parameters:
1824 None.
1825 $$END
1826 */
1827 void aClosePopupView() { MSafe_CallFunction(MSAFE_MISC_CLOSE_POPUP, NULL); }
1828
1829 /*
1830 $$ACTION
1831 Objects
1832 Set object [o:Object] shields to [f:Shields]
1833 aObjSetShields
1834 Set object shields
1835 Sets an object's shields to a specific value
1836
1837 Parameters:
1838 Object: the object whose shields are being set
1839 Shields: the value to assign to the object's shields
1840 $$END
1841 */
1842 void aObjSetShields(int objref, float shields) {
1843 msafe_struct mstruct;
1844
1845 mstruct.objhandle = objref;
1846 mstruct.shields = shields;
1847
1848 MSafe_CallFunction(MSAFE_OBJECT_SHIELDS, &mstruct);
1849 }
1850
1851 /*
1852 $$ACTION
1853 Objects
1854 Set object [o:Object] energy to [f:Energy]
1855 aObjSetEnergy
1856 Set object energy
1857 Sets an object's energy to a specific value
1858
1859 Parameters:
1860 Object: the object whose energy are being set
1861 Energy: the value to assign to the object's energy
1862 $$END
1863 */
1864 void aObjSetEnergy(int objref, float energy) {
1865 msafe_struct mstruct;
1866
1867 mstruct.objhandle = objref;
1868 mstruct.energy = energy;
1869
1870 MSafe_CallFunction(MSAFE_OBJECT_ENERGY, &mstruct);
1871 }
1872
1873 /*
1874 $$ACTION
1875 Objects
1876 Play object [o:Object] animation from frame [i:StartFrame] to [i:EndFrame=1], cycle time = [f:CycleTime=1.0], looping =
1877 [b:Looping=FALSE] aObjPlayAnim Play object animation Plays an animation for an object
1878
1879 Parameters:
1880 Object: the object to animate
1881 StartFrame: the frame number of the start of the animation
1882 EndFrame: the frame number of the end of the animation
1883 CycleTime: how long the entire animation takes
1884 Looping: if true, animation repeats. If false, animation plays once
1885 $$END
1886 */
1887 void aObjPlayAnim(int objref, int startframe, int endframe, float cycletime, bool looping) {
1888 int flags = 0;
1889
1890 if (looping)
1891 flags |= AIAF_LOOPING;
1892
1893 Obj_SetCustomAnim(objref, (float)startframe, (float)endframe, cycletime, flags, -1, -1);
1894 }
1895
1896 /*
1897 $$ACTION
1898 Objects
1899 Damage object [o:Object] by [f:DamageAmount]
1900 aObjApplyDamage
1901 Damage object
1902 Applies damage to an object
1903
1904 Parameters:
1905 Object: the object to damage
1906 DamageAmount: how much damage to apply to the object (scaled by difficulty level)
1907 $$END
1908 */
1909 void aObjApplyDamage(int objref, float damage) {
1910 msafe_struct mstruct;
1911
1912 mstruct.objhandle = objref;
1913 mstruct.killer_handle = objref;
1914 mstruct.damage_type = 0;
1915 mstruct.amount = damage;
1916
1917 MSafe_CallFunction(MSAFE_OBJECT_DAMAGE_OBJECT, &mstruct);
1918 }
1919
1920 /*
1921 Death info
1922
1923 $$ENUM DeathDelayType
1924 0:No Delay
1925 1:Delay Min/Max
1926 2:Delay from Anim
1927 $$END
1928
1929 $$ENUM DeathExplosionSize
1930 0:Small
1931 1:Medium
1932 2:Large
1933 $$END
1934
1935 $$FLAG DeathFlags
1936 4:During Delay: Sparks
1937 8:During Delay: Loses anti-grav
1938 16:During Delay: Smokes
1939 1048576:During Delay: Flies in air
1940 2097152:During Delay: Fireballs
1941 4194304:During Delay: Fades away
1942 32:On Death: Fireballs
1943 64:On Death: Breaks apart
1944 128:On Death: Blast ring
1945 256:On Death: Remains
1946 512:On Death: Loses anti-grav
1947 8388608:On Death: Fades away
1948 4096:On Contact: Fireball
1949 8192:On Contact: Breaks apart
1950 16384:On Contact: Blask ring
1951 32768:On Contact: Remains
1952 65536:Debris: Smokes
1953 131072:Debris Death: Fireball
1954 262144:Debris Death: Blast ring
1955 524288:Debris Death: Remains
1956 $$END
1957
1958 $$ACTION
1959 Objects
1960 Kill object [o:Object]; delay type = [e:DeathDelayType], explosion size = [e:DeathExplosionSize], death flags =
1961 [g:DeathFlags], Min/Max delay = [f:MinDelay] / [f:MaxDelay] aObjKill Kill Object Kills the specified object using the
1962 specified death info
1963
1964 Parameters:
1965 Object: the object to kill
1966 $$END
1967 */
1968 void aObjKill(int objhandle, int delay_type, int expl_size, int death_flags, float min_delay, float max_delay) {
1969 death_flags |= (expl_size << DF_EXPL_SIZE_SHIFT);
1970
1971 if (delay_type == 2)
1972 death_flags |= DF_DELAY_FROM_ANIM;
1973
1974 if (delay_type == 0)
1975 min_delay = max_delay = 0;
1976
1977 Obj_Kill(objhandle, OBJECT_HANDLE_NONE, 1000.0f, death_flags, min_delay, max_delay);
1978 }
1979
1980 /*
1981 $$ACTION
1982 Objects
1983 Kill object [o:Object] with its default death
1984 aObjDestroy
1985 Kill Object with default death
1986 Kills the specified object using the object's default death
1987
1988 Parameters:
1989 Object: the object to kill
1990 $$END
1991 */
1992 void aObjDestroy(int objhandle) { Obj_Kill(objhandle, OBJECT_HANDLE_NONE, 1000.0f, -1, 0.0, 0.0); }
1993
1994 /*
1995 $$ACTION
1996 Objects
1997 Delete object [o:Object]
1998 aObjDelete
1999 Delete Object
2000 Delete the specified object. The object disappears with no death.
2001
2002 Parameters:
2003 Object: the object to delete
2004 $$END
2005 */
2006 void aObjDelete(int objhandle) {
2007 msafe_struct mstruct;
2008
2009 mstruct.objhandle = objhandle;
2010 mstruct.playsound = 0;
2011
2012 MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mstruct);
2013 }
2014
2015 /*
2016 $$ACTION
2017 Objects
2018 Set object [o:Object] lighting distance to [f:Distance]
2019 aObjSetLightingDist
2020 Set object lighting distance
2021 Sets the lighting distance for an object
2022
2023 Parameters:
2024 Object: the object to set
2025 Distance: how far the light from the object will cast
2026 $$END
2027 */
2028 void aObjSetLightingDist(int objhandle, float dist) {
2029 msafe_struct mstruct;
2030
2031 mstruct.objhandle = objhandle;
2032 mstruct.light_distance = dist;
2033
2034 MSafe_CallFunction(MSAFE_OBJECT_LIGHT_DIST, &mstruct);
2035 }
2036
2037 /*
2038 $$ACTION
2039 Objects
2040 Set object [o:Object] lighting color = [f:Red=0.5],[f:Green=0.5],[f:Blue=0.5]
2041 aObjSetLightingColor
2042 Set object lighting color
2043 Sets the lighting color for an object
2044
2045 Parameters:
2046 Object: the object to set
2047 R,G,B: the fog color (0.0 to 1.0 for each of R,G, & B)
2048 $$END
2049 */
2050 void aObjSetLightingColor(int objhandle, float r, float g, float b) {
2051 msafe_struct mstruct;
2052
2053 mstruct.objhandle = objhandle;
2054 mstruct.r1 = r;
2055 mstruct.g1 = g;
2056 mstruct.b1 = b;
2057
2058 MSafe_CallFunction(MSAFE_OBJECT_LIGHT_COLOR, &mstruct);
2059 }
2060
2061 /*
2062 $$ACTION
2063 Objects
2064 [e:Enable/Disable] gravity for object [o:Object]
2065 aObjGravityEnable
2066 Enable/Disable object gravity
2067 Enable or Disable gravity for the specified object
2068
2069 Parameters:
2070 Enable/Disable: whether gravity should be on or off
2071 Object: the object to set
2072 $$END
2073 */
2074 void aObjGravityEnable(int enable, int objhandle) {
2075 int flags = PF_GRAVITY;
2076
2077 Obj_Value(objhandle, enable ? VF_SET_FLAGS : VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
2078 }
2079
2080 /*
2081 Object movement types
2082 $$ENUM MovementType
2083 0:None
2084 1:Physics
2085 2:Walking
2086 $$END
2087 */
2088
2089 /*
2090 $$ACTION
2091 Objects
2092 Set movement type for [o:Object] to [e:MovementType]
2093 aObjSetMovementType
2094 Set movement type for object
2095 Sets the movement type for an object
2096
2097 Parameters:
2098 Object: the object to set
2099 MovementType: how this object moves
2100 $$END
2101 */
2102 void aObjSetMovementType(int objhandle, int mtype) { Obj_Value(objhandle, VF_SET, OBJV_C_MOVEMENT_TYPE, &mtype); }
2103
2104 /*
2105 $$ACTION
2106 Objects
2107 Set object [o:Object] movement direction = <[f:X],[f:Y],[f:Z]>, speed = [f:Speed=1.0]
2108 aObjSetVelocity
2109 Set object movement direction and speed
2110 Sets the movement direction and speed for an object
2111
2112 Parameters:
2113 Object: the object to set
2114 X,Y,Z: the direction vector for the wind
2115 Speed: the speed of the wind (10.0 is faster than the player ship)
2116 $$END
2117 */
2118 void aObjSetVelocity(int objhandle, float x, float y, float z, float speed) {
2119 vector velocity;
2120
2121 velocity.x = x * speed;
2122 velocity.y = y * speed;
2123 velocity.z = z * speed;
2124
2125 Obj_Value(objhandle, VF_SET, OBJV_V_VELOCITY, &velocity);
2126 }
2127
2128 /*
2129 $$ACTION
2130 Rooms
2131 Turn [e:On/Off] Strobe in room [r:Room]
2132 aRoomSetLightingStrobe
2133 Turn On/Off strobe in room
2134 Turns on or off the light stobe in a room
2135
2136 Parameters:
2137 On/Off: whether the stobe should be on or off
2138 Room: the room to set
2139 $$END
2140 */
2141 void aRoomSetLightingStrobe(int state, int roomnum) {
2142 msafe_struct mstruct;
2143
2144 mstruct.roomnum = roomnum;
2145 mstruct.state = state;
2146
2147 MSafe_CallFunction(MSAFE_ROOM_LIGHT_STROBE, &mstruct);
2148 }
2149
2150 /*
2151 $$ACTION
2152 Rooms
2153 Turn [e:On/Off] Flicker in room [r:Room]
2154 aRoomSetLightingFlicker
2155 Turn On/Off flicker in room
2156 Turns on or off the light flicker in a room
2157
2158 Parameters:
2159 On/Off: whether the flicker should be on or off
2160 Room: the room to set
2161 $$END
2162 */
2163 void aRoomSetLightingFlicker(int state, int roomnum) {
2164 msafe_struct mstruct;
2165
2166 mstruct.roomnum = roomnum;
2167 mstruct.state = state;
2168
2169 MSafe_CallFunction(MSAFE_ROOM_LIGHT_FLICKER, &mstruct);
2170 }
2171
2172 /*
2173 $$ACTION
2174 Rooms
2175 Turn [e:On/Off] fuelcen in room [r:Room]
2176 aRoomSetFuelcen
2177 Turn On/Off fuelcen in room
2178 Turns on or off the fuelcen in a room
2179
2180 Parameters:
2181 On/Off: whether the fuelcen should be on or off
2182 Room: the room to set
2183 $$END
2184 */
2185 void aRoomSetFuelcen(int state, int roomnum) {
2186 msafe_struct mstruct;
2187
2188 mstruct.roomnum = roomnum;
2189 mstruct.state = state;
2190
2191 MSafe_CallFunction(MSAFE_ROOM_REFUEL, &mstruct);
2192 }
2193
2194 /*
2195 $$ACTION
2196 Rooms
2197 Set room [r:Room] lighting pulse time = [f:PulseTime] offset = [f:PulseOffset]
2198 aRoomSetLightingPulse
2199 Set room lighting pulse values
2200 Sets the lighting pulse values for a room
2201
2202 Parameters:
2203 Room: the room to set
2204 PulseTime: how long a pulse cycle takes, or 0 to turn off pulse
2205 PulseOffset: the time offset for this pulse
2206 $$END
2207 */
2208 void aRoomSetLightingPulse(int roomnum, float time, float offset) {
2209 msafe_struct mstruct;
2210
2211 mstruct.roomnum = roomnum;
2212 mstruct.pulse_time = (uint8_t)(time * 100);
2213 mstruct.pulse_offset = (uint8_t)(offset * 100);
2214
2215 MSafe_CallFunction(MSAFE_ROOM_LIGHT_PULSE, &mstruct);
2216 }
2217
2218 /*
2219 $$ACTION
2220 Misc
2221 Set waypoint [i:Number]
2222 aSetWaypoint
2223 Set waypoint
2224 Sets the specified waypoint as active
2225
2226 Parameters:
2227 Number: which waypoint to set
2228 $$END
2229 */
2230 void aSetWaypoint(int number) {
2231 msafe_struct mstruct;
2232
2233 mstruct.index = number;
2234
2235 MSafe_CallFunction(MSAFE_MISC_WAYPOINT, &mstruct);
2236 }
2237
2238 /*
2239 $$ACTION
2240 Spew
2241 Turn ON spew from [o:Object] at gunpoint
2242 [i:GunNum];[e:SpewType=7],[f:Mass=0.0],[f:Drag=0.0],[g:PhysicsFlags=65536:100480],[b:IsRealObject=FALSE],[f:BlobLifetime=1.5],[f:BlobInterval=0.15],[f:SpewLife=30.0],[f:BlobSize=4.0],[f:BlobSpeed=20.0],[b:Randomize].
2243 Handle = [e:SpewHandle] aTurnOnSpew Turn on spew Turns on spew and sets the spew type and other variables
2244
2245 Parameters:
2246 Object: the object to spew from
2247 GunNum: the gunpoint on the object to spew from, or -1 to spew from center of object
2248 SpewType: The type of effect the blobs of spew should be
2249 Mass: the mass of each blob of spew
2250 Drag: the drag of the blob as it moves through the atmosphere
2251 PhysicsFlags: how the slews blobs are treated by the physics
2252 IsRealObject: if set than the spew blobs are real objects, else it's just a viseffect (leave it as is unless you know
2253 what you are doing) BlobLifetime: the lifetime of each blob of spew BlobInterval: how often a new blob of spew should be
2254 created SpewLife: the lifetime of the spewer (-1 for infinite) BlobSize: the size of each blob of spew BlobSpeed: the
2255 speed of each blob spew Randomize: if set than BlobSize, BlobSpeed and BlobLifetime are randomized a little (+/- some)
2256 for each blob SpewHandle: Where to store the handle for this spewer
2257 $$END
2258 */
2259 void aTurnOnSpew(int objref, int gunpoint, int effect_type, float mass, float drag, int gravity_type, uint8_t isreal,
2260 float lifetime, float interval, float longevity, float size, float speed, uint8_t random,
2261 int handle_slot) {
2262 msafe_struct mstruct;
2263
2264 mstruct.objhandle = objref;
2265 mstruct.gunpoint = gunpoint;
2266 mstruct.effect_type = effect_type;
2267 mstruct.mass = mass;
2268 mstruct.drag = drag;
2269 mstruct.phys_info = gravity_type;
2270 mstruct.is_real = isreal;
2271 mstruct.lifetime = lifetime;
2272 mstruct.interval = interval;
2273 mstruct.longevity = longevity;
2274 mstruct.size = size;
2275 mstruct.speed = speed;
2276 mstruct.random = (random) ? SPEW_RAND_SIZE | SPEW_RAND_LIFETIME | SPEW_RAND_SPEED : 0;
2277
2278 MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct);
2279
2280 if ((handle_slot >= 0) && (handle_slot < MAX_SPEW_HANDLES))
2281 Spew_handles[handle_slot] = mstruct.id;
2282 }
2283
2284 /*
2285 $$ACTION
2286 Spew
2287 Turn OFF spew from [e:SpewHandle]
2288 aTurnOffSpew
2289 Turn off spew
2290 Turns off spew that was created with Turn On Spew. Pass in the handle given by Turn On Spew.
2291
2292 Parameters:
2293 SpewHandle: the handle of the spewer to stop
2294 $$END
2295 */
2296 void aTurnOffSpew(int handle_slot) {
2297 msafe_struct mstruct;
2298
2299 if ((handle_slot >= 0) && (handle_slot < MAX_SPEW_HANDLES)) {
2300
2301 mstruct.id = Spew_handles[handle_slot];
2302
2303 if (mstruct.id != SPEW_INVALID_HANDLE) {
2304 MSafe_CallFunction(MSAFE_OBJECT_STOP_SPEW, &mstruct);
2305 Spew_handles[handle_slot] = SPEW_INVALID_HANDLE;
2306 }
2307 }
2308 }
2309
2310 /*
2311 $$ACTION
2312 Objects
2313 Attach new object of type [a:ChildTypeName] attachpoint [i:ChildPoint] to object [o:Parent] at attachpoint
2314 [i:ParentPoint] aAttachObject Attach new object Creates a new object attached to another object
2315
2316 Parameters:
2317 $$END
2318 */
2319 void aAttachObject(const char *objtypename, int childpoint, int objref, int parentpoint) {
2320 int child_handle;
2321 int child_type = Obj_FindType(objtypename);
2322 int child_id = Obj_FindID(objtypename);
2323
2324 if (child_id >= 0) {
2325
2326 msafe_struct mstruct;
2327 mstruct.objhandle = objref;
2328 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
2329 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
2330
2331 child_handle = Obj_Create(child_type, child_id, mstruct.roomnum, &mstruct.pos);
2332
2333 if (child_handle != OBJECT_HANDLE_NONE) {
2334 if (!Obj_AttachObjectAP(objref, parentpoint, child_handle, childpoint, 1)) {
2335
2336 //!!Error attaching, so delete new object
2337 }
2338 }
2339 }
2340 }
2341
2342 /*
2343 $$ACTION
2344 Objects
2345 UnAttach [o:AttachedObject] from an object
2346 aUnAttachObject
2347 UnAttach an object from another one
2348 Unattaches an object
2349
2350 Parameters:
2351 $$END
2352 */
2353 void aUnAttachObject(int objref) { Obj_UnattachFromParent(objref); }
2354
2355 /*
2356 $$ACTION
2357 Objects
2358 Object [o:ParentObject] drop all attached objects
2359 aDropObjects
2360 Drop attached objects
2361 Makes an object drop objects attached to it
2362
2363 Parameters:
2364 $$END
2365 */
2366 void aDropObjects(int objref) { Obj_UnattachChildren(objref); }
2367
2368 /*
2369 $$ACTION
2370 Objects
2371 Attach existing object [o:Child] attachpoint [i:ChildPoint] to object [o:Parent] at attachpoint [i:ParentPoint]
2372 aAttachExistingObject
2373 Attach existing object to another object
2374 Attaches an existing object to another object
2375
2376 Parameters:
2377 $$END
2378 */
2379 void aAttachExistingObject(int child_ref, int childpoint, int objref, int parentpoint) {
2380 if (!Obj_AttachObjectAP(objref, parentpoint, child_ref, childpoint, 1)) {
2381
2382 //!!Error attaching, so delete new object
2383 }
2384 }
2385
2386 /*
2387 $$ACTION
2388 Sound && Music
2389 Set music region to [e:Region] for player [o:PlayerObject=IT]
2390 aMusicSetRegion
2391 Set music region
2392 Sets the specified region as the active region for the music system
2393
2394 Parameters:
2395 Region: which region is now active
2396 PlayerObject: which player gets the music change
2397 $$END
2398 */
2399 void aMusicSetRegion(int region_num, int objhandle) {
2400 msafe_struct mstruct;
2401
2402 mstruct.state = 0; // specific player
2403 mstruct.index = region_num;
2404 mstruct.objhandle = objhandle;
2405
2406 MSafe_CallFunction(MSAFE_MUSIC_REGION, &mstruct);
2407 }
2408
2409 /*
2410 $$ACTION
2411 Sound && Music
2412 Set music region to [e:Region] for all players
2413 aMusicSetRegionAll
2414 Set music region for all players
2415 Sets the specified region as the active region for the music system for all players
2416
2417 Parameters:
2418 Region: which region is now active
2419 $$END
2420 */
2421 void aMusicSetRegionAll(int region_num) {
2422 msafe_struct mstruct;
2423
2424 mstruct.state = 0; // all players
2425 mstruct.index = region_num;
2426
2427 MSafe_CallFunction(MSAFE_MUSIC_REGION, &mstruct);
2428 }
2429
2430 /*
2431 $$ACTION
2432 Timer
2433 Generate object [o:Object] timer event in [f:Time] seconds with ID [e:TimerID]
2434 aSetObjectTimer
2435 Generate object timer event
2436 Sets an object timer to go off in the specified amount of time
2437
2438 Parameters:
2439 Object: the object to receive the timer notification
2440 Time: how long in seconds until notification
2441 TimerID: the ID for this timer
2442 $$END
2443 */
2444 void aSetObjectTimer(int objref, float time, int id) {
2445 tOSIRISTIMER timer_info;
2446
2447 timer_info.flags = 0;
2448 timer_info.repeat_count = 0;
2449 timer_info.object_handle = objref;
2450 timer_info.object_handle_detonator = OBJECT_HANDLE_NONE;
2451 timer_info.timer_interval = time;
2452 timer_info.id = id;
2453
2454 Scrpt_CreateTimer(&timer_info);
2455 }
2456
2457 /*
2458 $$ACTION
2459 Timer
2460 Generate level timer event in [f:Time] seconds using with ID [e:TimerID]
2461 aSetLevelTimer
2462 Generate level timer event
2463 Sets a level timer to go off in the specified amount of time
2464
2465 Parameters:
2466 Time: how long in seconds until notification
2467 TimerID: the ID for this timer
2468 $$END
2469 */
2470 void aSetLevelTimer(float time, int id) {
2471 tOSIRISTIMER timer_info;
2472
2473 timer_info.flags = OTF_LEVEL;
2474 timer_info.repeat_count = OTF_LEVEL;
2475 timer_info.object_handle_detonator = OBJECT_HANDLE_NONE;
2476 timer_info.timer_interval = time;
2477 timer_info.id = id;
2478
2479 Scrpt_CreateTimer(&timer_info);
2480 }
2481
2482 /*
2483 $$ACTION
2484 Timer
2485 Cancel Timer [e:TimerID]
2486 aCancelTimer
2487 Cancels a timer event
2488 Cancels a timer
2489
2490 Parameters:
2491 TimerID: the ID for this timer
2492 $$END
2493 */
2494 void aCancelTimer(int id) { Scrpt_CancelTimerID(id); }
2495
2496 /*
2497 $$ACTION
2498 Timer
2499 Show Timer [e:TimerID] on HUD
2500 aTimerShow
2501 Show Timer on HUD
2502 Shows the specified timer on the HUD
2503
2504 Parameters:
2505 TimerID: the ID for this timer
2506 $$END
2507 */
2508 void aTimerShow(int id) {
2509 msafe_struct mstruct;
2510
2511 mstruct.index = id;
2512 mstruct.color = GR_RGB(0, 255, 0);
2513 MSafe_CallFunction(MSAFE_MISC_START_TIMER, &mstruct);
2514 }
2515
2516 /*
2517 $$ACTION
2518 Mission
2519 End level
2520 aEndLevel
2521 End level
2522 Terminates the level
2523
2524 Parameters:
2525 None.
2526 $$END
2527 */
2528 void aEndLevel() {
2529 msafe_struct mstruct;
2530
2531 mstruct.state = 1; // success
2532 MSafe_CallFunction(MSAFE_MISC_END_LEVEL, &mstruct);
2533 }
2534
2535 /*
2536 $$ACTION
2537 Mission
2538 Fail Level
2539 aFailLevel
2540 Fail Level
2541 Terminates the level in failure. Level will restart.
2542
2543 Parameters:
2544 None.
2545 $$END
2546 */
2547 void aFailLevel() {
2548 msafe_struct mstruct;
2549
2550 mstruct.state = 0; // failure
2551 MSafe_CallFunction(MSAFE_MISC_END_LEVEL, &mstruct);
2552 }
2553
2554 /*
2555 $$ACTION
2556 Cinematics
2557 Start endlevel sequence; camera = [o:Camera], path = [h:PlayerPath], time = [f:Time=10.0], text = [s:Text]
2558 aStartEndlevelSequence
2559 Start endlevel sequence
2560 Start the endlevel camera sequence
2561
2562 Parameters:
2563 Camera: the viewer object for the sequence
2564 PlayerPath: the path the player ship follows
2565 Time: how long before the level ends
2566 Text: Any text (if any) you want to display (pass empty message if you want none)
2567 $$END
2568 */
2569 void aStartEndlevelSequence(int objhandle, int pathid, float time, const char *text) {
2570 tCannedCinematicInfo info;
2571
2572 info.object_to_use_for_point = objhandle;
2573 info.target_pathid = pathid;
2574 info.text_to_display = text;
2575 info.time = time;
2576 info.type = CANNED_LEVEL_END_POINT;
2577
2578 Cine_StartCanned(&info);
2579 }
2580
2581 /*
2582 $$ACTION
2583 Cinematics
2584 Start endlevel sequence with camera on path; camera path = [h:CameraPath], player path = [h:PlayerPath], time =
2585 [f:Time=10.0], text = [s:Text] aStartEndlevelSequencePath Start endlevel sequence on Path Start the endlevel camera
2586 sequence, with the camera on a path
2587
2588 Parameters:
2589 CameraPath: the path the camera should follow for the sequence
2590 PlayerPath: the path the player ship follows
2591 Time: how long before the level ends
2592 Text: Any text (if any) you want to display (pass empty message if you want none)
2593 $$END
2594 */
2595 void aStartEndlevelSequencePath(int camerapath, int pathid, float time, const char *text) {
2596 tCannedCinematicInfo info;
2597
2598 info.camera_pathid = camerapath;
2599 info.target_pathid = pathid;
2600 info.text_to_display = text;
2601 info.time = time;
2602 info.type = CANNED_LEVEL_END_PATH;
2603
2604 Cine_StartCanned(&info);
2605 }
2606
2607 /*
2608 $$ACTION
2609 Cinematics
2610 Fade Screen to white, and end level time = [f:Time=10.0], text = [s:Text]
2611 aFadeWhiteAndEndlevel
2612 Fades the screen to white and ends the level
2613
2614 Parameters:
2615 Time: how long before the level ends (the screen fades to white across this time)
2616 Text: Any text (if any) you want to display (pass empty message if you want none)
2617 $$END
2618 */
2619 void aFadeWhiteAndEndlevel(float time, const char *text) {
2620 tCannedCinematicInfo info;
2621
2622 info.text_to_display = text;
2623 info.time = time;
2624 info.type = CANNED_LEVEL_END_FADE_WHITE;
2625
2626 Cine_StartCanned(&info);
2627 }
2628
2629 /*
2630 $$ACTION
2631 Players
2632 Fade Screen out and move [o:Player] to Position Clipboard
2633 aFadeAndMovePlayer
2634 Fades the screen out and 'warps' the player to the position in the
2635 position clipboard.
2636
2637 Parameters:
2638 Player: the player to move
2639 $$END
2640 */
2641 void aFadeAndMovePlayer(int Player) {
2642 if (PositionClipboard.has_pos) {
2643 tCannedCinematicInfo info;
2644
2645 info.room = PositionClipboard.room;
2646 info.pos = PositionClipboard.pos;
2647 info.orient = PositionClipboard.orient;
2648 info.target_objhandle = Player;
2649 info.type = CANNED_MOVE_PLAYER_FADE;
2650
2651 Cine_StartCanned(&info);
2652 } else {
2653 mprintf(0, "No ClipBoard Data Filled In\n");
2654 }
2655 }
2656
2657 /*
2658 $$ACTION
2659 Mission
2660 Set mission flag [i:FlagNum] to [b:State]
2661 aMissionSetFlag
2662 Set mission flag
2663 Sets the specified mission flag
2664
2665 Parameters:
2666 FlagNum: the flag to set
2667 State: the value to set the flag to
2668 $$END
2669 */
2670 void aMissionSetFlag(int flagnum, bool state) { Msn_FlagSet(flagnum, state); }
2671
2672 /*
2673 $$ACTION
2674 Mission
2675 Set secret level flag to [b:State]
2676 aMissionSetSecretFlag
2677 Set secret level flags
2678 Sets/Clears the secret level flag, so the next secret level will be enabled/disabled
2679
2680 Parameters:
2681 State: whether to set or clear the flag
2682 $$END
2683 */
2684 void aMissionSetSecretFlag(bool state) { Msn_FlagSet(32, state); }
2685
2686 /*
2687 $$ACTION
2688 Mission
2689 Set level objective flag [i:FlagNum] to [b:State=1]
2690 aMissionSetLevelFlag
2691 Set level objective flag
2692 Sets the specified level objective flag
2693
2694 Parameters:
2695 FlagNum: the flag to set
2696 State: the value to set the flag to
2697 $$END
2698 */
2699 void aMissionSetLevelFlag(int flagnum, bool state) {
2700 //!!Add code here
2701 }
2702
2703 /*
2704 $$ACTION
2705 Sound && Music
2706 Play 2D Sound [n:Sound] for player [o:PlayerObject=IT], volume = [p:Volume=1.0:0.0|1.0]
2707 aSoundPlay2DObj
2708 Play 2D Sound
2709 Plays a sound in 2D
2710
2711 Parameters:
2712 Sound: the sound to play
2713 PlayerObject: the player who hears the sound
2714 Volume: how loud to play the sound
2715 $$END
2716 */
2717 void aSoundPlay2DObj(int soundnum, int objhandle, float volume) {
2718 msafe_struct mstruct;
2719
2720 mstruct.state = 1; // specific player
2721 mstruct.index = soundnum;
2722 mstruct.objhandle = dfGetPlayer(objhandle);
2723 mstruct.volume = volume;
2724
2725 MSafe_CallFunction(MSAFE_SOUND_2D, &mstruct);
2726 }
2727
2728 /*
2729 $$ACTION
2730 Sound && Music
2731 Play 2D Sound [n:Sound] for all players, volume = [p:Volume=1.0:0.0|1.0]
2732 aSoundPlay2D
2733 Play 2D Sound
2734 Plays a sound in 2D
2735
2736 Parameters:
2737 Sound: the sound to play
2738 Volume: how loud to play the sound
2739 $$END
2740 */
2741 void aSoundPlay2D(int soundnum, float volume) {
2742 msafe_struct mstruct;
2743
2744 mstruct.state = 0; // all players
2745 mstruct.index = soundnum;
2746 mstruct.volume = volume;
2747
2748 MSafe_CallFunction(MSAFE_SOUND_2D, &mstruct);
2749 }
2750
2751 /*
2752 $$ACTION
2753 Sound && Music
2754 Play Sound [n:Sound] from object [o:Object], volume = [p:Volume=1.0:0.0|1.0]
2755 aSoundPlayObject
2756 Play Object Sound
2757 Plays a sound from an object
2758
2759 Parameters:
2760 Sound: the sound to play
2761 Object: the object to attach the sound to
2762 Volume: how loud to play the sound
2763 $$END
2764 */
2765 void aSoundPlayObject(int soundnum, int objref, float volume) {
2766 msafe_struct mstruct;
2767
2768 mstruct.index = soundnum;
2769 mstruct.volume = volume;
2770 mstruct.objhandle = objref;
2771
2772 MSafe_CallFunction(MSAFE_SOUND_OBJECT, &mstruct);
2773 }
2774
2775 /*
2776 $$ACTION
2777 Sound && Music
2778 Play streaming sound [z:Sound] for all players, volume = [p:Volume=1.0:0.0|1.0]
2779 aSoundPlaySteaming
2780 Play Steaming Sound
2781 Plays a streaming sound sample
2782
2783 Parameters:
2784 Sound: the sound to play
2785 Volume: how loud to play the sound
2786 $$END
2787 */
2788 void aSoundPlaySteaming(const char *soundname, float volume) {
2789 msafe_struct mstruct;
2790
2791 mstruct.state = 0; // all players
2792
2793 strncpy(mstruct.name, soundname, sizeof(mstruct.name) - 1);
2794 mstruct.name[sizeof(mstruct.name) - 1] = 0;
2795 mstruct.volume = volume;
2796
2797 MSafe_CallFunction(MSAFE_SOUND_STREAMING, &mstruct);
2798 }
2799
2800 /*
2801 $$ACTION
2802 Sound && Music
2803 Play streaming sound [a:SoundName] for all players, volume = [p:Volume=1.0:0.0|1.0] (TEXT NAME VERSION)
2804 aSoundPlaySteamingText
2805 Play Steaming Sound
2806 Plays a streaming sound sample
2807
2808 Parameters:
2809 SoundName: the sound to play
2810 Volume: how loud to play the sound
2811 $$END
2812 */
2813 #define aSoundPlaySteamingText aSoundPlaySteaming
2814
2815 /*
2816 $$ACTION
2817 Sound && Music
2818 Play streaming sound [z:Sound] for player [o:PlayerObject=IT], volume = [p:Volume=1.0:0.0|1.0]
2819 aSoundPlaySteamingObj
2820 Play Steaming Sound
2821 Plays a streaming sound sample
2822
2823 Parameters:
2824 Sound: the sound to play
2825 Volume: how loud to play the sound
2826 $$END
2827 */
2828 void aSoundPlaySteamingObj(const char *soundname, int objhandle, float volume) {
2829 msafe_struct mstruct;
2830
2831 mstruct.state = 1; // specific player
2832 mstruct.objhandle = objhandle;
2833
2834 strncpy(mstruct.name, soundname, sizeof(mstruct.name) - 1);
2835 mstruct.name[sizeof(mstruct.name) - 1] = 0;
2836 mstruct.volume = volume;
2837
2838 MSafe_CallFunction(MSAFE_SOUND_STREAMING, &mstruct);
2839 }
2840
2841 /*
2842 $$ACTION
2843 Sound && Music
2844 Set volume for object [o:Object] to [p:Volume=1.0:0.0|1.0]
2845 aSoundVolumeObj
2846 Set volume for object sound
2847 Sets the volume for all sounds attached to an object
2848
2849 Parameters:
2850 Object - the object whose sound to stop
2851 Volume - the volume to set
2852 $$END
2853 */
2854 void aSoundVolumeObj(int objhandle, float volume) {
2855 msafe_struct mstruct;
2856
2857 mstruct.objhandle = objhandle;
2858 mstruct.volume = volume;
2859
2860 MSafe_CallFunction(MSAFE_SOUND_VOLUME_OBJ, &mstruct);
2861 }
2862
2863 /*
2864 $$ACTION
2865 Sound && Music
2866 Stop sound for object [o:Object]
2867 aSoundStopObj
2868 Stop sound for object
2869 Stops all sounds attached to an object
2870
2871 Parameters:
2872 Object - the object whose sound to stop
2873 $$END
2874 */
2875 void aSoundStopObj(int objhandle) {
2876 msafe_struct mstruct;
2877
2878 mstruct.objhandle = objhandle;
2879
2880 MSafe_CallFunction(MSAFE_SOUND_STOP_OBJ, &mstruct);
2881 }
2882
2883 /*
2884 $$ENUM Ghost/Unghost
2885 0:UNGHOST
2886 1:GHOST
2887 $$END
2888 */
2889
2890 /*
2891 $$ACTION
2892 Objects
2893 [e:Ghost/Unghost] object [o:Object]
2894 aObjGhostSet
2895 Ghost/Unghost an object
2896 Ghosts or Unghosts an object
2897
2898 Parameters:
2899 Ghost/Unghost: whether to ghost or unghost the object
2900 Object: the object to ghost or unghost
2901 $$END
2902 */
2903 void aObjGhostSet(int state, int objref) {
2904 msafe_struct mstruct;
2905
2906 mstruct.objhandle = objref;
2907
2908 MSafe_CallFunction(state ? MSAFE_OBJECT_GHOST : MSAFE_OBJECT_UNGHOST, &mstruct);
2909 }
2910
2911 /*
2912 $$ACTION
2913 Objects
2914 Hide object [o:Object]
2915 aObjHide
2916 Hide an object
2917 Makes an object not render. It will still be there but be invisible.
2918
2919 Parameters:
2920 Object: the object to hide
2921 $$END
2922 */
2923 void aObjHide(int objref) {
2924 msafe_struct mstruct;
2925
2926 mstruct.objhandle = objref;
2927
2928 MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct);
2929 }
2930
2931 /*
2932 $$ACTION
2933 Objects
2934 Make object [o:Object] invulnerable for [i:Time=20.0]
2935 aObjMakeInvuln
2936 Makes object invulnerable
2937 Makes object invulnerable
2938
2939 Parameters:
2940 Object: the object to make invulnerable
2941 Time: how long the object stays invulnerable
2942 $$END
2943 */
2944 void aObjMakeInvuln(int objref, int time) {
2945 msafe_struct mstruct;
2946
2947 mstruct.objhandle = objref;
2948 mstruct.state = 1;
2949 mstruct.lifetime = time;
2950
2951 MSafe_CallFunction(MSAFE_OBJECT_INVULNERABLE, &mstruct);
2952 }
2953
2954 /*
2955 $$ACTION
2956 Objects
2957 Make object [o:Object] vulnerable
2958 aObjMakeVulnerable
2959 Makes object invulnerable
2960 Makes object invulnerable
2961
2962 Parameters:
2963 Object: the object to make vulnerable again
2964
2965 $$END
2966 */
2967 void aObjMakeVulnerable(int objref) {
2968 msafe_struct mstruct;
2969
2970 mstruct.objhandle = objref;
2971 mstruct.state = 0;
2972 MSafe_CallFunction(MSAFE_OBJECT_INVULNERABLE, &mstruct);
2973 }
2974
2975 /*
2976 $$ACTION
2977 Objects
2978 Deform object [o:Object] by [f:Amount=.1:0|1.0] for [f:Time] seconds
2979 aObjDeform
2980 Deform object
2981 Deforms an object (applies the microwave cannon effect)
2982
2983 Parameters:
2984 Object: the object to deform
2985 Amount: how much to deform the object. 0.1 is a "normal" amount; 0.4 is a big amount.
2986 Time: how long to deform the object
2987 $$END
2988 */
2989 void aObjDeform(int objhandle, float amount, float time) {
2990 msafe_struct mstruct;
2991
2992 mstruct.objhandle = objhandle;
2993 mstruct.amount = amount;
2994 mstruct.lifetime = time;
2995
2996 MSafe_CallFunction(MSAFE_OBJECT_DEFORM, &mstruct);
2997 }
2998
2999 /*
3000 $$ACTION
3001 Objects
3002 Make object [o:Object] spark at a rate of [f:SparkRate=50] for [f:Time] seconds
3003 aObjSpark
3004 Make object spark
3005 Makes an object have sparks for the given amount of time
3006
3007 Parameters:
3008 Object: the object to apply sparks to
3009 SparkRate: how many sparks per second the object will have
3010 Time: how long the sparking will last
3011 $$END
3012 */
3013 void aObjSpark(int objhandle, float rate, float time) {
3014 msafe_struct mstruct;
3015
3016 mstruct.objhandle = objhandle;
3017 mstruct.amount = rate;
3018 mstruct.lifetime = time;
3019
3020 MSafe_CallFunction(MSAFE_OBJECT_SPARKS, &mstruct);
3021 }
3022
3023 /*
3024 $$ACTION
3025 Misc
3026 Shake viewer by [f:Amount=40.0:0|100.0]
3027 aMiscViewerShake
3028 Shake view
3029 Shakes the viewer
3030
3031 Parameters:
3032 Amount: how much to shake the viewer (0-100)
3033 $$END
3034 */
3035 void aMiscViewerShake(float amount) {
3036 msafe_struct mstruct;
3037
3038 mstruct.amount = amount;
3039
3040 MSafe_CallFunction(MSAFE_OBJECT_VIEWER_SHAKE, &mstruct);
3041 }
3042
3043 /*
3044 $$ACTION
3045 Misc
3046 Shake area around object [o:Object] by [f:Amount=40.0:0|100.0] over a distance of [f:Dist=100]
3047 aMiscShakeArea
3048 Shake the area around an object
3049 Shakes the viewer proportional to the distance to an object
3050
3051 Parameters:
3052 Object: the epicenter of the shake
3053 Amount: how much to shake the viewer (0-100)
3054 Dist: how far away the shake can be felt.
3055 $$END
3056 */
3057 void aMiscShakeArea(int objhandle, float amount, float dist) {
3058 msafe_struct mstruct;
3059
3060 mstruct.objhandle = objhandle;
3061 mstruct.amount = amount;
3062 mstruct.scalar = dist;
3063
3064 MSafe_CallFunction(MSAFE_OBJECT_SHAKE_AREA, &mstruct);
3065 }
3066
3067 /*
3068 $$ACTION
3069 Rooms
3070 Set texture on room [r:Room] face [i:FaceNum] to [u:Texture]
3071 aRoomSetFaceTexture
3072 Change face texture
3073 Sets the texture for a room face
3074
3075 Parameters:
3076 Room: the room the face is in
3077 FaceNum: the face whose texture is changed
3078 TextureName: the texture to assign to the specified face
3079 $$END
3080 */
3081 void aRoomSetFaceTexture(int roomnum, int facenum, int texturenum) {
3082 msafe_struct mstruct;
3083
3084 mstruct.roomnum = roomnum;
3085 mstruct.facenum = facenum;
3086 mstruct.index = texturenum;
3087
3088 MSafe_CallFunction(MSAFE_ROOM_TEXTURE, &mstruct);
3089 }
3090
3091 /*
3092 $$ACTION
3093 Misc
3094 [e:Activate/Deactivate] matcen [m:Matcen]
3095 aMatcenSetState
3096 Activate/Deactivate matcen
3097 Activates or Deactivates a matcen, so it starts or stops producing
3098
3099 Parameters:
3100 Activate/Deactivate: whether to start or stop the matcen
3101 Matcen: the matcen to activate
3102 $$END
3103 */
3104 void aMatcenSetState(int state, int matcen_id) {
3105 int flags = MSTAT_ACTIVE;
3106
3107 if (matcen_id >= 0)
3108 Matcen_Value(matcen_id, state ? VF_SET_FLAGS : VF_CLEAR_FLAGS, MTNV_I_STATUS, &flags);
3109 }
3110
3111 /*
3112 $$ACTION
3113 Misc
3114 [e:Enable/Disable] matcen [m:Matcen]
3115 aMatcenSetEnableState
3116 Enable/disable matcen
3117 Enable or disable a matcen, so it's capable of producing
3118
3119 Parameters:
3120 Enable/Disable: whether the matcen is cabable of producing
3121 Matcen: the matcen to enable or disable
3122 $$END
3123 */
3124 void aMatcenSetEnableState(int state, int matcen_id) {
3125 int flags = MSTAT_DISABLED;
3126
3127 if (matcen_id >= 0)
3128 Matcen_Value(matcen_id, state ? VF_CLEAR_FLAGS : VF_SET_FLAGS, MTNV_I_STATUS, &flags);
3129 }
3130
3131 /*
3132 $$ACTION
3133 Misc
3134 Set matcen [m:Matcen] max produced = [i:MaxProduced=-1], production rate multiplier = [f:Multiplier=1.0], max alive
3135 children = [i:MaxAlive=-1:1|32] aMatcenSetValues Set matcen values Set matcen values for max produced, production rate
3136 multiplier, and max alive children
3137
3138 Parameters:
3139 Matcen: the matcen to set
3140 MaxProduced: the total number this matcen will produce in its lifetime, or -1 for no limit
3141 Multiplier: controls the speed of the matcen. 1.0 is the normal speed
3142 MaxAlive: the maximum number of created object that will be alive at one time, or -1 for no limit
3143 $$END
3144 */
3145 void aMatcenSetValues(int matcen_id, int max_produced, float multiplier, int max_alive) {
3146 if (matcen_id >= 0) {
3147 Matcen_Value(matcen_id, VF_SET, MTNV_I_MAX_PROD, &max_produced, 0);
3148 Matcen_Value(matcen_id, VF_SET, MTNV_F_PROD_MULTIPLIER, &multiplier, 0);
3149 Matcen_Value(matcen_id, VF_SET, MTNV_I_MAX_ALIVE_CHILDREN, &max_alive, 0);
3150 }
3151 }
3152
3153 /*
3154 $$ACTION
3155 Rooms
3156 Set fog in room [r:Room] to color = [f:Red=0.5],[f:Green=0.5],[f:Blue=0.5], depth = [f:Depth=300.0]
3157 aRoomSetFog
3158 Set room fog
3159 Sets the fog color and depth for a room
3160
3161 Parameters:
3162 Room: the room to set
3163 R,G,B: the fog color (0-1)
3164 Depth: how deep the fog should be
3165 $$END
3166 */
3167 void aRoomSetFog(int roomnum, float r, float g, float b, float depth) {
3168 msafe_struct mstruct;
3169
3170 mstruct.roomnum = roomnum;
3171 mstruct.fog_depth = depth;
3172 mstruct.fog_r = r;
3173 mstruct.fog_g = g;
3174 mstruct.fog_b = b;
3175
3176 MSafe_CallFunction(MSAFE_ROOM_FOG, &mstruct);
3177 }
3178
3179 /*
3180 $$ACTION
3181 Rooms
3182 Change fog in room [r:Room] to color = [f:Red=0.5],[f:Green=0.5],[f:Blue=0.5], delpth = [f:Depth=200.0] over
3183 [f:Time=20.0] seconds aRoomChangeFog Change room fog Changes the fog in a room over time
3184
3185 Parameters:
3186 Room: the room to set
3187 R,G,B: the new fog color (0-1)
3188 Depth: how deep the fog should be after the change (starts from the current fog depth)
3189 Time: how long in seconds the change takes
3190 $$END
3191 */
3192 void aRoomChangeFog(int roomnum, float r, float g, float b, float depth, float time) {
3193 msafe_struct mstruct;
3194
3195 mstruct.roomnum = roomnum;
3196 mstruct.fog_depth = depth;
3197 mstruct.fog_r = r;
3198 mstruct.fog_g = g;
3199 mstruct.fog_b = b;
3200 mstruct.interval = time;
3201
3202 MSafe_CallFunction(MSAFE_ROOM_CHANGING_FOG, &mstruct);
3203 }
3204
3205 /*
3206 $$ACTION
3207 Rooms
3208 Turn fog [e:On/Off] in room [r:Room]
3209 aRoomFogSetState
3210 Turn fog On/Off
3211 Turns On or Off the fog in a room
3212
3213 Parameters:
3214 On/Off: whether to turn the fog on or off
3215 Room: the room in which to turn on or off the fog
3216 $$END
3217 */
3218 void aRoomFogSetState(int state, int roomnum) {
3219 msafe_struct mstruct;
3220
3221 mstruct.roomnum = roomnum;
3222 mstruct.state = state;
3223
3224 MSafe_CallFunction(MSAFE_ROOM_FOG_STATE, &mstruct);
3225 }
3226
3227 /*
3228 $$ACTION
3229 Rooms
3230 Toggle fog in room [r:Room]
3231 aRoomToggleFog
3232 Toggle room fog
3233 Toggles the fog state in a room
3234
3235 Parameters:
3236 Room: the room in which to turn off the fog
3237 $$END
3238 */
3239 void aRoomToggleFog(int roomnum) {
3240 msafe_struct mstruct;
3241
3242 mstruct.roomnum = roomnum;
3243
3244 MSafe_GetValue(MSAFE_ROOM_FOG_STATE, &mstruct);
3245
3246 mstruct.state = !mstruct.state;
3247
3248 MSafe_CallFunction(MSAFE_ROOM_FOG_STATE, &mstruct);
3249 }
3250
3251 /*
3252 $$ACTION
3253 Rooms
3254 Set wind in room [r:Room], direction = <[f:X],[f:Y],[f:Z]>, speed = [f:Speed=1.0]
3255 aRoomSetWind
3256 Set wind in room
3257 Sets the wind in a room
3258
3259 Parameters:
3260 Room: the room in which to set the wind
3261 X,Y,Z: the direction vector for the wind
3262 Speed: the speed of the wind (10.0 is faster than the player ship)
3263 $$END
3264 */
3265 void aRoomSetWind(int roomnum, float x, float y, float z, float speed) {
3266 msafe_struct mstruct;
3267
3268 mstruct.roomnum = roomnum;
3269 //!!mstruct.wind = *v;
3270 mstruct.wind.x = x * speed;
3271 mstruct.wind.y = y * speed;
3272 mstruct.wind.z = z * speed;
3273
3274 MSafe_CallFunction(MSAFE_ROOM_WIND, &mstruct);
3275 }
3276
3277 /*
3278 $$ACTION
3279 Rooms
3280 Change wind in room [r:Room] to direction = <[f:X],[f:Y],[f:Z]>, speed = [f:Speed=1.0] over [f:Time=10.0] seconds
3281 aRoomChangeWind
3282 Change wind in room
3283 Changes the wind in a room over time
3284
3285 Parameters:
3286 Room: the room in which to set the wind
3287 X,Y,Z: the direction vector for the wind
3288 Speed: the speed of the wind (10.0 is faster than the player ship)
3289 Time: how long the change takes
3290 $$END
3291 */
3292 void aRoomChangeWind(int roomnum, float x, float y, float z, float speed, float time) {
3293 msafe_struct mstruct;
3294
3295 mstruct.roomnum = roomnum;
3296 //!!mstruct.wind = *v;
3297 mstruct.wind.x = x * speed;
3298 mstruct.wind.y = y * speed;
3299 mstruct.wind.z = z * speed;
3300 mstruct.interval = time;
3301
3302 MSafe_CallFunction(MSAFE_ROOM_CHANGING_WIND, &mstruct);
3303 }
3304
3305 /*
3306 $$ACTION
3307 AI
3308 Object For [o:Object] turn the AI scripted death flag [e:On/Off]
3309 aSetScriptedDeath
3310 Turn On/Off the AI scripted death flag
3311 Turns on/off the scripted death flag for the specified object
3312
3313 Parameters:
3314 Object - the object in question
3315 On/Off - whether to turn on/off the AI Scripted Death Flag
3316 $$END
3317 */
3318 void aSetScriptedDeath(int objhandle, int state) {
3319 int flags = OF_AI_DEATH;
3320
3321 Obj_Value(objhandle, state ? VF_SET_FLAGS : VF_CLEAR_FLAGS, OBJV_I_FLAGS, &flags);
3322 }
3323
3324 /*
3325 $$ACTION
3326 AI
3327 Turn [e:On/Off] the AI for object [o:Object]
3328 aAISetState
3329 Turn On/Off the AI for object
3330 Turns on or off the AI for the specified object
3331
3332 Parameters:
3333 On/Off - whether to turn the AI on or off
3334 Object - the object whose AI is turned on or off
3335 $$END
3336 */
3337 void aAISetState(int state, int objhandle) { AI_PowerSwitch(objhandle, state != 0); }
3338
3339 /*
3340 $$ACTION
3341 AI
3342 Set the FOV of [o:Object] to [f:FOV] degrees
3343 aAISetFOV
3344 Sets the FOV for an AI object (0 - 360)
3345 Sets the FOV for an AI object (0 - 360)
3346
3347 Parameters:
3348 Object - the object whose AI is turned on or off
3349 FOV - the number of angles of the FOV
3350 $$END
3351 */
3352 void aAISetFOV(int objhandle, float fov) {
3353 fov = cos(fov * PI / (360.0));
3354 AI_Value(objhandle, VF_SET, AIV_F_FOV, &fov);
3355 }
3356
3357 /*
3358 $$ACTION
3359 AI
3360 Set the Target of [o:Object] to [o:Target]
3361 aAISetTarget
3362 Sets the target for an AI object
3363 Sets the target for an AI object
3364
3365 Parameters:
3366 Object - the object whose AI target is being set
3367 Target - the object to be targetted for attack
3368 $$END
3369 */
3370 void aAISetTarget(int objhandle, int targethandle) { AI_Value(objhandle, VF_SET, AIV_I_TARGET_HANDLE, &targethandle); }
3371
3372 /*
3373 $$ACTION
3374 AI
3375 Set Team to [e:Teams] for the AI for object [o:Object]
3376 aAISetTeam
3377 Sets the team for a specific object
3378 Sets the team for a specific object
3379
3380 Parameters:
3381 Team: Which team you want the object to belong to
3382 Object - the object whose team you want to change
3383 $$END
3384 */
3385 void aAISetTeam(int team, int objhandle) {
3386 int flags = AIF_TEAM_MASK;
3387 AI_Value(objhandle, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3388 flags = team; // AIF_TEAM_REBEL;
3389 AI_Value(objhandle, VF_SET_FLAGS, AIV_I_FLAGS, &flags);
3390
3391 int target_handle = OBJECT_HANDLE_NONE;
3392 AI_Value(objhandle, VF_SET, AIV_I_TARGET_HANDLE, &target_handle);
3393 }
3394
3395 /*
3396 $$ACTION
3397 AI
3398 Clear the [e:GoalPriority=3] prioriity goal for object [o:Object]
3399 aAIClearGoal
3400 Clears a goal for a specific object
3401 Clears a goal for a specific object
3402
3403 Parameters:
3404 GoalPriority: The priority of the goal you can to clear
3405 Object: the object whose goal you want to clear
3406 $$END
3407 */
3408
3409 void aAIClearGoal(int slot, int handle) { AI_ClearGoal(handle, slot); }
3410
3411 /*
3412 $$ENUM AIModeType
3413 1:Stalker
3414 2:Standard Attack
3415 3:Guardian
3416 4:Stationary Turret
3417 6:Melee
3418 7:Bird Flock
3419 9:Herd
3420 $$END
3421
3422 Luke would additionally like these types:
3423 Wander
3424 Berzerker
3425 Pursue
3426 Sniper
3427 Survival
3428 Sneak Attack
3429 Supervisor
3430
3431 */
3432
3433 /*
3434 $$ACTION
3435 AI
3436 Set AI mode for object [o:Object] to [e:AIModeType]
3437 aAISetMode
3438 Set AI mode
3439 Sets the AI mode for an objectTurn ON AI for object
3440
3441 Parameters:
3442 Object - the object whose AI mode is set
3443 AIModeType - which mode to set for the object
3444 $$END
3445 */
3446 void aAISetMode(int objhandle, int modetype) { AI_SetType(objhandle, modetype); }
3447
3448 /*
3449 $$ACTION
3450 AI
3451 Set [o:Object] to have a max speed of [f:MaxSpeed]
3452 aAISetMaxSpeed
3453 Set the max speed of an object
3454 Set the max speed of an object
3455
3456 Parameters:
3457 Object - the object whose AI mode is set
3458 MaxSpeed - Maximum speed
3459 $$END
3460 */
3461 void aAISetMaxSpeed(int objhandle, float max_speed) { AI_Value(objhandle, VF_SET, AIV_F_MAX_SPEED, &max_speed); }
3462
3463 // Used for all AI Goal calls
3464 #define DEFAULT_INFLUENCE 1.0
3465
3466 /*
3467 Flags for AI Goals
3468
3469 $$FLAG AIGoalFlags
3470 1:Permanent
3471 4:Keep at Completion
3472 16:Object is Target
3473 128:Go Directly to Goal if Visible
3474 256:Force Awareness
3475 512:Objects are Friends
3476 1024:Objects are Species
3477 2048:Objects are Enemies
3478 4096:Orient Velocity
3479 65536:Orient Target
3480 131072:No Reorientation
3481 262144:Orient Goal Object
3482 1048576:Orient Path Node
3483 2097152:Follow Path Exactly
3484 4194304:Reverse at End of Path
3485 8388608:Circle at End of Path
3486 16777216:Follow Path in Reverse Direction
3487 $$END
3488
3489 Flags for AI
3490
3491 $$FLAG AIFlags
3492 1:Weapon Attack 1
3493 2:Weapon Attack 2
3494 4:Melee Attack 1
3495 8:Melee Attack 2
3496 32: Act as team neutral until shot
3497 64:Persistant (always using CPU cycles)
3498 128:Dodging
3499 256:Firing Ranged Weapons
3500 512:Flinching
3501 1024:Determining Targets
3502 2048:Aiming
3503 8192:Auto-avoid walls
3504 16384:Disabled
3505 32768:Team PTMC (WARNING - NEVER SET TWO TEAMS)
3506 65536:Team Rebel (WARNING - NEVER SET TWO TEAMS)
3507 131072:Team Hostile to everyone (WARNING - NEVER SET TWO TEAMS)
3508 196608:Team Neutral to everyone (WARNING - NEVER SET TWO TEAMS)
3509 524288:Orientate to velocity
3510 4194304:Target by distance
3511 8388608:Disable ranged weapon firing (even in script)
3512 16777216:Disable melee attacks (even in script)
3513 33554432:Auto-avoid friends
3514 268435456:Biased Flight Height
3515 536870912:Force awareness (always using CPU cycles)
3516 $$END
3517
3518 User type for Goal IDs
3519
3520 $$USERTYPE GoalID:99
3521
3522 AI Goal slot values
3523
3524 $$ENUM GoalPriority
3525 3:High
3526 0:Low
3527 $$END
3528
3529 $$ENUM Set/Clear
3530 0:Clear
3531 1:Set
3532 $$END
3533
3534 */
3535
3536 /*
3537 $$ACTION
3538 AI
3539 [e:Set/Clear=1] AI Flags [g:AIFlags=0] for Object [o:Object]
3540 aAIFlags
3541 Sets and clears AI flags
3542 Sets and clears AI flags
3543
3544 Parameters:
3545 Set/Clear - Set or Clear the specified flags
3546 AIFlags - the flags to either set or clear (other flags are not effected)
3547 Object - The object of which you want to alter the AI flags
3548 $$END
3549 */
3550 void aAIFlags(int set, int flags, int handle) {
3551 bool f_team = false;
3552
3553 // Because its a bitfield, I had to hack a team value... Team PTMC was 0; so, it was
3554 // impossible to set... 32768 wasn't used, so I hacked it here. O' The shame... :(
3555
3556 if (!set)
3557 flags &= ~(AIF_TEAM_MASK);
3558 else
3559 f_team = (flags & (AIF_TEAM_MASK | 32768)) != 0;
3560
3561 // hacked PTMC team value
3562 flags &= ~(32768);
3563
3564 // Since it is a bit field... clear out the old value
3565 if (f_team) {
3566 int team_mask = AIF_TEAM_MASK;
3567 AI_Value(handle, VF_CLEAR_FLAGS, AIV_I_FLAGS, &team_mask);
3568 }
3569
3570 AI_Value(handle, (set) ? VF_SET_FLAGS : VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags);
3571 }
3572
3573 /*
3574 $$ACTION
3575 AI
3576 Set AI object [o:Object] goal Priority = [e:GoalPriority=3] circle distance to [f:distance]
3577 aAIGoalSetCircleDistance
3578 Sets the circle distance for a goal
3579 Sets the circle distance for a goal
3580
3581 Parameters:
3582 Object - the object who is send to the room
3583 Priority - priority of the goal in question
3584 $$END
3585 */
3586 void aAIGoalSetCircleDistance(int objhandle, int slot, float distance) {
3587 AI_GoalValue(objhandle, slot, VF_SET, AIGV_F_CIRCLE_DIST, &distance);
3588 }
3589
3590 /*
3591 $$ACTION
3592 AI
3593 Send AI object [o:Object] to room [r:Room]; Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags=4352:201109], GoalID =
3594 [e:GoalID=-1] aAIGoalGotoRoom Send AI object to room Instructs an AI object to go to a specific room
3595
3596 Parameters:
3597 Object - the object who is send to the room
3598 Room - the room to go do
3599 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3600 Flags - the flags for this goal
3601 GoalID - an ID for this goal
3602 $$END
3603 */
3604 void aAIGoalGotoRoom(int objhandle, int roomnum, int slot, int flags, int goalid) {
3605 vector pos;
3606
3607 Room_Value(roomnum, VF_GET, RMSV_V_PATH_PNT, &pos, 0);
3608
3609 AI_AddGoal(objhandle, AIG_GET_TO_POS, slot, DEFAULT_INFLUENCE, goalid, flags, &pos, roomnum);
3610 }
3611
3612 /*
3613 $$ACTION
3614 AI
3615 Send AI object [o:Object] to object [o:Target]; Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags=4352:201109],
3616 GoalID = [e:GoalID=-1] aAIGoalGotoObject Send AI object to a specified object Instructs an AI object to go to a specific
3617 object
3618
3619 Parameters:
3620 Object - the object who is send to the room
3621 Target - the object to get to
3622 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3623 Flags - the flags for this goal
3624 GoalID - an ID for this goal
3625 $$END
3626 */
3627 void aAIGoalGotoObject(int objhandle, int target, int slot, int flags, int goalid) {
3628 AI_AddGoal(objhandle, AIG_GET_TO_OBJ, slot, DEFAULT_INFLUENCE, goalid, flags, target);
3629 }
3630
3631 /*
3632 $$ACTION
3633 AI
3634 Send AI object [o:Object] on path [h:Path]; Flags = [g:AIGoalFlags=4352:32706959], GoalID = [e:GoalID=-1], Priority =
3635 [e:GoalPriority=3] aAIGoalFollowPathSimple Send AI object on path Instructs an AI object to follow a path
3636
3637 Parameters:
3638 Object - the object who is send to the room
3639 Path - the path to follow
3640 Flags - the flags for this goal
3641 GoalID - an ID for this goal
3642 Priority - The priority of the goal
3643 $$END
3644 */
3645 void aAIGoalFollowPathSimple(int objhandle, int pathid, int flags, int goalid, int priority = 0) {
3646 //!!GoalID not used yet
3647
3648 if (pathid != -1)
3649 AI_GoalFollowPathSimple(objhandle, pathid, goalid, flags, priority);
3650 }
3651
3652 /*
3653 $$ACTION
3654 AI
3655 Send AI object [o:Object] on path [h:Path] between nodes [i:FirstNode] and [i:LastNode], starting at [i:StartNode];
3656 Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags=4352:32706959], GoalID = [e:GoalID=-1] aAIGoalFollowPath Send AI
3657 object on path Instructs an AI object to follow a path
3658
3659 Parameters:
3660 Object - the object who is send to the room
3661 Path - the path to follow
3662 FirstNode, LastNode - the endpoints of the part of the path to follow
3663 StartNode - where to start following the path
3664 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3665 Flags - the flags for this goal
3666 GoalID - an ID for this goal
3667 $$END
3668 */
3669 void aAIGoalFollowPath(int objhandle, int pathid, int firstnode, int lastnode, int startnode, int slot, int flags,
3670 int goalid) {
3671 if (pathid != -1)
3672 AI_AddGoal(objhandle, AIG_FOLLOW_PATH, slot, DEFAULT_INFLUENCE, goalid, flags, pathid, firstnode, lastnode,
3673 startnode);
3674 }
3675
3676 /*
3677 $$ACTION
3678 AI
3679 Make object [o:Picker] (attachpoint [i:PickerPoint]) pick up object [o:Pickee] (attachpoint = [i:PickeePoint]); Aligned
3680 = [b:Aligned]; Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags:463253], GoalID = [e:GoalID=-1] aAIGoalPickUpObject
3681 Make object pick up object
3682 Make one object pick up another
3683
3684 Parameters:
3685 Picker - the object doing the picking up
3686 PickerPoint - the attach point on the picker
3687 Pickee - the object being picked up
3688 PickeePoint - the attach point on the pickee
3689 Aligned - if true, aligns the two object
3690 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3691 Flags - the flags for this goal
3692 GoalID - an ID for this goal
3693 $$END
3694 */
3695 void aAIGoalPickUpObject(int pickerhandle, int pickerpoint, int pickeehandle, int pickeepoint, bool aligned, int slot,
3696 int flags, int goalid) {
3697 AI_AddGoal(pickerhandle, AIG_ATTACH_TO_OBJ, slot, DEFAULT_INFLUENCE, goalid, flags, pickeehandle, pickerpoint,
3698 pickeepoint, 0.0, aligned, 0);
3699 }
3700
3701 /*
3702 $$ACTION
3703 AI
3704 Make object [o:Picker] (attachpoint [i:CarriedObjectPoint]) be set down onto object [o:LandOnObject] (attachpoint =
3705 [i:LandOnPoint]); Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags:463253], GoalID = [e:GoalID=-1]
3706 aAIGoalSetObjectOnObject
3707 Make object pick up object
3708 Make one object pick up another
3709
3710 Parameters:
3711 Picker - the object doing the picking up
3712 CarriedObjectPoint - the attach point on the picker
3713 LandOnObject - the object being picked up
3714 LandOnPoint - the attach point on the pickee
3715 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3716 Flags - the flags for this goal
3717 GoalID - an ID for this goal
3718 $$END
3719 */
3720 void aAIGoalSetObjectOnObject(int pickerhandle, int pickerpoint, int pickeehandle, int pickeepoint, int slot, int flags,
3721 int goalid) {
3722 AI_AddGoal(pickerhandle, AIG_PLACE_OBJ_ON_OBJ, slot, DEFAULT_INFLUENCE, goalid, flags, pickeehandle, pickerpoint,
3723 pickeepoint, 0.0, true, 0);
3724 }
3725
3726 /*
3727 $$ACTION
3728 AI
3729 Make object [o:LandingObject] (attachpoint [i:LanderAttachPoint]) land on object [o:ObjectToLandOn] (attachpoint =
3730 [i:LandOnObjectAttachPoint]); Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags:463253], GoalID = [e:GoalID=-1]
3731 aAIGoalLandOnObject
3732 Make an object land on another object
3733 Make one object and on another object
3734
3735 Parameters:
3736 LandingObject - the object that is going to land
3737 LanderAttachPoint - the attach point that the landing object uses
3738 ObjectToLandOn - the object being landed on
3739 LandOnObjectAttachPoint - the attach point of the object being landed on
3740 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3741 Flags - the flags for this goal
3742 GoalID - an ID for this goal
3743 $$END
3744 */
3745 void aAIGoalLandOnObject(int pickerhandle, int pickerpoint, int pickeehandle, int pickeepoint, int slot, int flags,
3746 int goalid) {
3747 AI_AddGoal(pickerhandle, AIG_ATTACH_TO_OBJ, slot, DEFAULT_INFLUENCE, goalid, flags | GF_IS_ATTACH_CHILD, pickeehandle,
3748 pickerpoint, pickeepoint, 0.0, true, 0);
3749 }
3750
3751 /*
3752 $$ACTION
3753 AI
3754 Make object [o:Picker] (attachpoint [i:PickerPoint]) pick up object [o:Pickee] with radius = [p:RadiusRatio=1.0];
3755 Priority = [e:GoalPriority=3], Flags = [g:AIGoalFlags:463253], GoalID = [e:GoalID=-1] aAIGoalPickUpObjectRad Make object
3756 pick up object Make one object pick up another
3757
3758 Parameters:
3759 Picker - the object doing the picking up
3760 PickerPoint - the attach point on the picker
3761 Pickee - the object being picked up
3762 RadiusRatio - how close to hold the object relative to the object's size
3763 Priority - if High, overrides the default goals; if Low, does only when the object has no other enabled goals
3764 Flags - the flags for this goal
3765 GoalID - an ID for this goal
3766 $$END
3767 */
3768 void aAIGoalPickUpObjectRad(int pickerhandle, int pickerpoint, int pickeehandle, float radius, int slot, int flags,
3769 int goalid) {
3770 AI_AddGoal(pickerhandle, AIG_ATTACH_TO_OBJ, slot, DEFAULT_INFLUENCE, goalid, flags, pickeehandle, pickerpoint, -1,
3771 radius, 0, 1);
3772 }
3773
3774 /*
3775 $$ACTION
3776 Objects
3777 [e:Set/Clear=1] Physics Flags [g:PhysicsFlags=0] for Object [o:Object]
3778 aPhysFlags
3779 Set/Clear Physics flags
3780 Sets or and clears physics flags
3781
3782 Parameters:
3783 Set/Clear - Set or Clear the specified flags
3784 PhysicsFlags - the flags to either set or clear (other flags are not effected)
3785 Object - The object of which you want to alter the physics flags
3786 $$END
3787 */
3788 void aPhysFlags(int set, int flags, int handle) {
3789 Obj_Value(handle, (set) ? VF_SET_FLAGS : VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags);
3790 }
3791
3792 /*
3793 $$ACTION
3794 Cinematics
3795 Simple letterbox format cinematic, using path [h:CameraPath], with text [s:Text] targeting [o:Target] for
3796 [f:Seconds=10.0f] has fade in [b:FadeIn] aCinematicSimple CinematicSimple This creates a simple cinematic, in Letterbox
3797 mode. The camera will follow the given path. And the given text will be shown at the bottom of the screen. There is no
3798 'quick exit' by keypress. To do more than one line of text, seperate each line of text using a pipe ('|').
3799
3800 Parameters:
3801 CameraPath: The path the camera should follow
3802 Text: The text to be displayed on the screen
3803 Target: Object to target during the cinematic
3804 Seconds: how long the cinematic should last
3805 FadeIn: If TRUE then the cinematic will fade in
3806
3807 $$END
3808 */
3809 void aCinematicSimple(int pathid, const char *Text, int Target, float Seconds, bool FadeIn = false) {
3810 tGameCinematic info;
3811
3812 info.flags = 0;
3813 info.flags = (GCF_LETTERBOX | GCF_USEPATH | GCF_TEXT_WIPEIN | GCF_LAYOUT_BOTTOM);
3814 info.target_objhandle = Target;
3815 info.max_time_play = Seconds;
3816 info.callback = NULL;
3817 info.text_display.min = 0.40f;
3818 info.text_display.max = 1.0f;
3819 info.track_target.min = 0.0f;
3820 info.track_target.max = 1.0f;
3821 info.player_disabled.min = 0.0f;
3822 info.player_disabled.max = 1.0f;
3823 info.in_camera_view.min = 0.0f;
3824 info.in_camera_view.max = 1.0f;
3825 info.quick_exit.min = 1.0f;
3826 info.quick_exit.max = 1.0f;
3827 info.end_transition = GCTT_FADEINOUT;
3828 info.start_transition = (FadeIn) ? GCTT_FADE : GCTT_NONE;
3829 info.pathid = pathid;
3830
3831 Cine_Start(&info, Text);
3832 }
3833
3834 /*
3835 $$ACTION
3836 Cinematics
3837 Introduction fly-in using path [h:CameraPath], with text [s:Text] following player position [o:TotallyNotUsedTarget] on
3838 [h:PlayerPath] for [f:Seconds=10.0f]. aCinematicIntro CinematicIntro THE TARGET IS NOT USED, IT'S HERE FOR BACKWARD
3839 COMPATIBILITY This starts a level introduction cinematic. The camera will follow the given path. And the given text will
3840 be shown at the bottom of the screen. There is a 'quick exit' by keypress, after the first quarter of the cinematic is
3841 done. To do more than one line of text, seperate each line of text using a pipe ('|').
3842
3843 Parameters:
3844 ONCE AGAIN, THE TARGET IS NOT USED, IT'S HERE FOR BACKWARD COMPATIBILITY
3845 ONCE AGAIN, THE TARGET IS NOT USED, IT'S HERE FOR BACKWARD COMPATIBILITY
3846 CameraPath: The path the camera should follow
3847 Text: The text to be displayed on the screen
3848 Target: NO LONGER USED (it's the player object)
3849 PlayerPath: The path the target object should follow
3850 Seconds: how long the cinematic should last
3851 ONCE AGAIN, THE TARGET IS NOT USED, IT'S HERE FOR BACKWARD COMPATIBILITY
3852 ONCE AGAIN, THE TARGET IS NOT USED, IT'S HERE FOR BACKWARD COMPATIBILITY
3853 $$END
3854 */
3855 void aCinematicIntro(int camera_path, const char *Text, int NoLongerUserTarget, int PlayerPath, float Seconds) {
3856 tCannedCinematicInfo info;
3857
3858 info.type = CANNED_LEVEL_INTRO;
3859 info.camera_pathid = camera_path;
3860 info.target_pathid = PlayerPath;
3861 info.text_to_display = Text;
3862 info.time = Seconds;
3863
3864 Cine_StartCanned(&info);
3865 }
3866
3867 /*
3868 $$ACTION
3869 Cinematics
3870 Stops the currently playing in-game cinematic
3871 aCinematicStop
3872 CinematicStop
3873 Stops a currently playing in-game cinematic, restoring everything
3874 $$END
3875 */
3876 void aCinematicStop(void) { Cine_Stop(); }
3877
3878 class complex_cinematic {
3879 public:
3880 complex_cinematic() {
3881 being_made = false;
3882 memset(&info, 0, sizeof(tGameCinematic));
3883 }
3884
3885 tGameCinematic info;
3886 bool being_made;
3887 };
3888 complex_cinematic ccinematic;
3889
3890 /*
3891 $$ACTION
3892 Cinematics
3893 Complex Cinematic: Start
3894 aComplexCinematicStart
3895 ComplexCinematicStart
3896 Starts the creation process of a 'complex' in-game cinematic.
3897 $$END
3898 */
3899 void aComplexCinematicStart(void) {
3900 ccinematic.being_made = true;
3901 memset(&ccinematic.info, 0, sizeof(tGameCinematic));
3902
3903 ccinematic.info.flags = (GCF_LETTERBOX | GCF_USEPATH | GCF_TEXT_WIPEIN | GCF_LAYOUT_BOTTOM | GCF_STOPIFTAGETDEAD);
3904 ccinematic.info.target_objhandle = OBJECT_HANDLE_NONE;
3905 ccinematic.info.max_time_play = 10.0f;
3906 ccinematic.info.callback = NULL;
3907 ccinematic.info.text_display.min = 0.40f;
3908 ccinematic.info.text_display.max = 1.0f;
3909 ccinematic.info.track_target.min = 0.0f;
3910 ccinematic.info.track_target.max = 1.0f;
3911 ccinematic.info.player_disabled.min = 0.0f;
3912 ccinematic.info.player_disabled.max = 1.0f;
3913 ccinematic.info.in_camera_view.min = 0.0f;
3914 ccinematic.info.in_camera_view.max = 1.0f;
3915 ccinematic.info.quick_exit.min = 1.0f;
3916 ccinematic.info.quick_exit.max = 1.0f;
3917 ccinematic.info.end_transition = GCTT_FADEINOUT;
3918 ccinematic.info.start_transition = GCTT_NONE;
3919
3920 ccinematic.info.pathid = -1;
3921 }
3922
3923 /*
3924 $$ACTION
3925 Cinematics
3926 Complex Cinematic: End, cinematic text: [s:Text] play time: [f:Seconds=10.0]
3927 aComplexCinematicEnd
3928 ComplexCinematicEnd
3929 Ends the creation process of a 'complex' in-game cinematic and starts it running.
3930 Params:
3931 Text: The text you want displayed during the cinematic
3932 Seconds: How long cinematic should play
3933 $$END
3934 */
3935 void aComplexCinematicEnd(const char *Text, float Seconds) {
3936 if (!ccinematic.being_made)
3937 return;
3938
3939 ccinematic.info.max_time_play = Seconds;
3940
3941 Cine_Start(&ccinematic.info, Text);
3942 ccinematic.being_made = false;
3943 }
3944
3945 /*
3946 $$ACTION
3947 Cinematics
3948 Complex Cinematic: Text Display Start [p:Start=0.4] until End [p:End=0.8]
3949 aComplexCinematicText
3950 ComplexCinematicText
3951 Determines the range (based on a percentage into the cinematic) that the text should display
3952 Params:
3953 Start: At what percentage of time into the cinematic should text start displaying
3954 End: At what percentage of time into the cinematic should text stop displaying
3955 $$END
3956 */
3957 void aComplexCinematicText(float Start, float End) {
3958 ccinematic.info.text_display.min = Start;
3959 ccinematic.info.text_display.max = End;
3960 }
3961
3962 /*
3963 $$ACTION
3964 Cinematics
3965 Complex Cinematic: Track Target [o:Target] Start [p:Start=0.0] until End [p:End=1.0]
3966 aComplexCinematicTrack
3967 ComplexCinematicTrack
3968 Determines the range (based on a percentage into the cinematic) that the target should be tracked
3969 (NOTE: it should be the entire time...0->100% but you may feel different)
3970 Params:
3971 Target: Object to target
3972 Start: At what percentage of time into the cinematic should target be tracked
3973 End: At what percentage of time into the cinematic should target stop being tracked
3974 $$END
3975 */
3976 void aComplexCinematicTrack(int Target, float Start, float End) {
3977 ccinematic.info.target_objhandle = Target;
3978 ccinematic.info.track_target.min = Start;
3979 ccinematic.info.track_target.max = End;
3980 }
3981
3982 /*
3983 $$ACTION
3984 Cinematics
3985 Complex Cinematic: Player Disabled Start [p:Start=0.0] until End [p:End=1.0]
3986 aComplexCinematicPlayerDisabled
3987 ComplexCinematicPlayerDisabled
3988 Determines the range (based on a percentage into the cinematic) that the player's
3989 controls are disabled.
3990 Params:
3991 Start: At what percentage of time into the cinematic should controls disable
3992 End: At what percentage of time into the cinematic should controls be renabled
3993 $$END
3994 */
3995 void aComplexCinematicPlayerDisabled(float Start, float End) {
3996 ccinematic.info.player_disabled.min = Start;
3997 ccinematic.info.player_disabled.max = End;
3998 }
3999
4000 /*
4001 $$ACTION
4002 Cinematics
4003 Complex Cinematic: View From Camera Start [p:Start=0.0] until End [p:End=1.0]
4004 aComplexCinematicCameraView
4005 ComplexCinematicCameraView
4006 Determines the range (based on a percentage into the cinematic) that the view is from
4007 the camera
4008 Params:
4009 Start: At what percentage of time into the cinematic should the view be in the camera
4010 End: At what percentage of time into the cinematic should the view be back to the player
4011 $$END
4012 */
4013 void aComplexCinematicCameraView(float Start, float End) {
4014 ccinematic.info.in_camera_view.min = Start;
4015 ccinematic.info.in_camera_view.max = End;
4016 }
4017
4018 /*
4019 $$ACTION
4020 Cinematics
4021 Complex Cinematic: Quick Exit Start [p:Start=1.0] until End [p:End=1.0]
4022 aComplexCinematicQuickExit
4023 ComplexCinematicQuickExit
4024 Determines the range (based on a percentage into the cinematic) that the player can quick
4025 exit from the cinematic by pressing a key (usually 0%-100% or 100%-100%)
4026 Params:
4027 Start: At what percentage of time into the cinematic can the player quick exit
4028 End: At what percentage of time into the cinematic can't the player quick exit
4029 $$END
4030 */
4031 void aComplexCinematicQuickExit(float Start, float End) {
4032 ccinematic.info.quick_exit.min = Start;
4033 ccinematic.info.quick_exit.max = End;
4034 }
4035
4036 /*
4037 $$ENUM CineEndTransition
4038 0:None
4039 1:Wacky
4040 2:Fade In
4041 3:Fade Out/In
4042 $$END
4043 */
4044
4045 /*
4046 $$ACTION
4047 Cinematics
4048 Complex Cinematic: Set End Transition to [e:CineEndTransition=3]
4049 aComplexCinematicEndTrans
4050 ComplexCinematicEndTrans
4051 Sets the end transition setting.
4052 $$END
4053 */
4054 void aComplexCinematicEndTrans(int End) { ccinematic.info.end_transition = End; }
4055
4056 /*
4057 $$ACTION
4058 Cinematics
4059 Complex Cinematic: Set Start Fade in to [b:Enable]
4060 aComplexCinematicStartTrans
4061 ComplexCinematicStartTrans
4062 Sets whether the cinematic should fade in to start
4063 $$END
4064 */
4065 void aComplexCinematicStartTrans(bool Enable) { ccinematic.info.start_transition = (Enable) ? GCTT_FADE : GCTT_NONE; }
4066
4067 /*
4068 $$ACTION
4069 Cinematics
4070 Complex Cinematic: Put Camera On Path [h:Path]
4071 aComplexCinematicCameraOnPath
4072 ComplexCinematicCameraOnPath
4073 Tells the cinematic that the camera should be on the given path
4074 $$END
4075 */
4076 void aComplexCinematicCameraOnPath(int Path) {
4077 ccinematic.info.flags |= GCF_USEPATH;
4078 ccinematic.info.flags &= ~GCF_USEPOINT;
4079 ccinematic.info.pathid = Path;
4080 }
4081
4082 /*
4083 $$ACTION
4084 Cinematics
4085 Complex Cinematic: Put Camera At Position [v:Position] in room [r:Room]
4086 aComplexCinematicCameraAtPoint
4087 ComplexCinematicCameraAtPoint
4088 Tells the cinematic that the camera should be on a point
4089 Params:
4090 Position: The position of the camera in the world
4091 Room: The room that that position is in
4092 $$END
4093 */
4094 void aComplexCinematicCameraAtPoint(vector *Position, int Room) {
4095 ccinematic.info.flags &= ~GCF_USEPATH;
4096 ccinematic.info.flags |= GCF_USEPOINT;
4097
4098 ccinematic.info.position = *Position;
4099 ccinematic.info.room = Room;
4100 }
4101
4102 /*
4103 $$ACTION
4104 Cinematics
4105 Complex Cinematic: Put Camera At Position in clipboard in room [r:Room]
4106 aComplexCinematicCameraAtStoredPt
4107 ComplexCinematicCameraAtStored Point
4108 Tells the cinematic that the camera should be on a point stored in clipboard
4109 Params:
4110 Room: The room that that position is in
4111 $$END
4112 */
4113 void aComplexCinematicCameraAtStoredPt(int Room) {
4114 if (!PositionClipboard.has_pos)
4115 return;
4116
4117 ccinematic.info.flags &= ~GCF_USEPATH;
4118 ccinematic.info.flags |= GCF_USEPOINT;
4119
4120 ccinematic.info.position = PositionClipboard.pos;
4121 ccinematic.info.room = Room;
4122 }
4123
4124 /*
4125 $$ENUM CineScreenMode
4126 0:LetterBox
4127 1:FullScreen
4128 $$END
4129 */
4130
4131 /*
4132 $$ACTION
4133 Cinematics
4134 Complex Cinematic: Set Screen Mode to [e:CineScreenMode=0]
4135 aComplexCinematicScreenMode
4136 ComplexCinematicScreenMode
4137 Sets what type of screen mode the cinematic should be in
4138 $$END
4139 */
4140 void aComplexCinematicScreenMode(int Mode) {
4141 ccinematic.info.flags &= ~GCF_SCREENFORMAT;
4142 ccinematic.info.flags |= Mode;
4143 }
4144
4145 /*
4146 $$ENUM CineTextMode
4147 0:None
4148 4:WipeIn
4149 8:FadeInOut
4150 $$END
4151 */
4152
4153 /*
4154 $$ACTION
4155 Cinematics
4156 Complex Cinematic: Set Text Display Mode to [e:CineTextMode=8]
4157 aComplexCinematicTextMode
4158 ComplexCinematicTextMode
4159 Sets what type of text effect the cinematic should use
4160 $$END
4161 */
4162 void aComplexCinematicTextMode(int Mode) {
4163 ccinematic.info.flags &= ~GCF_TEXT_MASK;
4164 ccinematic.info.flags |= Mode;
4165 }
4166
4167 /*
4168 $$ENUM CineTextLayoutMode
4169 0:Bottom
4170 16:Top
4171 32:Middle
4172 64:Low
4173 $$END
4174 */
4175
4176 /*
4177 $$ACTION
4178 Cinematics
4179 Complex Cinematic: Set Text Screen Layout to [e:CineTextLayoutMode=0]
4180 aComplexCinematicTextLayoutMode
4181 ComplexCinematicTextLayoutMode
4182 Sets what type of text layout the cinematic should use
4183 $$END
4184 */
4185 void aComplexCinematicTextLayoutMode(int Mode) {
4186 ccinematic.info.flags &= ~GCF_LAYOUT_MASK;
4187 ccinematic.info.flags |= Mode;
4188 }
4189
4190 /*
4191 $$FLAG CinematicFlags
4192 256:Stop If Target Is Dead
4193 512:Force Target To End of Path on Quick Exit
4194 $$END
4195 */
4196
4197 /*
4198 $$ACTION
4199 Cinematics
4200 Complex Cinematic: Flags: [g:CinematicFlags=256:768]
4201 aComplexCinematicFlags
4202 ComplexCinematicFlags
4203 Sets special flags for the cinematic
4204 $$END
4205 */
4206 void aComplexCinematicFlags(int flags) {
4207 ccinematic.info.flags &= ~(GCF_STOPIFTAGETDEAD | GCF_FORCETARGETTOEND);
4208 ccinematic.info.flags |= flags;
4209 }
4210
4211 /*
4212 $$ACTION
4213 Mission
4214 Enable the given ship [a:Ship], so it can be chosen in single player
4215 aEnableShip
4216 EnableShip
4217 Enables a ship (given it's name) so it can be chosen in
4218 single player ship selection dialog.
4219
4220 Parameters:
4221 Ship: The name of the ship you want to enable
4222 $$END
4223 */
4224 void aEnableShip(const char *Ship) {
4225 // this doesn't have to be multiplayer friendly, since it's a single
4226 // player only thing
4227 Game_EnableShip(Ship, true);
4228 }
4229
4230 /*
4231 $$ACTION
4232 Mission
4233 Disable the given ship [a:Ship], so it can't be chosen in single player
4234 aDisableShip
4235 DisableShip
4236 Disables a ship (given it's name) so it can't be chosen in
4237 single player ship selection dialog.
4238
4239 Parameters:
4240 Ship: The name of the ship you want to disable
4241
4242 $$END
4243 */
4244 void aDisableShip(const char *Ship) {
4245 // this doesn't have to be multiplayer friendly, since it's a single
4246 // player only thing
4247 Game_EnableShip(Ship, false);
4248 }
4249
4250 /*
4251 $$ACTION
4252 Triggers
4253 [e:Enable/Disable] trigger [t:Trigger]
4254 aTriggerSetState
4255 Enable/Disable a trigger
4256 Enables or disables the specified trigger
4257
4258 Parameters:
4259 Enable/Disable: whether to enable or disable the trigger
4260 Trigger: which trigger to set
4261 $$END
4262 */
4263 void aTriggerSetState(int state, int trigger_num) {
4264 msafe_struct mstruct;
4265
4266 mstruct.trigger_num = trigger_num;
4267 mstruct.state = state;
4268 MSafe_CallFunction(MSAFE_TRIGGER_SET, &mstruct);
4269 }
4270
4271 /*
4272 $$ACTION
4273 Players
4274 Add [o:Object] to [o:PlayerObject]'s inventory, Spewable when player dies [b:Spewable=FALSE]
4275 aAddObjectToInventory
4276 Adds a specific object to a player's inventory
4277
4278 Parameters:
4279 Object: Object to add
4280 PlayerObject: Player to get object
4281 Spewable: Whether the object should be spewed from the inventory when the player dies
4282 $$END
4283 */
4284 void aAddObjectToInventory(int Object, int PlayerObject, bool Spewable) {
4285 msafe_struct mstruct;
4286
4287 mstruct.objhandle = PlayerObject;
4288 mstruct.ithandle = Object;
4289 mstruct.message[0] = '\0'; // no name
4290
4291 if (Spewable)
4292 mstruct.flags = 0;
4293 else
4294 mstruct.flags = INVAF_NOTSPEWABLE;
4295
4296 MSafe_CallFunction(MSAFE_INVEN_ADD_OBJECT, &mstruct);
4297 }
4298
4299 /*
4300 $$ACTION
4301 Players
4302 Add [o:Object] to [o:PlayerObject]'s inventory with name [s:ItemName], Spewable when player dies [b:Spewable=FALSE]
4303 aAddObjectToInventoryNamed
4304 Adds a specific object to a player's inventory with a custom name
4305
4306 Parameters:
4307 Object: Object to add
4308 PlayerObject: Player to get object
4309 ItemName: The name for this object
4310 Spewable: Whether the object should be spewed from the inventory when the player dies
4311 $$END
4312 */
4313 void aAddObjectToInventoryNamed(int Object, int PlayerObject, const char *name, bool Spewable) {
4314 msafe_struct mstruct;
4315
4316 mstruct.objhandle = PlayerObject;
4317 mstruct.ithandle = Object;
4318
4319 strncpy(mstruct.message, name, sizeof(mstruct.message) - 1);
4320 mstruct.message[sizeof(mstruct.message) - 1] = '\0';
4321
4322 if (Spewable)
4323 mstruct.flags = 0;
4324 else
4325 mstruct.flags = INVAF_NOTSPEWABLE;
4326
4327 MSafe_CallFunction(MSAFE_INVEN_ADD_OBJECT, &mstruct);
4328 }
4329
4330 /*
4331 $$ACTION
4332 Players
4333 Remove [o:Object] from [o:PlayerObject]'s inventory
4334 aRemoveObjectFromInventory
4335 Removes a specific object from a player's inventory
4336
4337 Parameters:
4338 Object: Object to remove
4339 PlayerObject: Which Player
4340 $$END
4341 */
4342 void aRemoveObjectFromInventory(int Object, int PlayerObject) {
4343 msafe_struct mstruct;
4344
4345 mstruct.objhandle = PlayerObject;
4346 mstruct.ithandle = Object;
4347 MSafe_CallFunction(MSAFE_INVEN_REMOVE_OBJECT, &mstruct);
4348 }
4349
4350 /*
4351 $$ACTION
4352 Objects
4353 Store [o:Object] position in position clipboard
4354 aStoreObjectInPositionClipboard
4355 Stores the position of an object in the internal 'clipboard'
4356
4357 Parameters:
4358 Object: object whose position you want to store
4359 $$END
4360 */
4361 void aStoreObjectInPositionClipboard(int Object) {
4362 msafe_struct mstruct;
4363 mstruct.objhandle = Object;
4364 MSafe_GetValue(MSAFE_OBJECT_WORLD_POSITION, &mstruct);
4365
4366 PositionClipboard.pos = mstruct.pos;
4367 PositionClipboard.orient = mstruct.orient;
4368 PositionClipboard.room = mstruct.roomnum;
4369 PositionClipboard.has_pos = true;
4370 }
4371
4372 /*
4373 $$ACTION
4374 Objects
4375 Move [o:Object] to position in position clipboard
4376 aMoveObjectToPositionClipboard
4377 Moves an object to the position stored in the internal 'clipboard'
4378
4379 Parameters:
4380 Object: object whose position you want to change
4381 $$END
4382 */
4383 void aMoveObjectToPositionClipboard(int Object) {
4384 if (!PositionClipboard.has_pos)
4385 return;
4386
4387 msafe_struct mstruct;
4388 mstruct.objhandle = Object;
4389 mstruct.pos = PositionClipboard.pos;
4390 mstruct.orient = PositionClipboard.orient;
4391 mstruct.roomnum = PositionClipboard.room;
4392
4393 MSafe_CallFunction(MSAFE_OBJECT_WORLD_POSITION, &mstruct);
4394 }
4395
4396 /*
4397 $$ACTION
4398 Objects
4399 Cloak [o:Object] for [f:Seconds] seconds
4400 aCloakObject
4401 Cloaks an object for the time specified.
4402
4403 Parameters:
4404 Object: object to cloak
4405 Seconds: how long should it be cloaked
4406 $$END
4407 */
4408 void aCloakObject(int Object, float Seconds) {
4409 msafe_struct mstruct;
4410 mstruct.objhandle = Object;
4411 mstruct.state = 1;
4412 mstruct.lifetime = Seconds;
4413 MSafe_CallFunction(MSAFE_OBJECT_CLOAK, &mstruct);
4414 }
4415
4416 /*
4417 $$ACTION
4418 Objects
4419 UnCloak [o:Object]
4420 aUnCloakObject
4421 UnCloaks an object
4422
4423 Parameters:
4424 Object: object to uncloak
4425 $$END
4426 */
4427 void aUnCloakObject(int Object) {
4428 msafe_struct mstruct;
4429 mstruct.objhandle = Object;
4430 mstruct.state = 0;
4431 MSafe_CallFunction(MSAFE_OBJECT_CLOAK, &mstruct);
4432 }
4433
4434 /*
4435 $$ACTION
4436 Players
4437 Cloak all players for [f:Seconds] seconds
4438 aCloakAllPlayers
4439 Cloaks all the Players in the game
4440
4441 Parameters:
4442 Seconds: how long should the players be cloaked
4443 $$END
4444 */
4445 void aCloakAllPlayers(float Seconds) {
4446 msafe_struct mstruct;
4447 mstruct.state = 1;
4448 mstruct.lifetime = Seconds;
4449 MSafe_CallFunction(MSAFE_OBJECT_CLOAKALLPLAYERS, &mstruct);
4450 }
4451
4452 /*
4453 $$ACTION
4454 Players
4455 UnCloak all players
4456 aUnCloakAllPlayers
4457 UnCloaks all the Players in the game
4458
4459 $$END
4460 */
4461 void aUnCloakAllPlayers(void) {
4462 msafe_struct mstruct;
4463 mstruct.state = 0;
4464 MSafe_CallFunction(MSAFE_OBJECT_CLOAKALLPLAYERS, &mstruct);
4465 }
4466
4467 /*
4468 $$ACTION
4469 Objects
4470 Set [o:Object] on Fire for [f:Seconds] doing [f:Damage] damage per second
4471 aSetObjectOnFire
4472 Sets an object on fire
4473
4474 Parameters:
4475 Object = object to be set on fire
4476 Seconds = how long it should be on fire
4477 Damage = how much damage per second the fire should do
4478 $$END
4479 */
4480 void aSetObjectOnFire(int obj, float seconds, float dps) {
4481 msafe_struct mstruct;
4482 mstruct.objhandle = obj;
4483 mstruct.longevity = seconds;
4484 mstruct.interval = dps;
4485 mstruct.ithandle = OBJECT_HANDLE_NONE;
4486 MSafe_CallFunction(MSAFE_OBJECT_SETONFIRE, &mstruct);
4487 }
4488
4489 /*
4490 $$ACTION
4491 Objects
4492 Fire weapon [a:WeaponName] from gun number [i:GunNum] of object [o:Object]
4493 aObjFireWeapon
4494 Fire weapon
4495 Fires the specified weapon from the given gun number of an object
4496
4497 Parameters:
4498 WeaponName - the weapon to fire
4499 GunNum - the gun number to fire from, or -1 to fire from the object's center
4500 Object - the object to fire the flare
4501 $$END
4502 */
4503 void aObjFireWeapon(const char *weapon_name, int gun_num, int objhandle) {
4504 msafe_struct mstruct;
4505
4506 mstruct.objhandle = objhandle;
4507 mstruct.index = Wpn_FindID(weapon_name);
4508 if (mstruct.index == -1)
4509 return;
4510 mstruct.gunpoint = gun_num;
4511
4512 MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON, &mstruct);
4513 }
4514
4515 /*
4516 $$ACTION
4517 Objects
4518 Fire flare from gun number [i:GunNum] of object [o:Object]
4519 aObjFireFlare
4520 Fire flare
4521 Fires a flare from the given gun number of an object
4522
4523 Parameters:
4524 GunNum - the gun number to fire from, or -1 to fire from the object's center
4525 Object - the object to fire the flare
4526 $$END
4527 */
4528 #define aObjFireFlare(gun_num, objhandle) aObjFireWeapon("Yellow flare", gun_num, objhandle)
4529
4530 ////////////////////////////////////////////////////////////////////////////////////////////
4531 // The following code is to handle a 'kill all object except these' Dallas command sequence.
4532 // these are beneficial for areas like Boss rooms with no escape or something, were it is
4533 // just nice to kill all objects in the level, except what is needed, for framerate
4534 // It will only kill robots in the level, except those designated to spare.
4535
4536 struct tKillRobotListNode {
4537 tKillObjectItem item;
4538 tKillRobotListNode *next;
4539 };
4540
4541 class CKillRobotList {
4542 public:
4543 CKillRobotList() { list = NULL; };
4544 ~CKillRobotList() { clear(); }
4545
4546 void clear(void);
4547 void add(tKillObjectItem *data);
4548
4549 tKillRobotListNode *list;
4550 };
4551 CKillRobotList KillRobotList;
4552
4553 void CKillRobotList::clear(void) {
4554 tKillRobotListNode *next, *curr = list;
4555
4556 while (curr) {
4557 next = curr->next;
4558 free(curr);
4559 curr = next;
4560 }
4561
4562 list = NULL;
4563 }
4564
4565 void CKillRobotList::add(tKillObjectItem *data) {
4566 tKillRobotListNode *curr = list;
4567
4568 if (!curr) {
4569 list = curr = (tKillRobotListNode *)malloc(sizeof(tKillRobotListNode));
4570 } else {
4571 while (curr->next) {
4572 curr = curr->next;
4573 }
4574
4575 curr->next = (tKillRobotListNode *)malloc(sizeof(tKillRobotListNode));
4576 curr = curr->next;
4577 }
4578
4579 if (!curr)
4580 return;
4581
4582 curr->next = NULL;
4583 memcpy(&curr->item, data, sizeof(tKillObjectItem));
4584 }
4585
4586 /*
4587 $$ACTION
4588 Objects
4589 Destroy All Robots: Start
4590 aDestroyAllRobotsInit
4591 Initializes the "Destroy All Robots" DALLAS command sequence. Call this BEFORE doing
4592 any other of the "Destroy All Robots" commands.
4593
4594 NOTE: It is VERY important that the entire command sequence happens all in the same
4595 action, and in proper order.
4596 $$END
4597 */
4598 void aDestroyAllRobotsInit(void) { KillRobotList.clear(); }
4599
4600 /*
4601 $$ACTION
4602 Objects
4603 Destroy All Robots: Spare robots of this type [a:RobotID]
4604 aDestroyAllRobotsSpareType
4605 Spares any robot that has if of the species given (i.e. Tubbs)
4606
4607 Parameters:
4608 RobotID - the name of the group of robots to Spare
4609 $$END
4610 */
4611 void aDestroyAllRobotsSpareType(const char *name) {
4612 int id = Obj_FindID(name);
4613
4614 if (id != -1) {
4615 tKillObjectItem item;
4616 item.info_type = KOI_ID;
4617 item.id = id;
4618
4619 KillRobotList.add(&item);
4620 }
4621 }
4622
4623 /*
4624 $$ACTION
4625 Objects
4626 Destroy All Robots: Spare robot ([o:RobotHandle])
4627 aDestroyAllRobotsSpareHandle
4628 Spares the robot with the given handle
4629
4630 Parameters:
4631 RobotHandle - the handle of the robot to Spare
4632 $$END
4633 */
4634 void aDestroyAllRobotsSpareHandle(int handle) {
4635 if (handle != OBJECT_HANDLE_NONE) {
4636 tKillObjectItem item;
4637 item.info_type = KOI_HANDLE;
4638 item.objhandle = handle;
4639
4640 KillRobotList.add(&item);
4641 }
4642 }
4643
4644 /*
4645 $$ACTION
4646 Objects
4647 Destroy All Robots: End
4648 aDestroyAllRobotsEnd
4649 Destroys the robots (except those spared) in the level
4650
4651 $$END
4652 */
4653 void aDestroyAllRobotsEnd(void) {
4654 tKillRobotListNode *curr = KillRobotList.list;
4655 int count = 0;
4656
4657 if (!curr)
4658 return;
4659
4660 while (curr) {
4661 count++;
4662 curr = curr->next;
4663 }
4664
4665 curr = KillRobotList.list;
4666 tKillObjectItem *kolist = NULL;
4667
4668 kolist = (tKillObjectItem *)malloc(sizeof(tKillObjectItem) * count);
4669 if (!kolist)
4670 return;
4671
4672 count = 0;
4673 while (curr) {
4674 memcpy(&kolist[count], &curr->item, sizeof(tKillObjectItem));
4675 count++;
4676 curr = curr->next;
4677 }
4678
4679 msafe_struct ms;
4680 ms.count = count;
4681 ms.list = kolist;
4682 MSafe_CallFunction(MSAFE_OBJECT_DESTROY_ROBOTS_EXCEPT, &ms);
4683
4684 free(kolist);
4685
4686 KillRobotList.clear();
4687 }
4688
4689 /*
4690 $$ACTION
4691 Objects
4692 [e:Enable/Disable] virus infections signs for [o:Object]
4693 aEnableVirusInfection
4694 Enables or disables the graphical effects related to an object being infected
4695 with a virus
4696
4697 $$END
4698 */
4699 void aEnableVirusInfection(int enable, int handle) {
4700 char cenable;
4701 cenable = (enable) ? 1 : 0;
4702
4703 Obj_Value(handle, VF_SET, OBJV_C_VIRUS_INFECTED, &cenable);
4704 }
4705
4706 /*
4707 $$ACTION
4708 Objects
4709 [e:Enable/Disable] negative lighting for [o:Object]
4710 aEnableNegativeLighting
4711 Enables or disables negative dynamic lighting (ala black hole) for the object
4712
4713 $$END
4714 */
4715 void aEnableNegativeLighting(int enable, int handle) {
4716 char cenable;
4717 cenable = (enable) ? 1 : 0;
4718
4719 Obj_Value(handle, VF_SET, OBJV_C_NEGATIVE_LIGHT, &cenable);
4720 }
4721
4722 /*
4723 $$ACTION
4724 Players
4725 Strip all weapons and energy from player [o:Object]
4726 aStripWeaponsEnergy
4727 Removes all weapons (but lasers) and ammo, and reduces energy to 0.
4728
4729 $$END
4730 */
4731 void aStripWeaponsEnergy(int Object) {
4732 int val = 0;
4733 Player_Value(Object, VF_SET, PLYV_I_STRIP_WEAPONS, &val);
4734 }
4735
4736 /*
4737 $$ACTION
4738 Players
4739 Strip all weapons and energy from all players
4740 aStripWeaponsEnergyFromAll
4741 Removes all weapons (but lasers) and ammo, and reduces energy to 0.
4742
4743 $$END
4744 */
4745 void aStripWeaponsEnergyFromAll(void) {
4746 int val = -1;
4747 Player_Value(OBJECT_HANDLE_NONE, VF_SET, PLYV_I_STRIP_WEAPONS, &val);
4748 }
4749
4750 /*
4751 $$ACTION
4752 Rooms
4753 Remove all powerups from room [r:Room]
4754 aRemovePowerupsInRoom
4755 Removes all the powerups in the room given
4756
4757 $$END
4758 */
4759 void aRemovePowerupsInRoom(int Room) {
4760 msafe_struct mstruct;
4761 mstruct.roomnum = Room;
4762 MSafe_CallFunction(MSAFE_ROOM_REMOVE_ALL_POWERUPS, &mstruct);
4763 }
4764
4765 /*
4766 $$QUERY
4767 Objects
4768 b:Is [o:Object] virus infected
4769 qVirusInfected
4770 Returns true if the object is showing signs of being infected by a virus
4771
4772 $$END
4773 */
4774 bool qVirusInfected(int handle) {
4775 char cenable;
4776 Obj_Value(handle, VF_GET, OBJV_C_VIRUS_INFECTED, &cenable);
4777
4778 return (cenable) ? true : false;
4779 }
4780
4781 /*
4782 $$QUERY
4783 Objects
4784 b:Is [o:Object] giving off negative dynamic light (ala black hole)
4785 qNegativeLight
4786 Returns true if the object is giving off negative light, like a black hole (it is
4787 removing light from the world)
4788
4789 $$END
4790 */
4791 bool qNegativeLight(int handle) {
4792 char cenable;
4793 Obj_Value(handle, VF_GET, OBJV_C_NEGATIVE_LIGHT, &cenable);
4794
4795 return (cenable) ? true : false;
4796 }
4797
4798 /*
4799 $$QUERY
4800 Mission
4801 i:Get difficulty level
4802 qGetDifficulty
4803 Returns the difficulty level (0 = trainee,4 = insane)
4804
4805 $$END
4806 */
4807 int qGetDifficulty(void) { return Game_GetDiffLevel(); }
4808
4809 /*
4810 Requested by Luke 1/15/99
4811
4812 PickupPowerup [OBJECT]
4813 -deletes powerup and plays powerup sound
4814 AddToInventory [OBJECT]
4815 -add powerup to the player's inventory
4816 Turn Fog in Room [ROOM] to [TRUE/FALSE]
4817 -turns on/off the fog flag
4818 Fade Fog in Room [ROOM] to Distance [DIST] and Color [RGB] over Time
4819 [TIME]
4820 -needs new code, but should be easy (like SetRoomFog over time)
4821 -ask Jason for new code if need be
4822 Fade Wind in Room [ROOM] to Direction [XYZ] over Time [TIME]
4823 -another new code one, but also easy (like SetRoomWind over time)
4824 -Jason also can help on this one
4825 AI: Fire when close [ROBOT], Distance [DIST]
4826 -Robot fires constantly when a player is within DIST meters
4827
4828 */
4829
4830 /*
4831
4832 MatcenSetStatus
4833 ChangeFaceTexture
4834
4835 PlaySoundLoc3d
4836 TouchSound
4837
4838 */
4839
4840 /*
4841 $$QUERY
4842 Objects
4843 f:[o:Object] cloak time left
4844 qObjectCloakTime
4845
4846 Parameters:
4847 Object: object to get cloak time left (0 if it's not cloaked)
4848 $$END
4849 */
4850 float qObjectCloakTime(int Object) {
4851 msafe_struct mstruct;
4852 mstruct.objhandle = Object;
4853 mstruct.state = 0;
4854 mstruct.lifetime = 0;
4855 MSafe_GetValue(MSAFE_OBJECT_CLOAK, &mstruct);
4856
4857 return (mstruct.state) ? mstruct.lifetime : 0;
4858 }
4859
4860 /*
4861 $$QUERY
4862 Objects
4863 f:Get [o:Object] position on [e:Axis=0] axis
4864 qObjectPosition
4865
4866 Parameters:
4867 Object: object to get cloak time left (0 if it's not cloaked)
4868 $$END
4869 */
4870 float qObjectPosition(int handle, int axis) {
4871 float value = 0.0f;
4872 int type;
4873
4874 Obj_Value(handle, VF_GET, OBJV_I_TYPE, &type);
4875 if (type != OBJ_NONE) {
4876 vector pos;
4877 Obj_Value(handle, VF_GET, OBJV_V_POS, &pos);
4878
4879 switch (axis) {
4880 case 0:
4881 value = pos.x;
4882 break;
4883 case 1:
4884 value = pos.y;
4885 break;
4886 case 2:
4887 value = pos.z;
4888 break;
4889 }
4890 }
4891
4892 return value;
4893 }
4894
4895 /*
4896 $$QUERY
4897 AI
4898 b:[o:Object] close to target
4899 qAICloseToTarget
4900
4901 Parameters:
4902 Object: Is this object near its target
4903 $$END
4904 */
4905 bool qAICloseToTarget(int me) {
4906 int target = OBJECT_HANDLE_NONE;
4907 bool f_close = false;
4908 char ctype;
4909 int status;
4910 float awareness;
4911
4912 Obj_Value(me, VF_GET, OBJV_C_CONTROL_TYPE, &ctype);
4913 if (ctype == CT_AI) {
4914 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target);
4915 if (target != OBJECT_HANDLE_NONE) {
4916 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
4917
4918 if (awareness >= AWARE_BARELY) {
4919 AI_Value(me, VF_GET, AIV_I_STATUS_REG, &status);
4920 f_close = ((status & AISR_CIRCLE_DIST) != 0);
4921 }
4922 }
4923 }
4924
4925 return f_close;
4926 }
4927
4928 /*
4929 $$QUERY
4930 AI
4931 b:Is [o:Object] aware
4932 qAIIsObjectAware
4933
4934 Parameters:
4935 Object: Is this object near its target
4936 $$END
4937 */
4938 bool qAIIsObjectAware(int me) {
4939 bool f_aware = false;
4940 char ctype;
4941
4942 Obj_Value(me, VF_GET, OBJV_C_CONTROL_TYPE, &ctype);
4943 if (ctype == CT_AI) {
4944 float awareness;
4945 AI_Value(me, VF_GET, AIV_F_AWARENESS, &awareness);
4946
4947 if (awareness >= AWARE_BARELY) {
4948 f_aware = true;
4949 }
4950 }
4951
4952 return f_aware;
4953 }
4954
4955 /*
4956 $$QUERY
4957 AI
4958 o:[o:Object] get target
4959 qAIGetTarget
4960
4961 Parameters:
4962 Object: object we want the the target of
4963 $$END
4964 */
4965 int qAIGetTarget(int me) {
4966 int target = OBJECT_HANDLE_NONE;
4967 char ctype;
4968
4969 Obj_Value(me, VF_GET, OBJV_C_CONTROL_TYPE, &ctype);
4970 if (ctype == CT_AI) {
4971 AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target);
4972 }
4973
4974 return target;
4975 }
4976
4977 /*
4978 $$QUERY
4979 Players
4980 b:[o:Player] has [o:Object] in their inventory
4981 qHasObjectInInventory
4982
4983 Parameters:
4984 Player: Player to check
4985 Object: Which object to check for
4986 $$END
4987 */
4988 bool qHasObjectInInventory(int PlayerObject, int Object) {
4989 msafe_struct mstruct;
4990
4991 mstruct.objhandle = PlayerObject;
4992 mstruct.ithandle = Object;
4993 MSafe_GetValue(MSAFE_INVEN_CHECK_OBJECT, &mstruct);
4994
4995 return mstruct.state;
4996 }
4997
4998 /*
4999 $$ACTION
5000 Objects
5001 Save object handle for [o:Object] in slot [e:SavedObjectSlot]
5002 aObjSaveHandle
5003 Save object handle
5004 Saves an object handle for later user
5005
5006 Parameters:
5007 o:Object: the object whose handle is saved
5008 SavedObjectSlot: the slot in which to save the handle
5009 $$END
5010 */
5011 void aObjSaveHandle(int objhandle, int slot) {
5012 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
5013 Saved_object_handles[slot] = objhandle;
5014 }
5015
5016 /*
5017 $$ACTION
5018 Level Goals
5019 Set goal [l:LevelGoal] as [e:Completed]
5020 aGoalCompleted
5021 Set goal completion state
5022 Tells the goal system that the specified goal has been completed or not
5023
5024 Parameters:
5025 LevelGoal: the goal to set
5026 Completed: whether or not the goal has been completed
5027 $$END
5028 */
5029 void aGoalCompleted(int goal_index, int completed) {
5030 int flags = LGF_COMPLETED;
5031
5032 LGoal_Value(completed ? VF_SET_FLAGS : VF_CLEAR_FLAGS, LGSV_I_STATUS, &flags, goal_index);
5033 }
5034
5035 /*
5036 $$ACTION
5037 Level Goals
5038 Set goal [l:LevelGoal] item number [i:ItemIndex] as [e:Completed]
5039 aGoalItemCompleted
5040 Set goal item completion state
5041 Tells the goal system that the specified goal item has been completed or not
5042
5043 Parameters:
5044 LevelGoal: the goal
5045 ItemIndex: the index of the item in question
5046 Completed: whether or not the goal item has been completed
5047 $$END
5048 */
5049 void aGoalItemCompleted(int goal_index, int item_index, int completed) {
5050 bool f_set = (completed != 0);
5051 LGoal_Value(VF_SET, LGSSV_B_ITEM_DONE, &f_set, goal_index, item_index - 1);
5052 }
5053
5054 /*
5055 $$ACTION
5056 Level Goals
5057 Set goal [l:LevelGoal] as [e:Failed]
5058 aGoalFailed
5059 Set goal fail state
5060 Tells the goal system that the specified goal has been failed or not
5061
5062 Parameters:
5063 LevelGoal: the goal to set
5064 Failed: whether or not the goal has been failed
5065 $$END
5066 */
5067 void aGoalFailed(int goal_index, int failed) {
5068 int flags = LGF_FAILED;
5069
5070 LGoal_Value(failed ? VF_SET_FLAGS : VF_CLEAR_FLAGS, LGSV_I_STATUS, &flags, goal_index);
5071 }
5072
5073 /*
5074 $$ACTION
5075 Level Goals
5076 [e:Enable/Disable] goal [l:LevelGoal]
5077 aGoalEnableDisable
5078 Enable/disable goal
5079 Enable or disable the specified goal
5080
5081 Parameters:
5082 Enable/Disable: whether the goal should be enabled or disabled
5083 LevelGoal: the goal to set
5084 $$END
5085 */
5086 void aGoalEnableDisable(int enabled, int goal_index) {
5087 int flags = LGF_ENABLED;
5088
5089 LGoal_Value(enabled ? VF_SET_FLAGS : VF_CLEAR_FLAGS, LGSV_I_STATUS, &flags, goal_index);
5090 }
5091
5092 /*
5093 $$ACTION
5094 Level Goals
5095 Set goal [l:LevelGoal] priority = [i:Priority]
5096 aGoalSetPriority
5097 Set goal priority
5098 Sets the priority of the specified goal
5099
5100 Parameters:
5101 LevelGoal: the goal to set
5102 Priority: the priority to set
5103 $$END
5104 */
5105 void aGoalSetPriority(int goal_index, int priority) { LGoal_Value(VF_SET, LGSV_I_PRIORITY, &priority, goal_index); }
5106
5107 /*
5108 $$ACTION
5109 Level Goals
5110 Set goal [l:LevelGoal] completion message = [s:Message]
5111 aGoalSetCompletionMessage
5112 Set goal completion message
5113 Sets the completion message for the specified goal
5114
5115 Parameters:
5116 LevelGoal: the goal to set
5117 Message: the message for the goal
5118 $$END
5119 */
5120 void aGoalSetCompletionMessage(int goal_index, const char *message) {
5121 LGoal_Value(VF_SET, LGSV_PC_COMPLETION_MESSAGE, (void *) message, goal_index);
5122 }
5123
5124 /*
5125 $$ACTION
5126 Level Goals
5127 GuideBot [e:Can/Cannot] lead the player to goal [l:LevelGoal]
5128 aGoalSetGBKnowledge
5129 GuideBot can/cannot lead the player to goal
5130 Tells the goal system whether the GuideBot is allowed to lead the player to the specified goal
5131
5132 Parameters:
5133 Can/Cannot: whether or not the GuideBot can lead the player to the goal
5134 LevelGoal: the goal to set
5135 $$END
5136 */
5137 void aGoalSetGBKnowledge(int enabled, int goal_index) {
5138 int flags = LGF_GB_DOESNT_KNOW_LOC;
5139
5140 LGoal_Value(enabled ? VF_CLEAR_FLAGS : VF_SET_FLAGS, LGSV_I_STATUS, &flags, goal_index);
5141 }
5142
5143 //
5144 // D3 queries
5145 //
5146
5147 /* NOTE: The following query is handled internally by DALLAS
5148 $$QUERY
5149 Scripts
5150 b:Script [x:ScriptID] has executed
5151 qScriptExecuted_DALLAS
5152 Has this script been executed?
5153 Determines if the specified script has executed at least once
5154
5155 Parameters:
5156 ScriptID: The script to check
5157 $$END
5158 */
5159
5160 /* NOTE: The following query is handled internally by DALLAS
5161 $$QUERY
5162 Scripts
5163 i:Times Script [x:ScriptID] has been executed
5164 qTimesScriptExecuted_DALLAS
5165 How many times has this script been executed?
5166 Returns the number of times the specified script has executed
5167
5168 Parameters:
5169 ScriptID: The script to check
5170 $$END
5171 */
5172
5173 /*
5174 $$QUERY
5175 Objects
5176 b:[o:Object] exists
5177 qObjExists
5178 Does this object exist?
5179 Determines if the specified object exists in the world
5180
5181 Parameters:
5182 Object: The object to check
5183 $$END
5184 */
5185 bool qObjExists(int objref) {
5186 msafe_struct mstruct;
5187
5188 mstruct.objhandle = objref;
5189
5190 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5191
5192 return (mstruct.type != -1);
5193 }
5194
5195 /*
5196 $$QUERY
5197 Objects
5198 b:[o:Object=IT] is a player
5199 qObjIsPlayer
5200 Is this object a player?
5201 Determines if the specified object is a player
5202
5203 Parameters:
5204 Object: The object to check
5205 $$END
5206 */
5207 bool qObjIsPlayer(int objref) {
5208 msafe_struct mstruct;
5209
5210 mstruct.objhandle = objref;
5211
5212 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5213
5214 return (mstruct.type == OBJ_PLAYER);
5215 }
5216
5217 /*
5218 $$QUERY
5219 Objects
5220 b:[o:Object=IT] is a player weapon
5221 qObjIsPlayerWeapon
5222 Is this object a player weapon?
5223 Determines if the specified object is a player weapon
5224
5225 Parameters:
5226 Object: The object to check
5227 $$END
5228 */
5229 bool qObjIsPlayerWeapon(int handle) {
5230 msafe_struct mstruct;
5231
5232 mstruct.objhandle = handle;
5233
5234 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5235
5236 if (mstruct.type == OBJ_WEAPON) {
5237 MSafe_GetValue(MSAFE_OBJECT_PARENT, &mstruct);
5238 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5239
5240 if (mstruct.type == OBJ_PLAYER)
5241 return 1;
5242 }
5243
5244 return 0;
5245 }
5246
5247 /*
5248 $$QUERY
5249 Objects
5250 b:[o:Object=IT] is a player or player weapon
5251 qObjIsPlayerOrPlayerWeapon
5252 Is this object either a player or a player weapon?
5253 Determines if the specified object is either a player or a player weapon
5254
5255 Parameters:
5256 Object: The object to check
5257 $$END
5258 */
5259 bool qObjIsPlayerOrPlayerWeapon(int handle) {
5260 msafe_struct mstruct;
5261
5262 mstruct.objhandle = handle;
5263
5264 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5265
5266 if (mstruct.type == OBJ_PLAYER)
5267 return 1;
5268
5269 if (mstruct.type == OBJ_WEAPON) {
5270 MSafe_GetValue(MSAFE_OBJECT_PARENT, &mstruct);
5271 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5272
5273 if (mstruct.type == OBJ_PLAYER)
5274 return 1;
5275 }
5276
5277 return 0;
5278 }
5279
5280 /*
5281 $$QUERY
5282 Objects
5283 b:[o:Object=IT] is an energy weapon
5284 qObjIsEnergyWeapon
5285 Is this object an energy weapon?
5286 Determines if the specified object is an energy weapon
5287
5288 Parameters:
5289 Object: The object to check
5290 $$END
5291 */
5292 bool qObjIsEnergyWeapon(int handle) {
5293 msafe_struct mstruct;
5294
5295 mstruct.objhandle = handle;
5296 MSafe_GetValue(MSAFE_OBJECT_ENERGY_WEAPON, &mstruct);
5297
5298 return mstruct.state;
5299 }
5300
5301 /*
5302 $$QUERY
5303 Objects
5304 b:[o:Object=IT] is a [e:ObjectType]
5305 qObjIsType
5306 Is this object the specified type?
5307 Determines if the specified object is the specified type
5308
5309 Parameters:
5310 Object: The object to check
5311 ObjectType: The type to check
5312 $$END
5313 */
5314 bool qObjIsType(int objhandle, int type) {
5315 msafe_struct mstruct;
5316
5317 mstruct.objhandle = objhandle;
5318
5319 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5320
5321 return (mstruct.type == type);
5322 }
5323
5324 /*
5325 $$QUERY
5326 Objects
5327 b:[o:TargetObject] is within the [i:Cone=90] degree view cone of [o:Object]
5328 qObjCanSeeObj
5329 Can object see the target object
5330 Determines if the specified object can see the other object
5331
5332 Parameters:
5333 Object: The object doing the looking
5334 TargetObject: The target object
5335 Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object
5336 $$END
5337 */
5338 bool qObjCanSeeObj(int handletarget, int cone, int handlesrc) {
5339 vector vsource, vtarget;
5340
5341 msafe_struct mstruct;
5342
5343 // Get half of the angle that the user specified because they specified a cone, and we want an angle
5344 double cangle = (double)((double)cone / (double)2);
5345
5346 double testangle = cos(cangle * PI / 180);
5347
5348 mstruct.objhandle = handletarget;
5349 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
5350 vtarget = mstruct.pos;
5351
5352 mstruct.objhandle = handlesrc;
5353 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
5354 vsource = mstruct.pos;
5355
5356 mstruct.objhandle = handlesrc;
5357 MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct);
5358
5359 vector subvec = vtarget - vsource;
5360 vm_VectorNormalizeFast(&subvec);
5361 float dotp = vm_DotProduct(&subvec, &mstruct.orient.fvec);
5362
5363 if (dotp > testangle) {
5364 return true;
5365 }
5366 return false;
5367 }
5368
5369 /*
5370 $$QUERY
5371 Objects
5372 b:[o:TargetObject] is within the [i:Cone=90] degree view cone of [o:Object] using flags [g:FVIHitFlags=1048585:16269119]
5373 qObjCanSeeObjAdvanced
5374 Can object see the target object
5375 Determines if the specified object can see the other object using the given flags
5376
5377 Parameters:
5378 Object: The object doing the looking
5379 TargetObject: The target object
5380 Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object
5381 FVIHitFlags: Flags used to determine visibility
5382 $$END
5383 */
5384 bool qObjCanSeeObjAdvanced(int handletarget, int cone, int handlesrc, int fvi_flags) {
5385 vector vsource, vtarget;
5386 int sourceroom;
5387
5388 msafe_struct mstruct;
5389
5390 // Get half of the angle that the user specified because they specified a cone, and we want an angle
5391 double cangle = (double)((double)cone / (double)2);
5392
5393 double testangle = cos(cangle * PI / 180);
5394
5395 mstruct.objhandle = handletarget;
5396 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
5397 vtarget = mstruct.pos;
5398
5399 mstruct.objhandle = handlesrc;
5400 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
5401 vsource = mstruct.pos;
5402
5403 mstruct.objhandle = handlesrc;
5404 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
5405 sourceroom = mstruct.roomnum;
5406
5407 mstruct.objhandle = handlesrc;
5408 MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct);
5409
5410 vector subvec = vtarget - vsource;
5411 vm_VectorNormalizeFast(&subvec);
5412 float dotp = vm_DotProduct(&subvec, &mstruct.orient.fvec);
5413
5414 if (dotp > testangle) {
5415 // see if we can cast a ray to the object
5416 ray_info ray;
5417 fvi_flags |= FQ_CHECK_OBJS;
5418 int fate = FVI_RayCast(handlesrc, &vsource, &vtarget, sourceroom, 0.0f, fvi_flags, &ray);
5419 if (fate == HIT_NONE)
5420 return true;
5421
5422 if (fate == HIT_OBJECT) {
5423 if (ray.hit_object == handletarget) {
5424 return true;
5425 }
5426 }
5427 }
5428 return false;
5429 }
5430
5431 /*
5432 $$QUERY
5433 Objects
5434 o:[o:Object=IT] parent
5435 qObjParent
5436 Object parent
5437 Gets the parent of the specified object
5438
5439 Parameters:
5440 Object: The object whose parent is returned
5441 $$END
5442 */
5443 int qObjParent(int objhandle) {
5444 msafe_struct mstruct;
5445
5446 mstruct.objhandle = objhandle;
5447
5448 MSafe_GetValue(MSAFE_OBJECT_PARENT, &mstruct);
5449
5450 return mstruct.objhandle;
5451 }
5452
5453 /*
5454 $$QUERY
5455 Objects
5456 o:Get attached child of [o:Object] at attach point [i:AttachPoint]
5457 qGetAtachedChild
5458 Attached child
5459 Gets the attached child of the specified object
5460
5461 Parameters:
5462 Object: The object who we want to determine its attached child
5463 AttachPoint: The attach point the child is attached to
5464 $$END
5465 */
5466 int qGetAtachedChild(int objhandle, int attachpoint) { return Obj_GetAttachChildHandle(objhandle, attachpoint); }
5467
5468 /*
5469 $$QUERY
5470 Objects
5471 r:[o:Object=IT] room
5472 qObjRoom
5473 Object Room
5474 Returns the room the specified object is in
5475
5476 Parameters:
5477 Object: The object whose room you want to know
5478 $$END
5479 */
5480 int qObjRoom(int objref) {
5481 msafe_struct mstruct;
5482
5483 mstruct.objhandle = objref;
5484
5485 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
5486
5487 return mstruct.roomnum;
5488 }
5489
5490 // These should be in object_external.h
5491 #define ROOMNUM_CELLNUM_FLAG 0x80000000
5492 #define ROOMNUM_OUTSIDE(roomnum) (((roomnum) & ROOMNUM_CELLNUM_FLAG) != 0)
5493
5494 /*
5495 $$QUERY
5496 Objects
5497 b:[o:Object=IT] is on the terrain
5498 qObjOnTerrain
5499 Object on terrain?
5500 Determines if the specified object is on the terrain
5501
5502 Parameters:
5503 Object: The object to check
5504 $$END
5505 */
5506 bool qObjOnTerrain(int objhandle) {
5507 msafe_struct mstruct;
5508
5509 mstruct.objhandle = objhandle;
5510
5511 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
5512
5513 return ROOMNUM_OUTSIDE(mstruct.roomnum);
5514 }
5515
5516 /*
5517 $$QUERY
5518 Objects
5519 e(ObjectType):[o:Object=IT] type
5520 qObjType
5521 Object type
5522 Returns the specified object's type
5523
5524 Parameters:
5525 Object: The object whose type you want to know
5526 $$END
5527 */
5528 int qObjType(int objref) {
5529 msafe_struct mstruct;
5530
5531 mstruct.objhandle = objref;
5532
5533 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
5534
5535 return mstruct.type;
5536 }
5537
5538 /*
5539 $$QUERY
5540 User Vars
5541 f:User Variable [e:UserVar]
5542 qUserVarValue
5543 User Variable
5544 Returns the value of the specified user variable
5545
5546 Parameters:
5547 UserVar: The variable whose value to return
5548 $$END
5549 */
5550 float qUserVarValue(int varnum) {
5551 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
5552 return User_vars[varnum];
5553 else
5554 return 0.0;
5555 }
5556
5557 /*
5558 $$QUERY
5559 User Vars
5560 i:User Variable [e:UserVar] (Integer)
5561 qUserVarValueInt
5562 User Variable (Integer)
5563 Returns the value of the specified user variable rounded to the nearest integer
5564
5565 Parameters:
5566 UserVar: The variable whose value to return
5567 $$END
5568 */
5569 int qUserVarValueInt(int varnum) {
5570 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
5571 return (User_vars[varnum] + 0.5);
5572 else
5573 return 0.0;
5574 }
5575
5576 /*
5577 $$QUERY
5578 User Vars
5579 b:User Flag [e:UserFlag]
5580 qUserFlag
5581 User flag
5582 Returns the state of the specified user flag
5583
5584 Parameters:
5585 UserFlag: The flag whose state to return
5586 $$END
5587 */
5588 bool qUserFlag(int flagnum) {
5589 if ((flagnum >= 0) && (flagnum < 32))
5590 return ((User_flags & (1 << flagnum)) != 0);
5591 else
5592 return 0;
5593 }
5594
5595 /*
5596 $$QUERY
5597 Objects
5598 f:Object [o:Object] shields
5599 qObjShields
5600 Get an object's shields
5601 Gets an object's shields
5602
5603 Parameters:
5604 Object: the object whose shields are being queried
5605 $$END
5606 */
5607 float qObjShields(int objref) {
5608 msafe_struct mstruct;
5609
5610 mstruct.objhandle = objref;
5611
5612 MSafe_GetValue(MSAFE_OBJECT_SHIELDS, &mstruct);
5613
5614 return mstruct.shields;
5615 }
5616
5617 /*
5618 $$QUERY
5619 Objects
5620 f:Object [o:Object] energy
5621 qObjEnergy
5622 Get an object's energy
5623 Gets an object's energy
5624
5625 Parameters:
5626 Object: the object whose energy are being queried
5627 $$END
5628 */
5629 float qObjEnergy(int objref) {
5630 msafe_struct mstruct;
5631
5632 mstruct.objhandle = objref;
5633
5634 MSafe_GetValue(MSAFE_OBJECT_ENERGY, &mstruct);
5635
5636 return mstruct.energy;
5637 }
5638
5639 /*
5640 $$QUERY
5641 Objects
5642 f:Object [o:Object] original shields
5643 qObjShieldsOriginal
5644 Object's original shields
5645 Gets an object's original (full-strength) shields
5646
5647 Parameters:
5648 Object: the object whose shields are being queried
5649 $$END
5650 */
5651 float qObjShieldsOriginal(int objref) {
5652 msafe_struct mstruct;
5653
5654 mstruct.objhandle = objref;
5655
5656 MSafe_GetValue(MSAFE_OBJECT_SHIELDS_ORIGINAL, &mstruct);
5657
5658 return mstruct.shields;
5659 }
5660
5661 /*
5662 $$QUERY
5663 Doors
5664 b:Door [d:Door] is locked
5665 qDoorLocked
5666 Door locked
5667 Determines if a door is locked
5668
5669 Parameters:
5670 Door: the door to check
5671 $$END
5672 */
5673 bool qDoorLocked(int objref) {
5674 msafe_struct mstruct;
5675
5676 mstruct.objhandle = objref;
5677 MSafe_GetValue(MSAFE_DOOR_LOCK_STATE, &mstruct);
5678
5679 return mstruct.state;
5680 }
5681
5682 /*
5683 $$QUERY
5684 Doors
5685 b:Door [d:Door] is openable by [o:Object=IT]
5686 qDoorOpenable
5687 Door openable
5688 Determines if a door is openable by the specified object
5689
5690 Parameters:
5691 Door: the door to check
5692 Object: the object to check
5693 $$END
5694 */
5695 bool qDoorOpenable(int door_handle, int opener_handle) {
5696 msafe_struct mstruct;
5697
5698 mstruct.objhandle = door_handle;
5699 mstruct.ithandle = opener_handle;
5700 MSafe_GetValue(MSAFE_DOOR_OPENABLE, &mstruct);
5701
5702 return mstruct.state;
5703 }
5704
5705 /*
5706 $$QUERY
5707 Doors
5708 p:Door [d:Door] position
5709 qDoorGetPos
5710 Get door position
5711 Gets the position of the specified door
5712
5713 Parameters:
5714 Door: the object of the door
5715 $$END
5716 */
5717 float qDoorGetPos(int objhandle) {
5718 msafe_struct mstruct;
5719
5720 mstruct.objhandle = objhandle;
5721
5722 MSafe_GetValue(MSAFE_DOOR_POSITION, &mstruct);
5723
5724 return mstruct.scalar;
5725 }
5726
5727 /*
5728 $$QUERY
5729 Mission
5730 b:Mission flag [i:FlagNum] is set
5731 aMissionGetFlag
5732 Get a mission flag
5733 Gets the specified mission flag
5734
5735 Parameters:
5736 FlagNum: the flag to get
5737 $$END
5738 */
5739 bool aMissionGetFlag(int flagnum) { return Msn_FlagGet(flagnum); }
5740
5741 /*
5742 $$QUERY
5743 Mission
5744 b:Level objective flag [i:FlagNum] is set
5745 aMissionGetLevelFlag
5746 Get a level objective flag
5747 Gets the specified level objective flag
5748
5749 Parameters:
5750 FlagNum: the flag to get
5751 $$END
5752 */
5753 bool aMissionGetLevelFlag(int flagnum) {
5754 //!!Add code here
5755
5756 return 0;
5757 }
5758
5759 /*
5760 $$QUERY
5761 Objects
5762 f:Object [o:Object] animation frame
5763 qObjAnimFrame
5764 Object animation frame
5765 Get an object's animation frame
5766
5767 Parameters:
5768 Object: the object whose animation frame is being queried
5769 $$END
5770 */
5771 float qObjAnimFrame(int objref) {
5772 float anim_frame;
5773
5774 Obj_Value(objref, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame);
5775
5776 return anim_frame;
5777 }
5778
5779 /*
5780 $$QUERY
5781 Rooms
5782 b:Room [r:Room] fog is on
5783 qRoomFogOn
5784 Room fog is on
5785 Checks if the fog is on in a room
5786
5787 Parameters:
5788 Room: the room to check
5789 $$END
5790 */
5791 bool qRoomFogOn(int roomnum) {
5792 msafe_struct mstruct;
5793
5794 mstruct.roomnum = roomnum;
5795
5796 MSafe_GetValue(MSAFE_ROOM_FOG_STATE, &mstruct);
5797
5798 return mstruct.state;
5799 }
5800
5801 /*
5802 $$ACTION
5803 Players
5804 [e:Enable/Disable] player controls [g:PlayerControl] for [o:PlayerObject]
5805 aTogglePlayerObjControl
5806 TogglePlayerControl
5807 Sets a players control either disabled or enabled
5808
5809 Parameters:
5810 Object: The player object
5811 PlayerObject: The player this affects
5812 Enable/Disable: Whether to Enable or Disable the specified controls
5813 $$END
5814 */
5815 void aTogglePlayerObjControl(int enable, int controlmask, int objhandle) {
5816 msafe_struct mstruct;
5817
5818 mstruct.objhandle = objhandle;
5819 mstruct.control_mask = controlmask;
5820 mstruct.control_val = enable;
5821
5822 MSafe_CallFunction(MSAFE_OBJECT_PLAYER_CMASK, &mstruct);
5823 }
5824
5825 /*
5826 $$ACTION
5827 Players
5828 [e:Enable/Disable] all player control for [o:PlayerObject]
5829 aTogglePlayerObjAllControls
5830 ToggleAllPlayerControls
5831 Sets a players control either disabled or enabled
5832
5833 Parameters:
5834 Enable/Disable: Enable/Disable the specified control
5835 PlayerObject: The player this affects
5836 $$END
5837 */
5838 void aTogglePlayerObjAllControls(int enable, int objhandle) {
5839 msafe_struct mstruct;
5840 int controlbit = 0xffffffff;
5841 mstruct.objhandle = objhandle;
5842 mstruct.control_mask = controlbit;
5843 mstruct.control_val = enable ? 1 : 0;
5844
5845 MSafe_CallFunction(MSAFE_OBJECT_PLAYER_CMASK, &mstruct);
5846 }
5847
5848 /*
5849 $$ACTION
5850 Players
5851 Give player [o:PlayerObject] key [o:KeyObject], key number [i:KeyNum=1:1|8], name = [s:KeyName], show HUD message =
5852 [e:Yes/No] aObjectPlayerGiveKey Give player key Gives a player the specified key, and deletes the key object if not
5853 multiplayer
5854
5855 Parameters:
5856 PlayerObject: The player who gets the key
5857 KeyObject: the object that is the key
5858 KeyNum: which key this is (1-8)
5859 KeyName: the name of this key (shown in inventory & on HUD)
5860 Yes/No: should the name of the key be shown on the HUD?
5861 $$END
5862 */
5863 void aObjectPlayerGiveKey(int player_handle, int key_handle, int key_num, const char *key_name, int show_on_hud) {
5864 msafe_struct mstruct;
5865
5866 mstruct.objhandle = key_handle;
5867 mstruct.ithandle = player_handle;
5868 mstruct.index = key_num;
5869
5870 strncpy(mstruct.message, key_name, sizeof(mstruct.message) - 1);
5871 mstruct.message[sizeof(mstruct.message) - 1] = 0;
5872
5873 MSafe_CallFunction(MSAFE_OBJECT_PLAYER_KEY, &mstruct);
5874
5875 if (show_on_hud)
5876 aShowHUDMessage(key_name);
5877 }
5878
5879 /*
5880 $$ACTION
5881 Players
5882 Give player [o:PlayerObject] invisible key number [i:KeyNum=1:1|8]
5883 aObjectPlayerGiveInvisibleKey
5884 Give player key
5885 Gives a player the specified key, which doesn't show up on the HUD or in the inventory
5886
5887 Parameters:
5888 PlayerObject: The player who gets the key
5889 KeyNum: which key this is (1-8)
5890 $$END
5891 */
5892 void aObjectPlayerGiveInvisibleKey(int player_handle, int key_num) {
5893 msafe_struct mstruct;
5894
5895 mstruct.objhandle = OBJECT_HANDLE_NONE;
5896 mstruct.ithandle = player_handle;
5897 mstruct.index = key_num;
5898 mstruct.message[0] = 0; // don't think this is used, but just in case
5899
5900 MSafe_CallFunction(MSAFE_OBJECT_PLAYER_KEY, &mstruct);
5901 }
5902
5903 /*
5904 $$QUERY
5905 Objects
5906 f:Object [o:Object] lighting distance
5907 qObjGetLightingDist
5908 Get object lighting distance
5909 Gets the lighting distance for an object
5910
5911 Parameters:
5912 Object: the object to get
5913 $$END
5914 */
5915 float qObjGetLightingDist(int objhandle) {
5916 msafe_struct mstruct;
5917
5918 mstruct.objhandle = objhandle;
5919
5920 MSafe_GetValue(MSAFE_OBJECT_LIGHT_DIST, &mstruct);
5921
5922 return mstruct.light_distance;
5923 }
5924
5925 /*
5926 $$QUERY
5927 Math
5928 f:[f:Float1] plus [f:Float2]
5929 qMathAddFloat
5930 Add floats
5931 Adds two floating-point numbers and returns the result
5932
5933 Parameters:
5934 Float1, Float2: the numbers to add
5935 $$END
5936 */
5937 float qMathAddFloat(float f0, float f1) { return f0 + f1; }
5938
5939 /*
5940 $$QUERY
5941 Math
5942 f:[f:Float1] minus [f:Float2]
5943 qMathSubFloat
5944 Subtract floats
5945 Subtracts one floating-point number from another
5946
5947 Parameters:
5948 Float1, Float2: subtracts Float2 from Float1
5949 $$END
5950 */
5951 float qMathSubFloat(float f0, float f1) { return f0 - f1; }
5952
5953 /*
5954 $$QUERY
5955 Math
5956 f:[f:Float1] times [f:Float2]
5957 qMathMulFloat
5958 Multiply floats
5959 Multiplies two floating-point numbers and returns the result
5960
5961 Parameters:
5962 Float1, Float2: the numbers to multiply
5963 $$END
5964 */
5965 float qMathMulFloat(float f0, float f1) { return f0 * f1; }
5966
5967 /*
5968 $$QUERY
5969 Math
5970 f:Convert int [i:Int] to float
5971 qMathIntToFloat
5972 Convert Int to Float
5973 Converts an integer value to a floating-point value
5974
5975 Parameters:
5976 Int: the interger that's converted to a float
5977 $$END
5978 */
5979 float qMathIntToFloat(int i) { return (float)i; }
5980
5981 /*
5982 $$QUERY
5983 Math
5984 p:[p:Percent1] plus [p:Percent2]
5985 qMathAddPercent
5986 Add percentages
5987 Adds two percentages and returns the result, without going above 100%
5988
5989 Parameters:
5990 Percent1, Percent2: the percentages to add
5991 $$END
5992 */
5993 float qMathAddPercent(float f0, float f1) {
5994 float r = f0 + f1;
5995
5996 return (r > 1.0) ? 1.0 : r;
5997 }
5998
5999 /*
6000 $$QUERY
6001 Math
6002 p:[p:Percent1] minus [p:Percent2]
6003 qMathSubPercent
6004 Subtract percentages
6005 Subtracts one percentage number from another, withing going below 0%
6006
6007 Parameters:
6008 Percent1, Percent2: subtracts Percent2 from Percent1
6009 $$END
6010 */
6011 float qMathSubPercent(float f0, float f1) {
6012 float r = f0 - f1;
6013
6014 return (r < 0.0) ? 0.0 : r;
6015 }
6016
6017 /*
6018 $$QUERY
6019 Math
6020 i:[i:Integer1] plus [i:Integer2]
6021 qMathAddInt
6022 Add integers
6023 Adds two integer numbers and returns the result
6024
6025 Parameters:
6026 Integer1, Integer2: the numbers to add
6027 $$END
6028 */
6029 int qMathAddInt(int f0, int f1) { return f0 + f1; }
6030
6031 /*
6032 $$QUERY
6033 Math
6034 i:[i:Integer1] minus [i:Integer2]
6035 qMathSubInt
6036 Subtract integers
6037 Subtracts one integer number from another
6038
6039 Parameters:
6040 Integer1, Integer2: subtracts Integer2 from Integer1
6041 $$END
6042 */
6043 int qMathSubInt(int f0, int f1) { return f0 - f1; }
6044
6045 /*
6046 $$QUERY
6047 Math
6048 f:[p:Percent] of [f:Float]
6049 qMathPercentage
6050 Percentage of a number
6051 Multiplies a number by a percentage
6052
6053 Parameters:
6054 Percent: how much to scale the number by
6055 Float: the number that's scaled
6056 $$END
6057 */
6058 float qMathPercentage(float f0, float f1) { return f0 * f1; }
6059
6060 #include <math.h>
6061
6062 /*
6063 $$QUERY
6064 Objects
6065 f:Distance between [o:Object1] and [o:Object2]
6066 qObjGetDistance
6067 Distance between two objects
6068 Gets the distance between two objects
6069
6070 Parameters:
6071 Object1, Object2: the two objects
6072 $$END
6073 */
6074 float qObjGetDistance(int objhandle0, int objhandle1) {
6075 msafe_struct mstruct;
6076 vector p0;
6077
6078 mstruct.objhandle = objhandle0;
6079 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6080 p0 = mstruct.pos;
6081
6082 mstruct.objhandle = objhandle1;
6083 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6084
6085 return vm_VectorDistance(&p0, &mstruct.pos);
6086 }
6087
6088 /*
6089 $$QUERY
6090 Rooms
6091 b:Forcefield at portal [i:PortalNum] in room [r:Room] is on
6092 qPortalIsOn
6093 Forcefield is on
6094 Checks whether a forcefield is on
6095
6096 Parameters:
6097 Room: The room the forcefield is in
6098 PortalNum: The portal number of the forcefield
6099 $$END
6100 */
6101 bool qPortalIsOn(int portalnum, int roomnum) {
6102 msafe_struct mstruct;
6103
6104 mstruct.roomnum = roomnum;
6105 mstruct.portalnum = portalnum;
6106
6107 MSafe_GetValue(MSAFE_ROOM_PORTAL_RENDER, &mstruct);
6108
6109 return mstruct.state;
6110 }
6111
6112 /*
6113 $$QUERY
6114 Misc
6115 b:Random chance of [p:Probability]
6116 qRandomChance
6117 Random Chance
6118 Determines whether a random event should happen. Returns true the portion of the time specified.
6119
6120 Parameters:
6121 Probablilty: how likely this query is to return true.
6122 $$END
6123 */
6124 bool qRandomChance(float prob) {
6125 if (prob == 0.0)
6126 return false;
6127
6128 return ((static_cast<float>(rand()) / static_cast<float>(RAND_MAX)) <= prob);
6129 }
6130
6131 /*
6132 $$QUERY
6133 Math
6134 f:Random value between [f:LowerLimit] and [f:UpperLimit]
6135 qRandomValue
6136 Random Value
6137 Returns a random value between the two specified values
6138
6139 Parameters:
6140 LowerLimit: the returned value will be higher than or equal to this value
6141 UpperLimit: the returned value will be lower than or equal to this value
6142 $$END
6143 */
6144 float qRandomValue(float low, float high) { return low + (static_cast<float>(rand()) / static_cast<float>(RAND_MAX)) * (high - low); }
6145
6146 /*
6147 $$QUERY
6148 Objects
6149 b:Player is within the [i:Cone=90] degree view cone of [o:Object] at a max distance of [f:Distance]
6150 qObjCanSeePlayer
6151 Can object see a player
6152 Determines if the specified object can see a player
6153
6154 Parameters:
6155 Object: The object doing the looking
6156 Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object
6157 Distance: The player must be within this distance for this query to return true
6158 $$END
6159 */
6160 bool qObjCanSeePlayer(int cone, int handlesrc, float max_distance) {
6161 vector vsource, vtarget, viewvec;
6162 msafe_struct mstruct;
6163
6164 // Get half of the angle that the user specified because they specified a cone, and we want an angle
6165 double cangle = (double)((double)cone / (double)2);
6166 double t = cangle * PI / 180;
6167 double testangle = cos(t);
6168
6169 // Loop though all possible players
6170 for (int p = 0; p < MAX_PLAYERS; p++) {
6171
6172 // Get player position
6173 mstruct.slot = p;
6174 MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct);
6175
6176 // See if this player active
6177 if (mstruct.objhandle == OBJECT_HANDLE_NONE)
6178 continue;
6179
6180 // Get the target position
6181 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6182 vtarget = mstruct.pos;
6183
6184 // Get the viewer position
6185 mstruct.objhandle = handlesrc;
6186 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6187 vsource = mstruct.pos;
6188
6189 // Get the viewer orientation
6190 mstruct.objhandle = handlesrc;
6191 MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct);
6192
6193 // Get the normalized vector from the source to the target
6194 float dist = vm_GetNormalizedDirFast(&viewvec, &vtarget, &vsource);
6195
6196 // Get the angle between the objects
6197 float dot = vm_DotProduct(&viewvec, &mstruct.orient.fvec);
6198
6199 // Check angle and distance
6200 if ((dot > testangle) && (dist < max_distance))
6201 return 1;
6202 }
6203
6204 // Didn't find any in the view cone
6205 return 0;
6206 }
6207
6208 /*
6209 $$QUERY
6210 Objects
6211 b:Player is within the [i:Cone=90] degree view cone of [o:Object] at a max distance of [f:Distance] using flags
6212 [g:FVIHitFlags=1048585:16269119] qObjCanSeePlayerAdvanced Can object see a player Determines if the specified object can
6213 see a player (but allowing some customizability as to what the object can see through)
6214
6215 Parameters:
6216 Object: The object doing the looking
6217 Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object
6218 Distance: The player must be within this distance for this query to return true
6219 FVIHitFlags: Flags used to determine visibility
6220 $$END
6221 */
6222 bool qObjCanSeePlayerAdvanced(int cone, int handlesrc, float max_distance, int fvi_flags) {
6223 vector vsource, vtarget, viewvec;
6224 msafe_struct mstruct;
6225 matrix orient;
6226 int sourceroom;
6227
6228 // Get half of the angle that the user specified because they specified a cone, and we want an angle
6229 double cangle = (double)((double)cone / (double)2);
6230 double t = cangle * PI / 180;
6231 double testangle = cos(t);
6232
6233 // Get the viewer position
6234 mstruct.objhandle = handlesrc;
6235 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6236 vsource = mstruct.pos;
6237
6238 // Get the viewer orientation
6239 MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct);
6240 orient = mstruct.orient;
6241
6242 // Get the viewer room
6243 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
6244 sourceroom = mstruct.roomnum;
6245
6246 // Loop though all possible players
6247 for (int p = 0; p < MAX_PLAYERS; p++) {
6248
6249 // Get player position
6250 mstruct.slot = p;
6251 MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct);
6252
6253 // See if this player active
6254 if (mstruct.objhandle == OBJECT_HANDLE_NONE)
6255 continue;
6256
6257 // Get the target position
6258 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6259 vtarget = mstruct.pos;
6260
6261 // Get the normalized vector from the source to the target
6262 float dist = vm_GetNormalizedDirFast(&viewvec, &vtarget, &vsource);
6263
6264 // Get the angle between the objects
6265 float dot = vm_DotProduct(&viewvec, &orient.fvec);
6266
6267 // Check angle and distance
6268 if ((dot > testangle) && (dist < max_distance)) {
6269 // see if we can cast a ray to the player
6270 ray_info ray;
6271 fvi_flags |= (FQ_CHECK_OBJS | FQ_ONLY_PLAYER_OBJ);
6272 int fate = FVI_RayCast(handlesrc, &vsource, &vtarget, sourceroom, 0.0f, fvi_flags, &ray);
6273
6274 if (fate == HIT_NONE)
6275 return true;
6276
6277 if (fate == HIT_OBJECT) {
6278 mstruct.objhandle = ray.hit_object;
6279 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
6280 if (mstruct.type == OBJ_PLAYER) {
6281 return 1;
6282 }
6283
6284 return 1;
6285 }
6286 }
6287 }
6288
6289 // Didn't find any in the view cone
6290 return 0;
6291 }
6292
6293 /*
6294 $$QUERY
6295 Objects
6296 b:Player (store in [e:SavedObjectSlot]) is within the [i:Cone=90] degree view cone of [o:Object] at a max distance of
6297 [f:Distance] using flags [g:FVIHitFlags=1048585:16269119] qObjCanSeePlayerAdvancedWithStore Can object see a player
6298 Determines if the specified object can see a player (but allowing some customizability as to what the object can see
6299 through), and if the player can be seen, stores the object in the given object slot.
6300
6301 Parameters:
6302 SavedObjectSlot: the slot to save the seen player object in
6303 Object: The object doing the looking
6304 Cone: Angle between 0-360 which makes the viewcone that determines if the object can see the other object
6305 Distance: The player must be within this distance for this query to return true
6306 FVIHitFlags: Flags used to determine visibility
6307 $$END
6308 */
6309 bool qObjCanSeePlayerAdvancedWithStore(int slot, int cone, int handlesrc, float max_distance, int fvi_flags) {
6310 vector vsource, vtarget, viewvec;
6311 msafe_struct mstruct;
6312 matrix orient;
6313 int sourceroom;
6314
6315 // Get half of the angle that the user specified because they specified a cone, and we want an angle
6316 double cangle = (double)((double)cone / (double)2);
6317 double t = cangle * PI / 180;
6318 double testangle = cos(t);
6319
6320 // Get the viewer position
6321 mstruct.objhandle = handlesrc;
6322 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6323 vsource = mstruct.pos;
6324
6325 // Get the viewer orientation
6326 MSafe_GetValue(MSAFE_OBJECT_ORIENT, &mstruct);
6327 orient = mstruct.orient;
6328
6329 // Get the viewer room
6330 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &mstruct);
6331 sourceroom = mstruct.roomnum;
6332
6333 // Loop though all possible players
6334 for (int p = 0; p < MAX_PLAYERS; p++) {
6335
6336 // Get player position
6337 mstruct.slot = p;
6338 MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct);
6339
6340 // See if this player active
6341 if (mstruct.objhandle == OBJECT_HANDLE_NONE)
6342 continue;
6343
6344 // Get the target position
6345 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6346 vtarget = mstruct.pos;
6347
6348 // Get the normalized vector from the source to the target
6349 float dist = vm_GetNormalizedDirFast(&viewvec, &vtarget, &vsource);
6350
6351 // Get the angle between the objects
6352 float dot = vm_DotProduct(&viewvec, &orient.fvec);
6353
6354 // Check angle and distance
6355 if ((dot > testangle) && (dist < max_distance)) {
6356 // see if we can cast a ray to the player
6357 ray_info ray;
6358 fvi_flags |= (FQ_CHECK_OBJS | FQ_ONLY_PLAYER_OBJ);
6359 int fate = FVI_RayCast(handlesrc, &vsource, &vtarget, sourceroom, 0.0f, fvi_flags, &ray);
6360
6361 if (fate == HIT_NONE) {
6362 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
6363 Saved_object_handles[slot] = mstruct.objhandle;
6364 return true;
6365 }
6366
6367 if (fate == HIT_OBJECT) {
6368 mstruct.objhandle = ray.hit_object;
6369 MSafe_GetValue(MSAFE_OBJECT_TYPE, &mstruct);
6370 if (mstruct.type == OBJ_PLAYER) {
6371 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
6372 Saved_object_handles[slot] = mstruct.objhandle;
6373 return 1;
6374 }
6375
6376 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
6377 Saved_object_handles[slot] = mstruct.objhandle;
6378
6379 return 1;
6380 }
6381 }
6382 }
6383
6384 // Didn't find any in the view cone
6385 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
6386 Saved_object_handles[slot] = OBJECT_HANDLE_NONE;
6387
6388 return 0;
6389 }
6390
6391 /*
6392 $$QUERY
6393 Rooms
6394 b:A player is in room [r:Room]
6395 qRoomHasPlayer
6396 A player is in the room
6397 Determines if a player is in the specified room
6398
6399 Parameters:
6400 Room: the room to check
6401 $$END
6402 */
6403 bool qRoomHasPlayer(int roomnum) {
6404 msafe_struct mstruct;
6405
6406 mstruct.roomnum = roomnum;
6407 MSafe_GetValue(MSAFE_ROOM_HAS_PLAYER, &mstruct);
6408
6409 return mstruct.state;
6410 }
6411
6412 /*
6413 $$QUERY
6414 Mission
6415 b:Is the ship [a:Ship] enabled?
6416 qIsShipEnabled
6417 Given the name of a ship, it will return true
6418 if the ship is allowed to be chosen in the single player
6419 ship selection.
6420
6421 Parameters:
6422 Ship: The name of the ship you want to query
6423 $$END
6424 */
6425 bool qIsShipEnabled(const char *Ship) { return Game_IsShipEnabled(Ship); }
6426
6427 /*
6428 $$QUERY
6429 Rooms
6430 f:Room [r:Room] damage
6431 qRoomGetDamage
6432 Get room damage
6433 Returns the current damage setting for the specified room
6434
6435 Parameters:
6436 Room: The room for which the damage is returned
6437 $$END
6438 */
6439 float qRoomGetDamage(int roomnum) {
6440 msafe_struct mstruct;
6441
6442 mstruct.roomnum = roomnum;
6443
6444 MSafe_GetValue(MSAFE_ROOM_DAMAGE, &mstruct);
6445
6446 return mstruct.amount;
6447 }
6448
6449 /*
6450 $$QUERY
6451 Objects
6452 o:Saved object handle [e:SavedObjectSlot]
6453 qObjSavedHandle
6454 Saved object handle
6455 Returns the object handle saved in the specified slot
6456
6457 Parameters:
6458 HandleSlot: the slot for which the object handle is returned
6459 $$END
6460 */
6461 int qObjSavedHandle(int slot) {
6462 if ((slot >= 0) && (slot < MAX_SAVED_OBJECT_HANDLES))
6463 return Saved_object_handles[slot];
6464 else
6465 return OBJECT_HANDLE_NONE;
6466 }
6467
6468 /*
6469 $$QUERY
6470 Triggers
6471 Trigger [t:Trigger] state
6472 qTriggerGetState
6473 Get the enabled/disabled state of a trigger
6474 Determines if a trigger is enabled or disabled
6475
6476 Parameters:
6477 Trigger: which trigger to check
6478 $$END
6479 */
6480 bool qTriggerGetState(int trigger_num) {
6481 msafe_struct mstruct;
6482
6483 mstruct.trigger_num = trigger_num;
6484 MSafe_GetValue(MSAFE_TRIGGER_SET, &mstruct);
6485
6486 return mstruct.state;
6487 }
6488
6489 /*
6490 $$QUERY
6491 Objects
6492 i:Number of [e:ObjectType] objects of ID = [a:ObjectIDName] in mine
6493 qObjCountTypeID
6494 Get number of objects of a certain type
6495 Counts the number of objects of the specified type
6496
6497 Parameters:
6498 ObjectType: the type of the objects to count
6499 ObjectIDName: the name of the object ID to count
6500 $$END
6501 */
6502 int qObjCountTypeID(int type, const char *idname) {
6503 int id = Obj_FindID(idname);
6504
6505 if (id != -1) {
6506 msafe_struct mstruct;
6507
6508 mstruct.type = type;
6509 mstruct.id = id;
6510
6511 MSafe_GetValue(MSAFE_OBJECT_COUNT_TYPE, &mstruct);
6512
6513 return mstruct.count;
6514 } else
6515 return 0;
6516 }
6517
6518 /*
6519 $$ACTION
6520 Misc
6521 Show HUD message [s:Message] [f:Float]
6522 aShowHUDMessageF
6523 Show HUD message
6524 Shows a HUD message for all players with a float parameter
6525
6526 Parameters:
6527 Message: The message to show, with %f marking where the number should go
6528 $$END
6529 */
6530 #define aShowHUDMessageF aShowHUDMessage
6531
6532 /*
6533 $$ACTION
6534 Misc
6535 Show HUD message [s:Message] for player [o:PlayerObject=IT] with parm [f:Float]
6536 aShowHUDMessageObjF
6537 Show HUD message to one player
6538 Shows a HUD message for one players with a float parameter
6539
6540 Parameters:
6541 Message: The message to show, with %f marking where the number should go
6542 PlayerObject: the player who sees the message
6543 Float: the number to show
6544 $$END
6545 */
6546 #define aShowHUDMessageObjF aShowHUDMessageObj
6547
6548 /*
6549 $$ACTION
6550 Misc
6551 Show HUD message [s:Message] [i:Integer]
6552 aShowHUDMessageI
6553 Show HUD message
6554 Shows a HUD message for all players with an integer parameter
6555
6556 Parameters:
6557 Message: The message to show, with %d marking where the number should go
6558 $$END
6559 */
6560 #define aShowHUDMessageI aShowHUDMessage
6561
6562 /*
6563 $$QUERY
6564 Level Goals
6565 b:All Primary Objectives Complete
6566 qGoalPrimariesComplete
6567 All Primary Objective Complete
6568 Determines if all primary objectives are complete
6569
6570 Parameters:
6571 None.
6572 $$END
6573 */
6574 bool qGoalPrimariesComplete() {
6575 int flags = LF_ALL_PRIMARIES_DONE;
6576
6577 LGoal_Value(VF_GET, LGV_I_STATUS, &flags);
6578
6579 return (flags != 0);
6580 }
6581
6582 /*
6583 $$QUERY
6584 Level Goals
6585 b:Goal [l:LevelGoal] is enabled
6586 qGoalEnabled
6587 Goal is enabled
6588 Determines if the specified goal is enabled
6589
6590 Parameters:
6591 LevelGoal: the goal to check
6592 $$END
6593 */
6594 bool qGoalEnabled(int goal_index) {
6595 int flags;
6596
6597 LGoal_Value(VF_GET, LGSV_I_STATUS, &flags, goal_index);
6598
6599 return ((flags & LGF_ENABLED) != 0);
6600 }
6601
6602 /*
6603 $$QUERY
6604 Level Goals
6605 b:Goal [l:LevelGoal] is complete
6606 qGoalCompleted
6607 Goal is enabled
6608 Determines if the specified goal is complete
6609
6610 Parameters:
6611 LevelGoal: the goal to check
6612 $$END
6613 */
6614 bool qGoalCompleted(int goal_index) {
6615 int flags;
6616
6617 LGoal_Value(VF_GET, LGSV_I_STATUS, &flags, goal_index);
6618
6619 return ((flags & LGF_COMPLETED) != 0);
6620 }
6621
6622 /*
6623 $$QUERY
6624 Level Goals
6625 b:Goal [l:LevelGoal] is failed
6626 qGoalFailed
6627 Goal is failed
6628 Determines if the specified goal is failed
6629
6630 Parameters:
6631 LevelGoal: the goal to check
6632 $$END
6633 */
6634 bool qGoalFailed(int goal_index) {
6635 int flags;
6636
6637 LGoal_Value(VF_GET, LGSV_I_STATUS, &flags, goal_index);
6638
6639 return ((flags & LGF_FAILED) != 0);
6640 }
6641
6642 /*
6643 $$QUERY
6644 Players
6645 o:Closest player to [o:Object]. Store dist in user var [e:UserVar].
6646 qPlayerClosest
6647 Closest player
6648 Find the closest player to the specified object
6649
6650 Parameters:
6651 Object: the object to check players against
6652 $$END
6653 */
6654 int qPlayerClosest(int objhandle, int varnum) {
6655 vector objpos;
6656 float closest_dist = FLT_MAX;
6657 int closest_player = OBJECT_HANDLE_NONE;
6658 msafe_struct mstruct;
6659
6660 // Get the object position
6661 mstruct.objhandle = objhandle;
6662 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6663 objpos = mstruct.pos;
6664
6665 // Loop though all possible players and compute distance
6666 for (int p = 0; p < MAX_PLAYERS; p++) {
6667
6668 // Get player position
6669 mstruct.slot = p;
6670 MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct);
6671
6672 // See if this player active
6673 if (mstruct.objhandle == OBJECT_HANDLE_NONE)
6674 continue;
6675
6676 // Get the target position
6677 MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct);
6678
6679 // Get the normalized vector from the source to the target
6680 float dist = vm_VectorDistanceQuick(&objpos, &mstruct.pos);
6681
6682 if (dist < closest_dist) {
6683 closest_dist = dist;
6684 closest_player = mstruct.objhandle;
6685 }
6686 }
6687
6688 if ((varnum >= 0) && (varnum < MAX_USER_VARS))
6689 User_vars[varnum] = closest_dist;
6690
6691 return closest_player;
6692 }
6693
6694 /*
6695 $$QUERY
6696 Objects
6697 f:[o:WeaponObject=IT] damage
6698 qObjDamage
6699 Object damage
6700 Returns the amount of damage the given weapon object does
6701
6702 Parameters:
6703 WeaponObject: The weapon object whose damage it returned
6704 $$END
6705 */
6706 float qObjDamage(int handle) {
6707 msafe_struct mstruct;
6708
6709 mstruct.objhandle = handle;
6710 MSafe_GetValue(MSAFE_OBJECT_DAMAGE_AMOUNT, &mstruct);
6711
6712 return mstruct.amount;
6713 }
6714
6715 /*
6716 $$QUERY
6717 Misc
6718 f:Frametime
6719 qFrametime
6720 Game Frametime
6721 Returns the frametime
6722
6723 Parameters:
6724 None
6725 $$END
6726 */
6727 float qFrametime() { return Game_GetFrameTime(); }
6728
6729 /*
6730 $$QUERY
6731 AI
6732 f:[o:Object] max speed
6733 qAIQueryMaxSpeed
6734
6735 Parameters:
6736 Object: Get object's max speed.
6737 $$END
6738 */
6739 float qAIQueryMaxSpeed(int objhandle) {
6740 float max_speed = 0.0f;
6741 AI_Value(objhandle, VF_GET, AIV_F_MAX_SPEED, &max_speed);
6742 return max_speed;
6743 }