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