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