/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.end.c - version 1.0.3 */
#define Sprintf (void) sprintf
extern char plname
[], pl_character
[];
extern char *itoa(), *ordin(), *eos();
(void) signal(SIGINT
,SIG_IGN
);
(void) signal(SIGINT
,done1
);
(void) signal(SIGINT
, SIG_IGN
);
(void) signal(SIGQUIT
, SIG_IGN
);
(void) signal(SIGHUP
, SIG_IGN
);
done_in_by(mtmp
) register struct monst
*mtmp
; {
if(mtmp
->data
->mlet
== ' '){
Sprintf(buf
, "the ghost of %s", (char *) mtmp
->mextra
);
} else if(mtmp
->mnamelth
) {
Sprintf(buf
, "%s called %s",
mtmp
->data
->mname
, NAME(mtmp
));
} else if(mtmp
->minvis
) {
Sprintf(buf
, "invisible %s", mtmp
->data
->mname
);
} else killer
= mtmp
->data
->mname
;
/* called with arg "died", "drowned", "escaped", "quit", "choked", "panicked",
"burned", "starved" or "tricked" */
/* Be careful not to call panic from here! */
if(wizard
&& *st1
== 'd'){
if(u
.uhpmax
< 0) u
.uhpmax
= 100; /* arbitrary */
pline("For some reason you are still alive.");
if(multi
> 0) multi
= 0; else multi
= -1;
(void) signal(SIGINT
, done_intr
);
(void) signal(SIGQUIT
, done_intr
);
(void) signal(SIGHUP
, done_hangup
);
if(*st1
== 'q' && u
.uhp
< 1){
killer
= "quit while already on Charon's boat";
if(*st1
== 's') killer
= "starvation"; else
if(*st1
== 'd' && st1
[1] == 'r') killer
= "drowning"; else
if(*st1
== 'p') killer
= "panic"; else
if(*st1
== 't') killer
= "trickery"; else
if(!index("bcd", *st1
)) killer
= st1
;
if(flags
.toplin
== 1) more();
if(*st1
== 'c') killer
= st1
; /* after outrip() */
settty((char *) 0); /* does a clear_screen() */
printf("Goodbye %s %s...\n\n", pl_character
, plname
);
tmp
= u
.ugold
- u
.ugold0
;
if(*st1
== 'd' || *st1
== 'b')
u
.urexp
+= 50 * maxdlevel
;
u
.urexp
+= 1000*((maxdlevel
> 30) ? 10 : maxdlevel
- 20);
extern struct monst
*mydogs
;
register struct monst
*mtmp
;
register struct obj
*otmp
;
register unsigned worthlessct
= 0;
boolean has_amulet
= FALSE
;
if(!done_stopprint
) printf("You");
printf(" and %s", monnam(mtmp
));
printf("\nescaped from the dungeon with %ld points,\n",
printf("You escaped from the dungeon with %ld points,\n",
for(otmp
= invent
; otmp
; otmp
= otmp
->nobj
) {
if(otmp
->olet
== GEM_SYM
){
objects
[otmp
->otyp
].oc_name_known
= 1;
i
= otmp
->quan
*objects
[otmp
->otyp
].g_val
;
worthlessct
+= otmp
->quan
;
printf("\t%s (worth %d Zorkmids),\n",
} else if(otmp
->olet
== AMULET_SYM
) {
i
= (otmp
->spe
< 0) ? 2 : 5000;
printf("\t%s (worth %d Zorkmids),\n",
killer
= "escaped (with amulet)";
if(worthlessct
) if(!done_stopprint
)
printf("\t%u worthless piece%s of coloured glass,\n",
worthlessct
, plur(worthlessct
));
if(has_amulet
) u
.urexp
*= 2;
printf("You %s on dungeon level %d with %ld points,\n",
printf("and %ld piece%s of gold, after %ld move%s.\n",
u
.ugold
, plur(u
.ugold
), moves
, plur(moves
));
printf("You were level %u with a maximum of %d hit points when you %s.\n",
u
.ulevel
, u
.uhpmax
, st1
);
if(*st1
== 'e' && !done_stopprint
){
getret(); /* all those pieces of coloured glass ... */
if(done_stopprint
) printf("\n\n");
#define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry))
#define POINTSMIN 1 /* must be > 0 */
#define ENTRYMAX 100 /* must be >= 10 */
#define PERS_IS_UID /* delete for PERSMAX per name; now per uid */
struct toptenentry
*tt_next
;
int level
,maxlvl
,hp
,maxhp
;
char date
[7]; /* yymmdd */
int rank
, rank0
= -1, rank1
= 0;
register struct toptenentry
*t0
, *t1
, *tprev
;
char *reclock
= "record_lock";
#define HUP if(!done_hup)
while(link(recfile
, reclock
) == -1) {
HUP
puts("I give up. Sorry.");
HUP
puts("Perhaps there is an old record_lock around?");
HUP
printf("Waiting for access to record file. (%d)\n",
HUP (void) fflush(stdout
);
if(!(rfile
= fopen(recfile
,"r"))){
HUP
puts("Cannot open record file!");
HUP (void) putchar('\n');
/* create a new 'topten' entry */
t0
->plchar
= pl_character
[0];
t0
->sex
= (flags
.female
? 'F' : 'M');
(void) strncpy(t0
->name
, plname
, NAMSZ
);
(void) strncpy(t0
->death
, killer
, DTHSZ
);
(void) strcpy(t0
->date
, getdate());
/* assure minimum number of points */
if(t0
->points
< POINTSMIN
)
t1
= tt_head
= newttentry();
/* rank0: -1 undefined, 0 not_on_list, n n_th on list */
if(fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
&t1
->hp
, &t1
->maxhp
, &t1
->points
,
&t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11
|| t1
->points
< POINTSMIN
)
if(rank0
< 0 && t1
->points
< t0
->points
) {
flg
++; /* ask for a rewrite */
if(t1
->points
== 0) break;
strncmp(t1
->name
, t0
->name
, NAMSZ
) == 0 &&
t1
->plchar
== t0
->plchar
&& --occ_cnt
<= 0){
HUP
printf("You didn't beat your previous score of %ld points.\n\n",
t1
= t1
->tt_next
= newttentry();
if(flg
) { /* rewrite record file */
if(!(rfile
= fopen(recfile
,"w"))){
HUP
puts("Cannot write record file\n");
if(!done_stopprint
) if(rank0
> 0){
puts("You made the top ten list!\n");
printf("You reached the %d%s place on the top %d list.\n\n",
rank0
, ordin(rank0
), ENTRYMAX
);
if(rank0
== 0) rank0
= rank1
;
if(rank0
<= 0) rank0
= rank
;
if(!done_stopprint
) outheader();
for(rank
= 1; t1
->points
!= 0; rank
++, t1
= t1
->tt_next
) {
if(flg
) fprintf(rfile
,"%6s %d %d %d %d %d %ld %c%c %s,%s\n",
t1
->hp
, t1
->maxhp
, t1
->points
,
t1
->plchar
, t1
->sex
, t1
->name
, t1
->death
);
if(done_stopprint
) continue;
if(rank
> flags
.end_top
&&
(rank
< rank0
-flags
.end_around
|| rank
> rank0
+flags
.end_around
)
strncmp(t1
->name
, t0
->name
, NAMSZ
)))
if(rank
== rank0
-flags
.end_around
&&
rank0
> flags
.end_top
+flags
.end_around
+1 &&
(void) outentry(rank
, t1
, 0);
(void) outentry(rank
, t1
, 1);
int t0lth
= outentry(0, t0
, -1);
int t1lth
= outentry(rank
, t1
, t0lth
);
if(t1lth
> t0lth
) t0lth
= t1lth
;
(void) outentry(0, t0
, t0lth
);
if(rank0
>= rank
) if(!done_stopprint
)
(void) outentry(0, t0
, 1);
(void) strcpy(linebuf
, "Number Points Name");
while(bp
< linebuf
+ COLNO
- 9) *bp
++ = ' ';
(void) strcpy(bp
, "Hp [max]");
/* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */
outentry(rank
,t1
,so
) register struct toptenentry
*t1
; {
boolean quit
= FALSE
, killed
= FALSE
, starv
= FALSE
;
if(rank
) Sprintf(eos(linebuf
), "%3d", rank
);
else Sprintf(eos(linebuf
), " ");
Sprintf(eos(linebuf
), " %6ld %8s", t1
->points
, t1
->name
);
if(t1
->plchar
== 'X') Sprintf(eos(linebuf
), " ");
else Sprintf(eos(linebuf
), "-%c ", t1
->plchar
);
if(!strncmp("escaped", t1
->death
, 7)) {
if(!strcmp(" (with amulet)", t1
->death
+7))
Sprintf(eos(linebuf
), "escaped the dungeon with amulet");
Sprintf(eos(linebuf
), "escaped the dungeon [max level %d]",
if(!strncmp(t1
->death
,"quit",4)) {
if(t1
->maxhp
< 3*t1
->hp
&& t1
->maxlvl
< 4)
Sprintf(eos(linebuf
), "cravenly gave up");
Sprintf(eos(linebuf
), "quit");
else if(!strcmp(t1
->death
,"choked"))
Sprintf(eos(linebuf
), "choked on %s food",
(t1
->sex
== 'F') ? "her" : "his");
else if(!strncmp(t1
->death
,"starv",5))
Sprintf(eos(linebuf
), "starved to death"), starv
= TRUE
;
else Sprintf(eos(linebuf
), "was killed"), killed
= TRUE
;
Sprintf(eos(linebuf
), " on%s level %d",
(killed
|| starv
) ? "" : " dungeon", t1
->level
);
if(t1
->maxlvl
!= t1
->level
)
Sprintf(eos(linebuf
), " [max %d]", t1
->maxlvl
);
if(quit
&& t1
->death
[4]) Sprintf(eos(linebuf
), t1
->death
+ 4);
if(killed
) Sprintf(eos(linebuf
), " by %s%s",
(!strncmp(t1
->death
, "trick", 5) || !strncmp(t1
->death
, "the ", 4))
index(vowels
,*t1
->death
) ? "an " : "a ",
Sprintf(eos(linebuf
), ".");
register char *bp
= eos(linebuf
);
Sprintf(hpbuf
, (t1
->hp
> 0) ? itoa(t1
->hp
) : "-");
hppos
= COLNO
- 7 - strlen(hpbuf
);
if(bp
<= linebuf
+ hppos
) {
while(bp
< linebuf
+ hppos
) *bp
++ = ' ';
(void) strcpy(bp
, hpbuf
);
Sprintf(eos(bp
), " [%d]", t1
->maxhp
);
if(so
== 0) puts(linebuf
);
register char *bp
= eos(linebuf
);
if(so
>= COLNO
) so
= COLNO
-1;
while(bp
< linebuf
+ so
) *bp
++ = ' ';
return((d
==0 || d
>3 || n
/10==1) ? "th" : (d
==1) ? "st" :
(void) signal(SIGHUP
,SIG_IGN
);
for(x
= maxdlevel
; x
>= 0; x
--) {
(void) unlink(lock
); /* not all levels need be present */
(void) signal(SIGINT
, SIG_IGN
);
/* it is the callers responsibility to check that there is room for c */
charcat(s
,c
) register char *s
, c
; {
* Called with args from main if argc >= 0. In this case, list scores as
* requested. Otherwise, find scores for the current player (and list them
prscore(argc
,argv
) int argc
; char **argv
; {
register struct toptenentry
*t1
, *t2
;
int outflg
= (argc
>= -1);
if(!(rfile
= fopen(recfile
,"r"))){
puts("Cannot open record file!");
if(argc
> 1 && !strncmp(argv
[1], "-s", 2)){
} else if(!argv
[1][3] && index("CFKSTWX", argv
[1][2])) {
if(outflg
) putchar('\n');
t1
= tt_head
= newttentry();
for(rank
= 1; ; rank
++) {
if(fscanf(rfile
, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]",
&t1
->hp
, &t1
->maxhp
, &t1
->points
,
&t1
->plchar
, &t1
->sex
, t1
->name
, t1
->death
) != 11)
if(t1
->points
== 0) break;
if(!playerct
&& t1
->uid
== uid
)
for(i
= 0; i
< playerct
; i
++){
if(strcmp(players
[i
], "all") == 0 ||
strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
players
[i
][1] == t1
->plchar
&&
(digit(players
[i
][0]) && rank
<= atoi(players
[i
])))
t1
= t1
->tt_next
= newttentry();
printf("Cannot find any entries for ");
if(playerct
< 1) printf("you.\n");
if(playerct
> 1) printf("any of ");
for(i
=0; i
<playerct
; i
++)
printf("%s%s", players
[i
], (i
<playerct
-1)?", ":".\n");
printf("Call is: %s -s [playernames]\n", hname
);
for(rank
= 1; t1
->points
!= 0; rank
++, t1
= t2
) {
if(!playerct
&& t1
->uid
== uid
)
for(i
= 0; i
< playerct
; i
++){
if(strcmp(players
[i
], "all") == 0 ||
strncmp(t1
->name
, players
[i
], NAMSZ
) == 0 ||
players
[i
][1] == t1
->plchar
&&
(digit(players
[i
][0]) && rank
<= atoi(players
[i
]))){
(void) outentry(rank
, t1
, 0);
total_score
+= t1
->points
;
if(totcharct
< sizeof(totchars
)-1)
totchars
[totcharct
++] = t1
->plchar
;
/* We would like to determine whether he is experienced. However,
the information collected here only tells about the scores/roles
that got into the topten (top 100?). We should maintain a
.hacklog or something in his home directory. */
flags
.beginner
= (total_score
< 6000);
if(!index(totchars
, "CFKSTWX"[i
])) {
if(!pl_character
[0]) pl_character
[0] = "CFKSTWX"[i
];