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