2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Game loop for Inferno
30 #define _USE_MATH_DEFINES
34 #include <StandardFile.h>
35 #include <Quickdraw.h>
59 #include "editor/editor.h"
66 //#define TEST_TIMER 1 //if this is set, do checking on timer
68 #define SHOW_EXIT_PATH 1
72 #if __WATCOMC__ < 1000
73 #include <wsample.h> //should come after inferno.h to get mark setting
78 extern void ReadControls(void); // located in gamecntl.c
79 extern void do_final_boss_frame(void);
84 int Mark_count = 0; // number of debugging marks set
85 int Speedtest_start_time;
87 int Speedtest_sidenum;
88 int Speedtest_frame_start;
89 int Speedtest_count=0; // number of times to do the debug test.
92 static fix last_timer_value=0;
95 #if defined(TIMER_TEST) && !defined(NDEBUG)
96 fix _timer_value,actual_last_timer_value,_last_frametime;
97 int stop_count,start_count;
98 int time_stopped,time_started;
101 uint32_t VR_screen_mode = 0;
103 ubyte VR_screen_flags = 0; //see values in screens.h
104 ubyte VR_current_page = 0;
105 fix VR_eye_width = F1_0;
106 int VR_render_mode = VR_NONE;
107 int VR_low_res = 3; // Default to low res
109 int VR_sensitivity = 1; // 0 - 2
112 int VR_eye_offset = 0;
113 int VR_eye_switch = 0;
114 int VR_eye_offset_changed = 0;
115 int VR_use_reg_code = 0;
117 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
118 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
119 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
120 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
121 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
123 //do menus work in 640x480 or 320x200?
124 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
125 int MenuHiresAvailable = 1; //can we do highres menus?
126 cvar_t menu_use_game_res = { "MenuGameres", "0", CVAR_ARCHIVE };
128 int Debug_pause=0; //John's debugging pause system
130 cvar_t Cockpit_mode = { "CockpitMode", "0", CVAR_ARCHIVE }; // CM_FULL_COCKPIT, see game.h for values
132 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
133 int force_cockpit_redraw=0;
136 cvar_t r_framerate = { "show_fps", "0", CVAR_NONE };
137 cvar_t cg_fov = { "fov", "30", CVAR_NONE };
139 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
141 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
143 int *Toggle_var = &Dummy_var;
146 //flag for whether initial fade-in has been done
150 #ifndef NDEBUG //these only exist if debugging
152 int Game_double_buffer = 1; //double buffer by default
153 fix fixed_frametime=0; //if non-zero, set frametime to this
157 int Game_suspended=0; //if non-zero, nothing moves but player
160 fix Auto_fire_fusion_cannon_time = 0;
161 fix Fusion_charge = 0;
162 fix Fusion_next_sound_time = 0;
163 fix Fusion_last_sound_time = 0;
166 int Game_turbo_mode = 0;
168 int Game_mode = GM_GAME_OVER;
170 int Global_laser_firing_count = 0;
171 int Global_missile_firing_count = 0;
173 grs_bitmap background_bitmap;
177 #define BACKGROUND_NAME "statback.pcx"
179 // Function prototypes for GAME.C exclusively.
181 void GameLoop(int RenderFlag, int ReadControlsFlag);
182 void FireLaser(void);
183 void slide_textures(void);
184 void powerup_grab_cheat_all(void);
187 extern void multi_check_for_killgoal_winner(void);
188 extern void RestoreGameSurfaces(void);
192 void grow_window(void);
193 void shrink_window(void);
197 void fill_background(void);
200 void show_framerate(void);
201 void ftoa(char *string, fix f);
204 extern ubyte DefiningMarkerMessage;
205 extern char Marker_input[];
207 // ==============================================================================================
209 extern char john_head_on;
211 void load_background_bitmap()
216 if (background_bitmap.bm_data)
217 d_free(background_bitmap.bm_data);
219 background_bitmap.bm_data=NULL;
220 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
221 if (pcx_error != PCX_ERROR_NONE)
222 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
223 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
228 void game_cmd_player(int argc, char **argv)
230 if (argc < 2 || argc > 2) {
231 cmd_insertf("help %s", argv[0]);
235 strncpy(Players[Player_num].callsign, argv[1], CALLSIGN_LEN);
237 WriteConfigFile(); // Update lastplr
242 void game_cmd_map(int argc, char **argv)
246 if (argc < 2 || argc > 3) {
247 cmd_insertf("help %s", argv[0]);
251 if (!strlen(Players[Player_num].callsign)) {
252 con_printf(CON_CRITICAL, "map: no player selected, not starting level\n");
256 load_mission_by_name(argv[1]);
259 level_num = atoi(argv[2]);
263 if (level_num > Last_level)
264 level_num = Last_level;
265 if (level_num < Last_secret_level)
266 level_num = Last_secret_level;
268 StartNewGame(level_num);
272 /* send network message */
273 void game_cmd_say(int argc, char **argv)
280 cmd_insertf("help %s", argv[0]);
285 Network_message[0] = 0;
287 ret = snprintf(Network_message, MAX_MESSAGE_LEN, "%s", argv[1]);
288 if (ret >= MAX_MESSAGE_LEN) {
289 con_printf(CON_CRITICAL, "say: message too long (max %d characters)\n", MAX_MESSAGE_LEN);
293 for (i = 2; i < argc; i++) {
294 strncat(Network_message, " ", sizeof(Network_message)-strlen(Network_message)-1);
295 strncat(Network_message, argv[i], sizeof(Network_message)-strlen(Network_message)-1);
296 ret = strlen(Network_message);
297 if (ret >= MAX_MESSAGE_LEN) {
298 con_printf(CON_CRITICAL, "say: message too long (max %d characters)\n", MAX_MESSAGE_LEN);
303 multi_send_message_end();
308 /* increase window size */
309 void game_cmd_sizeup(int argc, char **argv)
312 cmd_insertf("help %s", argv[0]);
320 /* decrease window size */
321 void game_cmd_sizedown(int argc, char **argv)
324 cmd_insertf("help %s", argv[0]);
332 /* start recording demo */
333 void game_cmd_recorddemo(int argc, char **argv)
336 cmd_insertf("help %s", argv[0]);
340 if ( Newdemo_state != ND_STATE_NORMAL )
343 if (Game_paused) // can't start demo while paused
346 newdemo_start_recording();
350 /* stop recording demo */
351 void game_cmd_stoprecording(int argc, char **argv)
354 cmd_insertf("help %s", argv[0]);
358 if ( Newdemo_state != ND_STATE_RECORDING )
361 newdemo_stop_recording();
365 //this is called once per game
368 atexit(close_game); //for cleanup
372 init_special_effects();
376 init_exploding_walls();
378 load_background_bitmap();
380 Clear_window = 2; // do portal only window clear.
382 set_detail_level_parameters(Detail_level);
385 cvar_registervariable(&r_framerate);
386 cvar_registervariable(&cg_fov);
387 cvar_registervariable(&Player_highest_level);
388 cvar_registervariable(&Cheats_enabled);
391 cmd_addcommand("player", game_cmd_player, "player <name>\n" " set player name to <name>");
392 cmd_addcommand("map", game_cmd_map, "map <name> [num]\n" " start level <num> of mission <name> (defaults to level 1)");
393 cmd_addcommand("say", game_cmd_say, "say <text>\n" " send the message <text> to the network");
394 cmd_addcommand("sizeup", game_cmd_sizeup, "sizeup\n" " increase the game window size");
395 cmd_addcommand("sizedown", game_cmd_sizedown, "sizedown\n" " decrease the game window size");
396 cmd_addcommand("recorddemo", game_cmd_recorddemo, "recorddemo\n" " start recording a demo");
397 cmd_addcommand("stoprecording", game_cmd_stoprecording, "stoprecording\n" " stop recording the current demo");
404 void reset_palette_add()
409 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
413 void game_show_warning(char *s)
416 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
419 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
421 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
426 //these should be in gr.h
427 #define cv_w cv_bitmap.bm_w
428 #define cv_h cv_bitmap.bm_h
430 int Game_window_x = 0;
431 int Game_window_y = 0;
432 cvar_t Game_window_w = { "GameWidth", "0", CVAR_ARCHIVE };
433 cvar_t Game_window_h = { "GameHeight", "0", CVAR_ARCHIVE };
434 int max_window_w = 0;
435 int max_window_h = 0;
437 extern void newdemo_record_cockpit_change(int);
439 //initialize the various canvases on the game screen
440 //called every time the screen mode or cockpit changes
443 // int minx, maxx, miny, maxy;
445 //Initialize the on-screen canvases
447 if (Newdemo_state==ND_STATE_RECORDING) {
448 newdemo_record_cockpit_change(Cockpit_mode.intval);
451 if ( VR_render_mode != VR_NONE )
452 cvar_setint(&Cockpit_mode, CM_FULL_SCREEN);
454 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) &&
455 (Cockpit_mode.intval == CM_FULL_COCKPIT ||
456 Cockpit_mode.intval == CM_STATUS_BAR ||
457 Cockpit_mode.intval == CM_REAR_VIEW) )
458 cvar_setint(&Cockpit_mode, CM_FULL_SCREEN);
460 if ( Screen_mode == SCREEN_EDITOR )
461 cvar_setint(&Cockpit_mode, CM_FULL_SCREEN);
463 gr_set_current_canvas(NULL);
464 gr_set_curfont( GAME_FONT );
466 switch( Cockpit_mode.intval ) {
467 case CM_FULL_COCKPIT:
470 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode.intval+(SM_HIRES?(Num_cockpits/2):0)].index];
472 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode.intval+(SM_HIRES?(Num_cockpits/2):0)]);
474 gr_set_current_canvas(VR_offscreen_buffer);
476 gr_bitmap( 0, 0, bm );
477 bm = &VR_offscreen_buffer->cv_bitmap;
478 bm->bm_flags = BM_FLAG_TRANSPARENT;
479 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
482 if (Cockpit_mode.intval == CM_FULL_COCKPIT)
483 game_init_render_sub_buffers(0, 0, grd_curscreen->sc_w, (grd_curscreen->sc_h*2)/3);
484 else if (Cockpit_mode.intval == CM_REAR_VIEW)
485 game_init_render_sub_buffers((16*grd_curscreen->sc_w)/640, (89*grd_curscreen->sc_h)/480, (604*grd_curscreen->sc_w)/640, (209*grd_curscreen->sc_h)/480);
491 max_window_h = grd_curscreen->sc_h;
493 if (Game_window_h.intval > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
494 cvar_setint(&Game_window_h, max_window_h);
496 if (Game_window_w.intval > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
497 cvar_setint(&Game_window_w, max_window_w);
499 Game_window_x = (max_window_w - Game_window_w.intval) / 2;
500 Game_window_y = (max_window_h - Game_window_h.intval) / 2;
502 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w.intval, Game_window_h.intval );
507 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(SM_HIRES?(Num_cockpits/2):0)].index].bm_h;
509 if (Game_window_h.intval > max_window_h)
510 cvar_setint(&Game_window_h, max_window_h);
512 if (Game_window_w.intval > max_window_w)
513 cvar_setint(&Game_window_w, max_window_w);
515 Game_window_x = (max_window_w - Game_window_w.intval) / 2;
516 Game_window_y = (max_window_h - Game_window_h.intval) / 2;
518 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w.intval, Game_window_h.intval );
524 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
525 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
526 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
528 game_init_render_sub_buffers( x, y, w, h );
534 gr_set_current_canvas(NULL);
537 //selects a given cockpit (or lack of one). See types in game.h
538 void select_cockpit(int mode)
540 if (mode != Cockpit_mode.intval) { //new mode
541 cvar_setint(&Cockpit_mode, mode);
546 extern int last_drawn_cockpit[2];
548 //force cockpit redraw next time. call this if you've trashed the screen
551 force_cockpit_redraw=1;
552 last_drawn_cockpit[0] = -1;
553 last_drawn_cockpit[1] = -1;
556 // void HUD_clear_messages(); //Already declared in gauges.h
559 void VR_reset_params()
561 VR_eye_width = VR_SEPARATION;
562 VR_eye_offset = VR_PIXEL_SHIFT;
563 VR_eye_offset_changed = 2;
566 void game_init_render_sub_buffers( int x, int y, int w, int h )
568 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
569 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
573 // Sets up the canvases we will be rendering to (NORMAL VERSION)
574 void game_init_render_buffers(uint32_t screen_mode, int render_w, int render_h, int render_method, int flags )
576 // if (vga_check_mode(screen_mode) != 0)
577 // Error("Cannot set requested video mode");
579 VR_screen_mode = screen_mode;
581 VR_screen_flags = flags;
585 VR_render_mode = render_method;
587 cvar_setint(&Game_window_w, render_w);
588 cvar_setint(&Game_window_h, render_h);
590 if (VR_offscreen_buffer) {
591 gr_free_canvas(VR_offscreen_buffer);
594 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
595 if ( render_h*2 < 200 ) {
596 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
599 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
602 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
603 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
606 if ( render_h < 200 ) {
607 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
610 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
614 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
617 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
618 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
621 game_init_render_sub_buffers( 0, 0, render_w, render_h );
624 //called to get the screen in a mode compatible with popup menus.
625 //if we can't have popups over the game screen, switch to menu mode.
626 void set_popup_screen(void)
629 newmenu_show_cursor();
630 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
632 #ifndef OGL // always have to switch to menu mode
633 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
636 set_screen_mode(SCREEN_MENU); //must switch to menu mode
641 //called to change the screen mode. Parameter sm is the new mode, one of
642 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
643 //mode if cannot init requested mode)
644 int set_screen_mode(int sm)
647 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
648 gr_set_current_canvas( Canv_editor );
653 if ( Screen_mode == sm && Vid_current_mode == VR_screen_mode) {
654 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
659 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
660 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
661 ogl_set_screen_mode();
672 switch( Screen_mode )
676 if (Vid_current_mode != MENU_SCREEN_MODE) {
677 if (vid_set_mode(MENU_SCREEN_MODE))
678 Error("Cannot set screen mode for menu");
679 if (!gr_palette_faded_out)
680 gr_palette_load(gr_palette);
683 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
684 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
686 FontHires = FontHiresAvailable && MenuHires;
690 newmenu_show_cursor();
695 if (Vid_current_mode != VR_screen_mode) {
696 if (vid_set_mode(VR_screen_mode)) {
697 Error("Cannot set desired screen mode for game!");
698 //we probably should do something else here, like select a standard mode
701 if ( Config_control_joystick.intval && (Function_mode == FMODE_GAME) )
707 if ( VR_render_mode == VR_NONE )
709 max_window_w = grd_curscreen->sc_w;
710 max_window_h = grd_curscreen->sc_h;
712 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
713 if (Cockpit_mode.intval == CM_STATUS_BAR)
714 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(SM_HIRES?(Num_cockpits/2):0)].index].bm_h;
716 else if (Cockpit_mode.intval != CM_LETTERBOX)
717 cvar_setint(&Cockpit_mode, CM_FULL_SCREEN);
719 if (Game_window_h.intval == 0 || Game_window_h.intval > max_window_h ||
720 Game_window_w.intval == 0 || Game_window_w.intval > max_window_w) {
721 cvar_setint(&Game_window_w, max_window_w);
722 cvar_setint(&Game_window_h, max_window_h);
727 cvar_setint(&Cockpit_mode, CM_FULL_SCREEN);
729 // Define screen pages for game mode
730 // If we designate through screen_flags to use paging, then do so.
731 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
733 if ( VR_screen_flags&VRF_USE_PAGING )
734 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, grd_curscreen->sc_h, grd_curscreen->sc_w, grd_curscreen->sc_h );
736 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
740 FontHires = FontHiresAvailable && MenuHires;
742 if ( VR_render_mode != VR_NONE ) {
743 // for 640x480 or higher, use hires font.
744 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
750 con_init_gfx(grd_curscreen->sc_w, grd_curscreen->sc_h / 2);
752 if (Newdemo_state != ND_STATE_PLAYBACK)
753 mouse_set_mode(Config_control_mouse.intval);
754 newmenu_hide_cursor();
759 if (grd_curscreen->sc_mode != SM(800,600)) {
761 if ((gr_error = vid_set_mode(SM(800,600))) != 0) { // force into game scrren
762 Warning("Cannot init editor screen (error=%d)",gr_error);
766 gr_palette_load( gr_palette );
768 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
769 Canv_editor = &VR_editor_canvas;
770 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
771 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
772 gr_set_current_canvas( Canv_editor );
773 init_editor_screen(); //setup other editor stuff
777 Error("Invalid screen mode %d",sm);
782 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
784 if ( VR_screen_flags&VRF_USE_PAGING )
785 gr_show_canvas( &VR_screen_pages[VR_current_page] );
787 ogl_set_screen_mode();
794 int game_toggle_fullscreen(void)
796 #ifdef VID_SUPPORTS_FULLSCREEN_TOGGLE
798 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s", (i = vid_toggle_fullscreen())?"on":"off" );
799 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
800 //it seems to be that the screen mode change takes long enough that the key has already sent repeat codes, or that its unpress event gets dropped, etc. This is a somewhat ugly fix, but it works.
801 // generic_key_handler(KEY_PADENTER,0);
802 // generic_key_handler(KEY_ENTER, 0);
807 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
813 int game_toggle_fullscreen_menu(void){
814 #ifdef VID_SUPPORTS_FULLSCREEN_MENU_TOGGLE
817 i = vid_toggle_fullscreen_menu();
819 // generic_key_handler(KEY_PADENTER,0);
820 // generic_key_handler(KEY_ENTER, 0);
829 static int timer_paused=0;
833 if (timer_paused==0) {
835 time = timer_get_fixed_seconds();
836 last_timer_value = time - last_timer_value;
837 if (last_timer_value < 0) {
838 #if defined(TIMER_TEST) && !defined(NDEBUG)
839 Int3(); //get Matt!!!!
841 last_timer_value = 0;
843 #if defined(TIMER_TEST) && !defined(NDEBUG)
849 #if defined(TIMER_TEST) && !defined(NDEBUG)
857 Assert(timer_paused >= 0);
858 if (timer_paused==0) {
860 time = timer_get_fixed_seconds();
861 #if defined(TIMER_TEST) && !defined(NDEBUG)
862 if (last_timer_value < 0)
863 Int3(); //get Matt!!!!
865 last_timer_value = time - last_timer_value;
866 #if defined(TIMER_TEST) && !defined(NDEBUG)
871 #if defined(TIMER_TEST) && !defined(NDEBUG)
876 MAC(extern ubyte joydefs_calibrating;)
878 void game_flush_inputs()
885 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
887 mouse_get_delta( &dx, &dy, &dz ); // Read mouse
889 memset(&Controls,0,sizeof(control_info));
894 last_timer_value = timer_get_fixed_seconds();
899 extern int Saving_movie_frames;
900 int Movie_fixed_frametime;
902 #define Saving_movie_frames 0
903 #define Movie_fixed_frametime 0
906 //added on 8/18/98 by Victor Rachels to add maximum framerate
907 int maxfps = MAX_FPS;
910 void calc_frame_time()
912 fix timer_value,last_frametime = FrameTime;
914 #if defined(TIMER_TEST) && !defined(NDEBUG)
915 _last_frametime = last_frametime;
918 timer_value = timer_get_fixed_seconds();
919 FrameTime = timer_value - last_timer_value;
921 while (FrameTime < f1_0 / maxfps)
923 timer_delay(f1_0 / maxfps - FrameTime);
924 timer_value = timer_get_fixed_seconds();
925 FrameTime = timer_value - last_timer_value;
928 #if defined(TIMER_TEST) && !defined(NDEBUG)
929 _timer_value = timer_value;
933 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
934 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
936 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
937 // if ( !dpmi_virtual_memory )
938 // Int3(); //Get MATT if hit this!
942 #if defined(TIMER_TEST) && !defined(NDEBUG)
943 actual_last_timer_value = last_timer_value;
946 if ( Game_turbo_mode )
949 // Limit frametime to be between 5 and 150 fps.
950 RealFrameTime = FrameTime;
951 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
952 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
954 last_timer_value = timer_value;
956 if (FrameTime < 0) //if bogus frametime...
957 FrameTime = last_frametime; //...then use time from last frame
960 if (fixed_frametime) FrameTime = fixed_frametime;
975 last_timer_value = timer_get_fixed_seconds();
983 #if defined(TIMER_TEST) && !defined(NDEBUG)
984 stop_count = start_count = 0;
987 // Set value to determine whether homing missile can see target.
988 // The lower frametime is, the more likely that it can see its target.
989 if (FrameTime <= F1_0/64)
990 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
991 else if (FrameTime < F1_0/32)
992 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
993 else if (FrameTime < F1_0/4)
994 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/16 - FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
996 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1000 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1002 void move_player_2_segment(segment *seg,int side)
1006 compute_segment_center(&ConsoleObject->pos,seg);
1007 compute_center_point_on_side(&vp,seg,side);
1008 vm_vec_sub2(&vp,&ConsoleObject->pos);
1009 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1011 obj_relink( OBJECT_NUMBER(ConsoleObject), SEG_PTR_2_NUM(seg) );
1016 void game_draw_time_left()
1018 char temp_string[30];
1022 gr_set_curfont( GAME_FONT ); //GAME_FONT
1023 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1025 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1026 i=f2i(timevar-ThisLevelTime);
1029 sprintf( temp_string, "Time left: %d secs", i );
1032 gr_string(0, 32, temp_string );
1037 void do_photos(void);
1038 void level_with_floor(void);
1040 void modex_clear_box(int x,int y,int w,int h)
1042 grs_canvas *temp_canv,*save_canv;
1044 save_canv = grd_curcanv;
1045 temp_canv = gr_create_canvas(w,h);
1046 gr_set_current_canvas(temp_canv);
1047 gr_clear_canvas(BM_XRGB(0,0,0));
1048 gr_set_current_canvas(save_canv);
1049 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1050 gr_free_canvas(temp_canv);
1054 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1056 // mac routine to drop contents of screen to a pict file using copybits
1057 // save a PICT to a file
1060 void SavePictScreen(int multiplayer)
1063 int parid, i, count;
1064 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1067 PicHandle pict_handle;
1068 static int multi_count = 0;
1069 StandardFileReply sf_reply;
1071 // dump the contents of the GameWindow into a picture using copybits
1073 pict_handle = OpenPicture(&GameWindow->portRect);
1074 if (pict_handle == NULL)
1077 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1080 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1081 if (!getcwd(cwd, FILENAME_MAX))
1083 // create the fsspec
1085 sprintf(filename, "screen%d", multi_count++);
1086 pfilename = c2pstr(filename);
1089 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1090 if (!sf_reply.sfGood)
1092 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1093 if (sf_reply.sfReplacing)
1095 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1099 // parid = GetAppDirId();
1100 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1105 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1110 // write the PICT file
1111 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1113 memset(buf, 0, sizeof(buf));
1115 if ( FSWrite(fd, &count, buf) )
1117 count = GetHandleSize((Handle)pict_handle);
1118 HLock((Handle)pict_handle);
1119 if ( FSWrite(fd, &count, *pict_handle) ) {
1125 HUnlock((Handle)pict_handle);
1126 DisposeHandle((Handle)pict_handle);
1134 //automap_flag is now unused, since we just check if the screen we're
1135 //writing to is modex
1136 //if called from automap, current canvas is set to visible screen
1138 void save_screen_shot(int automap_flag)
1140 #if !defined(MACINTOSH)
1143 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1144 grs_font *save_font;
1145 static int savenum=0;
1146 static int stereo_savenum=0;
1147 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1148 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1156 // // Can't do screen shots in VR modes.
1157 // if ( VR_render_mode != VR_NONE )
1162 save_canv = grd_curcanv;
1164 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1168 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1169 gr_set_current_canvas(temp_canv);
1170 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1172 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1173 gr_set_current_canvas(temp_canv2);
1174 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1177 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1178 gr_set_current_canvas(temp_canv);
1179 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1182 gr_set_current_canvas(save_canv);
1184 if ( savenum > 99 ) savenum = 0;
1185 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1188 sprintf(savename,"left%02d.pcx",stereo_savenum);
1189 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1190 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1192 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1195 sprintf(savename,"screen%02d.pcx",savenum++);
1196 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1199 if (!automap_flag) //if from automap, curcanv is already visible canv
1200 gr_set_current_canvas(NULL);
1201 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1202 if (!automap_flag && modex_flag)
1203 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1205 save_font = grd_curcanv->cv_font;
1206 gr_set_curfont(GAME_FONT);
1207 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1208 gr_get_string_size(message,&w,&h,&aw);
1213 //I changed how these coords were calculated for the high-res automap. -MT
1214 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1215 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1216 x = (grd_curcanv->cv_w-w)/2;
1217 y = (grd_curcanv->cv_h-h)/2;
1220 modex_clear_box(x-2,y-2,w+4,h+4);
1221 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1223 gr_setcolor(gr_find_closest_color_current(0,0,0));
1224 gr_rect(x-2,y-2,x+w+2,y+h+2);
1225 gr_printf(x,y,message);
1226 gr_set_curfont(save_font);
1228 t1 = timer_get_fixed_seconds() + F1_0;
1230 gr_palette_read(pal); //get actual palette from the hardware
1231 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1233 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1235 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1237 gr_set_current_canvas(screen_canv);
1239 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1240 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1242 gr_free_canvas(temp_canv);
1244 gr_free_canvas(temp_canv2);
1246 gr_set_current_canvas(save_canv);
1252 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1253 grs_canvas *temp_canv, *save_canv;
1255 // Can't do screen shots in VR modes.
1256 if ( VR_render_mode != VR_NONE )
1261 save_canv = grd_curcanv;
1262 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1265 gr_set_current_canvas( temp_canv );
1266 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1267 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1271 if (Game_mode & GM_MULTI)
1278 gr_set_current_canvas(screen_canv);
1280 // if (!automap_flag)
1281 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1283 gr_free_canvas(temp_canv);
1285 gr_set_current_canvas(save_canv);
1294 void fly_init(object *obj)
1296 obj->control_type = CT_FLYING;
1297 obj->movement_type = MT_PHYSICS;
1299 vm_vec_zero(&obj->mtype.phys_info.velocity);
1300 vm_vec_zero(&obj->mtype.phys_info.thrust);
1301 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1302 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1305 //void morph_test(), morph_step();
1308 // ------------------------------------------------------------------------------------
1310 void test_anim_states(void);
1314 //put up the help message
1321 extern int been_in_editor;
1323 // ------------------------------------------------------------------------------------
1324 void do_cloak_stuff(void)
1327 for (i = 0; i < N_players; i++)
1328 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1329 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1330 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1331 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1332 if (i == Player_num) {
1333 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1335 if (Game_mode & GM_MULTI)
1336 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1337 maybe_drop_net_powerup(POW_CLOAK);
1338 multi_send_decloak(); // For demo recording
1340 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1348 // ------------------------------------------------------------------------------------
1349 void do_invulnerable_stuff(void)
1351 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1352 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1353 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1356 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1358 if (Game_mode & GM_MULTI)
1360 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1361 maybe_drop_net_powerup(POW_INVULNERABILITY);
1364 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1371 ubyte Last_afterburner_state = 0;
1372 fix Last_afterburner_charge = 0;
1374 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1375 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1379 //@@// ------------------------------------------------------------------------------------
1380 //@@void afterburner_shake(void)
1384 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1385 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1387 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1388 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1389 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1393 // ------------------------------------------------------------------------------------
1395 extern void multi_send_sound_function (char,char);
1398 void do_afterburner_stuff(void)
1400 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1401 Afterburner_charge=0;
1403 if (Endlevel_sequence || Player_is_dead)
1405 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1407 multi_send_sound_function (0,0);
1411 if ((Controls.state[afterburner] != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1413 if (Afterburner_charge && Controls.state[afterburner] && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1414 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1416 if (Game_mode & GM_MULTI)
1417 multi_send_sound_function(3, (char)SOUND_AFTERBURNER_IGNITE);
1420 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1421 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1423 if (Game_mode & GM_MULTI)
1424 multi_send_sound_function (0,0);
1426 mprintf((0,"Killing afterburner sound\n"));
1430 //@@if (Controls.state[afterburner] && Afterburner_charge)
1431 //@@ afterburner_shake();
1433 Last_afterburner_state = Controls.state[afterburner];
1434 Last_afterburner_charge = Afterburner_charge;
1437 // -- // ------------------------------------------------------------------------------------
1438 // -- // if energy < F1_0/2, recharge up to F1_0/2
1439 // -- void recharge_energy_frame(void)
1441 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1442 // -- Players[Player_num].energy += FrameTime/4;
1444 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1445 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1449 // Amount to diminish guns towards normal, per second.
1450 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1452 extern fix Flash_effect;
1454 //adds to rgb values for palette flash
1455 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1459 PaletteRedAdd += _dr;
1460 PaletteGreenAdd += _dg;
1461 PaletteBlueAdd += _db;
1463 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1468 maxval = MAX_PALETTE_ADD;
1470 if (PaletteRedAdd > maxval)
1471 PaletteRedAdd = maxval;
1473 if (PaletteGreenAdd > maxval)
1474 PaletteGreenAdd = maxval;
1476 if (PaletteBlueAdd > maxval)
1477 PaletteBlueAdd = maxval;
1479 if (PaletteRedAdd < -maxval)
1480 PaletteRedAdd = -maxval;
1482 if (PaletteGreenAdd < -maxval)
1483 PaletteGreenAdd = -maxval;
1485 if (PaletteBlueAdd < -maxval)
1486 PaletteBlueAdd = -maxval;
1489 fix Time_flash_last_played;
1492 void game_palette_step_up( int r, int g, int b );
1493 // ------------------------------------------------------------------------------------
1494 // Diminish palette effects towards normal.
1495 void diminish_palette_towards_normal(void)
1499 // Diminish at DIMINISH_RATE units/second.
1500 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1501 if (FrameTime < F1_0/DIMINISH_RATE) {
1502 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1505 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1506 if (dec_amount == 0)
1507 dec_amount++; // make sure we decrement by something
1513 // Part of hack system to force update of palette after exiting a menu.
1514 if (Time_flash_last_played) {
1516 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1519 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1520 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1521 Time_flash_last_played = GameTime;
1524 Flash_effect -= FrameTime;
1525 if (Flash_effect < 0)
1528 if (force_do || (d_rand() > 4096 )) {
1529 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1530 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1532 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1539 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1540 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1542 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1543 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1545 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1546 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1548 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1549 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1551 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1553 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1556 int Redsave, Bluesave, Greensave;
1558 void palette_save(void)
1560 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1563 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1565 void game_palette_step_up( int r, int g, int b )
1567 if ( VR_use_reg_code ) {
1568 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1570 gr_palette_step_up( r, g, b );
1574 void palette_restore(void)
1576 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1577 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1579 // Forces flash effect to fixup palette next frame.
1580 Time_flash_last_played = 0;
1583 extern void dead_player_frame(void);
1586 // --------------------------------------------------------------------------------------------------
1587 int allowed_to_fire_laser(void)
1589 if (Player_is_dead) {
1590 Global_missile_firing_count = 0;
1594 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1595 // be a long while before laser can be fired, then there must be some mistake!
1596 if (Next_laser_fire_time > GameTime)
1597 if (Next_laser_fire_time < GameTime + 2*F1_0)
1603 fix Next_flare_fire_time = 0;
1604 #define FLARE_BIG_DELAY (F1_0*2)
1606 int allowed_to_fire_flare(void)
1608 if (Next_flare_fire_time > GameTime)
1609 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1612 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1613 Next_flare_fire_time = GameTime + F1_0/4;
1615 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1620 int allowed_to_fire_missile(void)
1622 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1623 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1624 // be a long while before missile can be fired, then there must be some mistake!
1625 if (Next_missile_fire_time > GameTime)
1626 if (Next_missile_fire_time < GameTime + 5*F1_0)
1632 void full_palette_save(void)
1635 apply_modified_palette();
1636 reset_palette_add();
1637 gr_palette_load( gr_palette );
1640 extern int Death_sequence_aborted;
1641 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) );
1648 char pixel_double_help[64];
1651 char command_help[64], save_help[64], restore_help[64];
1654 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
1656 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F2;
1657 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F3;
1659 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1660 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1661 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = save_help;
1662 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = restore_help;
1664 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
1665 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F3;
1666 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F4;
1667 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
1668 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F6\t Fast Save";
1670 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
1672 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (F15)\t Pause";
1674 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_MINUSPLUS;
1676 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
1678 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "printscrn (F13)\t save screen shot";
1680 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
1681 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
1682 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F1\t Cycle left window";
1683 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F2\t Cycle right window";
1684 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F4\t GuideBot menu";
1686 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F4\t Rename GuideBot";
1688 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Opt-Shift-F4\t Rename GuideBot";
1690 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F5\t Drop primary";
1691 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F6\t Drop secondary";
1692 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F7\t Calibrate joystick";
1693 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-number\t GuideBot commands";
1695 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1696 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = pixel_double_help;
1699 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
1700 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1701 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = command_help;
1704 full_palette_save();
1706 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1711 //temp function until Matt cleans up game sequencing
1712 extern void temp_reset_stuff_on_level(void);
1714 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
1716 //deal with rear view - switch it on, or off, or whatever
1717 void check_rear_view()
1719 static int leave_mode;
1720 static fix entry_time;
1722 if ( Controls.count[rear_view] ) { // key/button has gone down
1726 if (Cockpit_mode.intval == CM_REAR_VIEW) {
1727 select_cockpit(Cockpit_mode_save);
1728 Cockpit_mode_save = -1;
1730 if (Newdemo_state == ND_STATE_RECORDING)
1731 newdemo_record_restore_rearview();
1735 if (Rear_view_leave_time <= 0)
1737 leave_mode = 1; // set leave mode on here otherwise we will always have to hold for at least 1 frame to get leave_mode on
1741 leave_mode = 0; // means wait for another key
1742 entry_time = timer_get_fixed_seconds();
1744 if (Cockpit_mode.intval == CM_FULL_COCKPIT) {
1745 Cockpit_mode_save = Cockpit_mode.intval;
1746 select_cockpit(CM_REAR_VIEW);
1748 if (Newdemo_state == ND_STATE_RECORDING)
1749 newdemo_record_rearview();
1753 if (Controls.state[rear_view]) {
1755 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
1760 //@@if (leave_mode==1 && Cockpit_mode.intval == CM_REAR_VIEW) {
1762 if (leave_mode==1 && Rear_view) {
1764 if (Cockpit_mode.intval == CM_REAR_VIEW) {
1765 select_cockpit(Cockpit_mode_save);
1766 Cockpit_mode_save = -1;
1768 if (Newdemo_state == ND_STATE_RECORDING)
1769 newdemo_record_restore_rearview();
1774 void reset_rear_view(void)
1777 if (Newdemo_state == ND_STATE_RECORDING)
1778 newdemo_record_restore_rearview();
1783 if (!(Cockpit_mode.intval == CM_FULL_COCKPIT || Cockpit_mode.intval == CM_STATUS_BAR || Cockpit_mode.intval == CM_FULL_SCREEN)) {
1784 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
1785 Cockpit_mode_save = CM_FULL_COCKPIT;
1786 select_cockpit(Cockpit_mode_save);
1787 Cockpit_mode_save = -1;
1793 int Config_menu_flag;
1797 int gr_renderstats = 0;
1798 // need to define "cheat" for renderstats
1799 int gr_badtexture = 0;
1800 // need to define "cheat" for badtexture
1802 cvar_t Cheats_enabled = { "sv_cheats", "0", CVAR_NONE };
1804 extern int Laser_rapid_fire;
1805 extern void do_lunacy_on(void), do_lunacy_off(void);
1807 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
1808 extern char BounceCheat,HomingCheat,OldHomingState[20];
1809 extern char AcidCheatOn,old_IntMethod, Monster_mode;
1811 //turns off active cheats
1812 void turn_cheats_off()
1818 Weapon_info[i].homing_flag=OldHomingState[i];
1823 Interpolation_method=old_IntMethod;
1826 cvar_setint(&Buddy_dude_cheat, 0);
1830 Laser_rapid_fire = 0;
1831 Physics_cheat_flag = 0;
1833 Robots_kill_robots_cheat=0;
1834 Robot_firing_enabled = 1;
1837 //turns off all cheats & resets cheater flag
1838 void game_disable_cheats()
1841 cvar_setint(&Cheats_enabled, 0);
1846 // ----------------------------------------------------------------------------
1848 void game_setup(void)
1850 //@@int demo_playing=0;
1851 //@@int multi_game=0;
1853 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
1854 do_lunacy_off(); // Restore true insane mode.
1857 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
1858 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
1859 Endlevel_sequence = 0;
1861 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
1862 //@@ demo_playing = 1;
1863 //@@if ( Game_mode & GM_MULTI )
1864 //@@ multi_game = 1;
1866 set_screen_mode(SCREEN_GAME);
1867 reset_palette_add();
1869 set_warn_func(game_show_warning);
1873 //digi_init_sounds();
1875 //keyd_repeat = 0; // Don't allow repeat in game
1876 keyd_repeat = 1; // Do allow repeat in game
1879 //_MARK_("start of game");
1883 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
1884 obj_relink( OBJECT_NUMBER(ConsoleObject), SEG_PTR_2_NUM(Cursegp) );
1886 if (!check_obj_seg(ConsoleObject))
1887 move_player_2_segment(Cursegp,Curside);
1890 Viewer = ConsoleObject;
1891 fly_init(ConsoleObject);
1896 FrameTime = 0; //make first frame zero
1899 if (Current_level_num == 0) { //not a real level
1900 init_player_stats_game();
1907 game_flush_inputs();
1913 extern char IWasKicked;
1917 // ------------------------------------------------------------------------------------
1918 //this function is the game. called when game mode selected. runs until
1919 //editor mode or exit selected
1922 game_setup(); // Replaces what was here earlier.
1923 // Good for Windows Sake.
1926 ProfilerSetStatus(1);
1929 if ( setjmp(LeaveGame)==0 ) {
1935 Config_menu_flag = 0;
1937 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
1939 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
1940 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
1943 player_shields = Players[Player_num].shields;
1945 ExtGameStatus=GAMESTAT_RUNNING;
1946 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
1948 if (oldfov != cg_fov.fixval)
1950 oldfov = cg_fov.fixval;
1951 if (cg_fov.fixval < F1_0)
1952 cvar_setint(&cg_fov, 1);
1953 if (cg_fov.fixval > 170 * F1_0)
1954 cvar_setint(&cg_fov, 170);
1955 Render_zoom = cg_fov.fixval * M_PI / 180; // convert to radians
1956 con_printf(CON_VERBOSE, "FOV set to %f (0x%08x)\n", f2fl(cg_fov.fixval), Render_zoom);
1959 //if the player is taking damage, give up guided missile control
1960 if (Players[Player_num].shields != player_shields)
1961 release_guided_missile(Player_num);
1963 //see if redbook song needs to be restarted
1964 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
1966 if (Config_menu_flag) {
1967 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
1969 if (!(Game_mode&GM_MULTI)) palette_restore();
1973 int save_w = Game_window_w.intval, save_h = Game_window_h.intval;
1975 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
1976 cvar_setint(&Game_window_w, save_w);
1977 cvar_setint(&Game_window_h, save_h);
1979 last_drawn_cockpit[0] = -1;
1980 last_drawn_cockpit[1] = -1;
1983 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
1985 fmode = Function_mode;
1986 Function_mode = FMODE_GAME;
1988 apply_modified_palette();
1989 reset_palette_add();
1990 gr_palette_load( gr_palette );
1991 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
1993 Function_mode = fmode;
1996 newdemo_stop_playback();
1997 Function_mode = FMODE_MENU;
1999 Function_mode = FMODE_GAME;
2003 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2009 fmode = Function_mode;
2010 Function_mode = FMODE_GAME;
2012 apply_modified_palette();
2013 reset_palette_add();
2014 gr_palette_load( gr_palette );
2015 ExtGameStatus=GAMESTAT_ABORT_GAME;
2016 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2018 Function_mode = fmode;
2020 Function_mode = FMODE_GAME;
2026 if (Function_mode != FMODE_GAME)
2027 longjmp(LeaveGame,0);
2030 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2031 longjmp(LeaveGame,0);
2034 if (VR_screen_flags & VRF_COMPATIBLE_MENUS) {
2035 if (Newdemo_state != ND_STATE_PLAYBACK)
2036 mouse_set_mode(Config_control_mouse.intval);
2037 newmenu_hide_cursor();
2043 ProfilerSetStatus(0);
2048 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2049 newdemo_stop_recording();
2055 if ( Newdemo_state == ND_STATE_PLAYBACK )
2056 newdemo_stop_playback();
2058 if (Cockpit_mode_save!=-1)
2060 cvar_setint(&Cockpit_mode, Cockpit_mode_save);
2061 Cockpit_mode_save=-1;
2064 if (Function_mode != FMODE_EDITOR)
2065 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2067 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2068 //@@ scores_maybe_add_player(Game_aborted);
2072 //_MARK_("end of game");
2075 clear_warn_func(game_show_warning); //don't use this func anymore
2077 game_disable_cheats();
2080 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2084 //called at the end of the program
2087 if (VR_offscreen_buffer) {
2088 gr_free_canvas(VR_offscreen_buffer);
2089 VR_offscreen_buffer = NULL;
2092 close_gauge_canvases();
2094 restore_effect_bitmap_icons();
2096 if (background_bitmap.bm_data)
2097 d_free(background_bitmap.bm_data);
2099 clear_warn_func(game_show_warning); //don't use this func anymore
2102 grs_canvas * get_current_game_screen()
2104 return &VR_screen_pages[VR_current_page];
2108 extern void kconfig_center_headset(void);
2112 void speedtest_frame(void);
2113 int Debug_slowdown=0;
2117 extern void player_follow_path(object *objp);
2118 extern void check_create_player_path(void);
2122 extern int Do_appearance_effect;
2124 object *Missile_viewer=NULL;
2126 cvar_t Missile_view_enabled = { "MissileView", "1", CVAR_ARCHIVE };
2128 int Marker_viewer_num[2]={-1,-1};
2129 int Coop_view_player[2]={-1,-1};
2130 cvar_t Cockpit_3d_view[2] = {
2131 { "CockpitViewLeft", "0", CVAR_ARCHIVE },
2132 { "CockpitViewRight", "0", CVAR_ARCHIVE },
2135 //returns ptr to escort robot, or NULL
2136 object *find_escort()
2140 for (i=0; i<=Highest_object_index; i++)
2141 if (Objects[i].type == OBJ_ROBOT)
2142 if (Robot_info[Objects[i].id].companion)
2148 extern void process_super_mines_frame(void);
2149 extern void do_seismic_stuff(void);
2152 int Saving_movie_frames=0;
2153 int __Movie_frame_num=0;
2155 #define MAX_MOVIE_BUFFER_FRAMES 250
2156 #define MOVIE_FRAME_SIZE (320 * 200)
2158 ubyte *Movie_frame_buffer;
2159 int Movie_frame_counter;
2160 ubyte Movie_pal[768];
2161 char movie_path[50] = ".\\";
2163 grs_bitmap Movie_bm;
2165 void flush_movie_buffer()
2172 mprintf((0,"Flushing movie buffer..."));
2174 Movie_bm.bm_data = Movie_frame_buffer;
2176 for (f=0;f<Movie_frame_counter;f++) {
2177 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2178 __Movie_frame_num++;
2179 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2180 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2183 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2186 Movie_frame_counter=0;
2188 mprintf((0,"done \n"));
2193 void toggle_movie_saving()
2197 Saving_movie_frames = !Saving_movie_frames;
2199 if (Saving_movie_frames) {
2202 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2203 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2206 Saving_movie_frames = 0;
2210 while (isspace(movie_path[strlen(movie_path)-1]))
2211 movie_path[strlen(movie_path)-1] = 0;
2212 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2213 strcat(movie_path,"\\");
2216 if (!Movie_frame_buffer) {
2217 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2218 if (!Movie_frame_buffer) {
2220 Saving_movie_frames=0;
2223 Movie_frame_counter=0;
2225 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2226 Movie_bm.bm_w = 320;
2227 Movie_bm.bm_h = 200;
2228 Movie_bm.bm_type = BM_LINEAR;
2229 Movie_bm.bm_flags = 0;
2230 Movie_bm.bm_rowsize = 320;
2231 Movie_bm.bm_handle = 0;
2233 gr_palette_read(Movie_pal); //get actual palette from the hardware
2235 if (Newdemo_state == ND_STATE_PLAYBACK)
2236 Newdemo_do_interpolate = 0;
2240 flush_movie_buffer();
2242 if (Newdemo_state == ND_STATE_PLAYBACK)
2243 Newdemo_do_interpolate = 1;
2248 void save_movie_frame()
2250 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2252 Movie_frame_counter++;
2254 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2255 flush_movie_buffer();
2261 extern int Level_shake_duration;
2263 //if water or fire level, make occasional sound
2264 void do_ambient_sounds()
2266 int has_water,has_lava;
2269 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2270 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2272 if (has_lava) { //has lava
2273 sound = SOUND_AMBIENT_LAVA;
2274 if (has_water && (d_rand() & 1)) //both, pick one
2275 sound = SOUND_AMBIENT_WATER;
2277 else if (has_water) //just water
2278 sound = SOUND_AMBIENT_WATER;
2282 if (((d_rand() << 3) < FrameTime)) { //play the sound
2283 fix volume = d_rand() + f1_0/2;
2284 digi_play_sample(sound,volume);
2288 // -- extern void lightning_frame(void);
2290 void game_render_frame(void);
2291 extern void omega_charge_frame(void);
2293 extern time_t t_current_time, t_saved_time;
2295 void flicker_lights(void);
2297 void GameLoop(int RenderFlag, int ReadControlsFlag )
2300 // Used to slow down frame rate for testing things.
2301 // RenderFlag = 1; // DEBUG
2302 if (Debug_slowdown) {
2305 for (h=0; h<Debug_slowdown; h++)
2306 for (i=0; i<1000; i++)
2312 if (FindArg("-invulnerability"))
2313 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2317 update_player_stats();
2318 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2319 do_afterburner_stuff();
2321 do_invulnerable_stuff();
2322 remove_obsolete_stuck_objects();
2324 do_final_boss_frame();
2325 // -- lightning_frame();
2326 // -- recharge_energy_frame();
2328 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2329 static int turned_off=0;
2330 Players[Player_num].energy -= (FrameTime*3/8);
2331 if (Players[Player_num].energy < i2f(10)) {
2333 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2336 if (Game_mode & GM_MULTI)
2337 multi_send_flags(Player_num);
2344 if (Players[Player_num].energy <= 0) {
2345 Players[Player_num].energy = 0;
2346 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2348 if (Game_mode & GM_MULTI)
2349 multi_send_flags(Player_num);
2356 check_create_player_path();
2357 player_follow_path(ConsoleObject);
2361 if (Game_mode & GM_MULTI)
2364 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2365 multi_check_for_killgoal_winner();
2371 if (force_cockpit_redraw) { //screen need redrawing?
2373 force_cockpit_redraw=0;
2375 game_render_frame();
2376 //show_extra_views(); //missile view, buddy bot, etc.
2379 if (Saving_movie_frames)
2386 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2390 dead_player_frame();
2391 if (Newdemo_state != ND_STATE_PLAYBACK)
2392 do_controlcen_dead_frame();
2394 process_super_mines_frame();
2396 do_ambient_sounds();
2403 if (ReadControlsFlag)
2406 memset(&Controls, 0, sizeof(Controls));
2408 GameTime += FrameTime;
2410 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2411 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2413 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2414 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2415 mprintf((0,"GameTime reset to 0\n"));
2419 if (FindArg("-checktime") != 0)
2420 if (GameTime >= i2f(600)) //wrap after 10 minutes
2421 GameTime = FrameTime;
2425 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2426 ThisLevelTime +=FrameTime;
2431 if (Endlevel_sequence) {
2432 do_endlevel_frame();
2433 powerup_grab_cheat_all();
2434 do_special_effects();
2435 return; //skip everything else
2438 if (Newdemo_state != ND_STATE_PLAYBACK)
2439 do_exploding_wall_frame();
2440 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2441 do_special_effects();
2442 wall_frame_process();
2443 triggers_frame_process();
2447 if (Control_center_destroyed) {
2448 if (Newdemo_state==ND_STATE_RECORDING )
2449 newdemo_record_control_center_destroyed();
2454 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2455 newdemo_playback_one_frame();
2456 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2457 longjmp( LeaveGame, 0 ); // Go back to menu
2460 { // Note the link to above!
2462 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2465 powerup_grab_cheat_all();
2467 if (Endlevel_sequence) //might have been started during move
2470 fuelcen_update_all();
2474 if (allowed_to_fire_laser())
2475 FireLaser(); // Fire Laser!
2477 if (Auto_fire_fusion_cannon_time) {
2478 if (Primary_weapon != FUSION_INDEX)
2479 Auto_fire_fusion_cannon_time = 0;
2480 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2481 Auto_fire_fusion_cannon_time = 0;
2482 Global_laser_firing_count = 1;
2484 vms_vector rand_vec;
2487 Global_laser_firing_count = 0;
2489 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2490 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2491 make_random_vector(&rand_vec);
2493 bump_amount = F1_0*4;
2495 if (Fusion_charge > F1_0*2)
2496 bump_amount = Fusion_charge*4;
2498 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2502 if (Global_laser_firing_count) {
2503 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2504 // if (Fusion_charge > F1_0*2)
2505 // Fusion_charge = F1_0*2;
2506 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2509 if (Global_laser_firing_count < 0)
2510 Global_laser_firing_count = 0;
2513 if (Do_appearance_effect) {
2514 create_player_appearance_effect(ConsoleObject);
2515 Do_appearance_effect = 0;
2517 if ((Game_mode & GM_MULTI) && Netgame.invul)
2519 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2520 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2527 omega_charge_frame();
2531 //!!hoard_light_pulse(); //do cool hoard light pulsing
2535 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2536 //!!extern int Hoard_goal_eclip;
2538 //!!//do cool pulsing lights in hoard goals
2539 //!!hoard_light_pulse()
2541 //!! if (Game_mode & GM_HOARD) {
2545 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2549 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2552 //!! light = abs(frame - 5) * f1_0 / 5;
2554 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2559 ubyte Slide_segs[MAX_SEGMENTS];
2560 int Slide_segs_computed;
2562 void compute_slide_segs(void)
2564 int segnum, sidenum;
2566 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2567 Slide_segs[segnum] = 0;
2568 for (sidenum=0;sidenum<6;sidenum++) {
2569 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2570 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2571 Slide_segs[segnum] |= 1 << sidenum;
2575 Slide_segs_computed = 1;
2578 // -----------------------------------------------------------------------------
2579 void slide_textures(void)
2581 int segnum,sidenum,i;
2583 if (!Slide_segs_computed)
2584 compute_slide_segs();
2586 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2587 if (Slide_segs[segnum]) {
2588 for (sidenum=0;sidenum<6;sidenum++) {
2589 if (Slide_segs[segnum] & (1 << sidenum)) {
2590 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2591 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2593 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2594 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2595 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2598 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2600 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2603 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2605 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2608 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2610 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2613 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2623 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2625 int Num_flickering_lights=0;
2627 void flicker_lights()
2630 flickering_light *f;
2632 f = Flickering_lights;
2634 for (l=0;l<Num_flickering_lights;l++,f++) {
2635 segment *segp = &Segments[f->segnum];
2637 //make sure this is actually a light
2638 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2640 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2643 if (f->timer == 0x80000000) //disabled
2646 if ((f->timer -= FrameTime) < 0) {
2648 while (f->timer < 0)
2649 f->timer += f->delay;
2651 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2654 add_light(f->segnum,f->sidenum);
2656 subtract_light(f->segnum,f->sidenum);
2661 //returns ptr to flickering light structure, or NULL if can't find
2662 flickering_light *find_flicker(int segnum,int sidenum)
2665 flickering_light *f;
2667 //see if there's already an entry for this seg/side
2669 f = Flickering_lights;
2671 for (l=0;l<Num_flickering_lights;l++,f++)
2672 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2678 //turn flickering off (because light has been turned off)
2679 void disable_flicker(int segnum,int sidenum)
2681 flickering_light *f;
2683 if ((f=find_flicker(segnum,sidenum)) != NULL)
2684 f->timer = 0x80000000;
2687 //turn flickering off (because light has been turned on)
2688 void enable_flicker(int segnum,int sidenum)
2690 flickering_light *f;
2692 if ((f=find_flicker(segnum,sidenum)) != NULL)
2699 //returns 1 if ok, 0 if error
2700 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
2703 flickering_light *f;
2705 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2707 //see if there's already an entry for this seg/side
2709 f = Flickering_lights;
2711 for (l=0;l<Num_flickering_lights;l++,f++)
2712 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2715 if (mask==0) { //clearing entry
2716 if (l == Num_flickering_lights)
2720 for (i=l;i<Num_flickering_lights-1;i++)
2721 Flickering_lights[i] = Flickering_lights[i+1];
2722 Num_flickering_lights--;
2727 if (l == Num_flickering_lights) {
2728 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
2731 Num_flickering_lights++;
2735 f->sidenum = sidenum;
2736 f->delay = f->timer = delay;
2744 // -----------------------------------------------------------------------------
2745 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
2750 Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.state[fire_primary] || Controls.count[fire_primary]);
2752 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
2753 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
2754 Global_laser_firing_count = 0;
2756 if (Fusion_charge == 0)
2757 Players[Player_num].energy -= F1_0*2;
2759 Fusion_charge += FrameTime;
2760 Players[Player_num].energy -= FrameTime;
2762 if (Players[Player_num].energy <= 0) {
2763 Players[Player_num].energy = 0;
2764 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
2766 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
2767 // Fire the fusion cannon at this time in the future.
2769 if (Fusion_charge < F1_0*2)
2770 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
2772 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
2774 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
2775 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
2777 if (Fusion_next_sound_time < GameTime) {
2778 if (Fusion_charge > F1_0*2) {
2779 digi_play_sample( 11, F1_0 );
2780 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
2782 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
2783 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
2785 if (Game_mode & GM_MULTI)
2786 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
2789 Fusion_last_sound_time = GameTime;
2790 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
2798 // -------------------------------------------------------------------------------------------------------
2799 // If player is close enough to objnum, which ought to be a powerup, pick it up!
2800 // This could easily be made difficulty level dependent.
2801 void powerup_grab_cheat(object *player, int objnum)
2807 Assert(Objects[objnum].type == OBJ_POWERUP);
2809 powerup_size = Objects[objnum].size;
2810 player_size = player->size;
2812 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
2814 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
2815 vms_vector collision_point;
2817 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
2818 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
2822 // -------------------------------------------------------------------------------------------------------
2823 // Make it easier to pick up powerups.
2824 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
2825 // from player to powerup and player's forward vector.
2826 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
2827 // way before the player gets there.
2828 void powerup_grab_cheat_all(void)
2833 segp = &Segments[ConsoleObject->segnum];
2834 objnum = segp->objects;
2836 while (objnum != -1) {
2837 if (Objects[objnum].type == OBJ_POWERUP)
2838 powerup_grab_cheat(ConsoleObject, objnum);
2839 objnum = Objects[objnum].next;
2844 int Last_level_path_created = -1;
2846 #ifdef SHOW_EXIT_PATH
2848 // ------------------------------------------------------------------------------------------------------------------
2849 // Create path for player from current segment to goal segment.
2850 // Return true if path created, else return false.
2851 int mark_player_path_to_segment(int segnum)
2854 object *objp = ConsoleObject;
2855 short player_path_length=0;
2856 int player_hide_index=-1;
2858 if (Last_level_path_created == Current_level_num) {
2862 Last_level_path_created = Current_level_num;
2864 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
2865 mprintf((0, "Unable to form path of length %i for myself\n", 100));
2869 player_hide_index = POINT_SEG_NUMBER(Point_segs_free_ptr);
2870 Point_segs_free_ptr += player_path_length;
2872 if (POINT_SEG_NUMBER(Point_segs_free_ptr) + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
2873 mprintf((1, "Can't create path. Not enough point_segs.\n"));
2874 ai_reset_all_paths();
2878 for (i=1; i<player_path_length; i++) {
2880 vms_vector seg_center;
2883 segnum = Point_segs[player_hide_index+i].segnum;
2884 mprintf((0, "%3i ", segnum));
2885 seg_center = Point_segs[player_hide_index+i].point;
2887 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
2889 Int3(); // Unable to drop energy powerup for path
2893 obj = &Objects[objnum];
2894 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
2895 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
2896 obj->rtype.vclip_info.framenum = 0;
2897 obj->lifeleft = F1_0*100 + d_rand() * 4;
2904 // Return true if it happened, else return false.
2905 int create_special_path(void)
2909 // ---------- Find exit doors ----------
2910 for (i=0; i<=Highest_segment_index; i++)
2911 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
2912 if (Segments[i].children[j] == -2) {
2913 mprintf((0, "Exit at segment %i\n", i));
2914 return mark_player_path_to_segment(i);
2924 int Max_obj_count_mike = 0;
2926 // Shows current number of used objects.
2927 void show_free_objects(void)
2929 if (!(FrameCount & 8)) {
2933 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
2935 for (i=0; i<=Highest_object_index; i++)
2936 if (Objects[i].type != OBJ_NONE)
2939 mprintf((0, "%3i", count));
2941 if (count > Max_obj_count_mike) {
2942 Max_obj_count_mike = count;
2943 mprintf((0, " ***"));
2954 * reads a flickering_light structure from a CFILE
2956 void flickering_light_read(flickering_light *fl, CFILE *fp)
2958 fl->segnum = cfile_read_short(fp);
2959 fl->sidenum = cfile_read_short(fp);
2960 fl->mask = cfile_read_int(fp);
2961 fl->timer = cfile_read_fix(fp);
2962 fl->delay = cfile_read_fix(fp);
2965 void flickering_light_write(flickering_light *fl, PHYSFS_file *fp)
2967 PHYSFS_writeSLE16(fp, fl->segnum);
2968 PHYSFS_writeSLE16(fp, fl->sidenum);
2969 PHYSFS_writeULE32(fp, (uint32_t)fl->mask);
2970 PHYSFSX_writeFix(fp, fl->timer);
2971 PHYSFSX_writeFix(fp, fl->delay);