-+-+-+-+-+-+-+-+ START OF PART 9 -+-+-+-+-+-+-+-+ X holdmap`5Bk`5D.holdchar = map`5Bi`5D`5Bj`5D.mapchar; X`09 holdmap`5Bk`5D.num = map`5Bi`5D`5Bj`5D.number; X holdmap`5Bk`5D.x = j; X`09 holdmap`5Bk`5D.y = i; X `09 k++; X`09`7D X holdmap`5Bk`5D.num = -5; X X if ( fwrite( &player, sizeof(player), 1, outfile) != NULL) `7B X if ( fwrite( &ppos, sizeof(ppos), 1, outfile) != NULL) X if ( fwrite( &monsters, sizeof(monsters), 1, outfile) != NULL) X`09if ( fwrite( &BACKPACK, sizeof(BACKPACK), 1, outfile) != NULL) X/* `09 if ( fwrite( &(maparray`5B0`5D`5B0`5D), sizeof(maparray), 1, outfil Ve) != NULL)`20 X`09 if ( fwrite( &map, sizeof(map), 1, outfile) != NULL) X*/ X`09 if ( fwrite( &holdmap, sizeof(holdmap), 1, outfile) != NULL) X`09 if ( fwrite( &flags, sizeof(flags), 1, outfile) != NULL) X ret = E_SAVED; X `7D X else ret = E_WRITESAVE; X `7D Xelse ret = E_OPENSAVE; Xfclose ( outfile); Xif ( stat( savefile, &sfstat) != 0) ret = E_WRITESAVE; Xelse if ( (outfile = fopen( savefile, "a")) == NULL) ret = E_OPENSAVE; Xelse `7B X if ( fwrite( &sfstat, sizeof( sfstat), 1, outfile) == NULL) ret = E_WRITE VSAVE; X fclose( outfile); X`7D Xreturn ( ret); X`7D X X Xshort restore() X`7B XFILE *infile; Xshort ret = 0; Xstruct stat oldsfstat; X Xif ( stat( savefile, &oldsfstat) != 0) ret = E_NOSAVEFILE; Xelse `7B Xprintf("\33`5B24;1HRestoring game...\n"); Xif ( (infile = fopen( savefile,"r")) != NULL) `7B X if ( fread( &player, sizeof(player), 1, infile) != NULL) `7B X if ( fread( &ppos, sizeof(ppos), 1, infile) != NULL)`20 X if ( fread( &monsters, sizeof(monsters), 1, infile) != NULL) X`09if ( fread( &BACKPACK, sizeof(BACKPACK), 1, infile) != NULL) X/*`09 if ( fread( &(maparray`5B0`5D`5B0`5D), sizeof(maparray), 1, infile) ! V= NULL)`20 X if ( fread( &map, sizeof(map), 1, infile) != NULL) X*/ X`09 if ( fread( &holdmap, sizeof(holdmap), 1, infile) != NULL) X`09 if ( fread( &flags, sizeof(flags), 1, infile) != NULL) X`09 if ( fread( &sfstat, sizeof(sfstat), 1, infile) != NULL) `7B X`09 if ( (strcmp( username, SUPERUSER) != 0) &&`20 X`09`09( (strcmp( username, player.username) != 0) `7C`7C X`09`09 (sfstat.st_dev != oldsfstat.st_dev) `7C`7C X (sfstat.st_mode != oldsfstat.st_mode) `7C`7C X (sfstat.st_uid != oldsfstat.st_uid) `7C`7C X (sfstat.st_gid != oldsfstat.st_gid) `7C`7C X/* for some reason, there is a slight delay in saving, so the time is off */ X/* by a decimal value.. no problem, just check to see if it's close */ X (oldsfstat.st_mtime - sfstat.st_mtime > 2))) X ret = E_DATACORRUPT; X else `7B X/* in case the operator is restoring someone else's game */ X if ( strcmp( username, SUPERUSER) == 0 &&`20 X`09 strcmp( username, player.username) != 0) operator = TRUE; X`09 else operator = player.operator; X strcpy( username, player.username); X underchar = player.underchar; X level = player.level; X health = player.health; X speed = player.speed; X experience= player.experience; X wealth = player.wealth; X `09 monkilled = player.monkilled; X kills = player.kills; X`09 STR = player.STR; X`09 INT = player.INT; X `09 DEX = player.DEX; X `09 CON = player.CON; X`09 BUSE = player.BUSE; X`09 delx = player.delx; X dely = player.dely; X MAXHEALTH = player.MAXHEALTH; X`09 MAXWEIGHT = player.MAXWEIGHT; X `09 CURWEIGHT = player.CURWEIGHT; X`09 WIELD = player.WIELD; X WORN = player.WORN; X ALTWEAP = player.ALTWEAP; X KEYPOSESS = player.KEYPOSESS; X`09 DIFFICULTY = player.DIFFICULTY; X/* X for (i=0; i< MAXROWS; i++) `20 X for (j=0; j< MAXCOLS; j++) X maparray`5Bi`5D`5Bj`5D = map`5Bi`5D`5Bj`5D.mapchar; X*/ X ret = 0; X fclose ( infile); X `7D X `7D X `7D X else ret = E_READSAVE; X `7D Xelse ret = E_OPENSAVE; Xfclose ( infile); X`7D Xreturn ( ret); X`7D $ CALL UNPACK SAVE.C;1 1750733133 $ create 'f' X#include stdio X#include "aralu.h" X X Xstatic short scoreentries; Xstatic short rank; Xstatic struct `7B X char user`5B10`5D; X short level, kills, exp; X`7D scoretable`5BMAXSCOREENTRIES+1`5D; Xstatic FILE *scf; X X Xshort score() X`7B Xshort ret = 0; X X if( (ret = readscore()) == 0) X if( (ret = makescore()) == 0) X`09 if( (ret = writescore()) == 0) X`09 showscore(); X return( (ret == 0) ? E_ENDGAME : ret); X`7D X X Xshort outputscore() X`7B Xshort ret; X X if( (ret = readscore()) == 0) X showscore(); X return( (ret == 0) ? E_ENDGAME : ret); X`7D X X Xreadscore() `7B X X short rank; X short ret = 0; X X if( (scf = fopen( scorefile, "r")) == NULL) X ret = E_OPENSCORE; X else `7B X while(fscanf(scf,"%d",&rank)!=EOF && rank < MAXSCOREENTRIES) X`09 `7B X fscanf( scf, "%10s %8d %8d %8d\n", scoretable`5Brank`5D.user, V`20 X`09 &scoretable`5Brank`5D.level,&scoretable`5Brank`5D.kills,&scoretable`5Bra Vnk`5D.exp); X scoreentries++; X `7D X `7D X fclose( scf); X return( ret); X`7D X X Xmakescore() `7B X X short ret = 0, pos, i, build = 1, insert; X X if( (pos = finduser()) > -1) `7B`09/* user already in score file */ X insert = (experience + wealth > scoretable`5Bpos`5D.exp) X`09 `7C`7C ( (level == scoretable`5Bpos`5D.level) && X (kills > scoretable`5Bpos`5D.kills) X`09`09 ) X`09 `7C`7C ( (level == scoretable`5Bpos`5D.level) && X`09`09 (kills == scoretable`5Bpos`5D.kills) && X`09`09 (experience + wealth > scoretable`5Bpos`5D.exp) X`09`09 ); X if( insert) `7B `09`09`09/* delete existing entry */ X`09 for( i = pos; i < scoreentries-1; i++) X`09 cp_entry( i, i+1); X`09 scoreentries--; X `7D X else build = 0; X `7D X else if( scoreentries == MAXSCOREENTRIES+1) X ret = E_READSCORE;`20 X if( (ret == 0) && build) `7B X pos = findpos();`09`09`09/* find the new score position */ X if( pos > -1) `7B`09`09`09/* score table not empty */ X`09 for( i = scoreentries; i > pos; i--) X`09 cp_entry( i, i-1); X `7D X else pos = scoreentries; X X strcpy( scoretable`5Bpos`5D.user, username); X scoretable`5Bpos`5D.level = level; X scoretable`5Bpos`5D.kills = kills; X scoretable`5Bpos`5D.exp = experience + wealth; X/* scoreentries++; */ X `7D X return( ret); X`7D X X Xfinduser() `7B X X short i, found = 0; X X for( i = 0; (i < scoreentries) && (! found); i++) X found = (strcmp( scoretable`5Bi`5D.user, username) == 0); X return( (found) ? i-1 : -1); X`7D X X Xfindpos() `7B X`20 X short i, found = 0; X X for( i = 0; (i < scoreentries) && (! found); i++) X found = (experience + wealth > scoretable`5Bi`5D.exp) X`09 `7C`7C ( (level == scoretable`5Bi`5D.level) && X (kills > scoretable`5Bi`5D.kills) X`09`09 ) X`09 `7C`7C ( (level == scoretable`5Bi`5D.level) && X`09`09 (kills == scoretable`5Bi`5D.kills) && X`09`09 (experience + wealth > scoretable`5Bi`5D.exp) X`09`09 ); X return( (found) ? i-1 : -1); X`7D X X Xwritescore() `7B X X short ret = 0; X long tmp; X char score_string`5B70`5D; X X if( (scf = fopen( scorefile, "r+")) == NULL) X ret = E_OPENSCORE; X else `7B X for (tmp = 0; tmp < scoreentries; tmp++) `7B X sprintf(score_string," %2d %10s %8d %8d %8d", X tmp,scoretable`5Btmp`5D.user,scoretable`5Btmp`5D.level, X scoretable`5Btmp`5D.kills,scoretable`5Btmp`5D.exp); X while(strlen(score_string) < 70) strcat(score_string," "); X score_string`5B70`5D = '\0'; X if (fprintf(scf,"%s\n",score_string) == NULL)`20 X `7Bfclose( scf); return(E_WRITESCORE);`7D X `7D X `7D X fclose( scf); X return( ret); X`7D X Xshowscore() `7B X X short i; X X fprintf( stdout, " Rank User Level Kills Experience\n"); X fprintf( stdout, "==================================================\n"); X for ( i = 0; i < scoreentries; i++) X printf(" %2d %10s %8d %8d %8d\n",i+1,scoretable`5Bi`5D.user, X`09 scoretable`5Bi`5D.level,scoretable`5Bi`5D.kills,scoretable`5Bi`5D.ex Vp); X`7D X X Xcp_entry( i1, i2) Xregister short i1, i2; X`7B X strcpy( scoretable`5Bi1`5D.user, scoretable`5Bi2`5D.user); X scoretable`5Bi1`5D.level = scoretable`5Bi2`5D.level; X scoretable`5Bi1`5D.kills = scoretable`5Bi2`5D.kills; X scoretable`5Bi1`5D.exp = scoretable`5Bi2`5D.exp; X`7D X X X Xshort create_scorefile() X`7B XFILE *newfile; Xshort i; Xshort ret = 0; Xshort file_count; Xchar blank_line`5B70`5D; X Xif ( ( newfile = fopen(scorefile,"w")) != NULL) `7B X for (i=0; i<70; i++)`20 X blank_line`5Bi`5D = ' '; /* Make the blank line to put into the score f Vile */ X blank_line`5B70`5D = '\0'; X for (file_count=0; file_count < MAXSCOREENTRIES; file_count++) X if( fprintf( newfile,"%s\n", blank_line) == NULL) ret = E_WRITESCORE; X fclose( newfile); X`7D Xelse ret = E_OPENSCORE; Xreturn( ret); X`7D $ CALL UNPACK SCORE.C;1 1694535629 $ create 'f' X############################################################################ V######################################################## X# # # # # # V # # # # # # #### #### # X# @ # # # # # V # # # # # # + # # X# # # # # # #### V #### # # # # # # # ######### # X# # # ####### #### # # # # ## V # # # # # ### ### ### # X###### ################# ## ###### ############ ############ V # ########### # # # # # ##### ##### ###### X# # # ######## # ## V #### # # # # # # X###### ##### ######### ######### ### # ############ ######## V # # # # # # ##### ###### # X# # # # # ##### # ## V # ### #### ###### # # # ############### #$$$$# # X# # ####### ####### ###### # # ##### ######## ## # V # # # # # ############### #$`7C`7C$# # X# # # # ###### # ######## ## # V # # # # # ############### #$$$$# # X# ####### ################### ############## ## # V ### # # # ############ ###### # X####### ################## ####################### # # V####### ##### #### ######## # X# ###1### # # ###2### # # # V ####### ####### ####### ##### X################ ######### # ####### ######### #### # # V ### ################### # # # # # # X# ######## ########## #### ##### ############### # # # V ##### ####### # # # ## - # # # X# ######## # # ##### ########### #### ########## # # V################# ####### # # # # # # # X# ######## ############### ######### ####### # V # # # # # # # # X# # ############# ####### ################## # V # # # # # # # # # # # # # ## # # # # # # X### ########## ################# # - - # # V # # # # # # # # # # # # # # X# # # - - ########## ############### - # V # # # # # # # # # # # # # # # # # # X# # # - - # # - - - # # V # # # # # # # # # # # # # # # # X#### # - - - - # # - - - # # V # # # # # # # # # # # # # # # # X# # - - - - - # V # # # # # # # # # # # # - # # # X# # - - - - - - # # V # # # # # # # # # # # # # # # # X# # - - - - - - # # V # # # # # # # # ## # # # # # # X#### ##### ################################################################# V# ##### ##### ##### ########################## ######### X# # # # V #`7B`7B`7 VB`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B# ## # X# # # # # ## V #####################`7B=================== V== ## # X# # # # ## # # V `7B`7B`7B`7B`7B`7B`7B`7B`7B`7B"`7B`7B`7B`7 VB`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B# # V## # X# # # # # # # # V `7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B V`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B`7B`7B# ## V# # X# # ############ ### # # # # V =================="==================== # V### #### X# ## # ############ # V `7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B V`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B`7B# # V # X# ### ############ # # # V `7B`7B`7B`7B`7B`7B`7B`7B"`7B`7B`7B`7B`7B`7 VB`7B`7B`7B`7B`7B################## # # X# #### ###$$$$### # ################## # V #################### # # V # X# ##### ###$$### # # # # - # # +-+-+-+-+-+-+-+- END OF PART 9 +-+-+-+-+-+-+-+-