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