sh: Add simple tests for set -x and PS4.
[dragonfly.git] / games / larn / moreobj.c
1 /* moreobj.c            Larn is copyrighted 1986 by Noah Morgan.
2  * $FreeBSD: src/games/larn/moreobj.c,v 1.4 1999/11/16 02:57:22 billf Exp $
3  * $DragonFly: src/games/larn/moreobj.c,v 1.3 2006/08/26 17:05:05 pavalos Exp $
4  *
5  *      Routines in this file:
6  *
7  *      oaltar()
8  *      othrone()
9  *      ochest()
10  *      ofountain()
11  */
12 #include "header.h"
13
14 static void ohear(void);
15 static void fch(int, long *);
16 static void fntchange(int);
17
18 /*
19  *      subroutine to process an altar object
20  */
21 void
22 oaltar(void)
23 {
24         unsigned long k;
25
26         lprcat("\nDo you (p) pray  (d) desecrate");
27         iopts();
28         while (1) {
29                 while (1)
30                         switch (getchr()) {
31                         case 'p':
32                                 lprcat(" pray\nDo you (m) give money or (j) just pray? ");
33                                 while (1)
34                                         switch (getchr()) {
35                                         case 'j':
36                                                 if (rnd(100) < 75)
37                                                         lprcat("\nnothing happens");
38                                                 else if (rnd(13) < 4)
39                                                         ohear();
40                                                 else if (rnd(43) == 10) {
41                                                         if (c[WEAR])
42                                                                 lprcat("\nYou feel your armor vibrate for a moment");
43                                                         enchantarmor();
44                                                         return;
45                                                 } else if (rnd(43) == 10) {
46                                                         if (c[WIELD])
47                                                                 lprcat("\nYou feel your weapon vibrate for a moment");
48                                                         enchweapon();
49                                                         return;
50                                                 } else
51                                                         createmonster(makemonst(level + 1));
52                                                 return;
53
54                                         case 'm':
55                                                 lprcat("\n\n");
56                                                 cursor(1, 24);
57                                                 cltoeoln();
58                                                 cursor(1, 23);
59                                                 cltoeoln();
60                                                 lprcat("how much do you donate? ");
61                                                 k = readnum((long)c[GOLD]);
62                                                 if (c[GOLD] < (long)k) {
63                                                         lprcat("\nYou don't have that much!");
64                                                         return;
65                                                 }
66                                                 c[GOLD] -= k;
67                                                 if ((long)k < c[GOLD] / 10 || (long)k < rnd(50)) {
68                                                         createmonster(makemonst(level + 1));
69                                                         c[AGGRAVATE] += 200;
70                                                 } else if (rnd(101) > 50) {
71                                                         ohear();
72                                                         return;
73                                                 } else if (rnd(43) == 5) {
74                                                         if (c[WEAR])
75                                                                 lprcat("\nYou feel your armor vibrate for a moment");
76                                                         enchantarmor();
77                                                         return;
78                                                 } else if (rnd(43) == 8) {
79                                                         if (c[WIELD])
80                                                                 lprcat("\nYou feel your weapon vibrate for a moment");
81                                                         enchweapon();
82                                                         return;
83                                                 } else
84                                                         lprcat("\nThank You.");
85                                                 bottomline();
86                                                 return;
87
88                                         case '\33':
89                                                 return;
90                                         }
91
92                         case 'd':
93                                 lprcat(" desecrate");
94                                 if (rnd(100) < 60) {
95                                         createmonster(makemonst(level + 2) + 8);
96                                         c[AGGRAVATE] += 2500;
97                                 } else if (rnd(101) < 30) {
98                                         lprcat("\nThe altar crumbles into a pile of dust before your eyes");
99                                         forget();               /* remember to destroy the altar */
100                                 } else
101                                         lprcat("\nnothing happens");
102                                 return;
103
104                         case 'i':
105                         case '\33':
106                                 ignore();
107                                 if (rnd(100) < 30) {
108                                         createmonster(makemonst(level + 1));
109                                         c[AGGRAVATE] += rnd(450);
110                                 } else
111                                         lprcat("\nnothing happens");
112                                 return;
113                         }
114         }
115 }
116
117 /*
118         function to cast a +3 protection on the player
119  */
120 static void
121 ohear(void)
122 {
123         lprcat("\nYou have been heard!");
124         if (c[ALTPRO] == 0)
125                 c[MOREDEFENSES] += 3;
126         c[ALTPRO] += 500;       /* protection field */
127         bottomline();
128 }
129
130 /*
131         subroutine to process a throne object
132  */
133 void
134 othrone(int arg)
135 {
136         int i, k;
137
138         lprcat("\nDo you (p) pry off jewels, (s) sit down");
139         iopts();
140         while (1) {
141                 while (1)
142                         switch (getchr()) {
143                         case 'p':
144                                 lprcat(" pry off");
145                                 k = rnd(101);
146                                 if (k < 25) {
147                                         for (i = 0; i < rnd(4); i++)
148                                                 creategem();    /* gems pop off the throne */
149                                         item[playerx][playery] = ODEADTHRONE;
150                                         know[playerx][playery] = 0;
151                                 } else if (k < 40 && arg == 0) {
152                                         createmonster(GNOMEKING);
153                                         item[playerx][playery] = OTHRONE2;
154                                         know[playerx][playery] = 0;
155                                 } else
156                                         lprcat("\nnothing happens");
157                                 return;
158
159                         case 's':
160                                 lprcat(" sit down");
161                                 k = rnd(101);
162                                 if (k < 30 && arg == 0) {
163                                         createmonster(GNOMEKING);
164                                         item[playerx][playery] = OTHRONE2;
165                                         know[playerx][playery] = 0;
166                                 } else if (k < 35)             {
167                                         lprcat("\nZaaaappp!  You've been teleported!\n");
168                                         beep();
169                                         oteleport(0);
170                                 } else
171                                         lprcat("\nnothing happens");
172                                 return;
173
174                         case 'i':
175                         case '\33':
176                                 ignore();
177                                 return;
178                         }
179         }
180 }
181
182 void
183 odeadthrone(void)
184 {
185         int k;
186
187         lprcat("\nDo you (s) sit down");
188         iopts();
189         while (1) {
190                 while (1)
191                         switch (getchr()) {
192                         case 's':
193                                 lprcat(" sit down");
194                                 k = rnd(101);
195                                 if (k < 35) {
196                                         lprcat("\nZaaaappp!  You've been teleported!\n");
197                                         beep();
198                                         oteleport(0);
199                                 } else
200                                         lprcat("\nnothing happens");
201                                 return;
202
203                         case 'i':
204                         case '\33':
205                                 ignore();
206                                 return;
207                         }
208         }
209 }
210
211 /*
212         subroutine to process a throne object
213  */
214 void
215 ochest(void)
216 {
217         int i, k;
218         lprcat("\nDo you (t) take it, (o) try to open it");
219         iopts();
220         while (1) {
221                 while (1)
222                         switch (getchr()) {
223                         case 'o':
224                                 lprcat(" open it");
225                                 k = rnd(101);
226                                 if (k < 40) {
227                                         lprcat("\nThe chest explodes as you open it");
228                                         beep();
229                                         i = rnd(10);
230                                         lastnum = 281;          /* in case he dies */
231                                         lprintf("\nYou suffer %d hit points damage!", (long)i);
232                                         checkloss(i);
233                                         switch (rnd(10)) {      /* see if he gets a curse */
234                                         case 1:
235                                                 c[ITCHING] += rnd(1000) + 100;
236                                                 lprcat("\nYou feel an irritation spread over your skin!");
237                                                 beep();
238                                                 break;
239
240                                         case 2:
241                                                 c[CLUMSINESS] += rnd(1600) + 200;
242                                                 lprcat("\nYou begin to lose hand to eye coordination!");
243                                                 beep();
244                                                 break;
245
246                                         case 3:
247                                                 c[HALFDAM] += rnd(1600) + 200;
248                                                 beep();
249                                                 lprcat("\nA sickness engulfs you!");
250                                                 break;
251                                         }
252                                         item[playerx][playery] = know[playerx][playery] = 0;
253                                         if (rnd(100) < 69)
254                                                 creategem();    /* gems from the chest */
255                                         dropgold(rnd(110 * iarg[playerx][playery] + 200));
256                                         for (i = 0; i < rnd(4); i++)
257                                                 something(iarg[playerx][playery] + 2);
258                                 } else
259                                         lprcat("\nnothing happens");
260                                 return;
261
262                         case 't':
263                                 lprcat(" take");
264                                 if (take(OCHEST, iarg[playerx][playery]) == 0)
265                                         item[playerx][playery] = know[playerx][playery] = 0;
266                                 return;
267
268                         case 'i':
269                         case '\33':
270                                 ignore();
271                                 return;
272                         }
273         }
274 }
275
276 /*
277         process a fountain object
278  */
279 void
280 ofountain(void)
281 {
282         int x;
283         cursors();
284         lprcat("\nDo you (d) drink, (w) wash yourself");
285         iopts();
286         while (1)
287                 switch (getchr()) {
288                 case 'd':
289                         lprcat("drink");
290                         if (rnd(1501) < 2) {
291                                 lprcat("\nOops!  You seem to have caught the dreadful sleep!");
292                                 beep();
293                                 lflush();
294                                 sleep(3);
295                                 died(280);
296                                 return;
297                         }
298                         x = rnd(100);
299                         if (x < 7) {
300                                 c[HALFDAM] += 200 + rnd(200);
301                                 lprcat("\nYou feel a sickness coming on");
302                         } else if (x < 13)
303                                 quaffpotion(23);        /* see invisible */
304                         else if (x < 45)
305                                 lprcat("\nnothing seems to have happened");
306                         else if (rnd(3) != 2)
307                                 fntchange(1);           /* change char levels upward */
308                         else
309                                 fntchange(-1);          /* change char levels downward */
310                         if (rnd(12) < 3) {
311                                 lprcat("\nThe fountains bubbling slowly quiets");
312                                 item[playerx][playery] = ODEADFOUNTAIN; /* dead fountain */
313                                 know[playerx][playery] = 0;
314                         }
315                         return;
316
317                 case '\33':
318                 case 'i':
319                         ignore();
320                         return;
321
322                 case 'w':
323                         lprcat("wash yourself");
324                         if (rnd(100) < 11) {
325                                 x = rnd((level << 2) + 2);
326                                 lprintf("\nOh no!  The water was foul!  You suffer %d hit points!", (long)x);
327                                 lastnum = 273;
328                                 losehp(x);
329                                 bottomline();
330                                 cursors();
331                         } else if (rnd(100) < 29)
332                                 lprcat("\nYou got the dirt off!");
333                         else if (rnd(100) < 31)
334                                 lprcat("\nThis water seems to be hard water!  The dirt didn't come off!");
335                         else if (rnd(100) < 34)
336                                 createmonster(WATERLORD);       /* make water lord */
337                         else
338                                 lprcat("\nnothing seems to have happened");
339                         return;
340                 }
341 }
342
343 /*
344         ***
345         FCH
346         ***
347
348         subroutine to process an up/down of a character attribute for ofountain
349  */
350 static void
351 fch(int how, long *x)
352 {
353         if (how < 0) {
354                 lprcat(" went down by one!");
355                 --(*x);
356         } else {
357                 lprcat(" went up by one!");
358                 (*x)++;
359         }
360         bottomline();
361 }
362
363 /*
364         a subroutine to raise or lower character levels
365         if x > 0 they are raised   if x < 0 they are lowered
366  */
367 static void
368 fntchange(int how)
369 {
370         long j;
371         lprc('\n');
372         switch (rnd(9)) {
373         case 1:
374                 lprcat("Your strength");
375                 fch(how, &c[0]);
376                 break;
377         case 2:
378                 lprcat("Your intelligence");
379                 fch(how, &c[1]);
380                 break;
381         case 3:
382                 lprcat("Your wisdom");
383                 fch(how, &c[2]);
384                 break;
385         case 4:
386                 lprcat("Your constitution");
387                 fch(how, &c[3]);
388                 break;
389         case 5:
390                 lprcat("Your dexterity");
391                 fch(how, &c[4]);
392                 break;
393         case 6:
394                 lprcat("Your charm");
395                 fch(how, &c[5]);
396                 break;
397         case 7:
398                 j = rnd(level + 1);
399                 if (how < 0) {
400                         lprintf("You lose %d hit point", (long)j);
401                         if (j > 1)
402                                 lprcat("s!");
403                         else
404                                 lprc('!');
405                         losemhp((int)j);
406                 } else {
407                         lprintf("You gain %d hit point", (long)j);
408                         if (j > 1)
409                                 lprcat("s!");
410                         else
411                                 lprc('!');
412                         raisemhp((int)j);
413                 }
414                 bottomline();
415                 break;
416
417         case 8:
418                 j = rnd(level + 1);
419                 if (how > 0) {
420                         lprintf("You just gained %d spell", (long)j);
421                         raisemspells((int)j);
422                         if (j > 1)
423                                 lprcat("s!");
424                         else
425                                 lprc('!');
426                 } else {
427                         lprintf("You just lost %d spell", (long)j);
428                         losemspells((int)j);
429                         if (j > 1)
430                                 lprcat("s!");
431                         else
432                                 lprc('!');
433                 }
434                 bottomline();
435                 break;
436
437         case 9:
438                 j = 5 * rnd((level + 1) * (level + 1));
439                 if (how < 0) {
440                         lprintf("You just lost %d experience point", (long)j);
441                         if (j > 1)
442                                 lprcat("s!");
443                         else
444                                 lprc('!');
445                         loseexperience((long)j);
446                 } else {
447                         lprintf("You just gained %d experience point", (long)j);
448                         if (j > 1)
449                                 lprcat("s!");
450                         else
451                                 lprc('!');
452                         raiseexperience((long)j);
453                 }
454                 break;
455         }
456         cursors();
457 }