-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdungeon_obj.c
799 lines (723 loc) · 19 KB
/
dungeon_obj.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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/* =============================================================================
* PROGRAM: ularn
* FILENAME: dungeon_obj.c
*
* DESCRIPTION:
* This module contains functions for handling the effects of static objects
* in the dungeon.
* (ie. Objects that cannot be picked up such as stairs, fountains etc.)
*
* =============================================================================
* EXPORTED VARIABLES
*
* None
*
* =============================================================================
* EXPORTED FUNCTIONS
*
* oopendoor - processes the player opening a closed door
* oaltar - processes player stepping onto an alter
* othrone - processes player stepping onto a throne
* odeadthrone - processes player stepping onto a dead throne
* ofountain - processes player stepping onto a fountain
* ostairs - processes player stepping onto the stairs (up or down)
* oteleport - processes player stepping onto a teleport trap, and all other
* reasons for teleporting the player
* opit - processes player stepping onto a pit
* oelevator - processes player stepping onto an elevator
* ostatue - processes player stepping onto a statue
* omirror - processes player stepping onto a mirror
*
* =============================================================================
*/
#include "dungeon_obj.h"
#include "header.h"
#include "itm.h"
#include "monster.h"
#include "player.h"
#include "potion.h"
#include "scores.h"
#include "ularn_game.h"
#include "ularn_win.h"
/* =============================================================================
* Local functions
*/
/* =============================================================================
* FUNCTION: ohear
*
* DESCRIPTION:
* Function to cast a +3 protection on the player from an altar.
*
* PARAMETERS:
*
* None.
*
* RETURN VALUE:
*
* None.
*/
static void ohear(void) {
Print("\nYou have been heard!");
if (c[ALTPRO] == 0)
c[MOREDEFENSES] += ALTAR_PRO_BOOST;
c[ALTPRO] += 800; /* protection field */
recalc();
UpdateEffects();
}
/* =============================================================================
* FUNCTION: fch
*
* DESCRIPTION:
* Changes a players ability by 1 for ofountain effects.
*
* PARAMETERS:
*
* how : The direction the attribute is to be changed.
* x < 0 => down
* x > 0 => up
*
* x : A pointer to the attribute value to change.
*
* RETURN VALUE:
*
* None.
*/
static void fch(int how, long *x) {
if (how < 0) {
if (*x > 3) {
Print(" went down by one!");
--(*x);
} else
Print(" remained unchanged!");
} else {
Print(" went up by one!");
(*x)++;
}
UpdateStatus();
}
/* =============================================================================
* FUNCTION: fntchange
*
* DESCRIPTION:
* Function to change player attributes for fountain based effects.
*
* PARAMETERS:
*
* how : The size and direction of the change.
* how > 0 => raised
* how < 0 => lowered
*
* RETURN VALUE:
*
* None.
*/
static void fntchange(int how) {
long j;
Printc('\n');
switch (rnd(9)) {
case 1:
Print("Your strength");
fch(how, &c[STRENGTH]);
break;
case 2:
Print("Your intelligence");
fch(how, &c[INTELLIGENCE]);
break;
case 3:
Print("Your wisdom");
fch(how, &c[WISDOM]);
break;
case 4:
Print("Your constitution");
fch(how, &c[CONSTITUTION]);
break;
case 5:
Print("Your dexterity");
fch(how, &c[DEXTERITY]);
break;
case 6:
Print("Your charm");
fch(how, &c[CHARISMA]);
break;
case 7:
j = rnd(level + 1);
if (how < 0) {
Printf("You lose %d hit point%s!", (long)j, plural(j));
losemhp((int)j);
} else {
Printf("You gain %d hit point%s!", (long)j, plural(j));
raisemhp((int)j);
}
UpdateStatus();
break;
case 8:
j = rnd(level + 1);
if (how > 0) {
Printf("You just gained %d spell%s!", (long)j, plural(j));
raisemspells((int)j);
} else {
Printf("You just lost %d spell%s!", (long)j, plural(j));
losemspells((int)j);
}
UpdateStatus();
break;
case 9:
j = 5 * rnd((level + 1) * (level + 1));
if (how < 0) {
Printf("You just lost %d experience point%s!", (long)j, plural(j));
loseexperience((long)j);
} else {
Printf("You just gained %d experience point%s!", (long)j, plural(j));
raiseexperience((long)j);
}
break;
}
}
/* =============================================================================
* FUNCTION: obottomless
*
* DESCRIPTION:
* Processes the player falling into a bottomless pit.
*
* PARAMETERS:
*
* None.
*
* RETURN VALUE:
*
* None.
*/
static void obottomless(void) {
Print("\nYou fell into a pit leading straight to HELL!");
UlarnBeep();
nap(3000);
died(DIED_FELL_INTO_BOTTOMLESS_PIT, 0);
}
/* =============================================================================
* Exported functions
*/
/* =============================================================================
* FUNCTION: oopendoor
*/
void oopendoor(int x, int y) {
if (item[x][y] != OCLOSEDDOOR)
return;
if (rnd(11) < 7) {
/*
* Failed to open the door
* See if something nasty happened instead
*/
switch (iarg[x][y]) {
case 6:
c[AGGRAVATE] += rnd(400);
break;
case 7:
case 8:
Print("\nYou are jolted by an electric shock!");
losehp(DIED_ELECTRIC_SHOCK, rnd(20));
UpdateStatus();
break;
case 9:
Print("\nYou suddenly feel weaker!");
if (c[STRENGTH] > 3)
c[STRENGTH]--;
UpdateStatus();
break;
default:
break;
}
/* Now the trap has been triggered, clear the trap */
iarg[x][y] = 0;
} else {
item[x][y] = OOPENDOOR;
show1cell(x, y);
}
}
/* =============================================================================
* FUNCTION: oaltar
*/
void oaltar(void) {
long k;
int p;
int ans;
int redo;
do {
redo = 0;
ans = get_prompt_input(
"\nDo you (p) pray (d) desecrate, or (i) ignore it? ", "pdi\033", 1);
switch (ans) {
case 'p':
Print(" pray");
ans = get_prompt_input("\nDo you (m) give money or (j) just pray? ", "mj",
1);
switch (ans) {
case 'j':
p = rund(100);
if (p < 12)
createmonster(makemonst(level + 2));
else if (p < 17)
enchweapon(ENCH_ALTAR);
else if (p < 22)
enchantarmor(ENCH_ALTAR);
else if (p < 27)
ohear();
else
Print("\nNothing happens.");
break;
case 'm':
Print("\nHow much do you donate? ");
k = get_num_input(c[GOLD]);
if (k < 0)
redo = 1;
else if (c[GOLD] < k) {
Print(" You don't have that much!");
nap(1001);
redo = 1;
} else {
/*
* Remove gold from player
*/
c[GOLD] -= k;
if ((k < (c[GOLD] / 10)) && (rnd(60) < 30) && !wizard) {
/*
* Player offers < 1/11% of gold insults the gods 50% of the time.
* Insulted gods send a demon prince to punish the player.
*/
Print(
" Cheapskate! The Gods are insulted by such a tiny offering!");
forget();
createmonster(DEMONPRINCE);
c[AGGRAVATE] += 1500;
/* God takes more gold anyway */
c[GOLD] -= k;
} else if (((k < (c[GOLD] + k) / 10) || (k < rnd(50))) && !wizard) {
/*
* Player offers more than 1/11, but less than 1/10 of gold.
* God has a chance of sending a monster to encourage the player
* to be more generous based on how far below 50 gold the
* amount doneted is.
*/
createmonster(makemonst(level + 2));
c[AGGRAVATE] += 500;
/* God takes more gold anyway */
c[GOLD] -= k;
} else {
/*
* Player was reasonably generous, so give a blessing
*/
p = rund(16);
if (p < 4)
Print(" Thank you.");
else if (p < 6) {
enchantarmor(ENCH_ALTAR);
enchantarmor(ENCH_ALTAR);
} else if (p < 8) {
enchweapon(ENCH_ALTAR);
enchweapon(ENCH_ALTAR);
} else
ohear();
}
UpdateStatus();
}
break;
default:
break;
} /* end while switch : case j or m */
break;
case 'd':
Print(" desecrate");
if (rnd(100) < 60) {
createmonster(makemonst(level + 3) + 8);
c[AGGRAVATE] += 2500;
} else if (rnd(100) < 5)
raiselevel();
else if (rnd(101) < 30) {
Print("\nThe altar crumbles into a pile of dust before your eyes.");
forget();
} else
Print("\nNothing happens.");
UpdateStatus();
break;
case 'i':
case ESC:
Print(" ignore");
if (rnd(100) < 30) {
createmonster(makemonst(level + 2));
c[AGGRAVATE] += rnd(450);
} else {
Print("\nNothing happens.");
nomove = 1; /* XXX trn */
}
break;
} /* end while switch: pray, des, ignore */
} while (redo);
}
/* =============================================================================
* FUNCTION: othrone
*/
void othrone(int arg) {
int i, k;
int ans;
ans = get_prompt_input(
"\nDo you (p) pry off jewels, (s) sit down, or (i) ignore it? ",
"psi\033", 1);
switch (ans) {
case 'p':
Print(" pry off");
k = rnd(101);
if (k < 25) {
for (i = 0; i < rnd(4); i++) {
creategem(); /*gems pop off the throne*/
}
item[playerx][playery] = ODEADTHRONE;
} else if ((k < 40) && (arg == 0)) {
createmonster(GNOMEKING);
item[playerx][playery] = OTHRONE2;
} else
Print("\nNothing happens.");
break;
case 's':
Print(" sit down");
k = rnd(101);
if ((k < 30) && (arg == 0)) {
createmonster(GNOMEKING);
item[playerx][playery] = OTHRONE2;
} else if (k < 35) {
Print("\nZaaaappp! You've been teleported!\n");
UlarnBeep();
oteleport(0);
} else
Print("\nNothing happens.");
break;
case 'i':
case ESC:
Print(" ignore");
break;
;
}
}
/* =============================================================================
* FUNCTION: odeadthrone
*/
void odeadthrone(void) {
int k;
int ans;
ans = get_prompt_input("\nDo you (s) sit down, or (i) ignore it? ", "si\033",
1);
switch (ans) {
case 's':
Print(" sit down");
k = rnd(101);
if (k < 5)
raiselevel();
else if (k < 25) {
Print("\nZaaaappp! You've been teleported!\n");
UlarnBeep();
oteleport(0);
} else
Print("\nNothing happens.");
break;
case 'i':
case ESC:
Print(" ignore");
;
break;
}
}
/* =============================================================================
* FUNCTION: ofountain
*/
void ofountain(void) {
int x;
int ans;
ans = get_prompt_input(
"\nDo you (d) drink, (w) wash yourself, or (i) ignore it? ", "dwi\033",
1);
switch (ans) {
case 'd':
Print("drink");
if (rnd(1501) < 4) {
Print("\nOH MY GOD!! You have caught the *dreadful sleep*!");
UlarnBeep();
nap(3000);
died(DIED_DREADFUL_SLEEP, 0);
return;
} else {
x = rnd(100);
if (x == 1)
raiselevel();
else if (x < 11) {
x = rnd((level << 2) + 2);
Printf("\nBleah! The water tasted like stale gatorade! You lose %d "
"hit point%s!",
(long)x, plural(x));
losehp(DIED_DRANK_POISONOUS_WATER, x);
UpdateStatus();
} else if (x < 14) {
c[HALFDAM] += 200 + rnd(200);
Print("\nThe water makes you vomit.");
} else if (x < 17) {
/* Same effect as giant strength */
Print("\n You now have incredible bulging muscles!");
if (c[GIANTSTR] == 0)
c[STREXTRA] += PGIANTSTR_BOOST;
c[GIANTSTR] += 700;
UpdateEffects();
} else if (x < 45)
Print("\nNothing seems to have happened.");
else if (rnd(3) != 2) {
fntchange(1); /*change char levels upward*/
} else {
fntchange(-1); /*change char levels downward*/
}
if (rnd(12) < 3) {
Print("\nThe fountains bubbling slowly quietens.");
/* dead fountain */
item[playerx][playery] = ODEADFOUNTAIN;
}
}
break;
case 'i':
case ESC:
Print(" ignore");
break;
case 'w':
Print("wash yourself.");
if (rnd(100) < 11) {
x = rnd((level << 2) + 2);
Printf("\nThe water burns like acid! You lose %d hit point%s!", (long)x,
plural(x));
losehp(DIED_DRANK_POISONOUS_WATER, x);
UpdateStatus();
} else if (rnd(100) < 29) {
Print("\nYou are now clean.");
if (c[ITCHING])
/*
* Managed to get rid of the itching powder, so set it so the
* next call to regen will cancel the effect.
*/
c[ITCHING] = 1;
} else if (rnd(100) < 31)
Print("\nThis water needs soap -- the dirt didn't come off.");
else if (rnd(100) < 34)
createmonster(WATERLORD);
else
Print("\nNothing seems to have happened.");
break;
}
}
/* =============================================================================
* FUNCTION: ostairs
*/
void ostairs(int dir) {
int x, y;
int ans;
Print("\nDo you (s) stay here or ");
if (dir > 0)
Print("(u) go up? ");
else
Print("(d) go down? ");
ans = get_prompt_input("", "sudi\033", 1);
switch (ans) {
case ESC:
case 's':
case 'i':
Print("stay here.");
return;
case 'u':
Print("go up.");
if (dir < 0)
Print("\nThe stairs don't go up!");
else {
/* not on V1 */
if ((level >= 2) && (level != (DBOTTOM + 1))) {
newcavelevel(level - 1);
for (x = 0; x < MAXX; x++) {
for (y = 0; y < MAXY; y++) {
if (item[x][y] == OSTAIRSDOWN) {
playerx = (char)x;
playery = (char)y;
x = MAXX;
y = MAXY;
}
}
}
if (mitem[playerx][playery].mon != MONST_NONE)
/*
* A monster is on the stairs, so find an empty position for the
* player.
*/
positionplayer();
draws(0, MAXX, 0, MAXY);
UpdateStatusAndEffects();
} else
Print("\nThe stairs lead to a dead end!");
}
break;
case 'd':
Print("go down.");
if (dir > 0)
Print("\nThe stairs don't go down!");
else {
/* not on dungeon bottom or V5 */
if ((level != 0) && (level != DBOTTOM) && (level != VBOTTOM)) {
newcavelevel(level + 1);
for (x = 0; x < MAXX; x++) {
for (y = 0; y < MAXY; y++) {
if (item[x][y] == OSTAIRSUP) {
playerx = (char)x;
playery = (char)y;
x = MAXX;
y = MAXY;
}
}
}
if (mitem[playerx][playery].mon != MONST_NONE)
/*
* A monster is on the stairs, so find an empty position for the
* player.
*/
positionplayer();
draws(0, MAXX, 0, MAXY);
UpdateStatusAndEffects();
} else
Print("\nThe stairs lead to a dead end!");
}
break;
default:
break;
}
}
/* =============================================================================
* FUNCTION: oteleport
*/
void oteleport(int err) {
int tmp;
if (err) {
if (rnd(151) < 3) {
/* stuck in a rock if the player can't walk through walls */
if (c[WTW] == 0) {
died(DIED_TRAPPED_IN_SOLID_ROCK, 0);
return;
}
}
}
/* show ?? on bottomline if been teleported */
if (!wizard)
c[TELEFLAG] = 1;
if (level == 0)
tmp = 0;
else if (level <= DBOTTOM) {
/* in dungeon */
tmp = rnd(5) + level - 3;
if (tmp > DBOTTOM)
tmp = DBOTTOM;
if (tmp < 0)
tmp = 0;
} else {
/* in volcano */
tmp = rnd(4) + level - 2;
if (tmp >= VBOTTOM)
tmp = VBOTTOM;
if (tmp < DBOTTOM + 1)
/* back to surface */
tmp = 0;
}
playerx = (char)rnd(MAXX - 2);
playery = (char)rnd(MAXY - 2);
if (level != tmp)
newcavelevel(tmp);
else
positionplayer();
draws(0, MAXX, 0, MAXY);
UpdateStatusAndEffects();
}
/* =============================================================================
* FUNCTION: opit
*/
void opit(void) {
int i;
if (rnd(101) > 81)
return;
if ((rnd(70) > (9 * c[DEXTERITY] - packweight())) || (rnd(101) < 5)) {
/* Never fall into a pit if the player has a wand of wonder */
if (player_has_item(OWWAND)) {
Print("\nYou float right over the pit.");
return;
}
if (level == DBOTTOM || level == VBOTTOM)
/* Pits on the bottom of the dungeon or volcano are bottomless */
obottomless();
else {
if (rnd(101) < 20) {
i = 0;
Print("\nYou fell ino a pit! A poor monster cushions your fall!\n");
} else {
i = rnd(level * 3 + 3);
if (i > c[HP])
i = c[HP];
Printf("\nYou fell into a pit! You suffer %d hit point%s damage.",
(long)i, plural(i));
}
losehp(DIED_FELL_INTO_PIT, i);
nap(2000);
newcavelevel(level + 1);
draws(0, MAXX, 0, MAXY);
}
}
}
/* =============================================================================
* FUNCTION: oelevator
*/
void oelevator(int dir) {
int new_level;
if (dir == 1) {
/* going up */
if (level == 0) {
Print(",\nunfortunately, it is out of order.");
return;
}
playerx = (char)rnd(MAXX - 2);
playery = (char)rnd(MAXY - 2);
nap(2000);
if (level <= DBOTTOM)
/* In dungeon */
newcavelevel(rund(level));
else {
/* In volcano */
new_level = DBOTTOM + rund(level - DBOTTOM);
if (new_level == DBOTTOM)
new_level = 0;
newcavelevel(new_level);
}
} else {
/* going down */
if ((level == DBOTTOM) || (level == VBOTTOM)) {
nap(2000);
Print("\nand it leads straight to HELL!");
UlarnBeep();
nap(3000);
died(DIED_ELEVATOR_TO_HELL, 0);
return;
}
playerx = (char)rnd(MAXX - 2);
playery = (char)rnd(MAXY - 2);
nap(2000);
if (level < DBOTTOM)
/* In dungeon */
newcavelevel(level + rnd(DBOTTOM - level));
else
/* in volcano */
newcavelevel(level + rnd(VBOTTOM - level));
}
draws(0, MAXX, 0, MAXY);
UpdateStatusAndEffects();
}
/* =============================================================================
* FUNCTION: ostatue
*/
void ostatue(void) {} /* nothing happens when you move on a statue */
/* =============================================================================
* FUNCTION: omirror
*/
void omirror(void) {} /* nothing happens when you move on a mirror */