]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.end.c
1 /* $NetBSD: hack.end.c,v 1.5 2001/03/25 20:44:00 jsm Exp $ */
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
9 __RCSID("$NetBSD: hack.end.c,v 1.5 2001/03/25 20:44:00 jsm Exp $");
17 #define Sprintf (void) sprintf
32 int n
__attribute__((__unused__
));
34 (void) signal(SIGINT
, SIG_IGN
);
35 pline("Really quit?");
36 if (readchar() != 'y') {
37 (void) signal(SIGINT
, done1
);
39 (void) fflush(stdout
);
54 int n
__attribute__((__unused__
));
57 (void) signal(SIGINT
, SIG_IGN
);
58 (void) signal(SIGQUIT
, SIG_IGN
);
66 (void) signal(SIGHUP
, SIG_IGN
);
74 static char buf
[BUFSZ
];
76 if (mtmp
->data
->mlet
== ' ') {
77 Sprintf(buf
, "the ghost of %s", (char *) mtmp
->mextra
);
79 } else if (mtmp
->mnamelth
) {
80 Sprintf(buf
, "%s called %s",
81 mtmp
->data
->mname
, NAME(mtmp
));
83 } else if (mtmp
->minvis
) {
84 Sprintf(buf
, "invisible %s", mtmp
->data
->mname
);
87 killer
= mtmp
->data
->mname
;
92 * called with arg "died", "drowned", "escaped", "quit", "choked",
93 * "panicked", "burned", "starved" or "tricked"
95 /* Be careful not to call panic from here! */
102 if (wizard
&& *st1
== 'd') {
105 u
.uhpmax
= 100; /* arbitrary */
107 pline("For some reason you are still alive.");
117 (void) signal(SIGINT
, done_intr
);
118 (void) signal(SIGQUIT
, done_intr
);
119 (void) signal(SIGHUP
, done_hangup
);
120 if (*st1
== 'q' && u
.uhp
< 1) {
122 killer
= "quit while already on Charon's boat";
125 killer
= "starvation";
126 else if (*st1
== 'd' && st1
[1] == 'r')
128 else if (*st1
== 'p')
130 else if (*st1
== 't')
132 else if (!strchr("bcd", *st1
))
136 if (flags
.toplin
== 1)
138 if (strchr("bcds", *st1
)) {
143 if (!flags
.notombstone
)
147 killer
= st1
; /* after outrip() */
148 settty((char *) 0); /* does a clear_screen() */
150 printf("Goodbye %s %s...\n\n", pl_character
, plname
);
153 tmp
= u
.ugold
- u
.ugold0
;
156 if (*st1
== 'd' || *st1
== 'b')
159 u
.urexp
+= 50 * maxdlevel
;
161 u
.urexp
+= 1000 * ((maxdlevel
> 30) ? 10 : maxdlevel
- 20);
167 unsigned worthlessct
= 0;
168 boolean has_amulet
= FALSE
;
178 printf(" and %s", monnam(mtmp
));
180 u
.urexp
+= mtmp
->mhp
;
184 printf("\nescaped from the dungeon with %ld points,\n",
186 } else if (!done_stopprint
)
187 printf("You escaped from the dungeon with %ld points,\n",
189 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
190 if (otmp
->olet
== GEM_SYM
) {
191 objects
[otmp
->otyp
].oc_name_known
= 1;
192 i
= otmp
->quan
* objects
[otmp
->otyp
].g_val
;
194 worthlessct
+= otmp
->quan
;
199 printf("\t%s (worth %d Zorkmids),\n",
201 } else if (otmp
->olet
== AMULET_SYM
) {
203 i
= (otmp
->spe
< 0) ? 2 : 5000;
206 printf("\t%s (worth %d Zorkmids),\n",
208 if (otmp
->spe
>= 0) {
210 killer
= "escaped (with amulet)";
216 printf("\t%u worthless piece%s of coloured glass,\n",
217 worthlessct
, plur(worthlessct
));
220 } else if (!done_stopprint
)
221 printf("You %s on dungeon level %d with %ld points,\n",
222 st1
, dlevel
, u
.urexp
);
224 printf("and %ld piece%s of gold, after %ld move%s.\n",
225 u
.ugold
, plur(u
.ugold
), moves
, plur(moves
));
227 printf("You were level %u with a maximum of %d hit points when you %s.\n",
228 u
.ulevel
, u
.uhpmax
, st1
);
229 if (*st1
== 'e' && !done_stopprint
) {
230 getret(); /* all those pieces of coloured glass ... */
242 #define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry))
246 #define POINTSMIN 1 /* must be > 0 */
247 #define ENTRYMAX 100 /* must be >= 10 */
248 #define PERS_IS_UID /* delete for PERSMAX per name; now per uid */
250 struct toptenentry
*tt_next
;
252 int level
, maxlvl
, hp
, maxhp
;
256 char name
[NAMSZ
+ 1];
257 char death
[DTHSZ
+ 1];
258 char date
[7];/* yymmdd */
265 int rank
, rank0
= -1, rank1
= 0;
266 int occ_cnt
= PERSMAX
;
267 struct toptenentry
*t0
, *t1
, *tprev
;
268 const char *recfile
= RECORD
;
269 const char *reclock
= "record_lock";
273 #define HUP if(!done_hup)
274 while (link(recfile
, reclock
) == -1) {
277 HUP
puts("I give up. Sorry.");
278 HUP
puts("Perhaps there is an old record_lock around?");
281 HUP
printf("Waiting for access to record file. (%d)\n",
283 HUP(void) fflush(stdout
);
286 if (!(rfile
= fopen(recfile
, "r"))) {
287 HUP
puts("Cannot open record file!");
290 HUP(void) putchar('\n');
292 /* create a new 'topten' entry */
295 t0
->maxlvl
= maxdlevel
;
297 t0
->maxhp
= u
.uhpmax
;
298 t0
->points
= u
.urexp
;
299 t0
->plchar
= pl_character
[0];
300 t0
->sex
= (flags
.female
? 'F' : 'M');
302 (void) strncpy(t0
->name
, plname
, NAMSZ
);
303 (t0
->name
)[NAMSZ
] = 0;
304 (void) strncpy(t0
->death
, killer
, DTHSZ
);
305 (t0
->death
)[DTHSZ
] = 0;
306 (void) strcpy(t0
->date
, getdate());
308 /* assure minimum number of points */
309 if (t0
->points
< POINTSMIN
)
312 t1
= tt_head
= newttentry();
314 /* rank0: -1 undefined, 0 not_on_list, n n_th on list */
316 if (fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
318 &t1
->level
, &t1
->maxlvl
,
319 &t1
->hp
, &t1
->maxhp
, &t1
->points
,
320 &t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11
321 || t1
->points
< POINTSMIN
)
323 if (rank0
< 0 && t1
->points
< t0
->points
) {
331 flg
++; /* ask for a rewrite */
338 t1
->uid
== t0
->uid
&&
340 strncmp(t1
->name
, t0
->name
, NAMSZ
) == 0 &&
341 #endif /* PERS_IS_UID */
342 t1
->plchar
== t0
->plchar
&& --occ_cnt
<= 0) {
346 HUP
printf("You didn't beat your previous score of %ld points.\n\n",
354 if (rank
<= ENTRYMAX
) {
355 t1
= t1
->tt_next
= newttentry();
358 if (rank
> ENTRYMAX
) {
363 if (flg
) { /* rewrite record file */
364 (void) fclose(rfile
);
365 if (!(rfile
= fopen(recfile
, "w"))) {
366 HUP
puts("Cannot write record file\n");
372 puts("You made the top ten list!\n");
374 printf("You reached the %d%s place on the top %d list.\n\n",
375 rank0
, ordin(rank0
), ENTRYMAX
);
385 for (rank
= 1; t1
->points
!= 0; rank
++, t1
= t1
->tt_next
) {
387 fprintf(rfile
, "%6s %d %d %d %d %d %ld %c%c %s,%s\n",
389 t1
->level
, t1
->maxlvl
,
390 t1
->hp
, t1
->maxhp
, t1
->points
,
391 t1
->plchar
, t1
->sex
, t1
->name
, t1
->death
);
394 if (rank
> flags
.end_top
&&
395 (rank
< rank0
- flags
.end_around
|| rank
> rank0
+ flags
.end_around
)
396 && (!flags
.end_own
||
400 strncmp(t1
->name
, t0
->name
, NAMSZ
)))
401 #endif /* PERS_IS_UID */
403 if (rank
== rank0
- flags
.end_around
&&
404 rank0
> flags
.end_top
+ flags
.end_around
+ 1 &&
406 (void) putchar('\n');
408 (void) outentry(rank
, t1
, 0);
410 (void) outentry(rank
, t1
, 1);
412 int t0lth
= outentry(0, t0
, -1);
413 int t1lth
= outentry(rank
, t1
, t0lth
);
416 (void) outentry(0, t0
, t0lth
);
421 (void) outentry(0, t0
, 1);
422 (void) fclose(rfile
);
424 (void) unlink(reclock
);
432 (void) strcpy(linebuf
, "Number Points Name");
434 while (bp
< linebuf
+ COLNO
- 9)
436 (void) strcpy(bp
, "Hp [max]");
440 /* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */
442 outentry(int rank
, struct toptenentry
*t1
, int so
)
444 boolean quit
= FALSE
, killed
= FALSE
, starv
= FALSE
;
448 Sprintf(eos(linebuf
), "%3d", rank
);
450 Sprintf(eos(linebuf
), " ");
451 Sprintf(eos(linebuf
), " %6ld %8s", t1
->points
, t1
->name
);
452 if (t1
->plchar
== 'X')
453 Sprintf(eos(linebuf
), " ");
455 Sprintf(eos(linebuf
), "-%c ", t1
->plchar
);
456 if (!strncmp("escaped", t1
->death
, 7)) {
457 if (!strcmp(" (with amulet)", t1
->death
+ 7))
458 Sprintf(eos(linebuf
), "escaped the dungeon with amulet");
460 Sprintf(eos(linebuf
), "escaped the dungeon [max level %d]",
463 if (!strncmp(t1
->death
, "quit", 4)) {
465 if (t1
->maxhp
< 3 * t1
->hp
&& t1
->maxlvl
< 4)
466 Sprintf(eos(linebuf
), "cravenly gave up");
468 Sprintf(eos(linebuf
), "quit");
469 } else if (!strcmp(t1
->death
, "choked"))
470 Sprintf(eos(linebuf
), "choked on %s food",
471 (t1
->sex
== 'F') ? "her" : "his");
472 else if (!strncmp(t1
->death
, "starv", 5))
473 Sprintf(eos(linebuf
), "starved to death"), starv
= TRUE
;
475 Sprintf(eos(linebuf
), "was killed"), killed
= TRUE
;
476 Sprintf(eos(linebuf
), " on%s level %d",
477 (killed
|| starv
) ? "" : " dungeon", t1
->level
);
478 if (t1
->maxlvl
!= t1
->level
)
479 Sprintf(eos(linebuf
), " [max %d]", t1
->maxlvl
);
480 if (quit
&& t1
->death
[4])
481 Sprintf(eos(linebuf
), t1
->death
+ 4);
484 Sprintf(eos(linebuf
), " by %s%s",
485 (!strncmp(t1
->death
, "trick", 5) || !strncmp(t1
->death
, "the ", 4))
487 strchr(vowels
, *t1
->death
) ? "an " : "a ",
489 Sprintf(eos(linebuf
), ".");
491 char *bp
= eos(linebuf
);
494 Sprintf(hpbuf
, (t1
->hp
> 0) ? itoa(t1
->hp
) : "-");
495 hppos
= COLNO
- 7 - strlen(hpbuf
);
496 if (bp
<= linebuf
+ hppos
) {
497 while (bp
< linebuf
+ hppos
)
499 (void) strcpy(bp
, hpbuf
);
500 Sprintf(eos(bp
), " [%d]", t1
->maxhp
);
506 char *bp
= eos(linebuf
);
509 while (bp
< linebuf
+ so
)
513 fputs(linebuf
, stdout
);
515 (void) putchar('\n');
517 return (strlen(linebuf
));
525 Sprintf(buf
, "%d", a
);
534 return ((d
== 0 || d
> 3 || n
/ 10 == 1) ? "th" : (d
== 1) ? "st" :
535 (d
== 2) ? "nd" : "rd");
542 (void) signal(SIGHUP
, SIG_IGN
);
543 for (x
= maxdlevel
; x
>= 0; x
--) {
545 (void) unlink(lock
); /* not all levels need be present */
549 #ifdef NOSAVEONHANGUP
555 (void) signal(SIGINT
, SIG_IGN
);
559 #endif /* NOSAVEONHANGUP */
570 /* it is the callers responsibility to check that there is room for c */
582 * Called with args from main if argc >= 0. In this case, list scores as
583 * requested. Otherwise, find scores for the current player (and list them
591 char **players
= NULL
;
594 struct toptenentry
*t1
, *t2
;
595 const char *recfile
= RECORD
;
600 long total_score
= 0L;
603 #endif /* nonsense */
604 int outflg
= (argc
>= -1);
609 #endif /* PERS_IS_UID */
611 if (!(rfile
= fopen(recfile
, "r"))) {
612 puts("Cannot open record file!");
615 if (argc
> 1 && !strncmp(argv
[1], "-s", 2)) {
619 } else if (!argv
[1][3] && strchr("CFKSTWX", argv
[1][2])) {
632 player0
= "hackplayer";
635 #endif /* PERS_IS_UID */
643 t1
= tt_head
= newttentry();
644 for (rank
= 1;; rank
++) {
645 if (fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
647 &t1
->level
, &t1
->maxlvl
,
648 &t1
->hp
, &t1
->maxhp
, &t1
->points
,
649 &t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11)
654 if (!playerct
&& t1
->uid
== uid
)
657 #endif /* PERS_IS_UID */
658 for (i
= 0; i
< playerct
; i
++) {
659 if (strcmp(players
[i
], "all") == 0 ||
660 strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
661 (players
[i
][0] == '-' &&
662 players
[i
][1] == t1
->plchar
&&
663 players
[i
][2] == 0) ||
664 (digit(players
[i
][0]) && rank
<= atoi(players
[i
])))
667 t1
= t1
->tt_next
= newttentry();
669 (void) fclose(rfile
);
672 printf("Cannot find any entries for ");
678 for (i
= 0; i
< playerct
; i
++)
679 printf("%s%s", players
[i
], (i
< playerct
- 1) ? ", " : ".\n");
680 printf("Call is: %s -s [playernames]\n", hname
);
688 for (rank
= 1; t1
->points
!= 0; rank
++, t1
= t2
) {
691 if (!playerct
&& t1
->uid
== uid
)
694 #endif /* PERS_IS_UID */
695 for (i
= 0; i
< playerct
; i
++) {
696 if (strcmp(players
[i
], "all") == 0 ||
697 strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
698 (players
[i
][0] == '-' &&
699 players
[i
][1] == t1
->plchar
&&
700 players
[i
][2] == 0) ||
701 (digit(players
[i
][0]) && rank
<= atoi(players
[i
]))) {
704 (void) outentry(rank
, t1
, 0);
706 total_score
+= t1
->points
;
707 if (totcharct
< sizeof(totchars
) - 1)
708 totchars
[totcharct
++] = t1
->plchar
;
709 #endif /* nonsense */
716 totchars
[totcharct
] = 0;
719 * We would like to determine whether he is experienced. However, the
720 * information collected here only tells about the scores/roles that
721 * got into the topten (top 100?). We should maintain a .hacklog or
722 * something in his home directory.
724 flags
.beginner
= (total_score
< 6000);
725 for (i
= 0; i
< 6; i
++)
726 if (!strchr(totchars
, "CFKSTWX"[i
])) {
728 if (!pl_character
[0])
729 pl_character
[0] = "CFKSTWX"[i
];
732 #endif /* nonsense */