xref: /netbsd-src/games/hack/hack.end.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: hack.end.c,v 1.6 2003/04/02 18:36:36 jsm Exp $	*/
2 
3 /*
4  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5  * Amsterdam
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * - Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * - Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * - Neither the name of the Stichting Centrum voor Wiskunde en
20  * Informatica, nor the names of its contributors may be used to endorse or
21  * promote products derived from this software without specific prior
22  * written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 /*
38  * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39  * All rights reserved.
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in the
48  *    documentation and/or other materials provided with the distribution.
49  * 3. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
55  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 #include <sys/cdefs.h>
65 #ifndef lint
66 __RCSID("$NetBSD: hack.end.c,v 1.6 2003/04/02 18:36:36 jsm Exp $");
67 #endif				/* not lint */
68 
69 #include <signal.h>
70 #include <unistd.h>
71 #include <stdlib.h>
72 #include "hack.h"
73 #include "extern.h"
74 #define	Sprintf	(void) sprintf
75 
76 xchar           maxdlevel = 1;
77 
78 int
79 dodone()
80 {
81 	done1(0);
82 	return 0;
83 }
84 
85 
86 /*ARGSUSED*/
87 void
88 done1(n)
89 	int n __attribute__((__unused__));
90 {
91 	(void) signal(SIGINT, SIG_IGN);
92 	pline("Really quit?");
93 	if (readchar() != 'y') {
94 		(void) signal(SIGINT, done1);
95 		clrlin();
96 		(void) fflush(stdout);
97 		if (multi > 0)
98 			nomul(0);
99 		return;
100 	}
101 	done("quit");
102 	/* NOTREACHED */
103 }
104 
105 int             done_stopprint;
106 int             done_hup;
107 
108 /*ARGSUSED*/
109 void
110 done_intr(n)
111 	int n __attribute__((__unused__));
112 {
113 	done_stopprint++;
114 	(void) signal(SIGINT, SIG_IGN);
115 	(void) signal(SIGQUIT, SIG_IGN);
116 }
117 
118 void
119 done_hangup(n)
120 	int n;
121 {
122 	done_hup++;
123 	(void) signal(SIGHUP, SIG_IGN);
124 	done_intr(n);
125 }
126 
127 void
128 done_in_by(mtmp)
129 	struct monst   *mtmp;
130 {
131 	static char     buf[BUFSZ];
132 	pline("You die ...");
133 	if (mtmp->data->mlet == ' ') {
134 		Sprintf(buf, "the ghost of %s", (char *) mtmp->mextra);
135 		killer = buf;
136 	} else if (mtmp->mnamelth) {
137 		Sprintf(buf, "%s called %s",
138 			mtmp->data->mname, NAME(mtmp));
139 		killer = buf;
140 	} else if (mtmp->minvis) {
141 		Sprintf(buf, "invisible %s", mtmp->data->mname);
142 		killer = buf;
143 	} else
144 		killer = mtmp->data->mname;
145 	done("died");
146 }
147 
148 /*
149  * called with arg "died", "drowned", "escaped", "quit", "choked",
150  * "panicked", "burned", "starved" or "tricked"
151  */
152 /* Be careful not to call panic from here! */
153 void
154 done(st1)
155 	const char           *st1;
156 {
157 
158 #ifdef WIZARD
159 	if (wizard && *st1 == 'd') {
160 		u.uswldtim = 0;
161 		if (u.uhpmax < 0)
162 			u.uhpmax = 100;	/* arbitrary */
163 		u.uhp = u.uhpmax;
164 		pline("For some reason you are still alive.");
165 		flags.move = 0;
166 		if (multi > 0)
167 			multi = 0;
168 		else
169 			multi = -1;
170 		flags.botl = 1;
171 		return;
172 	}
173 #endif	/* WIZARD */
174 	(void) signal(SIGINT, done_intr);
175 	(void) signal(SIGQUIT, done_intr);
176 	(void) signal(SIGHUP, done_hangup);
177 	if (*st1 == 'q' && u.uhp < 1) {
178 		st1 = "died";
179 		killer = "quit while already on Charon's boat";
180 	}
181 	if (*st1 == 's')
182 		killer = "starvation";
183 	else if (*st1 == 'd' && st1[1] == 'r')
184 		killer = "drowning";
185 	else if (*st1 == 'p')
186 		killer = "panic";
187 	else if (*st1 == 't')
188 		killer = "trickery";
189 	else if (!strchr("bcd", *st1))
190 		killer = st1;
191 	paybill();
192 	clearlocks();
193 	if (flags.toplin == 1)
194 		more();
195 	if (strchr("bcds", *st1)) {
196 #ifdef WIZARD
197 		if (!wizard)
198 #endif	/* WIZARD */
199 			savebones();
200 		if (!flags.notombstone)
201 			outrip();
202 	}
203 	if (*st1 == 'c')
204 		killer = st1;	/* after outrip() */
205 	settty((char *) 0);	/* does a clear_screen() */
206 	if (!done_stopprint)
207 		printf("Goodbye %s %s...\n\n", pl_character, plname);
208 	{
209 		long int        tmp;
210 		tmp = u.ugold - u.ugold0;
211 		if (tmp < 0)
212 			tmp = 0;
213 		if (*st1 == 'd' || *st1 == 'b')
214 			tmp -= tmp / 10;
215 		u.urexp += tmp;
216 		u.urexp += 50 * maxdlevel;
217 		if (maxdlevel > 20)
218 			u.urexp += 1000 * ((maxdlevel > 30) ? 10 : maxdlevel - 20);
219 	}
220 	if (*st1 == 'e') {
221 		struct monst   *mtmp;
222 		struct obj     *otmp;
223 		int             i;
224 		unsigned        worthlessct = 0;
225 		boolean         has_amulet = FALSE;
226 
227 		killer = st1;
228 		keepdogs();
229 		mtmp = mydogs;
230 		if (mtmp) {
231 			if (!done_stopprint)
232 				printf("You");
233 			while (mtmp) {
234 				if (!done_stopprint)
235 					printf(" and %s", monnam(mtmp));
236 				if (mtmp->mtame)
237 					u.urexp += mtmp->mhp;
238 				mtmp = mtmp->nmon;
239 			}
240 			if (!done_stopprint)
241 				printf("\nescaped from the dungeon with %ld points,\n",
242 				       u.urexp);
243 		} else if (!done_stopprint)
244 			printf("You escaped from the dungeon with %ld points,\n",
245 			       u.urexp);
246 		for (otmp = invent; otmp; otmp = otmp->nobj) {
247 			if (otmp->olet == GEM_SYM) {
248 				objects[otmp->otyp].oc_name_known = 1;
249 				i = otmp->quan * objects[otmp->otyp].g_val;
250 				if (i == 0) {
251 					worthlessct += otmp->quan;
252 					continue;
253 				}
254 				u.urexp += i;
255 				if (!done_stopprint)
256 					printf("\t%s (worth %d Zorkmids),\n",
257 					       doname(otmp), i);
258 			} else if (otmp->olet == AMULET_SYM) {
259 				otmp->known = 1;
260 				i = (otmp->spe < 0) ? 2 : 5000;
261 				u.urexp += i;
262 				if (!done_stopprint)
263 					printf("\t%s (worth %d Zorkmids),\n",
264 					       doname(otmp), i);
265 				if (otmp->spe >= 0) {
266 					has_amulet = TRUE;
267 					killer = "escaped (with amulet)";
268 				}
269 			}
270 		}
271 		if (worthlessct)
272 			if (!done_stopprint)
273 				printf("\t%u worthless piece%s of coloured glass,\n",
274 				       worthlessct, plur(worthlessct));
275 		if (has_amulet)
276 			u.urexp *= 2;
277 	} else if (!done_stopprint)
278 		printf("You %s on dungeon level %d with %ld points,\n",
279 		       st1, dlevel, u.urexp);
280 	if (!done_stopprint)
281 		printf("and %ld piece%s of gold, after %ld move%s.\n",
282 		       u.ugold, plur(u.ugold), moves, plur(moves));
283 	if (!done_stopprint)
284 		printf("You were level %u with a maximum of %d hit points when you %s.\n",
285 		       u.ulevel, u.uhpmax, st1);
286 	if (*st1 == 'e' && !done_stopprint) {
287 		getret();	/* all those pieces of coloured glass ... */
288 		cls();
289 	}
290 #ifdef WIZARD
291 	if (!wizard)
292 #endif	/* WIZARD */
293 		topten();
294 	if (done_stopprint)
295 		printf("\n\n");
296 	exit(0);
297 }
298 
299 #define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry))
300 #define	NAMSZ	8
301 #define	DTHSZ	40
302 #define	PERSMAX	1
303 #define	POINTSMIN	1	/* must be > 0 */
304 #define	ENTRYMAX	100	/* must be >= 10 */
305 #define	PERS_IS_UID		/* delete for PERSMAX per name; now per uid */
306 struct toptenentry {
307 	struct toptenentry *tt_next;
308 	long int        points;
309 	int             level, maxlvl, hp, maxhp;
310 	int             uid;
311 	char            plchar;
312 	char            sex;
313 	char            name[NAMSZ + 1];
314 	char            death[DTHSZ + 1];
315 	char            date[7];/* yymmdd */
316 }              *tt_head;
317 
318 void
319 topten()
320 {
321 	int             uid = getuid();
322 	int             rank, rank0 = -1, rank1 = 0;
323 	int             occ_cnt = PERSMAX;
324 	struct toptenentry *t0, *t1, *tprev;
325 	const char     *recfile = RECORD;
326 	const char     *reclock = "record_lock";
327 	int             sleepct = 300;
328 	FILE           *rfile;
329 	int 		flg = 0;
330 #define	HUP	if(!done_hup)
331 	while (link(recfile, reclock) == -1) {
332 		HUP             perror(reclock);
333 		if (!sleepct--) {
334 			HUP             puts("I give up. Sorry.");
335 			HUP             puts("Perhaps there is an old record_lock around?");
336 			return;
337 		}
338 		HUP             printf("Waiting for access to record file. (%d)\n",
339 				                       sleepct);
340 		HUP(void) fflush(stdout);
341 		sleep(1);
342 	}
343 	if (!(rfile = fopen(recfile, "r"))) {
344 		HUP             puts("Cannot open record file!");
345 		goto unlock;
346 	}
347 	HUP(void) putchar('\n');
348 
349 	/* create a new 'topten' entry */
350 	t0 = newttentry();
351 	t0->level = dlevel;
352 	t0->maxlvl = maxdlevel;
353 	t0->hp = u.uhp;
354 	t0->maxhp = u.uhpmax;
355 	t0->points = u.urexp;
356 	t0->plchar = pl_character[0];
357 	t0->sex = (flags.female ? 'F' : 'M');
358 	t0->uid = uid;
359 	(void) strncpy(t0->name, plname, NAMSZ);
360 	(t0->name)[NAMSZ] = 0;
361 	(void) strncpy(t0->death, killer, DTHSZ);
362 	(t0->death)[DTHSZ] = 0;
363 	(void) strcpy(t0->date, getdate());
364 
365 	/* assure minimum number of points */
366 	if (t0->points < POINTSMIN)
367 		t0->points = 0;
368 
369 	t1 = tt_head = newttentry();
370 	tprev = 0;
371 	/* rank0: -1 undefined, 0 not_on_list, n n_th on list */
372 	for (rank = 1;;) {
373 		if (fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
374 			   t1->date, &t1->uid,
375 			   &t1->level, &t1->maxlvl,
376 			   &t1->hp, &t1->maxhp, &t1->points,
377 			   &t1->plchar, &t1->sex, t1->name, t1->death) != 11
378 		    || t1->points < POINTSMIN)
379 			t1->points = 0;
380 		if (rank0 < 0 && t1->points < t0->points) {
381 			rank0 = rank++;
382 			if (tprev == 0)
383 				tt_head = t0;
384 			else
385 				tprev->tt_next = t0;
386 			t0->tt_next = t1;
387 			occ_cnt--;
388 			flg++;	/* ask for a rewrite */
389 		} else
390 			tprev = t1;
391 		if (t1->points == 0)
392 			break;
393 		if (
394 #ifdef PERS_IS_UID
395 		    t1->uid == t0->uid &&
396 #else
397 		    strncmp(t1->name, t0->name, NAMSZ) == 0 &&
398 #endif	/* PERS_IS_UID */
399 		    t1->plchar == t0->plchar && --occ_cnt <= 0) {
400 			if (rank0 < 0) {
401 				rank0 = 0;
402 				rank1 = rank;
403 				HUP             printf("You didn't beat your previous score of %ld points.\n\n",
404 						                t1->points);
405 			}
406 			if (occ_cnt < 0) {
407 				flg++;
408 				continue;
409 			}
410 		}
411 		if (rank <= ENTRYMAX) {
412 			t1 = t1->tt_next = newttentry();
413 			rank++;
414 		}
415 		if (rank > ENTRYMAX) {
416 			t1->points = 0;
417 			break;
418 		}
419 	}
420 	if (flg) {		/* rewrite record file */
421 		(void) fclose(rfile);
422 		if (!(rfile = fopen(recfile, "w"))) {
423 			HUP             puts("Cannot write record file\n");
424 			goto unlock;
425 		}
426 		if (!done_stopprint)
427 			if (rank0 > 0) {
428 				if (rank0 <= 10)
429 					puts("You made the top ten list!\n");
430 				else
431 					printf("You reached the %d%s place on the top %d list.\n\n",
432 					     rank0, ordin(rank0), ENTRYMAX);
433 			}
434 	}
435 	if (rank0 == 0)
436 		rank0 = rank1;
437 	if (rank0 <= 0)
438 		rank0 = rank;
439 	if (!done_stopprint)
440 		outheader();
441 	t1 = tt_head;
442 	for (rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) {
443 		if (flg)
444 			fprintf(rfile, "%6s %d %d %d %d %d %ld %c%c %s,%s\n",
445 				t1->date, t1->uid,
446 				t1->level, t1->maxlvl,
447 				t1->hp, t1->maxhp, t1->points,
448 				t1->plchar, t1->sex, t1->name, t1->death);
449 		if (done_stopprint)
450 			continue;
451 		if (rank > flags.end_top &&
452 		    (rank < rank0 - flags.end_around || rank > rank0 + flags.end_around)
453 		    && (!flags.end_own ||
454 #ifdef PERS_IS_UID
455 			t1->uid != t0->uid))
456 #else
457 			strncmp(t1->name, t0->name, NAMSZ)))
458 #endif	/* PERS_IS_UID */
459 			continue;
460 		if (rank == rank0 - flags.end_around &&
461 		    rank0 > flags.end_top + flags.end_around + 1 &&
462 		    !flags.end_own)
463 			(void) putchar('\n');
464 		if (rank != rank0)
465 			(void) outentry(rank, t1, 0);
466 		else if (!rank1)
467 			(void) outentry(rank, t1, 1);
468 		else {
469 			int             t0lth = outentry(0, t0, -1);
470 			int             t1lth = outentry(rank, t1, t0lth);
471 			if (t1lth > t0lth)
472 				t0lth = t1lth;
473 			(void) outentry(0, t0, t0lth);
474 		}
475 	}
476 	if (rank0 >= rank)
477 		if (!done_stopprint)
478 			(void) outentry(0, t0, 1);
479 	(void) fclose(rfile);
480 unlock:
481 	(void) unlink(reclock);
482 }
483 
484 void
485 outheader()
486 {
487 	char            linebuf[BUFSZ];
488 	char           *bp;
489 	(void) strcpy(linebuf, "Number Points  Name");
490 	bp = eos(linebuf);
491 	while (bp < linebuf + COLNO - 9)
492 		*bp++ = ' ';
493 	(void) strcpy(bp, "Hp [max]");
494 	puts(linebuf);
495 }
496 
497 /* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */
498 int
499 outentry(int rank, struct toptenentry *t1, int so)
500 {
501 	boolean         quit = FALSE, killed = FALSE, starv = FALSE;
502 	char            linebuf[BUFSZ];
503 	linebuf[0] = 0;
504 	if (rank)
505 		Sprintf(eos(linebuf), "%3d", rank);
506 	else
507 		Sprintf(eos(linebuf), "   ");
508 	Sprintf(eos(linebuf), " %6ld %8s", t1->points, t1->name);
509 	if (t1->plchar == 'X')
510 		Sprintf(eos(linebuf), " ");
511 	else
512 		Sprintf(eos(linebuf), "-%c ", t1->plchar);
513 	if (!strncmp("escaped", t1->death, 7)) {
514 		if (!strcmp(" (with amulet)", t1->death + 7))
515 			Sprintf(eos(linebuf), "escaped the dungeon with amulet");
516 		else
517 			Sprintf(eos(linebuf), "escaped the dungeon [max level %d]",
518 				t1->maxlvl);
519 	} else {
520 		if (!strncmp(t1->death, "quit", 4)) {
521 			quit = TRUE;
522 			if (t1->maxhp < 3 * t1->hp && t1->maxlvl < 4)
523 				Sprintf(eos(linebuf), "cravenly gave up");
524 			else
525 				Sprintf(eos(linebuf), "quit");
526 		} else if (!strcmp(t1->death, "choked"))
527 			Sprintf(eos(linebuf), "choked on %s food",
528 				(t1->sex == 'F') ? "her" : "his");
529 		else if (!strncmp(t1->death, "starv", 5))
530 			Sprintf(eos(linebuf), "starved to death"), starv = TRUE;
531 		else
532 			Sprintf(eos(linebuf), "was killed"), killed = TRUE;
533 		Sprintf(eos(linebuf), " on%s level %d",
534 			(killed || starv) ? "" : " dungeon", t1->level);
535 		if (t1->maxlvl != t1->level)
536 			Sprintf(eos(linebuf), " [max %d]", t1->maxlvl);
537 		if (quit && t1->death[4])
538 			Sprintf(eos(linebuf), t1->death + 4);
539 	}
540 	if (killed)
541 		Sprintf(eos(linebuf), " by %s%s",
542 			(!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4))
543 			? "" :
544 			strchr(vowels, *t1->death) ? "an " : "a ",
545 			t1->death);
546 	Sprintf(eos(linebuf), ".");
547 	if (t1->maxhp) {
548 		char           *bp = eos(linebuf);
549 		char            hpbuf[10];
550 		int             hppos;
551 		Sprintf(hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-");
552 		hppos = COLNO - 7 - strlen(hpbuf);
553 		if (bp <= linebuf + hppos) {
554 			while (bp < linebuf + hppos)
555 				*bp++ = ' ';
556 			(void) strcpy(bp, hpbuf);
557 			Sprintf(eos(bp), " [%d]", t1->maxhp);
558 		}
559 	}
560 	if (so == 0)
561 		puts(linebuf);
562 	else if (so > 0) {
563 		char           *bp = eos(linebuf);
564 		if (so >= COLNO)
565 			so = COLNO - 1;
566 		while (bp < linebuf + so)
567 			*bp++ = ' ';
568 		*bp = 0;
569 		standoutbeg();
570 		fputs(linebuf, stdout);
571 		standoutend();
572 		(void) putchar('\n');
573 	}
574 	return (strlen(linebuf));
575 }
576 
577 char           *
578 itoa(a)
579 	int             a;
580 {
581 	static char     buf[12];
582 	Sprintf(buf, "%d", a);
583 	return (buf);
584 }
585 
586 const char           *
587 ordin(n)
588 	int             n;
589 {
590 	int             d = n % 10;
591 	return ((d == 0 || d > 3 || n / 10 == 1) ? "th" : (d == 1) ? "st" :
592 		(d == 2) ? "nd" : "rd");
593 }
594 
595 void
596 clearlocks()
597 {
598 	int x;
599 	(void) signal(SIGHUP, SIG_IGN);
600 	for (x = maxdlevel; x >= 0; x--) {
601 		glo(x);
602 		(void) unlink(lock);	/* not all levels need be present */
603 	}
604 }
605 
606 #ifdef NOSAVEONHANGUP
607 /*ARGSUSED*/
608 void
609 hangup(n)
610 	int n;
611 {
612 	(void) signal(SIGINT, SIG_IGN);
613 	clearlocks();
614 	exit(1);
615 }
616 #endif	/* NOSAVEONHANGUP */
617 
618 char           *
619 eos(s)
620 	char           *s;
621 {
622 	while (*s)
623 		s++;
624 	return (s);
625 }
626 
627 /* it is the callers responsibility to check that there is room for c */
628 void
629 charcat(s, c)
630 	char           *s, c;
631 {
632 	while (*s)
633 		s++;
634 	*s++ = c;
635 	*s = 0;
636 }
637 
638 /*
639  * Called with args from main if argc >= 0. In this case, list scores as
640  * requested. Otherwise, find scores for the current player (and list them
641  * if argc == -1).
642  */
643 void
644 prscore(argc, argv)
645 	int             argc;
646 	char          **argv;
647 {
648 	char          **players = NULL;
649 	int             playerct;
650 	int             rank;
651 	struct toptenentry *t1, *t2;
652 	const char           *recfile = RECORD;
653 	FILE           *rfile;
654 	int		flg = 0;
655 	int             i;
656 #ifdef nonsense
657 	long            total_score = 0L;
658 	char            totchars[10];
659 	int             totcharct = 0;
660 #endif	/* nonsense */
661 	int             outflg = (argc >= -1);
662 #ifdef PERS_IS_UID
663 	int             uid = -1;
664 #else
665 	char           *player0;
666 #endif	/* PERS_IS_UID */
667 
668 	if (!(rfile = fopen(recfile, "r"))) {
669 		puts("Cannot open record file!");
670 		return;
671 	}
672 	if (argc > 1 && !strncmp(argv[1], "-s", 2)) {
673 		if (!argv[1][2]) {
674 			argc--;
675 			argv++;
676 		} else if (!argv[1][3] && strchr("CFKSTWX", argv[1][2])) {
677 			argv[1]++;
678 			argv[1][0] = '-';
679 		} else
680 			argv[1] += 2;
681 	}
682 	if (argc <= 1) {
683 #ifdef PERS_IS_UID
684 		uid = getuid();
685 		playerct = 0;
686 #else
687 		player0 = plname;
688 		if (!*player0)
689 			player0 = "hackplayer";
690 		playerct = 1;
691 		players = &player0;
692 #endif	/* PERS_IS_UID */
693 	} else {
694 		playerct = --argc;
695 		players = ++argv;
696 	}
697 	if (outflg)
698 		putchar('\n');
699 
700 	t1 = tt_head = newttentry();
701 	for (rank = 1;; rank++) {
702 		if (fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
703 			   t1->date, &t1->uid,
704 			   &t1->level, &t1->maxlvl,
705 			   &t1->hp, &t1->maxhp, &t1->points,
706 			   &t1->plchar, &t1->sex, t1->name, t1->death) != 11)
707 			t1->points = 0;
708 		if (t1->points == 0)
709 			break;
710 #ifdef PERS_IS_UID
711 		if (!playerct && t1->uid == uid)
712 			flg++;
713 		else
714 #endif	/* PERS_IS_UID */
715 			for (i = 0; i < playerct; i++) {
716 				if (strcmp(players[i], "all") == 0 ||
717 				strncmp(t1->name, players[i], NAMSZ) == 0 ||
718 				    (players[i][0] == '-' &&
719 				     players[i][1] == t1->plchar &&
720 				     players[i][2] == 0) ||
721 				    (digit(players[i][0]) && rank <= atoi(players[i])))
722 					flg++;
723 			}
724 		t1 = t1->tt_next = newttentry();
725 	}
726 	(void) fclose(rfile);
727 	if (!flg) {
728 		if (outflg) {
729 			printf("Cannot find any entries for ");
730 			if (playerct < 1)
731 				printf("you.\n");
732 			else {
733 				if (playerct > 1)
734 					printf("any of ");
735 				for (i = 0; i < playerct; i++)
736 					printf("%s%s", players[i], (i < playerct - 1) ? ", " : ".\n");
737 				printf("Call is: %s -s [playernames]\n", hname);
738 			}
739 		}
740 		return;
741 	}
742 	if (outflg)
743 		outheader();
744 	t1 = tt_head;
745 	for (rank = 1; t1->points != 0; rank++, t1 = t2) {
746 		t2 = t1->tt_next;
747 #ifdef PERS_IS_UID
748 		if (!playerct && t1->uid == uid)
749 			goto outwithit;
750 		else
751 #endif	/* PERS_IS_UID */
752 			for (i = 0; i < playerct; i++) {
753 				if (strcmp(players[i], "all") == 0 ||
754 				strncmp(t1->name, players[i], NAMSZ) == 0 ||
755 				    (players[i][0] == '-' &&
756 				     players[i][1] == t1->plchar &&
757 				     players[i][2] == 0) ||
758 				    (digit(players[i][0]) && rank <= atoi(players[i]))) {
759 			outwithit:
760 					if (outflg)
761 						(void) outentry(rank, t1, 0);
762 #ifdef nonsense
763 					total_score += t1->points;
764 					if (totcharct < sizeof(totchars) - 1)
765 						totchars[totcharct++] = t1->plchar;
766 #endif	/* nonsense */
767 					break;
768 				}
769 			}
770 		free((char *) t1);
771 	}
772 #ifdef nonsense
773 	totchars[totcharct] = 0;
774 
775 	/*
776 	 * We would like to determine whether he is experienced. However, the
777 	 * information collected here only tells about the scores/roles that
778 	 * got into the topten (top 100?). We should maintain a .hacklog or
779 	 * something in his home directory.
780 	 */
781 	flags.beginner = (total_score < 6000);
782 	for (i = 0; i < 6; i++)
783 		if (!strchr(totchars, "CFKSTWX"[i])) {
784 			flags.beginner = 1;
785 			if (!pl_character[0])
786 				pl_character[0] = "CFKSTWX"[i];
787 			break;
788 		}
789 #endif	/* nonsense */
790 }
791