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