global.c revision 1.6 1 1.6 christos /* $NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos Exp $ */
2 1.6 christos
3 1.6 christos /*
4 1.6 christos * global.c Larn is copyrighted 1986 by Noah Morgan.
5 1.6 christos *
6 1.6 christos * raiselevel() subroutine to raise the player one level
7 1.6 christos * loselevel() subroutine to lower the player by one level
8 1.6 christos * raiseexperience(x) subroutine to increase experience points
9 1.6 christos * loseexperience(x) subroutine to lose experience points
10 1.6 christos * losehp(x) subroutine to remove hit points from the player
11 1.6 christos * losemhp(x) subroutine to remove max # hit points from the player
12 1.6 christos * raisehp(x) subroutine to gain hit points
13 1.6 christos * raisemhp(x) subroutine to gain maximum hit points
14 1.6 christos * losespells(x) subroutine to lose spells
15 1.6 christos * losemspells(x) subroutine to lose maximum spells
16 1.6 christos * raisespells(x) subroutine to gain spells
17 1.6 christos * raisemspells(x) subroutine to gain maximum spells
18 1.6 christos * recalc() function to recalculate the armor class of the player
19 1.6 christos * makemonst(lev) function to return monster number for a randomly
20 1.6 christos * selected monster
21 1.6 christos * positionplayer() function to be sure player is not in a wall
22 1.6 christos * quit() subroutine to ask if the player really wants to quit
23 1.6 christos */
24 1.6 christos #include <sys/cdefs.h>
25 1.2 mycroft #ifndef lint
26 1.6 christos __RCSID("$NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos Exp $");
27 1.2 mycroft #endif /* not lint */
28 1.2 mycroft
29 1.6 christos #include <string.h>
30 1.6 christos #include <unistd.h>
31 1.1 cgd #include "header.h"
32 1.6 christos #include "extern.h"
33 1.6 christos extern int score[], srcount, dropflag;
34 1.6 christos extern int random; /* the random number seed */
35 1.6 christos extern short playerx, playery, lastnum, level;
36 1.6 christos extern u_char cheat;
37 1.6 christos extern char monstnamelist[], logname[];
38 1.6 christos extern char lastmonst[], *what[], *who[];
39 1.6 christos extern char winner[];
40 1.6 christos extern u_char monstlevel[];
41 1.6 christos extern char sciv[SCORESIZE + 1][26][2], *potionname[], *scrollname[];
42 1.1 cgd /*
43 1.1 cgd ***********
44 1.1 cgd RAISE LEVEL
45 1.1 cgd ***********
46 1.1 cgd raiselevel()
47 1.1 cgd
48 1.1 cgd subroutine to raise the player one level
49 1.1 cgd uses the skill[] array to find level boundarys
50 1.1 cgd uses c[EXPERIENCE] c[LEVEL]
51 1.1 cgd */
52 1.6 christos void
53 1.1 cgd raiselevel()
54 1.6 christos {
55 1.6 christos if (c[LEVEL] < MAXPLEVEL)
56 1.6 christos raiseexperience((long) (skill[c[LEVEL]] - c[EXPERIENCE]));
57 1.6 christos }
58 1.1 cgd
59 1.1 cgd /*
60 1.1 cgd ***********
61 1.1 cgd LOOSE LEVEL
62 1.1 cgd ***********
63 1.1 cgd loselevel()
64 1.1 cgd
65 1.1 cgd subroutine to lower the players character level by one
66 1.1 cgd */
67 1.6 christos void
68 1.1 cgd loselevel()
69 1.6 christos {
70 1.6 christos if (c[LEVEL] > 1)
71 1.6 christos loseexperience((long) (c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1));
72 1.6 christos }
73 1.1 cgd
74 1.1 cgd /*
75 1.1 cgd ****************
76 1.1 cgd RAISE EXPERIENCE
77 1.1 cgd ****************
78 1.1 cgd raiseexperience(x)
79 1.1 cgd
80 1.1 cgd subroutine to increase experience points
81 1.1 cgd */
82 1.6 christos void
83 1.1 cgd raiseexperience(x)
84 1.6 christos long x;
85 1.6 christos {
86 1.6 christos int i, tmp;
87 1.6 christos i = c[LEVEL];
88 1.6 christos c[EXPERIENCE] += x;
89 1.6 christos while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) {
90 1.6 christos tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1;
91 1.6 christos c[LEVEL]++;
92 1.6 christos raisemhp((int) (rnd(3) + rnd((tmp > 0) ? tmp : 1)));
93 1.6 christos raisemspells((int) rund(3));
94 1.6 christos if (c[LEVEL] < 7 - c[HARDGAME])
95 1.6 christos raisemhp((int) (c[CONSTITUTION] >> 2));
96 1.6 christos }
97 1.6 christos if (c[LEVEL] != i) {
98 1.1 cgd cursors();
99 1.6 christos beep();
100 1.6 christos lprintf("\nWelcome to level %d", (long) c[LEVEL]); /* if we changed levels */
101 1.6 christos }
102 1.1 cgd bottomline();
103 1.6 christos }
104 1.1 cgd
105 1.1 cgd /*
106 1.1 cgd ****************
107 1.1 cgd LOOSE EXPERIENCE
108 1.1 cgd ****************
109 1.1 cgd loseexperience(x)
110 1.1 cgd
111 1.1 cgd subroutine to lose experience points
112 1.1 cgd */
113 1.6 christos void
114 1.1 cgd loseexperience(x)
115 1.6 christos long x;
116 1.6 christos {
117 1.6 christos int i, tmp;
118 1.6 christos i = c[LEVEL];
119 1.6 christos c[EXPERIENCE] -= x;
120 1.6 christos if (c[EXPERIENCE] < 0)
121 1.6 christos c[EXPERIENCE] = 0;
122 1.6 christos while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) {
123 1.6 christos if (--c[LEVEL] <= 1)
124 1.6 christos c[LEVEL] = 1; /* down one level */
125 1.6 christos tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; /* lose hpoints */
126 1.6 christos losemhp((int) rnd((tmp > 0) ? tmp : 1)); /* lose hpoints */
127 1.6 christos if (c[LEVEL] < 7 - c[HARDGAME])
128 1.6 christos losemhp((int) (c[CONSTITUTION] >> 2));
129 1.6 christos losemspells((int) rund(3)); /* lose spells */
130 1.6 christos }
131 1.6 christos if (i != c[LEVEL]) {
132 1.1 cgd cursors();
133 1.6 christos beep();
134 1.6 christos lprintf("\nYou went down to level %d!", (long) c[LEVEL]);
135 1.6 christos }
136 1.1 cgd bottomline();
137 1.6 christos }
138 1.1 cgd
139 1.1 cgd /*
140 1.1 cgd ********
141 1.1 cgd LOOSE HP
142 1.1 cgd ********
143 1.1 cgd losehp(x)
144 1.1 cgd losemhp(x)
145 1.1 cgd
146 1.1 cgd subroutine to remove hit points from the player
147 1.1 cgd warning -- will kill player if hp goes to zero
148 1.1 cgd */
149 1.6 christos void
150 1.1 cgd losehp(x)
151 1.6 christos int x;
152 1.6 christos {
153 1.6 christos if ((c[HP] -= x) <= 0) {
154 1.6 christos beep();
155 1.6 christos lprcat("\n");
156 1.6 christos nap(3000);
157 1.6 christos died(lastnum);
158 1.1 cgd }
159 1.6 christos }
160 1.1 cgd
161 1.6 christos void
162 1.1 cgd losemhp(x)
163 1.6 christos int x;
164 1.6 christos {
165 1.6 christos c[HP] -= x;
166 1.6 christos if (c[HP] < 1)
167 1.6 christos c[HP] = 1;
168 1.6 christos c[HPMAX] -= x;
169 1.6 christos if (c[HPMAX] < 1)
170 1.6 christos c[HPMAX] = 1;
171 1.6 christos }
172 1.1 cgd
173 1.1 cgd /*
174 1.1 cgd ********
175 1.1 cgd RAISE HP
176 1.1 cgd ********
177 1.1 cgd raisehp(x)
178 1.1 cgd raisemhp(x)
179 1.1 cgd
180 1.1 cgd subroutine to gain maximum hit points
181 1.1 cgd */
182 1.6 christos void
183 1.1 cgd raisehp(x)
184 1.6 christos int x;
185 1.6 christos {
186 1.6 christos if ((c[HP] += x) > c[HPMAX])
187 1.6 christos c[HP] = c[HPMAX];
188 1.6 christos }
189 1.1 cgd
190 1.6 christos void
191 1.1 cgd raisemhp(x)
192 1.6 christos int x;
193 1.6 christos {
194 1.6 christos c[HPMAX] += x;
195 1.6 christos c[HP] += x;
196 1.6 christos }
197 1.1 cgd
198 1.1 cgd /*
199 1.1 cgd ************
200 1.1 cgd RAISE SPELLS
201 1.1 cgd ************
202 1.1 cgd raisespells(x)
203 1.1 cgd raisemspells(x)
204 1.1 cgd
205 1.1 cgd subroutine to gain maximum spells
206 1.1 cgd */
207 1.6 christos void
208 1.1 cgd raisespells(x)
209 1.6 christos int x;
210 1.6 christos {
211 1.6 christos if ((c[SPELLS] += x) > c[SPELLMAX])
212 1.6 christos c[SPELLS] = c[SPELLMAX];
213 1.6 christos }
214 1.1 cgd
215 1.6 christos void
216 1.1 cgd raisemspells(x)
217 1.6 christos int x;
218 1.6 christos {
219 1.6 christos c[SPELLMAX] += x;
220 1.6 christos c[SPELLS] += x;
221 1.6 christos }
222 1.1 cgd
223 1.1 cgd /*
224 1.1 cgd ************
225 1.1 cgd LOOSE SPELLS
226 1.1 cgd ************
227 1.1 cgd losespells(x)
228 1.1 cgd losemspells(x)
229 1.1 cgd
230 1.1 cgd subroutine to lose maximum spells
231 1.1 cgd */
232 1.6 christos void
233 1.1 cgd losespells(x)
234 1.6 christos int x;
235 1.6 christos {
236 1.6 christos if ((c[SPELLS] -= x) < 0)
237 1.6 christos c[SPELLS] = 0;
238 1.6 christos }
239 1.1 cgd
240 1.6 christos void
241 1.1 cgd losemspells(x)
242 1.6 christos int x;
243 1.6 christos {
244 1.6 christos if ((c[SPELLMAX] -= x) < 0)
245 1.6 christos c[SPELLMAX] = 0;
246 1.6 christos if ((c[SPELLS] -= x) < 0)
247 1.6 christos c[SPELLS] = 0;
248 1.6 christos }
249 1.1 cgd
250 1.1 cgd /*
251 1.1 cgd makemonst(lev)
252 1.1 cgd int lev;
253 1.1 cgd
254 1.1 cgd function to return monster number for a randomly selected monster
255 1.6 christos for the given cave level
256 1.1 cgd */
257 1.6 christos int
258 1.1 cgd makemonst(lev)
259 1.6 christos int lev;
260 1.6 christos {
261 1.6 christos int tmp, x;
262 1.6 christos if (lev < 1)
263 1.6 christos lev = 1;
264 1.6 christos if (lev > 12)
265 1.6 christos lev = 12;
266 1.6 christos tmp = WATERLORD;
267 1.1 cgd if (lev < 5)
268 1.6 christos while (tmp == WATERLORD)
269 1.6 christos tmp = rnd((x = monstlevel[lev - 1]) ? x : 1);
270 1.6 christos else
271 1.6 christos while (tmp == WATERLORD)
272 1.6 christos tmp = rnd((x = monstlevel[lev - 1] - monstlevel[lev - 4]) ? x : 1) + monstlevel[lev - 4];
273 1.6 christos
274 1.6 christos while (monster[tmp].genocided && tmp < MAXMONST)
275 1.6 christos tmp++; /* genocided? */
276 1.6 christos return (tmp);
277 1.6 christos }
278 1.1 cgd
279 1.1 cgd /*
280 1.1 cgd positionplayer()
281 1.1 cgd
282 1.1 cgd function to be sure player is not in a wall
283 1.1 cgd */
284 1.6 christos void
285 1.1 cgd positionplayer()
286 1.6 christos {
287 1.6 christos int try;
288 1.1 cgd try = 2;
289 1.1 cgd while ((item[playerx][playery] || mitem[playerx][playery]) && (try))
290 1.6 christos if (++playerx >= MAXX - 1) {
291 1.1 cgd playerx = 1;
292 1.6 christos if (++playery >= MAXY - 1) {
293 1.6 christos playery = 1;
294 1.6 christos --try;
295 1.1 cgd }
296 1.6 christos }
297 1.6 christos if (try == 0)
298 1.6 christos lprcat("Failure in positionplayer\n");
299 1.6 christos }
300 1.1 cgd
301 1.1 cgd /*
302 1.1 cgd recalc() function to recalculate the armor class of the player
303 1.1 cgd */
304 1.6 christos void
305 1.1 cgd recalc()
306 1.6 christos {
307 1.6 christos int i, j, k;
308 1.1 cgd c[AC] = c[MOREDEFENSES];
309 1.6 christos if (c[WEAR] >= 0)
310 1.6 christos switch (iven[c[WEAR]]) {
311 1.6 christos case OSHIELD:
312 1.6 christos c[AC] += 2 + ivenarg[c[WEAR]];
313 1.6 christos break;
314 1.6 christos case OLEATHER:
315 1.6 christos c[AC] += 2 + ivenarg[c[WEAR]];
316 1.6 christos break;
317 1.6 christos case OSTUDLEATHER:
318 1.6 christos c[AC] += 3 + ivenarg[c[WEAR]];
319 1.6 christos break;
320 1.6 christos case ORING:
321 1.6 christos c[AC] += 5 + ivenarg[c[WEAR]];
322 1.6 christos break;
323 1.6 christos case OCHAIN:
324 1.6 christos c[AC] += 6 + ivenarg[c[WEAR]];
325 1.6 christos break;
326 1.6 christos case OSPLINT:
327 1.6 christos c[AC] += 7 + ivenarg[c[WEAR]];
328 1.6 christos break;
329 1.6 christos case OPLATE:
330 1.6 christos c[AC] += 9 + ivenarg[c[WEAR]];
331 1.6 christos break;
332 1.6 christos case OPLATEARMOR:
333 1.6 christos c[AC] += 10 + ivenarg[c[WEAR]];
334 1.6 christos break;
335 1.6 christos case OSSPLATE:
336 1.6 christos c[AC] += 12 + ivenarg[c[WEAR]];
337 1.6 christos break;
338 1.6 christos }
339 1.1 cgd
340 1.6 christos if (c[SHIELD] >= 0)
341 1.6 christos if (iven[c[SHIELD]] == OSHIELD)
342 1.6 christos c[AC] += 2 + ivenarg[c[SHIELD]];
343 1.6 christos if (c[WIELD] < 0)
344 1.6 christos c[WCLASS] = 0;
345 1.6 christos else {
346 1.1 cgd i = ivenarg[c[WIELD]];
347 1.6 christos switch (iven[c[WIELD]]) {
348 1.6 christos case ODAGGER:
349 1.6 christos c[WCLASS] = 3 + i;
350 1.6 christos break;
351 1.6 christos case OBELT:
352 1.6 christos c[WCLASS] = 7 + i;
353 1.6 christos break;
354 1.6 christos case OSHIELD:
355 1.6 christos c[WCLASS] = 8 + i;
356 1.6 christos break;
357 1.6 christos case OSPEAR:
358 1.6 christos c[WCLASS] = 10 + i;
359 1.6 christos break;
360 1.6 christos case OFLAIL:
361 1.6 christos c[WCLASS] = 14 + i;
362 1.6 christos break;
363 1.6 christos case OBATTLEAXE:
364 1.6 christos c[WCLASS] = 17 + i;
365 1.6 christos break;
366 1.6 christos case OLANCE:
367 1.6 christos c[WCLASS] = 19 + i;
368 1.6 christos break;
369 1.6 christos case OLONGSWORD:
370 1.6 christos c[WCLASS] = 22 + i;
371 1.6 christos break;
372 1.6 christos case O2SWORD:
373 1.6 christos c[WCLASS] = 26 + i;
374 1.6 christos break;
375 1.6 christos case OSWORD:
376 1.6 christos c[WCLASS] = 32 + i;
377 1.6 christos break;
378 1.6 christos case OSWORDofSLASHING:
379 1.6 christos c[WCLASS] = 30 + i;
380 1.6 christos break;
381 1.6 christos case OHAMMER:
382 1.6 christos c[WCLASS] = 35 + i;
383 1.6 christos break;
384 1.6 christos default:
385 1.6 christos c[WCLASS] = 0;
386 1.1 cgd }
387 1.6 christos }
388 1.1 cgd c[WCLASS] += c[MOREDAM];
389 1.1 cgd
390 1.6 christos /* now for regeneration abilities based on rings */
391 1.6 christos c[REGEN] = 1;
392 1.6 christos c[ENERGY] = 0;
393 1.6 christos j = 0;
394 1.6 christos for (k = 25; k > 0; k--)
395 1.6 christos if (iven[k]) {
396 1.6 christos j = k;
397 1.6 christos k = 0;
398 1.6 christos }
399 1.6 christos for (i = 0; i <= j; i++) {
400 1.6 christos switch (iven[i]) {
401 1.6 christos case OPROTRING:
402 1.6 christos c[AC] += ivenarg[i] + 1;
403 1.6 christos break;
404 1.6 christos case ODAMRING:
405 1.6 christos c[WCLASS] += ivenarg[i] + 1;
406 1.6 christos break;
407 1.6 christos case OBELT:
408 1.6 christos c[WCLASS] += ((ivenarg[i] << 1)) + 2;
409 1.6 christos break;
410 1.6 christos
411 1.6 christos case OREGENRING:
412 1.6 christos c[REGEN] += ivenarg[i] + 1;
413 1.6 christos break;
414 1.6 christos case ORINGOFEXTRA:
415 1.6 christos c[REGEN] += 5 * (ivenarg[i] + 1);
416 1.6 christos break;
417 1.6 christos case OENERGYRING:
418 1.6 christos c[ENERGY] += ivenarg[i] + 1;
419 1.6 christos break;
420 1.1 cgd }
421 1.1 cgd }
422 1.6 christos }
423 1.1 cgd
424 1.1 cgd
425 1.1 cgd /*
426 1.1 cgd quit()
427 1.1 cgd
428 1.1 cgd subroutine to ask if the player really wants to quit
429 1.1 cgd */
430 1.6 christos void
431 1.1 cgd quit()
432 1.6 christos {
433 1.6 christos int i;
434 1.6 christos cursors();
435 1.6 christos strcpy(lastmonst, "");
436 1.1 cgd lprcat("\n\nDo you really want to quit?");
437 1.6 christos while (1) {
438 1.6 christos i = getchar();
439 1.6 christos if (i == 'y') {
440 1.6 christos died(300);
441 1.6 christos return;
442 1.6 christos }
443 1.6 christos if ((i == 'n') || (i == '\33')) {
444 1.6 christos lprcat(" no");
445 1.6 christos lflush();
446 1.6 christos return;
447 1.6 christos }
448 1.6 christos lprcat("\n");
449 1.6 christos setbold();
450 1.6 christos lprcat("Yes");
451 1.6 christos resetbold();
452 1.6 christos lprcat(" or ");
453 1.6 christos setbold();
454 1.6 christos lprcat("No");
455 1.6 christos resetbold();
456 1.6 christos lprcat(" please? Do you want to quit? ");
457 1.1 cgd }
458 1.6 christos }
459 1.1 cgd
460 1.1 cgd /*
461 1.1 cgd function to ask --more-- then the user must enter a space
462 1.1 cgd */
463 1.6 christos void
464 1.1 cgd more()
465 1.6 christos {
466 1.6 christos lprcat("\n --- press ");
467 1.6 christos standout("space");
468 1.6 christos lprcat(" to continue --- ");
469 1.1 cgd while (getchar() != ' ');
470 1.6 christos }
471 1.1 cgd
472 1.1 cgd /*
473 1.1 cgd function to put something in the players inventory
474 1.1 cgd returns 0 if success, 1 if a failure
475 1.1 cgd */
476 1.6 christos int
477 1.6 christos take(itm, arg)
478 1.6 christos int itm, arg;
479 1.6 christos {
480 1.6 christos int i, limit;
481 1.6 christos /* cursors(); */
482 1.6 christos if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
483 1.6 christos limit = 26;
484 1.6 christos for (i = 0; i < limit; i++)
485 1.6 christos if (iven[i] == 0) {
486 1.6 christos iven[i] = itm;
487 1.6 christos ivenarg[i] = arg;
488 1.6 christos limit = 0;
489 1.6 christos switch (itm) {
490 1.6 christos case OPROTRING:
491 1.6 christos case ODAMRING:
492 1.6 christos case OBELT:
493 1.6 christos limit = 1;
494 1.6 christos break;
495 1.6 christos case ODEXRING:
496 1.6 christos c[DEXTERITY] += ivenarg[i] + 1;
497 1.6 christos limit = 1;
498 1.6 christos break;
499 1.6 christos case OSTRRING:
500 1.6 christos c[STREXTRA] += ivenarg[i] + 1;
501 1.6 christos limit = 1;
502 1.6 christos break;
503 1.6 christos case OCLEVERRING:
504 1.6 christos c[INTELLIGENCE] += ivenarg[i] + 1;
505 1.6 christos limit = 1;
506 1.6 christos break;
507 1.6 christos case OHAMMER:
508 1.6 christos c[DEXTERITY] += 10;
509 1.6 christos c[STREXTRA] += 10;
510 1.6 christos c[INTELLIGENCE] -= 10;
511 1.6 christos limit = 1;
512 1.6 christos break;
513 1.6 christos
514 1.6 christos case OORBOFDRAGON:
515 1.6 christos c[SLAYING]++;
516 1.6 christos break;
517 1.6 christos case OSPIRITSCARAB:
518 1.6 christos c[NEGATESPIRIT]++;
519 1.6 christos break;
520 1.6 christos case OCUBEofUNDEAD:
521 1.6 christos c[CUBEofUNDEAD]++;
522 1.6 christos break;
523 1.6 christos case ONOTHEFT:
524 1.6 christos c[NOTHEFT]++;
525 1.6 christos break;
526 1.6 christos case OSWORDofSLASHING:
527 1.6 christos c[DEXTERITY] += 5;
528 1.6 christos limit = 1;
529 1.6 christos break;
530 1.6 christos };
531 1.6 christos lprcat("\nYou pick up:");
532 1.6 christos srcount = 0;
533 1.6 christos show3(i);
534 1.6 christos if (limit)
535 1.6 christos bottomline();
536 1.6 christos return (0);
537 1.6 christos }
538 1.6 christos lprcat("\nYou can't carry anything else");
539 1.6 christos return (1);
540 1.6 christos }
541 1.1 cgd
542 1.1 cgd /*
543 1.6 christos subroutine to drop an object
544 1.6 christos returns 1 if something there already else 0
545 1.1 cgd */
546 1.6 christos int
547 1.1 cgd drop_object(k)
548 1.6 christos int k;
549 1.6 christos {
550 1.6 christos int itm;
551 1.6 christos if ((k < 0) || (k > 25))
552 1.6 christos return (0);
553 1.6 christos itm = iven[k];
554 1.6 christos cursors();
555 1.6 christos if (itm == 0) {
556 1.6 christos lprintf("\nYou don't have item %c! ", k + 'a');
557 1.6 christos return (1);
558 1.6 christos }
559 1.6 christos if (item[playerx][playery]) {
560 1.6 christos beep();
561 1.6 christos lprcat("\nThere's something here already");
562 1.6 christos return (1);
563 1.6 christos }
564 1.6 christos if (playery == MAXY - 1 && playerx == 33)
565 1.6 christos return (1); /* not in entrance */
566 1.1 cgd item[playerx][playery] = itm;
567 1.1 cgd iarg[playerx][playery] = ivenarg[k];
568 1.6 christos srcount = 0;
569 1.6 christos lprcat("\n You drop:");
570 1.6 christos show3(k); /* show what item you dropped */
571 1.6 christos know[playerx][playery] = 0;
572 1.6 christos iven[k] = 0;
573 1.6 christos if (c[WIELD] == k)
574 1.6 christos c[WIELD] = -1;
575 1.6 christos if (c[WEAR] == k)
576 1.6 christos c[WEAR] = -1;
577 1.6 christos if (c[SHIELD] == k)
578 1.6 christos c[SHIELD] = -1;
579 1.6 christos adjustcvalues(itm, ivenarg[k]);
580 1.6 christos dropflag = 1; /* say dropped an item so wont ask to pick it
581 1.6 christos * up right away */
582 1.6 christos return (0);
583 1.6 christos }
584 1.1 cgd
585 1.1 cgd /*
586 1.1 cgd function to enchant armor player is currently wearing
587 1.1 cgd */
588 1.6 christos void
589 1.1 cgd enchantarmor()
590 1.6 christos {
591 1.6 christos int tmp;
592 1.6 christos if (c[WEAR] < 0) {
593 1.6 christos if (c[SHIELD] < 0) {
594 1.6 christos cursors();
595 1.6 christos beep();
596 1.6 christos lprcat("\nYou feel a sense of loss");
597 1.6 christos return;
598 1.6 christos } else {
599 1.6 christos tmp = iven[c[SHIELD]];
600 1.6 christos if (tmp != OSCROLL)
601 1.6 christos if (tmp != OPOTION) {
602 1.6 christos ivenarg[c[SHIELD]]++;
603 1.6 christos bottomline();
604 1.6 christos }
605 1.6 christos }
606 1.6 christos }
607 1.1 cgd tmp = iven[c[WEAR]];
608 1.6 christos if (tmp != OSCROLL)
609 1.6 christos if (tmp != OPOTION) {
610 1.6 christos ivenarg[c[WEAR]]++;
611 1.6 christos bottomline();
612 1.6 christos }
613 1.6 christos }
614 1.1 cgd
615 1.1 cgd /*
616 1.1 cgd function to enchant a weapon presently being wielded
617 1.1 cgd */
618 1.6 christos void
619 1.1 cgd enchweapon()
620 1.6 christos {
621 1.6 christos int tmp;
622 1.6 christos if (c[WIELD] < 0) {
623 1.6 christos cursors();
624 1.6 christos beep();
625 1.6 christos lprcat("\nYou feel a sense of loss");
626 1.6 christos return;
627 1.6 christos }
628 1.1 cgd tmp = iven[c[WIELD]];
629 1.6 christos if (tmp != OSCROLL)
630 1.6 christos if (tmp != OPOTION) {
631 1.6 christos ivenarg[c[WIELD]]++;
632 1.6 christos if (tmp == OCLEVERRING)
633 1.6 christos c[INTELLIGENCE]++;
634 1.6 christos else if (tmp == OSTRRING)
635 1.6 christos c[STREXTRA]++;
636 1.6 christos else if (tmp == ODEXRING)
637 1.6 christos c[DEXTERITY]++;
638 1.6 christos bottomline();
639 1.6 christos }
640 1.6 christos }
641 1.1 cgd
642 1.1 cgd /*
643 1.1 cgd routine to tell if player can carry one more thing
644 1.1 cgd returns 1 if pockets are full, else 0
645 1.1 cgd */
646 1.6 christos int
647 1.1 cgd pocketfull()
648 1.6 christos {
649 1.6 christos int i, limit;
650 1.6 christos if ((limit = 15 + (c[LEVEL] >> 1)) > 26)
651 1.6 christos limit = 26;
652 1.6 christos for (i = 0; i < limit; i++)
653 1.6 christos if (iven[i] == 0)
654 1.6 christos return (0);
655 1.6 christos return (1);
656 1.6 christos }
657 1.1 cgd
658 1.1 cgd /*
659 1.1 cgd function to return 1 if a monster is next to the player else returns 0
660 1.1 cgd */
661 1.6 christos int
662 1.1 cgd nearbymonst()
663 1.6 christos {
664 1.6 christos int tmp, tmp2;
665 1.6 christos for (tmp = playerx - 1; tmp < playerx + 2; tmp++)
666 1.6 christos for (tmp2 = playery - 1; tmp2 < playery + 2; tmp2++)
667 1.6 christos if (mitem[tmp][tmp2])
668 1.6 christos return (1); /* if monster nearby */
669 1.6 christos return (0);
670 1.6 christos }
671 1.1 cgd
672 1.1 cgd /*
673 1.1 cgd function to steal an item from the players pockets
674 1.1 cgd returns 1 if steals something else returns 0
675 1.1 cgd */
676 1.6 christos int
677 1.1 cgd stealsomething()
678 1.6 christos {
679 1.6 christos int i, j;
680 1.6 christos j = 100;
681 1.6 christos while (1) {
682 1.6 christos i = rund(26);
683 1.6 christos if (iven[i])
684 1.6 christos if (c[WEAR] != i)
685 1.6 christos if (c[WIELD] != i)
686 1.6 christos if (c[SHIELD] != i) {
687 1.6 christos srcount = 0;
688 1.6 christos show3(i);
689 1.6 christos adjustcvalues(iven[i], ivenarg[i]);
690 1.6 christos iven[i] = 0;
691 1.6 christos return (1);
692 1.6 christos }
693 1.6 christos if (--j <= 0)
694 1.6 christos return (0);
695 1.1 cgd }
696 1.6 christos }
697 1.1 cgd
698 1.1 cgd /*
699 1.1 cgd function to return 1 is player carrys nothing else return 0
700 1.1 cgd */
701 1.6 christos int
702 1.1 cgd emptyhanded()
703 1.6 christos {
704 1.6 christos int i;
705 1.6 christos for (i = 0; i < 26; i++)
706 1.6 christos if (iven[i])
707 1.6 christos if (i != c[WIELD])
708 1.6 christos if (i != c[WEAR])
709 1.6 christos if (i != c[SHIELD])
710 1.6 christos return (0);
711 1.6 christos return (1);
712 1.6 christos }
713 1.1 cgd
714 1.1 cgd /*
715 1.1 cgd function to create a gem on a square near the player
716 1.1 cgd */
717 1.6 christos void
718 1.1 cgd creategem()
719 1.6 christos {
720 1.6 christos int i, j;
721 1.6 christos switch (rnd(4)) {
722 1.6 christos case 1:
723 1.6 christos i = ODIAMOND;
724 1.6 christos j = 50;
725 1.6 christos break;
726 1.6 christos case 2:
727 1.6 christos i = ORUBY;
728 1.6 christos j = 40;
729 1.6 christos break;
730 1.6 christos case 3:
731 1.6 christos i = OEMERALD;
732 1.6 christos j = 30;
733 1.6 christos break;
734 1.6 christos default:
735 1.6 christos i = OSAPPHIRE;
736 1.6 christos j = 20;
737 1.6 christos break;
738 1.6 christos };
739 1.6 christos createitem(i, rnd(j) + j / 10);
740 1.6 christos }
741 1.1 cgd
742 1.1 cgd /*
743 1.1 cgd function to change character levels as needed when dropping an object
744 1.1 cgd that affects these characteristics
745 1.1 cgd */
746 1.6 christos void
747 1.6 christos adjustcvalues(itm, arg)
748 1.6 christos int itm, arg;
749 1.6 christos {
750 1.6 christos int flag;
751 1.6 christos flag = 0;
752 1.6 christos switch (itm) {
753 1.6 christos case ODEXRING:
754 1.6 christos c[DEXTERITY] -= arg + 1;
755 1.6 christos flag = 1;
756 1.6 christos break;
757 1.6 christos case OSTRRING:
758 1.6 christos c[STREXTRA] -= arg + 1;
759 1.6 christos flag = 1;
760 1.6 christos break;
761 1.6 christos case OCLEVERRING:
762 1.6 christos c[INTELLIGENCE] -= arg + 1;
763 1.6 christos flag = 1;
764 1.6 christos break;
765 1.6 christos case OHAMMER:
766 1.6 christos c[DEXTERITY] -= 10;
767 1.6 christos c[STREXTRA] -= 10;
768 1.6 christos c[INTELLIGENCE] += 10;
769 1.6 christos flag = 1;
770 1.6 christos break;
771 1.6 christos case OSWORDofSLASHING:
772 1.6 christos c[DEXTERITY] -= 5;
773 1.6 christos flag = 1;
774 1.6 christos break;
775 1.6 christos case OORBOFDRAGON:
776 1.6 christos --c[SLAYING];
777 1.6 christos return;
778 1.6 christos case OSPIRITSCARAB:
779 1.6 christos --c[NEGATESPIRIT];
780 1.6 christos return;
781 1.6 christos case OCUBEofUNDEAD:
782 1.6 christos --c[CUBEofUNDEAD];
783 1.6 christos return;
784 1.6 christos case ONOTHEFT:
785 1.6 christos --c[NOTHEFT];
786 1.6 christos return;
787 1.6 christos case OLANCE:
788 1.6 christos c[LANCEDEATH] = 0;
789 1.6 christos return;
790 1.6 christos case OPOTION:
791 1.6 christos case OSCROLL:
792 1.6 christos return;
793 1.6 christos
794 1.6 christos default:
795 1.6 christos flag = 1;
796 1.6 christos };
797 1.6 christos if (flag)
798 1.6 christos bottomline();
799 1.6 christos }
800 1.1 cgd
801 1.1 cgd /*
802 1.1 cgd function to read a string from token input "string"
803 1.1 cgd returns a pointer to the string
804 1.1 cgd */
805 1.6 christos void
806 1.1 cgd gettokstr(str)
807 1.6 christos char *str;
808 1.6 christos {
809 1.6 christos int i, j;
810 1.6 christos i = 50;
811 1.1 cgd while ((getchar() != '"') && (--i > 0));
812 1.6 christos i = 36;
813 1.6 christos while (--i > 0) {
814 1.6 christos if ((j = getchar()) != '"')
815 1.6 christos *str++ = j;
816 1.6 christos else
817 1.6 christos i = 0;
818 1.6 christos }
819 1.1 cgd *str = 0;
820 1.6 christos i = 50;
821 1.6 christos if (j != '"')
822 1.6 christos /* if end due to too long, then find closing quote */
823 1.6 christos while ((getchar() != '"') && (--i > 0));
824 1.6 christos }
825 1.1 cgd
826 1.1 cgd /*
827 1.1 cgd function to ask user for a password (no echo)
828 1.1 cgd returns 1 if entered correctly, 0 if not
829 1.1 cgd */
830 1.6 christos static char gpwbuf[33];
831 1.6 christos int
832 1.1 cgd getpassword()
833 1.6 christos {
834 1.6 christos int i, j;
835 1.6 christos char *gpwp;
836 1.6 christos extern char *password;
837 1.6 christos scbr(); /* system("stty -echo cbreak"); */
838 1.6 christos gpwp = gpwbuf;
839 1.6 christos lprcat("\nEnter Password: ");
840 1.6 christos lflush();
841 1.1 cgd i = strlen(password);
842 1.6 christos for (j = 0; j < i; j++)
843 1.6 christos read(0, gpwp++, 1);
844 1.6 christos gpwbuf[i] = 0;
845 1.6 christos sncbr(); /* system("stty echo -cbreak"); */
846 1.6 christos if (strcmp(gpwbuf, password) != 0) {
847 1.6 christos lprcat("\nSorry\n");
848 1.6 christos lflush();
849 1.6 christos return (0);
850 1.6 christos } else
851 1.6 christos return (1);
852 1.6 christos }
853 1.1 cgd
854 1.1 cgd /*
855 1.1 cgd subroutine to get a yes or no response from the user
856 1.1 cgd returns y or n
857 1.1 cgd */
858 1.6 christos int
859 1.1 cgd getyn()
860 1.6 christos {
861 1.6 christos int i;
862 1.6 christos i = 0;
863 1.6 christos while (i != 'y' && i != 'n' && i != '\33')
864 1.6 christos i = getchar();
865 1.6 christos return (i);
866 1.6 christos }
867 1.1 cgd
868 1.1 cgd /*
869 1.1 cgd function to calculate the pack weight of the player
870 1.1 cgd returns the number of pounds the player is carrying
871 1.1 cgd */
872 1.6 christos int
873 1.1 cgd packweight()
874 1.6 christos {
875 1.6 christos int i, j, k;
876 1.6 christos k = c[GOLD] / 1000;
877 1.6 christos j = 25;
878 1.6 christos while ((iven[j] == 0) && (j > 0))
879 1.6 christos --j;
880 1.6 christos for (i = 0; i <= j; i++)
881 1.6 christos switch (iven[i]) {
882 1.6 christos case 0:
883 1.6 christos break;
884 1.6 christos case OSSPLATE:
885 1.6 christos case OPLATEARMOR:
886 1.6 christos k += 40;
887 1.6 christos break;
888 1.6 christos case OPLATE:
889 1.6 christos k += 35;
890 1.6 christos break;
891 1.6 christos case OHAMMER:
892 1.6 christos k += 30;
893 1.6 christos break;
894 1.6 christos case OSPLINT:
895 1.6 christos k += 26;
896 1.6 christos break;
897 1.6 christos case OSWORDofSLASHING:
898 1.6 christos case OCHAIN:
899 1.6 christos case OBATTLEAXE:
900 1.6 christos case O2SWORD:
901 1.6 christos k += 23;
902 1.6 christos break;
903 1.6 christos case OLONGSWORD:
904 1.6 christos case OSWORD:
905 1.6 christos case ORING:
906 1.6 christos case OFLAIL:
907 1.6 christos k += 20;
908 1.6 christos break;
909 1.6 christos case OLANCE:
910 1.6 christos case OSTUDLEATHER:
911 1.6 christos k += 15;
912 1.6 christos break;
913 1.6 christos case OLEATHER:
914 1.6 christos case OSPEAR:
915 1.6 christos k += 8;
916 1.6 christos break;
917 1.6 christos case OORBOFDRAGON:
918 1.6 christos case OBELT:
919 1.6 christos k += 4;
920 1.6 christos break;
921 1.6 christos case OSHIELD:
922 1.6 christos k += 7;
923 1.6 christos break;
924 1.6 christos case OCHEST:
925 1.6 christos k += 30 + ivenarg[i];
926 1.6 christos break;
927 1.6 christos default:
928 1.6 christos k++;
929 1.6 christos };
930 1.6 christos return (k);
931 1.6 christos }
932 1.1 cgd
933 1.1 cgd #ifndef MACRORND
934 1.6 christos /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */
935 1.6 christos int
936 1.1 cgd rnd(x)
937 1.6 christos int x;
938 1.6 christos {
939 1.6 christos return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)) + 1);
940 1.6 christos }
941 1.1 cgd
942 1.6 christos int
943 1.1 cgd rund(x)
944 1.6 christos int x;
945 1.6 christos {
946 1.6 christos return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)));
947 1.6 christos }
948 1.6 christos #endif /* MACRORND */
949