-
Notifications
You must be signed in to change notification settings - Fork 0
/
RIP.C
538 lines (500 loc) · 12.3 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
/*
* File for the fun ends
* Death or a total win
*
* rip.c 1.4 (A.I. Design) 12/14/84
*/
#include "rogue.h"
#include "curses.h"
static int sc_fd;
/*
* external curses IBM (jll)
*/
extern int scr_type;
/*
* score:
* Figure score and post it.
*/
/* VARARGS2 */
score(amount, flags, monst)
int amount, flags;
char monst;
{
#ifndef DEMO
#ifndef WIZARD
struct sc_ent his_score, top_ten[TOPSCORES];
register int newfile = FALSE, rank=0;
char response = ' ';
is_saved = TRUE;
if (amount || flags || monst)
{
move(LINES-1,0);
cursor(TRUE);
printw("[Press Enter to see rankings]");
flush_type();
wait_for('\r');
move(LINES-1,0);
}
while ((sc_fd = open(s_score, 0)) < 0)
{
printw("\n");
if (noscore || (amount == 0))
return;
str_attr("No scorefile: %Create %Retry %Abort");
reread:
switch(response = readchar())
{
case 'c':
case 'C':
close(creat(s_score, 0666));
case 'r':
case 'R':
break;
case 'a':
case 'A':
return;
default:
goto reread;
}
}
printw("\n");
get_scores(&top_ten);
if (noscore != TRUE)
{
strcpy(his_score.sc_name,whoami);
his_score.sc_gold = amount;
his_score.sc_fate = flags ? flags : monst;
his_score.sc_level = max_level;
his_score.sc_rank = pstats.s_lvl;
rank = add_scores(&his_score,&top_ten);
}
close(sc_fd);
if (rank > 0) {
if ((sc_fd = creat(s_score, 0666)) >= 0) {
put_scores(&top_ten);
close(sc_fd);
}
}
pr_scores(rank,&top_ten);
#endif WIZARD
#endif DEMO
}
#ifndef DEMO
#ifndef WIZARD
get_scores(top10)
struct sc_ent *top10;
{
register int i, retcode = 1;
for(i=0; i<TOPSCORES; i++,top10++) {
if (retcode > 0)
retcode = read(sc_fd,top10,sizeof(struct sc_ent));
if (retcode <= 0)
top10->sc_gold = 0;
}
}
put_scores(top10)
struct sc_ent *top10;
{
register int i;
for (i=0;(i<TOPSCORES) && top10->sc_gold;i++,top10++)
{
if (write(sc_fd,top10,sizeof(struct sc_ent)) <= 0)
return;
}
}
pr_scores(newrank,top10)
int newrank;
struct sc_ent *top10;
{
register int i;
register char *ki;
int curl;
char dthstr[30];
char *altmsg;
switch_page(old_page_no);
clear();
high();
if (scr_type == 7)
standout();
mvaddstr(0,0,"Guildmaster's Hall Of Fame:");
standend();
yellow();
mvaddstr(2,0,"Gold");
for (i=0;i<TOPSCORES;i++,top10++)
{
altmsg = NULL;
brown();
if (newrank - 1 == i)
{
if (scr_type == 7)
standout();
else
yellow();
}
if (top10->sc_gold <=0 )
break;
curl = 4 + ((COLS==40)?(i * 2):i);
move (curl,0);
printw("%d ",top10->sc_gold);
move (curl,6);
if (newrank - 1 != i)
red();
printw("%s",top10->sc_name);
if ((newrank) - 1 != i)
brown();
if (top10->sc_level >= 26)
altmsg = " Honored by the Guild";
if (isalpha(top10->sc_fate))
{
sprintf(dthstr," killed by %s",
killname((0xff & top10->sc_fate), TRUE));
if (COLS == 40 && strlen(dthstr) > 23)
strcpy(dthstr," killed");
}
else
switch(top10->sc_fate) {
case 2:
altmsg = " A total winner!";
break;
case 1:
strcpy(dthstr," quit");
break;
default:
strcpy(dthstr," wierded out");
}
if ((strlen(top10->sc_name) + 10 +
strlen(he_man[top10->sc_rank-1])) < COLS)
{
if (top10->sc_rank > 1 && (strlen(top10->sc_name)))
printw(" \"%s\"",he_man[top10->sc_rank - 1]);
}
if (COLS == 40)
move(curl+1,6);
if (altmsg == NULL)
printw("%s on level %d",dthstr,top10->sc_level);
else
addstr(altmsg);
}
standend();
if (COLS == 80)
addstr("\n\n\n\n");
}
add_scores(newscore,oldlist)
struct sc_ent *newscore, *oldlist;
{
register struct sc_ent *sentry, *insert;
int retcode = TOPSCORES+1;
for(sentry=&oldlist[TOPSCORES-1];sentry>=oldlist;sentry--) {
if ((unsigned)newscore->sc_gold > (unsigned)sentry->sc_gold) {
insert = sentry;
retcode--;
if ((insert < &oldlist[TOPSCORES-1]) && sentry->sc_gold)
sentry[1] = *sentry;
} else
break;
}
if (retcode == 11)
return 0;
*insert = *newscore;
return retcode;
}
#endif WIZARD
#endif DEMO
/*
* death:
* Do something really fun when he dies
*/
death(monst)
register char monst;
{
register char *killer;
char buf[MAXSTR];
register int year;
#ifndef DEMO
purse -= purse / 10;
switch_page(old_page_no);
clear();
drop_curtain();
if (is_color)
brown();
box((COLS==40)?1:7,(COLS-28)/2,22,(COLS+28)/2);
standend();
center(10, "REST");
center(11, "IN");
center(12, "PEACE");
red();
center(21, " * * * ");
green();
center(22, "___\\/(\\/)/(\\/ \\\\(//)\\)\\/(//)\\\\)//(\\__");
standend();
if (scr_type == 7)
uline();
center(14, whoami);
standend();
killer = killname(monst, TRUE);
strcpy(buf,"killed by");
center(15,buf);
center(16, prbuf);
sprintf(buf, "%u Au", purse);
center(18, buf);
regs->ax = 0x2a << 8;
swint(SW_DOS,regs);
year = regs->cx;
sprintf(buf, "%u", year);
center(19, buf);
raise_curtain();
move(LINES-1, 0);
score(purse, 0, monst);
#else DEMO
demo(0);
killer = killname(monst, TRUE);
strcpy(buf,"This time you were killed by");
strcat(buf," ");
strcat(buf,killer);
if (strlen(buf) > (COLS-2))
center(6,"This time you were killed");
else
center(6, buf);
move(LINES-2,0);
#endif DEMO
wclose(0);
exit();
}
/*
* total_winner:
* Code for a winner
*/
total_winner()
{
#ifndef DEMO
register THING *obj;
register int worth;
register byte c;
register int oldpurse;
switch_page(old_page_no);
clear();
#ifdef MINROG
if (!terse)
{
standout();
printw(" \n");
printw(" @ @ @ @ @ @@@ @ @ \n");
printw(" @ @ @@ @@ @ @ @ @ \n");
printw(" @ @ @@@ @ @ @ @ @ @@@ @@@@ @@@ @ @@@ @ \n");
printw(" @@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ \n");
printw(" @ @ @ @ @ @ @ @@@@ @ @ @@@@@ @ @ @ \n");
printw(" @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ \n");
printw(" @@@ @@@ @@ @ @ @ @@@@ @@@@ @@@ @@@ @@ @ \n");
}
printw(" \n");
printw(" Congratulations, you have made it to the light of day! \n");
standend();
printw("\nYou have joined the elite ranks of those who have escaped the\n");
printw("Dungeons of Doom alive. You journey home and sell all your loot at\n");
printw("a great profit and are admitted to the fighters guild.\n");
#else
printw("Congratulations!\n\nYou have made it to the light of day!\n\n\n\n");
printw("You journey home and sell all your\n");
printw("loot at a great profit and are\n");
printw("admitted to the fighters guild.\n\n\n");
#endif MINROG
mvaddstr(LINES - 1, 0, "--Press space to continue--");
wait_for(' ');
clear();
mvaddstr(0, 0, " Worth Item");
oldpurse = purse;
for (c = 'a', obj = pack; obj != NULL; c++, obj = next(obj))
{
switch (obj->o_type)
{
when FOOD:
worth = 2 * obj->o_count;
when WEAPON:
switch (obj->o_which)
{
when MACE: worth = 8;
when SWORD: worth = 15;
when CROSSBOW: worth = 30;
when ARROW: worth = 1;
when DAGGER: worth = 2;
when TWOSWORD: worth = 75;
when DART: worth = 1;
when BOW: worth = 15;
when BOLT: worth = 1;
when SPEAR: worth = 5;
}
worth *= 3 * (obj->o_hplus + obj->o_dplus) + obj->o_count;
obj->o_flags |= ISKNOW;
when ARMOR:
switch (obj->o_which)
{
when LEATHER: worth = 20;
when RING_MAIL: worth = 25;
when STUDDED_LEATHER: worth = 20;
when SCALE_MAIL: worth = 30;
when CHAIN_MAIL: worth = 75;
when SPLINT_MAIL: worth = 80;
when BANDED_MAIL: worth = 90;
when PLATE_MAIL: worth = 150;
}
worth += (9 - obj->o_ac) * 100;
worth += (10 * (a_class[obj->o_which] - obj->o_ac));
obj->o_flags |= ISKNOW;
when SCROLL:
worth = s_magic[obj->o_which].mi_worth;
worth *= obj->o_count;
if (!s_know[obj->o_which])
worth /= 2;
s_know[obj->o_which] = TRUE;
when POTION:
worth = p_magic[obj->o_which].mi_worth;
worth *= obj->o_count;
if (!p_know[obj->o_which])
worth /= 2;
p_know[obj->o_which] = TRUE;
when RING:
worth = r_magic[obj->o_which].mi_worth;
if (obj->o_which == R_ADDSTR || obj->o_which == R_ADDDAM ||
obj->o_which == R_PROTECT || obj->o_which == R_ADDHIT)
if (obj->o_ac > 0)
worth += obj->o_ac * 100;
else
worth = 10;
if (!(obj->o_flags & ISKNOW))
worth /= 2;
obj->o_flags |= ISKNOW;
r_know[obj->o_which] = TRUE;
when STICK:
worth = ws_magic[obj->o_which].mi_worth;
worth += 20 * obj->o_charges;
if (!(obj->o_flags & ISKNOW))
worth /= 2;
obj->o_flags |= ISKNOW;
ws_know[obj->o_which] = TRUE;
when AMULET:
worth = 1000;
}
if (worth < 0)
worth = 0;
move(c - 'a' + 1, 0);
printw( "%c) %5d %s", c, worth, inv_name(obj, FALSE));
purse += worth;
}
move(c - 'a' + 1, 0);
printw(" %5u Gold Pieces ", oldpurse);
score(purse, 2);
#endif DEMO
exit(0);
}
/*
* killname:
* Convert a code to a monster name
*/
char *
killname(monst, doart)
register char monst;
bool doart;
{
register char *sp;
register bool article;
sp = prbuf;
article = TRUE;
switch (monst)
{
when 'a':
sp = "arrow";
when 'b':
sp = "bolt";
when 'd':
sp = "dart";
when 's':
sp = "starvation";
article = FALSE;
when 'f':
sp = "fall";
otherwise:
if (monst >= 'A' && monst <= 'Z')
sp = monsters[monst-'A'].m_name;
else
{
sp = "God";
article = FALSE;
}
}
if (doart && article)
sprintf(prbuf, "a%s ", vowelstr(sp));
else
prbuf[0] = '\0';
strcat(prbuf, sp);
return prbuf;
}
#ifdef DEMO
/*
* For the demonstration version of rogue we really want to
* Print out a message when the game ends telling them how
* order the game.
*/
demo(endtype)
int endtype;
{
register int i;
char demobuf[81];
switch_page(old_page_no);
clear();
if (is_color)
brown();
box(0,0,LINES-2,COLS-1);
bold();
center(2,"ROGUE: The Adventure Game");
standend();
if (is_color)
lmagenta();
sprintf(demobuf,"Sorry, %s but this is just a demonstration",whoami);
if (terse)
sprintf(demobuf,"Sorry, this is just a demonstration");
center(4,demobuf);
if (endtype == 1) /* quiter */
{
sprintf(demobuf,"You quit with %u pieces of Gold",purse);
center(6,demobuf);
} else if (endtype == DEMOTIME) {
sprintf(demobuf,"You ended with %u gold pieces",purse);
center(6,demobuf);
}
if (terse)
center(8,"If you're interested in doing some");
else
center(8,"But, if you're interested in doing some");
center(9,"more exploring in the Dungeons of Doom");
if (is_color)
red();
center(11,"Please Contact: ");
if (!is_color)
uline();
else
standend();
center(13,"A. I. Design");
center(14,"P.O. Box 3685");
center(15,"Santa Clara, California 95055");
if (is_color)
red();
center(17,"(408) 296-1634");
if (is_color)
yellow();
else
standend();
center(19,"(C) Copyright 1983");
high();
center(20,"Artificial Intelligence Design");
if (is_color)
yellow();
else
standend();
center(21,"All Rights Reserved");
if (endtype == 0)
return;
move(LINES-2,0);
wclose(0);
exit(0);
}
#endif DEMO