]> icculus.org git repositories - btb/d2x.git/blob - main/gamecntl.c
remove rcs tags
[btb/d2x.git] / main / gamecntl.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Game Controls Stuff
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 //#define DOOR_DEBUGGING
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdarg.h>
30
31 #include "pstypes.h"
32 #include "console.h"
33 #include "inferno.h"
34 #include "game.h"
35 #include "player.h"
36 #include "key.h"
37 #include "object.h"
38 #include "menu.h"
39 #include "physics.h"
40 #include "error.h"
41 #include "joy.h"
42 #include "mono.h"
43 #include "iff.h"
44 #include "pcx.h"
45 #include "timer.h"
46 #include "render.h"
47 #include "laser.h"
48 #include "screens.h"
49 #include "textures.h"
50 #include "slew.h"
51 #include "gauges.h"
52 #include "texmap.h"
53 #include "3d.h"
54 #include "effects.h"
55 #include "gameseg.h"
56 #include "wall.h"
57 #include "ai.h"
58 #include "digi.h"
59 #include "ibitblt.h"
60 #include "u_mem.h"
61 #include "palette.h"
62 #include "morph.h"
63 #include "lighting.h"
64 #include "newdemo.h"
65 #include "weapon.h"
66 #include "sounds.h"
67 #include "args.h"
68 #include "gameseq.h"
69 #include "automap.h"
70 #include "text.h"
71 #include "powerup.h"
72 #include "newmenu.h"
73 #ifdef NETWORK
74 #include "network.h"
75 #endif
76 #include "gamefont.h"
77 #include "endlevel.h"
78 #include "joydefs.h"
79 #include "kconfig.h"
80 #include "mouse.h"
81 #include "titles.h"
82 #include "gr.h"
83 #include "playsave.h"
84 #include "movie.h"
85 #include "scores.h"
86 #ifdef MACINTOSH
87 #include "songs.h"
88 #endif
89
90 #if defined (TACTILE)
91 #include "tactile.h"
92 #endif
93
94 #include "multi.h"
95 #include "desc_id.h"
96 #include "cntrlcen.h"
97 #include "pcx.h"
98 #include "state.h"
99 #include "piggy.h"
100 #include "multibot.h"
101 #include "ai.h"
102 #include "rbaudio.h"
103 #include "switch.h"
104 #include "escort.h"
105
106 //#define TEST_TIMER    1               //if this is set, do checking on timer
107
108 #define SHOW_EXIT_PATH  1
109
110 #define Arcade_mode 0
111
112
113 #ifdef EDITOR
114 #include "editor/editor.h"
115 #endif
116
117 //#define _MARK_ON 1
118 #ifdef __WATCOMC__
119 #if __WATCOMC__ < 1000
120 #include <wsample.h>            //should come after inferno.h to get mark setting
121 #endif
122 #endif
123
124 #ifdef SDL_INPUT
125 #include <SDL.h>
126 #endif
127
128 extern void full_palette_save(void);
129 extern void object_goto_prev_viewer(void);
130
131 // Global Variables -----------------------------------------------------------
132
133 int     redbook_volume = 255;
134
135
136 //      External Variables ---------------------------------------------------------
137
138 extern int      Speedtest_on;                    // Speedtest global adapted from game.c
139 extern int Guided_in_big_window;
140 extern char WaitForRefuseAnswer,RefuseThisPlayer,RefuseTeam;
141
142 #ifndef NDEBUG
143 extern int      Mark_count;
144 extern int      Speedtest_start_time;
145 extern int      Speedtest_segnum;
146 extern int      Speedtest_sidenum;
147 extern int      Speedtest_frame_start;
148 extern int      Speedtest_count;
149 #endif
150
151 extern int      Global_missile_firing_count;
152 extern int      Automap_flag;
153 extern int      Config_menu_flag;
154 extern int  EscortHotKeys;
155
156
157 extern int      Game_aborted;
158 extern int      *Toggle_var;
159
160 extern int      Physics_cheat_flag;
161
162 extern int      last_drawn_cockpit[2];
163
164 extern int      Debug_spew;
165 extern int      Debug_pause;
166 extern cvar_t   r_framerate;
167
168 extern fix      Show_view_text_timer;
169
170 extern ubyte DefiningMarkerMessage;
171
172 //      Function prototypes --------------------------------------------------------
173
174
175 extern void CyclePrimary();
176 extern void CycleSecondary();
177 extern void InitMarkerInput();
178 extern void MarkerInputMessage (int);
179 extern void grow_window(void);
180 extern void shrink_window(void);
181 extern int      allowed_to_fire_missile(void);
182 extern int      allowed_to_fire_flare(void);
183 extern void     check_rear_view(void);
184 extern int      create_special_path(void);
185 extern void move_player_2_segment(segment *seg, int side);
186 extern void     kconfig_center_headset(void);
187 extern void game_render_frame_mono(void);
188 extern void newdemo_strip_frames(char *, int);
189 extern void toggle_cockpit(void);
190 extern int  dump_used_textures_all(void);
191 extern void DropMarker();
192 extern void DropSecondaryWeapon();
193 extern void DropCurrentWeapon();
194
195 void FinalCheats(int key);
196
197 #ifndef RELEASE
198 void do_cheat_menu(void);
199 #endif
200
201 void HandleGameKey(int key);
202 int HandleSystemKey(int key);
203 void HandleTestKey(int key);
204 void HandleVRKey(int key);
205
206 void speedtest_init(void);
207 void speedtest_frame(void);
208 void advance_sound(void);
209 void play_test_sound(void);
210
211 #define key_isfunc(k) (((k&0xff)>=KEY_F1 && (k&0xff)<=KEY_F10) || (k&0xff)==KEY_F11 || (k&0xff)==KEY_F12)
212 #define key_ismod(k)  ((k&0xff)==KEY_LALT || (k&0xff)==KEY_RALT || (k&0xff)==KEY_LSHIFT || (k&0xff)==KEY_RSHIFT || (k&0xff)==KEY_LCTRL || (k&0xff)==KEY_RCTRL)
213
214 // Functions ------------------------------------------------------------------
215
216 #define CONVERTER_RATE  20              //10 units per second xfer rate
217 #define CONVERTER_SCALE  2              //2 units energy -> 1 unit shields
218
219 #define CONVERTER_SOUND_DELAY (f1_0/2)          //play every half second
220
221 void transfer_energy_to_shield(fix time)
222 {
223         fix e;          //how much energy gets transfered
224         static fix last_play_time=0;
225
226         e = min(min(time*CONVERTER_RATE,Players[Player_num].energy - INITIAL_ENERGY),(MAX_SHIELDS-Players[Player_num].shields)*CONVERTER_SCALE);
227
228         if (e <= 0) {
229
230                 if (Players[Player_num].energy <= INITIAL_ENERGY)
231                         HUD_init_message("Need more than %i energy to enable transfer", f2i(INITIAL_ENERGY));
232                 else
233                         HUD_init_message("No transfer: Shields already at max");
234                 return;
235         }
236
237         Players[Player_num].energy  -= e;
238         Players[Player_num].shields += e/CONVERTER_SCALE;
239
240         if (last_play_time > GameTime)
241                 last_play_time = 0;
242
243         if (GameTime > last_play_time+CONVERTER_SOUND_DELAY) {
244                 digi_play_sample_once(SOUND_CONVERT_ENERGY, F1_0);
245                 last_play_time = GameTime;
246         }
247
248 }
249
250 void update_vcr_state();
251 void do_weapon_stuff(void);
252
253
254 // Control Functions
255
256 fix newdemo_single_frame_time;
257
258 void update_vcr_state(void)
259 {
260         if ((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) && keyd_pressed[KEY_RIGHT])
261                 Newdemo_vcr_state = ND_STATE_FASTFORWARD;
262         else if ((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) && keyd_pressed[KEY_LEFT])
263                 Newdemo_vcr_state = ND_STATE_REWINDING;
264         else if (!(keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]) && keyd_pressed[KEY_RIGHT] && ((timer_get_fixed_seconds() - newdemo_single_frame_time) >= F1_0))
265                 Newdemo_vcr_state = ND_STATE_ONEFRAMEFORWARD;
266         else if (!(keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]) && keyd_pressed[KEY_LEFT] && ((timer_get_fixed_seconds() - newdemo_single_frame_time) >= F1_0))
267                 Newdemo_vcr_state = ND_STATE_ONEFRAMEBACKWARD;
268         else if ((Newdemo_vcr_state == ND_STATE_FASTFORWARD) || (Newdemo_vcr_state == ND_STATE_REWINDING))
269                 Newdemo_vcr_state = ND_STATE_PLAYBACK;
270 }
271
272 //returns which bomb will be dropped next time the bomb key is pressed
273 int which_bomb()
274 {
275         int bomb;
276
277         //use the last one selected, unless there aren't any, in which case use
278         //the other if there are any
279
280
281    // If hoard game, only let the player drop smart mines
282    if (Game_mode & GM_HOARD)
283                 return SMART_MINE_INDEX;
284
285         bomb = Secondary_last_was_super[PROXIMITY_INDEX]?SMART_MINE_INDEX:PROXIMITY_INDEX;
286
287         if (Players[Player_num].secondary_ammo[bomb] == 0 &&
288                         Players[Player_num].secondary_ammo[SMART_MINE_INDEX+PROXIMITY_INDEX-bomb] != 0) {
289                 bomb = SMART_MINE_INDEX+PROXIMITY_INDEX-bomb;
290                 Secondary_last_was_super[bomb%SUPER_WEAPON] = (bomb == SMART_MINE_INDEX);
291         }
292         
293         
294
295         return bomb;
296 }
297
298
299 void do_weapon_stuff(void)
300 {
301   int i;
302
303         if (Controls.fire_flare_down_count)
304                 if (allowed_to_fire_flare())
305                         Flare_create(ConsoleObject);
306
307         if (allowed_to_fire_missile())
308                 Global_missile_firing_count += Weapon_info[Secondary_weapon_to_weapon_info[Secondary_weapon]].fire_count * (Controls.fire_secondary_state || Controls.fire_secondary_down_count);
309
310         if (Global_missile_firing_count) {
311                 do_missile_firing(1);                   //always enable autoselect for normal missile firing
312                 Global_missile_firing_count--;
313         }
314
315    if (Controls.cycle_primary_count)
316          {
317      for (i=0;i<Controls.cycle_primary_count;i++)
318                 CyclePrimary ();
319     }
320    if (Controls.cycle_secondary_count)
321          {
322      for (i=0;i<Controls.cycle_secondary_count;i++)
323                 CycleSecondary ();
324     }
325    if (Controls.headlight_count)
326          {
327      for (i=0;i<Controls.headlight_count;i++)
328                 toggle_headlight_active ();
329     }
330
331         if (Global_missile_firing_count < 0)
332                 Global_missile_firing_count = 0;
333
334         //      Drop proximity bombs.
335         if (Controls.drop_bomb_down_count) {
336                 int ssw_save = Secondary_weapon;
337
338                 while (Controls.drop_bomb_down_count--) {
339                         int ssw_save2;
340
341                         ssw_save2 = Secondary_weapon = which_bomb();
342
343                         do_missile_firing(Secondary_weapon == ssw_save);        //only allow autoselect if bomb is actually selected
344
345                         if (Secondary_weapon != ssw_save2 && ssw_save == ssw_save2)
346                                 ssw_save = Secondary_weapon;    //if bomb was selected, and we ran out & autoselect, then stick with new selection
347                 }
348
349                 Secondary_weapon = ssw_save;
350         }
351 }
352
353
354 int Game_paused;
355 char *Pause_msg;
356
357 extern void game_render_frame();
358 extern void show_extra_views();
359 extern fix Flash_effect;
360
361 void apply_modified_palette(void)
362 {
363 //@@    int                             k,x,y;
364 //@@    grs_bitmap      *sbp;
365 //@@    grs_canvas      *save_canv;
366 //@@    int                             color_xlate[256];
367 //@@
368 //@@
369 //@@    if (!Flash_effect && ((PaletteRedAdd < 10) || (PaletteRedAdd < (PaletteGreenAdd + PaletteBlueAdd))))
370 //@@            return;
371 //@@
372 //@@    reset_cockpit();
373 //@@
374 //@@    save_canv = grd_curcanv;
375 //@@    gr_set_current_canvas(&grd_curscreen->sc_canvas);
376 //@@
377 //@@    sbp = &grd_curscreen->sc_canvas.cv_bitmap;
378 //@@
379 //@@    for (x=0; x<256; x++)
380 //@@            color_xlate[x] = -1;
381 //@@
382 //@@    for (k=0; k<4; k++) {
383 //@@            for (y=0; y<grd_curscreen->sc_h; y+= 4) {
384 //@@                      for (x=0; x<grd_curscreen->sc_w; x++) {
385 //@@                                    int     color, new_color;
386 //@@                                    int     r, g, b;
387 //@@                                    int     xcrd, ycrd;
388 //@@
389 //@@                                    ycrd = y+k;
390 //@@                                    xcrd = x;
391 //@@
392 //@@                                    color = gr_ugpixel(sbp, xcrd, ycrd);
393 //@@
394 //@@                                    if (color_xlate[color] == -1) {
395 //@@                                            r = gr_palette[color*3+0];
396 //@@                                            g = gr_palette[color*3+1];
397 //@@                                            b = gr_palette[color*3+2];
398 //@@
399 //@@                                            r += PaletteRedAdd;              if (r > 63) r = 63;
400 //@@                                            g += PaletteGreenAdd;   if (g > 63) g = 63;
401 //@@                                            b += PaletteBlueAdd;            if (b > 63) b = 63;
402 //@@
403 //@@                                            color_xlate[color] = gr_find_closest_color_current(r, g, b);
404 //@@
405 //@@                                    }
406 //@@
407 //@@                                    new_color = color_xlate[color];
408 //@@
409 //@@                                    gr_setcolor(new_color);
410 //@@                                    gr_upixel(xcrd, ycrd);
411 //@@                      }
412 //@@            }
413 //@@    }
414 }
415
416 void format_time(char *str, int secs_int)
417 {
418         int h, m, s;
419
420         h = secs_int/3600;
421         s = secs_int%3600;
422         m = s / 60;
423         s = s % 60;
424         sprintf(str, "%1d:%02d:%02d", h, m, s );
425 }
426
427 extern int Redbook_playing;
428 void do_show_netgame_help();
429
430 //Process selected keys until game unpaused. returns key that left pause (p or esc)
431 int do_game_pause()
432 {
433         int key;
434         char msg[1000];
435         char total_time[9],level_time[9];
436
437         key=0;
438
439         if (Game_paused) {              //unpause!
440                 Game_paused=0;
441       #if defined (TACTILE)
442                         if (TactileStick)
443                           EnableForces();
444                 #endif
445                 return KEY_PAUSE;
446         }
447
448 #ifdef NETWORK
449         if (Game_mode & GM_NETWORK)
450         {
451          do_show_netgame_help();
452     return (KEY_PAUSE);
453         }
454         else if (Game_mode & GM_MULTI)
455          {
456           HUD_init_message ("You cannot pause in a modem/serial game!");
457           return (KEY_PAUSE);
458          }
459 #endif
460
461         digi_pause_all();
462         RBAPause();
463         stop_time();
464
465         palette_save();
466         apply_modified_palette();
467         reset_palette_add();
468
469 // -- Matt: This is a hacked-in test for the stupid menu/flash problem.
470 //      We need a new brightening primitive if we want to make this not horribly ugly.
471 //                Gr_scanline_darkening_level = 2;
472 //                gr_rect(0, 0, 319, 199);
473
474         game_flush_inputs();
475
476         Game_paused=1;
477
478    #if defined (TACTILE)
479         if (TactileStick)
480                   DisableForces();
481         #endif
482
483
484 //      set_screen_mode( SCREEN_MENU );
485         set_popup_screen();
486         gr_palette_load( gr_palette );
487
488         format_time(total_time, f2i(Players[Player_num].time_total) + Players[Player_num].hours_total*3600);
489         format_time(level_time, f2i(Players[Player_num].time_level) + Players[Player_num].hours_level*3600);
490
491    if (Newdemo_state!=ND_STATE_PLAYBACK)
492                 sprintf(msg,"PAUSE\n\nSkill level:  %s\nHostages on board:  %d\nTime on level: %s\nTotal time in game: %s",(*(&TXT_DIFFICULTY_1 + (Difficulty_level))),Players[Player_num].hostages_on_board,level_time,total_time);
493    else
494                 sprintf(msg,"PAUSE\n\nSkill level:  %s\nHostages on board:  %d\n",(*(&TXT_DIFFICULTY_1 + (Difficulty_level))),Players[Player_num].hostages_on_board);
495
496         show_boxed_message(Pause_msg=msg);                //TXT_PAUSE);
497         gr_update();
498
499 #ifdef SDL_INPUT
500         /* give control back to the WM */
501         if (FindArg("-grabmouse"))
502             SDL_WM_GrabInput(SDL_GRAB_OFF);
503 #endif
504
505         while (Game_paused) 
506         {
507                 int screen_changed;
508
509                 key = key_getch();
510
511                 #ifndef RELEASE
512                 HandleTestKey(key);
513                 #endif
514                 
515                 screen_changed = HandleSystemKey(key);
516
517                 HandleVRKey(key);
518
519                 if (screen_changed) {
520 //                      game_render_frame();
521                         WIN(set_popup_screen());
522                         show_boxed_message(msg);
523                         //show_extra_views();
524                         if (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR)
525                                 render_gauges();
526                 }
527         }
528
529 #ifdef SDL_INPUT
530         /* keep the mouse from wandering in SDL */
531         if (FindArg("-grabmouse"))
532             SDL_WM_GrabInput(SDL_GRAB_ON);
533 #endif
534
535         if (VR_screen_flags & VRF_COMPATIBLE_MENUS) {
536                 clear_boxed_message();
537         }
538
539         game_flush_inputs();
540
541         reset_cockpit();
542
543         palette_restore();
544
545         start_time();
546
547         if (Redbook_playing)
548                 RBAResume();
549         digi_resume_all();
550         
551         MAC(delay(500);)        // delay 1/2 second because of dumb redbook problem
552
553         return key;
554 }
555
556 extern int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) );
557 extern int network_who_is_master(),network_how_many_connected(),GetMyNetRanking();
558 extern int TotalMissedPackets,TotalPacketsGot;
559 extern char Pauseable_menu;
560 char *NetworkModeNames[]={"Anarchy","Team Anarchy","Robo Anarchy","Cooperative","Capture the Flag","Hoard","Team Hoard","Unknown"};
561 extern char *RankStrings[];
562 extern int PhallicLimit,PhallicMan;
563
564 #ifdef NETWORK
565 void do_show_netgame_help()
566  {
567         newmenu_item m[30];
568    char mtext[30][50];
569         int i,num=0,eff;
570 #ifndef RELEASE
571         int pl;
572 #endif
573         char *eff_strings[]={"trashing","really hurting","seriously effecting","hurting",
574                                                                 "effecting","tarnishing"};
575
576    for (i=0;i<30;i++)
577         {
578          m[i].text=(char *)&mtext[i];
579     m[i].type=NM_TYPE_TEXT;
580         }
581
582    sprintf (mtext[num],"Game: %s",Netgame.game_name); num++;
583    sprintf (mtext[num],"Mission: %s",Netgame.mission_title); num++;
584         sprintf (mtext[num],"Current Level: %d",Netgame.levelnum); num++;
585         sprintf (mtext[num],"Difficulty: %s",MENU_DIFFICULTY_TEXT(Netgame.difficulty)); num++;
586         sprintf (mtext[num],"Game Mode: %s",NetworkModeNames[Netgame.gamemode]); num++;
587         sprintf (mtext[num],"Game Master: %s",Players[network_who_is_master()].callsign); num++;
588    sprintf (mtext[num],"Number of players: %d/%d",network_how_many_connected(),Netgame.max_numplayers); num++;
589    sprintf (mtext[num],"Packets per second: %d",Netgame.PacketsPerSec); num++;
590    sprintf (mtext[num],"Short Packets: %s",Netgame.ShortPackets?"Yes":"No"); num++;
591
592 #ifndef RELEASE
593                 pl=(int)(((float)TotalMissedPackets/(float)TotalPacketsGot)*100.0);
594                 if (pl<0)
595                   pl=0;
596                 sprintf (mtext[num],"Packets lost: %d (%d%%)",TotalMissedPackets,pl); num++;
597 #endif
598
599    if (Netgame.KillGoal)
600      { sprintf (mtext[num],"Kill goal: %d",Netgame.KillGoal*5); num++; }
601
602    sprintf (mtext[num]," "); num++;
603    sprintf (mtext[num],"Connected players:"); num++;
604
605    NetPlayers.players[Player_num].rank=GetMyNetRanking();
606
607    for (i=0;i<N_players;i++)
608      if (Players[i].connected)
609           {               
610       if (!FindArg ("-norankings"))
611                  {
612                         if (i==Player_num)
613                                 sprintf (mtext[num],"%s%s (%d/%d)",RankStrings[NetPlayers.players[i].rank],Players[i].callsign,Netlife_kills,Netlife_killed); 
614                         else
615                                 sprintf (mtext[num],"%s%s %d/%d",RankStrings[NetPlayers.players[i].rank],Players[i].callsign,kill_matrix[Player_num][i],
616                                                         kill_matrix[i][Player_num]); 
617                         num++;
618                  }
619            else
620                  sprintf (mtext[num++],"%s",Players[i].callsign); 
621           }
622
623         
624   sprintf (mtext[num]," "); num++;
625
626   eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
627
628   if (eff<0)
629         eff=0;
630   
631   if (Game_mode & GM_HOARD)
632         {
633          if (PhallicMan==-1)
634                  sprintf (mtext[num],"There is no record yet for this level."); 
635          else
636                  sprintf (mtext[num],"%s has the record at %d points.",Players[PhallicMan].callsign,PhallicLimit); 
637         num++;
638         }
639   else if (!FindArg ("-norankings"))
640         {
641           if (eff<60)
642            {
643                  sprintf (mtext[num],"Your lifetime efficiency of %d%%",eff); num++;
644                  sprintf (mtext[num],"is %s your ranking.",eff_strings[eff/10]); num++;
645                 }
646           else
647            {
648                  sprintf (mtext[num],"Your lifetime efficiency of %d%%",eff); num++;
649                  sprintf (mtext[num],"is serving you well."); num++;
650            }
651         }  
652         
653
654         full_palette_save();
655
656    Pauseable_menu=1;
657         newmenu_dotiny2( NULL, "Netgame Information", num, m, NULL);
658
659         palette_restore();
660 }
661 #endif
662
663 void HandleEndlevelKey(int key)
664 {
665         if ( key == (KEY_COMMAND + KEY_SHIFTED + KEY_3) )
666                 save_screen_shot(0);
667
668         if ( key == KEY_COMMAND+KEY_Q && !(Game_mode & GM_MULTI) )
669                 quit_request();
670
671         if (key==KEY_PRINT_SCREEN)
672                 save_screen_shot(0);
673
674         if ( key == (KEY_COMMAND+KEY_P) )
675                 key = do_game_pause();
676
677         if (key == KEY_PAUSE)
678                 key = do_game_pause();          //so esc from pause will end level
679
680         if (key == KEY_ESC) {
681                 stop_endlevel_sequence();
682                 last_drawn_cockpit[0]=-1;
683                 last_drawn_cockpit[1]=-1;
684                 return;
685         }
686
687         if (key == KEY_BACKSP)
688                 Int3();
689 }
690
691 void HandleDeathKey(int key)
692 {
693 /*
694         Commented out redundant calls because the key used here typically
695         will be passed to HandleSystemKey later.  Note that I do this to pause
696         which is supposed to pass the ESC key to leave the level.  This
697         doesn't work in the DOS version anyway.   -Samir 
698 */
699
700         if (Player_exploded && !key_isfunc(key) && !key_ismod(key))
701                 Death_sequence_aborted  = 1;            //Any key but func or modifier aborts
702
703         if ( key == (KEY_COMMAND + KEY_SHIFTED + KEY_3) ) {
704 //              save_screen_shot(0);
705                 Death_sequence_aborted  = 0;            // Clear because code above sets this for any key.
706         }
707
708         if ( key == KEY_COMMAND+KEY_Q && !(Game_mode & GM_MULTI) )
709                 quit_request();
710
711         if (key==KEY_PRINT_SCREEN) {
712 //              save_screen_shot(0);
713                 Death_sequence_aborted  = 0;            // Clear because code above sets this for any key.
714         }
715
716         if ( key == (KEY_COMMAND+KEY_P) ) {
717 //              key = do_game_pause();
718                 Death_sequence_aborted  = 0;            // Clear because code above sets this for any key.
719         }
720
721         if (key == KEY_PAUSE)   {
722 //              key = do_game_pause();          //so esc from pause will end level
723                 Death_sequence_aborted  = 0;            // Clear because code above sets this for any key.
724         }
725
726         if (key == KEY_ESC) {
727                 if (ConsoleObject->flags & OF_EXPLODING)
728                         Death_sequence_aborted = 1;
729         }
730
731         if (key == KEY_BACKSP)  {
732                 Death_sequence_aborted  = 0;            // Clear because code above sets this for any key.
733                 Int3();
734         }
735
736         //don't abort death sequence for netgame join/refuse keys
737         if (    (key == KEY_ALTED + KEY_1) ||
738                         (key == KEY_ALTED + KEY_2))
739                 Death_sequence_aborted  = 0;
740
741         if (Death_sequence_aborted)
742                 game_flush_inputs();
743
744 }
745
746 void HandleDemoKey(int key)
747 {
748         switch (key) {
749
750                 case KEY_F3:
751                                 
752                          if (!(Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window))
753                                 toggle_cockpit();
754                          break;
755
756                 case KEY_SHIFTED+KEY_MINUS:
757                 case KEY_MINUS:         shrink_window(); break;
758
759                 case KEY_SHIFTED+KEY_EQUAL:
760                 case KEY_EQUAL:         grow_window(); break;
761
762                 case KEY_COMMAND+KEY_2:
763                 case KEY_F2:            Config_menu_flag = 1; break;
764
765                 case KEY_COMMAND+KEY_7:
766                 case KEY_F7:
767                         #ifdef NETWORK
768                         Show_kill_list = (Show_kill_list+1) % ((Newdemo_game_mode & GM_TEAM) ? 4 : 3);
769                         #endif
770                         break;
771                 case KEY_ESC:
772                         Function_mode = FMODE_MENU;
773                         break;
774                 case KEY_UP:
775                         Newdemo_vcr_state = ND_STATE_PLAYBACK;
776                         break;
777                 case KEY_DOWN:
778                         Newdemo_vcr_state = ND_STATE_PAUSED;
779                         break;
780                 case KEY_LEFT:
781                         newdemo_single_frame_time = timer_get_fixed_seconds();
782                         Newdemo_vcr_state = ND_STATE_ONEFRAMEBACKWARD;
783                         break;
784                 case KEY_RIGHT:
785                         newdemo_single_frame_time = timer_get_fixed_seconds();
786                         Newdemo_vcr_state = ND_STATE_ONEFRAMEFORWARD;
787                         break;
788                 case KEY_CTRLED + KEY_RIGHT:
789                         newdemo_goto_end();
790                         break;
791                 case KEY_CTRLED + KEY_LEFT:
792                         newdemo_goto_beginning();
793                         break;
794
795                 case KEY_COMMAND+KEY_P:
796                 case KEY_PAUSE:
797                         do_game_pause();
798                         break;
799
800                 case KEY_COMMAND + KEY_SHIFTED + KEY_3:
801                 case KEY_PRINT_SCREEN: {
802                         int old_state;
803
804                         old_state = Newdemo_vcr_state;
805                         Newdemo_vcr_state = ND_STATE_PRINTSCREEN;
806                         game_render_frame_mono();
807                         save_screen_shot(0);
808                         Newdemo_vcr_state = old_state;
809                         break;
810                 }
811
812                 case KEY_COMMAND+KEY_Q:
813                         if ( !(Game_mode & GM_MULTI) )
814                                 quit_request();
815                         break;
816
817                 #ifndef NDEBUG
818                 case KEY_BACKSP:
819                         Int3();
820                         break;
821                 case KEY_DEBUGGED + KEY_I:
822                         Newdemo_do_interpolate = !Newdemo_do_interpolate;
823                         if (Newdemo_do_interpolate)
824                                 mprintf ((0, "demo playback interpolation now on\n"));
825                         else
826                                 mprintf ((0, "demo playback interpolation now off\n"));
827                         break;
828                 case KEY_DEBUGGED + KEY_K: {
829                         int how_many, c;
830                         char filename[FILENAME_LEN], num[16];
831                         newmenu_item m[6];
832
833                         filename[0] = '\0';
834                         m[ 0].type = NM_TYPE_TEXT; m[ 0].text = "output file name";
835                         m[ 1].type = NM_TYPE_INPUT;m[ 1].text_len = 8; m[1].text = filename;
836                         c = newmenu_do( NULL, NULL, 2, m, NULL );
837                         if (c == -2)
838                                 break;
839                         strcat(filename, ".dem");
840                         num[0] = '\0';
841                         m[ 0].type = NM_TYPE_TEXT; m[ 0].text = "strip how many bytes";
842                         m[ 1].type = NM_TYPE_INPUT;m[ 1].text_len = 16; m[1].text = num;
843                         c = newmenu_do( NULL, NULL, 2, m, NULL );
844                         if (c == -2)
845                                 break;
846                         how_many = atoi(num);
847                         if (how_many <= 0)
848                                 break;
849                         newdemo_strip_frames(filename, how_many);
850
851                         break;
852                 }
853                 #endif
854
855         }
856 }
857
858 //switch a cockpit window to the next function
859 int select_next_window_function(int w)
860 {
861         Assert(w==0 || w==1);
862
863         switch (Cockpit_3d_view[w]) {
864                 case CV_NONE:
865                         Cockpit_3d_view[w] = CV_REAR;
866                         break;
867                 case CV_REAR:
868                         if (find_escort()) {
869                                 Cockpit_3d_view[w] = CV_ESCORT;
870                                 break;
871                         }
872                         //if no ecort, fall through
873                 case CV_ESCORT:
874                         Coop_view_player[w] = -1;               //force first player
875 #ifdef NETWORK
876                         //fall through
877                 case CV_COOP:
878                         Marker_viewer_num[w] = -1;
879                         if ((Game_mode & GM_MULTI_COOP) || (Game_mode & GM_TEAM)) {
880                                 Cockpit_3d_view[w] = CV_COOP;
881                                 while (1) {
882                                         Coop_view_player[w]++;
883                                         if (Coop_view_player[w] == N_players) {
884                                                 Cockpit_3d_view[w] = CV_MARKER;
885                                                 goto case_marker;
886                                         }
887                                         if (Coop_view_player[w]==Player_num)
888                                                 continue;
889
890                                         if (Game_mode & GM_MULTI_COOP)
891                                                 break;
892                                         else if (get_team(Coop_view_player[w]) == get_team(Player_num))
893                                                 break;
894                                 }
895                                 break;
896                         }
897                         //if not multi, fall through
898                 case CV_MARKER:
899                 case_marker:;
900                         if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP) && Netgame.Allow_marker_view) {      //anarchy only
901                                 Cockpit_3d_view[w] = CV_MARKER;
902                                 if (Marker_viewer_num[w] == -1)
903                                         Marker_viewer_num[w] = Player_num * 2;
904                                 else if (Marker_viewer_num[w] == Player_num * 2)
905                                         Marker_viewer_num[w]++;
906                                 else
907                                         Cockpit_3d_view[w] = CV_NONE;
908                         }
909                         else
910 #endif
911                                 Cockpit_3d_view[w] = CV_NONE;
912                         break;
913         }
914         write_player_file();
915
916         return 1;        //screen_changed
917 }
918
919 extern int Game_paused;
920
921 void songs_goto_next_song();
922 void songs_goto_prev_song();
923
924 #ifdef DOOR_DEBUGGING
925 dump_door_debugging_info()
926 {
927         object *obj;
928         vms_vector new_pos;
929         fvi_query fq;
930         fvi_info hit_info;
931         int fate;
932         FILE *dfile;
933         int wall_num;
934
935         obj = &Objects[Players[Player_num].objnum];
936         vm_vec_scale_add(&new_pos,&obj->pos,&obj->orient.fvec,i2f(100));
937
938         fq.p0                                           = &obj->pos;
939         fq.startseg                             = obj->segnum;
940         fq.p1                                           = &new_pos;
941         fq.rad                                  = 0;
942         fq.thisobjnum                   = Players[Player_num].objnum;
943         fq.ignore_obj_list      = NULL;
944         fq.flags                                        = 0;
945
946         fate = find_vector_intersection(&fq,&hit_info);
947
948         dfile = fopen("door.out","at");
949
950         fprintf(dfile,"FVI hit_type = %d\n",fate);
951         fprintf(dfile,"    hit_seg = %d\n",hit_info.hit_seg);
952         fprintf(dfile,"    hit_side = %d\n",hit_info.hit_side);
953         fprintf(dfile,"    hit_side_seg = %d\n",hit_info.hit_side_seg);
954         fprintf(dfile,"\n");
955
956         if (fate == HIT_WALL) {
957
958                 wall_num = Segments[hit_info.hit_seg].sides[hit_info.hit_side].wall_num;
959                 fprintf(dfile,"wall_num = %d\n",wall_num);
960         
961                 if (wall_num != -1) {
962                         wall *wall = &Walls[wall_num];
963                         active_door *d;
964                         int i;
965         
966                         fprintf(dfile,"    segnum = %d\n",wall->segnum);
967                         fprintf(dfile,"    sidenum = %d\n",wall->sidenum);
968                         fprintf(dfile,"    hps = %x\n",wall->hps);
969                         fprintf(dfile,"    linked_wall = %d\n",wall->linked_wall);
970                         fprintf(dfile,"    type = %d\n",wall->type);
971                         fprintf(dfile,"    flags = %x\n",wall->flags);
972                         fprintf(dfile,"    state = %d\n",wall->state);
973                         fprintf(dfile,"    trigger = %d\n",wall->trigger);
974                         fprintf(dfile,"    clip_num = %d\n",wall->clip_num);
975                         fprintf(dfile,"    keys = %x\n",wall->keys);
976                         fprintf(dfile,"    controlling_trigger = %d\n",wall->controlling_trigger);
977                         fprintf(dfile,"    cloak_value = %d\n",wall->cloak_value);
978                         fprintf(dfile,"\n");
979         
980         
981                         for (i=0;i<Num_open_doors;i++) {                //find door
982                                 d = &ActiveDoors[i];
983                                 if (d->front_wallnum[0]==wall-Walls || d->back_wallnum[0]==wall-Walls || (d->n_parts==2 && (d->front_wallnum[1]==wall-Walls || d->back_wallnum[1]==wall-Walls)))
984                                         break;
985                         } 
986         
987                         if (i>=Num_open_doors)
988                                 fprintf(dfile,"No active door.\n");
989                         else {
990                                 fprintf(dfile,"Active door %d:\n",i);
991                                 fprintf(dfile,"    n_parts = %d\n",d->n_parts);
992                                 fprintf(dfile,"    front_wallnum = %d,%d\n",d->front_wallnum[0],d->front_wallnum[1]);
993                                 fprintf(dfile,"    back_wallnum = %d,%d\n",d->back_wallnum[0],d->back_wallnum[1]);
994                                 fprintf(dfile,"    time = %x\n",d->time);
995                         }
996         
997                 }
998         }
999
1000         fprintf(dfile,"\n");
1001         fprintf(dfile,"\n");
1002
1003         fclose(dfile);
1004
1005 }
1006 #endif
1007
1008
1009 //this is for system-level keys, such as help, etc.
1010 //returns 1 if screen changed
1011 int HandleSystemKey(int key)
1012 {
1013         int screen_changed=0;
1014
1015         if (!Player_is_dead)
1016                 switch (key) {
1017
1018                         #ifdef DOOR_DEBUGGING
1019                         case KEY_LAPOSTRO+KEY_SHIFTED:
1020                                 dump_door_debugging_info();
1021                                 break;
1022                         #endif
1023
1024                         case KEY_ESC:
1025                                 if (Game_paused)
1026                                         Game_paused=0;
1027                                 else {
1028                                         Game_aborted=1;
1029                                         Function_mode = FMODE_MENU;
1030                                 }
1031                                 break;
1032
1033 // fleshed these out because F1 and F2 aren't sequenctial keycodes on mac -- MWA
1034
1035                         case KEY_COMMAND+KEY_SHIFTED+KEY_1:
1036                         case KEY_SHIFTED+KEY_F1:
1037                                 screen_changed = select_next_window_function(0);
1038                                 break;
1039                         case KEY_COMMAND+KEY_SHIFTED+KEY_2:
1040                         case KEY_SHIFTED+KEY_F2:
1041                                 screen_changed = select_next_window_function(1);
1042                                 break;
1043                 }
1044
1045         switch (key) {
1046
1047                 case KEY_LAPOSTRO:
1048                 case KEY_SHIFTED + KEY_LAPOSTRO:
1049                         CON_Show();
1050                         break;
1051
1052                 case KEY_SHIFTED + KEY_ESC:     //quick exit
1053                         #ifdef EDITOR
1054                                 if (! SafetyCheck()) break;
1055                                 close_editor_screen();
1056                         #endif
1057
1058                         Game_aborted=1;
1059                         Function_mode=FMODE_EXIT;
1060                         break;
1061
1062                 case KEY_COMMAND+KEY_P:
1063                 case KEY_PAUSE: 
1064                         do_game_pause();                                break;
1065
1066                 case KEY_COMMAND + KEY_SHIFTED + KEY_3:
1067                 case KEY_PRINT_SCREEN:  save_screen_shot(0);            break;
1068
1069                 case KEY_COMMAND+KEY_1:
1070                 case KEY_F1:                                    do_show_help();                 break;
1071
1072                 case KEY_COMMAND+KEY_2:
1073                 case KEY_F2:                                    //Config_menu_flag = 1; break;
1074                         {
1075                                 if (!(Game_mode&GM_MULTI)) {palette_save(); apply_modified_palette(); reset_palette_add(); gr_palette_load(gr_palette); }
1076                                 do_options_menu();
1077                                 if (!(Game_mode&GM_MULTI)) palette_restore();
1078                                 break;
1079                         }
1080
1081                 case KEY_COMMAND+KEY_3:
1082                 case KEY_F3:
1083                         if (!(Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window))
1084                         {
1085                                 toggle_cockpit();       screen_changed=1;
1086                         }
1087                         break;
1088
1089                 case KEY_COMMAND+KEY_SHIFTED+KEY_7:
1090                 case KEY_F7+KEY_SHIFTED: palette_save(); joydefs_calibrate(); palette_restore(); break;
1091
1092                 case KEY_SHIFTED+KEY_MINUS:
1093                 case KEY_MINUS: 
1094                         shrink_window(); 
1095                         screen_changed=1; 
1096                         break;
1097
1098                 case KEY_SHIFTED+KEY_EQUAL:
1099                 case KEY_EQUAL:                 
1100                         grow_window();  
1101                         screen_changed=1; 
1102                         break;
1103
1104                 case KEY_COMMAND+KEY_5:
1105                 case KEY_F5:
1106                         if ( Newdemo_state == ND_STATE_RECORDING )
1107                                 newdemo_stop_recording();
1108                         else if ( Newdemo_state == ND_STATE_NORMAL )
1109                                 if (!Game_paused)               //can't start demo while paused
1110                                         newdemo_start_recording();
1111                         break;
1112
1113                 case KEY_COMMAND+KEY_ALTED+KEY_4:
1114                 case KEY_ALTED+KEY_F4:
1115                         #ifdef NETWORK
1116                         Show_reticle_name = (Show_reticle_name+1)%2;
1117                         #endif
1118                         break;
1119
1120                 case KEY_COMMAND + KEY_6:
1121                 case KEY_F6:
1122                         if (!Player_is_dead && !(Game_mode & GM_MULTI))
1123                         {
1124                                 int rsave, gsave, bsave;
1125                                 rsave = PaletteRedAdd;
1126                                 gsave = PaletteGreenAdd;
1127                                 bsave = PaletteBlueAdd;
1128
1129                                 full_palette_save();
1130                                 PaletteRedAdd = rsave;
1131                                 PaletteGreenAdd = gsave;
1132                                 PaletteBlueAdd = bsave;
1133                                 state_save_all(0, 0, NULL, 1); // 0 means not between levels.
1134                                 palette_restore();
1135                         }
1136                         break;
1137
1138                 case KEY_COMMAND+KEY_7:
1139                 case KEY_F7:
1140                         #ifdef NETWORK
1141                         Show_kill_list = (Show_kill_list+1) % ((Game_mode & GM_TEAM) ? 4 : 3);
1142                         if (Game_mode & GM_MULTI)
1143                                 multi_sort_kill_list();
1144                 #endif
1145                         break;
1146
1147                 case KEY_COMMAND+KEY_8:
1148                 case KEY_F8:
1149                         #ifdef NETWORK
1150                         multi_send_message_start();
1151                         #endif
1152                         break;
1153
1154                 case KEY_F9:
1155                 case KEY_F10:
1156                 case KEY_F11:
1157                 case KEY_F12:
1158                         #ifdef NETWORK
1159                         multi_send_macro(key);
1160                         #endif
1161                         break;          // send taunt macros
1162
1163                 case KEY_9 + KEY_COMMAND:
1164                         multi_send_macro(KEY_F9);
1165                         break;
1166                 case KEY_0 + KEY_COMMAND:
1167                         multi_send_macro(KEY_F10);
1168                         break;
1169                 case KEY_1 + KEY_COMMAND + KEY_CTRLED:
1170                         multi_send_macro(KEY_F11);
1171                         break;
1172                 case KEY_2 + KEY_COMMAND + KEY_CTRLED:
1173                         multi_send_macro(KEY_F12);
1174                         break;
1175
1176                 case KEY_SHIFTED + KEY_F9:
1177                 case KEY_SHIFTED + KEY_F10:
1178                 case KEY_SHIFTED + KEY_F11:
1179                 case KEY_SHIFTED + KEY_F12:
1180                         #ifdef NETWORK
1181                         multi_define_macro(key);
1182                         #endif
1183                         break;          // redefine taunt macros
1184
1185                 case KEY_9 + KEY_SHIFTED + KEY_COMMAND:
1186                         multi_define_macro(KEY_F9);
1187                         break;
1188                 case KEY_0 + KEY_SHIFTED + KEY_COMMAND:
1189                         multi_define_macro(KEY_F10);
1190                         break;
1191                 case KEY_1 + KEY_SHIFTED + KEY_COMMAND + KEY_CTRLED:
1192                         multi_define_macro(KEY_F11);
1193                         break;
1194                 case KEY_2 + KEY_SHIFTED + KEY_COMMAND + KEY_CTRLED:
1195                         multi_define_macro(KEY_F12);
1196                         break;
1197
1198                 case KEY_COMMAND+KEY_S:
1199                 case KEY_COMMAND+KEY_ALTED+KEY_2:
1200                 case KEY_ALTED+KEY_F2:
1201                         if (!Player_is_dead && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))) {
1202                                 int     rsave, gsave, bsave;
1203                                 rsave = PaletteRedAdd;
1204                                 gsave = PaletteGreenAdd;
1205                                 bsave = PaletteBlueAdd;
1206
1207                                 full_palette_save();
1208                                 PaletteRedAdd = rsave;
1209                                 PaletteGreenAdd = gsave;
1210                                 PaletteBlueAdd = bsave;
1211                                 state_save_all(0, 0, NULL, 0); // 0 means not between levels.
1212                                 palette_restore();
1213                         }
1214                         break;
1215
1216                 case KEY_COMMAND+KEY_O:
1217                 case KEY_COMMAND+KEY_ALTED+KEY_3:
1218                 case KEY_ALTED+KEY_F3:
1219                         if (!Player_is_dead && !((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))) {
1220                                 full_palette_save();
1221                                 state_restore_all(1, 0, NULL);
1222                                 if (Game_paused)
1223                                         do_game_pause();
1224                         }
1225                         break;
1226
1227                 case KEY_COMMAND+KEY_SHIFTED+KEY_4:
1228                 case KEY_F4 + KEY_SHIFTED:
1229                         do_escort_menu();
1230                         break;
1231
1232                 case KEY_COMMAND+KEY_SHIFTED+KEY_ALTED+KEY_4:
1233                 case KEY_F4 + KEY_SHIFTED + KEY_ALTED:
1234                         change_guidebot_name();
1235                         break;
1236
1237                 case KEY_MINUS + KEY_ALTED:     songs_goto_prev_song(); break;
1238                 case KEY_EQUAL + KEY_ALTED:     songs_goto_next_song(); break;
1239
1240                 #ifdef MACINTOSH
1241                 
1242                 case KEY_COMMAND+KEY_M:
1243                         if ( (Game_mode & GM_MULTI) )           // don't process in multiplayer games
1244                                 break;
1245
1246                         key_close();            // no processing of keys with keyboard handler.. jeez                           
1247                         stop_time();
1248                         show_boxed_message ("Mounting CD\nESC to quit");        
1249                         RBAMountDisk();         // OS has totaly control of the CD.
1250                         if (Function_mode == FMODE_MENU)
1251                                 songs_play_song(SONG_TITLE,1);
1252                         else if (Function_mode == FMODE_GAME)
1253                                 songs_play_level_song( Current_level_num );
1254                         clear_boxed_message();
1255                         key_init();
1256                         start_time();
1257                         
1258                         break;
1259
1260                 case KEY_COMMAND+KEY_E:
1261                         songs_stop_redbook();
1262                         RBAEjectDisk();
1263                         break;
1264
1265                 case KEY_COMMAND+KEY_RIGHT:
1266                         songs_goto_next_song();
1267                         break;
1268                 case KEY_COMMAND+KEY_LEFT:
1269                         songs_goto_prev_song();
1270                         break;
1271                 case KEY_COMMAND+KEY_UP:
1272                         songs_play_level_song(1);
1273                         break;
1274                 case KEY_COMMAND+KEY_DOWN:
1275                         songs_stop_redbook();
1276                         break;
1277                 #endif
1278
1279                 case KEY_COMMAND+KEY_Q:
1280                         if ( !(Game_mode & GM_MULTI) )
1281                                 quit_request();
1282                         break;
1283
1284 //added 8/23/99 by Matt Mueller for hot key res/fullscreen changing, and menu access
1285                 case KEY_CTRLED+KEY_SHIFTED+KEY_PADDIVIDE:
1286                 case KEY_ALTED+KEY_CTRLED+KEY_PADDIVIDE:
1287                 case KEY_ALTED+KEY_SHIFTED+KEY_PADDIVIDE:
1288                         d2x_options_menu();
1289                         break;
1290 #if 0
1291                 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMULTIPLY:
1292                 case KEY_ALTED+KEY_CTRLED+KEY_PADMULTIPLY:
1293                 case KEY_ALTED+KEY_SHIFTED+KEY_PADMULTIPLY:
1294                         change_res();
1295                         break;
1296                 case KEY_CTRLED+KEY_SHIFTED+KEY_PADMINUS:
1297                 case KEY_ALTED+KEY_CTRLED+KEY_PADMINUS:
1298                 case KEY_ALTED+KEY_SHIFTED+KEY_PADMINUS:
1299                         //lower res 
1300                         //should we just cycle through the list that is displayed in the res change menu?
1301                         // what if their card/X/etc can't handle that mode? hrm. 
1302                         //well, the quick access to the menu is good enough for now.
1303                         break;
1304                 case KEY_CTRLED+KEY_SHIFTED+KEY_PADPLUS:
1305                 case KEY_ALTED+KEY_CTRLED+KEY_PADPLUS:
1306                 case KEY_ALTED+KEY_SHIFTED+KEY_PADPLUS:
1307                         //increase res
1308                         break;
1309 #endif
1310                 case KEY_COMMAND+KEY_SHIFTED+KEY_F:
1311                 case KEY_ALTED+KEY_ENTER:
1312                 case KEY_ALTED+KEY_PADENTER:
1313                         gr_toggle_fullscreen_game();
1314                         break;
1315 //end addition -MM
1316                         
1317 //added 11/01/98 Matt Mueller
1318 #if 0
1319                 case KEY_CTRLED+KEY_ALTED+KEY_LAPOSTRO:
1320                         toggle_hud_log();
1321                         break;
1322 #endif
1323 //end addition -MM
1324
1325                 default:
1326                         break;
1327
1328         }        //switch (key)
1329
1330         return screen_changed;
1331 }
1332
1333
1334 void HandleVRKey(int key)
1335 {
1336         switch( key )   {
1337
1338                 case KEY_ALTED+KEY_F5:
1339                         if ( VR_render_mode != VR_NONE )        {
1340                                 VR_reset_params();
1341                                 HUD_init_message( "-Stereoscopic Parameters Reset-" );
1342                                 HUD_init_message( "Interaxial Separation = %.2f", f2fl(VR_eye_width) );
1343                                 HUD_init_message( "Stereo balance = %.2f", (float)VR_eye_offset/30.0 );
1344                         }
1345                         break;
1346
1347                 case KEY_ALTED+KEY_F6:
1348                         if ( VR_render_mode != VR_NONE )        {
1349                                 VR_low_res++;
1350                                 if ( VR_low_res > 3 ) VR_low_res = 0;
1351                                 switch( VR_low_res )    {
1352                                         case 0: HUD_init_message( "Normal Resolution" ); break;
1353                                         case 1: HUD_init_message( "Low Vertical Resolution" ); break;
1354                                         case 2: HUD_init_message( "Low Horizontal Resolution" ); break;
1355                                         case 3: HUD_init_message( "Low Resolution" ); break;
1356                                 }
1357                         }
1358                         break;
1359
1360                 case KEY_ALTED+KEY_F7:
1361                         if ( VR_render_mode != VR_NONE )        {
1362                                 VR_eye_switch = !VR_eye_switch;
1363                                 HUD_init_message( "-Eyes toggled-" );
1364                                 if ( VR_eye_switch )
1365                                         HUD_init_message( "Right Eye -- Left Eye" );
1366                                 else
1367                                         HUD_init_message( "Left Eye -- Right Eye" );
1368                         }
1369                         break;
1370
1371                 case KEY_ALTED+KEY_F8:
1372                         if ( VR_render_mode != VR_NONE )        {
1373                         VR_sensitivity++;
1374                         if (VR_sensitivity > 2 )
1375                                 VR_sensitivity = 0;
1376                         HUD_init_message( "Head tracking sensitivy = %d", VR_sensitivity );
1377                  }
1378                         break;
1379                 case KEY_ALTED+KEY_F9:
1380                         if ( VR_render_mode != VR_NONE )        {
1381                                 VR_eye_width -= F1_0/10;
1382                                 if ( VR_eye_width < 0 ) VR_eye_width = 0;
1383                                 HUD_init_message( "Interaxial Separation = %.2f", f2fl(VR_eye_width) );
1384                                 HUD_init_message( "(The default value is %.2f)", f2fl(VR_SEPARATION) );
1385                         }
1386                         break;
1387                 case KEY_ALTED+KEY_F10:
1388                         if ( VR_render_mode != VR_NONE )        {
1389                                 VR_eye_width += F1_0/10;
1390                                 if ( VR_eye_width > F1_0*4 )    VR_eye_width = F1_0*4;
1391                                 HUD_init_message( "Interaxial Separation = %.2f", f2fl(VR_eye_width) );
1392                                 HUD_init_message( "(The default value is %.2f)", f2fl(VR_SEPARATION) );
1393                         }
1394                         break;
1395
1396                 case KEY_ALTED+KEY_F11:
1397                         if ( VR_render_mode != VR_NONE )        {
1398                                 VR_eye_offset--;
1399                                 if ( VR_eye_offset < -30 )      VR_eye_offset = -30;
1400                                 HUD_init_message( "Stereo balance = %.2f", (float)VR_eye_offset/30.0 );
1401                                 HUD_init_message( "(The default value is %.2f)", (float)VR_PIXEL_SHIFT/30.0 );
1402                                 VR_eye_offset_changed = 2;
1403                         }
1404                         break;
1405                 case KEY_ALTED+KEY_F12:
1406                         if ( VR_render_mode != VR_NONE )        {
1407                                 VR_eye_offset++;
1408                                 if ( VR_eye_offset > 30 )        VR_eye_offset = 30;
1409                                 HUD_init_message( "Stereo balance = %.2f", (float)VR_eye_offset/30.0 );
1410                                 HUD_init_message( "(The default value is %.2f)", (float)VR_PIXEL_SHIFT/30.0 );
1411                                 VR_eye_offset_changed = 2;
1412                         }
1413                         break;
1414         }
1415 }
1416
1417
1418 extern void DropFlag();
1419
1420 void HandleGameKey(int key)
1421 {
1422         if (cmd_handle_keybinding(key))
1423                 return;
1424
1425         switch (key) {
1426
1427                 #if !defined(RELEASE)
1428                 case KEY_COMMAND+KEY_F:
1429                         cvar_toggle( &r_framerate );
1430                         break;
1431                 #endif
1432
1433 #ifndef D2X_KEYS // weapon selection handled in controls_read_all, d1x-style
1434 // MWA changed the weapon select cases to have each case call
1435 // do_weapon_select the macintosh keycodes aren't consecutive from 1
1436 // -- 0 on the keyboard -- boy is that STUPID!!!!
1437
1438                 //      Select primary or secondary weapon.
1439                 case KEY_1:
1440                         do_weapon_select(0 , 0);
1441                         break;
1442                 case KEY_2:
1443                         do_weapon_select(1 , 0);
1444                         break;
1445                 case KEY_3:
1446                         do_weapon_select(2 , 0);
1447                         break;
1448                 case KEY_4:
1449                         do_weapon_select(3 , 0);
1450                         break;
1451                 case KEY_5:
1452                         do_weapon_select(4 , 0);
1453                         break;
1454
1455                 case KEY_6:
1456                         do_weapon_select(0 , 1);
1457                         break;
1458                 case KEY_7:
1459                         do_weapon_select(1 , 1);
1460                         break;
1461                 case KEY_8:
1462                         do_weapon_select(2 , 1);
1463                         break;
1464                 case KEY_9:
1465                         do_weapon_select(3 , 1);
1466                         break;
1467                 case KEY_0:
1468                         do_weapon_select(4 , 1);
1469                         break;
1470 #endif
1471
1472                 case KEY_1 + KEY_SHIFTED:
1473                 case KEY_2 + KEY_SHIFTED:
1474                 case KEY_3 + KEY_SHIFTED:
1475                 case KEY_4 + KEY_SHIFTED:
1476                 case KEY_5 + KEY_SHIFTED:
1477                 case KEY_6 + KEY_SHIFTED:
1478                 case KEY_7 + KEY_SHIFTED:
1479                 case KEY_8 + KEY_SHIFTED:
1480                 case KEY_9 + KEY_SHIFTED:
1481                 case KEY_0 + KEY_SHIFTED:
1482                 if (EscortHotKeys)
1483                 {
1484                         if (!(Game_mode & GM_MULTI))
1485                                 set_escort_special_goal(key);
1486                         else
1487                                 HUD_init_message ("No Guide-Bot in Multiplayer!");
1488                         break;
1489                 }
1490
1491                 case KEY_COMMAND+KEY_SHIFTED+KEY_5:
1492                 case KEY_F5 + KEY_SHIFTED:
1493          DropCurrentWeapon();
1494                         break;
1495
1496                 case KEY_COMMAND+KEY_SHIFTED+KEY_6:
1497                 case KEY_F6 + KEY_SHIFTED:
1498          DropSecondaryWeapon();
1499          break;
1500
1501 #ifdef NETWORK
1502                 case KEY_0 + KEY_ALTED:
1503                         DropFlag ();
1504                         break;
1505 #endif
1506
1507                 case KEY_COMMAND+KEY_4:
1508                 case KEY_F4:
1509                 if (!DefiningMarkerMessage)
1510                   InitMarkerInput();
1511                  break;
1512
1513 #ifdef NETWORK
1514                 case KEY_COMMAND+KEY_6:
1515                 case KEY_F6:
1516                         if (Netgame.RefusePlayers && WaitForRefuseAnswer && !(Game_mode & GM_TEAM))
1517                                 {
1518                                         RefuseThisPlayer=1;
1519                                         HUD_init_message ("Player accepted!");
1520                                 }
1521                         break;
1522                 case KEY_ALTED + KEY_1:
1523                         if (Netgame.RefusePlayers && WaitForRefuseAnswer && (Game_mode & GM_TEAM))
1524                                 {
1525                                         RefuseThisPlayer=1;
1526                                         HUD_init_message ("Player accepted!");
1527                                         RefuseTeam=1;
1528                                 }
1529                         break;
1530                 case KEY_ALTED + KEY_2:
1531                         if (Netgame.RefusePlayers && WaitForRefuseAnswer && (Game_mode & GM_TEAM))
1532                                 {
1533                                         RefuseThisPlayer=1;
1534                                         HUD_init_message ("Player accepted!");
1535                                         RefuseTeam=2;
1536                                 }
1537                         break;
1538 #endif
1539
1540                 default:
1541                         break;
1542
1543         }        //switch (key)
1544 }
1545
1546 void kill_all_robots(void)
1547 {
1548         int     i, dead_count=0;
1549         //int   boss_index = -1;
1550
1551         // Kill all bots except for Buddy bot and boss.  However, if only boss and buddy left, kill boss.
1552         for (i=0; i<=Highest_object_index; i++)
1553                 if (Objects[i].type == OBJ_ROBOT) {
1554                         if (!Robot_info[Objects[i].id].companion && !Robot_info[Objects[i].id].boss_flag) {
1555                                 dead_count++;
1556                                 Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1557                         }
1558                 }
1559
1560 // --           // Now, if more than boss and buddy left, un-kill boss.
1561 // --           if ((dead_count > 2) && (boss_index != -1)) {
1562 // --                   Objects[boss_index].flags &= ~(OF_EXPLODING|OF_SHOULD_BE_DEAD);
1563 // --                   dead_count--;
1564 // --           } else if (boss_index != -1)
1565 // --                   HUD_init_message("Toasted the BOSS!");
1566
1567         // Toast the buddy if nothing else toasted!
1568         if (dead_count == 0)
1569                 for (i=0; i<=Highest_object_index; i++)
1570                         if (Objects[i].type == OBJ_ROBOT)
1571                                 if (Robot_info[Objects[i].id].companion) {
1572                                         Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1573                                         HUD_init_message("Toasted the Buddy! *sniff*");
1574                                         dead_count++;
1575                                 }
1576
1577         HUD_init_message("%i robots toasted!", dead_count);
1578 }
1579
1580 //      --------------------------------------------------------------------------
1581 //      Detonate reactor.
1582 //      Award player all powerups in mine.
1583 //      Place player just outside exit.
1584 //      Kill all bots in mine.
1585 //      Yippee!!
1586 void kill_and_so_forth(void)
1587 {
1588         int     i, j;
1589
1590         HUD_init_message("Killing, awarding, etc.!");
1591
1592         for (i=0; i<=Highest_object_index; i++) {
1593                 switch (Objects[i].type) {
1594                         case OBJ_ROBOT:
1595                                 Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1596                                 break;
1597                         case OBJ_POWERUP:
1598                                 do_powerup(&Objects[i]);
1599                                 break;
1600                 }
1601         }
1602
1603         do_controlcen_destroyed_stuff(NULL);
1604
1605         for (i=0; i<Num_triggers; i++) {
1606                 if (Triggers[i].type == TT_EXIT) {
1607                         for (j=0; j<Num_walls; j++) {
1608                                 if (Walls[j].trigger == i) {
1609                                         compute_segment_center(&ConsoleObject->pos, &Segments[Walls[j].segnum]);
1610                                         obj_relink(OBJECT_NUMBER(ConsoleObject), Walls[j].segnum);
1611                                         goto kasf_done;
1612                                 }
1613                         }
1614                 }
1615         }
1616
1617 kasf_done: ;
1618
1619 }
1620
1621 #ifndef RELEASE
1622
1623 void kill_all_snipers(void)
1624 {
1625         int     i, dead_count=0;
1626
1627         //      Kill all snipers.
1628         for (i=0; i<=Highest_object_index; i++)
1629                 if (Objects[i].type == OBJ_ROBOT)
1630                         if (Objects[i].ctype.ai_info.behavior == AIB_SNIPE) {
1631                                 dead_count++;
1632                                 Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1633                         }
1634
1635         HUD_init_message("%i robots toasted!", dead_count);
1636 }
1637
1638 void kill_thief(void)
1639 {
1640         int     i;
1641
1642         //      Kill thief.
1643         for (i=0; i<=Highest_object_index; i++)
1644                 if (Objects[i].type == OBJ_ROBOT)
1645                         if (Robot_info[Objects[i].id].thief) {
1646                                 Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1647                                 HUD_init_message("Thief toasted!");
1648                         }
1649 }
1650
1651 void kill_buddy(void)
1652 {
1653         int     i;
1654
1655         //      Kill buddy.
1656         for (i=0; i<=Highest_object_index; i++)
1657                 if (Objects[i].type == OBJ_ROBOT)
1658                         if (Robot_info[Objects[i].id].companion) {
1659                                 Objects[i].flags |= OF_EXPLODING|OF_SHOULD_BE_DEAD;
1660                                 HUD_init_message("Buddy toasted!");
1661                         }
1662 }
1663
1664 void toggle_movie_saving(void);
1665 extern char Language[];
1666
1667 void HandleTestKey(int key)
1668 {
1669         switch (key) {
1670
1671                 case KEY_DEBUGGED+KEY_0:        show_weapon_status();   break;
1672
1673                 #ifdef SHOW_EXIT_PATH
1674                 case KEY_DEBUGGED+KEY_1:        create_special_path();  break;
1675                 #endif
1676
1677                 case KEY_DEBUGGED+KEY_Y:
1678                         do_controlcen_destroyed_stuff(NULL);
1679                         break;
1680
1681 #ifdef NETWORK
1682         case KEY_DEBUGGED+KEY_ALTED+KEY_D:
1683                         Netlife_kills=4000; Netlife_killed=5;
1684                         multi_add_lifetime_kills();
1685                         break;
1686 #endif
1687
1688                 case KEY_BACKSP:
1689                 case KEY_CTRLED+KEY_BACKSP:
1690                 case KEY_ALTED+KEY_BACKSP:
1691                 case KEY_SHIFTED+KEY_BACKSP:
1692                 case KEY_SHIFTED+KEY_ALTED+KEY_BACKSP:
1693                 case KEY_CTRLED+KEY_ALTED+KEY_BACKSP:
1694                 case KEY_SHIFTED+KEY_CTRLED+KEY_BACKSP:
1695                 case KEY_SHIFTED+KEY_CTRLED+KEY_ALTED+KEY_BACKSP:
1696
1697                                 Int3(); break;
1698
1699                 case KEY_DEBUGGED+KEY_S:                                digi_reset(); break;
1700
1701                 case KEY_DEBUGGED+KEY_P:
1702                         if (Game_suspended & SUSP_ROBOTS)
1703                                 Game_suspended &= ~SUSP_ROBOTS;         //robots move
1704                         else
1705                                 Game_suspended |= SUSP_ROBOTS;          //robots don't move
1706                         break;
1707
1708
1709
1710                 case KEY_DEBUGGED+KEY_K:        Players[Player_num].shields = 1;        break;                                                  //      a virtual kill
1711                 case KEY_DEBUGGED+KEY_SHIFTED + KEY_K:  Players[Player_num].shields = -1;        break;  //     an actual kill
1712                 case KEY_DEBUGGED+KEY_X: Players[Player_num].lives++; break; // Extra life cheat key.
1713                 case KEY_DEBUGGED+KEY_H:
1714 //                              if (!(Game_mode & GM_MULTI) )   {
1715                                 Players[Player_num].flags ^= PLAYER_FLAGS_CLOAKED;
1716                                 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) {
1717                                         #ifdef NETWORK
1718                                         if (Game_mode & GM_MULTI)
1719                                                 multi_send_cloak();
1720                                         #endif
1721                                         ai_do_cloak_stuff();
1722                                         Players[Player_num].cloak_time = GameTime;
1723                                         mprintf((0, "You are cloaked!\n"));
1724                                 } else
1725                                         mprintf((0, "You are DE-cloaked!\n"));
1726 //                              }
1727                         break;
1728
1729
1730                 case KEY_DEBUGGED+KEY_R:
1731                         Robot_firing_enabled = !Robot_firing_enabled;
1732                         break;
1733
1734                 case KEY_DEBUGGED+KEY_R+KEY_SHIFTED:
1735                         kill_all_robots();
1736                         break;
1737
1738                 #ifdef EDITOR           //editor-specific functions
1739
1740                 case KEY_E + KEY_DEBUGGED:
1741 #ifdef NETWORK
1742                         network_leave_game();
1743 #endif
1744                         Function_mode = FMODE_EDITOR;
1745                         break;
1746         case KEY_Q + KEY_SHIFTED + KEY_DEBUGGED:
1747                 {
1748                         char pal_save[768];
1749                         memcpy(pal_save,gr_palette,768);
1750                         init_subtitles("end.tex");      //ingore errors
1751                         PlayMovie ("end.mve",MOVIE_ABORT_ON);
1752                         close_subtitles();
1753                         Screen_mode = -1;
1754                         set_screen_mode(SCREEN_GAME);
1755                         reset_cockpit();
1756                         memcpy(gr_palette,pal_save,768);
1757                         gr_palette_load(gr_palette);
1758                         break;
1759                 }
1760                 case KEY_C + KEY_SHIFTED + KEY_DEBUGGED:
1761                         if (!( Game_mode & GM_MULTI ))
1762                                 move_player_2_segment(Cursegp,Curside);
1763                         break;   //move eye to curseg
1764
1765
1766                 case KEY_DEBUGGED+KEY_W:        draw_world_from_game(); break;
1767
1768                 #endif  //#ifdef EDITOR
1769
1770                 //flythrough keys
1771                 // case KEY_DEBUGGED+KEY_SHIFTED+KEY_F: toggle_flythrough(); break;
1772                 // case KEY_LEFT:               ft_preference=FP_LEFT; break;
1773                 // case KEY_RIGHT:                              ft_preference=FP_RIGHT; break;
1774                 // case KEY_UP:         ft_preference=FP_UP; break;
1775                 // case KEY_DOWN:               ft_preference=FP_DOWN; break;
1776
1777 #ifndef NDEBUG
1778                 case KEY_DEBUGGED+KEY_LAPOSTRO: Show_view_text_timer = 0x30000; object_goto_next_viewer(); break;
1779                 case KEY_DEBUGGED+KEY_CTRLED+KEY_LAPOSTRO: Show_view_text_timer = 0x30000; object_goto_prev_viewer(); break;
1780 #endif
1781                 case KEY_DEBUGGED+KEY_SHIFTED+KEY_LAPOSTRO: Viewer=ConsoleObject; break;
1782
1783         #ifndef NDEBUG
1784                 case KEY_DEBUGGED+KEY_O: toggle_outline_mode(); break;
1785         #endif
1786                 case KEY_DEBUGGED+KEY_T:
1787                         *Toggle_var = !*Toggle_var;
1788                         mprintf((0, "Variable at %08x set to %i\n", Toggle_var, *Toggle_var));
1789                         break;
1790                 case KEY_DEBUGGED + KEY_L:
1791                         if (++Lighting_on >= 2) Lighting_on = 0; break;
1792                 case KEY_DEBUGGED + KEY_SHIFTED + KEY_L:
1793                         Beam_brightness=0x38000-Beam_brightness; break;
1794                 case KEY_PAD5: slew_stop(); break;
1795
1796 #ifndef NDEBUG
1797                 case KEY_DEBUGGED + KEY_F11: play_test_sound(); break;
1798                 case KEY_DEBUGGED + KEY_SHIFTED+KEY_F11: advance_sound(); play_test_sound(); break;
1799 #endif
1800
1801                 case KEY_DEBUGGED +KEY_F4: {
1802                         //fvi_info hit_data;
1803                         //vms_vector p0 = {-0x1d99a7,-0x1b20000,0x186ab7f};
1804                         //vms_vector p1 = {-0x217865,-0x1b20000,0x187de3e};
1805                         //find_vector_intersection(&hit_data,&p0,0x1b9,&p1,0x40000,0x0,NULL,-1);
1806                         break;
1807                 }
1808
1809                 case KEY_DEBUGGED + KEY_M:
1810                         Debug_spew = !Debug_spew;
1811                         if (Debug_spew) {
1812                                 mopen( 0, 8, 1, 78, 16, "Debug Spew");
1813                                 HUD_init_message( "Debug Spew: ON" );
1814                         } else {
1815                                 mclose( 0 );
1816                                 HUD_init_message( "Debug Spew: OFF" );
1817                         }
1818                         break;
1819
1820                 case KEY_DEBUGGED + KEY_C:
1821
1822                         full_palette_save();
1823                         do_cheat_menu();
1824                         palette_restore();
1825                         break;
1826                 case KEY_DEBUGGED + KEY_SHIFTED + KEY_A:
1827                         do_megawow_powerup(10);
1828                         break;
1829                 case KEY_DEBUGGED + KEY_A:      {
1830                         do_megawow_powerup(200);
1831 //                                                              if ( Game_mode & GM_MULTI )     {
1832 //                                                                      nm_messagebox( NULL, 1, "Damn", "CHEATER!\nYou cannot use the\nmega-thing in network mode." );
1833 //                                                                      Network_message_reciever = 100;         // Send to everyone...
1834 //                                                                      sprintf( Network_message, "%s cheated!", Players[Player_num].callsign);
1835 //                                                              } else {
1836 //                                                                      do_megawow_powerup();
1837 //                                                              }
1838                                                 break;
1839                 }
1840
1841                 case KEY_DEBUGGED+KEY_F:
1842                         cvar_toggle( &r_framerate );
1843                         break;
1844
1845                 case KEY_DEBUGGED+KEY_SPACEBAR:         //KEY_F7:                               // Toggle physics flying
1846                         slew_stop();
1847                         game_flush_inputs();
1848                         if ( ConsoleObject->control_type != CT_FLYING ) {
1849                                 fly_init(ConsoleObject);
1850                                 Game_suspended &= ~SUSP_ROBOTS; //robots move
1851                         } else {
1852                                 slew_init(ConsoleObject);                       //start player slewing
1853                                 Game_suspended |= SUSP_ROBOTS;  //robots don't move
1854                         }
1855                         break;
1856
1857                 case KEY_DEBUGGED+KEY_COMMA: Render_zoom = fixmul(Render_zoom,62259); break;
1858                 case KEY_DEBUGGED+KEY_PERIOD: Render_zoom = fixmul(Render_zoom,68985); break;
1859
1860                 case KEY_DEBUGGED+KEY_P+KEY_SHIFTED: Debug_pause = 1; break;
1861
1862                 //case KEY_F7: {
1863                 //      char mystr[30];
1864                 //      sprintf(mystr,"mark %i start",Mark_count);
1865                 //      _MARK_(mystr);
1866                 //      break;
1867                 //}
1868                 //case KEY_SHIFTED+KEY_F7: {
1869                 //      char mystr[30];
1870                 //      sprintf(mystr,"mark %i end",Mark_count);
1871                 //      Mark_count++;
1872                 //      _MARK_(mystr);
1873                 //      break;
1874                 //}
1875
1876
1877                 #ifndef NDEBUG
1878                 case KEY_DEBUGGED+KEY_F8: speedtest_init(); Speedtest_count = 1;         break;
1879                 case KEY_DEBUGGED+KEY_F9: speedtest_init(); Speedtest_count = 10;        break;
1880
1881                 case KEY_DEBUGGED+KEY_D:
1882                         if ((Game_double_buffer = !Game_double_buffer)!=0)
1883                                 init_cockpit();
1884                         break;
1885                 #endif
1886
1887                 #ifdef EDITOR
1888                 case KEY_DEBUGGED+KEY_Q:
1889                         stop_time();
1890                         dump_used_textures_all();
1891                         start_time();
1892                         break;
1893                 #endif
1894
1895                 case KEY_DEBUGGED+KEY_B: {
1896                         newmenu_item m;
1897                         char text[FILENAME_LEN]="";
1898                         int item;
1899                         m.type=NM_TYPE_INPUT; m.text_len = FILENAME_LEN; m.text = text;
1900                         item = newmenu_do( NULL, "Briefing to play?", 1, &m, NULL );
1901                         if (item != -1) {
1902                                 do_briefing_screens(text,1);
1903                                 reset_cockpit();
1904                         }
1905                         break;
1906                 }
1907
1908                 case KEY_DEBUGGED+KEY_F5:
1909                         toggle_movie_saving();
1910                         break;
1911
1912                 case KEY_DEBUGGED+KEY_SHIFTED+KEY_F5: {
1913                         extern int Movie_fixed_frametime;
1914                         Movie_fixed_frametime = !Movie_fixed_frametime;
1915                         break;
1916                 }
1917
1918                 case KEY_DEBUGGED+KEY_ALTED+KEY_F5:
1919                         GameTime = i2f(0x7fff - 840);           //will overflow in 14 minutes
1920                         mprintf((0,"GameTime bashed to %d secs\n",f2i(GameTime)));
1921                         break;
1922
1923                 case KEY_DEBUGGED+KEY_SHIFTED+KEY_B:
1924                         kill_and_so_forth();
1925                         break;
1926         }
1927 }
1928 #endif          //#ifndef RELEASE
1929
1930 //      Cheat functions ------------------------------------------------------------
1931 extern char *jcrypt (char *);
1932
1933 char *LamerCheats[]={   "!UyN#E$I",     // gabba-gabbahey
1934                                                                 "ei5cQ-ZQ", // mo-therlode
1935                                                                 "q^EpZxs8", // c-urrygoat
1936                                                                 "mxk(DyyP", // zi-ngermans
1937                                                                 "cBo#@y@P", // ea-tangelos
1938                                                                 "CLygLBGQ", // e-ricaanne
1939                                                                 "xAnHQxZX", // jos-huaakira
1940                                                                 "cKc[KUWo", // wh-ammazoom
1941                                                         };
1942
1943 #define N_LAMER_CHEATS (sizeof(LamerCheats) / sizeof(*LamerCheats))
1944
1945 char *WowieCheat        ="F_JMO3CV";    //only Matt knows / h-onestbob
1946 char *AllKeysCheat      ="%v%MrgbU";    //only Matt knows / or-algroove
1947 char *InvulCheat        ="Wv_\\JJ\\Z";  //only Matt knows / almighty
1948 char *HomingCheatString ="t\\LIhSB[";   //only Matt knows / l-pnlizard
1949 char *BouncyCheat       ="bGbiChQJ";    //only Matt knows / duddaboo
1950 char *FullMapCheat      ="PI<XQHRI";    //only Matt knows / rockrgrl
1951 char *LevelWarpCheat    ="ZQHtqbb\"";   //only Matt knows / f-reespace
1952 char *MonsterCheat      ="nfpEfRQp";    //only Matt knows / godzilla
1953 char *BuddyLifeCheat    ="%A-BECuY";    //only Matt knows / he-lpvishnu
1954 char *BuddyDudeCheat    ="u#uzIr%e";    //only Matt knows / g-owingnut
1955 char *KillRobotsCheat   ="&wxbs:5O";    //only Matt knows / spaniard
1956 char *FinishLevelCheat  ="%bG_bZ<D";    //only Matt knows / d-elshiftb
1957 char *RapidFireCheat    ="*jLgHi'J";    //only Matt knows / wildfire
1958
1959 char *RobotsKillRobotsCheat ="rT6xD__S"; // New for 1.1 / silkwing
1960 char *AhimsaCheat       ="!Uscq_yc";    // New for 1.1 / im-agespace 
1961
1962 char *AccessoryCheat    ="dWdz[kCK";    // al-ifalafel
1963 char *JohnHeadCheat     ="ou]];H:%";    // p-igfarmer
1964 char *AcidCheat         ="qPmwxz\"S";   // bit-tersweet
1965 char *FramerateCheat    ="rQ60#ZBN";    // f-rametime
1966
1967 char CheatBuffer[]="AAAAAAAAAAAAAAA";
1968
1969 #define CHEATSPOT 14
1970 #define CHEATEND 15
1971
1972 void do_cheat_penalty ()
1973  {
1974   digi_play_sample( SOUND_CHEATER, F1_0);
1975   Cheats_enabled=1;
1976   Players[Player_num].score=0;
1977  }
1978
1979
1980 //      Main Cheat function
1981
1982 char BounceCheat=0;
1983 char HomingCheat=0;
1984 char john_head_on=0;
1985 char AcidCheatOn=0;
1986 char old_IntMethod;
1987 char OldHomingState[20];
1988 extern char Monster_mode;
1989
1990 void fill_background();
1991 void load_background_bitmap();
1992
1993 extern int Robots_kill_robots_cheat;
1994
1995 void FinalCheats(int key)
1996 {
1997   int i;
1998   char *cryptstring;
1999
2000   key=key_to_ascii(key);
2001
2002   for (i=0;i<15;i++)
2003    CheatBuffer[i]=CheatBuffer[i+1];
2004
2005   CheatBuffer[CHEATSPOT]=key;
2006
2007   cryptstring=jcrypt(&CheatBuffer[7]);
2008
2009         for (i=0;i<N_LAMER_CHEATS;i++)
2010           if (!(strcmp (cryptstring,LamerCheats[i])))
2011                         {
2012                                  do_cheat_penalty();
2013                                  Players[Player_num].shields=i2f(1);
2014                                  Players[Player_num].energy=i2f(1);
2015 #ifdef NETWORK
2016                   if (Game_mode & GM_MULTI)
2017                         {
2018                          Network_message_reciever = 100;                // Send to everyone...
2019                                 sprintf( Network_message, "%s is crippled...get him!",Players[Player_num].callsign);
2020                         }
2021 #endif
2022                         HUD_init_message ("Take that...cheater!");
2023                 }
2024
2025   if (!(strcmp (cryptstring,JohnHeadCheat)))
2026                 {
2027                                 john_head_on = !john_head_on;
2028                                 load_background_bitmap();
2029                                 fill_background();
2030                                 HUD_init_message (john_head_on?"Hi John!!":"Bye John!!");
2031                 }
2032   if (!(strcmp (cryptstring,AcidCheat)))
2033                 {
2034                                 if (AcidCheatOn)
2035                                 {
2036                                  AcidCheatOn=0;
2037                                  Interpolation_method=old_IntMethod;
2038                                  HUD_init_message ("Coming down...");
2039                                 }
2040                                 else
2041                                 {
2042                                  AcidCheatOn=1;
2043                                  old_IntMethod=Interpolation_method;
2044                                  Interpolation_method=1;
2045                                  HUD_init_message ("Going up!");
2046                                 }
2047
2048                 }
2049
2050   if (!(strcmp (cryptstring,FramerateCheat)))
2051                 {
2052                         cvar_toggle( &r_framerate );
2053                 }
2054
2055   if (Game_mode & GM_MULTI)
2056    return;
2057
2058   if (!(strcmp (&CheatBuffer[8],"blueorb")))
2059    {
2060                 if (Players[Player_num].shields < MAX_SHIELDS) {
2061                         fix boost = 3*F1_0 + 3*F1_0*(NDL - Difficulty_level);
2062                         if (Difficulty_level == 0)
2063                                 boost += boost/2;
2064                         Players[Player_num].shields += boost;
2065                         if (Players[Player_num].shields > MAX_SHIELDS)
2066                                 Players[Player_num].shields = MAX_SHIELDS;
2067                         powerup_basic(0, 0, 15, SHIELD_SCORE, "%s %s %d",TXT_SHIELD,TXT_BOOSTED_TO,f2ir(Players[Player_num].shields));
2068                         do_cheat_penalty();
2069                 } else
2070                         HUD_init_message(TXT_MAXED_OUT,TXT_SHIELD);
2071    }
2072
2073   if (!(strcmp(cryptstring,BuddyLifeCheat)))
2074    {
2075          do_cheat_penalty();
2076          HUD_init_message ("What's this? Another buddy bot!");
2077          create_buddy_bot();
2078    }
2079
2080
2081   if (!(strcmp(cryptstring,BuddyDudeCheat)))
2082    {
2083          do_cheat_penalty();
2084          Buddy_dude_cheat = !Buddy_dude_cheat;
2085          if (Buddy_dude_cheat) {
2086                 HUD_init_message ("%s gets angry!",guidebot_name);
2087                 strcpy(guidebot_name,"Wingnut");
2088          }
2089          else {
2090                 strcpy(guidebot_name,real_guidebot_name);
2091                 HUD_init_message ("%s calms down",guidebot_name);
2092          }
2093   }
2094
2095
2096   if (!(strcmp(cryptstring,MonsterCheat)))
2097    {
2098     Monster_mode=1-Monster_mode;
2099          do_cheat_penalty();
2100          HUD_init_message (Monster_mode?"Oh no, there goes Tokyo!":"What have you done, I'm shrinking!!");
2101    }
2102
2103
2104   if (!(strcmp (cryptstring,BouncyCheat)))
2105         {
2106                 do_cheat_penalty();
2107                 HUD_init_message ("Bouncing weapons!");
2108                 BounceCheat=1;
2109         }
2110
2111         if (!(strcmp(cryptstring,LevelWarpCheat)))
2112          {
2113                 newmenu_item m;
2114                 char text[10]="";
2115                 int new_level_num;
2116                 int item;
2117                 //digi_play_sample( SOUND_CHEATER, F1_0);
2118                 m.type=NM_TYPE_INPUT; m.text_len = 10; m.text = text;
2119                 item = newmenu_do( NULL, TXT_WARP_TO_LEVEL, 1, &m, NULL );
2120                 if (item != -1) {
2121                         new_level_num = atoi(m.text);
2122                         if (new_level_num!=0 && new_level_num>=0 && new_level_num<=Last_level) {
2123                                 StartNewLevel(new_level_num, 0);
2124                                 do_cheat_penalty();
2125                         }
2126                 }
2127          }
2128
2129   if (!(strcmp (cryptstring,WowieCheat)))
2130         {
2131
2132                                 HUD_init_message(TXT_WOWIE_ZOWIE);
2133                 do_cheat_penalty();
2134
2135                         if (Piggy_hamfile_version < 3) // SHAREWARE
2136                         {
2137                                 Players[Player_num].primary_weapon_flags = ~((1<<PHOENIX_INDEX) | (1<<OMEGA_INDEX) | (1<<FUSION_INDEX) | HAS_FLAG(SUPER_LASER_INDEX));
2138                                 Players[Player_num].secondary_weapon_flags = ~((1<<SMISSILE4_INDEX) | (1<<MEGA_INDEX) | (1<<SMISSILE5_INDEX));
2139                         }
2140                         else
2141                         {
2142                                 Players[Player_num].primary_weapon_flags = 0xffff ^ HAS_FLAG(SUPER_LASER_INDEX);                //no super laser
2143                                 Players[Player_num].secondary_weapon_flags = 0xffff;
2144                         }
2145
2146                         for (i=0; i<MAX_PRIMARY_WEAPONS; i++)
2147                                         Players[Player_num].primary_ammo[i] = Primary_ammo_max[i];
2148
2149                                 for (i=0; i<MAX_SECONDARY_WEAPONS; i++)
2150                                         Players[Player_num].secondary_ammo[i] = Secondary_ammo_max[i];
2151
2152                                 if (Piggy_hamfile_version < 3) // SHAREWARE
2153                                 {
2154                                         Players[Player_num].secondary_ammo[SMISSILE4_INDEX] = 0;
2155                                         Players[Player_num].secondary_ammo[SMISSILE5_INDEX] = 0;
2156                                         Players[Player_num].secondary_ammo[MEGA_INDEX] = 0;
2157                                 }
2158
2159                                 if (Game_mode & GM_HOARD)
2160                                         Players[Player_num].secondary_ammo[PROXIMITY_INDEX] = 12;
2161
2162                                 if (Newdemo_state == ND_STATE_RECORDING)
2163                                         newdemo_record_laser_level(Players[Player_num].laser_level, MAX_LASER_LEVEL);
2164
2165                                 Players[Player_num].energy = MAX_ENERGY;
2166                                 Players[Player_num].laser_level = MAX_SUPER_LASER_LEVEL;
2167                                 Players[Player_num].flags |= PLAYER_FLAGS_QUAD_LASERS;
2168                                 update_laser_weapon_info();
2169         }
2170
2171
2172   if (!(strcmp (cryptstring,AllKeysCheat)))
2173         {
2174                 do_cheat_penalty();
2175                                 HUD_init_message(TXT_ALL_KEYS);
2176                                 Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY;
2177         }
2178
2179
2180   if (!(strcmp (cryptstring,InvulCheat)))
2181                 {
2182                 do_cheat_penalty();
2183                                 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
2184                                 HUD_init_message("%s %s!", TXT_INVULNERABILITY, (Players[Player_num].flags&PLAYER_FLAGS_INVULNERABLE)?TXT_ON:TXT_OFF);
2185                                 Players[Player_num].invulnerable_time = GameTime+i2f(1000);
2186                 }
2187   if (!(strcmp (cryptstring,AccessoryCheat)))
2188                 {
2189                                 do_cheat_penalty();
2190                                 Players[Player_num].flags |=PLAYER_FLAGS_HEADLIGHT;
2191                                 Players[Player_num].flags |=PLAYER_FLAGS_AFTERBURNER;
2192                                 Players[Player_num].flags |=PLAYER_FLAGS_AMMO_RACK;
2193                                 Players[Player_num].flags |=PLAYER_FLAGS_CONVERTER;
2194
2195                                 HUD_init_message ("Accessories!!");
2196                 }
2197   if (!(strcmp (cryptstring,FullMapCheat)))
2198                 {
2199                                 do_cheat_penalty();
2200                                 Players[Player_num].flags |=PLAYER_FLAGS_MAP_ALL;
2201
2202                                 HUD_init_message ("Full Map!!");
2203                 }
2204
2205
2206   if (!(strcmp (cryptstring,HomingCheatString)))
2207                 {
2208                         if (!HomingCheat) {
2209                                 do_cheat_penalty();
2210                                 HomingCheat=1;
2211                                 for (i=0;i<20;i++)
2212                                  {
2213                                   OldHomingState[i]=Weapon_info[i].homing_flag;
2214                                   Weapon_info[i].homing_flag=1;
2215                                  }
2216                                 HUD_init_message ("Homing weapons!");
2217                         }
2218                 }
2219
2220   if (!(strcmp (cryptstring,KillRobotsCheat)))
2221                 {
2222                                 do_cheat_penalty();
2223                                 kill_all_robots();
2224                 }
2225
2226   if (!(strcmp (cryptstring,FinishLevelCheat)))
2227                 {
2228                                 do_cheat_penalty();
2229                                 kill_and_so_forth();
2230                 }
2231
2232         if (!(strcmp (cryptstring,RobotsKillRobotsCheat))) {
2233                 Robots_kill_robots_cheat = !Robots_kill_robots_cheat;
2234                 if (Robots_kill_robots_cheat) {
2235                         HUD_init_message ("Rabid robots!");
2236                         do_cheat_penalty();
2237                 }
2238                 else
2239                         HUD_init_message ("Kill the player!");
2240         }
2241
2242         if (!(strcmp (cryptstring,AhimsaCheat))) {
2243                 Robot_firing_enabled = !Robot_firing_enabled;
2244                 if (!Robot_firing_enabled) {
2245                         HUD_init_message("%s", "Robot firing OFF!");
2246                         do_cheat_penalty();
2247                 }
2248                 else
2249                         HUD_init_message("%s", "Robot firing ON!");
2250         }
2251
2252         if (!(strcmp (cryptstring,RapidFireCheat))) {
2253                 if (Laser_rapid_fire) {
2254                         Laser_rapid_fire = 0;
2255                         HUD_init_message("%s", "Rapid fire OFF!");
2256                 }
2257                 else {
2258                         Laser_rapid_fire = 0xbada55;
2259                         do_cheat_penalty();
2260                         HUD_init_message("%s", "Rapid fire ON!");
2261                 }
2262         }
2263
2264 }
2265
2266
2267 // Internal Cheat Menu
2268 #ifndef RELEASE
2269 void do_cheat_menu()
2270 {
2271         int mmn;
2272         newmenu_item mm[16];
2273         char score_text[21];
2274
2275         sprintf( score_text, "%d", Players[Player_num].score );
2276
2277         mm[0].type=NM_TYPE_CHECK; mm[0].value=Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE; mm[0].text="Invulnerability";
2278         mm[1].type=NM_TYPE_CHECK; mm[1].value=Players[Player_num].flags & PLAYER_FLAGS_CLOAKED; mm[1].text="Cloaked";
2279         mm[2].type=NM_TYPE_CHECK; mm[2].value=0; mm[2].text="All keys";
2280         mm[3].type=NM_TYPE_NUMBER; mm[3].value=f2i(Players[Player_num].energy); mm[3].text="% Energy"; mm[3].min_value=0; mm[3].max_value=200;
2281         mm[4].type=NM_TYPE_NUMBER; mm[4].value=f2i(Players[Player_num].shields); mm[4].text="% Shields"; mm[4].min_value=0; mm[4].max_value=200;
2282         mm[5].type=NM_TYPE_TEXT; mm[5].text = "Score:";
2283         mm[6].type=NM_TYPE_INPUT; mm[6].text_len = 10; mm[6].text = score_text;
2284         //mm[7].type=NM_TYPE_RADIO; mm[7].value=(Players[Player_num].laser_level==0); mm[7].group=0; mm[7].text="Laser level 1";
2285         //mm[8].type=NM_TYPE_RADIO; mm[8].value=(Players[Player_num].laser_level==1); mm[8].group=0; mm[8].text="Laser level 2";
2286         //mm[9].type=NM_TYPE_RADIO; mm[9].value=(Players[Player_num].laser_level==2); mm[9].group=0; mm[9].text="Laser level 3";
2287         //mm[10].type=NM_TYPE_RADIO; mm[10].value=(Players[Player_num].laser_level==3); mm[10].group=0; mm[10].text="Laser level 4";
2288
2289         mm[7].type=NM_TYPE_NUMBER; mm[7].value=Players[Player_num].laser_level+1; mm[7].text="Laser Level"; mm[7].min_value=0; mm[7].max_value=MAX_SUPER_LASER_LEVEL+1;
2290         mm[8].type=NM_TYPE_NUMBER; mm[8].value=Players[Player_num].secondary_ammo[CONCUSSION_INDEX]; mm[8].text="Missiles"; mm[8].min_value=0; mm[8].max_value=200;
2291
2292         mmn = newmenu_do("Wimp Menu",NULL,9, mm, NULL );
2293
2294         if (mmn > -1 )  {
2295                 if ( mm[0].value )  {
2296                         Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2297                         Players[Player_num].invulnerable_time = GameTime+i2f(1000);
2298                 } else
2299                         Players[Player_num].flags &= ~PLAYER_FLAGS_INVULNERABLE;
2300                 if ( mm[1].value ) {
2301                         Players[Player_num].flags |= PLAYER_FLAGS_CLOAKED;
2302                         #ifdef NETWORK
2303                         if (Game_mode & GM_MULTI)
2304                                 multi_send_cloak();
2305                         #endif
2306                         ai_do_cloak_stuff();
2307                         Players[Player_num].cloak_time = GameTime;
2308                 }
2309                 else
2310                         Players[Player_num].flags &= ~PLAYER_FLAGS_CLOAKED;
2311
2312                 if (mm[2].value) Players[Player_num].flags |= PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY;
2313                 Players[Player_num].energy=i2f(mm[3].value);
2314                 Players[Player_num].shields=i2f(mm[4].value);
2315                 Players[Player_num].score = atoi(mm[6].text);
2316                 //if (mm[7].value) Players[Player_num].laser_level=0;
2317                 //if (mm[8].value) Players[Player_num].laser_level=1;
2318                 //if (mm[9].value) Players[Player_num].laser_level=2;
2319                 //if (mm[10].value) Players[Player_num].laser_level=3;
2320                 Players[Player_num].laser_level = mm[7].value-1;
2321                 Players[Player_num].secondary_ammo[CONCUSSION_INDEX] = mm[8].value;
2322                 init_gauges();
2323         }
2324 }
2325 #endif
2326
2327
2328
2329 //      Testing functions ----------------------------------------------------------
2330
2331 #ifndef NDEBUG
2332 void speedtest_init(void)
2333 {
2334         Speedtest_start_time = timer_get_fixed_seconds();
2335         Speedtest_on = 1;
2336         Speedtest_segnum = 0;
2337         Speedtest_sidenum = 0;
2338         Speedtest_frame_start = FrameCount;
2339
2340         mprintf((0, "Starting speedtest.  Will be %i frames.  Each . = 10 frames.\n", Highest_segment_index+1));
2341 }
2342
2343 void speedtest_frame(void)
2344 {
2345         vms_vector      view_dir, center_point;
2346
2347         Speedtest_sidenum=Speedtest_segnum % MAX_SIDES_PER_SEGMENT;
2348
2349         compute_segment_center(&Viewer->pos, &Segments[Speedtest_segnum]);
2350         Viewer->pos.x += 0x10;          Viewer->pos.y -= 0x10;          Viewer->pos.z += 0x17;
2351
2352         obj_relink(OBJECT_NUMBER(Viewer), Speedtest_segnum);
2353         compute_center_point_on_side(&center_point, &Segments[Speedtest_segnum], Speedtest_sidenum);
2354         vm_vec_normalized_dir_quick(&view_dir, &center_point, &Viewer->pos);
2355         vm_vector_2_matrix(&Viewer->orient, &view_dir, NULL, NULL);
2356
2357         if (((FrameCount - Speedtest_frame_start) % 10) == 0)
2358                 mprintf((0, "."));
2359
2360         Speedtest_segnum++;
2361
2362         if (Speedtest_segnum > Highest_segment_index) {
2363                 char    msg[128];
2364
2365                 sprintf(msg, "\nSpeedtest done:  %i frames, %7.3f seconds, %7.3f frames/second.\n",
2366                         FrameCount-Speedtest_frame_start,
2367                         f2fl(timer_get_fixed_seconds() - Speedtest_start_time),
2368                         (float) (FrameCount-Speedtest_frame_start) / f2fl(timer_get_fixed_seconds() - Speedtest_start_time));
2369
2370                 mprintf((0, "%s", msg));
2371                 HUD_init_message(msg);
2372
2373                 Speedtest_count--;
2374                 if (Speedtest_count == 0)
2375                         Speedtest_on = 0;
2376                 else
2377                         speedtest_init();
2378         }
2379
2380 }
2381
2382
2383 //      Sounds for testing
2384
2385 int test_sound_num = 0;
2386 int sound_nums[] = {10,11,20,21,30,31,32,33,40,41,50,51,60,61,62,70,80,81,82,83,90,91};
2387
2388 #define N_TEST_SOUNDS (sizeof(sound_nums) / sizeof(*sound_nums))
2389
2390
2391 void advance_sound()
2392 {
2393         if (++test_sound_num == N_TEST_SOUNDS)
2394                 test_sound_num=0;
2395
2396 }
2397
2398
2399 int     Test_sound = 251;
2400
2401 void play_test_sound()
2402 {
2403
2404         // -- digi_play_sample(sound_nums[test_sound_num], F1_0);
2405         digi_play_sample(Test_sound, F1_0);
2406 }
2407
2408 #endif  //ifndef NDEBUG
2409
2410
2411
2412
2413
2414 void ReadControls()
2415 {
2416         int key;
2417         fix key_time;
2418         static ubyte exploding_flag=0;
2419
2420         Player_fired_laser_this_frame=-1;
2421
2422         if (!Endlevel_sequence) // && !Player_is_dead  //this was taken out of the if statement by WraithX
2423         {
2424
2425                         if ( (Newdemo_state == ND_STATE_PLAYBACK) || DefiningMarkerMessage || CON_isVisible()
2426                                 #ifdef NETWORK
2427                                 || multi_sending_message || multi_defining_message
2428                                 #endif
2429                                 )        // WATCH OUT!!! WEIRD CODE ABOVE!!!
2430                                 memset( &Controls, 0, sizeof(control_info) );
2431                         else
2432                                 #ifdef WINDOWS
2433                                         controls_read_all_win();
2434                                 #else
2435                                         controls_read_all();            //NOTE LINK TO ABOVE!!!
2436                                 #endif
2437
2438                 controls_read_console();
2439                 check_rear_view();
2440
2441                 //      If automap key pressed, enable automap unless you are in network mode, control center destroyed and < 10 seconds left
2442                 if ( Controls.automap_down_count && !((Game_mode & GM_MULTI) && Control_center_destroyed && (Countdown_seconds_left < 10)))
2443                         Automap_flag = 1;
2444
2445                 do_weapon_stuff();
2446
2447         }
2448
2449         if (Player_exploded) { //Player_is_dead && (ConsoleObject->flags & OF_EXPLODING) ) {
2450
2451                 if (exploding_flag==0)  {
2452                         exploding_flag = 1;                     // When player starts exploding, clear all input devices...
2453                         game_flush_inputs();
2454                 } else {
2455                         int i;
2456                         //if (key_down_count(KEY_BACKSP))
2457                         //      Int3();
2458                         //if (key_down_count(KEY_PRINT_SCREEN))
2459                         //      save_screen_shot(0);
2460
2461 #ifndef MACINTOSH
2462                         for (i = 0; i < 4; i++)
2463                                 // the following "if" added by WraithX, 4/17/00
2464                                 if (isJoyRotationKey(i) != 1)
2465                                 {
2466                                         if (joy_get_button_down_cnt(i) > 0)
2467                                                 Death_sequence_aborted = 1;
2468                                 }// end "if" added by WraithX
2469 #else
2470                         if (joy_get_any_button_down_cnt() > 0)
2471                                 Death_sequence_aborted = 1;
2472 #endif
2473                         for (i = 0; i < 3; i++)
2474                                 // the following "if" added by WraithX, 4/17/00
2475                                 if (isMouseRotationKey(i) != 1)
2476                                 {
2477                                         if (mouse_button_down_count(i) > 0)
2478                                                 Death_sequence_aborted = 1;
2479                                 }// end "if" added by WraithX
2480
2481                         //for (i = 0; i < 256; i++)
2482                         //      // the following "if" added by WraithX, 4/17/00
2483                         //      if (isKeyboardRotationKey(i) != 1)
2484                         //      {
2485                         //              if (!key_isfunc(i) && !key_ismod(i) && key_down_count(i) > 0)
2486                         //                      Death_sequence_aborted = 1;
2487                         //      }// end "if" added by WraithX
2488
2489                         if (Death_sequence_aborted)
2490                                 game_flush_inputs();
2491                 }
2492         } else {
2493                 exploding_flag=0;
2494         }
2495
2496         if (Newdemo_state == ND_STATE_PLAYBACK )
2497                 update_vcr_state();
2498
2499         while ((key=key_inkey_time(&key_time)) != 0)    {
2500
2501                 if (DefiningMarkerMessage)
2502                  {
2503                         MarkerInputMessage (key);
2504                         continue;
2505                  }
2506
2507                 #ifdef NETWORK
2508                 if ( (Game_mode&GM_MULTI) && (multi_sending_message || multi_defining_message ))        {
2509                         multi_message_input_sub( key );
2510                         continue;               //get next key
2511                 }
2512                 #endif
2513
2514                 #ifndef RELEASE
2515                 #ifdef NETWORK
2516                 if ((key&KEY_DEBUGGED)&&(Game_mode&GM_MULTI))   {
2517                         Network_message_reciever = 100;         // Send to everyone...
2518                         sprintf( Network_message, "%s %s", TXT_I_AM_A, TXT_CHEATER);
2519                 }
2520                 #endif
2521                 #endif
2522
2523                 if(!CON_Events(key))
2524                         continue;
2525
2526                 if (Player_is_dead)
2527                         HandleDeathKey(key);
2528
2529                 if (Endlevel_sequence)
2530                         HandleEndlevelKey(key);
2531                 else if (Newdemo_state == ND_STATE_PLAYBACK ) {
2532                         HandleDemoKey(key);
2533
2534                         #ifndef RELEASE
2535                         HandleTestKey(key);
2536                         #endif
2537                 } else {
2538                         FinalCheats(key);
2539
2540                         HandleSystemKey(key);
2541                         HandleVRKey(key);
2542                         HandleGameKey(key);
2543
2544                         #ifndef RELEASE
2545                         HandleTestKey(key);
2546                         #endif
2547                 }
2548         }
2549
2550
2551 //      if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[KEY_F8] && (keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT]))
2552   //            transfer_energy_to_shield(key_down_time(KEY_F8));
2553 }
2554