xref: /netbsd-src/games/larn/moreobj.c (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: moreobj.c,v 1.11 2008/02/19 06:05:26 dholland Exp $	*/
2 
3 /*
4  * moreobj.c 		Larn is copyrighted 1986 by Noah Morgan.
5  *
6  * Routines in this file:
7  *
8  * oaltar() othrone() ochest() ofountain()
9  */
10 #include <sys/cdefs.h>
11 #ifndef lint
12 __RCSID("$NetBSD: moreobj.c,v 1.11 2008/02/19 06:05:26 dholland Exp $");
13 #endif				/* not lint */
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include "header.h"
17 #include "extern.h"
18 
19 static void fch(int, long *);
20 
21 /*
22  *	subroutine to process an altar object
23  */
24 void
25 oaltar()
26 {
27 
28 	lprcat("\nDo you (p) pray  (d) desecrate");
29 	iopts();
30 	while (1) {
31 		while (1)
32 			switch (ttgetch()) {
33 			case 'p':
34 				lprcat(" pray\nDo you (m) give money or (j) just pray? ");
35 				while (1)
36 					switch (ttgetch()) {
37 					case 'j':
38 						act_just_pray();
39 						return;
40 
41 					case 'm':
42 						act_donation_pray();
43 						return;
44 
45 					case '\33':
46 						return;
47 					};
48 
49 			case 'd':
50 				lprcat(" desecrate");
51 				act_desecrate_altar();
52 				return;
53 
54 			case 'i':
55 			case '\33':
56 				ignore();
57 				act_ignore_altar();
58 				return;
59 			};
60 	}
61 }
62 
63 /*
64 	subroutine to process a throne object
65  */
66 void
67 othrone(arg)
68 	int             arg;
69 {
70 
71 	lprcat("\nDo you (p) pry off jewels, (s) sit down");
72 	iopts();
73 	while (1) {
74 		while (1)
75 			switch (ttgetch()) {
76 			case 'p':
77 				lprcat(" pry off");
78 				act_remove_gems(arg);
79 				return;
80 
81 			case 's':
82 				lprcat(" sit down");
83 				act_sit_throne(arg);
84 				return;
85 
86 			case 'i':
87 			case '\33':
88 				ignore();
89 				return;
90 			};
91 	}
92 }
93 
94 void
95 odeadthrone()
96 {
97 	int    k;
98 
99 	lprcat("\nDo you (s) sit down");
100 	iopts();
101 	while (1) {
102 		while (1)
103 			switch (ttgetch()) {
104 			case 's':
105 				lprcat(" sit down");
106 				k = rnd(101);
107 				if (k < 35) {
108 					lprcat("\nZaaaappp!  You've been teleported!\n");
109 					beep();
110 					oteleport(0);
111 				} else
112 					lprcat("\nnothing happens");
113 				return;
114 
115 			case 'i':
116 			case '\33':
117 				ignore();
118 				return;
119 			};
120 	}
121 }
122 
123 /*
124 	subroutine to process a throne object
125  */
126 void
127 ochest()
128 {
129 
130 	lprcat("\nDo you (t) take it, (o) try to open it");
131 	iopts();
132 	while (1) {
133 		while (1)
134 			switch (ttgetch()) {
135 			case 'o':
136 				lprcat(" open it");
137 				act_open_chest(playerx, playery);
138 				return;
139 
140 			case 't':
141 				lprcat(" take");
142 				if (take(OCHEST, iarg[playerx][playery]) == 0)
143 					item[playerx][playery] = know[playerx][playery] = 0;
144 				return;
145 
146 			case 'i':
147 			case '\33':
148 				ignore();
149 				return;
150 			};
151 	}
152 }
153 
154 /*
155 	process a fountain object
156  */
157 void
158 ofountain()
159 {
160 
161 	cursors();
162 	lprcat("\nDo you (d) drink, (w) wash yourself");
163 	iopts();
164 	while (1)
165 		switch (ttgetch()) {
166 		case 'd':
167 			lprcat("drink");
168 			act_drink_fountain();
169 			return;
170 
171 		case '\33':
172 		case 'i':
173 			ignore();
174 			return;
175 
176 		case 'w':
177 			lprcat("wash yourself");
178 			act_wash_fountain();
179 			return;
180 		}
181 }
182 
183 /*
184 	***
185 	FCH
186 	***
187 
188 	subroutine to process an up/down of a character attribute for ofountain
189  */
190 static void
191 fch(how, x)
192 	int             how;
193 	long           *x;
194 {
195 	if (how < 0) {
196 		lprcat(" went down by one!");
197 		--(*x);
198 	} else {
199 		lprcat(" went up by one!");
200 		(*x)++;
201 	}
202 	bottomline();
203 }
204 
205 /*
206 	a subroutine to raise or lower character levels
207 	if x > 0 they are raised   if x < 0 they are lowered
208  */
209 void
210 fntchange(how)
211 	int             how;
212 {
213 	long   j;
214 	lprc('\n');
215 	switch (rnd(9)) {
216 	case 1:
217 		lprcat("Your strength");
218 		fch(how, &c[0]);
219 		break;
220 	case 2:
221 		lprcat("Your intelligence");
222 		fch(how, &c[1]);
223 		break;
224 	case 3:
225 		lprcat("Your wisdom");
226 		fch(how, &c[2]);
227 		break;
228 	case 4:
229 		lprcat("Your constitution");
230 		fch(how, &c[3]);
231 		break;
232 	case 5:
233 		lprcat("Your dexterity");
234 		fch(how, &c[4]);
235 		break;
236 	case 6:
237 		lprcat("Your charm");
238 		fch(how, &c[5]);
239 		break;
240 	case 7:
241 		j = rnd(level + 1);
242 		if (how < 0) {
243 			lprintf("You lose %ld hit point", (long) j);
244 			if (j > 1)
245 				lprcat("s!");
246 			else
247 				lprc('!');
248 			losemhp((int) j);
249 		} else {
250 			lprintf("You gain %ld hit point", (long) j);
251 			if (j > 1)
252 				lprcat("s!");
253 			else
254 				lprc('!');
255 			raisemhp((int) j);
256 		}
257 		bottomline();
258 		break;
259 
260 	case 8:
261 		j = rnd(level + 1);
262 		if (how > 0) {
263 			lprintf("You just gained %ld spell", (long) j);
264 			raisemspells((int) j);
265 			if (j > 1)
266 				lprcat("s!");
267 			else
268 				lprc('!');
269 		} else {
270 			lprintf("You just lost %ld spell", (long) j);
271 			losemspells((int) j);
272 			if (j > 1)
273 				lprcat("s!");
274 			else
275 				lprc('!');
276 		}
277 		bottomline();
278 		break;
279 
280 	case 9:
281 		j = 5 * rnd((level + 1) * (level + 1));
282 		if (how < 0) {
283 			lprintf("You just lost %ld experience point", (long) j);
284 			if (j > 1)
285 				lprcat("s!");
286 			else
287 				lprc('!');
288 			loseexperience((long) j);
289 		} else {
290 			lprintf("You just gained %ld experience point", (long) j);
291 			if (j > 1)
292 				lprcat("s!");
293 			else
294 				lprc('!');
295 			raiseexperience((long) j);
296 		}
297 		break;
298 	}
299 	cursors();
300 }
301