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