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