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