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