]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.end.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$NetBSD: hack.end.c,v 1.3 1995/03/23 08:30:05 cgd Exp $";
12 #define Sprintf (void) sprintf
13 extern char plname
[], pl_character
[];
14 extern char *itoa(), *ordin(), *eos();
21 (void) signal(SIGINT
,SIG_IGN
);
22 pline("Really quit?");
23 if(readchar() != 'y') {
24 (void) signal(SIGINT
,done1
);
26 (void) fflush(stdout
);
27 if(multi
> 0) nomul(0);
40 (void) signal(SIGINT
, SIG_IGN
);
41 (void) signal(SIGQUIT
, SIG_IGN
);
47 (void) signal(SIGHUP
, SIG_IGN
);
51 done_in_by(mtmp
) register struct monst
*mtmp
; {
52 static char buf
[BUFSZ
];
54 if(mtmp
->data
->mlet
== ' '){
55 Sprintf(buf
, "the ghost of %s", (char *) mtmp
->mextra
);
57 } else if(mtmp
->mnamelth
) {
58 Sprintf(buf
, "%s called %s",
59 mtmp
->data
->mname
, NAME(mtmp
));
61 } else if(mtmp
->minvis
) {
62 Sprintf(buf
, "invisible %s", mtmp
->data
->mname
);
64 } else killer
= mtmp
->data
->mname
;
68 /* called with arg "died", "drowned", "escaped", "quit", "choked", "panicked",
69 "burned", "starved" or "tricked" */
70 /* Be careful not to call panic from here! */
76 if(wizard
&& *st1
== 'd'){
78 if(u
.uhpmax
< 0) u
.uhpmax
= 100; /* arbitrary */
80 pline("For some reason you are still alive.");
82 if(multi
> 0) multi
= 0; else multi
= -1;
87 (void) signal(SIGINT
, done_intr
);
88 (void) signal(SIGQUIT
, done_intr
);
89 (void) signal(SIGHUP
, done_hangup
);
90 if(*st1
== 'q' && u
.uhp
< 1){
92 killer
= "quit while already on Charon's boat";
94 if(*st1
== 's') killer
= "starvation"; else
95 if(*st1
== 'd' && st1
[1] == 'r') killer
= "drowning"; else
96 if(*st1
== 'p') killer
= "panic"; else
97 if(*st1
== 't') killer
= "trickery"; else
98 if(!index("bcd", *st1
)) killer
= st1
;
101 if(flags
.toplin
== 1) more();
102 if(index("bcds", *st1
)){
107 if(!flags
.notombstone
)
110 if(*st1
== 'c') killer
= st1
; /* after outrip() */
111 settty((char *) 0); /* does a clear_screen() */
113 printf("Goodbye %s %s...\n\n", pl_character
, plname
);
115 tmp
= u
.ugold
- u
.ugold0
;
118 if(*st1
== 'd' || *st1
== 'b')
121 u
.urexp
+= 50 * maxdlevel
;
123 u
.urexp
+= 1000*((maxdlevel
> 30) ? 10 : maxdlevel
- 20);
126 extern struct monst
*mydogs
;
127 register struct monst
*mtmp
;
128 register struct obj
*otmp
;
130 register unsigned worthlessct
= 0;
131 boolean has_amulet
= FALSE
;
137 if(!done_stopprint
) printf("You");
140 printf(" and %s", monnam(mtmp
));
142 u
.urexp
+= mtmp
->mhp
;
146 printf("\nescaped from the dungeon with %ld points,\n",
150 printf("You escaped from the dungeon with %ld points,\n",
152 for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
153 if(otmp
->olet
== GEM_SYM
){
154 objects
[otmp
->otyp
].oc_name_known
= 1;
155 i
= otmp
->quan
*objects
[otmp
->otyp
].g_val
;
157 worthlessct
+= otmp
->quan
;
162 printf("\t%s (worth %d Zorkmids),\n",
164 } else if(otmp
->olet
== AMULET_SYM
) {
166 i
= (otmp
->spe
< 0) ? 2 : 5000;
169 printf("\t%s (worth %d Zorkmids),\n",
173 killer
= "escaped (with amulet)";
177 if(worthlessct
) if(!done_stopprint
)
178 printf("\t%u worthless piece%s of coloured glass,\n",
179 worthlessct
, plur(worthlessct
));
180 if(has_amulet
) u
.urexp
*= 2;
183 printf("You %s on dungeon level %d with %ld points,\n",
184 st1
, dlevel
, u
.urexp
);
186 printf("and %ld piece%s of gold, after %ld move%s.\n",
187 u
.ugold
, plur(u
.ugold
), moves
, plur(moves
));
189 printf("You were level %u with a maximum of %d hit points when you %s.\n",
190 u
.ulevel
, u
.uhpmax
, st1
);
191 if(*st1
== 'e' && !done_stopprint
){
192 getret(); /* all those pieces of coloured glass ... */
199 if(done_stopprint
) printf("\n\n");
203 #define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry))
207 #define POINTSMIN 1 /* must be > 0 */
208 #define ENTRYMAX 100 /* must be >= 10 */
209 #define PERS_IS_UID /* delete for PERSMAX per name; now per uid */
211 struct toptenentry
*tt_next
;
213 int level
,maxlvl
,hp
,maxhp
;
219 char date
[7]; /* yymmdd */
224 int rank
, rank0
= -1, rank1
= 0;
225 int occ_cnt
= PERSMAX
;
226 register struct toptenentry
*t0
, *t1
, *tprev
;
227 char *recfile
= RECORD
;
228 char *reclock
= "record_lock";
232 extern char *getdate();
233 #define HUP if(!done_hup)
234 while(link(recfile
, reclock
) == -1) {
237 HUP
puts("I give up. Sorry.");
238 HUP
puts("Perhaps there is an old record_lock around?");
241 HUP
printf("Waiting for access to record file. (%d)\n",
243 HUP (void) fflush(stdout
);
246 if(!(rfile
= fopen(recfile
,"r"))){
247 HUP
puts("Cannot open record file!");
250 HUP (void) putchar('\n');
252 /* create a new 'topten' entry */
255 t0
->maxlvl
= maxdlevel
;
257 t0
->maxhp
= u
.uhpmax
;
258 t0
->points
= u
.urexp
;
259 t0
->plchar
= pl_character
[0];
260 t0
->sex
= (flags
.female
? 'F' : 'M');
262 (void) strncpy(t0
->name
, plname
, NAMSZ
);
263 (t0
->name
)[NAMSZ
] = 0;
264 (void) strncpy(t0
->death
, killer
, DTHSZ
);
265 (t0
->death
)[DTHSZ
] = 0;
266 (void) strcpy(t0
->date
, getdate());
268 /* assure minimum number of points */
269 if(t0
->points
< POINTSMIN
)
272 t1
= tt_head
= newttentry();
274 /* rank0: -1 undefined, 0 not_on_list, n n_th on list */
276 if(fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
278 &t1
->level
, &t1
->maxlvl
,
279 &t1
->hp
, &t1
->maxhp
, &t1
->points
,
280 &t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11
281 || t1
->points
< POINTSMIN
)
283 if(rank0
< 0 && t1
->points
< t0
->points
) {
291 flg
++; /* ask for a rewrite */
294 if(t1
->points
== 0) break;
297 t1
->uid
== t0
->uid
&&
299 strncmp(t1
->name
, t0
->name
, NAMSZ
) == 0 &&
301 t1
->plchar
== t0
->plchar
&& --occ_cnt
<= 0){
305 HUP
printf("You didn't beat your previous score of %ld points.\n\n",
313 if(rank
<= ENTRYMAX
){
314 t1
= t1
->tt_next
= newttentry();
322 if(flg
) { /* rewrite record file */
323 (void) fclose(rfile
);
324 if(!(rfile
= fopen(recfile
,"w"))){
325 HUP
puts("Cannot write record file\n");
329 if(!done_stopprint
) if(rank0
> 0){
331 puts("You made the top ten list!\n");
333 printf("You reached the %d%s place on the top %d list.\n\n",
334 rank0
, ordin(rank0
), ENTRYMAX
);
337 if(rank0
== 0) rank0
= rank1
;
338 if(rank0
<= 0) rank0
= rank
;
339 if(!done_stopprint
) outheader();
341 for(rank
= 1; t1
->points
!= 0; rank
++, t1
= t1
->tt_next
) {
342 if(flg
) fprintf(rfile
,"%6s %d %d %d %d %d %ld %c%c %s,%s\n",
344 t1
->level
, t1
->maxlvl
,
345 t1
->hp
, t1
->maxhp
, t1
->points
,
346 t1
->plchar
, t1
->sex
, t1
->name
, t1
->death
);
347 if(done_stopprint
) continue;
348 if(rank
> flags
.end_top
&&
349 (rank
< rank0
-flags
.end_around
|| rank
> rank0
+flags
.end_around
)
350 && (!flags
.end_own
||
352 t1
->uid
!= t0
->uid
))
354 strncmp(t1
->name
, t0
->name
, NAMSZ
)))
357 if(rank
== rank0
-flags
.end_around
&&
358 rank0
> flags
.end_top
+flags
.end_around
+1 &&
360 (void) putchar('\n');
362 (void) outentry(rank
, t1
, 0);
364 (void) outentry(rank
, t1
, 1);
366 int t0lth
= outentry(0, t0
, -1);
367 int t1lth
= outentry(rank
, t1
, t0lth
);
368 if(t1lth
> t0lth
) t0lth
= t1lth
;
369 (void) outentry(0, t0
, t0lth
);
372 if(rank0
>= rank
) if(!done_stopprint
)
373 (void) outentry(0, t0
, 1);
374 (void) fclose(rfile
);
376 (void) unlink(reclock
);
382 (void) strcpy(linebuf
, "Number Points Name");
384 while(bp
< linebuf
+ COLNO
- 9) *bp
++ = ' ';
385 (void) strcpy(bp
, "Hp [max]");
389 /* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */
391 outentry(rank
,t1
,so
) register struct toptenentry
*t1
; {
392 boolean quit
= FALSE
, killed
= FALSE
, starv
= FALSE
;
395 if(rank
) Sprintf(eos(linebuf
), "%3d", rank
);
396 else Sprintf(eos(linebuf
), " ");
397 Sprintf(eos(linebuf
), " %6ld %8s", t1
->points
, t1
->name
);
398 if(t1
->plchar
== 'X') Sprintf(eos(linebuf
), " ");
399 else Sprintf(eos(linebuf
), "-%c ", t1
->plchar
);
400 if(!strncmp("escaped", t1
->death
, 7)) {
401 if(!strcmp(" (with amulet)", t1
->death
+7))
402 Sprintf(eos(linebuf
), "escaped the dungeon with amulet");
404 Sprintf(eos(linebuf
), "escaped the dungeon [max level %d]",
407 if(!strncmp(t1
->death
,"quit",4)) {
409 if(t1
->maxhp
< 3*t1
->hp
&& t1
->maxlvl
< 4)
410 Sprintf(eos(linebuf
), "cravenly gave up");
412 Sprintf(eos(linebuf
), "quit");
414 else if(!strcmp(t1
->death
,"choked"))
415 Sprintf(eos(linebuf
), "choked on %s food",
416 (t1
->sex
== 'F') ? "her" : "his");
417 else if(!strncmp(t1
->death
,"starv",5))
418 Sprintf(eos(linebuf
), "starved to death"), starv
= TRUE
;
419 else Sprintf(eos(linebuf
), "was killed"), killed
= TRUE
;
420 Sprintf(eos(linebuf
), " on%s level %d",
421 (killed
|| starv
) ? "" : " dungeon", t1
->level
);
422 if(t1
->maxlvl
!= t1
->level
)
423 Sprintf(eos(linebuf
), " [max %d]", t1
->maxlvl
);
424 if(quit
&& t1
->death
[4]) Sprintf(eos(linebuf
), t1
->death
+ 4);
426 if(killed
) Sprintf(eos(linebuf
), " by %s%s",
427 (!strncmp(t1
->death
, "trick", 5) || !strncmp(t1
->death
, "the ", 4))
429 index(vowels
,*t1
->death
) ? "an " : "a ",
431 Sprintf(eos(linebuf
), ".");
433 register char *bp
= eos(linebuf
);
436 Sprintf(hpbuf
, (t1
->hp
> 0) ? itoa(t1
->hp
) : "-");
437 hppos
= COLNO
- 7 - strlen(hpbuf
);
438 if(bp
<= linebuf
+ hppos
) {
439 while(bp
< linebuf
+ hppos
) *bp
++ = ' ';
440 (void) strcpy(bp
, hpbuf
);
441 Sprintf(eos(bp
), " [%d]", t1
->maxhp
);
444 if(so
== 0) puts(linebuf
);
446 register char *bp
= eos(linebuf
);
447 if(so
>= COLNO
) so
= COLNO
-1;
448 while(bp
< linebuf
+ so
) *bp
++ = ' ';
451 fputs(linebuf
,stdout
);
453 (void) putchar('\n');
455 return(strlen(linebuf
));
467 register int d
= n%10
;
468 return((d
==0 || d
>3 || n
/10==1) ? "th" : (d
==1) ? "st" :
469 (d
==2) ? "nd" : "rd");
474 (void) signal(SIGHUP
,SIG_IGN
);
475 for(x
= maxdlevel
; x
>= 0; x
--) {
477 (void) unlink(lock
); /* not all levels need be present */
481 #ifdef NOSAVEONHANGUP
484 (void) signal(SIGINT
, SIG_IGN
);
488 #endif NOSAVEONHANGUP
498 /* it is the callers responsibility to check that there is room for c */
499 charcat(s
,c
) register char *s
, c
; {
506 * Called with args from main if argc >= 0. In this case, list scores as
507 * requested. Otherwise, find scores for the current player (and list them
510 prscore(argc
,argv
) int argc
; char **argv
; {
515 register struct toptenentry
*t1
, *t2
;
516 char *recfile
= RECORD
;
521 long total_score
= 0L;
525 int outflg
= (argc
>= -1);
532 if(!(rfile
= fopen(recfile
,"r"))){
533 puts("Cannot open record file!");
537 if(argc
> 1 && !strncmp(argv
[1], "-s", 2)){
541 } else if(!argv
[1][3] && index("CFKSTWX", argv
[1][2])) {
553 player0
= "hackplayer";
561 if(outflg
) putchar('\n');
563 t1
= tt_head
= newttentry();
564 for(rank
= 1; ; rank
++) {
565 if(fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
567 &t1
->level
, &t1
->maxlvl
,
568 &t1
->hp
, &t1
->maxhp
, &t1
->points
,
569 &t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11)
571 if(t1
->points
== 0) break;
573 if(!playerct
&& t1
->uid
== uid
)
577 for(i
= 0; i
< playerct
; i
++){
578 if(strcmp(players
[i
], "all") == 0 ||
579 strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
580 (players
[i
][0] == '-' &&
581 players
[i
][1] == t1
->plchar
&&
582 players
[i
][2] == 0) ||
583 (digit(players
[i
][0]) && rank
<= atoi(players
[i
])))
586 t1
= t1
->tt_next
= newttentry();
588 (void) fclose(rfile
);
591 printf("Cannot find any entries for ");
592 if(playerct
< 1) printf("you.\n");
594 if(playerct
> 1) printf("any of ");
595 for(i
=0; i
<playerct
; i
++)
596 printf("%s%s", players
[i
], (i
<playerct
-1)?", ":".\n");
597 printf("Call is: %s -s [playernames]\n", hname
);
603 if(outflg
) outheader();
605 for(rank
= 1; t1
->points
!= 0; rank
++, t1
= t2
) {
608 if(!playerct
&& t1
->uid
== uid
)
612 for(i
= 0; i
< playerct
; i
++){
613 if(strcmp(players
[i
], "all") == 0 ||
614 strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
615 (players
[i
][0] == '-' &&
616 players
[i
][1] == t1
->plchar
&&
617 players
[i
][2] == 0) ||
618 (digit(players
[i
][0]) && rank
<= atoi(players
[i
]))){
621 (void) outentry(rank
, t1
, 0);
623 total_score
+= t1
->points
;
624 if(totcharct
< sizeof(totchars
)-1)
625 totchars
[totcharct
++] = t1
->plchar
;
633 totchars
[totcharct
] = 0;
635 /* We would like to determine whether he is experienced. However,
636 the information collected here only tells about the scores/roles
637 that got into the topten (top 100?). We should maintain a
638 .hacklog or something in his home directory. */
639 flags
.beginner
= (total_score
< 6000);
641 if(!index(totchars
, "CFKSTWX"[i
])) {
643 if(!pl_character
[0]) pl_character
[0] = "CFKSTWX"[i
];