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