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