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