1 /* $Id: game.c,v 1.43 2006-06-03 12:54:03 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Game loop for Inferno
26 char game_rcsid[] = "$Id: game.c,v 1.43 2006-06-03 12:54:03 chris Exp $";
38 #include <StandardFile.h>
39 #include <Quickdraw.h>
102 #include "controls.h"
108 #include "cntrlcen.h"
112 #include "multibot.h"
115 #include "playsave.h"
119 int VGA_current_mode;
122 #include <profiler.h>
125 //#define TEST_TIMER 1 //if this is set, do checking on timer
127 #define SHOW_EXIT_PATH 1
130 #include "editor/editor.h"
135 #if __WATCOMC__ < 1000
136 #include <wsample.h> //should come after inferno.h to get mark setting
141 extern void ReadControls(void); // located in gamecntl.c
142 extern int Current_display_mode;
143 extern void do_final_boss_frame(void);
145 int Speedtest_on = 0;
148 int Mark_count = 0; // number of debugging marks set
149 int Speedtest_start_time;
150 int Speedtest_segnum;
151 int Speedtest_sidenum;
152 int Speedtest_frame_start;
153 int Speedtest_count=0; // number of times to do the debug test.
156 static fix last_timer_value=0;
159 #if defined(TIMER_TEST) && !defined(NDEBUG)
160 fix _timer_value,actual_last_timer_value,_last_frametime;
161 int stop_count,start_count;
162 int time_stopped,time_started;
165 int VR_screen_mode = 0;
167 ubyte VR_screen_flags = 0; //see values in screens.h
168 ubyte VR_current_page = 0;
169 fix VR_eye_width = F1_0;
170 int VR_render_mode = VR_NONE;
171 int VR_low_res = 3; // Default to low res
173 int VR_sensitivity = 1; // 0 - 2
176 int VR_eye_offset = 0;
177 int VR_eye_switch = 0;
178 int VR_eye_offset_changed = 0;
179 int VR_use_reg_code = 0;
181 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
182 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
183 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
184 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
185 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
187 //do menus work in 640x480 or 320x200?
188 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
189 int MenuHiresAvailable = 1; //can we do highres menus?
190 int MenuHires = 1; //are we currently in highres menus?
192 int Debug_pause=0; //John's debugging pause system
194 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
196 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
197 int force_cockpit_redraw=0;
199 cvar_t r_framerate = {"r_framerate","0"};
201 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
203 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
205 int *Toggle_var = &Dummy_var;
208 //flag for whether initial fade-in has been done
212 #ifndef NDEBUG //these only exist if debugging
214 int Game_double_buffer = 1; //double buffer by default
215 fix fixed_frametime=0; //if non-zero, set frametime to this
219 int Game_suspended=0; //if non-zero, nothing moves but player
222 fix Auto_fire_fusion_cannon_time = 0;
223 fix Fusion_charge = 0;
224 fix Fusion_next_sound_time = 0;
225 fix Fusion_last_sound_time = 0;
228 int Game_turbo_mode = 0;
230 int Game_mode = GM_GAME_OVER;
232 int Global_laser_firing_count = 0;
233 int Global_missile_firing_count = 0;
235 grs_bitmap background_bitmap;
239 #define BACKGROUND_NAME "statback.pcx"
241 // Function prototypes for GAME.C exclusively.
243 void GameLoop(int RenderFlag, int ReadControlsFlag);
244 void FireLaser(void);
245 void slide_textures(void);
246 void powerup_grab_cheat_all(void);
249 extern void multi_check_for_killgoal_winner();
250 extern void RestoreGameSurfaces();
254 void grow_window(void);
255 void shrink_window(void);
259 void fill_background();
262 void show_framerate(void);
263 void ftoa(char *string, fix f);
266 extern ubyte DefiningMarkerMessage;
267 extern char Marker_input[];
269 // ==============================================================================================
271 extern char john_head_on;
273 void load_background_bitmap()
278 if (background_bitmap.bm_data)
279 d_free(background_bitmap.bm_data);
281 background_bitmap.bm_data=NULL;
282 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
283 if (pcx_error != PCX_ERROR_NONE)
284 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
285 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
289 //this is called once per game
292 atexit(close_game); //for cleanup
296 init_special_effects();
300 init_exploding_walls();
302 load_background_bitmap();
304 Clear_window = 2; // do portal only window clear.
306 set_detail_level_parameters(Detail_level);
309 cvar_registervariable(&r_framerate);
314 void reset_palette_add()
319 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
323 void game_show_warning(char *s)
326 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
329 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
331 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
336 //these should be in gr.h
337 #define cv_w cv_bitmap.bm_w
338 #define cv_h cv_bitmap.bm_h
340 //added 3/24/99 by Owen Evans for screen res changing
341 u_int32_t Game_screen_mode = 0;
343 int Game_window_x = 0;
344 int Game_window_y = 0;
345 int Game_window_w = 0;
346 int Game_window_h = 0;
347 int max_window_w = 0;
348 int max_window_h = 0;
350 extern void newdemo_record_cockpit_change(int);
352 //initialize the various canvases on the game screen
353 //called every time the screen mode or cockpit changes
356 // int minx, maxx, miny, maxy;
358 //Initialize the on-screen canvases
360 if (Newdemo_state==ND_STATE_RECORDING) {
361 newdemo_record_cockpit_change(Cockpit_mode);
364 if ( VR_render_mode != VR_NONE )
365 Cockpit_mode = CM_FULL_SCREEN;
367 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
368 Cockpit_mode = CM_FULL_SCREEN;
370 if ( Screen_mode == SCREEN_EDITOR )
371 Cockpit_mode = CM_FULL_SCREEN;
373 gr_set_current_canvas(NULL);
374 gr_set_curfont( GAME_FONT );
376 switch( Cockpit_mode ) {
377 case CM_FULL_COCKPIT:
380 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
382 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
384 gr_set_current_canvas(VR_offscreen_buffer);
386 gr_bitmap( 0, 0, bm );
387 bm = &VR_offscreen_buffer->cv_bitmap;
388 bm->bm_flags = BM_FLAG_TRANSPARENT;
389 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
392 if (Cockpit_mode == CM_FULL_COCKPIT)
393 game_init_render_sub_buffers(0, 0, grd_curscreen->sc_w, (grd_curscreen->sc_h*2)/3);
394 else if (Cockpit_mode == CM_REAR_VIEW)
395 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);
401 max_window_h = grd_curscreen->sc_h;
403 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
404 Game_window_h = max_window_h;
406 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
407 Game_window_w = max_window_w;
409 Game_window_x = (max_window_w - Game_window_w)/2;
410 Game_window_y = (max_window_h - Game_window_h)/2;
412 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
417 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
419 if (Game_window_h > max_window_h)
420 Game_window_h = max_window_h;
422 if (Game_window_w > max_window_w)
423 Game_window_w = max_window_w;
425 Game_window_x = (max_window_w - Game_window_w)/2;
426 Game_window_y = (max_window_h - Game_window_h)/2;
428 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
434 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
435 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
436 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
438 game_init_render_sub_buffers( x, y, w, h );
444 gr_set_current_canvas(NULL);
447 //selects a given cockpit (or lack of one). See types in game.h
448 void select_cockpit(int mode)
450 if (mode != Cockpit_mode) { //new mode
456 extern int last_drawn_cockpit[2];
458 //force cockpit redraw next time. call this if you've trashed the screen
461 force_cockpit_redraw=1;
462 last_drawn_cockpit[0] = -1;
463 last_drawn_cockpit[1] = -1;
466 // void HUD_clear_messages(); //Already declared in gauges.h
469 void VR_reset_params()
471 VR_eye_width = VR_SEPARATION;
472 VR_eye_offset = VR_PIXEL_SHIFT;
473 VR_eye_offset_changed = 2;
476 void game_init_render_sub_buffers( int x, int y, int w, int h )
478 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
479 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
483 // Sets up the canvases we will be rendering to (NORMAL VERSION)
484 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
486 // if (vga_check_mode(screen_mode) != 0)
487 // Error("Cannot set requested video mode");
489 VR_screen_mode = screen_mode;
491 VR_screen_flags = flags;
495 VR_render_mode = render_method;
497 Game_window_w = render_w;
498 Game_window_h = render_h;
500 if (VR_offscreen_buffer) {
501 gr_free_canvas(VR_offscreen_buffer);
504 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
505 if ( render_h*2 < 200 ) {
506 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
509 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
512 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
513 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
516 if ( render_h < 200 ) {
517 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
520 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
524 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
527 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
528 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
531 game_init_render_sub_buffers( 0, 0, render_w, render_h );
534 //called to get the screen in a mode compatible with popup menus.
535 //if we can't have popups over the game screen, switch to menu mode.
536 void set_popup_screen(void)
538 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
540 #ifndef OGL // always have to switch to menu mode
541 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
544 set_screen_mode(SCREEN_MENU); //must switch to menu mode
549 //called to change the screen mode. Parameter sm is the new mode, one of
550 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
551 //mode if cannot init requested mode)
552 int set_screen_mode(int sm)
555 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
556 gr_set_current_canvas( Canv_editor );
561 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
562 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
567 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
568 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
569 ogl_set_screen_mode();
580 switch( Screen_mode )
586 MenuHires = MenuHiresAvailable; //do highres if we can
588 menu_mode = MenuHires?SM(640,480):SM(320,200);
590 if (VGA_current_mode != menu_mode) {
591 if (gr_set_mode(menu_mode))
592 Error("Cannot set screen mode for menu");
593 if (!gr_palette_faded_out)
594 gr_palette_load(gr_palette);
597 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
598 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
600 FontHires = FontHiresAvailable && MenuHires;
606 if (VGA_current_mode != VR_screen_mode) {
607 if (gr_set_mode(VR_screen_mode)) {
608 Error("Cannot set desired screen mode for game!");
609 //we probably should do something else here, like select a standard mode
612 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
618 if ( VR_render_mode == VR_NONE )
620 max_window_w = grd_curscreen->sc_w;
621 max_window_h = grd_curscreen->sc_h;
623 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
624 if (Cockpit_mode == CM_STATUS_BAR)
625 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
627 else if (Cockpit_mode != CM_LETTERBOX)
628 Cockpit_mode = CM_FULL_SCREEN;
630 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
631 Game_window_w = max_window_w;
632 Game_window_h = max_window_h;
637 Cockpit_mode = CM_FULL_SCREEN;
639 // Define screen pages for game mode
640 // If we designate through screen_flags to use paging, then do so.
641 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
643 if ( VR_screen_flags&VRF_USE_PAGING )
644 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 );
646 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
650 FontHires = FontHiresAvailable && (MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2)));
652 if ( VR_render_mode != VR_NONE ) {
653 // for 640x480 or higher, use hires font.
654 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
664 if (grd_curscreen->sc_mode != SM(800,600)) {
666 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
667 Warning("Cannot init editor screen (error=%d)",gr_error);
671 gr_palette_load( gr_palette );
673 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
674 Canv_editor = &VR_editor_canvas;
675 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
676 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
677 gr_set_current_canvas( Canv_editor );
678 init_editor_screen(); //setup other editor stuff
682 Error("Invalid screen mode %d",sm);
687 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
689 if ( VR_screen_flags&VRF_USE_PAGING )
690 gr_show_canvas( &VR_screen_pages[VR_current_page] );
692 ogl_set_screen_mode();
698 int gr_toggle_fullscreen_game(void){
699 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
701 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
702 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
703 //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.
704 // generic_key_handler(KEY_PADENTER,0);
705 // generic_key_handler(KEY_ENTER, 0);
710 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
715 int arch_toggle_fullscreen_menu(void);
717 int gr_toggle_fullscreen_menu(void){
718 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
720 i=arch_toggle_fullscreen_menu();
722 // generic_key_handler(KEY_PADENTER,0);
723 // generic_key_handler(KEY_ENTER, 0);
732 static int timer_paused=0;
736 if (timer_paused==0) {
738 time = timer_get_fixed_seconds();
739 last_timer_value = time - last_timer_value;
740 if (last_timer_value < 0) {
741 #if defined(TIMER_TEST) && !defined(NDEBUG)
742 Int3(); //get Matt!!!!
744 last_timer_value = 0;
746 #if defined(TIMER_TEST) && !defined(NDEBUG)
752 #if defined(TIMER_TEST) && !defined(NDEBUG)
760 Assert(timer_paused >= 0);
761 if (timer_paused==0) {
763 time = timer_get_fixed_seconds();
764 #if defined(TIMER_TEST) && !defined(NDEBUG)
765 if (last_timer_value < 0)
766 Int3(); //get Matt!!!!
769 last_timer_value = time - last_timer_value;
770 #if defined(TIMER_TEST) && !defined(NDEBUG)
775 #if defined(TIMER_TEST) && !defined(NDEBUG)
780 MAC(extern ubyte joydefs_calibrating;)
782 void game_flush_inputs()
789 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
791 mouse_get_delta( &dx, &dy ); // Read mouse
792 memset(&Controls,0,sizeof(control_info));
797 last_timer_value = timer_get_fixed_seconds();
802 extern int Saving_movie_frames;
803 int Movie_fixed_frametime;
805 #define Saving_movie_frames 0
806 #define Movie_fixed_frametime 0
809 //added on 8/18/98 by Victor Rachels to add maximum framerate
810 int maxfps = MAX_FPS;
813 void calc_frame_time()
815 fix timer_value,last_frametime = FrameTime;
817 #if defined(TIMER_TEST) && !defined(NDEBUG)
818 _last_frametime = last_frametime;
821 timer_value = timer_get_fixed_seconds();
822 FrameTime = timer_value - last_timer_value;
824 while (FrameTime < f1_0 / maxfps)
826 timer_delay(f1_0 / maxfps - FrameTime);
827 timer_value = timer_get_fixed_seconds();
828 FrameTime = timer_value - last_timer_value;
831 #if defined(TIMER_TEST) && !defined(NDEBUG)
832 _timer_value = timer_value;
836 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
837 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
839 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
840 // if ( !dpmi_virtual_memory )
841 // Int3(); //Get MATT if hit this!
845 #if defined(TIMER_TEST) && !defined(NDEBUG)
846 actual_last_timer_value = last_timer_value;
849 if ( Game_turbo_mode )
852 // Limit frametime to be between 5 and 150 fps.
853 RealFrameTime = FrameTime;
854 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
855 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
857 last_timer_value = timer_value;
859 if (FrameTime < 0) //if bogus frametime...
860 FrameTime = last_frametime; //...then use time from last frame
863 if (fixed_frametime) FrameTime = fixed_frametime;
878 last_timer_value = timer_get_fixed_seconds();
886 #if defined(TIMER_TEST) && !defined(NDEBUG)
887 stop_count = start_count = 0;
890 // Set value to determine whether homing missile can see target.
891 // The lower frametime is, the more likely that it can see its target.
892 if (FrameTime <= F1_0/64)
893 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
894 else if (FrameTime < F1_0/32)
895 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
896 else if (FrameTime < F1_0/4)
897 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;
899 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
903 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
905 void move_player_2_segment(segment *seg,int side)
909 compute_segment_center(&ConsoleObject->pos,seg);
910 compute_center_point_on_side(&vp,seg,side);
911 vm_vec_sub2(&vp,&ConsoleObject->pos);
912 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
914 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
919 void game_draw_time_left()
921 char temp_string[30];
925 gr_set_curfont( GAME_FONT ); //GAME_FONT
926 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
928 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
929 i=f2i(timevar-ThisLevelTime);
932 sprintf( temp_string, "Time left: %d secs", i );
935 gr_string(0, 32, temp_string );
940 extern int Game_pause;
943 void level_with_floor();
945 void modex_clear_box(int x,int y,int w,int h)
947 grs_canvas *temp_canv,*save_canv;
949 save_canv = grd_curcanv;
950 temp_canv = gr_create_canvas(w,h);
951 gr_set_current_canvas(temp_canv);
952 gr_clear_canvas(BM_XRGB(0,0,0));
953 gr_set_current_canvas(save_canv);
954 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
955 gr_free_canvas(temp_canv);
959 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
961 // mac routine to drop contents of screen to a pict file using copybits
962 // save a PICT to a file
965 void SavePictScreen(int multiplayer)
969 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
972 PicHandle pict_handle;
973 static int multi_count = 0;
974 StandardFileReply sf_reply;
976 // dump the contents of the GameWindow into a picture using copybits
978 pict_handle = OpenPicture(&GameWindow->portRect);
979 if (pict_handle == NULL)
982 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
985 // get the cwd to restore with chdir when done -- this keeps the mac world sane
986 if (!getcwd(cwd, FILENAME_MAX))
990 sprintf(filename, "screen%d", multi_count++);
991 pfilename = c2pstr(filename);
994 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
995 if (!sf_reply.sfGood)
997 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
998 if (sf_reply.sfReplacing)
1000 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1004 // parid = GetAppDirId();
1005 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1010 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1015 // write the PICT file
1016 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1018 memset(buf, 0, sizeof(buf));
1020 if ( FSWrite(fd, &count, buf) )
1022 count = GetHandleSize((Handle)pict_handle);
1023 HLock((Handle)pict_handle);
1024 if ( FSWrite(fd, &count, *pict_handle) ) {
1030 HUnlock((Handle)pict_handle);
1031 DisposeHandle((Handle)pict_handle);
1039 //automap_flag is now unused, since we just check if the screen we're
1040 //writing to is modex
1041 //if called from automap, current canvas is set to visible screen
1043 void save_screen_shot(int automap_flag)
1045 #if !defined(MACINTOSH)
1048 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1049 grs_font *save_font;
1050 static int savenum=0;
1051 static int stereo_savenum=0;
1052 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1053 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1061 // // Can't do screen shots in VR modes.
1062 // if ( VR_render_mode != VR_NONE )
1067 save_canv = grd_curcanv;
1069 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1073 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1074 gr_set_current_canvas(temp_canv);
1075 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1077 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1078 gr_set_current_canvas(temp_canv2);
1079 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1082 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1083 gr_set_current_canvas(temp_canv);
1084 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1087 gr_set_current_canvas(save_canv);
1089 if ( savenum > 99 ) savenum = 0;
1090 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1093 sprintf(savename,"left%02d.pcx",stereo_savenum);
1094 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1095 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1097 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1100 sprintf(savename,"screen%02d.pcx",savenum++);
1101 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1104 if (!automap_flag) //if from automap, curcanv is already visible canv
1105 gr_set_current_canvas(NULL);
1106 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1107 if (!automap_flag && modex_flag)
1108 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1110 save_font = grd_curcanv->cv_font;
1111 gr_set_curfont(GAME_FONT);
1112 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1113 gr_get_string_size(message,&w,&h,&aw);
1118 //I changed how these coords were calculated for the high-res automap. -MT
1119 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1120 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1121 x = (grd_curcanv->cv_w-w)/2;
1122 y = (grd_curcanv->cv_h-h)/2;
1125 modex_clear_box(x-2,y-2,w+4,h+4);
1126 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1128 gr_setcolor(gr_find_closest_color_current(0,0,0));
1129 gr_rect(x-2,y-2,x+w+2,y+h+2);
1130 gr_printf(x,y,message);
1131 gr_set_curfont(save_font);
1133 t1 = timer_get_fixed_seconds() + F1_0;
1135 gr_palette_read(pal); //get actual palette from the hardware
1136 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1138 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1140 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1142 gr_set_current_canvas(screen_canv);
1144 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1145 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1147 gr_free_canvas(temp_canv);
1149 gr_free_canvas(temp_canv2);
1151 gr_set_current_canvas(save_canv);
1157 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1158 grs_canvas *temp_canv, *save_canv;
1160 // Can't do screen shots in VR modes.
1161 if ( VR_render_mode != VR_NONE )
1166 save_canv = grd_curcanv;
1167 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1170 gr_set_current_canvas( temp_canv );
1171 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1172 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1176 if (Game_mode & GM_MULTI)
1183 gr_set_current_canvas(screen_canv);
1185 // if (!automap_flag)
1186 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1188 gr_free_canvas(temp_canv);
1190 gr_set_current_canvas(save_canv);
1199 void fly_init(object *obj)
1201 obj->control_type = CT_FLYING;
1202 obj->movement_type = MT_PHYSICS;
1204 vm_vec_zero(&obj->mtype.phys_info.velocity);
1205 vm_vec_zero(&obj->mtype.phys_info.thrust);
1206 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1207 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1210 //void morph_test(), morph_step();
1213 // ------------------------------------------------------------------------------------
1215 void test_anim_states();
1219 //put up the help message
1226 extern int been_in_editor;
1228 // ------------------------------------------------------------------------------------
1229 void do_cloak_stuff(void)
1232 for (i = 0; i < N_players; i++)
1233 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1234 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1235 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1236 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1237 if (i == Player_num) {
1238 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1240 if (Game_mode & GM_MULTI)
1241 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1242 maybe_drop_net_powerup(POW_CLOAK);
1243 multi_send_decloak(); // For demo recording
1245 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1253 // ------------------------------------------------------------------------------------
1254 void do_invulnerable_stuff(void)
1256 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1257 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1258 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1261 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1263 if (Game_mode & GM_MULTI)
1265 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1266 maybe_drop_net_powerup(POW_INVULNERABILITY);
1269 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1276 ubyte Last_afterburner_state = 0;
1277 fix Last_afterburner_charge = 0;
1279 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1280 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1284 //@@// ------------------------------------------------------------------------------------
1285 //@@void afterburner_shake(void)
1289 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1290 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1292 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1293 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1294 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1298 // ------------------------------------------------------------------------------------
1300 extern void multi_send_sound_function (char,char);
1303 void do_afterburner_stuff(void)
1305 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1306 Afterburner_charge=0;
1308 if (Endlevel_sequence || Player_is_dead)
1310 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1312 multi_send_sound_function (0,0);
1316 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1318 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1319 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1321 if (Game_mode & GM_MULTI)
1322 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1325 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1326 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1328 if (Game_mode & GM_MULTI)
1329 multi_send_sound_function (0,0);
1331 mprintf((0,"Killing afterburner sound\n"));
1335 //@@if (Controls.afterburner_state && Afterburner_charge)
1336 //@@ afterburner_shake();
1338 Last_afterburner_state = Controls.afterburner_state;
1339 Last_afterburner_charge = Afterburner_charge;
1342 // -- // ------------------------------------------------------------------------------------
1343 // -- // if energy < F1_0/2, recharge up to F1_0/2
1344 // -- void recharge_energy_frame(void)
1346 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1347 // -- Players[Player_num].energy += FrameTime/4;
1349 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1350 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1354 // Amount to diminish guns towards normal, per second.
1355 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1357 extern fix Flash_effect;
1359 //adds to rgb values for palette flash
1360 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1364 PaletteRedAdd += _dr;
1365 PaletteGreenAdd += _dg;
1366 PaletteBlueAdd += _db;
1368 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1373 maxval = MAX_PALETTE_ADD;
1375 if (PaletteRedAdd > maxval)
1376 PaletteRedAdd = maxval;
1378 if (PaletteGreenAdd > maxval)
1379 PaletteGreenAdd = maxval;
1381 if (PaletteBlueAdd > maxval)
1382 PaletteBlueAdd = maxval;
1384 if (PaletteRedAdd < -maxval)
1385 PaletteRedAdd = -maxval;
1387 if (PaletteGreenAdd < -maxval)
1388 PaletteGreenAdd = -maxval;
1390 if (PaletteBlueAdd < -maxval)
1391 PaletteBlueAdd = -maxval;
1394 fix Time_flash_last_played;
1397 void game_palette_step_up( int r, int g, int b );
1398 // ------------------------------------------------------------------------------------
1399 // Diminish palette effects towards normal.
1400 void diminish_palette_towards_normal(void)
1404 // Diminish at DIMINISH_RATE units/second.
1405 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1406 if (FrameTime < F1_0/DIMINISH_RATE) {
1407 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1410 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1411 if (dec_amount == 0)
1412 dec_amount++; // make sure we decrement by something
1418 // Part of hack system to force update of palette after exiting a menu.
1419 if (Time_flash_last_played) {
1421 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1424 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1425 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1426 Time_flash_last_played = GameTime;
1429 Flash_effect -= FrameTime;
1430 if (Flash_effect < 0)
1433 if (force_do || (d_rand() > 4096 )) {
1434 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1435 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1437 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1444 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1445 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1447 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1448 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1450 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1451 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1453 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1454 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1456 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1458 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1461 int Redsave, Bluesave, Greensave;
1463 void palette_save(void)
1465 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1468 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1470 void game_palette_step_up( int r, int g, int b )
1472 if ( VR_use_reg_code ) {
1473 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1475 gr_palette_step_up( r, g, b );
1479 void palette_restore(void)
1481 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1482 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1484 // Forces flash effect to fixup palette next frame.
1485 Time_flash_last_played = 0;
1488 extern void dead_player_frame(void);
1491 // --------------------------------------------------------------------------------------------------
1492 int allowed_to_fire_laser(void)
1494 if (Player_is_dead) {
1495 Global_missile_firing_count = 0;
1499 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1500 // be a long while before laser can be fired, then there must be some mistake!
1501 if (Next_laser_fire_time > GameTime)
1502 if (Next_laser_fire_time < GameTime + 2*F1_0)
1508 fix Next_flare_fire_time = 0;
1509 #define FLARE_BIG_DELAY (F1_0*2)
1511 int allowed_to_fire_flare(void)
1513 if (Next_flare_fire_time > GameTime)
1514 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1517 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1518 Next_flare_fire_time = GameTime + F1_0/4;
1520 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1525 int allowed_to_fire_missile(void)
1527 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1528 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1529 // be a long while before missile can be fired, then there must be some mistake!
1530 if (Next_missile_fire_time > GameTime)
1531 if (Next_missile_fire_time < GameTime + 5*F1_0)
1537 void full_palette_save(void)
1540 apply_modified_palette();
1541 reset_palette_add();
1542 gr_palette_load( gr_palette );
1545 extern int Death_sequence_aborted;
1546 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) );
1553 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1556 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
1558 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F2;
1559 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F3;
1561 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1562 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1563 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = save_help;
1564 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = restore_help;
1566 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
1567 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F3;
1568 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F4;
1569 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
1570 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F6\t Fast Save";
1572 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
1574 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (F15)\t Pause";
1576 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_MINUSPLUS;
1578 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
1580 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "printscrn (F13)\t save screen shot";
1582 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
1583 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
1584 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F1\t Cycle left window";
1585 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F2\t Cycle right window";
1586 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F4\t GuideBot menu";
1588 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F4\t Rename GuideBot";
1590 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Opt-Shift-F4\t Rename GuideBot";
1592 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F5\t Drop primary";
1593 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F6\t Drop secondary";
1594 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F7\t Calibrate joystick";
1595 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-number\t GuideBot commands";
1597 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1598 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = pixel_double_help;
1599 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
1600 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1601 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = command_help;
1604 full_palette_save();
1606 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1611 //temp function until Matt cleans up game sequencing
1612 extern void temp_reset_stuff_on_level();
1614 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
1616 //deal with rear view - switch it on, or off, or whatever
1617 void check_rear_view()
1619 static int leave_mode;
1620 static fix entry_time;
1622 if ( Controls.rear_view_down_count ) { //key/button has gone down
1626 if (Cockpit_mode==CM_REAR_VIEW) {
1627 select_cockpit(Cockpit_mode_save);
1628 Cockpit_mode_save = -1;
1630 if (Newdemo_state == ND_STATE_RECORDING)
1631 newdemo_record_restore_rearview();
1635 if (Rear_view_leave_time <= 0)
1637 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
1641 leave_mode = 0; // means wait for another key
1642 entry_time = timer_get_fixed_seconds();
1644 if (Cockpit_mode == CM_FULL_COCKPIT) {
1645 Cockpit_mode_save = Cockpit_mode;
1646 select_cockpit(CM_REAR_VIEW);
1648 if (Newdemo_state == ND_STATE_RECORDING)
1649 newdemo_record_rearview();
1653 if (Controls.rear_view_down_state) {
1655 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
1660 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
1662 if (leave_mode==1 && Rear_view) {
1664 if (Cockpit_mode==CM_REAR_VIEW) {
1665 select_cockpit(Cockpit_mode_save);
1666 Cockpit_mode_save = -1;
1668 if (Newdemo_state == ND_STATE_RECORDING)
1669 newdemo_record_restore_rearview();
1674 void reset_rear_view(void)
1677 if (Newdemo_state == ND_STATE_RECORDING)
1678 newdemo_record_restore_rearview();
1683 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
1684 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
1685 Cockpit_mode_save = CM_FULL_COCKPIT;
1686 select_cockpit(Cockpit_mode_save);
1687 Cockpit_mode_save = -1;
1693 int Config_menu_flag;
1697 int gr_renderstats = 0;
1698 // need to define "cheat" for renderstats
1699 int gr_badtexture = 0;
1700 // need to define "cheat" for badtexture
1702 int Cheats_enabled=0;
1704 extern int Laser_rapid_fire;
1705 extern void do_lunacy_on(), do_lunacy_off();
1707 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
1708 extern char BounceCheat,HomingCheat,OldHomingState[20];
1709 extern char AcidCheatOn,old_IntMethod, Monster_mode;
1710 extern int Buddy_dude_cheat;
1712 //turns off active cheats
1713 void turn_cheats_off()
1719 Weapon_info[i].homing_flag=OldHomingState[i];
1724 Interpolation_method=old_IntMethod;
1727 Buddy_dude_cheat = 0;
1731 Laser_rapid_fire = 0;
1732 Physics_cheat_flag = 0;
1734 Robots_kill_robots_cheat=0;
1735 Robot_firing_enabled = 1;
1738 //turns off all cheats & resets cheater flag
1739 void game_disable_cheats()
1747 // ----------------------------------------------------------------------------
1749 void game_setup(void)
1751 //@@int demo_playing=0;
1752 //@@int multi_game=0;
1754 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
1755 do_lunacy_off(); // Restore true insane mode.
1758 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
1759 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
1760 Endlevel_sequence = 0;
1762 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
1763 //@@ demo_playing = 1;
1764 //@@if ( Game_mode & GM_MULTI )
1765 //@@ multi_game = 1;
1767 set_screen_mode(SCREEN_GAME);
1768 reset_palette_add();
1770 set_warn_func(game_show_warning);
1774 //digi_init_sounds();
1776 //keyd_repeat = 0; // Don't allow repeat in game
1777 keyd_repeat = 1; // Do allow repeat in game
1780 //_MARK_("start of game");
1784 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
1785 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
1787 if (!check_obj_seg(ConsoleObject))
1788 move_player_2_segment(Cursegp,Curside);
1791 Viewer = ConsoleObject;
1792 fly_init(ConsoleObject);
1797 FrameTime = 0; //make first frame zero
1800 if (Current_level_num == 0) { //not a real level
1801 init_player_stats_game();
1808 game_flush_inputs();
1814 extern char IWasKicked;
1818 // ------------------------------------------------------------------------------------
1819 //this function is the game. called when game mode selected. runs until
1820 //editor mode or exit selected
1823 game_setup(); // Replaces what was here earlier.
1824 // Good for Windows Sake.
1827 ProfilerSetStatus(1);
1830 if ( setjmp(LeaveGame)==0 ) {
1836 Config_menu_flag = 0;
1838 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
1840 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
1841 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
1844 player_shields = Players[Player_num].shields;
1846 ExtGameStatus=GAMESTAT_RUNNING;
1847 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
1849 //if the player is taking damage, give up guided missile control
1850 if (Players[Player_num].shields != player_shields)
1851 release_guided_missile(Player_num);
1853 //see if redbook song needs to be restarted
1854 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
1856 if (Config_menu_flag) {
1857 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
1859 if (!(Game_mode&GM_MULTI)) palette_restore();
1863 int save_w=Game_window_w,save_h=Game_window_h;
1865 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
1866 Game_window_w=save_w; Game_window_h=save_h;
1868 last_drawn_cockpit[0] = -1;
1869 last_drawn_cockpit[1] = -1;
1872 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
1874 fmode = Function_mode;
1875 Function_mode = FMODE_GAME;
1877 apply_modified_palette();
1878 reset_palette_add();
1879 gr_palette_load( gr_palette );
1880 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
1882 Function_mode = fmode;
1885 newdemo_stop_playback();
1886 Function_mode = FMODE_MENU;
1888 Function_mode = FMODE_GAME;
1892 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
1898 fmode = Function_mode;
1899 Function_mode = FMODE_GAME;
1901 apply_modified_palette();
1902 reset_palette_add();
1903 gr_palette_load( gr_palette );
1904 ExtGameStatus=GAMESTAT_ABORT_GAME;
1905 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
1907 Function_mode = fmode;
1909 Function_mode = FMODE_GAME;
1915 if (Function_mode != FMODE_GAME)
1916 longjmp(LeaveGame,0);
1919 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
1920 longjmp(LeaveGame,0);
1926 ProfilerSetStatus(0);
1931 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
1932 newdemo_stop_recording();
1938 if ( Newdemo_state == ND_STATE_PLAYBACK )
1939 newdemo_stop_playback();
1941 if (Cockpit_mode_save!=-1)
1943 Cockpit_mode=Cockpit_mode_save;
1944 Cockpit_mode_save=-1;
1947 if (Function_mode != FMODE_EDITOR)
1948 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
1950 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
1951 //@@ scores_maybe_add_player(Game_aborted);
1955 //_MARK_("end of game");
1958 clear_warn_func(game_show_warning); //don't use this func anymore
1960 game_disable_cheats();
1963 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
1967 //called at the end of the program
1970 if (VR_offscreen_buffer) {
1971 gr_free_canvas(VR_offscreen_buffer);
1972 VR_offscreen_buffer = NULL;
1975 close_gauge_canvases();
1977 restore_effect_bitmap_icons();
1979 if (background_bitmap.bm_data)
1980 d_free(background_bitmap.bm_data);
1982 clear_warn_func(game_show_warning); //don't use this func anymore
1985 grs_canvas * get_current_game_screen()
1987 return &VR_screen_pages[VR_current_page];
1991 extern void kconfig_center_headset();
1995 void speedtest_frame(void);
1996 int Debug_slowdown=0;
2000 extern void player_follow_path(object *objp);
2001 extern void check_create_player_path(void);
2005 extern int Do_appearance_effect;
2007 object *Missile_viewer=NULL;
2009 int Missile_view_enabled = 1;
2011 int Marker_viewer_num[2]={-1,-1};
2012 int Coop_view_player[2]={-1,-1};
2013 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2015 //returns ptr to escort robot, or NULL
2016 object *find_escort()
2020 for (i=0; i<=Highest_object_index; i++)
2021 if (Objects[i].type == OBJ_ROBOT)
2022 if (Robot_info[Objects[i].id].companion)
2028 extern void process_super_mines_frame(void);
2029 extern void do_seismic_stuff(void);
2032 int Saving_movie_frames=0;
2033 int __Movie_frame_num=0;
2035 #define MAX_MOVIE_BUFFER_FRAMES 250
2036 #define MOVIE_FRAME_SIZE (320 * 200)
2038 ubyte *Movie_frame_buffer;
2039 int Movie_frame_counter;
2040 ubyte Movie_pal[768];
2041 char movie_path[50] = ".\\";
2043 grs_bitmap Movie_bm;
2045 void flush_movie_buffer()
2052 mprintf((0,"Flushing movie buffer..."));
2054 Movie_bm.bm_data = Movie_frame_buffer;
2056 for (f=0;f<Movie_frame_counter;f++) {
2057 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2058 __Movie_frame_num++;
2059 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2060 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2063 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2066 Movie_frame_counter=0;
2068 mprintf((0,"done \n"));
2073 void toggle_movie_saving()
2077 Saving_movie_frames = !Saving_movie_frames;
2079 if (Saving_movie_frames) {
2082 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2083 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2086 Saving_movie_frames = 0;
2090 while (isspace(movie_path[strlen(movie_path)-1]))
2091 movie_path[strlen(movie_path)-1] = 0;
2092 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2093 strcat(movie_path,"\\");
2096 if (!Movie_frame_buffer) {
2097 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2098 if (!Movie_frame_buffer) {
2100 Saving_movie_frames=0;
2103 Movie_frame_counter=0;
2105 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2106 Movie_bm.bm_w = 320;
2107 Movie_bm.bm_h = 200;
2108 Movie_bm.bm_type = BM_LINEAR;
2109 Movie_bm.bm_flags = 0;
2110 Movie_bm.bm_rowsize = 320;
2111 Movie_bm.bm_handle = 0;
2113 gr_palette_read(Movie_pal); //get actual palette from the hardware
2115 if (Newdemo_state == ND_STATE_PLAYBACK)
2116 Newdemo_do_interpolate = 0;
2120 flush_movie_buffer();
2122 if (Newdemo_state == ND_STATE_PLAYBACK)
2123 Newdemo_do_interpolate = 1;
2128 void save_movie_frame()
2130 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2132 Movie_frame_counter++;
2134 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2135 flush_movie_buffer();
2141 extern int Level_shake_duration;
2143 //if water or fire level, make occasional sound
2144 void do_ambient_sounds()
2146 int has_water,has_lava;
2149 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2150 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2152 if (has_lava) { //has lava
2153 sound = SOUND_AMBIENT_LAVA;
2154 if (has_water && (d_rand() & 1)) //both, pick one
2155 sound = SOUND_AMBIENT_WATER;
2157 else if (has_water) //just water
2158 sound = SOUND_AMBIENT_WATER;
2162 if (((d_rand() << 3) < FrameTime)) { //play the sound
2163 fix volume = d_rand() + f1_0/2;
2164 digi_play_sample(sound,volume);
2168 // -- extern void lightning_frame(void);
2170 void game_render_frame();
2171 extern void omega_charge_frame(void);
2173 extern time_t t_current_time, t_saved_time;
2175 void flicker_lights();
2177 void GameLoop(int RenderFlag, int ReadControlsFlag )
2180 // Used to slow down frame rate for testing things.
2181 // RenderFlag = 1; // DEBUG
2182 if (Debug_slowdown) {
2185 for (h=0; h<Debug_slowdown; h++)
2186 for (i=0; i<1000; i++)
2192 if (FindArg("-invulnerability"))
2193 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2197 update_player_stats();
2198 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2199 do_afterburner_stuff();
2201 do_invulnerable_stuff();
2202 remove_obsolete_stuck_objects();
2204 do_final_boss_frame();
2205 // -- lightning_frame();
2206 // -- recharge_energy_frame();
2208 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2209 static int turned_off=0;
2210 Players[Player_num].energy -= (FrameTime*3/8);
2211 if (Players[Player_num].energy < i2f(10)) {
2213 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2216 if (Game_mode & GM_MULTI)
2217 multi_send_flags(Player_num);
2224 if (Players[Player_num].energy <= 0) {
2225 Players[Player_num].energy = 0;
2226 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2228 if (Game_mode & GM_MULTI)
2229 multi_send_flags(Player_num);
2236 check_create_player_path();
2237 player_follow_path(ConsoleObject);
2241 if (Game_mode & GM_MULTI)
2244 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2245 multi_check_for_killgoal_winner();
2251 if (force_cockpit_redraw) { //screen need redrawing?
2253 force_cockpit_redraw=0;
2255 game_render_frame();
2256 //show_extra_views(); //missile view, buddy bot, etc.
2259 if (Saving_movie_frames)
2266 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2270 dead_player_frame();
2271 if (Newdemo_state != ND_STATE_PLAYBACK)
2272 do_controlcen_dead_frame();
2274 process_super_mines_frame();
2276 do_ambient_sounds();
2283 if (ReadControlsFlag)
2286 memset(&Controls, 0, sizeof(Controls));
2288 GameTime += FrameTime;
2290 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2291 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2293 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2294 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2295 mprintf((0,"GameTime reset to 0\n"));
2299 if (FindArg("-checktime") != 0)
2300 if (GameTime >= i2f(600)) //wrap after 10 minutes
2301 GameTime = FrameTime;
2305 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2306 ThisLevelTime +=FrameTime;
2311 if (Endlevel_sequence) {
2312 do_endlevel_frame();
2313 powerup_grab_cheat_all();
2314 do_special_effects();
2315 return; //skip everything else
2318 if (Newdemo_state != ND_STATE_PLAYBACK)
2319 do_exploding_wall_frame();
2320 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2321 do_special_effects();
2322 wall_frame_process();
2323 triggers_frame_process();
2327 if (Control_center_destroyed) {
2328 if (Newdemo_state==ND_STATE_RECORDING )
2329 newdemo_record_control_center_destroyed();
2334 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2335 newdemo_playback_one_frame();
2336 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2337 longjmp( LeaveGame, 0 ); // Go back to menu
2340 { // Note the link to above!
2342 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2345 powerup_grab_cheat_all();
2347 if (Endlevel_sequence) //might have been started during move
2350 fuelcen_update_all();
2354 if (allowed_to_fire_laser())
2355 FireLaser(); // Fire Laser!
2357 if (Auto_fire_fusion_cannon_time) {
2358 if (Primary_weapon != FUSION_INDEX)
2359 Auto_fire_fusion_cannon_time = 0;
2360 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2361 Auto_fire_fusion_cannon_time = 0;
2362 Global_laser_firing_count = 1;
2364 vms_vector rand_vec;
2367 Global_laser_firing_count = 0;
2369 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2370 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2371 make_random_vector(&rand_vec);
2373 bump_amount = F1_0*4;
2375 if (Fusion_charge > F1_0*2)
2376 bump_amount = Fusion_charge*4;
2378 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2382 if (Global_laser_firing_count) {
2383 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2384 // if (Fusion_charge > F1_0*2)
2385 // Fusion_charge = F1_0*2;
2386 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2389 if (Global_laser_firing_count < 0)
2390 Global_laser_firing_count = 0;
2393 if (Do_appearance_effect) {
2394 create_player_appearance_effect(ConsoleObject);
2395 Do_appearance_effect = 0;
2397 if ((Game_mode & GM_MULTI) && Netgame.invul)
2399 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2400 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2407 omega_charge_frame();
2411 //!!hoard_light_pulse(); //do cool hoard light pulsing
2415 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2416 //!!extern int Hoard_goal_eclip;
2418 //!!//do cool pulsing lights in hoard goals
2419 //!!hoard_light_pulse()
2421 //!! if (Game_mode & GM_HOARD) {
2425 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2429 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2432 //!! light = abs(frame - 5) * f1_0 / 5;
2434 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2439 ubyte Slide_segs[MAX_SEGMENTS];
2440 int Slide_segs_computed;
2442 void compute_slide_segs(void)
2444 int segnum, sidenum;
2446 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2447 Slide_segs[segnum] = 0;
2448 for (sidenum=0;sidenum<6;sidenum++) {
2449 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2450 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2451 Slide_segs[segnum] |= 1 << sidenum;
2455 Slide_segs_computed = 1;
2458 // -----------------------------------------------------------------------------
2459 void slide_textures(void)
2461 int segnum,sidenum,i;
2463 if (!Slide_segs_computed)
2464 compute_slide_segs();
2466 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2467 if (Slide_segs[segnum]) {
2468 for (sidenum=0;sidenum<6;sidenum++) {
2469 if (Slide_segs[segnum] & (1 << sidenum)) {
2470 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2471 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2473 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2474 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2475 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2478 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2480 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2483 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2485 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2488 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2490 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2493 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2503 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2505 int Num_flickering_lights=0;
2507 void flicker_lights()
2510 flickering_light *f;
2512 f = Flickering_lights;
2514 for (l=0;l<Num_flickering_lights;l++,f++) {
2515 segment *segp = &Segments[f->segnum];
2517 //make sure this is actually a light
2518 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2520 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2523 if (f->timer == 0x80000000) //disabled
2526 if ((f->timer -= FrameTime) < 0) {
2528 while (f->timer < 0)
2529 f->timer += f->delay;
2531 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2534 add_light(f->segnum,f->sidenum);
2536 subtract_light(f->segnum,f->sidenum);
2541 //returns ptr to flickering light structure, or NULL if can't find
2542 flickering_light *find_flicker(int segnum,int sidenum)
2545 flickering_light *f;
2547 //see if there's already an entry for this seg/side
2549 f = Flickering_lights;
2551 for (l=0;l<Num_flickering_lights;l++,f++)
2552 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2558 //turn flickering off (because light has been turned off)
2559 void disable_flicker(int segnum,int sidenum)
2561 flickering_light *f;
2563 if ((f=find_flicker(segnum,sidenum)) != NULL)
2564 f->timer = 0x80000000;
2567 //turn flickering off (because light has been turned on)
2568 void enable_flicker(int segnum,int sidenum)
2570 flickering_light *f;
2572 if ((f=find_flicker(segnum,sidenum)) != NULL)
2579 //returns 1 if ok, 0 if error
2580 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
2583 flickering_light *f;
2585 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2587 //see if there's already an entry for this seg/side
2589 f = Flickering_lights;
2591 for (l=0;l<Num_flickering_lights;l++,f++)
2592 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2595 if (mask==0) { //clearing entry
2596 if (l == Num_flickering_lights)
2600 for (i=l;i<Num_flickering_lights-1;i++)
2601 Flickering_lights[i] = Flickering_lights[i+1];
2602 Num_flickering_lights--;
2607 if (l == Num_flickering_lights) {
2608 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
2611 Num_flickering_lights++;
2615 f->sidenum = sidenum;
2616 f->delay = f->timer = delay;
2624 // -----------------------------------------------------------------------------
2625 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
2630 Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
2632 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
2633 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
2634 Global_laser_firing_count = 0;
2636 if (Fusion_charge == 0)
2637 Players[Player_num].energy -= F1_0*2;
2639 Fusion_charge += FrameTime;
2640 Players[Player_num].energy -= FrameTime;
2642 if (Players[Player_num].energy <= 0) {
2643 Players[Player_num].energy = 0;
2644 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
2646 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
2647 // Fire the fusion cannon at this time in the future.
2649 if (Fusion_charge < F1_0*2)
2650 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
2652 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
2654 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
2655 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
2657 if (Fusion_next_sound_time < GameTime) {
2658 if (Fusion_charge > F1_0*2) {
2659 digi_play_sample( 11, F1_0 );
2660 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
2662 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
2663 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
2665 if (Game_mode & GM_MULTI)
2666 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
2669 Fusion_last_sound_time = GameTime;
2670 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
2678 // -------------------------------------------------------------------------------------------------------
2679 // If player is close enough to objnum, which ought to be a powerup, pick it up!
2680 // This could easily be made difficulty level dependent.
2681 void powerup_grab_cheat(object *player, int objnum)
2687 Assert(Objects[objnum].type == OBJ_POWERUP);
2689 powerup_size = Objects[objnum].size;
2690 player_size = player->size;
2692 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
2694 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
2695 vms_vector collision_point;
2697 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
2698 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
2702 // -------------------------------------------------------------------------------------------------------
2703 // Make it easier to pick up powerups.
2704 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
2705 // from player to powerup and player's forward vector.
2706 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
2707 // way before the player gets there.
2708 void powerup_grab_cheat_all(void)
2713 segp = &Segments[ConsoleObject->segnum];
2714 objnum = segp->objects;
2716 while (objnum != -1) {
2717 if (Objects[objnum].type == OBJ_POWERUP)
2718 powerup_grab_cheat(ConsoleObject, objnum);
2719 objnum = Objects[objnum].next;
2724 int Last_level_path_created = -1;
2726 #ifdef SHOW_EXIT_PATH
2728 // ------------------------------------------------------------------------------------------------------------------
2729 // Create path for player from current segment to goal segment.
2730 // Return true if path created, else return false.
2731 int mark_player_path_to_segment(int segnum)
2734 object *objp = ConsoleObject;
2735 short player_path_length=0;
2736 int player_hide_index=-1;
2738 if (Last_level_path_created == Current_level_num) {
2742 Last_level_path_created = Current_level_num;
2744 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
2745 mprintf((0, "Unable to form path of length %i for myself\n", 100));
2749 player_hide_index = Point_segs_free_ptr - Point_segs;
2750 Point_segs_free_ptr += player_path_length;
2752 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
2753 mprintf((1, "Can't create path. Not enough point_segs.\n"));
2754 ai_reset_all_paths();
2758 for (i=1; i<player_path_length; i++) {
2760 vms_vector seg_center;
2763 segnum = Point_segs[player_hide_index+i].segnum;
2764 mprintf((0, "%3i ", segnum));
2765 seg_center = Point_segs[player_hide_index+i].point;
2767 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
2769 Int3(); // Unable to drop energy powerup for path
2773 obj = &Objects[objnum];
2774 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
2775 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
2776 obj->rtype.vclip_info.framenum = 0;
2777 obj->lifeleft = F1_0*100 + d_rand() * 4;
2784 // Return true if it happened, else return false.
2785 int create_special_path(void)
2789 // ---------- Find exit doors ----------
2790 for (i=0; i<=Highest_segment_index; i++)
2791 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
2792 if (Segments[i].children[j] == -2) {
2793 mprintf((0, "Exit at segment %i\n", i));
2794 return mark_player_path_to_segment(i);
2804 int Max_obj_count_mike = 0;
2806 // Shows current number of used objects.
2807 void show_free_objects(void)
2809 if (!(FrameCount & 8)) {
2813 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
2815 for (i=0; i<=Highest_object_index; i++)
2816 if (Objects[i].type != OBJ_NONE)
2819 mprintf((0, "%3i", count));
2821 if (count > Max_obj_count_mike) {
2822 Max_obj_count_mike = count;
2823 mprintf((0, " ***"));
2834 * reads a flickering_light structure from a CFILE
2836 void flickering_light_read(flickering_light *fl, CFILE *fp)
2838 fl->segnum = cfile_read_short(fp);
2839 fl->sidenum = cfile_read_short(fp);
2840 fl->mask = cfile_read_int(fp);
2841 fl->timer = cfile_read_fix(fp);
2842 fl->delay = cfile_read_fix(fp);
2845 void flickering_light_write(flickering_light *fl, PHYSFS_file *fp)
2847 PHYSFS_writeSLE16(fp, fl->segnum);
2848 PHYSFS_writeSLE16(fp, fl->sidenum);
2849 PHYSFS_writeULE32(fp, fl->mask);
2850 PHYSFSX_writeFix(fp, fl->timer);
2851 PHYSFSX_writeFix(fp, fl->delay);