MCPcopy Create free account
hub / github.com/NetHack/NetHack / get_rnd_toptenentry

Function get_rnd_toptenentry

src/topten.c:1380–1414  ·  view source on GitHub ↗

* Get a random player name and class from the high score list, */

Source from the content-addressed store, hash-verified

1378 * Get a random player name and class from the high score list,
1379 */
1380struct toptenentry *
1381get_rnd_toptenentry(void)
1382{
1383 int rank, i;
1384 FILE *rfile;
1385 struct toptenentry *tt;
1386 static struct toptenentry tt_buf;
1387
1388 rfile = fopen_datafile(RECORD, "r", SCOREPREFIX);
1389 if (!rfile) {
1390 impossible("Cannot open record file!");
1391 return NULL;
1392 }
1393
1394 tt = &tt_buf;
1395 rank = rnd(sysopt.tt_oname_maxrank);
1396 pickentry:
1397 for (i = rank; i; i--) {
1398 readentry(rfile, tt);
1399 if (tt->points == 0)
1400 break;
1401 }
1402
1403 if (tt->points == 0) {
1404 if (rank > 1) {
1405 rank = 1;
1406 rewind(rfile);
1407 goto pickentry;
1408 }
1409 tt = NULL;
1410 }
1411
1412 (void) fclose(rfile);
1413 return tt;
1414}
1415
1416
1417/*

Callers 2

tt_onameFunction · 0.85
tt_doppelFunction · 0.85

Calls 5

rndFunction · 0.85
readentryFunction · 0.85
fcloseFunction · 0.85
fopen_datafileFunction · 0.70
impossibleFunction · 0.70

Tested by

no test coverage detected