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