Split get_rnd_toptenentry from tt_oname

This commit is contained in:
Pasi Kallinen
2015-12-28 18:06:48 +02:00
parent 32305ace5c
commit a5ed69288f
2 changed files with 32 additions and 16 deletions

View File

@@ -2299,6 +2299,7 @@ E void NDECL(timer_sanity_check);
E void FDECL(formatkiller, (char *, unsigned, int, BOOLEAN_P)); E void FDECL(formatkiller, (char *, unsigned, int, BOOLEAN_P));
E void FDECL(topten, (int, time_t)); E void FDECL(topten, (int, time_t));
E void FDECL(prscore, (int, char **)); E void FDECL(prscore, (int, char **));
E struct toptenentry *NDECL(get_rnd_toptenentry);
E struct obj *FDECL(tt_oname, (struct obj *)); E struct obj *FDECL(tt_oname, (struct obj *));
/* ### track.c ### */ /* ### track.c ### */

View File

@@ -1171,25 +1171,19 @@ boolean fem;
/* /*
* Get a random player name and class from the high score list, * Get a random player name and class from the high score list,
* and attach them to an object (for statues or morgue corpses).
*/ */
struct obj * struct toptenentry *
tt_oname(otmp) get_rnd_toptenentry()
struct obj *otmp;
{ {
int rank; int rank, i;
register int i;
register struct toptenentry *tt;
FILE *rfile; FILE *rfile;
struct toptenentry tt_buf; register struct toptenentry *tt;
static struct toptenentry tt_buf;
if (!otmp)
return (struct obj *) 0;
rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); rfile = fopen_datafile(RECORD, "r", SCOREPREFIX);
if (!rfile) { if (!rfile) {
impossible("Cannot open record file!"); impossible("Cannot open record file!");
return (struct obj *) 0; return NULL;
} }
tt = &tt_buf; tt = &tt_buf;
@@ -1207,13 +1201,34 @@ pickentry:
rewind(rfile); rewind(rfile);
goto pickentry; goto pickentry;
} }
otmp = (struct obj *) 0; tt = NULL;
} else {
set_corpsenm(otmp, classmon(tt->plrole, (tt->plgend[0] == 'F')));
otmp = oname(otmp, tt->name);
} }
(void) fclose(rfile); (void) fclose(rfile);
return tt;
}
/*
* Attach random player name and class from high score list
* to an object (for statues or morgue corpses).
*/
struct obj *
tt_oname(otmp)
struct obj *otmp;
{
struct toptenentry *tt;
if (!otmp)
return (struct obj *) 0;
tt = get_rnd_toptenentry();
if (!tt)
return (struct obj *) 0;
set_corpsenm(otmp, classmon(tt->plrole, (tt->plgend[0] == 'F')));
otmp = oname(otmp, tt->name);
return otmp; return otmp;
} }