1 /* $Id: game.c,v 1.30 2004-05-22 07:15:04 btb 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
20 * Revision 1.1 1995/12/05 16:01:09 allender
23 * Revision 1.38 1995/11/13 13:02:35 allender
24 * put up HUD message when player starts tournament
26 * Revision 1.37 1995/11/13 09:21:05 allender
27 * ved and shorted tournament mode messages
29 * Revision 1.36 1995/11/09 17:27:00 allender
30 * took out cheats during demo playback
32 * Revision 1.35 1995/11/07 17:05:41 allender
33 * move registered cheats
35 * Revision 1.34 1995/11/03 12:55:45 allender
38 * Revision 1.33 1995/10/29 20:15:00 allender
39 * took out frame rate cheat. Pause for at least a second because
42 * Revision 1.32 1995/10/26 14:11:26 allender
43 * fix up message box stuff to align correctly
45 * Revision 1.31 1995/10/24 18:09:41 allender
46 * ixed cockpit weirdness -- don't update cockpit when do_appl_quit
47 * is called -- screen saved in mevent.c
49 * Revision 1.30 1995/10/21 23:39:10 allender
50 * ruise marking indicator
52 * Revision 1.29 1995/10/21 22:52:27 allender
53 * bald guy cheat -- print screen stuff
55 * Revision 1.28 1995/10/20 00:54:28 allender
56 * new help menus and redbook checking in outer game loop
58 * Revision 1.27 1995/10/17 15:34:19 allender
59 * pixel double is now default mode
61 * Revision 1.26 1995/10/12 17:34:44 allender
62 * bigger message box -- command key equivs for function keys
64 * Revision 1.25 1995/10/11 12:17:14 allender
65 * removed event loop processing
67 * Revision 1.24 1995/10/11 00:58:47 allender
68 * removed debugging code
70 * Revision 1.23 1995/10/10 11:50:32 allender
71 * fixed boxed message to align on 8 byte boundry,
74 * Revision 1.22 1995/09/24 10:51:26 allender
75 * cannot go to finder in network..added cmd-q for quit
77 * Revision 1.21 1995/09/22 15:05:18 allender
78 * *more* hud and font type stuff (messages)
80 * Revision 1.20 1995/09/22 14:39:57 allender
81 * ved framerate counter up
83 * Revision 1.19 1995/09/18 17:01:28 allender
84 * start of compatibility stuff
86 * Revision 1.18 1995/09/15 15:53:13 allender
87 * better handling of PICT screen shots
89 * Revision 1.17 1995/09/14 15:27:41 allender
90 * fixed function type on message_box routiens
92 * Revision 1.16 1995/09/13 11:37:47 allender
93 * put in call to dump PICT file instead of PCX
95 * Revision 1.15 1995/09/08 17:13:28 allender
96 * put back in ibitblt.h and start of PICT picture dump
98 * Revision 1.14 1995/09/07 10:20:58 allender
99 * make cockpit mode default
101 * Revision 1.13 1995/09/07 10:17:34 allender
102 * added command key equivalents for function keys
104 * Revision 1.12 1995/09/04 11:36:47 allender
105 * fixed pixel double mode to have correct number of rendered
108 * Revision 1.11 1995/09/01 15:47:07 allender
109 * cap frame rate at 60 fps
111 * Revision 1.10 1995/08/26 16:25:59 allender
112 * whole buncha' stuff!!!!
114 * Revision 1.9 1995/08/01 16:04:47 allender
115 * put in ctrl_esc sequence to go to menubar
117 * Revision 1.8 1995/07/28 14:15:11 allender
118 * added FRAME cheat to display frame rate
120 * Revision 1.7 1995/07/17 08:54:19 allender
121 * *** empty log message ***
123 * Revision 1.6 1995/07/12 12:54:06 allender
124 * removed some debug keys
126 * Revision 1.5 1995/07/05 16:44:35 allender
127 * changed some debug keys
129 * Revision 1.4 1995/06/23 10:24:57 allender
130 * added scanline doubling routine
132 * Revision 1.3 1995/06/13 13:08:26 allender
133 * added special debug key to move window into upper left corner.
134 * also added debug key to put game in 640x480 mode
136 * Revision 1.2 1995/06/12 11:10:31 allender
137 * added DEL_SHIFT_M to move window to corner of screen
139 * Revision 1.1 1995/05/16 15:25:08 allender
142 * Revision 2.36 1996/01/05 16:52:05 john
145 * Revision 2.35 1995/10/09 22:17:10 john
146 * Took out the page flipping in set_screen_mode, which shouldn't
147 * be there. This was hosing the modex stuff.
149 * Revision 2.34 1995/10/09 19:46:34 john
150 * Fixed bug with modex paging with lcdbios.
152 * Revision 2.33 1995/10/08 11:46:09 john
153 * Fixed bug with 2d offset in interlaced mode in low res.
154 * Made LCDBIOS with pageflipping using VESA set start
155 * Address function. X=CRTC offset, Y=0.
157 * Revision 2.32 1995/10/07 13:20:51 john
158 * Added new modes for LCDBIOS, also added support for -JoyNice,
159 * and added Shift+F1-F4 to controls various stereoscopic params.
161 * Revision 2.31 1995/05/31 14:34:43 unknown
164 * Revision 2.30 1995/05/08 11:23:45 john
165 * Made 3dmax work like Kasan wants it to.
167 * Revision 2.29 1995/04/06 13:47:39 yuan
168 * Restored rear view to original.
170 * Revision 2.28 1995/04/06 12:13:07 john
171 * Fixed some bugs with 3dmax.
173 * Revision 2.27 1995/04/05 13:18:18 mike
174 * decrease energy usage on fusion cannon
176 * Revision 2.26 1995/03/30 16:36:32 mike
179 * Revision 2.25 1995/03/27 16:45:26 john
180 * Fixed some cheat bugs. Added astral cheat.
182 * Revision 2.24 1995/03/27 15:37:11 mike
183 * boost fusion cannon for non-multiplayer modes.
185 * Revision 2.23 1995/03/24 17:48:04 john
186 * Fixed bug with menus and 320x100.
188 * Revision 2.22 1995/03/24 15:34:02 mike
191 * Revision 2.21 1995/03/24 13:11:39 john
192 * Added save game during briefing screens.
194 * Revision 2.20 1995/03/21 14:40:50 john
195 * Ifdef'd out the NETWORK code.
197 * Revision 2.19 1995/03/16 22:07:16 john
198 * Made so only for screen can be used for anything other
201 * Revision 2.18 1995/03/16 21:45:35 john
202 * Made all paged modes have incompatible menus!
204 * Revision 2.17 1995/03/16 18:30:35 john
205 * Made wider than 320 screens not have
208 * Revision 2.16 1995/03/16 10:53:34 john
209 * Move VFX center to Shift+Z instead of Enter because
210 * it conflicted with toggling HUD on/off.
212 * Revision 2.15 1995/03/16 10:18:33 john
213 * Fixed bug with VFX mode not working. also made warning
214 * when it can't set VESA mode.
216 * Revision 2.14 1995/03/14 16:22:39 john
217 * Added cdrom alternate directory stuff.
219 * Revision 2.13 1995/03/14 12:14:17 john
220 * Made VR helmets have 4 resolutions to choose from.
222 * Revision 2.12 1995/03/10 13:47:33 john
223 * Added head tracking sensitivity.
225 * Revision 2.11 1995/03/10 13:13:47 john
226 * Added code to show T-xx on iglasses.
228 * Revision 2.10 1995/03/09 18:07:29 john
229 * Fixed bug with iglasses tracking not "centering" right.
230 * Made VFX have bright headlight lighting.
232 * Revision 2.9 1995/03/09 11:48:02 john
233 * Added HUD for VR helmets.
235 * Revision 2.8 1995/03/07 15:12:53 john
236 * Fixed VFX,3dmax support.
238 * Revision 2.7 1995/03/07 11:35:03 john
239 * Fixed bug with cockpit in rear view.
241 * Revision 2.6 1995/03/06 18:40:17 john
242 * Added some ifdef EDITOR stuff.
244 * Revision 2.5 1995/03/06 18:31:21 john
245 * Fixed bug with nmenu popping up on editor screen.
247 * Revision 2.4 1995/03/06 17:28:33 john
248 * Fixed but with cockpit toggling wrong.
250 * Revision 2.3 1995/03/06 16:08:10 mike
251 * Fix compile errors if building without editor.
253 * Revision 2.2 1995/03/06 15:24:10 john
254 * New screen techniques.
256 * Revision 2.1 1995/02/27 13:41:03 john
257 * Removed floating point from frame rate calculations.
259 * Revision 2.0 1995/02/27 11:31:54 john
260 * New version 2.0, which has no anonymous unions, builds with
261 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
263 * Revision 1.770 1995/02/22 12:45:15 allender
264 * remove anonymous unions from object structure
266 * Revision 1.769 1995/02/15 10:06:25 allender
267 * make pause pause game during demo playback
269 * Revision 1.768 1995/02/13 20:35:11 john
272 * Revision 1.767 1995/02/13 19:40:29 allender
273 * added place to demo record restoration from rear view in place that
276 * Revision 1.766 1995/02/13 10:29:27 john
277 * Fixed bug with cheats not restoreing across save games.
279 * Revision 1.765 1995/02/11 22:54:33 john
280 * Made loading for pig not show up for demos.
282 * Revision 1.764 1995/02/11 17:30:08 allender
283 * ifndef NDEBUG around strip frame stuff
285 * Revision 1.763 1995/02/11 17:13:01 rob
286 * Took out modem.c code fille stuff.
288 * Revision 1.762 1995/02/11 16:36:47 allender
289 * debug key to strip frames from end of demo
291 * Revision 1.761 1995/02/11 14:29:16 john
292 * Turned off cheats when going into game.
294 * Revision 1.760 1995/02/11 13:46:54 mike
297 * Revision 1.759 1995/02/11 12:36:09 matt
300 * Revision 1.758 1995/02/11 12:27:04 mike
301 * fix path-to-exit cheat.
303 * Revision 1.757 1995/02/11 01:56:24 mike
304 * robots don't fire cheat.
306 * Revision 1.756 1995/02/10 16:38:40 mike
307 * illuminate path to exit cheat.
309 * Revision 1.755 1995/02/10 16:19:40 mike
310 * new show-path-to-exit system, still buggy, compiled out.
312 * Revision 1.754 1995/02/10 15:54:46 matt
315 * Revision 1.753 1995/02/09 12:25:42 matt
316 * Made mem_fill() test routines not be called if RELEASE
318 * Revision 1.752 1995/02/09 08:49:32 mike
319 * change fill opcode value to 0xcc, int 3 value.
322 * Revision 1.751 1995/02/09 02:59:26 mike
323 * check code for 00066xxx bugs.
325 * Revision 1.750 1995/02/08 17:10:02 mike
326 * add, but don't call, debug code.
328 * Revision 1.749 1995/02/07 11:07:27 john
329 * Added hooks for confirm on game state restore.
331 * Revision 1.748 1995/02/06 15:52:45 mike
332 * add mini megawow powerup for giving reasonable weapons.
334 * Revision 1.747 1995/02/06 12:53:35 allender
335 * force endlevel_sequence to 0 to fix weird bug
337 * Revision 1.746 1995/02/04 10:03:30 mike
340 * Revision 1.745 1995/02/02 15:57:52 john
341 * Added turbo mode cheat.
343 * Revision 1.744 1995/02/02 14:43:39 john
344 * Uppped frametime limit to 150 Hz.
346 * Revision 1.743 1995/02/02 13:37:16 mike
347 * move T-?? message down in certain modes.
349 * Revision 1.742 1995/02/02 01:26:59 john
350 * Took out no key repeating.
352 * Revision 1.741 1995/01/29 21:36:44 mike
353 * make fusion cannon not make pitching slow.
355 * Revision 1.740 1995/01/28 15:57:57 john
356 * Made joystick calibration be only when wrong detected in
357 * menu or joystick axis changed.
359 * Revision 1.739 1995/01/28 15:21:03 yuan
360 * Added X-tra life cheat.
362 * Revision 1.738 1995/01/27 14:08:31 rob
365 * Revision 1.737 1995/01/27 14:04:59 rob
366 * Its not my fault, Mark told me to do it!
368 * Revision 1.736 1995/01/27 13:12:18 rob
369 * Added charging noises to play across net.
371 * Revision 1.735 1995/01/27 11:48:28 allender
372 * check for newdemo_state to be paused and stop recording. We might be
375 * Revision 1.734 1995/01/26 22:11:41 mike
376 * Purple chromo-blaster (ie, fusion cannon) spruce up (chromification)
378 * Revision 1.733 1995/01/26 17:03:04 mike
379 * make fusion cannon have more chrome, make fusion, mega rock you!
381 * Revision 1.732 1995/01/25 14:37:25 john
382 * Made joystick only prompt for calibration once...
384 * Revision 1.731 1995/01/24 15:49:14 john
385 * Made typeing in long net messages wrap on
386 * small screen sizes.
388 * Revision 1.730 1995/01/24 15:23:42 mike
389 * network message tweaking.
391 * Revision 1.729 1995/01/24 12:00:47 john
392 * Fixed bug with defing macro passing keys to controls.
394 * Revision 1.728 1995/01/24 11:53:35 john
395 * Added better macro defining code.
397 * Revision 1.727 1995/01/23 22:17:15 john
398 * Fixed bug with not clearing key buffer when leaving f8.
400 * Revision 1.726 1995/01/23 22:07:09 john
401 * Added flush to game inputs during F8.
410 char game_rcsid[] = "$Id: game.c,v 1.30 2004-05-22 07:15:04 btb Exp $";
426 #include <StandardFile.h>
427 #include <Quickdraw.h>
433 #include "ogl_init.h"
438 #include "pa_enabl.h" //$$POLY_ACC
454 #include "textures.h"
470 #include "lighting.h"
480 #include "fireball.h"
485 #include "gamefont.h"
486 #include "endlevel.h"
491 #include "controls.h"
495 #if defined(POLY_ACC)
496 #include "poly_acc.h"
501 #include "cntrlcen.h"
505 #include "multibot.h"
508 #include "playsave.h"
512 int VGA_current_mode;
515 #include <profiler.h>
518 //#define TEST_TIMER 1 //if this is set, do checking on timer
520 #define SHOW_EXIT_PATH 1
523 #include "editor/editor.h"
528 #if __WATCOMC__ < 1000
529 #include <wsample.h> //should come after inferno.h to get mark setting
534 extern void ReadControls(void); // located in gamecntl.c
535 extern int Current_display_mode;
536 extern void do_final_boss_frame(void);
538 int Speedtest_on = 0;
541 int Mark_count = 0; // number of debugging marks set
542 int Speedtest_start_time;
543 int Speedtest_segnum;
544 int Speedtest_sidenum;
545 int Speedtest_frame_start;
546 int Speedtest_count=0; // number of times to do the debug test.
549 static fix last_timer_value=0;
552 #if defined(TIMER_TEST) && !defined(NDEBUG)
553 fix _timer_value,actual_last_timer_value,_last_frametime;
554 int stop_count,start_count;
555 int time_stopped,time_started;
559 ubyte * Game_cockpit_copy_code = NULL;
561 ubyte Game_cockpit_copy_code = 0;
562 ubyte Scanline_double = 1;
565 int VR_screen_mode = 0;
567 ubyte VR_screen_flags = 0; //see values in screens.h
568 ubyte VR_current_page = 0;
569 fix VR_eye_width = F1_0;
570 int VR_render_mode = VR_NONE;
571 int VR_low_res = 3; // Default to low res
573 int VR_sensitivity = 1; // 0 - 2
576 int VR_eye_offset = 0;
577 int VR_eye_switch = 0;
578 int VR_eye_offset_changed = 0;
579 int VR_use_reg_code = 0;
581 grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
582 grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
583 grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
584 grs_canvas VR_screen_pages[2]; // Two pages of VRAM if paging is available
585 grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
588 //@@ LPDIRECTDRAWSURFACE _lpDDSMask = NULL;
589 dd_grs_canvas *dd_VR_offscreen_buffer = NULL;
590 dd_grs_canvas dd_VR_screen_pages[2];
591 dd_grs_canvas dd_VR_render_buffer[2];
592 dd_grs_canvas dd_VR_render_sub_buffer[2];
594 void game_win_init_cockpit_mask(int sram);
597 //do menus work in 640x480 or 320x200?
598 //PC version sets this in main(). Mac versios is always high-res, so set to 1 here
599 int MenuHiresAvailable = 1; //can we do highres menus?
600 int MenuHires = 1; //are we currently in highres menus?
602 int Debug_pause=0; //John's debugging pause system
604 int Cockpit_mode=CM_FULL_COCKPIT; //set game.h for values
606 int Cockpit_mode_save=-1; //set while in letterbox or rear view, or -1
607 int force_cockpit_redraw=0;
609 cvar_t r_framerate = {"r_framerate","0"};
611 int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
613 // Toggle_var points at a variable which gets !ed on ctrl-alt-T press.
615 int *Toggle_var = &Dummy_var;
618 //flag for whether initial fade-in has been done
622 #ifndef NDEBUG //these only exist if debugging
624 int Game_double_buffer = 1; //double buffer by default
625 fix fixed_frametime=0; //if non-zero, set frametime to this
629 int Game_suspended=0; //if non-zero, nothing moves but player
632 fix Auto_fire_fusion_cannon_time = 0;
633 fix Fusion_charge = 0;
634 fix Fusion_next_sound_time = 0;
635 fix Fusion_last_sound_time = 0;
638 int Game_turbo_mode = 0;
640 int Game_mode = GM_GAME_OVER;
642 int Global_laser_firing_count = 0;
643 int Global_missile_firing_count = 0;
645 grs_bitmap background_bitmap;
649 #define BACKGROUND_NAME "statback.pcx"
651 // Function prototypes for GAME.C exclusively.
653 void GameLoop(int RenderFlag, int ReadControlsFlag);
654 void FireLaser(void);
655 void slide_textures(void);
656 void powerup_grab_cheat_all(void);
659 extern void multi_check_for_killgoal_winner();
660 extern void RestoreGameSurfaces();
664 void grow_window(void);
665 void shrink_window(void);
669 void fill_background();
672 void show_framerate(void);
673 void ftoa(char *string, fix f);
676 extern ubyte DefiningMarkerMessage;
677 extern char Marker_input[];
679 // ==============================================================================================
681 extern char john_head_on;
683 void load_background_bitmap()
688 if (background_bitmap.bm_data)
689 d_free(background_bitmap.bm_data);
691 background_bitmap.bm_data=NULL;
692 pcx_error = pcx_read_bitmap(john_head_on?"johnhead.pcx":BACKGROUND_NAME,&background_bitmap,BM_LINEAR,pal);
693 if (pcx_error != PCX_ERROR_NONE)
694 Error("File %s - PCX error: %s",BACKGROUND_NAME,pcx_errormsg(pcx_error));
695 gr_remap_bitmap_good( &background_bitmap, pal, -1, -1 );
699 //this is called once per game
702 atexit(close_game); //for cleanup
706 init_special_effects();
710 init_gauge_canvases();
712 init_exploding_walls();
714 load_background_bitmap();
716 Clear_window = 2; // do portal only window clear.
718 set_detail_level_parameters(Detail_level);
720 build_mission_list(0);
723 cvar_registervariable(&r_framerate);
728 void reset_palette_add()
733 //gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
738 void win_get_span_list(grs_bitmap *bm, int miny, int maxy)
744 int lspan=0, rspan=0, span=0;
748 //@@ fp = fopen("cockspan.dat", "w");
750 for (y = 0; y < miny; y++)
751 win_cockpit_mask[y].num = 0;
753 for (y = miny; y <= maxy; y++)
756 //@@ fprintf(fp, "line %d: ", y);
757 for (x = 0; x < bm->bm_w; x++)
759 offset = y*bm->bm_rowsize + x;
761 if (data[offset] == 255) {
764 case 0: // Start Mode
766 win_cockpit_mask[y].span[span].xmin = x;
768 //@@ fprintf(fp, "<%d,", lspan);
771 case 1: // Transparency mode
773 win_cockpit_mask[y].span[span].xmax = x;
776 case 2: // Switch from Draw mode to transparent
778 win_cockpit_mask[y].span[span].xmin = x;
779 //@@ fprintf(fp, "<%d,", lspan);
787 case 0: // Start mode
791 case 1: // Switching from transparent to Draw
794 win_cockpit_mask[y].span[span].xmax = x;
796 //@@ fprintf(fp, "%d> ", rspan);
805 //@@ fprintf(fp, "%d> ", rspan);
806 win_cockpit_mask[y].span[span].xmax = rspan;
809 win_cockpit_mask[y].num = span;
810 //@@ fprintf(fp, "\n");
813 win_cockpit_mask[y].num = 255;
818 void game_show_warning(char *s)
821 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
824 nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
826 if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
831 //these should be in gr.h
832 #define cv_w cv_bitmap.bm_w
833 #define cv_h cv_bitmap.bm_h
835 //added 3/24/99 by Owen Evans for screen res changing
836 u_int32_t Game_screen_mode = 0;
838 int Game_window_x = 0;
839 int Game_window_y = 0;
840 int Game_window_w = 0;
841 int Game_window_h = 0;
842 int max_window_w = 0;
843 int max_window_h = 0;
845 extern void newdemo_record_cockpit_change(int);
847 //initialize the various canvases on the game screen
848 //called every time the screen mode or cockpit changes
851 int minx, maxx, miny, maxy;
853 #if defined(POLY_ACC)
854 pa_flush(); // get rid of undrawn polys.
855 pa_clear_buffer(1, 0);
858 //Initialize the on-screen canvases
860 if (Newdemo_state==ND_STATE_RECORDING) {
861 newdemo_record_cockpit_change(Cockpit_mode);
864 if ( VR_render_mode != VR_NONE )
865 Cockpit_mode = CM_FULL_SCREEN;
867 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
868 Cockpit_mode = CM_FULL_SCREEN;
870 if ( Screen_mode == SCREEN_EDITOR )
871 Cockpit_mode = CM_FULL_SCREEN;
874 if (Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_REAR_VIEW) {
875 hud_message(MSGC_GAME_FEEDBACK, "Cockpit not available in GL mode");
876 Cockpit_mode = CM_FULL_SCREEN;
881 dd_gr_set_current_canvas(NULL),
882 gr_set_current_canvas(NULL)
884 gr_set_curfont( GAME_FONT );
886 #if !defined(MACINTOSH) && !defined(WINDOWS)
887 if (Game_cockpit_copy_code)
888 d_free(Game_cockpit_copy_code);
889 Game_cockpit_copy_code = NULL;
891 if (Game_cockpit_copy_code)
892 Game_cockpit_copy_code = 0;
896 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
900 game_win_init_cockpit_mask(0);
903 switch( Cockpit_mode ) {
904 case CM_FULL_COCKPIT:
906 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
908 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
911 dd_gr_set_current_canvas(NULL);
912 game_win_init_cockpit_mask(1);
913 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
915 gr_set_current_canvas(VR_offscreen_buffer);
918 WIN(DDGRLOCK(dd_grd_curcanv));
919 gr_bitmap( 0, 0, bm );
920 bm = &VR_offscreen_buffer->cv_bitmap;
921 bm->bm_flags = BM_FLAG_TRANSPARENT;
922 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
923 WIN( win_get_span_list(bm, miny, maxy);
924 DDGRUNLOCK(dd_grd_curcanv)
929 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
931 if ( Current_display_mode ) {
932 #if defined(POLY_ACC)
933 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 );
934 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
936 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 );
939 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
941 bm->bm_flags = 0; // Clear all flags for offscreen canvas
943 Game_cockpit_copy_code = (ubyte *)(1);
944 bm->bm_flags = 0; // Clear all flags for offscreen canvas
946 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
952 max_window_h = grd_curscreen->sc_h;
954 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
955 Game_window_h = max_window_h;
957 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
958 Game_window_w = max_window_w;
960 Game_window_x = (max_window_w - Game_window_w)/2;
961 Game_window_y = (max_window_h - Game_window_h)/2;
963 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
968 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
970 if (Game_window_h > max_window_h)
971 Game_window_h = max_window_h;
973 if (Game_window_w > max_window_w)
974 Game_window_w = max_window_w;
976 Game_window_x = (max_window_w - Game_window_w)/2;
977 Game_window_y = (max_window_h - Game_window_h)/2;
979 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
985 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
986 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
987 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
989 game_init_render_sub_buffers( x, y, w, h );
996 dd_gr_set_current_canvas(NULL),
997 gr_set_current_canvas(NULL)
1001 //selects a given cockpit (or lack of one). See types in game.h
1002 void select_cockpit(int mode)
1004 if (mode != Cockpit_mode) { //new mode
1010 extern int last_drawn_cockpit[2];
1012 //force cockpit redraw next time. call this if you've trashed the screen
1013 void reset_cockpit()
1015 force_cockpit_redraw=1;
1016 last_drawn_cockpit[0] = -1;
1017 last_drawn_cockpit[1] = -1;
1020 // void HUD_clear_messages(); //Already declared in gauges.h
1023 void VR_reset_params()
1025 VR_eye_width = VR_SEPARATION;
1026 VR_eye_offset = VR_PIXEL_SHIFT;
1027 VR_eye_offset_changed = 2;
1030 void game_init_render_sub_buffers( int x, int y, int w, int h )
1033 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
1034 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
1036 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
1037 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
1038 dd_VR_render_sub_buffer[0].xoff = x;
1039 dd_VR_render_sub_buffer[0].yoff = y;
1040 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
1041 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
1042 dd_VR_render_sub_buffer[1].xoff = x;
1043 dd_VR_render_sub_buffer[1].yoff = y;
1046 if (Scanline_double) {
1050 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
1051 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
1054 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
1055 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
1065 newBounds.right = x + w;
1067 newBounds.bottom = y + h;
1069 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
1075 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
1076 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
1077 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
1078 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
1084 // Sets up the canvases we will be rendering to (WIN95)
1085 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
1087 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
1088 // creating surfaces greater than the current resolution
1090 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
1091 render_w = GRMODEINFO(rw);
1092 render_h = GRMODEINFO(rh);
1095 VR_screen_mode = screen_mode;
1097 VR_screen_flags = flags;
1100 VR_render_mode = render_method;
1102 Game_window_w = render_w;
1103 Game_window_h = render_h;
1105 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
1106 dd_gr_free_canvas(dd_VR_offscreen_buffer);
1109 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
1110 if ( render_h*2 < 200 ) {
1111 Int3(); // Not Supported yet!!!
1112 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1115 Int3(); // Not Supported yet!!!
1116 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
1119 Int3(); // Not Supported yet!!!
1120 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1121 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
1123 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
1124 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
1125 // we can just flip it, saving a blt.
1127 dd_VR_offscreen_buffer = dd_grd_backcanv;
1128 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
1130 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
1131 // The offscreen buffer will be created. We will just blt this
1132 // to the screen (which may be blted to the primary surface)
1133 if ( render_h < 200 ) {
1134 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
1135 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
1138 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
1139 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
1143 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
1144 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
1145 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1146 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
1148 game_init_render_sub_buffers( 0, 0, render_w, render_h );
1153 // Sets up the canvases we will be rendering to (NORMAL VERSION)
1154 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
1156 // if (vga_check_mode(screen_mode) != 0)
1157 // Error("Cannot set requested video mode");
1159 VR_screen_mode = screen_mode;
1161 VR_screen_flags = flags;
1165 VR_render_mode = render_method;
1167 Game_window_w = render_w;
1168 Game_window_h = render_h;
1170 if (VR_offscreen_buffer) {
1171 gr_free_canvas(VR_offscreen_buffer);
1174 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
1175 if ( render_h*2 < 200 ) {
1176 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1179 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
1182 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1183 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
1186 if ( render_h < 200 ) {
1187 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1190 #if defined(POLY_ACC)
1192 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1193 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
1194 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
1196 if ( PAEnabled || gConfigInfo.mAcceleration ) {
1197 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
1198 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
1200 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1203 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1208 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
1211 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1212 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
1215 game_init_render_sub_buffers( 0, 0, render_w, render_h );
1219 //called to get the screen in a mode compatible with popup menus.
1220 //if we can't have popups over the game screen, switch to menu mode.
1221 void set_popup_screen(void)
1223 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
1225 #ifndef OGL // always have to switch to menu mode
1226 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
1229 set_screen_mode(SCREEN_MENU); //must switch to menu mode
1234 //called to change the screen mode. Parameter sm is the new mode, one of
1235 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
1236 //mode if cannot init requested mode)
1237 int set_screen_mode(int sm)
1239 WIN(static int force_mode_change=0);
1240 WIN(static int saved_window_w);
1241 WIN(static int saved_window_h);
1244 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
1245 gr_set_current_canvas( Canv_editor );
1251 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
1252 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
1256 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
1257 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1263 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
1264 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1265 ogl_set_screen_mode();
1276 switch( Screen_mode )
1280 //mouse_set_mode(0);
1282 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
1283 // HACK!!! Meant to save window size when switching from
1284 // non-compat menu mode to menu mode.
1285 saved_window_w = Game_window_w;
1286 saved_window_h = Game_window_h;
1287 force_mode_change = 1;
1289 if (W95DisplayMode != SM95_640x480x8) {
1290 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
1291 DDSETDISPLAYMODE(SM95_640x480x8);
1292 dd_gr_init_screen();
1293 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
1296 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
1298 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
1299 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
1300 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
1302 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
1303 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
1305 FontHires = FontHiresAvailable;
1311 MenuHires = MenuHiresAvailable; //do highres if we can
1313 #if defined(POLY_ACC)
1315 menu_mode = MenuHires?SM(640,480):SM(320,200);
1317 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
1320 menu_mode = MenuHires?SM(640,480):SM(320,200);
1323 if (VGA_current_mode != menu_mode) {
1324 if (gr_set_mode(menu_mode))
1325 Error("Cannot set screen mode for menu");
1326 if (!gr_palette_faded_out)
1327 gr_palette_load(gr_palette);
1330 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1331 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1333 FontHires = FontHiresAvailable && MenuHires;
1341 //mouse_set_mode(1);
1343 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
1345 DDSETDISPLAYMODE(VR_screen_mode);
1346 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
1347 dd_gr_init_screen();
1348 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
1349 game_init_render_buffers(W95DisplayMode,
1350 GRMODEINFO(rw), GRMODEINFO(rh),
1351 VR_render_mode, VR_screen_flags);
1356 if (VGA_current_mode != VR_screen_mode) {
1357 if (gr_set_mode(VR_screen_mode)) {
1358 Error("Cannot set desired screen mode for game!");
1359 //we probably should do something else here, like select a standard mode
1362 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
1363 joydefs_calibrate();
1369 if ( VR_render_mode == VR_NONE )
1371 max_window_w = grd_curscreen->sc_w;
1372 max_window_h = grd_curscreen->sc_h;
1374 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
1375 if (Cockpit_mode == CM_STATUS_BAR)
1376 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1378 else if (Cockpit_mode != CM_LETTERBOX)
1379 Cockpit_mode = CM_FULL_SCREEN;
1381 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
1382 Game_window_w = max_window_w;
1383 Game_window_h = max_window_h;
1388 Cockpit_mode = CM_FULL_SCREEN;
1391 // Super hack. If we are switching from a 320x200 game to 640x480.
1392 // and we were in a menumode when switching, we don't
1393 // restore Game_window vals
1394 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
1395 Game_window_w = saved_window_w;
1396 Game_window_h = saved_window_h;
1397 force_mode_change = 0;
1402 // Define screen pages for game mode
1403 // If we designate through screen_flags to use paging, then do so.
1405 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1406 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1409 if ( VR_screen_flags&VRF_USE_PAGING ) {
1411 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1412 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 )
1417 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1418 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1425 FontHires = FontHiresAvailable && (Current_display_mode != 0);
1428 FontHires = FontHiresAvailable && (MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2)));
1431 if ( VR_render_mode != VR_NONE ) {
1432 // for 640x480 or higher, use hires font.
1433 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
1443 if (grd_curscreen->sc_mode != SM(800,600)) {
1445 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
1446 Warning("Cannot init editor screen (error=%d)",gr_error);
1450 gr_palette_load( gr_palette );
1452 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1453 Canv_editor = &VR_editor_canvas;
1454 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1455 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1456 gr_set_current_canvas( Canv_editor );
1457 init_editor_screen(); //setup other editor stuff
1461 Error("Invalid screen mode %d",sm);
1464 VR_current_page = 0;
1467 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1468 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1471 if ( VR_screen_flags&VRF_USE_PAGING ) {
1474 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1478 ogl_set_screen_mode();
1484 int gr_toggle_fullscreen_game(void){
1485 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1487 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
1488 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
1489 //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.
1490 // generic_key_handler(KEY_PADENTER,0);
1491 // generic_key_handler(KEY_ENTER, 0);
1496 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
1501 int arch_toggle_fullscreen_menu(void);
1503 int gr_toggle_fullscreen_menu(void){
1504 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
1506 i=arch_toggle_fullscreen_menu();
1508 // generic_key_handler(KEY_PADENTER,0);
1509 // generic_key_handler(KEY_ENTER, 0);
1518 static int timer_paused=0;
1522 if (timer_paused==0) {
1524 time = timer_get_fixed_seconds();
1525 last_timer_value = time - last_timer_value;
1526 if (last_timer_value < 0) {
1527 #if defined(TIMER_TEST) && !defined(NDEBUG)
1528 Int3(); //get Matt!!!!
1530 last_timer_value = 0;
1532 #if defined(TIMER_TEST) && !defined(NDEBUG)
1533 time_stopped = time;
1538 #if defined(TIMER_TEST) && !defined(NDEBUG)
1546 Assert(timer_paused >= 0);
1547 if (timer_paused==0) {
1549 time = timer_get_fixed_seconds();
1550 #if defined(TIMER_TEST) && !defined(NDEBUG)
1551 if (last_timer_value < 0)
1552 Int3(); //get Matt!!!!
1555 last_timer_value = time - last_timer_value;
1556 #if defined(TIMER_TEST) && !defined(NDEBUG)
1557 time_started = time;
1561 #if defined(TIMER_TEST) && !defined(NDEBUG)
1566 MAC(extern ubyte joydefs_calibrating;)
1568 void game_flush_inputs()
1575 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1577 mouse_get_delta( &dx, &dy ); // Read mouse
1578 memset(&Controls,0,sizeof(control_info));
1583 last_timer_value = timer_get_fixed_seconds();
1588 extern int Saving_movie_frames;
1589 int Movie_fixed_frametime;
1591 #define Saving_movie_frames 0
1592 #define Movie_fixed_frametime 0
1595 //added on 8/18/98 by Victor Rachels to add maximum framerate
1599 void calc_frame_time()
1601 fix timer_value,last_frametime = FrameTime;
1603 #if defined(TIMER_TEST) && !defined(NDEBUG)
1604 _last_frametime = last_frametime;
1607 timer_value = timer_get_fixed_seconds();
1608 FrameTime = timer_value - last_timer_value;
1611 timer_value = timer_get_fixed_seconds();
1612 FrameTime = timer_value - last_timer_value;
1613 if (FrameTime < f1_0/maxfps);
1615 } while (FrameTime < f1_0/maxfps);
1617 #if defined(TIMER_TEST) && !defined(NDEBUG)
1618 _timer_value = timer_value;
1622 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1623 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1625 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1626 // if ( !dpmi_virtual_memory )
1627 // Int3(); //Get MATT if hit this!
1631 #if defined(TIMER_TEST) && !defined(NDEBUG)
1632 actual_last_timer_value = last_timer_value;
1635 if ( Game_turbo_mode )
1638 // Limit frametime to be between 5 and 150 fps.
1639 RealFrameTime = FrameTime;
1640 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1641 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1643 last_timer_value = timer_value;
1645 if (FrameTime < 0) //if bogus frametime...
1646 FrameTime = last_frametime; //...then use time from last frame
1649 if (fixed_frametime) FrameTime = fixed_frametime;
1654 if ( Debug_pause ) {
1664 last_timer_value = timer_get_fixed_seconds();
1672 #if defined(TIMER_TEST) && !defined(NDEBUG)
1673 stop_count = start_count = 0;
1676 // Set value to determine whether homing missile can see target.
1677 // The lower frametime is, the more likely that it can see its target.
1678 if (FrameTime <= F1_0/64)
1679 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1680 else if (FrameTime < F1_0/32)
1681 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1682 else if (FrameTime < F1_0/4)
1683 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;
1685 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1689 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1691 void move_player_2_segment(segment *seg,int side)
1695 compute_segment_center(&ConsoleObject->pos,seg);
1696 compute_center_point_on_side(&vp,seg,side);
1697 vm_vec_sub2(&vp,&ConsoleObject->pos);
1698 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1700 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1705 void game_draw_time_left()
1707 char temp_string[30];
1711 gr_set_curfont( GAME_FONT ); //GAME_FONT
1712 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1714 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1715 i=f2i(timevar-ThisLevelTime);
1718 sprintf( temp_string, "Time left: %d secs", i );
1721 gr_string(0, 32, temp_string );
1726 extern int Game_pause;
1729 void level_with_floor();
1731 void modex_clear_box(int x,int y,int w,int h)
1733 grs_canvas *temp_canv,*save_canv;
1735 save_canv = grd_curcanv;
1736 temp_canv = gr_create_canvas(w,h);
1737 gr_set_current_canvas(temp_canv);
1738 gr_clear_canvas(BM_XRGB(0,0,0));
1739 gr_set_current_canvas(save_canv);
1740 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1741 gr_free_canvas(temp_canv);
1745 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1747 // mac routine to drop contents of screen to a pict file using copybits
1748 // save a PICT to a file
1751 void SavePictScreen(int multiplayer)
1754 int parid, i, count;
1755 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1758 PicHandle pict_handle;
1759 static int multi_count = 0;
1760 StandardFileReply sf_reply;
1762 // dump the contents of the GameWindow into a picture using copybits
1764 pict_handle = OpenPicture(&GameWindow->portRect);
1765 if (pict_handle == NULL)
1768 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1771 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1772 if (!getcwd(cwd, FILENAME_MAX))
1774 // create the fsspec
1776 sprintf(filename, "screen%d", multi_count++);
1777 pfilename = c2pstr(filename);
1780 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1781 if (!sf_reply.sfGood)
1783 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1784 if (sf_reply.sfReplacing)
1786 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1790 // parid = GetAppDirId();
1791 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1796 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1801 // write the PICT file
1802 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1804 memset(buf, 0, sizeof(buf));
1806 if ( FSWrite(fd, &count, buf) )
1808 count = GetHandleSize((Handle)pict_handle);
1809 HLock((Handle)pict_handle);
1810 if ( FSWrite(fd, &count, *pict_handle) ) {
1816 HUnlock((Handle)pict_handle);
1817 DisposeHandle((Handle)pict_handle);
1825 //automap_flag is now unused, since we just check if the screen we're
1826 //writing to is modex
1827 //if called from automap, current canvas is set to visible screen
1829 void save_screen_shot(int automap_flag)
1831 #if defined(WINDOWS)
1832 mprintf((0, "Doing screen shot thing.\n"));
1833 win95_save_pcx_shot();
1835 #elif !defined(MACINTOSH)
1838 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1839 grs_font *save_font;
1840 static int savenum=0;
1841 static int stereo_savenum=0;
1842 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1843 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1851 // // Can't do screen shots in VR modes.
1852 // if ( VR_render_mode != VR_NONE )
1857 save_canv = grd_curcanv;
1859 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1863 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1864 gr_set_current_canvas(temp_canv);
1865 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1867 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1868 gr_set_current_canvas(temp_canv2);
1869 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1872 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1873 gr_set_current_canvas(temp_canv);
1874 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1877 gr_set_current_canvas(save_canv);
1879 if ( savenum > 99 ) savenum = 0;
1880 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1883 sprintf(savename,"left%02d.pcx",stereo_savenum);
1884 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1885 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1887 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1890 sprintf(savename,"screen%02d.pcx",savenum++);
1891 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1894 if (!automap_flag) //if from automap, curcanv is already visible canv
1895 gr_set_current_canvas(NULL);
1896 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1897 if (!automap_flag && modex_flag)
1898 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1900 save_font = grd_curcanv->cv_font;
1901 gr_set_curfont(GAME_FONT);
1902 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1903 gr_get_string_size(message,&w,&h,&aw);
1908 //I changed how these coords were calculated for the high-res automap. -MT
1909 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1910 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1911 x = (grd_curcanv->cv_w-w)/2;
1912 y = (grd_curcanv->cv_h-h)/2;
1915 modex_clear_box(x-2,y-2,w+4,h+4);
1916 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1918 gr_setcolor(gr_find_closest_color_current(0,0,0));
1919 gr_rect(x-2,y-2,x+w+2,y+h+2);
1920 gr_printf(x,y,message);
1921 gr_set_curfont(save_font);
1923 t1 = timer_get_fixed_seconds() + F1_0;
1925 gr_palette_read(pal); //get actual palette from the hardware
1926 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1928 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1930 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1932 gr_set_current_canvas(screen_canv);
1934 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1935 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1937 gr_free_canvas(temp_canv);
1939 gr_free_canvas(temp_canv2);
1941 gr_set_current_canvas(save_canv);
1947 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1948 grs_canvas *temp_canv, *save_canv;
1950 // Can't do screen shots in VR modes.
1951 if ( VR_render_mode != VR_NONE )
1956 save_canv = grd_curcanv;
1957 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1960 gr_set_current_canvas( temp_canv );
1961 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1962 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1966 if (Game_mode & GM_MULTI)
1973 gr_set_current_canvas(screen_canv);
1975 // if (!automap_flag)
1976 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1978 gr_free_canvas(temp_canv);
1980 gr_set_current_canvas(save_canv);
1989 void fly_init(object *obj)
1991 obj->control_type = CT_FLYING;
1992 obj->movement_type = MT_PHYSICS;
1994 vm_vec_zero(&obj->mtype.phys_info.velocity);
1995 vm_vec_zero(&obj->mtype.phys_info.thrust);
1996 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1997 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
2000 //void morph_test(), morph_step();
2003 // ------------------------------------------------------------------------------------
2005 void test_anim_states();
2009 //put up the help message
2016 extern int been_in_editor;
2018 // ------------------------------------------------------------------------------------
2019 void do_cloak_stuff(void)
2022 for (i = 0; i < N_players; i++)
2023 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
2024 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
2025 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
2026 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
2027 if (i == Player_num) {
2028 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
2030 if (Game_mode & GM_MULTI)
2031 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
2032 maybe_drop_net_powerup(POW_CLOAK);
2033 multi_send_decloak(); // For demo recording
2035 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
2043 // ------------------------------------------------------------------------------------
2044 void do_invulnerable_stuff(void)
2046 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
2047 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
2048 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
2051 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
2053 if (Game_mode & GM_MULTI)
2055 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
2056 maybe_drop_net_powerup(POW_INVULNERABILITY);
2059 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
2066 ubyte Last_afterburner_state = 0;
2067 fix Last_afterburner_charge = 0;
2069 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
2070 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
2074 //@@// ------------------------------------------------------------------------------------
2075 //@@void afterburner_shake(void)
2079 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
2080 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
2082 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
2083 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
2084 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
2088 // ------------------------------------------------------------------------------------
2090 extern void multi_send_sound_function (char,char);
2093 void do_afterburner_stuff(void)
2095 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
2096 Afterburner_charge=0;
2098 if (Endlevel_sequence || Player_is_dead)
2100 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
2102 multi_send_sound_function (0,0);
2106 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
2108 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
2109 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
2111 if (Game_mode & GM_MULTI)
2112 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
2115 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
2116 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
2118 if (Game_mode & GM_MULTI)
2119 multi_send_sound_function (0,0);
2121 mprintf((0,"Killing afterburner sound\n"));
2125 //@@if (Controls.afterburner_state && Afterburner_charge)
2126 //@@ afterburner_shake();
2128 Last_afterburner_state = Controls.afterburner_state;
2129 Last_afterburner_charge = Afterburner_charge;
2132 // -- // ------------------------------------------------------------------------------------
2133 // -- // if energy < F1_0/2, recharge up to F1_0/2
2134 // -- void recharge_energy_frame(void)
2136 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
2137 // -- Players[Player_num].energy += FrameTime/4;
2139 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
2140 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
2144 // Amount to diminish guns towards normal, per second.
2145 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
2147 extern fix Flash_effect;
2149 //adds to rgb values for palette flash
2150 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
2154 PaletteRedAdd += _dr;
2155 PaletteGreenAdd += _dg;
2156 PaletteBlueAdd += _db;
2158 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
2163 maxval = MAX_PALETTE_ADD;
2165 if (PaletteRedAdd > maxval)
2166 PaletteRedAdd = maxval;
2168 if (PaletteGreenAdd > maxval)
2169 PaletteGreenAdd = maxval;
2171 if (PaletteBlueAdd > maxval)
2172 PaletteBlueAdd = maxval;
2174 if (PaletteRedAdd < -maxval)
2175 PaletteRedAdd = -maxval;
2177 if (PaletteGreenAdd < -maxval)
2178 PaletteGreenAdd = -maxval;
2180 if (PaletteBlueAdd < -maxval)
2181 PaletteBlueAdd = -maxval;
2184 fix Time_flash_last_played;
2187 void game_palette_step_up( int r, int g, int b );
2188 // ------------------------------------------------------------------------------------
2189 // Diminish palette effects towards normal.
2190 void diminish_palette_towards_normal(void)
2194 // Diminish at DIMINISH_RATE units/second.
2195 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
2196 if (FrameTime < F1_0/DIMINISH_RATE) {
2197 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
2200 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
2201 if (dec_amount == 0)
2202 dec_amount++; // make sure we decrement by something
2208 // Part of hack system to force update of palette after exiting a menu.
2209 if (Time_flash_last_played) {
2211 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
2214 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
2215 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
2216 Time_flash_last_played = GameTime;
2219 Flash_effect -= FrameTime;
2220 if (Flash_effect < 0)
2223 if (force_do || (d_rand() > 4096 )) {
2224 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
2225 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2227 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2234 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
2235 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
2237 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
2238 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
2240 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
2241 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
2243 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
2244 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2246 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2248 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2251 int Redsave, Bluesave, Greensave;
2253 void palette_save(void)
2255 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
2258 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
2260 void game_palette_step_up( int r, int g, int b )
2262 if ( VR_use_reg_code ) {
2264 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
2267 gr_palette_step_up( r, g, b );
2271 void palette_restore(void)
2273 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
2274 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2276 // Forces flash effect to fixup palette next frame.
2277 Time_flash_last_played = 0;
2280 extern void dead_player_frame(void);
2283 // --------------------------------------------------------------------------------------------------
2284 int allowed_to_fire_laser(void)
2286 if (Player_is_dead) {
2287 Global_missile_firing_count = 0;
2291 // Make sure enough time has elapsed to fire laser, but if it looks like it will
2292 // be a long while before laser can be fired, then there must be some mistake!
2293 if (Next_laser_fire_time > GameTime)
2294 if (Next_laser_fire_time < GameTime + 2*F1_0)
2300 fix Next_flare_fire_time = 0;
2301 #define FLARE_BIG_DELAY (F1_0*2)
2303 int allowed_to_fire_flare(void)
2305 if (Next_flare_fire_time > GameTime)
2306 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
2309 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
2310 Next_flare_fire_time = GameTime + F1_0/4;
2312 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
2317 int allowed_to_fire_missile(void)
2319 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
2320 // Make sure enough time has elapsed to fire missile, but if it looks like it will
2321 // be a long while before missile can be fired, then there must be some mistake!
2322 if (Next_missile_fire_time > GameTime)
2323 if (Next_missile_fire_time < GameTime + 5*F1_0)
2329 void full_palette_save(void)
2332 apply_modified_palette();
2333 reset_palette_add();
2334 gr_palette_load( gr_palette );
2337 extern int Death_sequence_aborted;
2338 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) );
2345 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
2348 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
2350 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
2351 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
2353 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
2354 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
2355 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
2356 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
2358 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
2359 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
2360 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
2361 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
2363 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
2365 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
2367 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
2369 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
2371 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
2373 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
2374 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
2375 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
2376 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
2377 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
2379 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
2381 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
2383 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
2384 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
2385 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
2386 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
2389 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
2390 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
2391 m[21].type = NM_TYPE_TEXT; m[21].text = "";
2392 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
2393 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
2397 full_palette_save();
2399 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
2404 //temp function until Matt cleans up game sequencing
2405 extern void temp_reset_stuff_on_level();
2407 fix Rear_view_leave_time = 0x1000; // how long until we decide key is down (Used to be 0x4000)
2409 //deal with rear view - switch it on, or off, or whatever
2410 void check_rear_view()
2412 static int leave_mode;
2413 static fix entry_time;
2415 if ( Controls.rear_view_down_count ) { //key/button has gone down
2419 if (Cockpit_mode==CM_REAR_VIEW) {
2420 select_cockpit(Cockpit_mode_save);
2421 Cockpit_mode_save = -1;
2423 if (Newdemo_state == ND_STATE_RECORDING)
2424 newdemo_record_restore_rearview();
2428 if (Rear_view_leave_time <= 0)
2430 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
2434 leave_mode = 0; // means wait for another key
2435 entry_time = timer_get_fixed_seconds();
2437 if (Cockpit_mode == CM_FULL_COCKPIT) {
2438 Cockpit_mode_save = Cockpit_mode;
2439 select_cockpit(CM_REAR_VIEW);
2441 if (Newdemo_state == ND_STATE_RECORDING)
2442 newdemo_record_rearview();
2446 if (Controls.rear_view_down_state) {
2448 if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > Rear_view_leave_time)
2453 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2455 if (leave_mode==1 && Rear_view) {
2457 if (Cockpit_mode==CM_REAR_VIEW) {
2458 select_cockpit(Cockpit_mode_save);
2459 Cockpit_mode_save = -1;
2461 if (Newdemo_state == ND_STATE_RECORDING)
2462 newdemo_record_restore_rearview();
2467 void reset_rear_view(void)
2470 if (Newdemo_state == ND_STATE_RECORDING)
2471 newdemo_record_restore_rearview();
2476 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2477 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2478 Cockpit_mode_save = CM_FULL_COCKPIT;
2479 select_cockpit(Cockpit_mode_save);
2480 Cockpit_mode_save = -1;
2486 int Config_menu_flag;
2490 int gr_renderstats = 0;
2491 // need to define "cheat" for renderstats
2492 int gr_badtexture = 0;
2493 // need to define "cheat" for badtexture
2495 int Cheats_enabled=0;
2497 extern int Laser_rapid_fire;
2498 extern void do_lunacy_on(), do_lunacy_off();
2500 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2501 extern char BounceCheat,HomingCheat,OldHomingState[20];
2502 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2503 extern int Buddy_dude_cheat;
2505 //turns off active cheats
2506 void turn_cheats_off()
2512 Weapon_info[i].homing_flag=OldHomingState[i];
2517 Interpolation_method=old_IntMethod;
2520 Buddy_dude_cheat = 0;
2524 Laser_rapid_fire = 0;
2525 Physics_cheat_flag = 0;
2527 Robots_kill_robots_cheat=0;
2528 Robot_firing_enabled = 1;
2531 //turns off all cheats & resets cheater flag
2532 void game_disable_cheats()
2540 // ----------------------------------------------------------------------------
2542 void game_setup(void)
2544 //@@int demo_playing=0;
2545 //@@int multi_game=0;
2547 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2548 do_lunacy_off(); // Restore true insane mode.
2551 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2552 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2553 Endlevel_sequence = 0;
2555 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2556 //@@ demo_playing = 1;
2557 //@@if ( Game_mode & GM_MULTI )
2558 //@@ multi_game = 1;
2560 set_screen_mode(SCREEN_GAME);
2561 reset_palette_add();
2563 set_warn_func(game_show_warning);
2567 //digi_init_sounds();
2569 //keyd_repeat = 0; // Don't allow repeat in game
2570 keyd_repeat = 1; // Do allow repeat in game
2572 #if !defined(WINDOWS) && !defined(MACINTOSH)
2573 //_MARK_("start of game");
2577 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2578 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2580 if (!check_obj_seg(ConsoleObject))
2581 move_player_2_segment(Cursegp,Curside);
2584 Viewer = ConsoleObject;
2585 fly_init(ConsoleObject);
2590 FrameTime = 0; //make first frame zero
2593 if (Current_level_num == 0) { //not a real level
2594 init_player_stats_game();
2601 game_flush_inputs();
2607 extern char IWasKicked;
2611 // ------------------------------------------------------------------------------------
2612 //this function is the game. called when game mode selected. runs until
2613 //editor mode or exit selected
2616 game_setup(); // Replaces what was here earlier.
2617 // Good for Windows Sake.
2620 ProfilerSetStatus(1);
2623 if ( setjmp(LeaveGame)==0 ) {
2629 Config_menu_flag = 0;
2631 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2633 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2634 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2637 player_shields = Players[Player_num].shields;
2642 DoMessageStuff(&msg); // Do Windows event handling.
2643 if (_RedrawScreen) {
2644 _RedrawScreen = FALSE;
2645 load_palette(Current_level_palette,1,1);
2646 gr_palette_load(gr_palette);
2651 ExtGameStatus=GAMESTAT_RUNNING;
2652 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2654 //if the player is taking damage, give up guided missile control
2655 if (Players[Player_num].shields != player_shields)
2656 release_guided_missile(Player_num);
2658 //see if redbook song needs to be restarted
2659 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2661 if (Config_menu_flag) {
2662 int double_save = Scanline_double;
2664 //WIN(mouse_set_mode(0));
2665 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2667 if (Scanline_double != double_save) init_cockpit();
2668 if (!(Game_mode&GM_MULTI)) palette_restore();
2669 //WIN(mouse_set_mode(1));
2673 int save_w=Game_window_w,save_h=Game_window_h;
2675 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2676 Game_window_w=save_w; Game_window_h=save_h;
2678 last_drawn_cockpit[0] = -1;
2679 last_drawn_cockpit[1] = -1;
2682 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2684 fmode = Function_mode;
2685 Function_mode = FMODE_GAME;
2687 apply_modified_palette();
2688 reset_palette_add();
2689 gr_palette_load( gr_palette );
2690 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2692 Function_mode = fmode;
2695 newdemo_stop_playback();
2696 Function_mode = FMODE_MENU;
2698 Function_mode = FMODE_GAME;
2702 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2708 fmode = Function_mode;
2709 Function_mode = FMODE_GAME;
2711 apply_modified_palette();
2712 reset_palette_add();
2713 gr_palette_load( gr_palette );
2714 ExtGameStatus=GAMESTAT_ABORT_GAME;
2715 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2717 Function_mode = fmode;
2719 Function_mode = FMODE_GAME;
2725 if (Function_mode != FMODE_GAME)
2726 longjmp(LeaveGame,0);
2729 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2730 longjmp(LeaveGame,0);
2736 ProfilerSetStatus(0);
2741 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2742 newdemo_stop_recording();
2748 if ( Newdemo_state == ND_STATE_PLAYBACK )
2749 newdemo_stop_playback();
2751 if (Cockpit_mode_save!=-1)
2753 Cockpit_mode=Cockpit_mode_save;
2754 Cockpit_mode_save=-1;
2757 if (Function_mode != FMODE_EDITOR)
2758 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2760 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2761 //@@ scores_maybe_add_player(Game_aborted);
2764 #if !defined(WINDOWS) && !defined(MACINTOSH)
2765 //_MARK_("end of game");
2768 clear_warn_func(game_show_warning); //don't use this func anymore
2770 game_disable_cheats();
2773 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2777 //called at the end of the program
2781 if (dd_VR_offscreen_buffer) {
2782 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2783 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2785 dd_VR_offscreen_buffer = NULL;
2786 VR_offscreen_buffer = NULL;
2789 if (VR_offscreen_buffer) {
2790 gr_free_canvas(VR_offscreen_buffer);
2791 VR_offscreen_buffer = NULL;
2795 close_gauge_canvases();
2797 restore_effect_bitmap_icons();
2799 #if !defined(MACINTOSH) && !defined(WINDOWS)
2800 if (Game_cockpit_copy_code) {
2801 d_free(Game_cockpit_copy_code);
2802 Game_cockpit_copy_code = NULL;
2805 if (Game_cockpit_copy_code)
2806 Game_cockpit_copy_code = 0;
2809 if (background_bitmap.bm_data)
2810 d_free(background_bitmap.bm_data);
2812 clear_warn_func(game_show_warning); //don't use this func anymore
2816 dd_grs_canvas * get_current_game_screen()
2818 return &dd_VR_screen_pages[VR_current_page];
2823 grs_canvas * get_current_game_screen()
2825 return &VR_screen_pages[VR_current_page];
2830 extern void kconfig_center_headset();
2834 void speedtest_frame(void);
2835 int Debug_slowdown=0;
2839 extern void player_follow_path(object *objp);
2840 extern void check_create_player_path(void);
2844 extern int Do_appearance_effect;
2846 object *Missile_viewer=NULL;
2848 int Missile_view_enabled = 1;
2850 int Marker_viewer_num[2]={-1,-1};
2851 int Coop_view_player[2]={-1,-1};
2852 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2854 //returns ptr to escort robot, or NULL
2855 object *find_escort()
2859 for (i=0; i<=Highest_object_index; i++)
2860 if (Objects[i].type == OBJ_ROBOT)
2861 if (Robot_info[Objects[i].id].companion)
2867 extern void process_super_mines_frame(void);
2868 extern void do_seismic_stuff(void);
2871 int Saving_movie_frames=0;
2872 int __Movie_frame_num=0;
2874 #define MAX_MOVIE_BUFFER_FRAMES 250
2875 #define MOVIE_FRAME_SIZE (320 * 200)
2877 ubyte *Movie_frame_buffer;
2878 int Movie_frame_counter;
2879 ubyte Movie_pal[768];
2880 char movie_path[50] = ".\\";
2882 grs_bitmap Movie_bm;
2884 void flush_movie_buffer()
2891 mprintf((0,"Flushing movie buffer..."));
2893 Movie_bm.bm_data = Movie_frame_buffer;
2895 for (f=0;f<Movie_frame_counter;f++) {
2896 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2897 __Movie_frame_num++;
2898 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2899 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2902 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2905 Movie_frame_counter=0;
2907 mprintf((0,"done \n"));
2912 void toggle_movie_saving()
2916 Saving_movie_frames = !Saving_movie_frames;
2918 if (Saving_movie_frames) {
2921 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2922 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2925 Saving_movie_frames = 0;
2929 while (isspace(movie_path[strlen(movie_path)-1]))
2930 movie_path[strlen(movie_path)-1] = 0;
2931 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2932 strcat(movie_path,"\\");
2935 if (!Movie_frame_buffer) {
2936 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2937 if (!Movie_frame_buffer) {
2939 Saving_movie_frames=0;
2942 Movie_frame_counter=0;
2944 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2945 Movie_bm.bm_w = 320;
2946 Movie_bm.bm_h = 200;
2947 Movie_bm.bm_type = BM_LINEAR;
2948 Movie_bm.bm_flags = 0;
2949 Movie_bm.bm_rowsize = 320;
2950 Movie_bm.bm_handle = 0;
2952 gr_palette_read(Movie_pal); //get actual palette from the hardware
2954 if (Newdemo_state == ND_STATE_PLAYBACK)
2955 Newdemo_do_interpolate = 0;
2959 flush_movie_buffer();
2961 if (Newdemo_state == ND_STATE_PLAYBACK)
2962 Newdemo_do_interpolate = 1;
2967 void save_movie_frame()
2969 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2971 Movie_frame_counter++;
2973 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2974 flush_movie_buffer();
2980 extern int Level_shake_duration;
2982 //if water or fire level, make occasional sound
2983 void do_ambient_sounds()
2985 int has_water,has_lava;
2988 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2989 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2991 if (has_lava) { //has lava
2992 sound = SOUND_AMBIENT_LAVA;
2993 if (has_water && (d_rand() & 1)) //both, pick one
2994 sound = SOUND_AMBIENT_WATER;
2996 else if (has_water) //just water
2997 sound = SOUND_AMBIENT_WATER;
3001 if (((d_rand() << 3) < FrameTime)) { //play the sound
3002 fix volume = d_rand() + f1_0/2;
3003 digi_play_sample(sound,volume);
3007 // -- extern void lightning_frame(void);
3009 void game_render_frame();
3010 extern void omega_charge_frame(void);
3012 extern time_t t_current_time, t_saved_time;
3014 void flicker_lights();
3016 void GameLoop(int RenderFlag, int ReadControlsFlag )
3019 // Used to slow down frame rate for testing things.
3020 // RenderFlag = 1; // DEBUG
3021 if (Debug_slowdown) {
3024 for (h=0; h<Debug_slowdown; h++)
3025 for (i=0; i<1000; i++)
3032 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
3034 if (desc_id_exit_num) { // are we supposed to be checking
3035 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
3036 char time_str[32], time_str2[32];
3038 _ctime(&t_saved_time, time_str);
3039 _ctime(&t_current_time, time_str2);
3041 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
3042 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
3049 if (FindArg("-invulnerability"))
3050 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
3054 update_player_stats();
3055 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
3056 do_afterburner_stuff();
3058 do_invulnerable_stuff();
3059 remove_obsolete_stuck_objects();
3061 do_final_boss_frame();
3062 // -- lightning_frame();
3063 // -- recharge_energy_frame();
3065 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
3066 static int turned_off=0;
3067 Players[Player_num].energy -= (FrameTime*3/8);
3068 if (Players[Player_num].energy < i2f(10)) {
3070 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
3073 if (Game_mode & GM_MULTI)
3074 multi_send_flags(Player_num);
3081 if (Players[Player_num].energy <= 0) {
3082 Players[Player_num].energy = 0;
3083 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
3085 if (Game_mode & GM_MULTI)
3086 multi_send_flags(Player_num);
3093 check_create_player_path();
3094 player_follow_path(ConsoleObject);
3098 if (Game_mode & GM_MULTI)
3101 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
3102 multi_check_for_killgoal_winner();
3108 if (force_cockpit_redraw) { //screen need redrawing?
3110 force_cockpit_redraw=0;
3112 game_render_frame();
3113 //show_extra_views(); //missile view, buddy bot, etc.
3116 if (Saving_movie_frames)
3123 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
3127 dead_player_frame();
3128 if (Newdemo_state != ND_STATE_PLAYBACK)
3129 do_controlcen_dead_frame();
3131 process_super_mines_frame();
3133 do_ambient_sounds();
3140 if (ReadControlsFlag)
3143 memset(&Controls, 0, sizeof(Controls));
3145 GameTime += FrameTime;
3147 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
3148 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
3150 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
3151 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
3152 mprintf((0,"GameTime reset to 0\n"));
3156 if (FindArg("-checktime") != 0)
3157 if (GameTime >= i2f(600)) //wrap after 10 minutes
3158 GameTime = FrameTime;
3162 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
3163 ThisLevelTime +=FrameTime;
3168 if (Endlevel_sequence) {
3169 do_endlevel_frame();
3170 powerup_grab_cheat_all();
3171 do_special_effects();
3172 return; //skip everything else
3175 if (Newdemo_state != ND_STATE_PLAYBACK)
3176 do_exploding_wall_frame();
3177 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
3178 do_special_effects();
3179 wall_frame_process();
3180 triggers_frame_process();
3184 if (Control_center_destroyed) {
3185 if (Newdemo_state==ND_STATE_RECORDING )
3186 newdemo_record_control_center_destroyed();
3191 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
3192 newdemo_playback_one_frame();
3193 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
3194 longjmp( LeaveGame, 0 ); // Go back to menu
3197 { // Note the link to above!
3199 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
3202 powerup_grab_cheat_all();
3204 if (Endlevel_sequence) //might have been started during move
3207 fuelcen_update_all();
3211 if (allowed_to_fire_laser())
3212 FireLaser(); // Fire Laser!
3214 if (Auto_fire_fusion_cannon_time) {
3215 if (Primary_weapon != FUSION_INDEX)
3216 Auto_fire_fusion_cannon_time = 0;
3217 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
3218 Auto_fire_fusion_cannon_time = 0;
3219 Global_laser_firing_count = 1;
3221 vms_vector rand_vec;
3224 Global_laser_firing_count = 0;
3226 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
3227 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
3228 make_random_vector(&rand_vec);
3230 bump_amount = F1_0*4;
3232 if (Fusion_charge > F1_0*2)
3233 bump_amount = Fusion_charge*4;
3235 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
3239 if (Global_laser_firing_count) {
3240 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
3241 // if (Fusion_charge > F1_0*2)
3242 // Fusion_charge = F1_0*2;
3243 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
3246 if (Global_laser_firing_count < 0)
3247 Global_laser_firing_count = 0;
3250 if (Do_appearance_effect) {
3251 create_player_appearance_effect(ConsoleObject);
3252 Do_appearance_effect = 0;
3254 if ((Game_mode & GM_MULTI) && Netgame.invul)
3256 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
3257 Players[Player_num].invulnerable_time = GameTime-i2f(27);
3264 omega_charge_frame();
3268 //!!hoard_light_pulse(); //do cool hoard light pulsing
3272 //!!extern int Goal_blue_segnum,Goal_red_segnum;
3273 //!!extern int Hoard_goal_eclip;
3275 //!!//do cool pulsing lights in hoard goals
3276 //!!hoard_light_pulse()
3278 //!! if (Game_mode & GM_HOARD) {
3282 //!! frame = Effects[Hoard_goal_eclip].frame_count;
3286 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
3289 //!! light = abs(frame - 5) * f1_0 / 5;
3291 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
3296 ubyte Slide_segs[MAX_SEGMENTS];
3297 int Slide_segs_computed;
3299 void compute_slide_segs(void)
3301 int segnum, sidenum;
3303 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
3304 Slide_segs[segnum] = 0;
3305 for (sidenum=0;sidenum<6;sidenum++) {
3306 int tmn = Segments[segnum].sides[sidenum].tmap_num;
3307 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
3308 Slide_segs[segnum] |= 1 << sidenum;
3312 Slide_segs_computed = 1;
3315 // -----------------------------------------------------------------------------
3316 void slide_textures(void)
3318 int segnum,sidenum,i;
3320 if (!Slide_segs_computed)
3321 compute_slide_segs();
3323 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
3324 if (Slide_segs[segnum]) {
3325 for (sidenum=0;sidenum<6;sidenum++) {
3326 if (Slide_segs[segnum] & (1 << sidenum)) {
3327 int tmn = Segments[segnum].sides[sidenum].tmap_num;
3328 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
3330 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
3331 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
3332 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
3335 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
3337 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
3340 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
3342 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
3345 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
3347 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
3350 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
3360 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
3362 int Num_flickering_lights=0;
3364 void flicker_lights()
3367 flickering_light *f;
3369 f = Flickering_lights;
3371 for (l=0;l<Num_flickering_lights;l++,f++) {
3372 segment *segp = &Segments[f->segnum];
3374 //make sure this is actually a light
3375 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
3377 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
3380 if (f->timer == 0x80000000) //disabled
3383 if ((f->timer -= FrameTime) < 0) {
3385 while (f->timer < 0)
3386 f->timer += f->delay;
3388 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
3391 add_light(f->segnum,f->sidenum);
3393 subtract_light(f->segnum,f->sidenum);
3398 //returns ptr to flickering light structure, or NULL if can't find
3399 flickering_light *find_flicker(int segnum,int sidenum)
3402 flickering_light *f;
3404 //see if there's already an entry for this seg/side
3406 f = Flickering_lights;
3408 for (l=0;l<Num_flickering_lights;l++,f++)
3409 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3415 //turn flickering off (because light has been turned off)
3416 void disable_flicker(int segnum,int sidenum)
3418 flickering_light *f;
3420 if ((f=find_flicker(segnum,sidenum)) != NULL)
3421 f->timer = 0x80000000;
3424 //turn flickering off (because light has been turned on)
3425 void enable_flicker(int segnum,int sidenum)
3427 flickering_light *f;
3429 if ((f=find_flicker(segnum,sidenum)) != NULL)
3436 //returns 1 if ok, 0 if error
3437 int add_flicker(int segnum, int sidenum, fix delay, unsigned long mask)
3440 flickering_light *f;
3442 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
3444 //see if there's already an entry for this seg/side
3446 f = Flickering_lights;
3448 for (l=0;l<Num_flickering_lights;l++,f++)
3449 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3452 if (mask==0) { //clearing entry
3453 if (l == Num_flickering_lights)
3457 for (i=l;i<Num_flickering_lights-1;i++)
3458 Flickering_lights[i] = Flickering_lights[i+1];
3459 Num_flickering_lights--;
3464 if (l == Num_flickering_lights) {
3465 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3468 Num_flickering_lights++;
3472 f->sidenum = sidenum;
3473 f->delay = f->timer = delay;
3481 // -----------------------------------------------------------------------------
3482 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3487 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3489 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3490 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3491 Global_laser_firing_count = 0;
3493 if (Fusion_charge == 0)
3494 Players[Player_num].energy -= F1_0*2;
3496 Fusion_charge += FrameTime;
3497 Players[Player_num].energy -= FrameTime;
3499 if (Players[Player_num].energy <= 0) {
3500 Players[Player_num].energy = 0;
3501 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3503 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3504 // Fire the fusion cannon at this time in the future.
3506 if (Fusion_charge < F1_0*2)
3507 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3509 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3511 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3512 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3514 if (Fusion_next_sound_time < GameTime) {
3515 if (Fusion_charge > F1_0*2) {
3516 digi_play_sample( 11, F1_0 );
3517 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3519 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3520 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3522 if (Game_mode & GM_MULTI)
3523 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3526 Fusion_last_sound_time = GameTime;
3527 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3535 // -------------------------------------------------------------------------------------------------------
3536 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3537 // This could easily be made difficulty level dependent.
3538 void powerup_grab_cheat(object *player, int objnum)
3544 Assert(Objects[objnum].type == OBJ_POWERUP);
3546 powerup_size = Objects[objnum].size;
3547 player_size = player->size;
3549 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3551 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3552 vms_vector collision_point;
3554 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3555 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3559 // -------------------------------------------------------------------------------------------------------
3560 // Make it easier to pick up powerups.
3561 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3562 // from player to powerup and player's forward vector.
3563 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3564 // way before the player gets there.
3565 void powerup_grab_cheat_all(void)
3570 segp = &Segments[ConsoleObject->segnum];
3571 objnum = segp->objects;
3573 while (objnum != -1) {
3574 if (Objects[objnum].type == OBJ_POWERUP)
3575 powerup_grab_cheat(ConsoleObject, objnum);
3576 objnum = Objects[objnum].next;
3581 int Last_level_path_created = -1;
3583 #ifdef SHOW_EXIT_PATH
3585 // ------------------------------------------------------------------------------------------------------------------
3586 // Create path for player from current segment to goal segment.
3587 // Return true if path created, else return false.
3588 int mark_player_path_to_segment(int segnum)
3591 object *objp = ConsoleObject;
3592 short player_path_length=0;
3593 int player_hide_index=-1;
3595 if (Last_level_path_created == Current_level_num) {
3599 Last_level_path_created = Current_level_num;
3601 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3602 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3606 player_hide_index = Point_segs_free_ptr - Point_segs;
3607 Point_segs_free_ptr += player_path_length;
3609 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3610 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3611 ai_reset_all_paths();
3615 for (i=1; i<player_path_length; i++) {
3617 vms_vector seg_center;
3620 segnum = Point_segs[player_hide_index+i].segnum;
3621 mprintf((0, "%3i ", segnum));
3622 seg_center = Point_segs[player_hide_index+i].point;
3624 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3626 Int3(); // Unable to drop energy powerup for path
3630 obj = &Objects[objnum];
3631 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3632 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3633 obj->rtype.vclip_info.framenum = 0;
3634 obj->lifeleft = F1_0*100 + d_rand() * 4;
3641 // Return true if it happened, else return false.
3642 int create_special_path(void)
3646 // ---------- Find exit doors ----------
3647 for (i=0; i<=Highest_segment_index; i++)
3648 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3649 if (Segments[i].children[j] == -2) {
3650 mprintf((0, "Exit at segment %i\n", i));
3651 return mark_player_path_to_segment(i);
3661 int Max_obj_count_mike = 0;
3663 // Shows current number of used objects.
3664 void show_free_objects(void)
3666 if (!(FrameCount & 8)) {
3670 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3672 for (i=0; i<=Highest_object_index; i++)
3673 if (Objects[i].type != OBJ_NONE)
3676 mprintf((0, "%3i", count));
3678 if (count > Max_obj_count_mike) {
3679 Max_obj_count_mike = count;
3680 mprintf((0, " ***"));
3691 void game_win_init_cockpit_mask(int sram)
3693 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3694 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3697 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3698 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3699 // we can just flip it, saving a blt.
3702 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3703 // The offscreen buffer will be created. We will just blt this
3704 // to the screen (which may be blted to the primary surface)
3705 if ( grd_curscreen->sc_h < 200 ) {
3706 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3707 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3709 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3710 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3711 dd_VR_offscreen_buffer->sram = 1;
3715 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3716 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3718 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3719 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3720 dd_VR_offscreen_buffer->sram = 1;
3725 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3726 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3727 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3728 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3730 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3733 //@@void game_win_init_cockpit_mask()
3735 //@@ char title_pal[768];
3736 //@@ dd_grs_canvas ccanv;
3738 //@@ LPDIRECTDRAWSURFACE dds;
3740 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3741 //@@ Assert(dds != NULL);
3743 //@@ _lpDDSMask = dds;
3744 //@@ ccanv.lpdds = dds;
3745 //@@ dd_gr_reinit_canvas(&ccanv);
3747 //@@ dd_gr_set_current_canvas(&ccanv);
3748 //@@ DDGRLOCK(dd_grd_curcanv)
3750 //@@ if (W95DisplayMode == SM95_640x480x8) {
3751 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3752 //@@ grd_curcanv->cv_bitmap.bm_type,
3756 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3757 //@@ grd_curcanv->cv_bitmap.bm_type,
3761 //@@ DDGRUNLOCK(dd_grd_curcanv);
3763 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3764 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);
3770 * reads a flickering_light structure from a CFILE
3772 void flickering_light_read(flickering_light *fl, CFILE *fp)
3774 fl->segnum = cfile_read_short(fp);
3775 fl->sidenum = cfile_read_short(fp);
3776 fl->mask = cfile_read_int(fp);
3777 fl->timer = cfile_read_fix(fp);
3778 fl->delay = cfile_read_fix(fp);