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