1 /* $Id: state.c,v 1.16 2004-10-23 19:39:35 schaffner Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Functions to save/restore game state.
33 #if !defined(_MSC_VER) && !defined(macintosh)
47 #if defined(__APPLE__) && defined(__MACH__)
48 #include <OpenGL/gl.h>
55 #include "pa_enabl.h" //$$POLY_ACC
100 #include "multibot.h"
103 #if defined(POLY_ACC)
104 #include "poly_acc.h"
111 #define STATE_VERSION 22
112 #define STATE_COMPATIBLE_VERSION 20
113 // 0 - Put DGSS (Descent Game State Save) id at tof.
114 // 1 - Added Difficulty level save
115 // 2 - Added Cheats_enabled flag
116 // 3 - Added between levels save.
117 // 4 - Added mission support
118 // 5 - Mike changed ai and object structure.
119 // 6 - Added buggin' cheat save
120 // 7 - Added other cheat saves and game_id.
121 // 8 - Added AI stuff for escort and thief.
122 // 9 - Save palette with screen shot
123 // 12- Saved last_was_super array
124 // 13- Saved palette flash stuff
125 // 14- Save cloaking wall stuff
126 // 15- Save additional ai info
127 // 16- Save Light_subtracted
128 // 17- New marker save
129 // 18- Took out saving of old cheat status
130 // 19- Saved cheats_enabled flag
131 // 20- First_secret_visit
135 #define THUMBNAIL_W 100
136 #define THUMBNAIL_H 50
137 #define DESC_LENGTH 20
139 extern void multi_initiate_save_game();
140 extern void multi_initiate_restore_game();
141 extern void apply_all_changed_light(void);
143 extern int Do_appearance_effect;
144 extern fix Fusion_next_sound_time;
146 extern int Laser_rapid_fire;
147 extern int Physics_cheat_flag;
149 extern void do_lunacy_on(void);
150 extern void do_lunacy_off(void);
151 extern int First_secret_visit;
154 grs_bitmap *sc_bmp[NUM_SAVES+1];
156 char dgss_id[4] = "DGSS";
158 int state_default_item = 0;
162 extern int robot_controlled[MAX_ROBOTS_CONTROLLED];
163 extern int robot_agitation[MAX_ROBOTS_CONTROLLED];
164 extern fix robot_controlled_time[MAX_ROBOTS_CONTROLLED];
165 extern fix robot_last_send_time[MAX_ROBOTS_CONTROLLED];
166 extern fix robot_last_message_time[MAX_ROBOTS_CONTROLLED];
167 extern int robot_send_pending[MAX_ROBOTS_CONTROLLED];
168 extern int robot_fired[MAX_ROBOTS_CONTROLLED];
169 extern sbyte robot_fire_buf[MAX_ROBOTS_CONTROLLED][18+3];
172 #if defined(WINDOWS) || defined(MACINTOSH)
173 extern ubyte Hack_DblClick_MenuMode;
176 void compute_all_static_light(void);
178 //-------------------------------------------------------------------
179 void state_callback(int nitems,newmenu_item * items, int * last_key, int citem)
184 // if ( sc_last_item != citem ) {
185 // sc_last_item = citem;
187 if ( sc_bmp[citem-1] ) {
190 dd_grs_canvas *save_canv = dd_grd_curcanv,
191 grs_canvas *save_canv = grd_curcanv
193 grs_canvas *temp_canv = gr_create_canvas(THUMBNAIL_W*2,(THUMBNAIL_H*24/10));
194 grs_point vertbuf[3] = {{0,0}, {0,0}, {i2f(THUMBNAIL_W*2),i2f(THUMBNAIL_H*24/10)} };
195 gr_set_current_canvas(temp_canv);
196 scale_bitmap(sc_bmp[citem-1], vertbuf, 0 );
198 dd_gr_set_current_canvas(save_canv),
199 gr_set_current_canvas( save_canv )
201 WIN(DDGRLOCK(dd_grd_curcanv));
202 gr_bitmap( (grd_curcanv->cv_bitmap.bm_w-THUMBNAIL_W*2)/2,items[0].y-10, &temp_canv->cv_bitmap);
203 WIN(DDGRUNLOCK(dd_grd_curcanv));
204 gr_free_canvas(temp_canv);
210 gr_bitmap( (grd_curcanv->cv_bitmap.bm_w-THUMBNAIL_W)/2,items[0].y-5, sc_bmp[citem-1] );
218 void rpad_string( char * string, int max_chars )
223 for( i=0; i<max_chars; i++ ) {
230 *string = 0; // NULL terminate
233 int state_get_save_file(char * fname, char * dsc, int multi )
236 int i, choice, version;
237 newmenu_item m[NUM_SAVES+2];
238 char filename[NUM_SAVES+1][30];
239 char desc[NUM_SAVES+1][DESC_LENGTH+16];
243 for (i=0;i<NUM_SAVES; i++ ) {
247 sprintf( filename[i], "%s.sg%x", Players[Player_num].callsign, i );
249 sprintf( filename[i], ":Players:%s.sg%x", Players[Player_num].callsign, i );
253 sprintf( filename[i], "%s.mg%x", Players[Player_num].callsign, i );
255 sprintf( filename[i], ":Players:%s.mg%x", Players[Player_num].callsign, i );
258 fp = cfopen(filename[i], "rb");
261 cfread(id, sizeof(char)*4, 1, fp);
262 if ( !memcmp( id, dgss_id, 4 )) {
264 cfread(&version, sizeof(int), 1, fp);
265 if (version >= STATE_COMPATIBLE_VERSION) {
267 cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
268 //rpad_string( desc[i], DESC_LENGTH-1 );
270 //sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
271 //cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
278 strcpy( desc[i], TXT_EMPTY );
279 //rpad_string( desc[i], DESC_LENGTH-1 );
281 m[i].type = NM_TYPE_INPUT_MENU; m[i].text = desc[i]; m[i].text_len = DESC_LENGTH-1;
285 choice = newmenu_do1( NULL, "Save Game", NUM_SAVES, m, NULL, state_default_item );
287 for (i=0; i<NUM_SAVES; i++ ) {
289 gr_free_bitmap( sc_bmp[i] );
293 strcpy( fname, filename[choice] );
294 strcpy( dsc, desc[choice] );
295 state_default_item = choice;
302 extern int Current_display_mode;
304 int state_get_restore_file(char * fname, int multi)
307 int i, choice, version, nsaves;
308 newmenu_item m[NUM_SAVES+2];
309 char filename[NUM_SAVES+1][30];
310 char desc[NUM_SAVES+1][DESC_LENGTH + 16];
315 m[0].type = NM_TYPE_TEXT; m[0].text = "\n\n\n\n";
316 for (i=0;i<NUM_SAVES+1; i++ ) {
320 sprintf( filename[i], "%s.sg%x", Players[Player_num].callsign, i );
322 sprintf( filename[i], ":Players:%s.sg%x", Players[Player_num].callsign, i );
326 sprintf( filename[i], "%s.mg%x", Players[Player_num].callsign, i );
328 sprintf( filename[i], ":Players:%s.mg%x", Players[Player_num].callsign, i );
331 fp = cfopen(filename[i], "rb");
334 cfread(id, sizeof(char)*4, 1, fp);
335 if ( !memcmp( id, dgss_id, 4 )) {
337 cfread(&version, sizeof(int), 1, fp);
338 if (version >= STATE_COMPATIBLE_VERSION) {
340 cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
341 //rpad_string( desc[i], DESC_LENGTH-1 );
342 m[i+1].type = NM_TYPE_MENU; m[i+1].text = desc[i];
344 sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
345 cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
348 cfread(pal, 3, 256, fp);
349 gr_remap_bitmap_good( sc_bmp[i], pal, -1, -1 );
358 strcpy( desc[i], TXT_EMPTY );
359 //rpad_string( desc[i], DESC_LENGTH-1 );
360 m[i+1].type = NM_TYPE_TEXT; m[i+1].text = desc[i];
365 nm_messagebox( NULL, 1, "Ok", "No saved games were found!" );
369 if (Current_display_mode == 3) //restore menu won't fit on 640x400
370 VR_screen_flags ^= VRF_COMPATIBLE_MENUS;
374 #if defined(WINDOWS) || defined(MACINTOSH)
375 Hack_DblClick_MenuMode = 1;
379 choice = newmenu_do3( NULL, "Select Game to Restore", NUM_SAVES+2, m, state_callback, state_default_item+1, NULL, 190, -1 );
382 #if defined(WINDOWS) || defined(MACINTOSH)
383 Hack_DblClick_MenuMode = 0;
386 if (Current_display_mode == 3) //set flag back
387 VR_screen_flags ^= VRF_COMPATIBLE_MENUS;
390 for (i=0; i<NUM_SAVES+1; i++ ) {
392 gr_free_bitmap( sc_bmp[i] );
396 strcpy( fname, filename[choice-1] );
397 if (choice != NUM_SAVES+1) //no new default when restore from autosave
398 state_default_item = choice - 1;
404 #define DESC_OFFSET 8
406 #define CF_BUF_SIZE 1024
410 # define strerror(x) "Unknown Error"
414 // -----------------------------------------------------------------------------------
415 // Imagine if C had a function to copy a file...
416 int copy_file(char *old_file, char *new_file)
418 sbyte buf[CF_BUF_SIZE];
419 CFILE *in_file, *out_file;
421 out_file = cfopen(new_file, "wb");
423 if (out_file == NULL)
426 in_file = cfopen(old_file, "rb");
431 while (!cfeof(in_file))
435 bytes_read = cfread(buf, 1, CF_BUF_SIZE, in_file);
436 if (cferror(in_file))
437 Error("Cannot read from file <%s>: %s", old_file, strerror(errno));
439 Assert(bytes_read == CF_BUF_SIZE || cfeof(in_file));
441 cfwrite(buf, 1, bytes_read, out_file);
443 if (cferror(out_file))
444 Error("Cannot write to file <%s>: %s", new_file, strerror(errno));
447 if (cfclose(in_file)) {
452 if (cfclose(out_file))
459 #define SECRETB_FILENAME "secret.sgb"
460 #define SECRETC_FILENAME "secret.sgc"
462 #define SECRETB_FILENAME ":Players:secret.sgb"
463 #define SECRETC_FILENAME ":Players:secret.sgc"
466 extern int Final_boss_is_dead;
468 // -----------------------------------------------------------------------------------
469 // blind_save means don't prompt user for any info.
470 int state_save_all(int between_levels, int secret_save, char *filename_override)
472 int rval, filenum = -1;
474 char filename[128], desc[DESC_LENGTH+1];
476 Assert(between_levels == 0); //between levels save ripped out
479 if ( Game_mode & GM_MULTI ) {
480 multi_initiate_save_game();
485 if ((Current_level_num < 0) && (secret_save == 0)) {
486 HUD_init_message( "Can't save in secret level!" );
490 if (Final_boss_is_dead) //don't allow save while final boss is dying
493 mprintf(( 0, "CL=%d, NL=%d\n", Current_level_num, Next_level_num ));
495 // If this is a secret save and the control center has been destroyed, don't allow
496 // return to the base level.
497 if (secret_save && (Control_center_destroyed)) {
498 mprintf((0, "Deleting secret.sgb so player can't return to base level.\n"));
499 cfile_delete(SECRETB_FILENAME);
505 if (secret_save == 1) {
506 filename_override = filename;
507 sprintf(filename_override, SECRETB_FILENAME);
508 } else if (secret_save == 2) {
509 filename_override = filename;
510 sprintf(filename_override, SECRETC_FILENAME);
512 if (filename_override) {
513 strcpy( filename, filename_override);
514 sprintf(desc, "[autosave backup]");
515 } else if (!(filenum = state_get_save_file(filename,desc,0))) {
522 // If not in multiplayer, do special secret level stuff.
523 // If secret.sgc exists, then copy it to Nsecret.sgc (where N = filenum).
524 // If it doesn't exist, then delete Nsecret.sgc
525 if (!secret_save && !(Game_mode & GM_MULTI)) {
527 char temp_fname[32], fc;
532 fc = (filenum-10) + 'a';
537 sprintf(temp_fname, "%csecret.sgc", fc);
539 sprintf(temp_fname, ":Players:%csecret.sgc", fc);
542 mprintf((0, "Trying to copy secret.sgc to %s.\n", temp_fname));
544 if (cfexist(temp_fname))
546 mprintf((0, "Deleting file %s\n", temp_fname));
547 rval = cfile_delete(temp_fname);
548 Assert(rval == 0); // Oops, error deleting file in temp_fname.
551 if (cfexist(SECRETC_FILENAME))
553 mprintf((0, "Copying secret.sgc to %s.\n", temp_fname));
554 rval = copy_file(SECRETC_FILENAME, temp_fname);
555 Assert(rval == 0); // Oops, error copying temp_fname to secret.sgc!
560 // Save file we're going to save over in last slot and call "[autosave backup]"
561 if (!filename_override) {
564 tfp = cfopen(filename, "rb");
570 sprintf( newname, "%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
572 sprintf( newname, ":Players:%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
575 cfseek(tfp, DESC_OFFSET, SEEK_SET);
576 cfwrite("[autosave backup]", sizeof(char)*DESC_LENGTH, 1, tfp);
578 cfile_delete(newname);
579 cfile_rename(filename, newname);
583 rval = state_save_all_sub(filename, desc, between_levels);
588 extern fix Flash_effect, Time_flash_last_played;
591 int state_save_all_sub(char *filename, char *desc, int between_levels)
597 grs_canvas cnv2,*save_cnv2;
601 Assert(between_levels == 0); //between levels save ripped out
603 /* if ( Game_mode & GM_MULTI ) {
610 #if defined(MACINTOSH) && !defined(NDEBUG)
611 if ( strncmp(filename, ":Players:", 9) )
615 fp = cfopen(filename, "wb");
617 if ( !(Game_mode & GM_MULTI) )
618 nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
624 cfwrite(dgss_id, sizeof(char)*4, 1, fp);
628 cfwrite(&i, sizeof(int), 1, fp);
631 cfwrite(desc, sizeof(char) * DESC_LENGTH, 1, fp);
633 // Save the current screen shot...
635 cnv = gr_create_canvas( THUMBNAIL_W, THUMBNAIL_H );
643 dd_grs_canvas *cnv_save;
644 cnv_save = dd_grd_curcanv;
646 grs_canvas * cnv_save;
647 cnv_save = grd_curcanv;
652 #if defined(POLY_ACC)
654 PA_DFX (pa_fool_to_backbuffer());
656 //for poly_acc, we render the frame to the normal render buffer
657 //so that this doesn't show, we create yet another canvas to save
658 //and restore what's on the render buffer
659 PA_DFX (pa_alpha_always());
660 PA_DFX (pa_set_front_to_read());
661 gr_init_sub_canvas( &cnv2, &VR_render_buffer[0], 0, 0, THUMBNAIL_W, THUMBNAIL_H );
662 save_cnv2 = gr_create_canvas2(THUMBNAIL_W, THUMBNAIL_H, cnv2.cv_bitmap.bm_type);
663 gr_set_current_canvas( save_cnv2 );
664 PA_DFX (pa_set_front_to_read());
665 gr_bitmap(0,0,&cnv2.cv_bitmap);
666 gr_set_current_canvas( &cnv2 );
668 gr_set_current_canvas( cnv );
671 PA_DFX (pa_set_backbuffer_current());
673 PA_DFX (pa_alpha_always());
675 #if defined(POLY_ACC)
677 screen_shot_pa(cnv,&cnv2);
680 screen_shot_pa(cnv,&cnv2);
684 buf = d_malloc(THUMBNAIL_W * THUMBNAIL_H * 3);
685 glReadBuffer(GL_FRONT);
686 glReadPixels(0, SHEIGHT - THUMBNAIL_H, THUMBNAIL_W, THUMBNAIL_H, GL_RGB, GL_UNSIGNED_BYTE, buf);
688 for (i = 0; i < THUMBNAIL_W * THUMBNAIL_H; i++) {
689 if (!(j = i % THUMBNAIL_W))
691 cnv->cv_bitmap.bm_data[THUMBNAIL_W * k + j] =
692 gr_find_closest_color(buf[3*i]/4, buf[3*i+1]/4, buf[3*i+2]/4);
695 # else // simpler d1x method, not tested yet
696 ogl_ubitblt_tolinear(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h, 0, 0, 0, 0, &grd_curscreen->sc_canvas.cv_bitmap, &grd_curcanv->cv_bitmap);
702 cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
704 #if defined(POLY_ACC)
705 PA_DFX (pa_alpha_always());
706 PA_DFX (pa_set_frontbuffer_current());
707 PA_DFX(gr_bitmap(0,0,&save_cnv2->cv_bitmap));
708 PA_DFX (pa_set_backbuffer_current());
709 gr_bitmap(0,0,&save_cnv2->cv_bitmap);
710 gr_free_canvas(save_cnv2);
711 PA_DFX (pa_fool_to_offscreen());
715 #else // macintosh stuff below
717 #if defined(POLY_ACC)
718 int savePAEnabled = PAEnabled;
722 gr_set_current_canvas( cnv );
725 cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
727 #if defined(POLY_ACC)
728 PAEnabled = savePAEnabled;
731 #endif // end of ifndef macintosh
735 dd_gr_set_current_canvas(cnv_save),
736 gr_set_current_canvas(cnv_save)
738 gr_free_canvas( cnv );
739 cfwrite(pal, 3, 256, fp);
744 for ( i=0; i<THUMBNAIL_W*THUMBNAIL_H; i++ )
745 cfwrite(&color, sizeof(ubyte), 1, fp);
748 // Save the Between levels flag...
749 cfwrite(&between_levels, sizeof(int), 1, fp);
751 // Save the mission info...
752 mprintf ((0, "HEY! Mission name is %s\n", Current_mission_filename));
753 cfwrite(Current_mission_filename, sizeof(char), 9, fp);
756 cfwrite(&Current_level_num, sizeof(int), 1, fp);
757 cfwrite(&Next_level_num, sizeof(int), 1, fp);
760 cfwrite(&GameTime, sizeof(fix), 1, fp);
762 // If coop save, save all
764 if (Game_mode & GM_MULTI_COOP)
766 cfwrite(&state_game_id, sizeof(int), 1, fp);
767 cfwrite(&Netgame, sizeof(netgame_info), 1, fp);
768 cfwrite(&NetPlayers, sizeof(AllNetPlayers_info), 1, fp);
769 cfwrite(&N_players, sizeof(int), 1, fp);
770 cfwrite(&Player_num, sizeof(int), 1, fp);
771 for (i=0;i<N_players;i++)
772 cfwrite(&Players[i], sizeof(player), 1, fp);
774 #ifdef RISKY_PROPOSITION
775 cfwrite(&robot_controlled[0], 4, MAX_ROBOTS_CONTROLLED, fp);
776 cfwrite(&robot_agitation[0], 4, MAX_ROBOTS_CONTROLLED, fp);
777 cfwrite(&robot_controlled_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
778 cfwrite(&robot_last_send_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
779 cfwrite(&robot_last_message_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
780 cfwrite(&robot_send_pending[0], 4, MAX_ROBOTS_CONTROLLED, fp);
781 cfwrite(&robot_fired[0], 4, MAX_ROBOTS_CONTROLLED, fp);
783 for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
784 cfwrite(robot_fire_buf[i][0], 18 + 3, 1, fp);
791 cfwrite(&Players[Player_num], sizeof(player), 1, fp);
793 // Save the current weapon info
794 cfwrite(&Primary_weapon, sizeof(sbyte), 1, fp);
795 cfwrite(&Secondary_weapon, sizeof(sbyte), 1, fp);
797 // Save the difficulty level
798 cfwrite(&Difficulty_level, sizeof(int), 1, fp);
799 // Save cheats enabled
800 cfwrite(&Cheats_enabled, sizeof(int), 1, fp);
802 if ( !between_levels ) {
804 //Finish all morph objects
805 for (i=0; i<=Highest_object_index; i++ ) {
806 if ( (Objects[i].type != OBJ_NONE) && (Objects[i].render_type==RT_MORPH)) {
808 md = find_morph_data(&Objects[i]);
810 md->obj->control_type = md->morph_save_control_type;
811 md->obj->movement_type = md->morph_save_movement_type;
812 md->obj->render_type = RT_POLYOBJ;
813 md->obj->mtype.phys_info = md->morph_save_phys_info;
815 } else { //maybe loaded half-morphed from disk
816 Objects[i].flags |= OF_SHOULD_BE_DEAD;
817 Objects[i].render_type = RT_POLYOBJ;
818 Objects[i].control_type = CT_NONE;
819 Objects[i].movement_type = MT_NONE;
825 i = Highest_object_index+1;
826 cfwrite(&i, sizeof(int), 1, fp);
827 cfwrite(Objects, sizeof(object), i, fp);
831 cfwrite(&i, sizeof(int), 1, fp);
832 cfwrite(Walls, sizeof(wall), i, fp);
834 //Save exploding wall info
835 i = MAX_EXPLODING_WALLS;
836 cfwrite(&i, sizeof(int), 1, fp);
837 cfwrite(expl_wall_list, sizeof(*expl_wall_list), i, fp);
841 cfwrite(&i, sizeof(int), 1, fp );
842 cfwrite(ActiveDoors, sizeof(active_door), i, fp);
844 //Save cloaking wall info
845 i = Num_cloaking_walls;
846 cfwrite(&i, sizeof(int), 1, fp );
847 cfwrite(CloakingWalls, sizeof(cloaking_wall), i, fp);
850 cfwrite(&Num_triggers, sizeof(int), 1, fp);
851 cfwrite(Triggers, sizeof(trigger), Num_triggers, fp);
854 for (i=0; i<=Highest_segment_index; i++ ) {
855 for (j=0; j<6; j++ ) {
856 cfwrite(&Segments[i].sides[j].wall_num, sizeof(short), 1, fp);
857 cfwrite(&Segments[i].sides[j].tmap_num, sizeof(short), 1, fp);
858 cfwrite(&Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp);
862 // Save the fuelcen info
863 cfwrite(&Control_center_destroyed, sizeof(int), 1, fp);
864 cfwrite(&Countdown_timer, sizeof(int), 1, fp);
865 cfwrite(&Num_robot_centers, sizeof(int), 1, fp);
866 cfwrite(RobotCenters, sizeof(matcen_info), Num_robot_centers, fp);
867 cfwrite(&ControlCenterTriggers, sizeof(control_center_triggers), 1, fp);
868 cfwrite(&Num_fuelcenters, sizeof(int), 1, fp);
869 cfwrite(Station, sizeof(FuelCenter), Num_fuelcenters, fp);
871 // Save the control cen info
872 cfwrite(&Control_center_been_hit, sizeof(int), 1, fp);
873 cfwrite(&Control_center_player_been_seen, sizeof(int), 1, fp);
874 cfwrite(&Control_center_next_fire_time, sizeof(int), 1, fp);
875 cfwrite(&Control_center_present, sizeof(int), 1, fp);
876 cfwrite(&Dead_controlcen_object_num, sizeof(int), 1, fp);
881 // Save the automap visited info
882 cfwrite(Automap_visited, sizeof(ubyte) * MAX_SEGMENTS, 1, fp);
885 cfwrite(&state_game_id, sizeof(uint), 1, fp);
886 cfwrite(&Laser_rapid_fire, sizeof(int), 1, fp);
887 cfwrite(&Lunacy, sizeof(int), 1, fp); // Yes, writing this twice. Removed the Ugly robot system, but didn't want to change savegame format.
888 cfwrite(&Lunacy, sizeof(int), 1, fp);
890 // Save automap marker info
892 cfwrite(MarkerObject, sizeof(MarkerObject), 1, fp);
893 cfwrite(MarkerOwner, sizeof(MarkerOwner), 1, fp);
894 cfwrite(MarkerMessage, sizeof(MarkerMessage), 1, fp);
896 cfwrite(&Afterburner_charge, sizeof(fix), 1, fp);
898 //save last was super information
899 cfwrite(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
900 cfwrite(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
902 // Save flash effect stuff
903 cfwrite(&Flash_effect, sizeof(int), 1, fp);
904 cfwrite(&Time_flash_last_played, sizeof(int), 1, fp);
905 cfwrite(&PaletteRedAdd, sizeof(int), 1, fp);
906 cfwrite(&PaletteGreenAdd, sizeof(int), 1, fp);
907 cfwrite(&PaletteBlueAdd, sizeof(int), 1, fp);
909 cfwrite(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
911 cfwrite(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
913 cfwrite(&Omega_charge, sizeof(Omega_charge), 1, fp);
917 if ( !(Game_mode & GM_MULTI) ) {
918 nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
920 cfile_delete(filename);
925 #ifdef MACINTOSH // set the type and creator of the saved game file
931 strcpy(pfilename, filename);
933 err = HGetFInfo(0, 0, pfilename, &finfo);
934 finfo.fdType = 'SVGM';
935 finfo.fdCreator = 'DCT2';
936 err = HSetFInfo(0, 0, pfilename, &finfo);
946 // -----------------------------------------------------------------------------------
947 // Set the player's position from the globals Secret_return_segment and Secret_return_orient.
948 void set_pos_from_return_segment(void)
950 int plobjnum = Players[Player_num].objnum;
952 compute_segment_center(&Objects[plobjnum].pos, &Segments[Secret_return_segment]);
953 obj_relink(plobjnum, Secret_return_segment);
954 reset_player_object();
955 Objects[plobjnum].orient = Secret_return_orient;
958 // -----------------------------------------------------------------------------------
959 int state_restore_all(int in_game, int secret_restore, char *filename_override)
965 if ( Game_mode & GM_MULTI ) {
967 multi_initiate_restore_game();
973 if (in_game && (Current_level_num < 0) && (secret_restore == 0)) {
974 HUD_init_message( "Can't restore in secret level!" );
978 if ( Newdemo_state == ND_STATE_RECORDING )
979 newdemo_stop_recording();
981 if ( Newdemo_state != ND_STATE_NORMAL )
986 if (filename_override) {
987 strcpy(filename, filename_override);
988 filenum = NUM_SAVES+1; // So we don't trigger autosave
989 } else if (!(filenum = state_get_restore_file(filename, 0))) {
995 // If not in multiplayer, do special secret level stuff.
996 // If Nsecret.sgc (where N = filenum) exists, then copy it to secret.sgc.
997 // If it doesn't exist, then delete secret.sgc
998 if (!secret_restore && !(Game_mode & GM_MULTI)) {
1000 char temp_fname[32], fc;
1002 if (filenum != -1) {
1004 fc = (filenum-10) + 'a';
1009 sprintf(temp_fname, "%csecret.sgc", fc);
1011 sprintf(temp_fname, ":Players:%csecret.sgc", fc);
1014 mprintf((0, "Trying to copy %s to secret.sgc.\n", temp_fname));
1016 if (cfexist(temp_fname))
1018 mprintf((0, "Copying %s to secret.sgc\n", temp_fname));
1019 rval = copy_file(temp_fname, SECRETC_FILENAME);
1020 Assert(rval == 0); // Oops, error copying temp_fname to secret.sgc!
1022 cfile_delete(SECRETC_FILENAME);
1026 // Changed, 11/15/95, MK, don't to autosave if restoring from main menu.
1027 if ((filenum != (NUM_SAVES+1)) && in_game) {
1028 char temp_filename[128];
1029 mprintf((0, "Doing autosave, filenum = %i, != %i!\n", filenum, NUM_SAVES+1));
1031 sprintf( temp_filename, "%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
1033 sprintf( temp_filename, ":Players:%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
1035 state_save_all(!in_game, secret_restore, temp_filename);
1038 if ( !secret_restore && in_game ) {
1040 choice = nm_messagebox( NULL, 2, "Yes", "No", "Restore Game?" );
1041 if ( choice != 0 ) {
1049 return state_restore_all_sub(filename, 0, secret_restore);
1052 extern void init_player_stats_new_ship(void);
1054 void ShowLevelIntro(int level_num);
1056 extern void do_cloak_invul_secret_stuff(fix old_gametime);
1057 extern void copy_defaults_to_robot(object *objp);
1059 int state_restore_all_sub(char *filename, int multi, int secret_restore)
1061 int ObjectStartLocation;
1062 int version,i, j, segnum;
1065 int current_level, next_level;
1068 char desc[DESC_LENGTH+1];
1070 char org_callsign[CALLSIGN_LEN+16];
1073 int nplayers; //,playid[12],mynum;
1074 player restore_players[MAX_PLAYERS];
1076 fix old_gametime = GameTime;
1078 #if defined(MACINTOSH) && !defined(NDEBUG)
1079 if ( strncmp(filename, ":Players:", 9) )
1083 fp = cfopen(filename, "rb");
1084 if ( !fp ) return 0;
1087 cfread(id, sizeof(char)*4, 1, fp);
1088 if ( memcmp( id, dgss_id, 4 )) {
1094 cfread(&version, sizeof(int), 1, fp);
1095 if (version < STATE_COMPATIBLE_VERSION) {
1101 cfread(desc, sizeof(char) * DESC_LENGTH, 1, fp);
1103 // Skip the current screen shot...
1104 cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
1106 // And now...skip the goddamn palette stuff that somebody forgot to add
1107 cfseek(fp, 768, SEEK_CUR);
1109 // Read the Between levels flag...
1110 cfread(&between_levels, sizeof(int), 1, fp);
1112 Assert(between_levels == 0); //between levels save ripped out
1114 // Read the mission info...
1115 cfread(mission, sizeof(char), 9, fp);
1116 mprintf ((0,"Missionname to load = %s\n",mission));
1118 if (!load_mission_by_name( mission )) {
1119 nm_messagebox( NULL, 1, "Ok", "Error!\nUnable to load mission\n'%s'\n", mission );
1125 cfread(¤t_level, sizeof(int), 1, fp);
1126 cfread(&next_level, sizeof(int), 1, fp);
1129 cfread(&GameTime, sizeof(fix), 1, fp);
1131 // Start new game....
1133 Game_mode = GM_NORMAL;
1134 Function_mode = FMODE_GAME;
1136 change_playernum_to(0);
1138 strcpy( org_callsign, Players[0].callsign );
1140 if (!secret_restore) {
1141 InitPlayerObject(); //make sure player's object set up
1142 init_player_stats_game(); //clear all stats
1145 strcpy( org_callsign, Players[Player_num].callsign );
1149 if (Game_mode & GM_MULTI)
1151 cfread(&state_game_id,sizeof(int), 1, fp);
1152 cfread(&Netgame,sizeof(netgame_info), 1, fp);
1153 cfread(&NetPlayers,sizeof(AllNetPlayers_info), 1, fp);
1154 cfread(&nplayers,sizeof(N_players), 1, fp);
1155 cfread(&Player_num,sizeof(Player_num), 1, fp);
1156 for (i=0;i<nplayers;i++)
1157 cfread(&restore_players[i], sizeof(player), 1, fp);
1158 #ifdef RISKY_PROPOSITION
1159 cfread(&robot_controlled[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1160 cfread(&robot_agitation[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1161 cfread(&robot_controlled_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1162 cfread(&robot_last_send_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1163 cfread(&robot_last_message_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1164 cfread(&robot_send_pending[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1165 cfread(&robot_fired[0], 4, MAX_ROBOTS_CONTROLLED, fp);
1167 for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
1168 cfread(&robot_fire_buf[i][0], 21, 1, fp);
1171 for (i=0;i<nplayers;i++)
1174 for (j=0;j<nplayers;j++)
1176 if ((!strcmp (restore_players[i].callsign,Players[j].callsign)) && Players[j].connected==1)
1179 restore_players[i].connected=found;
1181 memcpy (&Players,&restore_players,sizeof(player)*nplayers);
1184 if (network_i_am_master())
1186 for (i=0;i<N_players;i++)
1190 Players[i].connected=0;
1194 //Viewer = ConsoleObject = &Objects[Players[Player_num].objnum];
1202 StartNewLevelSub(current_level, 1, secret_restore);
1204 if (secret_restore) {
1205 player dummy_player;
1207 cfread(&dummy_player, sizeof(player), 1, fp);
1208 if (secret_restore == 1) { // This means he didn't die, so he keeps what he got in the secret level.
1209 Players[Player_num].level = dummy_player.level;
1210 Players[Player_num].last_score = dummy_player.last_score;
1211 Players[Player_num].time_level = dummy_player.time_level;
1213 Players[Player_num].num_robots_level = dummy_player.num_robots_level;
1214 Players[Player_num].num_robots_total = dummy_player.num_robots_total;
1215 Players[Player_num].hostages_rescued_total = dummy_player.hostages_rescued_total;
1216 Players[Player_num].hostages_total = dummy_player.hostages_total;
1217 Players[Player_num].hostages_on_board = dummy_player.hostages_on_board;
1218 Players[Player_num].hostages_level = dummy_player.hostages_level;
1219 Players[Player_num].homing_object_dist = dummy_player.homing_object_dist;
1220 Players[Player_num].hours_level = dummy_player.hours_level;
1221 Players[Player_num].hours_total = dummy_player.hours_total;
1222 do_cloak_invul_secret_stuff(old_gametime);
1224 Players[Player_num] = dummy_player;
1227 cfread(&Players[Player_num], sizeof(player), 1, fp);
1230 strcpy( Players[Player_num].callsign, org_callsign );
1232 // Set the right level
1233 if ( between_levels )
1234 Players[Player_num].level = next_level;
1236 // Restore the weapon states
1237 cfread(&Primary_weapon, sizeof(sbyte), 1, fp);
1238 cfread(&Secondary_weapon, sizeof(sbyte), 1, fp);
1240 select_weapon(Primary_weapon, 0, 0, 0);
1241 select_weapon(Secondary_weapon, 1, 0, 0);
1243 // Restore the difficulty level
1244 cfread(&Difficulty_level, sizeof(int), 1, fp);
1246 // Restore the cheats enabled flag
1248 cfread(&Cheats_enabled, sizeof(int), 1, fp);
1250 if ( !between_levels ) {
1251 Do_appearance_effect = 0; // Don't do this for middle o' game stuff.
1253 ObjectStartLocation = cftell(fp);
1254 //Clear out all the objects from the lvl file
1255 for (segnum=0; segnum <= Highest_segment_index; segnum++)
1256 Segments[segnum].objects = -1;
1259 //Read objects, and pop 'em into their respective segments.
1260 cfread(&i, sizeof(int), 1, fp);
1261 Highest_object_index = i-1;
1262 cfread(Objects, sizeof(object), i, fp);
1264 Object_next_signature = 0;
1265 for (i=0; i<=Highest_object_index; i++ ) {
1267 obj->rtype.pobj_info.alt_textures = -1;
1268 segnum = obj->segnum;
1269 obj->next = obj->prev = obj->segnum = -1;
1270 if ( obj->type != OBJ_NONE ) {
1272 if ( obj->signature > Object_next_signature )
1273 Object_next_signature = obj->signature;
1276 //look for, and fix, boss with bogus shields
1277 if (obj->type == OBJ_ROBOT && Robot_info[obj->id].boss_flag) {
1278 fix save_shields = obj->shields;
1280 copy_defaults_to_robot(obj); //calculate starting shields
1282 //if in valid range, use loaded shield value
1283 if (save_shields > 0 && save_shields <= obj->shields)
1284 obj->shields = save_shields;
1286 obj->shields /= 2; //give player a break
1290 special_reset_objects();
1291 Object_next_signature++;
1293 // 1 = Didn't die on secret level.
1294 // 2 = Died on secret level.
1295 if (secret_restore && (Current_level_num >= 0)) {
1296 set_pos_from_return_segment();
1297 if (secret_restore == 2)
1298 init_player_stats_new_ship();
1302 cfread(&i, sizeof(int), 1, fp);
1304 cfread(Walls, sizeof(wall), Num_walls, fp);
1306 //now that we have the walls, check if any sounds are linked to
1307 //walls that are now open
1308 for (i=0;i<Num_walls;i++) {
1309 if (Walls[i].type == WALL_OPEN)
1310 digi_kill_sound_linked_to_segment(Walls[i].segnum,Walls[i].sidenum,-1); //-1 means kill any sound
1313 //Restore exploding wall info
1314 if (version >= 10) {
1315 cfread(&i, sizeof(int), 1, fp);
1316 cfread(expl_wall_list, sizeof(*expl_wall_list), i, fp);
1320 cfread(&i, sizeof(int), 1, fp);
1322 cfread(ActiveDoors, sizeof(active_door), Num_open_doors, fp);
1324 if (version >= 14) { //Restore cloaking wall info
1325 cfread(&i, sizeof(int), 1, fp);
1326 Num_cloaking_walls = i;
1327 cfread(CloakingWalls, sizeof(cloaking_wall), Num_cloaking_walls, fp);
1330 //Restore trigger info
1331 cfread(&Num_triggers, sizeof(int), 1, fp);
1332 cfread(Triggers, sizeof(trigger), Num_triggers, fp);
1335 for (i=0; i<=Highest_segment_index; i++ ) {
1336 for (j=0; j<6; j++ ) {
1337 cfread(&Segments[i].sides[j].wall_num, sizeof(short), 1, fp);
1338 cfread(&Segments[i].sides[j].tmap_num, sizeof(short), 1, fp);
1339 cfread(&Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp);
1343 //Restore the fuelcen info
1344 cfread(&Control_center_destroyed, sizeof(int), 1, fp);
1345 cfread(&Countdown_timer, sizeof(int), 1, fp);
1346 cfread(&Num_robot_centers, sizeof(int), 1, fp);
1347 cfread(RobotCenters, sizeof(matcen_info), Num_robot_centers, fp);
1348 cfread(&ControlCenterTriggers, sizeof(control_center_triggers), 1, fp);
1349 cfread(&Num_fuelcenters, sizeof(int), 1, fp);
1350 cfread(Station, sizeof(FuelCenter), Num_fuelcenters, fp);
1352 // Restore the control cen info
1353 cfread(&Control_center_been_hit, sizeof(int), 1, fp);
1354 cfread(&Control_center_player_been_seen, sizeof(int), 1, fp);
1355 cfread(&Control_center_next_fire_time, sizeof(int), 1, fp);
1356 cfread(&Control_center_present, sizeof(int), 1, fp);
1357 cfread(&Dead_controlcen_object_num, sizeof(int), 1, fp);
1359 // Restore the AI state
1360 ai_restore_state( fp, version );
1362 // Restore the automap visited info
1363 cfread( Automap_visited, sizeof(ubyte), MAX_SEGMENTS, fp);
1365 // Restore hacked up weapon system stuff.
1366 Fusion_next_sound_time = GameTime;
1367 Auto_fire_fusion_cannon_time = 0;
1368 Next_laser_fire_time = GameTime;
1369 Next_missile_fire_time = GameTime;
1370 Last_laser_fired_time = GameTime;
1375 if ( version >= 7 ) {
1376 cfread(&state_game_id, sizeof(uint), 1, fp);
1377 cfread(&Laser_rapid_fire, sizeof(int), 1, fp);
1378 cfread(&Lunacy, sizeof(int), 1, fp); // Yes, writing this twice. Removed the Ugly robot system, but didn't want to change savegame format.
1379 cfread(&Lunacy, sizeof(int), 1, fp);
1384 if (version >= 17) {
1385 cfread(MarkerObject, sizeof(MarkerObject), 1, fp);
1386 cfread(MarkerOwner, sizeof(MarkerOwner), 1, fp);
1387 cfread(MarkerMessage, sizeof(MarkerMessage), 1, fp);
1394 cfread(&num, sizeof(int), 1, fp); //was NumOfMarkers
1395 cfread(&dummy, sizeof(int), 1, fp); //was CurMarker
1397 cfseek(fp, num * (sizeof(vms_vector) + 40), SEEK_CUR);
1399 for (num=0;num<NUM_MARKERS;num++)
1400 MarkerObject[num] = -1;
1404 if (secret_restore != 1)
1405 cfread(&Afterburner_charge, sizeof(fix), 1, fp);
1408 cfread(&dummy_fix,sizeof(fix), 1, fp);
1412 //read last was super information
1413 cfread(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
1414 cfread(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
1417 if (version >= 12) {
1418 cfread(&Flash_effect, sizeof(int), 1, fp);
1419 cfread(&Time_flash_last_played, sizeof(int), 1, fp);
1420 cfread(&PaletteRedAdd, sizeof(int), 1, fp);
1421 cfread(&PaletteGreenAdd, sizeof(int), 1, fp);
1422 cfread(&PaletteBlueAdd, sizeof(int), 1, fp);
1425 Time_flash_last_played = 0;
1427 PaletteGreenAdd = 0;
1431 // Load Light_subtracted
1432 if (version >= 16) {
1433 cfread(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
1434 apply_all_changed_light();
1435 compute_all_static_light(); // set static_light field in segment struct. See note at that function.
1438 for (i=0; i<=Highest_segment_index; i++)
1439 Light_subtracted[i] = 0;
1442 if (!secret_restore) {
1443 if (version >= 20) {
1444 cfread(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
1445 mprintf((0, "File: [%s] Read First_secret_visit: New value = %i\n", filename, First_secret_visit));
1447 First_secret_visit = 1;
1449 First_secret_visit = 0;
1453 if (secret_restore != 1)
1454 cfread(&Omega_charge,sizeof(fix), 1, fp);
1457 cfread(&dummy_fix,sizeof(fix), 1, fp);
1464 if (Game_mode & GM_MULTI) // Get rid of ships that aren't
1465 { // connected in the restored game
1466 for (i=0;i<nplayers;i++)
1468 mprintf ((0,"Testing %s = %d\n",Players[i].callsign,Players[i].connected));
1469 if (Players[i].connected!=1)
1471 network_disconnect_player (i);
1472 create_player_appearance_effect(&Objects[Players[i].objnum]);
1473 mprintf ((0,"Killing player ship %s!\n",Players[i].callsign));
1480 // Load in bitmaps, etc..
1481 //!! piggy_load_level_data(); //already done by StartNewLevelSub()
1486 // When loading a saved game, segp->static_light is bogus.
1487 // This is because apply_all_changed_light, which is supposed to properly update this value,
1488 // cannot do so because it needs the original light cast from a light which is no longer there.
1489 // That is, a light has been blown out, so the texture remaining casts 0 light, but the static light
1490 // which is present in the static_light field contains the light cast from that light.
1491 void compute_all_static_light(void)
1495 for (i=0; i<=Highest_segment_index; i++) {
1499 segp = &Segments[i];
1502 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
1505 sidep = &segp->sides[j];
1508 total_light += sidep->uvls[k].l;
1511 Segment2s[i].static_light = total_light/(MAX_SIDES_PER_SEGMENT*4);
1517 int state_get_game_id(char *filename)
1523 char desc[DESC_LENGTH+1];
1527 mprintf((0, "Restoring multigame from [%s]\n", filename));
1529 fp = cfopen(filename, "rb");
1530 if ( !fp ) return 0;
1533 cfread(id, sizeof(char)*4, 1, fp);
1534 if ( memcmp( id, dgss_id, 4 )) {
1540 cfread(&version, sizeof(int), 1, fp);
1541 if (version < STATE_COMPATIBLE_VERSION) {
1547 cfread(desc, sizeof(char)*DESC_LENGTH, 1, fp);
1549 // Skip the current screen shot...
1550 cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
1552 // And now...skip the palette stuff that somebody forgot to add
1553 cfseek(fp, 768, SEEK_CUR);
1555 // Read the Between levels flag...
1556 cfread(&between_levels, sizeof(int), 1, fp);
1558 Assert(between_levels == 0); //between levels save ripped out
1560 // Read the mission info...
1561 cfread(mission, sizeof(char), 9, fp);
1563 cfread(&dumbint, sizeof(int), 1, fp);
1564 cfread(&dumbint, sizeof(int), 1, fp);
1567 cfread(&dumbint, sizeof(fix), 1, fp);
1569 cfread(&state_game_id, sizeof(int), 1, fp);
1571 return (state_game_id);
1574 #if defined(POLY_ACC)
1575 //void screen_shot_pa(ubyte *dst,ushort *src)
1577 // //ushort *src = pa_get_buffer_address(0),
1579 // fix u, v, du, dv;
1584 // du = (640.0 / (float)THUMBNAIL_W) * 65536.0;
1585 // dv = (480.0 / (float)THUMBNAIL_H) * 65536.0;
1587 // for(v = h = 0; h != THUMBNAIL_H; ++h)
1589 // s = src + f2i(v) * 640;
1591 // for(u = w = 0; w != THUMBNAIL_W; ++w)
1594 // *dst++ = gr_find_closest_color((s[ui] >> 9) & 0x3e, (s[ui] >> 4) & 0x3e, (s[ui] << 1) & 0x3e);
1600 void screen_shot_pa(grs_canvas *dcanv,grs_canvas *scanv)
1602 #if !defined(MACINTOSH)
1607 Assert(scanv->cv_w == dcanv->cv_w && scanv->cv_h == dcanv->cv_h);
1611 src = (ushort *) scanv->cv_bitmap.bm_data;
1612 dst = dcanv->cv_bitmap.bm_data;
1614 #ifdef PA_3DFX_VOODOO
1615 src=(ushort *)pa_set_back_to_read();
1618 for (y=0; y<scanv->cv_h; y++) {
1619 for (x=0; x<scanv->cv_w; x++) {
1620 #ifdef PA_3DFX_VOODOO
1621 *dst++ = gr_find_closest_color((*src >> 10) & 0x3e, (*src >> 5) & 0x3f, (*src << 1) & 0x3e);
1623 *dst++ = gr_find_closest_color((*src >> 9) & 0x3e, (*src >> 4) & 0x3e, (*src << 1) & 0x3e);
1628 src = (ushort *) (((ubyte *) src) + (scanv->cv_bitmap.bm_rowsize - (scanv->cv_bitmap.bm_w*PA_BPP)));
1629 dst += dcanv->cv_bitmap.bm_rowsize - dcanv->cv_bitmap.bm_w;
1631 #ifdef PA_3DFX_VOODOO
1632 pa_set_front_to_read();