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