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