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