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
34 #include <StandardFile.h>
35 #include <Quickdraw.h>
104 #include "cntrlcen.h"
108 #include "multibot.h"
111 #include "playsave.h"
115 int VGA_current_mode;
118 #include <profiler.h>
121 //#define TEST_TIMER 1 //if this is set, do checking on timer
123 #define SHOW_EXIT_PATH 1
126 #include "editor/editor.h"
131 #if __WATCOMC__ < 1000
132 #include <wsample.h> //should come after inferno.h to get mark setting
137 extern void ReadControls(void); // located in gamecntl.c
138 extern void do_final_boss_frame(void);
140 int Speedtest_on = 0;
143 int Mark_count = 0; // number of debugging marks set
144 int Speedtest_start_time;
145 int Speedtest_segnum;
146 int Speedtest_sidenum;
147 int Speedtest_frame_start;
148 int Speedtest_count=0; // number of times to do the debug test.
151 static fix last_timer_value=0;
154 #if defined(TIMER_TEST) && !defined(NDEBUG)
155 fix _timer_value,actual_last_timer_value,_last_frametime;
156 int stop_count,start_count;
157 int time_stopped,time_started;
160 int VR_screen_mode = 0;
162 ubyte VR_screen_flags = 0; //see values in screens.h
163 ubyte VR_current_page = 0;
164 fix VR_eye_width = F1_0;
165 int VR_render_mode = VR_NONE;
166 int VR_low_res = 3; // Default to low res
168 int VR_sensitivity = 1; // 0 - 2
171 int VR_eye_offset = 0;
172 int VR_eye_switch = 0;
173 int VR_eye_offset_changed = 0;
174 int VR_use_reg_code = 0;
176 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
177 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
178 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
179 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
180 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
182 //do menus work in 640x480 or 320x200?
183 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
184 int MenuHiresAvailable = 1; //can we do highres menus?
185 int MenuHires = 1; //are we currently in highres menus?
187 int Debug_pause=0; //John's debugging pause system
189 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
191 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
192 int force_cockpit_redraw=0;
195 cvar_t r_framerate = {"show_fps", "0"};
196 cvar_t cg_fov = {"fov", "30"};
198 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
200 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
202 int *Toggle_var = &Dummy_var;
205 //flag for whether initial fade-in has been done
209 #ifndef NDEBUG //these only exist if debugging
211 int Game_double_buffer = 1; //double buffer by default
212 fix fixed_frametime=0; //if non-zero, set frametime to this
216 int Game_suspended=0; //if non-zero, nothing moves but player
219 fix Auto_fire_fusion_cannon_time = 0;
220 fix Fusion_charge = 0;
221 fix Fusion_next_sound_time = 0;
222 fix Fusion_last_sound_time = 0;
225 int Game_turbo_mode = 0;
227 int Game_mode = GM_GAME_OVER;
229 int Global_laser_firing_count = 0;
230 int Global_missile_firing_count = 0;
232 grs_bitmap background_bitmap;
236 #define BACKGROUND_NAME "statback.pcx"
238 // Function prototypes for GAME.C exclusively.
240 void GameLoop(int RenderFlag, int ReadControlsFlag);
241 void FireLaser(void);
242 void slide_textures(void);
243 void powerup_grab_cheat_all(void);
246 extern void multi_check_for_killgoal_winner();
247 extern void RestoreGameSurfaces();
251 void grow_window(void);
252 void shrink_window(void);
256 void fill_background();
259 void show_framerate(void);
260 void ftoa(char *string, fix f);
263 extern ubyte DefiningMarkerMessage;
264 extern char Marker_input[];
266 // ==============================================================================================
268 extern char john_head_on;
270 void load_background_bitmap()
275 if (background_bitmap.bm_data)
276 d_free(background_bitmap.bm_data);
278 background_bitmap.bm_data=NULL;
279 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
280 if (pcx_error != PCX_ERROR_NONE)
281 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
282 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
287 void game_cmd_player(int argc, char **argv)
289 if (argc < 2 || !stricmp(argv[1], "-h")) {
290 con_printf(CON_NORMAL, "%s <name>\n", argv[0]);
291 con_printf(CON_NORMAL, " use the player/pilot file <name>\n");
295 strncpy(Players[Player_num].callsign, argv[1], CALLSIGN_LEN);
297 if (read_player_file() != EZERO) {
298 con_printf(CON_CRITICAL, "player: unable to load player file");
302 WriteConfigFile(); // Update lastplr
307 void game_cmd_map(int argc, char **argv)
311 if (argc < 2 || !stricmp(argv[1], "-h")) {
312 con_printf(CON_NORMAL, "%s <name> [num]\n", argv[0]);
313 con_printf(CON_NORMAL, " start level <num> of mission <name> (defaults to level 1)\n");
317 if (!strlen(Players[Player_num].callsign)) {
318 con_printf(CON_CRITICAL, "map: no player selected, not starting level\n");
322 load_mission_by_name(argv[1]);
325 level_num = atoi(argv[2]);
329 if (level_num > Last_level)
330 level_num = Last_level;
331 if (level_num < Last_secret_level)
332 level_num = Last_secret_level;
334 StartNewGame(level_num);
338 /* send network message */
339 void game_cmd_say(int argc, char **argv)
343 if (argc < 2 || !stricmp(argv[1], "-h")) {
344 con_printf(CON_NORMAL, "%s <text>\n", argv[0]);
345 con_printf(CON_NORMAL, " send the message <text> to the network\n");
349 Network_message[0] = 0;
351 ret = snprintf(Network_message, MAX_MESSAGE_LEN, "%s", argv[1]);
352 if (ret >= MAX_MESSAGE_LEN) {
353 con_printf(CON_CRITICAL, "say: message too long (max %d characters)\n", MAX_MESSAGE_LEN);
357 for (i = 2; i < argc; i++) {
358 ret = snprintf(Network_message, MAX_MESSAGE_LEN, "%s %s", Network_message, argv[i]);
359 if (ret >= MAX_MESSAGE_LEN) {
360 con_printf(CON_CRITICAL, "say: message too long (max %d characters)\n", MAX_MESSAGE_LEN);
365 multi_send_message_end();
369 /* increase window size */
370 void game_cmd_sizeup(int argc, char **argv)
373 con_printf(CON_NORMAL, "%s\n", argv[0]);
374 con_printf(CON_NORMAL, " increase the game window size\n");
382 /* decrease window size */
383 void game_cmd_sizedown(int argc, char **argv)
386 con_printf(CON_NORMAL, "%s\n", argv[0]);
387 con_printf(CON_NORMAL, " decrease the game window size\n");
395 //this is called once per game
398 atexit(close_game); //for cleanup
402 init_special_effects();
406 init_exploding_walls();
408 load_background_bitmap();
410 Clear_window = 2; // do portal only window clear.
412 set_detail_level_parameters(Detail_level);
415 cvar_registervariable(&r_framerate);
416 cvar_registervariable(&cg_fov);
419 cmd_addcommand("player", game_cmd_player);
420 cmd_addcommand("map", game_cmd_map);
421 cmd_addcommand("say", game_cmd_say);
422 cmd_addcommand("sizeup", game_cmd_sizeup);
423 cmd_addcommand("sizedown", game_cmd_sizedown);
427 void reset_palette_add()
432 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
436 void game_show_warning(char *s)
439 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
442 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
444 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
449 //these should be in gr.h
450 #define cv_w cv_bitmap.bm_w
451 #define cv_h cv_bitmap.bm_h
453 //added 3/24/99 by Owen Evans for screen res changing
454 uint32_t Game_screen_mode = 0;
456 int Game_window_x = 0;
457 int Game_window_y = 0;
458 int Game_window_w = 0;
459 int Game_window_h = 0;
460 int max_window_w = 0;
461 int max_window_h = 0;
463 extern void newdemo_record_cockpit_change(int);
465 //initialize the various canvases on the game screen
466 //called every time the screen mode or cockpit changes
469 // int minx, maxx, miny, maxy;
471 //Initialize the on-screen canvases
473 if (Newdemo_state==ND_STATE_RECORDING) {
474 newdemo_record_cockpit_change(Cockpit_mode);
477 if ( VR_render_mode != VR_NONE )
478 Cockpit_mode = CM_FULL_SCREEN;
480 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
481 Cockpit_mode = CM_FULL_SCREEN;
483 if ( Screen_mode == SCREEN_EDITOR )
484 Cockpit_mode = CM_FULL_SCREEN;
486 gr_set_current_canvas(NULL);
487 gr_set_curfont( GAME_FONT );
489 switch( Cockpit_mode ) {
490 case CM_FULL_COCKPIT:
493 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(SM_HIRES?(Num_cockpits/2):0)].index];
495 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(SM_HIRES?(Num_cockpits/2):0)]);
497 gr_set_current_canvas(VR_offscreen_buffer);
499 gr_bitmap( 0, 0, bm );
500 bm = &VR_offscreen_buffer->cv_bitmap;
501 bm->bm_flags = BM_FLAG_TRANSPARENT;
502 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
505 if (Cockpit_mode == CM_FULL_COCKPIT)
506 game_init_render_sub_buffers(0, 0, grd_curscreen->sc_w, (grd_curscreen->sc_h*2)/3);
507 else if (Cockpit_mode == CM_REAR_VIEW)
508 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);
514 max_window_h = grd_curscreen->sc_h;
516 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
517 Game_window_h = max_window_h;
519 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
520 Game_window_w = max_window_w;
522 Game_window_x = (max_window_w - Game_window_w)/2;
523 Game_window_y = (max_window_h - Game_window_h)/2;
525 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
530 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(SM_HIRES?(Num_cockpits/2):0)].index].bm_h;
532 if (Game_window_h > max_window_h)
533 Game_window_h = max_window_h;
535 if (Game_window_w > max_window_w)
536 Game_window_w = max_window_w;
538 Game_window_x = (max_window_w - Game_window_w)/2;
539 Game_window_y = (max_window_h - Game_window_h)/2;
541 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
547 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
548 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
549 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
551 game_init_render_sub_buffers( x, y, w, h );
557 gr_set_current_canvas(NULL);
560 //selects a given cockpit (or lack of one). See types in game.h
561 void select_cockpit(int mode)
563 if (mode != Cockpit_mode) { //new mode
569 extern int last_drawn_cockpit[2];
571 //force cockpit redraw next time. call this if you've trashed the screen
574 force_cockpit_redraw=1;
575 last_drawn_cockpit[0] = -1;
576 last_drawn_cockpit[1] = -1;
579 // void HUD_clear_messages(); //Already declared in gauges.h
582 void VR_reset_params()
584 VR_eye_width = VR_SEPARATION;
585 VR_eye_offset = VR_PIXEL_SHIFT;
586 VR_eye_offset_changed = 2;
589 void game_init_render_sub_buffers( int x, int y, int w, int h )
591 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
592 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
596 // Sets up the canvases we will be rendering to (NORMAL VERSION)
597 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
599 // if (vga_check_mode(screen_mode) != 0)
600 // Error("Cannot set requested video mode");
602 VR_screen_mode = screen_mode;
604 VR_screen_flags = flags;
608 VR_render_mode = render_method;
610 Game_window_w = render_w;
611 Game_window_h = render_h;
613 if (VR_offscreen_buffer) {
614 gr_free_canvas(VR_offscreen_buffer);
617 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
618 if ( render_h*2 < 200 ) {
619 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
622 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
625 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
626 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
629 if ( render_h < 200 ) {
630 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
633 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
637 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
640 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
641 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
644 game_init_render_sub_buffers( 0, 0, render_w, render_h );
647 //called to get the screen in a mode compatible with popup menus.
648 //if we can't have popups over the game screen, switch to menu mode.
649 void set_popup_screen(void)
651 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
653 #ifndef OGL // always have to switch to menu mode
654 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
657 set_screen_mode(SCREEN_MENU); //must switch to menu mode
662 //called to change the screen mode. Parameter sm is the new mode, one of
663 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
664 //mode if cannot init requested mode)
665 int set_screen_mode(int sm)
668 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
669 gr_set_current_canvas( Canv_editor );
674 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
675 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
680 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
681 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
682 ogl_set_screen_mode();
693 switch( Screen_mode )
699 MenuHires = MenuHiresAvailable; //do highres if we can
701 menu_mode = MenuHires?SM(640,480):SM(320,200);
703 if (VGA_current_mode != menu_mode) {
704 if (gr_set_mode(menu_mode))
705 Error("Cannot set screen mode for menu");
706 if (!gr_palette_faded_out)
707 gr_palette_load(gr_palette);
710 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
711 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
713 FontHires = FontHiresAvailable && MenuHires;
719 if (VGA_current_mode != VR_screen_mode) {
720 if (gr_set_mode(VR_screen_mode)) {
721 Error("Cannot set desired screen mode for game!");
722 //we probably should do something else here, like select a standard mode
725 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
731 if ( VR_render_mode == VR_NONE )
733 max_window_w = grd_curscreen->sc_w;
734 max_window_h = grd_curscreen->sc_h;
736 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
737 if (Cockpit_mode == CM_STATUS_BAR)
738 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(SM_HIRES?(Num_cockpits/2):0)].index].bm_h;
740 else if (Cockpit_mode != CM_LETTERBOX)
741 Cockpit_mode = CM_FULL_SCREEN;
743 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
744 Game_window_w = max_window_w;
745 Game_window_h = max_window_h;
750 Cockpit_mode = CM_FULL_SCREEN;
752 // Define screen pages for game mode
753 // If we designate through screen_flags to use paging, then do so.
754 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
756 if ( VR_screen_flags&VRF_USE_PAGING )
757 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 );
759 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
763 FontHires = FontHiresAvailable && (MenuHires = SM_HIRES2);
765 if ( VR_render_mode != VR_NONE ) {
766 // for 640x480 or higher, use hires font.
767 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
773 CON_InitGFX(grd_curscreen->sc_w, grd_curscreen->sc_h / 2);
778 if (grd_curscreen->sc_mode != SM(800,600)) {
780 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
781 Warning("Cannot init editor screen (error=%d)",gr_error);
785 gr_palette_load( gr_palette );
787 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
788 Canv_editor = &VR_editor_canvas;
789 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
790 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
791 gr_set_current_canvas( Canv_editor );
792 init_editor_screen(); //setup other editor stuff
796 Error("Invalid screen mode %d",sm);
801 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
803 if ( VR_screen_flags&VRF_USE_PAGING )
804 gr_show_canvas( &VR_screen_pages[VR_current_page] );
806 ogl_set_screen_mode();
812 int gr_toggle_fullscreen_game(void){
813 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
815 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
816 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
817 //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.
818 // generic_key_handler(KEY_PADENTER,0);
819 // generic_key_handler(KEY_ENTER, 0);
824 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
829 int arch_toggle_fullscreen_menu(void);
831 int gr_toggle_fullscreen_menu(void){
832 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
834 i=arch_toggle_fullscreen_menu();
836 // generic_key_handler(KEY_PADENTER,0);
837 // generic_key_handler(KEY_ENTER, 0);
846 static int timer_paused=0;
850 if (timer_paused==0) {
852 time = timer_get_fixed_seconds();
853 last_timer_value = time - last_timer_value;
854 if (last_timer_value < 0) {
855 #if defined(TIMER_TEST) && !defined(NDEBUG)
856 Int3(); //get Matt!!!!
858 last_timer_value = 0;
860 #if defined(TIMER_TEST) && !defined(NDEBUG)
866 #if defined(TIMER_TEST) && !defined(NDEBUG)
874 Assert(timer_paused >= 0);
875 if (timer_paused==0) {
877 time = timer_get_fixed_seconds();
878 #if defined(TIMER_TEST) && !defined(NDEBUG)
879 if (last_timer_value < 0)
880 Int3(); //get Matt!!!!
882 last_timer_value = time - last_timer_value;
883 #if defined(TIMER_TEST) && !defined(NDEBUG)
888 #if defined(TIMER_TEST) && !defined(NDEBUG)
893 MAC(extern ubyte joydefs_calibrating;)
895 void game_flush_inputs()
902 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
904 mouse_get_delta( &dx, &dy ); // Read mouse
905 memset(&Controls,0,sizeof(control_info));
910 last_timer_value = timer_get_fixed_seconds();
915 extern int Saving_movie_frames;
916 int Movie_fixed_frametime;
918 #define Saving_movie_frames 0
919 #define Movie_fixed_frametime 0
922 //added on 8/18/98 by Victor Rachels to add maximum framerate
923 int maxfps = MAX_FPS;
926 void calc_frame_time()
928 fix timer_value,last_frametime = FrameTime;
930 #if defined(TIMER_TEST) && !defined(NDEBUG)
931 _last_frametime = last_frametime;
934 timer_value = timer_get_fixed_seconds();
935 FrameTime = timer_value - last_timer_value;
937 while (FrameTime < f1_0 / maxfps)
939 timer_delay(f1_0 / maxfps - FrameTime);
940 timer_value = timer_get_fixed_seconds();
941 FrameTime = timer_value - last_timer_value;
944 #if defined(TIMER_TEST) && !defined(NDEBUG)
945 _timer_value = timer_value;
949 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
950 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
952 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
953 // if ( !dpmi_virtual_memory )
954 // Int3(); //Get MATT if hit this!
958 #if defined(TIMER_TEST) && !defined(NDEBUG)
959 actual_last_timer_value = last_timer_value;
962 if ( Game_turbo_mode )
965 // Limit frametime to be between 5 and 150 fps.
966 RealFrameTime = FrameTime;
967 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
968 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
970 last_timer_value = timer_value;
972 if (FrameTime < 0) //if bogus frametime...
973 FrameTime = last_frametime; //...then use time from last frame
976 if (fixed_frametime) FrameTime = fixed_frametime;
991 last_timer_value = timer_get_fixed_seconds();
999 #if defined(TIMER_TEST) && !defined(NDEBUG)
1000 stop_count = start_count = 0;
1003 // Set value to determine whether homing missile can see target.
1004 // The lower frametime is, the more likely that it can see its target.
1005 if (FrameTime <= F1_0/64)
1006 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1007 else if (FrameTime < F1_0/32)
1008 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1009 else if (FrameTime < F1_0/4)
1010 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;
1012 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1016 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1018 void move_player_2_segment(segment *seg,int side)
1022 compute_segment_center(&ConsoleObject->pos,seg);
1023 compute_center_point_on_side(&vp,seg,side);
1024 vm_vec_sub2(&vp,&ConsoleObject->pos);
1025 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1027 obj_relink( OBJECT_NUMBER(ConsoleObject), SEG_PTR_2_NUM(seg) );
1032 void game_draw_time_left()
1034 char temp_string[30];
1038 gr_set_curfont( GAME_FONT ); //GAME_FONT
1039 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1041 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1042 i=f2i(timevar-ThisLevelTime);
1045 sprintf( temp_string, "Time left: %d secs", i );
1048 gr_string(0, 32, temp_string );
1053 extern int Game_pause;
1056 void level_with_floor();
1058 void modex_clear_box(int x,int y,int w,int h)
1060 grs_canvas *temp_canv,*save_canv;
1062 save_canv = grd_curcanv;
1063 temp_canv = gr_create_canvas(w,h);
1064 gr_set_current_canvas(temp_canv);
1065 gr_clear_canvas(BM_XRGB(0,0,0));
1066 gr_set_current_canvas(save_canv);
1067 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1068 gr_free_canvas(temp_canv);
1072 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1074 // mac routine to drop contents of screen to a pict file using copybits
1075 // save a PICT to a file
1078 void SavePictScreen(int multiplayer)
1081 int parid, i, count;
1082 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1085 PicHandle pict_handle;
1086 static int multi_count = 0;
1087 StandardFileReply sf_reply;
1089 // dump the contents of the GameWindow into a picture using copybits
1091 pict_handle = OpenPicture(&GameWindow->portRect);
1092 if (pict_handle == NULL)
1095 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1098 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1099 if (!getcwd(cwd, FILENAME_MAX))
1101 // create the fsspec
1103 sprintf(filename, "screen%d", multi_count++);
1104 pfilename = c2pstr(filename);
1107 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1108 if (!sf_reply.sfGood)
1110 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1111 if (sf_reply.sfReplacing)
1113 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1117 // parid = GetAppDirId();
1118 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1123 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1128 // write the PICT file
1129 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1131 memset(buf, 0, sizeof(buf));
1133 if ( FSWrite(fd, &count, buf) )
1135 count = GetHandleSize((Handle)pict_handle);
1136 HLock((Handle)pict_handle);
1137 if ( FSWrite(fd, &count, *pict_handle) ) {
1143 HUnlock((Handle)pict_handle);
1144 DisposeHandle((Handle)pict_handle);
1152 //automap_flag is now unused, since we just check if the screen we're
1153 //writing to is modex
1154 //if called from automap, current canvas is set to visible screen
1156 void save_screen_shot(int automap_flag)
1158 #if !defined(MACINTOSH)
1161 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1162 grs_font *save_font;
1163 static int savenum=0;
1164 static int stereo_savenum=0;
1165 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1166 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1174 // // Can't do screen shots in VR modes.
1175 // if ( VR_render_mode != VR_NONE )
1180 save_canv = grd_curcanv;
1182 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1186 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1187 gr_set_current_canvas(temp_canv);
1188 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1190 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1191 gr_set_current_canvas(temp_canv2);
1192 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1195 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1196 gr_set_current_canvas(temp_canv);
1197 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1200 gr_set_current_canvas(save_canv);
1202 if ( savenum > 99 ) savenum = 0;
1203 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1206 sprintf(savename,"left%02d.pcx",stereo_savenum);
1207 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1208 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1210 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1213 sprintf(savename,"screen%02d.pcx",savenum++);
1214 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1217 if (!automap_flag) //if from automap, curcanv is already visible canv
1218 gr_set_current_canvas(NULL);
1219 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1220 if (!automap_flag && modex_flag)
1221 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1223 save_font = grd_curcanv->cv_font;
1224 gr_set_curfont(GAME_FONT);
1225 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1226 gr_get_string_size(message,&w,&h,&aw);
1231 //I changed how these coords were calculated for the high-res automap. -MT
1232 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1233 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1234 x = (grd_curcanv->cv_w-w)/2;
1235 y = (grd_curcanv->cv_h-h)/2;
1238 modex_clear_box(x-2,y-2,w+4,h+4);
1239 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1241 gr_setcolor(gr_find_closest_color_current(0,0,0));
1242 gr_rect(x-2,y-2,x+w+2,y+h+2);
1243 gr_printf(x,y,message);
1244 gr_set_curfont(save_font);
1246 t1 = timer_get_fixed_seconds() + F1_0;
1248 gr_palette_read(pal); //get actual palette from the hardware
1249 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1251 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1253 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1255 gr_set_current_canvas(screen_canv);
1257 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1258 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1260 gr_free_canvas(temp_canv);
1262 gr_free_canvas(temp_canv2);
1264 gr_set_current_canvas(save_canv);
1270 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1271 grs_canvas *temp_canv, *save_canv;
1273 // Can't do screen shots in VR modes.
1274 if ( VR_render_mode != VR_NONE )
1279 save_canv = grd_curcanv;
1280 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1283 gr_set_current_canvas( temp_canv );
1284 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1285 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1289 if (Game_mode & GM_MULTI)
1296 gr_set_current_canvas(screen_canv);
1298 // if (!automap_flag)
1299 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1301 gr_free_canvas(temp_canv);
1303 gr_set_current_canvas(save_canv);
1312 void fly_init(object *obj)
1314 obj->control_type = CT_FLYING;
1315 obj->movement_type = MT_PHYSICS;
1317 vm_vec_zero(&obj->mtype.phys_info.velocity);
1318 vm_vec_zero(&obj->mtype.phys_info.thrust);
1319 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1320 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1323 //void morph_test(), morph_step();
1326 // ------------------------------------------------------------------------------------
1328 void test_anim_states();
1332 //put up the help message
1339 extern int been_in_editor;
1341 // ------------------------------------------------------------------------------------
1342 void do_cloak_stuff(void)
1345 for (i = 0; i < N_players; i++)
1346 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1347 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1348 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1349 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1350 if (i == Player_num) {
1351 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1353 if (Game_mode & GM_MULTI)
1354 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1355 maybe_drop_net_powerup(POW_CLOAK);
1356 multi_send_decloak(); // For demo recording
1358 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1366 // ------------------------------------------------------------------------------------
1367 void do_invulnerable_stuff(void)
1369 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1370 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1371 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1374 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1376 if (Game_mode & GM_MULTI)
1378 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1379 maybe_drop_net_powerup(POW_INVULNERABILITY);
1382 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1389 ubyte Last_afterburner_state = 0;
1390 fix Last_afterburner_charge = 0;
1392 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1393 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1397 //@@// ------------------------------------------------------------------------------------
1398 //@@void afterburner_shake(void)
1402 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1403 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1405 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1406 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1407 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1411 // ------------------------------------------------------------------------------------
1413 extern void multi_send_sound_function (char,char);
1416 void do_afterburner_stuff(void)
1418 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1419 Afterburner_charge=0;
1421 if (Endlevel_sequence || Player_is_dead)
1423 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1425 multi_send_sound_function (0,0);
1429 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1431 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1432 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1434 if (Game_mode & GM_MULTI)
1435 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1438 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1439 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1441 if (Game_mode & GM_MULTI)
1442 multi_send_sound_function (0,0);
1444 mprintf((0,"Killing afterburner sound\n"));
1448 //@@if (Controls.afterburner_state && Afterburner_charge)
1449 //@@ afterburner_shake();
1451 Last_afterburner_state = Controls.afterburner_state;
1452 Last_afterburner_charge = Afterburner_charge;
1455 // -- // ------------------------------------------------------------------------------------
1456 // -- // if energy < F1_0/2, recharge up to F1_0/2
1457 // -- void recharge_energy_frame(void)
1459 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1460 // -- Players[Player_num].energy += FrameTime/4;
1462 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1463 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1467 // Amount to diminish guns towards normal, per second.
1468 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1470 extern fix Flash_effect;
1472 //adds to rgb values for palette flash
1473 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1477 PaletteRedAdd += _dr;
1478 PaletteGreenAdd += _dg;
1479 PaletteBlueAdd += _db;
1481 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1486 maxval = MAX_PALETTE_ADD;
1488 if (PaletteRedAdd > maxval)
1489 PaletteRedAdd = maxval;
1491 if (PaletteGreenAdd > maxval)
1492 PaletteGreenAdd = maxval;
1494 if (PaletteBlueAdd > maxval)
1495 PaletteBlueAdd = maxval;
1497 if (PaletteRedAdd < -maxval)
1498 PaletteRedAdd = -maxval;
1500 if (PaletteGreenAdd < -maxval)
1501 PaletteGreenAdd = -maxval;
1503 if (PaletteBlueAdd < -maxval)
1504 PaletteBlueAdd = -maxval;
1507 fix Time_flash_last_played;
1510 void game_palette_step_up( int r, int g, int b );
1511 // ------------------------------------------------------------------------------------
1512 // Diminish palette effects towards normal.
1513 void diminish_palette_towards_normal(void)
1517 // Diminish at DIMINISH_RATE units/second.
1518 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1519 if (FrameTime < F1_0/DIMINISH_RATE) {
1520 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1523 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1524 if (dec_amount == 0)
1525 dec_amount++; // make sure we decrement by something
1531 // Part of hack system to force update of palette after exiting a menu.
1532 if (Time_flash_last_played) {
1534 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1537 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1538 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1539 Time_flash_last_played = GameTime;
1542 Flash_effect -= FrameTime;
1543 if (Flash_effect < 0)
1546 if (force_do || (d_rand() > 4096 )) {
1547 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1548 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1550 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1557 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1558 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1560 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1561 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1563 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1564 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1566 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1567 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1569 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1571 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1574 int Redsave, Bluesave, Greensave;
1576 void palette_save(void)
1578 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1581 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1583 void game_palette_step_up( int r, int g, int b )
1585 if ( VR_use_reg_code ) {
1586 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1588 gr_palette_step_up( r, g, b );
1592 void palette_restore(void)
1594 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1595 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1597 // Forces flash effect to fixup palette next frame.
1598 Time_flash_last_played = 0;
1601 extern void dead_player_frame(void);
1604 // --------------------------------------------------------------------------------------------------
1605 int allowed_to_fire_laser(void)
1607 if (Player_is_dead) {
1608 Global_missile_firing_count = 0;
1612 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1613 // be a long while before laser can be fired, then there must be some mistake!
1614 if (Next_laser_fire_time > GameTime)
1615 if (Next_laser_fire_time < GameTime + 2*F1_0)
1621 fix Next_flare_fire_time = 0;
1622 #define FLARE_BIG_DELAY (F1_0*2)
1624 int allowed_to_fire_flare(void)
1626 if (Next_flare_fire_time > GameTime)
1627 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1630 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1631 Next_flare_fire_time = GameTime + F1_0/4;
1633 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1638 int allowed_to_fire_missile(void)
1640 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1641 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1642 // be a long while before missile can be fired, then there must be some mistake!
1643 if (Next_missile_fire_time > GameTime)
1644 if (Next_missile_fire_time < GameTime + 5*F1_0)
1650 void full_palette_save(void)
1653 apply_modified_palette();
1654 reset_palette_add();
1655 gr_palette_load( gr_palette );
1658 extern int Death_sequence_aborted;
1659 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) );
1666 char pixel_double_help[64];
1669 char command_help[64], save_help[64], restore_help[64];
1672 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
1674 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F2;
1675 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F3;
1677 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1678 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1679 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = save_help;
1680 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = restore_help;
1682 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
1683 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F3;
1684 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F4;
1685 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
1686 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F6\t Fast Save";
1688 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
1690 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (F15)\t Pause";
1692 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_MINUSPLUS;
1694 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
1696 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "printscrn (F13)\t save screen shot";
1698 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
1699 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
1700 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F1\t Cycle left window";
1701 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F2\t Cycle right window";
1702 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F4\t GuideBot menu";
1704 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F4\t Rename GuideBot";
1706 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Opt-Shift-F4\t Rename GuideBot";
1708 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F5\t Drop primary";
1709 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F6\t Drop secondary";
1710 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F7\t Calibrate joystick";
1711 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-number\t GuideBot commands";
1713 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1714 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = pixel_double_help;
1717 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
1718 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1719 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = command_help;
1722 full_palette_save();
1724 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1729 //temp function until Matt cleans up game sequencing
1730 extern void temp_reset_stuff_on_level();
1732 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
1734 //deal with rear view - switch it on, or off, or whatever
1735 void check_rear_view()
1737 static int leave_mode;
1738 static fix entry_time;
1740 if ( Controls.rear_view_down_count ) { //key/button has gone down
1744 if (Cockpit_mode==CM_REAR_VIEW) {
1745 select_cockpit(Cockpit_mode_save);
1746 Cockpit_mode_save = -1;
1748 if (Newdemo_state == ND_STATE_RECORDING)
1749 newdemo_record_restore_rearview();
1753 if (Rear_view_leave_time <= 0)
1755 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
1759 leave_mode = 0; // means wait for another key
1760 entry_time = timer_get_fixed_seconds();
1762 if (Cockpit_mode == CM_FULL_COCKPIT) {
1763 Cockpit_mode_save = Cockpit_mode;
1764 select_cockpit(CM_REAR_VIEW);
1766 if (Newdemo_state == ND_STATE_RECORDING)
1767 newdemo_record_rearview();
1771 if (Controls.rear_view_down_state) {
1773 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
1778 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
1780 if (leave_mode==1 && Rear_view) {
1782 if (Cockpit_mode==CM_REAR_VIEW) {
1783 select_cockpit(Cockpit_mode_save);
1784 Cockpit_mode_save = -1;
1786 if (Newdemo_state == ND_STATE_RECORDING)
1787 newdemo_record_restore_rearview();
1792 void reset_rear_view(void)
1795 if (Newdemo_state == ND_STATE_RECORDING)
1796 newdemo_record_restore_rearview();
1801 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
1802 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
1803 Cockpit_mode_save = CM_FULL_COCKPIT;
1804 select_cockpit(Cockpit_mode_save);
1805 Cockpit_mode_save = -1;
1811 int Config_menu_flag;
1815 int gr_renderstats = 0;
1816 // need to define "cheat" for renderstats
1817 int gr_badtexture = 0;
1818 // need to define "cheat" for badtexture
1820 int Cheats_enabled=0;
1822 extern int Laser_rapid_fire;
1823 extern void do_lunacy_on(), do_lunacy_off();
1825 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
1826 extern char BounceCheat,HomingCheat,OldHomingState[20];
1827 extern char AcidCheatOn,old_IntMethod, Monster_mode;
1828 extern int Buddy_dude_cheat;
1830 //turns off active cheats
1831 void turn_cheats_off()
1837 Weapon_info[i].homing_flag=OldHomingState[i];
1842 Interpolation_method=old_IntMethod;
1845 Buddy_dude_cheat = 0;
1849 Laser_rapid_fire = 0;
1850 Physics_cheat_flag = 0;
1852 Robots_kill_robots_cheat=0;
1853 Robot_firing_enabled = 1;
1856 //turns off all cheats & resets cheater flag
1857 void game_disable_cheats()
1865 // ----------------------------------------------------------------------------
1867 void game_setup(void)
1869 //@@int demo_playing=0;
1870 //@@int multi_game=0;
1872 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
1873 do_lunacy_off(); // Restore true insane mode.
1876 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
1877 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
1878 Endlevel_sequence = 0;
1880 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
1881 //@@ demo_playing = 1;
1882 //@@if ( Game_mode & GM_MULTI )
1883 //@@ multi_game = 1;
1885 set_screen_mode(SCREEN_GAME);
1886 reset_palette_add();
1888 set_warn_func(game_show_warning);
1892 //digi_init_sounds();
1894 //keyd_repeat = 0; // Don't allow repeat in game
1895 keyd_repeat = 1; // Do allow repeat in game
1898 //_MARK_("start of game");
1902 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
1903 obj_relink( OBJECT_NUMBER(ConsoleObject), SEG_PTR_2_NUM(Cursegp) );
1905 if (!check_obj_seg(ConsoleObject))
1906 move_player_2_segment(Cursegp,Curside);
1909 Viewer = ConsoleObject;
1910 fly_init(ConsoleObject);
1915 FrameTime = 0; //make first frame zero
1918 if (Current_level_num == 0) { //not a real level
1919 init_player_stats_game();
1926 game_flush_inputs();
1932 extern char IWasKicked;
1936 // ------------------------------------------------------------------------------------
1937 //this function is the game. called when game mode selected. runs until
1938 //editor mode or exit selected
1941 game_setup(); // Replaces what was here earlier.
1942 // Good for Windows Sake.
1945 ProfilerSetStatus(1);
1948 if ( setjmp(LeaveGame)==0 ) {
1954 Config_menu_flag = 0;
1956 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
1958 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
1959 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
1962 player_shields = Players[Player_num].shields;
1964 ExtGameStatus=GAMESTAT_RUNNING;
1965 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
1967 if (oldfov != cg_fov.value)
1969 oldfov = cg_fov.value;
1970 if (cg_fov.value < 1)
1971 cvar_set("fov", "1");
1972 if (cg_fov.value > 170)
1973 cvar_set("fov", "170");
1974 Render_zoom = fl2f(cg_fov.value * M_PI / 180); // convert to radians
1975 con_printf(CON_VERBOSE, "FOV set to %f (0x%08x)\n", cg_fov.value, Render_zoom);
1978 //if the player is taking damage, give up guided missile control
1979 if (Players[Player_num].shields != player_shields)
1980 release_guided_missile(Player_num);
1982 //see if redbook song needs to be restarted
1983 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
1985 if (Config_menu_flag) {
1986 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
1988 if (!(Game_mode&GM_MULTI)) palette_restore();
1992 int save_w=Game_window_w,save_h=Game_window_h;
1994 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
1995 Game_window_w=save_w; Game_window_h=save_h;
1997 last_drawn_cockpit[0] = -1;
1998 last_drawn_cockpit[1] = -1;
2001 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2003 fmode = Function_mode;
2004 Function_mode = FMODE_GAME;
2006 apply_modified_palette();
2007 reset_palette_add();
2008 gr_palette_load( gr_palette );
2009 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2011 Function_mode = fmode;
2014 newdemo_stop_playback();
2015 Function_mode = FMODE_MENU;
2017 Function_mode = FMODE_GAME;
2021 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2027 fmode = Function_mode;
2028 Function_mode = FMODE_GAME;
2030 apply_modified_palette();
2031 reset_palette_add();
2032 gr_palette_load( gr_palette );
2033 ExtGameStatus=GAMESTAT_ABORT_GAME;
2034 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2036 Function_mode = fmode;
2038 Function_mode = FMODE_GAME;
2044 if (Function_mode != FMODE_GAME)
2045 longjmp(LeaveGame,0);
2048 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2049 longjmp(LeaveGame,0);
2055 ProfilerSetStatus(0);
2060 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2061 newdemo_stop_recording();
2067 if ( Newdemo_state == ND_STATE_PLAYBACK )
2068 newdemo_stop_playback();
2070 if (Cockpit_mode_save!=-1)
2072 Cockpit_mode=Cockpit_mode_save;
2073 Cockpit_mode_save=-1;
2076 if (Function_mode != FMODE_EDITOR)
2077 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2079 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2080 //@@ scores_maybe_add_player(Game_aborted);
2084 //_MARK_("end of game");
2087 clear_warn_func(game_show_warning); //don't use this func anymore
2089 game_disable_cheats();
2092 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2096 //called at the end of the program
2099 if (VR_offscreen_buffer) {
2100 gr_free_canvas(VR_offscreen_buffer);
2101 VR_offscreen_buffer = NULL;
2104 close_gauge_canvases();
2106 restore_effect_bitmap_icons();
2108 if (background_bitmap.bm_data)
2109 d_free(background_bitmap.bm_data);
2111 clear_warn_func(game_show_warning); //don't use this func anymore
2114 grs_canvas * get_current_game_screen()
2116 return &VR_screen_pages[VR_current_page];
2120 extern void kconfig_center_headset();
2124 void speedtest_frame(void);
2125 int Debug_slowdown=0;
2129 extern void player_follow_path(object *objp);
2130 extern void check_create_player_path(void);
2134 extern int Do_appearance_effect;
2136 object *Missile_viewer=NULL;
2138 int Missile_view_enabled = 1;
2140 int Marker_viewer_num[2]={-1,-1};
2141 int Coop_view_player[2]={-1,-1};
2142 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2144 //returns ptr to escort robot, or NULL
2145 object *find_escort()
2149 for (i=0; i<=Highest_object_index; i++)
2150 if (Objects[i].type == OBJ_ROBOT)
2151 if (Robot_info[Objects[i].id].companion)
2157 extern void process_super_mines_frame(void);
2158 extern void do_seismic_stuff(void);
2161 int Saving_movie_frames=0;
2162 int __Movie_frame_num=0;
2164 #define MAX_MOVIE_BUFFER_FRAMES 250
2165 #define MOVIE_FRAME_SIZE (320 * 200)
2167 ubyte *Movie_frame_buffer;
2168 int Movie_frame_counter;
2169 ubyte Movie_pal[768];
2170 char movie_path[50] = ".\\";
2172 grs_bitmap Movie_bm;
2174 void flush_movie_buffer()
2181 mprintf((0,"Flushing movie buffer..."));
2183 Movie_bm.bm_data = Movie_frame_buffer;
2185 for (f=0;f<Movie_frame_counter;f++) {
2186 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2187 __Movie_frame_num++;
2188 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2189 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2192 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2195 Movie_frame_counter=0;
2197 mprintf((0,"done \n"));
2202 void toggle_movie_saving()
2206 Saving_movie_frames = !Saving_movie_frames;
2208 if (Saving_movie_frames) {
2211 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2212 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2215 Saving_movie_frames = 0;
2219 while (isspace(movie_path[strlen(movie_path)-1]))
2220 movie_path[strlen(movie_path)-1] = 0;
2221 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2222 strcat(movie_path,"\\");
2225 if (!Movie_frame_buffer) {
2226 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2227 if (!Movie_frame_buffer) {
2229 Saving_movie_frames=0;
2232 Movie_frame_counter=0;
2234 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2235 Movie_bm.bm_w = 320;
2236 Movie_bm.bm_h = 200;
2237 Movie_bm.bm_type = BM_LINEAR;
2238 Movie_bm.bm_flags = 0;
2239 Movie_bm.bm_rowsize = 320;
2240 Movie_bm.bm_handle = 0;
2242 gr_palette_read(Movie_pal); //get actual palette from the hardware
2244 if (Newdemo_state == ND_STATE_PLAYBACK)
2245 Newdemo_do_interpolate = 0;
2249 flush_movie_buffer();
2251 if (Newdemo_state == ND_STATE_PLAYBACK)
2252 Newdemo_do_interpolate = 1;
2257 void save_movie_frame()
2259 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2261 Movie_frame_counter++;
2263 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2264 flush_movie_buffer();
2270 extern int Level_shake_duration;
2272 //if water or fire level, make occasional sound
2273 void do_ambient_sounds()
2275 int has_water,has_lava;
2278 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2279 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2281 if (has_lava) { //has lava
2282 sound = SOUND_AMBIENT_LAVA;
2283 if (has_water && (d_rand() & 1)) //both, pick one
2284 sound = SOUND_AMBIENT_WATER;
2286 else if (has_water) //just water
2287 sound = SOUND_AMBIENT_WATER;
2291 if (((d_rand() << 3) < FrameTime)) { //play the sound
2292 fix volume = d_rand() + f1_0/2;
2293 digi_play_sample(sound,volume);
2297 // -- extern void lightning_frame(void);
2299 void game_render_frame();
2300 extern void omega_charge_frame(void);
2302 extern time_t t_current_time, t_saved_time;
2304 void flicker_lights();
2306 void GameLoop(int RenderFlag, int ReadControlsFlag )
2309 // Used to slow down frame rate for testing things.
2310 // RenderFlag = 1; // DEBUG
2311 if (Debug_slowdown) {
2314 for (h=0; h<Debug_slowdown; h++)
2315 for (i=0; i<1000; i++)
2320 cmd_queue_process();
2323 if (FindArg("-invulnerability"))
2324 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2328 update_player_stats();
2329 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2330 do_afterburner_stuff();
2332 do_invulnerable_stuff();
2333 remove_obsolete_stuck_objects();
2335 do_final_boss_frame();
2336 // -- lightning_frame();
2337 // -- recharge_energy_frame();
2339 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2340 static int turned_off=0;
2341 Players[Player_num].energy -= (FrameTime*3/8);
2342 if (Players[Player_num].energy < i2f(10)) {
2344 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2347 if (Game_mode & GM_MULTI)
2348 multi_send_flags(Player_num);
2355 if (Players[Player_num].energy <= 0) {
2356 Players[Player_num].energy = 0;
2357 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2359 if (Game_mode & GM_MULTI)
2360 multi_send_flags(Player_num);
2367 check_create_player_path();
2368 player_follow_path(ConsoleObject);
2372 if (Game_mode & GM_MULTI)
2375 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2376 multi_check_for_killgoal_winner();
2382 if (force_cockpit_redraw) { //screen need redrawing?
2384 force_cockpit_redraw=0;
2386 game_render_frame();
2387 //show_extra_views(); //missile view, buddy bot, etc.
2390 if (Saving_movie_frames)
2397 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2401 dead_player_frame();
2402 if (Newdemo_state != ND_STATE_PLAYBACK)
2403 do_controlcen_dead_frame();
2405 process_super_mines_frame();
2407 do_ambient_sounds();
2414 if (ReadControlsFlag)
2417 memset(&Controls, 0, sizeof(Controls));
2419 GameTime += FrameTime;
2421 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2422 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2424 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2425 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2426 mprintf((0,"GameTime reset to 0\n"));
2430 if (FindArg("-checktime") != 0)
2431 if (GameTime >= i2f(600)) //wrap after 10 minutes
2432 GameTime = FrameTime;
2436 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2437 ThisLevelTime +=FrameTime;
2442 if (Endlevel_sequence) {
2443 do_endlevel_frame();
2444 powerup_grab_cheat_all();
2445 do_special_effects();
2446 return; //skip everything else
2449 if (Newdemo_state != ND_STATE_PLAYBACK)
2450 do_exploding_wall_frame();
2451 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2452 do_special_effects();
2453 wall_frame_process();
2454 triggers_frame_process();
2458 if (Control_center_destroyed) {
2459 if (Newdemo_state==ND_STATE_RECORDING )
2460 newdemo_record_control_center_destroyed();
2465 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2466 newdemo_playback_one_frame();
2467 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2468 longjmp( LeaveGame, 0 ); // Go back to menu
2471 { // Note the link to above!
2473 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2476 powerup_grab_cheat_all();
2478 if (Endlevel_sequence) //might have been started during move
2481 fuelcen_update_all();
2485 if (allowed_to_fire_laser())
2486 FireLaser(); // Fire Laser!
2488 if (Auto_fire_fusion_cannon_time) {
2489 if (Primary_weapon != FUSION_INDEX)
2490 Auto_fire_fusion_cannon_time = 0;
2491 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2492 Auto_fire_fusion_cannon_time = 0;
2493 Global_laser_firing_count = 1;
2495 vms_vector rand_vec;
2498 Global_laser_firing_count = 0;
2500 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2501 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2502 make_random_vector(&rand_vec);
2504 bump_amount = F1_0*4;
2506 if (Fusion_charge > F1_0*2)
2507 bump_amount = Fusion_charge*4;
2509 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2513 if (Global_laser_firing_count) {
2514 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2515 // if (Fusion_charge > F1_0*2)
2516 // Fusion_charge = F1_0*2;
2517 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2520 if (Global_laser_firing_count < 0)
2521 Global_laser_firing_count = 0;
2524 if (Do_appearance_effect) {
2525 create_player_appearance_effect(ConsoleObject);
2526 Do_appearance_effect = 0;
2528 if ((Game_mode & GM_MULTI) && Netgame.invul)
2530 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2531 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2538 omega_charge_frame();
2542 //!!hoard_light_pulse(); //do cool hoard light pulsing
2546 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2547 //!!extern int Hoard_goal_eclip;
2549 //!!//do cool pulsing lights in hoard goals
2550 //!!hoard_light_pulse()
2552 //!! if (Game_mode & GM_HOARD) {
2556 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2560 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2563 //!! light = abs(frame - 5) * f1_0 / 5;
2565 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2570 ubyte Slide_segs[MAX_SEGMENTS];
2571 int Slide_segs_computed;
2573 void compute_slide_segs(void)
2575 int segnum, sidenum;
2577 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2578 Slide_segs[segnum] = 0;
2579 for (sidenum=0;sidenum<6;sidenum++) {
2580 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2581 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2582 Slide_segs[segnum] |= 1 << sidenum;
2586 Slide_segs_computed = 1;
2589 // -----------------------------------------------------------------------------
2590 void slide_textures(void)
2592 int segnum,sidenum,i;
2594 if (!Slide_segs_computed)
2595 compute_slide_segs();
2597 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2598 if (Slide_segs[segnum]) {
2599 for (sidenum=0;sidenum<6;sidenum++) {
2600 if (Slide_segs[segnum] & (1 << sidenum)) {
2601 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2602 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2604 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2605 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2606 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2609 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2611 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2614 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2616 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2619 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2621 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2624 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2634 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2636 int Num_flickering_lights=0;
2638 void flicker_lights()
2641 flickering_light *f;
2643 f = Flickering_lights;
2645 for (l=0;l<Num_flickering_lights;l++,f++) {
2646 segment *segp = &Segments[f->segnum];
2648 //make sure this is actually a light
2649 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2651 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2654 if (f->timer == 0x80000000) //disabled
2657 if ((f->timer -= FrameTime) < 0) {
2659 while (f->timer < 0)
2660 f->timer += f->delay;
2662 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2665 add_light(f->segnum,f->sidenum);
2667 subtract_light(f->segnum,f->sidenum);
2672 //returns ptr to flickering light structure, or NULL if can't find
2673 flickering_light *find_flicker(int segnum,int sidenum)
2676 flickering_light *f;
2678 //see if there's already an entry for this seg/side
2680 f = Flickering_lights;
2682 for (l=0;l<Num_flickering_lights;l++,f++)
2683 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2689 //turn flickering off (because light has been turned off)
2690 void disable_flicker(int segnum,int sidenum)
2692 flickering_light *f;
2694 if ((f=find_flicker(segnum,sidenum)) != NULL)
2695 f->timer = 0x80000000;
2698 //turn flickering off (because light has been turned on)
2699 void enable_flicker(int segnum,int sidenum)
2701 flickering_light *f;
2703 if ((f=find_flicker(segnum,sidenum)) != NULL)
2710 //returns 1 if ok, 0 if error
2711 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
2714 flickering_light *f;
2716 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2718 //see if there's already an entry for this seg/side
2720 f = Flickering_lights;
2722 for (l=0;l<Num_flickering_lights;l++,f++)
2723 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2726 if (mask==0) { //clearing entry
2727 if (l == Num_flickering_lights)
2731 for (i=l;i<Num_flickering_lights-1;i++)
2732 Flickering_lights[i] = Flickering_lights[i+1];
2733 Num_flickering_lights--;
2738 if (l == Num_flickering_lights) {
2739 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
2742 Num_flickering_lights++;
2746 f->sidenum = sidenum;
2747 f->delay = f->timer = delay;
2755 // -----------------------------------------------------------------------------
2756 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
2761 Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
2763 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
2764 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
2765 Global_laser_firing_count = 0;
2767 if (Fusion_charge == 0)
2768 Players[Player_num].energy -= F1_0*2;
2770 Fusion_charge += FrameTime;
2771 Players[Player_num].energy -= FrameTime;
2773 if (Players[Player_num].energy <= 0) {
2774 Players[Player_num].energy = 0;
2775 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
2777 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
2778 // Fire the fusion cannon at this time in the future.
2780 if (Fusion_charge < F1_0*2)
2781 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
2783 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
2785 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
2786 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
2788 if (Fusion_next_sound_time < GameTime) {
2789 if (Fusion_charge > F1_0*2) {
2790 digi_play_sample( 11, F1_0 );
2791 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
2793 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
2794 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
2796 if (Game_mode & GM_MULTI)
2797 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
2800 Fusion_last_sound_time = GameTime;
2801 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
2809 // -------------------------------------------------------------------------------------------------------
2810 // If player is close enough to objnum, which ought to be a powerup, pick it up!
2811 // This could easily be made difficulty level dependent.
2812 void powerup_grab_cheat(object *player, int objnum)
2818 Assert(Objects[objnum].type == OBJ_POWERUP);
2820 powerup_size = Objects[objnum].size;
2821 player_size = player->size;
2823 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
2825 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
2826 vms_vector collision_point;
2828 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
2829 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
2833 // -------------------------------------------------------------------------------------------------------
2834 // Make it easier to pick up powerups.
2835 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
2836 // from player to powerup and player's forward vector.
2837 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
2838 // way before the player gets there.
2839 void powerup_grab_cheat_all(void)
2844 segp = &Segments[ConsoleObject->segnum];
2845 objnum = segp->objects;
2847 while (objnum != -1) {
2848 if (Objects[objnum].type == OBJ_POWERUP)
2849 powerup_grab_cheat(ConsoleObject, objnum);
2850 objnum = Objects[objnum].next;
2855 int Last_level_path_created = -1;
2857 #ifdef SHOW_EXIT_PATH
2859 // ------------------------------------------------------------------------------------------------------------------
2860 // Create path for player from current segment to goal segment.
2861 // Return true if path created, else return false.
2862 int mark_player_path_to_segment(int segnum)
2865 object *objp = ConsoleObject;
2866 short player_path_length=0;
2867 int player_hide_index=-1;
2869 if (Last_level_path_created == Current_level_num) {
2873 Last_level_path_created = Current_level_num;
2875 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
2876 mprintf((0, "Unable to form path of length %i for myself\n", 100));
2880 player_hide_index = Point_segs_free_ptr - Point_segs;
2881 Point_segs_free_ptr += player_path_length;
2883 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
2884 mprintf((1, "Can't create path. Not enough point_segs.\n"));
2885 ai_reset_all_paths();
2889 for (i=1; i<player_path_length; i++) {
2891 vms_vector seg_center;
2894 segnum = Point_segs[player_hide_index+i].segnum;
2895 mprintf((0, "%3i ", segnum));
2896 seg_center = Point_segs[player_hide_index+i].point;
2898 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
2900 Int3(); // Unable to drop energy powerup for path
2904 obj = &Objects[objnum];
2905 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
2906 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
2907 obj->rtype.vclip_info.framenum = 0;
2908 obj->lifeleft = F1_0*100 + d_rand() * 4;
2915 // Return true if it happened, else return false.
2916 int create_special_path(void)
2920 // ---------- Find exit doors ----------
2921 for (i=0; i<=Highest_segment_index; i++)
2922 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
2923 if (Segments[i].children[j] == -2) {
2924 mprintf((0, "Exit at segment %i\n", i));
2925 return mark_player_path_to_segment(i);
2935 int Max_obj_count_mike = 0;
2937 // Shows current number of used objects.
2938 void show_free_objects(void)
2940 if (!(FrameCount & 8)) {
2944 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
2946 for (i=0; i<=Highest_object_index; i++)
2947 if (Objects[i].type != OBJ_NONE)
2950 mprintf((0, "%3i", count));
2952 if (count > Max_obj_count_mike) {
2953 Max_obj_count_mike = count;
2954 mprintf((0, " ***"));
2965 * reads a flickering_light structure from a CFILE
2967 void flickering_light_read(flickering_light *fl, CFILE *fp)
2969 fl->segnum = cfile_read_short(fp);
2970 fl->sidenum = cfile_read_short(fp);
2971 fl->mask = cfile_read_int(fp);
2972 fl->timer = cfile_read_fix(fp);
2973 fl->delay = cfile_read_fix(fp);
2976 void flickering_light_write(flickering_light *fl, PHYSFS_file *fp)
2978 PHYSFS_writeSLE16(fp, fl->segnum);
2979 PHYSFS_writeSLE16(fp, fl->sidenum);
2980 PHYSFS_writeULE32(fp, fl->mask);
2981 PHYSFSX_writeFix(fp, fl->timer);
2982 PHYSFSX_writeFix(fp, fl->delay);