From: Pasi Kallinen Date: Mon, 28 Dec 2015 16:06:48 +0000 (+0200) Subject: Split get_rnd_toptenentry from tt_oname X-Git-Tag: NetHack-3.6.1_RC01~1102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5ed69288fd0daf56a66ffd2e306c1681b685abc;p=nethack Split get_rnd_toptenentry from tt_oname --- diff --git a/include/extern.h b/include/extern.h index a74ea10a4..c25c634b6 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2299,6 +2299,7 @@ E void NDECL(timer_sanity_check); E void FDECL(formatkiller, (char *, unsigned, int, BOOLEAN_P)); E void FDECL(topten, (int, time_t)); E void FDECL(prscore, (int, char **)); +E struct toptenentry *NDECL(get_rnd_toptenentry); E struct obj *FDECL(tt_oname, (struct obj *)); /* ### track.c ### */ diff --git a/src/topten.c b/src/topten.c index 4056d2ac6..84146e9ad 100644 --- a/src/topten.c +++ b/src/topten.c @@ -1171,25 +1171,19 @@ boolean fem; /* * 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 * -tt_oname(otmp) -struct obj *otmp; +struct toptenentry * +get_rnd_toptenentry() { - int rank; - register int i; - register struct toptenentry *tt; + int rank, i; FILE *rfile; - struct toptenentry tt_buf; - - if (!otmp) - return (struct obj *) 0; + register struct toptenentry *tt; + static struct toptenentry tt_buf; rfile = fopen_datafile(RECORD, "r", SCOREPREFIX); if (!rfile) { impossible("Cannot open record file!"); - return (struct obj *) 0; + return NULL; } tt = &tt_buf; @@ -1207,13 +1201,34 @@ pickentry: rewind(rfile); goto pickentry; } - otmp = (struct obj *) 0; - } else { - set_corpsenm(otmp, classmon(tt->plrole, (tt->plgend[0] == 'F'))); - otmp = oname(otmp, tt->name); + tt = NULL; } (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; }