-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrip.c
763 lines (653 loc) · 22.8 KB
/
rip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
/*
rip.c - File for the fun ends Death or a total win
XRogue: Expeditions into the Dungeons of Doom
Copyright (C) 1991 Robert Pietkivitch
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
#define REALLIFE 1 /* Print out machine and logname */
#define EDITSCORE 2 /* Edit the current score file */
#define ADDSCORE 3 /* Add a new score */
#include <curses.h>
#include <time.h>
#include <signal.h>
#include <ctype.h>
#include <sys/types.h>
#include <fcntl.h>
#include "mach_dep.h"
#include "network.h"
#include "rogue.h"
/* Network machines (for mutual score keeping) */
struct network Network[] = {
{ "", "" },
};
static char *rip[] = {
" ___________",
" / \\",
" / \\",
" / R. I. P. \\",
" / \\",
" / \\",
" | |",
" | |",
" | killed by |",
" | |",
" | |",
" | |",
" *| * * * |*",
" _________)|//\\\\///\\///\\//\\//\\/|(_________",
NULL
};
char *killname();
/*UNUSED*/
void
byebye(sig)
int sig;
{
NOOP(sig);
exit_game(EXIT_ENDWIN);
}
/*
* death:
* Do something really fun when he dies
*/
death(monst)
register short monst;
{
register char **dp = rip, *killer;
register struct tm *lt;
time_t date;
char buf[LINELEN];
struct tm *localtime();
time(&date);
lt = localtime(&date);
clear();
move(8, 0);
while (*dp)
printw("%s\n", *dp++);
mvaddstr(14, 28-((strlen(whoami)+1)/2), whoami);
sprintf(buf, "%lu Points", pstats.s_exp );
mvaddstr(15, 28-((strlen(buf)+1)/2), buf);
killer = killname(monst);
mvaddstr(17, 28-((strlen(killer)+1)/2), killer);
mvaddstr(18, 25, (sprintf(prbuf, "%4d", 1900+lt->tm_year), prbuf));
move(lines-1, 0);
refresh();
score(pstats.s_exp, KILLED, monst);
exit_game(EXIT_ENDWIN);
}
char *
killname(monst)
register short monst;
{
static char mons_name[LINELEN/2];
int i;
if (monst > NUMMONST) return("a strange monster");
if (monst >= 0) {
switch (monsters[monst].m_name[0]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
sprintf(mons_name, "an %s", monsters[monst].m_name);
break;
default:
sprintf(mons_name, "a %s", monsters[monst].m_name);
}
return(mons_name);
}
for (i = 0; i< DEATHNUM; i++) {
if (deaths[i].reason == monst)
break;
}
if (i >= DEATHNUM)
return ("strange death");
return (deaths[i].name);
}
/*
* score -- figure score and post it.
*/
/* VARARGS2 */
score(amount, flags, monst)
unsigned long amount;
int flags;
short monst;
{
struct sc_ent top_ten[NUMSCORE];
register struct sc_ent *scp;
register int i;
register struct sc_ent *sc2;
register FILE *outf;
register char *killer;
register int prflags = 0;
short upquest=0, wintype=0, uplevel=0, uptype=0; /* For network updating */
char upsystem[SYSLEN], uplogin[LOGLEN];
char *thissys; /* Holds the name of this system */
#define REASONLEN 3
static char *reason[] = {
"killed",
"quit",
"A total winner",
"somehow left",
};
char *packend;
memset(top_ten,0,sizeof(top_ten));
signal(SIGINT, byebye);
if (level == 0 && max_level == 0)
amount = 0; /*don't count if quit early */
if (flags != WINNER && flags != SCOREIT && flags != UPDATE) {
if (flags == CHICKEN) {
packend = "when you quit";
amount = amount / 100;
}
else
packend = "at your untimely demise";
mvaddstr(lines - 1, 0, retstr);
refresh();
getstr(prbuf);
showpack(packend);
}
purse = 0; /* Steal all the gold */
/*
* Open file and read list
*/
if ((outf = fopen(score_file, "rb+")) == NULL)
{
if ((outf = fopen(score_file, "wb+")) == NULL)
{
mvprintw(lines - 1, 0, "Unable to open or create score file: %s",score_file);
refresh();
return;
}
}
thissys = md_gethostname();
/*
* If this is a SCOREIT optin (rogue -s), don't call byebye. The
* endwin() calls in byebye() will and this results in a core dump.
*/
if (flags == SCOREIT) signal(SIGINT, SIG_DFL);
else signal(SIGINT, byebye);
if (flags != SCOREIT && flags != UPDATE)
{
mvaddstr(lines - 1, 0, retstr);
refresh();
fflush(stdout);
getstr(prbuf);
}
/* Check for special options */
if (strcmp(prbuf, "names") == 0)
prflags = REALLIFE;
else if (wizard) {
if (strcmp(prbuf, "edit") == 0) prflags = EDITSCORE;
else if (strcmp(prbuf, "add") == 0) {
prflags = ADDSCORE;
waswizard = FALSE; /* We want the new score recorded */
}
}
/* Read the score and convert it to a compatible format */
fseek(outf, 0, SEEK_SET);
rs_read_scorefile(outf, top_ten, NUMSCORE);
/* Get some values if this is an update */
if (flags == UPDATE) {
int errcheck, errors = 0;
upquest = (short) netread(&errcheck, sizeof(short), stdin);
if (errcheck) errors++;
if (fread(whoami, 1, NAMELEN, stdin) != NAMELEN) errors++;
wintype = (short) netread(&errcheck, sizeof(short), stdin);
if (errcheck) errors++;
uplevel = (short) netread(&errcheck, sizeof(short), stdin);
if (errcheck) errors++;
uptype = (short) netread(&errcheck, sizeof(short), stdin);
if (errcheck) errors++;
if (fread(upsystem, 1, SYSLEN, stdin) != SYSLEN)
errors++;
if (fread(uplogin, 1, LOGLEN, stdin) != LOGLEN)
errors++;
if (errors) {
fclose(outf);
return;
}
}
/*
* Insert player in list if need be
*/
if (!waswizard) {
char *login= NULL;
if (flags != UPDATE) {
login = md_getusername();
if ((login == NULL) || (*login == 0))
login = "another rogue fiend";
}
if (flags == UPDATE)
(void) update(top_ten, amount, upquest, whoami, wintype,
uplevel, monst, uptype, upsystem, uplogin);
else {
if (prflags == ADDSCORE) { /* Overlay characteristic by new ones */
char buffer[LINELEN];
clear();
mvaddstr(1, 0, "Score: ");
mvaddstr(2, 0, "Quest (number): ");
mvaddstr(3, 0, "Name: ");
mvaddstr(4, 0, "System: ");
mvaddstr(5, 0, "Login: ");
mvaddstr(6, 0, "Level: ");
mvaddstr(7, 0, "Char type: ");
mvaddstr(8, 0, "Result: ");
/* Get the score */
move(1, 7);
get_str(buffer, stdscr);
amount = atol(buffer);
/* Get the character's quest -- must be a number */
move(2, 16);
get_str(buffer, stdscr);
quest_item = atoi(buffer);
/* Get the character's name */
move(3, 6);
get_str(buffer, stdscr);
strncpy(whoami, buffer, NAMELEN);
/* Get the system */
move(4, 8);
get_str(buffer, stdscr);
strncpy(thissys, buffer, SYSLEN);
/* Get the login */
move(5, 7);
get_str(buffer, stdscr);
strncpy(login, buffer, LOGLEN);
/* Get the level */
move(6, 7);
get_str(buffer, stdscr);
level = max_level = (short) atoi(buffer);
/* Get the character type */
move(7, 11);
get_str(buffer, stdscr);
for (i=0; i<NUM_CHARTYPES; i++) {
if (EQSTR(buffer, char_class[i].name, strlen(buffer)))
break;
}
player.t_ctype = i;
/* Get the win type */
move(8, 8);
get_str(buffer, stdscr);
switch (buffer[0]) {
case 'W':
case 'w':
case 'T':
case 't':
flags = WINNER;
break;
case 'Q':
case 'q':
flags = CHICKEN;
break;
case 'k':
case 'K':
default:
flags = KILLED;
break;
}
/* Get the monster if player was killed */
if (flags == KILLED) {
mvaddstr(9, 0, "Death type: ");
get_str(buffer, stdscr);
if (buffer[0] == 'M' || buffer[0] == 'm')
do {
monst = makemonster(TRUE, "choose");
} while (monst < 0); /* Force a choice */
else monst = getdeath();
}
}
if (update(top_ten, amount, (short) quest_item, whoami, flags,
(flags == WINNER) ? (short) max_level : (short) level,
monst, player.t_ctype, thissys, login)
) {
/* Send this update to the other systems in the network */
int i, j;
char cmd[256]; /* Command for remote execution */
FILE *rmf, *popen(); /* For input to remote command */
for (i=0; Network[i].system[0] != 0; i++)
if (Network[i].system[0] != '!' &&
strcmp(Network[i].system, thissys)) {
sprintf(cmd, NETCOMMAND,
Network[i].system, Network[i].rogue);
/* Execute the command */
if ((rmf=popen(cmd, "w")) != NULL) {
unsigned long temp; /* Temporary value */
/* Write out the parameters */
(void) netwrite((unsigned long) amount,
sizeof(unsigned long), rmf);
(void) netwrite((unsigned long) monst,
sizeof(short), rmf);
(void) netwrite((unsigned long) quest_item,
sizeof(short), rmf);
(void) fwrite(whoami, 1, strlen(whoami), rmf);
for (j=strlen(whoami); j<NAMELEN; j++)
putc('\0', rmf);
(void) netwrite((unsigned long) flags,
sizeof(short), rmf);
temp = (unsigned long)
(flags==WINNER ? max_level : level);
(void) netwrite(temp, sizeof(short), rmf);
(void) netwrite((unsigned long) player.t_ctype,
sizeof(short), rmf);
(void) fwrite(thissys, 1,
strlen(thissys), rmf);
for (j=strlen(thissys); j<SYSLEN; j++)
putc('\0', rmf);
(void) fwrite(login, 1, strlen(login), rmf);
for (j=strlen(login); j<LOGLEN; j++)
putc('\0', rmf);
/* Close off the command */
(void) pclose(rmf);
}
}
}
}
}
/*
* SCOREIT -- rogue -s option. Never started curses if this option.
* UPDATE -- network scoring update. Never started curses if this option.
* EDITSCORE -- want to delete or change a score.
*/
/* if (flags != SCOREIT && flags != UPDATE && prflags != EDITSCORE)
endwin(); */
if (flags != UPDATE) {
if (flags != SCOREIT) {
clear();
refresh();
endwin();
}
/*
* Print the list
*/
printf("\nTop %d Adventurers:\nRank Score\tName\n",
NUMSCORE);
for (scp = top_ten; scp < &top_ten[NUMSCORE]; scp++) {
char *class;
if (scp->sc_score != 0) {
class = char_class[scp->sc_ctype].name;
/* Make sure we have an in-bound reason */
if (scp->sc_flags > REASONLEN) scp->sc_flags = REASONLEN;
printf("%3d %10lu\t%s (%s)", scp - top_ten + 1,
scp->sc_score, scp->sc_name, class);
if (prflags == REALLIFE) printf(" [in real life %.*s!%.*s]",
SYSLEN, scp->sc_system, LOGLEN, scp->sc_login);
printf(":\n\t\t%s on level %d", reason[scp->sc_flags],
scp->sc_level);
switch (scp->sc_flags) {
case KILLED:
printf(" by");
killer = killname(scp->sc_monster);
printf(" %s", killer);
break;
case WINNER:
printf(" with the %s",
rel_magic[scp->sc_quest].mi_name);
break;
}
if (prflags == EDITSCORE)
{
fflush(stdout);
getstr(prbuf);
printf("\n");
if (prbuf[0] == 'd') {
for (sc2 = scp; sc2 < &top_ten[NUMSCORE-1]; sc2++)
*sc2 = *(sc2 + 1);
top_ten[NUMSCORE-1].sc_score = 0;
for (i = 0; i < NAMELEN; i++)
top_ten[NUMSCORE-1].sc_name[i] = rnd(255);
top_ten[NUMSCORE-1].sc_flags = RN;
top_ten[NUMSCORE-1].sc_level = RN;
top_ten[NUMSCORE-1].sc_monster = RN;
scp--;
}
else if (prbuf[0] == 'e') {
printf("Death type: ");
getstr(prbuf);
if (prbuf[0] == 'M' || prbuf[0] == 'm')
do {
scp->sc_monster =
makemonster(TRUE, "choose");
} while (scp->sc_monster < 0); /* Force a choice */
else scp->sc_monster = getdeath();
clear();
refresh();
}
}
else printf("\n");
}
}
/* if (prflags == EDITSCORE) endwin();*/ /* End editing windowing */
}
fseek(outf, 0L, SEEK_SET);
if (flags != SCOREIT)
rs_write_scorefile(outf,top_ten,NUMSCORE);
fclose(outf);
}
/*
* showpack:
* Display the contents of the hero's pack
*/
showpack(howso)
char *howso;
{
reg char *iname;
reg int cnt, packnum;
reg struct linked_list *item;
reg struct object *obj;
idenpack();
cnt = 1;
clear();
mvprintw(0, 0, "Contents of your pack %s:\n",howso);
packnum = 'a';
for (item = pack; item != NULL; item = next(item)) {
obj = OBJPTR(item);
iname = inv_name(obj, FALSE);
mvprintw(cnt, 0, "%c) %s\n",packnum++,iname);
if (++cnt >= lines - 2 &&
next(item) != NULL) {
cnt = 1;
mvaddstr(lines - 1, 0, morestr);
refresh();
wait_for(' ');
clear();
}
}
mvprintw(cnt + 1,0,"--- %ld Gold Pieces ---",purse);
refresh();
}
total_winner()
{
register struct linked_list *item;
register struct object *obj;
register long worth;
register char c;
register long oldpurse;
clear();
standout();
addstr(" \n");
addstr(" @ @ @ @ @ @@@ @ @ \n");
addstr(" @ @ @@ @@ @ @ @ @ \n");
addstr(" @ @ @@@ @ @ @ @ @ @@@ @@@@ @@@ @ @@@ @ \n");
addstr(" @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ \n");
addstr(" @ @ @ @ @ @ @ @@@@ @ @ @@@@@ @ @ @ \n");
addstr(" @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ \n");
addstr(" @@@ @@@ @@ @ @ @ @@@@ @@@@ @@@ @@@ @@ @ \n");
addstr(" \n");
addstr(" Congratulations, you have made it to the light of day! \n");
standend();
addstr("\nYou have joined the elite ranks of those who have escaped the\n");
addstr("Dungeons of Doom alive. You journey home and sell all your loot at\n");
addstr("a great profit and are appointed ");
switch (player.t_ctype) {
case C_FIGHTER: addstr("Leader of the Fighter's Guild.\n");
when C_RANGER: addstr("King of the Northern Land.\n");
when C_PALADIN: addstr("King of the Southern Land.\n");
when C_MAGICIAN:addstr("High Wizard of the Sorcerer's Guild.\n");
when C_CLERIC: addstr("Bishop of the Monastery.\n");
when C_THIEF: addstr("Leader of the Thief's Guild.\n");
when C_MONK: addstr("Master of the Temple.\n");
when C_ASSASSIN: addstr("Leader of the Assassin's Guild.\n");
when C_DRUID: addstr("High Priest of the Monastery.\n");
otherwise: addstr("Town Drunk in the Tavern.\n");
}
mvaddstr(lines - 1, 0, spacemsg);
refresh();
wait_for(' ');
clear();
mvaddstr(0, 0, " Worth Item");
oldpurse = purse;
for (c = 'a', item = pack; item != NULL; c++, item = next(item))
{
obj = OBJPTR(item);
worth = get_worth(obj);
if (obj->o_group == 0)
worth *= obj->o_count;
whatis(item);
mvprintw(c-'a'+1, 0, "%c) %6ld %s", c, worth, inv_name(obj, FALSE));
purse += worth;
}
mvprintw(c - 'a' + 1, 0," %5ld Gold Pieces ", oldpurse);
refresh();
score(pstats.s_exp + (long) purse, WINNER, '\0');
exit_game(EXIT_ENDWIN);
}
void
delete_score(top_ten, idx)
struct sc_ent top_ten[NUMSCORE];
int idx;
{
for(;idx < NUMSCORE-1;idx++)
top_ten[idx] = top_ten[idx+1];
top_ten[NUMSCORE-1].sc_score = 0L;
}
int
insert_score(top_ten, sc)
struct sc_ent top_ten[NUMSCORE];
struct sc_ent *sc;
{
int i,j;
if (top_ten[NUMSCORE-1].sc_score > 0)
return(-1); /* no room */
for(i = 0; i < NUMSCORE; i++) {
if (sc->sc_score > top_ten[i].sc_score) {
for(j = NUMSCORE-1; j > i; j--)
top_ten[j] = top_ten[j-1];
top_ten[i] = *sc;
return(i);
}
}
return(-1);
}
/* PCS = player-class-system (used to determines uniqueness of player) */
int
is_pcs_match(sc1,sc2)
struct sc_ent *sc1;
struct sc_ent *sc2;
{
return( (strcmp(sc1->sc_name,sc2->sc_name) == 0) &&
(sc1->sc_ctype == sc2->sc_ctype) &&
(strcmp(sc1->sc_system, sc2->sc_system)==0) );
}
int
count_pcs_matches(top_ten,sc,lowest)
struct sc_ent top_ten[NUMSCORE];
struct sc_ent *sc;
int *lowest;
{
int i, matches = 0;
*lowest = -1;
for(i = 0; i < NUMSCORE; i++) {
if (is_pcs_match(sc,&top_ten[i])) {
matches++;
*lowest = i;
}
}
return(matches);
}
int
find_most_pcs_matches(top_ten,sc,num,idx)
struct sc_ent top_ten[NUMSCORE];
struct sc_ent *sc;
int *num, *idx;
{
int i, matches, max_match=0, max_match_idx=-1, lowest;
for(i = NUMSCORE-1; i > 0; i--) {
matches = count_pcs_matches(top_ten,&top_ten[i],&lowest);
if (matches > max_match) {
max_match = matches;
max_match_idx = lowest;
}
}
matches = count_pcs_matches(top_ten,sc,&lowest) + 1;
if (matches > max_match) {
*num = matches;
*idx = lowest;
}
else {
*num = max_match;
*idx = max_match_idx;
}
return(0);
}
int
add_score(top_ten,sc)
struct sc_ent top_ten[NUMSCORE];
struct sc_ent *sc;
{
int idx, count;
if (insert_score(top_ten,sc) == -1) {
/* Simple insert if space available in table */
find_most_pcs_matches(top_ten,sc,&count,&idx);
/* EVERY ENTRY UNIQUE, */
/* INSERT IF SCORE > LOWEST MATCH SCORE */
if (count == 1) {
if (sc->sc_score > top_ten[idx].sc_score) {
delete_score(top_ten,idx);
insert_score(top_ten,sc);
}
}
/* CURRENT PCS HAS HIGHEST DUPE COUNT */
/* INSERT IF SCORE > LOWEST MATCH SCORE */
else if (is_pcs_match(sc,&top_ten[idx])) {
if (sc->sc_score > top_ten[idx].sc_score) {
delete_score(top_ten,idx);
insert_score(top_ten,sc);
}
}
/* UNRELATED PCS HAS HIGHEST DUPE COUNT */
/* DELETE LOWEST DUPE TO MAKE ROOM AND INSERT */
else {
delete_score(top_ten,idx);
insert_score(top_ten,sc);
}
}
}
update(top_ten, amount, quest, whoami, flags, level, monst, ctype, system, login)
struct sc_ent top_ten[];
unsigned long amount;
short quest, flags, level, monst, ctype;
char *whoami, *system, *login;
{
struct sc_ent sc;
sc.sc_score = amount;
sc.sc_quest = quest;
strncpy(sc.sc_name, whoami, NAMELEN);
sc.sc_name[NAMELEN-1] = 0;
sc.sc_flags = flags;
sc.sc_level = level;
sc.sc_monster = monst;
sc.sc_ctype = ctype;
strncpy(sc.sc_system, system, SYSLEN);
sc.sc_system[SYSLEN - 1] = 0;
strncpy(sc.sc_login, login, LOGLEN);
sc.sc_login[LOGLEN-1] = 0;
add_score(top_ten, &sc);
return(1);
}