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