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