1 /* $Id: game.c,v 1.23 2003-10-10 09:36:35 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.23 2003-10-10 09:36:35 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 int Game_window_x = 0;
836 int Game_window_y = 0;
837 int Game_window_w = 0;
838 int Game_window_h = 0;
839 int max_window_w = 0;
840 int max_window_h = 0;
842 extern void newdemo_record_cockpit_change(int);
844 //initialize the various canvases on the game screen
845 //called every time the screen mode or cockpit changes
848 int minx, maxx, miny, maxy;
850 #if defined(POLY_ACC)
851 pa_flush(); // get rid of undrawn polys.
852 pa_clear_buffer(1, 0);
855 //Initialize the on-screen canvases
857 if (Newdemo_state==ND_STATE_RECORDING) {
858 newdemo_record_cockpit_change(Cockpit_mode);
861 if ( VR_render_mode != VR_NONE )
862 Cockpit_mode = CM_FULL_SCREEN;
864 if (!(VR_screen_flags & VRF_ALLOW_COCKPIT) && (Cockpit_mode==CM_FULL_COCKPIT || Cockpit_mode==CM_STATUS_BAR || Cockpit_mode==CM_REAR_VIEW) )
865 Cockpit_mode = CM_FULL_SCREEN;
867 if ( Screen_mode == SCREEN_EDITOR )
868 Cockpit_mode = CM_FULL_SCREEN;
871 if (Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_REAR_VIEW) {
872 hud_message(MSGC_GAME_FEEDBACK, "Cockpit not available in GL mode");
873 Cockpit_mode = CM_FULL_SCREEN;
878 dd_gr_set_current_canvas(NULL),
879 gr_set_current_canvas(NULL)
881 gr_set_curfont( GAME_FONT );
883 #if !defined(MACINTOSH) && !defined(WINDOWS)
884 if (Game_cockpit_copy_code)
885 d_free(Game_cockpit_copy_code);
886 Game_cockpit_copy_code = NULL;
888 if (Game_cockpit_copy_code)
889 Game_cockpit_copy_code = 0;
893 //@@ if (_lpDDSMask) { DDFreeSurface(_lpDDSMask); _lpDDSMask = NULL; }
897 game_win_init_cockpit_mask(0);
900 switch( Cockpit_mode ) {
901 case CM_FULL_COCKPIT:
903 grs_bitmap *bm = &GameBitmaps[cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)].index];
905 PIGGY_PAGE_IN(cockpit_bitmap[Cockpit_mode+(Current_display_mode?(Num_cockpits/2):0)]);
908 dd_gr_set_current_canvas(NULL);
909 game_win_init_cockpit_mask(1);
910 dd_gr_set_current_canvas(dd_VR_offscreen_buffer);
912 gr_set_current_canvas(VR_offscreen_buffer);
915 WIN(DDGRLOCK(dd_grd_curcanv));
916 gr_bitmap( 0, 0, bm );
917 bm = &VR_offscreen_buffer->cv_bitmap;
918 bm->bm_flags = BM_FLAG_TRANSPARENT;
919 gr_ibitblt_find_hole_size ( bm, &minx, &miny, &maxx, &maxy );
920 WIN( win_get_span_list(bm, miny, maxy);
921 DDGRUNLOCK(dd_grd_curcanv)
926 gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize);
928 if ( Current_display_mode ) {
929 #if defined(POLY_ACC)
930 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 );
931 pa_clear_buffer(1, 0); // clear offscreen to reduce white flash.
933 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 );
936 Game_cockpit_copy_code = gr_ibitblt_create_mask( bm, minx, miny, maxx-minx+1, maxy-miny+1, VR_offscreen_buffer->cv_bitmap.bm_rowsize );
938 bm->bm_flags = 0; // Clear all flags for offscreen canvas
940 Game_cockpit_copy_code = (ubyte *)(1);
941 bm->bm_flags = 0; // Clear all flags for offscreen canvas
943 game_init_render_sub_buffers( 0, 0, maxx-minx+1, maxy-miny+1 );
949 max_window_h = grd_curscreen->sc_h;
951 if (Game_window_h > max_window_h || VR_screen_flags&VRF_ALLOW_COCKPIT)
952 Game_window_h = max_window_h;
954 if (Game_window_w > max_window_w || VR_screen_flags&VRF_ALLOW_COCKPIT)
955 Game_window_w = max_window_w;
957 Game_window_x = (max_window_w - Game_window_w)/2;
958 Game_window_y = (max_window_h - Game_window_h)/2;
960 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
965 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
967 if (Game_window_h > max_window_h)
968 Game_window_h = max_window_h;
970 if (Game_window_w > max_window_w)
971 Game_window_w = max_window_w;
973 Game_window_x = (max_window_w - Game_window_w)/2;
974 Game_window_y = (max_window_h - Game_window_h)/2;
976 game_init_render_sub_buffers( Game_window_x, Game_window_y, Game_window_w, Game_window_h );
982 x = 0; w = VR_render_buffer[0].cv_bitmap.bm_w; //VR_render_width;
983 h = (VR_render_buffer[0].cv_bitmap.bm_h * 7) / 10;
984 y = (VR_render_buffer[0].cv_bitmap.bm_h-h)/2;
986 game_init_render_sub_buffers( x, y, w, h );
993 dd_gr_set_current_canvas(NULL),
994 gr_set_current_canvas(NULL)
998 //selects a given cockpit (or lack of one). See types in game.h
999 void select_cockpit(int mode)
1001 if (mode != Cockpit_mode) { //new mode
1007 extern int last_drawn_cockpit[2];
1009 //force cockpit redraw next time. call this if you've trashed the screen
1010 void reset_cockpit()
1012 force_cockpit_redraw=1;
1013 last_drawn_cockpit[0] = -1;
1014 last_drawn_cockpit[1] = -1;
1017 // void HUD_clear_messages(); //Already declared in gauges.h
1020 void VR_reset_params()
1022 VR_eye_width = VR_SEPARATION;
1023 VR_eye_offset = VR_PIXEL_SHIFT;
1024 VR_eye_offset_changed = 2;
1027 void game_init_render_sub_buffers( int x, int y, int w, int h )
1030 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[0], &dd_VR_render_buffer[0], x, y, w, h );
1031 dd_gr_init_sub_canvas( &dd_VR_render_sub_buffer[1], &dd_VR_render_buffer[1], x, y, w, h );
1033 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_x = 0;
1034 dd_VR_render_sub_buffer[0].canvas.cv_bitmap.bm_y = 0;
1035 dd_VR_render_sub_buffer[0].xoff = x;
1036 dd_VR_render_sub_buffer[0].yoff = y;
1037 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_x = 0;
1038 dd_VR_render_sub_buffer[1].canvas.cv_bitmap.bm_y = 0;
1039 dd_VR_render_sub_buffer[1].xoff = x;
1040 dd_VR_render_sub_buffer[1].yoff = y;
1043 if (Scanline_double) {
1047 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w/2, (h/2)+1);
1048 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w/2, (h/2)+1);
1051 gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
1052 gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
1062 newBounds.right = x + w;
1064 newBounds.bottom = y + h;
1066 pa_set_context(kGamePlayDrawContextID, &newBounds); // must resize/create new context
1072 VR_render_sub_buffer[0].cv_bitmap.bm_x = 0;
1073 VR_render_sub_buffer[0].cv_bitmap.bm_y = 0;
1074 VR_render_sub_buffer[1].cv_bitmap.bm_x = 0;
1075 VR_render_sub_buffer[1].cv_bitmap.bm_y = 0;
1081 // Sets up the canvases we will be rendering to (WIN95)
1082 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
1084 // Hack for switching to higher that 640x480 modes (DDraw doesn't allow
1085 // creating surfaces greater than the current resolution
1087 if (GRMODEINFO(rw) < render_w || GRMODEINFO(rh) < render_h) {
1088 render_w = GRMODEINFO(rw);
1089 render_h = GRMODEINFO(rh);
1092 VR_screen_mode = screen_mode;
1094 VR_screen_flags = flags;
1097 VR_render_mode = render_method;
1099 Game_window_w = render_w;
1100 Game_window_h = render_h;
1102 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
1103 dd_gr_free_canvas(dd_VR_offscreen_buffer);
1106 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
1107 if ( render_h*2 < 200 ) {
1108 Int3(); // Not Supported yet!!!
1109 // VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1112 Int3(); // Not Supported yet!!!
1113 // VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
1116 Int3(); // Not Supported yet!!!
1117 // gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1118 // gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
1120 else if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
1121 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
1122 // we can just flip it, saving a blt.
1124 dd_VR_offscreen_buffer = dd_grd_backcanv;
1125 VR_offscreen_buffer = & dd_grd_backcanv->canvas;
1127 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
1128 // The offscreen buffer will be created. We will just blt this
1129 // to the screen (which may be blted to the primary surface)
1130 if ( render_h < 200 ) {
1131 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, 200);
1132 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
1135 dd_VR_offscreen_buffer = dd_gr_create_canvas(render_w, render_h);
1136 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
1140 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
1141 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, render_w, render_h );
1142 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1143 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
1145 game_init_render_sub_buffers( 0, 0, render_w, render_h );
1150 // Sets up the canvases we will be rendering to (NORMAL VERSION)
1151 void game_init_render_buffers(int screen_mode, int render_w, int render_h, int render_method, int flags )
1153 // if (vga_check_mode(screen_mode) != 0)
1154 // Error("Cannot set requested video mode");
1156 VR_screen_mode = screen_mode;
1158 VR_screen_flags = flags;
1162 VR_render_mode = render_method;
1164 Game_window_w = render_w;
1165 Game_window_h = render_h;
1167 if (VR_offscreen_buffer) {
1168 gr_free_canvas(VR_offscreen_buffer);
1171 if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
1172 if ( render_h*2 < 200 ) {
1173 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1176 VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
1179 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1180 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
1183 if ( render_h < 200 ) {
1184 VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
1187 #if defined(POLY_ACC)
1189 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1190 d_free(VR_offscreen_buffer->cv_bitmap.bm_data);
1191 gr_init_canvas(VR_offscreen_buffer, pa_get_buffer_address(1), BM_LINEAR15, render_w, render_h);
1193 if ( PAEnabled || gConfigInfo.mAcceleration ) {
1194 Cockpit_mode=CM_FULL_SCREEN; // HACK HACK HACK HACK HACK!!!!
1195 VR_offscreen_buffer = gr_create_canvas2(render_w, render_h, BM_LINEAR15);
1197 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1200 VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
1205 VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
1208 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
1209 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
1212 game_init_render_sub_buffers( 0, 0, render_w, render_h );
1216 //called to get the screen in a mode compatible with popup menus.
1217 //if we can't have popups over the game screen, switch to menu mode.
1218 void set_popup_screen(void)
1220 //WIN(LoadCursorWin(MOUSE_DEFAULT_CURSOR));
1222 if (! (VR_screen_flags & VRF_COMPATIBLE_MENUS))
1223 set_screen_mode(SCREEN_MENU); //must switch to menu mode
1227 //called to change the screen mode. Parameter sm is the new mode, one of
1228 //SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
1229 //mode if cannot init requested mode)
1230 int set_screen_mode(int sm)
1232 WIN(static int force_mode_change=0);
1233 WIN(static int saved_window_w);
1234 WIN(static int saved_window_h);
1237 if ( (sm==SCREEN_MENU) && (Screen_mode==SCREEN_EDITOR) ) {
1238 gr_set_current_canvas( Canv_editor );
1244 if ( Screen_mode == sm && W95DisplayMode == VR_screen_mode) {
1245 dd_gr_set_current_canvas( &dd_VR_screen_pages[VR_current_page] );
1249 if ( Screen_mode == sm && VGA_current_mode == VR_screen_mode) {
1250 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1256 if ((Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != VR_screen_mode) && (Screen_mode == SCREEN_GAME))) {
1257 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1258 ogl_set_screen_mode();
1269 switch( Screen_mode )
1273 //mouse_set_mode(0);
1275 if (!(VR_screen_flags & VRF_COMPATIBLE_MENUS)) {
1276 // HACK!!! Meant to save window size when switching from
1277 // non-compat menu mode to menu mode.
1278 saved_window_w = Game_window_w;
1279 saved_window_h = Game_window_h;
1280 force_mode_change = 1;
1282 if (W95DisplayMode != SM95_640x480x8) {
1283 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
1284 DDSETDISPLAYMODE(SM95_640x480x8);
1285 dd_gr_init_screen();
1286 if (!gr_palette_faded_out) gr_palette_load(gr_palette);
1289 dd_gr_init_sub_canvas(&dd_VR_screen_pages[0], dd_grd_screencanv,
1291 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
1292 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
1293 dd_gr_init_sub_canvas(&dd_VR_screen_pages[1], dd_grd_screencanv,
1295 dd_grd_screencanv->canvas.cv_bitmap.bm_w,
1296 dd_grd_screencanv->canvas.cv_bitmap.bm_h);
1298 FontHires = FontHiresAvailable;
1304 MenuHires = MenuHiresAvailable; //do highres if we can
1306 #if defined(POLY_ACC)
1308 menu_mode = MenuHires?SM(640,480):SM(320,200);
1310 menu_mode = PAEnabled?SM_640x480x15xPA:SM_640x480V;
1313 menu_mode = MenuHires?SM(640,480):SM(320,200);
1316 if (VGA_current_mode != menu_mode) {
1317 if (gr_set_mode(menu_mode))
1318 Error("Cannot set screen mode for menu");
1319 if (!gr_palette_faded_out)
1320 gr_palette_load(gr_palette);
1323 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1324 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1326 FontHires = FontHiresAvailable && MenuHires;
1334 //mouse_set_mode(1);
1336 if (force_mode_change || (W95DisplayMode != VR_screen_mode)) {
1338 DDSETDISPLAYMODE(VR_screen_mode);
1339 //@@ piggy_bitmap_page_out_all_w(); // 2D GFX Flush cache.
1340 dd_gr_init_screen();
1341 mprintf((0, "Reinitializing render buffers due to display mode change.\n"));
1342 game_init_render_buffers(W95DisplayMode,
1343 GRMODEINFO(rw), GRMODEINFO(rh),
1344 VR_render_mode, VR_screen_flags);
1349 if (VGA_current_mode != VR_screen_mode) {
1350 if (gr_set_mode(VR_screen_mode)) {
1351 Error("Cannot set desired screen mode for game!");
1352 //we probably should do something else here, like select a standard mode
1355 if ( (Config_control_type == 1) && (Function_mode == FMODE_GAME) )
1356 joydefs_calibrate();
1362 if ( VR_render_mode == VR_NONE )
1364 max_window_w = grd_curscreen->sc_w;
1365 max_window_h = grd_curscreen->sc_h;
1367 if (VR_screen_flags & VRF_ALLOW_COCKPIT) {
1368 if (Cockpit_mode == CM_STATUS_BAR)
1369 max_window_h = grd_curscreen->sc_h - GameBitmaps[cockpit_bitmap[CM_STATUS_BAR+(Current_display_mode?(Num_cockpits/2):0)].index].bm_h;
1371 else if (Cockpit_mode != CM_LETTERBOX)
1372 Cockpit_mode = CM_FULL_SCREEN;
1374 if (Game_window_h==0 || Game_window_h > max_window_h || Game_window_w==0 || Game_window_w > max_window_w) {
1375 Game_window_w = max_window_w;
1376 Game_window_h = max_window_h;
1381 Cockpit_mode = CM_FULL_SCREEN;
1384 // Super hack. If we are switching from a 320x200 game to 640x480.
1385 // and we were in a menumode when switching, we don't
1386 // restore Game_window vals
1387 if (force_mode_change && (W95DisplayMode == SM95_320x200x8X)) {
1388 Game_window_w = saved_window_w;
1389 Game_window_h = saved_window_h;
1390 force_mode_change = 0;
1395 // Define screen pages for game mode
1396 // If we designate through screen_flags to use paging, then do so.
1398 dd_gr_init_sub_canvas( &dd_VR_screen_pages[0], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1399 gr_init_sub_canvas( &VR_screen_pages[0], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1402 if ( VR_screen_flags&VRF_USE_PAGING ) {
1404 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_backcanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1405 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 )
1410 dd_gr_init_sub_canvas( &dd_VR_screen_pages[1], dd_grd_screencanv, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h ),
1411 gr_init_sub_canvas( &VR_screen_pages[1], &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h )
1418 FontHires = FontHiresAvailable && (Current_display_mode != 0);
1421 FontHires = FontHiresAvailable && (MenuHires = ((Current_display_mode != 0) && (Current_display_mode != 2)));
1424 if ( VR_render_mode != VR_NONE ) {
1425 // for 640x480 or higher, use hires font.
1426 if (FontHiresAvailable && (grd_curscreen->sc_h > 400))
1436 if (grd_curscreen->sc_mode != SM(800,600)) {
1438 if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
1439 Warning("Cannot init editor screen (error=%d)",gr_error);
1443 gr_palette_load( gr_palette );
1445 gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
1446 Canv_editor = &VR_editor_canvas;
1447 gr_init_sub_canvas( &VR_screen_pages[0], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1448 gr_init_sub_canvas( &VR_screen_pages[1], Canv_editor, 0, 0, Canv_editor->cv_w, Canv_editor->cv_h );
1449 gr_set_current_canvas( Canv_editor );
1450 init_editor_screen(); //setup other editor stuff
1454 Error("Invalid screen mode %d",sm);
1457 VR_current_page = 0;
1460 dd_gr_set_current_canvas(&dd_VR_screen_pages[VR_current_page]),
1461 gr_set_current_canvas( &VR_screen_pages[VR_current_page] )
1464 if ( VR_screen_flags&VRF_USE_PAGING ) {
1467 gr_show_canvas( &VR_screen_pages[VR_current_page] )
1471 ogl_set_screen_mode();
1477 int gr_toggle_fullscreen_game(void){
1478 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1480 hud_message(MSGC_GAME_FEEDBACK, "toggling fullscreen mode %s",(i=gr_toggle_fullscreen())?"on":"off" );
1481 //added 2000/06/19 Matthew Mueller - hack to fix "infinite toggle" problem
1482 //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.
1483 // generic_key_handler(KEY_PADENTER,0);
1488 hud_message(MSGC_GAME_FEEDBACK, "fullscreen toggle not supported by this target");
1493 int arch_toggle_fullscreen_menu(void);
1495 int gr_toggle_fullscreen_menu(void){
1496 #ifdef GR_SUPPORTS_FULLSCREEN_MENU_TOGGLE
1498 i=arch_toggle_fullscreen_menu();
1500 // generic_key_handler(KEY_PADENTER,0);
1509 static int timer_paused=0;
1513 if (timer_paused==0) {
1515 time = timer_get_fixed_seconds();
1516 last_timer_value = time - last_timer_value;
1517 if (last_timer_value < 0) {
1518 #if defined(TIMER_TEST) && !defined(NDEBUG)
1519 Int3(); //get Matt!!!!
1521 last_timer_value = 0;
1523 #if defined(TIMER_TEST) && !defined(NDEBUG)
1524 time_stopped = time;
1529 #if defined(TIMER_TEST) && !defined(NDEBUG)
1537 Assert(timer_paused >= 0);
1538 if (timer_paused==0) {
1540 time = timer_get_fixed_seconds();
1541 #if defined(TIMER_TEST) && !defined(NDEBUG)
1542 if (last_timer_value < 0)
1543 Int3(); //get Matt!!!!
1546 last_timer_value = time - last_timer_value;
1547 #if defined(TIMER_TEST) && !defined(NDEBUG)
1548 time_started = time;
1552 #if defined(TIMER_TEST) && !defined(NDEBUG)
1557 MAC(extern ubyte joydefs_calibrating;)
1559 void game_flush_inputs()
1566 if ( (Function_mode != FMODE_MENU) && !joydefs_calibrating ) // only reset mouse when not in menu or not calibrating
1568 mouse_get_delta( &dx, &dy ); // Read mouse
1569 memset(&Controls,0,sizeof(control_info));
1574 last_timer_value = timer_get_fixed_seconds();
1579 extern int Saving_movie_frames;
1580 int Movie_fixed_frametime;
1582 #define Saving_movie_frames 0
1583 #define Movie_fixed_frametime 0
1586 //added on 8/18/98 by Victor Rachels to add maximum framerate
1590 void calc_frame_time()
1592 fix timer_value,last_frametime = FrameTime;
1594 #if defined(TIMER_TEST) && !defined(NDEBUG)
1595 _last_frametime = last_frametime;
1598 timer_value = timer_get_fixed_seconds();
1599 FrameTime = timer_value - last_timer_value;
1602 timer_value = timer_get_fixed_seconds();
1603 FrameTime = timer_value - last_timer_value;
1604 if (FrameTime < f1_0/maxfps);
1606 } while (FrameTime < f1_0/maxfps);
1608 #if defined(TIMER_TEST) && !defined(NDEBUG)
1609 _timer_value = timer_value;
1613 if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) {
1614 mprintf((1,"Bad FrameTime - value = %x\n",FrameTime));
1616 Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed!
1617 // if ( !dpmi_virtual_memory )
1618 // Int3(); //Get MATT if hit this!
1622 #if defined(TIMER_TEST) && !defined(NDEBUG)
1623 actual_last_timer_value = last_timer_value;
1626 if ( Game_turbo_mode )
1629 // Limit frametime to be between 5 and 150 fps.
1630 RealFrameTime = FrameTime;
1631 if ( FrameTime < F1_0/150 ) FrameTime = F1_0/150;
1632 if ( FrameTime > F1_0/5 ) FrameTime = F1_0/5;
1634 last_timer_value = timer_value;
1636 if (FrameTime < 0) //if bogus frametime...
1637 FrameTime = last_frametime; //...then use time from last frame
1640 if (fixed_frametime) FrameTime = fixed_frametime;
1645 if ( Debug_pause ) {
1655 last_timer_value = timer_get_fixed_seconds();
1663 #if defined(TIMER_TEST) && !defined(NDEBUG)
1664 stop_count = start_count = 0;
1667 // Set value to determine whether homing missile can see target.
1668 // The lower frametime is, the more likely that it can see its target.
1669 if (FrameTime <= F1_0/64)
1670 Min_trackable_dot = MIN_TRACKABLE_DOT; // -- 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT;
1671 else if (FrameTime < F1_0/32)
1672 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - 2*FrameTime; // -- fixmul(F1_0 - MIN_TRACKABLE_DOT, F1_0-4*FrameTime) + MIN_TRACKABLE_DOT;
1673 else if (FrameTime < F1_0/4)
1674 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;
1676 Min_trackable_dot = MIN_TRACKABLE_DOT + F1_0/64 - F1_0/8;
1680 //--unused-- int Auto_flythrough=0; //if set, start flythough automatically
1682 void move_player_2_segment(segment *seg,int side)
1686 compute_segment_center(&ConsoleObject->pos,seg);
1687 compute_center_point_on_side(&vp,seg,side);
1688 vm_vec_sub2(&vp,&ConsoleObject->pos);
1689 vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
1691 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
1696 void game_draw_time_left()
1698 char temp_string[30];
1702 gr_set_curfont( GAME_FONT ); //GAME_FONT
1703 gr_set_fontcolor(gr_getcolor(0,63,0), -1 );
1705 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1706 i=f2i(timevar-ThisLevelTime);
1709 sprintf( temp_string, "Time left: %d secs", i );
1712 gr_string(0, 32, temp_string );
1717 extern int Game_pause;
1720 void level_with_floor();
1722 void modex_clear_box(int x,int y,int w,int h)
1724 grs_canvas *temp_canv,*save_canv;
1726 save_canv = grd_curcanv;
1727 temp_canv = gr_create_canvas(w,h);
1728 gr_set_current_canvas(temp_canv);
1729 gr_clear_canvas(BM_XRGB(0,0,0));
1730 gr_set_current_canvas(save_canv);
1731 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
1732 gr_free_canvas(temp_canv);
1736 extern void modex_printf(int x,int y,char *s,grs_font *font,int color);
1738 // mac routine to drop contents of screen to a pict file using copybits
1739 // save a PICT to a file
1742 void SavePictScreen(int multiplayer)
1745 int parid, i, count;
1746 char *pfilename, filename[50], buf[512], cwd[FILENAME_MAX];
1749 PicHandle pict_handle;
1750 static int multi_count = 0;
1751 StandardFileReply sf_reply;
1753 // dump the contents of the GameWindow into a picture using copybits
1755 pict_handle = OpenPicture(&GameWindow->portRect);
1756 if (pict_handle == NULL)
1759 CopyBits(&GameWindow->portBits, &GameWindow->portBits, &GameWindow->portRect, &GameWindow->portRect, srcBic, NULL);
1762 // get the cwd to restore with chdir when done -- this keeps the mac world sane
1763 if (!getcwd(cwd, FILENAME_MAX))
1765 // create the fsspec
1767 sprintf(filename, "screen%d", multi_count++);
1768 pfilename = c2pstr(filename);
1771 StandardPutFile("\pSave PICT as:", pfilename, &sf_reply);
1772 if (!sf_reply.sfGood)
1774 memcpy( &spec, &(sf_reply.sfFile), sizeof(FSSpec) );
1775 if (sf_reply.sfReplacing)
1777 err = FSpCreate( &spec, 'ttxt', 'PICT', smSystemScript );
1781 // parid = GetAppDirId();
1782 err = FSMakeFSSpec(0, 0, pfilename, &spec);
1787 err = FSpCreate(&spec, 'ttxt', 'PICT', smSystemScript);
1792 // write the PICT file
1793 if ( FSpOpenDF(&spec, fsRdWrPerm, &fd) )
1795 memset(buf, 0, sizeof(buf));
1797 if ( FSWrite(fd, &count, buf) )
1799 count = GetHandleSize((Handle)pict_handle);
1800 HLock((Handle)pict_handle);
1801 if ( FSWrite(fd, &count, *pict_handle) ) {
1807 HUnlock((Handle)pict_handle);
1808 DisposeHandle((Handle)pict_handle);
1816 //automap_flag is now unused, since we just check if the screen we're
1817 //writing to is modex
1818 //if called from automap, current canvas is set to visible screen
1820 void save_screen_shot(int automap_flag)
1822 #if defined(WINDOWS)
1823 mprintf((0, "Doing screen shot thing.\n"));
1824 win95_save_pcx_shot();
1826 #elif !defined(MACINTOSH)
1829 grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
1830 grs_font *save_font;
1831 static int savenum=0;
1832 static int stereo_savenum=0;
1833 grs_canvas *temp_canv,*temp_canv2,*save_canv;
1834 char savename[FILENAME_LEN],savename2[FILENAME_LEN];
1842 // // Can't do screen shots in VR modes.
1843 // if ( VR_render_mode != VR_NONE )
1848 save_canv = grd_curcanv;
1850 if ( VR_render_mode != VR_NONE && !automap_flag && Function_mode==FMODE_GAME && Screen_mode==SCREEN_GAME)
1854 temp_canv = gr_create_canvas(VR_render_buffer[0].cv_bitmap.bm_w,VR_render_buffer[0].cv_bitmap.bm_h);
1855 gr_set_current_canvas(temp_canv);
1856 gr_ubitmap(0,0,&VR_render_buffer[0].cv_bitmap);
1858 temp_canv2 = gr_create_canvas(VR_render_buffer[1].cv_bitmap.bm_w,VR_render_buffer[1].cv_bitmap.bm_h);
1859 gr_set_current_canvas(temp_canv2);
1860 gr_ubitmap(0,0,&VR_render_buffer[1].cv_bitmap);
1863 temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
1864 gr_set_current_canvas(temp_canv);
1865 gr_ubitmap(0,0,&screen_canv->cv_bitmap);
1868 gr_set_current_canvas(save_canv);
1870 if ( savenum > 99 ) savenum = 0;
1871 if ( stereo_savenum > 99 ) stereo_savenum = 0;
1874 sprintf(savename,"left%02d.pcx",stereo_savenum);
1875 sprintf(savename2,"right%02d.pcx",stereo_savenum);
1876 if (VR_eye_switch) {char t[FILENAME_LEN]; strcpy(t,savename); strcpy(savename,savename2); strcpy(savename2,t);}
1878 sprintf( message, "%s '%s' & '%s'", TXT_DUMPING_SCREEN, savename, savename2 );
1881 sprintf(savename,"screen%02d.pcx",savenum++);
1882 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
1885 if (!automap_flag) //if from automap, curcanv is already visible canv
1886 gr_set_current_canvas(NULL);
1887 modex_flag = (grd_curcanv->cv_bitmap.bm_type==BM_MODEX);
1888 if (!automap_flag && modex_flag)
1889 gr_set_current_canvas(&VR_screen_pages[VR_current_page]);
1891 save_font = grd_curcanv->cv_font;
1892 gr_set_curfont(GAME_FONT);
1893 gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
1894 gr_get_string_size(message,&w,&h,&aw);
1899 //I changed how these coords were calculated for the high-res automap. -MT
1900 //x = (VR_screen_pages[VR_current_page].cv_w-w)/2;
1901 //y = (VR_screen_pages[VR_current_page].cv_h-h)/2;
1902 x = (grd_curcanv->cv_w-w)/2;
1903 y = (grd_curcanv->cv_h-h)/2;
1906 modex_clear_box(x-2,y-2,w+4,h+4);
1907 modex_printf(x, y, message,GAME_FONT,gr_find_closest_color_current(0,31,0));
1909 gr_setcolor(gr_find_closest_color_current(0,0,0));
1910 gr_rect(x-2,y-2,x+w+2,y+h+2);
1911 gr_printf(x,y,message);
1912 gr_set_curfont(save_font);
1914 t1 = timer_get_fixed_seconds() + F1_0;
1916 gr_palette_read(pal); //get actual palette from the hardware
1917 pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
1919 pcx_write_bitmap(savename2,&temp_canv2->cv_bitmap,pal);
1921 while ( timer_get_fixed_seconds() < t1 ); // Wait so that messag stays up at least 1 second.
1923 gr_set_current_canvas(screen_canv);
1925 if (grd_curcanv->cv_bitmap.bm_type!=BM_MODEX && !stereo)
1926 gr_ubitmap(0,0,&temp_canv->cv_bitmap);
1928 gr_free_canvas(temp_canv);
1930 gr_free_canvas(temp_canv2);
1932 gr_set_current_canvas(save_canv);
1938 grs_canvas *screen_canv = &grd_curscreen->sc_canvas;
1939 grs_canvas *temp_canv, *save_canv;
1941 // Can't do screen shots in VR modes.
1942 if ( VR_render_mode != VR_NONE )
1947 save_canv = grd_curcanv;
1948 temp_canv = gr_create_canvas( screen_canv->cv_bitmap.bm_w, screen_canv->cv_bitmap.bm_h );
1951 gr_set_current_canvas( temp_canv );
1952 gr_ubitmap( 0, 0, &screen_canv->cv_bitmap );
1953 gr_set_current_canvas( &VR_screen_pages[VR_current_page] );
1957 if (Game_mode & GM_MULTI)
1964 gr_set_current_canvas(screen_canv);
1966 // if (!automap_flag)
1967 gr_ubitmap( 0, 0, &temp_canv->cv_bitmap);
1969 gr_free_canvas(temp_canv);
1971 gr_set_current_canvas(save_canv);
1980 void fly_init(object *obj)
1982 obj->control_type = CT_FLYING;
1983 obj->movement_type = MT_PHYSICS;
1985 vm_vec_zero(&obj->mtype.phys_info.velocity);
1986 vm_vec_zero(&obj->mtype.phys_info.thrust);
1987 vm_vec_zero(&obj->mtype.phys_info.rotvel);
1988 vm_vec_zero(&obj->mtype.phys_info.rotthrust);
1991 //void morph_test(), morph_step();
1994 // ------------------------------------------------------------------------------------
1996 void test_anim_states();
2000 //put up the help message
2007 extern int been_in_editor;
2009 // ------------------------------------------------------------------------------------
2010 void do_cloak_stuff(void)
2013 for (i = 0; i < N_players; i++)
2014 if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
2015 // mprintf(0, "Cloak time left: %7.3f\n", f2fl(CLOAK_TIME_MAX - (GameTime - Players[Player_num].cloak_time)));
2016 if (GameTime - Players[i].cloak_time > CLOAK_TIME_MAX) {
2017 Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
2018 if (i == Player_num) {
2019 digi_play_sample( SOUND_CLOAK_OFF, F1_0);
2021 if (Game_mode & GM_MULTI)
2022 multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
2023 maybe_drop_net_powerup(POW_CLOAK);
2024 multi_send_decloak(); // For demo recording
2026 // mprintf((0, " --- You have been DE-CLOAKED! ---\n"));
2034 // ------------------------------------------------------------------------------------
2035 void do_invulnerable_stuff(void)
2037 if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
2038 if (GameTime - Players[Player_num].invulnerable_time > INVULNERABLE_TIME_MAX) {
2039 Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
2042 digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
2044 if (Game_mode & GM_MULTI)
2046 multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
2047 maybe_drop_net_powerup(POW_INVULNERABILITY);
2050 mprintf((0, " --- You have been DE-INVULNERABLEIZED! ---\n"));
2057 ubyte Last_afterburner_state = 0;
2058 fix Last_afterburner_charge = 0;
2060 #define AFTERBURNER_LOOP_START ((digi_sample_rate==SAMPLE_RATE_22K)?32027:(32027/2)) //20098
2061 #define AFTERBURNER_LOOP_END ((digi_sample_rate==SAMPLE_RATE_22K)?48452:(48452/2)) //25776
2065 //@@// ------------------------------------------------------------------------------------
2066 //@@void afterburner_shake(void)
2070 //@@ rx = (Ab_scale * fixmul(d_rand() - 16384, F1_0/8 + (((GameTime + 0x4000)*4) & 0x3fff)))/16;
2071 //@@ rz = (Ab_scale * fixmul(d_rand() - 16384, F1_0/2 + ((GameTime*4) & 0xffff)))/16;
2073 //@@ // -- mprintf((0, "AB: %8x %8x\n", rx, rz));
2074 //@@ ConsoleObject->mtype.phys_info.rotvel.x += rx;
2075 //@@ ConsoleObject->mtype.phys_info.rotvel.z += rz;
2079 // ------------------------------------------------------------------------------------
2081 extern void multi_send_sound_function (char,char);
2084 void do_afterburner_stuff(void)
2086 if (!(Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER))
2087 Afterburner_charge=0;
2089 if (Endlevel_sequence || Player_is_dead)
2091 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
2093 multi_send_sound_function (0,0);
2097 if ((Controls.afterburner_state != Last_afterburner_state && Last_afterburner_charge) || (Last_afterburner_state && Last_afterburner_charge && !Afterburner_charge)) {
2099 if (Afterburner_charge && Controls.afterburner_state && (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)) {
2100 digi_link_sound_to_object3( SOUND_AFTERBURNER_IGNITE, Players[Player_num].objnum, 1, F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END );
2102 if (Game_mode & GM_MULTI)
2103 multi_send_sound_function (3,SOUND_AFTERBURNER_IGNITE);
2106 digi_kill_sound_linked_to_object( Players[Player_num].objnum);
2107 digi_link_sound_to_object2( SOUND_AFTERBURNER_PLAY, Players[Player_num].objnum, 0, F1_0, i2f(256));
2109 if (Game_mode & GM_MULTI)
2110 multi_send_sound_function (0,0);
2112 mprintf((0,"Killing afterburner sound\n"));
2116 //@@if (Controls.afterburner_state && Afterburner_charge)
2117 //@@ afterburner_shake();
2119 Last_afterburner_state = Controls.afterburner_state;
2120 Last_afterburner_charge = Afterburner_charge;
2123 // -- // ------------------------------------------------------------------------------------
2124 // -- // if energy < F1_0/2, recharge up to F1_0/2
2125 // -- void recharge_energy_frame(void)
2127 // -- if (Players[Player_num].energy < Weapon_info[0].energy_usage) {
2128 // -- Players[Player_num].energy += FrameTime/4;
2130 // -- if (Players[Player_num].energy > Weapon_info[0].energy_usage)
2131 // -- Players[Player_num].energy = Weapon_info[0].energy_usage;
2135 // Amount to diminish guns towards normal, per second.
2136 #define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
2138 extern fix Flash_effect;
2140 //adds to rgb values for palette flash
2141 void PALETTE_FLASH_ADD(int _dr,int _dg,int _db)
2145 PaletteRedAdd += _dr;
2146 PaletteGreenAdd += _dg;
2147 PaletteBlueAdd += _db;
2149 // -- mprintf((0, "Palette add: %3i %3i %3i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd));
2154 maxval = MAX_PALETTE_ADD;
2156 if (PaletteRedAdd > maxval)
2157 PaletteRedAdd = maxval;
2159 if (PaletteGreenAdd > maxval)
2160 PaletteGreenAdd = maxval;
2162 if (PaletteBlueAdd > maxval)
2163 PaletteBlueAdd = maxval;
2165 if (PaletteRedAdd < -maxval)
2166 PaletteRedAdd = -maxval;
2168 if (PaletteGreenAdd < -maxval)
2169 PaletteGreenAdd = -maxval;
2171 if (PaletteBlueAdd < -maxval)
2172 PaletteBlueAdd = -maxval;
2175 fix Time_flash_last_played;
2178 void game_palette_step_up( int r, int g, int b );
2179 // ------------------------------------------------------------------------------------
2180 // Diminish palette effects towards normal.
2181 void diminish_palette_towards_normal(void)
2185 // Diminish at DIMINISH_RATE units/second.
2186 // For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
2187 if (FrameTime < F1_0/DIMINISH_RATE) {
2188 if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
2191 dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
2192 if (dec_amount == 0)
2193 dec_amount++; // make sure we decrement by something
2199 // Part of hack system to force update of palette after exiting a menu.
2200 if (Time_flash_last_played) {
2202 PaletteRedAdd ^= 1; // Very Tricky! In gr_palette_step_up, if all stepups same as last time, won't do anything!
2205 if ((Time_flash_last_played + F1_0/8 < GameTime) || (Time_flash_last_played > GameTime)) {
2206 digi_play_sample( SOUND_CLOAK_OFF, Flash_effect/4);
2207 Time_flash_last_played = GameTime;
2210 Flash_effect -= FrameTime;
2211 if (Flash_effect < 0)
2214 if (force_do || (d_rand() > 4096 )) {
2215 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
2216 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2218 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2225 if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
2226 if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
2228 if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
2229 if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
2231 if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
2232 if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
2234 if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
2235 newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2237 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2239 //mprintf(0, "%2i %2i %2i\n", PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
2242 int Redsave, Bluesave, Greensave;
2244 void palette_save(void)
2246 Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
2249 extern void gr_palette_step_up_vr( int r, int g, int b, int white, int black );
2251 void game_palette_step_up( int r, int g, int b )
2253 if ( VR_use_reg_code ) {
2255 // gr_palette_step_up_vr( r, g, b, VR_WHITE_INDEX, VR_BLACK_INDEX );
2258 gr_palette_step_up( r, g, b );
2262 void palette_restore(void)
2264 PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
2265 game_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
2267 // Forces flash effect to fixup palette next frame.
2268 Time_flash_last_played = 0;
2271 extern void dead_player_frame(void);
2274 // --------------------------------------------------------------------------------------------------
2275 int allowed_to_fire_laser(void)
2277 if (Player_is_dead) {
2278 Global_missile_firing_count = 0;
2282 // Make sure enough time has elapsed to fire laser, but if it looks like it will
2283 // be a long while before laser can be fired, then there must be some mistake!
2284 if (Next_laser_fire_time > GameTime)
2285 if (Next_laser_fire_time < GameTime + 2*F1_0)
2291 fix Next_flare_fire_time = 0;
2292 #define FLARE_BIG_DELAY (F1_0*2)
2294 int allowed_to_fire_flare(void)
2296 if (Next_flare_fire_time > GameTime)
2297 if (Next_flare_fire_time < GameTime + FLARE_BIG_DELAY) // In case time is bogus, never wait > 1 second.
2300 if (Players[Player_num].energy >= Weapon_info[FLARE_ID].energy_usage)
2301 Next_flare_fire_time = GameTime + F1_0/4;
2303 Next_flare_fire_time = GameTime + FLARE_BIG_DELAY;
2308 int allowed_to_fire_missile(void)
2310 // mprintf(0, "Next fire = %7.3f, Cur time = %7.3f\n", f2fl(Next_missile_fire_time), f2fl(GameTime));
2311 // Make sure enough time has elapsed to fire missile, but if it looks like it will
2312 // be a long while before missile can be fired, then there must be some mistake!
2313 if (Next_missile_fire_time > GameTime)
2314 if (Next_missile_fire_time < GameTime + 5*F1_0)
2320 void full_palette_save(void)
2323 apply_modified_palette();
2324 reset_palette_add();
2325 gr_palette_load( gr_palette );
2328 extern int Death_sequence_aborted;
2329 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) );
2336 char command_help[64], pixel_double_help[64], save_help[64], restore_help[64];
2339 m[ 0].type = NM_TYPE_TEXT; m[ 0].text = TXT_HELP_ESC;
2341 m[ 1].type = NM_TYPE_TEXT; m[ 1].text = TXT_HELP_ALT_F2;
2342 m[ 2].type = NM_TYPE_TEXT; m[ 2].text = TXT_HELP_ALT_F3;
2344 sprintf(save_help, "OPT-F2 (%c-s)\t Save Game", 133);
2345 sprintf(restore_help, "OPT-F3 (%c-o)\t Load Game", 133);
2346 m[ 1].type = NM_TYPE_TEXT; m[1].text = save_help;
2347 m[ 2].type = NM_TYPE_TEXT; m[2].text = restore_help;
2349 m[ 3].type = NM_TYPE_TEXT; m[ 3].text = TXT_HELP_F2;
2350 m[ 4].type = NM_TYPE_TEXT; m[ 4].text = TXT_HELP_F3;
2351 m[ 5].type = NM_TYPE_TEXT; m[ 5].text = TXT_HELP_F4;
2352 m[ 6].type = NM_TYPE_TEXT; m[ 6].text = TXT_HELP_F5;
2354 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = TXT_HELP_PAUSE;
2356 m[ 7].type = NM_TYPE_TEXT; m[ 7].text = "Pause (F15)\t Pause";
2358 m[ 8].type = NM_TYPE_TEXT; m[ 8].text = TXT_HELP_MINUSPLUS;
2360 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = TXT_HELP_PRTSCN;
2362 m[ 9].type = NM_TYPE_TEXT; m[ 9].text = "printscrn (F13)\t save screen shot";
2364 m[10].type = NM_TYPE_TEXT; m[10].text = TXT_HELP_1TO5;
2365 m[11].type = NM_TYPE_TEXT; m[11].text = TXT_HELP_6TO10;
2366 m[12].type = NM_TYPE_TEXT; m[12].text = "Shift-F1\t Cycle left window";
2367 m[13].type = NM_TYPE_TEXT; m[13].text = "Shift-F2\t Cycle right window";
2368 m[14].type = NM_TYPE_TEXT; m[14].text = "Shift-F4\t GuideBot menu";
2370 m[15].type = NM_TYPE_TEXT; m[15].text = "Alt-Shift-F4\t Rename GuideBot";
2372 m[15].type = NM_TYPE_TEXT; m[15].text = "Opt-Shift-F4\t Rename GuideBot";
2374 m[16].type = NM_TYPE_TEXT; m[16].text = "Shift-F5\t Drop primary";
2375 m[17].type = NM_TYPE_TEXT; m[17].text = "Shift-F6\t Drop secondary";
2376 m[18].type = NM_TYPE_TEXT; m[18].text = "Shift-F7\t Calibrate joystick";
2377 m[19].type = NM_TYPE_TEXT; m[19].text = "Shift-number\t GuideBot commands";
2380 sprintf(pixel_double_help, "%c-D\t Toggle Pixel Double Mode", 133);
2381 m[20].type = NM_TYPE_TEXT; m[20].text = pixel_double_help;
2382 m[21].type = NM_TYPE_TEXT; m[21].text = "";
2383 sprintf(command_help, "(Use %c-# for F#. i.e. %c-1 for F1)", 133, 133);
2384 m[22].type = NM_TYPE_TEXT; m[22].text = command_help;
2388 full_palette_save();
2390 newmenu_dotiny2( NULL, TXT_KEYS, nitems, m, NULL );
2395 //temp function until Matt cleans up game sequencing
2396 extern void temp_reset_stuff_on_level();
2398 //deal with rear view - switch it on, or off, or whatever
2399 void check_rear_view()
2402 #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000)
2404 static int leave_mode;
2405 static fix entry_time;
2407 if ( Controls.rear_view_down_count ) { //key/button has gone down
2411 if (Cockpit_mode==CM_REAR_VIEW) {
2412 select_cockpit(Cockpit_mode_save);
2413 Cockpit_mode_save = -1;
2415 if (Newdemo_state == ND_STATE_RECORDING)
2416 newdemo_record_restore_rearview();
2420 leave_mode = 0; //means wait for another key
2421 entry_time = timer_get_fixed_seconds();
2422 if (Cockpit_mode == CM_FULL_COCKPIT) {
2423 Cockpit_mode_save = Cockpit_mode;
2424 select_cockpit(CM_REAR_VIEW);
2426 if (Newdemo_state == ND_STATE_RECORDING)
2427 newdemo_record_rearview();
2431 if (Controls.rear_view_down_state) {
2433 if (leave_mode==0 && (timer_get_fixed_seconds()-entry_time)>LEAVE_TIME)
2438 //@@if (leave_mode==1 && Cockpit_mode==CM_REAR_VIEW) {
2440 if (leave_mode==1 && Rear_view) {
2442 if (Cockpit_mode==CM_REAR_VIEW) {
2443 select_cockpit(Cockpit_mode_save);
2444 Cockpit_mode_save = -1;
2446 if (Newdemo_state == ND_STATE_RECORDING)
2447 newdemo_record_restore_rearview();
2452 void reset_rear_view(void)
2455 if (Newdemo_state == ND_STATE_RECORDING)
2456 newdemo_record_restore_rearview();
2461 if (!(Cockpit_mode == CM_FULL_COCKPIT || Cockpit_mode == CM_STATUS_BAR || Cockpit_mode == CM_FULL_SCREEN)) {
2462 if (!(Cockpit_mode_save == CM_FULL_COCKPIT || Cockpit_mode_save == CM_STATUS_BAR || Cockpit_mode_save == CM_FULL_SCREEN))
2463 Cockpit_mode_save = CM_FULL_COCKPIT;
2464 select_cockpit(Cockpit_mode_save);
2465 Cockpit_mode_save = -1;
2471 int Config_menu_flag;
2475 int Cheats_enabled=0;
2477 extern int Laser_rapid_fire;
2478 extern void do_lunacy_on(), do_lunacy_off();
2480 extern int Physics_cheat_flag,Robots_kill_robots_cheat;
2481 extern char BounceCheat,HomingCheat,OldHomingState[20];
2482 extern char AcidCheatOn,old_IntMethod, Monster_mode;
2483 extern int Buddy_dude_cheat;
2485 //turns off active cheats
2486 void turn_cheats_off()
2492 Weapon_info[i].homing_flag=OldHomingState[i];
2497 Interpolation_method=old_IntMethod;
2500 Buddy_dude_cheat = 0;
2504 Laser_rapid_fire = 0;
2505 Physics_cheat_flag = 0;
2507 Robots_kill_robots_cheat=0;
2508 Robot_firing_enabled = 1;
2511 //turns off all cheats & resets cheater flag
2512 void game_disable_cheats()
2520 // ----------------------------------------------------------------------------
2522 void game_setup(void)
2524 //@@int demo_playing=0;
2525 //@@int multi_game=0;
2527 do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
2528 do_lunacy_off(); // Restore true insane mode.
2531 last_drawn_cockpit[0] = -1; // Force cockpit to redraw next time a frame renders.
2532 last_drawn_cockpit[1] = -1; // Force cockpit to redraw next time a frame renders.
2533 Endlevel_sequence = 0;
2535 //@@if ( Newdemo_state == ND_STATE_PLAYBACK )
2536 //@@ demo_playing = 1;
2537 //@@if ( Game_mode & GM_MULTI )
2538 //@@ multi_game = 1;
2540 set_screen_mode(SCREEN_GAME);
2541 reset_palette_add();
2543 set_warn_func(game_show_warning);
2547 //digi_init_sounds();
2549 //keyd_repeat = 0; // Don't allow repeat in game
2550 keyd_repeat = 1; // Do allow repeat in game
2552 #if !defined(WINDOWS) && !defined(MACINTOSH)
2553 //_MARK_("start of game");
2557 if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
2558 obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2560 if (!check_obj_seg(ConsoleObject))
2561 move_player_2_segment(Cursegp,Curside);
2564 Viewer = ConsoleObject;
2565 fly_init(ConsoleObject);
2570 FrameTime = 0; //make first frame zero
2573 if (Current_level_num == 0) { //not a real level
2574 init_player_stats_game();
2581 game_flush_inputs();
2587 extern char IWasKicked;
2591 // ------------------------------------------------------------------------------------
2592 //this function is the game. called when game mode selected. runs until
2593 //editor mode or exit selected
2596 game_setup(); // Replaces what was here earlier.
2597 // Good for Windows Sake.
2600 ProfilerSetStatus(1);
2603 if ( setjmp(LeaveGame)==0 ) {
2609 Config_menu_flag = 0;
2611 if ( ConsoleObject != &Objects[Players[Player_num].objnum] )
2613 mprintf ((0,"Player_num=%d objnum=%d",Player_num,Players[Player_num].objnum));
2614 //Assert( ConsoleObject == &Objects[Players[Player_num].objnum] );
2617 player_shields = Players[Player_num].shields;
2622 DoMessageStuff(&msg); // Do Windows event handling.
2623 if (_RedrawScreen) {
2624 _RedrawScreen = FALSE;
2625 load_palette(Current_level_palette,1,1);
2626 gr_palette_load(gr_palette);
2631 ExtGameStatus=GAMESTAT_RUNNING;
2632 GameLoop( 1, 1 ); // Do game loop with rendering and reading controls.
2634 //if the player is taking damage, give up guided missile control
2635 if (Players[Player_num].shields != player_shields)
2636 release_guided_missile(Player_num);
2638 //see if redbook song needs to be restarted
2639 songs_check_redbook_repeat(); // Handle RedBook Audio Repeating.
2641 if (Config_menu_flag) {
2642 int double_save = Scanline_double;
2644 //WIN(mouse_set_mode(0));
2645 if (!(Game_mode&GM_MULTI)) {palette_save(); reset_palette_add(); apply_modified_palette(); gr_palette_load( gr_palette ); }
2647 if (Scanline_double != double_save) init_cockpit();
2648 if (!(Game_mode&GM_MULTI)) palette_restore();
2649 //WIN(mouse_set_mode(1));
2653 int save_w=Game_window_w,save_h=Game_window_h;
2655 Screen_mode=-1; set_screen_mode(SCREEN_GAME);
2656 Game_window_w=save_w; Game_window_h=save_h;
2658 last_drawn_cockpit[0] = -1;
2659 last_drawn_cockpit[1] = -1;
2662 if ( (Function_mode != FMODE_GAME) && Auto_demo && (Newdemo_state != ND_STATE_NORMAL) ) {
2664 fmode = Function_mode;
2665 Function_mode = FMODE_GAME;
2667 apply_modified_palette();
2668 reset_palette_add();
2669 gr_palette_load( gr_palette );
2670 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_AUTODEMO );
2672 Function_mode = fmode;
2675 newdemo_stop_playback();
2676 Function_mode = FMODE_MENU;
2678 Function_mode = FMODE_GAME;
2682 if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR)
2688 fmode = Function_mode;
2689 Function_mode = FMODE_GAME;
2691 apply_modified_palette();
2692 reset_palette_add();
2693 gr_palette_load( gr_palette );
2694 ExtGameStatus=GAMESTAT_ABORT_GAME;
2695 choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
2697 Function_mode = fmode;
2699 Function_mode = FMODE_GAME;
2705 if (Function_mode != FMODE_GAME)
2706 longjmp(LeaveGame,0);
2709 if ( (keyd_time_when_last_pressed + (F1_0 * 60)) < timer_get_fixed_seconds() ) // idle in game for 1 minutes means exit
2710 longjmp(LeaveGame,0);
2716 ProfilerSetStatus(0);
2721 if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
2722 newdemo_stop_recording();
2728 if ( Newdemo_state == ND_STATE_PLAYBACK )
2729 newdemo_stop_playback();
2731 if (Cockpit_mode_save!=-1)
2733 Cockpit_mode=Cockpit_mode_save;
2734 Cockpit_mode_save=-1;
2737 if (Function_mode != FMODE_EDITOR)
2738 gr_palette_fade_out(gr_palette,32,0); // Fade out before going to menu
2740 //@@ if ( (!demo_playing) && (!multi_game) && (Function_mode != FMODE_EDITOR)) {
2741 //@@ scores_maybe_add_player(Game_aborted);
2744 #if !defined(WINDOWS) && !defined(MACINTOSH)
2745 //_MARK_("end of game");
2748 clear_warn_func(game_show_warning); //don't use this func anymore
2750 game_disable_cheats();
2753 Function_mode = FMODE_EXIT; // get out of game in Apple OEM version
2757 //called at the end of the program
2761 if (dd_VR_offscreen_buffer) {
2762 if (dd_grd_backcanv != dd_VR_offscreen_buffer) {
2763 dd_gr_free_canvas(dd_VR_offscreen_buffer);
2765 dd_VR_offscreen_buffer = NULL;
2766 VR_offscreen_buffer = NULL;
2769 if (VR_offscreen_buffer) {
2770 gr_free_canvas(VR_offscreen_buffer);
2771 VR_offscreen_buffer = NULL;
2775 close_gauge_canvases();
2777 restore_effect_bitmap_icons();
2779 #if !defined(MACINTOSH) && !defined(WINDOWS)
2780 if (Game_cockpit_copy_code) {
2781 d_free(Game_cockpit_copy_code);
2782 Game_cockpit_copy_code = NULL;
2785 if (Game_cockpit_copy_code)
2786 Game_cockpit_copy_code = 0;
2789 if (background_bitmap.bm_data)
2790 d_free(background_bitmap.bm_data);
2792 clear_warn_func(game_show_warning); //don't use this func anymore
2796 dd_grs_canvas * get_current_game_screen()
2798 return &dd_VR_screen_pages[VR_current_page];
2803 grs_canvas * get_current_game_screen()
2805 return &VR_screen_pages[VR_current_page];
2810 extern void kconfig_center_headset();
2814 void speedtest_frame(void);
2815 int Debug_slowdown=0;
2819 extern void player_follow_path(object *objp);
2820 extern void check_create_player_path(void);
2824 extern int Do_appearance_effect;
2826 object *Missile_viewer=NULL;
2828 int Missile_view_enabled = 1;
2830 int Marker_viewer_num[2]={-1,-1};
2831 int Coop_view_player[2]={-1,-1};
2832 int Cockpit_3d_view[2]={CV_NONE,CV_NONE};
2834 //returns ptr to escort robot, or NULL
2835 object *find_escort()
2839 for (i=0; i<=Highest_object_index; i++)
2840 if (Objects[i].type == OBJ_ROBOT)
2841 if (Robot_info[Objects[i].id].companion)
2847 extern void process_super_mines_frame(void);
2848 extern void do_seismic_stuff(void);
2851 int Saving_movie_frames=0;
2852 int __Movie_frame_num=0;
2854 #define MAX_MOVIE_BUFFER_FRAMES 250
2855 #define MOVIE_FRAME_SIZE (320 * 200)
2857 ubyte *Movie_frame_buffer;
2858 int Movie_frame_counter;
2859 ubyte Movie_pal[768];
2860 char movie_path[50] = ".\\";
2862 grs_bitmap Movie_bm;
2864 void flush_movie_buffer()
2871 mprintf((0,"Flushing movie buffer..."));
2873 Movie_bm.bm_data = Movie_frame_buffer;
2875 for (f=0;f<Movie_frame_counter;f++) {
2876 sprintf(savename, "%sfrm%04d.pcx",movie_path,__Movie_frame_num);
2877 __Movie_frame_num++;
2878 pcx_write_bitmap(savename,&Movie_bm,Movie_pal);
2879 Movie_bm.bm_data += MOVIE_FRAME_SIZE;
2882 mprintf((0,"%3d/%3d\10\10\10\10\10\10\10",f,Movie_frame_counter));
2885 Movie_frame_counter=0;
2887 mprintf((0,"done \n"));
2892 void toggle_movie_saving()
2896 Saving_movie_frames = !Saving_movie_frames;
2898 if (Saving_movie_frames) {
2901 m[0].type=NM_TYPE_INPUT; m[0].text_len = 50; m[0].text = movie_path;
2902 exit = newmenu_do( NULL, "Directory for movie frames?" , 1, &(m[0]), NULL );
2905 Saving_movie_frames = 0;
2909 while (isspace(movie_path[strlen(movie_path)-1]))
2910 movie_path[strlen(movie_path)-1] = 0;
2911 if (movie_path[strlen(movie_path)-1]!='\\' && movie_path[strlen(movie_path)-1]!=':')
2912 strcat(movie_path,"\\");
2915 if (!Movie_frame_buffer) {
2916 Movie_frame_buffer = d_malloc(MAX_MOVIE_BUFFER_FRAMES * MOVIE_FRAME_SIZE);
2917 if (!Movie_frame_buffer) {
2919 Saving_movie_frames=0;
2922 Movie_frame_counter=0;
2924 Movie_bm.bm_x = Movie_bm.bm_y = 0;
2925 Movie_bm.bm_w = 320;
2926 Movie_bm.bm_h = 200;
2927 Movie_bm.bm_type = BM_LINEAR;
2928 Movie_bm.bm_flags = 0;
2929 Movie_bm.bm_rowsize = 320;
2930 Movie_bm.bm_handle = 0;
2932 gr_palette_read(Movie_pal); //get actual palette from the hardware
2934 if (Newdemo_state == ND_STATE_PLAYBACK)
2935 Newdemo_do_interpolate = 0;
2939 flush_movie_buffer();
2941 if (Newdemo_state == ND_STATE_PLAYBACK)
2942 Newdemo_do_interpolate = 1;
2947 void save_movie_frame()
2949 memcpy(Movie_frame_buffer+Movie_frame_counter*MOVIE_FRAME_SIZE,grd_curscreen->sc_canvas.cv_bitmap.bm_data,MOVIE_FRAME_SIZE);
2951 Movie_frame_counter++;
2953 if (Movie_frame_counter == MAX_MOVIE_BUFFER_FRAMES)
2954 flush_movie_buffer();
2960 extern int Level_shake_duration;
2962 //if water or fire level, make occasional sound
2963 void do_ambient_sounds()
2965 int has_water,has_lava;
2968 has_lava = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_LAVA);
2969 has_water = (Segment2s[ConsoleObject->segnum].s2_flags & S2F_AMBIENT_WATER);
2971 if (has_lava) { //has lava
2972 sound = SOUND_AMBIENT_LAVA;
2973 if (has_water && (d_rand() & 1)) //both, pick one
2974 sound = SOUND_AMBIENT_WATER;
2976 else if (has_water) //just water
2977 sound = SOUND_AMBIENT_WATER;
2981 if (((d_rand() << 3) < FrameTime)) { //play the sound
2982 fix volume = d_rand() + f1_0/2;
2983 digi_play_sample(sound,volume);
2987 // -- extern void lightning_frame(void);
2989 void game_render_frame();
2990 extern void omega_charge_frame(void);
2992 extern time_t t_current_time, t_saved_time;
2994 void flicker_lights();
2996 void GameLoop(int RenderFlag, int ReadControlsFlag )
2999 // Used to slow down frame rate for testing things.
3000 // RenderFlag = 1; // DEBUG
3001 if (Debug_slowdown) {
3004 for (h=0; h<Debug_slowdown; h++)
3005 for (i=0; i<1000; i++)
3012 static int desc_dead_countdown=100; /* used if player shouldn't be playing */
3014 if (desc_id_exit_num) { // are we supposed to be checking
3015 if (!(--desc_dead_countdown)) {// if so, at zero, then pull the plug
3016 char time_str[32], time_str2[32];
3018 _ctime(&t_saved_time, time_str);
3019 _ctime(&t_current_time, time_str2);
3021 Error ("EXPIRES %s. YOUR TIME %s.\n", time_str, time_str2);
3022 Error ("Loading overlay -- error number: %d\n", (int)desc_id_exit_num);
3029 if (FindArg("-invulnerability"))
3030 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
3034 update_player_stats();
3035 diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
3036 do_afterburner_stuff();
3038 do_invulnerable_stuff();
3039 remove_obsolete_stuck_objects();
3041 do_final_boss_frame();
3042 // -- lightning_frame();
3043 // -- recharge_energy_frame();
3045 if ((Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT) && (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON)) {
3046 static int turned_off=0;
3047 Players[Player_num].energy -= (FrameTime*3/8);
3048 if (Players[Player_num].energy < i2f(10)) {
3050 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
3053 if (Game_mode & GM_MULTI)
3054 multi_send_flags(Player_num);
3061 if (Players[Player_num].energy <= 0) {
3062 Players[Player_num].energy = 0;
3063 Players[Player_num].flags &= ~PLAYER_FLAGS_HEADLIGHT_ON;
3065 if (Game_mode & GM_MULTI)
3066 multi_send_flags(Player_num);
3073 check_create_player_path();
3074 player_follow_path(ConsoleObject);
3078 if (Game_mode & GM_MULTI)
3081 if (Netgame.PlayTimeAllowed && ThisLevelTime>=i2f((Netgame.PlayTimeAllowed*5*60)))
3082 multi_check_for_killgoal_winner();
3088 if (force_cockpit_redraw) { //screen need redrawing?
3090 force_cockpit_redraw=0;
3092 game_render_frame();
3093 //show_extra_views(); //missile view, buddy bot, etc.
3096 if (Saving_movie_frames)
3103 //mprintf(0,"Velocity %2.2f\n", f2fl(vm_vec_mag(&ConsoleObject->phys_info.velocity)));
3107 dead_player_frame();
3108 if (Newdemo_state != ND_STATE_PLAYBACK)
3109 do_controlcen_dead_frame();
3111 process_super_mines_frame();
3113 do_ambient_sounds();
3120 if (ReadControlsFlag)
3123 memset(&Controls, 0, sizeof(Controls));
3125 GameTime += FrameTime;
3127 if (f2i(GameTime)/10 != f2i(GameTime-FrameTime)/10)
3128 mprintf((0,"Gametime = %d secs\n",f2i(GameTime)));
3130 if (GameTime < 0 || GameTime > i2f(0x7fff - 600)) {
3131 GameTime = FrameTime; //wrap when goes negative, or gets within 10 minutes
3132 mprintf((0,"GameTime reset to 0\n"));
3136 if (FindArg("-checktime") != 0)
3137 if (GameTime >= i2f(600)) //wrap after 10 minutes
3138 GameTime = FrameTime;
3142 if ((Game_mode & GM_MULTI) && Netgame.PlayTimeAllowed)
3143 ThisLevelTime +=FrameTime;
3148 if (Endlevel_sequence) {
3149 do_endlevel_frame();
3150 powerup_grab_cheat_all();
3151 do_special_effects();
3152 return; //skip everything else
3155 if (Newdemo_state != ND_STATE_PLAYBACK)
3156 do_exploding_wall_frame();
3157 if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
3158 do_special_effects();
3159 wall_frame_process();
3160 triggers_frame_process();
3164 if (Control_center_destroyed) {
3165 if (Newdemo_state==ND_STATE_RECORDING )
3166 newdemo_record_control_center_destroyed();
3171 if ( Newdemo_state == ND_STATE_PLAYBACK ) {
3172 newdemo_playback_one_frame();
3173 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
3174 longjmp( LeaveGame, 0 ); // Go back to menu
3177 { // Note the link to above!
3179 Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
3182 powerup_grab_cheat_all();
3184 if (Endlevel_sequence) //might have been started during move
3187 fuelcen_update_all();
3191 if (allowed_to_fire_laser())
3192 FireLaser(); // Fire Laser!
3194 if (Auto_fire_fusion_cannon_time) {
3195 if (Primary_weapon != FUSION_INDEX)
3196 Auto_fire_fusion_cannon_time = 0;
3197 else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
3198 Auto_fire_fusion_cannon_time = 0;
3199 Global_laser_firing_count = 1;
3201 vms_vector rand_vec;
3204 Global_laser_firing_count = 0;
3206 ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
3207 ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
3208 make_random_vector(&rand_vec);
3210 bump_amount = F1_0*4;
3212 if (Fusion_charge > F1_0*2)
3213 bump_amount = Fusion_charge*4;
3215 bump_one_object(ConsoleObject, &rand_vec, bump_amount);
3219 if (Global_laser_firing_count) {
3220 // Don't cap here, gets capped in Laser_create_new and is based on whether in multiplayer mode, MK, 3/27/95
3221 // if (Fusion_charge > F1_0*2)
3222 // Fusion_charge = F1_0*2;
3223 Global_laser_firing_count -= do_laser_firing_player(); //do_laser_firing(Players[Player_num].objnum, Primary_weapon);
3226 if (Global_laser_firing_count < 0)
3227 Global_laser_firing_count = 0;
3230 if (Do_appearance_effect) {
3231 create_player_appearance_effect(ConsoleObject);
3232 Do_appearance_effect = 0;
3234 if ((Game_mode & GM_MULTI) && Netgame.invul)
3236 Players[Player_num].flags |= PLAYER_FLAGS_INVULNERABLE;
3237 Players[Player_num].invulnerable_time = GameTime-i2f(27);
3244 omega_charge_frame();
3248 //!!hoard_light_pulse(); //do cool hoard light pulsing
3252 //!!extern int Goal_blue_segnum,Goal_red_segnum;
3253 //!!extern int Hoard_goal_eclip;
3255 //!!//do cool pulsing lights in hoard goals
3256 //!!hoard_light_pulse()
3258 //!! if (Game_mode & GM_HOARD) {
3262 //!! frame = Effects[Hoard_goal_eclip].frame_count;
3266 //!! if (frame >= Effects[Hoard_goal_eclip].vc.num_frames)
3269 //!! light = abs(frame - 5) * f1_0 / 5;
3271 //!! Segment2s[Goal_red_segnum].static_light = Segment2s[Goal_blue_segnum].static_light = light;
3276 ubyte Slide_segs[MAX_SEGMENTS];
3277 int Slide_segs_computed;
3279 void compute_slide_segs(void)
3281 int segnum, sidenum;
3283 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
3284 Slide_segs[segnum] = 0;
3285 for (sidenum=0;sidenum<6;sidenum++) {
3286 int tmn = Segments[segnum].sides[sidenum].tmap_num;
3287 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0)
3288 Slide_segs[segnum] |= 1 << sidenum;
3292 Slide_segs_computed = 1;
3295 // -----------------------------------------------------------------------------
3296 void slide_textures(void)
3298 int segnum,sidenum,i;
3300 if (!Slide_segs_computed)
3301 compute_slide_segs();
3303 for (segnum=0;segnum<=Highest_segment_index;segnum++) {
3304 if (Slide_segs[segnum]) {
3305 for (sidenum=0;sidenum<6;sidenum++) {
3306 if (Slide_segs[segnum] & (1 << sidenum)) {
3307 int tmn = Segments[segnum].sides[sidenum].tmap_num;
3308 if (TmapInfo[tmn].slide_u != 0 || TmapInfo[tmn].slide_v != 0) {
3310 Segments[segnum].sides[sidenum].uvls[i].u += fixmul(FrameTime,TmapInfo[tmn].slide_u<<8);
3311 Segments[segnum].sides[sidenum].uvls[i].v += fixmul(FrameTime,TmapInfo[tmn].slide_v<<8);
3312 if (Segments[segnum].sides[sidenum].uvls[i].u > f2_0) {
3315 Segments[segnum].sides[sidenum].uvls[j].u -= f1_0;
3317 if (Segments[segnum].sides[sidenum].uvls[i].v > f2_0) {
3320 Segments[segnum].sides[sidenum].uvls[j].v -= f1_0;
3322 if (Segments[segnum].sides[sidenum].uvls[i].u < -f2_0) {
3325 Segments[segnum].sides[sidenum].uvls[j].u += f1_0;
3327 if (Segments[segnum].sides[sidenum].uvls[i].v < -f2_0) {
3330 Segments[segnum].sides[sidenum].uvls[j].v += f1_0;
3340 flickering_light Flickering_lights[MAX_FLICKERING_LIGHTS];
3342 int Num_flickering_lights=0;
3344 void flicker_lights()
3347 flickering_light *f;
3349 f = Flickering_lights;
3351 for (l=0;l<Num_flickering_lights;l++,f++) {
3352 segment *segp = &Segments[f->segnum];
3354 //make sure this is actually a light
3355 if (! (WALL_IS_DOORWAY(segp, f->sidenum) & WID_RENDER_FLAG))
3357 if (! (TmapInfo[segp->sides[f->sidenum].tmap_num].lighting | TmapInfo[segp->sides[f->sidenum].tmap_num2 & 0x3fff].lighting))
3360 if (f->timer == 0x80000000) //disabled
3363 if ((f->timer -= FrameTime) < 0) {
3365 while (f->timer < 0)
3366 f->timer += f->delay;
3368 f->mask = ((f->mask&0x80000000)?1:0) + (f->mask<<1);
3371 add_light(f->segnum,f->sidenum);
3373 subtract_light(f->segnum,f->sidenum);
3378 //returns ptr to flickering light structure, or NULL if can't find
3379 flickering_light *find_flicker(int segnum,int sidenum)
3382 flickering_light *f;
3384 //see if there's already an entry for this seg/side
3386 f = Flickering_lights;
3388 for (l=0;l<Num_flickering_lights;l++,f++)
3389 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3395 //turn flickering off (because light has been turned off)
3396 void disable_flicker(int segnum,int sidenum)
3398 flickering_light *f;
3400 if ((f=find_flicker(segnum,sidenum)) != NULL)
3401 f->timer = 0x80000000;
3404 //turn flickering off (because light has been turned on)
3405 void enable_flicker(int segnum,int sidenum)
3407 flickering_light *f;
3409 if ((f=find_flicker(segnum,sidenum)) != NULL)
3416 //returns 1 if ok, 0 if error
3417 int add_flicker(int segnum,int sidenum,fix delay,ulong mask)
3420 flickering_light *f;
3422 mprintf((0,"add_flicker: %d:%d %x %x\n",segnum,sidenum,delay,mask));
3424 //see if there's already an entry for this seg/side
3426 f = Flickering_lights;
3428 for (l=0;l<Num_flickering_lights;l++,f++)
3429 if (f->segnum == segnum && f->sidenum == sidenum) //found it!
3432 if (mask==0) { //clearing entry
3433 if (l == Num_flickering_lights)
3437 for (i=l;i<Num_flickering_lights-1;i++)
3438 Flickering_lights[i] = Flickering_lights[i+1];
3439 Num_flickering_lights--;
3444 if (l == Num_flickering_lights) {
3445 if (Num_flickering_lights == MAX_FLICKERING_LIGHTS)
3448 Num_flickering_lights++;
3452 f->sidenum = sidenum;
3453 f->delay = f->timer = delay;
3461 // -----------------------------------------------------------------------------
3462 // Fire Laser: Registers a laser fire, and performs special stuff for the fusion
3467 Global_laser_firing_count += Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
3469 if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
3470 if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
3471 Global_laser_firing_count = 0;
3473 if (Fusion_charge == 0)
3474 Players[Player_num].energy -= F1_0*2;
3476 Fusion_charge += FrameTime;
3477 Players[Player_num].energy -= FrameTime;
3479 if (Players[Player_num].energy <= 0) {
3480 Players[Player_num].energy = 0;
3481 Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
3483 Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1;
3484 // Fire the fusion cannon at this time in the future.
3486 if (Fusion_charge < F1_0*2)
3487 PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
3489 PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
3491 if (GameTime < Fusion_last_sound_time) //gametime has wrapped
3492 Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
3494 if (Fusion_next_sound_time < GameTime) {
3495 if (Fusion_charge > F1_0*2) {
3496 digi_play_sample( 11, F1_0 );
3497 apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
3499 create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
3500 digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
3502 if (Game_mode & GM_MULTI)
3503 multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
3506 Fusion_last_sound_time = GameTime;
3507 Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
3515 // -------------------------------------------------------------------------------------------------------
3516 // If player is close enough to objnum, which ought to be a powerup, pick it up!
3517 // This could easily be made difficulty level dependent.
3518 void powerup_grab_cheat(object *player, int objnum)
3524 Assert(Objects[objnum].type == OBJ_POWERUP);
3526 powerup_size = Objects[objnum].size;
3527 player_size = player->size;
3529 dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
3531 if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
3532 vms_vector collision_point;
3534 vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
3535 collide_player_and_powerup(player, &Objects[objnum], &collision_point);
3539 // -------------------------------------------------------------------------------------------------------
3540 // Make it easier to pick up powerups.
3541 // For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
3542 // from player to powerup and player's forward vector.
3543 // This has the effect of picking them up more easily left/right and up/down, but not making them disappear
3544 // way before the player gets there.
3545 void powerup_grab_cheat_all(void)
3550 segp = &Segments[ConsoleObject->segnum];
3551 objnum = segp->objects;
3553 while (objnum != -1) {
3554 if (Objects[objnum].type == OBJ_POWERUP)
3555 powerup_grab_cheat(ConsoleObject, objnum);
3556 objnum = Objects[objnum].next;
3561 int Last_level_path_created = -1;
3563 #ifdef SHOW_EXIT_PATH
3565 // ------------------------------------------------------------------------------------------------------------------
3566 // Create path for player from current segment to goal segment.
3567 // Return true if path created, else return false.
3568 int mark_player_path_to_segment(int segnum)
3571 object *objp = ConsoleObject;
3572 short player_path_length=0;
3573 int player_hide_index=-1;
3575 if (Last_level_path_created == Current_level_num) {
3579 Last_level_path_created = Current_level_num;
3581 if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
3582 mprintf((0, "Unable to form path of length %i for myself\n", 100));
3586 player_hide_index = Point_segs_free_ptr - Point_segs;
3587 Point_segs_free_ptr += player_path_length;
3589 if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
3590 mprintf((1, "Can't create path. Not enough point_segs.\n"));
3591 ai_reset_all_paths();
3595 for (i=1; i<player_path_length; i++) {
3597 vms_vector seg_center;
3600 segnum = Point_segs[player_hide_index+i].segnum;
3601 mprintf((0, "%3i ", segnum));
3602 seg_center = Point_segs[player_hide_index+i].point;
3604 objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
3606 Int3(); // Unable to drop energy powerup for path
3610 obj = &Objects[objnum];
3611 obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
3612 obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
3613 obj->rtype.vclip_info.framenum = 0;
3614 obj->lifeleft = F1_0*100 + d_rand() * 4;
3621 // Return true if it happened, else return false.
3622 int create_special_path(void)
3626 // ---------- Find exit doors ----------
3627 for (i=0; i<=Highest_segment_index; i++)
3628 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
3629 if (Segments[i].children[j] == -2) {
3630 mprintf((0, "Exit at segment %i\n", i));
3631 return mark_player_path_to_segment(i);
3641 int Max_obj_count_mike = 0;
3643 // Shows current number of used objects.
3644 void show_free_objects(void)
3646 if (!(FrameCount & 8)) {
3650 mprintf((0, "Highest_object_index = %3i, MAX_OBJECTS = %3i, now used = ", Highest_object_index, MAX_OBJECTS));
3652 for (i=0; i<=Highest_object_index; i++)
3653 if (Objects[i].type != OBJ_NONE)
3656 mprintf((0, "%3i", count));
3658 if (count > Max_obj_count_mike) {
3659 Max_obj_count_mike = count;
3660 mprintf((0, " ***"));
3671 void game_win_init_cockpit_mask(int sram)
3673 if (dd_VR_offscreen_buffer && dd_VR_offscreen_buffer != dd_grd_backcanv) {
3674 dd_gr_free_canvas(dd_VR_offscreen_buffer);
3677 if (GRMODEINFO(paged) && !GRMODEINFO(dbuf)) {
3678 // Here we will make the VR_offscreen_buffer the 2nd page and hopefully
3679 // we can just flip it, saving a blt.
3682 else if (GRMODEINFO(dbuf)||GRMODEINFO(emul)) {
3683 // The offscreen buffer will be created. We will just blt this
3684 // to the screen (which may be blted to the primary surface)
3685 if ( grd_curscreen->sc_h < 200 ) {
3686 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, 200);
3687 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3689 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3690 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, 200);
3691 dd_VR_offscreen_buffer->sram = 1;
3695 dd_VR_offscreen_buffer = dd_gr_create_canvas(grd_curscreen->sc_w, grd_curscreen->sc_h);
3696 VR_offscreen_buffer = &dd_VR_offscreen_buffer->canvas;
3698 DDFreeSurface(dd_VR_offscreen_buffer->lpdds);
3699 dd_VR_offscreen_buffer->lpdds = DDCreateSysMemSurface(grd_curscreen->sc_w, grd_curscreen->sc_h);
3700 dd_VR_offscreen_buffer->sram = 1;
3705 dd_gr_init_sub_canvas( &dd_VR_render_buffer[0], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3706 dd_gr_init_sub_canvas( &dd_VR_render_buffer[1], dd_VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3707 gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3708 gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3710 game_init_render_sub_buffers( 0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h );
3713 //@@void game_win_init_cockpit_mask()
3715 //@@ char title_pal[768];
3716 //@@ dd_grs_canvas ccanv;
3718 //@@ LPDIRECTDRAWSURFACE dds;
3720 //@@ dds = DDCreateSurface(GRMODEINFO(w), GRMODEINFO(h), 1);
3721 //@@ Assert(dds != NULL);
3723 //@@ _lpDDSMask = dds;
3724 //@@ ccanv.lpdds = dds;
3725 //@@ dd_gr_reinit_canvas(&ccanv);
3727 //@@ dd_gr_set_current_canvas(&ccanv);
3728 //@@ DDGRLOCK(dd_grd_curcanv)
3730 //@@ if (W95DisplayMode == SM95_640x480x8) {
3731 //@@ pcx_error=pcx_read_bitmap( "MASKB.PCX", &grd_curcanv->cv_bitmap,
3732 //@@ grd_curcanv->cv_bitmap.bm_type,
3736 //@@ pcx_error=pcx_read_bitmap( "MASK.PCX", &grd_curcanv->cv_bitmap,
3737 //@@ grd_curcanv->cv_bitmap.bm_type,
3741 //@@ DDGRUNLOCK(dd_grd_curcanv);
3743 //@@ Assert(pcx_error == PCX_ERROR_NONE);
3744 //@@ Game_cockpit_copy_code = (ubyte *)(0xABADC0DE);
3750 * reads a flickering_light structure from a CFILE
3752 void flickering_light_read(flickering_light *fl, CFILE *fp)
3754 fl->segnum = cfile_read_short(fp);
3755 fl->sidenum = cfile_read_short(fp);
3756 fl->mask = cfile_read_int(fp);
3757 fl->timer = cfile_read_fix(fp);
3758 fl->delay = cfile_read_fix(fp);