Initial import from FreeBSD RELENG_4:
[games.git] / games / larn / main.c
1 /*      main.c          */
2 /* $FreeBSD: src/games/larn/main.c,v 1.9 1999/11/30 03:48:59 billf Exp $ */
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include "header.h"
6 #include <pwd.h>
7 static const char copyright[]="\nLarn is copyrighted 1986 by Noah Morgan.\n";
8 int srcount=0;  /* line counter for showstr()   */
9 int dropflag=0; /* if 1 then don't lookforobject() next round */
10 int rmst=80;    /*      random monster creation counter         */
11 int userid;             /* the players login user id number */
12 char nowelcome=0,nomove=0; /* if (nomove) then don't count next iteration as a move */
13 static char viewflag=0;
14         /*      if viewflag then we have done a 99 stay here and don't showcell in the main loop */
15 char restorflag=0;      /* 1 means restore has been done        */
16 static char cmdhelp[] = "\
17 Cmd line format: larn [-slicnh] [-o<optsifle>] [-##] [++]\n\
18   -s   show the scoreboard\n\
19   -l   show the logfile (wizard id only)\n\
20   -i   show scoreboard with inventories of dead characters\n\
21   -c   create new scoreboard (wizard id only)\n\
22   -n   suppress welcome message on starting game\n\
23   -##  specify level of difficulty (example: -5)\n\
24   -h   print this help text\n\
25   ++   restore game from checkpoint file\n\
26   -o<optsfile>   specify .larnopts filename to be used instead of \"~/.larnopts\"\n\
27 ";
28 #ifdef VT100
29 static char *termtypes[] = { "vt100", "vt101", "vt102", "vt103", "vt125",
30         "vt131", "vt140", "vt180", "vt220", "vt240", "vt241", "vt320", "vt340",
31         "vt341"  };
32 #endif VT100
33 /*
34         ************
35         MAIN PROGRAM
36         ************
37  */
38 main(argc,argv)
39         int argc;
40         char **argv;
41         {
42         int i,j;
43         int hard;
44         char *ptr=0,*ttype;
45         struct passwd *pwe;
46         struct stat sb;
47
48 /*
49  *      first task is to identify the player
50  */
51 #ifndef VT100
52         init_term();    /* setup the terminal (find out what type) for termcap */
53 #endif VT100
54         if (((ptr = getlogin()) == 0) || (*ptr==0)) {   /* try to get login name */
55           if (pwe=getpwuid(getuid())) /* can we get it from /etc/passwd? */
56                 ptr = pwe->pw_name;
57           else
58           if ((ptr = getenv("USER")) == 0)
59                 if ((ptr = getenv("LOGNAME")) == 0)
60                   {
61                   noone: write(2, "Can't find your logname.  Who Are You?\n",39);
62                                  exit(1);
63                   }
64         }
65         if (ptr==0) goto noone;
66         if (strlen(ptr)==0) goto noone;
67 /*
68  *      second task is to prepare the pathnames the player will need
69  */
70         strcpy(loginname,ptr); /* save loginname of the user for logging purposes */
71         strcpy(logname,ptr);    /* this will be overwritten with the players name */
72         if ((ptr = getenv("HOME")) == 0) ptr = ".";
73         strcpy(savefilename, ptr);
74         strcat(savefilename, "/Larn.sav");      /* save file name in home directory */
75         sprintf(optsfile, "%s/.larnopts",ptr);  /* the .larnopts filename */
76
77 /*
78  *      now malloc the memory for the dungeon
79  */
80         cell = (struct cel *)malloc(sizeof(struct cel)*(MAXLEVEL+MAXVLEVEL)*MAXX*MAXY);
81         if (cell == 0) died(-285);      /* malloc failure */
82         lpbuf    = malloc((5* BUFBIG)>>2);      /* output buffer */
83         inbuffer = malloc((5*MAXIBUF)>>2);      /* output buffer */
84         if ((lpbuf==0) || (inbuffer==0)) died(-285); /* malloc() failure */
85
86         lcreat((char*)0);       newgame();              /*      set the initial clock  */ hard= -1;
87
88 #ifdef VT100
89 /*
90  *      check terminal type to avoid users who have not vt100 type terminals
91  */
92         ttype = getenv("TERM");
93         for (j=1, i=0; i<sizeof(termtypes)/sizeof(char *); i++)
94                 if (strcmp(ttype,termtypes[i]) == 0) { j=0;  break; }
95         if (j)
96                 {
97                 lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n"); lflush();
98                 exit(1);
99                 }
100 #endif VT100
101
102 /*
103  *      now make scoreboard if it is not there (don't clear)
104  */
105         if (stat(scorefile,&sb) < 0 || sb.st_size == 0) /* not there */
106                 makeboard();
107
108 /*
109  *      now process the command line arguments
110  */
111         for (i=1; i<argc; i++)
112                 {
113                 if (argv[i][0] == '-')
114                   switch(argv[i][1])
115                         {
116                         case 's': showscores();  exit(0);  /* show scoreboard   */
117
118                         case 'l': /* show log file     */
119                                                 diedlog();              exit(0);
120
121                         case 'i': showallscores();  exit(0);  /* show all scoreboard */
122
123                         case 'c':                /* anyone with password can create scoreboard */
124                                           lprcat("Preparing to initialize the scoreboard.\n");
125                                           if (getpassword() != 0)  /*make new scoreboard*/
126                                                         {
127                                                         makeboard(); lprc('\n'); showscores();
128                                                         }
129                                           exit(0);
130
131                         case 'n':       /* no welcome msg       */ nowelcome=1; argv[i][0]=0; break;
132
133                         case '0': case '1': case '2': case '3': case '4': case '5':
134                         case '6': case '7': case '8': case '9': /* for hardness */
135                                                 sscanf(&argv[i][1],"%d",&hard);
136                                                 break;
137
138                         case 'h':       /* print out command line arguments */
139                                                 write(1,cmdhelp,sizeof(cmdhelp));  exit(0);
140
141                         case 'o':       /* specify a .larnopts filename */
142                                                 strncpy(optsfile,argv[i]+2,127);  break;
143
144                         default:        printf("Unknown option <%s>\n",argv[i]);  exit(1);
145                         };
146
147                 if (argv[i][0] == '+')
148                         {
149                         clear();        restorflag = 1;
150                         if (argv[i][1] == '+')
151                                 {
152                                 hitflag=1; restoregame(ckpfile); /* restore checkpointed game */
153                                 }
154                         i = argc;
155                         }
156                 }
157
158         readopts();             /* read the options file if there is one */
159
160
161 #ifdef UIDSCORE
162         userid = geteuid();     /* obtain the user's effective id number */
163 #else UIDSCORE
164         userid = getplid(logname);      /* obtain the players id number */
165 #endif UIDSCORE
166         if (userid < 0) { write(2,"Can't obtain playerid\n",22); exit(1); }
167
168 #ifdef HIDEBYLINK
169 /*
170  *      this section of code causes the program to look like something else to ps
171  */
172         if (strcmp(psname,argv[0])) /* if a different process name only */
173                 {
174                 if ((i=access(psname,1)) < 0)
175                         {               /* link not there */
176                         if (link(argv[0],psname)>=0)
177                                 {
178                                 argv[0] = psname;   execv(psname,argv);
179                                 }
180                         }
181                 else
182                         unlink(psname);
183                 }
184
185         for (i=1; i<argc; i++)
186                 {
187                 szero(argv[i]); /* zero the argument to avoid ps snooping */
188                 }
189 #endif HIDEBYLINK
190
191         if (access(savefilename,0)==0)  /* restore game if need to */
192                 {
193                 clear();        restorflag = 1;
194                 hitflag=1;      restoregame(savefilename);  /* restore last game        */
195                 }
196         sigsetup();             /* trap all needed signals      */
197         sethard(hard);  /* set up the desired difficulty                                */
198         setupvt100();   /*      setup the terminal special mode                         */
199         if (c[HP]==0)   /* create new game */
200                 {
201                 makeplayer();   /*      make the character that will play                       */
202                 newcavelevel(0);/*      make the dungeon                                                        */
203                 predostuff = 1; /* tell signals that we are in the welcome screen */
204                 if (nowelcome==0) welcome();     /* welcome the player to the game */
205                 }
206         drawscreen();   /*      show the initial dungeon                                        */
207         predostuff = 2; /* tell the trap functions that they must do a showplayer()
208                                                 from here on */
209         /* nice(1); */  /* games should be run niced */
210         yrepcount = hit2flag = 0;
211         while (1)
212                 {
213                 if (dropflag==0) lookforobject(); /* see if there is an object here     */
214                         else dropflag=0; /* don't show it just dropped an item */
215                 if (hitflag==0) { if (c[HASTEMONST]) movemonst(); movemonst(); }        /*      move the monsters               */
216                 if (viewflag==0) showcell(playerx,playery); else viewflag=0;    /*      show stuff around player        */
217                 if (hit3flag) flushall();
218                 hitflag=hit3flag=0;     nomove=1;
219                 bot_linex();    /* update bottom line */
220                 while (nomove)
221                         {
222                         if (hit3flag) flushall();
223                         nomove=0; parse();
224                         }       /*      get commands and make moves     */
225                 regen();                        /*      regenerate hp and spells                        */
226                 if (c[TIMESTOP]==0)
227                         if (--rmst <= 0)
228                                 { rmst = 120-(level<<2); fillmonst(makemonst(level)); }
229                 }
230         }
231 \f
232 /*
233         showstr()
234
235         show character's inventory
236  */
237 showstr()
238         {
239         int i,number;
240         for (number=3, i=0; i<26; i++)
241                 if (iven[i]) number++;  /* count items in inventory */
242         t_setup(number);        qshowstr();       t_endup(number);
243         }
244
245 qshowstr()
246         {
247         int i,j,k,sigsav;
248         srcount=0;  sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
249         if (c[GOLD]) { lprintf(".)   %d gold pieces",(long)c[GOLD]); srcount++; }
250         for (k=26; k>=0; k--)
251           if (iven[k])
252                 {  for (i=22; i<84; i++)
253                          for (j=0; j<=k; j++)  if (i==iven[j])  show3(j); k=0; }
254
255         lprintf("\nElapsed time is %d.  You have %d mobuls left",(long)((gtime+99)/100+1),(long)((TIMELIMIT-gtime)/100));
256         more();         nosignal=sigsav;
257         }
258
259 /*
260  *      subroutine to clear screen depending on # lines to display
261  */
262 t_setup(count)
263         int count;
264         {
265         if (count<20)  /* how do we clear the screen? */
266                 {
267                 cl_up(79,count);  cursor(1,1);
268                 }
269         else
270                 {
271                 resetscroll(); clear();
272                 }
273         }
274
275 /*
276  *      subroutine to restore normal display screen depending on t_setup()
277  */
278 t_endup(count)
279         int count;
280         {
281         if (count<18)  /* how did we clear the screen? */
282                 draws(0,MAXX,0,(count>MAXY) ? MAXY : count);
283         else
284                 {
285                 drawscreen(); setscroll();
286                 }
287         }
288
289 /*
290         function to show the things player is wearing only
291  */
292 showwear()
293         {
294         int i,j,sigsav,count;
295         sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
296         srcount=0;
297
298          for (count=2,j=0; j<=26; j++)   /* count number of items we will display */
299            if (i=iven[j])
300                 switch(i)
301                         {
302                         case OLEATHER:  case OPLATE:    case OCHAIN:
303                         case ORING:             case OSTUDLEATHER:      case OSPLINT:
304                         case OPLATEARMOR:       case OSSPLATE:  case OSHIELD:
305                         count++;
306                         };
307
308         t_setup(count);
309
310         for (i=22; i<84; i++)
311                  for (j=0; j<=26; j++)
312                    if (i==iven[j])
313                         switch(i)
314                                 {
315                                 case OLEATHER:  case OPLATE:    case OCHAIN:
316                                 case ORING:             case OSTUDLEATHER:      case OSPLINT:
317                                 case OPLATEARMOR:       case OSSPLATE:  case OSHIELD:
318                                 show3(j);
319                                 };
320         more();         nosignal=sigsav;        t_endup(count);
321         }
322
323 /*
324         function to show the things player can wield only
325  */
326 showwield()
327         {
328         int i,j,sigsav,count;
329         sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
330         srcount=0;
331
332          for (count=2,j=0; j<=26; j++)  /* count how many items */
333            if (i=iven[j])
334                 switch(i)
335                         {
336                         case ODIAMOND:  case ORUBY:  case OEMERALD:  case OSAPPHIRE:
337                         case OBOOK:     case OCHEST:  case OLARNEYE: case ONOTHEFT:
338                         case OSPIRITSCARAB:  case OCUBEofUNDEAD:
339                         case OPOTION:   case OSCROLL:  break;
340                         default:  count++;
341                         };
342
343         t_setup(count);
344
345         for (i=22; i<84; i++)
346                  for (j=0; j<=26; j++)
347                    if (i==iven[j])
348                         switch(i)
349                                 {
350                                 case ODIAMOND:  case ORUBY:  case OEMERALD:  case OSAPPHIRE:
351                                 case OBOOK:     case OCHEST:  case OLARNEYE: case ONOTHEFT:
352                                 case OSPIRITSCARAB:  case OCUBEofUNDEAD:
353                                 case OPOTION:   case OSCROLL:  break;
354                                 default:  show3(j);
355                                 };
356         more();         nosignal=sigsav;        t_endup(count);
357         }
358
359 /*
360  *      function to show the things player can read only
361  */
362 showread()
363         {
364         int i,j,sigsav,count;
365         sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
366         srcount=0;
367
368         for (count=2,j=0; j<=26; j++)
369                 switch(iven[j])
370                         {
371                         case OBOOK:     case OSCROLL:   count++;
372                         };
373         t_setup(count);
374
375         for (i=22; i<84; i++)
376                  for (j=0; j<=26; j++)
377                    if (i==iven[j])
378                         switch(i)
379                                 {
380                                 case OBOOK:     case OSCROLL:   show3(j);
381                                 };
382         more();         nosignal=sigsav;        t_endup(count);
383         }
384
385 /*
386  *      function to show the things player can eat only
387  */
388 showeat()
389         {
390         int i,j,sigsav,count;
391         sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
392         srcount=0;
393
394         for (count=2,j=0; j<=26; j++)
395                 switch(iven[j])
396                         {
397                         case OCOOKIE:   count++;
398                         };
399         t_setup(count);
400
401         for (i=22; i<84; i++)
402                  for (j=0; j<=26; j++)
403                    if (i==iven[j])
404                         switch(i)
405                                 {
406                                 case OCOOKIE:   show3(j);
407                                 };
408         more();         nosignal=sigsav;        t_endup(count);
409         }
410
411 /*
412         function to show the things player can quaff only
413  */
414 showquaff()
415         {
416         int i,j,sigsav,count;
417         sigsav=nosignal;  nosignal=1; /* don't allow ^c etc */
418         srcount=0;
419
420         for (count=2,j=0; j<=26; j++)
421                 switch(iven[j])
422                         {
423                         case OPOTION:   count++;
424                         };
425         t_setup(count);
426
427         for (i=22; i<84; i++)
428                  for (j=0; j<=26; j++)
429                    if (i==iven[j])
430                         switch(i)
431                                 {
432                                 case OPOTION:   show3(j);
433                                 };
434         more();         nosignal=sigsav;                t_endup(count);
435         }
436
437 show1(idx,str2)
438         int idx;
439         char *str2[];
440         {
441         if (str2==0)  lprintf("\n%c)   %s",idx+'a',objectname[iven[idx]]);
442         else if (*str2[ivenarg[idx]]==0)  lprintf("\n%c)   %s",idx+'a',objectname[iven[idx]]);
443         else lprintf("\n%c)   %s of%s",idx+'a',objectname[iven[idx]],str2[ivenarg[idx]]);
444         }
445
446 show3(index)
447         int index;
448         {
449         switch(iven[index])
450                 {
451                 case OPOTION:   show1(index,potionname);  break;
452                 case OSCROLL:   show1(index,scrollname);  break;
453
454                 case OLARNEYE:          case OBOOK:                     case OSPIRITSCARAB:
455                 case ODIAMOND:          case ORUBY:                     case OCUBEofUNDEAD:
456                 case OEMERALD:          case OCHEST:            case OCOOKIE:
457                 case OSAPPHIRE:         case ONOTHEFT:          show1(index,(char **)0);  break;
458
459                 default:                lprintf("\n%c)   %s",index+'a',objectname[iven[index]]);
460                                                 if (ivenarg[index]>0) lprintf(" + %d",(long)ivenarg[index]);
461                                                 else if (ivenarg[index]<0) lprintf(" %d",(long)ivenarg[index]);
462                                                 break;
463                 }
464         if (c[WIELD]==index) lprcat(" (weapon in hand)");
465         if ((c[WEAR]==index) || (c[SHIELD]==index))  lprcat(" (being worn)");
466         if (++srcount>=22) { srcount=0; more(); clear(); }
467         }
468
469 /*
470         subroutine to randomly create monsters if needed
471  */
472 randmonst()
473         {
474         if (c[TIMESTOP]) return;        /*      don't make monsters if time is stopped  */
475         if (--rmst <= 0)
476                 {
477                 rmst = 120 - (level<<2);  fillmonst(makemonst(level));
478                 }
479         }
480
481 \f
482 /*
483         parse()
484
485         get and execute a command
486  */
487 parse()
488         {
489         int i,j,k,flag;
490         while   (1)
491                 {
492                 k = yylex();
493                 switch(k)       /*      get the token from the input and switch on it   */
494                         {
495                         case 'h':       moveplayer(4);  return;         /*      west            */
496                         case 'H':       run(4);                 return;         /*      west            */
497                         case 'l':       moveplayer(2);  return;         /*      east            */
498                         case 'L':       run(2);                 return;         /*      east            */
499                         case 'j':       moveplayer(1);  return;         /*      south           */
500                         case 'J':       run(1);                 return;         /*      south           */
501                         case 'k':       moveplayer(3);  return;         /*      north           */
502                         case 'K':       run(3);                 return;         /*      north           */
503                         case 'u':       moveplayer(5);  return;         /*      northeast       */
504                         case 'U':       run(5);                 return;         /*      northeast       */
505                         case 'y':       moveplayer(6);  return;         /*      northwest       */
506                         case 'Y':       run(6);                 return;         /*      northwest       */
507                         case 'n':       moveplayer(7);  return;         /*      southeast       */
508                         case 'N':       run(7);                 return;         /*      southeast       */
509                         case 'b':       moveplayer(8);  return;         /*      southwest       */
510                         case 'B':       run(8);                 return;         /*      southwest       */
511
512                         case '.':       if (yrepcount) viewflag=1; return;              /*      stay here               */
513
514                         case 'w':       yrepcount=0;    wield();        return;         /*      wield a weapon */
515
516                         case 'W':       yrepcount=0;    wear();         return; /*      wear armor      */
517
518                         case 'r':       yrepcount=0;
519                                                 if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else
520                                                 if (c[TIMESTOP]==0) readscr(); return;          /*      to read a scroll        */
521
522                         case 'q':       yrepcount=0;    if (c[TIMESTOP]==0) quaff();    return; /*      quaff a potion          */
523
524                         case 'd':       yrepcount=0;    if (c[TIMESTOP]==0) dropobj(); return;  /*      to drop an object       */
525
526                         case 'c':       yrepcount=0;    cast();         return;         /*      cast a spell    */
527
528                         case 'i':       yrepcount=0;    nomove=1;  showstr();   return;         /*      status          */
529
530                         case 'e':       yrepcount=0;
531                                                 if (c[TIMESTOP]==0) eatcookie(); return;        /*      to eat a fortune cookie */
532
533                         case 'D':       yrepcount=0;    seemagic(0);    nomove=1; return;       /*      list spells and scrolls */
534
535                         case '?':       yrepcount=0;    help(); nomove=1; return;       /*      give the help screen*/
536
537                         case 'S':       clear();  lprcat("Saving . . ."); lflush();
538                                                 savegame(savefilename); wizard=1; died(-257);   /*      save the game - doesn't return  */
539
540                         case 'Z':       yrepcount=0;    if (c[LEVEL]>9) { oteleport(1); return; }
541                                                 cursors(); lprcat("\nAs yet, you don't have enough experience to use teleportation");
542                                                 return; /*      teleport yourself       */
543
544                         case '^':       /* identify traps */  flag=yrepcount=0;  cursors();
545                                                 lprc('\n');  for (j=playery-1; j<playery+2; j++)
546                                                         {
547                                                         if (j < 0) j=0;         if (j >= MAXY) break;
548                                                         for (i=playerx-1; i<playerx+2; i++)
549                                                                 {
550                                                                 if (i < 0) i=0; if (i >= MAXX) break;
551                                                                 switch(item[i][j])
552                                                                         {
553                                                                         case OTRAPDOOR:         case ODARTRAP:
554                                                                         case OTRAPARROW:        case OTELEPORTER:
555                                                                                 lprcat("\nIts "); lprcat(objectname[item[i][j]]);  flag++;
556                                                                         };
557                                                                 }
558                                                         }
559                                                 if (flag==0) lprcat("\nNo traps are visible");
560                                                 return;
561
562 #if WIZID
563                         case '_':       /*      this is the fudge player password for wizard mode*/
564                                                 yrepcount=0;    cursors(); nomove=1;
565                                                 if (userid!=wisid)
566                                                         {
567                                                         lprcat("Sorry, you are not empowered to be a wizard.\n");
568                                                         scbr(); /* system("stty -echo cbreak"); */
569                                                         lflush();  return;
570                                                         }
571                                                 if (getpassword()==0)
572                                                         {
573                                                         scbr(); /* system("stty -echo cbreak"); */ return;
574                                                         }
575                                                 wizard=1;  scbr(); /* system("stty -echo cbreak"); */
576                                                 for (i=0; i<6; i++)  c[i]=70;  iven[0]=iven[1]=0;
577                                                 take(OPROTRING,50);   take(OLANCE,25);  c[WIELD]=1;
578                                                 c[LANCEDEATH]=1;   c[WEAR] = c[SHIELD] = -1;
579                                                 raiseexperience(6000000L);  c[AWARENESS] += 25000;
580                                                 {
581                                                 int i,j;
582                                                 for (i=0; i<MAXY; i++)
583                                                         for (j=0; j<MAXX; j++)  know[j][i]=1;
584                                                 for (i=0; i<SPNUM; i++) spelknow[i]=1;
585                                                 for (i=0; i<MAXSCROLL; i++)  scrollname[i][0]=' ';
586                                                 for (i=0; i<MAXPOTION; i++)  potionname[i][0]=' ';
587                                                 }
588                                                 for (i=0; i<MAXSCROLL; i++)
589                                                   if (strlen(scrollname[i])>2) /* no null items */
590                                                         { item[i][0]=OSCROLL; iarg[i][0]=i; }
591                                                 for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--)
592                                                   if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */
593                                                         { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; }
594                                                 for (i=1; i<MAXY; i++)
595                                                         { item[0][i]=i; iarg[0][i]=0; }
596                                                 for (i=MAXY; i<MAXY+MAXX; i++)
597                                                         { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; }
598                                                 for (i=MAXX+MAXY; i<MAXX+MAXY+MAXY; i++)
599                                                         { item[MAXX-1][i-MAXX-MAXY]=i; iarg[MAXX-1][i-MAXX-MAXY]=0; }
600                                                 c[GOLD]+=25000; drawscreen();   return;
601 #endif
602
603                         case 'T':       yrepcount=0;    cursors();  if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else
604                                                                                 if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); }
605                                                 else lprcat("\nYou aren't wearing anything");
606                                                 return;
607
608                         case 'g':       cursors();
609                                                 lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight());
610                         case ' ':       yrepcount=0;    nomove=1;  return;
611
612                         case 'v':       yrepcount=0;    cursors();
613                                                 lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)c[HARDGAME]);
614                                                 if (wizard) lprcat(" Wizard"); nomove=1;
615                                                 if (cheat) lprcat(" Cheater");
616                                                 lprcat(copyright);
617                                                 return;
618
619                         case 'Q':       yrepcount=0;    quit(); nomove=1;       return; /*      quit            */
620
621                         case 'L'-64:  yrepcount=0;      drawscreen();  nomove=1; return;        /*      look            */
622
623 #if WIZID
624 #ifdef EXTRA
625                         case 'A':       yrepcount=0;    nomove=1; if (wizard) { diag(); return; }  /*   create diagnostic file */
626                                                 return;
627 #endif
628 #endif
629                         case 'P':       cursors();
630                                                 if (outstanding_taxes>0)
631                                                         lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes);
632                                                 else
633                                                         lprcat("\nYou do not owe any taxes.");
634                                                 return;
635                         };
636                 }
637         }
638
639 parse2()
640         {
641         if (c[HASTEMONST]) movemonst(); movemonst(); /* move the monsters               */
642         randmonst();    regen();
643         }
644
645 run(dir)
646         int dir;
647         {
648         int i;
649         i=1; while (i)
650                 {
651                 i=moveplayer(dir);
652                 if (i>0) {  if (c[HASTEMONST]) movemonst();  movemonst(); randmonst(); regen(); }
653                 if (hitflag) i=0;
654                 if (i!=0)  showcell(playerx,playery);
655                 }
656         }
657
658 /*
659         function to wield a weapon
660  */
661 wield()
662         {
663         int i;
664         while (1)
665                 {
666                 if ((i = whatitem("wield"))=='\33')  return;
667                 if (i != '.')
668                         {
669                         if (i=='*') showwield();
670                         else  if (iven[i-'a']==0) { ydhi(i); return; }
671                         else if (iven[i-'a']==OPOTION) { ycwi(i); return; }
672                         else if (iven[i-'a']==OSCROLL) { ycwi(i); return; }
673                         else  if ((c[SHIELD]!= -1) && (iven[i-'a']==O2SWORD)) { lprcat("\nBut one arm is busy with your shield!"); return; }
674                         else  { c[WIELD]=i-'a'; if (iven[i-'a'] == OLANCE) c[LANCEDEATH]=1; else c[LANCEDEATH]=0;  bottomline(); return; }
675                         }
676                 }
677         }
678
679 /*
680         common routine to say you don't have an item
681  */
682 ydhi(x)
683         int x;
684         { cursors();  lprintf("\nYou don't have item %c!",x); }
685 ycwi(x)
686         int x;
687         { cursors();  lprintf("\nYou can't wield item %c!",x); }
688
689 /*
690         function to wear armor
691  */
692 wear()
693         {
694         int i;
695         while (1)
696                 {
697                 if ((i = whatitem("wear"))=='\33')  return;
698                 if (i != '.')
699                         {
700                         if (i=='*') showwear(); else
701                         switch(iven[i-'a'])
702                                 {
703                                 case 0:  ydhi(i); return;
704                                 case OLEATHER:  case OCHAIN:  case OPLATE:      case OSTUDLEATHER:
705                                 case ORING:             case OSPLINT:   case OPLATEARMOR:       case OSSPLATE:
706                                                 if (c[WEAR] != -1) { lprcat("\nYou're already wearing some armor"); return; }
707                                                         c[WEAR]=i-'a';  bottomline(); return;
708                                 case OSHIELD:   if (c[SHIELD] != -1) { lprcat("\nYou are already wearing a shield"); return; }
709                                                                 if (iven[c[WIELD]]==O2SWORD) { lprcat("\nYour hands are busy with the two handed sword!"); return; }
710                                                                 c[SHIELD] = i-'a';  bottomline(); return;
711                                 default:        lprcat("\nYou can't wear that!");
712                                 };
713                         }
714                 }
715         }
716
717 /*
718         function to drop an object
719  */
720 dropobj()
721         {
722         int i;
723         char *p;
724         long amt;
725         p = &item[playerx][playery];
726         while (1)
727                 {
728                 if ((i = whatitem("drop"))=='\33')  return;
729                 if (i=='*') showstr(); else
730                         {
731                         if (i=='.')     /* drop some gold */
732                                 {
733                                 if (*p) { lprcat("\nThere's something here already!"); return; }
734                                 lprcat("\n\n");
735                                 cl_dn(1,23);
736                                 lprcat("How much gold do you drop? ");
737                                 if ((amt=readnum((long)c[GOLD])) == 0) return;
738                                 if (amt>c[GOLD])
739                                         { lprcat("\nYou don't have that much!"); return; }
740                                 if (amt<=32767)
741                                         { *p=OGOLDPILE; i=amt; }
742                                 else if (amt<=327670L)
743                                         { *p=ODGOLD; i=amt/10; amt = 10*i; }
744                                 else if (amt<=3276700L)
745                                         { *p=OMAXGOLD; i=amt/100; amt = 100*i; }
746                                 else if (amt<=32767000L)
747                                         { *p=OKGOLD; i=amt/1000; amt = 1000*i; }
748                                 else
749                                         { *p=OKGOLD; i=32767; amt = 32767000L; }
750                                 c[GOLD] -= amt;
751                                 lprintf("You drop %d gold pieces",(long)amt);
752                                 iarg[playerx][playery]=i; bottomgold();
753                                 know[playerx][playery]=0; dropflag=1;  return;
754                                 }
755                         drop_object(i-'a');
756                         return;
757                         }
758                 }
759         }
760
761 /*
762  *      readscr()               Subroutine to read a scroll one is carrying
763  */
764 readscr()
765         {
766         int i;
767         while (1)
768                 {
769                 if ((i = whatitem("read"))=='\33')  return;
770                 if (i != '.')
771                         {
772                         if (i=='*') showread(); else
773                                 {
774                                 if (iven[i-'a']==OSCROLL) { read_scroll(ivenarg[i-'a']); iven[i-'a']=0; return; }
775                                 if (iven[i-'a']==OBOOK)   { readbook(ivenarg[i-'a']);  iven[i-'a']=0; return; }
776                                 if (iven[i-'a']==0) { ydhi(i); return; }
777                                 lprcat("\nThere's nothing on it to read");  return;
778                                 }
779                         }
780                 }
781         }
782
783 /*
784  *      subroutine to eat a cookie one is carrying
785  */
786 eatcookie()
787 {
788 int i;
789 char *p;
790 while (1)
791         {
792         if ((i = whatitem("eat"))=='\33')  return;
793         if (i != '.') {
794                 if (i=='*') showeat(); else
795                         {
796                         if (iven[i-'a']==OCOOKIE)
797                                 {
798                                 lprcat("\nThe cookie was delicious.");
799                                 iven[i-'a']=0;
800                                 if (!c[BLINDCOUNT])
801                                         {
802                                         if (p=fortune(fortfile))
803                                                 {
804                                                 lprcat("  Inside you find a scrap of paper that says:\n");
805                                                 lprcat(p);
806                                                 }
807                                         }
808                                 return;
809                                 }
810                         if (iven[i-'a']==0) { ydhi(i); return; }
811                         lprcat("\nYou can't eat that!");  return;
812                         }
813                  }
814         }
815 }
816
817 /*
818  *      subroutine to quaff a potion one is carrying
819  */
820 quaff()
821         {
822         int i;
823         while (1)
824                 {
825                 if ((i = whatitem("quaff"))=='\33')  return;
826                 if (i != '.')
827                         {
828                         if (i=='*') showquaff(); else
829                                 {
830                                 if (iven[i-'a']==OPOTION) { quaffpotion(ivenarg[i-'a']); iven[i-'a']=0; return; }
831                                 if (iven[i-'a']==0) { ydhi(i); return; }
832                                 lprcat("\nYou wouldn't want to quaff that, would you? ");  return;
833                                 }
834                         }
835                 }
836         }
837
838 /*
839         function to ask what player wants to do
840  */
841 whatitem(str)
842         char *str;
843         {
844         int i;
845         cursors();  lprintf("\nWhat do you want to %s [* for all] ? ",str);
846         i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar();
847         if (i=='\33')  lprcat(" aborted");
848         return(i);
849         }
850
851 /*
852         subroutine to get a number from the player
853         and allow * to mean return amt, else return the number entered
854  */
855 unsigned long readnum(mx)
856         long mx;
857         {
858         int i;
859         unsigned long amt=0;
860         sncbr();
861         if ((i=getchar()) == '*')  amt = mx;   /* allow him to say * for all gold */
862         else
863                 while (i != '\n')
864                         {
865                         if (i=='\033') { scbr(); lprcat(" aborted"); return(0); }
866                         if ((i <= '9') && (i >= '0') && (amt<99999999))
867                                 amt = amt*10+i-'0';
868                         i = getchar();
869                         }
870         scbr();  return(amt);
871         }
872
873 #ifdef HIDEBYLINK
874 /*
875  *      routine to zero every byte in a string
876  */
877 szero(str)
878         char *str;
879         {
880         while (*str)
881                 *str++ = 0;
882         }
883 #endif HIDEBYLINK