/* * Save a character and inventory. * Would be cool to save NPC's too for quest purposes, * some of the infrastructure is provided. */ void save_char_obj( CHAR_DATA *ch ) { FILE *fp; char buf [ MAX_STRING_LENGTH ]; char strsave [ MAX_INPUT_LENGTH ]; if ( IS_NPC( ch ) || ch->level < 2 ) return; if ( ch->desc && ch->desc->original ) ch = ch->desc->original; ch->save_time = current_time; fclose( fpReserve ); /* player files parsed directories by Yaz 4th Realm */ sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( ch->name ) ); if ( !( fp = fopen( strsave, "w" ) ) ) { sprintf( buf, "Save_char_obj: fopen %s: ", ch->name ); bug( buf, 0 ); perror( strsave ); } else { fwrite_char( ch, fp ); if ( ch->carrying ) fwrite_obj( ch, ch->carrying, fp, 0 ); fprintf( fp, "#END\n" ); } fclose( fp ); fpReserve = fopen( NULL_FILE, "r" ); return; }
/* * Save a character and inventory. * Would be cool to save NPC's too for quest purposes, * some of the infrastructure is provided. */ void save_char_obj( CHAR_DATA * ch ) { FILE * fp; CHAR_DATA * pet; char buf[ MAX_STRING_LENGTH ]; char strsave[ MAX_INPUT_LENGTH ]; if ( IS_NPC( ch ) ) { return; } if ( ch->desc && ch->desc->original ) { ch = ch->desc->original; } update_playerlist( ch ); ch->save_time = current_time; fclose( fpReserve ); /* player files parsed directories by Yaz 4th Realm */ sprintf( strsave, "%s%c/%s", PLAYER_DIR, LOWER( ch->name[ 0 ] ), capitalize( ch->name ) ); if ( !( fp = fopen( strsave, "w" ) ) ) { sprintf( buf, "Save_char_obj: fopen %s: ", ch->name ); bug( buf, 0 ); perror( strsave ); } else { fwrite_char( ch, fp ); if ( ch->carrying ) { fwrite_obj( ch, ch->carrying, fp, 0, FALSE ); } if ( !IS_NPC( ch ) && ch->pcdata->storage ) { fwrite_obj( ch, ch->pcdata->storage, fp, 0, TRUE ); } for ( pet = ch->in_room->people; pet; pet = pet->next_in_room ) { if ( IS_NPC( pet ) ) { if ( CHECK_BIT( pet->act, ACT_PET ) && ( pet->master == ch ) ) { save_pet( ch, fp, pet ); break; } } } tail_chain(); fprintf( fp, "#END\n" ); } fclose( fp ); fpReserve = fopen( NULL_FILE, "r" ); return; }
/* * Save a character and inventory. * Would be cool to save NPC's too for quest purposes, * some of the infrastructure is provided. */ bool save_char_obj( struct char_data *ch ) { FILE *fp; char buf [ MAX_STRING_LENGTH ]; char strsave [ MAX_INPUT_LENGTH ]; bool rval = FALSE; if ( IS_NPC( ch ) ) // || GET_LEVEL( ch ) < 2 ) return rval; if ( GET_DESC(ch) && GET_DESC(ch)->original ) ch = GET_DESC(ch)->original; // GET_SAVED(ch) = time( 0 ); /* close down the reserve descriptor -- don't forget to reopen it */ fclose( fpReserve ); sprintf( strsave, "%s/%s/%s", PLAYER_DIR, player_dir( GET_NAME( ch ) ), capitalize( GET_NAME( ch ) ) ); if ( !( fp = fopen( strsave, "w" ) ) ) { sprintf( buf, "save_char_obj: fopen %s: ", GET_NAME( ch ) ); log( buf ); perror( strsave ); rval = FALSE; } else { fwrite_char( ch, fp ); if ( ch->carrying ) fwrite_obj_char( ch, ch->carrying, fp, 0 ); if ( GET_ALIASES(ch) ) fwrite_alias( ch, GET_ALIASES(ch), fp ); fprintf( fp, "#END\n" ); fclose( fp ); rval = TRUE; } fpReserve = fopen( NULL_FILE, "r" ); return rval; }
/* * Save a character and inventory. * Would be cool to save NPC's too for quest purposes, * some of the infrastructure is provided. */ void save_char_obj( CHAR_DATA *ch ) { char strsave[MAX_INPUT_LENGTH]; FILE *fp; if ( IS_NPC(ch) || ch->level < 2 ) return; if ( ch->desc != NULL && ch->desc->original != NULL ) ch = ch->desc->original; ch->save_time = current_time; fclose( fpReserve ); /* player files parsed directories by Yaz 4th Realm */ #if !defined(machintosh) && !defined(MSDOS) sprintf( strsave, "%s%s%s%s", PLAYER_DIR, initial( ch->name ), "/", capitalize( ch->name ) ); #else sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( ch->name ) ); #endif if ( ( fp = fopen( strsave, "w" ) ) == NULL ) { bug( "Save_char_obj: fopen", 0 ); perror( strsave ); } else { fwrite_char( ch, fp ); if ( ch->carrying != NULL ) fwrite_obj( ch, ch->carrying, fp, 0 ); fprintf( fp, "#END\n" ); } fclose( fp ); fpReserve = fopen( NULL_FILE, "r" ); return; }