1 /* $Id: game.c,v 1.32 2004-10-23 19:09:58 schaffner 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.32 2004-10-23 19:09:58 schaffner Exp $";
42 #include <StandardFile.h>
43 #include <Quickdraw.h>
54 #include "pa_enabl.h" //$$POLY_ACC
101 #include "gamefont.h"
102 #include "endlevel.h"
107 #include "controls.h"
111 #if defined(POLY_ACC)
112 #include "poly_acc.h"
117 #include "cntrlcen.h"
121 #include "multibot.h"
124 #include "playsave.h"
128 int VGA_current_mode;
131 #include <profiler.h>
134 //#define TEST_TIMER 1 //if this is set, do checking on timer
136 #define SHOW_EXIT_PATH 1
139 #include "editor/editor.h"
144 #if __WATCOMC__ < 1000
145 #include <wsample.h> //should come after inferno.h to get mark setting
150 extern void ReadControls(void); // located in gamecntl.c
151 extern int Current_display_mode;
152 extern void do_final_boss_frame(void);
154 int Speedtest_on = 0;
157 int Mark_count = 0; // number of debugging marks set
158 int Speedtest_start_time;
159 int Speedtest_segnum;
160 int Speedtest_sidenum;
161 int Speedtest_frame_start;
162 int Speedtest_count=0; // number of times to do the debug test.
165 static fix last_timer_value=0;
168 #if defined(TIMER_TEST) && !defined(NDEBUG)
169 fix _timer_value,actual_last_timer_value,_last_frametime;
170 int stop_count,start_count;
171 int time_stopped,time_started;
175 ubyte * Game_cockpit_copy_code = NULL;
177 ubyte Game_cockpit_copy_code = 0;
178 ubyte Scanline_double = 1;
181 int VR_screen_mode = 0;
183 ubyte VR_screen_flags = 0; //see values in screens.h
184 ubyte VR_current_page = 0;
185 fix VR_eye_width = F1_0;
186 int VR_render_mode = VR_NONE;
187 int VR_low_res = 3; // Default to low res
189 int VR_sensitivity = 1; // 0 - 2
192 int VR_eye_offset = 0;
193 int VR_eye_switch = 0;
194 int VR_eye_offset_changed = 0;
195 int VR_use_reg_code = 0;
197 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
198 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
199 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
200 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
201 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
204 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
205 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
206 dd_grs_canvas dd_VR_screen_pages[2];
207 dd_grs_canvas dd_VR_render_buffer[2];
208 dd_grs_canvas dd_VR_render_sub_buffer[2];
210 void game_win_init_cockpit_mask(int sram);
213 //do menus work in 640x480 or 320x200?
214 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
215 int MenuHiresAvailable = 1; //can we do highres menus?
216 int MenuHires = 1; //are we currently in highres menus?
218 int Debug_pause=0; //John's debugging pause system
220 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
222 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
223 int force_cockpit_redraw=0;
225 cvar_t r_framerate = {"r_framerate","0"};
227 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
229 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
231 int *Toggle_var = &Dummy_var;
234 //flag for whether initial fade-in has been done
238 #ifndef NDEBUG //these only exist if debugging
240 int Game_double_buffer = 1; //double buffer by default
241 fix fixed_frametime=0; //if non-zero, set frametime to this
245 int Game_suspended=0; //if non-zero, nothing moves but player
248 fix Auto_fire_fusion_cannon_time = 0;
249 fix Fusion_charge = 0;
250 fix Fusion_next_sound_time = 0;
251 fix Fusion_last_sound_time = 0;
254 int Game_turbo_mode = 0;
256 int Game_mode = GM_GAME_OVER;
258 int Global_laser_firing_count = 0;
259 int Global_missile_firing_count = 0;
261 grs_bitmap background_bitmap;
265 #define BACKGROUND_NAME "statback.pcx"
267 // Function prototypes for GAME.C exclusively.
269 void GameLoop(int RenderFlag, int ReadControlsFlag);
270 void FireLaser(void);
271 void slide_textures(void);
272 void powerup_grab_cheat_all(void);
275 extern void multi_check_for_killgoal_winner();
276 extern void RestoreGameSurfaces();
280 void grow_window(void);
281 void shrink_window(void);
285 void fill_background();
288 void show_framerate(void);
289 void ftoa(char *string, fix f);
292 extern ubyte DefiningMarkerMessage;
293 extern char Marker_input[];
295 // ==============================================================================================
297 extern char john_head_on;
299 void load_background_bitmap()
304 if (background_bitmap.bm_data)
305 d_free(background_bitmap.bm_data);
307 background_bitmap.bm_data=NULL;
308 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
309 if (pcx_error != PCX_ERROR_NONE)
310 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
311 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
315 //this is called once per game
318 atexit(close_game); //for cleanup
322 init_special_effects();
326 init_gauge_canvases();
328 init_exploding_walls();
330 load_background_bitmap();
332 Clear_window = 2; // do portal only window clear.
334 set_detail_level_parameters(Detail_level);
337 cvar_registervariable(&r_framerate);
342 void reset_palette_add()
347 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
352 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
358 int lspan=0, rspan=0, span=0;
362 //@@ fp = fopen("cockspan.dat", "w");
364 for (y = 0; y < miny; y++)
365 win_cockpit_mask[y].num = 0;
367 for (y = miny; y <= maxy; y++)
370 //@@ fprintf(fp, "line %d: ", y);
371 for (x = 0; x < bm->bm_w; x++)
373 offset = y*bm->bm_rowsize + x;
375 if (data[offset] == 255) {
378 case 0: // Start Mode
380 win_cockpit_mask[y].span[span].xmin = x;
382 //@@ fprintf(fp, "<%d,", lspan);
385 case 1: // Transparency mode
387 win_cockpit_mask[y].span[span].xmax = x;
390 case 2: // Switch from Draw mode to transparent
392 win_cockpit_mask[y].span[span].xmin = x;
393 //@@ fprintf(fp, "<%d,", lspan);
401 case 0: // Start mode
405 case 1: // Switching from transparent to Draw
408 win_cockpit_mask[y].span[span].xmax = x;
410 //@@ fprintf(fp, "%d> ", rspan);
419 //@@ fprintf(fp, "%d> ", rspan);
420 win_cockpit_mask[y].span[span].xmax = rspan;
423 win_cockpit_mask[y].num = span;
424 //@@ fprintf(fp, "\n");
427 win_cockpit_mask[y].num = 255;
432 void game_show_warning(char *s)
435 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
438 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
440 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
445 //these should be in gr.h
446 #define cv_w cv_bitmap.bm_w
447 #define cv_h cv_bitmap.bm_h
449 //added 3/24/99 by Owen Evans for screen res changing
450 u_int32_t Game_screen_mode = 0;
452 int Game_window_x = 0;
453 int Game_window_y = 0;
454 int Game_window_w = 0;
455 int Game_window_h = 0;
456 int max_window_w = 0;
457 int max_window_h = 0;
459 extern void newdemo_record_cockpit_change(int);
461 //initialize the various canvases on the game screen
462 //called every time the screen mode or cockpit changes
465 int minx, maxx, miny, maxy;
467 #if defined(POLY_ACC)
468 pa_flush(); // get rid of undrawn polys.
469 pa_clear_buffer(1, 0);
472 //Initialize the on-screen canvases
474 if (Newdemo_state==ND_STATE_RECORDING) {
475 newdemo_record_cockpit_change(Cockpit_mode);
478 if ( VR_render_mode != VR_NONE )
479 Cockpit_mode = CM_FULL_SCREEN;
481 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
482 Cockpit_mode = CM_FULL_SCREEN;
484 if ( Screen_mode == SCREEN_EDITOR )
485 Cockpit_mode = CM_FULL_SCREEN;
488 if (Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_REAR_VIEW) {
489 hud_message(MSGC_GAME_FEEDBACK, "Cockpit not available in GL mode");
490 Cockpit_mode = CM_FULL_SCREEN;
495 dd_gr_set_current_canvas(NULL),
496 gr_set_current_canvas(NULL)
498 gr_set_curfont( GAME_FONT );
500 #if !defined(MACINTOSH) && !defined(WINDOWS)
501 if (Game_cockpit_copy_code)
502 d_free(Game_cockpit_copy_code);
503 Game_cockpit_copy_code = NULL;
505 if (Game_cockpit_copy_code)
506 Game_cockpit_copy_code = 0;
510 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
514 game_win_init_cockpit_mask(0);
517 switch( Cockpit_mode ) {
518 case CM_FULL_COCKPIT:
520 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
522 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
525 dd_gr_set_current_canvas(NULL);
526 game_win_init_cockpit_mask(1);
527 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
529 gr_set_current_canvas(VR_offscreen_buffer);
532 WIN(DDGRLOCK(dd_grd_curcanv));
533 gr_bitmap( 0, 0, bm );
534 bm = &VR_offscreen_buffer->cv_bitmap;
535 bm->bm_flags = BM_FLAG_TRANSPARENT;
536 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
537 WIN( win_get_span_list(bm, miny, maxy);
538 DDGRUNLOCK(dd_grd_curcanv)
543 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
545 if ( Current_display_mode ) {
546 #if defined(POLY_ACC)
547 Game_cockpit_copy_code = gr_ibitblt_create_mask_pa( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
548 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
550 Game_cockpit_copy_code = gr_ibitblt_create_mask_svga( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
553 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
555 bm->bm_flags = 0; // Clear all flags for offscreen canvas
557 Game_cockpit_copy_code = (ubyte *)(1);
558 bm->bm_flags = 0; // Clear all flags for offscreen canvas
560 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
566 max_window_h = grd_curscreen->sc_h;
568 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
569 Game_window_h = max_window_h;
571 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
572 Game_window_w = max_window_w;
574 Game_window_x = (max_window_w - Game_window_w)/2;
575 Game_window_y = (max_window_h - Game_window_h)/2;
577 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
582 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
584 if (Game_window_h > max_window_h)
585 Game_window_h = max_window_h;
587 if (Game_window_w > max_window_w)
588 Game_window_w = max_window_w;
590 Game_window_x = (max_window_w - Game_window_w)/2;
591 Game_window_y = (max_window_h - Game_window_h)/2;
593 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
599 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
600 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
601 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
603 game_init_render_sub_buffers( x, y, w, h );
610 dd_gr_set_current_canvas(NULL),
611 gr_set_current_canvas(NULL)
615 //selects a given cockpit (or lack of one). See types in game.h
616 void select_cockpit(int mode)
618 if (mode != Cockpit_mode) { //new mode
624 extern int last_drawn_cockpit[2];
626 //force cockpit redraw next time. call this if you've trashed the screen
629 force_cockpit_redraw=1;
630 last_drawn_cockpit[0] = -1;
631 last_drawn_cockpit[1] = -1;
634 // void HUD_clear_messages(); //Already declared in gauges.h
637 void VR_reset_params()
639 VR_eye_width = VR_SEPARATION;
640 VR_eye_offset = VR_PIXEL_SHIFT;
641 VR_eye_offset_changed = 2;
644 void game_init_render_sub_buffers( int x, int y, int w, int h )
647 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
648 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
650 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
651 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
652 dd_VR_render_sub_buffer[0].xoff = x;
653 dd_VR_render_sub_buffer[0].yoff = y;
654 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
655 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
656 dd_VR_render_sub_buffer[1].xoff = x;
657 dd_VR_render_sub_buffer[1].yoff = y;
660 if (Scanline_double) {
664 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
665 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
668 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
669 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
679 newBounds.right = x + w;
681 newBounds.bottom = y + h;
683 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
689 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
690 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
691 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
692 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
698 // Sets up the canvases we will be rendering to (WIN95)
699 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
701 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
702 // creating surfaces greater than the current resolution
704 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
705 render_w = GRMODEINFO(rw);
706 render_h = GRMODEINFO(rh);
709 VR_screen_mode = screen_mode;
711 VR_screen_flags = flags;
714 VR_render_mode = render_method;
716 Game_window_w = render_w;
717 Game_window_h = render_h;
719 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
720 dd_gr_free_canvas(dd_VR_offscreen_buffer);
723 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
724 if ( render_h*2 < 200 ) {
725 Int3(); // Not Supported yet!!!
726 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
729 Int3(); // Not Supported yet!!!
730 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
733 Int3(); // Not Supported yet!!!
734 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
735 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
737 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
738 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
739 // we can just flip it, saving a blt.
741 dd_VR_offscreen_buffer = dd_grd_backcanv;
742 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
744 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
745 // The offscreen buffer will be created. We will just blt this
746 // to the screen (which may be blted to the primary surface)
747 if ( render_h < 200 ) {
748 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
749 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
752 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
753 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
757 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
758 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
759 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
760 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
762 game_init_render_sub_buffers( 0, 0, render_w, render_h );
767 // Sets up the canvases we will be rendering to (NORMAL VERSION)
768 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
770 // if (vga_check_mode(screen_mode) != 0)
771 // Error("Cannot set requested video mode");
773 VR_screen_mode = screen_mode;
775 VR_screen_flags = flags;
779 VR_render_mode = render_method;
781 Game_window_w = render_w;
782 Game_window_h = render_h;
784 if (VR_offscreen_buffer) {
785 gr_free_canvas(VR_offscreen_buffer);
788 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
789 if ( render_h*2 < 200 ) {
790 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
793 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
796 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
797 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
800 if ( render_h < 200 ) {
801 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
804 #if defined(POLY_ACC)
806 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
807 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
808 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
810 if ( PAEnabled || gConfigInfo.mAcceleration ) {
811 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
812 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
814 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
817 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
822 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
825 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
826 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
829 game_init_render_sub_buffers( 0, 0, render_w, render_h );
833 //called to get the screen in a mode compatible with popup menus.
834 //if we can't have popups over the game screen, switch to menu mode.
835 void set_popup_screen(void)
837 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
839 #ifndef OGL // always have to switch to menu mode
840 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
843 set_screen_mode(SCREEN_MENU); //must switch to menu mode
848 //called to change the screen mode. Parameter sm is the new mode, one of
849 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
850 //mode if cannot init requested mode)
851 int set_screen_mode(int sm)
853 WIN(static int force_mode_change=0);
854 WIN(static int saved_window_w);
855 WIN(static int saved_window_h);
858 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
859 gr_set_current_canvas( Canv_editor );
865 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
866 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
870 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
871 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
877 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
878 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
879 ogl_set_screen_mode();
890 switch( Screen_mode )
896 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
897 // HACK!!! Meant to save window size when switching from
898 // non-compat menu mode to menu mode.
899 saved_window_w = Game_window_w;
900 saved_window_h = Game_window_h;
901 force_mode_change = 1;
903 if (W95DisplayMode != SM95_640x480x8) {
904 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
905 DDSETDISPLAYMODE(SM95_640x480x8);
907 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
910 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
912 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
913 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
914 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
916 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
917 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
919 FontHires = FontHiresAvailable;
925 MenuHires = MenuHiresAvailable; //do highres if we can
927 #if defined(POLY_ACC)
929 menu_mode = MenuHires?SM(640,480):SM(320,200);
931 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
934 menu_mode = MenuHires?SM(640,480):SM(320,200);
937 if (VGA_current_mode != menu_mode) {
938 if (gr_set_mode(menu_mode))
939 Error("Cannot set screen mode for menu");
940 if (!gr_palette_faded_out)
941 gr_palette_load(gr_palette);
944 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
945 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
947 FontHires = FontHiresAvailable && MenuHires;
957 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
959 DDSETDISPLAYMODE(VR_screen_mode);
960 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
962 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
963 game_init_render_buffers(W95DisplayMode,
964 GRMODEINFO(rw), GRMODEINFO(rh),
965 VR_render_mode, VR_screen_flags);
970 if (VGA_current_mode != VR_screen_mode) {
971 if (gr_set_mode(VR_screen_mode)) {
972 Error("Cannot set desired screen mode for game!");
973 //we probably should do something else here, like select a standard mode
976 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
983 if ( VR_render_mode == VR_NONE )
985 max_window_w = grd_curscreen->sc_w;
986 max_window_h = grd_curscreen->sc_h;
988 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
989 if (Cockpit_mode == CM_STATUS_BAR)
990 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
992 else if (Cockpit_mode != CM_LETTERBOX)
993 Cockpit_mode = CM_FULL_SCREEN;
995 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
996 Game_window_w = max_window_w;
997 Game_window_h = max_window_h;
1002 Cockpit_mode = CM_FULL_SCREEN;
1005 // Super hack. If we are switching from a 320x200 game to 640x480.
1006 // and we were in a menumode when switching, we don't
1007 // restore Game_window vals
1008 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
1009 Game_window_w = saved_window_w;
1010 Game_window_h = saved_window_h;
1011 force_mode_change = 0;
1016 // Define screen pages for game mode
1017 // If we designate through screen_flags to use paging, then do so.
1019 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1020 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1023 if ( VR_screen_flags&VRF_USE_PAGING ) {
1025 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1026 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 )
1031 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1032 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1039 FontHires = FontHiresAvailable && (Current_display_mode != 0);
1042 FontHires = FontHiresAvailable && (MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2)));
1045 if ( VR_render_mode != VR_NONE ) {
1046 // for 640x480 or higher, use hires font.
1047 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
1057 if (grd_curscreen->sc_mode != SM(800,600)) {
1059 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
1060 Warning("Cannot init editor screen (error=%d)",gr_error);
1064 gr_palette_load( gr_palette );
1066 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1067 Canv_editor = &VR_editor_canvas;
1068 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1069 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1070 gr_set_current_canvas( Canv_editor );
1071 init_editor_screen(); //setup other editor stuff
1075 Error("Invalid screen mode %d",sm);
1078 VR_current_page = 0;
1081 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1082 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1085 if ( VR_screen_flags&VRF_USE_PAGING ) {
1088 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1092 ogl_set_screen_mode();
1098 int gr_toggle_fullscreen_game(void){
1099 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1101 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
1102 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
1103 //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.
1104 // generic_key_handler(KEY_PADENTER,0);
1105 // generic_key_handler(KEY_ENTER, 0);
1110 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
1115 int arch_toggle_fullscreen_menu(void);
1117 int gr_toggle_fullscreen_menu(void){
1118 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
1120 i=arch_toggle_fullscreen_menu();
1122 // generic_key_handler(KEY_PADENTER,0);
1123 // generic_key_handler(KEY_ENTER, 0);
1132 static int timer_paused=0;
1136 if (timer_paused==0) {
1138 time = timer_get_fixed_seconds();
1139 last_timer_value = time - last_timer_value;
1140 if (last_timer_value < 0) {
1141 #if defined(TIMER_TEST) && !defined(NDEBUG)
1142 Int3(); //get Matt!!!!
1144 last_timer_value = 0;
1146 #if defined(TIMER_TEST) && !defined(NDEBUG)
1147 time_stopped = time;
1152 #if defined(TIMER_TEST) && !defined(NDEBUG)
1160 Assert(timer_paused >= 0);
1161 if (timer_paused==0) {
1163 time = timer_get_fixed_seconds();
1164 #if defined(TIMER_TEST) && !defined(NDEBUG)
1165 if (last_timer_value < 0)
1166 Int3(); //get Matt!!!!
1169 last_timer_value = time - last_timer_value;
1170 #if defined(TIMER_TEST) && !defined(NDEBUG)
1171 time_started = time;
1175 #if defined(TIMER_TEST) && !defined(NDEBUG)
1180 MAC(extern ubyte joydefs_calibrating;)
1182 void game_flush_inputs()
1189 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1191 mouse_get_delta( &dx, &dy ); // Read mouse
1192 memset(&Controls,0,sizeof(control_info));
1197 last_timer_value = timer_get_fixed_seconds();
1202 extern int Saving_movie_frames;
1203 int Movie_fixed_frametime;
1205 #define Saving_movie_frames 0
1206 #define Movie_fixed_frametime 0
1209 //added on 8/18/98 by Victor Rachels to add maximum framerate
1213 void calc_frame_time()
1215 fix timer_value,last_frametime = FrameTime;
1217 #if defined(TIMER_TEST) && !defined(NDEBUG)
1218 _last_frametime = last_frametime;
1221 timer_value = timer_get_fixed_seconds();
1222 FrameTime = timer_value - last_timer_value;
1225 timer_value = timer_get_fixed_seconds();
1226 FrameTime = timer_value - last_timer_value;
1227 if (FrameTime < f1_0/maxfps);
1229 } while (FrameTime < f1_0/maxfps);
1231 #if defined(TIMER_TEST) && !defined(NDEBUG)
1232 _timer_value = timer_value;
1236 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1237 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1239 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1240 // if ( !dpmi_virtual_memory )
1241 // Int3(); //Get MATT if hit this!
1245 #if defined(TIMER_TEST) && !defined(NDEBUG)
1246 actual_last_timer_value = last_timer_value;
1249 if ( Game_turbo_mode )
1252 // Limit frametime to be between 5 and 150 fps.
1253 RealFrameTime = FrameTime;
1254 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1255 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1257 last_timer_value = timer_value;
1259 if (FrameTime < 0) //if bogus frametime...
1260 FrameTime = last_frametime; //...then use time from last frame
1263 if (fixed_frametime) FrameTime = fixed_frametime;
1268 if ( Debug_pause ) {
1278 last_timer_value = timer_get_fixed_seconds();
1286 #if defined(TIMER_TEST) && !defined(NDEBUG)
1287 stop_count = start_count = 0;
1290 // Set value to determine whether homing missile can see target.
1291 // The lower frametime is, the more likely that it can see its target.
1292 if (FrameTime <= F1_0/64)
1293 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1294 else if (FrameTime < F1_0/32)
1295 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1296 else if (FrameTime < F1_0/4)
1297 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;
1299 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1303 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1305 void move_player_2_segment(segment *seg,int side)
1309 compute_segment_center(&ConsoleObject->pos,seg);
1310 compute_center_point_on_side(&vp,seg,side);
1311 vm_vec_sub2(&vp,&ConsoleObject->pos);
1312 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1314 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1319 void game_draw_time_left()
1321 char temp_string[30];
1325 gr_set_curfont( GAME_FONT ); //GAME_FONT
1326 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1328 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1329 i=f2i(timevar-ThisLevelTime);
1332 sprintf( temp_string, "Time left: %d secs", i );
1335 gr_string(0, 32, temp_string );
1340 extern int Game_pause;
1343 void level_with_floor();
1345 void modex_clear_box(int x,int y,int w,int h)
1347 grs_canvas *temp_canv,*save_canv;
1349 save_canv = grd_curcanv;
1350 temp_canv = gr_create_canvas(w,h);
1351 gr_set_current_canvas(temp_canv);
1352 gr_clear_canvas(BM_XRGB(0,0,0));
1353 gr_set_current_canvas(save_canv);
1354 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1355 gr_free_canvas(temp_canv);
1359 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1361 // mac routine to drop contents of screen to a pict file using copybits
1362 // save a PICT to a file
1365 void SavePictScreen(int multiplayer)
1368 int parid, i, count;
1369 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1372 PicHandle pict_handle;
1373 static int multi_count = 0;
1374 StandardFileReply sf_reply;
1376 // dump the contents of the GameWindow into a picture using copybits
1378 pict_handle = OpenPicture(&GameWindow->portRect);
1379 if (pict_handle == NULL)
1382 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1385 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1386 if (!getcwd(cwd, FILENAME_MAX))
1388 // create the fsspec
1390 sprintf(filename, "screen%d", multi_count++);
1391 pfilename = c2pstr(filename);
1394 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1395 if (!sf_reply.sfGood)
1397 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1398 if (sf_reply.sfReplacing)
1400 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1404 // parid = GetAppDirId();
1405 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1410 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1415 // write the PICT file
1416 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1418 memset(buf, 0, sizeof(buf));
1420 if ( FSWrite(fd, &count, buf) )
1422 count = GetHandleSize((Handle)pict_handle);
1423 HLock((Handle)pict_handle);
1424 if ( FSWrite(fd, &count, *pict_handle) ) {
1430 HUnlock((Handle)pict_handle);
1431 DisposeHandle((Handle)pict_handle);
1439 //automap_flag is now unused, since we just check if the screen we're
1440 //writing to is modex
1441 //if called from automap, current canvas is set to visible screen
1443 void save_screen_shot(int automap_flag)
1445 #if defined(WINDOWS)
1446 mprintf((0, "Doing screen shot thing.\n"));
1447 win95_save_pcx_shot();
1449 #elif !defined(MACINTOSH)
1452 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1453 grs_font *save_font;
1454 static int savenum=0;
1455 static int stereo_savenum=0;
1456 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1457 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1465 // // Can't do screen shots in VR modes.
1466 // if ( VR_render_mode != VR_NONE )
1471 save_canv = grd_curcanv;
1473 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1477 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1478 gr_set_current_canvas(temp_canv);
1479 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1481 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1482 gr_set_current_canvas(temp_canv2);
1483 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1486 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1487 gr_set_current_canvas(temp_canv);
1488 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1491 gr_set_current_canvas(save_canv);
1493 if ( savenum > 99 ) savenum = 0;
1494 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1497 sprintf(savename,"left%02d.pcx",stereo_savenum);
1498 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1499 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1501 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1504 sprintf(savename,"screen%02d.pcx",savenum++);
1505 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1508 if (!automap_flag) //if from automap, curcanv is already visible canv
1509 gr_set_current_canvas(NULL);
1510 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1511 if (!automap_flag && modex_flag)
1512 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1514 save_font = grd_curcanv->cv_font;
1515 gr_set_curfont(GAME_FONT);
1516 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1517 gr_get_string_size(message,&w,&h,&aw);
1522 //I changed how these coords were calculated for the high-res automap. -MT
1523 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1524 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1525 x = (grd_curcanv->cv_w-w)/2;
1526 y = (grd_curcanv->cv_h-h)/2;
1529 modex_clear_box(x-2,y-2,w+4,h+4);
1530 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1532 gr_setcolor(gr_find_closest_color_current(0,0,0));
1533 gr_rect(x-2,y-2,x+w+2,y+h+2);
1534 gr_printf(x,y,message);
1535 gr_set_curfont(save_font);
1537 t1 = timer_get_fixed_seconds() + F1_0;
1539 gr_palette_read(pal); //get actual palette from the hardware
1540 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1542 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1544 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1546 gr_set_current_canvas(screen_canv);
1548 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1549 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1551 gr_free_canvas(temp_canv);
1553 gr_free_canvas(temp_canv2);
1555 gr_set_current_canvas(save_canv);
1561 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1562 grs_canvas *temp_canv, *save_canv;
1564 // Can't do screen shots in VR modes.
1565 if ( VR_render_mode != VR_NONE )
1570 save_canv = grd_curcanv;
1571 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1574 gr_set_current_canvas( temp_canv );
1575 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1576 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1580 if (Game_mode & GM_MULTI)
1587 gr_set_current_canvas(screen_canv);
1589 // if (!automap_flag)
1590 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1592 gr_free_canvas(temp_canv);
1594 gr_set_current_canvas(save_canv);
1603 void fly_init(object *obj)
1605 obj->control_type = CT_FLYING;
1606 obj->movement_type = MT_PHYSICS;
1608 vm_vec_zero(&obj->mtype.phys_info.velocity);
1609 vm_vec_zero(&obj->mtype.phys_info.thrust);
1610 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1611 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1614 //void morph_test(), morph_step();
1617 // ------------------------------------------------------------------------------------
1619 void test_anim_states();
1623 //put up the help message
1630 extern int been_in_editor;
1632 // ------------------------------------------------------------------------------------
1633 void do_cloak_stuff(void)
1636 for (i = 0; i < N_players; i++)
1637 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
1638 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
1639 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
1640 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
1641 if (i == Player_num) {
1642 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
1644 if (Game_mode & GM_MULTI)
1645 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
1646 maybe_drop_net_powerup(POW_CLOAK);
1647 multi_send_decloak(); // For demo recording
1649 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
1657 // ------------------------------------------------------------------------------------
1658 void do_invulnerable_stuff(void)
1660 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
1661 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
1662 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
1665 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
1667 if (Game_mode & GM_MULTI)
1669 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
1670 maybe_drop_net_powerup(POW_INVULNERABILITY);
1673 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
1680 ubyte Last_afterburner_state = 0;
1681 fix Last_afterburner_charge = 0;
1683 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
1684 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
1688 //@@// ------------------------------------------------------------------------------------
1689 //@@void afterburner_shake(void)
1693 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
1694 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
1696 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
1697 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
1698 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
1702 // ------------------------------------------------------------------------------------
1704 extern void multi_send_sound_function (char,char);
1707 void do_afterburner_stuff(void)
1709 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
1710 Afterburner_charge=0;
1712 if (Endlevel_sequence || Player_is_dead)
1714 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1716 multi_send_sound_function (0,0);
1720 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
1722 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
1723 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
1725 if (Game_mode & GM_MULTI)
1726 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
1729 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
1730 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
1732 if (Game_mode & GM_MULTI)
1733 multi_send_sound_function (0,0);
1735 mprintf((0,"Killing afterburner sound\n"));
1739 //@@if (Controls.afterburner_state && Afterburner_charge)
1740 //@@ afterburner_shake();
1742 Last_afterburner_state = Controls.afterburner_state;
1743 Last_afterburner_charge = Afterburner_charge;
1746 // -- // ------------------------------------------------------------------------------------
1747 // -- // if energy < F1_0/2, recharge up to F1_0/2
1748 // -- void recharge_energy_frame(void)
1750 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
1751 // -- Players[Player_num].energy += FrameTime/4;
1753 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
1754 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
1758 // Amount to diminish guns towards normal, per second.
1759 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
1761 extern fix Flash_effect;
1763 //adds to rgb values for palette flash
1764 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
1768 PaletteRedAdd += _dr;
1769 PaletteGreenAdd += _dg;
1770 PaletteBlueAdd += _db;
1772 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
1777 maxval = MAX_PALETTE_ADD;
1779 if (PaletteRedAdd > maxval)
1780 PaletteRedAdd = maxval;
1782 if (PaletteGreenAdd > maxval)
1783 PaletteGreenAdd = maxval;
1785 if (PaletteBlueAdd > maxval)
1786 PaletteBlueAdd = maxval;
1788 if (PaletteRedAdd < -maxval)
1789 PaletteRedAdd = -maxval;
1791 if (PaletteGreenAdd < -maxval)
1792 PaletteGreenAdd = -maxval;
1794 if (PaletteBlueAdd < -maxval)
1795 PaletteBlueAdd = -maxval;
1798 fix Time_flash_last_played;
1801 void game_palette_step_up( int r, int g, int b );
1802 // ------------------------------------------------------------------------------------
1803 // Diminish palette effects towards normal.
1804 void diminish_palette_towards_normal(void)
1808 // Diminish at DIMINISH_RATE units/second.
1809 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
1810 if (FrameTime < F1_0/DIMINISH_RATE) {
1811 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
1814 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
1815 if (dec_amount == 0)
1816 dec_amount++; // make sure we decrement by something
1822 // Part of hack system to force update of palette after exiting a menu.
1823 if (Time_flash_last_played) {
1825 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
1828 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
1829 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
1830 Time_flash_last_played = GameTime;
1833 Flash_effect -= FrameTime;
1834 if (Flash_effect < 0)
1837 if (force_do || (d_rand() > 4096 )) {
1838 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1839 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1841 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1848 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
1849 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
1851 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
1852 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
1854 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
1855 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
1857 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
1858 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1860 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1862 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
1865 int Redsave, Bluesave, Greensave;
1867 void palette_save(void)
1869 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
1872 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
1874 void game_palette_step_up( int r, int g, int b )
1876 if ( VR_use_reg_code ) {
1878 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
1881 gr_palette_step_up( r, g, b );
1885 void palette_restore(void)
1887 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
1888 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
1890 // Forces flash effect to fixup palette next frame.
1891 Time_flash_last_played = 0;
1894 extern void dead_player_frame(void);
1897 // --------------------------------------------------------------------------------------------------
1898 int allowed_to_fire_laser(void)
1900 if (Player_is_dead) {
1901 Global_missile_firing_count = 0;
1905 // Make sure enough time has elapsed to fire laser, but if it looks like it will
1906 // be a long while before laser can be fired, then there must be some mistake!
1907 if (Next_laser_fire_time > GameTime)
1908 if (Next_laser_fire_time < GameTime + 2*F1_0)
1914 fix Next_flare_fire_time = 0;
1915 #define FLARE_BIG_DELAY (F1_0*2)
1917 int allowed_to_fire_flare(void)
1919 if (Next_flare_fire_time > GameTime)
1920 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
1923 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
1924 Next_flare_fire_time = GameTime + F1_0/4;
1926 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
1931 int allowed_to_fire_missile(void)
1933 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
1934 // Make sure enough time has elapsed to fire missile, but if it looks like it will
1935 // be a long while before missile can be fired, then there must be some mistake!
1936 if (Next_missile_fire_time > GameTime)
1937 if (Next_missile_fire_time < GameTime + 5*F1_0)
1943 void full_palette_save(void)
1946 apply_modified_palette();
1947 reset_palette_add();
1948 gr_palette_load( gr_palette );
1951 extern int Death_sequence_aborted;
1952 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) );
1959 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
1962 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
1964 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
1965 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
1967 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
1968 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
1969 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
1970 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
1972 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
1973 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
1974 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
1975 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
1977 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
1979 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
1981 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
1983 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
1985 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
1987 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
1988 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
1989 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
1990 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
1991 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
1993 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
1995 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
1997 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
1998 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
1999 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
2000 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
2003 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
2004 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
2005 m[21].type = NM_TYPE_TEXT; m[21].text = "";
2006 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
2007 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
2011 full_palette_save();
2013 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
2018 //temp function until Matt cleans up game sequencing
2019 extern void temp_reset_stuff_on_level();
2021 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
2023 //deal with rear view - switch it on, or off, or whatever
2024 void check_rear_view()
2026 static int leave_mode;
2027 static fix entry_time;
2029 if ( Controls.rear_view_down_count ) { //key/button has gone down
2033 if (Cockpit_mode==CM_REAR_VIEW) {
2034 select_cockpit(Cockpit_mode_save);
2035 Cockpit_mode_save = -1;
2037 if (Newdemo_state == ND_STATE_RECORDING)
2038 newdemo_record_restore_rearview();
2042 if (Rear_view_leave_time <= 0)
2044 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
2048 leave_mode = 0; // means wait for another key
2049 entry_time = timer_get_fixed_seconds();
2051 if (Cockpit_mode == CM_FULL_COCKPIT) {
2052 Cockpit_mode_save = Cockpit_mode;
2053 select_cockpit(CM_REAR_VIEW);
2055 if (Newdemo_state == ND_STATE_RECORDING)
2056 newdemo_record_rearview();
2060 if (Controls.rear_view_down_state) {
2062 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
2067 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2069 if (leave_mode==1 && Rear_view) {
2071 if (Cockpit_mode==CM_REAR_VIEW) {
2072 select_cockpit(Cockpit_mode_save);
2073 Cockpit_mode_save = -1;
2075 if (Newdemo_state == ND_STATE_RECORDING)
2076 newdemo_record_restore_rearview();
2081 void reset_rear_view(void)
2084 if (Newdemo_state == ND_STATE_RECORDING)
2085 newdemo_record_restore_rearview();
2090 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2091 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2092 Cockpit_mode_save = CM_FULL_COCKPIT;
2093 select_cockpit(Cockpit_mode_save);
2094 Cockpit_mode_save = -1;
2100 int Config_menu_flag;
2104 int gr_renderstats = 0;
2105 // need to define "cheat" for renderstats
2106 int gr_badtexture = 0;
2107 // need to define "cheat" for badtexture
2109 int Cheats_enabled=0;
2111 extern int Laser_rapid_fire;
2112 extern void do_lunacy_on(), do_lunacy_off();
2114 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2115 extern char BounceCheat,HomingCheat,OldHomingState[20];
2116 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2117 extern int Buddy_dude_cheat;
2119 //turns off active cheats
2120 void turn_cheats_off()
2126 Weapon_info[i].homing_flag=OldHomingState[i];
2131 Interpolation_method=old_IntMethod;
2134 Buddy_dude_cheat = 0;
2138 Laser_rapid_fire = 0;
2139 Physics_cheat_flag = 0;
2141 Robots_kill_robots_cheat=0;
2142 Robot_firing_enabled = 1;
2145 //turns off all cheats & resets cheater flag
2146 void game_disable_cheats()
2154 // ----------------------------------------------------------------------------
2156 void game_setup(void)
2158 //@@int demo_playing=0;
2159 //@@int multi_game=0;
2161 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2162 do_lunacy_off(); // Restore true insane mode.
2165 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2166 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2167 Endlevel_sequence = 0;
2169 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2170 //@@ demo_playing = 1;
2171 //@@if ( Game_mode & GM_MULTI )
2172 //@@ multi_game = 1;
2174 set_screen_mode(SCREEN_GAME);
2175 reset_palette_add();
2177 set_warn_func(game_show_warning);
2181 //digi_init_sounds();
2183 //keyd_repeat = 0; // Don't allow repeat in game
2184 keyd_repeat = 1; // Do allow repeat in game
2186 #if !defined(WINDOWS) && !defined(MACINTOSH)
2187 //_MARK_("start of game");
2191 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2192 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2194 if (!check_obj_seg(ConsoleObject))
2195 move_player_2_segment(Cursegp,Curside);
2198 Viewer = ConsoleObject;
2199 fly_init(ConsoleObject);
2204 FrameTime = 0; //make first frame zero
2207 if (Current_level_num == 0) { //not a real level
2208 init_player_stats_game();
2215 game_flush_inputs();
2221 extern char IWasKicked;
2225 // ------------------------------------------------------------------------------------
2226 //this function is the game. called when game mode selected. runs until
2227 //editor mode or exit selected
2230 game_setup(); // Replaces what was here earlier.
2231 // Good for Windows Sake.
2234 ProfilerSetStatus(1);
2237 if ( setjmp(LeaveGame)==0 ) {
2243 Config_menu_flag = 0;
2245 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2247 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2248 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2251 player_shields = Players[Player_num].shields;
2256 DoMessageStuff(&msg); // Do Windows event handling.
2257 if (_RedrawScreen) {
2258 _RedrawScreen = FALSE;
2259 load_palette(Current_level_palette,1,1);
2260 gr_palette_load(gr_palette);
2265 ExtGameStatus=GAMESTAT_RUNNING;
2266 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2268 //if the player is taking damage, give up guided missile control
2269 if (Players[Player_num].shields != player_shields)
2270 release_guided_missile(Player_num);
2272 //see if redbook song needs to be restarted
2273 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2275 if (Config_menu_flag) {
2276 int double_save = Scanline_double;
2278 //WIN(mouse_set_mode(0));
2279 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2281 if (Scanline_double != double_save) init_cockpit();
2282 if (!(Game_mode&GM_MULTI)) palette_restore();
2283 //WIN(mouse_set_mode(1));
2287 int save_w=Game_window_w,save_h=Game_window_h;
2289 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2290 Game_window_w=save_w; Game_window_h=save_h;
2292 last_drawn_cockpit[0] = -1;
2293 last_drawn_cockpit[1] = -1;
2296 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2298 fmode = Function_mode;
2299 Function_mode = FMODE_GAME;
2301 apply_modified_palette();
2302 reset_palette_add();
2303 gr_palette_load( gr_palette );
2304 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2306 Function_mode = fmode;
2309 newdemo_stop_playback();
2310 Function_mode = FMODE_MENU;
2312 Function_mode = FMODE_GAME;
2316 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2322 fmode = Function_mode;
2323 Function_mode = FMODE_GAME;
2325 apply_modified_palette();
2326 reset_palette_add();
2327 gr_palette_load( gr_palette );
2328 ExtGameStatus=GAMESTAT_ABORT_GAME;
2329 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2331 Function_mode = fmode;
2333 Function_mode = FMODE_GAME;
2339 if (Function_mode != FMODE_GAME)
2340 longjmp(LeaveGame,0);
2343 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2344 longjmp(LeaveGame,0);
2350 ProfilerSetStatus(0);
2355 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2356 newdemo_stop_recording();
2362 if ( Newdemo_state == ND_STATE_PLAYBACK )
2363 newdemo_stop_playback();
2365 if (Cockpit_mode_save!=-1)
2367 Cockpit_mode=Cockpit_mode_save;
2368 Cockpit_mode_save=-1;
2371 if (Function_mode != FMODE_EDITOR)
2372 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2374 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2375 //@@ scores_maybe_add_player(Game_aborted);
2378 #if !defined(WINDOWS) && !defined(MACINTOSH)
2379 //_MARK_("end of game");
2382 clear_warn_func(game_show_warning); //don't use this func anymore
2384 game_disable_cheats();
2387 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2391 //called at the end of the program
2395 if (dd_VR_offscreen_buffer) {
2396 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2397 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2399 dd_VR_offscreen_buffer = NULL;
2400 VR_offscreen_buffer = NULL;
2403 if (VR_offscreen_buffer) {
2404 gr_free_canvas(VR_offscreen_buffer);
2405 VR_offscreen_buffer = NULL;
2409 close_gauge_canvases();
2411 restore_effect_bitmap_icons();
2413 #if !defined(MACINTOSH) && !defined(WINDOWS)
2414 if (Game_cockpit_copy_code) {
2415 d_free(Game_cockpit_copy_code);
2416 Game_cockpit_copy_code = NULL;
2419 if (Game_cockpit_copy_code)
2420 Game_cockpit_copy_code = 0;
2423 if (background_bitmap.bm_data)
2424 d_free(background_bitmap.bm_data);
2426 clear_warn_func(game_show_warning); //don't use this func anymore
2430 dd_grs_canvas * get_current_game_screen()
2432 return &dd_VR_screen_pages[VR_current_page];
2437 grs_canvas * get_current_game_screen()
2439 return &VR_screen_pages[VR_current_page];
2444 extern void kconfig_center_headset();
2448 void speedtest_frame(void);
2449 int Debug_slowdown=0;
2453 extern void player_follow_path(object *objp);
2454 extern void check_create_player_path(void);
2458 extern int Do_appearance_effect;
2460 object *Missile_viewer=NULL;
2462 int Missile_view_enabled = 1;
2464 int Marker_viewer_num[2]={-1,-1};
2465 int Coop_view_player[2]={-1,-1};
2466 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2468 //returns ptr to escort robot, or NULL
2469 object *find_escort()
2473 for (i=0; i<=Highest_object_index; i++)
2474 if (Objects[i].type == OBJ_ROBOT)
2475 if (Robot_info[Objects[i].id].companion)
2481 extern void process_super_mines_frame(void);
2482 extern void do_seismic_stuff(void);
2485 int Saving_movie_frames=0;
2486 int __Movie_frame_num=0;
2488 #define MAX_MOVIE_BUFFER_FRAMES 250
2489 #define MOVIE_FRAME_SIZE (320 * 200)
2491 ubyte *Movie_frame_buffer;
2492 int Movie_frame_counter;
2493 ubyte Movie_pal[768];
2494 char movie_path[50] = ".\\";
2496 grs_bitmap Movie_bm;
2498 void flush_movie_buffer()
2505 mprintf((0,"Flushing movie buffer..."));
2507 Movie_bm.bm_data = Movie_frame_buffer;
2509 for (f=0;f<Movie_frame_counter;f++) {
2510 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2511 __Movie_frame_num++;
2512 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2513 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2516 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2519 Movie_frame_counter=0;
2521 mprintf((0,"done \n"));
2526 void toggle_movie_saving()
2530 Saving_movie_frames = !Saving_movie_frames;
2532 if (Saving_movie_frames) {
2535 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2536 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2539 Saving_movie_frames = 0;
2543 while (isspace(movie_path[strlen(movie_path)-1]))
2544 movie_path[strlen(movie_path)-1] = 0;
2545 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2546 strcat(movie_path,"\\");
2549 if (!Movie_frame_buffer) {
2550 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2551 if (!Movie_frame_buffer) {
2553 Saving_movie_frames=0;
2556 Movie_frame_counter=0;
2558 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2559 Movie_bm.bm_w = 320;
2560 Movie_bm.bm_h = 200;
2561 Movie_bm.bm_type = BM_LINEAR;
2562 Movie_bm.bm_flags = 0;
2563 Movie_bm.bm_rowsize = 320;
2564 Movie_bm.bm_handle = 0;
2566 gr_palette_read(Movie_pal); //get actual palette from the hardware
2568 if (Newdemo_state == ND_STATE_PLAYBACK)
2569 Newdemo_do_interpolate = 0;
2573 flush_movie_buffer();
2575 if (Newdemo_state == ND_STATE_PLAYBACK)
2576 Newdemo_do_interpolate = 1;
2581 void save_movie_frame()
2583 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2585 Movie_frame_counter++;
2587 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2588 flush_movie_buffer();
2594 extern int Level_shake_duration;
2596 //if water or fire level, make occasional sound
2597 void do_ambient_sounds()
2599 int has_water,has_lava;
2602 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2603 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2605 if (has_lava) { //has lava
2606 sound = SOUND_AMBIENT_LAVA;
2607 if (has_water && (d_rand() & 1)) //both, pick one
2608 sound = SOUND_AMBIENT_WATER;
2610 else if (has_water) //just water
2611 sound = SOUND_AMBIENT_WATER;
2615 if (((d_rand() << 3) < FrameTime)) { //play the sound
2616 fix volume = d_rand() + f1_0/2;
2617 digi_play_sample(sound,volume);
2621 // -- extern void lightning_frame(void);
2623 void game_render_frame();
2624 extern void omega_charge_frame(void);
2626 extern time_t t_current_time, t_saved_time;
2628 void flicker_lights();
2630 void GameLoop(int RenderFlag, int ReadControlsFlag )
2633 // Used to slow down frame rate for testing things.
2634 // RenderFlag = 1; // DEBUG
2635 if (Debug_slowdown) {
2638 for (h=0; h<Debug_slowdown; h++)
2639 for (i=0; i<1000; i++)
2646 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
2648 if (desc_id_exit_num) { // are we supposed to be checking
2649 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
2650 char time_str[32], time_str2[32];
2652 _ctime(&t_saved_time, time_str);
2653 _ctime(&t_current_time, time_str2);
2655 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
2656 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
2663 if (FindArg("-invulnerability"))
2664 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2668 update_player_stats();
2669 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
2670 do_afterburner_stuff();
2672 do_invulnerable_stuff();
2673 remove_obsolete_stuck_objects();
2675 do_final_boss_frame();
2676 // -- lightning_frame();
2677 // -- recharge_energy_frame();
2679 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
2680 static int turned_off=0;
2681 Players[Player_num].energy -= (FrameTime*3/8);
2682 if (Players[Player_num].energy < i2f(10)) {
2684 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2687 if (Game_mode & GM_MULTI)
2688 multi_send_flags(Player_num);
2695 if (Players[Player_num].energy <= 0) {
2696 Players[Player_num].energy = 0;
2697 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
2699 if (Game_mode & GM_MULTI)
2700 multi_send_flags(Player_num);
2707 check_create_player_path();
2708 player_follow_path(ConsoleObject);
2712 if (Game_mode & GM_MULTI)
2715 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
2716 multi_check_for_killgoal_winner();
2722 if (force_cockpit_redraw) { //screen need redrawing?
2724 force_cockpit_redraw=0;
2726 game_render_frame();
2727 //show_extra_views(); //missile view, buddy bot, etc.
2730 if (Saving_movie_frames)
2737 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
2741 dead_player_frame();
2742 if (Newdemo_state != ND_STATE_PLAYBACK)
2743 do_controlcen_dead_frame();
2745 process_super_mines_frame();
2747 do_ambient_sounds();
2754 if (ReadControlsFlag)
2757 memset(&Controls, 0, sizeof(Controls));
2759 GameTime += FrameTime;
2761 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
2762 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
2764 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
2765 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
2766 mprintf((0,"GameTime reset to 0\n"));
2770 if (FindArg("-checktime") != 0)
2771 if (GameTime >= i2f(600)) //wrap after 10 minutes
2772 GameTime = FrameTime;
2776 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
2777 ThisLevelTime +=FrameTime;
2782 if (Endlevel_sequence) {
2783 do_endlevel_frame();
2784 powerup_grab_cheat_all();
2785 do_special_effects();
2786 return; //skip everything else
2789 if (Newdemo_state != ND_STATE_PLAYBACK)
2790 do_exploding_wall_frame();
2791 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
2792 do_special_effects();
2793 wall_frame_process();
2794 triggers_frame_process();
2798 if (Control_center_destroyed) {
2799 if (Newdemo_state==ND_STATE_RECORDING )
2800 newdemo_record_control_center_destroyed();
2805 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
2806 newdemo_playback_one_frame();
2807 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
2808 longjmp( LeaveGame, 0 ); // Go back to menu
2811 { // Note the link to above!
2813 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
2816 powerup_grab_cheat_all();
2818 if (Endlevel_sequence) //might have been started during move
2821 fuelcen_update_all();
2825 if (allowed_to_fire_laser())
2826 FireLaser(); // Fire Laser!
2828 if (Auto_fire_fusion_cannon_time) {
2829 if (Primary_weapon != FUSION_INDEX)
2830 Auto_fire_fusion_cannon_time = 0;
2831 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
2832 Auto_fire_fusion_cannon_time = 0;
2833 Global_laser_firing_count = 1;
2835 vms_vector rand_vec;
2838 Global_laser_firing_count = 0;
2840 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
2841 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2842 make_random_vector(&rand_vec);
2844 bump_amount = F1_0*4;
2846 if (Fusion_charge > F1_0*2)
2847 bump_amount = Fusion_charge*4;
2849 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2853 if (Global_laser_firing_count) {
2854 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
2855 // if (Fusion_charge > F1_0*2)
2856 // Fusion_charge = F1_0*2;
2857 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
2860 if (Global_laser_firing_count < 0)
2861 Global_laser_firing_count = 0;
2864 if (Do_appearance_effect) {
2865 create_player_appearance_effect(ConsoleObject);
2866 Do_appearance_effect = 0;
2868 if ((Game_mode & GM_MULTI) && Netgame.invul)
2870 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
2871 Players[Player_num].invulnerable_time = GameTime-i2f(27);
2878 omega_charge_frame();
2882 //!!hoard_light_pulse(); //do cool hoard light pulsing
2886 //!!extern int Goal_blue_segnum,Goal_red_segnum;
2887 //!!extern int Hoard_goal_eclip;
2889 //!!//do cool pulsing lights in hoard goals
2890 //!!hoard_light_pulse()
2892 //!! if (Game_mode & GM_HOARD) {
2896 //!! frame = Effects[Hoard_goal_eclip].frame_count;
2900 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
2903 //!! light = abs(frame - 5) * f1_0 / 5;
2905 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
2910 ubyte Slide_segs[MAX_SEGMENTS];
2911 int Slide_segs_computed;
2913 void compute_slide_segs(void)
2915 int segnum, sidenum;
2917 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2918 Slide_segs[segnum] = 0;
2919 for (sidenum=0;sidenum<6;sidenum++) {
2920 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2921 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
2922 Slide_segs[segnum] |= 1 << sidenum;
2926 Slide_segs_computed = 1;
2929 // -----------------------------------------------------------------------------
2930 void slide_textures(void)
2932 int segnum,sidenum,i;
2934 if (!Slide_segs_computed)
2935 compute_slide_segs();
2937 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
2938 if (Slide_segs[segnum]) {
2939 for (sidenum=0;sidenum<6;sidenum++) {
2940 if (Slide_segs[segnum] & (1 << sidenum)) {
2941 int tmn = Segments[segnum].sides[sidenum].tmap_num;
2942 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
2944 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
2945 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
2946 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
2949 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
2951 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
2954 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
2956 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
2959 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
2961 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
2964 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
2974 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
2976 int Num_flickering_lights=0;
2978 void flicker_lights()
2981 flickering_light *f;
2983 f = Flickering_lights;
2985 for (l=0;l<Num_flickering_lights;l++,f++) {
2986 segment *segp = &Segments[f->segnum];
2988 //make sure this is actually a light
2989 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
2991 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
2994 if (f->timer == 0x80000000) //disabled
2997 if ((f->timer -= FrameTime) < 0) {
2999 while (f->timer < 0)
3000 f->timer += f->delay;
3002 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
3005 add_light(f->segnum,f->sidenum);
3007 subtract_light(f->segnum,f->sidenum);
3012 //returns ptr to flickering light structure, or NULL if can't find
3013 flickering_light *find_flicker(int segnum,int sidenum)
3016 flickering_light *f;
3018 //see if there's already an entry for this seg/side
3020 f = Flickering_lights;
3022 for (l=0;l<Num_flickering_lights;l++,f++)
3023 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3029 //turn flickering off (because light has been turned off)
3030 void disable_flicker(int segnum,int sidenum)
3032 flickering_light *f;
3034 if ((f=find_flicker(segnum,sidenum)) != NULL)
3035 f->timer = 0x80000000;
3038 //turn flickering off (because light has been turned on)
3039 void enable_flicker(int segnum,int sidenum)
3041 flickering_light *f;
3043 if ((f=find_flicker(segnum,sidenum)) != NULL)
3050 //returns 1 if ok, 0 if error
3051 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
3054 flickering_light *f;
3056 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
3058 //see if there's already an entry for this seg/side
3060 f = Flickering_lights;
3062 for (l=0;l<Num_flickering_lights;l++,f++)
3063 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3066 if (mask==0) { //clearing entry
3067 if (l == Num_flickering_lights)
3071 for (i=l;i<Num_flickering_lights-1;i++)
3072 Flickering_lights[i] = Flickering_lights[i+1];
3073 Num_flickering_lights--;
3078 if (l == Num_flickering_lights) {
3079 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3082 Num_flickering_lights++;
3086 f->sidenum = sidenum;
3087 f->delay = f->timer = delay;
3095 // -----------------------------------------------------------------------------
3096 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3101 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3103 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3104 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3105 Global_laser_firing_count = 0;
3107 if (Fusion_charge == 0)
3108 Players[Player_num].energy -= F1_0*2;
3110 Fusion_charge += FrameTime;
3111 Players[Player_num].energy -= FrameTime;
3113 if (Players[Player_num].energy <= 0) {
3114 Players[Player_num].energy = 0;
3115 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3117 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3118 // Fire the fusion cannon at this time in the future.
3120 if (Fusion_charge < F1_0*2)
3121 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3123 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3125 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3126 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3128 if (Fusion_next_sound_time < GameTime) {
3129 if (Fusion_charge > F1_0*2) {
3130 digi_play_sample( 11, F1_0 );
3131 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3133 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3134 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3136 if (Game_mode & GM_MULTI)
3137 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3140 Fusion_last_sound_time = GameTime;
3141 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3149 // -------------------------------------------------------------------------------------------------------
3150 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3151 // This could easily be made difficulty level dependent.
3152 void powerup_grab_cheat(object *player, int objnum)
3158 Assert(Objects[objnum].type == OBJ_POWERUP);
3160 powerup_size = Objects[objnum].size;
3161 player_size = player->size;
3163 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3165 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3166 vms_vector collision_point;
3168 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3169 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3173 // -------------------------------------------------------------------------------------------------------
3174 // Make it easier to pick up powerups.
3175 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3176 // from player to powerup and player's forward vector.
3177 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3178 // way before the player gets there.
3179 void powerup_grab_cheat_all(void)
3184 segp = &Segments[ConsoleObject->segnum];
3185 objnum = segp->objects;
3187 while (objnum != -1) {
3188 if (Objects[objnum].type == OBJ_POWERUP)
3189 powerup_grab_cheat(ConsoleObject, objnum);
3190 objnum = Objects[objnum].next;
3195 int Last_level_path_created = -1;
3197 #ifdef SHOW_EXIT_PATH
3199 // ------------------------------------------------------------------------------------------------------------------
3200 // Create path for player from current segment to goal segment.
3201 // Return true if path created, else return false.
3202 int mark_player_path_to_segment(int segnum)
3205 object *objp = ConsoleObject;
3206 short player_path_length=0;
3207 int player_hide_index=-1;
3209 if (Last_level_path_created == Current_level_num) {
3213 Last_level_path_created = Current_level_num;
3215 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3216 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3220 player_hide_index = Point_segs_free_ptr - Point_segs;
3221 Point_segs_free_ptr += player_path_length;
3223 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3224 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3225 ai_reset_all_paths();
3229 for (i=1; i<player_path_length; i++) {
3231 vms_vector seg_center;
3234 segnum = Point_segs[player_hide_index+i].segnum;
3235 mprintf((0, "%3i ", segnum));
3236 seg_center = Point_segs[player_hide_index+i].point;
3238 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3240 Int3(); // Unable to drop energy powerup for path
3244 obj = &Objects[objnum];
3245 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3246 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3247 obj->rtype.vclip_info.framenum = 0;
3248 obj->lifeleft = F1_0*100 + d_rand() * 4;
3255 // Return true if it happened, else return false.
3256 int create_special_path(void)
3260 // ---------- Find exit doors ----------
3261 for (i=0; i<=Highest_segment_index; i++)
3262 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3263 if (Segments[i].children[j] == -2) {
3264 mprintf((0, "Exit at segment %i\n", i));
3265 return mark_player_path_to_segment(i);
3275 int Max_obj_count_mike = 0;
3277 // Shows current number of used objects.
3278 void show_free_objects(void)
3280 if (!(FrameCount & 8)) {
3284 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3286 for (i=0; i<=Highest_object_index; i++)
3287 if (Objects[i].type != OBJ_NONE)
3290 mprintf((0, "%3i", count));
3292 if (count > Max_obj_count_mike) {
3293 Max_obj_count_mike = count;
3294 mprintf((0, " ***"));
3305 void game_win_init_cockpit_mask(int sram)
3307 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3308 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3311 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3312 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3313 // we can just flip it, saving a blt.
3316 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3317 // The offscreen buffer will be created. We will just blt this
3318 // to the screen (which may be blted to the primary surface)
3319 if ( grd_curscreen->sc_h < 200 ) {
3320 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3321 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3323 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3324 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3325 dd_VR_offscreen_buffer->sram = 1;
3329 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3330 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3332 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3333 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3334 dd_VR_offscreen_buffer->sram = 1;
3339 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3340 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3341 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3342 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3344 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3347 //@@void game_win_init_cockpit_mask()
3349 //@@ char title_pal[768];
3350 //@@ dd_grs_canvas ccanv;
3352 //@@ LPDIRECTDRAWSURFACE dds;
3354 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3355 //@@ Assert(dds != NULL);
3357 //@@ _lpDDSMask = dds;
3358 //@@ ccanv.lpdds = dds;
3359 //@@ dd_gr_reinit_canvas(&ccanv);
3361 //@@ dd_gr_set_current_canvas(&ccanv);
3362 //@@ DDGRLOCK(dd_grd_curcanv)
3364 //@@ if (W95DisplayMode == SM95_640x480x8) {
3365 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3366 //@@ grd_curcanv->cv_bitmap.bm_type,
3370 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3371 //@@ grd_curcanv->cv_bitmap.bm_type,
3375 //@@ DDGRUNLOCK(dd_grd_curcanv);
3377 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3378 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);
3384 * reads a flickering_light structure from a CFILE
3386 void flickering_light_read(flickering_light *fl, CFILE *fp)
3388 fl->segnum = cfile_read_short(fp);
3389 fl->sidenum = cfile_read_short(fp);
3390 fl->mask = cfile_read_int(fp);
3391 fl->timer = cfile_read_fix(fp);
3392 fl->delay = cfile_read_fix(fp);