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