1 /* $Id: game.c,v 1.44 2006-11-26 01:05:24 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.44 2006-11-26 01:05:24 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!!!!
768 last_timer_value = time - last_timer_value;
769 #if defined(TIMER_TEST) && !defined(NDEBUG)
774 #if defined(TIMER_TEST) && !defined(NDEBUG)
779 MAC(extern ubyte joydefs_calibrating;)
781 void game_flush_inputs()
788 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
790 mouse_get_delta( &dx, &dy ); // Read mouse
791 memset(&Controls,0,sizeof(control_info));
796 last_timer_value = timer_get_fixed_seconds();
801 extern int Saving_movie_frames;
802 int Movie_fixed_frametime;
804 #define Saving_movie_frames 0
805 #define Movie_fixed_frametime 0
808 //added on 8/18/98 by Victor Rachels to add maximum framerate
809 int maxfps = MAX_FPS;
812 void calc_frame_time()
814 fix timer_value,last_frametime = FrameTime;
816 #if defined(TIMER_TEST) && !defined(NDEBUG)
817 _last_frametime = last_frametime;
820 timer_value = timer_get_fixed_seconds();
821 FrameTime = timer_value - last_timer_value;
823 while (FrameTime < f1_0 / maxfps)
825 timer_delay(f1_0 / maxfps - FrameTime);
826 timer_value = timer_get_fixed_seconds();
827 FrameTime = timer_value - last_timer_value;
830 #if defined(TIMER_TEST) && !defined(NDEBUG)
831 _timer_value = timer_value;
835 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
836 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
838 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
839 // if ( !dpmi_virtual_memory )
840 // Int3(); //Get MATT if hit this!
844 #if defined(TIMER_TEST) && !defined(NDEBUG)
845 actual_last_timer_value = last_timer_value;
848 if ( Game_turbo_mode )
851 // Limit frametime to be between 5 and 150 fps.
852 RealFrameTime = FrameTime;
853 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
854 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
856 last_timer_value = timer_value;
858 if (FrameTime < 0) //if bogus frametime...
859 FrameTime = last_frametime; //...then use time from last frame
862 if (fixed_frametime) FrameTime = fixed_frametime;
877 last_timer_value = timer_get_fixed_seconds();
885 #if defined(TIMER_TEST) && !defined(NDEBUG)
886 stop_count = start_count = 0;
889 // Set value to determine whether homing missile can see target.
890 // The lower frametime is, the more likely that it can see its target.
891 if (FrameTime <= F1_0/64)
892 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
893 else if (FrameTime < F1_0/32)
894 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
895 else if (FrameTime < F1_0/4)
896 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;
898 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
902 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
904 void move_player_2_segment(segment *seg,int side)
908 compute_segment_center(&ConsoleObject->pos,seg);
909 compute_center_point_on_side(&vp,seg,side);
910 vm_vec_sub2(&vp,&ConsoleObject->pos);
911 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
913 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
918 void game_draw_time_left()
920 char temp_string[30];
924 gr_set_curfont( GAME_FONT ); //GAME_FONT
925 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
927 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
928 i=f2i(timevar-ThisLevelTime);
931 sprintf( temp_string, "Time left: %d secs", i );
934 gr_string(0, 32, temp_string );
939 extern int Game_pause;
942 void level_with_floor();
944 void modex_clear_box(int x,int y,int w,int h)
946 grs_canvas *temp_canv,*save_canv;
948 save_canv = grd_curcanv;
949 temp_canv = gr_create_canvas(w,h);
950 gr_set_current_canvas(temp_canv);
951 gr_clear_canvas(BM_XRGB(0,0,0));
952 gr_set_current_canvas(save_canv);
953 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
954 gr_free_canvas(temp_canv);
958 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
960 // mac routine to drop contents of screen to a pict file using copybits
961 // save a PICT to a file
964 void SavePictScreen(int multiplayer)
968 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
971 PicHandle pict_handle;
972 static int multi_count = 0;
973 StandardFileReply sf_reply;
975 // dump the contents of the GameWindow into a picture using copybits
977 pict_handle = OpenPicture(&GameWindow->portRect);
978 if (pict_handle == NULL)
981 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
984 // get the cwd to restore with chdir when done -- this keeps the mac world sane
985 if (!getcwd(cwd, FILENAME_MAX))
989 sprintf(filename, "screen%d", multi_count++);
990 pfilename = c2pstr(filename);
993 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
994 if (!sf_reply.sfGood)
996 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
997 if (sf_reply.sfReplacing)
999 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1003 // parid = GetAppDirId();
1004 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1009 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1014 // write the PICT file
1015 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1017 memset(buf, 0, sizeof(buf));
1019 if ( FSWrite(fd, &count, buf) )
1021 count = GetHandleSize((Handle)pict_handle);
1022 HLock((Handle)pict_handle);
1023 if ( FSWrite(fd, &count, *pict_handle) ) {
1029 HUnlock((Handle)pict_handle);
1030 DisposeHandle((Handle)pict_handle);
1038 //automap_flag is now unused, since we just check if the screen we're
1039 //writing to is modex
1040 //if called from automap, current canvas is set to visible screen
1042 void save_screen_shot(int automap_flag)
1044 #if !defined(MACINTOSH)
1047 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1048 grs_font *save_font;
1049 static int savenum=0;
1050 static int stereo_savenum=0;
1051 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1052 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1060 // // Can't do screen shots in VR modes.
1061 // if ( VR_render_mode != VR_NONE )
1066 save_canv = grd_curcanv;
1068 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1072 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1073 gr_set_current_canvas(temp_canv);
1074 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1076 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1077 gr_set_current_canvas(temp_canv2);
1078 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1081 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1082 gr_set_current_canvas(temp_canv);
1083 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1086 gr_set_current_canvas(save_canv);
1088 if ( savenum > 99 ) savenum = 0;
1089 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1092 sprintf(savename,"left%02d.pcx",stereo_savenum);
1093 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1094 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1096 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1099 sprintf(savename,"screen%02d.pcx",savenum++);
1100 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1103 if (!automap_flag) //if from automap, curcanv is already visible canv
1104 gr_set_current_canvas(NULL);
1105 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1106 if (!automap_flag && modex_flag)
1107 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1109 save_font = grd_curcanv->cv_font;
1110 gr_set_curfont(GAME_FONT);
1111 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1112 gr_get_string_size(message,&w,&h,&aw);
1117 //I changed how these coords were calculated for the high-res automap. -MT
1118 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1119 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1120 x = (grd_curcanv->cv_w-w)/2;
1121 y = (grd_curcanv->cv_h-h)/2;
1124 modex_clear_box(x-2,y-2,w+4,h+4);
1125 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1127 gr_setcolor(gr_find_closest_color_current(0,0,0));
1128 gr_rect(x-2,y-2,x+w+2,y+h+2);
1129 gr_printf(x,y,message);
1130 gr_set_curfont(save_font);
1132 t1 = timer_get_fixed_seconds() + F1_0;
1134 gr_palette_read(pal); //get actual palette from the hardware
1135 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1137 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1139 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1141 gr_set_current_canvas(screen_canv);
1143 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1144 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1146 gr_free_canvas(temp_canv);
1148 gr_free_canvas(temp_canv2);
1150 gr_set_current_canvas(save_canv);
1156 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1157 grs_canvas *temp_canv, *save_canv;
1159 // Can't do screen shots in VR modes.
1160 if ( VR_render_mode != VR_NONE )
1165 save_canv = grd_curcanv;
1166 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1169 gr_set_current_canvas( temp_canv );
1170 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1171 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1175 if (Game_mode & GM_MULTI)
1182 gr_set_current_canvas(screen_canv);
1184 // if (!automap_flag)
1185 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1187 gr_free_canvas(temp_canv);
1189 gr_set_current_canvas(save_canv);
1198 void fly_init(object *obj)
1200 obj->control_type = CT_FLYING;
1201 obj->movement_type = MT_PHYSICS;
1203 vm_vec_zero(&obj->mtype.phys_info.velocity);
1204 vm_vec_zero(&obj->mtype.phys_info.thrust);
1205 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1206 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1209 //void morph_test(), morph_step();
1212 // ------------------------------------------------------------------------------------
1214 void test_anim_states();
1218 //put up the help message
1225 extern int been_in_editor;
1227 // ------------------------------------------------------------------------------------
1228 void do_cloak_stuff(void)
1231 for (i = 0; i < N_players; i++)
1232 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1233 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1234 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1235 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1236 if (i == Player_num) {
1237 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1239 if (Game_mode & GM_MULTI)
1240 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1241 maybe_drop_net_powerup(POW_CLOAK);
1242 multi_send_decloak(); // For demo recording
1244 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1252 // ------------------------------------------------------------------------------------
1253 void do_invulnerable_stuff(void)
1255 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1256 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1257 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1260 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1262 if (Game_mode & GM_MULTI)
1264 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1265 maybe_drop_net_powerup(POW_INVULNERABILITY);
1268 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1275 ubyte Last_afterburner_state = 0;
1276 fix Last_afterburner_charge = 0;
1278 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1279 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1283 //@@// ------------------------------------------------------------------------------------
1284 //@@void afterburner_shake(void)
1288 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1289 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1291 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1292 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1293 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1297 // ------------------------------------------------------------------------------------
1299 extern void multi_send_sound_function (char,char);
1302 void do_afterburner_stuff(void)
1304 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1305 Afterburner_charge=0;
1307 if (Endlevel_sequence || Player_is_dead)
1309 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1311 multi_send_sound_function (0,0);
1315 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1317 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1318 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1320 if (Game_mode & GM_MULTI)
1321 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1324 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1325 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1327 if (Game_mode & GM_MULTI)
1328 multi_send_sound_function (0,0);
1330 mprintf((0,"Killing afterburner sound\n"));
1334 //@@if (Controls.afterburner_state && Afterburner_charge)
1335 //@@ afterburner_shake();
1337 Last_afterburner_state = Controls.afterburner_state;
1338 Last_afterburner_charge = Afterburner_charge;
1341 // -- // ------------------------------------------------------------------------------------
1342 // -- // if energy < F1_0/2, recharge up to F1_0/2
1343 // -- void recharge_energy_frame(void)
1345 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1346 // -- Players[Player_num].energy += FrameTime/4;
1348 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1349 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1353 // Amount to diminish guns towards normal, per second.
1354 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1356 extern fix Flash_effect;
1358 //adds to rgb values for palette flash
1359 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1363 PaletteRedAdd += _dr;
1364 PaletteGreenAdd += _dg;
1365 PaletteBlueAdd += _db;
1367 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1372 maxval = MAX_PALETTE_ADD;
1374 if (PaletteRedAdd > maxval)
1375 PaletteRedAdd = maxval;
1377 if (PaletteGreenAdd > maxval)
1378 PaletteGreenAdd = maxval;
1380 if (PaletteBlueAdd > maxval)
1381 PaletteBlueAdd = maxval;
1383 if (PaletteRedAdd < -maxval)
1384 PaletteRedAdd = -maxval;
1386 if (PaletteGreenAdd < -maxval)
1387 PaletteGreenAdd = -maxval;
1389 if (PaletteBlueAdd < -maxval)
1390 PaletteBlueAdd = -maxval;
1393 fix Time_flash_last_played;
1396 void game_palette_step_up( int r, int g, int b );
1397 // ------------------------------------------------------------------------------------
1398 // Diminish palette effects towards normal.
1399 void diminish_palette_towards_normal(void)
1403 // Diminish at DIMINISH_RATE units/second.
1404 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1405 if (FrameTime < F1_0/DIMINISH_RATE) {
1406 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1409 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1410 if (dec_amount == 0)
1411 dec_amount++; // make sure we decrement by something
1417 // Part of hack system to force update of palette after exiting a menu.
1418 if (Time_flash_last_played) {
1420 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1423 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1424 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1425 Time_flash_last_played = GameTime;
1428 Flash_effect -= FrameTime;
1429 if (Flash_effect < 0)
1432 if (force_do || (d_rand() > 4096 )) {
1433 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1434 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1436 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1443 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1444 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1446 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1447 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1449 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1450 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1452 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1453 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1455 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1457 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1460 int Redsave, Bluesave, Greensave;
1462 void palette_save(void)
1464 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1467 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1469 void game_palette_step_up( int r, int g, int b )
1471 if ( VR_use_reg_code ) {
1472 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1474 gr_palette_step_up( r, g, b );
1478 void palette_restore(void)
1480 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1481 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1483 // Forces flash effect to fixup palette next frame.
1484 Time_flash_last_played = 0;
1487 extern void dead_player_frame(void);
1490 // --------------------------------------------------------------------------------------------------
1491 int allowed_to_fire_laser(void)
1493 if (Player_is_dead) {
1494 Global_missile_firing_count = 0;
1498 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1499 // be a long while before laser can be fired, then there must be some mistake!
1500 if (Next_laser_fire_time > GameTime)
1501 if (Next_laser_fire_time < GameTime + 2*F1_0)
1507 fix Next_flare_fire_time = 0;
1508 #define FLARE_BIG_DELAY (F1_0*2)
1510 int allowed_to_fire_flare(void)
1512 if (Next_flare_fire_time > GameTime)
1513 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1516 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1517 Next_flare_fire_time = GameTime + F1_0/4;
1519 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1524 int allowed_to_fire_missile(void)
1526 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1527 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1528 // be a long while before missile can be fired, then there must be some mistake!
1529 if (Next_missile_fire_time > GameTime)
1530 if (Next_missile_fire_time < GameTime + 5*F1_0)
1536 void full_palette_save(void)
1539 apply_modified_palette();
1540 reset_palette_add();
1541 gr_palette_load( gr_palette );
1544 extern int Death_sequence_aborted;
1545 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) );
1552 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1555 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
1557 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F2;
1558 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F3;
1560 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1561 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1562 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = save_help;
1563 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = restore_help;
1565 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
1566 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F3;
1567 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F4;
1568 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
1569 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F6\t Fast Save";
1571 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
1573 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (F15)\t Pause";
1575 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_MINUSPLUS;
1577 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
1579 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "printscrn (F13)\t save screen shot";
1581 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
1582 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
1583 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F1\t Cycle left window";
1584 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F2\t Cycle right window";
1585 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F4\t GuideBot menu";
1587 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F4\t Rename GuideBot";
1589 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Opt-Shift-F4\t Rename GuideBot";
1591 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F5\t Drop primary";
1592 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F6\t Drop secondary";
1593 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F7\t Calibrate joystick";
1594 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-number\t GuideBot commands";
1596 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1597 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = pixel_double_help;
1598 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
1599 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1600 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = command_help;
1603 full_palette_save();
1605 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1610 //temp function until Matt cleans up game sequencing
1611 extern void temp_reset_stuff_on_level();
1613 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
1615 //deal with rear view - switch it on, or off, or whatever
1616 void check_rear_view()
1618 static int leave_mode;
1619 static fix entry_time;
1621 if ( Controls.rear_view_down_count ) { //key/button has gone down
1625 if (Cockpit_mode==CM_REAR_VIEW) {
1626 select_cockpit(Cockpit_mode_save);
1627 Cockpit_mode_save = -1;
1629 if (Newdemo_state == ND_STATE_RECORDING)
1630 newdemo_record_restore_rearview();
1634 if (Rear_view_leave_time <= 0)
1636 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
1640 leave_mode = 0; // means wait for another key
1641 entry_time = timer_get_fixed_seconds();
1643 if (Cockpit_mode == CM_FULL_COCKPIT) {
1644 Cockpit_mode_save = Cockpit_mode;
1645 select_cockpit(CM_REAR_VIEW);
1647 if (Newdemo_state == ND_STATE_RECORDING)
1648 newdemo_record_rearview();
1652 if (Controls.rear_view_down_state) {
1654 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
1659 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
1661 if (leave_mode==1 && Rear_view) {
1663 if (Cockpit_mode==CM_REAR_VIEW) {
1664 select_cockpit(Cockpit_mode_save);
1665 Cockpit_mode_save = -1;
1667 if (Newdemo_state == ND_STATE_RECORDING)
1668 newdemo_record_restore_rearview();
1673 void reset_rear_view(void)
1676 if (Newdemo_state == ND_STATE_RECORDING)
1677 newdemo_record_restore_rearview();
1682 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
1683 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
1684 Cockpit_mode_save = CM_FULL_COCKPIT;
1685 select_cockpit(Cockpit_mode_save);
1686 Cockpit_mode_save = -1;
1692 int Config_menu_flag;
1696 int gr_renderstats = 0;
1697 // need to define "cheat" for renderstats
1698 int gr_badtexture = 0;
1699 // need to define "cheat" for badtexture
1701 int Cheats_enabled=0;
1703 extern int Laser_rapid_fire;
1704 extern void do_lunacy_on(), do_lunacy_off();
1706 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
1707 extern char BounceCheat,HomingCheat,OldHomingState[20];
1708 extern char AcidCheatOn,old_IntMethod, Monster_mode;
1709 extern int Buddy_dude_cheat;
1711 //turns off active cheats
1712 void turn_cheats_off()
1718 Weapon_info[i].homing_flag=OldHomingState[i];
1723 Interpolation_method=old_IntMethod;
1726 Buddy_dude_cheat = 0;
1730 Laser_rapid_fire = 0;
1731 Physics_cheat_flag = 0;
1733 Robots_kill_robots_cheat=0;
1734 Robot_firing_enabled = 1;
1737 //turns off all cheats & resets cheater flag
1738 void game_disable_cheats()
1746 // ----------------------------------------------------------------------------
1748 void game_setup(void)
1750 //@@int demo_playing=0;
1751 //@@int multi_game=0;
1753 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
1754 do_lunacy_off(); // Restore true insane mode.
1757 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
1758 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
1759 Endlevel_sequence = 0;
1761 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
1762 //@@ demo_playing = 1;
1763 //@@if ( Game_mode & GM_MULTI )
1764 //@@ multi_game = 1;
1766 set_screen_mode(SCREEN_GAME);
1767 reset_palette_add();
1769 set_warn_func(game_show_warning);
1773 //digi_init_sounds();
1775 //keyd_repeat = 0; // Don't allow repeat in game
1776 keyd_repeat = 1; // Do allow repeat in game
1779 //_MARK_("start of game");
1783 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
1784 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
1786 if (!check_obj_seg(ConsoleObject))
1787 move_player_2_segment(Cursegp,Curside);
1790 Viewer = ConsoleObject;
1791 fly_init(ConsoleObject);
1796 FrameTime = 0; //make first frame zero
1799 if (Current_level_num == 0) { //not a real level
1800 init_player_stats_game();
1807 game_flush_inputs();
1813 extern char IWasKicked;
1817 // ------------------------------------------------------------------------------------
1818 //this function is the game. called when game mode selected. runs until
1819 //editor mode or exit selected
1822 game_setup(); // Replaces what was here earlier.
1823 // Good for Windows Sake.
1826 ProfilerSetStatus(1);
1829 if ( setjmp(LeaveGame)==0 ) {
1835 Config_menu_flag = 0;
1837 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
1839 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
1840 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
1843 player_shields = Players[Player_num].shields;
1845 ExtGameStatus=GAMESTAT_RUNNING;
1846 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
1848 //if the player is taking damage, give up guided missile control
1849 if (Players[Player_num].shields != player_shields)
1850 release_guided_missile(Player_num);
1852 //see if redbook song needs to be restarted
1853 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
1855 if (Config_menu_flag) {
1856 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
1858 if (!(Game_mode&GM_MULTI)) palette_restore();
1862 int save_w=Game_window_w,save_h=Game_window_h;
1864 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
1865 Game_window_w=save_w; Game_window_h=save_h;
1867 last_drawn_cockpit[0] = -1;
1868 last_drawn_cockpit[1] = -1;
1871 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
1873 fmode = Function_mode;
1874 Function_mode = FMODE_GAME;
1876 apply_modified_palette();
1877 reset_palette_add();
1878 gr_palette_load( gr_palette );
1879 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
1881 Function_mode = fmode;
1884 newdemo_stop_playback();
1885 Function_mode = FMODE_MENU;
1887 Function_mode = FMODE_GAME;
1891 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
1897 fmode = Function_mode;
1898 Function_mode = FMODE_GAME;
1900 apply_modified_palette();
1901 reset_palette_add();
1902 gr_palette_load( gr_palette );
1903 ExtGameStatus=GAMESTAT_ABORT_GAME;
1904 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
1906 Function_mode = fmode;
1908 Function_mode = FMODE_GAME;
1914 if (Function_mode != FMODE_GAME)
1915 longjmp(LeaveGame,0);
1918 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
1919 longjmp(LeaveGame,0);
1925 ProfilerSetStatus(0);
1930 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
1931 newdemo_stop_recording();
1937 if ( Newdemo_state == ND_STATE_PLAYBACK )
1938 newdemo_stop_playback();
1940 if (Cockpit_mode_save!=-1)
1942 Cockpit_mode=Cockpit_mode_save;
1943 Cockpit_mode_save=-1;
1946 if (Function_mode != FMODE_EDITOR)
1947 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
1949 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
1950 //@@ scores_maybe_add_player(Game_aborted);
1954 //_MARK_("end of game");
1957 clear_warn_func(game_show_warning); //don't use this func anymore
1959 game_disable_cheats();
1962 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
1966 //called at the end of the program
1969 if (VR_offscreen_buffer) {
1970 gr_free_canvas(VR_offscreen_buffer);
1971 VR_offscreen_buffer = NULL;
1974 close_gauge_canvases();
1976 restore_effect_bitmap_icons();
1978 if (background_bitmap.bm_data)
1979 d_free(background_bitmap.bm_data);
1981 clear_warn_func(game_show_warning); //don't use this func anymore
1984 grs_canvas * get_current_game_screen()
1986 return &VR_screen_pages[VR_current_page];
1990 extern void kconfig_center_headset();
1994 void speedtest_frame(void);
1995 int Debug_slowdown=0;
1999 extern void player_follow_path(object *objp);
2000 extern void check_create_player_path(void);
2004 extern int Do_appearance_effect;
2006 object *Missile_viewer=NULL;
2008 int Missile_view_enabled = 1;
2010 int Marker_viewer_num[2]={-1,-1};
2011 int Coop_view_player[2]={-1,-1};
2012 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2014 //returns ptr to escort robot, or NULL
2015 object *find_escort()
2019 for (i=0; i<=Highest_object_index; i++)
2020 if (Objects[i].type == OBJ_ROBOT)
2021 if (Robot_info[Objects[i].id].companion)
2027 extern void process_super_mines_frame(void);
2028 extern void do_seismic_stuff(void);
2031 int Saving_movie_frames=0;
2032 int __Movie_frame_num=0;
2034 #define MAX_MOVIE_BUFFER_FRAMES 250
2035 #define MOVIE_FRAME_SIZE (320 * 200)
2037 ubyte *Movie_frame_buffer;
2038 int Movie_frame_counter;
2039 ubyte Movie_pal[768];
2040 char movie_path[50] = ".\\";
2042 grs_bitmap Movie_bm;
2044 void flush_movie_buffer()
2051 mprintf((0,"Flushing movie buffer..."));
2053 Movie_bm.bm_data = Movie_frame_buffer;
2055 for (f=0;f<Movie_frame_counter;f++) {
2056 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2057 __Movie_frame_num++;
2058 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2059 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2062 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2065 Movie_frame_counter=0;
2067 mprintf((0,"done \n"));
2072 void toggle_movie_saving()
2076 Saving_movie_frames = !Saving_movie_frames;
2078 if (Saving_movie_frames) {
2081 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2082 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2085 Saving_movie_frames = 0;
2089 while (isspace(movie_path[strlen(movie_path)-1]))
2090 movie_path[strlen(movie_path)-1] = 0;
2091 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2092 strcat(movie_path,"\\");
2095 if (!Movie_frame_buffer) {
2096 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2097 if (!Movie_frame_buffer) {
2099 Saving_movie_frames=0;
2102 Movie_frame_counter=0;
2104 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2105 Movie_bm.bm_w = 320;
2106 Movie_bm.bm_h = 200;
2107 Movie_bm.bm_type = BM_LINEAR;
2108 Movie_bm.bm_flags = 0;
2109 Movie_bm.bm_rowsize = 320;
2110 Movie_bm.bm_handle = 0;
2112 gr_palette_read(Movie_pal); //get actual palette from the hardware
2114 if (Newdemo_state == ND_STATE_PLAYBACK)
2115 Newdemo_do_interpolate = 0;
2119 flush_movie_buffer();
2121 if (Newdemo_state == ND_STATE_PLAYBACK)
2122 Newdemo_do_interpolate = 1;
2127 void save_movie_frame()
2129 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2131 Movie_frame_counter++;
2133 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2134 flush_movie_buffer();
2140 extern int Level_shake_duration;
2142 //if water or fire level, make occasional sound
2143 void do_ambient_sounds()
2145 int has_water,has_lava;
2148 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2149 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2151 if (has_lava) { //has lava
2152 sound = SOUND_AMBIENT_LAVA;
2153 if (has_water && (d_rand() & 1)) //both, pick one
2154 sound = SOUND_AMBIENT_WATER;
2156 else if (has_water) //just water
2157 sound = SOUND_AMBIENT_WATER;
2161 if (((d_rand() << 3) < FrameTime)) { //play the sound
2162 fix volume = d_rand() + f1_0/2;
2163 digi_play_sample(sound,volume);
2167 // -- extern void lightning_frame(void);
2169 void game_render_frame();
2170 extern void omega_charge_frame(void);
2172 extern time_t t_current_time, t_saved_time;
2174 void flicker_lights();
2176 void GameLoop(int RenderFlag, int ReadControlsFlag )
2179 // Used to slow down frame rate for testing things.
2180 // RenderFlag = 1; // DEBUG
2181 if (Debug_slowdown) {
2184 for (h=0; h<Debug_slowdown; h++)
2185 for (i=0; i<1000; i++)
2191 if (FindArg("-invulnerability"))
2192 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2196 update_player_stats();
2197 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2198 do_afterburner_stuff();
2200 do_invulnerable_stuff();
2201 remove_obsolete_stuck_objects();
2203 do_final_boss_frame();
2204 // -- lightning_frame();
2205 // -- recharge_energy_frame();
2207 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2208 static int turned_off=0;
2209 Players[Player_num].energy -= (FrameTime*3/8);
2210 if (Players[Player_num].energy < i2f(10)) {
2212 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2215 if (Game_mode & GM_MULTI)
2216 multi_send_flags(Player_num);
2223 if (Players[Player_num].energy <= 0) {
2224 Players[Player_num].energy = 0;
2225 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2227 if (Game_mode & GM_MULTI)
2228 multi_send_flags(Player_num);
2235 check_create_player_path();
2236 player_follow_path(ConsoleObject);
2240 if (Game_mode & GM_MULTI)
2243 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2244 multi_check_for_killgoal_winner();
2250 if (force_cockpit_redraw) { //screen need redrawing?
2252 force_cockpit_redraw=0;
2254 game_render_frame();
2255 //show_extra_views(); //missile view, buddy bot, etc.
2258 if (Saving_movie_frames)
2265 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2269 dead_player_frame();
2270 if (Newdemo_state != ND_STATE_PLAYBACK)
2271 do_controlcen_dead_frame();
2273 process_super_mines_frame();
2275 do_ambient_sounds();
2282 if (ReadControlsFlag)
2285 memset(&Controls, 0, sizeof(Controls));
2287 GameTime += FrameTime;
2289 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2290 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2292 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2293 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2294 mprintf((0,"GameTime reset to 0\n"));
2298 if (FindArg("-checktime") != 0)
2299 if (GameTime >= i2f(600)) //wrap after 10 minutes
2300 GameTime = FrameTime;
2304 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2305 ThisLevelTime +=FrameTime;
2310 if (Endlevel_sequence) {
2311 do_endlevel_frame();
2312 powerup_grab_cheat_all();
2313 do_special_effects();
2314 return; //skip everything else
2317 if (Newdemo_state != ND_STATE_PLAYBACK)
2318 do_exploding_wall_frame();
2319 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2320 do_special_effects();
2321 wall_frame_process();
2322 triggers_frame_process();
2326 if (Control_center_destroyed) {
2327 if (Newdemo_state==ND_STATE_RECORDING )
2328 newdemo_record_control_center_destroyed();
2333 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2334 newdemo_playback_one_frame();
2335 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2336 longjmp( LeaveGame, 0 ); // Go back to menu
2339 { // Note the link to above!
2341 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2344 powerup_grab_cheat_all();
2346 if (Endlevel_sequence) //might have been started during move
2349 fuelcen_update_all();
2353 if (allowed_to_fire_laser())
2354 FireLaser(); // Fire Laser!
2356 if (Auto_fire_fusion_cannon_time) {
2357 if (Primary_weapon != FUSION_INDEX)
2358 Auto_fire_fusion_cannon_time = 0;
2359 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2360 Auto_fire_fusion_cannon_time = 0;
2361 Global_laser_firing_count = 1;
2363 vms_vector rand_vec;
2366 Global_laser_firing_count = 0;
2368 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2369 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2370 make_random_vector(&rand_vec);
2372 bump_amount = F1_0*4;
2374 if (Fusion_charge > F1_0*2)
2375 bump_amount = Fusion_charge*4;
2377 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2381 if (Global_laser_firing_count) {
2382 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2383 // if (Fusion_charge > F1_0*2)
2384 // Fusion_charge = F1_0*2;
2385 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2388 if (Global_laser_firing_count < 0)
2389 Global_laser_firing_count = 0;
2392 if (Do_appearance_effect) {
2393 create_player_appearance_effect(ConsoleObject);
2394 Do_appearance_effect = 0;
2396 if ((Game_mode & GM_MULTI) && Netgame.invul)
2398 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2399 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2406 omega_charge_frame();
2410 //!!hoard_light_pulse(); //do cool hoard light pulsing
2414 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2415 //!!extern int Hoard_goal_eclip;
2417 //!!//do cool pulsing lights in hoard goals
2418 //!!hoard_light_pulse()
2420 //!! if (Game_mode & GM_HOARD) {
2424 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2428 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2431 //!! light = abs(frame - 5) * f1_0 / 5;
2433 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2438 ubyte Slide_segs[MAX_SEGMENTS];
2439 int Slide_segs_computed;
2441 void compute_slide_segs(void)
2443 int segnum, sidenum;
2445 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2446 Slide_segs[segnum] = 0;
2447 for (sidenum=0;sidenum<6;sidenum++) {
2448 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2449 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2450 Slide_segs[segnum] |= 1 << sidenum;
2454 Slide_segs_computed = 1;
2457 // -----------------------------------------------------------------------------
2458 void slide_textures(void)
2460 int segnum,sidenum,i;
2462 if (!Slide_segs_computed)
2463 compute_slide_segs();
2465 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2466 if (Slide_segs[segnum]) {
2467 for (sidenum=0;sidenum<6;sidenum++) {
2468 if (Slide_segs[segnum] & (1 << sidenum)) {
2469 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2470 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2472 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2473 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2474 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2477 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2479 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2482 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2484 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2487 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2489 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2492 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2502 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2504 int Num_flickering_lights=0;
2506 void flicker_lights()
2509 flickering_light *f;
2511 f = Flickering_lights;
2513 for (l=0;l<Num_flickering_lights;l++,f++) {
2514 segment *segp = &Segments[f->segnum];
2516 //make sure this is actually a light
2517 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2519 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2522 if (f->timer == 0x80000000) //disabled
2525 if ((f->timer -= FrameTime) < 0) {
2527 while (f->timer < 0)
2528 f->timer += f->delay;
2530 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2533 add_light(f->segnum,f->sidenum);
2535 subtract_light(f->segnum,f->sidenum);
2540 //returns ptr to flickering light structure, or NULL if can't find
2541 flickering_light *find_flicker(int segnum,int sidenum)
2544 flickering_light *f;
2546 //see if there's already an entry for this seg/side
2548 f = Flickering_lights;
2550 for (l=0;l<Num_flickering_lights;l++,f++)
2551 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2557 //turn flickering off (because light has been turned off)
2558 void disable_flicker(int segnum,int sidenum)
2560 flickering_light *f;
2562 if ((f=find_flicker(segnum,sidenum)) != NULL)
2563 f->timer = 0x80000000;
2566 //turn flickering off (because light has been turned on)
2567 void enable_flicker(int segnum,int sidenum)
2569 flickering_light *f;
2571 if ((f=find_flicker(segnum,sidenum)) != NULL)
2578 //returns 1 if ok, 0 if error
2579 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
2582 flickering_light *f;
2584 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2586 //see if there's already an entry for this seg/side
2588 f = Flickering_lights;
2590 for (l=0;l<Num_flickering_lights;l++,f++)
2591 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2594 if (mask==0) { //clearing entry
2595 if (l == Num_flickering_lights)
2599 for (i=l;i<Num_flickering_lights-1;i++)
2600 Flickering_lights[i] = Flickering_lights[i+1];
2601 Num_flickering_lights--;
2606 if (l == Num_flickering_lights) {
2607 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
2610 Num_flickering_lights++;
2614 f->sidenum = sidenum;
2615 f->delay = f->timer = delay;
2623 // -----------------------------------------------------------------------------
2624 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
2629 Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
2631 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
2632 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
2633 Global_laser_firing_count = 0;
2635 if (Fusion_charge == 0)
2636 Players[Player_num].energy -= F1_0*2;
2638 Fusion_charge += FrameTime;
2639 Players[Player_num].energy -= FrameTime;
2641 if (Players[Player_num].energy <= 0) {
2642 Players[Player_num].energy = 0;
2643 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
2645 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
2646 // Fire the fusion cannon at this time in the future.
2648 if (Fusion_charge < F1_0*2)
2649 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
2651 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
2653 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
2654 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
2656 if (Fusion_next_sound_time < GameTime) {
2657 if (Fusion_charge > F1_0*2) {
2658 digi_play_sample( 11, F1_0 );
2659 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
2661 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
2662 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
2664 if (Game_mode & GM_MULTI)
2665 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
2668 Fusion_last_sound_time = GameTime;
2669 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
2677 // -------------------------------------------------------------------------------------------------------
2678 // If player is close enough to objnum, which ought to be a powerup, pick it up!
2679 // This could easily be made difficulty level dependent.
2680 void powerup_grab_cheat(object *player, int objnum)
2686 Assert(Objects[objnum].type == OBJ_POWERUP);
2688 powerup_size = Objects[objnum].size;
2689 player_size = player->size;
2691 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
2693 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
2694 vms_vector collision_point;
2696 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
2697 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
2701 // -------------------------------------------------------------------------------------------------------
2702 // Make it easier to pick up powerups.
2703 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
2704 // from player to powerup and player's forward vector.
2705 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
2706 // way before the player gets there.
2707 void powerup_grab_cheat_all(void)
2712 segp = &Segments[ConsoleObject->segnum];
2713 objnum = segp->objects;
2715 while (objnum != -1) {
2716 if (Objects[objnum].type == OBJ_POWERUP)
2717 powerup_grab_cheat(ConsoleObject, objnum);
2718 objnum = Objects[objnum].next;
2723 int Last_level_path_created = -1;
2725 #ifdef SHOW_EXIT_PATH
2727 // ------------------------------------------------------------------------------------------------------------------
2728 // Create path for player from current segment to goal segment.
2729 // Return true if path created, else return false.
2730 int mark_player_path_to_segment(int segnum)
2733 object *objp = ConsoleObject;
2734 short player_path_length=0;
2735 int player_hide_index=-1;
2737 if (Last_level_path_created == Current_level_num) {
2741 Last_level_path_created = Current_level_num;
2743 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
2744 mprintf((0, "Unable to form path of length %i for myself\n", 100));
2748 player_hide_index = Point_segs_free_ptr - Point_segs;
2749 Point_segs_free_ptr += player_path_length;
2751 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
2752 mprintf((1, "Can't create path. Not enough point_segs.\n"));
2753 ai_reset_all_paths();
2757 for (i=1; i<player_path_length; i++) {
2759 vms_vector seg_center;
2762 segnum = Point_segs[player_hide_index+i].segnum;
2763 mprintf((0, "%3i ", segnum));
2764 seg_center = Point_segs[player_hide_index+i].point;
2766 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
2768 Int3(); // Unable to drop energy powerup for path
2772 obj = &Objects[objnum];
2773 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
2774 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
2775 obj->rtype.vclip_info.framenum = 0;
2776 obj->lifeleft = F1_0*100 + d_rand() * 4;
2783 // Return true if it happened, else return false.
2784 int create_special_path(void)
2788 // ---------- Find exit doors ----------
2789 for (i=0; i<=Highest_segment_index; i++)
2790 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
2791 if (Segments[i].children[j] == -2) {
2792 mprintf((0, "Exit at segment %i\n", i));
2793 return mark_player_path_to_segment(i);
2803 int Max_obj_count_mike = 0;
2805 // Shows current number of used objects.
2806 void show_free_objects(void)
2808 if (!(FrameCount & 8)) {
2812 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
2814 for (i=0; i<=Highest_object_index; i++)
2815 if (Objects[i].type != OBJ_NONE)
2818 mprintf((0, "%3i", count));
2820 if (count > Max_obj_count_mike) {
2821 Max_obj_count_mike = count;
2822 mprintf((0, " ***"));
2833 * reads a flickering_light structure from a CFILE
2835 void flickering_light_read(flickering_light *fl, CFILE *fp)
2837 fl->segnum = cfile_read_short(fp);
2838 fl->sidenum = cfile_read_short(fp);
2839 fl->mask = cfile_read_int(fp);
2840 fl->timer = cfile_read_fix(fp);
2841 fl->delay = cfile_read_fix(fp);
2844 void flickering_light_write(flickering_light *fl, PHYSFS_file *fp)
2846 PHYSFS_writeSLE16(fp, fl->segnum);
2847 PHYSFS_writeSLE16(fp, fl->sidenum);
2848 PHYSFS_writeULE32(fp, fl->mask);
2849 PHYSFSX_writeFix(fp, fl->timer);
2850 PHYSFSX_writeFix(fp, fl->delay);