]> icculus.org git repositories - taylor/freespace2.git/blob - src/playerman/playercontrol.cpp
Initial revision
[taylor/freespace2.git] / src / playerman / playercontrol.cpp
1 /*
2  * $Logfile: /Freespace2/code/Playerman/PlayerControl.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines to deal with player ship movement
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:11  root
11  * Initial revision
12  *
13  * 
14  * 33    10/13/99 3:42p Jefff
15  * fixed unnumbered XSTRs
16  * 
17  * 32    9/06/99 9:43p Jefff
18  * skip mission support
19  * 
20  * 31    8/30/99 10:39a Mikeb
21  * Fixed can't-warpout problem.
22  * 
23  * 30    8/29/99 4:52p Andsager
24  * Don't rotate from engine wash when warping out.
25  * 
26  * 29    8/26/99 8:51p Dave
27  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
28  * 
29  * 28    8/03/99 12:06p Dave
30  * Fixed player death messages when a player has killed himself in
31  * multiplayer.
32  * 
33  * 27    7/28/99 1:36p Andsager
34  * Modify cargo1 to include flag CARGO_NO_DEPLETE.  Add sexp
35  * cargo-no-deplete (only for BIG / HUGE).  Modify ship struct to pack
36  * better.
37  * 
38  * 26    7/21/99 8:10p Dave
39  * First run of supernova effect.
40  * 
41  * 25    7/19/99 7:20p Dave
42  * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
43  * pre-rendering.
44  * 
45  * 24    7/08/99 10:53a Dave
46  * New multiplayer interpolation scheme. Not 100% done yet, but still
47  * better than the old way.
48  * 
49  * 23    7/02/99 3:48p Mikeb
50  * Remove semi-bogus assert. Handle properly.
51  * 
52  * 22    6/16/99 10:21a Dave
53  * Added send-message-list sexpression.
54  * 
55  * 21    6/14/99 5:19p Dave
56  * 
57  * 20    6/09/99 3:26p Dave
58  * Changed zing message for beam weapon deaths.
59  * 
60  * 19    6/04/99 4:13p Johne
61  * Made a potentially unsafe normalize safe.
62  * 
63  * 18    5/21/99 5:03p Andsager
64  * Add code to display engine wash death.  Modify ship_kill_packet
65  * 
66  * 17    5/18/99 10:08a Andsager
67  * Modified single maximum range before blown up to also be multi
68  * friendly.
69  * 
70  * 16    5/17/99 6:03p Dave
71  * Added new timing code. Put in code to allow camera speed zooming.
72  * 
73  * 15    5/11/99 10:16p Andsager
74  * First pass on engine wash effect.  Rotation (control input), damage,
75  * shake.  
76  * 
77  * 14    4/23/99 12:01p Johnson
78  * Added SIF_HUGE_SHIP
79  * 
80  * 13    3/30/99 5:40p Dave
81  * Fixed reinforcements for TvT in multiplayer.
82  * 
83  * 12    3/28/99 5:58p Dave
84  * Added early demo code. Make objects move. Nice and framerate
85  * independant, but not much else. Don't use yet unless you're me :)
86  * 
87  * 11    3/10/99 6:50p Dave
88  * Changed the way we buffer packets for all clients. Optimized turret
89  * fired packets. Did some weapon firing optimizations.
90  * 
91  * 10    2/26/99 6:01p Andsager
92  * Add sexp has-been-tagged-delay and cap-subsys-cargo-known-delay
93  * 
94  * 9     2/21/99 6:02p Dave
95  * Fixed standalone WSS packets. 
96  * 
97  * 8     1/30/99 1:29a Dave
98  * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot
99  * screen.  Fixed beam weapon death messages.
100  * 
101  * 7     1/14/99 6:06p Dave
102  * 100% full squad logo support for single player and multiplayer.
103  * 
104  * 6     1/12/99 5:45p Dave
105  * Moved weapon pipeline in multiplayer to almost exclusively client side.
106  * Very good results. Bandwidth goes down, playability goes up for crappy
107  * connections. Fixed object update problem for ship subsystems.
108  * 
109  * 5     12/10/98 10:54a Dave
110  * Fixed problem where a mission ended in multiplayer and a player was
111  * dead. There was an Int3() when getting player eye-point.
112  * 
113  * 4     11/12/98 12:13a Dave
114  * Tidied code up for multiplayer test. Put in network support for flak
115  * guns.
116  * 
117  * 3     10/13/98 9:29a Dave
118  * Started neatening up freespace.h. Many variables renamed and
119  * reorganized. Added AlphaColors.[h,cpp]
120  * 
121  * 2     10/07/98 10:53a Dave
122  * Initial checkin.
123  * 
124  * 1     10/07/98 10:50a Dave
125  * 
126  * 219   6/30/98 2:16p Dave
127  * Revised object update system. Removed updates for all weapons. Put
128  * button info back into control info packet.
129  * 
130  * 218   6/09/98 5:17p Lawrance
131  * French/German localization
132  * 
133  * 217   6/09/98 10:31a Hoffoss
134  * Created index numbers for all xstr() references.  Any new xstr() stuff
135  * added from here on out should be added to the end if the list.  The
136  * current list count can be found in FreeSpace.cpp (search for
137  * XSTR_SIZE).
138  * 
139  * 216   6/01/98 11:43a John
140  * JAS & MK:  Classified all strings for localization.
141  * 
142  * 215   5/22/98 11:27a Hoffoss
143  * Fixed the bank when pressed bug where you continue to turn while using
144  * it.
145  * 
146  * 214   5/19/98 8:19p Lawrance
147  * Make mouse invert work
148  * 
149  * 213   5/19/98 12:19p Mike
150  * Cheat codes!
151  * 
152  * 212   5/18/98 2:50p Lawrance
153  * Change text for when warp drive is inoperable
154  * 
155  * 211   5/18/98 1:58a Mike
156  * Make Phoenix not be fired at fighters (but yes bombers).
157  * Improve positioning of ships in guard mode.
158  * Make turrets on player ship not fire near end of support ship docking.
159  * 
160  * 210   5/17/98 1:43a Dave
161  * Eradicated chatbox problems. Remove speed match for observers. Put in
162  * help screens for PXO. Fix messaging and end mission privelges. Fixed
163  * team select screen bugs. Misc UI fixes.
164  * 
165  * 209   5/15/98 2:41p Hoffoss
166  * Made mouse default to off (for flying ship) and fixed some new pilot
167  * init bugs.
168  * 
169  * 208   5/15/98 1:14p Hoffoss
170  * Added a deadzone to ends of abs throttle range.
171  * 
172  * 207   5/14/98 5:32p Hoffoss
173  * Improved axis binding code some more.
174  * 
175  * 206   5/13/98 11:55a Frank
176  * Fixed bug with axis 2 and 3 not working correctly.
177  * 
178  * 205   5/13/98 1:17a Hoffoss
179  * Added joystick axes configurability.
180  * 
181  * 204   5/11/98 5:29p Hoffoss
182  * Added mouse button mapped to joystick button support.
183  * 
184  * 203   5/11/98 12:01p Hoffoss
185  * Changed mouse sensitivity code to approx. double top limit while
186  * keeping low limit the same.
187  * 
188  * 202   5/09/98 4:52p Lawrance
189  * Implement padlock view (up/rear/left/right)
190  * 
191  * 201   5/08/98 5:35p Lawrance
192  * only allow cargo inspection if sensors are ok
193  * 
194  * 200   5/08/98 5:31p Hoffoss
195  * Isolated the joystick force feedback code more from dependence on other
196  * libraries.
197  * 
198  * 199   5/07/98 6:58p Hoffoss
199  * Made changes to mouse code to fix a number of problems.
200  * 
201  * 198   5/06/98 12:02a Hoffoss
202  * Fixed throttle problems with joysticks.
203  * 
204  * 197   5/05/98 8:38p Hoffoss
205  * Added sensitivity adjustment to options menu and made it save to pilot
206  * file.
207  * 
208  * 196   5/05/98 1:33p Hoffoss
209  * Changed mouse formula around a little.
210  * 
211  * 195   5/04/98 11:08p Hoffoss
212  * Expanded on Force Feedback code, and moved it all into Joy_ff.cpp.
213  * Updated references everywhere to it.
214  * 
215  * 194   5/01/98 5:45p Hoffoss
216  * Made further improvements to the mouse code.
217  * 
218  * 193   5/01/98 4:24p Lawrance
219  * Play error sound if player tries to engage afterburner when none are on
220  * ship
221  * 
222  * 192   5/01/98 1:14p Hoffoss
223  * Changed mouse usage so directInput is only used for release version.
224  * 
225  * 191   4/30/98 9:12p Hoffoss
226  * Fixed a questionable precidence issue to be known.
227  * 
228  * 190   4/30/98 5:40p Hoffoss
229  * Added mouse as a supported control to fly the ship.
230  * 
231  * 189   4/29/98 1:44p Lawrance
232  * Fix bug that would cause primaries to be linked when returning from a
233  * menu in-game (if primaries were linked at mission start)
234  * 
235  * 188   4/25/98 4:36p Lawrance
236  * init auto_advance field when pilot is created
237  * 
238  * 187   4/25/98 3:49p Lawrance
239  * Save briefing auto-advance pref
240  * 
241  * 186   4/18/98 9:52p Mike
242  * Don't restore player flags from save file in training mission, as it
243  * enables auto-target to persist.
244  * 
245  * 185   4/17/98 11:16a Allender
246  * use short callsign when showing player name in cargo area of target
247  * info box
248  * 
249  * 184   4/09/98 12:32a Lawrance
250  * Fix bugs related to multiple screams from same ship, builtin messages
251  * playing after screams, or praising while severly damaged.
252  * 
253  * 183   4/08/98 7:11p Dave
254  * Fix auto-targeting and auto-matching reset after player respawn.
255  * Removed incorrect call to furball update if in a non-furball game.
256  * 
257  * 182   4/08/98 11:11a Hoffoss
258  * Fixed some bugs that showed up due to fixing other bugs the other day
259  * with controls.
260  * 
261  * 181   4/08/98 10:46a Lawrance
262  * fix uninitialized data warning
263  * 
264  * 180   4/06/98 11:00a Hoffoss
265  * Fixed bank when pressed key to also be usable with keyboard yaw
266  * controls.
267  * 
268  * 179   4/05/98 7:43p Lawrance
269  * fix up saving/restoring of link status and auto-target/match-speed.
270  * 
271  * 178   4/01/98 7:42p Lawrance
272  * Enable auto-targeting by default when a new pilot is created.
273  * 
274  * 177   4/01/98 1:31p Allender
275  * don't play all alone message in multiplayer
276  * 
277  * 176   3/31/98 11:47p Lawrance
278  * 
279  * 175   3/31/98 5:18p John
280  * Removed demo/save/restore.  Made NDEBUG defined compile.  Removed a
281  * bunch of debug stuff out of player file.  Made model code be able to
282  * unload models and malloc out only however many models are needed.
283  *  
284  * 
285  * 174   3/30/98 12:19a Lawrance
286  * Make scan time a property of a ship
287  * 
288  * 173   3/24/98 4:25p Lawrance
289  * Make finding out if player killed self easier and more reliable
290  * 
291  * 172   3/23/98 12:28p Hoffoss
292  * Fixed +/-5% throttle controls to actually do 5%, rather than whatever
293  * the heck it was doing before.
294  * 
295  * 171   3/21/98 3:35p Lawrance
296  * Fix joystick turning in external view
297  * 
298  * 170   3/19/98 5:35p Lawrance
299  * Correctly inform player if killed by ship explosion.
300  * 
301  * 169   3/18/98 6:04p Lawrance
302  * change text for warp destroyed message
303  * 
304  * 168   3/18/98 12:03p John
305  * Marked all the new strings as externalized or not.
306  * 
307  * 167   3/16/98 5:54p Lawrance
308  * Play cargo scanning sound
309  * 
310  * 166   3/14/98 4:58p Lawrance
311  * surpress HUD messages for auto-match speed
312  * 
313  * 165   3/11/98 12:11p Mike
314  * Increase max speed to enable warpout even if ship has little energy
315  * directed towards engines.
316  * 
317  * 164   3/11/98 11:19a Mike
318  * Quick fix since I completely broke warping out.
319  * 
320  * 163   3/11/98 9:08a Mike
321  * Intermediate checkin to resolve link errors.  Working on forcing
322  * player's engine energy high enough to enable warpout.
323  * 
324  * 162   3/10/98 5:08p Allender
325  * fixed up multiplayer death messages (I hope).  changes in object update
326  * packets
327  * 
328  * 161   3/09/98 4:30p Allender
329  * multiplayer secondary weapon changes.  red-alert and cargo-known-delay
330  * sexpressions.  Add time cargo revealed to ship structure
331  * 
332  * 160   3/07/98 3:49p Lawrance
333  * store killer species in player struct
334  * 
335  * 159   3/05/98 10:16p Lawrance
336  * Add 'save_flags' to player struct to save/restore certain player flags
337  * cleanly.
338  * 
339  * 158   2/28/98 7:03p Lawrance
340  * get slew working in any view
341  * 
342  * 157   2/26/98 12:33a Lawrance
343  * Added back slew mode,  lots of changes to external and chase views.
344  * 
345  * 156   2/23/98 6:54p Lawrance
346  * Make interface to real-time voice more generic and useful.
347  * 
348  * 155   2/22/98 4:30p John
349  * More string externalization classification
350  * 
351  * 154   2/22/98 3:56p Lawrance
352  * Make external view a toggle like chase view.  Allow extenal view to
353  * override chase view.
354  * 
355  * 153   2/22/98 2:48p John
356  * More String Externalization Classification
357  * 
358  * 152   2/20/98 8:30p Lawrance
359  * Play 'all alone' message when player is last ship left and primary
360  * objective is incomplete.
361  * 
362  * 151   2/19/98 5:30p Lawrance
363  * Allow player turrets to fire automatically.
364  * 
365  * 150   2/16/98 7:33p Lawrance
366  * add function to determine range of current secondary weapon
367  * 
368  * 149   2/15/98 9:51p Sandeep
369  * AL: Check for 'Player 1' as a ship name when displaying the death
370  * message
371  * 
372  * 148   2/14/98 4:41p Lawrance
373  * Add some new fields to keep track of how the player died.
374  * 
375  * 147   2/11/98 9:53a John
376  * Put in a real fix to the bug with not resetting joystick time between
377  * missions
378  * 
379  * 146   2/10/98 9:29p Mike
380  * Hack-fix bug with joystick reading not being allowed in 2nd playthrough
381  * of a mission until time exceeds duration of previous mission.
382  * 
383  * 145   2/10/98 1:15p John
384  * Made the joystick only read at 10Hz max
385  * 
386  * 144   2/06/98 4:31p Lawrance
387  * revamp radar code, allow dim radar dots
388  * 
389  * 143   2/06/98 3:48p Allender
390  * added code to clear out control info for multiplayer clients so they
391  * don't accidentally start firing all the time
392  * 
393  * 142   2/06/98 12:13a Lawrance
394  * Don't play throttle sounds when using analog throttle.
395  * 
396  * 141   2/05/98 10:41a Lawrance
397  * Scale frequency of 'good kill' messages by skill level.
398  * 
399  * 140   2/02/98 4:24p Lawrance
400  * Only inspect cargo and transport in single player.
401  * 
402  * 139   2/02/98 4:12p Allender
403  * fixed bug I introduced with multiplayer callsigns displaying in cargo
404  * spot
405  * 
406  * $NoKeywords: $
407 */
408
409 #include "pstypes.h"
410 #include "physics.h"
411 #include "key.h"
412 #include "joy.h"
413 #include "joy_ff.h"
414 #include "mouse.h"
415 #include "fix.h"
416 #include "floating.h"
417 #include "object.h"
418 #include "player.h"
419 #include "hud.h"
420 #include "hudtarget.h"
421 #include "hudtargetbox.h"
422 #include "ship.h"
423 #include "freespace.h"
424 #include "controlsconfig.h"
425 #include "sound.h"
426 #include "gamesnd.h"
427 #include "missionshipchoice.h"
428 #include "afterburner.h"
429 #include "timer.h"
430 #include "gamesequence.h"
431 #include "missionmessage.h"
432 #include "multiutil.h"
433 #include "linklist.h"
434 #include "missiongoals.h"
435 #include "hudsquadmsg.h"
436 #include "multi_obj.h"
437 #include "observer.h"
438
439 ////////////////////////////////////////////////////////////
440 // Global object and other interesting player type things
441 ////////////////////////////////////////////////////////////
442 player  Players[MAX_PLAYERS];
443
444 int             Player_num;
445 player  *Player = NULL;
446
447 physics_info Descent_physics;                   // used when we want to control the player like the descent ship
448
449 ////////////////////////////////////////////////////////////
450 // Module data
451 ////////////////////////////////////////////////////////////
452 static int Player_all_alone_msg_inited=0;       // flag used for initalizing a player-specific voice msg
453
454 #ifndef NDEBUG
455         int Show_killer_weapon = 0;
456         DCF_BOOL( show_killer_weapon, Show_killer_weapon );
457 #endif
458
459 void playercontrol_read_stick(int *axis, float frame_time);
460 void player_set_padlock_state();
461
462 //      Slew angles chase towards zero like they're on a spring.
463 //      When furthest away, move fastest.
464 //      Minimum speed set so that doesn't take too long.
465 //      When gets close, clamps to zero.
466 void chase_angles_to_zero(angles *ap)
467 {
468         float   k1, k2;
469         float   sk;
470
471         //      Make sure we actually need to do all this math.
472         if ((ap->p == 0.0f) && (ap->h == 0.0f))
473                 return;
474
475         //      This is what we'll scale each value by.
476         sk = 1.0f - 2*flFrametime;
477
478         //      These are the amounts that will be subtracted from pitch and heading.
479         //      They are only needed to make sure we aren't moving too slowly.
480         k1 = fl_abs(ap->p * (1.0f - sk));
481         k2 = fl_abs(ap->h * (1.0f - sk));
482
483         //      See if the larger dimension of movement is too small.
484         // If so, boost amount of movement in both dimensions.
485         if (k1 >= k2) {
486                 if (k1 < flFrametime)
487                         sk = 1.0f - (1.0f - sk) * flFrametime/k1;
488         } else if (k2 > k1) {
489                 if (k2 < flFrametime)
490                         sk = 1.0f - (1.0f - sk) * flFrametime/k2;
491         }
492
493         //      It's possible we made the scale factor negative above.
494         if (sk < 0.0f)
495                 sk = 0.0f;
496
497         ap->p *= sk;
498         ap->h *= sk;
499
500         //      If we're very close, put ourselves at goal.
501         if ((fl_abs(ap->p) < 0.005f) && (fl_abs(ap->h) < 0.005f)) {
502                 ap->p = 0.0f;
503                 ap->h = 0.0f;
504         }
505
506         //      Update Viewer_mode based on whether we're looking dead ahead.   
507         if ((ap->p == 0.0f) && (ap->b == 0.0f) && (ap->h == 0.0f))
508                 Viewer_mode &= ~VM_SLEWED;
509         else
510                 Viewer_mode |= VM_SLEWED;
511
512 }
513
514 angles  Viewer_slew_angles_delta;
515 angles  Viewer_external_angles_delta;
516
517 void view_modify(angles *ma, angles *da, float minv, float maxv, int slew, float frame_time)
518 {
519         int axis[JOY_NUM_AXES];
520         float   t;
521
522         if ( (!slew) && (Viewer_mode & VM_EXTERNAL) && (Viewer_mode & VM_EXTERNAL_CAMERA_LOCKED) ) {
523                 return;
524         }
525
526         if ( Viewer_mode & VM_EXTERNAL ) {
527                 t = (check_control_timef(YAW_LEFT) - check_control_timef(YAW_RIGHT)) / 16.0f;
528         } else {
529                 t = (check_control_timef(YAW_RIGHT) - check_control_timef(YAW_LEFT)) / 16.0f;
530         }
531
532         if (t != 0.0f)
533                 da->h += t;
534         else
535                 da->h = 0.0f;
536
537         t = (check_control_timef(PITCH_FORWARD) - check_control_timef(PITCH_BACK)) / 16.0f;
538         if (t != 0.0f)
539                 da->p += t;
540         else
541                 da->p = 0.0f;
542                         
543         da->b = 0.0f;
544
545         playercontrol_read_stick(axis, frame_time);
546
547         if ( Viewer_mode & VM_EXTERNAL ) {
548                 // check the heading on the x axis
549                 da->h -= f2fl( axis[0] );
550
551         } else {
552                 // check the heading on the x axis
553                 da->h += f2fl( axis[0] );
554         }
555
556         // check the pitch on the y axis
557         da->p -= f2fl( axis[1] );
558
559         if (da->h > 1.0f)
560                 da->h = 1.0f;
561         else if (da->h < -1.0f)
562                 da->h = -1.0f;
563
564         if (da->p > 1.0f)
565                 da->p = 1.0f;
566         else if (da->p < -1.0f)
567                 da->p = -1.0f;
568
569         ma->p += da->p * flFrametime;
570         ma->b += da->b * flFrametime;
571         ma->h += da->h * flFrametime;
572
573         if (ma->p > maxv)
574                 ma->p = maxv;
575         else if (ma->p < minv)
576                 ma->p = minv;
577
578         if (ma->h > maxv)
579                 ma->h = maxv;
580         else if (ma->h < minv)
581                 ma->h = minv;
582 }
583
584 //      When PAD0 is pressed, keypad controls viewer direction slewing.
585 void do_view_slew(float frame_time)
586 {
587         view_modify(&Viewer_slew_angles, &Viewer_slew_angles_delta, -PI/3, PI/3, 1, frame_time);
588
589         if ((Viewer_slew_angles.p == 0.0f) && (Viewer_slew_angles.b == 0.0f) && (Viewer_slew_angles.h == 0.0f))
590                 Viewer_mode &= ~VM_SLEWED;
591         else
592                 Viewer_mode |= VM_SLEWED;
593 }
594
595 void do_view_chase(float frame_time)
596 {
597         float t;
598
599         //      Process centering key.
600         if (check_control_timef(VIEW_CENTER)) {
601                 Viewer_chase_info.distance = 0.0f;
602         }
603         
604         t = check_control_timef(VIEW_DIST_INCREASE) - check_control_timef(VIEW_DIST_DECREASE);
605         Viewer_chase_info.distance += t*4;
606         if (Viewer_chase_info.distance < 0.0f)
607                 Viewer_chase_info.distance = 0.0f;
608 }
609
610 float camera_zoom_scale = 1.0f;
611
612 DCF(camera_speed, "")
613 {
614         dc_get_arg(ARG_FLOAT);
615         camera_zoom_scale = Dc_arg_float;
616 }
617
618 void do_view_external(float frame_time)
619 {
620         float   t;
621
622         view_modify(&Viewer_external_info.angles, &Viewer_external_angles_delta, -2*PI, 2*PI, 0, frame_time);
623
624         //      Process centering key.
625         if (check_control_timef(VIEW_CENTER)) {
626                 Viewer_external_info.angles.p = 0.0f;
627                 Viewer_external_info.angles.h = 0.0f;
628                 Viewer_external_info.distance = 0.0f;
629         }
630         
631         t = check_control_timef(VIEW_DIST_INCREASE) - check_control_timef(VIEW_DIST_DECREASE);
632         Viewer_external_info.distance += t*4*camera_zoom_scale;
633         if (Viewer_external_info.distance < 0.0f){
634                 Viewer_external_info.distance = 0.0f;
635         }
636
637         //      Do over-the-top correction.
638
639         if (Viewer_external_info.angles.p > PI)
640                 Viewer_external_info.angles.p = -2*PI + Viewer_external_info.angles.p;
641         else if (Viewer_external_info.angles.p < -PI)
642                 Viewer_external_info.angles.p = 2*PI + Viewer_external_info.angles.p;
643
644         if (Viewer_external_info.angles.h > PI)
645                 Viewer_external_info.angles.h = -2*PI + Viewer_external_info.angles.h;
646         else if (Viewer_external_info.angles.h < -PI)
647                 Viewer_external_info.angles.h = 2*PI + Viewer_external_info.angles.h;
648 }
649
650 // separate out the reading of thrust keys, so we can call this from external
651 // view as well as from normal view
652 void do_thrust_keys(control_info *ci)
653 {
654         ci->forward = check_control_timef(FORWARD_THRUST) - check_control_timef(REVERSE_THRUST);
655 }
656
657 // called by single and multiplayer modes to reset information inside of control info structure
658 void player_control_reset_ci( control_info *ci )
659 {
660         float t1, t2, oldspeed;
661
662         t1 = ci->heading;
663         t2 = ci->pitch;
664         oldspeed = ci->forward_cruise_percent;
665         memset( ci, 0, sizeof(control_info) );
666         ci->heading = t1;
667         ci->pitch = t2;
668         ci->forward_cruise_percent = oldspeed;
669 }
670
671 // Read the 4 joystick axis.  This is its own function
672 // because we only want to read it at a certain rate,
673 // since it takes time.
674
675 static int Joystick_saved_reading[JOY_NUM_AXES];
676 static int Joystick_last_reading = -1;
677
678 void playercontrol_read_stick(int *axis, float frame_time)
679 {
680         int i;
681
682 #ifndef NDEBUG
683         // Make sure things get reset properly between missions.
684         if ( (Joystick_last_reading != -1) && (timestamp_until(Joystick_last_reading) > 1000) ) {
685                 Int3();         // Get John!  John, the joystick last reading didn't get reset btwn levels.
686                 Joystick_last_reading = -1;
687         }
688 #endif
689
690         if ( (Joystick_last_reading == -1)  || timestamp_elapsed(Joystick_last_reading) ) {
691                 // Read the stick
692                 control_get_axes_readings(&Joystick_saved_reading[0], &Joystick_saved_reading[1], &Joystick_saved_reading[2], &Joystick_saved_reading[3], &Joystick_saved_reading[4]);
693                 Joystick_last_reading = timestamp( 1000/10 );   // Read 10x per second, like we did in Descent.
694         }
695
696         for (i=0; i<NUM_JOY_AXIS_ACTIONS; i++) {
697                 axis[i] = Joystick_saved_reading[i];
698         }
699
700         if (Use_mouse_to_fly) {
701                 int dx, dy, dz;
702                 float factor;
703
704 //              factor = (float) Mouse_sensitivity + 2.5f;
705 //              factor = factor * factor / frame_time / 1.2f;
706                 factor = (float) Mouse_sensitivity + 1.77f;
707                 factor = factor * factor / frame_time / 0.6f;
708
709                 mouse_get_delta(&dx, &dy, &dz);
710
711                 if ( Invert_axis[0] ) {
712                         dx = -dx;
713                 }
714
715                 if ( Invert_axis[1] ) {
716                         dy = -dy;
717                 }
718
719                 if ( Invert_axis[3] ) {
720                         dz = -dz;
721                 }
722
723                 axis[0] += (int) ((float) dx * factor);
724                 axis[1] += (int) ((float) dy * factor);
725                 axis[3] += (int) ((float) dz * factor);
726         }
727 }
728
729 void read_keyboard_controls( control_info * ci, float frame_time, physics_info *pi )
730 {
731         float kh=0.0f, scaled, newspeed, delta, oldspeed;
732         int axis[JOY_NUM_AXES], ignore_pitch, slew_active=0;
733         static int afterburner_last = 0;
734         static float analog_throttle_last = 9e9f;
735         static int override_analog_throttle = 0; 
736         int ok_to_read_ci_pitch_yaw=1;
737
738         oldspeed = ci->forward_cruise_percent;
739         player_control_reset_ci( ci );
740
741         if ( check_control(VIEW_SLEW) ) {
742                 do_view_slew(frame_time);
743                 slew_active=1;
744         }
745
746         if ( Viewer_mode & VM_EXTERNAL ) {
747                 control_used(VIEW_EXTERNAL);
748                 if ( !(Viewer_mode & VM_EXTERNAL_CAMERA_LOCKED) ) {
749                         ok_to_read_ci_pitch_yaw=0;
750                         slew_active=0;
751                 }
752
753                 do_view_external(frame_time);
754                 do_thrust_keys(ci);
755         }
756
757         if ( !slew_active ) {
758                 if ( Viewer_mode & VM_CHASE ) {
759                         do_view_chase(frame_time);
760                 }
761         }
762         
763         if ( ok_to_read_ci_pitch_yaw ) {
764                 // From keyboard...
765                 if ( check_control(BANK_WHEN_PRESSED) ) {
766                         ci->bank = check_control_timef(BANK_LEFT) + check_control_timef(YAW_LEFT) - check_control_timef(YAW_RIGHT) - check_control_timef(BANK_RIGHT);
767                         ci->heading = 0.0f;
768
769                 } else {
770                         kh = (check_control_timef(YAW_RIGHT) - check_control_timef(YAW_LEFT)) / 8.0f;
771                         if (kh == 0.0f) {
772                                 ci->heading = 0.0f;
773
774                         } else if (kh > 0.0f) {
775                                 if (ci->heading < 0.0f)
776                                         ci->heading = 0.0f;
777
778                         } else {  // kh < 0
779                                 if (ci->heading > 0.0f)
780                                         ci->heading = 0.0f;
781                         }
782
783                         ci->bank = check_control_timef(BANK_LEFT) - check_control_timef(BANK_RIGHT);
784                 }
785
786                 ci->heading += kh;
787
788                 kh = (check_control_timef(PITCH_FORWARD) - check_control_timef(PITCH_BACK)) / 8.0f;
789                 if (kh == 0.0f) {
790                         ci->pitch = 0.0f;
791
792                 } else if (kh > 0.0f) {
793                         if (ci->pitch < 0.0f)
794                                 ci->pitch = 0.0f;
795
796                 } else {  // kh < 0
797                         if (ci->pitch > 0.0f)
798                                 ci->pitch = 0.0f;
799                 }
800
801                 ci->pitch += kh;
802
803                 ci->sideways = (key_down_timef(KEY_PAD3) - key_down_timef(KEY_PAD1));
804                 ci->vertical = (key_down_timef(KEY_PADPLUS) - key_down_timef(KEY_PADENTER));
805
806                 do_thrust_keys(ci);
807         }
808
809         if ( !slew_active ) {
810                 chase_angles_to_zero(&Viewer_slew_angles);
811         }
812
813         player_set_padlock_state();
814
815         if (!(Game_mode & GM_DEAD)) {
816                 if ( button_info_query(&Player->bi, ONE_THIRD_THROTTLE) ) {
817                         control_used(ONE_THIRD_THROTTLE);
818                         player_clear_speed_matching();
819                         if ( Player->ci.forward_cruise_percent < 33.3f ) {
820                                 snd_play( &Snds[SND_THROTTLE_UP], 0.0f );
821
822                         } else if ( Player->ci.forward_cruise_percent > 33.3f ) {
823                                 snd_play( &Snds[SND_THROTTLE_DOWN], 0.0f );
824                         }
825
826                         Player->ci.forward_cruise_percent = 33.3f;
827                         override_analog_throttle = 1;
828                 }
829
830                 if ( button_info_query(&Player->bi, TWO_THIRDS_THROTTLE) ) {
831                         control_used(TWO_THIRDS_THROTTLE);
832                         player_clear_speed_matching();
833                         if ( Player->ci.forward_cruise_percent < 66.6f ) {
834                                 snd_play( &Snds[SND_THROTTLE_UP], 0.0f );
835
836                         } else if (Player->ci.forward_cruise_percent > 66.6f) {
837                                 snd_play( &Snds[SND_THROTTLE_DOWN], 0.0f );
838                         }
839
840                         Player->ci.forward_cruise_percent = 66.6f;
841                         override_analog_throttle = 1;
842                 }
843
844 //              if ( button_info_query(&Player->bi, PLUS_5_PERCENT_THROTTLE) ) {
845 //                      control_used(PLUS_5_PERCENT_THROTTLE);
846 //                      Player->ci.forward_cruise_percent += (100.0f/Player_ship->current_max_speed);
847 //              }
848
849                 if ( button_info_query(&Player->bi, PLUS_5_PERCENT_THROTTLE) ) {
850                         control_used(PLUS_5_PERCENT_THROTTLE);
851                         Player->ci.forward_cruise_percent += 5.0f;
852                         if (Player->ci.forward_cruise_percent > 100.0f)
853                                 Player->ci.forward_cruise_percent = 100.0f;
854                 }
855
856 //              if ( button_info_query(&Player->bi, MINUS_5_PERCENT_THROTTLE) ) {
857 //                      control_used(MINUS_5_PERCENT_THROTTLE);
858 //                      Player->ci.forward_cruise_percent -= (100.0f/Player_ship->current_max_speed);
859 //              }
860
861                 if ( button_info_query(&Player->bi, MINUS_5_PERCENT_THROTTLE) ) {
862                         control_used(MINUS_5_PERCENT_THROTTLE);
863                         Player->ci.forward_cruise_percent -= 5.0f;
864                         if (Player->ci.forward_cruise_percent < 0.0f)
865                                 Player->ci.forward_cruise_percent = 0.0f;
866                 }
867
868                 if ( button_info_query(&Player->bi, ZERO_THROTTLE) ) {
869                         control_used(ZERO_THROTTLE);
870                         player_clear_speed_matching();
871                         if ( ci->forward_cruise_percent > 0.0f && Player_obj->phys_info.fspeed > 0.5) {
872                                 snd_play( &Snds[SND_ZERO_THROTTLE], 0.0f );
873                         }
874
875                         ci->forward_cruise_percent = 0.0f;
876                         override_analog_throttle = 1;
877                 }
878
879                 if ( button_info_query(&Player->bi, MAX_THROTTLE) ) {
880                         control_used(MAX_THROTTLE);
881                         player_clear_speed_matching();
882                         if ( ci->forward_cruise_percent < 100.0f ) {
883                                 snd_play( &Snds[SND_FULL_THROTTLE], 0.0f );
884                         }
885
886                         ci->forward_cruise_percent = 100.0f;
887                         override_analog_throttle = 1;
888                 }
889
890                 // AL 12-29-97: If afterburner key is down, player should have full forward thrust (even if afterburners run out)
891                 if ( check_control(AFTERBURNER) ) {
892                         ci->forward = 1.0f;
893                 }
894
895                 if ( Player->flags & PLAYER_FLAGS_MATCH_TARGET ) {
896                         if ( (Player_ai->last_target == Player_ai->target_objnum) && (Player_ai->target_objnum != -1) && ( ci->forward_cruise_percent == oldspeed) ) {
897                                 float tspeed, pmax_speed;
898
899                                 tspeed = Objects[Player_ai->target_objnum].phys_info.fspeed;
900
901                                 // maybe need to get speed from docked partner
902                                 if ( tspeed < MATCH_SPEED_THRESHOLD ) {
903                                         ai_info *aip;
904
905                                         Assert(Objects[Player_ai->target_objnum].type == OBJ_SHIP);
906
907                                         aip = &Ai_info[Ships[Objects[Player_ai->target_objnum].instance].ai_index];
908                                         if ( aip->ai_flags & AIF_DOCKED ) {
909                                                 Assert( aip->dock_objnum != -1 );
910                                                 tspeed = Objects[aip->dock_objnum].phys_info.fspeed;
911                                         }
912                                 }
913
914                                 //      Note, if closer than 100 units, scale down speed a bit.  Prevents repeated collisions. -- MK, 12/17/97
915                                 float dist = vm_vec_dist(&Player_obj->pos, &Objects[Player_ai->target_objnum].pos);
916
917                                 if (dist < 100.0f) {
918                                         tspeed = tspeed * (0.5f + dist/200.0f);
919                                 }
920
921                                 //pmax_speed = Ship_info[Ships[Player_obj->instance].ship_info_index].max_speed;
922                                 pmax_speed = Ships[Player_obj->instance].current_max_speed;
923                                 ci->forward_cruise_percent = (tspeed / pmax_speed) * 100.0f;
924                                 override_analog_throttle = 1;
925         //                      if ( ci->forward_cruise_percent > 100.0f )
926         //                              HUD_printf ("Cannot travel that fast.  Setting throttle to full.");
927                                 // mprintf(("forward -- %7.3f\n", ci->forward_cruise_percent));
928
929                         } else
930                                 Player->flags &= ~PLAYER_FLAGS_MATCH_TARGET;
931                 }
932
933 //                      player_read_joystick();
934                 // code to read joystick axis for pitch/heading.  Code to read joystick buttons
935                 // fo1r bank.
936                 if ( !(Game_mode & GM_DEAD) )   {
937                         playercontrol_read_stick(axis, frame_time);
938                 } else {
939                         axis[0] = axis[1] = axis[2] = axis[3] = axis[4] = 0;
940                 }
941
942                 ignore_pitch = FALSE;
943
944                 if (Axis_map_to[JOY_HEADING_AXIS] >= 0) {
945                         // check the heading on the x axis
946                         if ( check_control(BANK_WHEN_PRESSED) ) {
947                                 delta = f2fl( axis[JOY_HEADING_AXIS] );
948                                 if ( (delta > 0.05f) || (delta < -0.05f) ) {
949                                         ci->bank -= delta;
950                                         ignore_pitch = TRUE;
951                                 }
952
953                         } else {
954                                 ci->heading += f2fl( axis[JOY_HEADING_AXIS] );
955                         }
956                 }
957
958                 // check the pitch on the y axis
959                 if (Axis_map_to[JOY_PITCH_AXIS] >= 0)
960                         ci->pitch -= f2fl( axis[JOY_PITCH_AXIS] );
961
962                 if (Axis_map_to[JOY_BANK_AXIS] >= 0) {
963                         ci->bank -= f2fl( axis[JOY_BANK_AXIS] ) * 1.5f;
964                 }
965
966                 // axis 2 is for throttle
967                 if (Axis_map_to[JOY_ABS_THROTTLE_AXIS] >= 0) {
968                         scaled = (float) axis[JOY_ABS_THROTTLE_AXIS] * 1.2f / (float) F1_0 - 0.1f;  // convert to -0.1 - 1.1 range
969                         oldspeed = ci->forward_cruise_percent;
970
971 //                      scaled = (scaled + 1.0f) / 1.85f;
972                         newspeed = (1.0f - scaled) * 100.0f;
973
974                         delta = analog_throttle_last - newspeed;
975                         if (!override_analog_throttle || (delta < -1.5f) || (delta > 1.5f)) {
976                                 ci->forward_cruise_percent = newspeed;
977                                 analog_throttle_last = newspeed;
978                                 override_analog_throttle = 0;
979 /*
980                                 // AL 1-5-98: don't play throttle sounds when using analog control
981
982                                 if ( (oldspeed < 1.0f) && (newspeed >= 1.0f) )
983                                         snd_play( &Snds[SND_THROTTLE_UP], 0.0f );
984                                 else if ( (oldspeed < 66.6f) && (newspeed >= 66.6f) )
985                                         snd_play( &Snds[SND_THROTTLE_UP], 0.0f );
986                                 else if ( (oldspeed < 33.3f) && (newspeed >= 33.3f) )
987                                         snd_play( &Snds[SND_THROTTLE_UP], 0.0f );
988                                 else if ( (oldspeed > 99.0f) && (newspeed <= 99.0f) )
989                                         snd_play( &Snds[SND_THROTTLE_DOWN], 0.0f );
990                                 else if ( (oldspeed > 33.3f) && (newspeed <= 33.3f) )
991                                         snd_play( &Snds[SND_THROTTLE_DOWN], 0.0f );
992                                 else if ( (oldspeed > 66.6f) && (newspeed <= 66.6f) )
993                                         snd_play( &Snds[SND_THROTTLE_DOWN], 0.0f );
994 */
995                         }
996                 }
997
998                 if (Axis_map_to[JOY_REL_THROTTLE_AXIS] >= 0)
999                         ci->forward_cruise_percent += f2fl(axis[JOY_REL_THROTTLE_AXIS]) * 100.0f * frame_time;
1000
1001                 if ( ci->forward_cruise_percent > 100.0f )
1002                         ci->forward_cruise_percent = 100.0f;
1003                 if ( ci->forward_cruise_percent < 0.0f )
1004                         ci->forward_cruise_percent = 0.0f;
1005
1006                 // set up the firing stuff.  Read into control info ala Descent so that weapons will be
1007                 // created during the object simulation phase, and not immediately as was happening before.
1008
1009                 //keyboard: fire the current primary weapon
1010                 if (check_control(FIRE_PRIMARY)) {
1011                         ci->fire_primary_count++;
1012
1013                         // if we're a multiplayer client, set our accum bits now
1014                         // if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && !(Netgame.debug_flags & NETD_FLAG_CLIENT_FIRING)){
1015                         // if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && !(Netgame.debug_flags & NETD_FLAG_CLIENT_FIRING)){
1016                                 // Net_player->s_info.accum_buttons |= OOC_FIRE_PRIMARY;
1017                         // }
1018                 }
1019
1020                 // mouse: fire the current primary weapon
1021 //              ci->fire_primary_count += mouse_down(1);
1022
1023                 // for debugging, check to see if the debug key is down -- if so, make fire the debug laser instead
1024 #ifndef NDEBUG
1025                 if ( keyd_pressed[KEY_DEBUG_KEY] ) {
1026                         ci->fire_debug_count = ci->fire_primary_count;
1027                         ci->fire_primary_count = 0;
1028                 }
1029 #endif
1030
1031                 // keyboard: fire the current secondary weapon
1032                 if (check_control(FIRE_SECONDARY)) {
1033                         ci->fire_secondary_count++;
1034
1035                         // if we're a multiplayer client, set our accum bits now
1036                         if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1037                                 Net_player->s_info.accum_buttons |= OOC_FIRE_SECONDARY;
1038                         }
1039                 }
1040
1041                 // keyboard: launch countermeasures
1042                 if ( button_info_query(&Player->bi, LAUNCH_COUNTERMEASURE) ) {
1043                         control_used(LAUNCH_COUNTERMEASURE);
1044                         ci->fire_countermeasure_count++;
1045                         hud_gauge_popup_start(HUD_CMEASURE_GAUGE);
1046
1047                         // if we're a multiplayer client, set our accum bits now
1048                         // if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) && !(Netgame.debug_flags & NETD_FLAG_CLIENT_FIRING)){
1049                                 // Net_player->s_info.accum_buttons |= OOC_FIRE_COUNTERMEASURE;
1050                         // }
1051                 }
1052
1053                 // see if the afterburner has been started (keyboard + joystick)
1054                 if (check_control(AFTERBURNER)) {
1055                         if (!afterburner_last) {
1056                                 Assert(Player_ship);
1057                                 if ( !(Ship_info[Player_ship->ship_info_index].flags & SIF_AFTERBURNER) ) {
1058                                         gamesnd_play_error_beep();
1059                                 } else {
1060                                         ci->afterburner_start = 1;
1061                                 }
1062                         }
1063
1064                         afterburner_last = 1;
1065
1066                 } else {
1067                         if (afterburner_last)
1068                                 ci->afterburner_stop = 1;
1069
1070                         afterburner_last = 0;
1071                 }
1072         }
1073
1074         if ( (Viewer_mode & VM_EXTERNAL) || slew_active ) {
1075                 if ( !(Viewer_mode & VM_EXTERNAL_CAMERA_LOCKED) || slew_active ) {
1076                         ci->heading=0.0f;
1077                         ci->pitch=0.0f;
1078                         ci->bank=0.0f;
1079                 }
1080         }
1081 }
1082
1083 void read_player_controls(object *objp, float frametime)
1084 {
1085 //      if (Game_mode & GM_DEAD)
1086 //              return;
1087
1088         joy_ff_adjust_handling((int) objp->phys_info.speed);
1089
1090         {
1091                 switch( Player->control_mode )  {
1092                 case PCM_SUPERNOVA:
1093                         break;
1094
1095                 case PCM_NORMAL:
1096               read_keyboard_controls(&(Player->ci), frametime, &objp->phys_info );
1097                         break;
1098                 case PCM_WARPOUT_STAGE1:        // Accelerate to 40 km/s
1099                 case PCM_WARPOUT_STAGE2:        // Go 40 km/s steady up to the effect
1100                 case PCM_WARPOUT_STAGE3:        // Go 40 km/s steady through the effect
1101
1102                         memset(&(Player->ci), 0, sizeof(control_info) );                // set the controls to 0
1103
1104                         if ( (objp->type == OBJ_SHIP) && (!(Game_mode & GM_DEAD)) )     {
1105
1106                                 Warpout_time += flFrametime;
1107
1108                                 if ( Warpout_forced )   {
1109
1110                                         Ships[objp->instance].current_max_speed = TARGET_WARPOUT_SPEED*2.0f;
1111
1112                                         float diff = TARGET_WARPOUT_SPEED-objp->phys_info.fspeed;                               
1113                                         if ( diff < 0.0f ) diff = 0.0f;
1114                                         
1115                                         Player->ci.forward = ((TARGET_WARPOUT_SPEED+diff) / Ships[objp->instance].current_max_speed);
1116
1117                                 } else {
1118                                         int warp_failed=0;
1119                                         // check if warp ability has been disabled
1120                                         if ( Ships[objp->instance].flags & ( SF_WARP_BROKEN|SF_WARP_NEVER ) ) {
1121                                                 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Cannot warp out at this time.", 81));
1122                                                 warp_failed=1;
1123                                         } else {
1124                                                 int     can_warp = 0;
1125                                                 if ( (!warp_failed) && (Ships[objp->instance].current_max_speed >= TARGET_WARPOUT_SPEED) )      {
1126                                                         can_warp = 1;
1127                                                 } else {
1128                                                         if (Ship_info[Ships[objp->instance].ship_info_index].max_overclocked_speed < TARGET_WARPOUT_SPEED) {
1129                                                                 // Cannot go fast enough, so abort sequence.
1130                                                                 warp_failed=1;
1131                                                                 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Unable to engage warp... ship must be able to reach %.1f km/s", 82), TARGET_WARPOUT_SPEED );
1132                                                                 can_warp = 0;
1133                                                         } else {
1134                                                                 Ships[objp->instance].current_max_speed = TARGET_WARPOUT_SPEED + 5.0f;
1135                                                                 //Ships[objp->instance].current_max_speed = Ship_info[Ships[objp->instance].ship_info_index].max_overclocked_speed;
1136                                                                 can_warp = 1;
1137                                                         }
1138                                                 }
1139                                                 if (can_warp) {
1140                                                         float diff = TARGET_WARPOUT_SPEED-objp->phys_info.fspeed;                               
1141                                                         if ( diff < 0.0f ) 
1142                                                                 diff = 0.0f;
1143                                                 
1144                                                         Player->ci.forward = ((TARGET_WARPOUT_SPEED+diff) / Ships[objp->instance].current_max_speed);
1145                                                 }
1146                                         }
1147
1148                                         if ( warp_failed ) {
1149                                                 snd_play(&Snds[SND_PLAYER_WARP_FAIL]);
1150                                                 gameseq_post_event( GS_EVENT_PLAYER_WARPOUT_STOP );
1151                                         }
1152                                 }
1153                         
1154                                 if ( Player->control_mode == PCM_WARPOUT_STAGE1 )       {
1155
1156
1157                                         // Wait at least 3 seconds before making sure warp speed is set.
1158                                         if ( Warpout_time>MINIMUM_PLAYER_WARPOUT_TIME ) {
1159                                                 // If we are going around 5% of the target speed, progress to next stage
1160                                                 float diff = fl_abs(objp->phys_info.fspeed - TARGET_WARPOUT_SPEED )/TARGET_WARPOUT_SPEED;
1161                                                 if ( diff < TARGET_WARPOUT_MATCH_PERCENT )      {
1162                                                         gameseq_post_event( GS_EVENT_PLAYER_WARPOUT_DONE_STAGE1 );
1163                                                 }
1164                                         }
1165                                 }
1166                         }
1167                         break;
1168                 }
1169         }
1170
1171         // the ships maximum velocity now depends on the energy flowing to engines
1172         if(objp->type != OBJ_OBSERVER){
1173                 objp->phys_info.max_vel.z = Ships[objp->instance].current_max_speed;
1174         } 
1175         if(Player_obj->type == OBJ_SHIP){       
1176                 // only read player control info if player ship is not dead
1177                 if ( !(Ships[Player_obj->instance].flags & SF_DYING) ) {
1178                         vector wash_rot;
1179                         if ((Ships[objp->instance].wash_intensity > 0) && !((Player->control_mode == PCM_WARPOUT_STAGE1) || (Player->control_mode == PCM_WARPOUT_STAGE2) || (Player->control_mode == PCM_WARPOUT_STAGE3)) ) {
1180                                 float intensity = 0.3f * min(Ships[objp->instance].wash_intensity, 1.0f);
1181                                 vm_vec_copy_scale(&wash_rot, &Ships[objp->instance].wash_rot_axis, intensity);
1182                                 physics_read_flying_controls( &objp->orient, &objp->phys_info, &(Player->ci), flFrametime, &wash_rot);
1183                         } else {
1184                                 physics_read_flying_controls( &objp->orient, &objp->phys_info, &(Player->ci), flFrametime);
1185                         }
1186                 }
1187         } else if(Player_obj->type == OBJ_OBSERVER){
1188                 physics_read_flying_controls(&objp->orient,&objp->phys_info,&(Player->ci), flFrametime);
1189         }
1190 }
1191
1192 void player_controls_init()
1193 {
1194         static int initted = 0;
1195
1196         if (initted)
1197                 return;
1198
1199         initted = 1;
1200         physics_init( &Descent_physics );
1201         Descent_physics.flags |= PF_ACCELERATES | PF_SLIDE_ENABLED;
1202
1203         Viewer_slew_angles_delta.p = 0.0f;
1204         Viewer_slew_angles_delta.b = 0.0f;
1205         Viewer_slew_angles_delta.h = 0.0f;
1206 }
1207
1208 // Clear current speed matching and auto-speed matching flags
1209 void player_clear_speed_matching()
1210 {
1211         if ( !Player ) {
1212                 Int3(); // why is Player NULL?
1213                 return;
1214         }
1215
1216         Player->flags &= ~PLAYER_FLAGS_MATCH_TARGET;
1217         Player->flags &= ~PLAYER_FLAGS_AUTO_MATCH_SPEED;
1218 }
1219
1220 // function which computes the forward_thrust_time needed for the player ship to match
1221 // velocities with the currently selected target
1222 // input:       no_target_text  => default parm (NULL), used to override HUD output when no target exists
1223 //                              match_off_text  =>      default parm (NULL), used to overide HUD output when matching toggled off
1224 //                              match_on_text   =>      default parm (NULL), used to overide HUD output when matching toggled on
1225 void player_match_target_speed(char *no_target_text, char *match_off_text, char *match_on_text)
1226 {
1227         if ( Objects[Player_ai->target_objnum].type != OBJ_SHIP ) {
1228                 return;
1229         }
1230
1231         // multiplayer observers can't match target speed
1232         if((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && ((Net_player->flags & NETINFO_FLAG_OBSERVER) || (Player_obj->type == OBJ_OBSERVER)) ){
1233                 return;
1234         }
1235
1236         if ( Player_ai->target_objnum == -1) {
1237                 if ( no_target_text ) {
1238                         if ( no_target_text[0] ) {
1239                                 HUD_sourced_printf(HUD_SOURCE_HIDDEN, no_target_text );
1240                         }
1241                 } else {
1242 //                      HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("No currently selected target.",-1) );
1243                 }
1244                 return;
1245         }
1246
1247         if ( Player->flags & PLAYER_FLAGS_MATCH_TARGET ) {
1248                 Player->flags &= ~PLAYER_FLAGS_MATCH_TARGET;
1249                 if ( match_off_text ) {
1250                         if ( match_off_text[0] ) {
1251                                 HUD_sourced_printf(HUD_SOURCE_HIDDEN, match_off_text );
1252                         }
1253                 } else {
1254 //                      HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("No longer matching speed with current target.",-1) );
1255                 }
1256         } else {
1257                 int can_match=0;
1258
1259                 if ( Objects[Player_ai->target_objnum].phys_info.speed > MATCH_SPEED_THRESHOLD ) {
1260                         can_match=1;
1261                 } else {
1262                         // account for case of matching speed with docked ship 
1263                         ai_info *aip;
1264                         aip = &Ai_info[Ships[Objects[Player_ai->target_objnum].instance].ai_index];
1265                         if ( aip->ai_flags & AIF_DOCKED ) {
1266                                 Assert( aip->dock_objnum != -1 );
1267                                 if ( Objects[aip->dock_objnum].phys_info.fspeed > MATCH_SPEED_THRESHOLD ) {
1268                                         can_match=1;
1269                                 }
1270                         }
1271                 }
1272
1273                 if ( can_match ) {
1274                         Player->flags |= PLAYER_FLAGS_MATCH_TARGET;
1275                         if ( match_on_text ) {
1276                                 if ( match_on_text[0] ) {
1277                                         HUD_sourced_printf(HUD_SOURCE_HIDDEN, match_on_text );
1278                                 }
1279                         } else {
1280 //                              HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("Matching speed with current target.",-1) );
1281                         }
1282                 }
1283         }
1284 }
1285
1286
1287 //#ifndef NDEBUG
1288
1289 // toggle_player_object toggles between the player objects (i.e. the ship they are currently flying)
1290 // and a descent style ship.
1291
1292 int use_descent = 0;
1293 LOCAL physics_info phys_save;
1294
1295 void toggle_player_object()
1296 {
1297         if ( use_descent ) {
1298                 memcpy( &Player_obj->phys_info, &phys_save, sizeof(physics_info) );
1299         } else {
1300                 memcpy( &phys_save, &Player_obj->phys_info, sizeof(physics_info) );
1301                 memcpy( &Player_obj->phys_info, &Descent_physics, sizeof(physics_info) );
1302         }
1303         use_descent = !use_descent;
1304
1305         HUD_sourced_printf(HUD_SOURCE_HIDDEN, NOX("Using %s style physics for player ship."), use_descent ? NOX("DESCENT") : NOX("FreeSpace"));
1306 }
1307
1308 //#endif                // ifndef NDEBUG
1309
1310 // Init the data required for determining whether 'all alone' message should play
1311 void player_init_all_alone_msg()
1312 {
1313         ship_obj        *so;
1314         object  *objp;
1315
1316         Player->check_for_all_alone_msg=timestamp(0);
1317
1318         // See if there are any friendly ships present, if so return without preventing msg
1319         for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1320                 objp = &Objects[so->objnum];
1321                 if ( objp == Player_obj ) {
1322                         continue;
1323                 }
1324
1325                 if ( Ships[objp->instance].team == Player_ship->team ) {
1326                         if ( !(Ship_info[Ships[objp->instance].ship_info_index].flags & SIF_HARMLESS) ) {
1327                                 return;
1328                         }
1329                 }
1330         }
1331
1332         // There must be no friendly ships present, so prevent the 'all alone' message from ever playing
1333         Player->flags |= PLAYER_FLAGS_NO_CHECK_ALL_ALONE_MSG;
1334 }
1335
1336 // Called when a new pilot is created
1337 void player_set_pilot_defaults(player *p)
1338 {
1339         // Enable auto-targeting by default for all new pilots
1340         p->flags |= PLAYER_FLAGS_AUTO_TARGETING;
1341         p->save_flags |= PLAYER_FLAGS_AUTO_TARGETING;
1342
1343         p->auto_advance = 1;
1344 }
1345
1346 // Store some player preferences to Player->save_flags
1347 void player_save_target_and_weapon_link_prefs()
1348 {
1349         Player->save_flags = 0;
1350         if ( Player->flags & PLAYER_FLAGS_AUTO_TARGETING ) {
1351                 Player->save_flags |= PLAYER_FLAGS_AUTO_TARGETING;
1352         }
1353
1354
1355         if ( Player->flags & PLAYER_FLAGS_AUTO_MATCH_SPEED ) {
1356                 // multiplayer observers can't match target speed
1357                 if(!((Game_mode & GM_MULTIPLAYER) && (Net_player != NULL) && ((Net_player->flags & NETINFO_FLAG_OBSERVER) || (Player_obj->type == OBJ_OBSERVER))) ){                            
1358                         Player->save_flags |= PLAYER_FLAGS_AUTO_MATCH_SPEED;
1359                 }               
1360         }
1361
1362         // if we're in multiplayer mode don't do this because we will desync ourselves with the server
1363         if(!(Game_mode & GM_MULTIPLAYER)){
1364                 if ( Player_ship->flags & SF_PRIMARY_LINKED ) {
1365                         Player->save_flags |= PLAYER_FLAGS_LINK_PRIMARY;
1366                 } else {
1367                         Player->flags &= ~PLAYER_FLAGS_LINK_PRIMARY;
1368                 }
1369                 if ( Player_ship->flags & SF_SECONDARY_DUAL_FIRE ) {
1370                         Player->save_flags |= PLAYER_FLAGS_LINK_SECONDARY;
1371                 } else {
1372                         Player->flags &= ~PLAYER_FLAGS_LINK_SECONDARY;
1373                 }
1374         }
1375 }
1376
1377 // Store some player preferences to Player->save_flags
1378 void player_restore_target_and_weapon_link_prefs()
1379 {
1380         //      Don't restores the save flags in training, as we must ensure certain things are off, such as speed matching.
1381         if ( !(The_mission.game_type & MISSION_TYPE_TRAINING )) {
1382                 Player->flags |= Player->save_flags;
1383         }
1384
1385         if ( Player->flags & PLAYER_FLAGS_LINK_PRIMARY ) {
1386                 if ( Player_ship->weapons.num_primary_banks > 1 ) {
1387                         Player_ship->flags |= SF_PRIMARY_LINKED;
1388                 }
1389         }
1390
1391         if ( Player->flags & PLAYER_FLAGS_LINK_SECONDARY ) {
1392                 Player_ship->flags |= SF_SECONDARY_DUAL_FIRE;
1393         }
1394 }
1395
1396 // initialize player statistics on a per mission basis
1397 void player_level_init()
1398 {       
1399         Player->flags = PLAYER_FLAGS_STRUCTURE_IN_USE;                  // reset the player flags
1400         Player->flags |= Player->save_flags;
1401
1402         memset(&(Player->ci), 0, sizeof(control_info) );                // set the controls to 0
1403
1404         Viewer_slew_angles.p = 0.0f;    Viewer_slew_angles.b = 0.0f;    Viewer_slew_angles.h = 0.0f;
1405         Viewer_external_info.angles.p = 0.0f;
1406         Viewer_external_info.angles.b = 0.0f;
1407         Viewer_external_info.angles.h = 0.0f;
1408         Viewer_external_info.distance = 0.0f;
1409
1410         Viewer_mode = 0;
1411  
1412         Player_obj = NULL;
1413         Player_ship = NULL;
1414         Player_ai = NULL;
1415         
1416         //      Init variables for friendly fire monitoring.
1417         Player->friendly_last_hit_time = 0;
1418         Player->friendly_hits = 0;
1419         Player->friendly_damage = 0.0f;
1420         Player->last_warning_message_time = 0;
1421
1422         Player->control_mode = PCM_NORMAL;
1423
1424         Player->allow_warn_timestamp = 1;               // init timestamp that is used for managing attack warnings sent to player
1425         Player->check_warn_timestamp = 1;
1426         Player->warn_count = 0;                                         // number of attack warnings player has received this mission
1427
1428         Player->distance_warning_count = 0;             // Number of warning too far from origin
1429         Player->distance_warning_time = 0;              // Time at which last warning was given
1430
1431         Player->praise_count = 0;                                       // number of praises player has received this mission
1432         Player->allow_praise_timestamp = 1;             // timestamp until next praise is allowed
1433         Player->praise_delay_timestamp = 0;             // timstamp used to delay praises given to the player
1434
1435         Player->ask_help_count = 0;                             // number of times player has been asked for help by wingmen
1436         Player->allow_ask_help_timestamp = 1;   // timestamp until next ask_help is allowed
1437
1438         Player->scream_count = 0;                                       // number of times player has heard wingman screams this mission
1439         Player->allow_scream_timestamp = 1;             // timestamp until next wingman scream is allowed
1440
1441         Player->request_repair_timestamp = 1;   // timestamp until next 'requesting repair sir' message can be played
1442
1443         Player->repair_sound_loop = -1;
1444         Player->cargo_scan_loop = -1;
1445         Player->cargo_inspect_time = 0;                 // time that current target's cargo has been inspected for
1446
1447         Player->target_is_dying = -1;                           // The player target is dying, set to -1 if no target
1448         Player->current_target_sx = -1;                 // Screen x-pos of current target (or subsystem if applicable)
1449         Player->current_target_sy = -1;                 // Screen y-pos of current target (or subsystem if applicable)
1450         Player->target_in_lock_cone = -1;               // Is the current target in secondary weapon lock cone?
1451         Player->locking_subsys=NULL;                            // Subsystem pointer that missile lock is trying to seek
1452         Player->locking_on_center=0;                            // boolean, whether missile lock is trying for center of ship or not
1453         Player->locking_subsys_parent=-1;
1454
1455         Player->killer_objtype=-1;                                      // type of object that killed player
1456         Player->killer_weapon_index;                            // weapon used to kill player (if applicable)
1457         Player->killer_parent_name[0]=0;                        // name of parent object that killed the player
1458
1459         Player_all_alone_msg_inited=0;
1460         Player->flags &= ~PLAYER_FLAGS_NO_CHECK_ALL_ALONE_MSG;
1461
1462         // Player->insignia_bitmap = -1;
1463
1464         Joystick_last_reading = -1;                             // Make the joystick read right away.
1465 }
1466
1467 // player_init() initializes global veriables once a game -- needed because of mallocing that
1468 // goes on in structures in the player file
1469 void player_init()
1470 {
1471         Player_num = 0;
1472         Player = &Players[Player_num];
1473         Player->num_campaigns = 0;
1474         Player->flags |= PLAYER_FLAGS_STRUCTURE_IN_USE;
1475         Player->failures_this_session = 0;
1476         Player->show_skip_popup = (ubyte) 1;
1477 }
1478
1479 // stop any looping sounds associated with the Player, called from game_stop_looped_sounds().
1480 void player_stop_looped_sounds()
1481 {
1482         Assert(Player);
1483         if ( Player->repair_sound_loop > -1 )   {
1484                 snd_stop(Player->repair_sound_loop);
1485                 Player->repair_sound_loop = -1;
1486         }
1487         if ( Player->cargo_scan_loop > -1 )     {
1488                 snd_stop(Player->cargo_scan_loop);
1489                 Player->cargo_scan_loop = -1;
1490         }
1491 }
1492
1493 // Start the repair sound if it hasn't already been started.  Called when a player ship is being
1494 // repaired by a support ship
1495 void player_maybe_start_repair_sound()
1496 {
1497         Assert(Player);
1498         if ( Player->repair_sound_loop == -1 ) {
1499                 Player->repair_sound_loop = snd_play_looping( &Snds[SND_SHIP_REPAIR] );
1500         }
1501 }
1502
1503 // stop the player repair sound if it is already playing
1504 void player_stop_repair_sound()
1505 {
1506         Assert(Player);
1507         if ( Player->repair_sound_loop != -1 ) {
1508                 snd_stop(Player->repair_sound_loop);
1509                 Player->repair_sound_loop  = -1;
1510         }
1511 }
1512
1513 // start the cargo scanning sound if it hasn't already been started
1514 void player_maybe_start_cargo_scan_sound()
1515 {
1516         Assert(Player);
1517         if ( Player->cargo_scan_loop == -1 ) {
1518                 Player->cargo_scan_loop = snd_play_looping( &Snds[SND_CARGO_SCAN] );
1519         }
1520 }
1521
1522 // stop the player repair sound if it is already playing
1523 void player_stop_cargo_scan_sound()
1524 {
1525         Assert(Player);
1526         if ( Player->cargo_scan_loop != -1 ) {
1527                 snd_stop(Player->cargo_scan_loop);
1528                 Player->cargo_scan_loop  = -1;
1529         }
1530 }
1531
1532 // See if there is a praise message to deliver to the player.  We want to delay the praise messages
1533 // a bit, to make them more realistic
1534 //
1535 // exit:        1       =>      a praise message was delivered to the player, or a praise is pending
1536 //                      0       => no praise is pending
1537
1538 #define PLAYER_ALLOW_PRAISE_INTERVAL    60000           // minimum time between praises
1539
1540 int player_process_pending_praise()
1541 {
1542         // in multiplayer, never praise
1543         if(Game_mode & GM_MULTIPLAYER){
1544                 return 0;
1545         }
1546
1547         if ( timestamp_elapsed(Player->praise_delay_timestamp) ) {
1548                 int ship_index;
1549
1550                 Player->praise_delay_timestamp = 0;
1551                 ship_index = ship_get_random_player_wing_ship( SHIP_GET_NO_PLAYERS, 1000.0f );
1552                 if ( ship_index >= 0 ) {
1553                         // Only praise if above 50% integrity
1554                         if ( Objects[Ships[ship_index].objnum].hull_strength/Ship_info[Ships[ship_index].ship_info_index].initial_hull_strength > 0.5f ) {
1555                                 message_send_builtin_to_player(MESSAGE_PRAISE, &Ships[ship_index], MESSAGE_PRIORITY_HIGH, MESSAGE_TIME_SOON, 0, 0, -1, -1);
1556                                 Player->allow_praise_timestamp = timestamp(PLAYER_ALLOW_PRAISE_INTERVAL*(Game_skill_level+1) );
1557                                 Player->allow_scream_timestamp = timestamp(20000);              // prevent death scream following praise
1558                                 Player->praise_count++;
1559                                 return 1;
1560                         }
1561                 }
1562         }
1563
1564         if ( Player->praise_delay_timestamp == 0 ) {
1565                 return 0;
1566         }
1567
1568         return 1;
1569 }
1570
1571 int player_inspect_cap_subsys_cargo(float frametime, char *outstr);
1572 // See if the player should be inspecting cargo, and update progress.
1573 // input:       frametime       =>              time since last frame in seconds
1574 // input:       outstr          =>              (output parm) holds string that HUD should display
1575 //
1576 //      exit:           1                               =>              player should display outstr on HUD
1577 //                              0                               =>              don't display cargo on HUD
1578 int player_inspect_cargo(float frametime, char *outstr)
1579 {
1580         object          *cargo_objp;
1581         ship                    *cargo_sp;
1582         ship_info       *cargo_sip;
1583         vector          vec_to_cargo;
1584         float                   dot;
1585
1586         outstr[0] = 0;
1587
1588         if ( Player_ai->target_objnum < 0 ) {
1589                 return 0;
1590         }
1591
1592         cargo_objp = &Objects[Player_ai->target_objnum];
1593         Assert(cargo_objp->type == OBJ_SHIP);
1594         cargo_sp = &Ships[cargo_objp->instance];
1595         cargo_sip = &Ship_info[cargo_sp->ship_info_index];
1596
1597         if (cargo_sip->flags & SIF_HUGE_SHIP) {
1598                 return player_inspect_cap_subsys_cargo(frametime, outstr);
1599         }
1600
1601         // check if target is ship class that can be inspected
1602         // MWA -- 1/27/98 -- added fighters/bombers to this list.  For multiplayer, we
1603         // want to show callsign of player
1604
1605         // scannable cargo behaves differently.  Scannable cargo is either "scanned" or "not scanned".  This flag
1606         // can be set on any ship.  Any ship with this set won't have "normal" cargo behavior
1607         if ( !(cargo_sp->flags & SF_SCANNABLE) ) {
1608                 if ( Game_mode & GM_NORMAL ) {
1609                         if ( !(cargo_sip->flags & (SIF_CARGO|SIF_TRANSPORT)) ) {
1610                                 return 0;
1611                         }
1612                 } else {
1613                         if ( !(cargo_sip->flags & (SIF_CARGO|SIF_TRANSPORT|SIF_FIGHTER|SIF_BOMBER)) ) {
1614                                 return 0;
1615                         }
1616                 }
1617
1618                 // won't show callsign information for single player games
1619                 if ( (Game_mode & GM_MULTIPLAYER) && !((cargo_sip->flags & (SIF_FIGHTER|SIF_BOMBER)) && (cargo_objp->flags & OF_PLAYER_SHIP)) )
1620                         return 0;
1621         }
1622
1623         // if cargo is already revealed
1624         if ( cargo_sp->flags & SF_CARGO_REVEALED ) {
1625                 if ( !(cargo_sp->flags & SF_SCANNABLE) ) {
1626                         char *cargo_name;
1627                         cargo_name = Cargo_names[cargo_sp->cargo1 & CARGO_INDEX_MASK];
1628                         Assert ( cargo_name );
1629
1630                         if ( cargo_sip->flags & (SIF_CARGO|SIF_TRANSPORT) ) {
1631                                 if ( cargo_name[0] == '#' )
1632                                         sprintf(outstr, XSTR( "passengers:\n   %s", 83), cargo_name+1 );
1633                                 else
1634                                         sprintf(outstr,XSTR( "cargo: %s", 84), cargo_name );
1635                         } else {
1636                                 int pn;
1637
1638                                 Assert( Game_mode & GM_MULTIPLAYER );
1639
1640                                 // get a player num from the object, then get a callsign from the player structure.
1641                                 pn = multi_find_player_by_object( cargo_objp );
1642                                 // Assert( pn != -1 );
1643                                 if(pn == -1){
1644                                         strcpy(outstr, "");
1645                                 } else {
1646                                         sprintf(outstr, "%s", Net_players[pn].player->short_callsign );
1647                                 }
1648                         }
1649                 } else {
1650                         sprintf(outstr, XSTR( "Scanned", 85) );
1651                 }
1652
1653                 // always bash cargo_inspect_time to 0 since AI ships can reveal cargo that we
1654                 // are in the process of scanning
1655                 Player->cargo_inspect_time = 0;
1656
1657                 return 1;
1658         }
1659
1660         // see if player is within inspection range
1661         if ( Player_ai->current_target_distance < max(CARGO_REVEAL_MIN_DIST, (cargo_objp->radius+CARGO_RADIUS_DELTA)) ) {
1662
1663                 // check if player is facing cargo, do not proceed with inspection if not
1664                 vm_vec_normalized_dir(&vec_to_cargo, &cargo_objp->pos, &Player_obj->pos);
1665                 dot = vm_vec_dot(&vec_to_cargo, &Player_obj->orient.fvec);
1666                 if ( dot < CARGO_MIN_DOT_TO_REVEAL ) {
1667                         if ( !(cargo_sp->flags & SF_SCANNABLE) )
1668                                 sprintf(outstr,XSTR( "cargo: <unknown>", 86));
1669                         else
1670                                 sprintf(outstr,XSTR( "not scanned", 87));
1671                         hud_targetbox_end_flash(TBOX_FLASH_CARGO);
1672                         Player->cargo_inspect_time = 0;
1673                         return 1;
1674                 }
1675
1676                 // player is facing the cargo, and withing range, so proceed with inspection
1677                 if ( hud_sensors_ok(Player_ship, 0) ) {
1678                         Player->cargo_inspect_time += fl2i(frametime*1000+0.5f);
1679                 }
1680
1681                 if ( !(cargo_sp->flags & SF_SCANNABLE) )
1682                         sprintf(outstr,XSTR( "cargo: inspecting", 88));
1683                 else
1684                         sprintf(outstr,XSTR( "scanning", 89));
1685
1686                 if ( Player->cargo_inspect_time > cargo_sip->scan_time ) {
1687                         ship_do_cargo_revealed( cargo_sp );
1688                         snd_play( &Snds[SND_CARGO_REVEAL], 0.0f );
1689                         Player->cargo_inspect_time = 0;
1690                 }
1691         } else {
1692                 if ( !(cargo_sp->flags & SF_SCANNABLE) )
1693                         sprintf(outstr,XSTR( "cargo: <unknown>", 86));
1694                 else
1695                         sprintf(outstr,XSTR( "not scanned", 87));
1696         }
1697
1698         return 1;
1699 }
1700
1701 //      exit:           1                               =>              player should display outstr on HUD
1702 //                              0                               =>              don't display cargo on HUD
1703 int player_inspect_cap_subsys_cargo(float frametime, char *outstr)
1704 {
1705         object          *cargo_objp;
1706         ship                    *cargo_sp;
1707         ship_info       *cargo_sip;
1708         vector          vec_to_cargo;
1709         float                   dot;
1710         ship_subsys     *subsys;
1711
1712         outstr[0] = 0;
1713         subsys = Player_ai->targeted_subsys;
1714
1715         if ( subsys == NULL ) {
1716                 return 0;
1717         } 
1718
1719         cargo_objp = &Objects[Player_ai->target_objnum];
1720         Assert(cargo_objp->type == OBJ_SHIP);
1721         cargo_sp = &Ships[cargo_objp->instance];
1722         cargo_sip = &Ship_info[cargo_sp->ship_info_index];
1723
1724         Assert(cargo_sip->flags & SIF_HUGE_SHIP);
1725
1726         if ( !(cargo_sp->flags & SF_SCANNABLE) ) {
1727                 return 0;
1728         }
1729
1730         // dont scan cargo on turrets, radar, etc.  only the majors: fighterbay, sensor, engines, weapons, nav, comm
1731         if (!valid_cap_subsys_cargo_list(subsys->system_info->name)) {
1732                 return 0;
1733         }
1734
1735         // if cargo is already revealed
1736         if ( subsys->subsys_cargo_revealed ) {
1737                 char *cargo_name;
1738                 if (subsys->subsys_cargo_name == -1) {
1739                         cargo_name = XSTR("Nothing", 1493);
1740                 } else {
1741                         cargo_name = Cargo_names[subsys->subsys_cargo_name];
1742                 }
1743                 Assert ( cargo_name );
1744
1745                 sprintf(outstr,XSTR( "cargo: %s", 84), cargo_name );
1746         
1747                 // always bash cargo_inspect_time to 0 since AI ships can reveal cargo that we
1748                 // are in the process of scanning
1749                 Player->cargo_inspect_time = 0;
1750
1751                 return 1;
1752         }
1753
1754         // see if player is within inspection range [ok for subsys]
1755         vector  subsys_pos;
1756         float           subsys_rad;
1757         int             subsys_in_view, x, y;
1758
1759         get_subsystem_world_pos(cargo_objp, Player_ai->targeted_subsys, &subsys_pos);
1760         subsys_rad = subsys->system_info->radius;
1761
1762         if ( Player_ai->current_target_distance < max(CAP_CARGO_REVEAL_MIN_DIST, (subsys_rad + CAPITAL_CARGO_RADIUS_DELTA)) ) {
1763
1764                 // check if player is facing cargo, do not proceed with inspection if not
1765                 vm_vec_normalized_dir(&vec_to_cargo, &subsys_pos, &Player_obj->pos);
1766                 dot = vm_vec_dot(&vec_to_cargo, &Player_obj->orient.fvec);
1767                 int hud_targetbox_subsystem_in_view(object *target_objp, int *sx, int *sy);
1768                 subsys_in_view = hud_targetbox_subsystem_in_view(cargo_objp, &x, &y);
1769
1770                 if ( (dot < CARGO_MIN_DOT_TO_REVEAL) || (!subsys_in_view) ) {
1771                         sprintf(outstr,XSTR( "cargo: <unknown>", 86));
1772                         hud_targetbox_end_flash(TBOX_FLASH_CARGO);
1773                         Player->cargo_inspect_time = 0;
1774                         return 1;
1775                 }
1776
1777                 // player is facing the cargo, and withing range, so proceed with inspection
1778                 if ( hud_sensors_ok(Player_ship, 0) ) {
1779                         Player->cargo_inspect_time += fl2i(frametime*1000+0.5f);
1780                 }
1781
1782                 sprintf(outstr,XSTR( "cargo: inspecting", 88));
1783
1784                 if ( Player->cargo_inspect_time > cargo_sip->scan_time ) {
1785                         void ship_do_cap_subsys_cargo_revealed( ship *shipp, ship_subsys *subsys, int from_network );
1786                         ship_do_cap_subsys_cargo_revealed( cargo_sp, subsys, 0);
1787                         snd_play( &Snds[SND_CARGO_REVEAL], 0.0f );
1788                         Player->cargo_inspect_time = 0;
1789                 }
1790         } else {
1791                 sprintf(outstr,XSTR( "cargo: <unknown>", 86));
1792         }
1793
1794         return 1;
1795 }
1796
1797
1798 // get the maximum weapon range for the player (of both primary and secondary)
1799 float   player_farthest_weapon_range()
1800 {
1801         float prange,srange;
1802
1803         hud_get_best_primary_bank(&prange);
1804         srange=ship_get_secondary_weapon_range(Player_ship);
1805
1806         return max(prange,srange);
1807 }
1808
1809 // Determine text name for the weapon that killed the player.
1810 // input:       weapon_info_index       =>              weapon type that killed the player (can be -1 if no weapon involved)
1811 //                              killer_species          =>              species of ship that fired weapon
1812 //                              weapon_name                     =>              output parameter... stores weapon name generated in this function       
1813 void player_generate_killer_weapon_name(int weapon_info_index, int killer_species, char *weapon_name)
1814 {
1815         if ( weapon_info_index < 0 ) {
1816                 return;
1817         }
1818
1819         #ifndef NDEBUG
1820         if ( Show_killer_weapon ) {
1821                 killer_species = SPECIES_TERRAN;
1822         }
1823         #endif
1824
1825         switch ( killer_species ) {
1826         case SPECIES_TERRAN:
1827                 strcpy(weapon_name, Weapon_info[weapon_info_index].name);
1828                 break;
1829         default:
1830                 if ( Weapon_info[weapon_info_index].subtype == WP_MISSILE ) {
1831                         strcpy(weapon_name, XSTR( "missile", 90));
1832                 } else {
1833                         strcpy(weapon_name, XSTR( "laser fire", 91));
1834                 }
1835                 break;
1836         }
1837 }
1838
1839 // function to generate the text for death of a player given the information stored in the player object.
1840 // a pointer to the text is returned
1841 char *player_generate_death_text( player *player_p, char *death_text )
1842 {
1843         char weapon_name[NAME_LENGTH];
1844         weapon_name[0] = 0;     
1845
1846         player_generate_killer_weapon_name(player_p->killer_weapon_index, player_p->killer_species, weapon_name);
1847
1848         switch ( player_p->killer_objtype ) {
1849         case OBJ_SHOCKWAVE:
1850                 if ( weapon_name[0] ) {
1851 //                      sprintf(death_text, XSTR("%s was killed by a shockwave from a %s, fired by %s",-1), player_p->callsign, weapon_name, player_p->killer_parent_name);
1852                         sprintf(death_text, XSTR( "%s was killed by a missile shockwave", 92), player_p->callsign);
1853                 } else {
1854                         sprintf(death_text, XSTR( "%s was killed by a shockwave from %s exploding", 93), player_p->callsign, player_p->killer_parent_name);
1855                 }
1856                 break;
1857         case OBJ_WEAPON:
1858                 Assert(weapon_name[0]);
1859
1860                 // is this from a friendly ship?
1861                 int ship_index;
1862                 ship_index = ship_name_lookup(player_p->killer_parent_name, 1);
1863                 if((ship_index >= 0) && (Player_ship != NULL) && (Player_ship->team == Ships[ship_index].team)){
1864                         sprintf(death_text, XSTR( "%s was killed by friendly fire from %s", 1338), player_p->callsign, player_p->killer_parent_name);
1865                 } else {
1866                         sprintf(death_text, XSTR( "%s was killed by %s", 94), player_p->callsign, player_p->killer_parent_name);
1867                 }
1868                 break;
1869         case OBJ_SHIP:
1870                 if ( player_p->flags & PLAYER_FLAGS_KILLED_BY_EXPLOSION ) {
1871                         sprintf(death_text, XSTR( "%s was killed by a blast from %s exploding", 95), player_p->callsign, player_p->killer_parent_name);
1872                 } else if (player_p->flags & PLAYER_FLAGS_KILLED_BY_ENGINE_WASH) {
1873                         sprintf(death_text, XSTR( "%s was killed by engine wash from %s", 1494), player_p->callsign, player_p->killer_parent_name);
1874                 } else {
1875                         sprintf(death_text, XSTR( "%s was killed by a collision with %s", 96), player_p->callsign, player_p->killer_parent_name);
1876                 }
1877                 break;
1878         case OBJ_DEBRIS:
1879                 sprintf(death_text, XSTR( "%s was killed by a collision with debris", 97), player_p->callsign);
1880                 break;
1881         case OBJ_ASTEROID:
1882                 sprintf(death_text, XSTR( "%s was killed by a collision with an asteroid", 98), player_p->callsign);
1883                 break;
1884         case OBJ_BEAM:
1885                 if(strlen(player_p->killer_parent_name) <= 0){                  
1886                         Int3();
1887                         sprintf(death_text, XSTR( "%s was killed by a beam from an unknown source", 1081), player_p->callsign);
1888                 } else {                                        
1889                         // is this from a friendly ship?
1890                         int ship_index;
1891                         ship_index = ship_name_lookup(player_p->killer_parent_name, 1);
1892                         if((ship_index >= 0) && (Player_ship != NULL) && (Player_ship->team == Ships[ship_index].team)){
1893                                 sprintf(death_text, XSTR( "%s was destroyed by friendly beam fire from %s", 1339), player_p->callsign, player_p->killer_parent_name);
1894                         } else {
1895                                 sprintf(death_text, XSTR( "%s was destroyed by a beam from %s", 1082), player_p->callsign, player_p->killer_parent_name);
1896                         }                       
1897                 }
1898                 break;
1899         default:
1900                 sprintf(death_text, XSTR( "%s was killed", 99), player_p->callsign);
1901                 break;
1902         }
1903
1904         return death_text;
1905 }
1906
1907 // display what/who killed the player
1908 void player_show_death_message()
1909 {
1910         char death_text[256];
1911
1912         // check if player killed self
1913         if ( Player->flags & PLAYER_KILLED_SELF ) {
1914                 // reasons he killed himself
1915                 if(Player->flags & PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE){
1916                         sprintf(death_text, XSTR( "You have killed yourself with a shockwave from your own weapon", 1421));                     
1917                 }
1918                 else if(Player->flags & PLAYER_FLAGS_KILLED_SELF_MISSILES){
1919                         sprintf(death_text, XSTR( "You have killed yourself with your own missiles", 1422));                    
1920                 } else {
1921                         sprintf(death_text, XSTR( "You have killed yourself", 100));
1922                 }
1923
1924                 Player->flags &= ~(PLAYER_FLAGS_KILLED_SELF_MISSILES | PLAYER_FLAGS_KILLED_SELF_SHOCKWAVE);
1925         } else {
1926                 player_generate_death_text( Player, death_text );
1927         }
1928
1929         HUD_fixed_printf(30.0f, death_text);
1930 }
1931
1932
1933 extern void ai_fire_from_turret(ship *shipp, ship_subsys *ss, int parent_objnum);
1934
1935 // maybe fire a turret that is on a player ship (single or multi)
1936 void player_maybe_fire_turret(object *objp)
1937 {
1938         model_subsystem *psub;
1939         ship_subsys             *pss;
1940
1941         ship                    *shipp = &Ships[objp->instance];
1942         ai_info                 *aip = &Ai_info[shipp->ai_index];
1943         ship_info               *sip = &Ship_info[shipp->ship_info_index];
1944
1945         // do a quick out if this isn't a bomber
1946         if ( !(sip->flags & SIF_BOMBER) ) {
1947                 return;
1948         }
1949
1950         if (aip->ai_flags & (AIF_AWAITING_REPAIR | AIF_BEING_REPAIRED)) {
1951                 if (aip->dock_objnum > -1) {
1952                         if (vm_vec_dist_quick(&objp->pos, &Objects[aip->dock_objnum].pos) < (objp->radius + Objects[aip->dock_objnum].radius) * 1.25f)
1953                                 return;
1954                 }
1955         }
1956
1957         // See if there are any turrets on the ship, if so see if they should fire
1958         for ( pss = GET_FIRST(&shipp->subsys_list); pss !=END_OF_LIST(&shipp->subsys_list); pss = GET_NEXT(pss) ) {
1959
1960                 if ( pss->current_hits <= 0.0f ) 
1961                         continue;
1962
1963                 psub = pss->system_info;
1964
1965                 if ( psub->type == SUBSYSTEM_TURRET ) {
1966                         if ( psub->turret_num_firing_points > 0 ) {
1967                                 ai_fire_from_turret(shipp, pss, OBJ_INDEX(objp));
1968                         }
1969                 }
1970         }
1971 }
1972
1973 void player_set_next_all_alone_msg_timestamp()
1974 {
1975         Player->check_for_all_alone_msg=timestamp(30000);
1976 }
1977
1978 // maybe play message from Terran Command 'You're all alone now Alpha 1'
1979 void player_maybe_play_all_alone_msg()
1980 {
1981         if ( Game_mode & GM_MULTIPLAYER ){
1982                 return;
1983         }
1984
1985         if ( !Player_all_alone_msg_inited ) {
1986                 player_init_all_alone_msg();
1987                 Player_all_alone_msg_inited=1;
1988                 return;
1989         }
1990
1991         if ( Player->flags & PLAYER_FLAGS_NO_CHECK_ALL_ALONE_MSG ) {
1992                 return;
1993         }
1994
1995         // only check every N seconds
1996         if ( !timestamp_elapsed(Player->check_for_all_alone_msg) ) {
1997                 return;
1998         }
1999
2000         player_set_next_all_alone_msg_timestamp();
2001         
2002         // at least one primary objective must be not complete (but not failed)
2003         if ( !mission_goals_incomplete(PRIMARY_GOAL) ) {
2004                 Player->flags |= PLAYER_FLAGS_NO_CHECK_ALL_ALONE_MSG;
2005                 return;
2006         }
2007
2008         // there must be no reinforcements available, hold off on message
2009         if ( (Player_ship != NULL) && hud_squadmsg_reinforcements_available(Player_ship->team) ) {
2010                 return;
2011         }
2012
2013         // there must be no ships present that are on the same team as the player
2014         ship_obj *so;
2015         object  *objp;
2016
2017         for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
2018                 objp = &Objects[so->objnum];
2019
2020                 if ( objp == Player_obj ) {
2021                         continue;
2022                 }
2023
2024                 if ( Ships[objp->instance].team == Player_ship->team ) {
2025                         if ( !(Ship_info[Ships[objp->instance].ship_info_index].flags & SIF_HARMLESS) ) {
2026                                 return;
2027                         }
2028                 }
2029         }
2030
2031         // met all the requirements, now only play 50% of the time :)
2032         if ( rand()&1 ) {
2033                 message_send_builtin_to_player(MESSAGE_ALL_ALONE, NULL, MESSAGE_PRIORITY_HIGH, MESSAGE_TIME_ANYTIME, 0, 0, -1, -1);
2034         }
2035         Player->flags |= PLAYER_FLAGS_NO_CHECK_ALL_ALONE_MSG;
2036
2037
2038
2039 void player_set_padlock_state()
2040 {
2041         // clear padlock views
2042         Viewer_mode &= ~(VM_PADLOCK_ANY);
2043
2044         if ( check_control(PADLOCK_UP) ) {
2045                 Viewer_mode |= VM_PADLOCK_UP;
2046                 return;
2047         }
2048
2049         if ( check_control(PADLOCK_DOWN) ) {
2050                 Viewer_mode |= VM_PADLOCK_REAR;
2051                 return;
2052         }
2053
2054         if ( check_control(PADLOCK_RIGHT) ) {
2055                 Viewer_mode |= VM_PADLOCK_RIGHT;
2056                 return;
2057         }
2058
2059         if ( check_control(PADLOCK_LEFT) ) {
2060                 Viewer_mode |= VM_PADLOCK_LEFT;
2061                 return;
2062         }
2063 }
2064
2065 void player_get_padlock_orient(matrix *eye_orient)
2066 {
2067         Assert(Viewer_mode & VM_PADLOCK_ANY);
2068
2069         matrix old_eye_orient;
2070         old_eye_orient = *eye_orient;
2071
2072         if ( Viewer_mode & VM_PADLOCK_UP ) {
2073                 eye_orient->fvec = old_eye_orient.uvec;
2074                 vm_vec_copy_scale( &eye_orient->uvec, &old_eye_orient.fvec, -1.0f );
2075         } else if ( Viewer_mode & VM_PADLOCK_REAR ) {
2076                 vm_vec_negate(&eye_orient->fvec);
2077                 vm_vec_negate(&eye_orient->rvec);
2078         } else if ( Viewer_mode & VM_PADLOCK_LEFT ) {
2079                 vm_vec_copy_scale( &eye_orient->fvec, &old_eye_orient.rvec, -1.0f );
2080                 eye_orient->rvec = old_eye_orient.fvec;
2081         } else if ( Viewer_mode & VM_PADLOCK_RIGHT ) {
2082                 eye_orient->fvec = old_eye_orient.rvec;
2083                 vm_vec_copy_scale( &eye_orient->rvec, &old_eye_orient.fvec, -1.0f );
2084         } else {
2085                 Int3();
2086         }
2087 }
2088
2089 void player_display_packlock_view()
2090 {
2091         int padlock_view_index=0;
2092
2093         if ( Viewer_mode & VM_PADLOCK_UP ) {
2094                 padlock_view_index = 0;
2095         } else if ( Viewer_mode & VM_PADLOCK_REAR ) {
2096                 padlock_view_index = 1;
2097         } else if ( Viewer_mode & VM_PADLOCK_LEFT ) {
2098                 padlock_view_index = 2;
2099         } else if ( Viewer_mode & VM_PADLOCK_RIGHT ) {
2100                 padlock_view_index = 3;
2101         } else {
2102                 Int3();
2103                 return;
2104         }
2105
2106         char    str[128];
2107
2108         if ( !(Viewer_mode & (VM_CHASE|VM_EXTERNAL|VM_SLEWED)) ) {
2109                 switch (padlock_view_index) {
2110                 case 0:
2111                         strcpy(str, XSTR( "top view", 101));    break;
2112                 case 1:
2113                         strcpy(str, XSTR( "rear view", 102));   break;
2114                 case 2:
2115                         strcpy(str, XSTR( "left view", 103));   break;
2116                 case 3:
2117                         strcpy(str, XSTR( "right view", 104));  break;
2118                         }
2119
2120                 HUD_fixed_printf(0.01f, str);
2121         }
2122 }
2123
2124 // get the player's eye position and orient
2125 // NOTE : this is mostly just copied from game_render_frame_setup()
2126 extern vector Dead_player_last_vel;
2127 extern vector Camera_pos;
2128 extern void compute_slew_matrix(matrix *orient, angles *a);
2129 #define MIN_DIST_TO_DEAD_CAMERA                 50.0f
2130 void player_get_eye(vector *eye_pos, matrix *eye_orient)
2131 {
2132         object *viewer_obj;
2133         vector eye_dir;
2134
2135         // if the player object is NULL, return
2136         if(Player_obj == NULL){
2137                 return;
2138         }
2139
2140         // standalone servers can bail here
2141         if(Game_mode & GM_STANDALONE_SERVER){
2142                 return;
2143         }
2144
2145         // if we're not in-mission, don't do this
2146         if(!(Game_mode & GM_IN_MISSION)){
2147                 return;
2148         }
2149
2150         Assert(eye_pos != NULL);
2151         Assert(eye_orient != NULL);
2152
2153         if (Game_mode & GM_DEAD) {
2154                 vector  vec_to_deader, view_pos;
2155                 float           dist;           
2156                 if (Player_ai->target_objnum != -1) {
2157                         int view_from_player = 1;
2158
2159                         if (Viewer_mode & VM_OTHER_SHIP) {
2160                                 //      View from target.
2161                                 viewer_obj = &Objects[Player_ai->target_objnum];
2162                                 if ( viewer_obj->type == OBJ_SHIP ) {
2163                                         ship_get_eye( eye_pos, eye_orient, viewer_obj );
2164                                         view_from_player = 0;
2165                                 }
2166                         }
2167
2168                         if ( view_from_player ) {
2169                                 //      View target from player ship.
2170                                 viewer_obj = NULL;
2171                                 *eye_pos = Player_obj->pos;
2172                                 vm_vec_normalized_dir(&eye_dir, &Objects[Player_ai->target_objnum].pos, eye_pos);
2173                                 vm_vector_2_matrix(eye_orient, &eye_dir, NULL, NULL);
2174                         }
2175                 } else {
2176                         dist = vm_vec_normalized_dir(&vec_to_deader, &Player_obj->pos, &Dead_camera_pos);
2177                         
2178                         if (dist < MIN_DIST_TO_DEAD_CAMERA){
2179                                 dist += flFrametime * 16.0f;
2180                         }
2181
2182                         vm_vec_scale(&vec_to_deader, -dist);
2183                         vm_vec_add(&Dead_camera_pos, &Player_obj->pos, &vec_to_deader);
2184                         
2185                         view_pos = Player_obj->pos;
2186
2187                         if (!(Game_mode & GM_DEAD_BLEW_UP)) {                                                           
2188                         } else if (Player_ai->target_objnum != -1) {
2189                                 view_pos = Objects[Player_ai->target_objnum].pos;
2190                         } else {
2191                                 //      Make camera follow explosion, but gradually slow down.
2192                                 vm_vec_scale_add2(&Player_obj->pos, &Dead_player_last_vel, flFrametime);
2193                                 view_pos = Player_obj->pos;                             
2194                         }
2195
2196                         *eye_pos = Dead_camera_pos;
2197
2198                         vm_vec_normalized_dir(&eye_dir, &Player_obj->pos, eye_pos);
2199
2200                         vm_vector_2_matrix(eye_orient, &eye_dir, NULL, NULL);
2201                         viewer_obj = NULL;
2202                 }
2203         } 
2204         
2205         //      If already blown up, these other modes can override.
2206         if (!(Game_mode & (GM_DEAD | GM_DEAD_BLEW_UP))) {
2207                 viewer_obj = Player_obj;
2208  
2209                 if (Viewer_mode & VM_OTHER_SHIP) {
2210                         if (Player_ai->target_objnum != -1){
2211                                 viewer_obj = &Objects[Player_ai->target_objnum];
2212                         } 
2213                 }
2214
2215                 if (Viewer_mode & VM_EXTERNAL) {
2216                         matrix  tm, tm2;
2217
2218                         vm_angles_2_matrix(&tm2, &Viewer_external_info.angles);
2219                         vm_matrix_x_matrix(&tm, &viewer_obj->orient, &tm2);
2220
2221                         vm_vec_scale_add(eye_pos, &viewer_obj->pos, &tm.fvec, 2.0f * viewer_obj->radius + Viewer_external_info.distance);
2222
2223                         vm_vec_sub(&eye_dir, &viewer_obj->pos, eye_pos);
2224                         vm_vec_normalize(&eye_dir);
2225                         vm_vector_2_matrix(eye_orient, &eye_dir, &viewer_obj->orient.uvec, NULL);
2226                         viewer_obj = NULL;
2227
2228                         //      Modify the orientation based on head orientation.
2229                         compute_slew_matrix(eye_orient, &Viewer_slew_angles);
2230                 } else if ( Viewer_mode & VM_CHASE ) {
2231                         vector  move_dir;
2232
2233                         if ( viewer_obj->phys_info.speed < 0.1 ){
2234                                 move_dir = viewer_obj->orient.fvec;
2235                         } else {
2236                                 move_dir = viewer_obj->phys_info.vel;
2237                                 vm_vec_normalize_safe(&move_dir);
2238                         }
2239
2240                         vm_vec_scale_add(eye_pos, &viewer_obj->pos, &move_dir, -3.0f * viewer_obj->radius - Viewer_chase_info.distance);
2241                         vm_vec_scale_add2(eye_pos, &viewer_obj->orient.uvec, 0.75f * viewer_obj->radius);
2242                         vm_vec_sub(&eye_dir, &viewer_obj->pos, eye_pos);
2243                         vm_vec_normalize(&eye_dir);
2244
2245                         // JAS: I added the following code because if you slew up using
2246                         // Descent-style physics, eye_dir and Viewer_obj->orient.uvec are
2247                         // equal, which causes a zero-length vector in the vm_vector_2_matrix
2248                         // call because the up and the forward vector are the same.   I fixed
2249                         // it by adding in a fraction of the right vector all the time to the
2250                         // up vector.
2251                         vector tmp_up = viewer_obj->orient.uvec;
2252                         vm_vec_scale_add2( &tmp_up, &viewer_obj->orient.rvec, 0.00001f );
2253
2254                         vm_vector_2_matrix(eye_orient, &eye_dir, &tmp_up, NULL);
2255                         viewer_obj = NULL;
2256
2257                         //      Modify the orientation based on head orientation.
2258                         compute_slew_matrix(eye_orient, &Viewer_slew_angles);
2259                 } else if ( Viewer_mode & VM_WARP_CHASE ) {
2260                         *eye_pos = Camera_pos;
2261
2262                         ship * shipp = &Ships[Player_obj->instance];
2263
2264                         vm_vec_sub(&eye_dir, &shipp->warp_effect_pos, eye_pos);
2265                         vm_vec_normalize(&eye_dir);
2266                         vm_vector_2_matrix(eye_orient, &eye_dir, &Player_obj->orient.uvec, NULL);
2267                         viewer_obj = NULL;
2268                 } else {
2269                         // get an eye position based upon the correct type of object
2270                         switch(viewer_obj->type){
2271                         case OBJ_SHIP:
2272                                 // make a call to get the eye point for the player object
2273                                 ship_get_eye( eye_pos, eye_orient, viewer_obj );
2274                                 break;
2275                         case OBJ_OBSERVER:
2276                                 // make a call to get the eye point for the player object
2277                                 observer_get_eye( eye_pos, eye_orient, viewer_obj );                            
2278                                 break;
2279                         default :
2280                                 Int3();
2281                         }                       
2282                 }
2283         }
2284 }