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