1 /* $Id: game.c,v 1.42 2005-08-07 09:58:12 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.42 2005-08-07 09:58:12 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_gauge_canvases();
302 init_exploding_walls();
304 load_background_bitmap();
306 Clear_window = 2; // do portal only window clear.
308 set_detail_level_parameters(Detail_level);
311 cvar_registervariable(&r_framerate);
316 void reset_palette_add()
321 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
325 void game_show_warning(char *s)
328 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
331 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
333 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
338 //these should be in gr.h
339 #define cv_w cv_bitmap.bm_w
340 #define cv_h cv_bitmap.bm_h
342 //added 3/24/99 by Owen Evans for screen res changing
343 u_int32_t Game_screen_mode = 0;
345 int Game_window_x = 0;
346 int Game_window_y = 0;
347 int Game_window_w = 0;
348 int Game_window_h = 0;
349 int max_window_w = 0;
350 int max_window_h = 0;
352 extern void newdemo_record_cockpit_change(int);
354 //initialize the various canvases on the game screen
355 //called every time the screen mode or cockpit changes
358 // int minx, maxx, miny, maxy;
360 //Initialize the on-screen canvases
362 if (Newdemo_state==ND_STATE_RECORDING) {
363 newdemo_record_cockpit_change(Cockpit_mode);
366 if ( VR_render_mode != VR_NONE )
367 Cockpit_mode = CM_FULL_SCREEN;
369 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
370 Cockpit_mode = CM_FULL_SCREEN;
372 if ( Screen_mode == SCREEN_EDITOR )
373 Cockpit_mode = CM_FULL_SCREEN;
375 gr_set_current_canvas(NULL);
376 gr_set_curfont( GAME_FONT );
378 switch( Cockpit_mode ) {
379 case CM_FULL_COCKPIT:
382 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
384 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
386 gr_set_current_canvas(VR_offscreen_buffer);
388 gr_bitmap( 0, 0, bm );
389 bm = &VR_offscreen_buffer->cv_bitmap;
390 bm->bm_flags = BM_FLAG_TRANSPARENT;
391 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
394 if (Cockpit_mode == CM_FULL_COCKPIT)
395 game_init_render_sub_buffers(0, 0, grd_curscreen->sc_w, (grd_curscreen->sc_h*2)/3);
396 else if (Cockpit_mode == CM_REAR_VIEW)
397 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);
403 max_window_h = grd_curscreen->sc_h;
405 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
406 Game_window_h = max_window_h;
408 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
409 Game_window_w = max_window_w;
411 Game_window_x = (max_window_w - Game_window_w)/2;
412 Game_window_y = (max_window_h - Game_window_h)/2;
414 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
419 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
421 if (Game_window_h > max_window_h)
422 Game_window_h = max_window_h;
424 if (Game_window_w > max_window_w)
425 Game_window_w = max_window_w;
427 Game_window_x = (max_window_w - Game_window_w)/2;
428 Game_window_y = (max_window_h - Game_window_h)/2;
430 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
436 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
437 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
438 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
440 game_init_render_sub_buffers( x, y, w, h );
446 gr_set_current_canvas(NULL);
449 //selects a given cockpit (or lack of one). See types in game.h
450 void select_cockpit(int mode)
452 if (mode != Cockpit_mode) { //new mode
458 extern int last_drawn_cockpit[2];
460 //force cockpit redraw next time. call this if you've trashed the screen
463 force_cockpit_redraw=1;
464 last_drawn_cockpit[0] = -1;
465 last_drawn_cockpit[1] = -1;
468 // void HUD_clear_messages(); //Already declared in gauges.h
471 void VR_reset_params()
473 VR_eye_width = VR_SEPARATION;
474 VR_eye_offset = VR_PIXEL_SHIFT;
475 VR_eye_offset_changed = 2;
478 void game_init_render_sub_buffers( int x, int y, int w, int h )
480 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
481 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
485 // Sets up the canvases we will be rendering to (NORMAL VERSION)
486 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
488 // if (vga_check_mode(screen_mode) != 0)
489 // Error("Cannot set requested video mode");
491 VR_screen_mode = screen_mode;
493 VR_screen_flags = flags;
497 VR_render_mode = render_method;
499 Game_window_w = render_w;
500 Game_window_h = render_h;
502 if (VR_offscreen_buffer) {
503 gr_free_canvas(VR_offscreen_buffer);
506 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
507 if ( render_h*2 < 200 ) {
508 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
511 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
514 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
515 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
518 if ( render_h < 200 ) {
519 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
522 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
526 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
529 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
530 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
533 game_init_render_sub_buffers( 0, 0, render_w, render_h );
536 //called to get the screen in a mode compatible with popup menus.
537 //if we can't have popups over the game screen, switch to menu mode.
538 void set_popup_screen(void)
540 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
542 #ifndef OGL // always have to switch to menu mode
543 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
546 set_screen_mode(SCREEN_MENU); //must switch to menu mode
551 //called to change the screen mode. Parameter sm is the new mode, one of
552 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
553 //mode if cannot init requested mode)
554 int set_screen_mode(int sm)
557 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
558 gr_set_current_canvas( Canv_editor );
563 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
564 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
569 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
570 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
571 ogl_set_screen_mode();
582 switch( Screen_mode )
588 MenuHires = MenuHiresAvailable; //do highres if we can
590 menu_mode = MenuHires?SM(640,480):SM(320,200);
592 if (VGA_current_mode != menu_mode) {
593 if (gr_set_mode(menu_mode))
594 Error("Cannot set screen mode for menu");
595 if (!gr_palette_faded_out)
596 gr_palette_load(gr_palette);
599 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
600 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
602 FontHires = FontHiresAvailable && MenuHires;
608 if (VGA_current_mode != VR_screen_mode) {
609 if (gr_set_mode(VR_screen_mode)) {
610 Error("Cannot set desired screen mode for game!");
611 //we probably should do something else here, like select a standard mode
614 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
620 if ( VR_render_mode == VR_NONE )
622 max_window_w = grd_curscreen->sc_w;
623 max_window_h = grd_curscreen->sc_h;
625 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
626 if (Cockpit_mode == CM_STATUS_BAR)
627 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
629 else if (Cockpit_mode != CM_LETTERBOX)
630 Cockpit_mode = CM_FULL_SCREEN;
632 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
633 Game_window_w = max_window_w;
634 Game_window_h = max_window_h;
639 Cockpit_mode = CM_FULL_SCREEN;
641 // Define screen pages for game mode
642 // If we designate through screen_flags to use paging, then do so.
643 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
645 if ( VR_screen_flags&VRF_USE_PAGING )
646 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 );
648 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
652 FontHires = FontHiresAvailable && (MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2)));
654 if ( VR_render_mode != VR_NONE ) {
655 // for 640x480 or higher, use hires font.
656 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
666 if (grd_curscreen->sc_mode != SM(800,600)) {
668 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
669 Warning("Cannot init editor screen (error=%d)",gr_error);
673 gr_palette_load( gr_palette );
675 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
676 Canv_editor = &VR_editor_canvas;
677 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
678 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
679 gr_set_current_canvas( Canv_editor );
680 init_editor_screen(); //setup other editor stuff
684 Error("Invalid screen mode %d",sm);
689 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
691 if ( VR_screen_flags&VRF_USE_PAGING )
692 gr_show_canvas( &VR_screen_pages[VR_current_page] );
694 ogl_set_screen_mode();
700 int gr_toggle_fullscreen_game(void){
701 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
703 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
704 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
705 //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.
706 // generic_key_handler(KEY_PADENTER,0);
707 // generic_key_handler(KEY_ENTER, 0);
712 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
717 int arch_toggle_fullscreen_menu(void);
719 int gr_toggle_fullscreen_menu(void){
720 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
722 i=arch_toggle_fullscreen_menu();
724 // generic_key_handler(KEY_PADENTER,0);
725 // generic_key_handler(KEY_ENTER, 0);
734 static int timer_paused=0;
738 if (timer_paused==0) {
740 time = timer_get_fixed_seconds();
741 last_timer_value = time - last_timer_value;
742 if (last_timer_value < 0) {
743 #if defined(TIMER_TEST) && !defined(NDEBUG)
744 Int3(); //get Matt!!!!
746 last_timer_value = 0;
748 #if defined(TIMER_TEST) && !defined(NDEBUG)
754 #if defined(TIMER_TEST) && !defined(NDEBUG)
762 Assert(timer_paused >= 0);
763 if (timer_paused==0) {
765 time = timer_get_fixed_seconds();
766 #if defined(TIMER_TEST) && !defined(NDEBUG)
767 if (last_timer_value < 0)
768 Int3(); //get Matt!!!!
771 last_timer_value = time - last_timer_value;
772 #if defined(TIMER_TEST) && !defined(NDEBUG)
777 #if defined(TIMER_TEST) && !defined(NDEBUG)
782 MAC(extern ubyte joydefs_calibrating;)
784 void game_flush_inputs()
791 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
793 mouse_get_delta( &dx, &dy ); // Read mouse
794 memset(&Controls,0,sizeof(control_info));
799 last_timer_value = timer_get_fixed_seconds();
804 extern int Saving_movie_frames;
805 int Movie_fixed_frametime;
807 #define Saving_movie_frames 0
808 #define Movie_fixed_frametime 0
811 //added on 8/18/98 by Victor Rachels to add maximum framerate
812 int maxfps = MAX_FPS;
815 void calc_frame_time()
817 fix timer_value,last_frametime = FrameTime;
819 #if defined(TIMER_TEST) && !defined(NDEBUG)
820 _last_frametime = last_frametime;
823 timer_value = timer_get_fixed_seconds();
824 FrameTime = timer_value - last_timer_value;
826 while (FrameTime < f1_0 / maxfps)
828 timer_delay(f1_0 / maxfps - FrameTime);
829 timer_value = timer_get_fixed_seconds();
830 FrameTime = timer_value - last_timer_value;
833 #if defined(TIMER_TEST) && !defined(NDEBUG)
834 _timer_value = timer_value;
838 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
839 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
841 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
842 // if ( !dpmi_virtual_memory )
843 // Int3(); //Get MATT if hit this!
847 #if defined(TIMER_TEST) && !defined(NDEBUG)
848 actual_last_timer_value = last_timer_value;
851 if ( Game_turbo_mode )
854 // Limit frametime to be between 5 and 150 fps.
855 RealFrameTime = FrameTime;
856 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
857 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
859 last_timer_value = timer_value;
861 if (FrameTime < 0) //if bogus frametime...
862 FrameTime = last_frametime; //...then use time from last frame
865 if (fixed_frametime) FrameTime = fixed_frametime;
880 last_timer_value = timer_get_fixed_seconds();
888 #if defined(TIMER_TEST) && !defined(NDEBUG)
889 stop_count = start_count = 0;
892 // Set value to determine whether homing missile can see target.
893 // The lower frametime is, the more likely that it can see its target.
894 if (FrameTime <= F1_0/64)
895 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
896 else if (FrameTime < F1_0/32)
897 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
898 else if (FrameTime < F1_0/4)
899 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;
901 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
905 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
907 void move_player_2_segment(segment *seg,int side)
911 compute_segment_center(&ConsoleObject->pos,seg);
912 compute_center_point_on_side(&vp,seg,side);
913 vm_vec_sub2(&vp,&ConsoleObject->pos);
914 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
916 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
921 void game_draw_time_left()
923 char temp_string[30];
927 gr_set_curfont( GAME_FONT ); //GAME_FONT
928 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
930 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
931 i=f2i(timevar-ThisLevelTime);
934 sprintf( temp_string, "Time left: %d secs", i );
937 gr_string(0, 32, temp_string );
942 extern int Game_pause;
945 void level_with_floor();
947 void modex_clear_box(int x,int y,int w,int h)
949 grs_canvas *temp_canv,*save_canv;
951 save_canv = grd_curcanv;
952 temp_canv = gr_create_canvas(w,h);
953 gr_set_current_canvas(temp_canv);
954 gr_clear_canvas(BM_XRGB(0,0,0));
955 gr_set_current_canvas(save_canv);
956 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
957 gr_free_canvas(temp_canv);
961 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
963 // mac routine to drop contents of screen to a pict file using copybits
964 // save a PICT to a file
967 void SavePictScreen(int multiplayer)
971 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
974 PicHandle pict_handle;
975 static int multi_count = 0;
976 StandardFileReply sf_reply;
978 // dump the contents of the GameWindow into a picture using copybits
980 pict_handle = OpenPicture(&GameWindow->portRect);
981 if (pict_handle == NULL)
984 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
987 // get the cwd to restore with chdir when done -- this keeps the mac world sane
988 if (!getcwd(cwd, FILENAME_MAX))
992 sprintf(filename, "screen%d", multi_count++);
993 pfilename = c2pstr(filename);
996 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
997 if (!sf_reply.sfGood)
999 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1000 if (sf_reply.sfReplacing)
1002 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1006 // parid = GetAppDirId();
1007 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1012 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1017 // write the PICT file
1018 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1020 memset(buf, 0, sizeof(buf));
1022 if ( FSWrite(fd, &count, buf) )
1024 count = GetHandleSize((Handle)pict_handle);
1025 HLock((Handle)pict_handle);
1026 if ( FSWrite(fd, &count, *pict_handle) ) {
1032 HUnlock((Handle)pict_handle);
1033 DisposeHandle((Handle)pict_handle);
1041 //automap_flag is now unused, since we just check if the screen we're
1042 //writing to is modex
1043 //if called from automap, current canvas is set to visible screen
1045 void save_screen_shot(int automap_flag)
1047 #if !defined(MACINTOSH)
1050 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1051 grs_font *save_font;
1052 static int savenum=0;
1053 static int stereo_savenum=0;
1054 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1055 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1063 // // Can't do screen shots in VR modes.
1064 // if ( VR_render_mode != VR_NONE )
1069 save_canv = grd_curcanv;
1071 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1075 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1076 gr_set_current_canvas(temp_canv);
1077 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1079 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1080 gr_set_current_canvas(temp_canv2);
1081 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1084 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1085 gr_set_current_canvas(temp_canv);
1086 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1089 gr_set_current_canvas(save_canv);
1091 if ( savenum > 99 ) savenum = 0;
1092 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1095 sprintf(savename,"left%02d.pcx",stereo_savenum);
1096 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1097 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1099 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1102 sprintf(savename,"screen%02d.pcx",savenum++);
1103 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1106 if (!automap_flag) //if from automap, curcanv is already visible canv
1107 gr_set_current_canvas(NULL);
1108 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1109 if (!automap_flag && modex_flag)
1110 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1112 save_font = grd_curcanv->cv_font;
1113 gr_set_curfont(GAME_FONT);
1114 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1115 gr_get_string_size(message,&w,&h,&aw);
1120 //I changed how these coords were calculated for the high-res automap. -MT
1121 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1122 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1123 x = (grd_curcanv->cv_w-w)/2;
1124 y = (grd_curcanv->cv_h-h)/2;
1127 modex_clear_box(x-2,y-2,w+4,h+4);
1128 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1130 gr_setcolor(gr_find_closest_color_current(0,0,0));
1131 gr_rect(x-2,y-2,x+w+2,y+h+2);
1132 gr_printf(x,y,message);
1133 gr_set_curfont(save_font);
1135 t1 = timer_get_fixed_seconds() + F1_0;
1137 gr_palette_read(pal); //get actual palette from the hardware
1138 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1140 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1142 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1144 gr_set_current_canvas(screen_canv);
1146 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1147 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1149 gr_free_canvas(temp_canv);
1151 gr_free_canvas(temp_canv2);
1153 gr_set_current_canvas(save_canv);
1159 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1160 grs_canvas *temp_canv, *save_canv;
1162 // Can't do screen shots in VR modes.
1163 if ( VR_render_mode != VR_NONE )
1168 save_canv = grd_curcanv;
1169 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1172 gr_set_current_canvas( temp_canv );
1173 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1174 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1178 if (Game_mode & GM_MULTI)
1185 gr_set_current_canvas(screen_canv);
1187 // if (!automap_flag)
1188 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1190 gr_free_canvas(temp_canv);
1192 gr_set_current_canvas(save_canv);
1201 void fly_init(object *obj)
1203 obj->control_type = CT_FLYING;
1204 obj->movement_type = MT_PHYSICS;
1206 vm_vec_zero(&obj->mtype.phys_info.velocity);
1207 vm_vec_zero(&obj->mtype.phys_info.thrust);
1208 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1209 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1212 //void morph_test(), morph_step();
1215 // ------------------------------------------------------------------------------------
1217 void test_anim_states();
1221 //put up the help message
1228 extern int been_in_editor;
1230 // ------------------------------------------------------------------------------------
1231 void do_cloak_stuff(void)
1234 for (i = 0; i < N_players; i++)
1235 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1236 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1237 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1238 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1239 if (i == Player_num) {
1240 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1242 if (Game_mode & GM_MULTI)
1243 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1244 maybe_drop_net_powerup(POW_CLOAK);
1245 multi_send_decloak(); // For demo recording
1247 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1255 // ------------------------------------------------------------------------------------
1256 void do_invulnerable_stuff(void)
1258 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1259 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1260 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1263 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1265 if (Game_mode & GM_MULTI)
1267 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1268 maybe_drop_net_powerup(POW_INVULNERABILITY);
1271 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1278 ubyte Last_afterburner_state = 0;
1279 fix Last_afterburner_charge = 0;
1281 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1282 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1286 //@@// ------------------------------------------------------------------------------------
1287 //@@void afterburner_shake(void)
1291 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1292 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1294 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1295 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1296 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1300 // ------------------------------------------------------------------------------------
1302 extern void multi_send_sound_function (char,char);
1305 void do_afterburner_stuff(void)
1307 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1308 Afterburner_charge=0;
1310 if (Endlevel_sequence || Player_is_dead)
1312 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1314 multi_send_sound_function (0,0);
1318 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1320 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1321 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1323 if (Game_mode & GM_MULTI)
1324 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1327 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1328 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1330 if (Game_mode & GM_MULTI)
1331 multi_send_sound_function (0,0);
1333 mprintf((0,"Killing afterburner sound\n"));
1337 //@@if (Controls.afterburner_state && Afterburner_charge)
1338 //@@ afterburner_shake();
1340 Last_afterburner_state = Controls.afterburner_state;
1341 Last_afterburner_charge = Afterburner_charge;
1344 // -- // ------------------------------------------------------------------------------------
1345 // -- // if energy < F1_0/2, recharge up to F1_0/2
1346 // -- void recharge_energy_frame(void)
1348 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1349 // -- Players[Player_num].energy += FrameTime/4;
1351 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1352 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1356 // Amount to diminish guns towards normal, per second.
1357 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1359 extern fix Flash_effect;
1361 //adds to rgb values for palette flash
1362 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1366 PaletteRedAdd += _dr;
1367 PaletteGreenAdd += _dg;
1368 PaletteBlueAdd += _db;
1370 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1375 maxval = MAX_PALETTE_ADD;
1377 if (PaletteRedAdd > maxval)
1378 PaletteRedAdd = maxval;
1380 if (PaletteGreenAdd > maxval)
1381 PaletteGreenAdd = maxval;
1383 if (PaletteBlueAdd > maxval)
1384 PaletteBlueAdd = maxval;
1386 if (PaletteRedAdd < -maxval)
1387 PaletteRedAdd = -maxval;
1389 if (PaletteGreenAdd < -maxval)
1390 PaletteGreenAdd = -maxval;
1392 if (PaletteBlueAdd < -maxval)
1393 PaletteBlueAdd = -maxval;
1396 fix Time_flash_last_played;
1399 void game_palette_step_up( int r, int g, int b );
1400 // ------------------------------------------------------------------------------------
1401 // Diminish palette effects towards normal.
1402 void diminish_palette_towards_normal(void)
1406 // Diminish at DIMINISH_RATE units/second.
1407 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1408 if (FrameTime < F1_0/DIMINISH_RATE) {
1409 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1412 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1413 if (dec_amount == 0)
1414 dec_amount++; // make sure we decrement by something
1420 // Part of hack system to force update of palette after exiting a menu.
1421 if (Time_flash_last_played) {
1423 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1426 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1427 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1428 Time_flash_last_played = GameTime;
1431 Flash_effect -= FrameTime;
1432 if (Flash_effect < 0)
1435 if (force_do || (d_rand() > 4096 )) {
1436 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1437 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1439 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1446 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1447 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1449 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1450 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1452 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1453 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1455 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1456 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1458 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1460 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1463 int Redsave, Bluesave, Greensave;
1465 void palette_save(void)
1467 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1470 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1472 void game_palette_step_up( int r, int g, int b )
1474 if ( VR_use_reg_code ) {
1475 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1477 gr_palette_step_up( r, g, b );
1481 void palette_restore(void)
1483 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1484 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1486 // Forces flash effect to fixup palette next frame.
1487 Time_flash_last_played = 0;
1490 extern void dead_player_frame(void);
1493 // --------------------------------------------------------------------------------------------------
1494 int allowed_to_fire_laser(void)
1496 if (Player_is_dead) {
1497 Global_missile_firing_count = 0;
1501 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1502 // be a long while before laser can be fired, then there must be some mistake!
1503 if (Next_laser_fire_time > GameTime)
1504 if (Next_laser_fire_time < GameTime + 2*F1_0)
1510 fix Next_flare_fire_time = 0;
1511 #define FLARE_BIG_DELAY (F1_0*2)
1513 int allowed_to_fire_flare(void)
1515 if (Next_flare_fire_time > GameTime)
1516 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1519 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1520 Next_flare_fire_time = GameTime + F1_0/4;
1522 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1527 int allowed_to_fire_missile(void)
1529 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1530 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1531 // be a long while before missile can be fired, then there must be some mistake!
1532 if (Next_missile_fire_time > GameTime)
1533 if (Next_missile_fire_time < GameTime + 5*F1_0)
1539 void full_palette_save(void)
1542 apply_modified_palette();
1543 reset_palette_add();
1544 gr_palette_load( gr_palette );
1547 extern int Death_sequence_aborted;
1548 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) );
1555 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1558 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
1560 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F2;
1561 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ALT_F3;
1563 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1564 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1565 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = save_help;
1566 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = restore_help;
1568 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
1569 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F3;
1570 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F4;
1571 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
1572 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F6\t Fast Save";
1574 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
1576 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (F15)\t Pause";
1578 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_MINUSPLUS;
1580 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
1582 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "printscrn (F13)\t save screen shot";
1584 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
1585 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
1586 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F1\t Cycle left window";
1587 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F2\t Cycle right window";
1588 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F4\t GuideBot menu";
1590 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F4\t Rename GuideBot";
1592 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Opt-Shift-F4\t Rename GuideBot";
1594 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F5\t Drop primary";
1595 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F6\t Drop secondary";
1596 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-F7\t Calibrate joystick";
1597 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Shift-number\t GuideBot commands";
1599 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
1600 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = pixel_double_help;
1601 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
1602 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
1603 m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = command_help;
1606 full_palette_save();
1608 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
1613 //temp function until Matt cleans up game sequencing
1614 extern void temp_reset_stuff_on_level();
1616 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
1618 //deal with rear view - switch it on, or off, or whatever
1619 void check_rear_view()
1621 static int leave_mode;
1622 static fix entry_time;
1624 if ( Controls.rear_view_down_count ) { //key/button has gone down
1628 if (Cockpit_mode==CM_REAR_VIEW) {
1629 select_cockpit(Cockpit_mode_save);
1630 Cockpit_mode_save = -1;
1632 if (Newdemo_state == ND_STATE_RECORDING)
1633 newdemo_record_restore_rearview();
1637 if (Rear_view_leave_time <= 0)
1639 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
1643 leave_mode = 0; // means wait for another key
1644 entry_time = timer_get_fixed_seconds();
1646 if (Cockpit_mode == CM_FULL_COCKPIT) {
1647 Cockpit_mode_save = Cockpit_mode;
1648 select_cockpit(CM_REAR_VIEW);
1650 if (Newdemo_state == ND_STATE_RECORDING)
1651 newdemo_record_rearview();
1655 if (Controls.rear_view_down_state) {
1657 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
1662 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
1664 if (leave_mode==1 && Rear_view) {
1666 if (Cockpit_mode==CM_REAR_VIEW) {
1667 select_cockpit(Cockpit_mode_save);
1668 Cockpit_mode_save = -1;
1670 if (Newdemo_state == ND_STATE_RECORDING)
1671 newdemo_record_restore_rearview();
1676 void reset_rear_view(void)
1679 if (Newdemo_state == ND_STATE_RECORDING)
1680 newdemo_record_restore_rearview();
1685 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
1686 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
1687 Cockpit_mode_save = CM_FULL_COCKPIT;
1688 select_cockpit(Cockpit_mode_save);
1689 Cockpit_mode_save = -1;
1695 int Config_menu_flag;
1699 int gr_renderstats = 0;
1700 // need to define "cheat" for renderstats
1701 int gr_badtexture = 0;
1702 // need to define "cheat" for badtexture
1704 int Cheats_enabled=0;
1706 extern int Laser_rapid_fire;
1707 extern void do_lunacy_on(), do_lunacy_off();
1709 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
1710 extern char BounceCheat,HomingCheat,OldHomingState[20];
1711 extern char AcidCheatOn,old_IntMethod, Monster_mode;
1712 extern int Buddy_dude_cheat;
1714 //turns off active cheats
1715 void turn_cheats_off()
1721 Weapon_info[i].homing_flag=OldHomingState[i];
1726 Interpolation_method=old_IntMethod;
1729 Buddy_dude_cheat = 0;
1733 Laser_rapid_fire = 0;
1734 Physics_cheat_flag = 0;
1736 Robots_kill_robots_cheat=0;
1737 Robot_firing_enabled = 1;
1740 //turns off all cheats & resets cheater flag
1741 void game_disable_cheats()
1749 // ----------------------------------------------------------------------------
1751 void game_setup(void)
1753 //@@int demo_playing=0;
1754 //@@int multi_game=0;
1756 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
1757 do_lunacy_off(); // Restore true insane mode.
1760 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
1761 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
1762 Endlevel_sequence = 0;
1764 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
1765 //@@ demo_playing = 1;
1766 //@@if ( Game_mode & GM_MULTI )
1767 //@@ multi_game = 1;
1769 set_screen_mode(SCREEN_GAME);
1770 reset_palette_add();
1772 set_warn_func(game_show_warning);
1776 //digi_init_sounds();
1778 //keyd_repeat = 0; // Don't allow repeat in game
1779 keyd_repeat = 1; // Do allow repeat in game
1782 //_MARK_("start of game");
1786 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
1787 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
1789 if (!check_obj_seg(ConsoleObject))
1790 move_player_2_segment(Cursegp,Curside);
1793 Viewer = ConsoleObject;
1794 fly_init(ConsoleObject);
1799 FrameTime = 0; //make first frame zero
1802 if (Current_level_num == 0) { //not a real level
1803 init_player_stats_game();
1810 game_flush_inputs();
1816 extern char IWasKicked;
1820 // ------------------------------------------------------------------------------------
1821 //this function is the game. called when game mode selected. runs until
1822 //editor mode or exit selected
1825 game_setup(); // Replaces what was here earlier.
1826 // Good for Windows Sake.
1829 ProfilerSetStatus(1);
1832 if ( setjmp(LeaveGame)==0 ) {
1838 Config_menu_flag = 0;
1840 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
1842 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
1843 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
1846 player_shields = Players[Player_num].shields;
1848 ExtGameStatus=GAMESTAT_RUNNING;
1849 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
1851 //if the player is taking damage, give up guided missile control
1852 if (Players[Player_num].shields != player_shields)
1853 release_guided_missile(Player_num);
1855 //see if redbook song needs to be restarted
1856 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
1858 if (Config_menu_flag) {
1859 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
1861 if (!(Game_mode&GM_MULTI)) palette_restore();
1865 int save_w=Game_window_w,save_h=Game_window_h;
1867 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
1868 Game_window_w=save_w; Game_window_h=save_h;
1870 last_drawn_cockpit[0] = -1;
1871 last_drawn_cockpit[1] = -1;
1874 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
1876 fmode = Function_mode;
1877 Function_mode = FMODE_GAME;
1879 apply_modified_palette();
1880 reset_palette_add();
1881 gr_palette_load( gr_palette );
1882 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
1884 Function_mode = fmode;
1887 newdemo_stop_playback();
1888 Function_mode = FMODE_MENU;
1890 Function_mode = FMODE_GAME;
1894 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
1900 fmode = Function_mode;
1901 Function_mode = FMODE_GAME;
1903 apply_modified_palette();
1904 reset_palette_add();
1905 gr_palette_load( gr_palette );
1906 ExtGameStatus=GAMESTAT_ABORT_GAME;
1907 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
1909 Function_mode = fmode;
1911 Function_mode = FMODE_GAME;
1917 if (Function_mode != FMODE_GAME)
1918 longjmp(LeaveGame,0);
1921 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
1922 longjmp(LeaveGame,0);
1928 ProfilerSetStatus(0);
1933 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
1934 newdemo_stop_recording();
1940 if ( Newdemo_state == ND_STATE_PLAYBACK )
1941 newdemo_stop_playback();
1943 if (Cockpit_mode_save!=-1)
1945 Cockpit_mode=Cockpit_mode_save;
1946 Cockpit_mode_save=-1;
1949 if (Function_mode != FMODE_EDITOR)
1950 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
1952 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
1953 //@@ scores_maybe_add_player(Game_aborted);
1957 //_MARK_("end of game");
1960 clear_warn_func(game_show_warning); //don't use this func anymore
1962 game_disable_cheats();
1965 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
1969 //called at the end of the program
1972 if (VR_offscreen_buffer) {
1973 gr_free_canvas(VR_offscreen_buffer);
1974 VR_offscreen_buffer = NULL;
1977 close_gauge_canvases();
1979 restore_effect_bitmap_icons();
1981 if (background_bitmap.bm_data)
1982 d_free(background_bitmap.bm_data);
1984 clear_warn_func(game_show_warning); //don't use this func anymore
1987 grs_canvas * get_current_game_screen()
1989 return &VR_screen_pages[VR_current_page];
1993 extern void kconfig_center_headset();
1997 void speedtest_frame(void);
1998 int Debug_slowdown=0;
2002 extern void player_follow_path(object *objp);
2003 extern void check_create_player_path(void);
2007 extern int Do_appearance_effect;
2009 object *Missile_viewer=NULL;
2011 int Missile_view_enabled = 1;
2013 int Marker_viewer_num[2]={-1,-1};
2014 int Coop_view_player[2]={-1,-1};
2015 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2017 //returns ptr to escort robot, or NULL
2018 object *find_escort()
2022 for (i=0; i<=Highest_object_index; i++)
2023 if (Objects[i].type == OBJ_ROBOT)
2024 if (Robot_info[Objects[i].id].companion)
2030 extern void process_super_mines_frame(void);
2031 extern void do_seismic_stuff(void);
2034 int Saving_movie_frames=0;
2035 int __Movie_frame_num=0;
2037 #define MAX_MOVIE_BUFFER_FRAMES 250
2038 #define MOVIE_FRAME_SIZE (320 * 200)
2040 ubyte *Movie_frame_buffer;
2041 int Movie_frame_counter;
2042 ubyte Movie_pal[768];
2043 char movie_path[50] = ".\\";
2045 grs_bitmap Movie_bm;
2047 void flush_movie_buffer()
2054 mprintf((0,"Flushing movie buffer..."));
2056 Movie_bm.bm_data = Movie_frame_buffer;
2058 for (f=0;f<Movie_frame_counter;f++) {
2059 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2060 __Movie_frame_num++;
2061 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2062 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2065 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2068 Movie_frame_counter=0;
2070 mprintf((0,"done \n"));
2075 void toggle_movie_saving()
2079 Saving_movie_frames = !Saving_movie_frames;
2081 if (Saving_movie_frames) {
2084 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2085 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2088 Saving_movie_frames = 0;
2092 while (isspace(movie_path[strlen(movie_path)-1]))
2093 movie_path[strlen(movie_path)-1] = 0;
2094 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2095 strcat(movie_path,"\\");
2098 if (!Movie_frame_buffer) {
2099 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2100 if (!Movie_frame_buffer) {
2102 Saving_movie_frames=0;
2105 Movie_frame_counter=0;
2107 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2108 Movie_bm.bm_w = 320;
2109 Movie_bm.bm_h = 200;
2110 Movie_bm.bm_type = BM_LINEAR;
2111 Movie_bm.bm_flags = 0;
2112 Movie_bm.bm_rowsize = 320;
2113 Movie_bm.bm_handle = 0;
2115 gr_palette_read(Movie_pal); //get actual palette from the hardware
2117 if (Newdemo_state == ND_STATE_PLAYBACK)
2118 Newdemo_do_interpolate = 0;
2122 flush_movie_buffer();
2124 if (Newdemo_state == ND_STATE_PLAYBACK)
2125 Newdemo_do_interpolate = 1;
2130 void save_movie_frame()
2132 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2134 Movie_frame_counter++;
2136 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2137 flush_movie_buffer();
2143 extern int Level_shake_duration;
2145 //if water or fire level, make occasional sound
2146 void do_ambient_sounds()
2148 int has_water,has_lava;
2151 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2152 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2154 if (has_lava) { //has lava
2155 sound = SOUND_AMBIENT_LAVA;
2156 if (has_water && (d_rand() & 1)) //both, pick one
2157 sound = SOUND_AMBIENT_WATER;
2159 else if (has_water) //just water
2160 sound = SOUND_AMBIENT_WATER;
2164 if (((d_rand() << 3) < FrameTime)) { //play the sound
2165 fix volume = d_rand() + f1_0/2;
2166 digi_play_sample(sound,volume);
2170 // -- extern void lightning_frame(void);
2172 void game_render_frame();
2173 extern void omega_charge_frame(void);
2175 extern time_t t_current_time, t_saved_time;
2177 void flicker_lights();
2179 void GameLoop(int RenderFlag, int ReadControlsFlag )
2182 // Used to slow down frame rate for testing things.
2183 // RenderFlag = 1; // DEBUG
2184 if (Debug_slowdown) {
2187 for (h=0; h<Debug_slowdown; h++)
2188 for (i=0; i<1000; i++)
2194 if (FindArg("-invulnerability"))
2195 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2199 update_player_stats();
2200 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2201 do_afterburner_stuff();
2203 do_invulnerable_stuff();
2204 remove_obsolete_stuck_objects();
2206 do_final_boss_frame();
2207 // -- lightning_frame();
2208 // -- recharge_energy_frame();
2210 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2211 static int turned_off=0;
2212 Players[Player_num].energy -= (FrameTime*3/8);
2213 if (Players[Player_num].energy < i2f(10)) {
2215 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2218 if (Game_mode & GM_MULTI)
2219 multi_send_flags(Player_num);
2226 if (Players[Player_num].energy <= 0) {
2227 Players[Player_num].energy = 0;
2228 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2230 if (Game_mode & GM_MULTI)
2231 multi_send_flags(Player_num);
2238 check_create_player_path();
2239 player_follow_path(ConsoleObject);
2243 if (Game_mode & GM_MULTI)
2246 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2247 multi_check_for_killgoal_winner();
2253 if (force_cockpit_redraw) { //screen need redrawing?
2255 force_cockpit_redraw=0;
2257 game_render_frame();
2258 //show_extra_views(); //missile view, buddy bot, etc.
2261 if (Saving_movie_frames)
2268 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2272 dead_player_frame();
2273 if (Newdemo_state != ND_STATE_PLAYBACK)
2274 do_controlcen_dead_frame();
2276 process_super_mines_frame();
2278 do_ambient_sounds();
2285 if (ReadControlsFlag)
2288 memset(&Controls, 0, sizeof(Controls));
2290 GameTime += FrameTime;
2292 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2293 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2295 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2296 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2297 mprintf((0,"GameTime reset to 0\n"));
2301 if (FindArg("-checktime") != 0)
2302 if (GameTime >= i2f(600)) //wrap after 10 minutes
2303 GameTime = FrameTime;
2307 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2308 ThisLevelTime +=FrameTime;
2313 if (Endlevel_sequence) {
2314 do_endlevel_frame();
2315 powerup_grab_cheat_all();
2316 do_special_effects();
2317 return; //skip everything else
2320 if (Newdemo_state != ND_STATE_PLAYBACK)
2321 do_exploding_wall_frame();
2322 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2323 do_special_effects();
2324 wall_frame_process();
2325 triggers_frame_process();
2329 if (Control_center_destroyed) {
2330 if (Newdemo_state==ND_STATE_RECORDING )
2331 newdemo_record_control_center_destroyed();
2336 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2337 newdemo_playback_one_frame();
2338 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2339 longjmp( LeaveGame, 0 ); // Go back to menu
2342 { // Note the link to above!
2344 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2347 powerup_grab_cheat_all();
2349 if (Endlevel_sequence) //might have been started during move
2352 fuelcen_update_all();
2356 if (allowed_to_fire_laser())
2357 FireLaser(); // Fire Laser!
2359 if (Auto_fire_fusion_cannon_time) {
2360 if (Primary_weapon != FUSION_INDEX)
2361 Auto_fire_fusion_cannon_time = 0;
2362 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2363 Auto_fire_fusion_cannon_time = 0;
2364 Global_laser_firing_count = 1;
2366 vms_vector rand_vec;
2369 Global_laser_firing_count = 0;
2371 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2372 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2373 make_random_vector(&rand_vec);
2375 bump_amount = F1_0*4;
2377 if (Fusion_charge > F1_0*2)
2378 bump_amount = Fusion_charge*4;
2380 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2384 if (Global_laser_firing_count) {
2385 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2386 // if (Fusion_charge > F1_0*2)
2387 // Fusion_charge = F1_0*2;
2388 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2391 if (Global_laser_firing_count < 0)
2392 Global_laser_firing_count = 0;
2395 if (Do_appearance_effect) {
2396 create_player_appearance_effect(ConsoleObject);
2397 Do_appearance_effect = 0;
2399 if ((Game_mode & GM_MULTI) && Netgame.invul)
2401 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2402 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2409 omega_charge_frame();
2413 //!!hoard_light_pulse(); //do cool hoard light pulsing
2417 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2418 //!!extern int Hoard_goal_eclip;
2420 //!!//do cool pulsing lights in hoard goals
2421 //!!hoard_light_pulse()
2423 //!! if (Game_mode & GM_HOARD) {
2427 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2431 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2434 //!! light = abs(frame - 5) * f1_0 / 5;
2436 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2441 ubyte Slide_segs[MAX_SEGMENTS];
2442 int Slide_segs_computed;
2444 void compute_slide_segs(void)
2446 int segnum, sidenum;
2448 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2449 Slide_segs[segnum] = 0;
2450 for (sidenum=0;sidenum<6;sidenum++) {
2451 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2452 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2453 Slide_segs[segnum] |= 1 << sidenum;
2457 Slide_segs_computed = 1;
2460 // -----------------------------------------------------------------------------
2461 void slide_textures(void)
2463 int segnum,sidenum,i;
2465 if (!Slide_segs_computed)
2466 compute_slide_segs();
2468 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2469 if (Slide_segs[segnum]) {
2470 for (sidenum=0;sidenum<6;sidenum++) {
2471 if (Slide_segs[segnum] & (1 << sidenum)) {
2472 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2473 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2475 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2476 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2477 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2480 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2482 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2485 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2487 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2490 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2492 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2495 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2505 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2507 int Num_flickering_lights=0;
2509 void flicker_lights()
2512 flickering_light *f;
2514 f = Flickering_lights;
2516 for (l=0;l<Num_flickering_lights;l++,f++) {
2517 segment *segp = &Segments[f->segnum];
2519 //make sure this is actually a light
2520 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2522 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2525 if (f->timer == 0x80000000) //disabled
2528 if ((f->timer -= FrameTime) < 0) {
2530 while (f->timer < 0)
2531 f->timer += f->delay;
2533 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
2536 add_light(f->segnum,f->sidenum);
2538 subtract_light(f->segnum,f->sidenum);
2543 //returns ptr to flickering light structure, or NULL if can't find
2544 flickering_light *find_flicker(int segnum,int sidenum)
2547 flickering_light *f;
2549 //see if there's already an entry for this seg/side
2551 f = Flickering_lights;
2553 for (l=0;l<Num_flickering_lights;l++,f++)
2554 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2560 //turn flickering off (because light has been turned off)
2561 void disable_flicker(int segnum,int sidenum)
2563 flickering_light *f;
2565 if ((f=find_flicker(segnum,sidenum)) != NULL)
2566 f->timer = 0x80000000;
2569 //turn flickering off (because light has been turned on)
2570 void enable_flicker(int segnum,int sidenum)
2572 flickering_light *f;
2574 if ((f=find_flicker(segnum,sidenum)) != NULL)
2581 //returns 1 if ok, 0 if error
2582 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
2585 flickering_light *f;
2587 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
2589 //see if there's already an entry for this seg/side
2591 f = Flickering_lights;
2593 for (l=0;l<Num_flickering_lights;l++,f++)
2594 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
2597 if (mask==0) { //clearing entry
2598 if (l == Num_flickering_lights)
2602 for (i=l;i<Num_flickering_lights-1;i++)
2603 Flickering_lights[i] = Flickering_lights[i+1];
2604 Num_flickering_lights--;
2609 if (l == Num_flickering_lights) {
2610 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
2613 Num_flickering_lights++;
2617 f->sidenum = sidenum;
2618 f->delay = f->timer = delay;
2626 // -----------------------------------------------------------------------------
2627 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
2632 Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
2634 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
2635 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
2636 Global_laser_firing_count = 0;
2638 if (Fusion_charge == 0)
2639 Players[Player_num].energy -= F1_0*2;
2641 Fusion_charge += FrameTime;
2642 Players[Player_num].energy -= FrameTime;
2644 if (Players[Player_num].energy <= 0) {
2645 Players[Player_num].energy = 0;
2646 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
2648 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
2649 // Fire the fusion cannon at this time in the future.
2651 if (Fusion_charge < F1_0*2)
2652 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
2654 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
2656 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
2657 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
2659 if (Fusion_next_sound_time < GameTime) {
2660 if (Fusion_charge > F1_0*2) {
2661 digi_play_sample( 11, F1_0 );
2662 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
2664 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
2665 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
2667 if (Game_mode & GM_MULTI)
2668 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
2671 Fusion_last_sound_time = GameTime;
2672 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
2680 // -------------------------------------------------------------------------------------------------------
2681 // If player is close enough to objnum, which ought to be a powerup, pick it up!
2682 // This could easily be made difficulty level dependent.
2683 void powerup_grab_cheat(object *player, int objnum)
2689 Assert(Objects[objnum].type == OBJ_POWERUP);
2691 powerup_size = Objects[objnum].size;
2692 player_size = player->size;
2694 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
2696 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
2697 vms_vector collision_point;
2699 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
2700 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
2704 // -------------------------------------------------------------------------------------------------------
2705 // Make it easier to pick up powerups.
2706 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
2707 // from player to powerup and player's forward vector.
2708 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
2709 // way before the player gets there.
2710 void powerup_grab_cheat_all(void)
2715 segp = &Segments[ConsoleObject->segnum];
2716 objnum = segp->objects;
2718 while (objnum != -1) {
2719 if (Objects[objnum].type == OBJ_POWERUP)
2720 powerup_grab_cheat(ConsoleObject, objnum);
2721 objnum = Objects[objnum].next;
2726 int Last_level_path_created = -1;
2728 #ifdef SHOW_EXIT_PATH
2730 // ------------------------------------------------------------------------------------------------------------------
2731 // Create path for player from current segment to goal segment.
2732 // Return true if path created, else return false.
2733 int mark_player_path_to_segment(int segnum)
2736 object *objp = ConsoleObject;
2737 short player_path_length=0;
2738 int player_hide_index=-1;
2740 if (Last_level_path_created == Current_level_num) {
2744 Last_level_path_created = Current_level_num;
2746 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
2747 mprintf((0, "Unable to form path of length %i for myself\n", 100));
2751 player_hide_index = Point_segs_free_ptr - Point_segs;
2752 Point_segs_free_ptr += player_path_length;
2754 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
2755 mprintf((1, "Can't create path. Not enough point_segs.\n"));
2756 ai_reset_all_paths();
2760 for (i=1; i<player_path_length; i++) {
2762 vms_vector seg_center;
2765 segnum = Point_segs[player_hide_index+i].segnum;
2766 mprintf((0, "%3i ", segnum));
2767 seg_center = Point_segs[player_hide_index+i].point;
2769 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
2771 Int3(); // Unable to drop energy powerup for path
2775 obj = &Objects[objnum];
2776 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
2777 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
2778 obj->rtype.vclip_info.framenum = 0;
2779 obj->lifeleft = F1_0*100 + d_rand() * 4;
2786 // Return true if it happened, else return false.
2787 int create_special_path(void)
2791 // ---------- Find exit doors ----------
2792 for (i=0; i<=Highest_segment_index; i++)
2793 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
2794 if (Segments[i].children[j] == -2) {
2795 mprintf((0, "Exit at segment %i\n", i));
2796 return mark_player_path_to_segment(i);
2806 int Max_obj_count_mike = 0;
2808 // Shows current number of used objects.
2809 void show_free_objects(void)
2811 if (!(FrameCount & 8)) {
2815 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
2817 for (i=0; i<=Highest_object_index; i++)
2818 if (Objects[i].type != OBJ_NONE)
2821 mprintf((0, "%3i", count));
2823 if (count > Max_obj_count_mike) {
2824 Max_obj_count_mike = count;
2825 mprintf((0, " ***"));
2836 * reads a flickering_light structure from a CFILE
2838 void flickering_light_read(flickering_light *fl, CFILE *fp)
2840 fl->segnum = cfile_read_short(fp);
2841 fl->sidenum = cfile_read_short(fp);
2842 fl->mask = cfile_read_int(fp);
2843 fl->timer = cfile_read_fix(fp);
2844 fl->delay = cfile_read_fix(fp);
2847 void flickering_light_write(flickering_light *fl, PHYSFS_file *fp)
2849 PHYSFS_writeSLE16(fp, fl->segnum);
2850 PHYSFS_writeSLE16(fp, fl->sidenum);
2851 PHYSFS_writeULE32(fp, fl->mask);
2852 PHYSFSX_writeFix(fp, fl->timer);
2853 PHYSFSX_writeFix(fp, fl->delay);