main.c revision 1.14 1 1.14 veego /* $NetBSD: main.c,v 1.14 1998/08/30 09:19:38 veego Exp $ */
2 1.11 christos
3 1.11 christos /* main.c */
4 1.11 christos #include <sys/cdefs.h>
5 1.3 mycroft #ifndef lint
6 1.14 veego __RCSID("$NetBSD: main.c,v 1.14 1998/08/30 09:19:38 veego Exp $");
7 1.11 christos #endif /* not lint */
8 1.3 mycroft
9 1.1 cgd #include <sys/types.h>
10 1.11 christos #include <stdio.h>
11 1.1 cgd #include <pwd.h>
12 1.11 christos #include <unistd.h>
13 1.11 christos #include <stdlib.h>
14 1.7 cgd #include <string.h>
15 1.11 christos #include "header.h"
16 1.11 christos #include "extern.h"
17 1.7 cgd
18 1.11 christos static char copyright[] = "\nLarn is copyrighted 1986 by Noah Morgan.\n";
19 1.11 christos int srcount = 0; /* line counter for showstr() */
20 1.11 christos int dropflag = 0; /* if 1 then don't lookforobject() next round */
21 1.11 christos int rmst = 80; /* random monster creation counter */
22 1.11 christos int userid; /* the players login user id number */
23 1.11 christos uid_t uid, euid; /* used for security */
24 1.11 christos u_char nowelcome = 0, nomove = 0; /* if (nomove) then don't
25 1.11 christos * count next iteration as a
26 1.11 christos * move */
27 1.11 christos static char viewflag = 0;
28 1.11 christos /*
29 1.11 christos * if viewflag then we have done a 99 stay here and don't showcell in the
30 1.11 christos * main loop
31 1.11 christos */
32 1.11 christos u_char restorflag = 0; /* 1 means restore has been done */
33 1.11 christos static char cmdhelp[] = "\
34 1.12 mikel Cmd line format: larn [-slicnh] [-o<optsfile>] [-##] [++]\n\
35 1.1 cgd -s show the scoreboard\n\
36 1.1 cgd -l show the logfile (wizard id only)\n\
37 1.1 cgd -i show scoreboard with inventories of dead characters\n\
38 1.1 cgd -c create new scoreboard (wizard id only)\n\
39 1.1 cgd -n suppress welcome message on starting game\n\
40 1.1 cgd -## specify level of difficulty (example: -5)\n\
41 1.1 cgd -h print this help text\n\
42 1.1 cgd ++ restore game from checkpoint file\n\
43 1.1 cgd -o<optsfile> specify .larnopts filename to be used instead of \"~/.larnopts\"\n\
44 1.1 cgd ";
45 1.1 cgd #ifdef VT100
46 1.11 christos static char *termtypes[] = {"vt100", "vt101", "vt102", "vt103", "vt125",
47 1.1 cgd "vt131", "vt140", "vt180", "vt220", "vt240", "vt241", "vt320", "vt340",
48 1.11 christos "vt341"};
49 1.11 christos #endif /* VT100 */
50 1.1 cgd /*
51 1.1 cgd ************
52 1.1 cgd MAIN PROGRAM
53 1.1 cgd ************
54 1.1 cgd */
55 1.11 christos int
56 1.11 christos main(argc, argv)
57 1.11 christos int argc;
58 1.11 christos char **argv;
59 1.11 christos {
60 1.11 christos int i;
61 1.11 christos int hard;
62 1.13 mycroft const char *ptr = 0;
63 1.11 christos struct passwd *pwe;
64 1.1 cgd
65 1.9 mrg euid = geteuid();
66 1.9 mrg uid = getuid();
67 1.11 christos seteuid(uid); /* give up "games" if we have it */
68 1.11 christos /*
69 1.11 christos * first task is to identify the player
70 1.11 christos */
71 1.1 cgd #ifndef VT100
72 1.11 christos init_term(); /* setup the terminal (find out what type)
73 1.11 christos * for termcap */
74 1.11 christos #endif /* VT100 */
75 1.14 veego /* try to get login name */
76 1.14 veego if (((ptr = getlogin()) == 0) || (*ptr == 0)) {
77 1.14 veego /* can we get it from /etc/passwd? */
78 1.14 veego if ((pwe = getpwuid(getuid())) != NULL)
79 1.11 christos ptr = pwe->pw_name;
80 1.11 christos else if ((ptr = getenv("USER")) == 0)
81 1.11 christos if ((ptr = getenv("LOGNAME")) == 0) {
82 1.11 christos noone: write(2, "Can't find your logname. Who Are You?\n", 39);
83 1.11 christos exit(1);
84 1.11 christos }
85 1.14 veego }
86 1.11 christos if (ptr == 0)
87 1.11 christos goto noone;
88 1.11 christos if (strlen(ptr) == 0)
89 1.11 christos goto noone;
90 1.11 christos /*
91 1.11 christos * second task is to prepare the pathnames the player will need
92 1.11 christos */
93 1.11 christos strcpy(loginname, ptr); /* save loginname of the user for logging
94 1.11 christos * purposes */
95 1.11 christos strcpy(logname, ptr); /* this will be overwritten with the players
96 1.11 christos * name */
97 1.11 christos if ((ptr = getenv("HOME")) == NULL)
98 1.11 christos ptr = ".";
99 1.1 cgd strcpy(savefilename, ptr);
100 1.11 christos strcat(savefilename, "/Larn.sav"); /* save file name in home
101 1.11 christos * directory */
102 1.11 christos sprintf(optsfile, "%s/.larnopts", ptr); /* the .larnopts filename */
103 1.11 christos
104 1.11 christos /*
105 1.11 christos * now malloc the memory for the dungeon
106 1.11 christos */
107 1.11 christos cell = (struct cel *) malloc(sizeof(struct cel) * (MAXLEVEL + MAXVLEVEL) * MAXX * MAXY);
108 1.11 christos if (cell == 0)
109 1.11 christos died(-285); /* malloc failure */
110 1.11 christos lpbuf = malloc((5 * BUFBIG) >> 2); /* output buffer */
111 1.11 christos inbuffer = malloc((5 * MAXIBUF) >> 2); /* output buffer */
112 1.11 christos if ((lpbuf == 0) || (inbuffer == 0))
113 1.11 christos died(-285); /* malloc() failure */
114 1.11 christos
115 1.11 christos lcreat((char *) 0);
116 1.11 christos newgame(); /* set the initial clock */
117 1.11 christos hard = -1;
118 1.1 cgd
119 1.1 cgd #ifdef VT100
120 1.11 christos /*
121 1.11 christos * check terminal type to avoid users who have not vt100 type terminals
122 1.11 christos */
123 1.1 cgd ttype = getenv("TERM");
124 1.11 christos for (j = 1, i = 0; i < sizeof(termtypes) / sizeof(char *); i++)
125 1.11 christos if (strcmp(ttype, termtypes[i]) == 0) {
126 1.11 christos j = 0;
127 1.11 christos break;
128 1.1 cgd }
129 1.11 christos if (j) {
130 1.11 christos lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n");
131 1.11 christos lflush();
132 1.11 christos exit(1);
133 1.11 christos }
134 1.11 christos #endif /* VT100 */
135 1.11 christos
136 1.11 christos /*
137 1.11 christos * now make scoreboard if it is not there (don't clear)
138 1.11 christos */
139 1.11 christos if (access(scorefile, 0) == -1) /* not there */
140 1.1 cgd makeboard();
141 1.1 cgd
142 1.11 christos /*
143 1.11 christos * now process the command line arguments
144 1.11 christos */
145 1.11 christos for (i = 1; i < argc; i++) {
146 1.1 cgd if (argv[i][0] == '-')
147 1.11 christos switch (argv[i][1]) {
148 1.11 christos case 's':
149 1.11 christos showscores();
150 1.11 christos exit(0); /* show scoreboard */
151 1.11 christos
152 1.11 christos case 'l': /* show log file */
153 1.11 christos diedlog();
154 1.11 christos exit(0);
155 1.11 christos
156 1.11 christos case 'i':
157 1.11 christos showallscores();
158 1.11 christos exit(0); /* show all scoreboard */
159 1.11 christos
160 1.11 christos case 'c': /* anyone with password can create
161 1.11 christos * scoreboard */
162 1.11 christos lprcat("Preparing to initialize the scoreboard.\n");
163 1.11 christos if (getpassword() != 0) { /* make new scoreboard */
164 1.11 christos makeboard();
165 1.11 christos lprc('\n');
166 1.11 christos showscores();
167 1.11 christos }
168 1.11 christos exit(0);
169 1.1 cgd
170 1.11 christos case 'n': /* no welcome msg */
171 1.11 christos nowelcome = 1;
172 1.11 christos argv[i][0] = 0;
173 1.11 christos break;
174 1.11 christos
175 1.11 christos case '0':
176 1.11 christos case '1':
177 1.11 christos case '2':
178 1.11 christos case '3':
179 1.11 christos case '4':
180 1.11 christos case '5':
181 1.11 christos case '6':
182 1.11 christos case '7':
183 1.11 christos case '8':
184 1.11 christos case '9': /* for hardness */
185 1.11 christos sscanf(&argv[i][1], "%d", &hard);
186 1.11 christos break;
187 1.1 cgd
188 1.1 cgd case 'h': /* print out command line arguments */
189 1.11 christos write(1, cmdhelp, sizeof(cmdhelp));
190 1.11 christos exit(0);
191 1.1 cgd
192 1.1 cgd case 'o': /* specify a .larnopts filename */
193 1.11 christos strncpy(optsfile, argv[i] + 2, 127);
194 1.11 christos break;
195 1.1 cgd
196 1.11 christos default:
197 1.11 christos printf("Unknown option <%s>\n", argv[i]);
198 1.11 christos exit(1);
199 1.1 cgd };
200 1.1 cgd
201 1.11 christos if (argv[i][0] == '+') {
202 1.11 christos clear();
203 1.11 christos restorflag = 1;
204 1.11 christos if (argv[i][1] == '+') {
205 1.11 christos hitflag = 1;
206 1.11 christos restoregame(ckpfile); /* restore checkpointed
207 1.11 christos * game */
208 1.11 christos }
209 1.1 cgd i = argc;
210 1.1 cgd }
211 1.11 christos }
212 1.1 cgd
213 1.1 cgd readopts(); /* read the options file if there is one */
214 1.1 cgd
215 1.1 cgd
216 1.1 cgd #ifdef UIDSCORE
217 1.1 cgd userid = geteuid(); /* obtain the user's effective id number */
218 1.11 christos #else /* UIDSCORE */
219 1.1 cgd userid = getplid(logname); /* obtain the players id number */
220 1.11 christos #endif /* UIDSCORE */
221 1.11 christos if (userid < 0) {
222 1.11 christos write(2, "Can't obtain playerid\n", 22);
223 1.11 christos exit(1);
224 1.11 christos }
225 1.1 cgd #ifdef HIDEBYLINK
226 1.11 christos /*
227 1.11 christos * this section of code causes the program to look like something else to ps
228 1.11 christos */
229 1.11 christos if (strcmp(psname, argv[0])) { /* if a different process name only */
230 1.11 christos if ((i = access(psname, 1)) < 0) { /* link not there */
231 1.11 christos if (link(argv[0], psname) >= 0) {
232 1.11 christos argv[0] = psname;
233 1.11 christos execv(psname, argv);
234 1.1 cgd }
235 1.11 christos } else
236 1.1 cgd unlink(psname);
237 1.11 christos }
238 1.11 christos for (i = 1; i < argc; i++) {
239 1.1 cgd szero(argv[i]); /* zero the argument to avoid ps snooping */
240 1.11 christos }
241 1.11 christos #endif /* HIDEBYLINK */
242 1.1 cgd
243 1.11 christos if (access(savefilename, 0) == 0) { /* restore game if need to */
244 1.11 christos clear();
245 1.11 christos restorflag = 1;
246 1.11 christos hitflag = 1;
247 1.11 christos restoregame(savefilename); /* restore last game */
248 1.11 christos }
249 1.11 christos sigsetup(); /* trap all needed signals */
250 1.11 christos sethard(hard); /* set up the desired difficulty */
251 1.11 christos setupvt100(); /* setup the terminal special mode */
252 1.11 christos if (c[HP] == 0) { /* create new game */
253 1.11 christos makeplayer(); /* make the character that will play */
254 1.11 christos newcavelevel(0);/* make the dungeon */
255 1.11 christos predostuff = 1; /* tell signals that we are in the welcome
256 1.11 christos * screen */
257 1.11 christos if (nowelcome == 0)
258 1.11 christos welcome(); /* welcome the player to the game */
259 1.11 christos }
260 1.11 christos drawscreen(); /* show the initial dungeon */
261 1.11 christos predostuff = 2; /* tell the trap functions that they must do
262 1.11 christos * a showplayer() from here on */
263 1.11 christos #if 0
264 1.11 christos nice(1); /* games should be run niced */
265 1.11 christos #endif
266 1.1 cgd yrepcount = hit2flag = 0;
267 1.11 christos while (1) {
268 1.11 christos if (dropflag == 0)
269 1.11 christos lookforobject(); /* see if there is an object
270 1.11 christos * here */
271 1.11 christos else
272 1.11 christos dropflag = 0; /* don't show it just dropped an item */
273 1.11 christos if (hitflag == 0) {
274 1.11 christos if (c[HASTEMONST])
275 1.11 christos movemonst();
276 1.11 christos movemonst();
277 1.11 christos } /* move the monsters */
278 1.11 christos if (viewflag == 0)
279 1.11 christos showcell(playerx, playery);
280 1.11 christos else
281 1.11 christos viewflag = 0; /* show stuff around player */
282 1.11 christos if (hit3flag)
283 1.11 christos flushall();
284 1.11 christos hitflag = hit3flag = 0;
285 1.11 christos nomove = 1;
286 1.1 cgd bot_linex(); /* update bottom line */
287 1.11 christos while (nomove) {
288 1.11 christos if (hit3flag)
289 1.11 christos flushall();
290 1.11 christos nomove = 0;
291 1.11 christos parse();
292 1.11 christos } /* get commands and make moves */
293 1.11 christos regen(); /* regenerate hp and spells */
294 1.11 christos if (c[TIMESTOP] == 0)
295 1.11 christos if (--rmst <= 0) {
296 1.11 christos rmst = 120 - (level << 2);
297 1.11 christos fillmonst(makemonst(level));
298 1.11 christos }
299 1.1 cgd }
300 1.11 christos }
301 1.11 christos
302 1.11 christos
303 1.1 cgd /*
304 1.1 cgd showstr()
305 1.1 cgd
306 1.1 cgd show character's inventory
307 1.1 cgd */
308 1.11 christos void
309 1.1 cgd showstr()
310 1.11 christos {
311 1.11 christos int i, number;
312 1.11 christos for (number = 3, i = 0; i < 26; i++)
313 1.11 christos if (iven[i])
314 1.11 christos number++; /* count items in inventory */
315 1.11 christos t_setup(number);
316 1.11 christos qshowstr();
317 1.11 christos t_endup(number);
318 1.11 christos }
319 1.1 cgd
320 1.11 christos void
321 1.1 cgd qshowstr()
322 1.11 christos {
323 1.11 christos int i, j, k, sigsav;
324 1.11 christos srcount = 0;
325 1.11 christos sigsav = nosignal;
326 1.11 christos nosignal = 1; /* don't allow ^c etc */
327 1.11 christos if (c[GOLD]) {
328 1.11 christos lprintf(".) %d gold pieces", (long) c[GOLD]);
329 1.11 christos srcount++;
330 1.11 christos }
331 1.11 christos for (k = 26; k >= 0; k--)
332 1.11 christos if (iven[k]) {
333 1.11 christos for (i = 22; i < 84; i++)
334 1.11 christos for (j = 0; j <= k; j++)
335 1.11 christos if (i == iven[j])
336 1.11 christos show3(j);
337 1.11 christos k = 0;
338 1.11 christos }
339 1.11 christos lprintf("\nElapsed time is %d. You have %d mobuls left", (long) ((gltime + 99) / 100 + 1), (long) ((TIMELIMIT - gltime) / 100));
340 1.11 christos more();
341 1.11 christos nosignal = sigsav;
342 1.11 christos }
343 1.1 cgd
344 1.1 cgd /*
345 1.1 cgd * subroutine to clear screen depending on # lines to display
346 1.1 cgd */
347 1.11 christos void
348 1.1 cgd t_setup(count)
349 1.11 christos int count;
350 1.11 christos {
351 1.11 christos if (count < 20) { /* how do we clear the screen? */
352 1.11 christos cl_up(79, count);
353 1.11 christos cursor(1, 1);
354 1.11 christos } else {
355 1.11 christos resetscroll();
356 1.11 christos clear();
357 1.1 cgd }
358 1.11 christos }
359 1.1 cgd
360 1.1 cgd /*
361 1.1 cgd * subroutine to restore normal display screen depending on t_setup()
362 1.1 cgd */
363 1.11 christos void
364 1.1 cgd t_endup(count)
365 1.11 christos int count;
366 1.11 christos {
367 1.11 christos if (count < 18) /* how did we clear the screen? */
368 1.11 christos draws(0, MAXX, 0, (count > MAXY) ? MAXY : count);
369 1.11 christos else {
370 1.11 christos drawscreen();
371 1.11 christos setscroll();
372 1.1 cgd }
373 1.11 christos }
374 1.1 cgd
375 1.1 cgd /*
376 1.1 cgd function to show the things player is wearing only
377 1.1 cgd */
378 1.11 christos void
379 1.1 cgd showwear()
380 1.11 christos {
381 1.11 christos int i, j, sigsav, count;
382 1.11 christos sigsav = nosignal;
383 1.11 christos nosignal = 1; /* don't allow ^c etc */
384 1.11 christos srcount = 0;
385 1.11 christos
386 1.11 christos for (count = 2, j = 0; j <= 26; j++) /* count number of items we
387 1.11 christos * will display */
388 1.11 christos if ((i = iven[j]) != 0)
389 1.11 christos switch (i) {
390 1.11 christos case OLEATHER:
391 1.11 christos case OPLATE:
392 1.11 christos case OCHAIN:
393 1.11 christos case ORING:
394 1.11 christos case OSTUDLEATHER:
395 1.11 christos case OSPLINT:
396 1.11 christos case OPLATEARMOR:
397 1.11 christos case OSSPLATE:
398 1.11 christos case OSHIELD:
399 1.11 christos count++;
400 1.1 cgd };
401 1.1 cgd
402 1.1 cgd t_setup(count);
403 1.1 cgd
404 1.11 christos for (i = 22; i < 84; i++)
405 1.11 christos for (j = 0; j <= 26; j++)
406 1.11 christos if (i == iven[j])
407 1.11 christos switch (i) {
408 1.11 christos case OLEATHER:
409 1.11 christos case OPLATE:
410 1.11 christos case OCHAIN:
411 1.11 christos case ORING:
412 1.11 christos case OSTUDLEATHER:
413 1.11 christos case OSPLINT:
414 1.11 christos case OPLATEARMOR:
415 1.11 christos case OSSPLATE:
416 1.11 christos case OSHIELD:
417 1.11 christos show3(j);
418 1.1 cgd };
419 1.11 christos more();
420 1.11 christos nosignal = sigsav;
421 1.11 christos t_endup(count);
422 1.11 christos }
423 1.1 cgd
424 1.1 cgd /*
425 1.11 christos function to show the things player can wield only
426 1.1 cgd */
427 1.11 christos void
428 1.1 cgd showwield()
429 1.11 christos {
430 1.11 christos int i, j, sigsav, count;
431 1.11 christos sigsav = nosignal;
432 1.11 christos nosignal = 1; /* don't allow ^c etc */
433 1.11 christos srcount = 0;
434 1.11 christos
435 1.11 christos for (count = 2, j = 0; j <= 26; j++) /* count how many items */
436 1.11 christos if ((i = iven[j]) != 0)
437 1.11 christos switch (i) {
438 1.11 christos case ODIAMOND:
439 1.11 christos case ORUBY:
440 1.11 christos case OEMERALD:
441 1.11 christos case OSAPPHIRE:
442 1.11 christos case OBOOK:
443 1.11 christos case OCHEST:
444 1.11 christos case OLARNEYE:
445 1.11 christos case ONOTHEFT:
446 1.11 christos case OSPIRITSCARAB:
447 1.11 christos case OCUBEofUNDEAD:
448 1.11 christos case OPOTION:
449 1.11 christos case OSCROLL:
450 1.11 christos break;
451 1.11 christos default:
452 1.11 christos count++;
453 1.1 cgd };
454 1.1 cgd
455 1.1 cgd t_setup(count);
456 1.1 cgd
457 1.11 christos for (i = 22; i < 84; i++)
458 1.11 christos for (j = 0; j <= 26; j++)
459 1.11 christos if (i == iven[j])
460 1.11 christos switch (i) {
461 1.11 christos case ODIAMOND:
462 1.11 christos case ORUBY:
463 1.11 christos case OEMERALD:
464 1.11 christos case OSAPPHIRE:
465 1.11 christos case OBOOK:
466 1.11 christos case OCHEST:
467 1.11 christos case OLARNEYE:
468 1.11 christos case ONOTHEFT:
469 1.11 christos case OSPIRITSCARAB:
470 1.11 christos case OCUBEofUNDEAD:
471 1.11 christos case OPOTION:
472 1.11 christos case OSCROLL:
473 1.11 christos break;
474 1.11 christos default:
475 1.11 christos show3(j);
476 1.1 cgd };
477 1.11 christos more();
478 1.11 christos nosignal = sigsav;
479 1.11 christos t_endup(count);
480 1.11 christos }
481 1.1 cgd
482 1.1 cgd /*
483 1.1 cgd * function to show the things player can read only
484 1.1 cgd */
485 1.11 christos void
486 1.1 cgd showread()
487 1.11 christos {
488 1.11 christos int i, j, sigsav, count;
489 1.11 christos sigsav = nosignal;
490 1.11 christos nosignal = 1; /* don't allow ^c etc */
491 1.11 christos srcount = 0;
492 1.11 christos
493 1.11 christos for (count = 2, j = 0; j <= 26; j++)
494 1.11 christos switch (iven[j]) {
495 1.11 christos case OBOOK:
496 1.11 christos case OSCROLL:
497 1.11 christos count++;
498 1.11 christos };
499 1.1 cgd t_setup(count);
500 1.1 cgd
501 1.11 christos for (i = 22; i < 84; i++)
502 1.11 christos for (j = 0; j <= 26; j++)
503 1.11 christos if (i == iven[j])
504 1.11 christos switch (i) {
505 1.11 christos case OBOOK:
506 1.11 christos case OSCROLL:
507 1.11 christos show3(j);
508 1.1 cgd };
509 1.11 christos more();
510 1.11 christos nosignal = sigsav;
511 1.11 christos t_endup(count);
512 1.11 christos }
513 1.1 cgd
514 1.1 cgd /*
515 1.1 cgd * function to show the things player can eat only
516 1.1 cgd */
517 1.11 christos void
518 1.1 cgd showeat()
519 1.11 christos {
520 1.11 christos int i, j, sigsav, count;
521 1.11 christos sigsav = nosignal;
522 1.11 christos nosignal = 1; /* don't allow ^c etc */
523 1.11 christos srcount = 0;
524 1.11 christos
525 1.11 christos for (count = 2, j = 0; j <= 26; j++)
526 1.11 christos switch (iven[j]) {
527 1.11 christos case OCOOKIE:
528 1.11 christos count++;
529 1.11 christos };
530 1.1 cgd t_setup(count);
531 1.1 cgd
532 1.11 christos for (i = 22; i < 84; i++)
533 1.11 christos for (j = 0; j <= 26; j++)
534 1.11 christos if (i == iven[j])
535 1.11 christos switch (i) {
536 1.11 christos case OCOOKIE:
537 1.11 christos show3(j);
538 1.1 cgd };
539 1.11 christos more();
540 1.11 christos nosignal = sigsav;
541 1.11 christos t_endup(count);
542 1.11 christos }
543 1.1 cgd
544 1.1 cgd /*
545 1.1 cgd function to show the things player can quaff only
546 1.1 cgd */
547 1.11 christos void
548 1.1 cgd showquaff()
549 1.11 christos {
550 1.11 christos int i, j, sigsav, count;
551 1.11 christos sigsav = nosignal;
552 1.11 christos nosignal = 1; /* don't allow ^c etc */
553 1.11 christos srcount = 0;
554 1.11 christos
555 1.11 christos for (count = 2, j = 0; j <= 26; j++)
556 1.11 christos switch (iven[j]) {
557 1.11 christos case OPOTION:
558 1.11 christos count++;
559 1.11 christos };
560 1.1 cgd t_setup(count);
561 1.1 cgd
562 1.11 christos for (i = 22; i < 84; i++)
563 1.11 christos for (j = 0; j <= 26; j++)
564 1.11 christos if (i == iven[j])
565 1.11 christos switch (i) {
566 1.11 christos case OPOTION:
567 1.11 christos show3(j);
568 1.1 cgd };
569 1.11 christos more();
570 1.11 christos nosignal = sigsav;
571 1.11 christos t_endup(count);
572 1.11 christos }
573 1.1 cgd
574 1.11 christos void
575 1.11 christos show1(idx, str2)
576 1.11 christos int idx;
577 1.11 christos char *str2[];
578 1.11 christos {
579 1.11 christos lprintf("\n%c) %s", idx + 'a', objectname[iven[idx]]);
580 1.11 christos if (str2 != 0 && str2[ivenarg[idx]][0] != 0)
581 1.11 christos lprintf(" of%s", str2[ivenarg[idx]]);
582 1.11 christos }
583 1.1 cgd
584 1.11 christos void
585 1.1 cgd show3(index)
586 1.11 christos int index;
587 1.11 christos {
588 1.11 christos switch (iven[index]) {
589 1.11 christos case OPOTION:
590 1.11 christos show1(index, potionname);
591 1.11 christos break;
592 1.11 christos case OSCROLL:
593 1.11 christos show1(index, scrollname);
594 1.11 christos break;
595 1.11 christos
596 1.11 christos case OLARNEYE:
597 1.11 christos case OBOOK:
598 1.11 christos case OSPIRITSCARAB:
599 1.11 christos case ODIAMOND:
600 1.11 christos case ORUBY:
601 1.11 christos case OCUBEofUNDEAD:
602 1.11 christos case OEMERALD:
603 1.11 christos case OCHEST:
604 1.11 christos case OCOOKIE:
605 1.11 christos case OSAPPHIRE:
606 1.11 christos case ONOTHEFT:
607 1.11 christos show1(index, (char **) 0);
608 1.11 christos break;
609 1.11 christos
610 1.11 christos default:
611 1.11 christos lprintf("\n%c) %s", index + 'a', objectname[iven[index]]);
612 1.11 christos if (ivenarg[index] > 0)
613 1.11 christos lprintf(" + %d", (long) ivenarg[index]);
614 1.11 christos else if (ivenarg[index] < 0)
615 1.11 christos lprintf(" %d", (long) ivenarg[index]);
616 1.11 christos break;
617 1.11 christos }
618 1.11 christos if (c[WIELD] == index)
619 1.11 christos lprcat(" (weapon in hand)");
620 1.11 christos if ((c[WEAR] == index) || (c[SHIELD] == index))
621 1.11 christos lprcat(" (being worn)");
622 1.11 christos if (++srcount >= 22) {
623 1.11 christos srcount = 0;
624 1.11 christos more();
625 1.11 christos clear();
626 1.1 cgd }
627 1.11 christos }
628 1.1 cgd
629 1.1 cgd /*
630 1.1 cgd subroutine to randomly create monsters if needed
631 1.1 cgd */
632 1.11 christos void
633 1.1 cgd randmonst()
634 1.11 christos {
635 1.11 christos if (c[TIMESTOP])
636 1.11 christos return; /* don't make monsters if time is stopped */
637 1.11 christos if (--rmst <= 0) {
638 1.11 christos rmst = 120 - (level << 2);
639 1.11 christos fillmonst(makemonst(level));
640 1.1 cgd }
641 1.11 christos }
642 1.11 christos
643 1.11 christos
644 1.1 cgd
645 1.1 cgd /*
646 1.1 cgd parse()
647 1.1 cgd
648 1.1 cgd get and execute a command
649 1.1 cgd */
650 1.11 christos void
651 1.1 cgd parse()
652 1.11 christos {
653 1.11 christos int i, j, k, flag;
654 1.11 christos while (1) {
655 1.1 cgd k = yylex();
656 1.11 christos switch (k) { /* get the token from the input and switch on
657 1.11 christos * it */
658 1.11 christos case 'h':
659 1.11 christos moveplayer(4);
660 1.11 christos return; /* west */
661 1.11 christos case 'H':
662 1.11 christos run(4);
663 1.11 christos return; /* west */
664 1.11 christos case 'l':
665 1.11 christos moveplayer(2);
666 1.11 christos return; /* east */
667 1.11 christos case 'L':
668 1.11 christos run(2);
669 1.11 christos return; /* east */
670 1.11 christos case 'j':
671 1.11 christos moveplayer(1);
672 1.11 christos return; /* south */
673 1.11 christos case 'J':
674 1.11 christos run(1);
675 1.11 christos return; /* south */
676 1.11 christos case 'k':
677 1.11 christos moveplayer(3);
678 1.11 christos return; /* north */
679 1.11 christos case 'K':
680 1.11 christos run(3);
681 1.11 christos return; /* north */
682 1.11 christos case 'u':
683 1.11 christos moveplayer(5);
684 1.11 christos return; /* northeast */
685 1.11 christos case 'U':
686 1.11 christos run(5);
687 1.11 christos return; /* northeast */
688 1.11 christos case 'y':
689 1.11 christos moveplayer(6);
690 1.11 christos return; /* northwest */
691 1.11 christos case 'Y':
692 1.11 christos run(6);
693 1.11 christos return; /* northwest */
694 1.11 christos case 'n':
695 1.11 christos moveplayer(7);
696 1.11 christos return; /* southeast */
697 1.11 christos case 'N':
698 1.11 christos run(7);
699 1.11 christos return; /* southeast */
700 1.11 christos case 'b':
701 1.11 christos moveplayer(8);
702 1.11 christos return; /* southwest */
703 1.11 christos case 'B':
704 1.11 christos run(8);
705 1.11 christos return; /* southwest */
706 1.11 christos
707 1.11 christos case '.':
708 1.11 christos if (yrepcount)
709 1.11 christos viewflag = 1;
710 1.11 christos return; /* stay here */
711 1.11 christos
712 1.11 christos case 'w':
713 1.11 christos yrepcount = 0;
714 1.11 christos wield();
715 1.11 christos return; /* wield a weapon */
716 1.11 christos
717 1.11 christos case 'W':
718 1.11 christos yrepcount = 0;
719 1.11 christos wear();
720 1.11 christos return; /* wear armor */
721 1.11 christos
722 1.11 christos case 'r':
723 1.11 christos yrepcount = 0;
724 1.11 christos if (c[BLINDCOUNT]) {
725 1.11 christos cursors();
726 1.11 christos lprcat("\nYou can't read anything when you're blind!");
727 1.11 christos } else if (c[TIMESTOP] == 0)
728 1.11 christos readscr();
729 1.11 christos return; /* to read a scroll */
730 1.11 christos
731 1.11 christos case 'q':
732 1.11 christos yrepcount = 0;
733 1.11 christos if (c[TIMESTOP] == 0)
734 1.11 christos quaff();
735 1.11 christos return; /* quaff a potion */
736 1.11 christos
737 1.11 christos case 'd':
738 1.11 christos yrepcount = 0;
739 1.11 christos if (c[TIMESTOP] == 0)
740 1.11 christos dropobj();
741 1.11 christos return; /* to drop an object */
742 1.11 christos
743 1.11 christos case 'c':
744 1.11 christos yrepcount = 0;
745 1.11 christos cast();
746 1.11 christos return; /* cast a spell */
747 1.11 christos
748 1.11 christos case 'i':
749 1.11 christos yrepcount = 0;
750 1.11 christos nomove = 1;
751 1.11 christos showstr();
752 1.11 christos return; /* status */
753 1.11 christos
754 1.11 christos case 'e':
755 1.11 christos yrepcount = 0;
756 1.11 christos if (c[TIMESTOP] == 0)
757 1.11 christos eatcookie();
758 1.11 christos return; /* to eat a fortune cookie */
759 1.11 christos
760 1.11 christos case 'D':
761 1.11 christos yrepcount = 0;
762 1.11 christos seemagic(0);
763 1.11 christos nomove = 1;
764 1.11 christos return; /* list spells and scrolls */
765 1.11 christos
766 1.11 christos case '?':
767 1.11 christos yrepcount = 0;
768 1.11 christos help();
769 1.11 christos nomove = 1;
770 1.11 christos return; /* give the help screen */
771 1.11 christos
772 1.11 christos case 'S':
773 1.11 christos clear();
774 1.11 christos lprcat("Saving . . .");
775 1.11 christos lflush();
776 1.11 christos savegame(savefilename);
777 1.11 christos wizard = 1;
778 1.11 christos died(-257); /* save the game - doesn't return */
779 1.11 christos
780 1.11 christos case 'Z':
781 1.11 christos yrepcount = 0;
782 1.11 christos if (c[LEVEL] > 9) {
783 1.11 christos oteleport(1);
784 1.11 christos return;
785 1.11 christos }
786 1.11 christos cursors();
787 1.11 christos lprcat("\nAs yet, you don't have enough experience to use teleportation");
788 1.11 christos return; /* teleport yourself */
789 1.11 christos
790 1.11 christos case '^': /* identify traps */
791 1.11 christos flag = yrepcount = 0;
792 1.11 christos cursors();
793 1.11 christos lprc('\n');
794 1.11 christos for (j = playery - 1; j < playery + 2; j++) {
795 1.11 christos if (j < 0)
796 1.11 christos j = 0;
797 1.11 christos if (j >= MAXY)
798 1.11 christos break;
799 1.11 christos for (i = playerx - 1; i < playerx + 2; i++) {
800 1.11 christos if (i < 0)
801 1.11 christos i = 0;
802 1.11 christos if (i >= MAXX)
803 1.11 christos break;
804 1.11 christos switch (item[i][j]) {
805 1.11 christos case OTRAPDOOR:
806 1.11 christos case ODARTRAP:
807 1.11 christos case OTRAPARROW:
808 1.11 christos case OTELEPORTER:
809 1.11 christos lprcat("\nIts ");
810 1.11 christos lprcat(objectname[item[i][j]]);
811 1.11 christos flag++;
812 1.11 christos };
813 1.11 christos }
814 1.11 christos }
815 1.11 christos if (flag == 0)
816 1.11 christos lprcat("\nNo traps are visible");
817 1.11 christos return;
818 1.1 cgd
819 1.1 cgd #if WIZID
820 1.11 christos case '_': /* this is the fudge player password for
821 1.11 christos * wizard mode */
822 1.11 christos yrepcount = 0;
823 1.11 christos cursors();
824 1.11 christos nomove = 1;
825 1.11 christos if (userid != wisid) {
826 1.11 christos lprcat("Sorry, you are not empowered to be a wizard.\n");
827 1.11 christos scbr(); /* system("stty -echo cbreak"); */
828 1.11 christos lflush();
829 1.11 christos return;
830 1.11 christos }
831 1.11 christos if (getpassword() == 0) {
832 1.11 christos scbr(); /* system("stty -echo cbreak"); */
833 1.11 christos return;
834 1.11 christos }
835 1.11 christos wizard = 1;
836 1.11 christos scbr(); /* system("stty -echo cbreak"); */
837 1.11 christos for (i = 0; i < 6; i++)
838 1.11 christos c[i] = 70;
839 1.11 christos iven[0] = iven[1] = 0;
840 1.11 christos take(OPROTRING, 50);
841 1.11 christos take(OLANCE, 25);
842 1.11 christos c[WIELD] = 1;
843 1.11 christos c[LANCEDEATH] = 1;
844 1.11 christos c[WEAR] = c[SHIELD] = -1;
845 1.11 christos raiseexperience(6000000L);
846 1.11 christos c[AWARENESS] += 25000;
847 1.11 christos {
848 1.11 christos int i, j;
849 1.11 christos for (i = 0; i < MAXY; i++)
850 1.11 christos for (j = 0; j < MAXX; j++)
851 1.11 christos know[j][i] = 1;
852 1.11 christos for (i = 0; i < SPNUM; i++)
853 1.11 christos spelknow[i] = 1;
854 1.11 christos for (i = 0; i < MAXSCROLL; i++)
855 1.11 christos scrollname[i] = scrollhide[i];
856 1.11 christos for (i = 0; i < MAXPOTION; i++)
857 1.11 christos potionname[i] = potionhide[i];
858 1.11 christos }
859 1.11 christos for (i = 0; i < MAXSCROLL; i++)
860 1.11 christos if (strlen(scrollname[i]) > 2) { /* no null items */
861 1.11 christos item[i][0] = OSCROLL;
862 1.11 christos iarg[i][0] = i;
863 1.11 christos }
864 1.11 christos for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--)
865 1.11 christos if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) { /* no null items */
866 1.11 christos item[i][0] = OPOTION;
867 1.11 christos iarg[i][0] = i - MAXX + MAXPOTION;
868 1.11 christos }
869 1.11 christos for (i = 1; i < MAXY; i++) {
870 1.11 christos item[0][i] = i;
871 1.11 christos iarg[0][i] = 0;
872 1.11 christos }
873 1.11 christos for (i = MAXY; i < MAXY + MAXX; i++) {
874 1.11 christos item[i - MAXY][MAXY - 1] = i;
875 1.11 christos iarg[i - MAXY][MAXY - 1] = 0;
876 1.11 christos }
877 1.11 christos for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) {
878 1.11 christos item[MAXX - 1][i - MAXX - MAXY] = i;
879 1.11 christos iarg[MAXX - 1][i - MAXX - MAXY] = 0;
880 1.11 christos }
881 1.11 christos c[GOLD] += 25000;
882 1.11 christos drawscreen();
883 1.11 christos return;
884 1.1 cgd #endif
885 1.1 cgd
886 1.11 christos case 'T':
887 1.11 christos yrepcount = 0;
888 1.11 christos cursors();
889 1.11 christos if (c[SHIELD] != -1) {
890 1.11 christos c[SHIELD] = -1;
891 1.11 christos lprcat("\nYour shield is off");
892 1.11 christos bottomline();
893 1.11 christos } else if (c[WEAR] != -1) {
894 1.11 christos c[WEAR] = -1;
895 1.11 christos lprcat("\nYour armor is off");
896 1.11 christos bottomline();
897 1.11 christos } else
898 1.11 christos lprcat("\nYou aren't wearing anything");
899 1.11 christos return;
900 1.1 cgd
901 1.11 christos case 'g':
902 1.11 christos cursors();
903 1.11 christos lprintf("\nThe stuff you are carrying presently weighs %d pounds", (long) packweight());
904 1.11 christos case ' ':
905 1.11 christos yrepcount = 0;
906 1.11 christos nomove = 1;
907 1.11 christos return;
908 1.1 cgd
909 1.11 christos case 'v':
910 1.11 christos yrepcount = 0;
911 1.11 christos cursors();
912 1.11 christos lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d", (long) VERSION, (long) SUBVERSION, (long) c[HARDGAME]);
913 1.11 christos if (wizard)
914 1.11 christos lprcat(" Wizard");
915 1.11 christos nomove = 1;
916 1.11 christos if (cheat)
917 1.11 christos lprcat(" Cheater");
918 1.11 christos lprcat(copyright);
919 1.11 christos return;
920 1.1 cgd
921 1.11 christos case 'Q':
922 1.11 christos yrepcount = 0;
923 1.11 christos quit();
924 1.11 christos nomove = 1;
925 1.11 christos return; /* quit */
926 1.11 christos
927 1.11 christos case 'L' - 64:
928 1.11 christos yrepcount = 0;
929 1.11 christos drawscreen();
930 1.11 christos nomove = 1;
931 1.11 christos return; /* look */
932 1.1 cgd
933 1.1 cgd #if WIZID
934 1.1 cgd #ifdef EXTRA
935 1.11 christos case 'A':
936 1.11 christos yrepcount = 0;
937 1.11 christos nomove = 1;
938 1.11 christos if (wizard) {
939 1.11 christos diag();
940 1.11 christos return;
941 1.11 christos } /* create diagnostic file */
942 1.11 christos return;
943 1.1 cgd #endif
944 1.1 cgd #endif
945 1.11 christos case 'P':
946 1.11 christos cursors();
947 1.11 christos if (outstanding_taxes > 0)
948 1.11 christos lprintf("\nYou presently owe %d gp in taxes.", (long) outstanding_taxes);
949 1.11 christos else
950 1.11 christos lprcat("\nYou do not owe any taxes.");
951 1.11 christos return;
952 1.11 christos };
953 1.1 cgd }
954 1.11 christos }
955 1.1 cgd
956 1.11 christos void
957 1.1 cgd parse2()
958 1.11 christos {
959 1.11 christos if (c[HASTEMONST])
960 1.11 christos movemonst();
961 1.11 christos movemonst(); /* move the monsters */
962 1.11 christos randmonst();
963 1.11 christos regen();
964 1.11 christos }
965 1.1 cgd
966 1.11 christos void
967 1.1 cgd run(dir)
968 1.11 christos int dir;
969 1.11 christos {
970 1.11 christos int i;
971 1.11 christos i = 1;
972 1.11 christos while (i) {
973 1.11 christos i = moveplayer(dir);
974 1.11 christos if (i > 0) {
975 1.11 christos if (c[HASTEMONST])
976 1.11 christos movemonst();
977 1.11 christos movemonst();
978 1.11 christos randmonst();
979 1.11 christos regen();
980 1.1 cgd }
981 1.11 christos if (hitflag)
982 1.11 christos i = 0;
983 1.11 christos if (i != 0)
984 1.11 christos showcell(playerx, playery);
985 1.1 cgd }
986 1.11 christos }
987 1.1 cgd
988 1.1 cgd /*
989 1.1 cgd function to wield a weapon
990 1.1 cgd */
991 1.11 christos void
992 1.11 christos wield()
993 1.11 christos {
994 1.11 christos int i;
995 1.11 christos while (1) {
996 1.11 christos if ((i = whatitem("wield")) == '\33')
997 1.11 christos return;
998 1.11 christos if (i != '.') {
999 1.11 christos if (i == '*')
1000 1.11 christos showwield();
1001 1.11 christos else if (iven[i - 'a'] == 0) {
1002 1.11 christos ydhi(i);
1003 1.11 christos return;
1004 1.11 christos } else if (iven[i - 'a'] == OPOTION) {
1005 1.11 christos ycwi(i);
1006 1.11 christos return;
1007 1.11 christos } else if (iven[i - 'a'] == OSCROLL) {
1008 1.11 christos ycwi(i);
1009 1.11 christos return;
1010 1.11 christos } else if ((c[SHIELD] != -1) && (iven[i - 'a'] == O2SWORD)) {
1011 1.11 christos lprcat("\nBut one arm is busy with your shield!");
1012 1.11 christos return;
1013 1.11 christos } else {
1014 1.11 christos c[WIELD] = i - 'a';
1015 1.11 christos if (iven[i - 'a'] == OLANCE)
1016 1.11 christos c[LANCEDEATH] = 1;
1017 1.11 christos else
1018 1.11 christos c[LANCEDEATH] = 0;
1019 1.11 christos bottomline();
1020 1.11 christos return;
1021 1.1 cgd }
1022 1.1 cgd }
1023 1.1 cgd }
1024 1.11 christos }
1025 1.1 cgd
1026 1.1 cgd /*
1027 1.1 cgd common routine to say you don't have an item
1028 1.1 cgd */
1029 1.11 christos void
1030 1.1 cgd ydhi(x)
1031 1.11 christos int x;
1032 1.11 christos {
1033 1.11 christos cursors();
1034 1.11 christos lprintf("\nYou don't have item %c!", x);
1035 1.11 christos }
1036 1.11 christos void
1037 1.1 cgd ycwi(x)
1038 1.11 christos int x;
1039 1.11 christos {
1040 1.11 christos cursors();
1041 1.11 christos lprintf("\nYou can't wield item %c!", x);
1042 1.11 christos }
1043 1.1 cgd
1044 1.1 cgd /*
1045 1.1 cgd function to wear armor
1046 1.1 cgd */
1047 1.11 christos void
1048 1.1 cgd wear()
1049 1.11 christos {
1050 1.11 christos int i;
1051 1.11 christos while (1) {
1052 1.11 christos if ((i = whatitem("wear")) == '\33')
1053 1.11 christos return;
1054 1.11 christos if (i != '.') {
1055 1.11 christos if (i == '*')
1056 1.11 christos showwear();
1057 1.11 christos else
1058 1.11 christos switch (iven[i - 'a']) {
1059 1.11 christos case 0:
1060 1.11 christos ydhi(i);
1061 1.11 christos return;
1062 1.11 christos case OLEATHER:
1063 1.11 christos case OCHAIN:
1064 1.11 christos case OPLATE:
1065 1.11 christos case OSTUDLEATHER:
1066 1.11 christos case ORING:
1067 1.11 christos case OSPLINT:
1068 1.11 christos case OPLATEARMOR:
1069 1.11 christos case OSSPLATE:
1070 1.11 christos if (c[WEAR] != -1) {
1071 1.11 christos lprcat("\nYou're already wearing some armor");
1072 1.11 christos return;
1073 1.11 christos }
1074 1.11 christos c[WEAR] = i - 'a';
1075 1.11 christos bottomline();
1076 1.11 christos return;
1077 1.11 christos case OSHIELD:
1078 1.11 christos if (c[SHIELD] != -1) {
1079 1.11 christos lprcat("\nYou are already wearing a shield");
1080 1.11 christos return;
1081 1.11 christos }
1082 1.11 christos if (iven[c[WIELD]] == O2SWORD) {
1083 1.11 christos lprcat("\nYour hands are busy with the two handed sword!");
1084 1.11 christos return;
1085 1.11 christos }
1086 1.11 christos c[SHIELD] = i - 'a';
1087 1.11 christos bottomline();
1088 1.11 christos return;
1089 1.11 christos default:
1090 1.11 christos lprcat("\nYou can't wear that!");
1091 1.1 cgd };
1092 1.1 cgd }
1093 1.1 cgd }
1094 1.11 christos }
1095 1.1 cgd
1096 1.1 cgd /*
1097 1.1 cgd function to drop an object
1098 1.1 cgd */
1099 1.11 christos void
1100 1.1 cgd dropobj()
1101 1.11 christos {
1102 1.11 christos int i;
1103 1.11 christos char *p;
1104 1.11 christos long amt;
1105 1.1 cgd p = &item[playerx][playery];
1106 1.11 christos while (1) {
1107 1.11 christos if ((i = whatitem("drop")) == '\33')
1108 1.11 christos return;
1109 1.11 christos if (i == '*')
1110 1.11 christos showstr();
1111 1.11 christos else {
1112 1.11 christos if (i == '.') { /* drop some gold */
1113 1.11 christos if (*p) {
1114 1.11 christos lprcat("\nThere's something here already!");
1115 1.11 christos return;
1116 1.11 christos }
1117 1.1 cgd lprcat("\n\n");
1118 1.11 christos cl_dn(1, 23);
1119 1.1 cgd lprcat("How much gold do you drop? ");
1120 1.11 christos if ((amt = readnum((long) c[GOLD])) == 0)
1121 1.11 christos return;
1122 1.11 christos if (amt > c[GOLD]) {
1123 1.11 christos lprcat("\nYou don't have that much!");
1124 1.11 christos return;
1125 1.11 christos }
1126 1.11 christos if (amt <= 32767) {
1127 1.11 christos *p = OGOLDPILE;
1128 1.11 christos i = amt;
1129 1.11 christos } else if (amt <= 327670L) {
1130 1.11 christos *p = ODGOLD;
1131 1.11 christos i = amt / 10;
1132 1.11 christos amt = 10 * i;
1133 1.11 christos } else if (amt <= 3276700L) {
1134 1.11 christos *p = OMAXGOLD;
1135 1.11 christos i = amt / 100;
1136 1.11 christos amt = 100 * i;
1137 1.11 christos } else if (amt <= 32767000L) {
1138 1.11 christos *p = OKGOLD;
1139 1.11 christos i = amt / 1000;
1140 1.11 christos amt = 1000 * i;
1141 1.11 christos } else {
1142 1.11 christos *p = OKGOLD;
1143 1.11 christos i = 32767;
1144 1.11 christos amt = 32767000L;
1145 1.1 cgd }
1146 1.11 christos c[GOLD] -= amt;
1147 1.11 christos lprintf("You drop %d gold pieces", (long) amt);
1148 1.11 christos iarg[playerx][playery] = i;
1149 1.11 christos bottomgold();
1150 1.11 christos know[playerx][playery] = 0;
1151 1.11 christos dropflag = 1;
1152 1.11 christos return;
1153 1.11 christos }
1154 1.11 christos drop_object(i - 'a');
1155 1.1 cgd return;
1156 1.1 cgd }
1157 1.1 cgd }
1158 1.11 christos }
1159 1.1 cgd
1160 1.1 cgd /*
1161 1.1 cgd * readscr() Subroutine to read a scroll one is carrying
1162 1.1 cgd */
1163 1.11 christos void
1164 1.1 cgd readscr()
1165 1.11 christos {
1166 1.11 christos int i;
1167 1.11 christos while (1) {
1168 1.11 christos if ((i = whatitem("read")) == '\33')
1169 1.11 christos return;
1170 1.11 christos if (i != '.') {
1171 1.11 christos if (i == '*')
1172 1.11 christos showread();
1173 1.11 christos else {
1174 1.11 christos if (iven[i - 'a'] == OSCROLL) {
1175 1.11 christos read_scroll(ivenarg[i - 'a']);
1176 1.11 christos iven[i - 'a'] = 0;
1177 1.11 christos return;
1178 1.11 christos }
1179 1.11 christos if (iven[i - 'a'] == OBOOK) {
1180 1.11 christos readbook(ivenarg[i - 'a']);
1181 1.11 christos iven[i - 'a'] = 0;
1182 1.11 christos return;
1183 1.11 christos }
1184 1.11 christos if (iven[i - 'a'] == 0) {
1185 1.11 christos ydhi(i);
1186 1.11 christos return;
1187 1.1 cgd }
1188 1.11 christos lprcat("\nThere's nothing on it to read");
1189 1.11 christos return;
1190 1.1 cgd }
1191 1.1 cgd }
1192 1.1 cgd }
1193 1.11 christos }
1194 1.1 cgd
1195 1.1 cgd /*
1196 1.1 cgd * subroutine to eat a cookie one is carrying
1197 1.1 cgd */
1198 1.11 christos void
1199 1.1 cgd eatcookie()
1200 1.1 cgd {
1201 1.11 christos int i;
1202 1.11 christos char *p;
1203 1.11 christos while (1) {
1204 1.11 christos if ((i = whatitem("eat")) == '\33')
1205 1.11 christos return;
1206 1.14 veego if (i != '.') {
1207 1.11 christos if (i == '*')
1208 1.11 christos showeat();
1209 1.11 christos else {
1210 1.11 christos if (iven[i - 'a'] == OCOOKIE) {
1211 1.11 christos lprcat("\nThe cookie was delicious.");
1212 1.11 christos iven[i - 'a'] = 0;
1213 1.11 christos if (!c[BLINDCOUNT]) {
1214 1.11 christos if ((p = fortune()) != NULL) {
1215 1.11 christos lprcat(" Inside you find a scrap of paper that says:\n");
1216 1.11 christos lprcat(p);
1217 1.1 cgd }
1218 1.1 cgd }
1219 1.11 christos return;
1220 1.11 christos }
1221 1.11 christos if (iven[i - 'a'] == 0) {
1222 1.11 christos ydhi(i);
1223 1.11 christos return;
1224 1.11 christos }
1225 1.11 christos lprcat("\nYou can't eat that!");
1226 1.1 cgd return;
1227 1.1 cgd }
1228 1.14 veego }
1229 1.1 cgd }
1230 1.1 cgd }
1231 1.1 cgd
1232 1.1 cgd /*
1233 1.1 cgd * subroutine to quaff a potion one is carrying
1234 1.1 cgd */
1235 1.11 christos void
1236 1.1 cgd quaff()
1237 1.11 christos {
1238 1.11 christos int i;
1239 1.11 christos while (1) {
1240 1.11 christos if ((i = whatitem("quaff")) == '\33')
1241 1.11 christos return;
1242 1.11 christos if (i != '.') {
1243 1.11 christos if (i == '*')
1244 1.11 christos showquaff();
1245 1.11 christos else {
1246 1.11 christos if (iven[i - 'a'] == OPOTION) {
1247 1.11 christos quaffpotion(ivenarg[i - 'a']);
1248 1.11 christos iven[i - 'a'] = 0;
1249 1.11 christos return;
1250 1.11 christos }
1251 1.11 christos if (iven[i - 'a'] == 0) {
1252 1.11 christos ydhi(i);
1253 1.11 christos return;
1254 1.1 cgd }
1255 1.11 christos lprcat("\nYou wouldn't want to quaff that, would you? ");
1256 1.11 christos return;
1257 1.1 cgd }
1258 1.1 cgd }
1259 1.1 cgd }
1260 1.11 christos }
1261 1.1 cgd
1262 1.1 cgd /*
1263 1.1 cgd function to ask what player wants to do
1264 1.1 cgd */
1265 1.11 christos int
1266 1.1 cgd whatitem(str)
1267 1.11 christos char *str;
1268 1.11 christos {
1269 1.11 christos int i;
1270 1.11 christos cursors();
1271 1.11 christos lprintf("\nWhat do you want to %s [* for all] ? ", str);
1272 1.11 christos i = 0;
1273 1.11 christos while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.'))
1274 1.11 christos i = getchar();
1275 1.11 christos if (i == '\33')
1276 1.11 christos lprcat(" aborted");
1277 1.11 christos return (i);
1278 1.11 christos }
1279 1.1 cgd
1280 1.1 cgd /*
1281 1.1 cgd subroutine to get a number from the player
1282 1.1 cgd and allow * to mean return amt, else return the number entered
1283 1.1 cgd */
1284 1.11 christos unsigned long
1285 1.11 christos readnum(mx)
1286 1.11 christos long mx;
1287 1.11 christos {
1288 1.11 christos int i;
1289 1.11 christos unsigned long amt = 0;
1290 1.1 cgd sncbr();
1291 1.11 christos if ((i = getchar()) == '*')
1292 1.11 christos amt = mx; /* allow him to say * for all gold */
1293 1.1 cgd else
1294 1.11 christos while (i != '\n') {
1295 1.11 christos if (i == '\033') {
1296 1.11 christos scbr();
1297 1.11 christos lprcat(" aborted");
1298 1.11 christos return (0);
1299 1.11 christos }
1300 1.11 christos if ((i <= '9') && (i >= '0') && (amt < 99999999))
1301 1.11 christos amt = amt * 10 + i - '0';
1302 1.1 cgd i = getchar();
1303 1.11 christos }
1304 1.11 christos scbr();
1305 1.11 christos return (amt);
1306 1.11 christos }
1307 1.1 cgd
1308 1.1 cgd #ifdef HIDEBYLINK
1309 1.1 cgd /*
1310 1.1 cgd * routine to zero every byte in a string
1311 1.1 cgd */
1312 1.11 christos void
1313 1.1 cgd szero(str)
1314 1.11 christos char *str;
1315 1.11 christos {
1316 1.1 cgd while (*str)
1317 1.1 cgd *str++ = 0;
1318 1.11 christos }
1319 1.11 christos #endif /* HIDEBYLINK */
1320