Debian Codegraph @

Descent3/Player.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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/Player.cpp $
21 * $Revision: 331 $
22 * $Date: 10/22/01 12:43p $
23 * $Author: Matt $
24 *
25 * Code for dealing with players
26 *
27 * $Log: /DescentIII/Main/Player.cpp $
28 *
29 * 331 10/22/01 12:43p Matt
30 * On player death/exit, don't try to spew a red guidebot if Mercenary is
31 * not installed.
32 *
33 * 330 3/20/00 12:19p Matt
34 * Merge of Duane's post-1.3 changes.
35 * Change for no avilable vis effects.
36 *
37 * 329 1/26/00 9:20p Jeff
38 * added support for IntelliVIBE DLL
39 *
40 * 328 11/02/99 1:56p Chris
41 * Fixed bug with black pyro spewing a blue gb on death
42 *
43 * 327 10/21/99 9:28p Jeff
44 * B.A. Macintosh code merge
45 *
46 * 326 10/20/99 5:40p Chris
47 * Added the Red Guidebot
48 *
49 * 325 7/28/99 3:47p Kevin
50 * Mac!
51 *
52 * 324 7/26/99 4:56p Kevin
53 * more demo bug fixes
54 *
55 * 323 7/26/99 12:40p Kevin
56 * Fixed some multiplayer client recorded demo bugs
57 *
58 * 322 7/08/99 5:45p Jason
59 * Bug fixes for the patch
60 *
61 * 321 5/23/99 3:06a Jason
62 * fixed bug with player rankings not being updated correctly
63 *
64 * 320 5/21/99 7:09p Jason
65 * fixed some weird multiplayer rejoin anomalies
66 *
67 * 319 5/20/99 7:54p 3dsmax
68 * added better memory support changing ships
69 *
70 * 318 5/20/99 2:53p Jason
71 * made autowaypoints work in coop
72 *
73 * 317 5/20/99 2:48a Matt
74 * Auto-waypoints now stored & used per player. Manual waypoints will all
75 * players, once Jason makes it work.
76 *
77 * 316 5/19/99 3:25p Jason
78 * fixed wrong ordering of InitObjectScripts and MultiSendObject
79 *
80 * 315 5/17/99 11:03a Matt
81 * When initializing the player ship for a new level, limit the ammo to
82 * the max the ship can carry.
83 *
84 * 314 5/13/99 3:41p Ardussi
85 * changes for compiling on the Mac
86 *
87 * 313 5/12/99 3:26p Jason
88 * made terrain damage effect multiplayer friendly
89 *
90 * 312 5/10/99 10:23p Ardussi
91 * changes to compile on Mac
92 *
93 * 311 5/10/99 9:25p Jeff
94 * first phase of Rock 'n' Ride support added
95 *
96 * 310 5/10/99 2:01a Jason
97 * make player invulnerable for 2 seconds during respawn in a single
98 * player game
99 *
100 * 309 5/08/99 4:12p Chris
101 * Added AI hearing noises... version 1
102 *
103 * 308 5/07/99 1:44p Chris
104 * Made in-game cinematics use the ORIENT_PATH_NODE for player ships
105 *
106 * 307 5/05/99 2:33p Jason
107 * Room 18 face 116: No connection for edge 3
108 * Room 18 face 116: No connection for edge 4
109 * Room 18 face 116: No connection for edge 5
110 * Room 18 face 140: No connection for edge 0
111 * Fixed some multiplayer issues
112 *
113 * 306 5/05/99 1:32a Jeff
114 * save/restore player energy also
115 *
116 * 305 5/05/99 1:28a Jeff
117 * save/restore player's shields in single player game if they are over
118 * 100
119 *
120 * 304 5/04/99 9:27p Jeff
121 * cheaters don't win! (no score for cheaters)
122 *
123 * 303 5/04/99 7:09p Jason
124 * changed sun damage effect just a little
125 *
126 * 302 4/29/99 3:03p Jason
127 * fixed player popping in and out in a multiplayer game
128 *
129 * 301 4/28/99 5:55p Matt
130 * Don't spew powerup for secondaries if have none. This fixes spewing
131 * multipacks with count == 0.
132 *
133 * 300 4/28/99 5:10p Jeff
134 * fixed inventory spew in multiplayer (with non-spewable items)
135 *
136 * 299 4/28/99 2:25a Jeff
137 * added call to add guidebot in selected multiplayer games to the clients
138 *
139 * 298 4/27/99 10:33p Matt
140 * Added code to spew multi-pack powerups upon death if available for a
141 * weapon. Now you're not limited to spewing three homing missiles, for
142 * example -- you can spew a multi-pack with 8 missiles in it.
143 *
144 * 297 4/27/99 4:27p Jeff
145 * added player respawn osiris event
146 *
147 * 296 4/27/99 4:44a Jeff
148 * only add guidebots to inventory in a single player game...must figure
149 * out a way to handle initial join of multiplayer
150 *
151 * 295 4/27/99 1:38a Jason
152 * fixed sparse array bug with players
153 *
154 * 294 4/26/99 7:53p Jason
155 * temp fix for multiplayer waypoints
156 *
157 * 293 4/24/99 10:39p Samir
158 * turn off any current ship engine sounds if ship noises are turned off
159 *
160 * 292 4/24/99 8:40p Samir
161 * ship toggle sounds implemented.
162 *
163 * 291 4/24/99 7:22p Jason
164 * fixed another respawn problem
165 *
166 * 290 4/24/99 6:45p Jeff
167 * added functions for theif so he can steal things other than weapons
168 *
169 * 289 4/24/99 2:20a Chris
170 * Added the Neutral_till_hit flag
171 *
172 * 288 4/23/99 1:56a Matt
173 * Added system for counting kills of friendly objects
174 *
175 * 287 4/22/99 4:31p Jason
176 * fixed team spawning problems
177 *
178 * 286 4/21/99 11:05a Kevin
179 * new ps_rand and ps_srand to replace rand & srand
180 *
181 * 285 4/14/99 3:57a Jeff
182 * fixed case mismatch in #includes
183 *
184 * 284 4/10/99 5:56p Matt
185 * Cleaned up object initialization code, including create object & load
186 * object.
187 *
188 * 283 4/09/99 7:04p Jason
189 * changed some texture defines
190 *
191 * 282 4/06/99 6:25p Jason
192 * various fixes for multiplayer
193 *
194 * 281 4/06/99 6:02p Matt
195 * Added score system
196 *
197 * 280 4/06/99 2:08p Jason
198 * fixed crashes with dying models not being set
199 *
200 * 279 4/05/99 3:34p Matt
201 * Cleaned up player start flags
202 *
203 * 278 4/05/99 10:54a Matt
204 * Added auto-waypoint system
205 *
206 * 277 4/03/99 2:20p Jason
207 * added better heat damage effect
208 *
209 * 276 4/02/99 6:31p Jason
210 * Fixed multiplayer powerup/player start bugs
211 *
212 * 275 4/02/99 3:55p Chris
213 * Fixed or at least commented about guidebot bugs
214 *
215 * 274 3/31/99 10:27a Samir
216 * code to reset auto select states when ship is initializiaed and code to
217 * save and load these states from disk.
218 *
219 * 273 3/23/99 12:33p Kevin
220 * More post level results improvements
221 *
222 * 272 3/16/99 6:43p Kevin
223 * OEM Split fixes
224 *
225 * 271 3/12/99 7:45p Jeff
226 * handle demo items (lifeleft, player change type, etc). Reset quad fire
227 * masks on inventory spew.
228 *
229 * 270 3/11/99 6:31p Jeff
230 * numerous fixes to demo system in multiplayer games (when
231 * recording/playback a demo in a multiplayer game)
232 *
233 * 269 3/10/99 2:25p Kevin
234 * Save/Load and Demo file fixes
235 *
236 * 268 3/09/99 6:34p Kevin
237 * Made the training mission not be branching, and fixed the crash with
238 * people dying in the demo playback
239 *
240 * 267 3/09/99 6:17p Jason
241 * fixed observer mode changing
242 *
243 * 266 3/09/99 3:19p Jason
244 * fixed persistent player death message in multiplayer game
245 *
246 * 265 3/08/99 5:14p Jason
247 * added delay to player respawn after death
248 *
249 * 264 3/05/99 11:57a Jason
250 * fixes for OEM
251 *
252 * 263 3/04/99 7:39p Matt
253 * Added sound effects to FreeSpace-style persistent HUD messages.
254 *
255 * 262 3/03/99 5:35p Matt
256 * Added fade-out for goal complete messages
257 *
258 * 261 3/03/99 3:38a Samir
259 * reset reticle when you die.
260 *
261 * 260 3/02/99 2:50p Samir
262 * hud observer mode works with rest of hud.
263 *
264 * 259 3/02/99 1:17p Jason
265 * made player textures play at a fixed rate
266 *
267 * 258 3/02/99 12:22p Matt
268 * Revisions to weapon & ammo powerups. Not fully tested.
269 *
270 * 257 3/01/99 7:20p Chris
271 * Fixed dist problems with finding nearby objects
272 *
273 * 256 3/01/99 4:17p Jeff
274 *
275 * 255 2/25/99 8:55p Jeff
276 * Inventory supports level change persistant items. Inventory supports
277 * time-out objects. Inventory Reset changed (takes a level of reset
278 * now). Quad lasers stay across level change (single player). Guidebot
279 * bug fixed (now back in ship on level start). Quads time out when
280 * spewed. Invulnerability and cloak powerups no longer use game
281 * event/callbacks, so they can be saved in game saves (moved to
282 * MakePlayerInvulnerable and MakeObjectInvisible)
283 *
284 * 254 2/25/99 10:28a Jason
285 * made player able to fire flares in netgames
286 *
287 * 253 2/24/99 11:25a Matt
288 * Small improvement
289 *
290 * 251 2/23/99 7:35p Jeff
291 * handle not spewing of inventory items marked as such
292 *
293 * 250 2/22/99 2:04p Jason
294 * added different damages for players and generics
295 *
296 * 249 2/18/99 5:27p Matt
297 * Added color parm to AddPersistentHUDMessage() and fixed the timeout.
298 *
299 * 248 2/17/99 2:08p Jason
300 * fixed observermode bug
301 *
302 * 247 2/17/99 2:04p Jason
303 * changed spew timeouts just a little
304 *
305 * 246 2/16/99 3:47p Jason
306 * added marker updates to multiplayer server stream
307 *
308 * 245 2/15/99 7:50p Jeff
309 * new pilot file class and read/write system checked in...should be more
310 * robust than old
311 *
312 * 244 2/15/99 11:22a Jason
313 * took out client-side prediciton
314 *
315 * 243 2/13/99 12:32a Jeff
316 * updated inventory spew to handle 'new' inventory system. Inventory
317 * reset takes a different parameter too now.
318 *
319 * 242 2/12/99 3:38p Jason
320 * added client side interpolation
321 *
322 * 241 2/11/99 1:22a Jeff
323 * made function to switch a player into AI mode, converted code that did
324 * this to call this function.
325 *
326 * 240 2/10/99 1:47p Matt
327 * Changed object handle symbolic constants
328 *
329 * 239 2/09/99 6:53p Jeff
330 * implemented 'typing inidcator' in multiplayer...players that are typing
331 * messages have an icon on them
332 *
333 * 238 2/08/99 5:26p Jeff
334 * removed all calls to MultiSendRemoveObject, incorportated into
335 * SetObjectDeadFlag. Fixes sequencing issues in multiplayer
336 *
337 * 237 2/08/99 3:06a Jeff
338 * added a function to reset a player's control type
339 *
340 * 236 2/06/99 10:03p Matt
341 * Added keys system
342 *
343 * 235 2/04/99 11:20a Jason
344 * added waypoint message
345 *
346 * 234 2/04/99 11:01a Jason
347 * added anti cheating to multiplayer
348 *
349 * 233 2/03/99 4:26p Jason
350 * made multiplayer coop actually work!
351 *
352 * 232 2/03/99 1:50a Jeff
353 * fixed bug on checking if a player ship is available (if -1 is passed
354 * in)
355 *
356 * 231 2/01/99 4:25p Jeff
357 * fixed player invulnerabilty after cinematic sequence and death bug
358 *
359 * 230 2/01/99 12:56p Jeff
360 * correctly restore hud if in cinematics
361 *
362 * 229 1/31/99 7:26p Matt
363 * Renamed a bunch of functions to have HUD capitalized
364 *
365 * 228 1/29/99 7:13p Jeff
366 * localization
367 *
368 * 227 1/28/99 6:17p Jason
369 * added markers
370 *
371 * 226 1/27/99 6:37p Jason
372 * fixed player spawning over terrain
373 *
374 * 225 1/21/99 11:15p Jeff
375 * pulled out some structs and defines from header files and moved them
376 * into seperate header files so that multiplayer dlls don't require major
377 * game headers, just those new headers. Side effect is a shorter build
378 * time. Also cleaned up some header file #includes that weren't needed.
379 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
380 * manage.h and multi.h
381 *
382 * 224 1/20/99 4:23p Jason
383 * made player flags work again
384 *
385 * 223 1/18/99 6:18p Kevin
386 * Added controller masking to DALLAS
387 *
388 * 222 1/15/99 7:52p Chris
389 * Updated ObjSetPos() to include a f_update_attach_children flag
390 *
391 * 221 1/14/99 4:24p Jason
392 * made damage effect go away much faster
393 *
394 * 220 1/13/99 2:29a Chris
395 * Massive AI, OSIRIS update
396 *
397 * 219 1/12/99 7:11p Jeff
398 * init scripts on player spew
399 *
400 * 218 1/08/99 2:56p Samir
401 * Ripped out OSIRIS1.
402 *
403 * 217 1/06/99 12:34p Jason
404 * misc changes for multiplayer
405 *
406 * 216 12/01/98 3:35p Matt
407 * Got rear view working.
408 *
409 * 215 11/23/98 1:50p Jason
410 * added thruster sounds
411 *
412 * 214 11/13/98 12:30p Jason
413 * changes for weapons
414 *
415 * 213 11/11/98 7:18p Jeff
416 * changes made so that a dedicated server's team is always -1 (team game
417 * or not)
418 *
419 * 212 11/11/98 11:41a Jason
420 * added sunlight damage
421 *
422 * 211 11/06/98 11:39a Chris
423 * Robots with flamethrowers and Omega cannons work in single player
424 *
425 * 210 11/03/98 6:16p Chris
426 * Starting to make on/off and spray weapons accessable to robots
427 *
428 * 209 10/29/98 4:54p Jason
429 * made ClearTransientObjects not work in multiplayer
430 *
431 * 208 10/28/98 5:25p Jason
432 * fixed player death problems in multiplayer
433 *
434 * 207 10/22/98 10:45p Samir
435 * try more death options.
436 *
437 * 206 10/22/98 2:58p Chris
438 * Difficulty levels are in beta
439 *
440 * 205 10/19/98 9:22p Matt
441 * Stop effects sound when resetting player object.
442 *
443 * 204 10/19/98 11:35a Chris
444 * Made a change in when the player gets GB
445 *
446 * 203 10/18/98 11:11p Matt
447 * Added call to ClearTransientObjects() and cleaned up some sequencing
448 * stuff.
449 *
450 * 202 10/18/98 7:27p Samir
451 * spin on y axis for d2 death.
452 *
453 * 201 10/17/98 3:07p Jason
454 * respawn players not near each other
455 *
456 * 200 10/16/98 1:54p Kevin
457 * Changes for Demo Beta 4
458 *
459 * 199 10/14/98 4:27p Samir
460 * use new persistent hud message system for death message.
461 *
462 * 198 10/14/98 1:02p Jason
463 * fixed FindSoundName issues
464 *
465 * 197 10/13/98 4:12p Jason
466 * toned down speed of observer mode
467 *
468 * 196 10/13/98 3:41p Kevin
469 * bug fixes
470 *
471 * 195 10/13/98 2:31p Jason
472 * automatically create new player starts
473 *
474 * 194 10/13/98 1:53p Jason
475 * added some asserts to track down explosion bug
476 *
477 * 193 10/08/98 5:49p Sean
478 * (Jeff) fixed reset of Quad fire flag when resetting a player ship
479 *
480 * 192 10/08/98 3:36p Jason
481 * fixes for the demo
482 *
483 * 191 10/07/98 9:29p Jeff
484 * reset quad firing masks on init new ship
485 *
486 * 190 10/07/98 12:35p Jason
487 * fixed player cameras going from level to level
488 *
489 * 189 10/05/98 6:48p Jason
490 * took out annoying mprintf
491 *
492 * 188 10/03/98 8:05p Matt
493 * Added asserts
494 *
495 * 187 10/02/98 8:54p Jason
496 * fixed bad parentin on badass damage
497 *
498 * 186 10/02/98 12:31p Samir
499 * restored player breakup with fixed code (from renderobject.cpp too).
500 *
501 * 185 10/01/98 11:30a Jeff
502 * made the observer mode events into just a client event
503 *
504 * 184 9/30/98 4:05p Jason
505 * more parenting fun
506 *
507 * 183 9/30/98 3:49p Jeff
508 * added events for when a player enters/exits observer mode
509 *
510 * 182 9/30/98 3:17p Jason
511 * fixed countermeasure spewing problem
512 *
513 * 181 9/29/98 1:59p Jason
514 * don't do breakup death
515 *
516 * 180 9/28/98 8:39p Jason
517 * give spewed objects parents
518 *
519 * 179 9/28/98 10:59a Samir
520 * clarified passing of pointer to CreateFireball in
521 * PlayerShipSpewPartSub. Adding two vectors should return a vector
522 * reference, and that should be valid, but I guess not.
523 *
524 * 178 9/23/98 6:07p Samir
525 * player death cam should fit nicely on walls.
526 *
527 * 177 9/23/98 2:55p Chris
528 * Improved auto-leveling and added newbie leveling
529 *
530 * 176 9/22/98 6:48p Jason
531 * fixed dedicated server problems
532 *
533 * 175 9/22/98 5:20p Jason
534 * fixed some player bugs
535 *
536 * 174 9/22/98 11:15a Jeff
537 * took out bad ASSERT
538 *
539 * 173 9/21/98 12:56p Jason
540 * made camera even smoother
541 *
542 * 172 9/21/98 12:11p Jason
543 * fixed camera problems
544 *
545 * 171 9/18/98 6:09p Jason
546 * added smoother camera
547 *
548 * 170 9/18/98 4:52p Jason
549 * Incremental checkin for camera
550 *
551 * 169 9/18/98 1:27p Matt
552 * Added afterburner release sound
553 *
554 * 168 9/18/98 11:18a Jason
555 * fixed miscellaneous bugs with camera system
556 *
557 * 167 9/17/98 3:03p Jason
558 * added lightning and invul hit effects
559 *
560 * 166 9/16/98 5:10p Jason
561 * added first pass at thrid-person camera system
562 *
563 * 165 9/11/98 12:26p Jason
564 * got energy to shield and fusion damage working in multiplayer
565 *
566 * 164 9/10/98 12:18p Jason
567 * more changes to afterburner/thrust effect
568 *
569 * 163 9/09/98 7:09p Jason
570 * changed afterburner effect for ships
571 *
572 * 162 8/28/98 1:34p Matt
573 * Added code to reset the waypoint when starting a new level, and while I
574 * was at it cleaned up the new level start sequencing.
575 *
576 * 161 8/24/98 2:45p Jason
577 * added team start position stuff
578 *
579 * 160 8/24/98 12:24p Jason
580 * added waypoints and player start position flags
581 *
582 * 159 8/20/98 7:01p Jeff
583 * changed sound on energy->shields converter
584 *
585 * 158 8/19/98 12:38p Jason
586 * made countermeasure spewing work correctly
587 *
588 * 157 8/17/98 10:48a Jason
589 * added more sparks when players explode
590 *
591 * 156 8/16/98 6:18p Chris
592 * Fixed player spewing
593 *
594 * 155 8/16/98 2:34a Jeff
595 * fixed a hud message
596 *
597 * 154 8/16/98 12:19a Jeff
598 * added energy->shields function
599 *
600 * 153 8/10/98 2:21p Jeff
601 * changes made due to adding flag for inventory reset
602 *
603 * 152 8/07/98 2:44p Jeff
604 * some changes to ship permissions (reset can take a -1 for pnum in order
605 * to reset everyone)
606 *
607 * 151 8/07/98 10:51a Jason
608 * made custom textures 64x64
609 *
610 * 150 8/06/98 2:44p Jeff
611 * added ship permissions functions (first round)
612 *
613 * 149 8/03/98 5:56p Jason
614 * got fusion cannon working correctly
615 *
616 * 148 8/03/98 4:29p Jason
617 * fixed afterburner bug
618 *
619 * 147 7/31/98 3:24p Samir
620 * allow breakup death outside only.
621 *
622 * 146 7/31/98 1:55p Jason
623 * added a function for custom textures
624 *
625 * 145 7/31/98 11:51a Jason
626 * added player ship choosing to multiplayer games
627 *
628 * 144 7/29/98 12:47p Jason
629 * multiplayer changes
630 *
631 * 143 7/28/98 5:39p Samir
632 * tweaked death sequence.
633 *
634 * 142 7/28/98 12:29p Jason
635 * added rotational velocity to multiplayer position packets
636 *
637 * 141 7/27/98 5:59p Jason
638 * added piggyback mode plus multiplayer colors
639 *
640 * 140 7/22/98 4:36p Jason
641 * took out bugs from observer mode
642 *
643 * 139 7/22/98 3:16p Jason
644 * added observer mode
645 *
646 * 138 7/20/98 10:42a Jason
647 * added more player scalars, plus afterburner changes
648 *
649 * 137 7/19/98 6:48p Jeff
650 * got rid of annoying mprintf on death
651 *
652 * 136 7/17/98 5:57p Jason
653 * misc multiplayer changes
654 *
655 * 135 7/15/98 2:33p Jason
656 * added scalar variables for various player skills
657 *
658 * 134 7/03/98 3:09p Jeff
659 * added counter measures inventory
660 *
661 * 133 7/02/98 6:37p Jason
662 * fixed bug with last rev
663 *
664 * 132 7/02/98 6:30p Jason
665 * added some multiplayer stuff for Jeff
666 *
667 * 131 7/02/98 12:57p Jason
668 * various changes for multiplayer positional sequencing
669 *
670 * 130 6/29/98 3:08p Jason
671 * added on/off weapons
672 *
673 * 129 6/25/98 5:17p Jason
674 * added multiple colored balls for players
675 *
676 * 128 6/22/98 6:02p Samir
677 * don't show cockpit when dying.
678 *
679 * 127 6/17/98 6:31p Samir
680 * Added anti-grav warning when dying.
681 *
682 * 126 6/16/98 10:54a Jeff
683 *
684 * 125 6/15/98 6:08p Chris
685 * Hit_type to hit_type[0]
686 *
687 * 124 6/11/98 12:48p Jason
688 * added better spewing weapons
689 *
690 * 123 6/05/98 4:54p Samir
691 * fixed bugs in MoveDeathCam.
692 *
693 * 122 6/03/98 6:42p Chris
694 * Added multipoint collision detection an Assert on invalid (infinite
695 * endpoint).
696 *
697 * 121 6/02/98 5:49p Jeff
698 * changed assert in PlayerSpewObject so it handles a ghost along with
699 * player type
700 *
701 * 120 6/01/98 10:37a Matt
702 * Added system to spew powerups when the player dies. Still needs Jason
703 * to deal with mng_FindSpecificGenericPage().
704 *
705 * 119 5/27/98 12:36a Samir
706 * invulnerablize player at start of E3 demo level, and use default
707 * weapons.
708 *
709 * 118 5/26/98 10:48p Samir
710 * for E3, new level = special weapons.
711 *
712 * 117 5/25/98 6:50p Matt
713 * Added needed include.
714 *
715 * 116 5/22/98 6:27p Samir
716 * reimplemented spinning D2 death, a bit modified.
717 *
718 * 115 5/22/98 11:59a Chris
719 * Fixed improper uses of FindSoundName and made the proper static sounds
720 *
721 * 114 5/15/98 5:41p Jason
722 * implemented volume lighting system
723 *
724 * 113 5/12/98 3:45p Chris
725 * Added a "dead" buddy when the player dies with the buddy in his
726 * inventory
727 *
728 * 112 5/11/98 4:40p Chris
729 * AI info is now a malloc'ed pointer
730 *
731 * 111 5/04/98 4:04p Chris
732 * Minestone checkin' -- energy effect and more AI functionality
733 *
734 * 110 5/04/98 12:22p Chris
735 * Improved Guidebot spewing
736 *
737 * 109 5/04/98 10:56a Kevin
738 * Mastertracker fixes/enhancements
739 *
740 * 108 5/01/98 6:50p Samir
741 * changed death sequence to fall on melee kill (single player) and death
742 * camera improvements.
743 *
744 * 107 5/01/98 4:32p Jason
745 * take care afterburner sound when a player dies
746 *
747 * 106 4/30/98 2:48p Kevin
748 * mastertracker
749 *
750 * 105 4/30/98 2:34p Kevin
751 * Movet mastertracker stuff to playerinit
752 *
753 * 104 4/30/98 1:15p Kevin
754 * Added lifetime deaths and kills for MT
755 *
756 * 103 4/30/98 11:32a Chris
757 * ClearWB to WBClear
758 *
759 * 102 4/29/98 12:51p Kevin
760 * Added mastertracker values
761 *
762 * 101 4/27/98 1:14p Jason
763 * cleaned up afterburner stuff
764 *
765 * 100 4/22/98 4:20p Jason
766 * reset player effects when dead
767 *
768 * 99 4/22/98 3:25p Jason
769 * changes for multiplayer debugging
770 *
771 * 98 4/20/98 3:03p Craig
772 * FROM JASON: Fixed effect resetting bug
773 *
774 * 97 4/19/98 5:00p Jason
775 * added cool napalm effect, plus made object effects dynamically
776 * allocated
777 *
778 * 96 4/18/98 7:17a Samir
779 * Update level time each player frame.
780 *
781 * 95 4/17/98 1:59p Jason
782 * added cool object effects
783 *
784 * 94 4/15/98 2:33p Jason
785 * changed some smoke trail stuff
786 *
787 * 93 4/13/98 12:42p Jason
788 * changed afterburner effect
789 *
790 * 92 4/10/98 8:59p Jason
791 * toned down red damage effect
792 *
793 * 91 4/10/98 3:28p Jason
794 * fixed afterburner bug
795 *
796 * 90 4/10/98 2:42p Jason
797 * fixed afterburner blobs to be a stream
798 *
799 * 89 4/09/98 7:15p Craig
800 * Remove inventory add
801 *
802 * 88 4/09/98 5:18p Jason
803 * got guided working in multiplayer
804 *
805 * 87 4/09/98 2:23p Jason
806 * added guided/afterburner stuff
807 *
808 * 86 4/07/98 7:17p Chris
809 * Removed guidebots from multiplayer
810 *
811 * 85 4/07/98 4:50p Jason
812 * made red damage glow fade much quicker
813 *
814 * 84 4/07/98 4:25p Chris
815 * Added support for buddy bot
816 *
817 * 83 4/06/98 2:54p Jason
818 * yet more multiplayer changes
819 *
820 * 82 4/06/98 12:14p Jason
821 * changes to multiplayer
822 *
823 * 81 4/03/98 12:28p Jason
824 * fixed confusion with clients changing rooms in multiplayer
825 *
826 * 80 4/03/98 11:55a Jason
827 * fixed polymodel paging problem
828 *
829 * 79 4/02/98 6:32p Jason
830 * get multiple items in inventory spewing
831 *
832 * 78 4/01/98 6:23p Jason
833 * added a slew of stuff for multiplayer
834 *
835 * 77 4/01/98 2:13p Jason
836 * added PlayerChangeShip
837 *
838 * 76 4/01/98 12:02p Jason
839 * incremental checkin for rendering changes
840 *
841 * 75 3/31/98 11:15a Jason
842 * added the ability for player objects to cast light
843 *
844 * 74 3/30/98 5:11p Jason
845 * more changes for game/dll integration
846 *
847 * 73 3/27/98 6:53p Samir
848 * lessen death glitter.
849 *
850 * 72 3/23/98 7:37p Jason
851 * fixed multiplayer shield problem
852 *
853 * 71 3/20/98 6:05p Chris
854 * Fixed a bug with player sounds
855 *
856 * 70 3/20/98 5:51p Jason
857 * more changes for multiplayer
858 *
859 * 69 3/20/98 2:18p Jason
860 * changes for multiplayer
861 *
862 * 68 3/19/98 7:15p Jason
863 * more changes for multiplayer
864 *
865 * 67 3/18/98 5:45p Jason
866 * more multiplayer script integration
867 *
868 * 66 3/18/98 12:11p Jason
869 * fixed non-existant killer problems
870 *
871 * 65 3/18/98 11:08a Jason
872 * more changes for script and multiplayer
873 *
874 * 64 3/17/98 3:25p Jason
875 * added number of team functions
876 *
877 * 63 3/17/98 2:40p Samir
878 * reorg of hud/gauge system.
879 *
880 * 62 3/17/98 11:34a Jason
881 * added GetGoalRoom stuff
882 *
883 * 61 3/13/98 12:09p Samir
884 * made changes to reflect new cockpit.cpp and cockpit.h
885 *
886 * 60 3/12/98 7:30p Chris
887 * Added ObjSetOrient
888 *
889 * 59 2/25/98 2:05p Jason
890 * did FOV and object visibility changes
891 *
892 * 58 2/25/98 1:01p Jason
893 * fixed FOV effect showing up for everyone in a multiplayer game
894 *
895 * 57 2/24/98 2:31p Jason
896 * added FOV warp effect for when coming back to life
897 *
898 * 56 2/23/98 4:52p Chris
899 * Removed size hack
900 *
901 * 55 2/19/98 6:38p Chris
902 * Added the ship size hack back in.
903 *
904 * 54 2/19/98 6:31p Jason
905 * fixed bug where a player killer object wasn't valid
906 *
907 * 53 2/18/98 11:03p Chris
908 * Removed the false ship size of 4.0 that we used for the milestone
909 *
910 * 52 2/18/98 2:13a Chris
911 * hacked size to 4
912 *
913 * 51 2/17/98 11:33p Matt
914 * Stop player weapon firing activity when player dies
915 *
916 * 50 2/17/98 3:46p Matt
917 * Revamped weapon system and got sounds for spray and fusion weapons
918 * working. Still need to implements getting continuous & cutoff sounds
919 * from player ship.
920 *
921 * 49 2/15/98 4:50p Jeff
922 * added a call to reset the player's inventory
923 *
924 * 48 2/09/98 5:38p Jeff
925 * changed EVT_PLAYEREXPLODED to EVT_GAMEPLAYEREXPLODED
926 *
927 * 47 2/06/98 6:07p Jason
928 * made multiplayer objects get deleted in single-player mode
929 *
930 * 46 2/05/98 2:57p Matt
931 * Changed code to use ObjSetPos()
932 *
933 * 45 2/05/98 10:44a Jason
934 * changed Red_blast_ring_index define
935 *
936 * 44 2/04/98 6:09p Matt
937 * Changed object room number to indicate a terrain cell via a flag. Got
938 * rid of the object flag which used to indicate terrain.
939 *
940 * 43 2/03/98 4:04p Jeff
941 * added OSIRIS events for player killed and exploded
942 *
943 * 42 1/28/98 1:12p Jason
944 * took shields field out of Player struct
945 *
946 * 41 1/28/98 12:00p Jason
947 * more changes for multiplayer
948 *
949 * 40 1/23/98 6:25p Jason
950 * Got spray weapons working
951 *
952 * 39 1/23/98 11:21a Jason
953 * incremental multiplayer checkin
954 *
955 * 38 1/21/98 6:09p Jason
956 * Got player deaths working in multiplayer
957 *
958 * 37 1/21/98 1:31p Samir
959 * No use thrust because of multiplayer.
960 *
961 * 36 1/21/98 1:11p Jason
962 * incremental checkin for multiplayer
963 *
964 * 35 1/20/98 6:35p Samir
965 * Death sequence more multiplayer friendly?
966 *
967 * 34 1/20/98 6:01p Jason
968 * first pass at getting multiplayer deaths working
969 *
970 * 33 1/20/98 12:10p Jason
971 * implemented vis effect system
972 *
973 * 32 1/19/98 5:49p Samir
974 * Some more death stuff.
975 *
976 * 31 1/08/98 12:31p Samir
977 * Called InitPlayerNewShip when died.
978 *
979 * 30 1/07/98 6:39p Jason
980 * Fixed player object number stuff
981 *
982 * 29 12/17/97 4:02p Samir
983 * Fixed bug.
984 *
985 * 28 12/16/97 4:44p Samir
986 * Some newer player death stuff.
987 *
988 * 27 12/10/97 3:28p Samir
989 * Some randomness.
990 *
991 * 26 12/01/97 2:45p Samir
992 * Press space bar to quit death sequence.
993 *
994 * 25 11/17/97 4:58p Samir
995 * Fixed player death cam problems.
996 *
997 * 24 11/14/97 2:59p Mark
998 * FROM JASON:changed the way paging weapons and player weapons work
999 *
1000 * 23 11/11/97 12:31p Samir
1001 * Hopefully fixed bug when death cam is moving from terrain to mine and
1002 * vice-versa.
1003 *
1004 * 22 10/28/97 6:38p Samir
1005 * Took out include to gauges.h
1006 *
1007 * 21 10/27/97 4:31p Samir
1008 * Commented out annoying mprintfs.
1009 *
1010 * 20 10/27/97 10:57a Samir
1011 * A little better close corner death scenes.
1012 *
1013 * 19 10/23/97 6:46p Samir
1014 * Mostly functional player explosions with special FX like fireballs and
1015 * splinters, breakups, etc.
1016 *
1017 * 18 10/22/97 7:26p Samir
1018 * Player death mostly working. Damn hangup still occurs. Freaky.
1019 *
1020 * 17 10/21/97 3:16p Samir
1021 * Death with explosions (not customized yet.)
1022 *
1023 * 16 10/20/97 3:00p Samir
1024 * Tweaked some random behavior in death and 'fixed' the camera on room
1025 * side problem.
1026 *
1027 * 15 10/16/97 4:10p Chris
1028 * Added some bounciness to the player object
1029 *
1030 * 14 10/15/97 3:05p Samir
1031 * Death cam 99% working.
1032 *
1033 * 13 10/10/97 3:57p Samir
1034 * Death sequence mostly perfect. Needs explosions still.
1035 *
1036 * 12 10/08/97 6:36p Samir
1037 * Except for player explosions, player death cycle implemented. May
1038 * change due to asthetics.
1039 *
1040 * 11 10/03/97 11:59a Samir
1041 * Take care of setting player weapon usage stats.
1042 *
1043 * 10 10/01/97 4:51p Samir
1044 * Moved ApplyDamagePlayer to damage.cpp
1045 *
1046 * 9 9/30/97 5:34p Samir
1047 * Moved level script code out of this file.
1048 *
1049 * 8 9/17/97 5:40p Samir
1050 * Fixed some vulnerability problems.
1051 *
1052 * 7 9/17/97 11:35a Samir
1053 * BIG SEGMENT RIPOUT
1054 *
1055 * 6 9/12/97 4:16p Samir
1056 * Added cloaking and invulnerability.
1057 *
1058 * 5 9/05/97 4:37p Samir
1059 * Some nonsense.
1060 *
1061 * 4 9/05/97 3:53p Samir
1062 * Fixed some more initial player stats.
1063 *
1064 * 3 9/05/97 2:33p Samir
1065 * Simple player death should work.
1066 *
1067 * 2 9/05/97 12:26p Samir
1068 * Player takes damage, and dies.
1069 *
1070 * 5 5/06/97 3:45p Matt
1071 * Save all player flags in player struct, not just over_terrain
1072 *
1073 * 4 5/06/97 12:53p Matt
1074 * Save over terrain flag with start position in player struct
1075 *
1076 * 3 4/23/97 6:06p Jason
1077 * made player ship and weapons work correctly together (first pass)
1078 *
1079 * 2 4/01/97 10:49p Matt
1080 * Added code
1081 *
1082 * 1 4/01/97 10:27p Matt
1083 *
1084 * $NoKeywords: $
1085 */
1086
1087 #include <cmath>
1088
1089 #include "pserror.h"
1090 #include "player.h"
1091 #include "game.h"
1092 #include "hud.h"
1093 #include "gauges.h"
1094 #include "Mission.h"
1095 #include "vecmat.h"
1096 #include "fireball.h"
1097 #include "polymodel.h"
1098 #include "findintersection.h"
1099 #include "hud.h"
1100 #include "splinter.h"
1101 #include "physics.h"
1102 #include "viseffect.h"
1103 #include "damage.h"
1104 #include "multi.h"
1105 #include "ship.h"
1106 #include "gameevent.h"
1107 #include "gameloop.h"
1108 #include "descent.h"
1109 #include "cockpit.h"
1110 #include "game2dll.h"
1111 #include "robotfire.h"
1112 #include "robot.h"
1113 #include "AIMain.h"
1114 #include "aipath.h"
1115 #include "AIGoal.h"
1116 #include "hlsoundlib.h"
1117 #include "soundload.h"
1118 #include "sounds.h"
1119 #include "weapon.h"
1120 #include "stringtable.h"
1121 #include "pilot.h"
1122 #include "vclip.h"
1123 #include <stdlib.h>
1124 #include "objinit.h"
1125 #include "difficulty.h"
1126 #include "ddio.h"
1127 #include "ObjScript.h"
1128 #include "gamecinematics.h"
1129 #include "demofile.h"
1130 #include "psrand.h"
1131 #include "osiris_share.h"
1132 #include "config.h"
1133 #include "osiris_dll.h"
1134 #include "gamesequence.h"
1135
1136 #include <algorithm>
1137
1138 player Players[MAX_PLAYERS];
1139 int Player_num;
1140
1141 int Num_teams = 0;
1142 int Team_game = 0;
1143 int Default_ship_permission = 0x01;
1144 float HudNameTan = -1;
1145
1146 team Teams[MAX_TEAMS];
1147
1148 static int Highest_player_start = 0;
1149
1150 // Only one of these waypoint variable can be active at one time; the other will be -1
1151 int Current_waypoint = 0; // the most recent manually-set waypoint, or -1
1152
1153 // Stuff for the new score info on the HUD
1154 int Score_added = 0; // the recently-added amount
1155 float Score_added_timer = 0.0; // how long the added value will be displayed
1156
1157 // Camera stuff
1158 #define MAX_CAMERA_SAMPLES 100
1159 #define MAX_CAMERA_SUB_SAMPLES 50
1160 #define CAMERA_LAG_TIME .10f // How far behind the camera is in time
1161 #define CAMERA_SAMPLE_INCREMENT (CAMERA_LAG_TIME / (float)MAX_CAMERA_SUB_SAMPLES)
1162 bool Player_has_camera = false;
1163 int Player_camera_objnum = -1;
1164 float Player_shields_saved_from_last_level = -1.0f;
1165 float Player_energy_saved_from_last_level = -1.0f;
1166
1167 uint32_t Players_typing; // information about which players are typing messages (to display an icon)
1168
1169 static float Player_camera_last_sample_time = 0;
1170 static float Player_camera_last_follow_time = 0;
1171
1172 static int Camera_sample_index = 0;
1173 static int Camera_follow_index = 0;
1174 static vector Camera_sample_vectors[MAX_CAMERA_SAMPLES];
1175 static matrix Camera_sample_matrix[MAX_CAMERA_SAMPLES];
1176 static int Camera_sample_rooms[MAX_CAMERA_SAMPLES];
1177
1178 float Total_time_dead = 0;
1179
1180 static void StartPlayerDeath(int slot, float damage, bool melee, int fate);
1181
1182 // Sets up the players array
1183 void InitPlayers() {
1184 int i;
1185
1186 // find the ships that are allowed by default
1187 Default_ship_permission = 0;
1188 for (i = 0; i < MAX_SHIPS; i++) {
1189 if (Ships[i].used & Ships[i].flags & SF_DEFAULT_ALLOW) {
1190 int flag = 0x01;
1191 flag = flag << i;
1192 Default_ship_permission |= flag;
1193 }
1194 }
1195
1196 for (i = 0; i < MAX_PLAYERS; i++) {
1197 Players[i].startpos_flags = 0;
1198
1199 int index = AllocTexture();
1200
1201 ASSERT(index >= 0);
1202 GameTextures[index].bm_handle = 0;
1203 snprintf(GameTextures[index].name, sizeof(GameTextures[index].name), "Player %d texture", i);
1204 Players[i].custom_texture_handle = index;
1205 }
1206 PlayerResetShipPermissions(-1, true);
1207 Players_typing = 0;
1208 }
1209
1210 // Look for player objects & set player starts
1211 void FindPlayerStarts() {
1212 int i;
1213 int unique = 0;
1214
1215 // Flag all players as unused
1216 for (i = 0; i < MAX_PLAYERS; i++)
1217 Players[i].start_roomnum = -1;
1218
1219 Highest_player_start = 0;
1220
1221 if (Game_mode & GM_MULTI) {
1222 ps_srand(400);
1223 }
1224
1225 // Now look for player objects
1226 for (i = 0; i <= Highest_object_index; i++)
1227 if (Objects[i].type == OBJ_PLAYER) {
1228 ASSERT(Players[Objects[i].id].start_roomnum == -1); // make sure not used twice
1229 Players[Objects[i].id].start_pos = Objects[i].pos;
1230 Players[Objects[i].id].start_roomnum = Objects[i].roomnum;
1231 Players[Objects[i].id].start_orient = Objects[i].orient;
1232 Players[Objects[i].id].objnum = i;
1233
1234 if (Objects[i].id > Highest_player_start)
1235 Highest_player_start = Objects[i].id;
1236
1237 unique++;
1238 }
1239
1240 mprintf(0, "There are %d unique start positions in this level\n", unique);
1241
1242 // Now create the extra players
1243 if (Game_mode & GM_MULTI) {
1244 // Build a list so we can fill in the rest
1245 int choose_list[MAX_PLAYERS];
1246 int num_choose = 0;
1247 for (i = 0; i < MAX_PLAYERS; i++) {
1248 if (Players[i].start_roomnum != -1) {
1249 choose_list[num_choose++] = i;
1250 }
1251 }
1252 for (i = Highest_player_start + 1; i < MAX_PLAYERS; i++) {
1253 int oldplaynum = ps_rand() % num_choose;
1254 oldplaynum = choose_list[oldplaynum];
1255
1256 int objnum = ObjCreate(OBJ_PLAYER, i, Players[oldplaynum].start_roomnum, &Players[oldplaynum].start_pos,
1257 &Players[oldplaynum].start_orient);
1258 ASSERT(objnum >= 0);
1259 Players[Objects[objnum].id].start_pos = Players[oldplaynum].start_pos;
1260 Players[Objects[objnum].id].start_roomnum = Players[oldplaynum].start_roomnum;
1261 Players[Objects[objnum].id].start_orient = Players[oldplaynum].start_orient;
1262 Players[Objects[objnum].id].startpos_flags = Players[oldplaynum].startpos_flags;
1263 Players[Objects[objnum].id].objnum = objnum;
1264 if (Objects[objnum].id > Highest_player_start)
1265 Highest_player_start = Objects[objnum].id;
1266 }
1267
1268 for (i = 0; i < MAX_PLAYERS; i++) {
1269 // Make all extra slots use slot 0
1270 if (Players[i].start_roomnum == -1) {
1271 int oldplaynum = ps_rand() % num_choose;
1272 oldplaynum = choose_list[oldplaynum];
1273
1274 int objnum = ObjCreate(OBJ_PLAYER, i, Players[oldplaynum].start_roomnum, &Players[oldplaynum].start_pos,
1275 &Players[oldplaynum].start_orient);
1276 ASSERT(objnum >= 0);
1277 Players[Objects[objnum].id].start_pos = Players[oldplaynum].start_pos;
1278 Players[Objects[objnum].id].start_roomnum = Players[oldplaynum].start_roomnum;
1279 Players[Objects[objnum].id].start_orient = Players[oldplaynum].start_orient;
1280 Players[Objects[objnum].id].startpos_flags = Players[oldplaynum].startpos_flags;
1281 Players[Objects[objnum].id].objnum = objnum;
1282 if (Objects[objnum].id > Highest_player_start)
1283 Highest_player_start = Objects[objnum].id;
1284 }
1285 }
1286 }
1287 }
1288
1289 // Returns a random player starting position
1290 int PlayerGetRandomStartPosition(int slot) {
1291 if (Netgame.flags & NF_RESPAWN_WAYPOINT) {
1292 // Grab an autowaypoint
1293 if (Players[slot].current_auto_waypoint_room != -1) {
1294 int waypointnum = -(Players[slot].current_auto_waypoint_room - 1);
1295 return waypointnum;
1296 } else {
1297 if (Current_waypoint < 0)
1298 return 0;
1299 else
1300 return Current_waypoint;
1301 }
1302 }
1303
1304 ps_srand((timer_GetTime() * 1000));
1305 // If this is a team game then pick a spot on that team
1306 if (Team_game) {
1307
1308 int team = PlayerGetTeam(slot);
1309 mprintf(0, "Picking team start position, team=%d.\n", team);
1310 int num_avail = 0;
1311 int avail_array[MAX_PLAYERS];
1312
1313 for (int i = 0; i <= Highest_player_start; i++) {
1314 if ((Players[i].startpos_flags & (1 << team)) && Players[i].start_roomnum != -1) {
1315 avail_array[num_avail] = i;
1316 num_avail++;
1317 }
1318 }
1319 if (num_avail > 0) {
1320 int num;
1321 int done = 0;
1322 while (!done) {
1323 num = avail_array[ps_rand() % (num_avail)];
1324 if (Players[num].start_roomnum != -1)
1325 done = 1;
1326 }
1327 return num;
1328 }
1329 }
1330
1331 // Default to non-team mode
1332 int num;
1333 int done = 0;
1334 int badcount = 0;
1335 mprintf(0, "Picking non-team start position.\n");
1336 while (!done) {
1337 num = ps_rand() % (Highest_player_start + 1);
1338 if (Players[num].start_roomnum != -1) {
1339 // Check to see if there are any other players in this room
1340 int objnum = -1;
1341 if (Players[num].start_roomnum >= 0) {
1342 room *rp = &Rooms[Players[num].start_roomnum];
1343 objnum = rp->objects;
1344 } else {
1345 objnum = Terrain_seg[Players[num].start_roomnum].objects;
1346 }
1347 int bad = 0;
1348 for (; objnum != -1 && !bad; objnum = Objects[objnum].next) {
1349 if (Objects[objnum].type == OBJ_PLAYER)
1350 bad = 1;
1351 }
1352
1353 if (bad) {
1354 badcount++;
1355 if (badcount >= 15) // give up after fifteen tries
1356 {
1357 mprintf(0, "Stopping cuz I couldn't find a valid player position!\n");
1358 done = 1;
1359 }
1360 } else
1361 done = 1;
1362 }
1363 }
1364
1365 mprintf(0, "Picked index for start position %d\n", num);
1366
1367 return num;
1368 }
1369
1370 // Called from a single player game to get rid of all multiplayer ships
1371 void DeleteMultiplayerObjects() {
1372 for (int i = 0; i <= Highest_object_index; i++) {
1373 if (Objects[i].type == OBJ_PLAYER && Objects[i].id != Player_num)
1374 ObjDelete(i);
1375 }
1376 }
1377
1378 // Stops all sounds for a player
1379 void PlayerStopSounds(int slot) {
1380 if (Players[slot].afterburner_sound_handle != -1) {
1381 Sound_system.StopSoundImmediate(Players[slot].afterburner_sound_handle);
1382 Players[slot].afterburner_sound_handle = -1;
1383 }
1384
1385 if (Players[slot].thruster_sound_handle != -1) {
1386 Sound_system.StopSoundImmediate(Players[slot].thruster_sound_handle);
1387 Players[slot].thruster_sound_handle = -1;
1388 }
1389 }
1390
1391 // Called when a player is entering the game for the first time
1392 void InitPlayerNewGame(int slot) {
1393 Players[slot].num_kills_total = 0;
1394 Players[slot].num_deaths_total = 0;
1395 Players[slot].score = 0;
1396
1397 uint32_t bit = (0x01 << slot);
1398 Players_typing &= ~bit;
1399 }
1400
1401 // Called when a player is entering a new level
1402 void InitPlayerNewLevel(int slot) {
1403 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1404
1405 if (Player_num == slot && (!(Game_mode & GM_MULTI))) {
1406 // see if we should restore our shields (which were saved in the last call
1407 // to ResetPlayerObject. Only restore if shields are >INITIAL_SHIELDS
1408 if (Player_shields_saved_from_last_level > INITIAL_SHIELDS)
1409 Objects[Players[slot].objnum].shields = Player_shields_saved_from_last_level;
1410 if (Player_energy_saved_from_last_level > INITIAL_ENERGY)
1411 Players[slot].energy = Player_energy_saved_from_last_level;
1412
1413 // set this to -1 to prevent any unneeded madness
1414 Player_shields_saved_from_last_level = -1.0f;
1415 Player_energy_saved_from_last_level = -1.0f;
1416 }
1417
1418 Players[slot].num_kills_level = 0;
1419 Players[slot].friendly_kills_level = 0;
1420 Players[slot].num_hits_level = 0;
1421 Players[slot].num_discharges_level = 0;
1422 Players[slot].num_markers = 0;
1423 Players[slot].inventory.Reset(true, (Game_mode & GM_MULTI) ? INVRESET_ALL : INVRESET_LEVELCHANGE);
1424 Players[slot].counter_measures.Reset(true, (Game_mode & GM_MULTI) ? INVRESET_ALL : INVRESET_LEVELCHANGE);
1425 Players[slot].keys = 0;
1426 Players[slot].num_deaths_level = 0;
1427
1428 if (Game_mode & GM_MULTI)
1429 NetPlayers[slot].packet_time = 0;
1430
1431 if (slot == Player_num)
1432 Player_camera_objnum = -1;
1433
1434 // Turn off rear view
1435 Players[slot].flags &= ~PLAYER_FLAGS_REARVIEW;
1436
1437 // Kill autowaypoint
1438 Players[slot].current_auto_waypoint_room = -1;
1439
1440 // Restore Quad Lasers if they are still in inventory
1441 static int quad_laser_id = -2;
1442 if (quad_laser_id == -2)
1443 quad_laser_id = FindObjectIDName("QuadLaser");
1444 if (quad_laser_id != -1) {
1445 if (Players[slot].inventory.CheckItem(OBJ_POWERUP, quad_laser_id)) {
1446 object *pobj = &Objects[Players[slot].objnum];
1447 pobj->dynamic_wb[LASER_INDEX].flags |= DWBF_QUAD;
1448 pobj->dynamic_wb[SUPER_LASER_INDEX].flags |= DWBF_QUAD;
1449 }
1450 }
1451
1452 uint32_t bit = (0x01 << slot);
1453 Players_typing &= ~bit;
1454
1455 // Give the player a GuideBot if he doesn't have one and if the GB isn't out there
1456 if ((!(Game_mode & GM_MULTI)) && (Demo_flags != DF_PLAYBACK)) {
1457 if ((!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
1458 (ObjGet(Buddy_handle[slot])->type != OBJ_ROBOT))
1459 Players[slot].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
1460 }
1461
1462 // Limit the player's ammo to what the current ship can hold
1463 player *player = &Players[slot];
1464 ship *ship = &Ships[player->ship_index];
1465 for (int i = 0; i < MAX_PLAYER_WEAPONS; i++) {
1466 if ((i >= SECONDARY_INDEX) || ship->static_wb[i].ammo_usage)
1467 player->weapon_ammo[i] = std::min<float>(ship->max_ammo[i], player->weapon_ammo[i]);
1468 }
1469
1470 #ifdef E3_DEMO
1471 extern float E3_TIME_LIMIT;
1472
1473 MakePlayerInvulnerable(slot, E3_TIME_LIMIT * 2);
1474 //@@ Players[slot].energy=200.0f;
1475 //@@ Players[slot].weapon_flags=HAS_FLAG(LASER_INDEX)+HAS_FLAG(PLASMA_INDEX)+HAS_FLAG(VAUSS_INDEX)
1476 //@@ +HAS_FLAG(MICROWAVE_INDEX);
1477 //@@ Players[slot].weapon_flags+= HAS_FLAG(GUIDED_INDEX)+HAS_FLAG(NAPALMROCKET_INDEX)+HAS_FLAG(CYCLONE_INDEX);
1478 //@@
1479 //@@ for (int i=0;i<MAX_PLAYER_WEAPONS;i++)
1480 //@@ Players[slot].weapon_ammo[i] = 1000;
1481
1482 #endif
1483 }
1484
1485 // Resets all the properties a player ship to the default values
1486 // Pass into inven_reset what you want passed to Inventory.Reset()
1487 void InitPlayerNewShip(int slot, int inven_reset) {
1488 int i;
1489
1490 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1491
1492 Players[slot].energy = INITIAL_ENERGY;
1493 Players[slot].num_balls = 0;
1494 Players[slot].laser_level = 0;
1495 Players[slot].killer_objnum = -1;
1496 Players[slot].light_dist = 0;
1497 Players[slot].oldroom = -1;
1498 Players[slot].guided_obj = NULL;
1499 Players[slot].user_timeout_obj = NULL;
1500 Players[slot].afterburn_time_left = AFTERBURN_TIME;
1501 Players[slot].last_thrust_time = 0;
1502 Players[slot].last_afterburner_time = 0;
1503
1504 // start out with basic weapons
1505 for (i = 0; i < MAX_PLAYER_WEAPONS; i++)
1506 Players[slot].weapon_ammo[i] = 0;
1507
1508 Players[slot].weapon_flags = HAS_FLAG(LASER_INDEX);
1509 Players[slot].weapon_flags += HAS_FLAG(CONCUSSION_INDEX);
1510 Players[slot].weapon_flags += HAS_FLAG(FLARE_INDEX);
1511 Players[slot].weapon_ammo[CONCUSSION_INDEX] = 2 + MAX_DIFFICULTY_LEVELS - Difficulty_level;
1512
1513 Players[slot].weapon[PW_PRIMARY].index = LASER_INDEX;
1514 Players[slot].weapon[PW_PRIMARY].firing_time = 0;
1515 Players[slot].weapon[PW_PRIMARY].sound_handle = -1;
1516
1517 Players[slot].weapon[PW_SECONDARY].index = CONCUSSION_INDEX;
1518 Players[slot].weapon[PW_SECONDARY].firing_time = 0;
1519 Players[slot].weapon[PW_SECONDARY].sound_handle = -1;
1520
1521 Players[slot].small_left_obj = -1;
1522 Players[slot].small_right_obj = -1;
1523 Players[slot].small_dll_obj = -1;
1524
1525 // some other stuff
1526 Players[slot].flags = 0;
1527
1528 Players[slot].invulnerable_time = 0;
1529
1530 Players[slot].damage_magnitude = 0;
1531 Players[slot].edrain_magnitude = 0;
1532
1533 if (Players[slot].objnum >= 0 && Players[slot].objnum <= Highest_object_index &&
1534 Objects[Players[slot].objnum].type != OBJ_NONE)
1535 Objects[Players[slot].objnum].weapon_fire_flags = 0;
1536
1537 // reset the inventory
1538 Players[slot].inventory.Reset(true, inven_reset);
1539 Players[slot].counter_measures.Reset(true, inven_reset);
1540
1541 Players[slot].last_homing_warning_sound_time = 0.0f;
1542 Players[slot].last_hit_wall_sound_time = 0.0f;
1543 Players[slot].multiplayer_flags = 0;
1544 Players[slot].last_multiplayer_flags = 0;
1545 Players[slot].afterburner_mag = 0;
1546 Players[slot].thrust_mag = 0;
1547 Players[slot].last_guided_time = 0;
1548 Players[slot].afterburner_sound_handle = -1;
1549
1550 Players[slot].thruster_sound_state = 0;
1551 Players[slot].thruster_sound_handle = -1;
1552
1553 Players[slot].movement_scalar = 1;
1554 Players[slot].armor_scalar = 1;
1555 Players[slot].damage_scalar = 1;
1556 Players[slot].turn_scalar = 1;
1557 Players[slot].weapon_recharge_scalar = 1;
1558 Players[slot].weapon_speed_scalar = 1;
1559 // Enable all controller input
1560 Players[slot].controller_bitflags = 0xffffffff;
1561
1562 ResetWeaponSelectStates(); // reset storage of current weapon class selected per slot.
1563 ResetReticle();
1564
1565 // add his guidebot (if it is a guidebot game)
1566 // this is here in case DMFC calls this function (which would remove the guidebot)
1567 if (GetGameState() == GAMESTATE_LVLPLAYING && Game_mode & GM_MULTI && Netgame.local_role == LR_SERVER &&
1568 Netgame.flags & NF_ALLOWGUIDEBOT) {
1569 if ((!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
1570 (ObjGet(Buddy_handle[slot])->type != OBJ_ROBOT))
1571 Players[slot].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
1572 }
1573 }
1574
1575 // Gives the named player an afterburner
1576 void PlayerGiveAfterburner(int slot) {
1577 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1578 Players[slot].flags |= PLAYER_FLAGS_AFTERBURNER;
1579 }
1580
1581 // makes the player invulnerable
1582 void MakePlayerInvulnerable(int slot, float time, bool play_sound_and_message) {
1583 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1584 Players[slot].flags |= PLAYER_FLAGS_INVULNERABLE;
1585 Players[slot].invulnerable_time = time;
1586
1587 if (play_sound_and_message) {
1588 Players[slot].flags |= PLAYER_FLAGS_PLAYSOUNDMSGFORINVULN;
1589 static int inv_sound_on_id = -2;
1590 if (inv_sound_on_id == -2)
1591 inv_sound_on_id = FindSoundName("Invulnerability on");
1592
1593 if (inv_sound_on_id != -1)
1594 Sound_system.Play3dSound(inv_sound_on_id, &Objects[Players[slot].objnum], MAX_GAME_VOLUME / 2);
1595
1596 if (slot == Player_num) {
1597 AddHUDMessage(TXT_INVULNON);
1598 }
1599 }
1600 }
1601
1602 // makes the player invulnerable
1603 void MakePlayerVulnerable(int slot) {
1604 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1605 // Play sound maybe.
1606 Players[slot].flags &= ~PLAYER_FLAGS_INVULNERABLE;
1607 Players[slot].invulnerable_time = 0.0f;
1608
1609 if (Players[slot].flags & PLAYER_FLAGS_PLAYSOUNDMSGFORINVULN) {
1610 static int inv_sound_off_id = -1;
1611 if (inv_sound_off_id == -1)
1612 inv_sound_off_id = FindSoundName("Invulnerability off");
1613
1614 if (inv_sound_off_id != -1)
1615 Sound_system.Play3dSound(inv_sound_off_id, &Objects[Players[slot].objnum], MAX_GAME_VOLUME / 2);
1616
1617 if (slot == Player_num) {
1618 AddHUDMessage(TXT_INVULNOFF);
1619 }
1620 }
1621 }
1622
1623 // Performs the player death sequence.
1624
1625 // Here list prototypes of all player automatic functions
1626 void DoNewPlayerDeathFrame(int slot);
1627
1628 // Does sampling of player position plus sets the camera positon
1629
1630 void UpdatePlayerCameraPosition() {
1631 object *playerobj = &Objects[Players[Player_num].objnum];
1632 vector dest_pos;
1633 matrix dest_mat;
1634 int dest_room;
1635 int total_increments = 0;
1636
1637 // Increment our timers
1638 Player_camera_last_sample_time += Frametime;
1639 Player_camera_last_follow_time += Frametime;
1640
1641 ASSERT(Player_camera_last_sample_time >= 0);
1642 ASSERT(Player_camera_last_follow_time >= 0);
1643
1644 while (Player_camera_last_sample_time >= CAMERA_SAMPLE_INCREMENT) {
1645 Player_camera_last_sample_time -= CAMERA_SAMPLE_INCREMENT;
1646 total_increments++;
1647 }
1648
1649 if (total_increments > 0) {
1650 vector delta_vec = playerobj->pos - Camera_sample_vectors[Camera_sample_index];
1651
1652 vector delta_r = playerobj->orient.rvec - Camera_sample_matrix[Camera_sample_index].rvec;
1653 vector delta_u = playerobj->orient.uvec - Camera_sample_matrix[Camera_sample_index].uvec;
1654 vector delta_f = playerobj->orient.fvec - Camera_sample_matrix[Camera_sample_index].fvec;
1655
1656 delta_vec /= total_increments;
1657 delta_r /= total_increments;
1658 delta_u /= total_increments;
1659 delta_f /= total_increments;
1660
1661 vector current_pos = Camera_sample_vectors[Camera_sample_index];
1662 vector current_r = Camera_sample_matrix[Camera_sample_index].rvec;
1663 vector current_u = Camera_sample_matrix[Camera_sample_index].uvec;
1664 vector current_f = Camera_sample_matrix[Camera_sample_index].fvec;
1665
1666 int current_room = Camera_sample_rooms[Camera_sample_index];
1667
1668 for (int i = 0; i < total_increments; i++) {
1669 Camera_sample_vectors[Camera_sample_index] = current_pos;
1670
1671 if (i < (total_increments / 2))
1672 Camera_sample_rooms[Camera_sample_index] = current_room;
1673 else
1674 Camera_sample_rooms[Camera_sample_index] = playerobj->roomnum;
1675
1676 Camera_sample_matrix[Camera_sample_index].rvec = current_r;
1677 Camera_sample_matrix[Camera_sample_index].uvec = current_u;
1678 Camera_sample_matrix[Camera_sample_index].fvec = current_f;
1679
1680 Camera_sample_index++;
1681
1682 if (Camera_sample_index == MAX_CAMERA_SAMPLES)
1683 Camera_sample_index = 0;
1684
1685 current_pos += delta_vec;
1686 current_r += delta_r;
1687 current_u += delta_u;
1688 current_f += delta_f;
1689 }
1690
1691 Camera_sample_vectors[Camera_sample_index] = current_pos;
1692 Camera_sample_rooms[Camera_sample_index] = playerobj->roomnum;
1693 Camera_sample_matrix[Camera_sample_index] = playerobj->orient;
1694 }
1695
1696 while (Player_camera_last_follow_time >= CAMERA_SAMPLE_INCREMENT) {
1697 Camera_follow_index++;
1698
1699 if (Camera_follow_index == MAX_CAMERA_SAMPLES)
1700 Camera_follow_index = 0;
1701
1702 Player_camera_last_follow_time -= CAMERA_SAMPLE_INCREMENT;
1703 }
1704
1705 // Get normalize position of the following camera
1706 int follow_start = Camera_follow_index;
1707 int follow_end = (Camera_follow_index + 1) % MAX_CAMERA_SAMPLES;
1708
1709 float follow_norm = Player_camera_last_follow_time / CAMERA_SAMPLE_INCREMENT;
1710
1711 ASSERT(follow_norm >= 0 && follow_norm <= 1);
1712
1713 // Set position
1714 dest_pos =
1715 ((1.0 - follow_norm) * Camera_sample_vectors[follow_start]) + (follow_norm * Camera_sample_vectors[follow_end]);
1716
1717 // Set room
1718 if (follow_norm > .5)
1719 dest_room = Camera_sample_rooms[follow_start];
1720 else
1721 dest_room = Camera_sample_rooms[follow_end];
1722
1723 // Set orientation matrix
1724 dest_mat.rvec = ((1.0 - follow_norm) * Camera_sample_matrix[follow_start].rvec) +
1725 ((follow_norm)*Camera_sample_matrix[follow_end].rvec);
1726 dest_mat.uvec = ((1.0 - follow_norm) * Camera_sample_matrix[follow_start].uvec) +
1727 ((follow_norm)*Camera_sample_matrix[follow_end].uvec);
1728 dest_mat.fvec = ((1.0 - follow_norm) * Camera_sample_matrix[follow_start].fvec) +
1729 ((follow_norm)*Camera_sample_matrix[follow_end].fvec);
1730
1731 // Set camera position
1732 fvi_info hit_data;
1733 fvi_query fq;
1734 vector new_pos = dest_pos;
1735 new_pos -= dest_mat.fvec * (playerobj->size * 3);
1736 new_pos += dest_mat.uvec * (playerobj->size / 2);
1737
1738 fq.p1 = &new_pos;
1739 fq.p0 = &dest_pos;
1740 fq.startroom = dest_room;
1741 fq.rad = .5;
1742 fq.thisobjnum = OBJNUM(playerobj);
1743 fq.ignore_obj_list = NULL;
1744 fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_NON_LIGHTMAP_OBJECTS;
1745 fvi_FindIntersection(&fq, &hit_data);
1746
1747 ObjSetPos(&Objects[Player_camera_objnum], &hit_data.hit_pnt, hit_data.hit_room, &dest_mat, false);
1748 }
1749
1750 // Creates or destroys a player camera depending on what the situation calls for
1751 void SetupPlayerCamera() {
1752 object *playerobj = &Objects[Players[Player_num].objnum];
1753
1754 if (Player_has_camera) {
1755 if (Player_camera_objnum == -1) {
1756 // We have to create a new camera
1757 int objnum = ObjCreate(OBJ_CAMERA, 0, playerobj->roomnum, &playerobj->pos, &playerobj->orient);
1758 if (objnum < 0) {
1759 // Couldn't create a camera for some reason
1760 Player_has_camera = false;
1761 Player_camera_objnum = 0;
1762 return;
1763 } else {
1764 Player_camera_objnum = objnum;
1765 Camera_sample_index = MAX_CAMERA_SUB_SAMPLES;
1766 Player_camera_last_sample_time = 0;
1767 Player_camera_last_follow_time = 0;
1768 Camera_follow_index = 0;
1769
1770 for (int i = 0; i < MAX_CAMERA_SAMPLES; i++) {
1771 Camera_sample_matrix[i] = playerobj->orient;
1772 Camera_sample_vectors[i] = playerobj->pos;
1773 Camera_sample_rooms[i] = playerobj->roomnum;
1774 }
1775 }
1776 }
1777
1778 if (Viewer_object == playerobj) {
1779 // Set viewer to be camera
1780 Viewer_object = &Objects[Player_camera_objnum];
1781 }
1782
1783 UpdatePlayerCameraPosition();
1784 } else {
1785 if (Player_camera_objnum != -1) {
1786 SetObjectDeadFlag(&Objects[Player_camera_objnum]);
1787 Player_camera_objnum = -1;
1788 }
1789 }
1790 }
1791
1792 // Does actions for the given player slot
1793 void DoPlayerFrameForOne(int slot) {
1794 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
1795 object *obj = &Objects[Players[slot].objnum];
1796 static int napalm_id = -1;
1797
1798 Players[slot].time_level = Gametime;
1799
1800 if (napalm_id == -1) {
1801 napalm_id = FindWeaponName("Napalm");
1802 }
1803
1804 // If piggy backing observer, then set position relative to observed object
1805 if (obj->type == OBJ_OBSERVER && Players[slot].piggy_objnum != -1) {
1806 object *observed = &Objects[Players[slot].piggy_objnum];
1807 ObjSetPos(obj, &observed->pos, observed->roomnum, &observed->orient, false);
1808
1809 obj->mtype.phys_info = observed->mtype.phys_info;
1810 }
1811
1812 if (obj->type == OBJ_PLAYER || obj->type == OBJ_OBSERVER && obj->id == Player_num) {
1813 // Do camera stuff if needed
1814 SetupPlayerCamera();
1815 }
1816
1817 if (Demo_flags != DF_PLAYBACK) {
1818 if ((Players[slot].flags & PLAYER_FLAGS_DYING) || (Players[slot].flags & PLAYER_FLAGS_DEAD))
1819 DoNewPlayerDeathFrame(slot);
1820 }
1821
1822 // do invulnerable stuff
1823 if (Players[slot].flags & PLAYER_FLAGS_INVULNERABLE) {
1824 Players[slot].invulnerable_time -= Frametime;
1825 if (Players[slot].invulnerable_time <= 0.0f) {
1826 // deinvulnerablize the player!!
1827 MakePlayerVulnerable(slot);
1828 }
1829 }
1830
1831 // Do terrain damage stuff
1832 if (Terrain_sky.damage_per_second > 0 && !(Players[slot].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))) {
1833 if (OBJECT_OUTSIDE(obj)) {
1834 float scalar = GetTerrainDynamicScalar(&obj->pos, CELLNUM(obj->roomnum));
1835
1836 // White out the screen
1837 if (scalar > 0 && slot == Player_num) {
1838 float vals[4];
1839
1840 vals[0] = 1.0;
1841 vals[1] = 1.0;
1842 vals[2] = .8f;
1843 vals[3] = scalar / 4;
1844
1845 CreateNewEvent(RENDER_EVENT, 0, 0, &vals, sizeof(float) * 4, DrawAlphaEvent);
1846 }
1847
1848 if (scalar > .7) {
1849 SetNapalmDamageEffect(obj, NULL, napalm_id);
1850 obj->effect_info->damage_time = 1;
1851 obj->effect_info->damage_per_second = 2;
1852 }
1853 }
1854 }
1855
1856 Players[slot].invul_magnitude -= (Frametime * 2);
1857
1858 // Drop the red effect of the console player faster than other players
1859 float alpha_blend_scalar_time = 1.0;
1860 if (slot == Player_num)
1861 alpha_blend_scalar_time = 2.0;
1862
1863 Players[slot].damage_magnitude -= (Frametime * (MAX_DAMAGE_MAG)*alpha_blend_scalar_time);
1864 Players[slot].edrain_magnitude -= (Frametime * (MAX_EDRAIN_MAG)*alpha_blend_scalar_time);
1865
1866 if (Players[slot].invul_magnitude < 0)
1867 Players[slot].invul_magnitude = 0;
1868
1869 if (Players[slot].damage_magnitude < 0)
1870 Players[slot].damage_magnitude = 0;
1871 if (Players[slot].edrain_magnitude < 0)
1872 Players[slot].edrain_magnitude = 0;
1873
1874 if ((obj->weapon_fire_flags & WFF_SPRAY) && !(Players[slot].flags & PLAYER_FLAGS_DEAD)) {
1875 int ship_index = Players[slot].ship_index;
1876 int wb_index = Players[slot].weapon[PW_PRIMARY].index;
1877 DoSprayEffect(&Objects[Players[slot].objnum], &Ships[ship_index].static_wb[wb_index], wb_index);
1878 }
1879
1880 // Do On/Off weapons for multiplayer
1881 if (slot != Player_num && (obj->weapon_fire_flags & WFF_ON_OFF) && !(Players[slot].flags & PLAYER_FLAGS_DEAD)) {
1882 FireOnOffWeapon(&Objects[Players[slot].objnum]);
1883 }
1884
1885 // Do thrust stuff here
1886 if (Player_num == slot && Game_toggles.ship_noises == false) {
1887 if (Players[slot].thruster_sound_handle > -1) {
1888 Sound_system.StopSoundImmediate(Players[slot].thruster_sound_handle);
1889 Players[slot].thruster_sound_handle = -1;
1890 }
1891 }
1892
1893 if (Players[slot].flags & PLAYER_FLAGS_THRUSTED) {
1894 Players[slot].thrust_mag += (Frametime * 2);
1895 if (Players[slot].thrust_mag > 1)
1896 Players[slot].thrust_mag = 1;
1897
1898 // Play thrust sound
1899 if (slot == Player_num) {
1900 if (Players[slot].thruster_sound_state == 0) {
1901 if (Players[slot].thruster_sound_handle != -1) {
1902 Sound_system.StopSoundImmediate(Players[slot].thruster_sound_handle);
1903 Players[slot].thruster_sound_handle = -1;
1904 }
1905 if (Players[slot].thruster_sound_handle == -1) {
1906 if (Game_toggles.ship_noises) {
1907 Players[slot].thruster_sound_handle = Sound_system.Play3dSound(SOUND_SHIP_FORWARD_THRUST, obj);
1908 }
1909 }
1910
1911 Players[slot].thruster_sound_state = 1;
1912 }
1913 }
1914 } else {
1915 // Cool down thrust
1916 Players[slot].thrust_mag -= (Frametime * 2);
1917 if (Players[slot].thrust_mag < 0)
1918 Players[slot].thrust_mag = 0;
1919
1920 // Stop thrust sound
1921 if (slot == Player_num) {
1922 if (Players[slot].thruster_sound_state == 1) {
1923 if (Players[slot].thruster_sound_handle != -1) {
1924 Sound_system.StopSoundImmediate(Players[slot].thruster_sound_handle);
1925 }
1926
1927 Players[slot].thruster_sound_handle = -1;
1928
1929 if (Game_toggles.ship_noises) {
1930 Sound_system.Play3dSound(SOUND_SHIP_FORWARD_RELEASE, obj);
1931 }
1932 }
1933
1934 if (Players[slot].thruster_sound_handle == -1) {
1935 if (Game_toggles.ship_noises) {
1936 Players[slot].thruster_sound_handle = Sound_system.Play3dSound(SOUND_SHIP_IDLE, obj);
1937 }
1938 }
1939 Players[slot].thruster_sound_state = 0;
1940 }
1941 }
1942
1943 // Do afterburner stuff
1944 if ((Players[slot].flags & PLAYER_FLAGS_AFTERBURN_ON) &&
1945 !(Players[slot].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))) {
1946 if (Players[slot].afterburner_sound_handle == -1) {
1947 // turn on the afterburner!
1948 Players[slot].afterburner_sound_handle = Sound_system.Play3dSound(SOUND_AFTERBURNER, obj);
1949 }
1950
1951 Players[slot].afterburner_mag += (Frametime * 2);
1952 if (Players[slot].afterburner_mag > 1)
1953 Players[slot].afterburner_mag = 1;
1954 } else {
1955 // Cool down afterburner
1956 Players[slot].afterburner_mag -= (Frametime * 2);
1957 if (Players[slot].afterburner_mag < 0)
1958 Players[slot].afterburner_mag = 0;
1959
1960 if (Players[slot].afterburner_sound_handle != -1) {
1961 Sound_system.StopSoundImmediate(Players[slot].afterburner_sound_handle);
1962 Players[slot].afterburner_sound_handle = -1;
1963 Sound_system.Play3dSound(SOUND_AFTERBURNER_TAIL, obj);
1964 }
1965 }
1966 }
1967
1968 // Do player automatic frame (all player automatic actions)
1969 // Does all player, single or multiplayer games
1970 void DoPlayerFrame() {
1971 if (Demo_flags == DF_PLAYBACK) {
1972 for (int i = 0; i < MAX_PLAYERS; i++) {
1973 if (Objects[Players[i].objnum].id != i)
1974 continue;
1975 if (Objects[Players[i].objnum].type == OBJ_GHOST)
1976 continue;
1977
1978 DoPlayerFrameForOne(i);
1979 }
1980
1981 } else if (Game_mode & GM_MULTI) {
1982 for (int i = 0; i < MAX_NET_PLAYERS; i++) {
1983 if (!(NetPlayers[i].flags & NPF_CONNECTED))
1984 continue;
1985
1986 DoPlayerFrameForOne(i);
1987 }
1988
1989 } else {
1990 DoPlayerFrameForOne(Player_num);
1991 }
1992 }
1993
1994 // This function performs the death roll for a player.
1995 #define MIN_DEATHCAM_DIST 40.0f
1996 #define MEDIAN_DEATHCAM_DIST 80.0f
1997 #define MAX_DEATHCAM_DIST 150.0f
1998
1999 #define DEATH_PHYS_INTERVAL 0.10f
2000 #define DEATH_FATE_INTERVAL 0.50f
2001
2002 #define MAX_EXPLOSION_MAG 40.0f
2003 #define MAX_ROLL_TIME 2.5
2004 #define DEATH_COCKPIT_TIME 0.0f
2005
2006 #define DEATH_INSTANT 0
2007 #define DEATH_FALL 1
2008 #define DEATH_BREAKUP 2
2009 #define DEATH_D2STYLE 3
2010
2011 #define DEATH_EXPLODE_THRESHOLD 100.0f
2012 #define DEATH_BREAKUP_THRESHOLD 40.0f
2013
2014 struct tDeathSeq {
2015 object *camera;
2016 object *oldviewer;
2017
2018 poly_model *dying_model;
2019
2020 int16_t fate;
2021 int16_t breakup_count;
2022 float initial_death_time;
2023 float time_dying;
2024 float max_time_dying;
2025 float physics_frametime;
2026 float fate_frametime;
2027
2028 float damage;
2029 float accel_mod;
2030 vector force_dir;
2031
2032 uint8_t saved_ctrl_type;
2033 uint32_t saved_phys_flags;
2034 float saved_drag;
2035 vector saved_rotthrust;
2036
2037 tHUDMode saved_cockpit;
2038 int saved_player_modelnum;
2039 bool in_cockpit;
2040
2041 tDeathSeq() { camera = NULL; };
2042
2043 };
2044
2045 static tDeathSeq Death[MAX_NET_PLAYERS];
2046
2047 void debug_deathtype(int slot, int damage) {
2048 if (Death[slot].fate == DEATH_INSTANT)
2049 mprintf(0, "INSTANT DEATH ");
2050 else if (Death[slot].fate == DEATH_FALL)
2051 mprintf(0, "FALLING DEATH ");
2052 else if (Death[slot].fate == DEATH_BREAKUP)
2053 mprintf(0, "BREAKUP DEATH ");
2054 else
2055 mprintf(0, "UNKNOWN DEATH ");
2056 }
2057
2058 float MoveDeathCam(int slot, vector *vec, float distance);
2059 void PlayerShipExplode(object *obj, float magnitude);
2060 void PlayerShipBreakup(object *obj, float magnitude);
2061 void PlayerShipSpewPart(object *obj, int subobjnum, float magnitude);
2062
2063 void InitiatePlayerDeath(object *playerobj, bool melee, int fate) {
2064 if (!(Players[playerobj->id].flags & (PLAYER_FLAGS_DEAD + PLAYER_FLAGS_DYING))) {
2065 // player is dying. We don't want to make player dead yet.
2066 Players[playerobj->id].flags |= PLAYER_FLAGS_DYING;
2067
2068 // Take care of stuff that should happen when you die
2069 ClearPlayerFiring(playerobj, PW_PRIMARY);
2070 ClearPlayerFiring(playerobj, PW_SECONDARY);
2071
2072 // Start the death sequence
2073 StartPlayerDeath(playerobj->id, -playerobj->shields, melee, fate);
2074 }
2075 }
2076
2077 // Chooses the style of death a player is going to use
2078 int PlayerChooseDeathFate(int slot, float damage, bool melee) {
2079 int fate;
2080 bool is_moving;
2081 object *playerobj = &Objects[Players[slot].objnum];
2082
2083 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2084
2085 if (vm_GetMagnitude(&playerobj->mtype.phys_info.velocity))
2086 is_moving = true;
2087 else
2088 is_moving = false;
2089
2090 fate = (damage <= DEATH_BREAKUP_THRESHOLD && is_moving && !melee && OBJECT_OUTSIDE(playerobj)) ? DEATH_BREAKUP
2091 : (damage <= DEATH_EXPLODE_THRESHOLD || melee) ? DEATH_FALL
2092 : DEATH_INSTANT;
2093
2094 if (fate == DEATH_BREAKUP) {
2095 if ((ps_rand() % 4) < 2)
2096 fate = DEATH_D2STYLE;
2097 } else if (fate == DEATH_FALL) {
2098 if ((ps_rand() % 4) != 3)
2099 fate = DEATH_D2STYLE;
2100 }
2101
2102 // split ship into subobjects. they should still be one object but now with several parts.
2103 if (playerobj->rtype.pobj_info.dying_model_num == -1) {
2104 if (fate == DEATH_BREAKUP) {
2105 fate = DEATH_FALL;
2106 }
2107 }
2108
2109 return fate;
2110 }
2111
2112 ///////////////////////////////////////////////////////////////////////////////
2113 // Starts player death sequence.
2114
2115 void StartPlayerDeath(int slot, float damage, bool melee, int fate) {
2116 int objnum;
2117 object *playerobj = &Objects[Players[slot].objnum];
2118 int killer_num = Players[playerobj->id].killer_objnum;
2119 object *killer;
2120
2121 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2122
2123 Players[playerobj->id].num_deaths_level++;
2124 Players[playerobj->id].num_deaths_total++;
2125 // Do killer object stuff
2126 if (killer_num < 0 || killer_num > MAX_OBJECTS)
2127 killer = NULL;
2128 else {
2129 killer = &Objects[killer_num];
2130 if (killer->type == OBJ_NONE)
2131 killer = NULL;
2132 }
2133
2134 // determine current state of player object.
2135 // create death camera if it doesn't exit
2136 if (slot == Player_num) {
2137 objnum = ObjCreate(OBJ_CAMERA, 0, playerobj->roomnum, &playerobj->pos, &playerobj->orient);
2138 if (objnum == -1) {
2139 mprintf(0, "Failed to create death cam.\n");
2140 Int3();
2141 } else {
2142 Death[slot].camera = &Objects[objnum];
2143 if (Objects[objnum].type == OBJ_NONE)
2144 Int3(); // Samir- This really shouldn't happen. will cause assertion
2145 }
2146
2147 Death[slot].oldviewer = Viewer_object;
2148
2149 // set screen mode
2150 if (Cinematic_inuse) {
2151 Death[slot].saved_cockpit = Cinematic_GetOldHudMode();
2152 } else {
2153 Death[slot].saved_cockpit = GetHUDMode();
2154 }
2155
2156 Death[slot].in_cockpit = true;
2157 }
2158
2159 // save player ship information that will be changed here.
2160 Death[slot].saved_ctrl_type = playerobj->control_type;
2161 Death[slot].saved_phys_flags = playerobj->mtype.phys_info.flags;
2162 Death[slot].saved_drag = playerobj->mtype.phys_info.drag;
2163 Death[slot].saved_player_modelnum = playerobj->rtype.pobj_info.model_num;
2164 Death[slot].saved_rotthrust = playerobj->mtype.phys_info.rotthrust;
2165 Death[slot].breakup_count = 0;
2166
2167 if (killer == NULL) // If the killer isn't valid, just use the reverse forward direction
2168 Death[slot].force_dir = -playerobj->orient.fvec;
2169 else
2170 Death[slot].force_dir = playerobj->pos - killer->pos;
2171
2172 vm_NormalizeVector(&Death[slot].force_dir);
2173 Death[slot].force_dir = Death[slot].force_dir * playerobj->orient;
2174
2175 // determine fate of player ship
2176 if (fate == -1)
2177 Death[slot].fate = PlayerChooseDeathFate(slot, damage, melee);
2178 else
2179 Death[slot].fate = fate;
2180
2181 // split ship into subobjects. they should still be one object but now with several parts.
2182 if (playerobj->rtype.pobj_info.dying_model_num != -1) {
2183 playerobj->rtype.pobj_info.model_num = playerobj->rtype.pobj_info.dying_model_num;
2184 Death[slot].dying_model = GetPolymodelPointer(playerobj->rtype.pobj_info.model_num);
2185 playerobj->rtype.pobj_info.subobj_flags = 0xffffffff;
2186 // playerobj->rtype.pobj_info.subobj_flags = ~(0xffffffff << (Death[slot].dying_model->n_models));
2187 // mprintf(0, "initflags=%08x\n", playerobj->rtype.pobj_info.subobj_flags);
2188 } else {
2189 // This ship has no dying model so dont break up
2190 if (Death[slot].fate == DEATH_BREAKUP)
2191 Int3(); // Get Jason - a death was chosen that this ship doesn't support
2192
2193 Death[slot].dying_model = GetPolymodelPointer(playerobj->rtype.pobj_info.model_num);
2194 playerobj->rtype.pobj_info.subobj_flags = 0xffffffff;
2195 }
2196
2197 // determine physics properties of death
2198 SetObjectControlType(playerobj, CT_NONE);
2199 float rotate_adj = 0.0f;
2200
2201 if (Death[slot].fate == DEATH_BREAKUP) {
2202 // a breakup typically means the ship starts to fall apart.
2203 Death[slot].accel_mod = 1.0f;
2204 playerobj->mtype.phys_info.flags = (PF_FIXED_ROT_VELOCITY);
2205 playerobj->mtype.phys_info.drag = .005f;
2206 playerobj->mtype.phys_info.mass = 3000.0f;
2207 playerobj->mtype.phys_info.coeff_restitution = 0.3f;
2208 rotate_adj = 32768.0f;
2209 } else if (Death[slot].fate == DEATH_D2STYLE) {
2210 Death[slot].accel_mod = 0.960f;
2211 playerobj->mtype.phys_info.drag = 50.0;
2212 playerobj->mtype.phys_info.mass = 3000.0f;
2213 playerobj->mtype.phys_info.flags = PF_FIXED_ROT_VELOCITY;
2214 playerobj->mtype.phys_info.coeff_restitution = 0.3f;
2215 rotate_adj = 32768.0f;
2216 } else {
2217 // if we're falling or dying immediately, let gravity take control of the ship while it
2218 // deaccelerates.
2219 Death[slot].accel_mod = 0.960f;
2220 playerobj->mtype.phys_info.flags = PF_GRAVITY | PF_FIXED_ROT_VELOCITY;
2221 playerobj->mtype.phys_info.num_bounces = 0;
2222 playerobj->mtype.phys_info.coeff_restitution = .03f;
2223 playerobj->mtype.phys_info.mass = 2500.0f;
2224 playerobj->mtype.phys_info.drag = 50.0f;
2225 rotate_adj = 32768.0f;
2226 }
2227
2228 playerobj->mtype.phys_info.rotvel.x = (float)((rotate_adj));
2229 playerobj->mtype.phys_info.rotvel.y = (float)((rotate_adj));
2230 playerobj->mtype.phys_info.rotvel.z = (float)((rotate_adj));
2231
2232 // set times and other stuff for dying.
2233 if (Death[slot].fate == DEATH_FALL)
2234 Death[slot].max_time_dying = 3.0f;
2235 else if (Death[slot].fate == DEATH_INSTANT)
2236 Death[slot].max_time_dying = 2.5f;
2237 else if (Death[slot].fate == DEATH_BREAKUP)
2238 Death[slot].max_time_dying = 4.0f;
2239 else if (Death[slot].fate == DEATH_D2STYLE)
2240 Death[slot].max_time_dying = 2.0f;
2241
2242 Total_time_dead = 0;
2243
2244 Death[slot].initial_death_time = Gametime;
2245 Death[slot].physics_frametime = Gametime;
2246 Death[slot].fate_frametime = Gametime;
2247
2248 #ifndef RELEASE
2249 // debug_deathtype(slot, damage);
2250 #endif
2251 }
2252
2253 ///////////////////////////////////////////////////////////////////////////////
2254 // The Death sequencer.
2255
2256 void DoNewPlayerDeathFrame(int slot) {
2257 object *playerobj;
2258
2259 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2260
2261 // Kevin added this in case the player dies and while dying stops recording a demo.
2262 // It's the cleanest solution I could find.
2263 if ((Player_num == slot) && (!Death[slot].camera))
2264 return;
2265
2266 // if (Player_num==slot)
2267 // ASSERT(Death[slot].camera);
2268
2269 playerobj = &Objects[Players[slot].objnum];
2270
2271 // determine current state of player object.
2272 Death[slot].time_dying = Gametime - Death[slot].initial_death_time;
2273
2274 // Increase death time
2275 if (slot == Player_num && (Players[slot].flags & PLAYER_FLAGS_DEAD)) {
2276 // Total_time_dead+=Frametime;
2277 Total_time_dead = Death[slot].time_dying;
2278 if (Total_time_dead > DEATH_RESPAWN_TIME) {
2279 AddPersistentHUDMessage(GR_RGB(0, 255, 0), HUD_MSG_PERSISTENT_CENTER, Game_window_y + Game_window_h - 20,
2280 HUD_MSG_PERSISTENT_INFINITE, 0, SOUND_NONE_INDEX, TXT_SPACETOCONT);
2281 }
2282 }
2283
2284 // depending on state of player ship, perform some operation
2285 if (Players[playerobj->id].flags & PLAYER_FLAGS_DYING) {
2286 // modify player ship physics as needed.
2287 // player ship will fall to the ground and deaccelerate
2288 // modify physics properties every INTERVAL
2289 if ((Death[slot].physics_frametime + DEATH_PHYS_INTERVAL) > Gametime) {
2290 if (Death[slot].fate == DEATH_FALL) {
2291 playerobj->mtype.phys_info.rotvel.x /= 1.15f;
2292 playerobj->mtype.phys_info.rotvel.y /= 1.1f;
2293 playerobj->mtype.phys_info.rotvel.z /= 1.0f;
2294 } else if (Death[slot].fate == DEATH_D2STYLE) {
2295 playerobj->mtype.phys_info.rotvel.x /= 1.15f;
2296 playerobj->mtype.phys_info.rotvel.y /= 1.0f;
2297 playerobj->mtype.phys_info.rotvel.z /= 1.05f;
2298 } else {
2299 playerobj->mtype.phys_info.rotvel.x /= 1.10f;
2300 playerobj->mtype.phys_info.rotvel.y /= 1.05f;
2301 playerobj->mtype.phys_info.rotvel.z /= 1.0f;
2302 }
2303
2304 playerobj->mtype.phys_info.velocity *= Death[slot].accel_mod;
2305 Death[slot].physics_frametime = Gametime;
2306 }
2307
2308 // move death camera if distance between death camera and player is less than a certain amount.
2309 if (slot == Player_num && Death[slot].in_cockpit) {
2310 if (Death[slot].time_dying > DEATH_COCKPIT_TIME) {
2311 Death[slot].in_cockpit = false;
2312 SetHUDMode(HUD_LETTERBOX);
2313 Viewer_object = Death[slot].camera; // set the current viewer to be this new camera.
2314 }
2315 } else if (slot == Player_num) {
2316 vector directional;
2317 float death_cam_dist = vm_VectorDistanceQuick(&Death[slot].camera->pos, &playerobj->pos);
2318
2319 if (death_cam_dist < MIN_DEATHCAM_DIST) {
2320 vm_MakeRandomVector(&directional);
2321 MoveDeathCam(slot, &directional, MEDIAN_DEATHCAM_DIST);
2322 } else if (death_cam_dist > MAX_DEATHCAM_DIST) {
2323 vm_MakeRandomVector(&directional);
2324 MoveDeathCam(slot, &directional, MEDIAN_DEATHCAM_DIST);
2325 }
2326
2327 // check to see if the vector from death cam to player is obstructed by something.
2328 fvi_info hit_data;
2329 fvi_query fq;
2330
2331 hit_data.hit_type[0] = (OBJECT_OUTSIDE(playerobj) ? HIT_TERRAIN : HIT_WALL);
2332 fq.p1 = &playerobj->pos;
2333 fq.p0 = &Death[slot].camera->pos;
2334 fq.startroom = Death[slot].camera->roomnum;
2335 fq.rad = .5;
2336 fq.thisobjnum = OBJNUM(Death[slot].camera);
2337 fq.ignore_obj_list = NULL;
2338 fq.flags = 0;
2339 fvi_FindIntersection(&fq, &hit_data);
2340
2341 if (hit_data.hit_type[0] == HIT_WALL) {
2342 // death camera's view is obstructed, move the death cam
2343 // mprintf(0, "Death cam view obstructed, changing view...\n");
2344 vm_MakeRandomVector(&directional);
2345 MoveDeathCam(slot, &directional, MEDIAN_DEATHCAM_DIST);
2346 }
2347
2348 // orient death camera towards player ship
2349 directional = playerobj->pos - Death[slot].camera->pos;
2350 if (vm_GetMagnitudeFast(&directional) == 0.0f)
2351 directional.x += 1.0f;
2352 vm_VectorToMatrix(&Death[slot].camera->orient, &directional, NULL, NULL);
2353 }
2354
2355 // perform fate specific actions here
2356 if (Death[slot].time_dying >= Death[slot].max_time_dying) {
2357 PlayerShipExplode(playerobj, 40.0f);
2358 Players[playerobj->id].flags |= PLAYER_FLAGS_DEAD;
2359 Players[playerobj->id].flags &= ~PLAYER_FLAGS_DYING;
2360 }
2361 // fate action occurs every fate interval.
2362 else if ((Death[slot].fate_frametime + DEATH_FATE_INTERVAL) > Gametime) {
2363 if (Death[slot].fate == DEATH_BREAKUP) {
2364 if (ps_rand() % 8) {
2365 // break up a piece of the ship
2366 if (Death[slot].breakup_count == 2) {
2367 Death[slot].time_dying = Death[slot].max_time_dying;
2368 } else {
2369 PlayerShipBreakup(playerobj, 20.0f + (ps_rand() % 10));
2370 Death[slot].breakup_count++;
2371 // mprintf(0, "Breakup!\n");
2372 }
2373 }
2374 }
2375 Death[slot].fate_frametime = Gametime;
2376 }
2377
2378 // do smoke trails and special visual effects.
2379 if ((ps_rand() % 6) == 0) {
2380 // smoke
2381 int visnum;
2382 vector smoke_pt;
2383 smoke_pt = (-playerobj->orient.fvec) * (playerobj->size * 0.5f);
2384 smoke_pt = playerobj->pos + smoke_pt;
2385 visnum = CreateFireball(&smoke_pt, BLACK_SMOKE_INDEX, playerobj->roomnum, VISUAL_FIREBALL);
2386 if (visnum >= 0)
2387 VisEffects[visnum].size = 1.0 + ((ps_rand() % 3) / 3.0); // Make small!
2388 }
2389
2390 // Create an explosion that follows every now and then
2391 if ((ps_rand() % 5) == 0) {
2392
2393 vector dest;
2394 poly_model *pm = Death[slot].dying_model;
2395 bsp_info *sm = &pm->submodel[0];
2396 int vertnum = ps_rand() % sm->nverts;
2397
2398 GetPolyModelPointInWorld(&dest, pm, &playerobj->pos, &playerobj->orient, 0, &sm->verts[vertnum]);
2399 int visnum = CreateFireball(&dest, GetRandomSmallExplosion(), playerobj->roomnum, VISUAL_FIREBALL);
2400
2401 if (visnum >= 0) { // DAJ added to pervent -1 array index
2402 VisEffects[visnum].size += ((ps_rand() % 20) / 20.0) * 3.0;
2403
2404 if ((ps_rand() % 2)) {
2405 VisEffects[visnum].movement_type = MT_PHYSICS;
2406 VisEffects[visnum].velocity = playerobj->mtype.phys_info.velocity;
2407 VisEffects[visnum].mass = playerobj->mtype.phys_info.mass;
2408 VisEffects[visnum].drag = playerobj->mtype.phys_info.drag;
2409 }
2410 }
2411 }
2412 }
2413
2414 // mprintf(0,"Playerobj size=%f\n",playerobj->size);
2415 }
2416
2417 #define TARGET_DEGREE (170 / 2)
2418 #define FOV_CHANGE_TIME .7f
2419
2420 // Alters the field of view over a period of time
2421 void DoFOVEvent(int eventnum, void *data) {
2422 float *val = (float *)data;
2423 float new_time = *val;
2424 float norm = new_time / FOV_CHANGE_TIME;
2425
2426 new_time -= Frametime;
2427
2428 if (new_time < 0) {
2429 Render_zoom = D3_DEFAULT_ZOOM;
2430 } else {
2431
2432 float num = (Render_FOV / 2) + (norm * (TARGET_DEGREE - (Render_FOV / 2)));
2433 num = (3.14 * (float)num / 180.0);
2434 Render_zoom = tan(num);
2435 CreateNewEvent(OBJECT_EVENT, FOV_CHANGE_EVENT, 0, &new_time, sizeof(float), DoFOVEvent);
2436 }
2437 }
2438
2439 // forces an end to the player death sequence
2440 void EndPlayerDeath(int slot) {
2441 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2442 object *playerobj = &Objects[Players[slot].objnum];
2443
2444 if (slot == Player_num) {
2445 if (Death[slot].camera) {
2446 ObjDelete(OBJNUM(Death[slot].camera));
2447 Death[slot].camera = NULL;
2448 Viewer_object = Death[slot].oldviewer;
2449 }
2450 SetHUDMode(Death[slot].saved_cockpit);
2451 ResetPersistentHUDMessage();
2452 }
2453
2454 if (!(Players[playerobj->id].flags & PLAYER_FLAGS_DEAD))
2455 PlayerShipExplode(playerobj, 50.0f);
2456
2457 // Stop sounds for this player
2458 PlayerStopSounds(slot);
2459
2460 // Get rid of explosions, weapons etc. that are still alive
2461 if (!(Game_mode & GM_MULTI))
2462 ClearTransientObjects(0);
2463
2464 // Reset the player object
2465 InitPlayerNewShip(slot, INVRESET_DEATHSPEW);
2466 ResetPlayerObject(slot);
2467
2468 // Do the zoom-in effect and set him for invulernable in single player
2469 if (slot == Player_num) {
2470 float val = FOV_CHANGE_TIME;
2471 float *valp = &val;
2472 DoFOVEvent(-1, (void *)valp);
2473
2474 if (!(Game_mode & GM_MULTI)) {
2475 MakePlayerInvulnerable(slot, 2.0);
2476 }
2477 }
2478
2479 // call osiris level event
2480 tOSIRISEventInfo evt;
2481 evt.evt_player_respawn.it_handle = Objects[Players[slot].objnum].handle;
2482 Osiris_CallLevelEvent(EVT_PLAYER_RESPAWN, &evt);
2483 }
2484
2485 void MovePlayerToWaypoint(object *objp);
2486
2487 void ResetPlayerObject(int slot, bool f_reset_pos) {
2488 // Init physics
2489 object *playobj = &Objects[Players[slot].objnum];
2490 ship *ship = &Ships[Players[slot].ship_index];
2491
2492 playobj->shields = INITIAL_SHIELDS;
2493 Players[slot].energy = INITIAL_ENERGY;
2494 playobj->mtype.phys_info = Ships[Players[slot].ship_index].phys_info;
2495 Objects[Players[slot].objnum].effect_info->type_flags = EF_VOLUME_LIT;
2496
2497 if (playobj->effect_info->sound_handle != SOUND_NONE_INDEX) {
2498 Sound_system.StopSoundLooping(playobj->effect_info->sound_handle);
2499 playobj->effect_info->sound_handle = SOUND_NONE_INDEX;
2500 }
2501
2502 if (f_reset_pos) {
2503 if ((Game_mode & GM_MULTI) && !(Netgame.flags & NF_RESPAWN_WAYPOINT)) {
2504 ObjSetPos(playobj, &Players[slot].start_pos, Players[slot].start_roomnum, &Players[slot].start_orient, false);
2505 } else {
2506 MovePlayerToWaypoint(playobj);
2507 }
2508 }
2509
2510 playobj->render_type = RT_POLYOBJ;
2511 playobj->rtype.pobj_info.model_num = ship->model_handle;
2512 playobj->rtype.pobj_info.dying_model_num = ship->dying_model_handle;
2513 playobj->rtype.pobj_info.tmap_override = -1;
2514 playobj->rtype.pobj_info.subobj_flags = 0xFFFFFFFF;
2515 playobj->lighting_render_type = LRT_GOURAUD;
2516 playobj->lm_object.used = 0;
2517 playobj->flags = (OF_POLYGON_OBJECT | OF_DESTROYABLE);
2518
2519 if (Demo_flags == DF_PLAYBACK) {
2520 playobj->flags |= OF_SERVER_OBJECT;
2521 }
2522
2523 if (Game_mode & GM_MULTI) {
2524 if (Netgame.local_role == LR_CLIENT) {
2525 playobj->flags |= OF_SERVER_OBJECT;
2526 } else
2527 playobj->flags |= OF_CLIENT_KNOWS;
2528 }
2529
2530 playobj->size = Poly_models[playobj->rtype.pobj_info.model_num].rad;
2531
2532 vm_MakeZero(&playobj->mtype.phys_info.velocity);
2533 vm_MakeZero(&playobj->mtype.phys_info.thrust);
2534 vm_MakeZero(&playobj->mtype.phys_info.rotvel);
2535 vm_MakeZero(&playobj->mtype.phys_info.rotthrust);
2536
2537 playobj->mtype.phys_info.turnroll = 0;
2538
2539 if (slot == Player_num) {
2540 SetObjectControlType(playobj, CT_FLYING);
2541 playobj->movement_type = MT_PHYSICS;
2542 } else {
2543 SetObjectControlType(playobj, CT_NONE);
2544 playobj->movement_type = MT_PHYSICS;
2545 playobj->mtype.phys_info.flags = PF_FIXED_VELOCITY;
2546 }
2547
2548 if (Game_mode & GM_MULTI) {
2549 MultiMakePlayerReal(slot);
2550 if (Netgame.flags & NF_PERMISSABLE)
2551 playobj->mtype.phys_info.flags &= ~PF_WIGGLE;
2552 }
2553
2554 if (slot == Player_num) {
2555 Viewer_object = Player_object = playobj;
2556 }
2557
2558 // Reset quad firing mask
2559 object *objp = &Objects[Players[slot].objnum];
2560 for (int weapon_battery = 0; weapon_battery < MAX_WBS_PER_OBJ; weapon_battery++) {
2561 objp->dynamic_wb[weapon_battery].flags &= ~DWBF_QUAD;
2562 }
2563
2564 // Give the player a GuideBot if he doesn't have one and if the GB isn't out there
2565 if ((!(Game_mode & GM_MULTI)) && (Demo_flags != DF_PLAYBACK)) {
2566 // The first if is to prevent a tough demo playback bug where
2567 // the game would crash *after* the demo is done playing back.
2568 if (ObjGet(Buddy_handle[slot]))
2569 if ((!Players[slot].inventory.CheckItem(OBJ_ROBOT, ROBOT_GUIDEBOT)) &&
2570 (ObjGet(Buddy_handle[slot])->type != OBJ_ROBOT))
2571 Players[slot].inventory.Add(OBJ_ROBOT, ROBOT_GUIDEBOT);
2572 }
2573
2574 // reinit the reticle
2575 ResetReticle();
2576 }
2577
2578 // Resets a player's control type back to it's default setting
2579 void ResetPlayerControlType(int slot) {
2580 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2581
2582 // Init physics
2583 object *playobj = &Objects[Players[slot].objnum];
2584 ship *ship = &Ships[Players[slot].ship_index];
2585
2586 playobj->mtype.phys_info = Ships[Players[slot].ship_index].phys_info;
2587
2588 vm_MakeZero(&playobj->mtype.phys_info.velocity);
2589 vm_MakeZero(&playobj->mtype.phys_info.thrust);
2590 vm_MakeZero(&playobj->mtype.phys_info.rotvel);
2591 vm_MakeZero(&playobj->mtype.phys_info.rotthrust);
2592
2593 playobj->mtype.phys_info.turnroll = 0;
2594
2595 if (slot == Player_num) {
2596 SetObjectControlType(playobj, CT_FLYING);
2597 playobj->movement_type = MT_PHYSICS;
2598 } else {
2599 SetObjectControlType(playobj, CT_NONE);
2600 playobj->movement_type = MT_PHYSICS;
2601 playobj->mtype.phys_info.flags = PF_FIXED_VELOCITY;
2602 }
2603 }
2604
2605 // Makes the player into an AI controlled physics object
2606 void PlayerSetControlToAI(int slot, float velocity) {
2607 ASSERT(slot >= 0 && slot < MAX_PLAYERS);
2608 if (slot < 0 || slot >= MAX_PLAYERS)
2609 return;
2610
2611 object *pobj = &Objects[Players[slot].objnum];
2612
2613 // Turn off some player physics stuff
2614 pobj->mtype.phys_info.flags &= ~PF_USES_THRUST;
2615 pobj->mtype.phys_info.drag = .1f;
2616 pobj->mtype.phys_info.flags &= ~PF_LEVELING;
2617
2618 // pobj->flags &= ~OF_DESTROYABLE;
2619 vm_MakeZero(&pobj->mtype.phys_info.thrust);
2620 vm_MakeZero(&pobj->mtype.phys_info.rotthrust);
2621 vm_MakeZero(&pobj->mtype.phys_info.rotvel);
2622 vm_MakeZero(&pobj->mtype.phys_info.velocity);
2623
2624 // Put the player in AI mode
2625 SetObjectControlType(pobj, CT_AI);
2626
2627 memset(pobj->ai_info, 0, sizeof(ai_frame));
2628
2629 pobj->ai_info->ai_class = AIC_STATIC;
2630 pobj->ai_info->ai_type = AIT_AIS;
2631
2632 GoalInitTypeGoals(pobj, AIT_AIS);
2633
2634 pobj->ai_info->flags = AIF_PERSISTANT | AIF_DISABLE_FIRING | AIF_DISABLE_MELEE | AIF_ORIENT_TO_VEL;
2635 pobj->ai_info->max_velocity = velocity;
2636 pobj->ai_info->max_delta_velocity = 40.0f;
2637 pobj->ai_info->max_turn_rate = 14000;
2638 pobj->ai_info->awareness = AWARE_MOSTLY;
2639 pobj->ai_info->movement_type = MC_FLYING;
2640 pobj->ai_info->next_movement = AI_INVALID_INDEX;
2641 pobj->ai_info->anim_sound_handle = 0;
2642 pobj->ai_info->status_reg = 0;
2643 pobj->ai_info->last_played_sound_index = -1;
2644 pobj->ai_info->weapon_speed = 0.0f;
2645 pobj->ai_info->animation_type = AS_ALERT;
2646 pobj->ai_info->next_melee_time = Gametime;
2647 pobj->ai_info->next_flinch_time = Gametime;
2648 pobj->ai_info->target_handle = OBJECT_HANDLE_NONE;
2649 pobj->ai_info->next_check_see_target_time = Gametime;
2650 pobj->ai_info->last_see_target_time = Gametime;
2651 pobj->ai_info->last_render_time = -1.0f;
2652 pobj->ai_info->next_target_update_time = Gametime;
2653 pobj->ai_info->notify_flags |= AI_NOTIFIES_ALWAYS_ON;
2654 pobj->ai_info->last_see_target_pos = Zero_vector;
2655 pobj->ai_info->dodge_vel_percent = 1.0f;
2656 pobj->ai_info->attack_vel_percent = 1.0f;
2657 pobj->ai_info->fight_same = 0.0f;
2658 pobj->ai_info->agression = 0.0f;
2659 pobj->ai_info->avoid_friends_distance = 0.0f;
2660 pobj->ai_info->biased_flight_importance = 0.0f;
2661 pobj->ai_info->circle_distance = 10.0f;
2662 pobj->ai_info->dodge_percent = 0.0f;
2663 pobj->ai_info->fight_team = 0.0f;
2664
2665 AIPathInitPath(&pobj->ai_info->path);
2666 }
2667
2668 // Moves a player to a specified start position
2669 void PlayerMoveToStartPos(int player_slot, int start_slot) {
2670 object *playobj = &Objects[Players[player_slot].objnum];
2671
2672 if (start_slot >= 0) // Non autowaypoint
2673 {
2674 Players[player_slot].current_auto_waypoint_room = -1;
2675 ObjSetPos(playobj, &Players[start_slot].start_pos, Players[start_slot].start_roomnum,
2676 &Players[start_slot].start_orient, true);
2677 } else {
2678 // Do autowaypoint stuff
2679 int waypointnum = (-start_slot) + 1;
2680 Players[player_slot].current_auto_waypoint_room = waypointnum;
2681 MovePlayerToWaypoint(playobj);
2682 }
2683 }
2684
2685 // Force player to explode (this should be called to intercept the death sequencer's control of explosions
2686 void StartPlayerExplosion(int slot) {
2687 Death[slot].max_time_dying = 0.0f;
2688
2689 if (Death[slot].in_cockpit) {
2690 Death[slot].in_cockpit = false;
2691 SetHUDMode(HUD_LETTERBOX);
2692 Viewer_object = Death[slot].camera; // set the current viewer to be this new camera.
2693 }
2694 }
2695
2696 // Detaches a subobject from the player ship
2697 void DeadPlayerShipHit(object *obj, int hit_room, vector *hitpt, float magnitude) {
2698 fvi_info hit_data;
2699 fvi_query fq;
2700 vector hitvec, hitpt2;
2701 int subobjnum = -1;
2702
2703 // vector from hitpoint to object center position
2704 hitvec = obj->pos - (*hitpt);
2705 hitpt2 = *hitpt;
2706
2707 // get first subobject to be hit when looking for a hit subobject.
2708 hit_data.hit_type[0] = HIT_SPHERE_2_POLY_OBJECT;
2709
2710 while (hit_data.hit_type[0] != HIT_NONE) {
2711 fq.p0 = &hitpt2;
2712 fq.p1 = &obj->pos;
2713 fq.startroom = hit_room;
2714 fq.rad = obj->size;
2715 fq.thisobjnum = obj - Objects;
2716 fq.ignore_obj_list = NULL;
2717 fq.flags = FQ_CHECK_OBJS | FQ_OBJ_BACKFACE | FQ_ONLY_PLAYER_OBJ;
2718
2719 fvi_FindIntersection(&fq, &hit_data);
2720
2721 if (hit_data.hit_type[0] == HIT_SPHERE_2_POLY_OBJECT) {
2722 // we probably hit a subobject of the player object.
2723 // NOTE: we should check if the hit object is still the player object!
2724 subobjnum = hit_data.hit_subobject[0];
2725 } else if (hit_data.hit_type[0] != HIT_NONE) {
2726 hitpt2 = hit_data.hit_pnt;
2727 hit_data.hit_type[0] = HIT_NONE;
2728 }
2729 }
2730
2731 if (subobjnum > -1) {
2732 // we hit a subobject. new debris object, and delete this subobject from the player model. note that
2733 // we should must the suobject handle to the polymodel when we're done.
2734 PlayerShipSpewPart(obj, subobjnum, magnitude);
2735 }
2736 }
2737
2738 // Spews a guidebot
2739 void PlayerSpewGuidebot(object *parent, int type, int id) {
2740 int objnum;
2741 object *obj;
2742 int model_num = Object_info[ROBOT_GUIDEBOT].render_handle;
2743 float size;
2744
2745 if (stricmp(Ships[Players[parent->id].ship_index].name, "Black Pyro") == 0) {
2746 // Only spew red GB if merc is installed
2747 extern bool MercInstalled();
2748 if (MercInstalled())
2749 model_num = Object_info[ROBOT_GUIDEBOTRED].render_handle;
2750 }
2751
2752 PageInPolymodel(model_num, OBJ_ROBOT, &size);
2753
2754 objnum = ObjCreate(OBJ_DEBRIS, 0, parent->roomnum, &parent->pos, &parent->orient);
2755
2756 if (objnum < 0 || objnum > Highest_object_index) {
2757 mprintf(0, "WARNING: No object slots. Dead GB not created!\n");
2758 return;
2759 }
2760
2761 obj = &Objects[objnum];
2762
2763 // Set polygon-object-specific data
2764 obj->rtype.pobj_info.model_num = model_num;
2765 obj->rtype.pobj_info.subobj_flags = 0xFFFFFFFF;
2766
2767 // Set physics data for this object
2768
2769 obj->mtype.phys_info.velocity = parent->mtype.phys_info.velocity + parent->orient.fvec * 30.0;
2770
2771 vm_MakeZero(&obj->mtype.phys_info.rotthrust);
2772
2773 obj->size = Object_info[ROBOT_GUIDEBOT].size;
2774 obj->mtype.phys_info.mass = 40.0;
2775 obj->mtype.phys_info.drag = .001f;
2776
2777 obj->mtype.phys_info.flags = (PF_GRAVITY | PF_BOUNCE | PF_FIXED_ROT_VELOCITY);
2778 obj->mtype.phys_info.coeff_restitution = .25f;
2779
2780 obj->mtype.phys_info.rotvel.x = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
2781 obj->mtype.phys_info.rotvel.y = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
2782 obj->mtype.phys_info.rotvel.z = (float)((120000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
2783
2784 obj->mtype.phys_info.num_bounces = 5;
2785
2786 obj->movement_type = MT_PHYSICS;
2787
2788 ASSERT(obj != Player_object);
2789 obj->type = OBJ_DEBRIS;
2790 SetObjectControlType(obj, CT_DEBRIS); // become debris while exploding
2791 obj->lifeleft = 5.0 + ((ps_rand() % 50) * .05);
2792 obj->flags |= OF_USES_LIFELEFT;
2793 DemoWriteObjLifeLeft(obj);
2794 }
2795
2796 // Spews an object in a random direction
2797 void PlayerSpewObject(object *objp, int timed, int room, vector *pos, matrix *orient) {
2798 ASSERT((!(Game_mode & GM_MULTI)) || (Netgame.local_role == LR_SERVER));
2799
2800 ObjSetPos(objp, pos, room, orient, true);
2801
2802 // Set random velocity for powerups
2803 objp->mtype.phys_info.velocity.x = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
2804 objp->mtype.phys_info.velocity.z = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
2805 objp->mtype.phys_info.velocity.y = ((ps_rand() / (float)D3_RAND_MAX) - .5f) * 40.0; // +20 to -20
2806
2807 // Send object to other players
2808 if (Game_mode & GM_MULTI) {
2809 if (Netgame.flags & NF_COOP)
2810 timed = 0;
2811
2812 if (Netgame.local_role == LR_SERVER) {
2813 if (timed == 2) {
2814 objp->flags |= OF_USES_LIFELEFT;
2815 objp->lifeleft = 20.0;
2816 } else if (timed == 1) {
2817 objp->flags |= OF_USES_LIFELEFT;
2818 objp->lifeleft = 180.0;
2819 }
2820 DemoWriteObjLifeLeft(objp);
2821 }
2822 }
2823 }
2824
2825 // Spews an object in a random direction
2826 // Returns the new object
2827 int PlayerSpewObject(object *parent, int type, int id, int timed, void *sinfo) {
2828 if (id < 0) // Don't spew non-existant stuff
2829 return -1;
2830
2831 ASSERT((parent->type == OBJ_PLAYER) || (parent->type == OBJ_GHOST));
2832
2833 if (type == OBJ_POWERUP) {
2834 if (Game_mode & GM_MULTI) {
2835 if (Object_info[id].multi_allowed == 0)
2836 return -1;
2837 }
2838 }
2839 // A dead GB is spew'ed on player death (if he had one)
2840 if (type == OBJ_ROBOT && id == ROBOT_GUIDEBOT) {
2841 PlayerSpewGuidebot(parent, type, id);
2842 return -1;
2843 }
2844
2845 int objnum = ObjCreate(type, id, parent->roomnum, &parent->pos, NULL, parent->handle);
2846
2847 if (objnum < 0) {
2848 mprintf(0, "Couldn't spew object!\n");
2849 return -1;
2850 }
2851
2852 object *obj = &Objects[objnum];
2853
2854 PlayerSpewObject(obj, timed, parent->roomnum, &parent->pos, NULL);
2855
2856 // Send object to other players
2857 if (Game_mode & GM_MULTI) {
2858 if (Netgame.local_role == LR_SERVER) {
2859 MultiSendObject(obj, 0);
2860 }
2861 }
2862
2863 // Setup the script used for this object
2864 InitObjectScripts(obj);
2865
2866 return objnum;
2867 }
2868
2869 // TEMP: this should be in a header file
2870 #define FIRST_SECONDARY_WEAPON MAX_PRIMARY_WEAPONS
2871
2872 // How many at most to spew of each secondary weapon
2873 #define MAX_SECONDARY_SPEW 3
2874
2875 // This is a terrible hack -- it maps powerup to multi-pack versions
2876 // This mapping should really be on the powerup page
2877 const char *powerup_multipacks[] = {"Concussion", "4packConc", "Frag", "4packFrag",
2878 "Guided", "4packGuided", "Homing", "4packHoming"};
2879 #define N_POWERUP_MULTIPACKS (sizeof(powerup_multipacks) / sizeof(*powerup_multipacks) / 2)
2880
2881 // Returns the index of the multipack version of the specified powerup, or -1 if none
2882 int FindMultipackPowerup(int single_index) {
2883 for (int i = 0; i < N_POWERUP_MULTIPACKS; i++) {
2884 if (stricmp(Object_info[single_index].name, powerup_multipacks[i * 2]) == 0)
2885 return FindObjectIDName(powerup_multipacks[i * 2 + 1]);
2886 }
2887
2888 return -1;
2889 }
2890
2891 // Spews the inventory of the passed in player object
2892 void PlayerSpewInventory(object *obj, bool spew_energy_and_shield, bool spew_nonspewable) {
2893 ASSERT(obj->type == OBJ_PLAYER || obj->type == OBJ_GHOST || obj->type == OBJ_OBSERVER);
2894 int slot = obj->id;
2895 int id, type;
2896 player *playp = &Players[slot];
2897
2898 if (slot == Player_num || (Game_mode & GM_MULTI && Netgame.local_role == LR_SERVER)) {
2899 // turn off quad firing flag (becuase they will be spewing quad fire here
2900 for (int weapon_battery = 0; weapon_battery < MAX_WBS_PER_OBJ; weapon_battery++) {
2901 obj->dynamic_wb[weapon_battery].flags &= ~DWBF_QUAD;
2902 }
2903 }
2904
2905 if (obj->type == OBJ_OBSERVER)
2906 return; // don't do anything if observer
2907
2908 if (Game_mode & GM_MULTI) {
2909 if (Netgame.local_role != LR_SERVER) {
2910 playp->inventory.Reset(true, (spew_nonspewable) ? INVRESET_ALL : INVRESET_DEATHSPEW);
2911 playp->counter_measures.Reset(true, (spew_nonspewable) ? INVRESET_ALL : INVRESET_DEATHSPEW);
2912 return;
2913 }
2914 }
2915
2916 // spew a shield and energy
2917 if (spew_energy_and_shield) {
2918 id = FindObjectIDName("Shield");
2919 if (id >= 0)
2920 PlayerSpewObject(obj, OBJ_POWERUP, id, 1, NULL);
2921
2922 id = FindObjectIDName("Energy");
2923 if (id >= 0)
2924 PlayerSpewObject(obj, OBJ_POWERUP, id, 1, NULL);
2925 }
2926
2927 // Spew the primary weapon powerups
2928 if (Game_mode & GM_MULTI) {
2929 if (playp->weapon[PW_PRIMARY].index > 0) {
2930 id = Ships[playp->ship_index].spew_powerup[playp->weapon[PW_PRIMARY].index];
2931 if (id != -1) {
2932 ASSERT(Object_info[id].type == OBJ_POWERUP);
2933 PlayerSpewObject(obj, OBJ_POWERUP, id, 2, NULL);
2934 }
2935 }
2936
2937 // Spew the secondary weapon powerups
2938 id = Ships[playp->ship_index].spew_powerup[playp->weapon[PW_SECONDARY].index];
2939 if (id != -1) {
2940 ASSERT(Object_info[id].type == OBJ_POWERUP);
2941 int count = std::min<int>(playp->weapon_ammo[playp->weapon[PW_SECONDARY].index], MAX_SECONDARY_SPEW);
2942 for (int t = 0; t < count; t++)
2943 PlayerSpewObject(obj, OBJ_POWERUP, id, 2, NULL);
2944 }
2945 } else // Single player
2946 {
2947 int w;
2948
2949 // Spew the primary weapon powerups
2950 for (w = 1; w < MAX_PRIMARY_WEAPONS; w++) {
2951 if (playp->weapon_flags & HAS_FLAG(w)) {
2952 id = Ships[playp->ship_index].spew_powerup[w];
2953 if (id != -1) {
2954 ASSERT(Object_info[id].type == OBJ_POWERUP);
2955 int objnum = PlayerSpewObject(obj, OBJ_POWERUP, id, 0, NULL);
2956
2957 // Set ammo
2958 if (objnum != -1) {
2959 object *objp = &Objects[objnum];
2960 ASSERT(objp->control_type == CT_POWERUP);
2961 if (Game_mode & GM_MULTI)
2962 objp->ctype.powerup_info.count = std::max<int>(objp->ctype.powerup_info.count / 4, playp->weapon_ammo[w]);
2963 else
2964 objp->ctype.powerup_info.count = playp->weapon_ammo[w];
2965 }
2966 }
2967 }
2968 }
2969
2970 // Spew the secondary weapon powerups
2971 for (w = FIRST_SECONDARY_WEAPON; w < FIRST_SECONDARY_WEAPON + MAX_SECONDARY_WEAPONS; w++) {
2972 if ((playp->weapon_flags & HAS_FLAG(w)) && playp->weapon_ammo[w]) {
2973 id = Ships[playp->ship_index].spew_powerup[w];
2974 if (id != -1) {
2975 ASSERT(Object_info[id].type == OBJ_POWERUP);
2976
2977 // Check for multipack version
2978 int multi_id = FindMultipackPowerup(id);
2979 if (multi_id != -1) {
2980 int objnum;
2981 ASSERT(Object_info[multi_id].type == OBJ_POWERUP);
2982 objnum = PlayerSpewObject(obj, OBJ_POWERUP, multi_id, 0, NULL);
2983 if (objnum != -1)
2984 Objects[objnum].ctype.powerup_info.count = playp->weapon_ammo[w];
2985 } else {
2986 int count = std::min<int>(playp->weapon_ammo[w], MAX_SECONDARY_SPEW);
2987 for (int t = 0; t < count; t++)
2988 PlayerSpewObject(obj, OBJ_POWERUP, id, 0, NULL);
2989 }
2990 }
2991 }
2992 }
2993 }
2994
2995 // Spew out the inventory items
2996 object *temp_obj;
2997 uint16_t inven_flags;
2998 int object_flags;
2999 bool spew_it;
3000
3001 playp->inventory.ResetPos();
3002 int count = playp->inventory.Size();
3003 int i;
3004 for (i = 0; i < count; i++) {
3005 int limit = playp->inventory.GetPosCount();
3006 for (int t = 0; t < limit; t++) {
3007 playp->inventory.GetPosTypeID(type, id);
3008 playp->inventory.GetPosInfo(inven_flags, object_flags);
3009
3010 if (spew_nonspewable)
3011 spew_it = true;
3012 else {
3013 if (!(inven_flags & INVF_NOTSPEWABLE)) {
3014 spew_it = true;
3015 } else {
3016 spew_it = false;
3017 }
3018 }
3019
3020 if (spew_it) {
3021 if (id == -1) {
3022 // this is an already exisiting object, no creating
3023 playp->inventory.Remove(type, id);
3024
3025 // type is really the object handle
3026 temp_obj = ObjGet(type);
3027 ASSERT(temp_obj);
3028 if (temp_obj) {
3029 ObjUnGhostObject(OBJNUM(temp_obj));
3030 if (Game_mode & GM_MULTI) {
3031 // tell the clients to unghost
3032 MultiSendGhostObject(temp_obj, false);
3033 }
3034
3035 if (Game_mode & GM_MULTI)
3036 PlayerSpewObject(temp_obj, (inven_flags & INVF_TIMEOUTONSPEW) ? 2 : 0, obj->roomnum, &obj->pos, NULL);
3037 else
3038 PlayerSpewObject(temp_obj, 0, obj->roomnum, &obj->pos, NULL);
3039 }
3040
3041 } else {
3042 ASSERT(type != OBJ_NONE);
3043 if (Game_mode & GM_MULTI)
3044 PlayerSpewObject(obj, type, id, (inven_flags & INVF_TIMEOUTONSPEW) ? 2 : 0, NULL);
3045 else
3046 PlayerSpewObject(obj, type, id, 0, NULL);
3047 playp->inventory.Remove(type, id);
3048 }
3049 }
3050 }
3051 playp->inventory.NextPos(true);
3052 }
3053
3054 // Spew out the countermeasure items
3055 playp->counter_measures.ResetPos();
3056 count = playp->counter_measures.Size();
3057 int done = 0;
3058 int total_spewed = 0;
3059
3060 for (i = 0; i < count && !done; i++) {
3061 if (count < 2 || (ps_rand() % 2)) {
3062 int limit = playp->counter_measures.GetPosCount();
3063 limit = std::min(2, limit);
3064 for (int t = 0; t < limit; t++) {
3065 playp->counter_measures.GetAuxPosTypeID(type, id);
3066 playp->counter_measures.GetPosInfo(inven_flags, object_flags);
3067 ASSERT(id != -1);
3068 ASSERT(type != OBJ_NONE);
3069
3070 if (Game_mode & GM_MULTI)
3071 PlayerSpewObject(obj, type, id, (inven_flags & INVF_TIMEOUTONSPEW) ? 2 : 0, NULL);
3072 else
3073 PlayerSpewObject(obj, type, id, 0, NULL);
3074
3075 playp->counter_measures.GetPosTypeID(type, id);
3076 playp->counter_measures.Remove(type, id);
3077 }
3078
3079 total_spewed++;
3080 if (total_spewed >= 3)
3081 done = 1;
3082 }
3083 playp->counter_measures.NextPos(true);
3084 }
3085 }
3086
3087 ///////////////////////////////////////////////////////////////////////////////
3088
3089 // Blow up the entire ship (all remaining subobjects.
3090 void PlayerShipExplode(object *obj, float magnitude) {
3091 int visnum;
3092
3093 ASSERT(obj != NULL);
3094
3095 DLLInfo.me_handle = obj->handle;
3096 DLLInfo.it_handle = obj->handle;
3097 CallGameDLL(EVT_GAMEPLAYEREXPLODED, &DLLInfo);
3098
3099 if (Death[obj->id].dying_model && (Death[obj->id].dying_model->n_models > 1)) {
3100 int i;
3101
3102 // Create debris pieces from subobjects
3103 for (i = 1; i < Death[obj->id].dying_model->n_models; i++) {
3104 if (obj->rtype.pobj_info.subobj_flags & (1 << i)) {
3105 PlayerShipSpewPart(obj, i, magnitude * 0.85f);
3106 }
3107 }
3108 }
3109
3110 CreateBlastRing(&obj->pos, BLAST_RING_INDEX, DAMAGE_RING_TIME, obj->size * 3, obj->roomnum);
3111
3112 obj->rtype.pobj_info.subobj_flags = 0;
3113
3114 // Player explosion sound
3115 Sound_system.Play3dSound(SOUND_BUILDING_EXPLODE, obj);
3116
3117 CreateRandomSparks(80, &obj->pos, obj->roomnum, HOT_SPARK_INDEX, (ps_rand() % 3) + 2);
3118 visnum = CreateFireball(&obj->pos, BIG_EXPLOSION_INDEX, obj->roomnum, VISUAL_FIREBALL);
3119 if (visnum >= 0)
3120 VisEffects[visnum].size *= (3.0f * (magnitude / MAX_EXPLOSION_MAG));
3121
3122 // Do badass damage
3123 obj->impact_time = 0;
3124 obj->impact_size = obj->size * 3;
3125 obj->impact_force = obj->impact_size * 2;
3126 obj->impact_generic_damage = obj->impact_size * 3;
3127 obj->impact_player_damage = obj->impact_size * 3;
3128 DoConcussiveForce(obj, obj->handle, 1.0);
3129
3130 // Spew out any weapons, powerups, inventory
3131 PlayerSpewInventory(obj);
3132
3133 if (Game_mode & GM_MULTI)
3134 MultiMakePlayerGhost(obj->id);
3135
3136 obj->effect_info->type_flags = 0;
3137
3138 // Stop sounds for this player
3139 PlayerStopSounds(obj->id);
3140
3141 // Clear keyboard buffer
3142 if (obj->id == Player_num) {
3143 ddio_KeyFlush();
3144 Controller->flush();
3145 }
3146 }
3147
3148 // breaks off a random piece.
3149 void PlayerShipBreakup(object *obj, float magnitude) {
3150 int subobjnum, i, j, idx;
3151 unsigned test_flag;
3152 int n_models = Death[obj->id].dying_model ? Death[obj->id].dying_model->n_models : 0;
3153 int n_remaining_models;
3154
3155 // don't break off object 0.
3156 if (n_models == 1)
3157 return;
3158
3159 // count number of valid subobjects skip 1st subobject
3160 n_remaining_models = 0;
3161 test_flag = obj->rtype.pobj_info.subobj_flags;
3162 for (i = 1; i < n_models; i++) {
3163 if (test_flag & (1 << i))
3164 n_remaining_models++;
3165 }
3166
3167 // this is an INDEX into the VALID subobjects in the polymodel. (skip 1st subobj)
3168 idx = (ps_rand() * n_remaining_models / D3_RAND_MAX) + 1;
3169
3170 subobjnum = -1;
3171 for (i = 1, j = 1; i < n_models; i++) {
3172 if (test_flag & (1 << i)) { // valid subobject?
3173 if (idx == j) { // correct subobject index?
3174 test_flag &= ~(1 << i);
3175 subobjnum = i;
3176 break;
3177 }
3178 j++;
3179 }
3180 }
3181
3182 // okay, if no suboject found, blowup.
3183 if (subobjnum == -1) {
3184 StartPlayerExplosion(obj->id);
3185 } else {
3186 PlayerShipSpewPart(obj, subobjnum, magnitude);
3187 }
3188 }
3189
3190 // spews a part of the player ship and all its child subobjects
3191 void PlayerShipSpewPartSub(object *obj, bsp_info *submodel, float magnitude);
3192
3193 void PlayerShipSpewPart(object *obj, int subobjnum, float magnitude) {
3194 PlayerShipSpewPartSub(obj, &Poly_models[obj->rtype.pobj_info.model_num].submodel[subobjnum], magnitude);
3195 }
3196
3197 void PlayerShipSpewPartSub(object *obj, bsp_info *submodel, float magnitude) {
3198 vector rand_vec;
3199 int subobjnum = submodel - Poly_models[obj->rtype.pobj_info.model_num].submodel;
3200 int i;
3201 int visnum;
3202
3203 ASSERT(subobjnum > -1 && subobjnum < Poly_models[obj->rtype.pobj_info.model_num].n_models);
3204
3205 // first go through all children.
3206 // find child index, and use that index into the submodel array of the polymodel to pass a new submodel down
3207 // the chain.
3208 i = 0;
3209 while (i < submodel->num_children) {
3210 PlayerShipSpewPartSub(obj, &Poly_models[obj->rtype.pobj_info.model_num].submodel[submodel->children[i]], magnitude);
3211 i++;
3212 }
3213
3214 rand_vec.x = (float)(D3_RAND_MAX / 2 - ps_rand());
3215 if (obj->movement_type != MT_PHYSICS)
3216 rand_vec.y = (float)((float)ps_rand() / 2.0); // A habit of moving upward
3217 else
3218 rand_vec.y = (float)((float)D3_RAND_MAX / 1.5f - (float)ps_rand()); // A habit of moving upward
3219 rand_vec.z = (float)(D3_RAND_MAX / 2 - ps_rand());
3220 vm_NormalizeVectorFast(&rand_vec);
3221
3222 object *subobj = CreateSubobjectDebrisDirected(obj, subobjnum, &rand_vec, magnitude);
3223 if (subobj) {
3224 // create mini-explosion at start of debris fall.
3225 vector newpos = subobj->pos + submodel->offset;
3226 visnum = CreateFireball(&newpos, MED_EXPLOSION_INDEX, subobj->roomnum, VISUAL_FIREBALL);
3227 if (visnum >= 0) {
3228 VisEffects[visnum].size *= (2.5f * (magnitude / MAX_EXPLOSION_MAG));
3229 VisEffects[visnum].lifeleft *= 2.0f;
3230 rand_vec = (-rand_vec) * (magnitude * 25.0f);
3231 phys_apply_force(obj, &rand_vec);
3232 // mprintf(0, "Breakoff fireball size: %f, lifeleft: %f\n", Objects[objnum].size, Objects[objnum].lifeleft);
3233 }
3234 }
3235
3236 // mark subobject dead
3237 obj->rtype.pobj_info.subobj_flags &= (~(1 << subobjnum));
3238 // mprintf(0, "%d:sobj=%08x\n", subobjnum, obj->rtype.pobj_info.subobj_flags);
3239 }
3240
3241 // Moves death camera a certain distance based off of direction from vec from
3242 // the player. returns new dist
3243 //
3244 static vector Death_cam_vectors[] = {{0, 1, 0}, {0, 1, -1}, {0, 0, -1}, {0, -1, -1}, {0, -1, 0}, {0, -1, 1},
3245 {0, 0, 1}, {0, 1, 1}, {1, 0, 0}, {1, 0, -1}, {-1, 0, -1}, {-1, 0, 0},
3246 {-1, 0, 1}, {1, 0, 1}, {1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}};
3247
3248 #define NUM_DEATH_VECS (sizeof(Death_cam_vectors) / sizeof(vector))
3249
3250 float MoveDeathCam(int slot, vector *vec, float distance) {
3251 fvi_info hit_data;
3252 fvi_query fq;
3253 vector best_vec, next_vec, cam_vec;
3254 float far_scale;
3255 int cur_vec_index, init_vec_index, loop_count;
3256 object *playobj = &Objects[Players[slot].objnum];
3257
3258 // once we've reached our distance goal, then we stop, otherwise keep moving.
3259 // actually move the camera. make sure we don't leave the mine though.
3260 hit_data.hit_type[0] = (OBJECT_OUTSIDE(playobj) ? HIT_TERRAIN : HIT_WALL);
3261 far_scale = 1.0f;
3262
3263 init_vec_index = ps_rand() % NUM_DEATH_VECS;
3264 cur_vec_index = init_vec_index;
3265 loop_count = 0;
3266
3267 do {
3268 // randomize cam_vec just a little bit if possible.
3269 cam_vec = Death_cam_vectors[cur_vec_index++];
3270 cam_vec.x += ((ps_rand() % 5) - 2) * 0.1f;
3271 cam_vec.y += ((ps_rand() % 5) - 2) * 0.1f;
3272 vm_NormalizeVector(&cam_vec);
3273
3274 cam_vec = cam_vec * distance;
3275 best_vec = playobj->pos + cam_vec;
3276 cam_vec = cam_vec * far_scale;
3277 next_vec = playobj->pos + cam_vec;
3278
3279 if (cur_vec_index == init_vec_index) {
3280 distance = distance / 1.25f;
3281 far_scale = far_scale * 1.05f;
3282 loop_count++;
3283 }
3284
3285 fq.p0 = &playobj->pos;
3286 fq.p1 = &next_vec;
3287 fq.startroom = playobj->roomnum;
3288 fq.rad = .5;
3289 fq.thisobjnum = OBJNUM(playobj);
3290 fq.ignore_obj_list = NULL;
3291 fq.flags = 0;
3292
3293 ASSERT(std::isfinite(next_vec.x));
3294 ASSERT(std::isfinite(next_vec.y));
3295 ASSERT(std::isfinite(next_vec.z));
3296
3297 fvi_FindIntersection(&fq, &hit_data);
3298
3299 if (hit_data.hit_type[0] == HIT_NONE || loop_count == 32) {
3300 // okay, we need to find the room that best_vec is in.
3301 fq.p0 = &playobj->pos;
3302 fq.p1 = &best_vec;
3303 fq.startroom = playobj->roomnum;
3304 fq.rad = 0.75f;
3305 fq.thisobjnum = OBJNUM(playobj);
3306 fq.ignore_obj_list = NULL;
3307 fq.flags = 0;
3308 fvi_FindIntersection(&fq, &hit_data);
3309
3310 if (hit_data.hit_type[0] != HIT_NONE)
3311 ObjSetPos(Death[slot].camera, &hit_data.hit_pnt, hit_data.hit_room, NULL, false);
3312 else
3313 ObjSetPos(Death[slot].camera, &best_vec, hit_data.hit_room, NULL, false);
3314 } else {
3315 float ray_dist = vm_VectorDistanceQuick(&hit_data.hit_pnt, &playobj->pos);
3316 if (ray_dist < distance) {
3317 hit_data.hit_type[0] = HIT_NONE;
3318 }
3319 }
3320
3321 // go back to start of list if at end.
3322 if (cur_vec_index == NUM_DEATH_VECS)
3323 cur_vec_index = 0;
3324 } while (hit_data.hit_type[0] != HIT_NONE && loop_count < 32);
3325
3326 *vec = cam_vec;
3327
3328 return distance;
3329 }
3330
3331 // Returns the goal room of the passed in team
3332 int GetGoalRoomForTeam(int teamnum) {
3333 ASSERT(teamnum >= 0 && teamnum <= 3);
3334 int flags[] = {RF_GOAL1, RF_GOAL2, RF_GOAL3, RF_GOAL4};
3335
3336 for (int i = 0; i <= Highest_room_index; i++) {
3337 if (Rooms[i].used && (Rooms[i].flags & flags[teamnum])) {
3338 return i;
3339 }
3340 }
3341
3342 return -1; // No goal for this team!
3343 }
3344
3345 // Returns the goal room of the passed in player
3346 int GetGoalRoomForPlayer(int slot) {
3347 ASSERT(slot >= 0 && slot <= MAX_PLAYERS);
3348 int team = PlayerGetTeam(slot);
3349
3350 if (team == -1)
3351 return -1;
3352
3353 return (GetGoalRoomForTeam(team));
3354 }
3355
3356 // Sets the maximum number of teams in a game
3357 void SetMaxTeams(int num) {
3358 if (num > MAX_TEAMS)
3359 num = MAX_TEAMS;
3360
3361 if (num < 2)
3362 num = 1;
3363
3364 if (num >= 2)
3365 Team_game = 1;
3366 else
3367 Team_game = 0;
3368
3369 Num_teams = num;
3370 }
3371
3372 int IncTeamScore(int teamnum, int add) {
3373 ASSERT(teamnum >= 0 && teamnum < Num_teams);
3374 Teams[teamnum].score += add;
3375 return Teams[teamnum].score;
3376 }
3377
3378 // Resets the teams scores to zero
3379 void ResetTeamScores() {
3380 int i;
3381 for (i = 0; i < MAX_TEAMS; i++)
3382 Teams[i].score = 0;
3383 }
3384
3385 // Sets the lighting that a player will cast
3386 void PlayerSetLighting(int slot, float dist, float r, float g, float b) {
3387 Players[slot].light_dist = dist;
3388 Players[slot].r = r;
3389 Players[slot].g = g;
3390 Players[slot].b = b;
3391 }
3392
3393 // Gets the position of a given ball in world coords
3394 void PlayerGetBallPosition(vector *dest, int slot, int num) {
3395 matrix rotmat, tempm;
3396 object *obj = &Objects[Players[slot].objnum];
3397
3398 // Get position in circle
3399 float ballspeed = Players[slot].ballspeed * 65536;
3400 float rot_temp = ballspeed / 65536.0;
3401 int int_game = Gametime / rot_temp;
3402 float diff = Gametime - (int_game * rot_temp);
3403 int rot_angle = (diff * 65536);
3404 rot_angle = (rot_angle + (num * 5000)) % 65536;
3405
3406 // Get matrix to multiply with
3407 if (num == 0)
3408 vm_AnglesToMatrix(&rotmat, 0, 0, rot_angle);
3409 else if (num == 1)
3410 vm_AnglesToMatrix(&rotmat, 0, rot_angle, 0);
3411 else
3412 vm_AnglesToMatrix(&rotmat, rot_angle, 0, 0);
3413
3414 tempm = obj->orient * rotmat;
3415
3416 // Get world position
3417 if (num == 1)
3418 *dest = obj->pos + (tempm.fvec * (obj->size + 1));
3419 else
3420 *dest = obj->pos + (tempm.uvec * (obj->size + 1));
3421 }
3422
3423 // Sets a wacky rotating ball around the player ship
3424 void PlayerSetRotatingBall(int slot, int num, float speed, float *r, float *g, float *b) {
3425 ASSERT(num >= 0 && num <= 3);
3426
3427 Players[slot].ballspeed = speed;
3428 Players[slot].num_balls = num;
3429
3430 for (int i = 0; i < num; i++) {
3431 Players[slot].ball_r[i] = r[i];
3432 Players[slot].ball_g[i] = g[i];
3433 Players[slot].ball_b[i] = b[i];
3434 }
3435
3436 if (Demo_flags == DF_RECORDING) {
3437 DemoWritePlayerBalls(slot);
3438 }
3439 }
3440
3441 void ObjSetRenderPolyobj(object *objp, int model_num, int dying_model_num = -1);
3442
3443 // Changes the ship a particular player is flying
3444 void PlayerChangeShip(int slot, int ship_index) {
3445 ship *ship;
3446
3447 if (Players[slot].start_roomnum == -1)
3448 return; // this player doesn't exist
3449
3450 object *objp = &Objects[Players[slot].objnum];
3451
3452 ship = &Ships[ship_index];
3453
3454 if (!ship->used) { // this ship doesn't exist
3455 Int3();
3456 ship_index = GetNextShip(0);
3457 ASSERT(ship_index != -1);
3458 ship = &Ships[ship_index];
3459 }
3460
3461 // Set size & shields
3462 objp->size = ship->size;
3463 objp->mtype.phys_info = ship->phys_info;
3464
3465 // Set up render info, but save render type first
3466 int save_rt = objp->render_type;
3467 ObjSetRenderPolyobj(objp, ship->model_handle, ship->dying_model_handle);
3468 objp->render_type = save_rt;
3469
3470 objp->rtype.pobj_info.model_num = ship->model_handle;
3471 objp->rtype.pobj_info.dying_model_num = ship->dying_model_handle;
3472 PageInPolymodel(ship->model_handle);
3473 if (ship->dying_model_handle != -1)
3474 PageInPolymodel(ship->dying_model_handle);
3475
3476 if (ship->lo_render_handle >= 0)
3477 PageInPolymodel(ship->lo_render_handle);
3478 if (ship->med_render_handle >= 0)
3479 PageInPolymodel(ship->med_render_handle);
3480
3481 ComputeDefaultSize(OBJ_PLAYER, objp->rtype.pobj_info.model_num, &objp->size);
3482
3483 WBClearInfo(objp);
3484
3485 Players[slot].ship_index = ship_index;
3486 }
3487
3488 // Sets the FOV range at which the hud names will come on
3489 void PlayerSetHUDNameFOV(int fov) {
3490 if (fov < 0) {
3491 HudNameTan = -1;
3492 return;
3493 }
3494
3495 float rad = (float)(3.14 * (float)(fov / 2) / 180.0);
3496 HudNameTan = tan(rad);
3497 }
3498
3499 // Switches a player object to observer mode
3500 void PlayerSwitchToObserver(int slot, int observer_mode, int piggy_objnum) {
3501 object *obj = &Objects[Players[slot].objnum];
3502
3503 // call the event to the multiplayer DLL's so they can do what they need
3504 if (Game_mode & GM_MULTI) {
3505 DLLInfo.me_handle = obj->handle;
3506
3507 if (observer_mode == OBSERVER_MODE_PIGGYBACK) {
3508 DLLInfo.it_handle = Objects[piggy_objnum].handle;
3509 } else {
3510 DLLInfo.it_handle = OBJECT_HANDLE_NONE;
3511 }
3512
3513 CallGameDLL(EVT_CLIENT_GAMEPLAYERENTERSOBSERVER, &DLLInfo);
3514 }
3515
3516 // Stop sounds for this player
3517 PlayerStopSounds(slot);
3518
3519 if (slot == Player_num) {
3520 AddHUDMessage(TXT_ENTEROBS);
3521 SetHUDMode(HUD_OBSERVER);
3522 Players[slot].movement_scalar = 2.0;
3523 } else
3524 AddHUDMessage(TXT_PLYRENTEROBS, Players[slot].callsign);
3525
3526 CreateRandomSparks(30, &obj->pos, obj->roomnum, HOT_SPARK_INDEX, (ps_rand() % 3) + 2);
3527
3528 if (Demo_flags != DF_PLAYBACK) {
3529 PlayerSpewInventory(obj, false);
3530 }
3531
3532 obj->type = OBJ_OBSERVER;
3533 obj->render_type = RT_NONE;
3534
3535 if (Demo_flags == DF_RECORDING) {
3536 DemoWritePlayerTypeChange(slot, false, observer_mode, piggy_objnum);
3537 }
3538
3539 if (observer_mode == OBSERVER_MODE_ROAM) {
3540 SetObjectControlType(obj, CT_FLYING);
3541 Players[slot].piggy_objnum = -1;
3542 obj->movement_type = MT_PHYSICS;
3543 } else if (observer_mode == OBSERVER_MODE_PIGGYBACK) {
3544 SetObjectControlType(obj, CT_NONE);
3545 Players[slot].piggy_objnum = piggy_objnum;
3546 Players[slot].piggy_sig = Objects[piggy_objnum].handle & HANDLE_COUNT_MASK;
3547 mprintf(0, "Object %d is observing object %d!\n", obj - Objects, piggy_objnum);
3548 }
3549 }
3550
3551 // Stops a player from observing
3552 void PlayerStopObserving(int slot) {
3553 // call the event to the multiplayer DLL's so they can do what they need
3554 if (Game_mode & GM_MULTI) {
3555 DLLInfo.me_handle = Objects[Players[slot].objnum].handle;
3556 DLLInfo.it_handle = OBJECT_HANDLE_NONE;
3557 CallGameDLL(EVT_CLIENT_GAMEPLAYEREXITSOBSERVER, &DLLInfo);
3558 }
3559
3560 if (slot == Player_num) {
3561 uint8_t hud_mode;
3562 Current_pilot.get_hud_data(&hud_mode);
3563 AddHUDMessage(TXT_LEAVEOBS);
3564 SetHUDMode((tHUDMode)hud_mode);
3565 } else
3566 AddHUDMessage(TXT_PLYRLEAVEOBS, Players[slot].callsign);
3567
3568 // Stop sounds for this player
3569 PlayerStopSounds(slot);
3570
3571 object *obj = &Objects[Players[slot].objnum];
3572
3573 obj->type = OBJ_PLAYER;
3574 Players[slot].piggy_objnum = -1;
3575
3576 InitPlayerNewShip(slot, INVRESET_ALL);
3577 ResetPlayerObject(slot);
3578
3579 if (Demo_flags == DF_RECORDING) {
3580 DemoWritePlayerTypeChange(slot, true);
3581 }
3582 }
3583
3584 #define PLAYER_TEXTURE_FPS 8.0f
3585 // Sets the players custom texture. If filename=NULL then sets to no texture
3586 // Returns 1 if filename was successfully loaded, else 0
3587 int PlayerSetCustomTexture(int slot, char *filename) {
3588 // Free up previous vclip/bitmap if there is one
3589 texture *texp = &GameTextures[Players[slot].custom_texture_handle];
3590 int bm_handle = texp->bm_handle;
3591
3592 if (bm_handle != 0) {
3593 if (texp->flags & TF_ANIMATED)
3594 FreeVClip(bm_handle);
3595 else
3596 bm_FreeBitmap(bm_handle);
3597
3598 texp->bm_handle = 0;
3599 }
3600
3601 // Now load the new one
3602 texp->bm_handle = 0;
3603 if (filename == NULL)
3604 return 1;
3605
3606 int anim;
3607 int new_handle = LoadTextureImage(filename, &anim, SMALL_TEXTURE, 1, 0);
3608
3609 if (new_handle < 0)
3610 return 0;
3611
3612 texp->bm_handle = new_handle;
3613 if (anim)
3614 texp->flags |= TF_ANIMATED;
3615 else
3616 texp->flags &= ~TF_ANIMATED;
3617
3618 texp->flags |= TF_TEXTURE_64;
3619
3620 // Set texture speed
3621 if (texp->flags & TF_ANIMATED) {
3622 vclip *vc = &GameVClips[texp->bm_handle];
3623 texp->speed = vc->num_frames * (1.0 / PLAYER_TEXTURE_FPS);
3624 }
3625
3626 return 1;
3627 }
3628
3629 // Sets/Clears a permission for a ship on a given player
3630 // if pnum is -1 then all players will be set, else player is the player number
3631 // returns true on success
3632 bool PlayerSetShipPermission(int pnum, char *ship_name, bool allowed) {
3633 ASSERT(ship_name);
3634
3635 if (pnum < -1 || pnum >= MAX_PLAYERS) // illegal value
3636 return false;
3637
3638 int ship_index = FindShipName(ship_name);
3639 if (ship_index == -1) {
3640 ASSERT(ship_index != -1);
3641 return false;
3642 }
3643 int bit = 0x01;
3644 bit = bit << ship_index;
3645
3646 if (pnum == -1) {
3647 // go through everyone
3648 for (int i = 0; i < MAX_PLAYERS; i++) {
3649 if (allowed)
3650 Players[i].ship_permissions |= bit;
3651 else
3652 Players[i].ship_permissions &= ~bit;
3653 }
3654 } else {
3655 if (allowed)
3656 Players[pnum].ship_permissions |= bit;
3657 else
3658 Players[pnum].ship_permissions &= ~bit;
3659 }
3660 return true;
3661 }
3662
3663 // Resets the ship permissions for a given player
3664 // pass false for set_default if you don't want the default ship allowed
3665 bool PlayerResetShipPermissions(int pnum, bool set_default) {
3666 if (pnum < -1 || pnum >= MAX_PLAYERS)
3667 return false;
3668
3669 int perm;
3670
•3671 mprintf(0, "Resetting ship permissions\n");
3672
3673 if (set_default)
3674 perm = Default_ship_permission;
3675 else
3676 perm = 0;
3677
3678 if (pnum == -1) {
3679 for (int i = 0; i < MAX_PLAYERS; i++) {
3680 Players[i].ship_permissions = perm;
3681 }
3682 } else {
3683 Players[pnum].ship_permissions = perm;
3684 }
3685
3686 return true;
3687 }
3688
3689 // Returns true if the given ship is allowed to be chosen for a pnum
3690 bool PlayerIsShipAllowed(int pnum, char *ship_name) {
3691 ASSERT(ship_name);
3692
3693 if (pnum < -1 || pnum >= MAX_PLAYERS) // illegal value
3694 return false;
3695
3696 int ship_index = FindShipName(ship_name);
3697 if (ship_index == -1) {
3698 ASSERT(ship_index != -1);
3699 return false;
3700 }
3701 int bit = 0x01;
3702 bit = bit << ship_index;
3703 return ((Players[(pnum != -1) ? pnum : Player_num].ship_permissions & bit) != 0);
3704 }
3705 bool PlayerIsShipAllowed(int pnum, int ship_index) {
3706 if (pnum < -1 || pnum >= MAX_PLAYERS) // illegal value
3707 return false;
3708
3709 ASSERT(ship_index >= 0 && ship_index < MAX_SHIPS);
3710
3711 int bit = 0x01;
3712 bit = bit << ship_index;
3713 return ((Players[pnum].ship_permissions & bit) != 0);
3714 }
3715
3716 void DoEnergyToShields(int pnum) {
3717 float amount; // how much energy gets transfered
3718 static float last_play_time = 0;
3719
3720 if (Players[pnum].energy - INITIAL_ENERGY <= 0) {
3721 if (pnum == Player_num)
3722 AddHUDMessage(TXT_NEEDMOREENERGY, INITIAL_ENERGY);
3723 return;
3724 }
3725 if (Objects[Players[pnum].objnum].shields >= MAX_SHIELDS) {
3726 if (pnum == Player_num)
3727 AddHUDMessage(TXT_SHIELDSATMAX);
3728 return;
3729 }
3730
3731 amount = std::min({Frametime * CONVERTER_RATE, Players[pnum].energy - INITIAL_ENERGY, (MAX_SHIELDS - Objects[Players[pnum].objnum].shields) * CONVERTER_SCALE});
3732
3733 Players[pnum].energy -= amount;
3734
3735 if ((!(Game_mode & GM_MULTI)) || Netgame.local_role == LR_SERVER)
3736 Objects[Players[pnum].objnum].shields += amount / CONVERTER_SCALE;
3737 else
3738 Multi_additional_shields[SHIELD_REQUEST_ENERGY_TO_SHIELD] += Frametime;
3739
3740 if (pnum == Player_num) {
3741 if (last_play_time > Gametime)
3742 last_play_time = 0;
3743
3744 if (Gametime > last_play_time + CONVERTER_SOUND_DELAY) {
3745 Sound_system.Play3dSound(SOUND_ENERGY_CONVERTER, &Objects[Players[pnum].objnum], MAX_GAME_VOLUME / 2);
3746
3747 ain_hear hear;
3748 hear.f_directly_player = true;
3749 hear.hostile_level = 0.3f;
3750 hear.curiosity_level = 1.0f;
3751 hear.max_dist = Sounds[SOUND_ENERGY_CONVERTER].max_distance * 0.5f;
3752 AINotify(&Objects[Players[Player_num].objnum], AIN_HEAR_NOISE, (void *)&hear);
3753
3754 last_play_time = Gametime;
3755 }
3756 }
3757 }
3758
3759 // Sets the start position that the player will respawn at
3760 void PlayerAddWaypoint(int index) {
3761 ASSERT(Players[index].start_roomnum != -1); // Invalid start position specified
3762 mprintf(0, "Current waypoint is now %d\n", index);
3763 Current_waypoint = index;
3764
3765 // A manual waypoint blows away all auto-waypoints
3766 for (int i = 0; i < MAX_PLAYERS; i++)
3767 Players[i].current_auto_waypoint_room = -1;
3768 }
3769
3770 // Resets the waypoints (for new level)
3771 void ResetWaypoint() {
3772 // Set global waypoint to first start position
3773 Current_waypoint = 0;
3774
3775 // Clear out all auto-waypoints
3776 for (int i = 0; i < MAX_PLAYERS; i++)
3777 Players[i].current_auto_waypoint_room = -1;
3778 }
3779
3780 struct waypoint {
3781 vector pos;
3782 int roomnum;
3783 matrix orient;
3784 };
3785
3786 waypoint Waypoints[MAX_WAYPOINTS];
3787 int Num_waypoints;
3788
3789 // Find all the waypoint objects and add them to the list of waypoints
3790 void MakeAtuoWaypointList() {
3791 int i;
3792 object *objp;
3793 room *rp;
3794
3795 Num_waypoints = 0;
3796
3797 // Clear room waypoint flags
3798 for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++)
3799 rp->flags &= ~RF_WAYPOINT;
3800
3801 // Look through objects for waypoints
3802 for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) {
3803 if (objp->type == OBJ_WAYPOINT) {
3804 if (Num_waypoints < MAX_WAYPOINTS) {
3805 Waypoints[Num_waypoints].pos = objp->pos;
3806 Waypoints[Num_waypoints].roomnum = objp->roomnum;
3807 Waypoints[Num_waypoints].orient = objp->orient;
3808 Num_waypoints++;
3809
3810 if (OBJECT_OUTSIDE(objp))
3811 ; // Terrain_seg[CELLNUM(objp->roomnum)].flags |= TF_WAYPOINT;
3812 else
3813 Rooms[objp->roomnum].flags |= RF_WAYPOINT;
3814 }
3815
3816 ObjDelete(i);
3817 }
3818 }
3819 }
3820
3821 // Sets the player's waypoint to the one in the specified room
3822 void SetAutoWaypoint(object *objp) {
3823 ASSERT(objp->type == OBJ_PLAYER);
3824
3825 // Get the player we're setting
3826 player *pp = &Players[objp->id];
3827
3828 if (!OBJECT_OUTSIDE(objp)) {
3829 // delete the next two lines
3830 if (pp->current_auto_waypoint_room != objp->roomnum) {
3831 mprintf(0, "Setting auto-waypoint in room %d\n", objp->roomnum);
3832 }
3833 pp->current_auto_waypoint_room = objp->roomnum;
3834 }
3835 }
3836
3837 // Moves the player to his last waypoint
3838 void MovePlayerToWaypoint(object *objp) {
3839 ASSERT(objp->type == OBJ_PLAYER || objp->type == OBJ_GHOST);
3840
3841 player *pp = &Players[objp->id];
3842
3843 // If this player has an auto-waypoint, use it. Else use global waypoint.
3844 if (pp->current_auto_waypoint_room != -1) {
3845 waypoint *wp;
3846 int i;
3847
3848 // Find the waypoint
3849 for (i = 0, wp = Waypoints; i < Num_waypoints; i++, wp++)
3850 if (wp->roomnum == pp->current_auto_waypoint_room)
3851 break;
3852 ASSERT(i < Num_waypoints);
3853
3854 ObjSetPos(objp, &wp->pos, wp->roomnum, &wp->orient, false);
3855 } else {
3856 ASSERT(Current_waypoint != -1);
3857
3858 mprintf(0, "Resetting player ship to waypoint %d\n", Current_waypoint);
3859 ObjSetPos(objp, &Players[Current_waypoint].start_pos, Players[Current_waypoint].start_roomnum,
3860 &Players[Current_waypoint].start_orient, false);
3861 }
3862 }
3863
3864 // Adds to the player's score & kill total
3865 void PlayerScoreAdd(int playernum, int points) {
3866 // Add score
3867 if (points) {
3868
3869 if (points > 0)
3870 Players[playernum].num_kills_level++;
3871 else
3872 Players[playernum].friendly_kills_level++;
3873
3874 if (!(playernum != Player_num || IsCheater)) {
3875 Players[playernum].score += points;
3876
3877 Score_added = points;
3878 Score_added_timer = SCORE_ADDED_TIME;
3879 }
3880 }
3881 }
3882
3883 ////////////////////////////////////////////////////
3884 // Thief interface functions
3885 ////////////////////////////////////////////////////
3886 extern uint8_t AutomapVisMap[MAX_ROOMS];
3887 void MakeObjectVisible(object *obj);
3888
3889 // steals an item from the given player
3890 void ThiefStealItem(int player_object_handle, int item) {
3891 object *pobj = ObjGet(player_object_handle);
3892 ASSERT(pobj);
3893 ASSERT(pobj->type == OBJ_PLAYER);
3894
3895 int playernum = pobj->id;
3896
3897 static int conv_id = -2;
3898 static int quad_id = -2;
3899
3900 bool is_multi = false;
3901 if (Game_mode & GM_MULTI)
3902 is_multi = true;
3903
3904 if (is_multi) {
3905 ASSERT(item != THIEFITEM_AUTOMAP);
3906 }
3907
3908 if (is_multi && Netgame.local_role == LR_SERVER) {
3909 // send it off
3910 MultiSendThiefSteal(playernum, item);
3911 }
3912
3913 switch (item) {
3914 case THIEFITEM_AUTOMAP:
3915 if (playernum == Player_num) {
3916 for (int i = 0; i < MAX_ROOMS; i++) {
3917 if (AutomapVisMap[i] == 1)
3918 AutomapVisMap[i] = 2;
3919 }
3920 }
3921 break;
3922
3923 case THIEFITEM_HEADLIGHT:
3924 Players[playernum].flags &= ~PLAYER_FLAGS_HEADLIGHT;
3925 Players[playernum].flags |= PLAYER_FLAGS_HEADLIGHT_STOLEN;
3926 break;
3927
3928 case THIEFITEM_ETOSCONV: {
3929 if (conv_id == -2)
3930 conv_id = FindObjectIDName("Converter");
3931
3932 if (conv_id != -1) {
3933 Players[playernum].inventory.Remove(OBJ_POWERUP, conv_id);
3934 }
3935 } break;
3936
3937 case THIEFITEM_CLOAK: {
3938 if ((pobj->effect_info) && (pobj->effect_info->type_flags & EF_FADING_OUT) ||
3939 (pobj->effect_info->type_flags & EF_CLOAKED)) {
3940 MakeObjectVisible(pobj);
3941 }
3942 } break;
3943
3944 case THIEFITEM_INVULN: {
3945 if (Players[playernum].flags & PLAYER_FLAGS_INVULNERABLE) {
3946 MakePlayerVulnerable(playernum);
3947 }
3948 } break;
3949
3950 case THIEFITEM_QUADFIRE: {
3951 pobj->dynamic_wb[LASER_INDEX].flags &= ~DWBF_QUAD;
3952 pobj->dynamic_wb[SUPER_LASER_INDEX].flags &= ~DWBF_QUAD;
3953
3954 // remove from inventory
3955 if (quad_id == -2)
3956 quad_id = FindObjectIDName("QuadLaser");
3957
3958 if (quad_id > -1) {
3959 Players[playernum].inventory.Remove(OBJ_POWERUP, quad_id);
3960 }
3961
3962 } break;
3963
3964 case THIEFITEM_RAPIDFIRE: {
3965 if (Players[playernum].weapon_recharge_scalar < 1.0f) {
3966 Players[playernum].weapon_recharge_scalar = 1.0f;
3967 }
3968 } break;
3969 }
3970 }
3971
3972 // returns a stolen item to a player
3973 void ThiefReturnItem(int player_object_handle, int item) {
3974 object *pobj = ObjGet(player_object_handle);
3975 ASSERT(pobj);
3976 ASSERT(pobj->type == OBJ_PLAYER);
3977
3978 int playernum = pobj->id;
3979
3980 switch (item) {
3981 case THIEFITEM_AUTOMAP:
3982 if (playernum == Player_num) {
3983 for (int i = 0; i < MAX_ROOMS; i++) {
3984 if (AutomapVisMap[i] == 2)
3985 AutomapVisMap[i] = 1;
3986 }
3987 }
3988 break;
3989 case THIEFITEM_HEADLIGHT:
3990 Players[playernum].flags &= ~PLAYER_FLAGS_HEADLIGHT_STOLEN;
3991 break;
3992 // all others should be handled by their powerup
3993 }
3994 }
3995
3996 // returns true if a player has the specified item to be stolen
3997 bool ThiefPlayerHasItem(int player_object_handle, int item) {
3998 object *pobj = ObjGet(player_object_handle);
3999 ASSERT(pobj);
4000 ASSERT(pobj->type == OBJ_PLAYER);
4001
4002 int playernum = pobj->id;
4003
4004 static int conv_id = -2;
4005
4006 bool is_multi = false;
4007 if (Game_mode & GM_MULTI)
4008 is_multi = true;
4009
4010 if ((playernum < 0 || playernum >= MAX_PLAYERS))
4011 return false;
4012 if (is_multi && !(NetPlayers[playernum].flags & NPF_CONNECTED))
4013 return false;
4014
4015 switch (item) {
4016 case THIEFITEM_AUTOMAP:
4017 return !is_multi;
4018 break;
4019 case THIEFITEM_HEADLIGHT:
4020 if (Players[playernum].flags & PLAYER_FLAGS_HEADLIGHT_STOLEN)
4021 return false;
4022 return true;
4023 break;
4024 case THIEFITEM_ETOSCONV: {
4025 if (conv_id == -2)
4026 conv_id = FindObjectIDName("Converter");
4027
4028 if (conv_id != -1) {
4029 int inv_count = Players[playernum].inventory.GetTypeIDCount(OBJ_POWERUP, conv_id);
4030 if (inv_count > 0)
4031 return true;
4032 }
4033 return false;
4034 } break;
4035 case THIEFITEM_CLOAK: {
4036 if (pobj->effect_info) {
4037 if (!((pobj->effect_info->type_flags & EF_FADING_OUT) || (pobj->effect_info->type_flags & EF_CLOAKED))) {
4038 return false;
4039 } else {
4040 return true;
4041 }
4042 }
4043 return false;
4044 } break;
4045 case THIEFITEM_INVULN: {
4046 if (Players[playernum].flags & PLAYER_FLAGS_INVULNERABLE) {
4047 return true;
4048 }
4049 return false;
4050 } break;
4051 case THIEFITEM_QUADFIRE: {
4052 if (pobj->dynamic_wb[LASER_INDEX].flags & DWBF_QUAD)
4053 return true;
4054 else
4055 return false;
4056 } break;
4057 case THIEFITEM_RAPIDFIRE: {
4058 if (Players[playernum].weapon_recharge_scalar < 1.0f) {
4059 return true;
4060 }
4061 return false;
4062 } break;
4063 }
4064
4065 return false;
4066 }