Difference for main/state.c from version 1.6 to 1.7


version 1.6 version 1.7
Line 19
 
Line 19
  * Functions to save/restore game state.   * Functions to save/restore game state.
  *    *
  * $Log$   * $Log$
    * Revision 1.7  2002/03/27 00:30:35  donut
    * show savegame thumbnail in save mode too (and refactor savegame chooser code) (patch from Steven Mueller)
    *
  * Revision 1.6  2002/03/26 05:33:14  donut   * Revision 1.6  2002/03/26 05:33:14  donut
  * fix savegame thumbnail saving in OGL   * fix savegame thumbnail saving in OGL
  *   *
Line 336
 
Line 339
 // if ( sc_last_item != citem ) {  // if ( sc_last_item != citem ) {
 // sc_last_item = citem;  // sc_last_item = citem;
  if ( citem > 0 ) {   if ( citem > 0 ) {
    int w=SWIDTH * THUMBNAIL_W / 320;
    int h=SHEIGHT * THUMBNAIL_H / 200;
  if ( sc_bmp[citem-1] ) {   if ( sc_bmp[citem-1] ) {
 // gr_set_current_canvas( NULL );  // gr_set_current_canvas( NULL );
  if (SWIDTH>320 || SHEIGHT>200){   if (SWIDTH>320 || SHEIGHT>200){
  grs_canvas *tmp,*old;   grs_canvas *tmp,*old;
  int w;  
  old=grd_curcanv;   old=grd_curcanv;
  w=SWIDTH/(320.0/THUMBNAIL_W);  
  tmp=gr_create_sub_canvas(grd_curcanv, (grd_curcanv->cv_bitmap.bm_w-w)/2,   tmp=gr_create_sub_canvas(grd_curcanv, (grd_curcanv->cv_bitmap.bm_w-w)/2,
  items[0].y-5, w, SHEIGHT/(200.0/sc_bmp[citem-1]->bm_h));   items[0].y-5, w, h);
  gr_set_current_canvas(tmp);   gr_set_current_canvas(tmp);
  show_fullscr( sc_bmp[citem-1] );   show_fullscr( sc_bmp[citem-1] );
 // gr_set_current_canvas(NULL);  // gr_set_current_canvas(NULL);
Line 352
 
Line 355
  gr_free_sub_canvas(tmp);   gr_free_sub_canvas(tmp);
  }else   }else
  gr_bitmap( (grd_curcanv->cv_bitmap.bm_w-THUMBNAIL_W)/2,items[0].y-5, sc_bmp[citem-1] );   gr_bitmap( (grd_curcanv->cv_bitmap.bm_w-THUMBNAIL_W)/2,items[0].y-5, sc_bmp[citem-1] );
    } else {
    gr_setcolor( BM_XRGB( 0, 0, 0 ) );
    gr_rect( (grd_curcanv->cv_bitmap.bm_w - w) / 2,     items[0].y - 5,
             (grd_curcanv->cv_bitmap.bm_w + w) / 2 - 1, items[0].y - 5 + SHEIGHT/(200.0/THUMBNAIL_H) - 1);
  }   }
  }   }
 // }   // }
Line 372
 
Line 379
  *string = 0; // NULL terminate   *string = 0; // NULL terminate
 }  }
   
 int state_get_save_file(char * fname, char * dsc, int multi )  /* Present a menu for selection of a savegame filename.
 {   * For saving, dsc should be a pre-allocated buffer into which the new
  FILE * fp;   * savegame description will be stored.
  int i, choice, version;   * For restoring, dsc should be NULL, in which case empty slots will not be
  newmenu_item m[NUM_SAVES+1];   * selectable and savagames descriptions will not be editable.
  char filename[NUM_SAVES][20];   */
  char desc[NUM_SAVES][DESC_LENGTH+16];  int state_get_savegame_filename(char * fname, char * dsc, int multi, char * caption )
  char id[5];  
  int valid=0;  
    
  for (i=0;i<NUM_SAVES; i++ ) {  
  sc_bmp[i] = NULL;  
  if ( !multi )  
  sprintf( filename[i], "%s.sg%d", Players[Player_num].callsign, i );  
  else  
  sprintf( filename[i], "%s.mg%d", Players[Player_num].callsign, i );  
 //added on 9/30/98 by Matt Mueller to fix savegames in linux  
  strlwr(filename[i]);  
 //end addition -MM  
  valid = 0;  
  fp = fopen( filename[i], "rb" );  
  if ( fp ) {  
  //Read id  
  fread( id, sizeof(char)*4, 1, fp );  
  if ( !memcmp( id, dgss_id, 4 )) {  
  //Read version  
  fread( &version, sizeof(int), 1, fp );  
  if (version >= STATE_COMPATIBLE_VERSION) {  
  // Read description  
  fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp );  
  //rpad_string( desc[i], DESC_LENGTH-1 );  
  // Read thumbnail  
  //sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );  
  //fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp );  
  valid = 1;  
  }  
  }   
  fclose(fp);  
  }  
  if (!valid) {  
  strcpy( desc[i], TXT_EMPTY );  
  //rpad_string( desc[i], DESC_LENGTH-1 );  
  }  
  m[i].type = NM_TYPE_INPUT_MENU; m[i].text = desc[i]; m[i].text_len = DESC_LENGTH-1;  
  }  
   
  sc_last_item = -1;  
  choice = newmenu_do1( NULL, "Save Game", NUM_SAVES, m, NULL, state_default_item );  
   
  for (i=0; i<NUM_SAVES; i++ ) {  
  if ( sc_bmp[i] )  
  gr_free_bitmap( sc_bmp[i] );  
  }  
   
  if (choice > -1) {  
  strcpy( fname, filename[choice] );  
  strcpy( dsc, desc[choice] );  
  state_default_item = choice;  
  return choice+1;  
  }  
  return 0;  
 }  
   
 int state_get_restore_file(char * fname, int multi )  
 {  {
  FILE * fp;   FILE * fp;
  int i, choice, version, nsaves;   int i, choice, version, nsaves;
Line 481
 
Line 431
  // Read description   // Read description
  fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp );   fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp );
  //rpad_string( desc[i], DESC_LENGTH-1 );   //rpad_string( desc[i], DESC_LENGTH-1 );
  m[i+1].type = NM_TYPE_MENU; m[i+1].text = desc[i];;   if (dsc == NULL) m[i+1].type = NM_TYPE_MENU;
  // Read thumbnail   // Read thumbnail
  sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );   sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
  fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp );   fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp );
Line 494
 
Line 444
  if (!valid) {   if (!valid) {
  strcpy( desc[i], TXT_EMPTY );   strcpy( desc[i], TXT_EMPTY );
  //rpad_string( desc[i], DESC_LENGTH-1 );   //rpad_string( desc[i], DESC_LENGTH-1 );
  m[i+1].type = NM_TYPE_TEXT; m[i+1].text = desc[i];   if (dsc == NULL) m[i+1].type = NM_TYPE_TEXT;
    }
    if (dsc != NULL) {
    m[i+1].type = NM_TYPE_INPUT_MENU;
  }   }
    m[i+1].text_len = DESC_LENGTH-1;
    m[i+1].text = desc[i];
  }   }
   
  if ( nsaves < 1 ) {   if ( dsc == NULL && nsaves < 1 ) {
  nm_messagebox( NULL, 1, "Ok", "No saved games were found!" );   nm_messagebox( NULL, 1, "Ok", "No saved games were found!" );
  return 0;   return 0;
  }   }
   
  sc_last_item = -1;   sc_last_item = -1;
  choice = newmenu_do3( NULL, "Select Game to Restore", NUM_SAVES+1, m, state_callback, state_default_item+1, NULL, 190, -1 );   choice = newmenu_do3( NULL, caption, NUM_SAVES+1, m, state_callback, state_default_item+1, NULL, -1, -1 );
   
  for (i=0; i<NUM_SAVES; i++ ) {   for (i=0; i<NUM_SAVES; i++ ) {
  if ( sc_bmp[i] )   if ( sc_bmp[i] )
Line 513
 
Line 468
   
  if (choice > 0) {   if (choice > 0) {
  strcpy( fname, filename[choice-1] );   strcpy( fname, filename[choice-1] );
    if ( dsc != NULL ) strcpy( dsc, desc[choice-1] );
  state_default_item = choice - 1;   state_default_item = choice - 1;
  return choice;   return choice;
  }   }
  return 0;   return 0;
   }
   
   int state_get_save_file(char * fname, char * dsc, int multi )
   {
    return state_get_savegame_filename(fname, dsc, multi, "Save Game");
   }
   
   int state_get_restore_file(char * fname, int multi )
   {
    return state_get_savegame_filename(fname, NULL, multi, "Select Game to Restore");
 }  }
   
 int state_save_old_game(int slotnum, char * sg_name, player * sg_player,   int state_save_old_game(int slotnum, char * sg_name, player * sg_player,

Legend:
line(s) removed in v.1.6 
line(s) changed
 line(s) added in v.1.7