forked from RoguelikeRestorationProject/urogue1.03
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrip.c
675 lines (569 loc) · 17.6 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
/*
rip.c - File for the fun ends Death or a total win
UltraRogue: The Ultimate Adventure in the Dungeons of Doom
Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka
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.
*/
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include "rogue.h"
static struct sc_ent
{
int sc_lvl;
long sc_score;
char sc_name[76];
long sc_gold;
int sc_flags;
int sc_level;
int sc_artifacts;
int sc_monster;
} top_ten[10];
static const char *rip[] =
{
" __________",
" / \\",
" / REST \\",
" / IN \\",
" / PEACE \\",
" / \\",
" | |",
" | |",
" | killed by |",
" | |",
" | 1993 |",
" *| * * * | *",
" ________)/\\\\_//(\\/(/\\)/\\//\\/|_)_______",
0
};
/*
death()
Do something really fun when he dies
*/
void
death(int monst)
{
char **dp = (char **) rip, *killer;
struct tm *lt;
time_t date;
char buf[80];
int c;
if (is_wearing(R_RESURRECT) || rnd(wizard ? 3 : 67) == 0)
{
int die = TRUE;
if (resurrect-- == 0)
msg("You've run out of lives.");
else if (!save_resurrect(ring_value(R_RESURRECT)))
msg("Your attempt to return from the grave fails.");
else
{
struct linked_list *item;
struct linked_list *next_item;
struct object *obj;
int rm, flags;
coord pos;
die = FALSE;
msg("You feel a sudden warmth and then nothingness.");
teleport();
if (ring_value(R_RESURRECT) > 1 && rnd(10))
{
pstats.s_hpt = 2 * pstats.s_const;
pstats.s_const = max(pstats.s_const - 1, 3);
}
else
{
for (item = pack; item != NULL; item = next_item)
{
obj = OBJPTR(item);
if (obj->o_flags & ISOWNED || obj->o_flags & ISPROT)
{
next_item = next(item);
continue;
}
flags = obj->o_flags;
obj->o_flags &= ~ISCURSED;
dropcheck(obj);
obj->o_flags = flags;
next_item = next(item);
rem_pack(obj);
if (obj->o_type == ARTIFACT)
has_artifact &= ~(1 << obj->o_which);
do
{
rm = rnd_room();
rnd_pos(&rooms[rm], &pos);
}
while(winat(pos.y, pos.x) != FLOOR);
obj->o_pos = pos;
add_obj(item, obj->o_pos.y, obj->o_pos.x);
}
pstats.s_hpt = pstats.s_const;
pstats.s_const = max(pstats.s_const - roll(2, 2), 3);
}
chg_str(roll(1, 4), TRUE, FALSE);
pstats.s_lvl = max(pstats.s_lvl, 1);
no_command += 2 + rnd(4);
if (on(player, ISHUH))
lengthen_fuse(FUSE_UNCONFUSE, rnd(8) + HUHDURATION);
else
light_fuse(FUSE_UNCONFUSE, 0, rnd(8) + HUHDURATION, AFTER);
turn_on(player, ISHUH);
light(&hero);
}
if (die)
{
wmove(cw, mpos, 0);
waddstr(cw, morestr);
wrefresh(cw);
wait_for(' ');
}
else
return;
}
time(&date);
lt = localtime(&date);
clear();
wclear(cw);
move(8, 0);
while (*dp)
printw("%s\n", *dp++);
mvaddstr(14, 28 - ((int)(strlen(whoami) + 1) / 2), whoami);
sprintf(buf, "%d+%ld Points", pstats.s_lvl, pstats.s_exp);
mvaddstr(15, 28 - ((int)(strlen(buf) + 1) / 2), buf);
killer = killname(monst,buf);
mvaddstr(17, 28 - ((int)(strlen(killer) + 1) / 2), killer);
mvaddstr(18, 28, (sprintf(prbuf, "%2d", lt->tm_year), prbuf));
move(ur_lines - 1, 0);
mvaddstr(ur_lines - 1, 0, retstr);
while ((c = readcharw(stdscr)) != '\n' && c != '\r')
continue;
idenpack();
wrefresh(cw);
refresh();
score(pstats.s_exp, pstats.s_lvl, KILLED, monst);
byebye();
}
/*
score()
figure score and post it.
*/
void
score(long amount, int lvl, int flags, int monst) /*ARGSUSED*/
{
struct sc_ent *scp=NULL, *sc2=NULL;
int i;
char *killer;
char buf[1024];
static const char *reason[] =
{
"killed",
"quit",
"a winner",
"a total winner"
};
char *packend;
if (flags != WINNER && flags != TOTAL && flags != SCOREIT)
{
if (flags == CHICKEN)
packend = "when you quit";
else
packend = "at your untimely demise";
noecho();
nl();
refresh();
showpack(packend);
}
/* Open file and read list */
if (fd_score == NULL)
{
printf("No score file opened\n");
return;
}
for (scp = top_ten; scp < &top_ten[10]; scp++)
{
scp->sc_lvl = 0L;
scp->sc_score = 0L;
for (i = 0; i < 76; i++)
scp->sc_name[i] = ucrnd(255);
scp->sc_gold = 0L;
scp->sc_flags = rnd(10);
scp->sc_level = rnd(10);
scp->sc_monster = srnd(10);
scp->sc_artifacts = 0;
}
if (flags != SCOREIT)
{
mvaddstr(ur_lines - 1, 0, retstr);
refresh();
fflush(stdout);
wait_for('\n');
}
fseek(fd_score, 0L, SEEK_SET);
fread(top_ten, sizeof(top_ten), 1, fd_score);
/* Insert player in list if need be */
if (!waswizard)
{
for (scp = top_ten; scp < &top_ten[10]; scp++)
{
if (lvl > scp->sc_lvl)
break;
if (lvl == scp->sc_lvl && amount > scp->sc_score)
break;
}
if (scp < &top_ten[10])
{
if (flags == WINNER)
sc2 = &top_ten[9]; /* LAST WINNER ALWAYS MAKES IT */
while (sc2 > scp)
{
*sc2 = sc2[-1];
sc2--;
}
scp->sc_lvl = lvl;
scp->sc_gold = purse;
scp->sc_score = amount;
strcpy(scp->sc_name, whoami);
strcat(scp->sc_name,", ");
strcat(scp->sc_name, which_class(player.t_ctype));
scp->sc_flags = flags;
if (flags == WINNER)
scp->sc_level = max_level;
else
scp->sc_level = level;
scp->sc_monster = monst;
scp->sc_artifacts = has_artifact;
sc2 = scp;
}
}
if (flags != SCOREIT)
{
clear();
refresh();
endwin();
}
/* Print the list */
printf("\nTop Ten Adventurers:\n%4s %15s %10s %s\n",
"Rank", "Score", "Gold", "Name");
for (scp = top_ten; scp < &top_ten[10]; scp++)
{
if (scp->sc_score)
{
char lev[20];
sprintf(lev, "%ld+%ld", scp->sc_lvl, scp->sc_score);
printf("%4d %15s %10ld %s:", scp - top_ten + 1,
lev,
scp->sc_gold,
scp->sc_name);
if (scp->sc_artifacts)
{
char thangs[80];
int n;
int first = TRUE;
thangs[0] = '\0';
for (n = 0; n <= maxartifact; n++)
{
if (scp->sc_artifacts & (1 << n))
{
if (strlen(thangs))
strcat(thangs, ", ");
if (first)
{
strcat(thangs, "retrieved ");
first = FALSE;
}
if (45 - strlen(thangs) < strlen(arts[n].ar_name))
{
printf("%s\n%32s", thangs," ");
thangs[0] = '\0';
}
strcat(thangs, arts[n].ar_name);
}
}
if (strlen(thangs))
printf("%s,", thangs);
printf("\n%32s"," ");
}
printf("%s on level %d",reason[scp->sc_flags],scp->sc_level);
if (scp->sc_flags == 0)
{
printf(" by \n%32s"," ");
killer = killname(scp->sc_monster, buf);
printf(" %s", killer);
}
putchar('\n');
}
}
if (sc2 != NULL)
{
fseek(fd_score, 0L, SEEK_SET);
/* Update the list file */
fwrite(top_ten, sizeof(top_ten), 1, fd_score);
}
fclose(fd_score);
/*
* delete old autosave file when we win or quit
*/
if (autosave == TRUE && flags != SCOREIT) {
char fname[200];
strcpy(fname, home);
strcat(fname, "rogue.asave");
if (access(fname, F_OK) == -0)
unlink(fname);
}
}
void
total_winner(void)
{
struct linked_list *item;
struct object *obj;
int worth, oldpurse;
char c;
struct linked_list *bag = NULL;
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 \n");
addstr("escaped the Dungeons of Doom alive. You journey home \n");
addstr("and sell all your loot at a great profit.\n");
addstr("The White Council approves the recommendation of\n");
if (player.t_ctype == C_FIGHTER)
addstr("the fighters guild and appoints you Lord Protector\n");
else if (player.t_ctype == C_ASSASIN)
addstr("the assassins guild and appoints you Master Murderer\n");
else if (player.t_ctype == C_NINJA)
addstr("the ninja guild and appoints you Master of the Wind\n");
else if (player.t_ctype == C_ILLUSION)
addstr("the illusionists guild and appoints you Master Wizard\n");
else if (player.t_ctype == C_MAGICIAN)
addstr("the magicians guild and appoints you Master Wizard\n");
else if (player.t_ctype == C_CLERIC)
addstr("the temple priests and appoints you Master of the Flowers\n");
else if (player.t_ctype == C_DRUID)
addstr("the temple priests and appoints you Master of the Flowers\n");
else if (player.t_ctype == C_RANGER)
addstr("the rangers guild and appoints you Master Ranger\n");
else if (player.t_ctype == C_PALADIN)
addstr("the paladins guild and appoints you Master Paladin\n");
else if (player.t_ctype == C_THIEF)
{
addstr("the thieves guild under protest and appoints you\n");
addstr("Master of the Highways\n");
}
addstr("of the Land Between the Mountains.\n");
mvaddstr(ur_lines - 1, 0, spacemsg);
refresh();
wait_for(' ');
clear();
idenpack();
oldpurse = purse;
mvaddstr(0, 0, " Worth Item");
for (c = 'a', item = pack; item != NULL; c++, item = next(item))
{
obj = OBJPTR(item);
worth = get_worth(obj);
purse += worth;
if (obj->o_type == ARTIFACT && obj->o_which == TR_PURSE)
bag = obj->o_bag;
mvprintw(c - 'a' + 1, 0, "%c) %8d %s", c,
worth, inv_name(obj, UPPERCASE));
}
if (bag != NULL)
{
mvaddstr(ur_lines - 1, 0, morestr);
refresh();
wait_for(' ');
clear();
mvprintw(0, 0, "Contents of the Magic Purse of Yendor:\n");
for (c = 'a', item = bag; item != NULL; c++, item = next(item))
{
obj = OBJPTR(item);
worth = get_worth(obj);
whatis(item);
purse += worth;
mvprintw(c - 'a' + 1, 0, "%c) %8d %s\n", c,
worth, inv_name(obj, UPPERCASE));
}
}
mvprintw(c - 'a' + 1, 0, " %6d Gold Pieces ", oldpurse);
refresh();
if (has_artifact == 255)
score(pstats.s_exp, pstats.s_lvl, TOTAL, 0);
else
score(pstats.s_exp, pstats.s_lvl, WINNER, 0);
byebye();
}
char *
killname(int monst, char *buf)
{
if (buf == NULL)
return("A bug in UltraRogue #102");
if (monst >= 0)
{
switch (monsters[monst].m_name[0])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
sprintf(buf, "an %s", monsters[monst].m_name);
break;
default:
sprintf(buf, "a %s", monsters[monst].m_name);
}
return(buf);
}
else
switch(monst)
{
case D_ARROW:
strcpy(buf, "an arrow"); break;
case D_DART:
strcpy(buf, "a dart"); break;
case D_BOLT:
strcpy(buf, "a bolt"); break;
case D_POISON:
strcpy(buf, "poison"); break;
case D_POTION:
strcpy(buf, "a cursed potion"); break;
case D_PETRIFY:
strcpy(buf, "petrification"); break;
case D_SUFFOCATION:
strcpy(buf, "suffocation"); break;
case D_INFESTATION:
strcpy(buf, "a parasite"); break;
case D_DROWN:
strcpy(buf, "drowning"); break;
case D_FALL:
strcpy(buf, "falling"); break;
case D_FIRE:
strcpy(buf, "slow boiling in oil"); break;
case D_SPELLFUMBLE:
strcpy(buf, "a botched spell"); break;
case D_DRAINLIFE:
strcpy(buf, "a drain life spell"); break;
case D_ARTIFACT:
strcpy(buf, "an artifact of the gods"); break;
case D_GODWRATH:
strcpy(buf, "divine retribution"); break;
case D_CLUMSY:
strcpy(buf, "excessive clumsyness"); break;
default:
strcpy(buf, "stupidity"); break;
}
return(buf);
}
/*
showpack()
Display the contents of the hero's pack
*/
void
showpack(char *howso)
{
char *iname;
unsigned int worth;
int cnt, ch, oldpurse;
struct linked_list *item;
struct object *obj;
struct linked_list *bag = NULL;
cnt = 1;
clear();
mvprintw(0, 0, "Contents of your pack %s:\n", howso);
ch = 0;
oldpurse = purse;
purse = 0;
for (item = pack; item != NULL; item = next(item))
{
obj = OBJPTR(item);
worth = get_worth(obj);
whatis(item);
purse += worth;
if (obj->o_type == ARTIFACT && obj->o_which == TR_PURSE)
bag = obj->o_bag;
iname = inv_name(obj, UPPERCASE);
mvprintw(cnt, 0, "%d) %s\n", ch, iname);
ch += 1;
if (++cnt > ur_lines - 5 && next(item) != NULL)
{
cnt = 1;
mvaddstr(ur_lines - 1, 0, morestr);
refresh();
wait_for(' ');
clear();
}
}
if (bag != NULL)
{
mvaddstr(ur_lines - 1, 0, morestr);
refresh();
wait_for(' ');
clear();
cnt = 1;
ch = 0;
mvprintw(0, 0, "Contents of the Magic Purse of Yendor %s:\n", howso);
for (item = bag; item != NULL; item = next(item))
{
obj = OBJPTR(item);
worth = get_worth(obj);
whatis(item);
purse += worth;
mvprintw(cnt, 0, "%d) %s\n", ch, inv_name(obj, UPPERCASE));
ch += 1;
if (++cnt > ur_lines - 5 && next(item) != NULL)
{
cnt = 1;
mvaddstr(ur_lines - 1, 0, morestr);
refresh();
wait_for(' ');
clear();
}
}
}
mvprintw(cnt + 1, 0, "Carrying %d gold pieces", oldpurse);
mvprintw(cnt + 2, 0, "Carrying objects worth %d gold pieces", purse);
purse += oldpurse;
refresh();
}
void
byebye(void)
{
endwin();
printf("\n");
exit(0);
}
/*
save_resurrect()
chance of resurrection according to modifed D&D probabilities
*/
int
save_resurrect(int bonus)
{
int need, adjust;
adjust = pstats.s_const + bonus - luck;
if (adjust > 17)
return(TRUE);
else if (adjust < 14)
need = 5 * (adjust + 5);
else
need = 90 + 2 * (adjust - 13);
return(roll(1, 100) < need);
}