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