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