Debian Codegraph @

Descent3/multisafe.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/Main/multisafe.cpp $
21 * $Revision: 210 $
22 * $Date: 9/13/01 11:38a $
23 * $Author: Matt $
24 *
25 * Multiplayer safe code
26 *
27 * $Log: /DescentIII/Main/multisafe.cpp $
28 *
29 * 210 9/13/01 11:38a Matt
30 * Made the get-player-objhandle function not return the handle for
31 * players in observer mode.
32 *
33 * 209 4/19/00 5:07p Matt
34 * From Duane for 1.4
35 * Added checks, asserts, and fixes for bad return values
36 *
37 * 208 11/03/99 8:47p Chris
38 * Improved the auto-select algorithm for dual fire secondary weapons
39 *
40 * 207 11/03/99 6:29p Chris
41 * Improved the auto-selection code for dual fire secondary weapons
42 *
43 * 206 10/20/99 5:41p Chris
44 * Added Red GB
45 *
46 * 205 10/20/99 4:08p 3dsmax
47 * don't delete invisible powerup when deleting powerups from room
48 *
49 * 204 10/16/99 8:45p Jeff
50 * multisafe function to remove all powerups from a room
51 *
52 * 203 7/28/99 3:54p Kevin
53 * MAC
54 *
55 * 202 5/26/99 2:05a Jason
56 * fixed world position bug
57 *
58 * 201 5/23/99 9:07p Matt
59 * Changed the customtext2 multisafe functions to create the item when
60 * it's updated, instead of having a separate create and update functions.
61 * This deals with players who join a netgame after the level has started
62 * (i.e., everyone but the server).
63 *
64 * 200 5/23/99 5:58p Jason
65 * don't send rotational drag to clients
66 *
67 * 199 5/23/99 5:50p Chris
68 * Fixed problems with msafe send on over non-changed information
69 *
70 * 198 5/23/99 12:33a Chris
71 * Cannot change the control type of dying objects
72 *
73 * 197 5/22/99 12:33a Jason
74 * added sending of physics flags upon joining
75 *
76 * 196 5/21/99 4:06p Matt
77 * For customtext2 HUD items, store the buffer length in the HUD item.
78 *
79 * 195 5/21/99 3:06p Matt
80 * Changed customtext2 HUD items so that the HUD system keeps the text
81 * buffer an no one else references it directly.
82 *
83 * 194 5/20/99 5:49p Matt
84 * Added a HUD item flag, for use by Dallas-created items, that makes a
85 * HUD item persisitent for the duration of one level, but get cleared
86 * between levels.
87 *
88 * 193 5/20/99 4:12p Jeff
89 * fixed up add to inventory
90 *
91 * 192 5/20/99 2:48a Matt
92 * Changed stat type for timer & custom HUD messages.
93 *
94 * 191 5/19/99 4:23p Chris
95 * Fixed level goal problems with keys and persistant inventory items
96 *
97 * 190 5/19/99 4:01p Jason
98 * handle robot firing
99 *
100 * 189 5/19/99 12:12p Jason
101 * fixed some issues with multiplayer
102 *
103 * 188 5/19/99 11:26a Matt
104 * Added multisafe functions & Dallas actions for showing a timer on the
105 * screen and adding custom HUD messages.
106 *
107 * 187 5/18/99 6:09p Kevin
108 * for Jeff. fixed crash in multiplayer
109 *
110 * 186 5/17/99 6:22p Jeff
111 * added filtered HUD messages
112 *
113 * 185 5/17/99 4:09p Jeff
114 * fixed secondary autoselect if the thief steals your currently selected
115 * secondary and you have no more
116 *
117 * 184 5/11/99 11:49a Matt
118 * Added the ability to specify a name when adding an item to the
119 * inventory.
120 *
121 * 183 5/10/99 10:23p Ardussi
122 * changes to compile on Mac
123 *
124 * 182 5/10/99 2:37a Jason
125 * fixed potential crash bug with lightning effects
126 *
127 * 181 5/09/99 10:49p Jason
128 * fix string chopping in multiplayer games
129 *
130 * 180 5/08/99 4:06p Matt
131 * Made Guidebot name translation work for game messages.
132 *
133 * 179 5/07/99 11:55p Matt
134 * Made player key action work if passed a player weapon or a player.
135 *
136 * 178 5/07/99 10:57p Chris
137 * Added a spew uvec dir
138 *
139 * 177 5/07/99 10:49p Matt
140 * For GB HUD messages, only make the sound if the message is actually
141 * added (i.e., if it isn't the same as the last message).
142 *
143 * 176 5/07/99 1:32p Jeff
144 * made osipf for sounds multisafe
145 *
146 * 175 5/06/99 12:52p Jason
147 * fixed set on fire bug
148 *
149 * 174 5/06/99 5:44a Chris
150 * Exclude GBs from the delete robot lists
151 *
152 * 173 5/06/99 4:11a Jeff
153 * created multisafe function to destroy robots in the level (helps boss
154 * fights)
155 *
156 * 172 5/05/99 12:55a Chris
157 * Setting a dead object's shields makes it no longer OF_AI_DEATH
158 *
159 * 171 5/04/99 12:13p Matt
160 * Renamed fire-flare symbol to fire-weapon.
161 *
162 * 170 5/04/99 1:04a Matt
163 * Turned fire flare function into fire weapon, though I haven't yet
164 * actually changed the name.
165 *
166 * 169 5/02/99 5:09a Jeff
167 * send levelgoal state to joining clients
168 *
169 * 168 5/02/99 1:36a Jason
170 * added moving object lighting viseffects
171 *
172 * 167 5/01/99 1:41a Jeff
173 * made levelgoals multi friendly
174 *
175 * 166 4/30/99 4:32p Matt
176 * Added a Dallas action to fire a flare from an object.
177 *
178 * 165 4/29/99 7:21p Jason
179 * fixed some wacky spew issues
180 *
181 * 164 4/29/99 1:28p Jeff
182 * fixed errant hud messages being displayed for wrong people
183 *
184 * 163 4/29/99 2:01a Chris
185 * Added the portal blockage support
186 *
187 * 162 4/28/99 9:49p Jeff
188 * handle player or player weapon types
189 *
190 * 161 4/27/99 9:20p Jason
191 * fixed key spewing
192 *
193 * 160 4/27/99 4:43a Jeff
194 * added multisafe function for setting/getting guidebot name, fixed msafe
195 * object flag set for clients
196 *
197 * 159 4/26/99 11:46p Matt
198 * Don't give the player a key if he's already got it.
199 *
200 * 158 4/26/99 8:16p Jason
201 * added sparks type
202 *
203 * 157 4/26/99 11:14a Jason
204 * more levelgoal work for Chris
205 *
206 * 156 4/26/99 4:27a Jeff
207 * added multisafe functions to check a player's weapons, and add/remove
208 * weapons from a player
209 *
210 * 155 4/25/99 10:13p Matt
211 * Added code to scan HUD messages for messages from the Guide-Bot, and
212 * print them using the GB message format.
213 *
214 * 154 4/24/99 6:45p Jeff
215 * added functions for theif so he can steal things other than weapons
216 *
217 * 153 4/23/99 11:00p Jeff
218 * added Afterburner HUD name
219 *
220 * 152 4/22/99 7:12p Jeff
221 * don't send object remove (it calls MultiSendRemoveObject)
222 *
223 * 151 4/22/99 4:44p Jason
224 * fixed level goal stuff for multiplayer
225 *
226 * 150 4/22/99 3:43p Kevin
227 * Training missions show controls on screen
228 *
229 * 149 4/22/99 3:24p Jason
230 * fixed some multisafe problems
231 *
232 * 148 4/20/99 7:29p Jeff
233 * difficulty based shields & energy
234 *
235 * 147 4/20/99 6:55p Matt
236 * Added code to keep a bitmask of all keys held by all players, and to
237 * allow a robot to open a door if any player has the key(s) for that
238 * door.
239 *
240 * 146 4/18/99 3:06p Jason
241 * fixed printing of hud message on the wrong players machine
242 *
243 * 145 4/17/99 3:45p Matt
244 * Add keys to the player's inventory.
245 *
246 * 144 4/14/99 11:54a Jason
247 * added message in multipay
248 *
249 * 143 4/14/99 3:56a Jeff
250 * fixed case mismatch in #includes
251 *
252 * 142 4/12/99 6:15p Samir
253 * Sound priorities pass 1
254 *
255 * 141 4/11/99 6:44p Matt
256 * Moved/renamed some text symbols that were in multisafe but belonged in
257 * stringtable
258 *
259 * 140 4/07/99 12:30p Matt
260 * Added code for failed missions.
261 *
262 * 139 4/06/99 11:44p Matt
263 * Added action to create a lighting bolt between two gunpoints on the
264 * same object, and queries to return an object's original shields and to
265 * multiply a percent times a float.
266 *
267 * 138 4/06/99 8:44p Matt
268 * Added a couple actions for Mark's energy/shield collector
269 *
270 * 137 4/06/99 6:24p Jason
271 * various fixes for multiplayer
272 *
273 * 136 4/04/99 6:20p Matt
274 * Added distance-based shake Dallas action.
275 *
276 * 135 4/03/99 5:23p Matt
277 * Removed placeholder code for Possession and Hint Reveal powerups.
278 *
279 * 134 4/03/99 1:13a Jeff
280 * added multisafe/dallas actions to set an object on fire
281 *
282 * 133 4/02/99 10:12p Jeff
283 * made ship permissions multi safe
284 *
285 * 132 4/02/99 9:33p Jeff
286 * added full map
287 *
288 * 131 3/31/99 11:41a Jason
289 * added support for attached thick lightning
290 *
291 * 130 3/30/99 7:26p Chris
292 *
293 * 128 3/29/99 7:30p Jason
294 * added cool new energy effect
295 *
296 * 127 3/28/99 5:56p Matt
297 * Added Dallas action to turn on object sparking
298 *
299 * 126 3/27/99 2:15p Jason
300 * added better thick lightining
301 *
302 * 125 3/26/99 3:25p Jeff
303 * option to display hud message when cloaking
304 *
305 * 124 3/26/99 12:38p Jeff
306 * added cloak predefs
307 *
308 * 123 3/25/99 3:30p Jason
309 * added option to randomize powerup respawn points
310 *
311 * 122 3/24/99 6:02p Jason
312 * fixed size for thick lightning
313 *
314 * 121 3/24/99 10:02a Matt
315 * Added Dallas action to set music region for all players
316 *
317 * 120 3/23/99 3:51p Jason
318 * added lightning bolt effect to msafe
319 *
320 * 119 3/22/99 1:59p Matt
321 * Added break glass Dallas action
322 *
323 * 118 3/22/99 11:26a Matt
324 * Changed energy powerup pickup behavior, and added energy full message.
325 *
326 * 117 3/22/99 10:59a Chris
327 * Awareness code was tweaked. Multisafe stuff added for objects.
328 *
329 * 116 3/16/99 6:43p Kevin
330 * OEM Split fixes
331 *
332 * 115 3/12/99 7:50p Jeff
333 * demo record a powerup being set dead if msafe says so
334 *
335 * 114 3/10/99 2:25p Kevin
336 * Save/Load and Demo file fixes
337 *
338 * 113 3/05/99 12:18p Matt
339 * Fixed, I hope, a bunch of ammo and weapon bugs
340 *
341 * 112 3/04/99 8:50p Samir
342 * AddColoredHUDMessage is formatted, so when mulitplayer messages went
343 * out, they would take the % signs and screw up the string. Now it
344 * doesn't.
345 *
346 * 111 3/04/99 7:39p Matt
347 * Added sound effects to FreeSpace-style persistent HUD messages.
348 *
349 * 110 3/04/99 7:01p Matt
350 * Fixed max ammo bug, and took out hack to set max ammo
351 *
352 * 109 3/04/99 6:30p Jason
353 * took out comments
354 *
355 * 108 3/04/99 6:29p Jason
356 * added more multiplayer functionality
357 *
358 * 107 3/04/99 6:04p Matt
359 * Made music region work for the specified object.
360 * Added sound effect & FreeSpace draw to game message.
361 *
362 * 106 3/04/99 3:46p Jason
363 * fixed some multisafe stuff
364 *
365 * 105 3/03/99 5:35p Matt
366 * Added fade-out for goal complete messages
367 *
368 * 104 3/03/99 5:08p Samir
369 * AddWeaponAmmoToPlayer added.
370 *
371 * 103 3/03/99 4:39p Matt
372 * Fixed some prematurely-check-in code.
373 *
374 * 102 3/03/99 3:02p Matt
375 * Added Game Message action in Dallas
376 *
377 * 101 3/02/99 1:31p Matt
378 * Added hack for secondary weapon ammo max not set
379 *
380 * 100 3/02/99 12:22p Matt
381 * Revisions to weapon & ammo powerups. Not fully tested.
382 *
383 * 99 3/01/99 1:09p Matt
384 * Changed validate functions to do an int3 & return nicely rather than
385 * error out
386 *
387 * 98 2/25/99 8:55p Jeff
388 * Inventory supports level change persistant items. Inventory supports
389 * time-out objects. Inventory Reset changed (takes a level of reset
390 * now). Quad lasers stay across level change (single player). Guidebot
391 * bug fixed (now back in ship on level start). Quads time out when
392 * spewed. Invulnerability and cloak powerups no longer use game
393 * event/callbacks, so they can be saved in game saves (moved to
394 * MakePlayerInvulnerable and MakeObjectInvisible)
395 *
396 * 97 2/23/99 7:36p Jeff
397 * handle non-spewing inventory item add
398 *
399 * 96 2/22/99 1:20a Jeff
400 * added support for inventory (simple) in dallas. Moved end-level
401 * sequence to use IGC. Add position clipboard stuff for dallas. Fixed
402 * some inventory bug with storing object handles
403 *
404 * 95 2/21/99 8:36p Jeff
405 * misc changes to handle new matcen and path types of dallas
406 *
407 * 94 2/21/99 5:49p Matt
408 * Added Dallas action to set an object's volume
409 *
410 * 93 2/19/99 7:14p Luke
411 * ghost and unghost dont cause int3s
412 *
413 * 92 2/16/99 6:26p Matt
414 * Fixed bug in get player handle code & cleaned it up a bit besides
415 *
416 * 91 2/15/99 11:09a Matt
417 * Added function to count the number of a certain type of object in the
418 * level. (Also added HUD actions to print an int and float.)
419 *
420 * 90 2/11/99 1:44p Matt
421 * Fixed compile warning
422 *
423 * 89 2/11/99 1:10p Matt
424 * Added functions to get & set a triggers enabled/disabled state
425 *
426 * 88 2/11/99 2:56a Jeff
427 * added multisafe function to set an objects position in the world
428 *
429 * 87 2/10/99 7:14p Jeff
430 * 4 proxmines instead of 1
431 *
432 * 86 2/10/99 6:55p Jeff
433 * added proxmines to the game
434 *
435 * 85 2/10/99 3:48p Jason
436 * table filter changes
437 *
438 * 84 2/10/99 1:47p Matt
439 * Changed object handle symbolic constants
440 *
441 * 83 2/09/99 12:43p Matt
442 * Added function to check for players in a room
443 *
444 * 82 2/09/99 11:57a Jeff
445 * quad fire now goes into your inventory so you spew it
446 *
447 * 81 2/08/99 7:05p Kevin
448 * Trying to get demo system working with powerup scripts
449 *
450 * 80 2/08/99 5:25p Jeff
451 * removed all calls to MultiSendRemoveObject, incorportated into
452 * SetObjectDeadFlag. Fixes sequencing issues in multiplayer
453 *
454 * 79 2/08/99 3:09a Jeff
455 * added a multisafe type to switch a player in and out of ai control mode
456 * (and to get whether a player is in ai mode or not)
457 *
458 * 78 2/06/99 10:03p Matt
459 * Added keys system
460 *
461 * 77 2/06/99 1:52a Matt
462 * Added a bunch of Dallas funcs, mostly for Sean
463 *
464 * 76 2/04/99 12:26p Jason
465 * added spew that was better for multiplayer
466 *
467 * 75 2/03/99 5:49p Matt
468 * Added room damage system
469 *
470 * 74 2/03/99 4:26p Jason
471 * made multiplayer coop actually work!
472 *
473 * 73 2/03/99 12:24a Matt
474 * Got HUD message, 2D sound, streaming sound, and player-is-visible all
475 * working correctly in multiplayer.
476 *
477 * 72 2/02/99 12:43p Kevin
478 * Fixes to the Save/Load game system, and the demo system to work with
479 * the new OSIRIS
480 *
481 * 71 2/01/99 4:17p Jason
482 * more changes for multisafe
483 *
484 * 70 2/01/99 3:47p Jason
485 * added more multisafe functionality
486 *
487 * 69 2/01/99 2:31p Jason
488 * made player handle grabbing more reliable
489 *
490 * 68 2/01/99 1:11p Matt
491 * Changed a bunch of stuff to work with object handles instead of player
492 * numbers. Also fixed the view cone action, which ignored distance.
493 *
494 * 67 1/31/99 11:05p Matt
495 * Added music region set
496 *
497 * 66 1/31/99 8:11p Matt
498 * Added player visible query, and made zoom work with popup cameras.
499 *
500 * 65 1/31/99 7:26p Matt
501 * Renamed a bunch of functions to have HUD capitalized
502 *
503 * 64 1/30/99 3:19p Matt
504 * Made Dallas spews work from object centers in addition to gunpoints
505 *
506 * 63 1/29/99 5:22p Jeff
507 * localization
508 *
509 * 62 1/29/99 3:14p Matt
510 * Deleted some obsolete Dallas actions, and made the player controls
511 * actions take player numbers instead of the player object.
512 *
513 * 61 1/29/99 12:48p Matt
514 * Rewrote the doorway system
515 *
516 * 60 1/26/99 5:16p Matt
517 * Added STOP_SOUND_OBJ
518 *
519 * 59 1/26/99 4:03p Jason
520 * fixed bad object invulnerable code that someone wrote
521 *
522 * 58 1/25/99 7:06p Matt
523 * Ripped out doorway index stuff, since doors are referred to by their
524 * door objects.
525 *
526 * 57 1/25/99 6:30p Matt
527 * Made sound functions take sound num instead of name, and door functions
528 * take object handle instead of doorway index.
529 *
530 * 56 1/23/99 10:10p Kevin
531 * Added the start of osiris support into the demo system
532 *
533 * 55 1/22/99 6:53p Chris
534 * Fixed LoadandBind Aux notify problems, fixed static path problems,
535 * fixed AIF_FORCE_AWARE Problems, improved path code
536 *
537 * 54 1/21/99 11:15p Jeff
538 * pulled out some structs and defines from header files and moved them
539 * into seperate header files so that multiplayer dlls don't require major
540 * game headers, just those new headers. Side effect is a shorter build
541 * time. Also cleaned up some header file #includes that weren't needed.
542 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
543 * manage.h and multi.h
544 *
545 * 53 1/20/99 8:29p Matt
546 * Added a comment block listing what functions have been added or
547 * modified.
548 *
549 * 52 1/20/99 6:26p Matt
550 * Added several actions
551 *
552 * 51 1/20/99 4:33p Jason
553 * added changing wind/fog to msafe
554 *
555 * 50 1/20/99 2:13a Chris
556 * It is now possible for robots to have special immunities, resistances,
557 * and vunerabilities
558 *
559 * 49 1/19/99 10:27p Jeff
560 * in single player, primaries will give you energy if you already have
561 * the weapon
562 *
563 * 48 1/19/99 6:53p Matt
564 * Added some error checking
565 *
566 * 47 1/19/99 6:13p Matt
567 * Added an action & query for lighting distance
568 *
569 * 46 1/19/99 3:43p Kevin
570 * Added msafe functionality to set an object to render type RT_NONE
571 *
572 * 45 1/19/99 12:16p Matt
573 * Added start endlevel sequence action
574 *
575 * 44 1/18/99 7:31p Matt
576 * Added a bunch of Dallas actions
577 *
578 * 43 1/18/99 6:18p Kevin
579 * Added controller masking to DALLAS
580 *
581 * 42 1/18/99 2:46p Matt
582 * Combined flags & flags2 fields in object struct
583 *
584 * 41 1/15/99 10:44a Jason
585 * fixed fog bug
586 *
587 * 40 1/13/99 2:29p Jeff
588 * state is set of the mstruct for when getting a doorway index (if the
589 * door doesn't exist anymore...the object handle)
590 *
591 * 39 1/13/99 12:42p Matt
592 * Added code to close a popup view
593 *
594 * 38 1/11/99 2:14p Chris
595 * Massive work on OSIRIS and AI
596 *
597 * 37 1/11/99 10:43a Matt
598 * Made forcefield on/off/toggle optionally do both sides of a portal
599 *
600 * 36 1/08/99 4:33p Matt
601 * Got popup views working in Dallas
602 *
603 * 35 1/06/99 5:06p Chris
604 * Improving OSIRIS/game intergration - improved support for custom
605 * animations
606 *
607 * 34 1/06/99 4:23p Jeff
608 * added a couple of inventory and counter measure functions
609 *
610 * 33 1/06/99 1:46p Jeff
611 * cloak and invuln put in multisafe
612 *
613 * 32 1/05/99 3:41p Jeff
614 * added spew create and stop functions
615 *
616 * 31 1/05/99 12:42p Jason
617 * fixed missing break
618 *
619 * 30 1/05/99 11:52a Jason
620 * added more msafe functionality
621 *
622 * 29 1/04/99 12:24p Jeff
623 * added invulnerablilty and cloak. FInished up rest of powerups
624 *
625 * 28 12/31/98 7:36p Jeff
626 * correctly hash type/ids for multisafe. Added some new inline functions
627 * to add/get type/id to a packet
628 *
629 * 27 12/30/98 6:05p Jason
630 * added some inventory functions
631 *
632 * 26 12/30/98 2:17p Jason
633 * added MSAFE_DOOR_DOORWAY_INDEX
634 *
635 * 25 12/30/98 1:37p Jason
636 * added waypoint function
637 *
638 * 24 12/30/98 12:09p Jason
639 * added logfile
640 */
641 #include "multisafe.h"
642 #include "weather.h"
643 #include "room.h"
644 #include "game.h"
645 #include "multi.h"
646 #include "damage.h"
647 #include "hud.h"
648 #include "doorway.h"
649 #include "trigger.h"
650 #include "gamepath.h"
651 #include "AIGoal.h"
652 #include "weapon.h"
653 #include "spew.h"
654 #include "hlsoundlib.h"
655 #include "sounds.h"
656 #include "ship.h"
657 #include "player.h"
658 #include "object_lighting.h"
659 #include "soundload.h"
660 #include "streamaudio.h"
661 #include "gamesequence.h"
662 #include "gameevent.h"
663 #include "SmallViews.h"
664 #include "difficulty.h"
665 #include "door.h"
666 #include "demofile.h"
667 #include "stringtable.h"
668 #include "d3music.h"
669 #include "multi_world_state.h"
670 #include "osiris_predefs.h"
671 #include "viseffect.h"
672 #include "levelgoal.h"
673
674 #include <algorithm>
675
676 /*
677 The following functions have been added or modified by Matt and/or someone else other than Jason,
678 and thus Jason should check them out to make sure they're ok for multiplayer.
679
680 */
681 // Returns true if the player has this weapon (this fuction should be moved)
682 bool PlayerHasWeapon(int slot, int weapon_index);
683 int AddWeaponAmmo(int slot, int weap_index, int ammo);
684 void CheckForWeaponSelect(int id, int weapon_index);
685 #define MOBJ (ObjGet(mstruct->objhandle))
686 #define KOBJ (ObjGet(mstruct->killer_handle))
687 #define IOBJ (ObjGet(mstruct->ithandle))
688 // Returns true if the specified room is valid
689 bool VALIDATE_ROOM(int roomnum) {
690
691 bool valid = ((roomnum >= 0) && (roomnum <= Highest_room_index) && Rooms[roomnum].used);
692 if (!valid)
693 Int3();
694 return valid;
695 }
696 // Returns true if the specified room & face are valid
697 bool VALIDATE_ROOM_FACE(int roomnum, int facenum) {
698
699 bool valid = ((roomnum >= 0) && (roomnum <= Highest_room_index) && (Rooms[roomnum].used) && (facenum >= 0) &&
700 (facenum < Rooms[roomnum].num_faces));
701 if (!valid)
702 Int3();
703 return valid;
704 }
705 // Returns true if the specified room & portal are valid
706 bool VALIDATE_ROOM_PORTAL(int roomnum, int portalnum) {
707
708 bool valid = ((roomnum >= 0) && (roomnum <= Highest_room_index) && (Rooms[roomnum].used) && (portalnum >= 0) &&
709 (portalnum < Rooms[roomnum].num_portals));
710 if (!valid)
711 Int3();
712 return valid;
713 }
714 // Returns an object pointer from a handle. Really just ObjGet() with an mprintf()
715 object *VALIDATE_OBJECT(int handle) {
716 object *objp = ObjGet(handle);
717 if (!objp) {
718 mprintf(0, "Invalid object passed to multisafe.\n");
719 }
720 return objp;
721 }
722
723 // Gets a value for the calling party
724 void msafe_GetValue(int type, msafe_struct *mstruct) {
725 object *objp;
726 switch (type) {
727 case MSAFE_SHOW_ENABLED_CONTROLS:
728 objp = ObjGet(mstruct->objhandle);
729 if (objp && (objp->type == OBJ_PLAYER))
730 mstruct->state = Hud_show_controls;
731 else
732 mstruct->state = false;
733 break;
734 break;
735 case MSAFE_OBJECT_PLAYER_CMASK:
736 objp = ObjGet(mstruct->objhandle);
737 if (objp && (objp->type == OBJ_PLAYER))
738 mstruct->control_mask = Players[objp->id].controller_bitflags;
739 else
740 mstruct->control_mask = 0;
741 break;
742 case MSAFE_OBJECT_POS:
743 objp = ObjGet(mstruct->objhandle);
744 if (!objp)
745 mstruct->pos = Zero_vector;
746 else
747 mstruct->pos = objp->pos;
748 break;
749 case MSAFE_OBJECT_ORIENT:
750 objp = ObjGet(mstruct->objhandle);
751 if (!objp)
752 mstruct->orient = Identity_matrix;
753 else
754 mstruct->orient = objp->orient;
755 break;
756 case MSAFE_OBJECT_ROOMNUM:
757 objp = ObjGet(mstruct->objhandle);
758 if (!objp)
759 mstruct->roomnum = -1;
760 else
761 mstruct->roomnum = objp->roomnum;
762 break;
763 case MSAFE_OBJECT_WORLD_POSITION:
764 objp = ObjGet(mstruct->objhandle);
765 if (!objp) {
766 mstruct->pos = Zero_vector;
767 mstruct->orient = Identity_matrix;
768 mstruct->roomnum = -1;
769 } else {
770 mstruct->orient = objp->orient;
771 mstruct->roomnum = objp->roomnum;
772 mstruct->pos = objp->pos;
773 }
774 break;
775 case MSAFE_OBJECT_VELOCITY:
776 objp = ObjGet(mstruct->objhandle);
777 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
778 mstruct->velocity = Zero_vector;
779 else
780 mstruct->velocity = objp->mtype.phys_info.velocity;
781 break;
782 case MSAFE_OBJECT_ROTVELOCITY:
783 objp = ObjGet(mstruct->objhandle);
784 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
785 mstruct->rot_velocity = Zero_vector;
786 else
787 mstruct->rot_velocity = objp->mtype.phys_info.rotvel;
788 break;
789 case MSAFE_OBJECT_THRUST:
790 objp = ObjGet(mstruct->objhandle);
791 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
792 mstruct->thrust = Zero_vector;
793 else
794 mstruct->thrust = objp->mtype.phys_info.thrust;
795 break;
796 case MSAFE_OBJECT_ROTTHRUST:
797 objp = ObjGet(mstruct->objhandle);
798 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
799 mstruct->rot_thrust = Zero_vector;
800 else
801 mstruct->rot_thrust = objp->mtype.phys_info.rotthrust;
802 break;
803 case MSAFE_OBJECT_FLAGS: // Needs to be send
804 objp = ObjGet(mstruct->objhandle);
805 if (!objp)
806 mstruct->flags = 0;
807 else
808 mstruct->flags = objp->flags;
809 break;
810 case MSAFE_OBJECT_SIZE:
811 objp = ObjGet(mstruct->objhandle);
812 if (!objp)
813 mstruct->size = 0.0f;
814 else
815 mstruct->size = objp->size;
816 break;
817 case MSAFE_OBJECT_CONTROL_TYPE: // Needs to be send
818 objp = ObjGet(mstruct->objhandle);
819 if (!objp)
820 mstruct->control_type = CT_NONE;
821 else
822 mstruct->control_type = objp->control_type;
823 break;
824 case MSAFE_OBJECT_MOVEMENT_TYPE: // Needs to be send
825 objp = ObjGet(mstruct->objhandle);
826 if (!objp)
827 mstruct->movement_type = MT_NONE;
828 else
829 mstruct->movement_type = objp->movement_type;
830 break;
831 case MSAFE_OBJECT_CREATION_TIME:
832 objp = ObjGet(mstruct->objhandle);
833 if (!objp)
834 mstruct->creation_time = 0.0f;
835 else
836 mstruct->creation_time = objp->creation_time;
837 break;
838 case MSAFE_OBJECT_PHYSICS_FLAGS: // Needs to be send
839 objp = ObjGet(mstruct->objhandle);
840 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
841 mstruct->physics_flags = 0;
842 else
843 mstruct->physics_flags = objp->mtype.phys_info.flags;
844 break;
845 case MSAFE_OBJECT_ROTDRAG:
846 objp = ObjGet(mstruct->objhandle);
847 if (!objp || (objp->movement_type != MT_WALKING && objp->movement_type != MT_PHYSICS))
848 mstruct->rot_drag = 1.0f;
849 else
850 mstruct->rot_drag = objp->mtype.phys_info.rotdrag;
851 break;
852 case MSAFE_OBJECT_SHIELDS:
853 objp = ObjGet(mstruct->objhandle);
854 if (!objp)
855 mstruct->shields = -1;
856 else
857 mstruct->shields = objp->shields;
858 break;
859 case MSAFE_OBJECT_SHIELDS_ORIGINAL:
860 objp = ObjGet(mstruct->objhandle);
861 if (!objp || !IS_GENERIC(objp->type))
862 mstruct->shields = -1;
863 else
864 mstruct->shields = Object_info[objp->id].hit_points;
865 break;
866 case MSAFE_OBJECT_ENERGY:
867 ASSERT(MOBJ->type == OBJ_PLAYER);
868 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
869 mstruct->energy = 0;
870 else
871 mstruct->energy = Players[MOBJ->id].energy;
872 break;
873 case MSAFE_OBJECT_MOVEMENT_SCALAR:
874 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
875 mstruct->scalar = 0.0;
876 else
877 mstruct->scalar = Players[MOBJ->id].movement_scalar;
878 break;
879 case MSAFE_OBJECT_RECHARGE_SCALAR:
880 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
881 mstruct->scalar = 0.0;
882 else
883 mstruct->scalar = Players[MOBJ->id].weapon_recharge_scalar;
884 break;
885 case MSAFE_OBJECT_WSPEED_SCALAR:
886 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
887 mstruct->scalar = 0.0;
888 else
889 mstruct->scalar = Players[MOBJ->id].weapon_speed_scalar;
890 break;
891 case MSAFE_OBJECT_ARMOR_SCALAR:
892 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
893 mstruct->scalar = 0.0;
894 else
895 mstruct->scalar = Players[MOBJ->id].armor_scalar;
896 break;
897 case MSAFE_OBJECT_DAMAGE_SCALAR:
898 if (!VALIDATE_OBJECT(mstruct->objhandle) || (MOBJ->type != OBJ_PLAYER))
899 mstruct->scalar = 0.0;
900 else
901 mstruct->scalar = Players[MOBJ->id].damage_scalar;
902 break;
903 case MSAFE_OBJECT_TYPE:
904 objp = ObjGet(mstruct->objhandle);
905 if (!objp)
906 mstruct->type = -1;
907 else
908 mstruct->type = objp->type;
909 break;
910 case MSAFE_OBJECT_ID:
911 objp = ObjGet(mstruct->objhandle);
912 if (!objp)
913 mstruct->id = -1;
914 else
915 mstruct->id = objp->id;
916 break;
917 case MSAFE_OBJECT_PARENT: {
918 object *obj = ObjGet(mstruct->objhandle);
919 if (!obj)
920 return;
921 obj = ObjGetUltimateParent(obj);
922 mstruct->objhandle = obj->handle;
923 break;
924 }
925 case MSAFE_OBJECT_ENERGY_WEAPON: {
926 object *objp = ObjGet(mstruct->objhandle);
927 mstruct->state = (objp && (objp->type == OBJ_WEAPON) && !(Weapons[objp->id].flags & WF_MATTER_WEAPON));
928 }
929 case MSAFE_OBJECT_DAMAGE_AMOUNT: {
930 mstruct->amount = 0; // default
931 object *objp = ObjGet(mstruct->objhandle);
932 if (!objp || (objp->type != OBJ_WEAPON))
933 return;
934 mstruct->amount = Weapons[objp->id].generic_damage * objp->ctype.laser_info.multiplier;
935 break;
936 }
937 case MSAFE_OBJECT_COUNT_TYPE: {
938 int i, count = 0;
939 for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) {
940 if ((objp->type == mstruct->type) && (objp->id == mstruct->id))
941 count++;
942 }
943 mstruct->count = count;
944 break;
945 }
946 // case MSAFE_OBJECT_ANIM_FRAME:
947 // {
948 // objp = ObjGet(mstruct->objhandle);
949 // if(!objp || !(objp->flags & OF_POLYGON_OBJECT))
950 // mstruct->anim_frame = 0.0f;
951 // else
952 // mstruct->anim_frame = objp->rtype.pobj_info.anim_frame;
953 // break;
954 // }
955 case MSAFE_OBJECT_INVULNERABLE: {
956 if (!VALIDATE_OBJECT(mstruct->objhandle)) {
957 mstruct->state = 0;
958 mstruct->lifetime = 0;
959 return;
960 }
961
962 if (MOBJ->type == OBJ_PLAYER) {
963 mstruct->state = (bool)((Players[MOBJ->id].flags & PLAYER_FLAGS_INVULNERABLE) != 0);
964 if (mstruct->state)
965 mstruct->lifetime = Players[MOBJ->id].invulnerable_time;
966 else
967 mstruct->lifetime = 0;
968 } else {
969 mstruct->state = (bool)((MOBJ->flags & OF_DESTROYABLE) == 0);
970 mstruct->lifetime = 0;
971 }
972
973 break;
974 }
975 case MSAFE_OBJECT_CLOAK: {
976 if (!VALIDATE_OBJECT(mstruct->objhandle)) {
977 mstruct->state = 0;
978 mstruct->lifetime = 0;
979 return;
980 }
981 if (!MOBJ->effect_info) {
982 mstruct->state = 0;
983 mstruct->lifetime = 0;
984 return;
985 }
986 mstruct->state = (bool)((MOBJ->effect_info->type_flags & EF_CLOAKED) != 0);
987 if (mstruct->state)
988 mstruct->lifetime = MOBJ->effect_info->cloak_time;
989 else
990 mstruct->lifetime = 0;
991 break;
992 }
993 case MSAFE_OBJECT_LIGHT_DIST: {
994 mstruct->light_distance = 0.0; // default
995 object *objp = ObjGet(mstruct->objhandle);
996 if (objp) {
997 light_info *li = ObjGetLightInfo(objp);
998 if (li)
999 mstruct->light_distance = li->light_distance;
1000 }
1001 break;
1002 }
1003 case MSAFE_OBJECT_PLAYER_HANDLE:
1004 mstruct->objhandle = OBJECT_HANDLE_NONE; // default to none
1005 if ((mstruct->slot >= 0) && (mstruct->slot < MAX_PLAYERS) && (Players[mstruct->slot].objnum != -1)) {
1006 if (Game_mode & GM_MULTI) {
1007 // Don't return the handle for observers
1008 if (Objects[Players[mstruct->slot].objnum].type == OBJ_OBSERVER)
1009 break;
1010
1011 if (NetPlayers[mstruct->slot].flags & NPF_CONNECTED && NetPlayers[mstruct->slot].sequence == NETSEQ_PLAYING)
1012 mstruct->objhandle = Objects[Players[mstruct->slot].objnum].handle;
1013 } else {
1014 if (mstruct->slot == 0)
1015 mstruct->objhandle = Objects[Players[mstruct->slot].objnum].handle;
1016 }
1017 }
1018 break;
1019 case MSAFE_OBJECT_PLAYER_CONTROLAI: {
1020 bool ok = false;
1021 mstruct->state = false;
1022 if ((mstruct->slot >= 0) && (mstruct->slot < MAX_PLAYERS) && (Players[mstruct->slot].objnum != -1)) {
1023 if (Game_mode & GM_MULTI) {
1024 if (NetPlayers[mstruct->slot].flags & NPF_CONNECTED && NetPlayers[mstruct->slot].sequence == NETSEQ_PLAYING)
1025 ok = true;
1026 } else {
1027 if (mstruct->slot == 0)
1028 ok = true;
1029 }
1030 }
1031 if (ok) {
1032 if (Objects[Players[mstruct->slot].objnum].control_type == CT_AI)
1033 mstruct->state = true;
1034 else
1035 mstruct->state = false;
1036 }
1037 } break;
1038 case MSAFE_DOOR_LOCK_STATE:
1039 mstruct->state = DoorwayLocked(mstruct->objhandle);
1040 break;
1041 case MSAFE_DOOR_OPENABLE:
1042 mstruct->state = DoorwayOpenable(mstruct->objhandle, mstruct->ithandle);
1043 break;
1044 case MSAFE_DOOR_POSITION:
1045 mstruct->scalar = DoorwayGetPosition(mstruct->objhandle);
1046 break;
1047 case MSAFE_TRIGGER_SET:
1048 // Returns 1 if the trigger is enabled
1049 mstruct->state = TriggerGetState(mstruct->trigger_num);
1050 break;
1051 case MSAFE_ROOM_HAS_PLAYER: {
1052 int objnum;
1053
1054 if (!VALIDATE_ROOM(mstruct->roomnum)) {
1055 mstruct->state = 0;
1056 break;
1057 }
1058 for (objnum = Rooms[mstruct->roomnum].objects; objnum != -1; objnum = Objects[objnum].next) {
1059 if (Objects[objnum].type == OBJ_PLAYER)
1060 break;
1061 }
1062 mstruct->state = (objnum != -1);
1063 break;
1064 }
1065 case MSAFE_ROOM_PORTAL_RENDER: {
1066 if (!VALIDATE_ROOM_PORTAL(mstruct->roomnum, mstruct->portalnum)) {
1067 mstruct->state = 0;
1068 break;
1069 }
1070
1071 portal *pp = &Rooms[mstruct->roomnum].portals[mstruct->portalnum];
1072
1073 if (pp->flags & PF_RENDER_FACES)
1074 mstruct->state = 1;
1075 else
1076 mstruct->state = 0;
1077 break;
1078 }
1079 case MSAFE_ROOM_PORTAL_BLOCK: {
1080 if (!VALIDATE_ROOM_PORTAL(mstruct->roomnum, mstruct->portalnum)) {
1081 mstruct->state = 0;
1082 break;
1083 }
1084
1085 portal *pp = &Rooms[mstruct->roomnum].portals[mstruct->portalnum];
1086 if (pp->flags & PF_BLOCK)
1087 mstruct->state = 1;
1088 else
1089 mstruct->state = 0;
1090 break;
1091 }
1092 case MSAFE_ROOM_DAMAGE:
1093 if (!VALIDATE_ROOM(mstruct->roomnum)) {
1094 mstruct->amount = 0.0;
1095 mstruct->index = 0;
1096 break;
1097 }
1098 mstruct->amount = Rooms[mstruct->roomnum].damage;
1099 mstruct->index = Rooms[mstruct->roomnum].damage_type;
1100 break;
1101 case MSAFE_MISC_ENABLE_SHIP: {
1102 mstruct->state = PlayerIsShipAllowed(-1, mstruct->name);
1103 } break;
1104 case MSAFE_MISC_WAYPOINT:
1105 mstruct->index = Current_waypoint;
1106 break;
1107 case MSAFE_MISC_GUIDEBOT_NAME: {
1108 object *objp = ObjGet(mstruct->objhandle);
1109 if (objp && objp->type == OBJ_PLAYER && objp->id == Player_num) {
1110 Current_pilot.get_guidebot_name(mstruct->name);
1111 } else {
1112 strcpy(mstruct->name, "GB");
1113 }
1114 } break;
1115 case MSAFE_INVEN_CHECK:
1116 case MSAFE_COUNTERMEASURE_CHECK: {
1117 object *objp = ObjGet(mstruct->objhandle);
1118 int ret;
1119 if (objp && (objp->type == OBJ_PLAYER)) {
1120 int slot = objp->id;
1121 if (type == MSAFE_COUNTERMEASURE_CHECK)
1122 mstruct->type = OBJ_WEAPON;
1123 if (mstruct->type == OBJ_WEAPON)
1124 ret = Players[slot].counter_measures.CheckItem(mstruct->type, mstruct->id);
1125 else
1126 ret = Players[slot].inventory.CheckItem(mstruct->type, mstruct->id);
1127 if (ret)
1128 mstruct->state = 1;
1129 else
1130 mstruct->state = 0;
1131 }
1132 break;
1133 }
1134 case MSAFE_INVEN_COUNT: {
1135 object *objp = ObjGet(mstruct->objhandle);
1136 if (objp && (objp->type == OBJ_PLAYER)) {
1137 int slot = objp->id;
1138 mstruct->count = Players[slot].inventory.GetTypeIDCount(mstruct->type, mstruct->id);
1139 }
1140 break;
1141 }
1142 case MSAFE_INVEN_SIZE: {
1143 object *objp = ObjGet(mstruct->objhandle);
1144 if (objp && (objp->type == OBJ_PLAYER)) {
1145 int slot = objp->id;
1146 mstruct->size = Players[slot].inventory.Size();
1147 }
1148 } break;
1149 case MSAFE_INVEN_GET_TYPE_ID: {
1150 object *objp = ObjGet(mstruct->objhandle);
1151 if (objp && (objp->type == OBJ_PLAYER)) {
1152 int slot = objp->id;
1153 int size = Players[slot].inventory.Size();
1154 if (mstruct->index < 0 || mstruct->index > size) {
1155 mstruct->count = 0;
1156 mstruct->type = OBJ_NONE;
1157 mstruct->id = 0;
1158 return;
1159 }
1160 int savepos = Players[slot].inventory.GetPos();
1161 Players[slot].inventory.GotoPos(mstruct->index);
1162 mstruct->count = Players[slot].inventory.GetPosCount();
1163 Players[slot].inventory.GetPosTypeID(mstruct->type, mstruct->id);
1164
1165 Players[slot].inventory.GotoPos(savepos);
1166 }
1167 } break;
1168 case MSAFE_INVEN_CHECK_OBJECT: {
1169 object *player = ObjGet(mstruct->objhandle);
1170 object *object = ObjGet(mstruct->ithandle);
1171 mstruct->state = false;
1172 if (player && object && (player->type == OBJ_PLAYER)) {
1173 int slot = player->id;
1174 mstruct->state = Players[slot].inventory.CheckItem(mstruct->ithandle, -1);
1175 }
1176 } break;
1177 case MSAFE_COUNTERMEASURE_COUNT: {
1178 object *objp = ObjGet(mstruct->objhandle);
1179 if (objp && (objp->type == OBJ_PLAYER)) {
1180 int slot = objp->id;
1181 int id = FindWeaponName(IGNORE_TABLE(mstruct->name));
1182 if (id == -1) {
1183 mstruct->count = 0;
1184 } else {
1185 mstruct->count = Players[slot].counter_measures.GetTypeIDCount(OBJ_WEAPON, id);
1186 }
1187 }
1188 } break;
1189 case MSAFE_COUNTERMEASURE_SIZE: {
1190 object *objp = ObjGet(mstruct->objhandle);
1191 if (objp && (objp->type == OBJ_PLAYER)) {
1192 int slot = objp->id;
1193 mstruct->size = Players[slot].counter_measures.Size();
1194 }
1195 } break;
1196 case MSAFE_COUNTERMEASURE_GET: {
1197 object *objp = ObjGet(mstruct->objhandle);
1198 if (objp && (objp->type == OBJ_PLAYER)) {
1199 int slot = objp->id;
1200 int size = Players[slot].counter_measures.Size();
1201 if (mstruct->index < 0 || mstruct->index > size) {
1202 mstruct->count = 0;
1203 mstruct->type = OBJ_NONE;
1204 mstruct->id = 0;
1205 return;
1206 }
1207 int savepos = Players[slot].counter_measures.GetPos();
1208 Players[slot].counter_measures.GotoPos(mstruct->index);
1209 mstruct->count = Players[slot].counter_measures.GetPosCount();
1210 Players[slot].counter_measures.GetPosTypeID(mstruct->type, mstruct->id);
1211 Players[slot].counter_measures.GotoPos(savepos);
1212 }
1213 } break;
1214 case MSAFE_ROOM_FOG_STATE:
1215 if (!VALIDATE_ROOM(mstruct->roomnum))
1216 mstruct->state = 0;
1217 else
1218 mstruct->state = (Rooms[mstruct->roomnum].flags & RF_FOG) != 0;
1219 break;
1220 case MSAFE_WEAPON_CHECK: {
1221 // we want to check a player for a particular weapon
1222 // objhandle: the player
1223 // index: the weapon
1224 // state: whether the player has the weapon
1225 // count: ammo (if it's an ammo/secondary) of the weapon, else -1
1226 object *objp = ObjGet(mstruct->objhandle);
1227 mstruct->state = 0;
1228 ASSERT(mstruct->index >= 0 && mstruct->index < MAX_PRIMARY_WEAPONS + MAX_SECONDARY_WEAPONS);
1229 if (objp && (objp->type == OBJ_PLAYER)) {
1230 int pnum = objp->id;
1231 if (Players[pnum].weapon_flags & HAS_FLAG(mstruct->index)) {
1232 mstruct->state = 1;
1233 if (mstruct->index >= SECONDARY_INDEX) {
1234 mstruct->count = Players[pnum].weapon_ammo[mstruct->index];
1235 } else {
1236 ship *ship = &Ships[Players[pnum].ship_index];
1237 otype_wb_info *wb = &ship->static_wb[mstruct->index];
1238 ASSERT(wb != NULL);
1239 if (wb->ammo_usage) {
1240 // this guy is an ammo weapon!
1241 mstruct->count = Players[pnum].weapon_ammo[mstruct->index];
1242 } else {
1243 // no ammo
1244 mstruct->count = -1;
1245 }
1246 }
1247 }
1248 } else {
1249 Int3(); // uhhhh
1250 }
1251 } break;
1252 case MSAFE_WEAPON_ADD:
1253 Int3(); // huh?
1254 break;
1255 default:
1256 Int3(); // Invalid type passed to function
1257 break;
1258 }
1259 }
1260 // Gets the player slot from the specified object, if the object is a player or player weapon
1261 // Returns -1 if can't find player
1262 int GetPlayerSlot(int objhandle) {
1263 object *objp = ObjGet(objhandle);
1264 if (!objp)
1265 return -1;
1266 if (objp->type == OBJ_WEAPON)
1267 objp = ObjGetUltimateParent(objp);
1268 if (objp->type == OBJ_PLAYER)
1269 return objp->id;
1270 else
1271 return -1;
1272 }
1273 #define GB_TOKEN "GUIDEBOT:"
1274 // If the src message is from the guidebot, xlates it into the proper format. If not a GB
1275 // message, just copies the string over.
1276 // Returns true if is a GB message
1277 bool XlateGBMessage(char *dest, char *src) {
1278 if (strnicmp(src, GB_TOKEN, sizeof(GB_TOKEN) - 1) != 0) {
1279 strcpy(dest, src);
1280 return 0;
1281 }
1282 char *t = src + strlen(GB_TOKEN); // skip the first part of the string
1283 while (*t == ' ') // skip spaces
1284 t++;
1285 if (*t == '"') // skip the leading quote
1286 t++;
1287 char gbname[100];
1288 Current_pilot.get_guidebot_name(gbname);
1289 sprintf(dest, "\1\255\255\1%s:\1\1\255\1 %s", gbname, t);
1290 while (dest[strlen(dest) - 1] == ' ') // strip spaces at end
1291 dest[strlen(dest) - 1] = 0;
1292 if (dest[strlen(dest) - 1] == '"') // Remove the trailing quote
1293 dest[strlen(dest) - 1] = 0;
1294 return 1;
1295 }
1296 char Custom_HUD_text[MSAFE_MESSAGE_LENGTH] = "";
1297 extern bool Demo_call_ok;
1298 // The main entry point for all the multisafe functions
1299 // Pass the type of function you want, and then fill in the relevant fields
1300 // of the mstruct
1301 void msafe_CallFunction(uint8_t type, msafe_struct *mstruct) {
1302 if ((Demo_flags == DF_PLAYBACK) && (!Demo_call_ok))
1303 return;
1304 uint8_t send_it = 1;
1305 switch (type) {
1306 case MSAFE_WEATHER_RAIN:
1307 SetRainState(mstruct->state, mstruct->scalar);
1308 break;
1309 case MSAFE_WEATHER_SNOW:
1310 SetSnowState(mstruct->state, mstruct->scalar);
1311 break;
1312 case MSAFE_WEATHER_LIGHTNING:
1313 SetLightningState(mstruct->state, mstruct->scalar, mstruct->randval);
1314 break;
1315 case MSAFE_WEATHER_LIGHTNING_BOLT: {
1316 if (mstruct->texnum == -1) {
1317 mprintf(0, "Failing bolt because texnum is -1\n");
1318 return;
1319 }
1320
1321 if (mstruct->flags) {
1322 if (!VALIDATE_OBJECT(mstruct->objhandle))
1323 return;
1324 } else {
1325 if (!VALIDATE_OBJECT(mstruct->objhandle))
1326 return;
1327 if (!VALIDATE_OBJECT(mstruct->ithandle))
1328 return;
1329 }
1330 int visnum = VisEffectCreate(VIS_FIREBALL, THICK_LIGHTNING_INDEX, mstruct->roomnum, &mstruct->pos);
1331 if (visnum >= 0) {
1332 vis_effect *vis = &VisEffects[visnum];
1333 vis->lifeleft = mstruct->lifetime;
1334 vis->lifetime = mstruct->lifetime;
1335 vis->end_pos = mstruct->pos2;
1336
1337 vis->custom_handle = mstruct->texnum;
1338
1339 vis->lighting_color = mstruct->color;
1340 vis->billboard_info.width = mstruct->size;
1341 vis->billboard_info.texture = mstruct->state;
1342 vis->velocity.x = mstruct->count;
1343 vis->velocity.y = mstruct->interval;
1344 vis->velocity.z = mstruct->index;
1345
1346 vis->flags = VF_USES_LIFELEFT | VF_WINDSHIELD_EFFECT | VF_LINK_TO_VIEWER;
1347 vis->size = vm_VectorDistanceQuick(&vis->pos, &vis->end_pos);
1348 if (mstruct->flags) // Do attached lightning effect
1349 {
1350 vis->flags |= VF_ATTACHED;
1351 vis->attach_info.obj_handle = MOBJ->handle;
1352 vis->attach_info.modelnum = MOBJ->rtype.pobj_info.model_num;
1353 vis->attach_info.vertnum = mstruct->g1;
1354 vis->attach_info.end_vertnum = mstruct->g2;
1355 WeaponCalcGun(&vis->pos, NULL, MOBJ, vis->attach_info.vertnum);
1356 WeaponCalcGun(&vis->end_pos, NULL, MOBJ, vis->attach_info.end_vertnum);
1357 } else {
1358 vis->flags |= VF_ATTACHED | VF_PLANAR;
1359 vis->attach_info.obj_handle = MOBJ->handle;
1360 vis->attach_info.dest_objhandle = IOBJ->handle;
1361 vis->end_pos = IOBJ->pos;
1362 }
1363 }
1364 break;
1365 }
1366 case MSAFE_ROOM_TEXTURE: {
1367 if (!VALIDATE_ROOM_FACE(mstruct->roomnum, mstruct->facenum))
1368 return;
1369 ASSERT(Rooms[mstruct->roomnum].num_faces > mstruct->facenum);
1370 ChangeRoomFaceTexture(mstruct->roomnum, mstruct->facenum, mstruct->index);
1371 break;
1372 }
1373 case MSAFE_ROOM_WIND:
1374 if (!VALIDATE_ROOM(mstruct->roomnum))
1375 return;
1376 Rooms[mstruct->roomnum].wind = mstruct->wind;
1377 Rooms[mstruct->roomnum].room_change_flags |= RCF_WIND;
1378 break;
1379 case MSAFE_ROOM_FOG:
1380 if (!VALIDATE_ROOM(mstruct->roomnum))
1381 return;
1382 Rooms[mstruct->roomnum].fog_r = mstruct->fog_r;
1383 Rooms[mstruct->roomnum].fog_g = mstruct->fog_g;
1384 Rooms[mstruct->roomnum].fog_b = mstruct->fog_b;
1385 Rooms[mstruct->roomnum].fog_depth = mstruct->fog_depth;
1386 Rooms[mstruct->roomnum].room_change_flags |= RCF_FOG;
1387 Rooms[mstruct->roomnum].flags |= RF_FOG;
1388 break;
1389 case MSAFE_ROOM_FOG_STATE:
1390 if (!VALIDATE_ROOM(mstruct->roomnum))
1391 return;
1392 if (mstruct->state)
1393 Rooms[mstruct->roomnum].flags |= RF_FOG;
1394 else
1395 Rooms[mstruct->roomnum].flags &= ~RF_FOG;
1396 Rooms[mstruct->roomnum].room_change_flags |= RCF_FOG;
1397 break;
1398 case MSAFE_ROOM_LIGHT_PULSE:
1399 if (!VALIDATE_ROOM(mstruct->roomnum))
1400 return;
1401 Rooms[mstruct->roomnum].pulse_time = mstruct->pulse_time;
1402 Rooms[mstruct->roomnum].pulse_offset = mstruct->pulse_offset;
1403 Rooms[mstruct->roomnum].room_change_flags |= RCF_LIGHTING;
1404 break;
1405 case MSAFE_ROOM_LIGHT_FLICKER:
1406 if (!VALIDATE_ROOM(mstruct->roomnum))
1407 return;
1408 if (mstruct->state)
1409 Rooms[mstruct->roomnum].flags |= RF_FLICKER;
1410 else
1411 Rooms[mstruct->roomnum].flags &= ~RF_FLICKER;
1412 Rooms[mstruct->roomnum].room_change_flags |= RCF_LIGHTING;
1413 break;
1414 case MSAFE_ROOM_LIGHT_STROBE:
1415 if (!VALIDATE_ROOM(mstruct->roomnum))
1416 return;
1417 if (mstruct->state)
1418 Rooms[mstruct->roomnum].flags |= RF_STROBE;
1419 else
1420 Rooms[mstruct->roomnum].flags &= ~RF_STROBE;
1421 Rooms[mstruct->roomnum].room_change_flags |= RCF_LIGHTING;
1422 break;
1423 case MSAFE_ROOM_REFUEL:
1424 if (!VALIDATE_ROOM(mstruct->roomnum))
1425 return;
1426 if (mstruct->state)
1427 Rooms[mstruct->roomnum].flags |= RF_FUELCEN;
1428 else
1429 Rooms[mstruct->roomnum].flags &= ~RF_FUELCEN;
1430 Rooms[mstruct->roomnum].room_change_flags |= RCF_REFUEL;
1431 break;
1432 case MSAFE_ROOM_CHANGING_FOG: {
1433 if (!VALIDATE_ROOM(mstruct->roomnum))
1434 return;
1435 vector fog_vec;
1436 fog_vec.x = mstruct->fog_r;
1437 fog_vec.y = mstruct->fog_g;
1438 fog_vec.z = mstruct->fog_b;
1439 SetRoomChangeOverTime(mstruct->roomnum, 1, &fog_vec, mstruct->fog_depth, mstruct->interval);
1440 break;
1441 }
1442 case MSAFE_ROOM_CHANGING_WIND: {
1443 if (!VALIDATE_ROOM(mstruct->roomnum))
1444 return;
1445 SetRoomChangeOverTime(mstruct->roomnum, 0, &mstruct->wind, 0, mstruct->interval);
1446 break;
1447 }
1448 case MSAFE_ROOM_PORTAL_RENDER: {
1449 if (!VALIDATE_ROOM_PORTAL(mstruct->roomnum, mstruct->portalnum))
1450 return;
1451
1452 portal *pp = &Rooms[mstruct->roomnum].portals[mstruct->portalnum];
1453
1454 if (mstruct->state)
1455 pp->flags |= PF_RENDER_FACES;
1456 else
1457 pp->flags &= ~PF_RENDER_FACES;
1458 Rooms[mstruct->roomnum].room_change_flags |= RCF_PORTAL_RENDER;
1459 pp->flags |= PF_CHANGED;
1460
1461 // check other side of portal
1462 if (mstruct->flags) {
1463 portal *pp2 = &Rooms[pp->croom].portals[pp->cportal];
1464 if (mstruct->state)
1465 pp2->flags |= PF_RENDER_FACES;
1466 else
1467 pp2->flags &= ~PF_RENDER_FACES;
1468 Rooms[pp->croom].room_change_flags |= RCF_PORTAL_RENDER;
1469 pp2->flags |= PF_CHANGED;
1470 }
1471 break;
1472 }
1473 case MSAFE_ROOM_PORTAL_BLOCK: {
1474 if (!VALIDATE_ROOM_PORTAL(mstruct->roomnum, mstruct->portalnum))
1475 return;
1476
1477 portal *pp = &Rooms[mstruct->roomnum].portals[mstruct->portalnum];
1478 if (!(pp->flags & (PF_BLOCK | PF_BLOCK_REMOVABLE)))
1479 return;
1480 if (mstruct->state)
1481 pp->flags |= PF_BLOCK;
1482 else
1483 pp->flags &= ~PF_BLOCK;
1484 Rooms[mstruct->roomnum].room_change_flags |= RCF_PORTAL_BLOCK;
1485 pp->flags |= PF_CHANGED;
1486
1487 // check other side of portal
1488 portal *pp2 = &Rooms[pp->croom].portals[pp->cportal];
1489 if (mstruct->state)
1490 pp2->flags |= PF_BLOCK;
1491 else
1492 pp2->flags &= ~PF_BLOCK;
1493 Rooms[pp->croom].room_change_flags |= RCF_PORTAL_BLOCK;
1494 pp2->flags |= PF_CHANGED;
1495 break;
1496 }
1497 case MSAFE_ROOM_BREAK_GLASS: {
1498 void ComputeCenterPointOnFace(vector * vp, room * rp, int facenum);
1499 if (!VALIDATE_ROOM_PORTAL(mstruct->roomnum, mstruct->portalnum))
1500 return;
1501 send_it = 0; // Handled in function below
1502
1503 BreakGlassFace(&Rooms[mstruct->roomnum], Rooms[mstruct->roomnum].portals[mstruct->portalnum].portal_face);
1504 break;
1505 }
1506 case MSAFE_ROOM_DAMAGE:
1507 if (!VALIDATE_ROOM(mstruct->roomnum))
1508 return;
1509 Rooms[mstruct->roomnum].damage = mstruct->amount;
1510 Rooms[mstruct->roomnum].damage_type = mstruct->index;
1511 Rooms[mstruct->roomnum].room_change_flags |= RCF_DAMAGE;
1512 break;
1513 case MSAFE_ROOM_REMOVE_ALL_POWERUPS: {
1514 if (VALIDATE_ROOM(mstruct->roomnum)) {
1515 int i, high_index;
1516 int invis_id;
1517 invis_id = FindObjectIDName("InvisiblePowerup");
1518 high_index = Highest_object_index + 1;
1519 for (i = 0; i < high_index; i++) {
1520 if (Objects[i].type != OBJ_POWERUP)
1521 continue;
1522 if (Objects[i].roomnum != mstruct->roomnum)
1523 continue;
1524 if (Objects[i].id == invis_id)
1525 continue;
1526 SetObjectDeadFlag(&Objects[i], true, false);
1527 }
1528 }
1529 } break;
1530 case MSAFE_OBJECT_FIRE_WEAPON: {
1531 object *objp = ObjGet(mstruct->objhandle);
1532 if (objp && (mstruct->index >= 0) && (mstruct->index < MAX_WEAPONS) && Weapons[mstruct->index].used)
1533 FireWeaponFromObject(objp, mstruct->index, mstruct->gunpoint);
1534 send_it = 0;
1535 break;
1536 }
1537 case MSAFE_OBJECT_SETONFIRE: {
1538 if (!VALIDATE_OBJECT(mstruct->objhandle))
1539 return;
1540
1541 object *obj = MOBJ;
1542 float damage_time = mstruct->longevity;
1543 float d_per_sec = mstruct->interval;
1544 if (obj->effect_info) {
1545 if (damage_time > 0) {
1546 obj->effect_info->type_flags |= EF_NAPALMED;
1547 obj->effect_info->damage_time += damage_time;
1548 // NOTE: commented out because lava rocks need to go burning for awhile...
1549 // so we trust that someone doesn't do something stupid
1550 // obj->effect_info->damage_time=std::min(10.0f,obj->effect_info->damage_time);
1551 obj->effect_info->damage_per_second = d_per_sec;
1552 if (Gametime - obj->effect_info->last_damage_time > 1.0f)
1553 obj->effect_info->last_damage_time = 0;
1554
1555 obj->effect_info->damage_handle = mstruct->ithandle;
1556 if (obj->effect_info->sound_handle == SOUND_NONE_INDEX)
1557 obj->effect_info->sound_handle = Sound_system.Play3dSound(SOUND_PLAYER_BURNING, SND_PRIORITY_HIGHEST, obj);
1558 } else {
1559 obj->effect_info->type_flags &= ~EF_NAPALMED;
1560 obj->effect_info->damage_time = 0;
1561 }
1562 }
1563 } break;
1564 case MSAFE_OBJECT_SHIELDS:
1565 if (!VALIDATE_OBJECT(mstruct->objhandle))
1566 return;
1567
1568 MOBJ->shields = mstruct->shields;
1569 MOBJ->flags &= ~(OF_AI_DEATH);
1570
1571 break;
1572 case MSAFE_OBJECT_ENERGY:
1573 if (!VALIDATE_OBJECT(mstruct->objhandle))
1574 return;
1575 ASSERT(MOBJ->type == OBJ_PLAYER);
1576 Players[MOBJ->id].energy = mstruct->energy;
1577 break;
1578 case MSAFE_SHOW_ENABLED_CONTROLS: {
1579 object *objp = ObjGet(mstruct->objhandle);
1580 if (objp && (objp->type == OBJ_PLAYER)) {
1581 Hud_show_controls = mstruct->state ? true : false;
1582 }
1583 } break;
1584 case MSAFE_OBJECT_PLAYER_CMASK: {
1585 object *objp = ObjGet(mstruct->objhandle);
1586 if (objp && (objp->type == OBJ_PLAYER)) {
1587 if (mstruct->control_val)
1588 Players[objp->id].controller_bitflags |= mstruct->control_mask;
1589 else
1590 Players[objp->id].controller_bitflags &= ~mstruct->control_mask;
1591 }
1592 break;
1593 }
1594 case MSAFE_OBJECT_PLAYER_KEY: {
1595 int slot = GetPlayerSlot(mstruct->ithandle);
1596 if (slot == -1)
1597 break; // couldn't find player object
1598 if (Players[slot].keys & KEY_FLAG(mstruct->index))
1599 return; // if player already has key, do nothing
1600 // We should really have a function to set the key flags
1601 Players[slot].keys |= KEY_FLAG(mstruct->index);
1602 Global_keys |= KEY_FLAG(mstruct->index);
1603 if (mstruct->objhandle != OBJECT_HANDLE_NONE) {
1604 object *keyobj = ObjGet(mstruct->objhandle);
1605 if (keyobj) {
1606 mprintf(0, "Adding key from multisafe to player %d\n", slot);
1607 Sound_system.Play3dSound(SOUND_POWERUP_PICKUP, SND_PRIORITY_HIGH, keyobj);
1608 Players[slot].inventory.Add(keyobj->type, keyobj->id, NULL, -1, -1, INVAF_NOTSPEWABLE, mstruct->message);
1609
1610 if (!(Game_mode & GM_MULTI)) // If not multiplayer, delete the key
1611 {
1612 SetObjectDeadFlag(keyobj);
1613 } else if ((keyobj->flags & OF_INFORM_DESTROY_TO_LG)) {
1614 Level_goals.Inform(LIT_OBJECT, LGF_COMP_DESTROY, keyobj->handle);
1615 }
1616 }
1617 }
1618 send_it = 0; // Handled by server
1619 break;
1620 }
1621 case MSAFE_OBJECT_MOVEMENT_SCALAR:
1622 if (!VALIDATE_OBJECT(mstruct->objhandle))
1623 return;
1624 ASSERT(MOBJ->type == OBJ_PLAYER);
1625 Players[MOBJ->id].movement_scalar = mstruct->scalar;
1626 break;
1627 case MSAFE_OBJECT_RECHARGE_SCALAR:
1628 if (!VALIDATE_OBJECT(mstruct->objhandle))
1629 return;
1630 ASSERT(MOBJ->type == OBJ_PLAYER);
1631 Players[MOBJ->id].weapon_recharge_scalar = mstruct->scalar;
1632 break;
1633 case MSAFE_OBJECT_WSPEED_SCALAR:
1634 if (!VALIDATE_OBJECT(mstruct->objhandle))
1635 return;
1636 ASSERT(MOBJ->type == OBJ_PLAYER);
1637 Players[MOBJ->id].weapon_speed_scalar = mstruct->scalar;
1638 break;
1639 case MSAFE_OBJECT_ARMOR_SCALAR:
1640 if (!VALIDATE_OBJECT(mstruct->objhandle))
1641 return;
1642 ASSERT(MOBJ->type == OBJ_PLAYER);
1643 Players[MOBJ->id].armor_scalar = mstruct->scalar;
1644 break;
1645 case MSAFE_OBJECT_DAMAGE_SCALAR:
1646 if (!VALIDATE_OBJECT(mstruct->objhandle))
1647 return;
1648 ASSERT(MOBJ->type == OBJ_PLAYER);
1649 Players[MOBJ->id].damage_scalar = mstruct->scalar;
1650 break;
1651 case MSAFE_OBJECT_ADD_WEAPON:
1652 if (!VALIDATE_OBJECT(mstruct->objhandle))
1653 return;
1654 ASSERT(MOBJ->type == OBJ_PLAYER);
1655 AddWeaponToPlayer(MOBJ->id, mstruct->index, mstruct->ammo);
1656 if (MOBJ->id == Player_num)
1657 send_it = 0; // Don't send because the server is picking it up
1658 break;
1659 case MSAFE_OBJECT_DAMAGE_OBJECT:
1660 if (!VALIDATE_OBJECT(mstruct->objhandle))
1661 return;
1662 send_it = 0; // Don't need to send because ApplyDamage does the work
1663 if (MOBJ->type == OBJ_PLAYER) {
1664 if (mstruct->killer_handle == OBJECT_HANDLE_NONE)
1665 ApplyDamageToPlayer(MOBJ, NULL, mstruct->damage_type, mstruct->amount);
1666 else
1667 ApplyDamageToPlayer(MOBJ, KOBJ, mstruct->damage_type, mstruct->amount);
1668 } else {
1669 if (mstruct->killer_handle == OBJECT_HANDLE_NONE)
1670 ApplyDamageToGeneric(MOBJ, NULL, mstruct->damage_type, mstruct->amount);
1671 else
1672 ApplyDamageToGeneric(MOBJ, KOBJ, mstruct->damage_type, mstruct->amount);
1673 }
1674 break;
1675 case MSAFE_OBJECT_START_SPEW: {
1676 if (!VALIDATE_OBJECT(mstruct->objhandle))
1677 return;
1678 spewinfo spew;
1679 if (mstruct->gunpoint == -2) { // no gun
1680 object *objp = ObjGet(mstruct->objhandle);
1681 if (!objp)
1682 break;
1683 spew.use_gunpoint = false;
1684 spew.pt.origin = objp->pos;
1685 spew.pt.normal = objp->orient.uvec;
1686 spew.pt.room_num = objp->roomnum;
1687 } else if (mstruct->gunpoint == -1) { // no gun
1688 object *objp = ObjGet(mstruct->objhandle);
1689 if (!objp)
1690 break;
1691 spew.use_gunpoint = false;
1692 spew.pt.origin = objp->pos;
1693 spew.pt.normal = objp->orient.fvec;
1694 spew.pt.room_num = objp->roomnum;
1695 } else {
1696 spew.use_gunpoint = true;
1697 spew.gp.obj_handle = mstruct->objhandle;
1698 spew.gp.gunpoint = mstruct->gunpoint;
1699 }
1700 spew.random = mstruct->random;
1701 spew.real_obj = (bool)(mstruct->is_real != 0);
1702 spew.effect_type = mstruct->effect_type;
1703 spew.phys_info = mstruct->phys_info;
1704 spew.drag = mstruct->drag;
1705 spew.mass = mstruct->mass;
1706 spew.time_int = mstruct->interval;
1707 spew.longevity = mstruct->longevity;
1708 spew.lifetime = mstruct->lifetime;
1709 spew.size = mstruct->size;
1710 spew.speed = mstruct->speed;
1711 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_CLIENT) {
1712 int spewnum = SpewCreate(&spew);
1713 ASSERT(spewnum != -1); // DAJ -1FIX
1714 spewnum &= 0xFF;
1715
1716 Server_spew_list[mstruct->id] = spewnum;
1717 } else {
1718 mstruct->id = SpewCreate(&spew);
1719 ASSERT(mstruct->id != -1); // DAJ -1FIX
1720 }
1721 break;
1722 }
1723 case MSAFE_OBJECT_STOP_SPEW: {
1724 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_CLIENT) {
1725 SpewClearEvent(SpewEffects[mstruct->id].handle, true);
1726 Server_spew_list[mstruct->id] = 65535;
1727 } else {
1728 SpewClearEvent(mstruct->id, true);
1729 }
1730 break;
1731 }
1732 case MSAFE_OBJECT_NO_RENDER:
1733 if (!VALIDATE_OBJECT(mstruct->objhandle))
1734 return;
1735 MOBJ->render_type = RT_NONE;
1736 MOBJ->change_flags |= OCF_NO_RENDER;
1737 break;
1738 case MSAFE_OBJECT_GHOST:
1739 if (!VALIDATE_OBJECT(mstruct->objhandle))
1740 return;
1741 if (ObjGet(mstruct->objhandle)->type == OBJ_NONE)
1742 return;
1743 if (ObjGet(mstruct->objhandle)->type == OBJ_DUMMY)
1744 return; // Don't ghost a ghosted object!!
1745 if (ObjGet(mstruct->objhandle)->type == OBJ_PLAYER)
1746 return;
1747 if (ObjGet(mstruct->objhandle)->type == OBJ_GHOST)
1748 return;
1749 ObjGhostObject(mstruct->objhandle & HANDLE_OBJNUM_MASK);
1750 break;
1751 case MSAFE_OBJECT_UNGHOST:
1752 if (!VALIDATE_OBJECT(mstruct->objhandle))
1753 return;
1754 if (ObjGet(mstruct->objhandle)->type != OBJ_DUMMY)
1755 return; // Don't unghost an unghosted object!!
1756 ObjUnGhostObject(mstruct->objhandle & HANDLE_OBJNUM_MASK);
1757 break;
1758 case MSAFE_OBJECT_REMOVE:
1759 send_it = 0;
1760 if (!VALIDATE_OBJECT(mstruct->objhandle))
1761 return;
1762
1763 SetObjectDeadFlag(MOBJ, true, (bool)(mstruct->playsound != 0));
1764 if (mstruct->playsound)
1765 Sound_system.Play3dSound(SOUND_POWERUP_PICKUP, SND_PRIORITY_HIGH, MOBJ);
1766 break;
1767 case MSAFE_OBJECT_INVULNERABLE: {
1768 if (!VALIDATE_OBJECT(mstruct->objhandle))
1769 return;
1770
1771 if (MOBJ->type == OBJ_PLAYER) {
1772 if (mstruct->state)
1773 MakePlayerInvulnerable(MOBJ->id, mstruct->lifetime);
1774 else
1775 MakePlayerVulnerable(MOBJ->id);
1776 } else {
1777 if (mstruct->state)
1778 MOBJ->flags &= ~OF_DESTROYABLE;
1779 else
1780 MOBJ->flags |= OF_DESTROYABLE;
1781 }
1782 send_it = 1;
1783 break;
1784 }
1785 case MSAFE_OBJECT_CLOAKALLPLAYERS: {
1786 if (mstruct->state) {
1787 if (Game_mode & GM_MULTI) {
1788 for (int i = 0; i < MAX_PLAYERS; i++) {
1789 if (NetPlayers[i].flags & NPF_CONNECTED && NetPlayers[i].sequence == NETSEQ_PLAYING) {
1790 MakeObjectInvisible(&Objects[Players[i].objnum], mstruct->lifetime, 1.0f, true);
1791 }
1792 }
1793 } else {
1794 MakeObjectInvisible(Player_object, mstruct->lifetime, 1.0f, true);
1795 }
1796 } else {
1797 if (Game_mode & GM_MULTI) {
1798 for (int i = 0; i < MAX_PLAYERS; i++) {
1799 if (NetPlayers[i].flags & NPF_CONNECTED && NetPlayers[i].sequence == NETSEQ_PLAYING) {
1800 MakeObjectVisible(&Objects[Players[i].objnum]);
1801 }
1802 }
1803 } else {
1804 MakeObjectVisible(Player_object);
1805 }
1806 }
1807 send_it = 1;
1808 } break;
1809 case MSAFE_OBJECT_CLOAK: {
1810 if (!VALIDATE_OBJECT(mstruct->objhandle))
1811 return;
1812 if (mstruct->state) {
1813 MakeObjectInvisible(MOBJ, mstruct->lifetime);
1814 } else {
1815 MakeObjectVisible(MOBJ);
1816 }
1817 send_it = 1;
1818 break;
1819 }
1820 case MSAFE_OBJECT_LIGHT_DIST: {
1821 object *objp = ObjGet(mstruct->objhandle);
1822 if (objp) {
1823 ObjSetLocalLighting(objp);
1824 if (mstruct->light_distance < 0)
1825 mstruct->light_distance = 0;
1826 objp->lighting_info->light_distance = mstruct->light_distance;
1827 objp->change_flags |= OCF_LIGHT_DISTANCE;
1828 }
1829 break;
1830 }
1831 case MSAFE_OBJECT_LIGHT_COLOR: {
1832 object *objp = ObjGet(mstruct->objhandle);
1833 if (objp) {
1834 ObjSetLocalLighting(objp);
1835 objp->lighting_info->red_light1 = mstruct->r1;
1836 objp->lighting_info->green_light1 = mstruct->g1;
1837 objp->lighting_info->blue_light1 = mstruct->b1;
1838 objp->change_flags |= OCF_LIGHT_COLOR;
1839 }
1840 break;
1841 }
1842 case MSAFE_OBJECT_DEFORM: {
1843 object *objp = ObjGet(mstruct->objhandle);
1844 if (objp && objp->effect_info) {
1845 objp->effect_info->type_flags |= EF_DEFORM;
1846 objp->effect_info->deform_range = mstruct->amount;
1847 objp->effect_info->deform_time = mstruct->lifetime;
1848 }
1849 break;
1850 }
1851 case MSAFE_OBJECT_SPARKS: {
1852 object *objp = ObjGet(mstruct->objhandle);
1853 if (objp && objp->effect_info) {
1854 objp->effect_info->type_flags |= EF_SPARKING;
1855 objp->effect_info->spark_delay = 1.0 / mstruct->amount;
1856 objp->effect_info->spark_timer = 0;
1857 objp->effect_info->spark_time_left = mstruct->lifetime;
1858 }
1859 break;
1860 }
1861 case MSAFE_OBJECT_VIEWER_SHAKE: {
1862 AddToShakeMagnitude(mstruct->amount);
1863 break;
1864 }
1865 case MSAFE_OBJECT_SHAKE_AREA: {
1866 object *objp = ObjGet(mstruct->objhandle);
1867 if (objp) {
1868 float dist = vm_VectorDistanceQuick(&Viewer_object->pos, &objp->pos);
1869 if (dist < mstruct->scalar)
1870 AddToShakeMagnitude(mstruct->amount * (1.0 - (dist / mstruct->scalar)));
1871 }
1872 break;
1873 }
1874 case MSAFE_OBJECT_WORLD_POSITION: {
1875 object *objp = ObjGet(mstruct->objhandle);
1876 send_it = 0;
1877 if (objp) {
1878 if (mstruct->roomnum != -1) {
1879 ObjSetPos(objp, &mstruct->pos, mstruct->roomnum, &mstruct->orient, true);
1880 // When DON'T we want to send this to the clients??
1881 send_it = 1;
1882 }
1883 }
1884 } break;
1885 case MSAFE_OBJECT_PLAYER_CONTROLAI: {
1886 bool ok = false;
1887 send_it = 0;
1888 if ((mstruct->slot >= 0) && (mstruct->slot < MAX_PLAYERS) && (Players[mstruct->slot].objnum != -1)) {
1889 if (Game_mode & GM_MULTI) {
1890 if (NetPlayers[mstruct->slot].flags & NPF_CONNECTED && NetPlayers[mstruct->slot].sequence == NETSEQ_PLAYING)
1891 ok = true;
1892 } else {
1893 if (mstruct->slot == 0)
1894 ok = true;
1895 }
1896 }
1897 if (ok) {
1898 // if mstruct->state is true, then set to AI
1899 // else set back to control mode
1900 osipf_SetPlayerControlMode(mstruct->slot, (bool)(mstruct->state != 0));
1901 }
1902 } break;
1903 case MSAFE_OBJECT_DESTROY_ROBOTS_EXCEPT: {
1904 // destroy all object (generics) except those in the list specified
1905 tKillObjectItem *koilist = (tKillObjectItem *)mstruct->list;
1906 int koisize = mstruct->count;
1907 bool kill_it;
1908 send_it = 0;
1909 // go through all generic objects, kill those that don't match an exception
1910 for (int i = 0; i <= Highest_object_index; i++) {
1911 if (IS_ROBOT((&Objects[i])) && !(IS_GUIDEBOT(&Objects[i]))) {
1912 kill_it = true;
1913 // see if it's on the exception list
1914 for (int x = 0; x < koisize; x++) {
1915 switch (koilist[x].info_type) {
1916 case KOI_ID:
1917 if (Objects[i].id == koilist[x].id) {
1918 // spare it!
1919 kill_it = false;
1920 }
1921 break;
1922 case KOI_HANDLE:
1923 if (Objects[i].handle == koilist[x].objhandle) {
1924 // spare it!
1925 kill_it = false;
1926 }
1927 break;
1928 }
1929 if (kill_it == false)
1930 break;
1931 }
1932 if (kill_it) {
1933 SetObjectDeadFlag(&Objects[i], true, false);
1934 }
1935 }
1936 }
1937 } break;
1938 case MSAFE_SOUND_STREAMING: {
1939 int slot;
1940 if (mstruct->state) { // player specified
1941 slot = GetPlayerSlot(mstruct->objhandle);
1942 if (slot == -1)
1943 break; // couldn't find player object
1944 mstruct->objhandle = Objects[Players[slot].objnum].handle;
1945 } else
1946 slot = -1; // all players
1947 if ((slot == -1) || (slot == Player_num))
1948 mstruct->sound_handle = StreamPlay(mstruct->name, mstruct->volume, mstruct->flags);
1949 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER && slot == Player_num)
1950 send_it = 0;
1951 mstruct->slot = slot; // for send_to
1952 break;
1953 }
1954 case MSAFE_SOUND_2D: {
1955 int slot;
1956 if (mstruct->state) { // player specified
1957 slot = GetPlayerSlot(mstruct->objhandle);
1958 if (slot == -1)
1959 break; // couldn't find player object
1960 mstruct->objhandle = Objects[Players[slot].objnum].handle;
1961 } else
1962 slot = -1; // all players
1963 if ((slot == -1) || (slot == Player_num))
1964 mstruct->sound_handle = Sound_system.Play2dSound(mstruct->index, SND_PRIORITY_HIGHEST, mstruct->volume);
1965 else
1966 mstruct->sound_handle = -1;
1967 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER && slot == Player_num)
1968 send_it = 0;
1969 mstruct->slot = slot; // for send_to
1970 break;
1971 }
1972 case MSAFE_SOUND_OBJECT: {
1973 if (!VALIDATE_OBJECT(mstruct->objhandle))
1974 return;
1975 mstruct->sound_handle = Sound_system.Play3dSound(mstruct->index, SND_PRIORITY_HIGHEST, MOBJ);
1976 break;
1977 }
1978 case MSAFE_SOUND_STOP:
1979 Int3();
1980 send_it = 0;
1981 break;
1982 case MSAFE_SOUND_STOP_OBJ:
1983 Sound_system.StopObjectSound(mstruct->objhandle);
1984 break;
1985 case MSAFE_SOUND_VOLUME_OBJ:
1986 Sound_system.SetVolumeObject(mstruct->objhandle, mstruct->volume);
1987 break;
1988 case MSAFE_MUSIC_REGION: {
1989 int slot;
1990 if (mstruct->state) { // player specified
1991 slot = GetPlayerSlot(mstruct->objhandle);
1992 if (slot == -1)
1993 break; // couldn't find player object
1994 mstruct->objhandle = Objects[Players[slot].objnum].handle;
1995 } else
1996 slot = -1; // all players
1997 if ((slot == -1) || (slot == Player_num))
1998 D3MusicSetRegion(mstruct->index);
1999 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER && slot == Player_num)
2000 send_it = 0;
2001 mstruct->slot = slot; // for send_to
2002 break;
2003 }
2004 case MSAFE_MISC_LEVELGOAL:
2005 if (Game_mode & GM_MULTI && Netgame.local_role == LR_CLIENT) {
2006 int v = 0xFFFFFFFF;
2007 Level_goals.GoalSetName(mstruct->index, mstruct->message);
2008 Level_goals.GoalStatus(mstruct->index, LO_CLEAR_SPECIFIED, &v);
2009 Level_goals.GoalStatus(mstruct->index, LO_SET_SPECIFIED, &mstruct->type);
2010 Level_goals.GoalPriority(mstruct->index, LO_SET_SPECIFIED, &mstruct->count);
2011 }
2012 break;
2013 case MSAFE_MISC_WAYPOINT:
2014 PlayerAddWaypoint(mstruct->index);
2015 break;
2016 case MSAFE_MISC_ENABLE_SHIP: {
2017 PlayerSetShipPermission(-1, mstruct->name, (bool)(mstruct->state != 0));
2018 } break;
2019 case MSAFE_MISC_FILTERED_HUD_MESSAGE:
2020 case MSAFE_MISC_HUD_MESSAGE: {
2021 int slot;
2022 if (mstruct->state) { // player specified
2023 slot = GetPlayerSlot(mstruct->objhandle);
2024 if (slot == -1)
2025 break; // couldn't find player object
2026 mstruct->objhandle = Objects[Players[slot].objnum].handle;
2027 } else
2028 slot = -1; // all players
2029 if ((slot == -1) || (slot == Player_num)) {
2030 char message[256];
2031 bool gb = XlateGBMessage(message, mstruct->message);
2032 bool added;
2033 if (type == MSAFE_MISC_HUD_MESSAGE)
2034 added = AddColoredHUDMessage(mstruct->color, "%s", message); // "%s" because message could contain % signs!
2035 else
2036 added =
2037 AddFilteredColoredHUDMessage(mstruct->color, "%s", message); // "%s" because message could contain % signs!
2038 if (gb && added) // If was GB message & was added, play the GB sound
2039 Sound_system.Play2dSound(FindSoundName("GBotGreetB1"), SND_PRIORITY_HIGHEST, 1.0);
2040 }
2041 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER && slot == Player_num)
2042 send_it = 0;
2043 mstruct->slot = slot; // for send_to
2044 break;
2045 }
2046 case MSAFE_MISC_GAME_MESSAGE: {
2047 int slot;
2048 if (mstruct->state) { // player specified
2049 slot = GetPlayerSlot(mstruct->objhandle);
2050 if (slot == -1)
2051 break; // couldn't find player object
2052 mstruct->objhandle = Objects[Players[slot].objnum].handle;
2053 } else
2054 slot = -1; // all players
2055 if ((slot == -1) || (slot == Player_num)) {
2056 AddGameMessage(mstruct->message);
2057 char message2[256];
2058 XlateGBMessage(message2, mstruct->message2);
2059 int y = Game_window_h / 4 - 15;
2060 if (Demo_flags == DF_RECORDING) {
2061 DemoWritePersistantHUDMessage(mstruct->color, HUD_MSG_PERSISTENT_CENTER, y, 10.0,
2062 HPF_FADEOUT + HPF_FREESPACE_DRAW, SOUND_GAME_MESSAGE, message2);
2063 }
2064 if (Demo_flags != DF_PLAYBACK) {
2065 AddPersistentHUDMessage(mstruct->color, HUD_MSG_PERSISTENT_CENTER, y, 10.0, HPF_FADEOUT + HPF_FREESPACE_DRAW,
2066 SOUND_GAME_MESSAGE, message2);
2067 }
2068 }
2069 if ((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER && slot == Player_num)
2070 send_it = 0;
2071 mstruct->slot = slot; // for send_to
2072 break;
2073 }
2074 case MSAFE_MISC_END_LEVEL:
2075 if (Game_mode & GM_MULTI)
2076 MultiEndLevel();
2077 else
2078 SetGameState(mstruct->state ? GAMESTATE_LVLEND : GAMESTATE_LVLFAILED);
2079 send_it = 0;
2080 break;
2081 case MSAFE_MISC_POPUP_CAMERA: {
2082 CreateSmallView(SVW_LEFT, mstruct->objhandle, SVF_POPUP + SVF_BIGGER, mstruct->interval,
2083 D3_DEFAULT_ZOOM / mstruct->scalar, mstruct->gunpoint);
2084 break;
2085 }
2086 case MSAFE_MISC_CLOSE_POPUP:
2087 ClosePopupView(SVW_LEFT);
2088 break;
2089 case MSAFE_MISC_GUIDEBOT_NAME: {
2090 object *objp = ObjGet(mstruct->objhandle);
2091 if (objp && objp->type == OBJ_PLAYER && objp->id == Player_num) {
2092 Current_pilot.set_guidebot_name(mstruct->name);
2093 }
2094 } break;
2095 case MSAFE_MISC_START_TIMER: {
2096 extern void RenderHUDTimer(tHUDItem * item);
2097 int Osiris_GetTimerHandle(int id);
2098 int handle = Osiris_GetTimerHandle(mstruct->index);
2099 if (handle == 0)
2100 return;
2101 tHUDItem huditem;
2102 memset(&huditem, 0, sizeof(huditem));
2103 huditem.alpha = HUD_ALPHA;
2104 huditem.color = mstruct->color;
2105 huditem.type = HUD_ITEM_TIMER;
2106 huditem.x = 0;
2107 huditem.y = 0;
2108 huditem.data.timer_handle = handle;
2109 huditem.stat = STAT_CUSTOM;
2110 huditem.flags = HUD_FLAG_LEVEL;
2111 huditem.render_fn = RenderHUDTimer;
2112 AddHUDItem(&huditem);
2113 send_it = 0;
2114 break;
2115 }
2116 case MSAFE_MISC_UPDATE_HUD_ITEM:
2117 // If item not added yet, add it now
2118 if (FindCustomtext2HUDItem() == -1) {
2119 tHUDItem huditem;
2120 memset(&huditem, 0, sizeof(huditem));
2121 huditem.alpha = HUD_ALPHA;
2122 huditem.color = mstruct->color;
2123 huditem.type = HUD_ITEM_CUSTOMTEXT2;
2124 huditem.x = 0;
2125 huditem.y = 0;
2126 huditem.buffer_size = MSAFE_MESSAGE_LENGTH;
2127 huditem.stat = STAT_CUSTOM;
2128 huditem.flags = HUD_FLAG_LEVEL;
2129 huditem.render_fn = NULL;
2130 AddHUDItem(&huditem);
2131 ASSERT(FindCustomtext2HUDItem() != -1);
2132 }
2133 UpdateCustomtext2HUDItem(mstruct->message);
2134 break;
2135 case MSAFE_DOOR_LOCK_STATE:
2136 DoorwayLockUnlock(mstruct->objhandle, (mstruct->state != 0));
2137 break;
2138 case MSAFE_DOOR_ACTIVATE:
2139 ASSERT(Objects[mstruct->objhandle & HANDLE_OBJNUM_MASK].type == OBJ_DOOR);
2140 DoorwayActivate(mstruct->objhandle);
2141 break;
2142 case MSAFE_DOOR_STOP:
2143 DoorwayStop(mstruct->objhandle);
2144 break;
2145 case MSAFE_DOOR_POSITION:
2146 DoorwaySetPosition(mstruct->objhandle, mstruct->scalar);
2147 break;
2148 case MSAFE_TRIGGER_SET:
2149 TriggerSetState(mstruct->trigger_num, (mstruct->state != 0));
2150 send_it = 0;
2151 break;
2152 case MSAFE_INVEN_ADD_OBJECT: {
2153 object *player = ObjGet(mstruct->objhandle);
2154 object *item = ObjGet(mstruct->ithandle);
2155 bool ret = false;
2156
2157 send_it = 0;
2158 if (player && item && (player->type == OBJ_PLAYER)) {
2159 int slot = player->id;
2160 ret = Players[slot].inventory.AddObject(item->handle, mstruct->flags,
2161 (mstruct->message[0] != '\0') ? mstruct->message : NULL);
2162 if (ret)
2163 send_it = 1;
2164 }
2165 } break;
2166 case MSAFE_INVEN_REMOVE_OBJECT: {
2167 object *player = ObjGet(mstruct->objhandle);
2168 object *item = ObjGet(mstruct->ithandle);
2169 mstruct->state = false;
2170 send_it = 0;
2171 if (player && item && (player->type == OBJ_PLAYER)) {
2172 int slot = player->id;
2173 mstruct->state = Players[slot].inventory.Remove(item->handle, -1);
2174 if (mstruct->state)
2175 send_it = 1;
2176 }
2177 } break;
2178 case MSAFE_INVEN_ADD_TYPE_ID: {
2179 object *objp = ObjGet(mstruct->objhandle);
2180 if (objp && (objp->type == OBJ_PLAYER)) {
2181 int slot = objp->id;
2182
2183 if (mstruct->type == OBJ_WEAPON)
2184 Players[slot].counter_measures.Add(mstruct->type, mstruct->id, NULL, -1, -1, mstruct->flags);
2185 else
2186 Players[slot].inventory.Add(mstruct->type, mstruct->id, NULL, -1, -1, mstruct->flags);
2187 }
2188 break;
2189 }
2190 case MSAFE_INVEN_REMOVE:
2191 case MSAFE_COUNTERMEASURE_REMOVE: {
2192 object *objp = ObjGet(mstruct->objhandle);
2193 if (objp && (objp->type == OBJ_PLAYER)) {
2194 int slot = objp->id;
2195 if (type == MSAFE_COUNTERMEASURE_REMOVE)
2196 mstruct->type = OBJ_WEAPON;
2197
2198 if (mstruct->type == OBJ_WEAPON)
2199 Players[slot].counter_measures.Remove(mstruct->type, mstruct->id);
2200 else
2201 Players[slot].inventory.Remove(mstruct->type, mstruct->id);
2202 }
2203 break;
2204 }
2205 case MSAFE_COUNTERMEASURE_ADD: {
2206 object *objp = ObjGet(mstruct->objhandle);
2207 if (objp && (objp->type == OBJ_PLAYER)) {
2208 int slot = objp->id;
2209 int total = 0;
2210 if (mstruct->count > 0) {
2211 int id = FindWeaponName(IGNORE_TABLE(mstruct->name));
2212 if (id != -1) {
2213 for (int i = 0; i < mstruct->count; i++) {
2214 if (Players[slot].counter_measures.Add(OBJ_WEAPON, id, objp, mstruct->aux_type, mstruct->aux_id)) {
2215 total++;
2216 }
2217 }
2218 }
2219 }
2220 mstruct->count = total;
2221 if (total)
2222 send_it = 1;
2223 else
2224 send_it = 0;
2225 }
2226 } break;
2227 case MSAFE_OBJECT_ROTDRAG: {
2228 object *objp = ObjGet(mstruct->objhandle);
2229 if (objp) {
2230 objp->mtype.phys_info.rotdrag = mstruct->rot_drag;
2231 send_it = false;
2232 } else {
2233 return;
2234 }
2235 } break;
2236 case MSAFE_OBJECT_TYPE: {
2237 object *objp = ObjGet(mstruct->objhandle);
2238 if (objp) {
2239 objp->type = mstruct->type;
2240 } else {
2241 return;
2242 }
2243 } break;
2244 case MSAFE_OBJECT_ID: {
2245 object *objp = ObjGet(mstruct->objhandle);
2246 if (objp) {
2247 objp->id = mstruct->id;
2248 } else {
2249 return;
2250 }
2251 } break;
2252 case MSAFE_OBJECT_CONTROL_TYPE: {
2253 object *objp = ObjGet(mstruct->objhandle);
2254 if (objp && !(objp->flags & OF_DYING)) {
2255 objp->control_type = mstruct->control_type;
2256 } else {
2257 return;
2258 }
2259 } break;
2260 case MSAFE_OBJECT_FLAGS: {
2261 object *objp = ObjGet(mstruct->objhandle);
2262 if (objp) {
2263 if (Game_mode & GM_MULTI && Netgame.local_role == LR_CLIENT) {
2264 ASSERT(objp->flags & OF_SERVER_OBJECT);
2265 }
2266 if (objp->flags != (uint32_t)mstruct->flags) {
2267 objp->flags = mstruct->flags;
2268 } else {
2269 send_it = false;
2270 }
2271 if (Game_mode & GM_MULTI && Netgame.local_role == LR_CLIENT) {
2272 objp->flags |= OF_SERVER_OBJECT;
2273 }
2274 } else {
2275 return;
2276 }
2277 } break;
2278 case MSAFE_OBJECT_MOVEMENT_TYPE: {
2279 object *objp = ObjGet(mstruct->objhandle);
2280 if (objp) {
2281 objp->movement_type = mstruct->movement_type;
2282 } else {
2283 return;
2284 }
2285 } break;
2286 case MSAFE_OBJECT_CREATION_TIME: {
2287 object *objp = ObjGet(mstruct->objhandle);
2288 if (objp) {
2289 objp->creation_time = mstruct->creation_time;
2290 } else {
2291 return;
2292 }
2293 } break;
2294 case MSAFE_OBJECT_PHYSICS_FLAGS: {
2295 object *objp = ObjGet(mstruct->objhandle);
2296 if (objp) {
2297 if (objp->mtype.phys_info.flags != (uint32_t)mstruct->physics_flags) {
2298 objp->mtype.phys_info.flags = mstruct->physics_flags;
2299 objp->change_flags |= OCF_PHYS_FLAGS;
2300 } else {
2301 send_it = false;
2302 }
2303 } else {
2304 return;
2305 }
2306 } break;
2307 case MSAFE_OBJECT_PARENT: {
2308 object *objp = ObjGet(mstruct->objhandle);
2309 if (objp) {
2310 objp->parent_handle = mstruct->ithandle;
2311 } else {
2312 return;
2313 }
2314 } break;
2315
2316 case MSAFE_WEAPON_CHECK:
2317 Int3(); // hmmmm
2318 break;
2319 case MSAFE_WEAPON_ADD: {
2320 // add/subtract ammo/weapons from a player
2321 // if count>0 and the player doesn't have the weapon it will be added
2322 // objhandle: the player
2323 // index: the weapon
2324 // state: if the weapon is a secondary:
2325 // 1: remove weapon if ammo<=0
2326 // 0: do nothing to the weapon
2327 // if the weapon is a primary
2328 // 1: remove weapon if count==0
2329 // 0: do nothing to the weapon
2330 // count: ammo (if it's an ammo/secondary) of the weapon
2331 object *player = ObjGet(mstruct->objhandle);
2332 ASSERT(mstruct->index >= 0 && mstruct->index < MAX_PRIMARY_WEAPONS + MAX_SECONDARY_WEAPONS);
2333 if (player && player->type == OBJ_PLAYER) {
2334 ship *ship = &Ships[Players[player->id].ship_index];
2335 otype_wb_info *wb = &ship->static_wb[mstruct->index];
2336 ASSERT(wb != NULL);
2337 // check if the player has the weapon
2338 bool have_weapon = PlayerHasWeapon(player->id, mstruct->index);
2339 if (!have_weapon && mstruct->count <= 0) {
2340 // nothing to do
2341 return;
2342 }
2343 if (mstruct->count > 0) {
2344 bool is_ammo = false;
2345 if ((mstruct->index >= SECONDARY_INDEX) || wb->ammo_usage) {
2346 is_ammo = true;
2347 }
2348 // we're going to give the player the weapon and ammo (if needed)
2349 if (!have_weapon) {
2350 AddWeaponToPlayer(player->id, mstruct->index, (is_ammo) ? mstruct->count : 0);
2351 // thats it!
2352 return;
2353 }
2354 // ok, the player already has this weapon, add some ammo if ammo weapon
2355 int old_ammo = Players[player->id].weapon_ammo[mstruct->index];
2356 int added = 1;
2357 // now add ammo if necessary
2358 if (is_ammo) {
2359 added = AddWeaponAmmo(player->id, mstruct->index, mstruct->count);
2360 }
2361 if (added > 0 && player->id == Player_num && old_ammo == 0) {
2362 CheckForWeaponSelect(player->id, mstruct->index);
2363 }
2364 } else {
2365 bool weap_removed = false;
2366 int type;
2367 // we're going to remove the weapon/ammo
2368 if (mstruct->index >= SECONDARY_INDEX) {
2369 type = PW_SECONDARY;
2370 // remove ammo
2371 Players[player->id].weapon_ammo[mstruct->index] += mstruct->count;
2372 if (Players[player->id].weapon_ammo[mstruct->index] < 0)
2373 Players[player->id].weapon_ammo[mstruct->index] = 0;
2374 if (Players[player->id].weapon_ammo[mstruct->index] == 0) {
2375 weap_removed = true;
2376 if (mstruct->state == 1) {
2377 // remove weapon
2378 Players[player->id].weapon_flags &= ~HAS_FLAG(mstruct->index);
2379 }
2380 }
2381 } else {
2382 type = PW_PRIMARY;
2383 // remove the weapon
2384 if (mstruct->state == 1) {
2385 Players[player->id].weapon_flags &= ~HAS_FLAG(mstruct->index);
2386 weap_removed = true;
2387 }
2388 }
2389 if (weap_removed) {
2390 int curr_weapon_index = Players[player->id].weapon[type].index;
2391 if (curr_weapon_index == mstruct->index) {
2392 // check autoselect
2393 if (player->id == Player_num) {
2394 bool select_new;
2395
2396 select_new = AutoSelectWeapon(type, -1);
2397 if (!select_new) {
2398 // AddHUDMessage ("%s",TXT(Static_weapon_names_msg[Players[player->id].weapon[type].index]));
2399 }
2400 }
2401 }
2402 }
2403 }
2404 } else {
2405 Int3(); // come on it isn't even a player!
2406 }
2407 } break;
2408 default:
2409 Int3(); // Illegal type passed to multisafe function
2410 break;
2411 }
2412 if (((Demo_flags == DF_RECORDING) && send_it) ||
2413 (send_it && (Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER))
2414 MultiSendMSafeFunction(type, mstruct);
2415 }
2416 #define SHIELD_BONUS 12.0f
2417 #define ENERGY_BONUS 12.0f
2418 // Returns true if the player has this weapon (this fuction should be moved)
2419 bool PlayerHasWeapon(int slot, int weapon_index) {
2420 if (Players[slot].weapon_flags & HAS_FLAG(weapon_index))
2421 if (weapon_index >= SECONDARY_INDEX)
2422 return (Players[slot].weapon_ammo[weapon_index] > 0); // have secondary only if have ammo
2423 else
2424 return true; // primaries don't check for ammo
2425 else
2426 return false;
2427 }
2428 // Adds weapon ammo to a player, returns 0 if it couldn't
2429 // This function should be moved!
2430 int AddWeaponAmmo(int slot, int weap_index, int ammo) {
2431 // Get pointer to the battery for this weapon
2432 player *player = &Players[slot];
2433 ship *ship = &Ships[player->ship_index];
2434 otype_wb_info *wb = &ship->static_wb[weap_index];
2435 ASSERT(wb != NULL);
2436 // if secondary or primary that uses ammo, then use the ammo
2437 if ((weap_index >= SECONDARY_INDEX) || wb->ammo_usage) {
2438 // figure out much ammo to add
2439 int added = std::min(ship->max_ammo[weap_index] - player->weapon_ammo[weap_index], ammo);
2440 // now add it
2441 player->weapon_ammo[weap_index] += added;
2442 return added;
2443 } else // not an ammo-using weapon
2444 {
2445 Int3(); // trying to add ammo to something that doesn't take it
2446 return 0;
2447 }
2448 }
2449 bool AddPowerupEnergyToPlayer(int id) {
2450 if (Game_mode & GM_MULTI)
2451 return false;
2452 float curr_energy = Players[Player_num].energy;
2453 if (Players[id].energy >= MAX_ENERGY)
2454 return false;
2455 float amount = 10.0f * Diff_general_scalar[DIFF_LEVEL];
2456 curr_energy = std::min<float>(MAX_ENERGY, curr_energy + amount);
2457 Players[id].energy = curr_energy;
2458 return true;
2459 }
2460 // returns true if it was handled
2461 bool HandleCommonPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup);
2462 bool HandleWeaponPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup);
2463 bool HandleCounterMeasurePowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup);
2464 bool HandleInventoryPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup);
2465 // Does whatever magic needs to be done to get the default powerups to work
2466 void msafe_DoPowerup(msafe_struct *mstruct) {
2467 char pname[255];
2468 strcpy(pname, Object_info[MOBJ->id].name);
2469 ASSERT(MOBJ->type == OBJ_POWERUP);
2470 ASSERT(IOBJ->type == OBJ_PLAYER);
2471 uint8_t pickup = 0;
2472 // Now go through and do the magic for each powerup
2473 bool handled = false;
2474 handled = HandleCommonPowerups(pname, mstruct, &pickup);
2475 if (!handled)
2476 handled = HandleWeaponPowerups(pname, mstruct, &pickup);
2477 if (!handled)
2478 handled = HandleCounterMeasurePowerups(pname, mstruct, &pickup);
2479 if (!handled)
2480 handled = HandleInventoryPowerups(pname, mstruct, &pickup);
2481 if (!handled)
2482 return;
2483 // if (Game_mode & GM_MULTI && Netgame.local_role==LR_SERVER)
2484 //{
2485 MultiSendMSafePowerup(mstruct);
2486 //}
2487
2488 // Now remove the object from the world
2489 if (pickup) {
2490 if (((Game_mode & GM_MULTI) && Netgame.local_role == LR_SERVER) || !(Game_mode & GM_MULTI)) {
2491 if (Demo_flags == DF_RECORDING) {
2492 // DemoWriteSetObjDead(MOBJ);
2493 }
2494 SetObjectDeadFlag(MOBJ, true, (bool)(mstruct->playsound != 0));
2495 Sound_system.Play3dSound(SOUND_POWERUP_PICKUP, SND_PRIORITY_HIGH, MOBJ);
2496 }
2497 }
2498 }
2499 // Data for primary powerups
2500 struct {
2501 const char *name;
2502 int weapon_index;
2503 int pickup_msg, already_have_msg, ammo_msg, full_msg;
2504 } powerup_data_primary[] = {
2505 {"Vauss", VAUSS_INDEX, TXI_MSG_VAUSS, TXI_MSG_HAVEVAUSS, TXI_MSG_VAUSSAMMO, TXI_MSG_VAUSSFULL},
2506 {"Napalm", NAPALM_INDEX, TXI_MSG_NAPALM, TXI_MSG_NAPALMHAVE, TXI_MSG_NAPALMFUEL, TXI_MSG_NAPALMFULL},
2507 {"EMDlauncher", EMD_INDEX, TXI_MSG_EMD, TXI_MSG_EMDALREADYHAVE, -1, -1},
2508 {"Microwave", MICROWAVE_INDEX, TXI_MSG_MICROWAVE, TXI_MSG_MICROWAVEHAVE, -1, -1},
2509 {"MassDriver", MASSDRIVER_INDEX, TXI_MSG_MASSDRIVER, TXI_MSG_MASSALREADYHAVE, TXI_MSG_MASSAMMO, TXI_MSG_MASSFULL},
2510 {"SuperLaser", SUPER_LASER_INDEX, TXI_MSG_SUPERLASER, TXI_MSG_SUPERLHAVE, -1, -1},
2511 {"Plasmacannon", PLASMA_INDEX, TXI_MSG_PLASMA, TXI_MSG_PLASMAHAVE, -1, -1},
2512 {"Fusioncannon", FUSION_INDEX, TXI_MSG_FUSION, TXI_MSG_FUSIONHAVE, -1, -1},
2513 {"Omegacannon", OMEGA_INDEX, TXI_MSG_OMEGA, TXI_MSG_OMEGAHAVE, -1, -1},
2514 };
2515 #define NUM_POWERUP_TYPES_PRIMARY (sizeof(powerup_data_primary) / sizeof(*powerup_data_primary))
2516 struct {
2517 const char *name;
2518 int weapon_index;
2519 int added_one_msg, added_multi_msg, full_msg;
2520 } powerup_data_secondary[] = {
2521 {"Frag", FRAG_INDEX, TXI_MSG_FRAG, -1, TXI_MSG_FRAGFULL},
2522 {"ImpactMortar", IMPACTMORTAR_INDEX, TXI_MSG_IMPACTM, -1, TXI_MSG_IMPACTMFULL},
2523 {"NapalmRocket", NAPALMROCKET_INDEX, TXI_MSG_NAPALMR, -1, TXI_MSG_NAPALMRFULL},
2524 {"Cyclone", CYCLONE_INDEX, TXI_MSG_CYCLONE, -1, TXI_MSG_CYCLONEFULL},
2525 {"BlackShark", BLACKSHARK_INDEX, TXI_MSG_BSHARK, -1, TXI_MSG_BSHARKFULL},
2526 {"Concussion", CONCUSSION_INDEX, TXI_MSG_CONC, -1, TXI_MSG_CONCFULL},
2527 {"Homing", HOMING_INDEX, TXI_MSG_HOMING, -1, TXI_MSG_HOMINGFULL},
2528 {"Smart", SMART_INDEX, TXI_MSG_SMART, -1, TXI_MSG_SMARTFULL},
2529 {"Mega", MEGA_INDEX, TXI_MSG_MEGA, -1, TXI_MSG_MEGAFULL},
2530 {"Guided", GUIDED_INDEX, TXI_MSG_GUIDED, -1, TXI_MSG_GUIDEDFULL},
2531 {"4PackHoming", HOMING_INDEX, TXI_MSG_HOMING, TXI_MSG_MULTI_HOMING, TXI_MSG_HOMINGFULL},
2532 {"4PackConc", CONCUSSION_INDEX, TXI_MSG_CONC, TXI_MSG_MULTI_CONC, TXI_MSG_CONCFULL},
2533 {"4PackFrag", FRAG_INDEX, TXI_MSG_FRAG, TXI_MSG_MULTI_FRAG, TXI_MSG_FRAGFULL},
2534 {"4PackGuided", GUIDED_INDEX, TXI_MSG_GUIDED, TXI_MSG_MULTI_GUIDED, TXI_MSG_GUIDEDFULL},
2535 };
2536 #define NUM_POWERUP_TYPES_SECONDARY (sizeof(powerup_data_secondary) / sizeof(*powerup_data_secondary))
2537 struct {
2538 const char *name;
2539 int weapon_index;
2540 int ammo_msg, full_msg;
2541 } powerup_data_ammo[] = {{"Vauss clip", VAUSS_INDEX, TXI_MSG_VAUSSAMMO, TXI_MSG_VAUSSFULL},
2542 {"MassDriverAmmo", MASSDRIVER_INDEX, TXI_MSG_MASSAMMO, TXI_MSG_MASSFULL},
2543 {"NapalmTank", NAPALM_INDEX, TXI_MSG_NAPALMFUEL, TXI_MSG_NAPALMFULL}};
2544 #define NUM_POWERUP_TYPES_AMMO (sizeof(powerup_data_ammo) / sizeof(*powerup_data_ammo))
2545 void ShowAmmoAddedMessage(int weapon_index, int msg_index, int added) {
2546 int added_frac = 0;
2547 if (Ships[Players[Player_num].ship_index].fire_flags[weapon_index] & SFF_TENTHS) {
2548 added_frac = added;
2549 while (added_frac >= 100)
2550 added_frac -= 100;
2551 while (added_frac >= 10)
2552 added_frac -= 10;
2553 added /= 10;
2554 }
2555 AddFilteredHUDMessage(TXT(msg_index), added, added_frac);
2556 }
2557 // See if we should select the specified weapon
2558 void CheckForWeaponSelect(int id, int weapon_index) {
2559 if (id == Player_num) {
2560 bool select_new;
2561 if (weapon_index < SECONDARY_INDEX)
2562 select_new = AutoSelectWeapon(PW_PRIMARY, weapon_index);
2563 else
2564 select_new = AutoSelectWeapon(PW_SECONDARY, weapon_index);
2565 if (!select_new) {
2566 AddFilteredHUDMessage("%s", TXT(Static_weapon_names_msg[weapon_index]));
2567 }
2568 }
2569 }
2570 extern uint8_t AutomapVisMap[MAX_ROOMS];
2571 // New spiffy table-based code
2572 bool HandleWeaponPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup) {
2573 object *player = ObjGet(mstruct->ithandle);
2574 object *powerup = ObjGet(mstruct->objhandle);
2575 int p;
2576 if (!player || !powerup)
2577 return 0;
2578 bool handled = false;
2579 ASSERT(player->type == OBJ_PLAYER);
2580 ASSERT(powerup->control_type == CT_POWERUP);
2581 // Check the primaries
2582 for (p = 0; p < NUM_POWERUP_TYPES_PRIMARY; p++) {
2583 if (!stricmp(powerup_data_primary[p].name, pname)) {
2584 handled = true;
2585 int weapon_index = powerup_data_primary[p].weapon_index;
2586 if (!PlayerHasWeapon(player->id, weapon_index)) {
2587 *pickup = 1;
2588 if (player->id == Player_num)
2589 AddFilteredHUDMessage(TXT(powerup_data_primary[p].pickup_msg));
2590 AddWeaponToPlayer(player->id, weapon_index, powerup->ctype.powerup_info.count);
2591 } else { // we already have this weapon
2592 // If multiplayer, don't do anything (except print the message), so only do stuff if not multiplayer
2593 if (!(Game_mode & GM_MULTI)) {
2594 // If this is an ammo weapon, give the player the ammo
2595 if (powerup->ctype.powerup_info.count > 0) {
2596 int old_ammo = Players[player->id].weapon_ammo[weapon_index];
2597 int added = AddWeaponAmmo(player->id, weapon_index, powerup->ctype.powerup_info.count);
2598 if (added) { // got ammo, so remove powerup
2599 *pickup = 1;
2600 if (player->id == Player_num) {
2601 ShowAmmoAddedMessage(weapon_index, powerup_data_primary[p].ammo_msg, added);
2602 if (old_ammo == 0)
2603 CheckForWeaponSelect(player->id, weapon_index);
2604 }
2605 } else { // did not get ammo from powerup, so say full
2606 if (player->id == Player_num)
2607 AddFilteredHUDMessage(TXT(powerup_data_primary[p].full_msg));
2608 }
2609 } else { // not an ammo weapon (or has no ammo)
2610 // Give the player energy & remove powerup, if energy not full,
2611 if (AddPowerupEnergyToPlayer(player->id))
2612 *pickup = 1;
2613 }
2614 } else {
2615 if (player->id == Player_num)
2616 AddFilteredHUDMessage(TXT_ALREADY_HAVE_WEAPON);
2617 }
2618 }
2619 }
2620 }
2621 // Check the secondaries
2622 for (p = 0; p < NUM_POWERUP_TYPES_SECONDARY; p++) {
2623 if (!stricmp(powerup_data_secondary[p].name, pname)) {
2624 handled = true;
2625 int weapon_index = powerup_data_secondary[p].weapon_index;
2626 // Does the player have any now?
2627 bool has_weapon = PlayerHasWeapon(player->id, weapon_index);
2628 // Determine how much to add
2629 int added = AddWeaponAmmo(player->id, weapon_index, powerup->ctype.powerup_info.count);
2630 // Pickup powerup if multiplayer or if got any ammo from it
2631 *pickup = (Game_mode & GM_MULTI) || (added != 0);
2632
2633 // Show message
2634 if (player->id == Player_num) {
2635 if (added > 1) {
2636 ASSERT(powerup_data_secondary[p].added_multi_msg != -1);
2637 AddFilteredHUDMessage(TXT(powerup_data_secondary[p].added_multi_msg), added);
2638 } else if (added == 1)
2639 AddFilteredHUDMessage(TXT(powerup_data_secondary[p].added_one_msg));
2640 else
2641 AddFilteredHUDMessage(TXT(powerup_data_secondary[p].full_msg));
2642 }
2643 // Give the player the weapon if didn't already have it
2644
2645 ship *ship = &Ships[Players[player->id].ship_index];
2646 otype_wb_info *wb = &ship->static_wb[weapon_index];
2647
2648 if (!has_weapon || (player->id == Player_num && wb->ammo_usage > 1 &&
2649 wb->ammo_usage == Players[player->id].weapon_ammo[weapon_index]))
2650 AddWeaponToPlayer(player->id, weapon_index, 0);
2651 }
2652 }
2653 // Check the ammo powerups
2654 for (p = 0; p < NUM_POWERUP_TYPES_AMMO; p++) {
2655 if (!stricmp(pname, powerup_data_ammo[p].name)) {
2656 handled = true;
2657 int weapon_index = powerup_data_ammo[p].weapon_index;
2658 ASSERT(weapon_index < SECONDARY_INDEX);
2659 // Get the ammo from this weapon
2660 int old_ammo = Players[player->id].weapon_ammo[weapon_index];
2661 int added = AddWeaponAmmo(player->id, weapon_index, powerup->ctype.powerup_info.count);
2662 // Pickup powerup if multiplayer or if got any ammo from it
2663 *pickup = (Game_mode & GM_MULTI) || (added != 0);
2664
2665 if (player->id == Player_num) {
2666 if (added > 0)
2667 ShowAmmoAddedMessage(weapon_index, powerup_data_ammo[p].ammo_msg, added);
2668 else
2669 AddFilteredHUDMessage(TXT(powerup_data_ammo[p].full_msg));
2670 }
2671 // Check to select the weapon
2672 if (added && PlayerHasWeapon(player->id, weapon_index) && (old_ammo == 0))
2673 CheckForWeaponSelect(player->id, weapon_index);
2674 }
2675 }
2676 return handled;
2677 }
2678 // returns true if it was handled
2679 bool HandleCommonPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup) {
2680 int pnum = IOBJ->id;
2681 bool handled = false;
2682 // Shield bonus
2683 if (!stricmp("Shield", pname)) {
2684 handled = true;
2685 // If this guy is already at max shields, then don't do anything
2686 if ((IOBJ->shields) >= MAX_SHIELDS) {
2687 if (pnum == Player_num)
2688 AddFilteredHUDMessage(TXT_MAXSHIELDS);
2689 } else {
2690 // Pick it up
2691 *pickup = 1;
2692 float addval = SHIELD_BONUS * Diff_shield_energy_scalar[DIFF_LEVEL];
2693 if (IOBJ->shields + addval > MAX_SHIELDS)
2694 addval = MAX_SHIELDS - IOBJ->shields;
2695
2696 IOBJ->shields += addval;
2697 if (pnum == Player_num)
2698 AddFilteredHUDMessage(TXT_SHIELDBOOST, (int)IOBJ->shields);
2699 }
2700 }
2701 // ENERGY POWERUP
2702 else if (!stricmp("Energy", pname)) {
2703 handled = true;
2704 float addval = ENERGY_BONUS * Diff_shield_energy_scalar[DIFF_LEVEL];
2705 addval = std::min(addval, MAX_ENERGY - Players[pnum].energy);
2706 Players[pnum].energy += addval;
2707 // Pick up if multiplayer or added
2708 if ((Game_mode & GM_MULTI) || (addval > 0))
2709 *pickup = 1;
2710 if (pnum == Player_num)
2711 AddFilteredHUDMessage((addval > 0) ? TXT_MSG_ENERGY : TXT_MAXENERGY);
2712 }
2713 // Quad Laser
2714 else if (!stricmp("QuadLaser", pname)) {
2715 handled = true;
2716 object *pobj = &Objects[Players[pnum].objnum];
2717 if (!(pobj->dynamic_wb[LASER_INDEX].flags & DWBF_QUAD)) {
2718 // player doesn't have Quad Lasers
2719
2720 if (pnum == Player_num)
2721 AddFilteredHUDMessage(TXT_QUADLASER);
2722 *pickup = 1;
2723 pobj->dynamic_wb[LASER_INDEX].flags |= DWBF_QUAD;
2724 pobj->dynamic_wb[SUPER_LASER_INDEX].flags |= DWBF_QUAD;
2725 // add them to the inventory so we can spew it
2726 static int quad_id = -2;
2727 if (quad_id == -2)
2728 quad_id = FindObjectIDName(IGNORE_TABLE(pname));
2729 if (quad_id > -1) {
2730 Players[pnum].inventory.Add(OBJ_POWERUP, quad_id, NULL, -1, -1, INVAF_LEVELLAST | INVAF_TIMEOUTONSPEW);
2731 }
2732 } else if (pnum == Player_num)
2733 AddFilteredHUDMessage(TXT_MSG_QUADHAVE);
2734 }
2735 // FullMap Powerup
2736 else if (!stricmp("FullMap", pname)) {
2737 handled = true;
2738 if (pnum == Player_num) {
2739 AddFilteredHUDMessage(TXT_FULLMAP);
2740
2741 for (int i = 0; i < MAX_ROOMS; i++) {
2742 if (!(Rooms[i].flags & RF_SECRET))
2743 AutomapVisMap[i] = 1;
2744 }
2745 }
2746
2747 *pickup = 1;
2748 }
2749 // Thief stolen automap
2750 else if (!stricmp("ThiefAutoMap", pname)) {
2751 handled = true;
2752 if (pnum == Player_num) {
2753 AddFilteredHUDMessage(TXT_RETURNEDAUTOMAP);
2754 }
2755 ThiefReturnItem(IOBJ->handle, THIEFITEM_AUTOMAP);
2756 *pickup = 1;
2757 }
2758 // Thief stolen headlight
2759 else if (!stricmp("HeadlightPowerup", pname)) {
2760 handled = true;
2761 if (!ThiefPlayerHasItem(IOBJ->handle, THIEFITEM_HEADLIGHT)) {
2762 if (pnum == Player_num) {
2763 AddFilteredHUDMessage(TXT_RETURNEDHEADLIGHT);
2764 }
2765 ThiefReturnItem(IOBJ->handle, THIEFITEM_HEADLIGHT);
2766 *pickup = 1;
2767 } else {
2768 if (pnum == Player_num) {
2769 AddFilteredHUDMessage(TXT_HAVEHEADLIGHT);
2770 }
2771 }
2772 }
2773 // Invulnerability
2774 else if (!stricmp(pname, "Invulnerability")) {
2775 handled = true;
2776 if (!(Players[pnum].flags & PLAYER_FLAGS_INVULNERABLE)) {
2777 float time_period = 30.0f; // 30 seconds
2778 MakePlayerInvulnerable(pnum, time_period, true);
2779 *pickup = 1;
2780 } else if (pnum == Player_num) {
2781 AddFilteredHUDMessage(TXT_INVULNALREADY);
2782 }
2783 }
2784 // Cloak
2785 else if (!stricmp(pname, "Cloak")) {
2786 handled = true;
2787 if (IOBJ->effect_info) {
2788 if (!((IOBJ->effect_info->type_flags & EF_FADING_OUT) || (IOBJ->effect_info->type_flags & EF_CLOAKED))) {
2789 float time_period = 30.0f; // 30 seconds
2790 MakeObjectInvisible(IOBJ, time_period);
2791 *pickup = 1;
2792 } else if (pnum == Player_num) {
2793 AddFilteredHUDMessage(TXT_CLOAKALREADY);
2794 }
2795 }
2796 }
2797 return handled;
2798 }
2799 bool HandleCounterMeasurePowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup) {
2800 bool handled = false;
2801 // Chaff
2802 if (!stricmp("Chaff", pname)) {
2803 handled = true;
2804 int pnum = IOBJ->id;
2805 int added_count = 0;
2806 int weapon_id = FindWeaponName("Chaff");
2807
2808 if (weapon_id != -1) {
2809 int amount = 12 - Players[pnum].counter_measures.GetTypeIDCount(OBJ_WEAPON, weapon_id);
2810 if (amount > 4)
2811 amount = 4;
2812 if (amount > 0) {
2813 for (int c = 0; c < amount; c++) {
2814 if (Players[pnum].counter_measures.AddCounterMeasure(weapon_id, MOBJ->type, MOBJ->id)) {
2815 added_count++;
2816 } else
2817 break;
2818 }
2819 if (added_count) {
2820 // Pick it up
2821 *pickup = 1;
2822 }
2823 if (pnum == Player_num) {
2824 if (added_count == 1) {
2825 AddFilteredHUDMessage(TXT_CHAFF);
2826 } else if (added_count > 1) {
2827 AddFilteredHUDMessage(TXT_MSG_MULTI_CHAFFS, added_count);
2828 } else {
2829 AddFilteredHUDMessage(TXT_COUNTERMEASUREFULL);
2830 }
2831 }
2832 } else if (pnum == Player_num) {
2833 AddFilteredHUDMessage(TXT_CHAFFSFULL);
2834 }
2835 }
2836 }
2837 // Betty4pack
2838 else if (!stricmp("Betty4Pack", pname)) {
2839 handled = true;
2840 int pnum = IOBJ->id;
2841 int added_count = 0;
2842 int weapon_id = FindWeaponName("Betty");
2843
2844 if (weapon_id != -1) {
2845 int amount = 12 - Players[pnum].counter_measures.GetTypeIDCount(OBJ_WEAPON, weapon_id);
2846 if (amount > 4)
2847 amount = 4;
2848 if (amount > 0) {
2849 for (int c = 0; c < amount; c++) {
2850 if (Players[pnum].counter_measures.AddCounterMeasure(weapon_id, MOBJ->type, MOBJ->id)) {
2851 added_count++;
2852 } else
2853 break;
2854 }
2855 if (added_count) {
2856 // Pick it up
2857 *pickup = 1;
2858 }
2859 if (pnum == Player_num) {
2860 if (added_count == 1) {
2861 AddFilteredHUDMessage(TXT_BETTY);
2862 } else if (added_count > 1) {
2863 AddFilteredHUDMessage(TXT_MSG_MULTI_BETTY, added_count);
2864 } else {
2865 AddFilteredHUDMessage(TXT_COUNTERMEASUREFULL);
2866 }
2867 }
2868 } else if (pnum == Player_num) {
2869 AddFilteredHUDMessage(TXT_BETTYFULL);
2870 }
2871 }
2872 }
2873 // Seeker3pack
2874 else if (!stricmp("Seeker3Pack", pname)) {
2875 handled = true;
2876 int pnum = IOBJ->id;
2877 int added_count = 0;
2878 int weapon_id = FindWeaponName("SeekerMine");
2879
2880 if (weapon_id != -1) {
2881 int amount = 12 - Players[pnum].counter_measures.GetTypeIDCount(OBJ_WEAPON, weapon_id);
2882 if (amount > 3)
2883 amount = 3;
2884 if (amount > 0) {
2885 for (int c = 0; c < amount; c++) {
2886 if (Players[pnum].counter_measures.AddCounterMeasure(weapon_id, MOBJ->type, MOBJ->id)) {
2887 added_count++;
2888 } else
2889 break;
2890 }
2891 if (added_count) {
2892 // Pick it up
2893 *pickup = 1;
2894 }
2895 if (pnum == Player_num) {
2896 if (added_count == 1) {
2897 AddFilteredHUDMessage(TXT_SEEKERMINE);
2898 } else if (added_count > 1) {
2899 AddFilteredHUDMessage(TXT_MSG_MULTI_SEEKERS, added_count);
2900 } else {
2901 AddFilteredHUDMessage(TXT_COUNTERMEASUREFULL);
2902 }
2903 }
2904 } else if (pnum == Player_num) {
2905 AddFilteredHUDMessage(TXT_SEEKERFULL);
2906 }
2907 }
2908 }
2909 // Gunboy
2910 else if (!stricmp("GunboyPowerup", pname)) {
2911 handled = true;
2912 int pnum = IOBJ->id;
2913 int added_count = 0;
2914 int weapon_id = FindWeaponName("GunBoy");
2915
2916 if (weapon_id != -1) {
2917 int amount = 4 - Players[pnum].counter_measures.GetTypeIDCount(OBJ_WEAPON, weapon_id);
2918 if (amount > 1)
2919 amount = 1;
2920 if (amount > 0) {
2921 for (int c = 0; c < amount; c++) {
2922 if (Players[pnum].counter_measures.AddCounterMeasure(weapon_id, MOBJ->type, MOBJ->id)) {
2923 added_count++;
2924 } else
2925 break;
2926 }
2927 if (added_count) {
2928 // Pick it up
2929 *pickup = 1;
2930 }
2931 if (pnum == Player_num) {
2932 if (added_count == 1) {
2933 AddFilteredHUDMessage(TXT_GUNBOY);
2934 } else if (added_count > 1) {
2935 AddFilteredHUDMessage(TXT_MSG_MULTI_GUNBOY, added_count);
2936 } else {
2937 AddFilteredHUDMessage(TXT_COUNTERMEASUREFULL);
2938 }
2939 }
2940 } else if (pnum == Player_num) {
2941 AddFilteredHUDMessage(TXT_GUNBOYFULL);
2942 }
2943 }
2944 }
2945 // ProxMine
2946 else if (!stricmp("ProxMinePowerup", pname)) {
2947 handled = true;
2948 int pnum = IOBJ->id;
2949 int added_count = 0;
2950 int weapon_id = FindWeaponName("ProxMine");
2951
2952 if (weapon_id != -1) {
2953 int amount = 12 - Players[pnum].counter_measures.GetTypeIDCount(OBJ_WEAPON, weapon_id);
2954 if (amount > 4)
2955 amount = 4;
2956 if (amount > 0) {
2957 for (int c = 0; c < amount; c++) {
2958 if (Players[pnum].counter_measures.AddCounterMeasure(weapon_id, MOBJ->type, MOBJ->id)) {
2959 added_count++;
2960 } else
2961 break;
2962 }
2963 if (added_count) {
2964 // Pick it up
2965 *pickup = 1;
2966 }
2967 if (pnum == Player_num) {
2968 if (added_count == 1) {
2969 AddFilteredHUDMessage(TXT_PROXMINE);
2970 } else if (added_count > 1) {
2971 AddFilteredHUDMessage(TXT_PROXMINECOUNT, added_count);
2972 } else {
2973 AddFilteredHUDMessage(TXT_COUNTERMEASUREFULL);
2974 }
2975 }
2976 } else if (pnum == Player_num) {
2977 AddFilteredHUDMessage(TXT_PROXMINEFULL);
2978 }
2979 }
2980 }
2981 return handled;
2982 }
2983 bool HandleInventoryPowerups(char *pname, msafe_struct *mstruct, uint8_t *pickup) {
2984 bool handled = false;
2985 int pnum = IOBJ->id;
2986 // Afterburner cooler
2987 if (!stricmp("Afterburner", pname)) {
2988 handled = true;
2989 int ab_id = FindObjectIDName("Afterburner");
2990 if (ab_id != -1) {
2991
2992 int inv_count = Players[pnum].inventory.GetTypeIDCount(OBJ_POWERUP, ab_id);
2993 if (inv_count == 0) {
2994 // pickit up
2995 *pickup = 1;
2996 Players[pnum].inventory.Add(OBJ_POWERUP, ab_id, NULL, -1, -1, INVAF_TIMEOUTONSPEW, TXT_ABCOOLER);
2997 if (pnum == Player_num)
2998 AddFilteredHUDMessage(TXT_AFTERBURNERCOOLER);
2999 } else if (pnum == Player_num) {
3000 AddFilteredHUDMessage(TXT_ABCOOLERHAVE);
3001 }
3002 }
3003 }
3004 // Energy->Shield Converter
3005 else if (!stricmp("Converter", pname)) {
3006 handled = true;
3007 int es_id = FindObjectIDName("Converter");
3008 if (es_id != -1) {
3009 int inv_count = Players[pnum].inventory.GetTypeIDCount(OBJ_POWERUP, es_id);
3010 if (inv_count == 0) {
3011 // pick it up
3012 *pickup = 1;
3013 Players[pnum].inventory.Add(OBJ_POWERUP, es_id, NULL, -1, -1, INVAF_TIMEOUTONSPEW);
3014 if (pnum == Player_num)
3015 AddFilteredHUDMessage(TXT_ETOSCONVERTER);
3016 } else if (pnum == Player_num) {
3017 AddFilteredHUDMessage(TXT_ETOSCONVHAVE);
3018 }
3019 }
3020 }
3021 return handled;
3022 }