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