diff options
author | 1997-10-18 20:03:05 +0000 | |
---|---|---|
committer | 1997-10-18 20:03:05 +0000 | |
commit | f73f1009084e75624e3bc00fef9cf4749de80dcc (patch) | |
tree | 10cc39737f667f056c5537c3fba7cf4d2a832c9d | |
parent | 39d5db4411fe42946cd3d94eb7d275f3f453d6aa (diff) | |
download | bsdgames-darwin-f73f1009084e75624e3bc00fef9cf4749de80dcc.tar.gz bsdgames-darwin-f73f1009084e75624e3bc00fef9cf4749de80dcc.tar.zst bsdgames-darwin-f73f1009084e75624e3bc00fef9cf4749de80dcc.zip |
Tons of changes; re-indent, use termios, fix warnings, add prototypes...
Games is almost clean; only hack is left...
-rw-r--r-- | larn/Makefile | 16 | ||||
-rw-r--r-- | larn/bill.c | 26 | ||||
-rw-r--r-- | larn/config.c | 44 | ||||
-rw-r--r-- | larn/create.c | 790 | ||||
-rw-r--r-- | larn/data.c | 1099 | ||||
-rw-r--r-- | larn/diag.c | 465 | ||||
-rw-r--r-- | larn/display.c | 808 | ||||
-rw-r--r-- | larn/extern.h | 312 | ||||
-rw-r--r-- | larn/fortune.c | 15 | ||||
-rw-r--r-- | larn/global.c | 1096 | ||||
-rw-r--r-- | larn/header.h | 337 | ||||
-rw-r--r-- | larn/help.c | 136 | ||||
-rw-r--r-- | larn/io.c | 1396 | ||||
-rw-r--r-- | larn/main.c | 1711 | ||||
-rw-r--r-- | larn/monster.c | 2706 | ||||
-rw-r--r-- | larn/moreobj.c | 689 | ||||
-rw-r--r-- | larn/movem.c | 642 | ||||
-rw-r--r-- | larn/nap.c | 26 | ||||
-rw-r--r-- | larn/object.c | 1856 | ||||
-rw-r--r-- | larn/pathnames.h | 2 | ||||
-rw-r--r-- | larn/regen.c | 231 | ||||
-rw-r--r-- | larn/savelev.c | 74 | ||||
-rw-r--r-- | larn/scores.c | 1152 | ||||
-rw-r--r-- | larn/signal.c | 160 | ||||
-rw-r--r-- | larn/store.c | 1256 | ||||
-rw-r--r-- | larn/tok.c | 377 |
26 files changed, 10542 insertions, 6880 deletions
diff --git a/larn/Makefile b/larn/Makefile index 34b3ba3e..1541bf4a 100644 --- a/larn/Makefile +++ b/larn/Makefile @@ -1,10 +1,13 @@ -# $NetBSD: Makefile,v 1.11 1997/10/12 14:21:47 lukem Exp $ +# $NetBSD: Makefile,v 1.12 1997/10/18 20:03:05 christos Exp $ # @(#)Makefile 5.12 (Berkeley) 5/30/93 # EXTRA # Incorporates code to gather additional performance statistics -# SYSV -# Use system III/V (instead of V7) type ioctl calls +# +# TERMIO +# Use sysv termio +# TERMIOS +# Use posix termios # BSD # Use BSD specific features (mostly timer and signal stuff) # BSD4.1 @@ -52,15 +55,14 @@ # NOLOG # Turn off logging. -WARNS= 0 PROG= larn MAN= larn.6 -CFLAGS+=-DBSD -DVER=12 -DSUBVER=0 -DNONAP -DUIDSCORE +CFLAGS+=-DBSD -DVER=12 -DSUBVER=0 -DNONAP -DUIDSCORE -DTERMIOS SRCS= main.c object.c create.c tok.c display.c global.c data.c io.c \ monster.c store.c diag.c help.c config.c nap.c bill.c scores.c \ signal.c moreobj.c movem.c regen.c fortune.c savelev.c -DPADD= ${LIBTERM} ${LIBCOMPAT} -LDADD= -ltermcap -lcompat +DPADD= ${LIBTERM} +LDADD= -ltermcap HIDEGAME=hidegame DAT=larnmaze larnopts larn.help FILES=${DAT:S@^@${.CURDIR}/datfiles/@g} diff --git a/larn/bill.c b/larn/bill.c index 3d1799e6..dbc71495 100644 --- a/larn/bill.c +++ b/larn/bill.c @@ -1,4 +1,4 @@ -/* $NetBSD: bill.c,v 1.4 1996/05/22 00:34:35 mrg Exp $ */ +/* $NetBSD: bill.c,v 1.5 1997/10/18 20:03:06 christos Exp $ */ /*- * Copyright (c) 1991 The Regents of the University of California. @@ -33,11 +33,12 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)bill.c 5.2 (Berkeley) 5/28/91"; #else -static char rcsid[] = "$NetBSD: bill.c,v 1.4 1996/05/22 00:34:35 mrg Exp $"; +__RCSID("$NetBSD: bill.c,v 1.5 1997/10/18 20:03:06 christos Exp $"); #endif #endif /* not lint */ @@ -48,6 +49,7 @@ static char rcsid[] = "$NetBSD: bill.c,v 1.4 1996/05/22 00:34:35 mrg Exp $"; #include <stdio.h> #include <unistd.h> #include "header.h" +#include "extern.h" /* bill.c Larn is copyrighted 1986 by Noah Morgan. */ @@ -116,17 +118,17 @@ char *mail[] = { }; /* - * function to mail the letters to the player if a winner + * function to mail the letters to the player if a winner */ void mailbill() { - register int i; - char fname[32]; - char buf[128]; + int i; + char fname[32]; + char buf[128]; char **cp; - int fd; + int fd; wait(0); if (fork() == 0) { @@ -135,15 +137,15 @@ mailbill() sprintf(fname, "/tmp/#%dlarnmail", getpid()); for (i = 0; i < 6; i++) { if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT, - 0666)) == -1) + 0666)) == -1) exit(0); while (*cp != NULL) { if (*cp[0] == '1') { - sprintf(buf, "\n%d gold pieces back with you from your journey. As the", - (long)c[GOLD]); + sprintf(buf, "\n%ld gold pieces back with you from your journey. As the", + (long) c[GOLD]); write(fd, buf, strlen(buf)); } else if (*cp[0] == '2') { - sprintf(buf, "\nin preparing your tax bill. You owe %d gold pieces as", (long)c[GOLD]*TAXRATE); + sprintf(buf, "\nin preparing your tax bill. You owe %ld gold pieces as", (long) c[GOLD] * TAXRATE); write(fd, buf, strlen(buf)); } else write(fd, *cp, strlen(*cp)); @@ -153,7 +155,7 @@ mailbill() close(fd); sprintf(buf, "mail -I %s < %s > /dev/null", - loginname, fname); + loginname, fname); system(buf); unlink(fname); } diff --git a/larn/config.c b/larn/config.c index 3746c09c..30b64cfd 100644 --- a/larn/config.c +++ b/larn/config.c @@ -1,48 +1,50 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: config.c,v 1.4 1995/04/22 07:34:04 cgd Exp $"; -#endif /* not lint */ +/* $NetBSD: config.c,v 1.5 1997/10/18 20:03:08 christos Exp $ */ /* - * config.c -- This defines the installation dependent variables. - * Some strings are modified later. ANSI C would - * allow compile time string concatenation, we must - * do runtime concatenation, in main. + * config.c -- This defines the installation dependent variables. + * Some strings are modified later. ANSI C would + * allow compile time string concatenation, we must + * do runtime concatenation, in main. * * Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: config.c,v 1.5 1997/10/18 20:03:08 christos Exp $"); +#endif /* not lint */ + #include "header.h" #include "pathnames.h" /* - * All these strings will be appended to in main() to be complete filenames + * All these strings will be appended to in main() to be complete filenames */ /* the game save filename */ -char savefilename[1024]; +char savefilename[1024]; /* the logging file */ -char logfile[] = _PATH_LOG; +char logfile[] = _PATH_LOG; /* the help text file */ -char helpfile[] = _PATH_HELP; +char helpfile[] = _PATH_HELP; /* the score file */ -char scorefile[] = _PATH_SCORE; +char scorefile[] = _PATH_SCORE; /* the maze data file */ -char larnlevels[] = _PATH_LEVELS; +char larnlevels[] = _PATH_LEVELS; /* the .larnopts filename */ -char optsfile[1024] ="/.larnopts"; +char optsfile[1024] = "/.larnopts"; /* the player id datafile name */ -char playerids[] = _PATH_PLAYERIDS; +char playerids[] = _PATH_PLAYERIDS; -char diagfile[] ="Diagfile"; /* the diagnostic filename */ -char ckpfile[] ="Larn12.0.ckp"; /* the checkpoint filename */ -char *password ="pvnert(x)"; /* the wizards password <=32 */ -char psname[PSNAMESIZE]="larn"; /* the process name */ +char diagfile[] = "Diagfile"; /* the diagnostic filename */ +char ckpfile[] = "Larn12.0.ckp"; /* the checkpoint filename */ +char *password = "pvnert(x)"; /* the wizards password <=32 */ +char psname[PSNAMESIZE] = "larn"; /* the process name */ #define WIZID 1 -int wisid=0; /* the user id of the only person who can be wizard */ - +int wisid = 0; /* the user id of the only person who can be wizard */ diff --git a/larn/create.c b/larn/create.c index 3bba976e..ed7d3f00 100644 --- a/larn/create.c +++ b/larn/create.c @@ -1,43 +1,56 @@ +/* $NetBSD: create.c,v 1.6 1997/10/18 20:03:09 christos Exp $ */ + +/* create.c Larn is copyrighted 1986 by Noah Morgan. */ + +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: create.c,v 1.5 1997/07/13 20:21:32 christos Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: create.c,v 1.6 1997/10/18 20:03:09 christos Exp $"); +#endif /* not lint */ -/* create.c Larn is copyrighted 1986 by Noah Morgan. */ #include "header.h" -extern char spelknow[],larnlevels[]; -extern char beenhere[],wizard; -extern short level; -extern short oldx,oldy; +#include "extern.h" +#include <unistd.h> +static void fillroom __P((int, int)); + /* makeplayer() subroutine to create the player and the players attributes this is called at the beginning of a game and at no other time */ +void makeplayer() - { - register int i; - scbr(); clear(); - c[HPMAX]=c[HP]=10; /* start player off with 15 hit points */ - c[LEVEL]=1; /* player starts at level one */ - c[SPELLMAX]=c[SPELLS]=1; /* total # spells starts off as 3 */ - c[REGENCOUNTER]=16; c[ECOUNTER]=96; /*start regeneration correctly*/ +{ + int i; + scbr(); + clear(); + c[HPMAX] = c[HP] = 10; /* start player off with 15 hit points */ + c[LEVEL] = 1; /* player starts at level one */ + c[SPELLMAX] = c[SPELLS] = 1; /* total # spells starts off as 3 */ + c[REGENCOUNTER] = 16; + c[ECOUNTER] = 96; /* start regeneration correctly */ c[SHIELD] = c[WEAR] = c[WIELD] = -1; - for (i=0; i<26; i++) iven[i]=0; - spelknow[0]=spelknow[1]=1; /*he knows protection, magic missile*/ - if (c[HARDGAME]<=0) - { - iven[0]=OLEATHER; iven[1]=ODAGGER; - ivenarg[1]=ivenarg[0]=c[WEAR]=0; c[WIELD]=1; - } - playerx=rnd(MAXX-2); playery=rnd(MAXY-2); - oldx=0; oldy=25; - gltime=0; /* time clock starts at zero */ + for (i = 0; i < 26; i++) + iven[i] = 0; + spelknow[0] = spelknow[1] = 1; /* he knows protection, magic missile */ + if (c[HARDGAME] <= 0) { + iven[0] = OLEATHER; + iven[1] = ODAGGER; + ivenarg[1] = ivenarg[0] = c[WEAR] = 0; + c[WIELD] = 1; + } + playerx = rnd(MAXX - 2); + playery = rnd(MAXY - 2); + oldx = 0; + oldy = 25; + gltime = 0; /* time clock starts at zero */ cbak[SPELLS] = -50; - for (i=0; i<6; i++) c[i]=12; /* make the attributes, ie str, int, etc. */ + for (i = 0; i < 6; i++) + c[i] = 12; /* make the attributes, ie str, int, etc. */ recalc(); - } - +} + + /* newcavelevel(level) int level; @@ -48,27 +61,40 @@ makeplayer() levels will get a few more monsters. Note that it is here we remove genocided monsters from the present level. */ +void newcavelevel(x) - register int x; - { - register int i,j; - if (beenhere[level]) savelevel(); /* put the level back into storage */ - level = x; /* get the new level and put in working storage */ - if (beenhere[x]==0) for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) know[j][i]=mitem[j][i]=0; - else { getlevel(); sethp(0); goto chgn; } - makemaze(x); makeobject(x); beenhere[x]=1; sethp(1); + int x; +{ + int i, j; + if (beenhere[level]) + savelevel(); /* put the level back into storage */ + level = x; /* get the new level and put in working + * storage */ + if (beenhere[x] == 0) + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + know[j][i] = mitem[j][i] = 0; + else { + getlevel(); + sethp(0); + goto chgn; + } + makemaze(x); + makeobject(x); + beenhere[x] = 1; + sethp(1); #if WIZID - if (wizard || x==0) + if (wizard || x == 0) #else - if (x==0) + if (x == 0) #endif - for (j=0; j<MAXY; j++) - for (i=0; i<MAXX; i++) - know[i][j]=1; -chgn: checkgen(); /* wipe out any genocided monsters */ - } + for (j = 0; j < MAXY; j++) + for (i = 0; i < MAXX; i++) + know[i][j] = 1; +chgn: checkgen(); /* wipe out any genocided monsters */ +} /* makemaze(level) @@ -76,83 +102,119 @@ chgn: checkgen(); /* wipe out any genocided monsters */ subroutine to make the caverns for a given level. only walls are made. */ -static int mx,mxl,mxh,my,myl,myh,tmp2; - makemaze(k) - int k; - { - register int i,j,tmp; - int z; - if (k > 1 && (rnd(17)<=4 || k==MAXLEVEL-1 || k==MAXLEVEL+MAXVLEVEL-1)) - { - if (cannedlevel(k)); return; /* read maze from data file */ - } - if (k==0) tmp=0; else tmp=OWALL; - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) item[j][i]=tmp; - if (k==0) return; eat(1,1); - if (k==1) item[33][MAXY-1]=0; /* exit from dungeon */ - -/* now for open spaces -- not on level 10 */ - if (k != MAXLEVEL-1) - { - tmp2 = rnd(3)+3; - for (tmp=0; tmp<tmp2; tmp++) - { - my = rnd(11)+2; myl = my - rnd(2); myh = my + rnd(2); - if (k < MAXLEVEL) - { - mx = rnd(44)+5; mxl = mx - rnd(4); mxh = mx + rnd(12)+3; - z=0; - } - else - { - mx = rnd(60)+3; mxl = mx - rnd(2); mxh = mx + rnd(2); +static int mx, mxl, mxh, my, myl, myh, tmp2; +void +makemaze(k) + int k; +{ + int i, j, tmp; + int z; + if (k > 1 && (rnd(17) <= 4 || k == MAXLEVEL - 1 || k == MAXLEVEL + MAXVLEVEL - 1)) { + if (cannedlevel(k)); + return; /* read maze from data file */ + } + if (k == 0) + tmp = 0; + else + tmp = OWALL; + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + item[j][i] = tmp; + if (k == 0) + return; + eat(1, 1); + if (k == 1) + item[33][MAXY - 1] = 0; /* exit from dungeon */ + + /* now for open spaces -- not on level 10 */ + if (k != MAXLEVEL - 1) { + tmp2 = rnd(3) + 3; + for (tmp = 0; tmp < tmp2; tmp++) { + my = rnd(11) + 2; + myl = my - rnd(2); + myh = my + rnd(2); + if (k < MAXLEVEL) { + mx = rnd(44) + 5; + mxl = mx - rnd(4); + mxh = mx + rnd(12) + 3; + z = 0; + } else { + mx = rnd(60) + 3; + mxl = mx - rnd(2); + mxh = mx + rnd(2); z = makemonst(k); - } - for (i=mxl; i<mxh; i++) for (j=myl; j<myh; j++) - { item[i][j]=0; - if ((mitem[i][j]=z)) hitp[i][j]=monster[z].hitpoints; - } } + for (i = mxl; i < mxh; i++) + for (j = myl; j < myh; j++) { + item[i][j] = 0; + if ((mitem[i][j] = z)) + hitp[i][j] = monster[z].hitpoints; + } } - if (k!=MAXLEVEL-1) { my=rnd(MAXY-2); for (i=1; i<MAXX-1; i++) item[i][my] = 0; } - if (k>1) treasureroom(k); } + if (k != MAXLEVEL - 1) { + my = rnd(MAXY - 2); + for (i = 1; i < MAXX - 1; i++) + item[i][my] = 0; + } + if (k > 1) + treasureroom(k); +} /* function to eat away a filled in maze */ -eat(xx,yy) - register int xx,yy; - { - register int dir,try; - dir = rnd(4); try=2; - while (try) - { - switch(dir) - { - case 1: if (xx <= 2) break; /* west */ - if ((item[xx-1][yy]!=OWALL) || (item[xx-2][yy]!=OWALL)) break; - item[xx-1][yy] = item[xx-2][yy] = 0; - eat(xx-2,yy); break; - - case 2: if (xx >= MAXX-3) break; /* east */ - if ((item[xx+1][yy]!=OWALL) || (item[xx+2][yy]!=OWALL)) break; - item[xx+1][yy] = item[xx+2][yy] = 0; - eat(xx+2,yy); break; - - case 3: if (yy <= 2) break; /* south */ - if ((item[xx][yy-1]!=OWALL) || (item[xx][yy-2]!=OWALL)) break; - item[xx][yy-1] = item[xx][yy-2] = 0; - eat(xx,yy-2); break; - - case 4: if (yy >= MAXY-3 ) break; /* north */ - if ((item[xx][yy+1]!=OWALL) || (item[xx][yy+2]!=OWALL)) break; - item[xx][yy+1] = item[xx][yy+2] = 0; - eat(xx,yy+2); break; - }; - if (++dir > 4) { dir=1; --try; } +void +eat(xx, yy) + int xx, yy; +{ + int dir, try; + dir = rnd(4); + try = 2; + while (try) { + switch (dir) { + case 1: + if (xx <= 2) + break; /* west */ + if ((item[xx - 1][yy] != OWALL) || (item[xx - 2][yy] != OWALL)) + break; + item[xx - 1][yy] = item[xx - 2][yy] = 0; + eat(xx - 2, yy); + break; + + case 2: + if (xx >= MAXX - 3) + break; /* east */ + if ((item[xx + 1][yy] != OWALL) || (item[xx + 2][yy] != OWALL)) + break; + item[xx + 1][yy] = item[xx + 2][yy] = 0; + eat(xx + 2, yy); + break; + + case 3: + if (yy <= 2) + break; /* south */ + if ((item[xx][yy - 1] != OWALL) || (item[xx][yy - 2] != OWALL)) + break; + item[xx][yy - 1] = item[xx][yy - 2] = 0; + eat(xx, yy - 2); + break; + + case 4: + if (yy >= MAXY - 3) + break; /* north */ + if ((item[xx][yy + 1] != OWALL) || (item[xx][yy + 2] != OWALL)) + break; + item[xx][yy + 1] = item[xx][yy + 2] = 0; + eat(xx, yy + 2); + break; + }; + if (++dir > 4) { + dir = 1; + --try; } } +} /* * function to read in a maze from a data file @@ -166,122 +228,157 @@ eat(xx,yy) * ~ eye of larn ! cure dianthroritis * - random object */ +int cannedlevel(k) - int k; - { - char *row,*lgetl(); - register int i,j; - int it,arg,mit,marg; - if (lopen(larnlevels)<0) - { - write(1,"Can't open the maze data file\n",30); died(-282); return(0); - } - i=lgetc(); if (i<='0') { died(-282); return(0); } - for (i=18*rund(i-'0'); i>0; i--) lgetl(); /* advance to desired maze */ - for (i=0; i<MAXY; i++) - { + int k; +{ + char *row; + int i, j; + int it, arg, mit, marg; + if (lopen(larnlevels) < 0) { + write(1, "Can't open the maze data file\n", 30); + died(-282); + return (0); + } + i = lgetc(); + if (i <= '0') { + died(-282); + return (0); + } + for (i = 18 * rund(i - '0'); i > 0; i--) + lgetl(); /* advance to desired maze */ + for (i = 0; i < MAXY; i++) { row = lgetl(); - for (j=0; j<MAXX; j++) - { + for (j = 0; j < MAXX; j++) { it = mit = arg = marg = 0; - switch(*row++) - { - case '#': it = OWALL; break; - case 'D': it = OCLOSEDDOOR; arg = rnd(30); break; - case '~': if (k!=MAXLEVEL-1) break; - it = OLARNEYE; - mit = rund(8)+DEMONLORD; - marg = monster[mit].hitpoints; break; - case '!': if (k!=MAXLEVEL+MAXVLEVEL-1) break; - it = OPOTION; arg = 21; - mit = DEMONLORD+7; - marg = monster[mit].hitpoints; break; - case '.': if (k<MAXLEVEL) break; - mit = makemonst(k+1); - marg = monster[mit].hitpoints; break; - case '-': it = newobject(k+1,&arg); break; - }; - item[j][i] = it; iarg[j][i] = arg; - mitem[j][i] = mit; hitp[j][i] = marg; + switch (*row++) { + case '#': + it = OWALL; + break; + case 'D': + it = OCLOSEDDOOR; + arg = rnd(30); + break; + case '~': + if (k != MAXLEVEL - 1) + break; + it = OLARNEYE; + mit = rund(8) + DEMONLORD; + marg = monster[mit].hitpoints; + break; + case '!': + if (k != MAXLEVEL + MAXVLEVEL - 1) + break; + it = OPOTION; + arg = 21; + mit = DEMONLORD + 7; + marg = monster[mit].hitpoints; + break; + case '.': + if (k < MAXLEVEL) + break; + mit = makemonst(k + 1); + marg = monster[mit].hitpoints; + break; + case '-': + it = newobject(k + 1, &arg); + break; + }; + item[j][i] = it; + iarg[j][i] = arg; + mitem[j][i] = mit; + hitp[j][i] = marg; #if WIZID know[j][i] = (wizard) ? 1 : 0; #else know[j][i] = 0; #endif - } } - lrclose(); - return(1); } + lrclose(); + return (1); +} /* function to make a treasure room on a level level 10's treasure room has the eye in it and demon lords level V3 has potion of cure dianthroritis and demon prince */ +void treasureroom(lv) - register int lv; - { - register int tx,ty,xsize,ysize; - - for (tx=1+rnd(10); tx<MAXX-10; tx+=10) - if ( (lv==MAXLEVEL-1) || (lv==MAXLEVEL+MAXVLEVEL-1) || rnd(13)==2) - { - xsize = rnd(6)+3; ysize = rnd(3)+3; - ty = rnd(MAXY-9)+1; /* upper left corner of room */ - if (lv==MAXLEVEL-1 || lv==MAXLEVEL+MAXVLEVEL-1) - troom(lv,xsize,ysize,tx=tx+rnd(MAXX-24),ty,rnd(3)+6); - else troom(lv,xsize,ysize,tx,ty,rnd(9)); + int lv; +{ + int tx, ty, xsize, ysize; + + for (tx = 1 + rnd(10); tx < MAXX - 10; tx += 10) + if ((lv == MAXLEVEL - 1) || (lv == MAXLEVEL + MAXVLEVEL - 1) || rnd(13) == 2) { + xsize = rnd(6) + 3; + ysize = rnd(3) + 3; + ty = rnd(MAXY - 9) + 1; /* upper left corner of room */ + if (lv == MAXLEVEL - 1 || lv == MAXLEVEL + MAXVLEVEL - 1) + troom(lv, xsize, ysize, tx = tx + rnd(MAXX - 24), ty, rnd(3) + 6); + else + troom(lv, xsize, ysize, tx, ty, rnd(9)); } - } +} /* - * subroutine to create a treasure room of any size at a given location - * room is filled with objects and monsters + * subroutine to create a treasure room of any size at a given location + * room is filled with objects and monsters * the coordinate given is that of the upper left corner of the room */ -troom(lv,xsize,ysize,tx,ty,glyph) - int lv,xsize,ysize,tx,ty,glyph; - { - register int i,j; - int tp1,tp2; - for (j=ty-1; j<=ty+ysize; j++) - for (i=tx-1; i<=tx+xsize; i++) /* clear out space for room */ - item[i][j]=0; - for (j=ty; j<ty+ysize; j++) - for (i=tx; i<tx+xsize; i++) /* now put in the walls */ - { - item[i][j]=OWALL; mitem[i][j]=0; +void +troom(lv, xsize, ysize, tx, ty, glyph) + int lv, xsize, ysize, tx, ty, glyph; +{ + int i, j; + int tp1, tp2; + for (j = ty - 1; j <= ty + ysize; j++) + for (i = tx - 1; i <= tx + xsize; i++) /* clear out space for + * room */ + item[i][j] = 0; + for (j = ty; j < ty + ysize; j++) + for (i = tx; i < tx + xsize; i++) { /* now put in the walls */ + item[i][j] = OWALL; + mitem[i][j] = 0; + } + for (j = ty + 1; j < ty + ysize - 1; j++) + for (i = tx + 1; i < tx + xsize - 1; i++) /* now clear out + * interior */ + item[i][j] = 0; + + switch (rnd(2)) { /* locate the door on the treasure room */ + case 1: + item[i = tx + rund(xsize)][j = ty + (ysize - 1) * rund(2)] = OCLOSEDDOOR; + iarg[i][j] = glyph; /* on horizontal walls */ + break; + case 2: + item[i = tx + (xsize - 1) * rund(2)][j = ty + rund(ysize)] = OCLOSEDDOOR; + iarg[i][j] = glyph; /* on vertical walls */ + break; + }; + + tp1 = playerx; + tp2 = playery; + playery = ty + (ysize >> 1); + if (c[HARDGAME] < 2) + for (playerx = tx + 1; playerx <= tx + xsize - 2; playerx += 2) + for (i = 0, j = rnd(6); i <= j; i++) { + something(lv + 2); + createmonster(makemonst(lv + 1)); } - for (j=ty+1; j<ty+ysize-1; j++) - for (i=tx+1; i<tx+xsize-1; i++) /* now clear out interior */ - item[i][j]=0; - - switch(rnd(2)) /* locate the door on the treasure room */ - { - case 1: item[i=tx+rund(xsize)][j=ty+(ysize-1)*rund(2)]=OCLOSEDDOOR; - iarg[i][j] = glyph; /* on horizontal walls */ - break; - case 2: item[i=tx+(xsize-1)*rund(2)][j=ty+rund(ysize)]=OCLOSEDDOOR; - iarg[i][j] = glyph; /* on vertical walls */ - break; - }; - - tp1=playerx; tp2=playery; playery=ty+(ysize>>1); - if (c[HARDGAME]<2) - for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2) - for (i=0, j=rnd(6); i<=j; i++) - { something(lv+2); createmonster(makemonst(lv+1)); } else - for (playerx=tx+1; playerx<=tx+xsize-2; playerx+=2) - for (i=0, j=rnd(4); i<=j; i++) - { something(lv+2); createmonster(makemonst(lv+3)); } + for (playerx = tx + 1; playerx <= tx + xsize - 2; playerx += 2) + for (i = 0, j = rnd(4); i <= j; i++) { + something(lv + 2); + createmonster(makemonst(lv + 3)); + } + + playerx = tp1; + playery = tp2; +} - playerx=tp1; playery=tp2; - } - -static void fillroom(); /* *********** @@ -289,180 +386,215 @@ static void fillroom(); *********** subroutine to create the objects in the maze for the given level */ +void makeobject(j) - register int j; - { - register int i; - if (j==0) - { - fillroom(OENTRANCE,0); /* entrance to dungeon */ - fillroom(ODNDSTORE,0); /* the DND STORE */ - fillroom(OSCHOOL,0); /* college of Larn */ - fillroom(OBANK,0); /* 1st national bank of larn */ - fillroom(OVOLDOWN,0); /* volcano shaft to temple */ - fillroom(OHOME,0); /* the players home & family */ - fillroom(OTRADEPOST,0); /* the trading post */ - fillroom(OLRS,0); /* the larn revenue service */ + int j; +{ + int i; + if (j == 0) { + fillroom(OENTRANCE, 0); /* entrance to dungeon */ + fillroom(ODNDSTORE, 0); /* the DND STORE */ + fillroom(OSCHOOL, 0); /* college of Larn */ + fillroom(OBANK, 0); /* 1st national bank of larn */ + fillroom(OVOLDOWN, 0); /* volcano shaft to temple */ + fillroom(OHOME, 0); /* the players home & family */ + fillroom(OTRADEPOST, 0); /* the trading post */ + fillroom(OLRS, 0); /* the larn revenue service */ return; - } - - if (j==MAXLEVEL) fillroom(OVOLUP,0); /* volcano shaft up from the temple */ - -/* make the fixed objects in the maze STAIRS */ - if ((j>0) && (j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1)) - fillroom(OSTAIRSDOWN,0); - if ((j > 1) && (j != MAXLEVEL)) fillroom(OSTAIRSUP,0); - -/* make the random objects in the maze */ - - fillmroom(rund(3),OBOOK,j); fillmroom(rund(3),OALTAR,0); - fillmroom(rund(3),OSTATUE,0); fillmroom(rund(3),OPIT,0); - fillmroom(rund(3),OFOUNTAIN,0); fillmroom( rnd(3)-2,OIVTELETRAP,0); - fillmroom(rund(2),OTHRONE,0); fillmroom(rund(2),OMIRROR,0); - fillmroom(rund(2),OTRAPARROWIV,0); fillmroom( rnd(3)-2,OIVDARTRAP,0); - fillmroom(rund(3),OCOOKIE,0); - if (j==1) fillmroom(1,OCHEST,j); - else fillmroom(rund(2),OCHEST,j); - if ((j != MAXLEVEL-1) && (j != MAXLEVEL+MAXVLEVEL-1)) - fillmroom(rund(2),OIVTRAPDOOR,0); - if (j<=10) - { - fillmroom((rund(2)),ODIAMOND,rnd(10*j+1)+10); - fillmroom(rund(2),ORUBY,rnd(6*j+1)+6); - fillmroom(rund(2),OEMERALD,rnd(4*j+1)+4); - fillmroom(rund(2),OSAPPHIRE,rnd(3*j+1)+2); - } - for (i=0; i<rnd(4)+3; i++) - fillroom(OPOTION,newpotion()); /* make a POTION */ - for (i=0; i<rnd(5)+3; i++) - fillroom(OSCROLL,newscroll()); /* make a SCROLL */ - for (i=0; i<rnd(12)+11; i++) - fillroom(OGOLDPILE,12*rnd(j+1)+(j<<3)+10); /* make GOLD */ - if (j==5) fillroom(OBANK2,0); /* branch office of the bank */ - froom(2,ORING,0); /* a ring mail */ - froom(1,OSTUDLEATHER,0); /* a studded leather */ - froom(3,OSPLINT,0); /* a splint mail */ - froom(5,OSHIELD,rund(3)); /* a shield */ - froom(2,OBATTLEAXE,rund(3)); /* a battle axe */ - froom(5,OLONGSWORD,rund(3)); /* a long sword */ - froom(5,OFLAIL,rund(3)); /* a flail */ - froom(4,OREGENRING,rund(3)); /* ring of regeneration */ - froom(1,OPROTRING,rund(3)); /* ring of protection */ - froom(2,OSTRRING,4); /* ring of strength + 4 */ - froom(7,OSPEAR,rnd(5)); /* a spear */ - froom(3,OORBOFDRAGON,0); /* orb of dragon slaying*/ - froom(4,OSPIRITSCARAB,0); /*scarab of negate spirit*/ - froom(4,OCUBEofUNDEAD,0); /* cube of undead control */ - froom(2,ORINGOFEXTRA,0); /* ring of extra regen */ - froom(3,ONOTHEFT,0); /* device of antitheft */ - froom(2,OSWORDofSLASHING,0); /* sword of slashing */ - if (c[BESSMANN]==0) - { - froom(4,OHAMMER,0);/*Bessman's flailing hammer*/ c[BESSMANN]=1; - } - if (c[HARDGAME]<3 || (rnd(4)==3)) - { - if (j>3) - { - froom(3,OSWORD,3); /* sunsword + 3 */ - froom(5,O2SWORD,rnd(4)); /* a two handed sword */ - froom(3,OBELT,4); /* belt of striking */ - froom(3,OENERGYRING,3); /* energy ring */ - froom(4,OPLATE,5); /* platemail + 5 */ - } + } + if (j == MAXLEVEL) + fillroom(OVOLUP, 0); /* volcano shaft up from the temple */ + + /* make the fixed objects in the maze STAIRS */ + if ((j > 0) && (j != MAXLEVEL - 1) && (j != MAXLEVEL + MAXVLEVEL - 1)) + fillroom(OSTAIRSDOWN, 0); + if ((j > 1) && (j != MAXLEVEL)) + fillroom(OSTAIRSUP, 0); + + /* make the random objects in the maze */ + + fillmroom(rund(3), OBOOK, j); + fillmroom(rund(3), OALTAR, 0); + fillmroom(rund(3), OSTATUE, 0); + fillmroom(rund(3), OPIT, 0); + fillmroom(rund(3), OFOUNTAIN, 0); + fillmroom(rnd(3) - 2, OIVTELETRAP, 0); + fillmroom(rund(2), OTHRONE, 0); + fillmroom(rund(2), OMIRROR, 0); + fillmroom(rund(2), OTRAPARROWIV, 0); + fillmroom(rnd(3) - 2, OIVDARTRAP, 0); + fillmroom(rund(3), OCOOKIE, 0); + if (j == 1) + fillmroom(1, OCHEST, j); + else + fillmroom(rund(2), OCHEST, j); + if ((j != MAXLEVEL - 1) && (j != MAXLEVEL + MAXVLEVEL - 1)) + fillmroom(rund(2), OIVTRAPDOOR, 0); + if (j <= 10) { + fillmroom((rund(2)), ODIAMOND, rnd(10 * j + 1) + 10); + fillmroom(rund(2), ORUBY, rnd(6 * j + 1) + 6); + fillmroom(rund(2), OEMERALD, rnd(4 * j + 1) + 4); + fillmroom(rund(2), OSAPPHIRE, rnd(3 * j + 1) + 2); + } + for (i = 0; i < rnd(4) + 3; i++) + fillroom(OPOTION, newpotion()); /* make a POTION */ + for (i = 0; i < rnd(5) + 3; i++) + fillroom(OSCROLL, newscroll()); /* make a SCROLL */ + for (i = 0; i < rnd(12) + 11; i++) + fillroom(OGOLDPILE, 12 * rnd(j + 1) + (j << 3) + 10); /* make GOLD */ + if (j == 5) + fillroom(OBANK2, 0); /* branch office of the bank */ + froom(2, ORING, 0); /* a ring mail */ + froom(1, OSTUDLEATHER, 0); /* a studded leather */ + froom(3, OSPLINT, 0); /* a splint mail */ + froom(5, OSHIELD, rund(3)); /* a shield */ + froom(2, OBATTLEAXE, rund(3)); /* a battle axe */ + froom(5, OLONGSWORD, rund(3)); /* a long sword */ + froom(5, OFLAIL, rund(3)); /* a flail */ + froom(4, OREGENRING, rund(3)); /* ring of regeneration */ + froom(1, OPROTRING, rund(3)); /* ring of protection */ + froom(2, OSTRRING, 4); /* ring of strength + 4 */ + froom(7, OSPEAR, rnd(5)); /* a spear */ + froom(3, OORBOFDRAGON, 0); /* orb of dragon slaying */ + froom(4, OSPIRITSCARAB, 0); /* scarab of negate spirit */ + froom(4, OCUBEofUNDEAD, 0); /* cube of undead control */ + froom(2, ORINGOFEXTRA, 0); /* ring of extra regen */ + froom(3, ONOTHEFT, 0); /* device of antitheft */ + froom(2, OSWORDofSLASHING, 0); /* sword of slashing */ + if (c[BESSMANN] == 0) { + froom(4, OHAMMER, 0); /* Bessman's flailing hammer */ + c[BESSMANN] = 1; + } + if (c[HARDGAME] < 3 || (rnd(4) == 3)) { + if (j > 3) { + froom(3, OSWORD, 3); /* sunsword + 3 */ + froom(5, O2SWORD, rnd(4)); /* a two handed sword */ + froom(3, OBELT, 4); /* belt of striking */ + froom(3, OENERGYRING, 3); /* energy ring */ + froom(4, OPLATE, 5); /* platemail + 5 */ } } +} /* subroutine to fill in a number of objects of the same kind */ -fillmroom(n,what,arg) - int n,arg; - char what; - { - register int i; - for (i=0; i<n; i++) fillroom(what,arg); - } -froom(n,itm,arg) - int n,arg; - char itm; - { if (rnd(151) < n) fillroom(itm,arg); } +void +fillmroom(n, what, arg) + int n, arg; + char what; +{ + int i; + for (i = 0; i < n; i++) + fillroom(what, arg); +} +void +froom(n, itm, arg) + int n, arg; + char itm; +{ + if (rnd(151) < n) + fillroom(itm, arg); +} /* subroutine to put an object into an empty room * uses a random walk */ static void -fillroom(what,arg) - int arg; - char what; - { - register int x,y; +fillroom(what, arg) + int arg; + char what; +{ + int x, y; #ifdef EXTRA c[FILLROOM]++; #endif - x=rnd(MAXX-2); y=rnd(MAXY-2); - while (item[x][y]) - { + x = rnd(MAXX - 2); + y = rnd(MAXY - 2); + while (item[x][y]) { #ifdef EXTRA - c[RANDOMWALK]++; /* count up these random walks */ + c[RANDOMWALK]++;/* count up these random walks */ #endif - x += rnd(3)-2; y += rnd(3)-2; - if (x > MAXX-2) x=1; if (x < 1) x=MAXX-2; - if (y > MAXY-2) y=1; if (y < 1) y=MAXY-2; - } - item[x][y]=what; iarg[x][y]=arg; + x += rnd(3) - 2; + y += rnd(3) - 2; + if (x > MAXX - 2) + x = 1; + if (x < 1) + x = MAXX - 2; + if (y > MAXY - 2) + y = 1; + if (y < 1) + y = MAXY - 2; } + item[x][y] = what; + iarg[x][y] = arg; +} /* subroutine to put monsters into an empty room without walls or other monsters */ +int fillmonst(what) - char what; - { - register int x,y,trys; - for (trys=5; trys>0; --trys) /* max # of creation attempts */ - { - x=rnd(MAXX-2); y=rnd(MAXY-2); - if ((item[x][y]==0) && (mitem[x][y]==0) && ((playerx!=x) || (playery!=y))) - { - mitem[x][y] = what; know[x][y]=0; - hitp[x][y] = monster[what].hitpoints; return(0); + int what; +{ + int x, y, trys; + for (trys = 5; trys > 0; --trys) { /* max # of creation attempts */ + x = rnd(MAXX - 2); + y = rnd(MAXY - 2); + if ((item[x][y] == 0) && (mitem[x][y] == 0) && ((playerx != x) || (playery != y))) { + mitem[x][y] = what; + know[x][y] = 0; + hitp[x][y] = monster[what].hitpoints; + return (0); } - } - return(-1); /* creation failure */ } + return (-1); /* creation failure */ +} /* creates an entire set of monsters for a level must be done when entering a new level if sethp(1) then wipe out old monsters else leave them there */ +void sethp(flg) - int flg; - { - register int i,j; - if (flg) for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) stealth[j][i]=0; - if (level==0) { c[TELEFLAG]=0; return; } /* if teleported and found level 1 then know level we are on */ - if (flg) j = rnd(12) + 2 + (level>>1); else j = (level>>1) + 1; - for (i=0; i<j; i++) fillmonst(makemonst(level)); + int flg; +{ + int i, j; + if (flg) + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + stealth[j][i] = 0; + if (level == 0) { + c[TELEFLAG] = 0; + return; + } /* if teleported and found level 1 then know + * level we are on */ + if (flg) + j = rnd(12) + 2 + (level >> 1); + else + j = (level >> 1) + 1; + for (i = 0; i < j; i++) + fillmonst(makemonst(level)); positionplayer(); - } +} /* * Function to destroy all genocided monsters on the present level */ +void checkgen() - { - register int x,y; - for (y=0; y<MAXY; y++) - for (x=0; x<MAXX; x++) +{ + int x, y; + for (y = 0; y < MAXY; y++) + for (x = 0; x < MAXX; x++) if (monster[mitem[x][y]].genocided) - mitem[x][y]=0; /* no more monster */ - } + mitem[x][y] = 0; /* no more monster */ +} diff --git a/larn/data.c b/larn/data.c index 7f57a15b..6a2eff8d 100644 --- a/larn/data.c +++ b/larn/data.c @@ -1,4 +1,4 @@ -/* $NetBSD: data.c,v 1.7 1997/07/13 20:21:33 christos Exp $ */ +/* $NetBSD: data.c,v 1.8 1997/10/18 20:03:10 christos Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -33,65 +33,68 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 -static char sccsid[] = "@(#)data.c 5.3 (Berkeley) 5/13/91"; +static char sccsid[] = "@(#)data.c 5.3 (Berkeley) 5/13/91"; #else -static char rcsid[] = "$NetBSD: data.c,v 1.7 1997/07/13 20:21:33 christos Exp $"; +__RCSID("$NetBSD: data.c,v 1.8 1997/10/18 20:03:10 christos Exp $"); #endif #endif /* not lint */ -/* data.c Larn is copyrighted 1986 by Noah Morgan. */ +/* data.c Larn is copyrighted 1986 by Noah Morgan. */ /* #define NODEFS */ #include "header.h" +#include "extern.h" /* class[c[LEVEL]-1] gives the correct name of the players experience level */ -static char aa1[] = " mighty evil master"; -static char aa2[] = "apprentice demi-god"; -static char aa3[] = " minor demi-god "; -static char aa4[] = " major demi-god "; -static char aa5[] = " minor deity "; -static char aa6[] = " major deity "; -static char aa7[] = " novice guardian "; -static char aa8[] = "apprentice guardian"; -static char aa9[] = " The Creator "; -char *class[]= -{ " novice explorer ", "apprentice explorer", " practiced explorer",/* -3*/ - " expert explorer ", " novice adventurer", " adventurer ",/* -6*/ - "apprentice conjurer", " conjurer ", " master conjurer ",/* -9*/ - " apprentice mage ", " mage ", " experienced mage ",/* -12*/ - " master mage ", " apprentice warlord", " novice warlord ",/* -15*/ - " expert warlord ", " master warlord ", " apprentice gorgon ",/* -18*/ - " gorgon ", " practiced gorgon ", " master gorgon ",/* -21*/ - " demi-gorgon ", " evil master ", " great evil master ",/* -24*/ - aa1 , aa1 , aa1 ,/* -27*/ - aa1 , aa1 , aa1 ,/* -30*/ - aa1 , aa1 , aa1 ,/* -33*/ - aa1 , aa1 , aa1 ,/* -36*/ - aa1 , aa1 , aa1 ,/* -39*/ - aa2 , aa2 , aa2 ,/* -42*/ - aa2 , aa2 , aa2 ,/* -45*/ - aa2 , aa2 , aa2 ,/* -48*/ - aa3 , aa3 , aa3 ,/* -51*/ - aa3 , aa3 , aa3 ,/* -54*/ - aa3 , aa3 , aa3 ,/* -57*/ - aa4 , aa4 , aa4 ,/* -60*/ - aa4 , aa4 , aa4 ,/* -63*/ - aa4 , aa4 , aa4 ,/* -66*/ - aa5 , aa5 , aa5 ,/* -69*/ - aa5 , aa5 , aa5 ,/* -72*/ - aa5 , aa5 , aa5 ,/* -75*/ - aa6 , aa6 , aa6 ,/* -78*/ - aa6 , aa6 , aa6 ,/* -81*/ - aa6 , aa6 , aa6 ,/* -84*/ - aa7 , aa7 , aa7 ,/* -87*/ - aa8 , aa8 , aa8 ,/* -90*/ - aa8 , aa8 , aa8 ,/* -93*/ - " earth guardian ", " air guardian ", " fire guardian ",/* -96*/ - " water guardian ", " time guardian ", " ethereal guardian ",/* -99*/ - aa9 , aa9 , aa9 ,/* -102*/ +static char aa1[] = " mighty evil master"; +static char aa2[] = "apprentice demi-god"; +static char aa3[] = " minor demi-god "; +static char aa4[] = " major demi-god "; +static char aa5[] = " minor deity "; +static char aa6[] = " major deity "; +static char aa7[] = " novice guardian "; +static char aa8[] = "apprentice guardian"; +static char aa9[] = " The Creator "; +u_char *class[] = +{ + " novice explorer ", "apprentice explorer", " practiced explorer", /* -3 */ + " expert explorer ", " novice adventurer", " adventurer ", /* -6 */ + "apprentice conjurer", " conjurer ", " master conjurer ", /* -9 */ + " apprentice mage ", " mage ", " experienced mage ", /* -12 */ + " master mage ", " apprentice warlord", " novice warlord ", /* -15 */ + " expert warlord ", " master warlord ", " apprentice gorgon ", /* -18 */ + " gorgon ", " practiced gorgon ", " master gorgon ", /* -21 */ + " demi-gorgon ", " evil master ", " great evil master ", /* -24 */ + aa1, aa1, aa1, /* -27 */ + aa1, aa1, aa1, /* -30 */ + aa1, aa1, aa1, /* -33 */ + aa1, aa1, aa1, /* -36 */ + aa1, aa1, aa1, /* -39 */ + aa2, aa2, aa2, /* -42 */ + aa2, aa2, aa2, /* -45 */ + aa2, aa2, aa2, /* -48 */ + aa3, aa3, aa3, /* -51 */ + aa3, aa3, aa3, /* -54 */ + aa3, aa3, aa3, /* -57 */ + aa4, aa4, aa4, /* -60 */ + aa4, aa4, aa4, /* -63 */ + aa4, aa4, aa4, /* -66 */ + aa5, aa5, aa5, /* -69 */ + aa5, aa5, aa5, /* -72 */ + aa5, aa5, aa5, /* -75 */ + aa6, aa6, aa6, /* -78 */ + aa6, aa6, aa6, /* -81 */ + aa6, aa6, aa6, /* -84 */ + aa7, aa7, aa7, /* -87 */ + aa8, aa8, aa8, /* -90 */ + aa8, aa8, aa8, /* -93 */ + " earth guardian ", " air guardian ", " fire guardian ", /* -96 */ + " water guardian ", " time guardian ", " ethereal guardian ", /* -99 */ + aa9, aa9, aa9, /* -102 */ }; /* @@ -99,333 +102,367 @@ char *class[]= skill[c[LEVEL]] is the experience required to attain the next level */ #define MEG 1000000 -long skill[] = { -0, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, /* 1-11 */ -10240, 20480, 40960, 100000, 200000, 400000, 700000, 1*MEG, /* 12-19 */ -2*MEG,3*MEG,4*MEG,5*MEG,6*MEG,8*MEG,10*MEG, /* 20-26 */ -12*MEG,14*MEG,16*MEG,18*MEG,20*MEG,22*MEG,24*MEG,26*MEG,28*MEG, /* 27-35 */ -30*MEG,32*MEG,34*MEG,36*MEG,38*MEG,40*MEG,42*MEG,44*MEG,46*MEG, /* 36-44 */ -48*MEG,50*MEG,52*MEG,54*MEG,56*MEG,58*MEG,60*MEG,62*MEG,64*MEG, /* 45-53 */ -66*MEG,68*MEG,70*MEG,72*MEG,74*MEG,76*MEG,78*MEG,80*MEG,82*MEG, /* 54-62 */ -84*MEG,86*MEG,88*MEG,90*MEG,92*MEG,94*MEG,96*MEG,98*MEG,100*MEG, /* 63-71 */ -105*MEG,110*MEG,115*MEG,120*MEG, 125*MEG, 130*MEG, 135*MEG, 140*MEG, /* 72-79 */ -145*MEG,150*MEG,155*MEG,160*MEG, 165*MEG, 170*MEG, 175*MEG, 180*MEG, /* 80-87 */ -185*MEG,190*MEG,195*MEG,200*MEG, 210*MEG, 220*MEG, 230*MEG, 240*MEG, /* 88-95 */ -250*MEG,260*MEG,270*MEG,280*MEG, 290*MEG, 300*MEG /* 96-101*/ +long skill[] = { + 0, 10, 20, 40, 80, 160, 320, 640, 1280, 2560, 5120, /* 1-11 */ + 10240, 20480, 40960, 100000, 200000, 400000, 700000, 1 * MEG, /* 12-19 */ + 2 * MEG, 3 * MEG, 4 * MEG, 5 * MEG, 6 * MEG, 8 * MEG, 10 * MEG, /* 20-26 */ + 12 * MEG, 14 * MEG, 16 * MEG, 18 * MEG, 20 * MEG, 22 * MEG, 24 * MEG, 26 * MEG, 28 * MEG, /* 27-35 */ + 30 * MEG, 32 * MEG, 34 * MEG, 36 * MEG, 38 * MEG, 40 * MEG, 42 * MEG, 44 * MEG, 46 * MEG, /* 36-44 */ + 48 * MEG, 50 * MEG, 52 * MEG, 54 * MEG, 56 * MEG, 58 * MEG, 60 * MEG, 62 * MEG, 64 * MEG, /* 45-53 */ + 66 * MEG, 68 * MEG, 70 * MEG, 72 * MEG, 74 * MEG, 76 * MEG, 78 * MEG, 80 * MEG, 82 * MEG, /* 54-62 */ + 84 * MEG, 86 * MEG, 88 * MEG, 90 * MEG, 92 * MEG, 94 * MEG, 96 * MEG, 98 * MEG, 100 * MEG, /* 63-71 */ + 105 * MEG, 110 * MEG, 115 * MEG, 120 * MEG, 125 * MEG, 130 * MEG, 135 * MEG, 140 * MEG, /* 72-79 */ + 145 * MEG, 150 * MEG, 155 * MEG, 160 * MEG, 165 * MEG, 170 * MEG, 175 * MEG, 180 * MEG, /* 80-87 */ + 185 * MEG, 190 * MEG, 195 * MEG, 200 * MEG, 210 * MEG, 220 * MEG, 230 * MEG, 240 * MEG, /* 88-95 */ + 250 * MEG, 260 * MEG, 270 * MEG, 280 * MEG, 290 * MEG, 300 * MEG /* 96-101 */ }; #undef MEG -char *lpbuf,*lpnt,*inbuffer,*lpend; /* input/output pointers to the buffers */ -struct cel *cell; /* pointer to the dungeon storage */ -short hitp[MAXX][MAXY]; /* monster hp on level */ -short iarg[MAXX][MAXY]; /* arg for the item array */ -char item[MAXX][MAXY]; /* objects in maze if any */ -char know[MAXX][MAXY]; /* 1 or 0 if here before */ -char mitem[MAXX][MAXY]; /* monster item array */ -char moved[MAXX][MAXY]; /* monster movement flags */ -char stealth[MAXX][MAXY]; /* 0=sleeping 1=awake monst*/ -char iven[26]; /* inventory for player */ -short ivenarg[26]; /* inventory for player */ -char lastmonst[40]; /* this has the name of the current monster */ -char beenhere[MAXLEVEL+MAXVLEVEL]={0}; /* 1 if have been on this level */ -char VERSION=VER; /* this is the present version # of the program */ -char SUBVERSION=SUBVER; -char nosignal=0; /* set to 1 to disable the signals from doing anything */ -char predostuff=0; /* 2 means that the trap handling routines must do a - showplayer() after a trap. 0 means don't showplayer() - 0 - we are in create player screen - 1 - we are in welcome screen - 2 - we are in the normal game */ -char loginname[20]; /* players login name */ -char logname[LOGNAMESIZE]; /* players name storage for scoring */ -char sex=1; /* default is a man 0=woman */ -char boldon=1; /* 1=bold objects 0=inverse objects */ -char ckpflag=0; /* 1 if want checkpointing of game, 0 otherwise */ -char cheat=0; /* 1 if the player has fudged save file */ -short level=0; /* cavelevel player is on = c[CAVELEVEL] */ -char wizard=0; /* the wizard mode flag */ -short lastnum=0; /* the number of the monster last hitting player */ -short hitflag=0; /* flag for if player has been hit when running */ -short hit2flag=0; /* flag for if player has been hit when running */ -short hit3flag=0; /* flag for if player has been hit flush input */ -short playerx,playery; /* the room on the present level of the player */ -short lastpx,lastpy; /* 0 --- MAXX-1 or 0 --- MAXY-1 */ -short oldx,oldy; -short lasthx=0,lasthy=0; /* location of monster last hit by player */ -short nobeep=0; /* true if program is not to beep */ -unsigned long randx=33601; /* the random number seed */ -long initialtime=0; /* time playing began */ -long gltime=0; /* the clock for the game */ -long outstanding_taxes=0; /* present tax bill from score file */ -long c[100],cbak[100]; /* the character description arrays */ -int enable_scroll=0; /* constant for enabled/disabled scrolling regn */ -char aborted[] = " aborted"; -struct sphere *spheres=0; /*pointer to linked list for spheres of annihilation*/ -char *levelname[]= -{ " H"," 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10","V1","V2","V3" }; - -char objnamelist[]=" ATOP%^F&^+M=%^$$f*OD#~][[)))(((||||||||{?!BC}o:@.<<<<EVV))([[]]](^ [H*** ^^ S tsTLc............................................"; -char monstnamelist[]=" BGHJKOScjtAELNQRZabhiCTYdegmvzFWflorXV pqsyUkMwDDPxnDDuD ..............................................................."; -char *objectname[]= -{ 0,"a holy altar","a handsome jewel encrusted throne","the orb","a pit", - "a staircase leading upwards","an elevator going up","a bubbling fountain", - "a great marble statue","a teleport trap","the college of Larn", - "a mirror","the DND store","a staircase going down","an elevator going down", - "the bank of Larn","the 5th branch of the Bank of Larn", - "a dead fountain","gold","an open door","a closed door", - "a wall","The Eye of Larn","plate mail","chain mail","leather armor", - "a sword of slashing","Bessman's flailing hammer","a sunsword", - "a two handed sword","a spear","a dagger", - "ring of extra regeneration","a ring of regeneration","a ring of protection", - "an energy ring","a ring of dexterity","a ring of strength", - "a ring of cleverness","a ring of increase damage","a belt of striking", - "a magic scroll","a magic potion","a book","a chest", - "an amulet of invisibility","an orb of dragon slaying", - "a scarab of negate spirit","a cube of undead control", - "device of theft prevention","a brilliant diamond","a ruby", - "an enchanting emerald","a sparkling sapphire","the dungeon entrance", - "a volcanic shaft leaning downward","the base of a volcanic shaft", - "a battle axe","a longsword","a flail","ring mail","studded leather armor", - "splint mail","plate armor","stainless plate armor","a lance of death", - "an arrow trap","an arrow trap","a shield","your home", - "gold","gold","gold","a dart trap", - "a dart trap","a trapdoor","a trapdoor","the local trading post", - "a teleport trap", "a massive throne", - "a sphere of annihilation","a handsome jewel encrusted throne", - "the Larn Revenue Service","a fortune cookie","","","","","","", - "","","","","","","","","","","","","","","","","","","","" - }; - - +u_char *lpbuf, *lpnt, *inbuffer, *lpend; /* input/output pointers + * to the buffers */ +struct cel *cell; /* pointer to the dungeon storage */ +short hitp[MAXX][MAXY]; /* monster hp on level */ +short iarg[MAXX][MAXY]; /* arg for the item array */ +u_char item[MAXX][MAXY]; /* objects in maze if any */ +u_char know[MAXX][MAXY]; /* 1 or 0 if here before */ +u_char mitem[MAXX][MAXY]; /* monster item array */ +u_char moved[MAXX][MAXY]; /* monster movement flags */ +u_char stealth[MAXX][MAXY]; /* 0=sleeping 1=awake monst */ +u_char iven[26]; /* inventory for player */ +short ivenarg[26]; /* inventory for player */ +char lastmonst[40]; /* this has the name of the current monster */ +u_char beenhere[MAXLEVEL + MAXVLEVEL] = {0}; /* 1 if have been on + * this level */ +char VERSION = VER; /* this is the present version # of the + * program */ +char SUBVERSION = SUBVER; +u_char nosignal = 0; /* set to 1 to disable the signals from doing + * anything */ +u_char predostuff = 0; /* 2 means that the trap handling routines + * must do a showplayer() after a trap. 0 + * means don't showplayer() 0 - we are in + * create player screen 1 - we are in welcome + * screen 2 - we are in the normal game */ +char loginname[20]; /* players login name */ +char logname[LOGNAMESIZE]; /* players name storage for scoring */ +u_char sex = 1; /* default is a man 0=woman */ +u_char boldon = 1; /* 1=bold objects 0=inverse objects */ +u_char ckpflag = 0; /* 1 if want checkpointing of game, 0 + * otherwise */ +u_char cheat = 0; /* 1 if the player has fudged save file */ +short level = 0; /* cavelevel player is on = c[CAVELEVEL] */ +u_char wizard = 0; /* the wizard mode flag */ +short lastnum = 0; /* the number of the monster last hitting + * player */ +short hitflag = 0; /* flag for if player has been hit when + * running */ +short hit2flag = 0; /* flag for if player has been hit when + * running */ +short hit3flag = 0; /* flag for if player has been hit flush + * input */ +short playerx, playery; /* the room on the present level of + * the player */ +short lastpx, lastpy; /* 0 --- MAXX-1 or 0 --- MAXY-1 */ +short oldx, oldy; +short lasthx = 0, lasthy = 0; /* location of monster last hit by + * player */ +short nobeep = 0; /* true if program is not to beep */ +unsigned long randx = 33601; /* the random number seed */ +long initialtime = 0;/* time playing began */ +long gltime = 0; /* the clock for the game */ +long outstanding_taxes = 0; /* present tax bill from score file */ +long c[100], cbak[100]; /* the character description arrays */ +int enable_scroll = 0; /* constant for enabled/disabled + * scrolling regn */ +char aborted[] = " aborted"; +struct sphere *spheres = 0; /* pointer to linked list for spheres of + * annihilation */ +char *levelname[] = +{" H", " 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10", "V1", "V2", "V3"}; + +char objnamelist[] = " ATOP%^F&^+M=%^$$f*OD#~][[)))(((||||||||{?!BC}o:@.<<<<EVV))([[]]](^ [H*** ^^ S tsTLc............................................"; +char monstnamelist[] = " BGHJKOScjtAELNQRZabhiCTYdegmvzFWflorXV pqsyUkMwDDPxnDDuD ..............................................................."; +char *objectname[] = +{0, "a holy altar", "a handsome jewel encrusted throne", "the orb", "a pit", + "a staircase leading upwards", "an elevator going up", "a bubbling fountain", + "a great marble statue", "a teleport trap", "the college of Larn", + "a mirror", "the DND store", "a staircase going down", "an elevator going down", + "the bank of Larn", "the 5th branch of the Bank of Larn", + "a dead fountain", "gold", "an open door", "a closed door", + "a wall", "The Eye of Larn", "plate mail", "chain mail", "leather armor", + "a sword of slashing", "Bessman's flailing hammer", "a sunsword", + "a two handed sword", "a spear", "a dagger", + "ring of extra regeneration", "a ring of regeneration", "a ring of protection", + "an energy ring", "a ring of dexterity", "a ring of strength", + "a ring of cleverness", "a ring of increase damage", "a belt of striking", + "a magic scroll", "a magic potion", "a book", "a chest", + "an amulet of invisibility", "an orb of dragon slaying", + "a scarab of negate spirit", "a cube of undead control", + "device of theft prevention", "a brilliant diamond", "a ruby", + "an enchanting emerald", "a sparkling sapphire", "the dungeon entrance", + "a volcanic shaft leaning downward", "the base of a volcanic shaft", + "a battle axe", "a longsword", "a flail", "ring mail", "studded leather armor", + "splint mail", "plate armor", "stainless plate armor", "a lance of death", + "an arrow trap", "an arrow trap", "a shield", "your home", + "gold", "gold", "gold", "a dart trap", + "a dart trap", "a trapdoor", "a trapdoor", "the local trading post", + "a teleport trap", "a massive throne", + "a sphere of annihilation", "a handsome jewel encrusted throne", + "the Larn Revenue Service", "a fortune cookie", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" +}; + + + /* * for the monster data * * array to do rnd() to create monsters <= a given level */ -char monstlevel[] = { 5, 11, 17, 22, 27, 33, 39, 42, 46, 50, 53, 56, 59 }; - -struct monst monster[] = { -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ------------------------------------------------------------------ */ -{ "", 0, 0, 0, 0, 0, 0, 3, 0, 0, 0 }, -{ "bat", 1, 0, 1, 0, 0, 0, 3, 0, 1, 1 }, -{ "gnome", 1, 10, 1, 0, 0, 0, 8, 30, 2, 2 }, -{ "hobgoblin", 1, 14, 2, 0, 0, 0, 5, 25, 3, 2 }, -{ "jackal", 1, 17, 1, 0, 0, 0, 4, 0, 1, 1 }, -{ "kobold", 1, 20, 1, 0, 0, 0, 7, 10, 1, 1 }, - -{ "orc", 2, 12, 1, 0, 0, 0, 9, 40, 4, 2 }, -{ "snake", 2, 15, 1, 0, 0, 0, 3, 0, 3, 1 }, -{ "giant centipede",2, 14, 0, 4, 0, 0, 3, 0, 1, 2 }, -{ "jaculi", 2, 20, 1, 0, 0, 0, 3, 0, 2, 1 }, -{ "troglodyte", 2, 10, 2, 0, 0, 0, 5, 80, 4, 3 }, -{ "giant ant", 2, 8, 1, 4, 0, 0, 4, 0, 5, 5 }, - -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ------------------------------------------------------------------ */ - -{ "floating eye", 3, 8, 1, 0, 0, 0, 3, 0, 5, 2 }, -{ "leprechaun", 3, 3, 0, 8, 0, 0, 3,1500, 13, 45 }, -{ "nymph", 3, 3, 0, 14, 0, 0, 9, 0, 18, 45 }, -{ "quasit", 3, 5, 3, 0, 0, 0, 3, 0, 10, 15 }, -{ "rust monster", 3, 4, 0, 1, 0, 0, 3, 0, 18, 25 }, -{ "zombie", 3, 12, 2, 0, 0, 0, 3, 0, 6, 7 }, - -{ "assassin bug", 4, 9, 3, 0, 0, 0, 3, 0, 20, 15 }, -{ "bugbear", 4, 5, 4, 15, 0, 0, 5, 40, 20, 35 }, -{ "hell hound", 4, 5, 2, 2, 0, 0, 6, 0, 16, 35 }, -{ "ice lizard", 4, 11, 2, 10, 0, 0, 6, 50, 16, 25 }, -{ "centaur", 4, 6, 4, 0, 0, 0, 10, 40, 24, 45 }, - -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ------------------------------------------------------------------ */ - -{ "troll", 5, 4, 5, 0, 0, 0, 9, 80, 50, 300 }, -{ "yeti", 5, 6, 4, 0, 0, 0, 5, 50, 35, 100 }, -{ "white dragon", 5, 2, 4, 5, 0, 0, 16, 500, 55, 1000}, -{ "elf", 5, 8, 1, 0, 0, 0, 15, 50, 22, 35 }, -{ "gelatinous cube",5, 9, 1, 0, 0, 0, 3, 0, 22, 45 }, - -{ "metamorph", 6, 7, 3, 0, 0, 0, 3, 0, 30, 40 }, -{ "vortex", 6, 4, 3, 0, 0, 0, 3, 0, 30, 55 }, -{ "ziller", 6, 15, 3, 0, 0, 0, 3, 0, 30, 35 }, -{ "violet fungi", 6, 12, 3, 0, 0, 0, 3, 0, 38, 100 }, -{ "wraith", 6, 3, 1, 6, 0, 0, 3, 0, 30, 325 }, -{ "forvalaka", 6, 2, 5, 0, 0, 0, 7, 0, 50, 280 }, - -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ------------------------------------------------------------------ */ - -{ "lama nobe", 7, 7, 3, 0, 0, 0, 6, 0, 35, 80 }, -{ "osequip", 7, 4, 3, 16, 0, 0, 4, 0, 35, 100 }, -{ "rothe", 7, 15, 5, 0, 0, 0, 3, 100, 50, 250 }, -{ "xorn", 7, 0, 6, 0, 0, 0, 13, 0, 60, 300 }, -{ "vampire", 7, 3, 4, 6, 0, 0, 17, 0, 50, 1000}, -{ "invisible stalker",7,3, 6, 0, 0, 0, 5, 0, 50, 350 }, - -{ "poltergeist", 8, 1, 4, 0, 0, 0, 3, 0, 50, 450 }, -{ "disenchantress", 8, 3, 0, 9, 0, 0, 3, 0, 50, 500 }, -{ "shambling mound",8, 2, 5, 0, 0, 0, 6, 0, 45, 400 }, -{ "yellow mold", 8, 12, 4, 0, 0, 0, 3, 0, 35, 250 }, -{ "umber hulk", 8, 3, 7, 11, 0, 0, 14, 0, 65, 600 }, - -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ------------------------------------------------------------------ */ - -{ "gnome king", 9, -1, 10, 0, 0, 0, 18, 2000, 100,3000 }, -{ "mimic", 9, 5, 6, 0, 0, 0, 8, 0, 55, 99 }, -{ "water lord", 9, -10, 15, 7, 0, 0, 20, 0, 150,15000 }, -{ "bronze dragon", 9, 2, 9, 3, 0, 0, 16, 300, 80, 4000 }, -{ "green dragon", 9, 3, 8, 10, 0, 0, 15, 200, 70, 2500 }, -{ "purple worm", 9, -1, 11, 0, 0, 0, 3, 100, 120,15000 }, -{ "xvart", 9, -2, 12, 0, 0, 0, 13, 0, 90, 1000 }, - -{ "spirit naga", 10, -20,12, 12, 0, 0, 23, 0, 95, 20000 }, -{ "silver dragon", 10, -1, 12, 3, 0, 0, 20, 700, 100,10000 }, -{ "platinum dragon",10, -5, 15, 13, 0, 0, 22, 1000, 130,24000 }, -{ "green urchin", 10, -3, 12, 0, 0, 0, 3, 0, 85, 5000 }, -{ "red dragon", 10, -2, 13, 3, 0, 0, 19, 800, 110,14000 }, - -{ "type I demon lord", 12,-30, 18, 0, 0, 0, 20, 0, 140,50000 }, -{ "type II demon lord", 13,-30, 18, 0, 0, 0, 21, 0, 160,75000 }, -{ "type III demon lord",14,-30, 18, 0, 0, 0, 22, 0, 180,100000 }, -{ "type IV demon lord", 15,-35, 20, 0, 0, 0, 23, 0, 200,125000 }, -{ "type V demon lord", 16,-40, 22, 0, 0, 0, 24, 0, 220,150000 }, -{ "type VI demon lord", 17,-45, 24, 0, 0, 0, 25, 0, 240,175000 }, -{ "type VII demon lord",18,-70, 27, 6, 0, 0, 26, 0, 260,200000 }, -{ "demon prince", 25,-127,30, 6, 0, 0, 28, 0, 345,300000 } - -/* NAME LV AC DAM ATT DEF GEN INT GOLD HP EXP ---------------------------------------------------------------------- */ - }; - -/* name array for scrolls */ - -char *scrollname[] = {"","","","","","","","","","","","","","", - "","","","","","","","","","","","","",""}; - -char *scrollhide[] = { -" enchant armor", -" enchant weapon", -" enlightenment", -" blank paper", -" create monster", -" create artifact", -" aggravate monsters", -" time warp", -" teleportation", -" expanded awareness", -" haste monsters", -" monster healing", -" spirit protection", -" undead protection", -" stealth", -" magic mapping", -" hold monsters", -" gem perfection", -" spell extension", -" identify", -" remove curse", -" annihilation", -" pulverization", -" life protection", -" ", -" ", -" ", -" " - }; - -char *potionname[] = {"","","","","","","","","","","","","","", - "","","","","","","","","","","","","","", - "","","","","","",""}; - -/* name array for magic potions */ -char *potionhide[] = { -" sleep", -" healing", -" raise level", -" increase ability", -" wisdom", -" strength", -" raise charisma", -" dizziness", -" learning", -" gold detection", -" monster detection", -" forgetfulness", -" water", -" blindness", -" confusion", -" heroism", -" sturdiness", -" giant strength", -" fire resistance", -" treasure finding", -" instant healing", -" cure dianthroritis", -" poison", -" see invisible", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" " - }; - - +u_char monstlevel[] = {5, 11, 17, 22, 27, 33, 39, 42, 46, 50, 53, 56, 59}; + +struct monst monster[] = { + /* + * NAME LV AC DAM ATT DEF GEN + * INT GOLD HP EXP + * ----------------------------------------------------------------- + */ + {"", 0, 0, 0, 0, 0, 0, 3, 0, 0, 0}, + {"bat", 1, 0, 1, 0, 0, 0, 3, 0, 1, 1}, + {"gnome", 1, 10, 1, 0, 0, 0, 8, 30, 2, 2}, + {"hobgoblin", 1, 14, 2, 0, 0, 0, 5, 25, 3, 2}, + {"jackal", 1, 17, 1, 0, 0, 0, 4, 0, 1, 1}, + {"kobold", 1, 20, 1, 0, 0, 0, 7, 10, 1, 1}, + + {"orc", 2, 12, 1, 0, 0, 0, 9, 40, 4, 2}, + {"snake", 2, 15, 1, 0, 0, 0, 3, 0, 3, 1}, + {"giant centipede", 2, 14, 0, 4, 0, 0, 3, 0, 1, 2}, + {"jaculi", 2, 20, 1, 0, 0, 0, 3, 0, 2, 1}, + {"troglodyte", 2, 10, 2, 0, 0, 0, 5, 80, 4, 3}, + {"giant ant", 2, 8, 1, 4, 0, 0, 4, 0, 5, 5}, + + /* + * NAME LV AC DAM ATT DEF GEN + * INT GOLD HP EXP + * ----------------------------------------------------------------- + */ + + {"floating eye", 3, 8, 1, 0, 0, 0, 3, 0, 5, 2}, + {"leprechaun", 3, 3, 0, 8, 0, 0, 3, 1500, 13, 45}, + {"nymph", 3, 3, 0, 14, 0, 0, 9, 0, 18, 45}, + {"quasit", 3, 5, 3, 0, 0, 0, 3, 0, 10, 15}, + {"rust monster", 3, 4, 0, 1, 0, 0, 3, 0, 18, 25}, + {"zombie", 3, 12, 2, 0, 0, 0, 3, 0, 6, 7}, + + {"assassin bug", 4, 9, 3, 0, 0, 0, 3, 0, 20, 15}, + {"bugbear", 4, 5, 4, 15, 0, 0, 5, 40, 20, 35}, + {"hell hound", 4, 5, 2, 2, 0, 0, 6, 0, 16, 35}, + {"ice lizard", 4, 11, 2, 10, 0, 0, 6, 50, 16, 25}, + {"centaur", 4, 6, 4, 0, 0, 0, 10, 40, 24, 45}, + + /* + * NAME LV AC DAM ATT DEF GEN + * INT GOLD HP EXP + * ----------------------------------------------------------------- + */ + + {"troll", 5, 4, 5, 0, 0, 0, 9, 80, 50, 300}, + {"yeti", 5, 6, 4, 0, 0, 0, 5, 50, 35, 100}, + {"white dragon", 5, 2, 4, 5, 0, 0, 16, 500, 55, 1000}, + {"elf", 5, 8, 1, 0, 0, 0, 15, 50, 22, 35}, + {"gelatinous cube", 5, 9, 1, 0, 0, 0, 3, 0, 22, 45}, + + {"metamorph", 6, 7, 3, 0, 0, 0, 3, 0, 30, 40}, + {"vortex", 6, 4, 3, 0, 0, 0, 3, 0, 30, 55}, + {"ziller", 6, 15, 3, 0, 0, 0, 3, 0, 30, 35}, + {"violet fungi", 6, 12, 3, 0, 0, 0, 3, 0, 38, 100}, + {"wraith", 6, 3, 1, 6, 0, 0, 3, 0, 30, 325}, + {"forvalaka", 6, 2, 5, 0, 0, 0, 7, 0, 50, 280}, + + /* + * NAME LV AC DAM ATT DEF GEN + * INT GOLD HP EXP + * ----------------------------------------------------------------- + */ + + {"lama nobe", 7, 7, 3, 0, 0, 0, 6, 0, 35, 80}, + {"osequip", 7, 4, 3, 16, 0, 0, 4, 0, 35, 100}, + {"rothe", 7, 15, 5, 0, 0, 0, 3, 100, 50, 250}, + {"xorn", 7, 0, 6, 0, 0, 0, 13, 0, 60, 300}, + {"vampire", 7, 3, 4, 6, 0, 0, 17, 0, 50, 1000}, + {"invisible stalker", 7, 3, 6, 0, 0, 0, 5, 0, 50, 350}, + + {"poltergeist", 8, 1, 4, 0, 0, 0, 3, 0, 50, 450}, + {"disenchantress", 8, 3, 0, 9, 0, 0, 3, 0, 50, 500}, + {"shambling mound", 8, 2, 5, 0, 0, 0, 6, 0, 45, 400}, + {"yellow mold", 8, 12, 4, 0, 0, 0, 3, 0, 35, 250}, + {"umber hulk", 8, 3, 7, 11, 0, 0, 14, 0, 65, 600}, + + /* + * NAME LV AC DAM ATT DEF GEN + * INT GOLD HP EXP + * ----------------------------------------------------------------- + */ + + {"gnome king", 9, -1, 10, 0, 0, 0, 18, 2000, 100, 3000}, + {"mimic", 9, 5, 6, 0, 0, 0, 8, 0, 55, 99}, + {"water lord", 9, -10, 15, 7, 0, 0, 20, 0, 150, 15000}, + {"bronze dragon", 9, 2, 9, 3, 0, 0, 16, 300, 80, 4000}, + {"green dragon", 9, 3, 8, 10, 0, 0, 15, 200, 70, 2500}, + {"purple worm", 9, -1, 11, 0, 0, 0, 3, 100, 120, 15000}, + {"xvart", 9, -2, 12, 0, 0, 0, 13, 0, 90, 1000}, + + {"spirit naga", 10, -20, 12, 12, 0, 0, 23, 0, 95, 20000}, + {"silver dragon", 10, -1, 12, 3, 0, 0, 20, 700, 100, 10000}, + {"platinum dragon", 10, -5, 15, 13, 0, 0, 22, 1000, 130, 24000}, + {"green urchin", 10, -3, 12, 0, 0, 0, 3, 0, 85, 5000}, + {"red dragon", 10, -2, 13, 3, 0, 0, 19, 800, 110, 14000}, + + {"type I demon lord", 12, -30, 18, 0, 0, 0, 20, 0, 140, 50000}, + {"type II demon lord", 13, -30, 18, 0, 0, 0, 21, 0, 160, 75000}, + {"type III demon lord", 14, -30, 18, 0, 0, 0, 22, 0, 180, 100000}, + {"type IV demon lord", 15, -35, 20, 0, 0, 0, 23, 0, 200, 125000}, + {"type V demon lord", 16, -40, 22, 0, 0, 0, 24, 0, 220, 150000}, + {"type VI demon lord", 17, -45, 24, 0, 0, 0, 25, 0, 240, 175000}, + {"type VII demon lord", 18, -70, 27, 6, 0, 0, 26, 0, 260, 200000}, + {"demon prince", 25, -127, 30, 6, 0, 0, 28, 0, 345, 300000} + + /* + * NAME LV AC DAM ATT DEF + * GEN INT GOLD HP EXP + * ------------------------------------------------------------------- + * -- + */ +}; + +/* name array for scrolls */ + +char *scrollname[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", +"", "", "", "", "", "", "", "", "", "", "", "", "", ""}; + +char *scrollhide[] = { + " enchant armor", + " enchant weapon", + " enlightenment", + " blank paper", + " create monster", + " create artifact", + " aggravate monsters", + " time warp", + " teleportation", + " expanded awareness", + " haste monsters", + " monster healing", + " spirit protection", + " undead protection", + " stealth", + " magic mapping", + " hold monsters", + " gem perfection", + " spell extension", + " identify", + " remove curse", + " annihilation", + " pulverization", + " life protection", + " ", + " ", + " ", + " " +}; + +char *potionname[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", +"", "", "", "", "", "", ""}; + +/* name array for magic potions */ +char *potionhide[] = { + " sleep", + " healing", + " raise level", + " increase ability", + " wisdom", + " strength", + " raise charisma", + " dizziness", + " learning", + " gold detection", + " monster detection", + " forgetfulness", + " water", + " blindness", + " confusion", + " heroism", + " sturdiness", + " giant strength", + " fire resistance", + " treasure finding", + " instant healing", + " cure dianthroritis", + " poison", + " see invisible", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " " +}; + + + /* spell data */ -char spelknow[SPNUM]={0}; -char splev[] = { 1, 4, 9, 14, 18, 22, 26, 29, 32, 35, 37, 37, 37, 37, 37 }; - -char *spelcode[]={ - "pro", "mle", "dex", "sle", "chm", "ssp", - "web", "str", "enl", "hel", "cbl", "cre", "pha", "inv", - "bal", "cld", "ply", "can", "has", "ckl", "vpr", - "dry", "lit", "drl", "glo", "flo", "fgr", - "sca", "hld", "stp", "tel", "mfi", /* 31 */ - "sph", "gen", "sum", "wtw", "alt", "per" - }; - -char *spelname[]={ - "protection", "magic missile", "dexterity", - "sleep", "charm monster", "sonic spear", - - "web", "strength", "enlightenment", - "healing", "cure blindness", "create monster", - "phantasmal forces", "invisibility", - - "fireball", "cold", "polymorph", - "cancellation", "haste self", "cloud kill", +u_char spelknow[SPNUM] = {0}; +u_char splev[] = {1, 4, 9, 14, 18, 22, 26, 29, 32, 35, 37, 37, 37, 37, 37}; + +char *spelcode[] = { + "pro", "mle", "dex", "sle", "chm", "ssp", + "web", "str", "enl", "hel", "cbl", "cre", "pha", "inv", + "bal", "cld", "ply", "can", "has", "ckl", "vpr", + "dry", "lit", "drl", "glo", "flo", "fgr", + "sca", "hld", "stp", "tel", "mfi", /* 31 */ + "sph", "gen", "sum", "wtw", "alt", "per" +}; + +char *spelname[] = { + "protection", "magic missile", "dexterity", + "sleep", "charm monster", "sonic spear", + + "web", "strength", "enlightenment", + "healing", "cure blindness", "create monster", + "phantasmal forces", "invisibility", + + "fireball", "cold", "polymorph", + "cancellation", "haste self", "cloud kill", "vaporize rock", - "dehydration", "lightning", "drain life", - "invulnerability", "flood", "finger of death", + "dehydration", "lightning", "drain life", + "invulnerability", "flood", "finger of death", - "scare monster", "hold monster", "time stop", - "teleport away", "magic fire", + "scare monster", "hold monster", "time stop", + "teleport away", "magic fire", - "sphere of annihilation", "genocide", "summon demon", - "walk through walls", "alter reality", "permanence", + "sphere of annihilation", "genocide", "summon demon", + "walk through walls", "alter reality", "permanence", "" - }; +}; -char *speldescript[]={ -/* 1 */ +char *speldescript[] = { + /* 1 */ "generates a +2 protection field", "creates and hurls a magic missile equivalent to a + 1 magic arrow", "adds +2 to the casters dexterity", "causes some monsters to go to sleep", "some monsters may be awed at your magnificence", "causes your hands to emit a screeching sound toward what they point", -/* 7 */ + /* 7 */ "causes strands of sticky thread to entangle an enemy", "adds +2 to the casters strength for a short term", "the caster becomes aware of things around him", @@ -434,7 +471,7 @@ char *speldescript[]={ "creates a monster near the caster appropriate for the location", "creates illusions, and if believed, monsters die", "the caster becomes invisible", -/* 15 */ + /* 15 */ "makes a ball of fire that burns on what it hits", "sends forth a cone of cold which freezes what it touches", "you can find out what this does for yourself", @@ -442,20 +479,20 @@ char *speldescript[]={ "speeds up the casters movements", "creates a fog of poisonous gas which kills all that is within it", "this changes rock to air", -/* 22 */ + /* 22 */ "dries up water in the immediate vicinity", "you finger will emit a lightning bolt when this spell is cast", "subtracts hit points from both you and a monster", "this globe helps to protect the player from physical attack", "this creates an avalanche of H2O to flood the immediate chamber", "this is a holy spell and calls upon your god to back you up", -/* 28 */ + /* 28 */ "terrifies the monster so that hopefully he wont hit the magic user", "the monster is frozen in his tracks if this is successful", "all movement in the caverns ceases for a limited duration", "moves a particular monster around in the dungeon (hopefully away from you)", "this causes a curtain of fire to appear all around you", -/* 33 */ + /* 33 */ "anything caught in this sphere is instantly killed. Warning -- dangerous", "eliminates a species of monster from the game -- use sparingly", "summons a demon who hopefully helps you out", @@ -463,165 +500,185 @@ char *speldescript[]={ "god only knows what this will do", "makes a character spell permanent, i. e. protection, strength, etc.", "" - }; - -char spelweird[MAXMONST+8][SPNUM] = { -/* p m d s c s w s e h c c p i b c p c h c v d l d g f f s h s t m s g s w a p */ -/* r l e l h s e t n e b r h n a l l a a k p r i r l l g c l t e f p e u t l e */ -/* o e x e m p b r l l l e a v l d y n s l r y t l o o r a d p l i h n m w t r */ - - -/* bat */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* gnome */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* hobgoblin */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* jackal */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* kobold */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* orc */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 4,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* snake */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/*giant centipede */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* jaculi */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* troglodyte */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* giant ant */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* floating eye */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* leprechaun */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* nymph */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* quasit */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* rust monster */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 4,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* zombie */ { 0,0,0,8,0,4, 0,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 4,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* assassin bug */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* bugbear */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* hell hound */ { 0,6,0,0,0,0, 12,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* ice lizard */ { 0,0,0,0,0,0, 11,0,0,0,0,0,0,0, 0,15,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* centaur */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* troll */ { 0,7,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 4,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* yeti */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,15,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* white dragon */ { 0,0,0,0,0,0, 0,0,0,0,0,0,14,0, 0,15,0,0,0,0,0, 4,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* elf */ { 0,0,0,0,0,0, 0,0,0,0,0,0,14,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/*gelatinous cube */ { 0,0,0,0,0,0, 2,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 0,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* metamorph */ { 0,13,0,0,0,0, 2,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 4,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* vortex */ { 0,13,0,0,0,10, 1,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* ziller */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* violet fungi */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* wraith */ { 0,0,0,8,0,4, 0,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 4,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* forvalaka */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* lama nobe */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* osequip */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* rothe */ { 0,7,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* xorn */ { 0,7,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 4,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* vampire */ { 0,0,0,8,0,4, 0,0,0,0,0,0,0,0, 0,0,0,0,0,4,0, 0,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/*invisible staker*/ { 0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* poltergeist */ { 0,13,0,8,0,4, 1,0,0,0,0,0,0,0, 0,4,0,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* disenchantress */ { 0,0,0,8,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/*shambling mound */ { 0,0,0,0,0,10, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* yellow mold */ { 0,0,0,8,0,0, 1,0,0,0,0,0,4,0, 0,0,0,0,0,4,0, 0,0,0,0,0,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* umber hulk */ { 0,7,0,0,0,0, 0,0,0,0,0,0,0,5, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* gnome king */ { 0,7,0,0,3,0, 0,0,0,0,0,0,0,5, 0,0,9,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* mimic */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* water lord */ { 0,13,0,8,3,4, 1,0,0,0,0,0,0,0, 0,0,9,0,0,4,0, 0,0,0,0,16,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* bronze dragon */ { 0,7,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* green dragon */ { 0,7,0,0,0,0, 11,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* purple worm */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* xvart */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* spirit naga */ { 0,13,0,8,3,4, 1,0,0,0,0,0,0,5, 0,4,9,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* silver dragon */ { 0,6,0,9,0,0, 12,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/*platinum dragon */ { 0,7,0,9,0,0, 11,0,0,0,0,0,14,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* green urchin */ { 0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, -/* red dragon */ { 0,6,0,0,0,0, 12,0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0,0 }, - -/* p m d s c s w s e h c c p i b c p c h c v d l d g f f s h s t m s g s w a p */ -/* r l e l h s e t n e b r h n a l l a a k p r i r l l g c l t e f p e u t l e */ -/* o e x e m p b r l l l e a v l d y n s l r y t l o o r a d p l i h n m w t r */ - -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon lord */ { 0,7,0,4,3,0, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 0,0,0,0,0, 9,0,0,0,0,0 }, -/* demon prince */ { 0,7,0,4,3,9, 1,0,0,0,0,0,14,5, 0,0,4,0,0,4,0, 4,0,0,0,4,4, 4,0,0,0,4, 9,0,0,0,0,0 } - - }; - -char *spelmes[] = { "", -/* 1 */ "the web had no effect on the %s", -/* 2 */ "the %s changed shape to avoid the web", -/* 3 */ "the %s isn't afraid of you", -/* 4 */ "the %s isn't affected", -/* 5 */ "the %s can see you with his infravision", -/* 6 */ "the %s vaporizes your missile", -/* 7 */ "your missile bounces off the %s", -/* 8 */ "the %s doesn't sleep", -/* 9 */ "the %s resists", -/* 10 */ "the %s can't hear the noise", -/* 11 */ "the %s's tail cuts it free of the web", -/* 12 */ "the %s burns through the web", -/* 13 */ "your missiles pass right through the %s", -/* 14 */ "the %s sees through your illusions", -/* 15 */ "the %s loves the cold!", -/* 16 */ "the %s loves the water!" - }; - -char to_lower[]= /* tolower[character] = lower case converted character */ - { - 0000,0001,0002,0003,0004,0005,0006,0007,0010,0011,0012,0013,0014,0015,0016,0017, /* NUL-SI*/ - 0020,0021,0022,0023,0024,0025,0026,0027,0030,0031,0032,0033,0034,0035,0036,0037, /* DLE-US*/ - 0040,0041,0042,0043,0044,0045,0046,0047,0050,0051,0052,0053,0054,0055,0056,0057, /* SP-/ */ - 0060,0061,0062,0063,0064,0065,0066,0067,0070,0071,0072,0073,0074,0075,0076,0077, /* 0-? */ - 0100,0141,0142,0143,0144,0145,0146,0147,0150,0151,0152,0153,0154,0155,0156,0157, /* @-O */ - 0160,0161,0162,0163,0164,0165,0166,0167,0170,0171,0172,0133,0134,0135,0136,0137, /* P-_ */ - 0140,0141,0142,0143,0144,0145,0146,0147,0150,0151,0152,0153,0154,0155,0156,0157, /* `-o */ - 0160,0161,0162,0163,0164,0165,0166,0167,0170,0171,0172,0173,0174,0175,0176,0177, /* p-DEL */ - }; - -char to_upper[]= /* toupper[character] = upper case converted character */ - { - 0000,0001,0002,0003,0004,0005,0006,0007,0010,0011,0012,0013,0014,0015,0016,0017, /* NUL-SI*/ - 0020,0021,0022,0023,0024,0025,0026,0027,0030,0031,0032,0033,0034,0035,0036,0037, /* DLE-US*/ - 0040,0041,0042,0043,0044,0045,0046,0047,0050,0051,0052,0053,0054,0055,0056,0057, /* SP-/ */ - 0060,0061,0062,0063,0064,0065,0066,0067,0070,0071,0072,0073,0074,0075,0076,0077, /* 0-? */ - 0100,0101,0102,0103,0104,0105,0106,0107,0110,0111,0112,0113,0114,0115,0116,0117, /* @-O */ - 0120,0121,0122,0123,0124,0125,0126,0127,0130,0131,0132,0133,0134,0135,0136,0137, /* P-_ */ - 0140,0101,0102,0103,0104,0105,0106,0107,0110,0111,0112,0113,0114,0115,0116,0117, /* `-o */ - 0120,0121,0122,0123,0124,0125,0126,0127,0130,0131,0132,0173,0174,0175,0176,0177, /* p-DEL */ - }; - -char is_digit[]= /* isdigit[character] = TRUE || FALSE */ - { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* NUL-SI*/ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* DLE-US*/ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* SP-/ */ - 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 0-? */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* @-O */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* P-_ */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* `-o */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* p-DEL */ - }; - -char is_alpha[]= /* isalpha[character] = TRUE || FALSE */ - { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* NUL-SI*/ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* DLE-US*/ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* SP-/ */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0-? */ - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* @-O */ - 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* P-_ */ - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* `-o */ - 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, /* p-DEL */ - }; +}; + +char spelweird[MAXMONST + 8][SPNUM] = { + /* + * p m d s c s w s e h c c p i b c p c h c v d l d g f f + * s h s t m s g s w a p + */ + /* + * r l e l h s e t n e b r h n a l l a a k p r i r l l g + * c l t e f p e u t l e + */ + /* + * o e x e m p b r l l l e a v l d y n s l r y t l o o r + * a d p l i h n m w t r + */ + + + /* bat */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* gnome */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* hobgoblin */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* jackal */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* kobold */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* orc */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* snake */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* giant centipede */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* jaculi */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* troglodyte */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* giant ant */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* floating eye */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* leprechaun */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* nymph */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* quasit */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* rust monster */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* zombie */ {0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* assassin bug */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* bugbear */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* hell hound */ {0, 6, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* ice lizard */ {0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* centaur */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* troll */ {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* yeti */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* white dragon */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 15, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* elf */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* gelatinous cube */ {0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* metamorph */ {0, 13, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* vortex */ {0, 13, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* ziller */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* violet fungi */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* wraith */ {0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* forvalaka */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* lama nobe */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* osequip */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* rothe */ {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* xorn */ {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* vampire */ {0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* invisible staker */ {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* poltergeist */ {0, 13, 0, 8, 0, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* disenchantress */ {0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* shambling mound */ {0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* yellow mold */ {0, 0, 0, 8, 0, 0, 1, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* umber hulk */ {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* gnome king */ {0, 7, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* mimic */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* water lord */ {0, 13, 0, 8, 3, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 4, 0, 0, 0, 0, 0, 16, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* bronze dragon */ {0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* green dragon */ {0, 7, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* purple worm */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* xvart */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* spirit naga */ {0, 13, 0, 8, 3, 4, 1, 0, 0, 0, 0, 0, 0, 5, 0, 4, 9, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* silver dragon */ {0, 6, 0, 9, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* platinum dragon */ {0, 7, 0, 9, 0, 0, 11, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* green urchin */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + /* red dragon */ {0, 6, 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + + /* + * p m d s c s w s e h c c p i b c p c h c v d l d g f f + * s h s t m s g s w a p + */ + /* + * r l e l h s e t n e b r h n a l l a a k p r i r l l g + * c l t e f p e u t l e + */ + /* + * o e x e m p b r l l l e a v l d y n s l r y t l o o r + * a d p l i h n m w t r + */ + + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon lord */ {0, 7, 0, 4, 3, 0, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0}, + /* demon prince */ {0, 7, 0, 4, 3, 9, 1, 0, 0, 0, 0, 0, 14, 5, 0, 0, 4, 0, 0, 4, 0, 4, 0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 9, 0, 0, 0, 0, 0} + +}; + +char *spelmes[] = {"", + /* 1 */ "the web had no effect on the %s", + /* 2 */ "the %s changed shape to avoid the web", + /* 3 */ "the %s isn't afraid of you", + /* 4 */ "the %s isn't affected", + /* 5 */ "the %s can see you with his infravision", + /* 6 */ "the %s vaporizes your missile", + /* 7 */ "your missile bounces off the %s", + /* 8 */ "the %s doesn't sleep", + /* 9 */ "the %s resists", + /* 10 */ "the %s can't hear the noise", + /* 11 */ "the %s's tail cuts it free of the web", + /* 12 */ "the %s burns through the web", + /* 13 */ "your missiles pass right through the %s", + /* 14 */ "the %s sees through your illusions", + /* 15 */ "the %s loves the cold!", + /* 16 */ "the %s loves the water!" +}; + +u_char to_lower[] = /* tolower[character] = lower case converted + * character */ +{ + 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007, 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017, /* NUL-SI */ + 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027, 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037, /* DLE-US */ + 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047, 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057, /* SP-/ */ + 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077, /* 0-? */ + 0100, 0141, 0142, 0143, 0144, 0145, 0146, 0147, 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157, /* @-O */ + 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167, 0170, 0171, 0172, 0133, 0134, 0135, 0136, 0137, /* P-_ */ + 0140, 0141, 0142, 0143, 0144, 0145, 0146, 0147, 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157, /* `-o */ + 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167, 0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177, /* p-DEL */ +}; + +u_char to_upper[] = /* toupper[character] = upper case converted + * character */ +{ + 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007, 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017, /* NUL-SI */ + 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027, 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037, /* DLE-US */ + 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047, 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057, /* SP-/ */ + 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077, /* 0-? */ + 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, /* @-O */ + 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, /* P-_ */ + 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, /* `-o */ + 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, /* p-DEL */ +}; + +u_char is_digit[] = /* isdigit[character] = TRUE || FALSE */ +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* NUL-SI */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DLE-US */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* SP-/ */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0-? */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @-O */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* P-_ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* `-o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* p-DEL */ +}; + +u_char is_alpha[] = /* isalpha[character] = TRUE || FALSE */ +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* NUL-SI */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DLE-US */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* SP-/ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-? */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* @-O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* P-_ */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* `-o */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* p-DEL */ +}; /* - * function to create scroll numbers with appropriate probability of + * function to create scroll numbers with appropriate probability of * occurrence * * 0 - armor 1 - weapon 2 - enlightenment 3 - paper @@ -633,11 +690,11 @@ char is_alpha[]= /* isalpha[character] = TRUE || FALSE */ * 20 - remove curse 21 - annihilation 22 - pulverization * 23 - life protection */ -char scprob[]= { 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, +u_char scprob[] = {0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 20, 21, 22, - 22, 22, 23 }; +22, 22, 23}; /* * function to return a potion number created with appropriate probability @@ -652,10 +709,10 @@ char scprob[]= { 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, * 18 - fire resistance 19 - treasure finding 20 - instant healing * 21 - cure dianthroritis 22 - poison 23 - see invisible */ -char potprob[] = { 0, 0, 1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 20, 22, 22, 23, 23 }; +u_char potprob[] = {0, 0, 1, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 20, 22, 22, 23, 23}; -char nlpts[] = { 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7 }; -char nch[] = { 0, 0, 0, 1, 1, 1, 2, 2, 3, 4 }; -char nplt[] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 4 }; -char ndgg[] = { 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5 }; -char nsw[] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3 }; +u_char nlpts[] = {0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7}; +u_char nch[] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4}; +u_char nplt[] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 4}; +u_char ndgg[] = {0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5}; +u_char nsw[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3}; diff --git a/larn/diag.c b/larn/diag.c index 26324ad3..3e32d56c 100644 --- a/larn/diag.c +++ b/larn/diag.c @@ -1,15 +1,18 @@ +/* $NetBSD: diag.c,v 1.8 1997/10/18 20:03:12 christos Exp $ */ + +/* diag.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: diag.c,v 1.7 1997/07/13 20:21:34 christos Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: diag.c,v 1.8 1997/10/18 20:03:12 christos Exp $"); +#endif /* not lint */ -/* diag.c Larn is copyrighted 1986 by Noah Morgan. */ #include <sys/types.h> #include <sys/times.h> #include <sys/stat.h> +#include <stdlib.h> +#include <unistd.h> #include "header.h" -extern long int initialtime; -extern int rmst,maxitm,lasttime; -extern char nosignal; +#include "extern.h" static struct tms cputime; /* *************************** @@ -19,47 +22,47 @@ static struct tms cputime; subroutine to print out data for debugging */ #ifdef EXTRA -static int rndcount[16]; +static int rndcount[16]; +void diag() - { - register int i,j; - int hit,dam; - cursors(); lwclose(); - if (lcreat(diagfile) < 0) /* open the diagnostic file */ - { - lcreat((char*)0); lprcat("\ndiagnostic failure\n"); return(-1); - } - - write(1,"\nDiagnosing . . .\n",18); +{ + int i, j; + int hit, dam; + cursors(); + lwclose(); + if (lcreat(diagfile) < 0) { /* open the diagnostic file */ + lcreat((char *) 0); + lprcat("\ndiagnostic failure\n"); + return (-1); + } + write(1, "\nDiagnosing . . .\n", 18); lprcat("\n\nBeginning of DIAG diagnostics ----------\n"); -/* for the character attributes */ + /* for the character attributes */ - lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)",(long)c[HP],(long)c[HPMAX]); + lprintf("\n\nPlayer attributes:\n\nHit points: %2d(%2d)", (long) c[HP], (long) c[HPMAX]); lprintf("\ngold: %d Experience: %d Character level: %d Level in caverns: %d", - (long)c[GOLD],(long)c[EXPERIENCE],(long)c[LEVEL],(long)level); - lprintf("\nTotal types of monsters: %d",(long)MAXMONST+8); + (long) c[GOLD], (long) c[EXPERIENCE], (long) c[LEVEL], (long) level); + lprintf("\nTotal types of monsters: %d", (long) MAXMONST + 8); lprcat("\f\nHere's the dungeon:\n\n"); - i=level; - for (j=0; j<MAXLEVEL+MAXVLEVEL; j++) - { + i = level; + for (j = 0; j < MAXLEVEL + MAXVLEVEL; j++) { newcavelevel(j); - lprintf("\nMaze for level %s:\n",levelname[level]); + lprintf("\nMaze for level %s:\n", levelname[level]); diagdrawscreen(); - } + } newcavelevel(i); lprcat("\f\nNow for the monster data:\n\n"); lprcat(" Monster Name LEV AC DAM ATT DEF GOLD HP EXP \n"); lprcat("--------------------------------------------------------------------------\n"); - for (i=0; i<=MAXMONST+8; i++) - { - lprintf("%19s %2d %3d ",monster[i].name,(long)monster[i].level,(long)monster[i].armorclass); - lprintf(" %3d %3d %3d ",(long)monster[i].damage,(long)monster[i].attack,(long)monster[i].defense); - lprintf("%6d %3d %6d\n",(long)monster[i].gold,(long)monster[i].hitpoints,(long)monster[i].experience); - } + for (i = 0; i <= MAXMONST + 8; i++) { + lprintf("%19s %2d %3d ", monster[i].name, (long) monster[i].level, (long) monster[i].armorclass); + lprintf(" %3d %3d %3d ", (long) monster[i].damage, (long) monster[i].attack, (long) monster[i].defense); + lprintf("%6d %3d %6d\n", (long) monster[i].gold, (long) monster[i].hitpoints, (long) monster[i].experience); + } lprcat("\n\nHere's a Table for the to hit percentages\n"); lprcat("\n We will be assuming that players level = 2 * monster level"); @@ -70,249 +73,333 @@ diag() lprcat("\n Each entry is as follows: to hit / damage / number hits to kill\n"); lprcat("\n monster WC = 4 WC = 20 WC = 40"); lprcat("\n---------------------------------------------------------------"); - for (i=0; i<=MAXMONST+8; i++) - { - hit = 2*monster[i].armorclass+2*monster[i].level+16; + for (i = 0; i <= MAXMONST + 8; i++) { + hit = 2 * monster[i].armorclass + 2 * monster[i].level + 16; dam = 16 - c[HARDGAME]; lprintf("\n%20s %2d/%2d/%2d %2d/%2d/%2d %2d/%2d/%2d", - monster[i].name, - (long)(hit/2),(long)max(0,dam+2),(long)(monster[i].hitpoints/(dam+2)+1), - (long)((hit+2)/2),(long)max(0,dam+10),(long)(monster[i].hitpoints/(dam+10)+1), - (long)((hit+5)/2),(long)max(0,dam+20),(long)(monster[i].hitpoints/(dam+20)+1)); - } + monster[i].name, + (long) (hit / 2), (long) max(0, dam + 2), (long) (monster[i].hitpoints / (dam + 2) + 1), + (long) ((hit + 2) / 2), (long) max(0, dam + 10), (long) (monster[i].hitpoints / (dam + 10) + 1), + (long) ((hit + 5) / 2), (long) max(0, dam + 20), (long) (monster[i].hitpoints / (dam + 20) + 1)); + } lprcat("\n\nHere's the list of available potions:\n\n"); - for (i=0; i<MAXPOTION; i++) lprintf("%20s\n",&potionhide[i][1]); + for (i = 0; i < MAXPOTION; i++) + lprintf("%20s\n", &potionhide[i][1]); lprcat("\n\nHere's the list of available scrolls:\n\n"); - for (i=0; i<MAXSCROLL; i++) lprintf("%20s\n",&scrollhide[i][1]); + for (i = 0; i < MAXSCROLL; i++) + lprintf("%20s\n", &scrollhide[i][1]); lprcat("\n\nHere's the spell list:\n\n"); lprcat("spell name description\n"); lprcat("-------------------------------------------------------------------------------------------\n\n"); - for (j=0; j<SPNUM; j++) - { - lprc(' '); lprcat(spelcode[j]); - lprintf(" %21s %s\n",spelname[j],speldescript[j]); - } + for (j = 0; j < SPNUM; j++) { + lprc(' '); + lprcat(spelcode[j]); + lprintf(" %21s %s\n", spelname[j], speldescript[j]); + } lprcat("\n\nFor the c[] array:\n"); - for (j=0; j<100; j+=10) - { - lprintf("\nc[%2d] = ",(long)j); for (i=0; i<9; i++) lprintf("%5d ",(long)c[i+j]); - } + for (j = 0; j < 100; j += 10) { + lprintf("\nc[%2d] = ", (long) j); + for (i = 0; i < 9; i++) + lprintf("%5d ", (long) c[i + j]); + } lprcat("\n\nTest of random number generator ----------------"); lprcat("\n for 25,000 calls divided into 16 slots\n\n"); - for (i=0; i<16; i++) rndcount[i]=0; - for (i=0; i<25000; i++) rndcount[rund(16)]++; - for (i=0; i<16; i++) { lprintf(" %5d",(long)rndcount[i]); if (i==7) lprc('\n'); } - - lprcat("\n\n"); lwclose(); - lcreat((char*)0); lprcat("Done Diagnosing . . ."); - return(0); + for (i = 0; i < 16; i++) + rndcount[i] = 0; + for (i = 0; i < 25000; i++) + rndcount[rund(16)]++; + for (i = 0; i < 16; i++) { + lprintf(" %5d", (long) rndcount[i]); + if (i == 7) + lprc('\n'); } + + lprcat("\n\n"); + lwclose(); + lcreat((char *) 0); + lprcat("Done Diagnosing . . ."); + return (0); +} /* subroutine to count the number of occurrences of an object */ +int dcount(l) int l; - { - register int i,j,p; +{ + int i, j, p; int k; - k=0; - for (i=0; i<MAXX; i++) - for (j=0; j<MAXY; j++) - for (p=0; p<MAXLEVEL; p++) - if (cell[p*MAXX*MAXY+i*MAXY+j].item == l) k++; - return(k); - } + k = 0; + for (i = 0; i < MAXX; i++) + for (j = 0; j < MAXY; j++) + for (p = 0; p < MAXLEVEL; p++) + if (cell[p * MAXX * MAXY + i * MAXY + j].item == l) + k++; + return (k); +} /* subroutine to draw the whole screen as the player knows it */ +void diagdrawscreen() - { - register int i,j,k; - - for (i=0; i<MAXY; i++) +{ + int i, j, k; -/* for the east west walls of this line */ - { - for (j=0; j<MAXX; j++) if (k=mitem[j][i]) lprc(monstnamelist[k]); else - lprc(objnamelist[item[j][i]]); + for (i = 0; i < MAXY; i++) + /* for the east west walls of this line */ + { + for (j = 0; j < MAXX; j++) + if (k = mitem[j][i]) + lprc(monstnamelist[k]); + else + lprc(objnamelist[item[j][i]]); lprc('\n'); - } } +} #endif - + + /* to save the game in a file */ -static time_t zzz=0; +static time_t zzz = 0; +int savegame(fname) char *fname; - { - register int i,k; - register struct sphere *sp; - struct stat statbuf; - nosignal=1; lflush(); savelevel(); - ointerest(); - if (lcreat(fname) < 0) - { - lcreat((char*)0); lprintf("\nCan't open file <%s> to save game\n",fname); - nosignal=0; return(-1); - } +{ + int i, k; + struct sphere *sp; + struct stat statbuf; + nosignal = 1; + lflush(); + savelevel(); + ointerest(); + if (lcreat(fname) < 0) { + lcreat((char *) 0); + lprintf("\nCan't open file <%s> to save game\n", fname); + nosignal = 0; + return (-1); + } set_score_output(); - lwrite((char*)beenhere,MAXLEVEL+MAXVLEVEL); - for (k=0; k<MAXLEVEL+MAXVLEVEL; k++) + lwrite((char *) beenhere, MAXLEVEL + MAXVLEVEL); + for (k = 0; k < MAXLEVEL + MAXVLEVEL; k++) if (beenhere[k]) - lwrite((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX); + lwrite((char *) &cell[k * MAXX * MAXY], sizeof(struct cel) * MAXY * MAXX); times(&cputime); /* get cpu time */ - c[CPUTIME] += (cputime.tms_utime+cputime.tms_stime)/60; - lwrite((char*)&c[0],100*sizeof(long)); - lprint((long)gltime); lprc(level); - lprc(playerx); lprc(playery); - lwrite((char*)iven,26); lwrite((char*)ivenarg,26*sizeof(short)); - for (k=0; k<MAXSCROLL; k++) lprc(scrollname[k][0]); - for (k=0; k<MAXPOTION; k++) lprc(potionname[k][0]); - lwrite((char*)spelknow,SPNUM); lprc(wizard); - lprc(rmst); /* random monster generation counter */ - for (i=0; i<90; i++) lprc(itm[i].qty); - lwrite((char*)course,25); lprc(cheat); lprc(VERSION); - for (i=0; i<MAXMONST; i++) lprc(monster[i].genocided); /* genocide info */ - for (sp=spheres; sp; sp=sp->p) - lwrite((char*)sp,sizeof(struct sphere)); /* save spheres of annihilation */ - time(&zzz); lprint((long)(zzz-initialtime)); - lwrite((char*)&zzz,sizeof(long)); - if (fstat(lfd,&statbuf)< 0) lprint(0L); - else lprint((long)statbuf.st_ino); /* inode # */ - lwclose(); lastmonst[0] = 0; + c[CPUTIME] += (cputime.tms_utime + cputime.tms_stime) / 60; + lwrite((char *) &c[0], 100 * sizeof(long)); + lprint((long) gltime); + lprc(level); + lprc(playerx); + lprc(playery); + lwrite((char *) iven, 26); + lwrite((char *) ivenarg, 26 * sizeof(short)); + for (k = 0; k < MAXSCROLL; k++) + lprc(scrollname[k][0]); + for (k = 0; k < MAXPOTION; k++) + lprc(potionname[k][0]); + lwrite((char *) spelknow, SPNUM); + lprc(wizard); + lprc(rmst); /* random monster generation counter */ + for (i = 0; i < 90; i++) + lprc(itm[i].qty); + lwrite((char *) course, 25); + lprc(cheat); + lprc(VERSION); + for (i = 0; i < MAXMONST; i++) + lprc(monster[i].genocided); /* genocide info */ + for (sp = spheres; sp; sp = sp->p) + lwrite((char *) sp, sizeof(struct sphere)); /* save spheres of + * annihilation */ + time(&zzz); + lprint((long) (zzz - initialtime)); + lwrite((char *) &zzz, sizeof(long)); + if (fstat(lfd, &statbuf) < 0) + lprint(0L); + else + lprint((long) statbuf.st_ino); /* inode # */ + lwclose(); + lastmonst[0] = 0; #ifndef VT100 setscroll(); -#endif VT100 - lcreat((char*)0); nosignal=0; - return(0); - } +#endif /* VT100 */ + lcreat((char *) 0); + nosignal = 0; + return (0); +} +void restoregame(fname) - char *fname; - { - register int i,k; - register struct sphere *sp,*sp2; - struct stat filetimes; - cursors(); lprcat("\nRestoring . . ."); lflush(); - if (lopen(fname) <= 0) - { - lcreat((char*)0); lprintf("\nCan't open file <%s>to restore game\n",fname); - nap(2000); c[GOLD]=c[BANKACCOUNT]=0; died(-265); return; - } - - lrfill((char*)beenhere,MAXLEVEL+MAXVLEVEL); - for (k=0; k<MAXLEVEL+MAXVLEVEL; k++) + char *fname; +{ + int i, k; + struct sphere *sp, *sp2; + struct stat filetimes; + cursors(); + lprcat("\nRestoring . . ."); + lflush(); + if (lopen(fname) <= 0) { + lcreat((char *) 0); + lprintf("\nCan't open file <%s>to restore game\n", fname); + nap(2000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-265); + return; + } + lrfill((char *) beenhere, MAXLEVEL + MAXVLEVEL); + for (k = 0; k < MAXLEVEL + MAXVLEVEL; k++) if (beenhere[k]) - lrfill((char*)&cell[k*MAXX*MAXY],sizeof(struct cel)*MAXY*MAXX); + lrfill((char *) &cell[k * MAXX * MAXY], sizeof(struct cel) * MAXY * MAXX); - lrfill((char*)&c[0],100*sizeof(long)); gltime = lrint(); + lrfill((char *) &c[0], 100 * sizeof(long)); + gltime = lrint(); level = c[CAVELEVEL] = lgetc(); - playerx = lgetc(); playery = lgetc(); - lrfill((char*)iven,26); lrfill((char*)ivenarg,26*sizeof(short)); - for (k=0; k<MAXSCROLL; k++) scrollname[k] = lgetc() ? scrollhide[k] : ""; - for (k=0; k<MAXPOTION; k++) potionname[k] = lgetc() ? potionhide[k] : ""; - lrfill((char*)spelknow,SPNUM); wizard = lgetc(); - rmst = lgetc(); /* random monster creation flag */ + playerx = lgetc(); + playery = lgetc(); + lrfill((char *) iven, 26); + lrfill((char *) ivenarg, 26 * sizeof(short)); + for (k = 0; k < MAXSCROLL; k++) + scrollname[k] = lgetc() ? scrollhide[k] : ""; + for (k = 0; k < MAXPOTION; k++) + potionname[k] = lgetc() ? potionhide[k] : ""; + lrfill((char *) spelknow, SPNUM); + wizard = lgetc(); + rmst = lgetc(); /* random monster creation flag */ - for (i=0; i<90; i++) itm[i].qty = lgetc(); - lrfill((char*)course,25); cheat = lgetc(); - if (VERSION != lgetc()) /* version number */ - { - cheat=1; + for (i = 0; i < 90; i++) + itm[i].qty = lgetc(); + lrfill((char *) course, 25); + cheat = lgetc(); + if (VERSION != lgetc()) { /* version number */ + cheat = 1; lprcat("Sorry, But your save file is for an older version of larn\n"); - nap(2000); c[GOLD]=c[BANKACCOUNT]=0; died(-266); return; - } - - for (i=0; i<MAXMONST; i++) monster[i].genocided=lgetc(); /* genocide info */ - for (sp=0,i=0; i<c[SPHCAST]; i++) - { + nap(2000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-266); + return; + } + for (i = 0; i < MAXMONST; i++) + monster[i].genocided = lgetc(); /* genocide info */ + for (sp = 0, i = 0; i < c[SPHCAST]; i++) { sp2 = sp; - sp = (struct sphere *)malloc(sizeof(struct sphere)); - if (sp==0) { write(2,"Can't malloc() for sphere space\n",32); break; } - lrfill((char*)sp,sizeof(struct sphere)); /* get spheres of annihilation */ - sp->p=0; /* null out pointer */ - if (i==0) spheres=sp; /* beginning of list */ - else sp2->p = sp; + sp = (struct sphere *) malloc(sizeof(struct sphere)); + if (sp == 0) { + write(2, "Can't malloc() for sphere space\n", 32); + break; } + lrfill((char *) sp, sizeof(struct sphere)); /* get spheres of + * annihilation */ + sp->p = 0; /* null out pointer */ + if (i == 0) + spheres = sp; /* beginning of list */ + else + sp2->p = sp; + } time(&zzz); - initialtime = zzz-lrint(); - fstat(fd,&filetimes); /* get the creation and modification time of file */ - lrfill((char*)&zzz,sizeof(long)); zzz += 6; - if (filetimes.st_ctime > zzz) fsorry(); /* file create time */ - else if (filetimes.st_mtime > zzz) fsorry(); /* file modify time */ - if (c[HP]<0) { died(284); return; } /* died a post mortem death */ - + initialtime = zzz - lrint(); + fstat(fd, &filetimes); /* get the creation and modification time of + * file */ + lrfill((char *) &zzz, sizeof(long)); + zzz += 6; + if (filetimes.st_ctime > zzz) + fsorry(); /* file create time */ + else if (filetimes.st_mtime > zzz) + fsorry(); /* file modify time */ + if (c[HP] < 0) { + died(284); + return; + } /* died a post mortem death */ oldx = oldy = 0; - i = lrint(); /* inode # */ - if (i && (filetimes.st_ino!=i)) fsorry(); + i = lrint(); /* inode # */ + if (i && (filetimes.st_ino != i)) + fsorry(); lrclose(); - if (strcmp(fname,ckpfile) == 0) - { - if (lappend(fname) < 0) fcheat(); else { lprc(' '); lwclose(); } - lcreat((char*)0); + if (strcmp(fname, ckpfile) == 0) { + if (lappend(fname) < 0) + fcheat(); + else { + lprc(' '); + lwclose(); } - else if (unlink(fname) < 0) fcheat(); /* can't unlink save file */ -/* for the greedy cheater checker */ - for (k=0; k<6; k++) if (c[k]>99) greedy(); - if (c[HPMAX]>999 || c[SPELLMAX]>125) greedy(); - if (c[LEVEL]==25 && c[EXPERIENCE]>skill[24]) /* if patch up lev 25 player */ - { - long tmp; - tmp = c[EXPERIENCE]-skill[24]; /* amount to go up */ + lcreat((char *) 0); + } else if (unlink(fname) < 0) + fcheat(); /* can't unlink save file */ + /* for the greedy cheater checker */ + for (k = 0; k < 6; k++) + if (c[k] > 99) + greedy(); + if (c[HPMAX] > 999 || c[SPELLMAX] > 125) + greedy(); + if (c[LEVEL] == 25 && c[EXPERIENCE] > skill[24]) { /* if patch up lev 25 + * player */ + long tmp; + tmp = c[EXPERIENCE] - skill[24]; /* amount to go up */ c[EXPERIENCE] = skill[24]; - raiseexperience((long)tmp); - } - getlevel(); lasttime=gltime; + raiseexperience((long) tmp); } + getlevel(); + lasttime = gltime; +} /* subroutine to not allow greedy cheaters */ +void greedy() - { +{ #if WIZID - if (wizard) return; + if (wizard) + return; #endif lprcat("\n\nI am so sorry, but your character is a little TOO good! Since this\n"); lprcat("cannot normally happen from an honest game, I must assume that you cheated.\n"); lprcat("In that you are GREEDY as well as a CHEATER, I cannot allow this game\n"); - lprcat("to continue.\n"); nap(5000); c[GOLD]=c[BANKACCOUNT]=0; died(-267); return; - } + lprcat("to continue.\n"); + nap(5000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-267); + return; +} /* subroutine to not allow altered save files and terminate the attempted restart */ +void fsorry() - { +{ lprcat("\nSorry, but your savefile has been altered.\n"); lprcat("However, seeing as I am a good sport, I will let you play.\n"); lprcat("Be advised though, you won't be placed on the normal scoreboard."); - cheat = 1; nap(4000); - } + cheat = 1; + nap(4000); +} /* subroutine to not allow game if save file can't be deleted */ +void fcheat() - { +{ #if WIZID - if (wizard) return; + if (wizard) + return; #endif lprcat("\nSorry, but your savefile can't be deleted. This can only mean\n"); lprcat("that you tried to CHEAT by protecting the directory the savefile\n"); lprcat("is in. Since this is unfair to the rest of the larn community, I\n"); lprcat("cannot let you play this game.\n"); - nap(5000); c[GOLD]=c[BANKACCOUNT]=0; died(-268); return; - } + nap(5000); + c[GOLD] = c[BANKACCOUNT] = 0; + died(-268); + return; +} diff --git a/larn/display.c b/larn/display.c index adfcefe3..6dbba44b 100644 --- a/larn/display.c +++ b/larn/display.c @@ -1,328 +1,468 @@ +/* $NetBSD: display.c,v 1.4 1997/10/18 20:03:15 christos Exp $ */ + +/* display.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: display.c,v 1.3 1995/03/23 08:33:21 cgd Exp $"; +__RCSID("$NetBSD: display.c,v 1.4 1997/10/18 20:03:15 christos Exp $"); #endif /* not lint */ -/* display.c Larn is copyrighted 1986 by Noah Morgan. */ #include "header.h" +#include "extern.h" #define makecode(_a,_b,_c) (((_a)<<16) + ((_b)<<8) + (_c)) -static int minx,maxx,miny,maxy,k,m; -static char bot1f=0,bot2f=0,bot3f=0; -char always=0; +static void botsub __P((int, char *)); + +static int minx, maxx, miny, maxy, k, m; +static char bot1f = 0, bot2f = 0, bot3f = 0; +char always = 0; /* bottomline() now for the bottom line of the display */ +void bottomline() - { recalc(); bot1f=1; } +{ + recalc(); + bot1f = 1; +} + +void bottomhp() - { bot2f=1; } +{ + bot2f = 1; +} + +void bottomspell() - { bot3f=1; } +{ + bot3f = 1; +} + +void bottomdo() - { - if (bot1f) { bot3f=bot1f=bot2f=0; bot_linex(); return; } - if (bot2f) { bot2f=0; bot_hpx(); } - if (bot3f) { bot3f=0; bot_spellx(); } +{ + if (bot1f) { + bot3f = bot1f = bot2f = 0; + bot_linex(); + return; } + if (bot2f) { + bot2f = 0; + bot_hpx(); + } + if (bot3f) { + bot3f = 0; + bot_spellx(); + } +} -static void botsub(); - +void bot_linex() - { - register int i; - if (cbak[SPELLS] <= -50 || (always)) - { - cursor( 1,18); - if (c[SPELLMAX]>99) lprintf("Spells:%3d(%3d)",(long)c[SPELLS],(long)c[SPELLMAX]); - else lprintf("Spells:%3d(%2d) ",(long)c[SPELLS],(long)c[SPELLMAX]); - lprintf(" AC: %-3d WC: %-3d Level",(long)c[AC],(long)c[WCLASS]); - if (c[LEVEL]>99) lprintf("%3d",(long)c[LEVEL]); - else lprintf(" %-2d",(long)c[LEVEL]); - lprintf(" Exp: %-9d %s\n",(long)c[EXPERIENCE],class[c[LEVEL]-1]); +{ + int i; + if (cbak[SPELLS] <= -50 || (always)) { + cursor(1, 18); + if (c[SPELLMAX] > 99) + lprintf("Spells:%3d(%3d)", (long) c[SPELLS], (long) c[SPELLMAX]); + else + lprintf("Spells:%3d(%2d) ", (long) c[SPELLS], (long) c[SPELLMAX]); + lprintf(" AC: %-3d WC: %-3d Level", (long) c[AC], (long) c[WCLASS]); + if (c[LEVEL] > 99) + lprintf("%3d", (long) c[LEVEL]); + else + lprintf(" %-2d", (long) c[LEVEL]); + lprintf(" Exp: %-9d %s\n", (long) c[EXPERIENCE], class[c[LEVEL] - 1]); lprintf("HP: %3d(%3d) STR=%-2d INT=%-2d ", - (long)c[HP],(long)c[HPMAX],(long)(c[STRENGTH]+c[STREXTRA]),(long)c[INTELLIGENCE]); + (long) c[HP], (long) c[HPMAX], (long) (c[STRENGTH] + c[STREXTRA]), (long) c[INTELLIGENCE]); lprintf("WIS=%-2d CON=%-2d DEX=%-2d CHA=%-2d LV:", - (long)c[WISDOM],(long)c[CONSTITUTION],(long)c[DEXTERITY],(long)c[CHARISMA]); - - if ((level==0) || (wizard)) c[TELEFLAG]=0; - if (c[TELEFLAG]) lprcat(" ?"); else lprcat(levelname[level]); - lprintf(" Gold: %-6d",(long)c[GOLD]); - always=1; botside(); - c[TMP] = c[STRENGTH]+c[STREXTRA]; - for (i=0; i<100; i++) cbak[i]=c[i]; - return; - } + (long) c[WISDOM], (long) c[CONSTITUTION], (long) c[DEXTERITY], (long) c[CHARISMA]); - botsub(makecode(SPELLS,8,18),"%3d"); - if (c[SPELLMAX]>99) botsub(makecode(SPELLMAX,12,18),"%3d)"); - else botsub(makecode(SPELLMAX,12,18),"%2d) "); - botsub(makecode(HP,5,19),"%3d"); - botsub(makecode(HPMAX,9,19),"%3d"); - botsub(makecode(AC,21,18),"%-3d"); - botsub(makecode(WCLASS,30,18),"%-3d"); - botsub(makecode(EXPERIENCE,49,18),"%-9d"); - if (c[LEVEL] != cbak[LEVEL]) - { cursor(59,18); lprcat(class[c[LEVEL]-1]); } - if (c[LEVEL]>99) botsub(makecode(LEVEL,40,18),"%3d"); - else botsub(makecode(LEVEL,40,18)," %-2d"); - c[TMP] = c[STRENGTH]+c[STREXTRA]; botsub(makecode(TMP,18,19),"%-2d"); - botsub(makecode(INTELLIGENCE,25,19),"%-2d"); - botsub(makecode(WISDOM,32,19),"%-2d"); - botsub(makecode(CONSTITUTION,39,19),"%-2d"); - botsub(makecode(DEXTERITY,46,19),"%-2d"); - botsub(makecode(CHARISMA,53,19),"%-2d"); - if ((level != cbak[CAVELEVEL]) || (c[TELEFLAG] != cbak[TELEFLAG])) - { - if ((level==0) || (wizard)) c[TELEFLAG]=0; + if ((level == 0) || (wizard)) + c[TELEFLAG] = 0; + if (c[TELEFLAG]) + lprcat(" ?"); + else + lprcat(levelname[level]); + lprintf(" Gold: %-6d", (long) c[GOLD]); + always = 1; + botside(); + c[TMP] = c[STRENGTH] + c[STREXTRA]; + for (i = 0; i < 100; i++) + cbak[i] = c[i]; + return; + } + botsub(makecode(SPELLS, 8, 18), "%3d"); + if (c[SPELLMAX] > 99) + botsub(makecode(SPELLMAX, 12, 18), "%3d)"); + else + botsub(makecode(SPELLMAX, 12, 18), "%2d) "); + botsub(makecode(HP, 5, 19), "%3d"); + botsub(makecode(HPMAX, 9, 19), "%3d"); + botsub(makecode(AC, 21, 18), "%-3d"); + botsub(makecode(WCLASS, 30, 18), "%-3d"); + botsub(makecode(EXPERIENCE, 49, 18), "%-9d"); + if (c[LEVEL] != cbak[LEVEL]) { + cursor(59, 18); + lprcat(class[c[LEVEL] - 1]); + } + if (c[LEVEL] > 99) + botsub(makecode(LEVEL, 40, 18), "%3d"); + else + botsub(makecode(LEVEL, 40, 18), " %-2d"); + c[TMP] = c[STRENGTH] + c[STREXTRA]; + botsub(makecode(TMP, 18, 19), "%-2d"); + botsub(makecode(INTELLIGENCE, 25, 19), "%-2d"); + botsub(makecode(WISDOM, 32, 19), "%-2d"); + botsub(makecode(CONSTITUTION, 39, 19), "%-2d"); + botsub(makecode(DEXTERITY, 46, 19), "%-2d"); + botsub(makecode(CHARISMA, 53, 19), "%-2d"); + if ((level != cbak[CAVELEVEL]) || (c[TELEFLAG] != cbak[TELEFLAG])) { + if ((level == 0) || (wizard)) + c[TELEFLAG] = 0; cbak[TELEFLAG] = c[TELEFLAG]; - cbak[CAVELEVEL] = level; cursor(59,19); - if (c[TELEFLAG]) lprcat(" ?"); else lprcat(levelname[level]); - } - botsub(makecode(GOLD,69,19),"%-6d"); - botside(); + cbak[CAVELEVEL] = level; + cursor(59, 19); + if (c[TELEFLAG]) + lprcat(" ?"); + else + lprcat(levelname[level]); } + botsub(makecode(GOLD, 69, 19), "%-6d"); + botside(); +} /* special subroutine to update only the gold number on the bottomlines called from ogold() */ +void bottomgold() - { - botsub(makecode(GOLD,69,19),"%-6d"); -/* botsub(GOLD,"%-6d",69,19); */ - } +{ + botsub(makecode(GOLD, 69, 19), "%-6d"); + /* botsub(GOLD,"%-6d",69,19); */ +} /* special routine to update hp and level fields on bottom lines called in monster.c hitplayer() and spattack() */ +void bot_hpx() - { - if (c[EXPERIENCE] != cbak[EXPERIENCE]) - { - recalc(); bot_linex(); - } - else botsub(makecode(HP,5,19),"%3d"); - } +{ + if (c[EXPERIENCE] != cbak[EXPERIENCE]) { + recalc(); + bot_linex(); + } else + botsub(makecode(HP, 5, 19), "%3d"); +} /* special routine to update number of spells called from regen() */ +void bot_spellx() - { - botsub(makecode(SPELLS,9,18),"%2d"); - } +{ + botsub(makecode(SPELLS, 9, 18), "%2d"); +} /* common subroutine for a more economical bottomline() */ -static struct bot_side_def - { - int typ; - char *string; - } - bot_data[] = - { - STEALTH,"stealth", UNDEADPRO,"undead pro", SPIRITPRO,"spirit pro", - CHARMCOUNT,"Charm", TIMESTOP,"Time Stop", HOLDMONST,"Hold Monst", - GIANTSTR,"Giant Str", FIRERESISTANCE,"Fire Resit", DEXCOUNT,"Dexterity", - STRCOUNT,"Strength", SCAREMONST,"Scare", HASTESELF,"Haste Self", - CANCELLATION,"Cancel", INVISIBILITY,"Invisible", ALTPRO,"Protect 3", - PROTECTIONTIME,"Protect 2", WTW,"Wall-Walk" - }; - +static struct bot_side_def { + int typ; + char *string; +} + bot_data[] = +{ + { STEALTH, "stealth"}, + { UNDEADPRO, "undead pro" }, + { SPIRITPRO, "spirit pro" }, + { CHARMCOUNT, "Charm"}, + { TIMESTOP, "Time Stop" }, + { HOLDMONST, "Hold Monst" }, + { GIANTSTR, "Giant Str"}, + { FIRERESISTANCE, "Fire Resit" }, + { DEXCOUNT, "Dexterity" }, + { STRCOUNT, "Strength"}, + { SCAREMONST, "Scare" }, + { HASTESELF, "Haste Self" }, + { CANCELLATION, "Cancel"}, + { INVISIBILITY, "Invisible" }, + { ALTPRO, "Protect 3" }, + { PROTECTIONTIME, "Protect 2"}, + { WTW, "Wall-Walk" } +}; + +void botside() - { - register int i,idx; - for (i=0; i<17; i++) - { +{ + int i, idx; + for (i = 0; i < 17; i++) { idx = bot_data[i].typ; - if ((always) || (c[idx] != cbak[idx])) - { - if ((always) || (cbak[idx] == 0)) - { if (c[idx]) { cursor(70,i+1); lprcat(bot_data[i].string); } } else - if (c[idx]==0) { cursor(70,i+1); lprcat(" "); } - cbak[idx]=c[idx]; - } + if ((always) || (c[idx] != cbak[idx])) { + if ((always) || (cbak[idx] == 0)) { + if (c[idx]) { + cursor(70, i + 1); + lprcat(bot_data[i].string); + } + } else if (c[idx] == 0) { + cursor(70, i + 1); + lprcat(" "); + } + cbak[idx] = c[idx]; } - always=0; } + always = 0; +} static void -botsub(idx,str) - register int idx; - char *str; - { - register int x,y; - y = idx & 0xff; x = (idx>>8) & 0xff; idx >>= 16; - if (c[idx] != cbak[idx]) - { cbak[idx]=c[idx]; cursor(x,y); lprintf(str,(long)c[idx]); } +botsub(idx, str) + int idx; + char *str; +{ + int x, y; + y = idx & 0xff; + x = (idx >> 8) & 0xff; + idx >>= 16; + if (c[idx] != cbak[idx]) { + cbak[idx] = c[idx]; + cursor(x, y); + lprintf(str, (long) c[idx]); } +} /* * subroutine to draw only a section of the screen - * only the top section of the screen is updated. If entire lines are being - * drawn, then they will be cleared first. + * only the top section of the screen is updated. + * If entire lines are being drawn, then they will be cleared first. */ -int d_xmin=0,d_xmax=MAXX,d_ymin=0,d_ymax=MAXY; /* for limited screen drawing */ -draws(xmin,xmax,ymin,ymax) - int xmin,xmax,ymin,ymax; - { - register int i,idx; - if (xmin==0 && xmax==MAXX) /* clear section of screen as needed */ - { - if (ymin==0) cl_up(79,ymax); - else for (i=ymin; i<ymin; i++) cl_line(1,i+1); +/* for limited screen drawing */ +int d_xmin = 0, d_xmax = MAXX, d_ymin = 0, d_ymax = MAXY; + +void +draws(xmin, xmax, ymin, ymax) + int xmin, xmax, ymin, ymax; +{ + int i, idx; + if (xmin == 0 && xmax == MAXX) { /* clear section of screen as + * needed */ + if (ymin == 0) + cl_up(79, ymax); + else + for (i = ymin; i < ymin; i++) + cl_line(1, i + 1); xmin = -1; - } - d_xmin=xmin; d_xmax=xmax; d_ymin=ymin; d_ymax=ymax; /* for limited screen drawing */ + } + d_xmin = xmin; + d_xmax = xmax; + d_ymin = ymin; + d_ymax = ymax; /* for limited screen drawing */ drawscreen(); - if (xmin<=0 && xmax==MAXX) /* draw stuff on right side of screen as needed*/ - { - for (i=ymin; i<ymax; i++) - { + if (xmin <= 0 && xmax == MAXX) { /* draw stuff on right side + * of screen as needed */ + for (i = ymin; i < ymax; i++) { idx = bot_data[i].typ; - if (c[idx]) - { - cursor(70,i+1); lprcat(bot_data[i].string); - } - cbak[idx]=c[idx]; + if (c[idx]) { + cursor(70, i + 1); + lprcat(bot_data[i].string); } + cbak[idx] = c[idx]; } } +} /* drawscreen() subroutine to redraw the whole screen as the player knows it */ -char screen[MAXX][MAXY],d_flag; /* template for the screen */ +u_char screen[MAXX][MAXY], d_flag; /* template for the screen */ +void drawscreen() - { - register int i,j,k; - int lastx,lasty; /* variables used to optimize the object printing */ - if (d_xmin==0 && d_xmax==MAXX && d_ymin==0 && d_ymax==MAXY) - { - d_flag=1; clear(); /* clear the screen */ - } - else - { - d_flag=0; cursor(1,1); - } - if (d_xmin<0) - d_xmin=0; /* d_xmin=-1 means display all without bottomline */ - - for (i=d_ymin; i<d_ymax; i++) - for (j=d_xmin; j<d_xmax; j++) - if (know[j][i]==0) screen[j][i] = ' '; else - if (k=mitem[j][i]) screen[j][i] = monstnamelist[k]; else - if ((k=item[j][i])==OWALL) screen[j][i] = '#'; - else screen[j][i] = ' '; - - for (i=d_ymin; i<d_ymax; i++) - { - j=d_xmin; while ((screen[j][i]==' ') && (j<d_xmax)) j++; +{ + int i, j, k; + int lastx, lasty; /* variables used to optimize the + * object printing */ + if (d_xmin == 0 && d_xmax == MAXX && d_ymin == 0 && d_ymax == MAXY) { + d_flag = 1; + clear(); /* clear the screen */ + } else { + d_flag = 0; + cursor(1, 1); + } + if (d_xmin < 0) + d_xmin = 0; /* d_xmin=-1 means display all without + * bottomline */ + + for (i = d_ymin; i < d_ymax; i++) + for (j = d_xmin; j < d_xmax; j++) + if (know[j][i] == 0) + screen[j][i] = ' '; + else if ((k = mitem[j][i]) != 0) + screen[j][i] = monstnamelist[k]; + else if ((k = item[j][i]) == OWALL) + screen[j][i] = '#'; + else + screen[j][i] = ' '; + + for (i = d_ymin; i < d_ymax; i++) { + j = d_xmin; + while ((screen[j][i] == ' ') && (j < d_xmax)) + j++; /* was m=0 */ - if (j >= d_xmax) m=d_xmin; /* don't search backwards if blank line */ - else - { /* search backwards for end of line */ - m=d_xmax-1; while ((screen[m][i]==' ') && (m>d_xmin)) --m; - if (j<=m) cursor(j+1,i+1); else continue; - } - while (j <= m) - { - if (j <= m-3) - { - for (k=j; k<=j+3; k++) if (screen[k][i] != ' ') k=1000; - if (k < 1000) - { while(screen[j][i]==' ' && j<=m) j++; cursor(j+1,i+1); } + if (j >= d_xmax) + m = d_xmin; /* don't search backwards if blank + * line */ + else { /* search backwards for end of line */ + m = d_xmax - 1; + while ((screen[m][i] == ' ') && (m > d_xmin)) + --m; + if (j <= m) + cursor(j + 1, i + 1); + else + continue; + } + while (j <= m) { + if (j <= m - 3) { + for (k = j; k <= j + 3; k++) + if (screen[k][i] != ' ') + k = 1000; + if (k < 1000) { + while (screen[j][i] == ' ' && j <= m) + j++; + cursor(j + 1, i + 1); } - lprc(screen[j++][i]); } + lprc(screen[j++][i]); } + } setbold(); /* print out only bold objects now */ - for (lastx=lasty=127, i=d_ymin; i<d_ymax; i++) - for (j=d_xmin; j<d_xmax; j++) - { - if (k=item[j][i]) + for (lastx = lasty = 127, i = d_ymin; i < d_ymax; i++) + for (j = d_xmin; j < d_xmax; j++) { + if ((k = item[j][i]) != 0) if (k != OWALL) - if ((know[j][i]) && (mitem[j][i]==0)) - if (objnamelist[k]!=' ') - { - if (lasty!=i+1 || lastx!=j) - cursor(lastx=j+1,lasty=i+1); else lastx++; + if ((know[j][i]) && (mitem[j][i] == 0)) + if (objnamelist[k] != ' ') { + if (lasty != i + 1 || lastx != j) + cursor(lastx = j + 1, lasty = i + 1); + else + lastx++; lprc(objnamelist[k]); - } - } + } + } - resetbold(); if (d_flag) { always=1; botside(); always=1; bot_linex(); } - oldx=99; - d_xmin = 0 , d_xmax = MAXX , d_ymin = 0 , d_ymax = MAXY; /* for limited screen drawing */ + resetbold(); + if (d_flag) { + always = 1; + botside(); + always = 1; + bot_linex(); } - + oldx = 99; + d_xmin = 0, d_xmax = MAXX, d_ymin = 0, d_ymax = MAXY; /* for limited screen + * drawing */ +} + + /* showcell(x,y) subroutine to display a cell location on the screen */ -showcell(x,y) - int x,y; - { - register int i,j,k,m; - if (c[BLINDCOUNT]) return; /* see nothing if blind */ - if (c[AWARENESS]) { minx = x-3; maxx = x+3; miny = y-3; maxy = y+3; } - else { minx = x-1; maxx = x+1; miny = y-1; maxy = y+1; } - - if (minx < 0) minx=0; if (maxx > MAXX-1) maxx = MAXX-1; - if (miny < 0) miny=0; if (maxy > MAXY-1) maxy = MAXY-1; - - for (j=miny; j<=maxy; j++) - for (m=minx; m<=maxx; m++) - if (know[m][j]==0) - { - cursor(m+1,j+1); - x=maxx; while (know[x][j]) --x; - for (i=m; i<=x; i++) - { - if ((k=mitem[i][j]) != 0) lprc(monstnamelist[k]); - else switch(k=item[i][j]) - { - case OWALL: case 0: case OIVTELETRAP: case OTRAPARROWIV: - case OIVDARTRAP: case OIVTRAPDOOR: - lprc(objnamelist[k]); break; - - default: setbold(); lprc(objnamelist[k]); resetbold(); - }; - know[i][j]=1; +void +showcell(x, y) + int x, y; +{ + int i, j, k, m; + if (c[BLINDCOUNT]) + return; /* see nothing if blind */ + if (c[AWARENESS]) { + minx = x - 3; + maxx = x + 3; + miny = y - 3; + maxy = y + 3; + } else { + minx = x - 1; + maxx = x + 1; + miny = y - 1; + maxy = y + 1; + } + + if (minx < 0) + minx = 0; + if (maxx > MAXX - 1) + maxx = MAXX - 1; + if (miny < 0) + miny = 0; + if (maxy > MAXY - 1) + maxy = MAXY - 1; + + for (j = miny; j <= maxy; j++) + for (m = minx; m <= maxx; m++) + if (know[m][j] == 0) { + cursor(m + 1, j + 1); + x = maxx; + while (know[x][j]) + --x; + for (i = m; i <= x; i++) { + if ((k = mitem[i][j]) != 0) + lprc(monstnamelist[k]); + else + switch (k = item[i][j]) { + case OWALL: + case 0: + case OIVTELETRAP: + case OTRAPARROWIV: + case OIVDARTRAP: + case OIVTRAPDOOR: + lprc(objnamelist[k]); + break; + + default: + setbold(); + lprc(objnamelist[k]); + resetbold(); + }; + know[i][j] = 1; } - m = maxx; + m = maxx; } - } +} /* this routine shows only the spot that is given it. the spaces around these coordinated are not shown used in godirect() in monster.c for missile weapons display */ -show1cell(x,y) - int x,y; - { - if (c[BLINDCOUNT]) return; /* see nothing if blind */ - cursor(x+1,y+1); - if ((k=mitem[x][y]) != 0) lprc(monstnamelist[k]); - else switch(k=item[x][y]) - { - case OWALL: case 0: case OIVTELETRAP: case OTRAPARROWIV: - case OIVDARTRAP: case OIVTRAPDOOR: - lprc(objnamelist[k]); break; - - default: setbold(); lprc(objnamelist[k]); resetbold(); - }; - know[x][y]|=1; /* we end up knowing about it */ - } +void +show1cell(x, y) + int x, y; +{ + if (c[BLINDCOUNT]) + return; /* see nothing if blind */ + cursor(x + 1, y + 1); + if ((k = mitem[x][y]) != 0) + lprc(monstnamelist[k]); + else + switch (k = item[x][y]) { + case OWALL: + case 0: + case OIVTELETRAP: + case OTRAPARROWIV: + case OIVDARTRAP: + case OIVTRAPDOOR: + lprc(objnamelist[k]); + break; + + default: + setbold(); + lprc(objnamelist[k]); + resetbold(); + }; + know[x][y] |= 1; /* we end up knowing about it */ +} /* showplayer() @@ -330,11 +470,13 @@ show1cell(x,y) subroutine to show where the player is on the screen cursor values start from 1 up */ +void showplayer() - { - cursor(playerx+1,playery+1); - oldx=playerx; oldy=playery; - } +{ + cursor(playerx + 1, playery + 1); + oldx = playerx; + oldy = playery; +} /* moveplayer(dir) @@ -345,94 +487,144 @@ showplayer() nomove is set to 1 to stop the next move (inadvertent monsters hitting players when walking into walls) if player walks off screen or into wall */ -short diroffx[] = { 0, 0, 1, 0, -1, 1, -1, 1, -1 }; -short diroffy[] = { 0, 1, 0, -1, 0, -1, -1, 1, 1 }; +short diroffx[] = {0, 0, 1, 0, -1, 1, -1, 1, -1}; +short diroffy[] = {0, 1, 0, -1, 0, -1, -1, 1, 1}; +int moveplayer(dir) - int dir; /* from = present room # direction = [1-north] - [2-east] [3-south] [4-west] [5-northeast] - [6-northwest] [7-southeast] [8-southwest] - if direction=0, don't move--just show where he is */ - { - register int k,m,i,j; - if (c[CONFUSE]) if (c[LEVEL]<rnd(30)) dir=rund(9); /*if confused any dir*/ - k = playerx + diroffx[dir]; m = playery + diroffy[dir]; - if (k<0 || k>=MAXX || m<0 || m>=MAXY) { nomove=1; return(yrepcount = 0); } - i = item[k][m]; j = mitem[k][m]; - if (i==OWALL && c[WTW]==0) { nomove=1; return(yrepcount = 0); } /* hit a wall */ - if (k==33 && m==MAXY-1 && level==1) - { - newcavelevel(0); for (k=0; k<MAXX; k++) for (m=0; m<MAXY; m++) - if (item[k][m]==OENTRANCE) - { playerx=k; playery=m; positionplayer(); drawscreen(); return(0); } - } - if (j>0) { hitmonster(k,m); return(yrepcount = 0); } /* hit a monster*/ - lastpx = playerx; lastpy = playery; - playerx = k; playery = m; - if (i && i!=OTRAPARROWIV && i!=OIVTELETRAP && i!=OIVDARTRAP && i!=OIVTRAPDOOR) return(yrepcount = 0); else return(1); + int dir; /* from = present room # direction = + * [1-north] [2-east] [3-south] [4-west] + * [5-northeast] [6-northwest] [7-southeast] + * [8-southwest] if direction=0, don't + * move--just show where he is */ +{ + int k, m, i, j; + if (c[CONFUSE]) + if (c[LEVEL] < rnd(30)) + dir = rund(9); /* if confused any dir */ + k = playerx + diroffx[dir]; + m = playery + diroffy[dir]; + if (k < 0 || k >= MAXX || m < 0 || m >= MAXY) { + nomove = 1; + return (yrepcount = 0); + } + i = item[k][m]; + j = mitem[k][m]; + if (i == OWALL && c[WTW] == 0) { + nomove = 1; + return (yrepcount = 0); + } /* hit a wall */ + if (k == 33 && m == MAXY - 1 && level == 1) { + newcavelevel(0); + for (k = 0; k < MAXX; k++) + for (m = 0; m < MAXY; m++) + if (item[k][m] == OENTRANCE) { + playerx = k; + playery = m; + positionplayer(); + drawscreen(); + return (0); + } } - + if (j > 0) { + hitmonster(k, m); + return (yrepcount = 0); + } /* hit a monster */ + lastpx = playerx; + lastpy = playery; + playerx = k; + playery = m; + if (i && i != OTRAPARROWIV && i != OIVTELETRAP && i != OIVDARTRAP && i != OIVTRAPDOOR) + return (yrepcount = 0); + else + return (1); +} + + /* * function to show what magic items have been discovered thus far * enter with -1 for just spells, anything else will give scrolls & potions */ -static int lincount,count; +static int lincount, count; +void seemagic(arg) - int arg; - { - register int i,number; - count = lincount = 0; nosignal=1; - - if (arg== -1) /* if display spells while casting one */ - { - for (number=i=0; i<SPNUM; i++) if (spelknow[i]) number++; - number = (number+2)/3 + 4; /* # lines needed to display */ - cl_up(79,number); cursor(1,1); - } - else - { - resetscroll(); clear(); - } + int arg; +{ + int i, number = 0; + count = lincount = 0; + nosignal = 1; + + if (arg == -1) { /* if display spells while casting one */ + for (number = i = 0; i < SPNUM; i++) + if (spelknow[i]) + number++; + number = (number + 2) / 3 + 4; /* # lines needed to display */ + cl_up(79, number); + cursor(1, 1); + } else { + resetscroll(); + clear(); + } lprcat("The magic spells you have discovered thus far:\n\n"); - for (i=0; i<SPNUM; i++) - if (spelknow[i]) - { lprintf("%s %-20s ",spelcode[i],spelname[i]); seepage(); } - - if (arg== -1) - { - seepage(); more(); nosignal=0; - draws(0,MAXX,0,number); return; + for (i = 0; i < SPNUM; i++) + if (spelknow[i]) { + lprintf("%s %-20s ", spelcode[i], spelname[i]); + seepage(); } - - lincount += 3; if (count!=0) { count=2; seepage(); } - + if (arg == -1) { + seepage(); + more(); + nosignal = 0; + draws(0, MAXX, 0, number); + return; + } + lincount += 3; + if (count != 0) { + count = 2; + seepage(); + } lprcat("\nThe magic scrolls you have found to date are:\n\n"); - count=0; - for (i=0; i<MAXSCROLL; i++) + count = 0; + for (i = 0; i < MAXSCROLL; i++) if (scrollname[i][0]) - if (scrollname[i][1]!=' ') - { lprintf("%-26s",&scrollname[i][1]); seepage(); } - - lincount += 3; if (count!=0) { count=2; seepage(); } - + if (scrollname[i][1] != ' ') { + lprintf("%-26s", &scrollname[i][1]); + seepage(); + } + lincount += 3; + if (count != 0) { + count = 2; + seepage(); + } lprcat("\nThe magic potions you have found to date are:\n\n"); - count=0; - for (i=0; i<MAXPOTION; i++) + count = 0; + for (i = 0; i < MAXPOTION; i++) if (potionname[i][0]) - if (potionname[i][1]!=' ') - { lprintf("%-26s",&potionname[i][1]); seepage(); } - - if (lincount!=0) more(); nosignal=0; setscroll(); drawscreen(); - } + if (potionname[i][1] != ' ') { + lprintf("%-26s", &potionname[i][1]); + seepage(); + } + if (lincount != 0) + more(); + nosignal = 0; + setscroll(); + drawscreen(); +} /* * subroutine to paginate the seemagic function */ +void seepage() - { - if (++count==3) - { - lincount++; count=0; lprc('\n'); - if (lincount>17) { lincount=0; more(); clear(); } +{ + if (++count == 3) { + lincount++; + count = 0; + lprc('\n'); + if (lincount > 17) { + lincount = 0; + more(); + clear(); } } +} diff --git a/larn/extern.h b/larn/extern.h new file mode 100644 index 00000000..17f65bf6 --- /dev/null +++ b/larn/extern.h @@ -0,0 +1,312 @@ +/* $NetBSD: extern.h,v 1.1 1997/10/18 20:03:17 christos Exp $ */ + +/* + * Copyright (c) 1997 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* bill.c */ +void mailbill __P((void)); + +/* config.c */ + +/* create.c */ +void makeplayer __P((void)); +void newcavelevel __P((int)); +void makemaze __P((int)); +void eat __P((int, int)); +int cannedlevel __P((int)); +void treasureroom __P((int)); +void troom __P((int, int, int, int, int, int)); +void makeobject __P((int)); +void fillmroom __P((int, int, int)); +void froom __P((int, int, int)); +int fillmonst __P((int)); +void sethp __P((int)); +void checkgen __P((void)); + +/* data.c */ + +/* diag.c */ +void diag __P((void)); +int dcount __P((int)); +void diagdrawscreen __P((void)); +int savegame __P((char *)); +void restoregame __P((char *)); +void greedy __P((void)); +void fsorry __P((void)); +void fcheat __P((void)); + +/* display.c */ +void bottomline __P((void)); +void bottomhp __P((void)); +void bottomspell __P((void)); +void bottomdo __P((void)); +void bot_linex __P((void)); +void bottomgold __P((void)); +void bot_hpx __P((void)); +void bot_spellx __P((void)); +void botside __P((void)); +void draws __P((int, int, int, int)); +void drawscreen __P((void)); +void showcell __P((int, int)); +void show1cell __P((int, int)); +void showplayer __P((void)); +int moveplayer __P((int)); +void seemagic __P((int)); +void seepage __P((void)); + +/* fortune.c */ +char *fortune __P((void)); + +/* global.c */ +void raiselevel __P((void)); +void loselevel __P((void)); +void raiseexperience __P((long)); +void loseexperience __P((long)); +void losehp __P((int)); +void losemhp __P((int)); +void raisehp __P((int)); +void raisemhp __P((int)); +void raisespells __P((int)); +void raisemspells __P((int)); +void losespells __P((int)); +void losemspells __P((int)); +int makemonst __P((int)); +void positionplayer __P((void)); +void recalc __P((void)); +void quit __P((void)); +void more __P((void)); +int take __P((int, int)); +int drop_object __P((int)); +void enchantarmor __P((void)); +void enchweapon __P((void)); +int pocketfull __P((void)); +int nearbymonst __P((void)); +int stealsomething __P((void)); +int emptyhanded __P((void)); +void creategem __P((void)); +void adjustcvalues __P((int, int)); +void gettokstr __P((char *)); +int getpassword __P((void)); +int getyn __P((void)); +int packweight __P((void)); +int rnd __P((int)); +int rund __P((int)); + +/* help.c */ +void help __P((void)); +void welcome __P((void)); +void retcont __P((void)); +int openhelp __P((void)); + +/* io.c */ +void setupvt100 __P((void)); +void clearvt100 __P((void)); +int getchar __P((void)); +void scbr __P((void)); +void sncbr __P((void)); +void newgame __P((void)); +void lprintf __P((const char *, ...)); +void lprint __P((long)); +void lwrite __P((char *, int)); +long lgetc __P((void)); +long lrint __P((void)); +void lrfill __P((char *, int)); +char *lgetw __P((void)); +char *lgetl __P((void)); +int lcreat __P((char *)); +int lopen __P((char *)); +int lappend __P((char *)); +void lrclose __P((void)); +void lwclose __P((void)); +void lprcat __P((char *)); +void cursor __P((int, int)); +void cursors __P((void)); +void init_term __P((void)); +void cl_line __P((int, int)); +void cl_up __P((int, int)); +void cl_dn __P((int, int)); +void standout __P((char *)); +void set_score_output __P((void)); +void lflush __P((void)); +void xputchar __P((int)); +void flush_buf __P((void)); +char *tmcapcnv __P((char *, char *)); +void beep __P((void)); + +/* main.c */ +int main __P((int, char **)); +void showstr __P((void)); +void qshowstr __P((void)); +void t_setup __P((int)); +void t_endup __P((int)); +void showwear __P((void)); +void showwield __P((void)); +void showread __P((void)); +void showeat __P((void)); +void showquaff __P((void)); +void show1 __P((int, char *[])); +void show3 __P((int)); +void randmonst __P((void)); +void parse __P((void)); +void parse2 __P((void)); +void run __P((int)); +void wield __P((void)); +void ydhi __P((int)); +void ycwi __P((int)); +void wear __P((void)); +void dropobj __P((void)); +void readscr __P((void)); +void eatcookie __P((void)); +void quaff __P((void)); +int whatitem __P((char *)); +unsigned long readnum __P((long)); +void szero __P((char *)); + +/* monster.c */ +void createmonster __P((int)); +int cgood __P((int, int, int, int)); +void createitem __P((int, int)); +void cast __P((void)); +void speldamage __P((int)); +void loseint __P((void)); +int isconfuse __P((void)); +int nospell __P((int, int)); +int fullhit __P((int)); +void direct __P((int, int, char *, int)); +void godirect __P((int, int, char *, int, int)); +void ifblind __P((int, int)); +void tdirect __P((int)); +void omnidirect __P((int, int, char *)); +int vxy __P((int *, int *)); +void dirpoly __P((int)); +void hitmonster __P((int, int)); +int hitm __P((int, int, int)); +void hitplayer __P((int, int)); +void dropsomething __P((int)); +void dropgold __P((int)); +void something __P((int)); +int newobject __P((int, int *)); +int spattack __P((int, int, int)); +void checkloss __P((int)); +int annihilate __P((void)); +int newsphere __P((int, int, int, int)); +int rmsphere __P((int, int)); +void sphboom __P((int, int)); +void genmonst __P((void)); + +/* moreobj.c */ +void oaltar __P((void)); +void othrone __P((int)); +void odeadthrone __P((void)); +void ochest __P((void)); +void ofountain __P((void)); +void fntchange __P((int)); + +/* movem.c */ +void movemonst __P((void)); +void movemt __P((int, int)); +void mmove __P((int, int, int, int)); +void movsphere __P((void)); + +/* nap.c */ +void nap __P((int)); + +/* object.c */ +void lookforobject __P((void)); +void finditem __P((int)); +void ostairs __P((int)); +void oteleport __P((int)); +void opotion __P((int)); +void quaffpotion __P((int)); +void oscroll __P((int)); +void adjusttime __P((long)); +void read_scroll __P((int)); +void oorb __P((void)); +void opit __P((void)); +void obottomless __P((void)); +void oelevator __P((int)); +void ostatue __P((void)); +void omirror __P((void)); +void obook __P((void)); +void readbook __P((int)); +void ocookie __P((void)); +void ogold __P((int)); +void ohome __P((void)); +void iopts __P((void)); +void ignore __P((void)); + +/* regen.c */ +void regen __P((void)); + +/* savelev.c */ +void savelevel __P((void)); +void getlevel __P((void)); + +/* scores.c */ +int readboard __P((void)); +int writeboard __P((void)); +int makeboard __P((void)); +int hashewon __P((void)); +long paytaxes __P((long)); +int winshou __P((void)); +int shou __P((int)); +void showscores __P((void)); +void showallscores __P((void)); +int sortboard __P((void)); +void newscore __P((long, char *, int, int)); +void new1sub __P((long, int, char *, long)); +void new2sub __P((long, int, char *, int)); +void died __P((int)); +void diedsub __P((int)); +void diedlog __P((void)); +int getplid __P((char *)); + +/* signal.c */ +void sigsetup __P((void)); + +/* store.c */ +void dnd_2hed __P((void)); +void dnd_hed __P((void)); +void dndstore __P((void)); +void sch_hed __P((void)); +void oschool __P((void)); +void obank __P((void)); +void obank2 __P((void)); +void ointerest __P((void)); +void obanksub __P((void)); +void appraise __P((int)); +void otradepost __P((void)); +void cnsitm __P((void)); +void olrs __P((void)); + +/* tok.c */ +int yylex __P((void)); +void flushall __P((void)); +void sethard __P((int)); +void readopts __P((void)); diff --git a/larn/fortune.c b/larn/fortune.c index 54a7a955..7f41c8c0 100644 --- a/larn/fortune.c +++ b/larn/fortune.c @@ -1,3 +1,5 @@ +/* $NetBSD: fortune.c,v 1.4 1997/10/18 20:03:18 christos Exp $ */ + /*- * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. @@ -31,21 +33,26 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 -static char sccsid[] = "@(#)fortune.c 5.5 (Berkeley) 6/10/91"; +static char sccsid[] = "@(#)fortune.c 5.5 (Berkeley) 6/10/91"; #else -static char rcsid[] = "$NetBSD: fortune.c,v 1.3 1995/03/23 08:33:23 cgd Exp $"; +__RCSID("$NetBSD: fortune.c,v 1.4 1997/10/18 20:03:18 christos Exp $"); #endif -#endif /* not lint */ +#endif /* not lint */ + +#include <stdlib.h> +#include "header.h" +#include "extern.h" /* fortune.c Larn is copyrighted 1986 by Noah Morgan. */ /* * function to return a random fortune from the fortune file */ -char *flines[] = { +char *flines[] = { "gem value = gem * 2 ^ perfection", "sitting down can have unexpected results", "don't pry into the affairs of others", diff --git a/larn/global.c b/larn/global.c index 80736170..90e41823 100644 --- a/larn/global.c +++ b/larn/global.c @@ -1,37 +1,44 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: global.c,v 1.5 1997/03/29 20:42:19 thorpej Exp $"; -#endif /* not lint */ +/* $NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos Exp $ */ -/* global.c Larn is copyrighted 1986 by Noah Morgan. - * - * raiselevel() subroutine to raise the player one level - * loselevel() subroutine to lower the player by one level - * raiseexperience(x) subroutine to increase experience points - * loseexperience(x) subroutine to lose experience points - * losehp(x) subroutine to remove hit points from the player - * losemhp(x) subroutine to remove max # hit points from the player - * raisehp(x) subroutine to gain hit points - * raisemhp(x) subroutine to gain maximum hit points - * losespells(x) subroutine to lose spells - * losemspells(x) subroutine to lose maximum spells - * raisespells(x) subroutine to gain spells - * raisemspells(x) subroutine to gain maximum spells - * recalc() function to recalculate the armor class of the player - * makemonst(lev) function to return monster number for a randomly selected monster - * positionplayer() function to be sure player is not in a wall - * quit() subroutine to ask if the player really wants to quit +/* + * global.c Larn is copyrighted 1986 by Noah Morgan. + * + * raiselevel() subroutine to raise the player one level + * loselevel() subroutine to lower the player by one level + * raiseexperience(x) subroutine to increase experience points + * loseexperience(x) subroutine to lose experience points + * losehp(x) subroutine to remove hit points from the player + * losemhp(x) subroutine to remove max # hit points from the player + * raisehp(x) subroutine to gain hit points + * raisemhp(x) subroutine to gain maximum hit points + * losespells(x) subroutine to lose spells + * losemspells(x) subroutine to lose maximum spells + * raisespells(x) subroutine to gain spells + * raisemspells(x) subroutine to gain maximum spells + * recalc() function to recalculate the armor class of the player + * makemonst(lev) function to return monster number for a randomly + * selected monster + * positionplayer() function to be sure player is not in a wall + * quit() subroutine to ask if the player really wants to quit */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: global.c,v 1.6 1997/10/18 20:03:20 christos Exp $"); +#endif /* not lint */ -#include "header.h" #include <string.h> -extern int score[],srcount,dropflag; -extern int random;/* the random number seed */ -extern short playerx,playery,lastnum,level; -extern char cheat,monstnamelist[]; -extern char lastmonst[],*what[],*who[]; -extern char winner[]; -extern char logname[],monstlevel[]; -extern char sciv[SCORESIZE+1][26][2],*potionname[],*scrollname[]; +#include <unistd.h> +#include "header.h" +#include "extern.h" +extern int score[], srcount, dropflag; +extern int random; /* the random number seed */ +extern short playerx, playery, lastnum, level; +extern u_char cheat; +extern char monstnamelist[], logname[]; +extern char lastmonst[], *what[], *who[]; +extern char winner[]; +extern u_char monstlevel[]; +extern char sciv[SCORESIZE + 1][26][2], *potionname[], *scrollname[]; /* *********** RAISE LEVEL @@ -42,10 +49,12 @@ extern char sciv[SCORESIZE+1][26][2],*potionname[],*scrollname[]; uses the skill[] array to find level boundarys uses c[EXPERIENCE] c[LEVEL] */ +void raiselevel() - { - if (c[LEVEL] < MAXPLEVEL) raiseexperience((long)(skill[c[LEVEL]]-c[EXPERIENCE])); - } +{ + if (c[LEVEL] < MAXPLEVEL) + raiseexperience((long) (skill[c[LEVEL]] - c[EXPERIENCE])); +} /* *********** @@ -55,10 +64,12 @@ raiselevel() subroutine to lower the players character level by one */ +void loselevel() - { - if (c[LEVEL] > 1) loseexperience((long)(c[EXPERIENCE] - skill[c[LEVEL]-1] + 1)); - } +{ + if (c[LEVEL] > 1) + loseexperience((long) (c[EXPERIENCE] - skill[c[LEVEL] - 1] + 1)); +} /* **************** @@ -68,25 +79,28 @@ loselevel() subroutine to increase experience points */ +void raiseexperience(x) - register long x; - { - register int i,tmp; - i=c[LEVEL]; c[EXPERIENCE]+=x; - while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) - { - tmp = (c[CONSTITUTION]-c[HARDGAME])>>1; - c[LEVEL]++; raisemhp((int)(rnd(3)+rnd((tmp>0)?tmp:1))); - raisemspells((int)rund(3)); - if (c[LEVEL] < 7-c[HARDGAME]) raisemhp((int)(c[CONSTITUTION]>>2)); - } - if (c[LEVEL] != i) - { + long x; +{ + int i, tmp; + i = c[LEVEL]; + c[EXPERIENCE] += x; + while (c[EXPERIENCE] >= skill[c[LEVEL]] && (c[LEVEL] < MAXPLEVEL)) { + tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; + c[LEVEL]++; + raisemhp((int) (rnd(3) + rnd((tmp > 0) ? tmp : 1))); + raisemspells((int) rund(3)); + if (c[LEVEL] < 7 - c[HARDGAME]) + raisemhp((int) (c[CONSTITUTION] >> 2)); + } + if (c[LEVEL] != i) { cursors(); - beep(); lprintf("\nWelcome to level %d",(long)c[LEVEL]); /* if we changed levels */ - } - bottomline(); + beep(); + lprintf("\nWelcome to level %d", (long) c[LEVEL]); /* if we changed levels */ } + bottomline(); +} /* **************** @@ -96,27 +110,31 @@ raiseexperience(x) subroutine to lose experience points */ +void loseexperience(x) - register long x; - { - register int i,tmp; - i=c[LEVEL]; c[EXPERIENCE]-=x; - if (c[EXPERIENCE] < 0) c[EXPERIENCE]=0; - while (c[EXPERIENCE] < skill[c[LEVEL]-1]) - { - if (--c[LEVEL] <= 1) c[LEVEL]=1; /* down one level */ - tmp = (c[CONSTITUTION]-c[HARDGAME])>>1; /* lose hpoints */ - losemhp((int)rnd((tmp>0)?tmp:1)); /* lose hpoints */ - if (c[LEVEL] < 7-c[HARDGAME]) losemhp((int)(c[CONSTITUTION]>>2)); - losemspells((int)rund(3)); /* lose spells */ - } - if (i!=c[LEVEL]) - { + long x; +{ + int i, tmp; + i = c[LEVEL]; + c[EXPERIENCE] -= x; + if (c[EXPERIENCE] < 0) + c[EXPERIENCE] = 0; + while (c[EXPERIENCE] < skill[c[LEVEL] - 1]) { + if (--c[LEVEL] <= 1) + c[LEVEL] = 1; /* down one level */ + tmp = (c[CONSTITUTION] - c[HARDGAME]) >> 1; /* lose hpoints */ + losemhp((int) rnd((tmp > 0) ? tmp : 1)); /* lose hpoints */ + if (c[LEVEL] < 7 - c[HARDGAME]) + losemhp((int) (c[CONSTITUTION] >> 2)); + losemspells((int) rund(3)); /* lose spells */ + } + if (i != c[LEVEL]) { cursors(); - beep(); lprintf("\nYou went down to level %d!",(long)c[LEVEL]); - } - bottomline(); + beep(); + lprintf("\nYou went down to level %d!", (long) c[LEVEL]); } + bottomline(); +} /* ******** @@ -128,21 +146,29 @@ loseexperience(x) subroutine to remove hit points from the player warning -- will kill player if hp goes to zero */ +void losehp(x) - register int x; - { - if ((c[HP] -= x) <= 0) - { - beep(); lprcat("\n"); nap(3000); died(lastnum); - } + int x; +{ + if ((c[HP] -= x) <= 0) { + beep(); + lprcat("\n"); + nap(3000); + died(lastnum); } +} +void losemhp(x) - register int x; - { - c[HP] -= x; if (c[HP] < 1) c[HP]=1; - c[HPMAX] -= x; if (c[HPMAX] < 1) c[HPMAX]=1; - } + int x; +{ + c[HP] -= x; + if (c[HP] < 1) + c[HP] = 1; + c[HPMAX] -= x; + if (c[HPMAX] < 1) + c[HPMAX] = 1; +} /* ******** @@ -153,17 +179,21 @@ losemhp(x) subroutine to gain maximum hit points */ +void raisehp(x) - register int x; - { - if ((c[HP] += x) > c[HPMAX]) c[HP] = c[HPMAX]; - } + int x; +{ + if ((c[HP] += x) > c[HPMAX]) + c[HP] = c[HPMAX]; +} +void raisemhp(x) - register int x; - { - c[HPMAX] += x; c[HP] += x; - } + int x; +{ + c[HPMAX] += x; + c[HP] += x; +} /* ************ @@ -174,17 +204,21 @@ raisemhp(x) subroutine to gain maximum spells */ +void raisespells(x) - register int x; - { - if ((c[SPELLS] += x) > c[SPELLMAX]) c[SPELLS] = c[SPELLMAX]; - } + int x; +{ + if ((c[SPELLS] += x) > c[SPELLMAX]) + c[SPELLS] = c[SPELLMAX]; +} +void raisemspells(x) - register int x; - { - c[SPELLMAX]+=x; c[SPELLS]+=x; - } + int x; +{ + c[SPELLMAX] += x; + c[SPELLS] += x; +} /* ************ @@ -195,121 +229,197 @@ raisemspells(x) subroutine to lose maximum spells */ +void losespells(x) - register int x; - { - if ((c[SPELLS] -= x) < 0) c[SPELLS]=0; - } + int x; +{ + if ((c[SPELLS] -= x) < 0) + c[SPELLS] = 0; +} +void losemspells(x) - register int x; - { - if ((c[SPELLMAX] -= x) < 0) c[SPELLMAX]=0; - if ((c[SPELLS] -= x) < 0) c[SPELLS]=0; - } + int x; +{ + if ((c[SPELLMAX] -= x) < 0) + c[SPELLMAX] = 0; + if ((c[SPELLS] -= x) < 0) + c[SPELLS] = 0; +} /* makemonst(lev) int lev; function to return monster number for a randomly selected monster - for the given cave level + for the given cave level */ +int makemonst(lev) - register int lev; - { - register int tmp,x; - if (lev < 1) lev = 1; if (lev > 12) lev = 12; - tmp=WATERLORD; + int lev; +{ + int tmp, x; + if (lev < 1) + lev = 1; + if (lev > 12) + lev = 12; + tmp = WATERLORD; if (lev < 5) - while (tmp==WATERLORD) tmp=rnd((x=monstlevel[lev-1])?x:1); - else while (tmp==WATERLORD) - tmp=rnd((x=monstlevel[lev-1]-monstlevel[lev-4])?x:1)+monstlevel[lev-4]; + while (tmp == WATERLORD) + tmp = rnd((x = monstlevel[lev - 1]) ? x : 1); + else + while (tmp == WATERLORD) + tmp = rnd((x = monstlevel[lev - 1] - monstlevel[lev - 4]) ? x : 1) + monstlevel[lev - 4]; - while (monster[tmp].genocided && tmp<MAXMONST) tmp++; /* genocided? */ - return(tmp); - } + while (monster[tmp].genocided && tmp < MAXMONST) + tmp++; /* genocided? */ + return (tmp); +} /* positionplayer() function to be sure player is not in a wall */ +void positionplayer() - { - int try; +{ + int try; try = 2; while ((item[playerx][playery] || mitem[playerx][playery]) && (try)) - if (++playerx >= MAXX-1) - { + if (++playerx >= MAXX - 1) { playerx = 1; - if (++playery >= MAXY-1) - { playery = 1; --try; } + if (++playery >= MAXY - 1) { + playery = 1; + --try; } - if (try==0) lprcat("Failure in positionplayer\n"); - } + } + if (try == 0) + lprcat("Failure in positionplayer\n"); +} /* recalc() function to recalculate the armor class of the player */ +void recalc() - { - register int i,j,k; +{ + int i, j, k; c[AC] = c[MOREDEFENSES]; - if (c[WEAR] >= 0) - switch(iven[c[WEAR]]) - { - case OSHIELD: c[AC] += 2 + ivenarg[c[WEAR]]; break; - case OLEATHER: c[AC] += 2 + ivenarg[c[WEAR]]; break; - case OSTUDLEATHER: c[AC] += 3 + ivenarg[c[WEAR]]; break; - case ORING: c[AC] += 5 + ivenarg[c[WEAR]]; break; - case OCHAIN: c[AC] += 6 + ivenarg[c[WEAR]]; break; - case OSPLINT: c[AC] += 7 + ivenarg[c[WEAR]]; break; - case OPLATE: c[AC] += 9 + ivenarg[c[WEAR]]; break; - case OPLATEARMOR: c[AC] += 10 + ivenarg[c[WEAR]]; break; - case OSSPLATE: c[AC] += 12 + ivenarg[c[WEAR]]; break; - } + if (c[WEAR] >= 0) + switch (iven[c[WEAR]]) { + case OSHIELD: + c[AC] += 2 + ivenarg[c[WEAR]]; + break; + case OLEATHER: + c[AC] += 2 + ivenarg[c[WEAR]]; + break; + case OSTUDLEATHER: + c[AC] += 3 + ivenarg[c[WEAR]]; + break; + case ORING: + c[AC] += 5 + ivenarg[c[WEAR]]; + break; + case OCHAIN: + c[AC] += 6 + ivenarg[c[WEAR]]; + break; + case OSPLINT: + c[AC] += 7 + ivenarg[c[WEAR]]; + break; + case OPLATE: + c[AC] += 9 + ivenarg[c[WEAR]]; + break; + case OPLATEARMOR: + c[AC] += 10 + ivenarg[c[WEAR]]; + break; + case OSSPLATE: + c[AC] += 12 + ivenarg[c[WEAR]]; + break; + } - if (c[SHIELD] >= 0) if (iven[c[SHIELD]] == OSHIELD) c[AC] += 2 + ivenarg[c[SHIELD]]; - if (c[WIELD] < 0) c[WCLASS] = 0; else - { + if (c[SHIELD] >= 0) + if (iven[c[SHIELD]] == OSHIELD) + c[AC] += 2 + ivenarg[c[SHIELD]]; + if (c[WIELD] < 0) + c[WCLASS] = 0; + else { i = ivenarg[c[WIELD]]; - switch(iven[c[WIELD]]) - { - case ODAGGER: c[WCLASS] = 3 + i; break; - case OBELT: c[WCLASS] = 7 + i; break; - case OSHIELD: c[WCLASS] = 8 + i; break; - case OSPEAR: c[WCLASS] = 10 + i; break; - case OFLAIL: c[WCLASS] = 14 + i; break; - case OBATTLEAXE: c[WCLASS] = 17 + i; break; - case OLANCE: c[WCLASS] = 19 + i; break; - case OLONGSWORD: c[WCLASS] = 22 + i; break; - case O2SWORD: c[WCLASS] = 26 + i; break; - case OSWORD: c[WCLASS] = 32 + i; break; - case OSWORDofSLASHING: c[WCLASS] = 30 + i; break; - case OHAMMER: c[WCLASS] = 35 + i; break; - default: c[WCLASS] = 0; - } + switch (iven[c[WIELD]]) { + case ODAGGER: + c[WCLASS] = 3 + i; + break; + case OBELT: + c[WCLASS] = 7 + i; + break; + case OSHIELD: + c[WCLASS] = 8 + i; + break; + case OSPEAR: + c[WCLASS] = 10 + i; + break; + case OFLAIL: + c[WCLASS] = 14 + i; + break; + case OBATTLEAXE: + c[WCLASS] = 17 + i; + break; + case OLANCE: + c[WCLASS] = 19 + i; + break; + case OLONGSWORD: + c[WCLASS] = 22 + i; + break; + case O2SWORD: + c[WCLASS] = 26 + i; + break; + case OSWORD: + c[WCLASS] = 32 + i; + break; + case OSWORDofSLASHING: + c[WCLASS] = 30 + i; + break; + case OHAMMER: + c[WCLASS] = 35 + i; + break; + default: + c[WCLASS] = 0; } + } c[WCLASS] += c[MOREDAM]; -/* now for regeneration abilities based on rings */ - c[REGEN]=1; c[ENERGY]=0; - j=0; for (k=25; k>0; k--) if (iven[k]) {j=k; k=0; } - for (i=0; i<=j; i++) - { - switch(iven[i]) - { - case OPROTRING: c[AC] += ivenarg[i] + 1; break; - case ODAMRING: c[WCLASS] += ivenarg[i] + 1; break; - case OBELT: c[WCLASS] += ((ivenarg[i]<<1)) + 2; break; - - case OREGENRING: c[REGEN] += ivenarg[i] + 1; break; - case ORINGOFEXTRA: c[REGEN] += 5 * (ivenarg[i]+1); break; - case OENERGYRING: c[ENERGY] += ivenarg[i] + 1; break; - } + /* now for regeneration abilities based on rings */ + c[REGEN] = 1; + c[ENERGY] = 0; + j = 0; + for (k = 25; k > 0; k--) + if (iven[k]) { + j = k; + k = 0; + } + for (i = 0; i <= j; i++) { + switch (iven[i]) { + case OPROTRING: + c[AC] += ivenarg[i] + 1; + break; + case ODAMRING: + c[WCLASS] += ivenarg[i] + 1; + break; + case OBELT: + c[WCLASS] += ((ivenarg[i] << 1)) + 2; + break; + + case OREGENRING: + c[REGEN] += ivenarg[i] + 1; + break; + case ORINGOFEXTRA: + c[REGEN] += 5 * (ivenarg[i] + 1); + break; + case OENERGYRING: + c[ENERGY] += ivenarg[i] + 1; + break; } } +} /* @@ -317,310 +427,522 @@ recalc() subroutine to ask if the player really wants to quit */ +void quit() - { - register int i; - cursors(); strcpy(lastmonst,""); +{ + int i; + cursors(); + strcpy(lastmonst, ""); lprcat("\n\nDo you really want to quit?"); - while (1) - { - i=getchar(); - if (i == 'y') { died(300); return; } - if ((i == 'n') || (i == '\33')) { lprcat(" no"); lflush(); return; } - lprcat("\n"); setbold(); lprcat("Yes"); resetbold(); lprcat(" or "); - setbold(); lprcat("No"); resetbold(); lprcat(" please? Do you want to quit? "); - } - } + while (1) { + i = getchar(); + if (i == 'y') { + died(300); + return; + } + if ((i == 'n') || (i == '\33')) { + lprcat(" no"); + lflush(); + return; + } + lprcat("\n"); + setbold(); + lprcat("Yes"); + resetbold(); + lprcat(" or "); + setbold(); + lprcat("No"); + resetbold(); + lprcat(" please? Do you want to quit? "); + } +} /* function to ask --more-- then the user must enter a space */ +void more() - { - lprcat("\n --- press "); standout("space"); lprcat(" to continue --- "); +{ + lprcat("\n --- press "); + standout("space"); + lprcat(" to continue --- "); while (getchar() != ' '); - } +} /* function to put something in the players inventory returns 0 if success, 1 if a failure */ -take(itm,arg) - int itm,arg; - { - register int i,limit; -/* cursors(); */ - if ((limit = 15+(c[LEVEL]>>1)) > 26) limit=26; - for (i=0; i<limit; i++) - if (iven[i]==0) - { - iven[i] = itm; ivenarg[i] = arg; limit=0; - switch(itm) - { - case OPROTRING: case ODAMRING: case OBELT: limit=1; break; - case ODEXRING: c[DEXTERITY] += ivenarg[i]+1; limit=1; break; - case OSTRRING: c[STREXTRA] += ivenarg[i]+1; limit=1; break; - case OCLEVERRING: c[INTELLIGENCE] += ivenarg[i]+1; limit=1; break; - case OHAMMER: c[DEXTERITY] += 10; c[STREXTRA]+=10; - c[INTELLIGENCE]-=10; limit=1; break; - - case OORBOFDRAGON: c[SLAYING]++; break; - case OSPIRITSCARAB: c[NEGATESPIRIT]++; break; - case OCUBEofUNDEAD: c[CUBEofUNDEAD]++; break; - case ONOTHEFT: c[NOTHEFT]++; break; - case OSWORDofSLASHING: c[DEXTERITY] +=5; limit=1; break; - }; - lprcat("\nYou pick up:"); srcount=0; show3(i); - if (limit) bottomline(); return(0); - } - lprcat("\nYou can't carry anything else"); return(1); - } +int +take(itm, arg) + int itm, arg; +{ + int i, limit; + /* cursors(); */ + if ((limit = 15 + (c[LEVEL] >> 1)) > 26) + limit = 26; + for (i = 0; i < limit; i++) + if (iven[i] == 0) { + iven[i] = itm; + ivenarg[i] = arg; + limit = 0; + switch (itm) { + case OPROTRING: + case ODAMRING: + case OBELT: + limit = 1; + break; + case ODEXRING: + c[DEXTERITY] += ivenarg[i] + 1; + limit = 1; + break; + case OSTRRING: + c[STREXTRA] += ivenarg[i] + 1; + limit = 1; + break; + case OCLEVERRING: + c[INTELLIGENCE] += ivenarg[i] + 1; + limit = 1; + break; + case OHAMMER: + c[DEXTERITY] += 10; + c[STREXTRA] += 10; + c[INTELLIGENCE] -= 10; + limit = 1; + break; + + case OORBOFDRAGON: + c[SLAYING]++; + break; + case OSPIRITSCARAB: + c[NEGATESPIRIT]++; + break; + case OCUBEofUNDEAD: + c[CUBEofUNDEAD]++; + break; + case ONOTHEFT: + c[NOTHEFT]++; + break; + case OSWORDofSLASHING: + c[DEXTERITY] += 5; + limit = 1; + break; + }; + lprcat("\nYou pick up:"); + srcount = 0; + show3(i); + if (limit) + bottomline(); + return (0); + } + lprcat("\nYou can't carry anything else"); + return (1); +} /* - subroutine to drop an object returns 1 if something there already else 0 + subroutine to drop an object + returns 1 if something there already else 0 */ +int drop_object(k) - int k; - { - int itm; - if ((k<0) || (k>25)) return(0); - itm = iven[k]; cursors(); - if (itm==0) { lprintf("\nYou don't have item %c! ",k+'a'); return(1); } - if (item[playerx][playery]) - { beep(); lprcat("\nThere's something here already"); return(1); } - if (playery==MAXY-1 && playerx==33) return(1); /* not in entrance */ + int k; +{ + int itm; + if ((k < 0) || (k > 25)) + return (0); + itm = iven[k]; + cursors(); + if (itm == 0) { + lprintf("\nYou don't have item %c! ", k + 'a'); + return (1); + } + if (item[playerx][playery]) { + beep(); + lprcat("\nThere's something here already"); + return (1); + } + if (playery == MAXY - 1 && playerx == 33) + return (1); /* not in entrance */ item[playerx][playery] = itm; iarg[playerx][playery] = ivenarg[k]; - srcount=0; lprcat("\n You drop:"); show3(k); /* show what item you dropped*/ - know[playerx][playery] = 0; iven[k]=0; - if (c[WIELD]==k) c[WIELD]= -1; if (c[WEAR]==k) c[WEAR] = -1; - if (c[SHIELD]==k) c[SHIELD]= -1; - adjustcvalues(itm,ivenarg[k]); - dropflag=1; /* say dropped an item so wont ask to pick it up right away */ - return(0); - } + srcount = 0; + lprcat("\n You drop:"); + show3(k); /* show what item you dropped */ + know[playerx][playery] = 0; + iven[k] = 0; + if (c[WIELD] == k) + c[WIELD] = -1; + if (c[WEAR] == k) + c[WEAR] = -1; + if (c[SHIELD] == k) + c[SHIELD] = -1; + adjustcvalues(itm, ivenarg[k]); + dropflag = 1; /* say dropped an item so wont ask to pick it + * up right away */ + return (0); +} /* function to enchant armor player is currently wearing */ +void enchantarmor() - { - register int tmp; - if (c[WEAR]<0) { if (c[SHIELD] < 0) - { cursors(); beep(); lprcat("\nYou feel a sense of loss"); return; } - else { tmp=iven[c[SHIELD]]; if (tmp != OSCROLL) if (tmp != OPOTION) { ivenarg[c[SHIELD]]++; bottomline(); } } } - tmp = iven[c[WEAR]]; - if (tmp!=OSCROLL) if (tmp!=OPOTION) { ivenarg[c[WEAR]]++; bottomline(); } +{ + int tmp; + if (c[WEAR] < 0) { + if (c[SHIELD] < 0) { + cursors(); + beep(); + lprcat("\nYou feel a sense of loss"); + return; + } else { + tmp = iven[c[SHIELD]]; + if (tmp != OSCROLL) + if (tmp != OPOTION) { + ivenarg[c[SHIELD]]++; + bottomline(); + } + } } + tmp = iven[c[WEAR]]; + if (tmp != OSCROLL) + if (tmp != OPOTION) { + ivenarg[c[WEAR]]++; + bottomline(); + } +} /* function to enchant a weapon presently being wielded */ +void enchweapon() - { - register int tmp; - if (c[WIELD]<0) - { cursors(); beep(); lprcat("\nYou feel a sense of loss"); return; } - tmp = iven[c[WIELD]]; - if (tmp!=OSCROLL) if (tmp!=OPOTION) - { ivenarg[c[WIELD]]++; - if (tmp==OCLEVERRING) c[INTELLIGENCE]++; else - if (tmp==OSTRRING) c[STREXTRA]++; else - if (tmp==ODEXRING) c[DEXTERITY]++; bottomline(); } +{ + int tmp; + if (c[WIELD] < 0) { + cursors(); + beep(); + lprcat("\nYou feel a sense of loss"); + return; } + tmp = iven[c[WIELD]]; + if (tmp != OSCROLL) + if (tmp != OPOTION) { + ivenarg[c[WIELD]]++; + if (tmp == OCLEVERRING) + c[INTELLIGENCE]++; + else if (tmp == OSTRRING) + c[STREXTRA]++; + else if (tmp == ODEXRING) + c[DEXTERITY]++; + bottomline(); + } +} /* routine to tell if player can carry one more thing returns 1 if pockets are full, else 0 */ +int pocketfull() - { - register int i,limit; - if ((limit = 15+(c[LEVEL]>>1)) > 26) limit=26; - for (i=0; i<limit; i++) if (iven[i]==0) return(0); - return(1); - } +{ + int i, limit; + if ((limit = 15 + (c[LEVEL] >> 1)) > 26) + limit = 26; + for (i = 0; i < limit; i++) + if (iven[i] == 0) + return (0); + return (1); +} /* function to return 1 if a monster is next to the player else returns 0 */ +int nearbymonst() - { - register int tmp,tmp2; - for (tmp=playerx-1; tmp<playerx+2; tmp++) - for (tmp2=playery-1; tmp2<playery+2; tmp2++) - if (mitem[tmp][tmp2]) return(1); /* if monster nearby */ - return(0); - } +{ + int tmp, tmp2; + for (tmp = playerx - 1; tmp < playerx + 2; tmp++) + for (tmp2 = playery - 1; tmp2 < playery + 2; tmp2++) + if (mitem[tmp][tmp2]) + return (1); /* if monster nearby */ + return (0); +} /* function to steal an item from the players pockets returns 1 if steals something else returns 0 */ +int stealsomething() - { - register int i,j; - j=100; - while (1) - { - i=rund(26); - if (iven[i]) if (c[WEAR]!=i) if (c[WIELD]!=i) if (c[SHIELD]!=i) - { - srcount=0; show3(i); - adjustcvalues(iven[i],ivenarg[i]); iven[i]=0; return(1); - } - if (--j <= 0) return(0); - } - } +{ + int i, j; + j = 100; + while (1) { + i = rund(26); + if (iven[i]) + if (c[WEAR] != i) + if (c[WIELD] != i) + if (c[SHIELD] != i) { + srcount = 0; + show3(i); + adjustcvalues(iven[i], ivenarg[i]); + iven[i] = 0; + return (1); + } + if (--j <= 0) + return (0); + } +} /* function to return 1 is player carrys nothing else return 0 */ +int emptyhanded() - { - register int i; - for (i=0; i<26; i++) - if (iven[i]) if (i!=c[WIELD]) if (i!=c[WEAR]) if (i!=c[SHIELD]) return(0); - return(1); - } +{ + int i; + for (i = 0; i < 26; i++) + if (iven[i]) + if (i != c[WIELD]) + if (i != c[WEAR]) + if (i != c[SHIELD]) + return (0); + return (1); +} /* function to create a gem on a square near the player */ +void creategem() - { - register int i,j; - switch(rnd(4)) - { - case 1: i=ODIAMOND; j=50; break; - case 2: i=ORUBY; j=40; break; - case 3: i=OEMERALD; j=30; break; - default: i=OSAPPHIRE; j=20; break; - }; - createitem(i,rnd(j)+j/10); - } +{ + int i, j; + switch (rnd(4)) { + case 1: + i = ODIAMOND; + j = 50; + break; + case 2: + i = ORUBY; + j = 40; + break; + case 3: + i = OEMERALD; + j = 30; + break; + default: + i = OSAPPHIRE; + j = 20; + break; + }; + createitem(i, rnd(j) + j / 10); +} /* function to change character levels as needed when dropping an object that affects these characteristics */ -adjustcvalues(itm,arg) - int itm,arg; - { - register int flag; - flag=0; - switch(itm) - { - case ODEXRING: c[DEXTERITY] -= arg+1; flag=1; break; - case OSTRRING: c[STREXTRA] -= arg+1; flag=1; break; - case OCLEVERRING: c[INTELLIGENCE] -= arg+1; flag=1; break; - case OHAMMER: c[DEXTERITY] -= 10; c[STREXTRA] -= 10; - c[INTELLIGENCE] += 10; flag=1; break; - case OSWORDofSLASHING: c[DEXTERITY] -= 5; flag=1; break; - case OORBOFDRAGON: --c[SLAYING]; return; - case OSPIRITSCARAB: --c[NEGATESPIRIT]; return; - case OCUBEofUNDEAD: --c[CUBEofUNDEAD]; return; - case ONOTHEFT: --c[NOTHEFT]; return; - case OLANCE: c[LANCEDEATH]=0; return; - case OPOTION: case OSCROLL: return; - - default: flag=1; - }; - if (flag) bottomline(); - } +void +adjustcvalues(itm, arg) + int itm, arg; +{ + int flag; + flag = 0; + switch (itm) { + case ODEXRING: + c[DEXTERITY] -= arg + 1; + flag = 1; + break; + case OSTRRING: + c[STREXTRA] -= arg + 1; + flag = 1; + break; + case OCLEVERRING: + c[INTELLIGENCE] -= arg + 1; + flag = 1; + break; + case OHAMMER: + c[DEXTERITY] -= 10; + c[STREXTRA] -= 10; + c[INTELLIGENCE] += 10; + flag = 1; + break; + case OSWORDofSLASHING: + c[DEXTERITY] -= 5; + flag = 1; + break; + case OORBOFDRAGON: + --c[SLAYING]; + return; + case OSPIRITSCARAB: + --c[NEGATESPIRIT]; + return; + case OCUBEofUNDEAD: + --c[CUBEofUNDEAD]; + return; + case ONOTHEFT: + --c[NOTHEFT]; + return; + case OLANCE: + c[LANCEDEATH] = 0; + return; + case OPOTION: + case OSCROLL: + return; + + default: + flag = 1; + }; + if (flag) + bottomline(); +} /* function to read a string from token input "string" returns a pointer to the string */ +void gettokstr(str) - register char *str; - { - register int i,j; - i=50; + char *str; +{ + int i, j; + i = 50; while ((getchar() != '"') && (--i > 0)); - i=36; - while (--i > 0) - { - if ((j=getchar()) != '"') *str++ = j; else i=0; - } - *str = 0; - i=50; - if (j != '"') while ((getchar() != '"') && (--i > 0)); /* if end due to too long, then find closing quote */ + i = 36; + while (--i > 0) { + if ((j = getchar()) != '"') + *str++ = j; + else + i = 0; } + *str = 0; + i = 50; + if (j != '"') + /* if end due to too long, then find closing quote */ + while ((getchar() != '"') && (--i > 0)); +} /* function to ask user for a password (no echo) returns 1 if entered correctly, 0 if not */ -static char gpwbuf[33]; +static char gpwbuf[33]; +int getpassword() - { - register int i,j; - register char *gpwp; - extern char *password; - scbr(); /* system("stty -echo cbreak"); */ - gpwp = gpwbuf; lprcat("\nEnter Password: "); lflush(); +{ + int i, j; + char *gpwp; + extern char *password; + scbr(); /* system("stty -echo cbreak"); */ + gpwp = gpwbuf; + lprcat("\nEnter Password: "); + lflush(); i = strlen(password); - for (j=0; j<i; j++) read(0,gpwp++,1); gpwbuf[i]=0; - sncbr(); /* system("stty echo -cbreak"); */ - if (strcmp(gpwbuf,password) != 0) - { lprcat("\nSorry\n"); lflush(); return(0); } - else return(1); - } + for (j = 0; j < i; j++) + read(0, gpwp++, 1); + gpwbuf[i] = 0; + sncbr(); /* system("stty echo -cbreak"); */ + if (strcmp(gpwbuf, password) != 0) { + lprcat("\nSorry\n"); + lflush(); + return (0); + } else + return (1); +} /* subroutine to get a yes or no response from the user returns y or n */ +int getyn() - { - register int i; - i=0; while (i!='y' && i!='n' && i!='\33') i=getchar(); - return(i); - } +{ + int i; + i = 0; + while (i != 'y' && i != 'n' && i != '\33') + i = getchar(); + return (i); +} /* function to calculate the pack weight of the player returns the number of pounds the player is carrying */ +int packweight() - { - register int i,j,k; - k=c[GOLD]/1000; j=25; while ((iven[j]==0) && (j>0)) --j; - for (i=0; i<=j; i++) - switch(iven[i]) - { - case 0: break; - case OSSPLATE: case OPLATEARMOR: k += 40; break; - case OPLATE: k += 35; break; - case OHAMMER: k += 30; break; - case OSPLINT: k += 26; break; - case OSWORDofSLASHING: case OCHAIN: - case OBATTLEAXE: case O2SWORD: k += 23; break; - case OLONGSWORD: case OSWORD: - case ORING: case OFLAIL: k += 20; break; - case OLANCE: case OSTUDLEATHER: k += 15; break; - case OLEATHER: case OSPEAR: k += 8; break; - case OORBOFDRAGON: case OBELT: k += 4; break; - case OSHIELD: k += 7; break; - case OCHEST: k += 30 + ivenarg[i]; break; - default: k++; - }; - return(k); - } +{ + int i, j, k; + k = c[GOLD] / 1000; + j = 25; + while ((iven[j] == 0) && (j > 0)) + --j; + for (i = 0; i <= j; i++) + switch (iven[i]) { + case 0: + break; + case OSSPLATE: + case OPLATEARMOR: + k += 40; + break; + case OPLATE: + k += 35; + break; + case OHAMMER: + k += 30; + break; + case OSPLINT: + k += 26; + break; + case OSWORDofSLASHING: + case OCHAIN: + case OBATTLEAXE: + case O2SWORD: + k += 23; + break; + case OLONGSWORD: + case OSWORD: + case ORING: + case OFLAIL: + k += 20; + break; + case OLANCE: + case OSTUDLEATHER: + k += 15; + break; + case OLEATHER: + case OSPEAR: + k += 8; + break; + case OORBOFDRAGON: + case OBELT: + k += 4; + break; + case OSHIELD: + k += 7; + break; + case OCHEST: + k += 30 + ivenarg[i]; + break; + default: + k++; + }; + return (k); +} #ifndef MACRORND - /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */ +/* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */ +int rnd(x) - int x; - { - return((((randx=randx*1103515245+12345)>>7)%(x))+1); - } + int x; +{ + return ((((randx = randx * 1103515245 + 12345) >> 7) % (x)) + 1); +} +int rund(x) - int x; - { - return((((randx=randx*1103515245+12345)>>7)%(x)) ); - } -#endif MACRORND + int x; +{ + return ((((randx = randx * 1103515245 + 12345) >> 7) % (x))); +} +#endif /* MACRORND */ diff --git a/larn/header.h b/larn/header.h index c3b8e392..0f033070 100644 --- a/larn/header.h +++ b/larn/header.h @@ -1,81 +1,79 @@ -/* $NetBSD: header.h,v 1.10 1997/07/13 20:21:35 christos Exp $ */ +/* $NetBSD: header.h,v 1.11 1997/10/18 20:03:22 christos Exp $ */ -/* header.h Larn is copyrighted 1986 by Noah Morgan. */ +/* header.h Larn is copyrighted 1986 by Noah Morgan. */ #include <sys/types.h> #define MAXLEVEL 11 - /* max # levels in the dungeon */ +/* max # levels in the dungeon */ #define MAXVLEVEL 3 - /* max # of levels in the temple of the luran */ +/* max # of levels in the temple of the luran */ #define MAXX 67 #define MAXY 17 #define SCORESIZE 10 - /* this is the number of people on a scoreboard max */ +/* this is the number of people on a scoreboard max */ #define MAXPLEVEL 100 - /* maximum player level allowed */ +/* maximum player level allowed */ #define MAXMONST 56 - /* maximum # monsters in the dungeon */ +/* maximum # monsters in the dungeon */ #define SPNUM 38 - /* maximum number of spells in existance */ +/* maximum number of spells in existance */ #define MAXSCROLL 28 - /* maximum number of scrolls that are possible */ +/* maximum number of scrolls that are possible */ #define MAXPOTION 35 - /* maximum number of potions that are possible */ +/* maximum number of potions that are possible */ #define TIMELIMIT 30000 - /* the maximum number of moves before the game is called */ +/* the maximum number of moves before the game is called */ #define TAXRATE 1/20 - /* the tax rate for the LRS */ +/* the tax rate for the LRS */ #define MAXOBJ 93 - /* the maximum number of objects n < MAXOBJ */ +/* the maximum number of objects n < MAXOBJ */ -/* this is the structure definition of the monster data */ -struct monst - { - char *name; - char level; - short armorclass; - char damage; - char attack; - char defense; - char genocided; - char intelligence; /* monsters intelligence -- used to choose movement */ - short gold; - short hitpoints; - unsigned long experience; - }; +/* this is the structure definition of the monster data */ +struct monst { + char *name; + char level; + short armorclass; + char damage; + char attack; + char defense; + char genocided; + char intelligence; /* monsters intelligence -- used to + * choose movement */ + short gold; + short hitpoints; + unsigned long experience; +}; -/* this is the structure definition for the items in the dnd store */ -struct _itm - { - short price; - char obj; - char arg; - char qty; - }; +/* this is the structure definition for the items in the dnd store */ +struct _itm { + short price; + u_char obj; + u_char arg; + char qty; +}; -/* this is the structure that holds the entire dungeon specifications */ -struct cel - { - short hitp; /* monster's hit points */ - char mitem; /* the monster ID */ - char item; /* the object's ID */ - short iarg; /* the object's argument */ - char know; /* have we been here before*/ - }; +/* this is the structure that holds the entire dungeon specifications */ +struct cel { + short hitp; /* monster's hit points */ + char mitem; /* the monster ID */ + char item; /* the object's ID */ + short iarg; /* the object's argument */ + char know; /* have we been here before */ +}; /* this is the structure for maintaining & moving the spheres of annihilation */ -struct sphere - { - struct sphere *p; /* pointer to next structure */ - char x,y,lev; /* location of the sphere */ - char dir; /* direction sphere is going in */ - short lifetime; /* duration of the sphere */ - }; +struct sphere { + struct sphere *p; /* pointer to next structure */ + char x, y, lev; /* location of the sphere */ + char dir; /* direction sphere is going in */ + short lifetime; /* duration of the sphere */ +}; -/* defines for the character attribute array c[] */ -#define STRENGTH 0 /* characters physical strength not due to objects */ +/* defines for the character attribute array c[] */ +#define STRENGTH 0 /* characters physical strength not due to + * objects */ #define INTELLIGENCE 1 #define WISDOM 2 #define CONSTITUTION 3 @@ -149,13 +147,14 @@ struct sphere #define SEEINVISIBLE 71 #define FILLROOM 72 #define RANDOMWALK 73 -#define SPHCAST 74 /* nz if an active sphere of annihilation */ -#define WTW 75 /* walk through walls */ -#define STREXTRA 76 /* character strength due to objects or enchantments */ -#define TMP 77 /* misc scratch space */ -#define LIFEPROT 78 /* life protection counter */ +#define SPHCAST 74 /* nz if an active sphere of annihilation */ +#define WTW 75 /* walk through walls */ +#define STREXTRA 76 /* character strength due to objects or + * enchantments */ +#define TMP 77 /* misc scratch space */ +#define LIFEPROT 78 /* life protection counter */ -/* defines for the objects in the game */ +/* defines for the objects in the game */ #define OALTAR 1 #define OTHRONE 2 @@ -222,7 +221,7 @@ struct sphere #define OSCROLL 41 #define OPOTION 42 #define OBOOK 43 -#define OCHEST 44 +#define OCHEST 44 #define OAMULET 45 #define OORBOFDRAGON 46 @@ -249,62 +248,62 @@ struct sphere #define OTRADEPOST 77 #define OIVTELETRAP 78 #define ODEADTHRONE 79 -#define OANNIHILATION 80 /* sphere of annihilation */ +#define OANNIHILATION 80 /* sphere of annihilation */ #define OTHRONE2 81 -#define OLRS 82 /* Larn Revenue Service */ +#define OLRS 82 /* Larn Revenue Service */ #define OCOOKIE 83 #define OURN 84 #define OBRASSLAMP 85 #define OHANDofFEAR 86 /* hand of fear */ #define OSPHTAILSMAN 87 /* tailsman of the sphere */ -#define OWWAND 88 /* wand of wonder */ -#define OPSTAFF 89 /* staff of power */ +#define OWWAND 88 /* wand of wonder */ +#define OPSTAFF 89 /* staff of power */ /* used up to 92 */ -/* defines for the monsters as objects */ +/* defines for the monsters as objects */ -#define BAT 1 -#define GNOME 2 -#define HOBGOBLIN 3 -#define JACKAL 4 -#define KOBOLD 5 -#define ORC 6 +#define BAT 1 +#define GNOME 2 +#define HOBGOBLIN 3 +#define JACKAL 4 +#define KOBOLD 5 +#define ORC 6 #define SNAKE 7 #define CENTIPEDE 8 -#define JACULI 9 -#define TROGLODYTE 10 -#define ANT 11 -#define EYE 12 +#define JACULI 9 +#define TROGLODYTE 10 +#define ANT 11 +#define EYE 12 #define LEPRECHAUN 13 -#define NYMPH 14 -#define QUASIT 15 -#define RUSTMONSTER 16 -#define ZOMBIE 17 -#define ASSASSINBUG 18 -#define BUGBEAR 19 -#define HELLHOUND 20 -#define ICELIZARD 21 -#define CENTAUR 22 -#define TROLL 23 -#define YETI 24 -#define WHITEDRAGON 25 -#define ELF 26 -#define CUBE 27 -#define METAMORPH 28 -#define VORTEX 29 -#define ZILLER 30 -#define VIOLETFUNGI 31 -#define WRAITH 32 -#define FORVALAKA 33 -#define LAMANOBE 34 -#define OSEQUIP 35 -#define ROTHE 36 -#define XORN 37 -#define VAMPIRE 38 -#define INVISIBLESTALKER 39 -#define POLTERGEIST 40 -#define DISENCHANTRESS 41 -#define SHAMBLINGMOUND 42 +#define NYMPH 14 +#define QUASIT 15 +#define RUSTMONSTER 16 +#define ZOMBIE 17 +#define ASSASSINBUG 18 +#define BUGBEAR 19 +#define HELLHOUND 20 +#define ICELIZARD 21 +#define CENTAUR 22 +#define TROLL 23 +#define YETI 24 +#define WHITEDRAGON 25 +#define ELF 26 +#define CUBE 27 +#define METAMORPH 28 +#define VORTEX 29 +#define ZILLER 30 +#define VIOLETFUNGI 31 +#define WRAITH 32 +#define FORVALAKA 33 +#define LAMANOBE 34 +#define OSEQUIP 35 +#define ROTHE 36 +#define XORN 37 +#define VAMPIRE 38 +#define INVISIBLESTALKER 39 +#define POLTERGEIST 40 +#define DISENCHANTRESS 41 +#define SHAMBLINGMOUND 42 #define YELLOWMOLD 43 #define UMBERHULK 44 #define GNOMEKING 45 @@ -323,78 +322,85 @@ struct sphere #define DEMONPRINCE 64 #define NULL 0 -#define BUFBIG 4096 /* size of the output buffer */ -#define MAXIBUF 4096 /* size of the input buffer */ -#define LOGNAMESIZE 40 /* max size of the players name */ -#define PSNAMESIZE 40 /* max size of the process name */ +#define BUFBIG 4096 /* size of the output buffer */ +#define MAXIBUF 4096 /* size of the input buffer */ +#define LOGNAMESIZE 40 /* max size of the players name */ +#define PSNAMESIZE 40 /* max size of the process name */ #ifndef NODEFS -extern char VERSION,SUBVERSION; -extern char aborted[],alpha[],beenhere[],boldon,cheat,ckpfile[],ckpflag; -extern char *class[],course[],diagfile[],helpfile[]; -extern char *inbuffer,is_alpha[],is_digit[]; -extern char item[MAXX][MAXY],iven[],know[MAXX][MAXY],larnlevels[],lastmonst[]; -extern char *levelname[],logfile[],loginname[],logname[],*lpbuf,*lpend; -extern char *lpnt,moved[MAXX][MAXY],mitem[MAXX][MAXY],monstlevel[]; -extern char monstnamelist[],nch[],ndgg[],nlpts[],nomove,nosignal,nowelcome; -extern char nplt[],nsw[],*objectname[],objnamelist[],optsfile[]; -extern char *potionhide[],*potionname[],playerids[],potprob[]; -extern char predostuff,psname[],restorflag,savefilename[],scorefile[],scprob[]; -extern char screen[MAXX][MAXY],*scrollhide[],*scrollname[],sex,*spelcode[]; -extern char *speldescript[]; -extern char spelknow[],*spelname[],*spelmes[],spelweird[MAXMONST+8][SPNUM]; -extern char splev[],stealth[MAXX][MAXY],to_lower[],to_upper[],wizard; -extern short diroffx[],diroffy[],hitflag,hit2flag,hit3flag,hitp[MAXX][MAXY]; -extern short iarg[MAXX][MAXY],ivenarg[],lasthx,lasthy,lastnum,lastpx,lastpy; -extern short nobeep,oldx,oldy,playerx,playery,level; -extern int dayplay,enable_scroll,srcount,yrepcount,userid,wisid,lfd,fd; -extern uid_t uid, euid; -extern long initialtime,outstanding_taxes,skill[],gltime,c[],cbak[]; +extern char VERSION, SUBVERSION; +extern u_char alpha[], beenhere[], boldon, cheat, ckpflag; +extern u_char *class[], course[]; +extern char diagfile[], helpfile[], ckpfile[], larnlevels[], + playerids[], optsfile[], psname[], savefilename[], + scorefile[]; +extern u_char *inbuffer, is_alpha[], is_digit[]; +extern u_char item[MAXX][MAXY], iven[], know[MAXX][MAXY]; +extern char *levelname[], logfile[], loginname[], logname[], + lastmonst[]; +extern u_char *lpbuf, *lpend; +extern u_char *lpnt, moved[MAXX][MAXY], mitem[MAXX][MAXY], monstlevel[]; +extern char monstnamelist[], objnamelist[]; +extern u_char nch[], ndgg[], nlpts[], nomove, nosignal, nowelcome; +extern u_char nplt[], nsw[]; +extern char *objectname[], *potionhide[], *potionname[], + *spelcode[], *spelname[], *spelmes[], aborted[], + spelweird[MAXMONST + 8][SPNUM]; +extern u_char potprob[]; +extern u_char predostuff, restorflag, scprob[]; +extern u_char screen[MAXX][MAXY], sex; +extern char *speldescript[], *scrollhide[], *scrollname[]; +extern u_char spelknow[]; +extern u_char splev[], stealth[MAXX][MAXY], to_lower[], to_upper[], wizard; +extern short diroffx[], diroffy[], hitflag, hit2flag, hit3flag, hitp[MAXX][MAXY]; +extern short iarg[MAXX][MAXY], ivenarg[], lasthx, lasthy, lastnum, lastpx, + lastpy; +extern short nobeep, oldx, oldy, playerx, playery, level; +extern int dayplay, enable_scroll, srcount, yrepcount, userid, wisid, + lfd, fd; +extern uid_t uid, euid; +extern long initialtime, outstanding_taxes, skill[], gltime, c[], cbak[]; extern unsigned long randx; extern struct cel *cell; extern struct monst monster[]; extern struct sphere *spheres; extern struct _itm itm[]; +extern long initialtime; +extern int rmst, maxitm, lasttime; -char *fortune(),*getenv(),*getlogin(),*lgetw(),*lgetl(),*ctime(); -char *tmcapcnv(),*tgetstr(),*tgoto(); -long paytaxes(),lgetc(),lrint(); -unsigned long readnum(); -void *malloc(); - - /* macro to create scroll #'s with probability of occurrence */ +/* macro to create scroll #'s with probability of occurrence */ #define newscroll() (scprob[rund(81)]) - /* macro to return a potion # created with probability of occurrence */ +/* macro to return a potion # created with probability of occurrence */ #define newpotion() (potprob[rund(41)]) - /* macro to return the + points on created leather armor */ +/* macro to return the + points on created leather armor */ #define newleather() (nlpts[rund(c[HARDGAME]?13:15)]) - /* macro to return the + points on chain armor */ +/* macro to return the + points on chain armor */ #define newchain() (nch[rund(10)]) - /* macro to return + points on plate armor */ +/* macro to return + points on plate armor */ #define newplate() (nplt[rund(c[HARDGAME]?4:12)]) - /* macro to return + points on new daggers */ +/* macro to return + points on new daggers */ #define newdagger() (ndgg[rund(13)]) - /* macro to return + points on new swords */ +/* macro to return + points on new swords */ #define newsword() (nsw[rund(c[HARDGAME]?6:13)]) - /* macro to destroy object at present location */ +/* macro to destroy object at present location */ #define forget() (item[playerx][playery]=know[playerx][playery]=0) - /* macro to wipe out a monster at a location */ +/* macro to wipe out a monster at a location */ #define disappear(x,y) (mitem[x][y]=know[x][y]=0) #ifdef VT100 - /* macro to turn on bold display for the terminal */ +/* macro to turn on bold display for the terminal */ #define setbold() (lprcat(boldon?"\33[1m":"\33[7m")) - /* macro to turn off bold display for the terminal */ +/* macro to turn off bold display for the terminal */ #define resetbold() (lprcat("\33[m")) - /* macro to setup the scrolling region for the terminal */ +/* macro to setup the scrolling region for the terminal */ #define setscroll() (lprcat("\33[20;24r")) - /* macro to clear the scrolling region for the terminal */ +/* macro to clear the scrolling region for the terminal */ #define resetscroll() (lprcat("\33[;24r")) - /* macro to clear the screen and home the cursor */ +/* macro to clear the screen and home the cursor */ #define clear() (lprcat("\33[2J\33[f"), cbak[SPELLS]= -50) #define cltoeoln() lprcat("\33[K") -#else VT100 - /* defines below are for use in the termcap mode only */ +#else /* VT100 */ +/* defines below are for use in the termcap mode only */ #define ST_START 1 #define ST_END 2 #define BOLD 3 @@ -403,31 +409,31 @@ void *malloc(); #define CL_LINE 6 #define CL_DOWN 14 #define CURSOR 15 - /* macro to turn on bold display for the terminal */ +/* macro to turn on bold display for the terminal */ #define setbold() (*lpnt++ = ST_START) - /* macro to turn off bold display for the terminal */ +/* macro to turn off bold display for the terminal */ #define resetbold() (*lpnt++ = ST_END) - /* macro to setup the scrolling region for the terminal */ +/* macro to setup the scrolling region for the terminal */ #define setscroll() enable_scroll=1 - /* macro to clear the scrolling region for the terminal */ +/* macro to clear the scrolling region for the terminal */ #define resetscroll() enable_scroll=0 - /* macro to clear the screen and home the cursor */ +/* macro to clear the screen and home the cursor */ #define clear() (*lpnt++ =CLEAR, cbak[SPELLS]= -50) - /* macro to clear to end of line */ +/* macro to clear to end of line */ #define cltoeoln() (*lpnt++ = CL_LINE) -#endif VT100 +#endif /* VT100 */ - /* macro to output one byte to the output buffer */ +/* macro to output one byte to the output buffer */ #define lprc(ch) ((lpnt>=lpend)?(*lpnt++ =(ch), lflush()):(*lpnt++ =(ch))) - /* macro to seed the random number generator */ +/* macro to seed the random number generator */ #define srand(x) (randx=x) #ifdef MACRORND - /* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */ +/* macros to generate random numbers 1<=rnd(N)<=N 0<=rund(N)<=N-1 */ #define rnd(x) ((((randx=randx*1103515245+12345)>>7)%(x))+1) #define rund(x) ((((randx=randx*1103515245+12345)>>7)%(x)) ) -#endif MACRORND - /* macros for miscellaneous data conversion */ +#endif /* MACRORND */ +/* macros for miscellaneous data conversion */ #define min(x,y) (((x)>(y))?(y):(x)) #define max(x,y) (((x)>(y))?(x):(y)) #define isalpha(x) (is_alpha[x]) @@ -436,5 +442,4 @@ void *malloc(); #define toupper(x) (to_upper[x]) #define lcc(x) (to_lower[x]) #define ucc(x) (to_upper[x]) -#endif NODEFS - +#endif /* NODEFS */ diff --git a/larn/help.c b/larn/help.c index 8cbae3a1..d0c1af04 100644 --- a/larn/help.c +++ b/larn/help.c @@ -1,11 +1,17 @@ +/* $NetBSD: help.c,v 1.4 1997/10/18 20:03:24 christos Exp $ */ + +/* help.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: help.c,v 1.3 1995/03/23 08:33:33 cgd Exp $"; +__RCSID("$NetBSD: help.c,v 1.4 1997/10/18 20:03:24 christos Exp $"); #endif /* not lint */ -/* help.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <unistd.h> + #include "header.h" +#include "extern.h" /* - * help function to display the help info + * help function to display the help info * * format of the .larn.help file * @@ -13,79 +19,107 @@ static char rcsid[] = "$NetBSD: help.c,v 1.3 1995/03/23 08:33:33 cgd Exp $"; * page (23 lines) for the introductory message (not counted in above) * pages of help text (23 lines per page) */ -extern char helpfile[]; +void help() - { - register int i,j; +{ + int i, j; #ifndef VT100 - char tmbuf[128]; /* intermediate translation buffer when not a VT100 */ -#endif VT100 - if ((j=openhelp()) < 0) return; /* open the help file and get # pages */ - for (i=0; i<23; i++) lgetl(); /* skip over intro message */ - for (; j>0; j--) - { + char tmbuf[128]; /* intermediate translation buffer + * when not a VT100 */ +#endif /* VT100 */ + if ((j = openhelp()) < 0) + return; /* open the help file and get # pages */ + for (i = 0; i < 23; i++) + lgetl(); /* skip over intro message */ + for (; j > 0; j--) { clear(); - for (i=0; i<23; i++) + for (i = 0; i < 23; i++) #ifdef VT100 - lprcat(lgetl()); /* print out each line that we read in */ -#else VT100 - { tmcapcnv(tmbuf,lgetl()); lprcat(tmbuf); } /* intercept \33's */ -#endif VT100 - if (j>1) - { - lprcat(" ---- Press "); standout("return"); - lprcat(" to exit, "); standout("space"); + lprcat(lgetl()); /* print out each line that + * we read in */ +#else /* VT100 */ + { + tmcapcnv(tmbuf, lgetl()); + lprcat(tmbuf); + } /* intercept \33's */ +#endif /* VT100 */ + if (j > 1) { + lprcat(" ---- Press "); + standout("return"); + lprcat(" to exit, "); + standout("space"); lprcat(" for more help ---- "); - i=0; while ((i!=' ') && (i!='\n') && (i!='\33')) i=getchar(); - if ((i=='\n') || (i=='\33')) - { - lrclose(); setscroll(); drawscreen(); return; - } + i = 0; + while ((i != ' ') && (i != '\n') && (i != '\33')) + i = getchar(); + if ((i == '\n') || (i == '\33')) { + lrclose(); + setscroll(); + drawscreen(); + return; } } - lrclose(); retcont(); drawscreen(); } + lrclose(); + retcont(); + drawscreen(); +} /* * function to display the welcome message and background */ +void welcome() - { - register int i; +{ + int i; #ifndef VT100 - char tmbuf[128]; /* intermediate translation buffer when not a VT100 */ -#endif VT100 - if (openhelp() < 0) return; /* open the help file */ + char tmbuf[128]; /* intermediate translation buffer + * when not a VT100 */ +#endif /* VT100 */ + if (openhelp() < 0) + return; /* open the help file */ clear(); - for(i=0; i<23; i++) + for (i = 0; i < 23; i++) #ifdef VT100 - lprcat(lgetl()); /* print out each line that we read in */ -#else VT100 - { tmcapcnv(tmbuf,lgetl()); lprcat(tmbuf); } /* intercept \33's */ -#endif VT100 - lrclose(); retcont(); /* press return to continue */ - } + lprcat(lgetl());/* print out each line that we read in */ +#else /* VT100 */ + { + tmcapcnv(tmbuf, lgetl()); + lprcat(tmbuf); + } /* intercept \33's */ +#endif /* VT100 */ + lrclose(); + retcont(); /* press return to continue */ +} /* * function to say press return to continue and reset scroll when done */ +void retcont() - { - cursor(1,24); lprcat("Press "); standout("return"); - lprcat(" to continue: "); while (getchar() != '\n'); +{ + cursor(1, 24); + lprcat("Press "); + standout("return"); + lprcat(" to continue: "); + while (getchar() != '\n'); setscroll(); - } +} /* * routine to open the help file and return the first character - '0' */ +int openhelp() - { - if (lopen(helpfile)<0) - { - lprintf("Can't open help file \"%s\" ",helpfile); - lflush(); sleep(4); drawscreen(); setscroll(); return(-1); - } - resetscroll(); return(lgetc() - '0'); +{ + if (lopen(helpfile) < 0) { + lprintf("Can't open help file \"%s\" ", helpfile); + lflush(); + sleep(4); + drawscreen(); + setscroll(); + return (-1); } - + resetscroll(); + return (lgetc() - '0'); +} @@ -1,80 +1,110 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: io.c,v 1.6 1997/05/17 19:26:22 pk Exp $"; -#endif /* not lint */ +/* $NetBSD: io.c,v 1.7 1997/10/18 20:03:26 christos Exp $ */ -/* io.c Larn is copyrighted 1986 by Noah Morgan. - * - * Below are the functions in this file: - * - * setupvt100() Subroutine to set up terminal in correct mode for game - * clearvt100() Subroutine to clean up terminal when the game is over - * getchar() Routine to read in one character from the terminal - * scbr() Function to set cbreak -echo for the terminal - * sncbr() Function to set -cbreak echo for the terminal - * newgame() Subroutine to save the initial time and seed rnd() - * - * FILE OUTPUT ROUTINES - * - * lprintf(format,args . . .) printf to the output buffer - * lprint(integer) send binary integer to output buffer - * lwrite(buf,len) write a buffer to the output buffer - * lprcat(str) sent string to output buffer - * - * FILE OUTPUT MACROS (in header.h) - * - * lprc(character) put the character into the output buffer - * - * FILE INPUT ROUTINES - * - * long lgetc() read one character from input buffer - * long lrint() read one integer from input buffer - * lrfill(address,number) put input bytes into a buffer - * char *lgetw() get a whitespace ended word from input - * char *lgetl() get a \n or EOF ended line from input - * - * FILE OPEN / CLOSE ROUTINES - * - * lcreat(filename) create a new file for write - * lopen(filename) open a file for read - * lappend(filename) open for append to an existing file - * lrclose() close the input file - * lwclose() close output file - * lflush() flush the output buffer - * - * Other Routines - * - * cursor(x,y) position cursor at [x,y] - * cursors() position cursor at [1,24] (saves memory) - * cl_line(x,y) Clear line at [1,y] and leave cursor at [x,y] - * cl_up(x,y) Clear screen from [x,1] to current line. - * cl_dn(x,y) Clear screen from [1,y] to end of display. - * standout(str) Print the string in standout mode. - * set_score_output() Called when output should be literally printed. - ** putchar(ch) Print one character in decoded output buffer. - ** flush_buf() Flush buffer with decoded output. - ** init_term() Terminal initialization -- setup termcap info - ** char *tmcapcnv(sd,ss) Routine to convert VT100 \33's to termcap format - * beep() Routine to emit a beep if enabled (see no-beep in .larnopts) - * +/* + * io.c Larn is copyrighted 1986 by Noah Morgan. + * + * Below are the functions in this file: + * + * setupvt100() Subroutine to set up terminal in correct mode for game + * clearvt100() Subroutine to clean up terminal when the game is over + * getchar() Routine to read in one character from the terminal + * scbr() Function to set cbreak -echo for the terminal + * sncbr() Function to set -cbreak echo for the terminal + * newgame() Subroutine to save the initial time and seed rnd() + * + * FILE OUTPUT ROUTINES + * + * lprintf(format,args . . .) printf to the output buffer lprint(integer) + * end binary integer to output buffer lwrite(buf,len) + * rite a buffer to the output buffer lprcat(str) + * ent string to output buffer + * + * FILE OUTPUT MACROS (in header.h) + * + * lprc(character) put the character into the output + * buffer + * + * FILE INPUT ROUTINES + * + * long lgetc() read one character from input buffer + * long lrint() read one integer from input buffer + * lrfill(address,number) put input bytes into a buffer char + * *lgetw() get a whitespace ended word from + * input char *lgetl() get a \n or EOF ended line + * from input + * + * FILE OPEN / CLOSE ROUTINES + * + * lcreat(filename) create a new file for write + * lopen(filename) open a file for read + * lappend(filename) open for append to an existing file + * lrclose() close the input file + * lwclose() close output file lflush() + * lush the output buffer + * + * Other Routines + * + * cursor(x,y) position cursor at [x,y] + * cursors() position cursor at [1,24] + * (saves memory) cl_line(x,y) Clear line at [1,y] and leave + * cursor at [x,y] cl_up(x,y) Clear screen + * from [x,1] to current line. cl_dn(x,y) + * lear screen from [1,y] to end of display. standout(str) + * rint the string in standout mode. set_score_output() + * alled when output should be literally printed. * xputchar(ch) + * rint one character in decoded output buffer. * flush_buf() + * lush buffer with decoded output. * init_term() + * erminal initialization -- setup termcap info * char *tmcapcnv(sd,ss) + * outine to convert VT100 \33's to termcap format beep() + * e to emit a beep if enabled (see no-beep in .larnopts) + * * Note: ** entries are available only in termcap mode. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: io.c,v 1.7 1997/10/18 20:03:26 christos Exp $"); +#endif /* not lint */ #include "header.h" +#include "extern.h" #include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <termcap.h> +#include <fcntl.h> #include <errno.h> -#ifdef SYSV /* system III or system V */ +#ifdef TERMIO #include <termio.h> #define sgttyb termio #define stty(_a,_b) ioctl(_a,TCSETA,_b) #define gtty(_a,_b) ioctl(_a,TCGETA,_b) -static int rawflg = 0; -static char saveeof,saveeol; -#define doraw(_a) if(!rawflg){++rawflg;saveeof=_a.c_cc[VMIN];saveeol=_a.c_cc[VTIME];}\ - _a.c_cc[VMIN]=1;_a.c_cc[VTIME]=1;_a.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL) -#define unraw(_a) _a.c_cc[VMIN]=saveeof;_a.c_cc[VTIME]=saveeol;_a.c_lflag |= ICANON|ECHO|ECHOE|ECHOK|ECHONL +#endif +#ifdef TERMIOS +#include <termios.h> +#define sgttyb termios +#define stty(_a,_b) tcsetattr(_a,TCSADRAIN,_b) +#define gtty(_a,_b) tcgetattr(_a,_b) +#endif -#else not SYSV +#if defined(TERMIO) || defined(TERMIOS) +static int rawflg = 0; +static char saveeof, saveeol; +#define doraw(_a) \ + if(!rawflg) { \ + ++rawflg; \ + saveeof = _a.c_cc[VMIN]; \ + saveeol = _a.c_cc[VTIME]; \ + } \ + _a.c_cc[VMIN] = 1; \ + _a.c_cc[VTIME] = 1; \ + _a.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL) +#define unraw(_a) \ + _a.c_cc[VMIN] = saveeof; \ + _a.c_cc[VTIME] = saveeol; \ + _a.c_lflag |= ICANON|ECHO|ECHOE|ECHOK|ECHONL + +#else /* not TERMIO or TERMIOS */ #ifndef BSD #define CBREAK RAW /* V7 has no CBREAK */ @@ -83,89 +113,109 @@ static char saveeof,saveeol; #define doraw(_a) (_a.sg_flags |= CBREAK,_a.sg_flags &= ~ECHO) #define unraw(_a) (_a.sg_flags &= ~CBREAK,_a.sg_flags |= ECHO) #include <sgtty.h> -#endif not SYSV +#endif /* not TERMIO or TERMIOS */ #ifndef NOVARARGS /* if we have varargs */ +#ifdef __STDC__ +#include <stdarg.h> +#else #include <varargs.h> -#else NOVARARGS /* if we don't have varargs */ -typedef char *va_list; +#endif +#else /* NOVARARGS */ /* if we don't have varargs */ +typedef char *va_list; #define va_dcl int va_alist; #define va_start(plist) plist = (char *) &va_alist #define va_end(plist) #define va_arg(plist,mode) ((mode *)(plist += sizeof(mode)))[-1] -#endif NOVARARGS +#endif /* NOVARARGS */ -#define LINBUFSIZE 128 /* size of the lgetw() and lgetl() buffer */ -int lfd; /* output file numbers */ -int fd; /* input file numbers */ -static struct sgttyb ttx; /* storage for the tty modes */ -static int ipoint=MAXIBUF,iepoint=MAXIBUF; /* input buffering pointers */ -static char lgetwbuf[LINBUFSIZE]; /* get line (word) buffer */ +#define LINBUFSIZE 128 /* size of the lgetw() and lgetl() buffer */ +int lfd; /* output file numbers */ +int fd; /* input file numbers */ +static struct sgttyb ttx;/* storage for the tty modes */ +static int ipoint = MAXIBUF, iepoint = MAXIBUF; /* input buffering + * pointers */ +static char lgetwbuf[LINBUFSIZE]; /* get line (word) buffer */ /* - * setupvt100() Subroutine to set up terminal in correct mode for game + * setupvt100() Subroutine to set up terminal in correct mode for game * - * Attributes off, clear screen, set scrolling region, set tty mode + * Attributes off, clear screen, set scrolling region, set tty mode */ +void setupvt100() - { - clear(); setscroll(); scbr(); /* system("stty cbreak -echo"); */ - } +{ + clear(); + setscroll(); + scbr(); /* system("stty cbreak -echo"); */ +} /* - * clearvt100() Subroutine to clean up terminal when the game is over + * clearvt100() Subroutine to clean up terminal when the game is over * - * Attributes off, clear screen, unset scrolling region, restore tty mode + * Attributes off, clear screen, unset scrolling region, restore tty mode */ +void clearvt100() - { - resetscroll(); clear(); sncbr(); /* system("stty -cbreak echo"); */ - } +{ + resetscroll(); + clear(); + sncbr(); /* system("stty -cbreak echo"); */ +} /* - * getchar() Routine to read in one character from the terminal + * getchar() Routine to read in one character from the terminal */ +int getchar() - { - char byt; +{ + char byt; #ifdef EXTRA c[BYTESIN]++; #endif lflush(); /* be sure output buffer is flushed */ - read(0,&byt,1); /* get byte from terminal */ - return(byt); - } + read(0, &byt, 1); /* get byte from terminal */ + return (byt); +} /* * scbr() Function to set cbreak -echo for the terminal * * like: system("stty cbreak -echo") */ +void scbr() - { - gtty(0,&ttx); doraw(ttx); stty(0,&ttx); - } +{ + gtty(0, &ttx); + doraw(ttx); + stty(0, &ttx); +} /* * sncbr() Function to set -cbreak echo for the terminal * * like: system("stty -cbreak echo") */ +void sncbr() - { - gtty(0,&ttx); unraw(ttx); stty(0,&ttx); - } +{ + gtty(0, &ttx); + unraw(ttx); + stty(0, &ttx); +} /* - * newgame() Subroutine to save the initial time and seed rnd() + * newgame() Subroutine to save the initial time and seed rnd() */ +void newgame() - { - register long *p,*pe; - for (p=c,pe=c+100; p<pe; *p++ =0); - time(&initialtime); srand(initialtime); - lcreat((char*)0); /* open buffering for output to terminal */ - } +{ + long *p, *pe; + for (p = c, pe = c + 100; p < pe; *p++ = 0); + time(&initialtime); + srand(initialtime); + lcreat((char *) 0); /* open buffering for output to terminal */ +} /* * lprintf(format,args . . .) printf to the output buffer @@ -176,76 +226,119 @@ newgame() * and any needed arguments following it * Note: lprintf() only supports %s, %c and %d, with width modifier and left * or right justification. - * No correct checking for output buffer overflow is done, but flushes + * No correct checking for output buffer overflow is done, but flushes * are done beforehand if needed. * Returns nothing of value. */ #ifdef lint -/*VARARGS*/ +/* VARARGS */ lprintf(str) - char *str; - { - char *str2; + char *str; +{ + char *str2; str2 = str; - str = str2; /* to make lint happy */ - } -/*VARARGS*/ + str = str2; /* to make lint happy */ +} +/* VARARGS */ sprintf(str) - char *str; - { - char *str2; + char *str; +{ + char *str2; str2 = str; - str = str2; /* to make lint happy */ - } -#else lint -/*VARARGS*/ + str = str2; /* to make lint happy */ +} +#else /* lint */ +/* VARARGS */ +#ifdef __STDC__ +void lprintf(const char *fmt, ...) +#else +void lprintf(va_alist) va_dcl - { - va_list ap; /* pointer for variable argument list */ - register char *fmt; - register char *outb,*tmpb; - register long wide,left,cont,n; /* data for lprintf */ - char db[12]; /* %d buffer in lprintf */ - - va_start(ap); /* initialize the var args pointer */ +#endif +{ + va_list ap; /* pointer for variable argument list */ + char *outb, *tmpb; + long wide, left, cont, n; /* data for lprintf */ + char db[12]; /* %d buffer in lprintf */ +#ifndef __STDC__ + char *fmt; + + va_start(ap); /* initialize the var args pointer */ fmt = va_arg(ap, char *); /* pointer to format string */ - if (lpnt >= lpend) lflush(); +#else + va_start(ap, fmt); +#endif + if (lpnt >= lpend) + lflush(); outb = lpnt; - for ( ; ; ) - { + for (;;) { while (*fmt != '%') - if (*fmt) *outb++ = *fmt++; else { lpnt=outb; return; } - wide = 0; left = 1; cont=1; + if (*fmt) + *outb++ = *fmt++; + else { + lpnt = outb; + return; + } + wide = 0; + left = 1; + cont = 1; while (cont) - switch(*(++fmt)) - { - case 'd': n = va_arg(ap, long); - if (n<0) { n = -n; *outb++ = '-'; if (wide) --wide; } - tmpb = db+11; *tmpb = (char)(n % 10 + '0'); - while (n>9) *(--tmpb) = (char)((n /= 10) % 10 + '0'); - if (wide==0) while (tmpb < db+12) *outb++ = *tmpb++; - else - { - wide -= db-tmpb+12; - if (left) while (wide-- > 0) *outb++ = ' '; - while (tmpb < db+12) *outb++ = *tmpb++; - if (left==0) while (wide-- > 0) *outb++ = ' '; - } - cont=0; break; - - case 's': tmpb = va_arg(ap, char *); - if (wide==0) { while (*outb++ = *tmpb++); --outb; } - else - { - n = wide - strlen(tmpb); - if (left) while (n-- > 0) *outb++ = ' '; - while (*outb++ = *tmpb++); --outb; - if (left==0) while (n-- > 0) *outb++ = ' '; - } - cont=0; break; - - case 'c': *outb++ = va_arg(ap, int); cont=0; break; + switch (*(++fmt)) { + case 'd': + n = va_arg(ap, long); + if (n < 0) { + n = -n; + *outb++ = '-'; + if (wide) + --wide; + } + tmpb = db + 11; + *tmpb = (char) (n % 10 + '0'); + while (n > 9) + *(--tmpb) = (char) ((n /= 10) % 10 + '0'); + if (wide == 0) + while (tmpb < db + 12) + *outb++ = *tmpb++; + else { + wide -= db - tmpb + 12; + if (left) + while (wide-- > 0) + *outb++ = ' '; + while (tmpb < db + 12) + *outb++ = *tmpb++; + if (left == 0) + while (wide-- > 0) + *outb++ = ' '; + } + cont = 0; + break; + + case 's': + tmpb = va_arg(ap, char *); + if (wide == 0) { + while ((*outb++ = *tmpb++) != '\0') + continue; + --outb; + } else { + n = wide - strlen(tmpb); + if (left) + while (n-- > 0) + *outb++ = ' '; + while ((*outb++ = *tmpb++) != '\0') + continue; + --outb; + if (left == 0) + while (n-- > 0) + *outb++ = ' '; + } + cont = 0; + break; + + case 'c': + *outb++ = va_arg(ap, int); + cont = 0; + break; case '0': case '1': @@ -256,194 +349,232 @@ va_dcl case '6': case '7': case '8': - case '9': wide = 10*wide + *fmt - '0'; break; - - case '-': left = 0; break; - - default: *outb++ = *fmt; cont=0; break; + case '9': + wide = 10 * wide + *fmt - '0'; + break; + + case '-': + left = 0; + break; + + default: + *outb++ = *fmt; + cont = 0; + break; }; fmt++; - } - va_end(ap); } -#endif lint + va_end(ap); +} +#endif /* lint */ /* - * lprint(long-integer) send binary integer to output buffer + * lprint(long-integer) send binary integer to output buffer * long integer; * * +---------+---------+---------+---------+ - * | high | | | low | - * | order | | | order | - * | byte | | | byte | + * | high | | | low | + * | order | | | order | + * | byte | | | byte | * +---------+---------+---------+---------+ - * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 + * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 * * The save order is low order first, to high order (4 bytes total) - * and is written to be system independent. + * and is written to be system independent. * No checking for output buffer overflow is done, but flushes if needed! * Returns nothing of value. */ +void lprint(x) - register long x; - { - if (lpnt >= lpend) lflush(); - *lpnt++ = 255 & x; *lpnt++ = 255 & (x>>8); - *lpnt++ = 255 & (x>>16); *lpnt++ = 255 & (x>>24); - } + long x; +{ + if (lpnt >= lpend) + lflush(); + *lpnt++ = 255 & x; + *lpnt++ = 255 & (x >> 8); + *lpnt++ = 255 & (x >> 16); + *lpnt++ = 255 & (x >> 24); +} /* - * lwrite(buf,len) write a buffer to the output buffer + * lwrite(buf,len) write a buffer to the output buffer * char *buf; * int len; - * + * * Enter with the address and number of bytes to write out * Returns nothing of value */ -lwrite(buf,len) - register char *buf; - int len; - { - register char *str; - register int num2; - if (len > 399) /* don't copy data if can just write it */ - { +void +lwrite(buf, len) + char *buf; + int len; +{ + char *str; + int num2; + if (len > 399) { /* don't copy data if can just write it */ #ifdef EXTRA c[BYTESOUT] += len; #endif #ifndef VT100 - for (str=buf; len>0; --len) + for (str = buf; len > 0; --len) lprc(*str++); -#else VT100 +#else /* VT100 */ lflush(); - write(lfd,buf,len); -#endif VT100 - } - else while (len) - { - if (lpnt >= lpend) lflush(); /* if buffer is full flush it */ - num2 = lpbuf+BUFBIG-lpnt; /* # bytes left in output buffer */ - if (num2 > len) num2=len; - str = lpnt; len -= num2; - while (num2--) *str++ = *buf++; /* copy in the bytes */ - lpnt = str; + write(lfd, buf, len); +#endif /* VT100 */ + } else + while (len) { + if (lpnt >= lpend) + lflush(); /* if buffer is full flush it */ + num2 = lpbuf + BUFBIG - lpnt; /* # bytes left in + * output buffer */ + if (num2 > len) + num2 = len; + str = lpnt; + len -= num2; + while (num2--) + *str++ = *buf++; /* copy in the bytes */ + lpnt = str; } - } +} /* - * long lgetc() Read one character from input buffer + * long lgetc() Read one character from input buffer * * Returns 0 if EOF, otherwise the character */ -long lgetc() - { - register int i; - if (ipoint != iepoint) return(inbuffer[ipoint++]); - if (iepoint!=MAXIBUF) return(0); - if ((i=read(fd,inbuffer,MAXIBUF))<=0) - { - if (i!=0) write(1,"error reading from input file\n",30); - iepoint = ipoint = 0; return(0); - } - ipoint=1; iepoint=i; return(*inbuffer); - } - -/* - * long lrint() Read one integer from input buffer +long +lgetc() +{ + int i; + if (ipoint != iepoint) + return (inbuffer[ipoint++]); + if (iepoint != MAXIBUF) + return (0); + if ((i = read(fd, inbuffer, MAXIBUF)) <= 0) { + if (i != 0) + write(1, "error reading from input file\n", 30); + iepoint = ipoint = 0; + return (0); + } + ipoint = 1; + iepoint = i; + return (*inbuffer); +} + +/* + * long lrint() Read one integer from input buffer * * +---------+---------+---------+---------+ - * | high | | | low | - * | order | | | order | - * | byte | | | byte | + * | high | | | low | + * | order | | | order | + * | byte | | | byte | * +---------+---------+---------+---------+ - * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 + * 31 --- 24 23 --- 16 15 --- 8 7 --- 0 * * The save order is low order first, to high order (4 bytes total) * Returns the int read */ -long lrint() - { - register unsigned long i; - i = 255 & lgetc(); i |= (255 & lgetc()) << 8; - i |= (255 & lgetc()) << 16; i |= (255 & lgetc()) << 24; - return(i); - } +long +lrint() +{ + unsigned long i; + i = 255 & lgetc(); + i |= (255 & lgetc()) << 8; + i |= (255 & lgetc()) << 16; + i |= (255 & lgetc()) << 24; + return (i); +} /* - * lrfill(address,number) put input bytes into a buffer + * lrfill(address,number) put input bytes into a buffer * char *address; * int number; * * Reads "number" bytes into the buffer pointed to by "address". * Returns nothing of value */ -lrfill(adr,num) - register char *adr; - int num; - { - register char *pnt; - register int num2; - while (num) - { - if (iepoint == ipoint) - { - if (num>5) /* fast way */ - { - if (read(fd,adr,num) != num) - write(2,"error reading from input file\n",30); - num=0; - } - else { *adr++ = lgetc(); --num; } - } - else - { - num2 = iepoint-ipoint; /* # of bytes left in the buffer */ - if (num2 > num) num2=num; - pnt = inbuffer+ipoint; num -= num2; ipoint += num2; - while (num2--) *adr++ = *pnt++; +void +lrfill(adr, num) + char *adr; + int num; +{ + char *pnt; + int num2; + while (num) { + if (iepoint == ipoint) { + if (num > 5) { /* fast way */ + if (read(fd, adr, num) != num) + write(2, "error reading from input file\n", 30); + num = 0; + } else { + *adr++ = lgetc(); + --num; } + } else { + num2 = iepoint - ipoint; /* # of bytes left in + * the buffer */ + if (num2 > num) + num2 = num; + pnt = inbuffer + ipoint; + num -= num2; + ipoint += num2; + while (num2--) + *adr++ = *pnt++; } } +} /* * char *lgetw() Get a whitespace ended word from input * * Returns pointer to a buffer that contains word. If EOF, returns a NULL */ -char *lgetw() - { - register char *lgp,cc; - register int n=LINBUFSIZE,quote=0; +char * +lgetw() +{ + char *lgp, cc; + int n = LINBUFSIZE, quote = 0; lgp = lgetwbuf; - do cc=lgetc(); while ((cc <= 32) && (cc > '\0')); /* eat whitespace */ - for ( ; ; --n,cc=lgetc()) - { - if ((cc=='\0') && (lgp==lgetwbuf)) return(NULL); /* EOF */ - if ((n<=1) || ((cc<=32) && (quote==0))) { *lgp='\0'; return(lgetwbuf); } - if (cc != '"') *lgp++ = cc; else quote ^= 1; + do + cc = lgetc(); + while ((cc <= 32) && (cc > '\0')); /* eat whitespace */ + for (;; --n, cc = lgetc()) { + if ((cc == '\0') && (lgp == lgetwbuf)) + return (NULL); /* EOF */ + if ((n <= 1) || ((cc <= 32) && (quote == 0))) { + *lgp = '\0'; + return (lgetwbuf); } + if (cc != '"') + *lgp++ = cc; + else + quote ^= 1; } +} /* - * char *lgetl() Function to read in a line ended by newline or EOF + * char *lgetl() Function to read in a line ended by newline or EOF * - * Returns pointer to a buffer that contains the line. If EOF, returns NULL - */ -char *lgetl() - { - register int i=LINBUFSIZE,ch; - register char *str=lgetwbuf; - for ( ; ; --i) - { - if ((*str++ = ch = lgetc()) == '\0') - { - if (str == lgetwbuf+1) return(NULL); /* EOF */ - ot: *str = '\0'; return(lgetwbuf); /* line ended by EOF */ - } - if ((ch=='\n') || (i<=1)) goto ot; /* line ended by \n */ + * Returns pointer to a buffer that contains the line. If EOF, returns NULL + */ +char * +lgetl() +{ + int i = LINBUFSIZE, ch; + char *str = lgetwbuf; + for (;; --i) { + if ((*str++ = ch = lgetc()) == '\0') { + if (str == lgetwbuf + 1) + return (NULL); /* EOF */ + ot: *str = '\0'; + return (lgetwbuf); /* line ended by EOF */ } + if ((ch == '\n') || (i <= 1)) + goto ot;/* line ended by \n */ } +} /* * lcreat(filename) Create a new file for write @@ -452,19 +583,23 @@ char *lgetl() * lcreat((char*)0); means to the terminal * Returns -1 if error, otherwise the file descriptor opened. */ +int lcreat(str) char *str; - { - lpnt = lpbuf; lpend = lpbuf+BUFBIG; - if (str==NULL) return(lfd=1); - if ((lfd=creat(str,0644)) < 0) - { - lfd=1; lprintf("error creating file <%s>: %s\n",str, +{ + lpnt = lpbuf; + lpend = lpbuf + BUFBIG; + if (str == NULL) + return (lfd = 1); + if ((lfd = creat(str, 0644)) < 0) { + lfd = 1; + lprintf("error creating file <%s>: %s\n", str, strerror(errno)); - lflush(); return(-1); - } - return(lfd); + lflush(); + return (-1); } + return (lfd); +} /* * lopen(filename) Open a file for read @@ -473,17 +608,21 @@ lcreat(str) * lopen(0) means from the terminal * Returns -1 if error, otherwise the file descriptor opened. */ +int lopen(str) - char *str; - { + char *str; +{ ipoint = iepoint = MAXIBUF; - if (str==NULL) return(fd=0); - if ((fd=open(str,0)) < 0) - { - lwclose(); lfd=1; lpnt=lpbuf; return(-1); - } - return(fd); + if (str == NULL) + return (fd = 0); + if ((fd = open(str, 0)) < 0) { + lwclose(); + lfd = 1; + lpnt = lpbuf; + return (-1); } + return (fd); +} /* * lappend(filename) Open for append to an existing file @@ -492,107 +631,129 @@ lopen(str) * lappend(0) means to the terminal * Returns -1 if error, otherwise the file descriptor opened. */ +int lappend(str) - char *str; - { - lpnt = lpbuf; lpend = lpbuf+BUFBIG; - if (str==NULL) return(lfd=1); - if ((lfd=open(str,2)) < 0) - { - lfd=1; return(-1); - } - lseek(lfd,0,2); /* seek to end of file */ - return(lfd); + char *str; +{ + lpnt = lpbuf; + lpend = lpbuf + BUFBIG; + if (str == NULL) + return (lfd = 1); + if ((lfd = open(str, 2)) < 0) { + lfd = 1; + return (-1); } + lseek(lfd, 0, 2); /* seek to end of file */ + return (lfd); +} /* - * lrclose() close the input file + * lrclose() close the input file * * Returns nothing of value. */ +void lrclose() - { - if (fd > 0) close(fd); - } +{ + if (fd > 0) + close(fd); +} /* - * lwclose() close output file flushing if needed + * lwclose() close output file flushing if needed * * Returns nothing of value. */ +void lwclose() - { - lflush(); if (lfd > 2) close(lfd); - } +{ + lflush(); + if (lfd > 2) + close(lfd); +} /* - * lprcat(string) append a string to the output buffer - * avoids calls to lprintf (time consuming) + * lprcat(string) append a string to the output buffer + * avoids calls to lprintf (time consuming) */ +void lprcat(str) - register char *str; - { - register char *str2; - if (lpnt >= lpend) lflush(); + char *str; +{ + char *str2; + if (lpnt >= lpend) + lflush(); str2 = lpnt; - while (*str2++ = *str++); + while ((*str2++ = *str++) != '\0') + continue; lpnt = str2 - 1; - } +} #ifdef VT100 /* * cursor(x,y) Subroutine to set the cursor position * * x and y are the cursor coordinates, and lpbuff is the output buffer where - * escape sequence will be placed. - */ -static char *y_num[]= { "\33[","\33[","\33[2","\33[3","\33[4","\33[5","\33[6", - "\33[7","\33[8","\33[9","\33[10","\33[11","\33[12","\33[13","\33[14", - "\33[15","\33[16","\33[17","\33[18","\33[19","\33[20","\33[21","\33[22", - "\33[23","\33[24" }; - -static char *x_num[]= { "H","H",";2H",";3H",";4H",";5H",";6H",";7H",";8H",";9H", - ";10H",";11H",";12H",";13H",";14H",";15H",";16H",";17H",";18H",";19H", - ";20H",";21H",";22H",";23H",";24H",";25H",";26H",";27H",";28H",";29H", - ";30H",";31H",";32H",";33H",";34H",";35H",";36H",";37H",";38H",";39H", - ";40H",";41H",";42H",";43H",";44H",";45H",";46H",";47H",";48H",";49H", - ";50H",";51H",";52H",";53H",";54H",";55H",";56H",";57H",";58H",";59H", - ";60H",";61H",";62H",";63H",";64H",";65H",";66H",";67H",";68H",";69H", - ";70H",";71H",";72H",";73H",";74H",";75H",";76H",";77H",";78H",";79H", - ";80H" }; - -cursor(x,y) - int x,y; - { - register char *p; - if (lpnt >= lpend) lflush(); - - p = y_num[y]; /* get the string to print */ - while (*p) *lpnt++ = *p++; /* print the string */ - - p = x_num[x]; /* get the string to print */ - while (*p) *lpnt++ = *p++; /* print the string */ - } -#else VT100 + * escape sequence will be placed. + */ +static char *y_num[] = { +"\33[", "\33[", "\33[2", "\33[3", "\33[4", "\33[5", "\33[6", +"\33[7", "\33[8", "\33[9", "\33[10", "\33[11", "\33[12", "\33[13", "\33[14", +"\33[15", "\33[16", "\33[17", "\33[18", "\33[19", "\33[20", "\33[21", "\33[22", +"\33[23", "\33[24"}; + +static char *x_num[] = { +"H", "H", ";2H", ";3H", ";4H", ";5H", ";6H", ";7H", ";8H", ";9H", +";10H", ";11H", ";12H", ";13H", ";14H", ";15H", ";16H", ";17H", ";18H", ";19H", +";20H", ";21H", ";22H", ";23H", ";24H", ";25H", ";26H", ";27H", ";28H", ";29H", +";30H", ";31H", ";32H", ";33H", ";34H", ";35H", ";36H", ";37H", ";38H", ";39H", +";40H", ";41H", ";42H", ";43H", ";44H", ";45H", ";46H", ";47H", ";48H", ";49H", +";50H", ";51H", ";52H", ";53H", ";54H", ";55H", ";56H", ";57H", ";58H", ";59H", +";60H", ";61H", ";62H", ";63H", ";64H", ";65H", ";66H", ";67H", ";68H", ";69H", +";70H", ";71H", ";72H", ";73H", ";74H", ";75H", ";76H", ";77H", ";78H", ";79H", +";80H"}; + +void +cursor(x, y) + int x, y; +{ + char *p; + if (lpnt >= lpend) + lflush(); + + p = y_num[y]; /* get the string to print */ + while (*p) + *lpnt++ = *p++; /* print the string */ + + p = x_num[x]; /* get the string to print */ + while (*p) + *lpnt++ = *p++; /* print the string */ +} +#else /* VT100 */ /* * cursor(x,y) Put cursor at specified coordinates staring at [1,1] (termcap) */ -cursor (x,y) - int x,y; - { - if (lpnt >= lpend) lflush (); +void +cursor(x, y) + int x, y; +{ + if (lpnt >= lpend) + lflush(); - *lpnt++ = CURSOR; *lpnt++ = x; *lpnt++ = y; - } -#endif VT100 + *lpnt++ = CURSOR; + *lpnt++ = x; + *lpnt++ = y; +} +#endif /* VT100 */ /* * Routine to position cursor at beginning of 24th line */ +void cursors() - { - cursor(1,24); - } +{ + cursor(1, 24); +} #ifndef VT100 /* @@ -602,322 +763,371 @@ cursors() * obvious meanings. */ -static char cap[256]; -char *CM, *CE, *CD, *CL, *SO, *SE, *AL, *DL;/* Termcap capabilities */ -static char *outbuf=0; /* translated output buffer */ - -int putchar (); +static char cap[256]; +char *CM, *CE, *CD, *CL, *SO, *SE, *AL, *DL; /* Termcap capabilities */ +static char *outbuf = 0; /* translated output buffer */ /* * init_term() Terminal initialization -- setup termcap info */ +void init_term() - { - char termbuf[1024]; - char *capptr = cap+10; - char *term; - - switch (tgetent(termbuf, term = getenv("TERM"))) - { - case -1: - write(2, "Cannot open termcap file.\n", 26); exit(); - case 0: - write(2, "Cannot find entry of ", 21); - write(2, term, strlen (term)); - write(2, " in termcap\n", 12); - exit(); - }; - - CM = tgetstr("cm", &capptr); /* Cursor motion */ - CE = tgetstr("ce", &capptr); /* Clear to eoln */ - CL = tgetstr("cl", &capptr); /* Clear screen */ - -/* OPTIONAL */ - AL = tgetstr("al", &capptr); /* Insert line */ - DL = tgetstr("dl", &capptr); /* Delete line */ - SO = tgetstr("so", &capptr); /* Begin standout mode */ - SE = tgetstr("se", &capptr); /* End standout mode */ - CD = tgetstr("cd", &capptr); /* Clear to end of display */ - - if (!CM) /* can't find cursor motion entry */ - { - write(2, "Sorry, for a ",13); write(2, term, strlen(term)); - write(2, ", I can't find the cursor motion entry in termcap\n",50); - exit(); - } - if (!CE) /* can't find clear to end of line entry */ - { - write(2, "Sorry, for a ",13); write(2, term, strlen(term)); - write(2,", I can't find the clear to end of line entry in termcap\n",57); - exit(); - } - if (!CL) /* can't find clear entire screen entry */ - { - write(2, "Sorry, for a ",13); write(2, term, strlen(term)); - write(2, ", I can't find the clear entire screen entry in termcap\n",56); - exit(); - } - if ((outbuf=malloc(BUFBIG+16))==0) /* get memory for decoded output buffer*/ - { - write(2,"Error malloc'ing memory for decoded output buffer\n",50); +{ + char termbuf[1024]; + char *capptr = cap + 10; + char *term; + + switch (tgetent(termbuf, term = getenv("TERM"))) { + case -1: + write(2, "Cannot open termcap file.\n", 26); + exit(1); + case 0: + write(2, "Cannot find entry of ", 21); + write(2, term, strlen(term)); + write(2, " in termcap\n", 12); + exit(1); + }; + + CM = tgetstr("cm", &capptr); /* Cursor motion */ + CE = tgetstr("ce", &capptr); /* Clear to eoln */ + CL = tgetstr("cl", &capptr); /* Clear screen */ + + /* OPTIONAL */ + AL = tgetstr("al", &capptr); /* Insert line */ + DL = tgetstr("dl", &capptr); /* Delete line */ + SO = tgetstr("so", &capptr); /* Begin standout mode */ + SE = tgetstr("se", &capptr); /* End standout mode */ + CD = tgetstr("cd", &capptr); /* Clear to end of display */ + + if (!CM) { /* can't find cursor motion entry */ + write(2, "Sorry, for a ", 13); + write(2, term, strlen(term)); + write(2, ", I can't find the cursor motion entry in termcap\n", 50); + exit(1); + } + if (!CE) { /* can't find clear to end of line entry */ + write(2, "Sorry, for a ", 13); + write(2, term, strlen(term)); + write(2, ", I can't find the clear to end of line entry in termcap\n", 57); + exit(1); + } + if (!CL) { /* can't find clear entire screen entry */ + write(2, "Sorry, for a ", 13); + write(2, term, strlen(term)); + write(2, ", I can't find the clear entire screen entry in termcap\n", 56); + exit(1); + } + if ((outbuf = malloc(BUFBIG + 16)) == 0) { /* get memory for + * decoded output buffer */ + write(2, "Error malloc'ing memory for decoded output buffer\n", 50); died(-285); /* malloc() failure */ - } } -#endif VT100 +} +#endif /* VT100 */ /* * cl_line(x,y) Clear the whole line indicated by 'y' and leave cursor at [x,y] */ -cl_line(x,y) - int x,y; - { +void +cl_line(x, y) + int x, y; +{ #ifdef VT100 - cursor(x,y); lprcat("\33[2K"); -#else VT100 - cursor(1,y); *lpnt++ = CL_LINE; cursor(x,y); -#endif VT100 - } + cursor(x, y); + lprcat("\33[2K"); +#else /* VT100 */ + cursor(1, y); + *lpnt++ = CL_LINE; + cursor(x, y); +#endif /* VT100 */ +} /* * cl_up(x,y) Clear screen from [x,1] to current position. Leave cursor at [x,y] */ -cl_up(x,y) - register int x,y; - { +void +cl_up(x, y) + int x, y; +{ #ifdef VT100 - cursor(x,y); lprcat("\33[1J\33[2K"); -#else VT100 - register int i; - cursor(1,1); - for (i=1; i<=y; i++) { *lpnt++ = CL_LINE; *lpnt++ = '\n'; } - cursor(x,y); -#endif VT100 + cursor(x, y); + lprcat("\33[1J\33[2K"); +#else /* VT100 */ + int i; + cursor(1, 1); + for (i = 1; i <= y; i++) { + *lpnt++ = CL_LINE; + *lpnt++ = '\n'; } + cursor(x, y); +#endif /* VT100 */ +} /* * cl_dn(x,y) Clear screen from [1,y] to end of display. Leave cursor at [x,y] */ -cl_dn(x,y) - register int x,y; - { +void +cl_dn(x, y) + int x, y; +{ #ifdef VT100 - cursor(x,y); lprcat("\33[J\33[2K"); -#else VT100 - register int i; - cursor(1,y); - if (!CD) - { + cursor(x, y); + lprcat("\33[J\33[2K"); +#else /* VT100 */ + int i; + cursor(1, y); + if (!CD) { *lpnt++ = CL_LINE; - for (i=y; i<=24; i++) { *lpnt++ = CL_LINE; if (i!=24) *lpnt++ = '\n'; } - cursor(x,y); + for (i = y; i <= 24; i++) { + *lpnt++ = CL_LINE; + if (i != 24) + *lpnt++ = '\n'; } - else + cursor(x, y); + } else *lpnt++ = CL_DOWN; - cursor(x,y); -#endif VT100 - } + cursor(x, y); +#endif /* VT100 */ +} /* * standout(str) Print the argument string in inverse video (standout mode). */ +void standout(str) - register char *str; - { + char *str; +{ #ifdef VT100 setbold(); while (*str) *lpnt++ = *str++; resetbold(); -#else VT100 +#else /* VT100 */ *lpnt++ = ST_START; while (*str) *lpnt++ = *str++; *lpnt++ = ST_END; -#endif VT100 - } +#endif /* VT100 */ +} /* * set_score_output() Called when output should be literally printed. */ +void set_score_output() - { +{ enable_scroll = -1; - } +} /* - * lflush() Flush the output buffer + * lflush() Flush the output buffer * * Returns nothing of value. * for termcap version: Flush output in output buffer according to output - * status as indicated by `enable_scroll' + * status as indicated by `enable_scroll' */ #ifndef VT100 -static int scrline=18; /* line # for wraparound instead of scrolling if no DL */ -lflush () - { - register int lpoint; - register char *str; - static int curx = 0; - static int cury = 0; - - if ((lpoint = lpnt - lpbuf) > 0) - { +static int scrline = 18; /* line # for wraparound instead of scrolling + * if no DL */ +void +lflush() +{ + int lpoint; + u_char *str; + static int curx = 0; + static int cury = 0; + + if ((lpoint = lpnt - lpbuf) > 0) { #ifdef EXTRA c[BYTESOUT] += lpoint; #endif - if (enable_scroll <= -1) - { + if (enable_scroll <= -1) { flush_buf(); - if (write(lfd,lpbuf,lpoint) != lpoint) - write(2,"error writing to output file\n",29); + if (write(lfd, lpbuf, lpoint) != lpoint) + write(2, "error writing to output file\n", 29); lpnt = lpbuf; /* point back to beginning of buffer */ return; - } - for (str = lpbuf; str < lpnt; str++) - { - if (*str>=32) { putchar (*str); curx++; } - else switch (*str) - { - case CLEAR: tputs (CL, 0, putchar); curx = cury = 0; - break; - - case CL_LINE: tputs (CE, 0, putchar); - break; - - case CL_DOWN: tputs (CD, 0, putchar); - break; - - case ST_START: tputs (SO, 0, putchar); - break; - - case ST_END: tputs (SE, 0, putchar); - break; - - case CURSOR: curx = *++str - 1; cury = *++str - 1; - tputs (tgoto (CM, curx, cury), 0, putchar); - break; - - case '\n': if ((cury == 23) && enable_scroll) - { - if (!DL || !AL) /* wraparound or scroll? */ - { - if (++scrline > 23) scrline=19; - - if (++scrline > 23) scrline=19; - tputs (tgoto (CM, 0, scrline), 0, putchar); - tputs (CE, 0, putchar); - - if (--scrline < 19) scrline=23; - tputs (tgoto (CM, 0, scrline), 0, putchar); - tputs (CE, 0, putchar); - } - else - { - tputs (tgoto (CM, 0, 19), 0, putchar); - tputs (DL, 0, putchar); - tputs (tgoto (CM, 0, 23), 0, putchar); - /* tputs (AL, 0, putchar); */ - } - } - else - { - putchar ('\n'); cury++; - } - curx = 0; - break; - - default: putchar (*str); curx++; + } + for (str = lpbuf; str < lpnt; str++) { + if (*str >= 32) { + xputchar(*str); + curx++; + } else + switch (*str) { + case CLEAR: + tputs(CL, 0, xputchar); + curx = cury = 0; + break; + + case CL_LINE: + tputs(CE, 0, xputchar); + break; + + case CL_DOWN: + tputs(CD, 0, xputchar); + break; + + case ST_START: + tputs(SO, 0, xputchar); + break; + + case ST_END: + tputs(SE, 0, xputchar); + break; + + case CURSOR: + curx = *++str - 1; + cury = *++str - 1; + tputs(tgoto(CM, curx, cury), 0, xputchar); + break; + + case '\n': + if ((cury == 23) && enable_scroll) { + if (!DL || !AL) { /* wraparound or scroll? */ + if (++scrline > 23) + scrline = 19; + + if (++scrline > 23) + scrline = 19; + tputs(tgoto(CM, 0, scrline), 0, xputchar); + tputs(CE, 0, xputchar); + + if (--scrline < 19) + scrline = 23; + tputs(tgoto(CM, 0, scrline), 0, xputchar); + tputs(CE, 0, xputchar); + } else { + tputs(tgoto(CM, 0, 19), 0, xputchar); + tputs(DL, 0, xputchar); + tputs(tgoto(CM, 0, 23), 0, xputchar); + /* + * tputs (AL, 0, + * xputchar); + */ + } + } else { + xputchar('\n'); + cury++; + } + curx = 0; + break; + + default: + xputchar(*str); + curx++; }; - } } - lpnt = lpbuf; - flush_buf(); /* flush real output buffer now */ } -#else VT100 + lpnt = lpbuf; + flush_buf(); /* flush real output buffer now */ +} +#else /* VT100 */ /* - * lflush() flush the output buffer + * lflush() flush the output buffer * * Returns nothing of value. */ +void lflush() - { - register int lpoint; - if ((lpoint = lpnt - lpbuf) > 0) - { +{ + int lpoint; + if ((lpoint = lpnt - lpbuf) > 0) { #ifdef EXTRA c[BYTESOUT] += lpoint; #endif - if (write(lfd,lpbuf,lpoint) != lpoint) - write(2,"error writing to output file\n",29); - } - lpnt = lpbuf; /* point back to beginning of buffer */ - } -#endif VT100 + if (write(lfd, lpbuf, lpoint) != lpoint) + write(2, "error writing to output file\n", 29); + } + lpnt = lpbuf; /* point back to beginning of buffer */ +} +#endif /* VT100 */ #ifndef VT100 -static int vindex=0; +static int vindex = 0; /* - * putchar(ch) Print one character in decoded output buffer. + * xputchar(ch) Print one character in decoded output buffer. */ -int putchar(c) -int c; - { +void +xputchar(c) + int c; +{ outbuf[vindex++] = c; - if (vindex >= BUFBIG) flush_buf(); - } + if (vindex >= BUFBIG) + flush_buf(); +} /* * flush_buf() Flush buffer with decoded output. */ +void flush_buf() - { - if (vindex) write(lfd, outbuf, vindex); +{ + if (vindex) + write(lfd, outbuf, vindex); vindex = 0; - } +} /* - * char *tmcapcnv(sd,ss) Routine to convert VT100 escapes to termcap format - * - * Processes only the \33[#m sequence (converts . files for termcap use - */ -char *tmcapcnv(sd,ss) - register char *sd,*ss; - { - register int tmstate=0; /* 0=normal, 1=\33 2=[ 3=# */ - char tmdigit=0; /* the # in \33[#m */ - while (*ss) - { - switch(tmstate) - { - case 0: if (*ss=='\33') { tmstate++; break; } - ign: *sd++ = *ss; - ign2: tmstate = 0; - break; - case 1: if (*ss!='[') goto ign; - tmstate++; - break; - case 2: if (isdigit(*ss)) { tmdigit= *ss-'0'; tmstate++; break; } - if (*ss == 'm') { *sd++ = ST_END; goto ign2; } - goto ign; - case 3: if (*ss == 'm') - { - if (tmdigit) *sd++ = ST_START; - else *sd++ = ST_END; - goto ign2; - } - default: goto ign; - }; + * char *tmcapcnv(sd,ss) Routine to convert VT100 escapes to termcap + * format + * Processes only the \33[#m sequence (converts . files for termcap use + */ +char * +tmcapcnv(sd, ss) + char *sd, *ss; +{ + int tmstate = 0; /* 0=normal, 1=\33 2=[ 3=# */ + char tmdigit = 0; /* the # in \33[#m */ + while (*ss) { + switch (tmstate) { + case 0: + if (*ss == '\33') { + tmstate++; + break; + } + ign: *sd++ = *ss; + ign2: tmstate = 0; + break; + case 1: + if (*ss != '[') + goto ign; + tmstate++; + break; + case 2: + if (isdigit((u_char)*ss)) { + tmdigit = *ss - '0'; + tmstate++; + break; + } + if (*ss == 'm') { + *sd++ = ST_END; + goto ign2; + } + goto ign; + case 3: + if (*ss == 'm') { + if (tmdigit) + *sd++ = ST_START; + else + *sd++ = ST_END; + goto ign2; + } + default: + goto ign; + }; ss++; - } - *sd=0; /* NULL terminator */ - return(sd); } -#endif VT100 + *sd = 0; /* NULL terminator */ + return (sd); +} +#endif /* VT100 */ /* - * beep() Routine to emit a beep if enabled (see no-beep in .larnopts) + * beep() Routine to emit a beep if enabled (see no-beep in .larnopts) */ +void beep() - { - if (!nobeep) *lpnt++ = '\7'; - } +{ + if (!nobeep) + *lpnt++ = '\7'; +} diff --git a/larn/main.c b/larn/main.c index 1517c787..a65edfdf 100644 --- a/larn/main.c +++ b/larn/main.c @@ -1,24 +1,36 @@ +/* $NetBSD: main.c,v 1.11 1997/10/18 20:03:27 christos Exp $ */ + +/* main.c */ +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: main.c,v 1.10 1997/07/13 20:21:36 christos Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: main.c,v 1.11 1997/10/18 20:03:27 christos Exp $"); +#endif /* not lint */ -/* main.c */ #include <sys/types.h> -#include "header.h" +#include <stdio.h> #include <pwd.h> +#include <unistd.h> +#include <stdlib.h> #include <string.h> - -static char copyright[]="\nLarn is copyrighted 1986 by Noah Morgan.\n"; -int srcount=0; /* line counter for showstr() */ -int dropflag=0; /* if 1 then don't lookforobject() next round */ -int rmst=80; /* random monster creation counter */ -int userid; /* the players login user id number */ -uid_t uid, euid; /* used for security */ -char nowelcome=0,nomove=0; /* if (nomove) then don't count next iteration as a move */ -static char viewflag=0; - /* if viewflag then we have done a 99 stay here and don't showcell in the main loop */ -char restorflag=0; /* 1 means restore has been done */ -static char cmdhelp[] = "\ +#include "header.h" +#include "extern.h" + +static char copyright[] = "\nLarn is copyrighted 1986 by Noah Morgan.\n"; +int srcount = 0; /* line counter for showstr() */ +int dropflag = 0; /* if 1 then don't lookforobject() next round */ +int rmst = 80; /* random monster creation counter */ +int userid; /* the players login user id number */ +uid_t uid, euid; /* used for security */ +u_char nowelcome = 0, nomove = 0; /* if (nomove) then don't + * count next iteration as a + * move */ +static char viewflag = 0; +/* + * if viewflag then we have done a 99 stay here and don't showcell in the + * main loop + */ +u_char restorflag = 0; /* 1 means restore has been done */ +static char cmdhelp[] = "\ Cmd line format: larn [-slicnh] [-o<optsifle>] [-##] [++]\n\ -s show the scoreboard\n\ -l show the logfile (wizard id only)\n\ @@ -31,789 +43,1185 @@ Cmd line format: larn [-slicnh] [-o<optsifle>] [-##] [++]\n\ -o<optsfile> specify .larnopts filename to be used instead of \"~/.larnopts\"\n\ "; #ifdef VT100 -static char *termtypes[] = { "vt100", "vt101", "vt102", "vt103", "vt125", +static char *termtypes[] = {"vt100", "vt101", "vt102", "vt103", "vt125", "vt131", "vt140", "vt180", "vt220", "vt240", "vt241", "vt320", "vt340", - "vt341" }; -#endif VT100 +"vt341"}; +#endif /* VT100 */ /* ************ MAIN PROGRAM ************ */ -main(argc,argv) - int argc; - char **argv; - { - register int i,j; - int hard; - char *ptr=0,*ttype; - struct passwd *pwe; +int +main(argc, argv) + int argc; + char **argv; +{ + int i; + int hard; + char *ptr = 0; + struct passwd *pwe; euid = geteuid(); uid = getuid(); - seteuid(uid); /* give up "games" if we have it */ -/* - * first task is to identify the player - */ + seteuid(uid); /* give up "games" if we have it */ + /* + * first task is to identify the player + */ #ifndef VT100 - init_term(); /* setup the terminal (find out what type) for termcap */ -#endif VT100 - if (((ptr = getlogin()) == 0) || (*ptr==0)) /* try to get login name */ - if (pwe=getpwuid(getuid())) /* can we get it from /etc/passwd? */ - ptr = pwe->pw_name; - else - if ((ptr = getenv("USER")) == 0) - if ((ptr = getenv("LOGNAME")) == 0) - { - noone: write(2, "Can't find your logname. Who Are You?\n",39); - exit(); - } - if (ptr==0) goto noone; - if (strlen(ptr)==0) goto noone; -/* - * second task is to prepare the pathnames the player will need - */ - strcpy(loginname,ptr); /* save loginname of the user for logging purposes */ - strcpy(logname,ptr); /* this will be overwritten with the players name */ - if ((ptr = getenv("HOME")) == 0) ptr = "."; + init_term(); /* setup the terminal (find out what type) + * for termcap */ +#endif /* VT100 */ + if (((ptr = getlogin()) == 0) || (*ptr == 0)) /* try to get login name */ + if ((pwe = getpwuid(getuid())) != NULL)/* can we get it from + * /etc/passwd? */ + ptr = pwe->pw_name; + else if ((ptr = getenv("USER")) == 0) + if ((ptr = getenv("LOGNAME")) == 0) { + noone: write(2, "Can't find your logname. Who Are You?\n", 39); + exit(1); + } + if (ptr == 0) + goto noone; + if (strlen(ptr) == 0) + goto noone; + /* + * second task is to prepare the pathnames the player will need + */ + strcpy(loginname, ptr); /* save loginname of the user for logging + * purposes */ + strcpy(logname, ptr); /* this will be overwritten with the players + * name */ + if ((ptr = getenv("HOME")) == NULL) + ptr = "."; strcpy(savefilename, ptr); - strcat(savefilename, "/Larn.sav"); /* save file name in home directory */ - sprintf(optsfile, "%s/.larnopts",ptr); /* the .larnopts filename */ - -/* - * now malloc the memory for the dungeon - */ - cell = (struct cel *)malloc(sizeof(struct cel)*(MAXLEVEL+MAXVLEVEL)*MAXX*MAXY); - if (cell == 0) died(-285); /* malloc failure */ - lpbuf = malloc((5* BUFBIG)>>2); /* output buffer */ - inbuffer = malloc((5*MAXIBUF)>>2); /* output buffer */ - if ((lpbuf==0) || (inbuffer==0)) died(-285); /* malloc() failure */ - - lcreat((char*)0); newgame(); /* set the initial clock */ hard= -1; + strcat(savefilename, "/Larn.sav"); /* save file name in home + * directory */ + sprintf(optsfile, "%s/.larnopts", ptr); /* the .larnopts filename */ + + /* + * now malloc the memory for the dungeon + */ + cell = (struct cel *) malloc(sizeof(struct cel) * (MAXLEVEL + MAXVLEVEL) * MAXX * MAXY); + if (cell == 0) + died(-285); /* malloc failure */ + lpbuf = malloc((5 * BUFBIG) >> 2); /* output buffer */ + inbuffer = malloc((5 * MAXIBUF) >> 2); /* output buffer */ + if ((lpbuf == 0) || (inbuffer == 0)) + died(-285); /* malloc() failure */ + + lcreat((char *) 0); + newgame(); /* set the initial clock */ + hard = -1; #ifdef VT100 -/* - * check terminal type to avoid users who have not vt100 type terminals - */ + /* + * check terminal type to avoid users who have not vt100 type terminals + */ ttype = getenv("TERM"); - for (j=1, i=0; i<sizeof(termtypes)/sizeof(char *); i++) - if (strcmp(ttype,termtypes[i]) == 0) { j=0; break; } - if (j) - { - lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n"); lflush(); - exit(); + for (j = 1, i = 0; i < sizeof(termtypes) / sizeof(char *); i++) + if (strcmp(ttype, termtypes[i]) == 0) { + j = 0; + break; } -#endif VT100 + if (j) { + lprcat("Sorry, Larn needs a VT100 family terminal for all it's features.\n"); + lflush(); + exit(1); + } +#endif /* VT100 */ -/* - * now make scoreboard if it is not there (don't clear) - */ - if (access(scorefile,0) == -1) /* not there */ + /* + * now make scoreboard if it is not there (don't clear) + */ + if (access(scorefile, 0) == -1) /* not there */ makeboard(); -/* - * now process the command line arguments - */ - for (i=1; i<argc; i++) - { + /* + * now process the command line arguments + */ + for (i = 1; i < argc; i++) { if (argv[i][0] == '-') - switch(argv[i][1]) - { - case 's': showscores(); exit(); /* show scoreboard */ - - case 'l': /* show log file */ - diedlog(); exit(); - - case 'i': showallscores(); exit(); /* show all scoreboard */ - - case 'c': /* anyone with password can create scoreboard */ - lprcat("Preparing to initialize the scoreboard.\n"); - if (getpassword() != 0) /*make new scoreboard*/ - { - makeboard(); lprc('\n'); showscores(); - } - exit(); - - case 'n': /* no welcome msg */ nowelcome=1; argv[i][0]=0; break; - - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': /* for hardness */ - sscanf(&argv[i][1],"%d",&hard); - break; + switch (argv[i][1]) { + case 's': + showscores(); + exit(0); /* show scoreboard */ + + case 'l': /* show log file */ + diedlog(); + exit(0); + + case 'i': + showallscores(); + exit(0); /* show all scoreboard */ + + case 'c': /* anyone with password can create + * scoreboard */ + lprcat("Preparing to initialize the scoreboard.\n"); + if (getpassword() != 0) { /* make new scoreboard */ + makeboard(); + lprc('\n'); + showscores(); + } + exit(0); + + case 'n': /* no welcome msg */ + nowelcome = 1; + argv[i][0] = 0; + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': /* for hardness */ + sscanf(&argv[i][1], "%d", &hard); + break; case 'h': /* print out command line arguments */ - write(1,cmdhelp,sizeof(cmdhelp)); exit(); + write(1, cmdhelp, sizeof(cmdhelp)); + exit(0); case 'o': /* specify a .larnopts filename */ - strncpy(optsfile,argv[i]+2,127); break; + strncpy(optsfile, argv[i] + 2, 127); + break; - default: printf("Unknown option <%s>\n",argv[i]); exit(); + default: + printf("Unknown option <%s>\n", argv[i]); + exit(1); }; - if (argv[i][0] == '+') - { - clear(); restorflag = 1; - if (argv[i][1] == '+') - { - hitflag=1; restoregame(ckpfile); /* restore checkpointed game */ - } - i = argc; + if (argv[i][0] == '+') { + clear(); + restorflag = 1; + if (argv[i][1] == '+') { + hitflag = 1; + restoregame(ckpfile); /* restore checkpointed + * game */ } + i = argc; } + } readopts(); /* read the options file if there is one */ #ifdef UIDSCORE userid = geteuid(); /* obtain the user's effective id number */ -#else UIDSCORE +#else /* UIDSCORE */ userid = getplid(logname); /* obtain the players id number */ -#endif UIDSCORE - if (userid < 0) { write(2,"Can't obtain playerid\n",22); exit(); } - +#endif /* UIDSCORE */ + if (userid < 0) { + write(2, "Can't obtain playerid\n", 22); + exit(1); + } #ifdef HIDEBYLINK -/* - * this section of code causes the program to look like something else to ps - */ - if (strcmp(psname,argv[0])) /* if a different process name only */ - { - if ((i=access(psname,1)) < 0) - { /* link not there */ - if (link(argv[0],psname)>=0) - { - argv[0] = psname; execv(psname,argv); - } + /* + * this section of code causes the program to look like something else to ps + */ + if (strcmp(psname, argv[0])) { /* if a different process name only */ + if ((i = access(psname, 1)) < 0) { /* link not there */ + if (link(argv[0], psname) >= 0) { + argv[0] = psname; + execv(psname, argv); } - else + } else unlink(psname); - } - - for (i=1; i<argc; i++) - { + } + for (i = 1; i < argc; i++) { szero(argv[i]); /* zero the argument to avoid ps snooping */ - } -#endif HIDEBYLINK + } +#endif /* HIDEBYLINK */ - if (access(savefilename,0)==0) /* restore game if need to */ - { - clear(); restorflag = 1; - hitflag=1; restoregame(savefilename); /* restore last game */ - } - sigsetup(); /* trap all needed signals */ - sethard(hard); /* set up the desired difficulty */ - setupvt100(); /* setup the terminal special mode */ - if (c[HP]==0) /* create new game */ - { - makeplayer(); /* make the character that will play */ - newcavelevel(0);/* make the dungeon */ - predostuff = 1; /* tell signals that we are in the welcome screen */ - if (nowelcome==0) welcome(); /* welcome the player to the game */ - } - drawscreen(); /* show the initial dungeon */ - predostuff = 2; /* tell the trap functions that they must do a showplayer() - from here on */ - /* nice(1); /* games should be run niced */ + if (access(savefilename, 0) == 0) { /* restore game if need to */ + clear(); + restorflag = 1; + hitflag = 1; + restoregame(savefilename); /* restore last game */ + } + sigsetup(); /* trap all needed signals */ + sethard(hard); /* set up the desired difficulty */ + setupvt100(); /* setup the terminal special mode */ + if (c[HP] == 0) { /* create new game */ + makeplayer(); /* make the character that will play */ + newcavelevel(0);/* make the dungeon */ + predostuff = 1; /* tell signals that we are in the welcome + * screen */ + if (nowelcome == 0) + welcome(); /* welcome the player to the game */ + } + drawscreen(); /* show the initial dungeon */ + predostuff = 2; /* tell the trap functions that they must do + * a showplayer() from here on */ +#if 0 + nice(1); /* games should be run niced */ +#endif yrepcount = hit2flag = 0; - while (1) - { - if (dropflag==0) lookforobject(); /* see if there is an object here */ - else dropflag=0; /* don't show it just dropped an item */ - if (hitflag==0) { if (c[HASTEMONST]) movemonst(); movemonst(); } /* move the monsters */ - if (viewflag==0) showcell(playerx,playery); else viewflag=0; /* show stuff around player */ - if (hit3flag) flushall(); - hitflag=hit3flag=0; nomove=1; + while (1) { + if (dropflag == 0) + lookforobject(); /* see if there is an object + * here */ + else + dropflag = 0; /* don't show it just dropped an item */ + if (hitflag == 0) { + if (c[HASTEMONST]) + movemonst(); + movemonst(); + } /* move the monsters */ + if (viewflag == 0) + showcell(playerx, playery); + else + viewflag = 0; /* show stuff around player */ + if (hit3flag) + flushall(); + hitflag = hit3flag = 0; + nomove = 1; bot_linex(); /* update bottom line */ - while (nomove) - { - if (hit3flag) flushall(); - nomove=0; parse(); - } /* get commands and make moves */ - regen(); /* regenerate hp and spells */ - if (c[TIMESTOP]==0) - if (--rmst <= 0) - { rmst = 120-(level<<2); fillmonst(makemonst(level)); } - } + while (nomove) { + if (hit3flag) + flushall(); + nomove = 0; + parse(); + } /* get commands and make moves */ + regen(); /* regenerate hp and spells */ + if (c[TIMESTOP] == 0) + if (--rmst <= 0) { + rmst = 120 - (level << 2); + fillmonst(makemonst(level)); + } } - +} + + /* showstr() show character's inventory */ +void showstr() - { - register int i,number; - for (number=3, i=0; i<26; i++) - if (iven[i]) number++; /* count items in inventory */ - t_setup(number); qshowstr(); t_endup(number); - } +{ + int i, number; + for (number = 3, i = 0; i < 26; i++) + if (iven[i]) + number++; /* count items in inventory */ + t_setup(number); + qshowstr(); + t_endup(number); +} +void qshowstr() - { - register int i,j,k,sigsav; - srcount=0; sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - if (c[GOLD]) { lprintf(".) %d gold pieces",(long)c[GOLD]); srcount++; } - for (k=26; k>=0; k--) - if (iven[k]) - { for (i=22; i<84; i++) - for (j=0; j<=k; j++) if (i==iven[j]) show3(j); k=0; } - - lprintf("\nElapsed time is %d. You have %d mobuls left",(long)((gltime+99)/100+1),(long)((TIMELIMIT-gltime)/100)); - more(); nosignal=sigsav; +{ + int i, j, k, sigsav; + srcount = 0; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + if (c[GOLD]) { + lprintf(".) %d gold pieces", (long) c[GOLD]); + srcount++; } + for (k = 26; k >= 0; k--) + if (iven[k]) { + for (i = 22; i < 84; i++) + for (j = 0; j <= k; j++) + if (i == iven[j]) + show3(j); + k = 0; + } + lprintf("\nElapsed time is %d. You have %d mobuls left", (long) ((gltime + 99) / 100 + 1), (long) ((TIMELIMIT - gltime) / 100)); + more(); + nosignal = sigsav; +} /* * subroutine to clear screen depending on # lines to display */ +void t_setup(count) - register int count; - { - if (count<20) /* how do we clear the screen? */ - { - cl_up(79,count); cursor(1,1); - } - else - { - resetscroll(); clear(); - } + int count; +{ + if (count < 20) { /* how do we clear the screen? */ + cl_up(79, count); + cursor(1, 1); + } else { + resetscroll(); + clear(); } +} /* * subroutine to restore normal display screen depending on t_setup() */ +void t_endup(count) - register int count; - { - if (count<18) /* how did we clear the screen? */ - draws(0,MAXX,0,(count>MAXY) ? MAXY : count); - else - { - drawscreen(); setscroll(); - } + int count; +{ + if (count < 18) /* how did we clear the screen? */ + draws(0, MAXX, 0, (count > MAXY) ? MAXY : count); + else { + drawscreen(); + setscroll(); } +} /* function to show the things player is wearing only */ +void showwear() - { - register int i,j,sigsav,count; - sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - srcount=0; - - for (count=2,j=0; j<=26; j++) /* count number of items we will display */ - if (i=iven[j]) - switch(i) - { - case OLEATHER: case OPLATE: case OCHAIN: - case ORING: case OSTUDLEATHER: case OSPLINT: - case OPLATEARMOR: case OSSPLATE: case OSHIELD: - count++; +{ + int i, j, sigsav, count; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + srcount = 0; + + for (count = 2, j = 0; j <= 26; j++) /* count number of items we + * will display */ + if ((i = iven[j]) != 0) + switch (i) { + case OLEATHER: + case OPLATE: + case OCHAIN: + case ORING: + case OSTUDLEATHER: + case OSPLINT: + case OPLATEARMOR: + case OSSPLATE: + case OSHIELD: + count++; }; t_setup(count); - for (i=22; i<84; i++) - for (j=0; j<=26; j++) - if (i==iven[j]) - switch(i) - { - case OLEATHER: case OPLATE: case OCHAIN: - case ORING: case OSTUDLEATHER: case OSPLINT: - case OPLATEARMOR: case OSSPLATE: case OSHIELD: - show3(j); + for (i = 22; i < 84; i++) + for (j = 0; j <= 26; j++) + if (i == iven[j]) + switch (i) { + case OLEATHER: + case OPLATE: + case OCHAIN: + case ORING: + case OSTUDLEATHER: + case OSPLINT: + case OPLATEARMOR: + case OSSPLATE: + case OSHIELD: + show3(j); }; - more(); nosignal=sigsav; t_endup(count); - } + more(); + nosignal = sigsav; + t_endup(count); +} /* - function to show the things player can wield only + function to show the things player can wield only */ +void showwield() - { - register int i,j,sigsav,count; - sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - srcount=0; - - for (count=2,j=0; j<=26; j++) /* count how many items */ - if (i=iven[j]) - switch(i) - { - case ODIAMOND: case ORUBY: case OEMERALD: case OSAPPHIRE: - case OBOOK: case OCHEST: case OLARNEYE: case ONOTHEFT: - case OSPIRITSCARAB: case OCUBEofUNDEAD: - case OPOTION: case OSCROLL: break; - default: count++; +{ + int i, j, sigsav, count; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + srcount = 0; + + for (count = 2, j = 0; j <= 26; j++) /* count how many items */ + if ((i = iven[j]) != 0) + switch (i) { + case ODIAMOND: + case ORUBY: + case OEMERALD: + case OSAPPHIRE: + case OBOOK: + case OCHEST: + case OLARNEYE: + case ONOTHEFT: + case OSPIRITSCARAB: + case OCUBEofUNDEAD: + case OPOTION: + case OSCROLL: + break; + default: + count++; }; t_setup(count); - for (i=22; i<84; i++) - for (j=0; j<=26; j++) - if (i==iven[j]) - switch(i) - { - case ODIAMOND: case ORUBY: case OEMERALD: case OSAPPHIRE: - case OBOOK: case OCHEST: case OLARNEYE: case ONOTHEFT: - case OSPIRITSCARAB: case OCUBEofUNDEAD: - case OPOTION: case OSCROLL: break; - default: show3(j); + for (i = 22; i < 84; i++) + for (j = 0; j <= 26; j++) + if (i == iven[j]) + switch (i) { + case ODIAMOND: + case ORUBY: + case OEMERALD: + case OSAPPHIRE: + case OBOOK: + case OCHEST: + case OLARNEYE: + case ONOTHEFT: + case OSPIRITSCARAB: + case OCUBEofUNDEAD: + case OPOTION: + case OSCROLL: + break; + default: + show3(j); }; - more(); nosignal=sigsav; t_endup(count); - } + more(); + nosignal = sigsav; + t_endup(count); +} /* * function to show the things player can read only */ +void showread() - { - register int i,j,sigsav,count; - sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - srcount=0; - - for (count=2,j=0; j<=26; j++) - switch(iven[j]) - { - case OBOOK: case OSCROLL: count++; - }; +{ + int i, j, sigsav, count; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + srcount = 0; + + for (count = 2, j = 0; j <= 26; j++) + switch (iven[j]) { + case OBOOK: + case OSCROLL: + count++; + }; t_setup(count); - for (i=22; i<84; i++) - for (j=0; j<=26; j++) - if (i==iven[j]) - switch(i) - { - case OBOOK: case OSCROLL: show3(j); + for (i = 22; i < 84; i++) + for (j = 0; j <= 26; j++) + if (i == iven[j]) + switch (i) { + case OBOOK: + case OSCROLL: + show3(j); }; - more(); nosignal=sigsav; t_endup(count); - } + more(); + nosignal = sigsav; + t_endup(count); +} /* * function to show the things player can eat only */ +void showeat() - { - register int i,j,sigsav,count; - sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - srcount=0; - - for (count=2,j=0; j<=26; j++) - switch(iven[j]) - { - case OCOOKIE: count++; - }; +{ + int i, j, sigsav, count; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + srcount = 0; + + for (count = 2, j = 0; j <= 26; j++) + switch (iven[j]) { + case OCOOKIE: + count++; + }; t_setup(count); - for (i=22; i<84; i++) - for (j=0; j<=26; j++) - if (i==iven[j]) - switch(i) - { - case OCOOKIE: show3(j); + for (i = 22; i < 84; i++) + for (j = 0; j <= 26; j++) + if (i == iven[j]) + switch (i) { + case OCOOKIE: + show3(j); }; - more(); nosignal=sigsav; t_endup(count); - } + more(); + nosignal = sigsav; + t_endup(count); +} /* function to show the things player can quaff only */ +void showquaff() - { - register int i,j,sigsav,count; - sigsav=nosignal; nosignal=1; /* don't allow ^c etc */ - srcount=0; - - for (count=2,j=0; j<=26; j++) - switch(iven[j]) - { - case OPOTION: count++; - }; +{ + int i, j, sigsav, count; + sigsav = nosignal; + nosignal = 1; /* don't allow ^c etc */ + srcount = 0; + + for (count = 2, j = 0; j <= 26; j++) + switch (iven[j]) { + case OPOTION: + count++; + }; t_setup(count); - for (i=22; i<84; i++) - for (j=0; j<=26; j++) - if (i==iven[j]) - switch(i) - { - case OPOTION: show3(j); + for (i = 22; i < 84; i++) + for (j = 0; j <= 26; j++) + if (i == iven[j]) + switch (i) { + case OPOTION: + show3(j); }; - more(); nosignal=sigsav; t_endup(count); - } + more(); + nosignal = sigsav; + t_endup(count); +} -show1(idx,str2) - register int idx; - register char *str2[]; - { - lprintf("\n%c) %s",idx+'a',objectname[iven[idx]]); - if (str2!=0 && str2[ivenarg[idx]][0]!=0) lprintf(" of%s",str2[ivenarg[idx]]); - } +void +show1(idx, str2) + int idx; + char *str2[]; +{ + lprintf("\n%c) %s", idx + 'a', objectname[iven[idx]]); + if (str2 != 0 && str2[ivenarg[idx]][0] != 0) + lprintf(" of%s", str2[ivenarg[idx]]); +} +void show3(index) - register int index; - { - switch(iven[index]) - { - case OPOTION: show1(index,potionname); break; - case OSCROLL: show1(index,scrollname); break; - - case OLARNEYE: case OBOOK: case OSPIRITSCARAB: - case ODIAMOND: case ORUBY: case OCUBEofUNDEAD: - case OEMERALD: case OCHEST: case OCOOKIE: - case OSAPPHIRE: case ONOTHEFT: show1(index,(char **)0); break; - - default: lprintf("\n%c) %s",index+'a',objectname[iven[index]]); - if (ivenarg[index]>0) lprintf(" + %d",(long)ivenarg[index]); - else if (ivenarg[index]<0) lprintf(" %d",(long)ivenarg[index]); - break; - } - if (c[WIELD]==index) lprcat(" (weapon in hand)"); - if ((c[WEAR]==index) || (c[SHIELD]==index)) lprcat(" (being worn)"); - if (++srcount>=22) { srcount=0; more(); clear(); } + int index; +{ + switch (iven[index]) { + case OPOTION: + show1(index, potionname); + break; + case OSCROLL: + show1(index, scrollname); + break; + + case OLARNEYE: + case OBOOK: + case OSPIRITSCARAB: + case ODIAMOND: + case ORUBY: + case OCUBEofUNDEAD: + case OEMERALD: + case OCHEST: + case OCOOKIE: + case OSAPPHIRE: + case ONOTHEFT: + show1(index, (char **) 0); + break; + + default: + lprintf("\n%c) %s", index + 'a', objectname[iven[index]]); + if (ivenarg[index] > 0) + lprintf(" + %d", (long) ivenarg[index]); + else if (ivenarg[index] < 0) + lprintf(" %d", (long) ivenarg[index]); + break; } + if (c[WIELD] == index) + lprcat(" (weapon in hand)"); + if ((c[WEAR] == index) || (c[SHIELD] == index)) + lprcat(" (being worn)"); + if (++srcount >= 22) { + srcount = 0; + more(); + clear(); + } +} /* subroutine to randomly create monsters if needed */ +void randmonst() - { - if (c[TIMESTOP]) return; /* don't make monsters if time is stopped */ - if (--rmst <= 0) - { - rmst = 120 - (level<<2); fillmonst(makemonst(level)); - } +{ + if (c[TIMESTOP]) + return; /* don't make monsters if time is stopped */ + if (--rmst <= 0) { + rmst = 120 - (level << 2); + fillmonst(makemonst(level)); } +} + + - /* parse() get and execute a command */ +void parse() - { - register int i,j,k,flag; - while (1) - { +{ + int i, j, k, flag; + while (1) { k = yylex(); - switch(k) /* get the token from the input and switch on it */ - { - case 'h': moveplayer(4); return; /* west */ - case 'H': run(4); return; /* west */ - case 'l': moveplayer(2); return; /* east */ - case 'L': run(2); return; /* east */ - case 'j': moveplayer(1); return; /* south */ - case 'J': run(1); return; /* south */ - case 'k': moveplayer(3); return; /* north */ - case 'K': run(3); return; /* north */ - case 'u': moveplayer(5); return; /* northeast */ - case 'U': run(5); return; /* northeast */ - case 'y': moveplayer(6); return; /* northwest */ - case 'Y': run(6); return; /* northwest */ - case 'n': moveplayer(7); return; /* southeast */ - case 'N': run(7); return; /* southeast */ - case 'b': moveplayer(8); return; /* southwest */ - case 'B': run(8); return; /* southwest */ - - case '.': if (yrepcount) viewflag=1; return; /* stay here */ - - case 'w': yrepcount=0; wield(); return; /* wield a weapon */ - - case 'W': yrepcount=0; wear(); return; /* wear armor */ - - case 'r': yrepcount=0; - if (c[BLINDCOUNT]) { cursors(); lprcat("\nYou can't read anything when you're blind!"); } else - if (c[TIMESTOP]==0) readscr(); return; /* to read a scroll */ - - case 'q': yrepcount=0; if (c[TIMESTOP]==0) quaff(); return; /* quaff a potion */ - - case 'd': yrepcount=0; if (c[TIMESTOP]==0) dropobj(); return; /* to drop an object */ - - case 'c': yrepcount=0; cast(); return; /* cast a spell */ - - case 'i': yrepcount=0; nomove=1; showstr(); return; /* status */ - - case 'e': yrepcount=0; - if (c[TIMESTOP]==0) eatcookie(); return; /* to eat a fortune cookie */ - - case 'D': yrepcount=0; seemagic(0); nomove=1; return; /* list spells and scrolls */ - - case '?': yrepcount=0; help(); nomove=1; return; /* give the help screen*/ - - case 'S': clear(); lprcat("Saving . . ."); lflush(); - savegame(savefilename); wizard=1; died(-257); /* save the game - doesn't return */ - - case 'Z': yrepcount=0; if (c[LEVEL]>9) { oteleport(1); return; } - cursors(); lprcat("\nAs yet, you don't have enough experience to use teleportation"); - return; /* teleport yourself */ - - case '^': /* identify traps */ flag=yrepcount=0; cursors(); - lprc('\n'); for (j=playery-1; j<playery+2; j++) - { - if (j < 0) j=0; if (j >= MAXY) break; - for (i=playerx-1; i<playerx+2; i++) - { - if (i < 0) i=0; if (i >= MAXX) break; - switch(item[i][j]) - { - case OTRAPDOOR: case ODARTRAP: - case OTRAPARROW: case OTELEPORTER: - lprcat("\nIts "); lprcat(objectname[item[i][j]]); flag++; - }; - } - } - if (flag==0) lprcat("\nNo traps are visible"); - return; + switch (k) { /* get the token from the input and switch on + * it */ + case 'h': + moveplayer(4); + return; /* west */ + case 'H': + run(4); + return; /* west */ + case 'l': + moveplayer(2); + return; /* east */ + case 'L': + run(2); + return; /* east */ + case 'j': + moveplayer(1); + return; /* south */ + case 'J': + run(1); + return; /* south */ + case 'k': + moveplayer(3); + return; /* north */ + case 'K': + run(3); + return; /* north */ + case 'u': + moveplayer(5); + return; /* northeast */ + case 'U': + run(5); + return; /* northeast */ + case 'y': + moveplayer(6); + return; /* northwest */ + case 'Y': + run(6); + return; /* northwest */ + case 'n': + moveplayer(7); + return; /* southeast */ + case 'N': + run(7); + return; /* southeast */ + case 'b': + moveplayer(8); + return; /* southwest */ + case 'B': + run(8); + return; /* southwest */ + + case '.': + if (yrepcount) + viewflag = 1; + return; /* stay here */ + + case 'w': + yrepcount = 0; + wield(); + return; /* wield a weapon */ + + case 'W': + yrepcount = 0; + wear(); + return; /* wear armor */ + + case 'r': + yrepcount = 0; + if (c[BLINDCOUNT]) { + cursors(); + lprcat("\nYou can't read anything when you're blind!"); + } else if (c[TIMESTOP] == 0) + readscr(); + return; /* to read a scroll */ + + case 'q': + yrepcount = 0; + if (c[TIMESTOP] == 0) + quaff(); + return; /* quaff a potion */ + + case 'd': + yrepcount = 0; + if (c[TIMESTOP] == 0) + dropobj(); + return; /* to drop an object */ + + case 'c': + yrepcount = 0; + cast(); + return; /* cast a spell */ + + case 'i': + yrepcount = 0; + nomove = 1; + showstr(); + return; /* status */ + + case 'e': + yrepcount = 0; + if (c[TIMESTOP] == 0) + eatcookie(); + return; /* to eat a fortune cookie */ + + case 'D': + yrepcount = 0; + seemagic(0); + nomove = 1; + return; /* list spells and scrolls */ + + case '?': + yrepcount = 0; + help(); + nomove = 1; + return; /* give the help screen */ + + case 'S': + clear(); + lprcat("Saving . . ."); + lflush(); + savegame(savefilename); + wizard = 1; + died(-257); /* save the game - doesn't return */ + + case 'Z': + yrepcount = 0; + if (c[LEVEL] > 9) { + oteleport(1); + return; + } + cursors(); + lprcat("\nAs yet, you don't have enough experience to use teleportation"); + return; /* teleport yourself */ + + case '^': /* identify traps */ + flag = yrepcount = 0; + cursors(); + lprc('\n'); + for (j = playery - 1; j < playery + 2; j++) { + if (j < 0) + j = 0; + if (j >= MAXY) + break; + for (i = playerx - 1; i < playerx + 2; i++) { + if (i < 0) + i = 0; + if (i >= MAXX) + break; + switch (item[i][j]) { + case OTRAPDOOR: + case ODARTRAP: + case OTRAPARROW: + case OTELEPORTER: + lprcat("\nIts "); + lprcat(objectname[item[i][j]]); + flag++; + }; + } + } + if (flag == 0) + lprcat("\nNo traps are visible"); + return; #if WIZID - case '_': /* this is the fudge player password for wizard mode*/ - yrepcount=0; cursors(); nomove=1; - if (userid!=wisid) - { - lprcat("Sorry, you are not empowered to be a wizard.\n"); - scbr(); /* system("stty -echo cbreak"); */ - lflush(); return; - } - if (getpassword()==0) - { - scbr(); /* system("stty -echo cbreak"); */ return; - } - wizard=1; scbr(); /* system("stty -echo cbreak"); */ - for (i=0; i<6; i++) c[i]=70; iven[0]=iven[1]=0; - take(OPROTRING,50); take(OLANCE,25); c[WIELD]=1; - c[LANCEDEATH]=1; c[WEAR] = c[SHIELD] = -1; - raiseexperience(6000000L); c[AWARENESS] += 25000; - { - register int i,j; - for (i=0; i<MAXY; i++) - for (j=0; j<MAXX; j++) know[j][i]=1; - for (i=0; i<SPNUM; i++) spelknow[i]=1; - for (i=0; i<MAXSCROLL; i++) scrollname[i]=scrollhide[i]; - for (i=0; i<MAXPOTION; i++) potionname[i]=potionhide[i]; - } - for (i=0; i<MAXSCROLL; i++) - if (strlen(scrollname[i])>2) /* no null items */ - { item[i][0]=OSCROLL; iarg[i][0]=i; } - for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--) - if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */ - { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; } - for (i=1; i<MAXY; i++) - { item[0][i]=i; iarg[0][i]=0; } - for (i=MAXY; i<MAXY+MAXX; i++) - { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; } - for (i=MAXX+MAXY; i<MAXX+MAXY+MAXY; i++) - { item[MAXX-1][i-MAXX-MAXY]=i; iarg[MAXX-1][i-MAXX-MAXY]=0; } - c[GOLD]+=25000; drawscreen(); return; + case '_': /* this is the fudge player password for + * wizard mode */ + yrepcount = 0; + cursors(); + nomove = 1; + if (userid != wisid) { + lprcat("Sorry, you are not empowered to be a wizard.\n"); + scbr(); /* system("stty -echo cbreak"); */ + lflush(); + return; + } + if (getpassword() == 0) { + scbr(); /* system("stty -echo cbreak"); */ + return; + } + wizard = 1; + scbr(); /* system("stty -echo cbreak"); */ + for (i = 0; i < 6; i++) + c[i] = 70; + iven[0] = iven[1] = 0; + take(OPROTRING, 50); + take(OLANCE, 25); + c[WIELD] = 1; + c[LANCEDEATH] = 1; + c[WEAR] = c[SHIELD] = -1; + raiseexperience(6000000L); + c[AWARENESS] += 25000; + { + int i, j; + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + know[j][i] = 1; + for (i = 0; i < SPNUM; i++) + spelknow[i] = 1; + for (i = 0; i < MAXSCROLL; i++) + scrollname[i] = scrollhide[i]; + for (i = 0; i < MAXPOTION; i++) + potionname[i] = potionhide[i]; + } + for (i = 0; i < MAXSCROLL; i++) + if (strlen(scrollname[i]) > 2) { /* no null items */ + item[i][0] = OSCROLL; + iarg[i][0] = i; + } + for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--) + if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) { /* no null items */ + item[i][0] = OPOTION; + iarg[i][0] = i - MAXX + MAXPOTION; + } + for (i = 1; i < MAXY; i++) { + item[0][i] = i; + iarg[0][i] = 0; + } + for (i = MAXY; i < MAXY + MAXX; i++) { + item[i - MAXY][MAXY - 1] = i; + iarg[i - MAXY][MAXY - 1] = 0; + } + for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) { + item[MAXX - 1][i - MAXX - MAXY] = i; + iarg[MAXX - 1][i - MAXX - MAXY] = 0; + } + c[GOLD] += 25000; + drawscreen(); + return; #endif - case 'T': yrepcount=0; cursors(); if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else - if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); } - else lprcat("\nYou aren't wearing anything"); - return; + case 'T': + yrepcount = 0; + cursors(); + if (c[SHIELD] != -1) { + c[SHIELD] = -1; + lprcat("\nYour shield is off"); + bottomline(); + } else if (c[WEAR] != -1) { + c[WEAR] = -1; + lprcat("\nYour armor is off"); + bottomline(); + } else + lprcat("\nYou aren't wearing anything"); + return; - case 'g': cursors(); - lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight()); - case ' ': yrepcount=0; nomove=1; return; + case 'g': + cursors(); + lprintf("\nThe stuff you are carrying presently weighs %d pounds", (long) packweight()); + case ' ': + yrepcount = 0; + nomove = 1; + return; - case 'v': yrepcount=0; cursors(); - lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)c[HARDGAME]); - if (wizard) lprcat(" Wizard"); nomove=1; - if (cheat) lprcat(" Cheater"); - lprcat(copyright); - return; + case 'v': + yrepcount = 0; + cursors(); + lprintf("\nCaverns of Larn, Version %d.%d, Diff=%d", (long) VERSION, (long) SUBVERSION, (long) c[HARDGAME]); + if (wizard) + lprcat(" Wizard"); + nomove = 1; + if (cheat) + lprcat(" Cheater"); + lprcat(copyright); + return; - case 'Q': yrepcount=0; quit(); nomove=1; return; /* quit */ + case 'Q': + yrepcount = 0; + quit(); + nomove = 1; + return; /* quit */ - case 'L'-64: yrepcount=0; drawscreen(); nomove=1; return; /* look */ + case 'L' - 64: + yrepcount = 0; + drawscreen(); + nomove = 1; + return; /* look */ #if WIZID #ifdef EXTRA - case 'A': yrepcount=0; nomove=1; if (wizard) { diag(); return; } /* create diagnostic file */ - return; + case 'A': + yrepcount = 0; + nomove = 1; + if (wizard) { + diag(); + return; + } /* create diagnostic file */ + return; #endif #endif - case 'P': cursors(); - if (outstanding_taxes>0) - lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes); - else - lprcat("\nYou do not owe any taxes."); - return; - }; - } + case 'P': + cursors(); + if (outstanding_taxes > 0) + lprintf("\nYou presently owe %d gp in taxes.", (long) outstanding_taxes); + else + lprcat("\nYou do not owe any taxes."); + return; + }; } +} +void parse2() - { - if (c[HASTEMONST]) movemonst(); movemonst(); /* move the monsters */ - randmonst(); regen(); - } +{ + if (c[HASTEMONST]) + movemonst(); + movemonst(); /* move the monsters */ + randmonst(); + regen(); +} +void run(dir) - int dir; - { - register int i; - i=1; while (i) - { - i=moveplayer(dir); - if (i>0) { if (c[HASTEMONST]) movemonst(); movemonst(); randmonst(); regen(); } - if (hitflag) i=0; - if (i!=0) showcell(playerx,playery); + int dir; +{ + int i; + i = 1; + while (i) { + i = moveplayer(dir); + if (i > 0) { + if (c[HASTEMONST]) + movemonst(); + movemonst(); + randmonst(); + regen(); } + if (hitflag) + i = 0; + if (i != 0) + showcell(playerx, playery); } +} /* function to wield a weapon */ -wield() - { - register int i; - while (1) - { - if ((i = whatitem("wield"))=='\33') return; - if (i != '.') - { - if (i=='*') showwield(); - else if (iven[i-'a']==0) { ydhi(i); return; } - else if (iven[i-'a']==OPOTION) { ycwi(i); return; } - else if (iven[i-'a']==OSCROLL) { ycwi(i); return; } - else if ((c[SHIELD]!= -1) && (iven[i-'a']==O2SWORD)) { lprcat("\nBut one arm is busy with your shield!"); return; } - else { c[WIELD]=i-'a'; if (iven[i-'a'] == OLANCE) c[LANCEDEATH]=1; else c[LANCEDEATH]=0; bottomline(); return; } +void +wield() +{ + int i; + while (1) { + if ((i = whatitem("wield")) == '\33') + return; + if (i != '.') { + if (i == '*') + showwield(); + else if (iven[i - 'a'] == 0) { + ydhi(i); + return; + } else if (iven[i - 'a'] == OPOTION) { + ycwi(i); + return; + } else if (iven[i - 'a'] == OSCROLL) { + ycwi(i); + return; + } else if ((c[SHIELD] != -1) && (iven[i - 'a'] == O2SWORD)) { + lprcat("\nBut one arm is busy with your shield!"); + return; + } else { + c[WIELD] = i - 'a'; + if (iven[i - 'a'] == OLANCE) + c[LANCEDEATH] = 1; + else + c[LANCEDEATH] = 0; + bottomline(); + return; } } } +} /* common routine to say you don't have an item */ +void ydhi(x) - int x; - { cursors(); lprintf("\nYou don't have item %c!",x); } + int x; +{ + cursors(); + lprintf("\nYou don't have item %c!", x); +} +void ycwi(x) - int x; - { cursors(); lprintf("\nYou can't wield item %c!",x); } + int x; +{ + cursors(); + lprintf("\nYou can't wield item %c!", x); +} /* function to wear armor */ +void wear() - { - register int i; - while (1) - { - if ((i = whatitem("wear"))=='\33') return; - if (i != '.') - { - if (i=='*') showwear(); else - switch(iven[i-'a']) - { - case 0: ydhi(i); return; - case OLEATHER: case OCHAIN: case OPLATE: case OSTUDLEATHER: - case ORING: case OSPLINT: case OPLATEARMOR: case OSSPLATE: - if (c[WEAR] != -1) { lprcat("\nYou're already wearing some armor"); return; } - c[WEAR]=i-'a'; bottomline(); return; - case OSHIELD: if (c[SHIELD] != -1) { lprcat("\nYou are already wearing a shield"); return; } - if (iven[c[WIELD]]==O2SWORD) { lprcat("\nYour hands are busy with the two handed sword!"); return; } - c[SHIELD] = i-'a'; bottomline(); return; - default: lprcat("\nYou can't wear that!"); +{ + int i; + while (1) { + if ((i = whatitem("wear")) == '\33') + return; + if (i != '.') { + if (i == '*') + showwear(); + else + switch (iven[i - 'a']) { + case 0: + ydhi(i); + return; + case OLEATHER: + case OCHAIN: + case OPLATE: + case OSTUDLEATHER: + case ORING: + case OSPLINT: + case OPLATEARMOR: + case OSSPLATE: + if (c[WEAR] != -1) { + lprcat("\nYou're already wearing some armor"); + return; + } + c[WEAR] = i - 'a'; + bottomline(); + return; + case OSHIELD: + if (c[SHIELD] != -1) { + lprcat("\nYou are already wearing a shield"); + return; + } + if (iven[c[WIELD]] == O2SWORD) { + lprcat("\nYour hands are busy with the two handed sword!"); + return; + } + c[SHIELD] = i - 'a'; + bottomline(); + return; + default: + lprcat("\nYou can't wear that!"); }; - } } } +} /* function to drop an object */ +void dropobj() - { - register int i; - register char *p; - long amt; +{ + int i; + char *p; + long amt; p = &item[playerx][playery]; - while (1) - { - if ((i = whatitem("drop"))=='\33') return; - if (i=='*') showstr(); else - { - if (i=='.') /* drop some gold */ - { - if (*p) { lprcat("\nThere's something here already!"); return; } + while (1) { + if ((i = whatitem("drop")) == '\33') + return; + if (i == '*') + showstr(); + else { + if (i == '.') { /* drop some gold */ + if (*p) { + lprcat("\nThere's something here already!"); + return; + } lprcat("\n\n"); - cl_dn(1,23); + cl_dn(1, 23); lprcat("How much gold do you drop? "); - if ((amt=readnum((long)c[GOLD])) == 0) return; - if (amt>c[GOLD]) - { lprcat("\nYou don't have that much!"); return; } - if (amt<=32767) - { *p=OGOLDPILE; i=amt; } - else if (amt<=327670L) - { *p=ODGOLD; i=amt/10; amt = 10*i; } - else if (amt<=3276700L) - { *p=OMAXGOLD; i=amt/100; amt = 100*i; } - else if (amt<=32767000L) - { *p=OKGOLD; i=amt/1000; amt = 1000*i; } - else - { *p=OKGOLD; i=32767; amt = 32767000L; } - c[GOLD] -= amt; - lprintf("You drop %d gold pieces",(long)amt); - iarg[playerx][playery]=i; bottomgold(); - know[playerx][playery]=0; dropflag=1; return; + if ((amt = readnum((long) c[GOLD])) == 0) + return; + if (amt > c[GOLD]) { + lprcat("\nYou don't have that much!"); + return; } - drop_object(i-'a'); - return; + if (amt <= 32767) { + *p = OGOLDPILE; + i = amt; + } else if (amt <= 327670L) { + *p = ODGOLD; + i = amt / 10; + amt = 10 * i; + } else if (amt <= 3276700L) { + *p = OMAXGOLD; + i = amt / 100; + amt = 100 * i; + } else if (amt <= 32767000L) { + *p = OKGOLD; + i = amt / 1000; + amt = 1000 * i; + } else { + *p = OKGOLD; + i = 32767; + amt = 32767000L; + } + c[GOLD] -= amt; + lprintf("You drop %d gold pieces", (long) amt); + iarg[playerx][playery] = i; + bottomgold(); + know[playerx][playery] = 0; + dropflag = 1; + return; } + drop_object(i - 'a'); + return; } } +} /* * readscr() Subroutine to read a scroll one is carrying */ +void readscr() - { - register int i; - while (1) - { - if ((i = whatitem("read"))=='\33') return; - if (i != '.') - { - if (i=='*') showread(); else - { - if (iven[i-'a']==OSCROLL) { read_scroll(ivenarg[i-'a']); iven[i-'a']=0; return; } - if (iven[i-'a']==OBOOK) { readbook(ivenarg[i-'a']); iven[i-'a']=0; return; } - if (iven[i-'a']==0) { ydhi(i); return; } - lprcat("\nThere's nothing on it to read"); return; +{ + int i; + while (1) { + if ((i = whatitem("read")) == '\33') + return; + if (i != '.') { + if (i == '*') + showread(); + else { + if (iven[i - 'a'] == OSCROLL) { + read_scroll(ivenarg[i - 'a']); + iven[i - 'a'] = 0; + return; + } + if (iven[i - 'a'] == OBOOK) { + readbook(ivenarg[i - 'a']); + iven[i - 'a'] = 0; + return; + } + if (iven[i - 'a'] == 0) { + ydhi(i); + return; } + lprcat("\nThere's nothing on it to read"); + return; } } } +} /* * subroutine to eat a cookie one is carrying */ +void eatcookie() { -register int i; -char *p; -while (1) - { - if ((i = whatitem("eat"))=='\33') return; - if (i != '.') - if (i=='*') showeat(); else - { - if (iven[i-'a']==OCOOKIE) - { - lprcat("\nThe cookie was delicious."); - iven[i-'a']=0; - if (!c[BLINDCOUNT]) - { - if (p=fortune()) - { - lprcat(" Inside you find a scrap of paper that says:\n"); - lprcat(p); + int i; + char *p; + while (1) { + if ((i = whatitem("eat")) == '\33') + return; + if (i != '.') + if (i == '*') + showeat(); + else { + if (iven[i - 'a'] == OCOOKIE) { + lprcat("\nThe cookie was delicious."); + iven[i - 'a'] = 0; + if (!c[BLINDCOUNT]) { + if ((p = fortune()) != NULL) { + lprcat(" Inside you find a scrap of paper that says:\n"); + lprcat(p); } } - return; + return; + } + if (iven[i - 'a'] == 0) { + ydhi(i); + return; } - if (iven[i-'a']==0) { ydhi(i); return; } - lprcat("\nYou can't eat that!"); return; + lprcat("\nYou can't eat that!"); + return; } } } @@ -821,67 +1229,88 @@ while (1) /* * subroutine to quaff a potion one is carrying */ +void quaff() - { - register int i; - while (1) - { - if ((i = whatitem("quaff"))=='\33') return; - if (i != '.') - { - if (i=='*') showquaff(); else - { - if (iven[i-'a']==OPOTION) { quaffpotion(ivenarg[i-'a']); iven[i-'a']=0; return; } - if (iven[i-'a']==0) { ydhi(i); return; } - lprcat("\nYou wouldn't want to quaff that, would you? "); return; +{ + int i; + while (1) { + if ((i = whatitem("quaff")) == '\33') + return; + if (i != '.') { + if (i == '*') + showquaff(); + else { + if (iven[i - 'a'] == OPOTION) { + quaffpotion(ivenarg[i - 'a']); + iven[i - 'a'] = 0; + return; + } + if (iven[i - 'a'] == 0) { + ydhi(i); + return; } + lprcat("\nYou wouldn't want to quaff that, would you? "); + return; } } } +} /* function to ask what player wants to do */ +int whatitem(str) - char *str; - { - int i; - cursors(); lprintf("\nWhat do you want to %s [* for all] ? ",str); - i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar(); - if (i=='\33') lprcat(" aborted"); - return(i); - } + char *str; +{ + int i; + cursors(); + lprintf("\nWhat do you want to %s [* for all] ? ", str); + i = 0; + while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.')) + i = getchar(); + if (i == '\33') + lprcat(" aborted"); + return (i); +} /* subroutine to get a number from the player and allow * to mean return amt, else return the number entered */ -unsigned long readnum(mx) - long mx; - { - register int i; - register unsigned long amt=0; +unsigned long +readnum(mx) + long mx; +{ + int i; + unsigned long amt = 0; sncbr(); - if ((i=getchar()) == '*') amt = mx; /* allow him to say * for all gold */ + if ((i = getchar()) == '*') + amt = mx; /* allow him to say * for all gold */ else - while (i != '\n') - { - if (i=='\033') { scbr(); lprcat(" aborted"); return(0); } - if ((i <= '9') && (i >= '0') && (amt<99999999)) - amt = amt*10+i-'0'; - i = getchar(); + while (i != '\n') { + if (i == '\033') { + scbr(); + lprcat(" aborted"); + return (0); } - scbr(); return(amt); - } + if ((i <= '9') && (i >= '0') && (amt < 99999999)) + amt = amt * 10 + i - '0'; + i = getchar(); + } + scbr(); + return (amt); +} #ifdef HIDEBYLINK /* * routine to zero every byte in a string */ +void szero(str) - register char *str; - { + char *str; +{ while (*str) *str++ = 0; - } -#endif HIDEBYLINK +} +#endif /* HIDEBYLINK */ diff --git a/larn/monster.c b/larn/monster.c index 68d60c23..d12601b0 100644 --- a/larn/monster.c +++ b/larn/monster.c @@ -1,1392 +1,1906 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: monster.c,v 1.4 1995/04/24 12:24:05 cgd Exp $"; -#endif /* not lint */ +/* $NetBSD: monster.c,v 1.5 1997/10/18 20:03:29 christos Exp $ */ /* - * monster.c Larn is copyrighted 1986 by Noah Morgan. + * monster.c Larn is copyrighted 1986 by Noah Morgan. * - * This file contains the following functions: - * ---------------------------------------------------------------------------- + * This file contains the following functions: + * ---------------------------------------------------------------------------- * - * createmonster(monstno) Function to create a monster next to the player - * int monstno; + * createmonster(monstno) Function to create a monster next to the player + * int monstno; * - * int cgood(x,y,itm,monst) Function to check location for emptiness - * int x,y,itm,monst; + * int cgood(x,y,itm,monst)Function to check location for emptiness + * int x,y,itm,monst; * - * createitem(it,arg) Routine to place an item next to the player - * int it,arg; + * createitem(it,arg) Routine to place an item next to the player + * int it,arg; * - * cast() Subroutine called by parse to cast a spell for the user + * cast() Subroutine called by parse to cast a spell for the user * - * speldamage(x) Function to perform spell functions cast by the player - * int x; + * speldamage(x) Function to perform spell functions cast by the player + * int x; * - * loseint() Routine to decrement your int (intelligence) if > 3 + * loseint() Routine to decrement your int (intelligence) if > 3 * - * isconfuse() Routine to check to see if player is confused + * isconfuse() Routine to check to see if player is confused * - * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster - * int x,monst; + * nospell(x,monst)Routine to return 1 if a spell doesn't affect a monster + * int x,monst; * - * fullhit(xx) Function to return full damage against a monst (aka web) - * int xx; + * fullhit(xx) Function to return full damage against a monst (aka web) + * int xx; * - * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir - * int spnum,dam,arg; - * char *str; + * direct(spnum,dam,str,arg)Routine to direct spell damage 1 square in 1 dir + * int spnum,dam,arg; + * char *str; * - * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks - * int spnum,dam,delay; - * char *str,cshow; + * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks + * int spnum,dam,delay; + * char *str,cshow; * - * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt - * int x,y; + * ifblind(x,y)Routine to put "monster" or the monster name into lastmosnt + * int x,y; * - * tdirect(spnum) Routine to teleport away a monster - * int spnum; + * tdirect(spnum) Routine to teleport away a monster + * int spnum; * - * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player - * int sp,dam; - * char *str; + * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player + * int sp,dam; + * char *str; * - * dirsub(x,y) Routine to ask for direction, then modify x,y for it - * int *x,*y; + * dirsub(x,y) Routine to ask for direction, then modify x,y for it + * int *x,*y; * - * vxy(x,y) Routine to verify/fix (*x,*y) for being within bounds - * int *x,*y; + * vxy(x,y) Routine to verify/fix (*x,*y) for being within bounds + * int *x,*y; * - * dirpoly(spnum) Routine to ask for a direction and polymorph a monst - * int spnum; + * dirpoly(spnum) Routine to ask for a direction and polymorph a monst + * int spnum; * - * hitmonster(x,y) Function to hit a monster at the designated coordinates - * int x,y; + * hitmonster(x,y) Function to hit a monster at the designated coordinates + * int x,y; * - * hitm(x,y,amt) Function to just hit a monster at a given coordinates - * int x,y,amt; + * hitm(x,y,amt) Function to just hit a monster at a given coordinates + * int x,y,amt; * - * hitplayer(x,y) Function for the monster to hit the player from (x,y) - * int x,y; + * hitplayer(x,y) Function for the monster to hit the player from (x,y) + * int x,y; * - * dropsomething(monst) Function to create an object when a monster dies - * int monst; + * dropsomething(monst) Function to create an object when a monster dies + * int monst; * - * dropgold(amount) Function to drop some gold around player - * int amount; + * dropgold(amount) Function to drop some gold around player + * int amount; * - * something(level) Function to create a random item around player - * int level; + * something(level) Function to create a random item around player + * int level; * - * newobject(lev,i) Routine to return a randomly selected new object - * int lev,*i; + * newobject(lev,i) Routine to return a randomly selected new object + * int lev,*i; * - * spattack(atckno,xx,yy) Function to process special attacks from monsters - * int atckno,xx,yy; + * spattack(atckno,xx,yy) Function to process special attacks from monsters + * int atckno,xx,yy; * - * checkloss(x) Routine to subtract hp from user and flag bottomline display - * int x; + * checkloss(x) Routine to subtract hp from user and flag bottomline display + * int x; * - * annihilate() Routine to annihilate monsters around player, playerx,playery + * annihilate() Routine to annihilate monsters around player, playerx,playery * - * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation - * int x,y,dir,lifetime; + * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation + * int x,y,dir,lifetime; * - * rmsphere(x,y) Function to delete a sphere of annihilation from list - * int x,y; + * rmsphere(x,y) Function to delete a sphere of annihilation from list + * int x,y; * - * sphboom(x,y) Function to perform the effects of a sphere detonation - * int x,y; + * sphboom(x,y) Function to perform the effects of a sphere detonation + * int x,y; * - * genmonst() Function to ask for monster and genocide from game + * genmonst() Function to ask for monster and genocide from game * */ -#include "header.h" +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: monster.c,v 1.5 1997/10/18 20:03:29 christos Exp $"); +#endif /* not lint */ + #include <string.h> +#include <stdlib.h> +#include "header.h" +#include "extern.h" -struct isave /* used for altar reality */ - { - char type; /* 0=item, 1=monster */ - char id; /* item number or monster number */ - short arg; /* the type of item or hitpoints of monster */ - }; +struct isave { /* used for altar reality */ + char type; /* 0=item, 1=monster */ + char id; /* item number or monster number */ + short arg; /* the type of item or hitpoints of monster */ +}; +static int dirsub __P((int *, int *)); /* - * createmonster(monstno) Function to create a monster next to the player - * int monstno; + * createmonster(monstno) Function to create a monster next to the player + * int monstno; * - * Enter with the monster number (1 to MAXMONST+8) - * Returns no value. + * Enter with the monster number (1 to MAXMONST+8) + * Returns no value. */ +void createmonster(mon) - int mon; - { - register int x,y,k,i; - if (mon<1 || mon>MAXMONST+8) /* check for monster number out of bounds */ - { - beep(); lprintf("\ncan't createmonst(%d)\n",(long)mon); nap(3000); return; - } - while (monster[mon].genocided && mon<MAXMONST) mon++; /* genocided? */ - for (k=rnd(8), i= -8; i<0; i++,k++) /* choose direction, then try all */ - { - if (k>8) k=1; /* wraparound the diroff arrays */ - x = playerx + diroffx[k]; y = playery + diroffy[k]; - if (cgood(x,y,0,1)) /* if we can create here */ - { + int mon; +{ + int x, y, k, i; + if (mon < 1 || mon > MAXMONST + 8) { /* check for monster number + * out of bounds */ + beep(); + lprintf("\ncan't createmonst(%d)\n", (long) mon); + nap(3000); + return; + } + while (monster[mon].genocided && mon < MAXMONST) + mon++; /* genocided? */ + for (k = rnd(8), i = -8; i < 0; i++, k++) { /* choose direction, + * then try all */ + if (k > 8) + k = 1; /* wraparound the diroff arrays */ + x = playerx + diroffx[k]; + y = playery + diroffy[k]; + if (cgood(x, y, 0, 1)) { /* if we can create here */ mitem[x][y] = mon; hitp[x][y] = monster[mon].hitpoints; - stealth[x][y]=know[x][y]=0; - switch(mon) - { - case ROTHE: case POLTERGEIST: case VAMPIRE: stealth[x][y]=1; - }; + stealth[x][y] = know[x][y] = 0; + switch (mon) { + case ROTHE: + case POLTERGEIST: + case VAMPIRE: + stealth[x][y] = 1; + }; return; - } } } +} /* - * int cgood(x,y,itm,monst) Function to check location for emptiness - * int x,y,itm,monst; - * - * Routine to return TRUE if a location does not have itm or monst there - * returns FALSE (0) otherwise - * Enter with itm or monst TRUE or FALSE if checking it - * Example: if itm==TRUE check for no item at this location - * if monst==TRUE check for no monster at this location - * This routine will return FALSE if at a wall or the dungeon exit on level 1 + * int cgood(x,y,itm,monst) Function to check location for emptiness + * int x,y,itm,monst; + * + * Routine to return TRUE if a location does not have itm or monst there + * returns FALSE (0) otherwise + * Enter with itm or monst TRUE or FALSE if checking it + * Example: if itm==TRUE check for no item at this location + * if monst==TRUE check for no monster at this location + * This routine will return FALSE if at a wall or the dungeon exit on level 1 */ -int cgood(x,y,itm,monst) - register int x,y; - int itm,monst; - { - if ((y>=0) && (y<=MAXY-1) && (x>=0) && (x<=MAXX-1)) /* within bounds? */ - if (item[x][y]!=OWALL) /* can't make anything on walls */ - if (itm==0 || (item[x][y]==0)) /* is it free of items? */ - if (monst==0 || (mitem[x][y]==0)) /* is it free of monsters? */ - if ((level!=1) || (x!=33) || (y!=MAXY-1)) /* not exit to level 1 */ - return(1); - return(0); - } +int +cgood(x, y, itm, monst) + int x, y; + int itm, monst; +{ + if ((y >= 0) && (y <= MAXY - 1) && (x >= 0) && (x <= MAXX - 1)) + /* within bounds? */ + if (item[x][y] != OWALL) /* can't make anything on walls */ + /* is it free of items? */ + if (itm == 0 || (item[x][y] == 0)) + /* is it free of monsters? */ + if (monst == 0 || (mitem[x][y] == 0)) + if ((level != 1) || (x != 33) || + (y != MAXY - 1)) + /* not exit to level 1 */ + return (1); + return (0); +} /* - * createitem(it,arg) Routine to place an item next to the player - * int it,arg; + * createitem(it,arg) Routine to place an item next to the player + * int it,arg; * - * Enter with the item number and its argument (iven[], ivenarg[]) - * Returns no value, thus we don't know about createitem() failures. + * Enter with the item number and its argument (iven[], ivenarg[]) + * Returns no value, thus we don't know about createitem() failures. */ -createitem(it,arg) - int it,arg; - { - register int x,y,k,i; - if (it >= MAXOBJ) return; /* no such object */ - for (k=rnd(8), i= -8; i<0; i++,k++) /* choose direction, then try all */ - { - if (k>8) k=1; /* wraparound the diroff arrays */ - x = playerx + diroffx[k]; y = playery + diroffy[k]; - if (cgood(x,y,1,0)) /* if we can create here */ - { - item[x][y] = it; know[x][y]=0; iarg[x][y]=arg; return; - } +void +createitem(it, arg) + int it, arg; +{ + int x, y, k, i; + if (it >= MAXOBJ) + return; /* no such object */ + for (k = rnd(8), i = -8; i < 0; i++, k++) { /* choose direction, + * then try all */ + if (k > 8) + k = 1; /* wraparound the diroff arrays */ + x = playerx + diroffx[k]; + y = playery + diroffy[k]; + if (cgood(x, y, 1, 0)) { /* if we can create here */ + item[x][y] = it; + know[x][y] = 0; + iarg[x][y] = arg; + return; } } +} /* - * cast() Subroutine called by parse to cast a spell for the user + * cast() Subroutine called by parse to cast a spell for the user * - * No arguments and no return value. + * No arguments and no return value. */ -static char eys[] = "\nEnter your spell: "; +static char eys[] = "\nEnter your spell: "; +void cast() - { - register int i,j,a,b,d; +{ + int i, j, a, b, d; cursors(); - if (c[SPELLS]<=0) { lprcat("\nYou don't have any spells!"); return; } - lprcat(eys); --c[SPELLS]; - while ((a=getchar())=='D') - { seemagic(-1); cursors(); lprcat(eys); } - if (a=='\33') goto over; /* to escape casting a spell */ - if ((b=getchar())=='\33') goto over; /* to escape casting a spell */ - if ((d=getchar())=='\33') - { over: lprcat(aborted); c[SPELLS]++; return; } /* to escape casting a spell */ + if (c[SPELLS] <= 0) { + lprcat("\nYou don't have any spells!"); + return; + } + lprcat(eys); + --c[SPELLS]; + while ((a = getchar()) == 'D') { + seemagic(-1); + cursors(); + lprcat(eys); + } + if (a == '\33') + goto over; /* to escape casting a spell */ + if ((b = getchar()) == '\33') + goto over; /* to escape casting a spell */ + if ((d = getchar()) == '\33') { +over: lprcat(aborted); + c[SPELLS]++; + return; + } /* to escape casting a spell */ #ifdef EXTRA c[SPELLSCAST]++; #endif - for (lprc('\n'),j= -1,i=0; i<SPNUM; i++) /*seq search for his spell, hash?*/ - if ((spelcode[i][0]==a) && (spelcode[i][1]==b) && (spelcode[i][2]==d)) - if (spelknow[i]) - { speldamage(i); j = 1; i=SPNUM; } - - if (j == -1) lprcat(" Nothing Happened "); + for (lprc('\n'), j = -1, i = 0; i < SPNUM; i++) /* seq search for his + * spell, hash? */ + if ((spelcode[i][0] == a) && (spelcode[i][1] == b) && (spelcode[i][2] == d)) + if (spelknow[i]) { + speldamage(i); + j = 1; + i = SPNUM; + } + if (j == -1) + lprcat(" Nothing Happened "); bottomline(); - } - -static int dirsub(); +} /* - * speldamage(x) Function to perform spell functions cast by the player - * int x; + * speldamage(x) Function to perform spell functions cast by the player + * int x; * - * Enter with the spell number, returns no value. - * Please insure that there are 2 spaces before all messages here + * Enter with the spell number, returns no value. + * Please insure that there are 2 spaces before all messages here */ +void speldamage(x) - int x; - { - register int i,j,clev; - int xl,xh,yl,yh; - register char *p,*kn,*pm; - if (x>=SPNUM) return; /* no such spell */ - if (c[TIMESTOP]) { lprcat(" It didn't seem to work"); return; } /* not if time stopped */ + int x; +{ + int i, j, clev; + int xl, xh, yl, yh; + char *p, *kn, *pm; + if (x >= SPNUM) + return; /* no such spell */ + if (c[TIMESTOP]) { + lprcat(" It didn't seem to work"); + return; + } /* not if time stopped */ clev = c[LEVEL]; - if ((rnd(23)==7) || (rnd(18) > c[INTELLIGENCE])) - { lprcat(" It didn't work!"); return; } - if (clev*3+2 < x) { lprcat(" Nothing happens. You seem inexperienced at this"); return; } + if ((rnd(23) == 7) || (rnd(18) > c[INTELLIGENCE])) { + lprcat(" It didn't work!"); + return; + } + if (clev * 3 + 2 < x) { + lprcat(" Nothing happens. You seem inexperienced at this"); + return; + } + switch (x) { + /* ----- LEVEL 1 SPELLS ----- */ - switch(x) - { -/* ----- LEVEL 1 SPELLS ----- */ + case 0: + if (c[PROTECTIONTIME] == 0) + c[MOREDEFENSES] += 2; /* protection field +2 */ + c[PROTECTIONTIME] += 250; + return; - case 0: if (c[PROTECTIONTIME]==0) c[MOREDEFENSES]+=2; /* protection field +2 */ - c[PROTECTIONTIME] += 250; return; + case 1: + i = rnd(((clev + 1) << 1)) + clev + 3; + godirect(x, i, (clev >= 2) ? " Your missiles hit the %s" : " Your missile hit the %s", 100, '+'); /* magic missile */ - case 1: i = rnd(((clev+1)<<1)) + clev + 3; - godirect(x,i,(clev>=2)?" Your missiles hit the %s":" Your missile hit the %s",100,'+'); /* magic missile */ + return; - return; + case 2: + if (c[DEXCOUNT] == 0) + c[DEXTERITY] += 3; /* dexterity */ + c[DEXCOUNT] += 400; + return; - case 2: if (c[DEXCOUNT]==0) c[DEXTERITY]+=3; /* dexterity */ - c[DEXCOUNT] += 400; return; + case 3: + i = rnd(3) + 1; + p = " While the %s slept, you smashed it %d times"; +ws: direct(x, fullhit(i), p, i); /* sleep */ + return; - case 3: i=rnd(3)+1; - p=" While the %s slept, you smashed it %d times"; - ws: direct(x,fullhit(i),p,i); /* sleep */ return; + case 4: /* charm monster */ + c[CHARMCOUNT] += c[CHARISMA] << 1; + return; - case 4: /* charm monster */ c[CHARMCOUNT] += c[CHARISMA]<<1; return; + case 5: + godirect(x, rnd(10) + 15 + clev, " The sound damages the %s", 70, '@'); /* sonic spear */ + return; - case 5: godirect(x,rnd(10)+15+clev," The sound damages the %s",70,'@'); /* sonic spear */ - return; + /* ----- LEVEL 2 SPELLS ----- */ -/* ----- LEVEL 2 SPELLS ----- */ + case 6: + i = rnd(3) + 2; + p = " While the %s is entangled, you hit %d times"; + goto ws; /* web */ - case 6: i=rnd(3)+2; p=" While the %s is entangled, you hit %d times"; - goto ws; /* web */ + case 7: + if (c[STRCOUNT] == 0) + c[STREXTRA] += 3; /* strength */ + c[STRCOUNT] += 150 + rnd(100); + return; - case 7: if (c[STRCOUNT]==0) c[STREXTRA]+=3; /* strength */ - c[STRCOUNT] += 150+rnd(100); return; + case 8: + yl = playery - 5; /* enlightenment */ + yh = playery + 6; + xl = playerx - 15; + xh = playerx + 16; + vxy(&xl, &yl); + vxy(&xh, &yh); /* check bounds */ + for (i = yl; i <= yh; i++) /* enlightenment */ + for (j = xl; j <= xh; j++) + know[j][i] = 1; + draws(xl, xh + 1, yl, yh + 1); + return; - case 8: yl = playery-5; /* enlightenment */ - yh = playery+6; xl = playerx-15; xh = playerx+16; - vxy(&xl,&yl); vxy(&xh,&yh); /* check bounds */ - for (i=yl; i<=yh; i++) /* enlightenment */ - for (j=xl; j<=xh; j++) know[j][i]=1; - draws(xl,xh+1,yl,yh+1); return; + case 9: + raisehp(20 + (clev << 1)); + return; /* healing */ - case 9: raisehp(20+(clev<<1)); return; /* healing */ + case 10: + c[BLINDCOUNT] = 0; + return; /* cure blindness */ - case 10: c[BLINDCOUNT]=0; return; /* cure blindness */ + case 11: + createmonster(makemonst(level + 1) + 8); + return; - case 11: createmonster(makemonst(level+1)+8); return; + case 12: + if (rnd(11) + 7 <= c[WISDOM]) + direct(x, rnd(20) + 20 + clev, " The %s believed!", 0); + else + lprcat(" It didn't believe the illusions!"); + return; - case 12: if (rnd(11)+7 <= c[WISDOM]) direct(x,rnd(20)+20+clev," The %s believed!",0); - else lprcat(" It didn't believe the illusions!"); - return; + case 13: /* if he has the amulet of invisibility then + * add more time */ + for (j = i = 0; i < 26; i++) + if (iven[i] == OAMULET) + j += 1 + ivenarg[i]; + c[INVISIBILITY] += (j << 7) + 12; + return; - case 13: /* if he has the amulet of invisibility then add more time */ - for (j=i=0; i<26; i++) - if (iven[i]==OAMULET) j+= 1+ivenarg[i]; - c[INVISIBILITY] += (j<<7)+12; return; + /* ----- LEVEL 3 SPELLS ----- */ -/* ----- LEVEL 3 SPELLS ----- */ + case 14: + godirect(x, rnd(25 + clev) + 25 + clev, " The fireball hits the %s", 40, '*'); + return; /* fireball */ - case 14: godirect(x,rnd(25+clev)+25+clev," The fireball hits the %s",40,'*'); return; /* fireball */ + case 15: + godirect(x, rnd(25) + 20 + clev, " Your cone of cold strikes the %s", 60, 'O'); /* cold */ + return; - case 15: godirect(x,rnd(25)+20+clev," Your cone of cold strikes the %s",60,'O'); /* cold */ - return; + case 16: + dirpoly(x); + return; /* polymorph */ - case 16: dirpoly(x); return; /* polymorph */ + case 17: + c[CANCELLATION] += 5 + clev; + return; /* cancellation */ - case 17: c[CANCELLATION]+= 5+clev; return; /* cancellation */ + case 18: + c[HASTESELF] += 7 + clev; + return; /* haste self */ - case 18: c[HASTESELF]+= 7+clev; return; /* haste self */ + case 19: + omnidirect(x, 30 + rnd(10), " The %s gasps for air"); /* cloud kill */ + return; - case 19: omnidirect(x,30+rnd(10)," The %s gasps for air"); /* cloud kill */ - return; + case 20: + xh = min(playerx + 1, MAXX - 2); + yh = min(playery + 1, MAXY - 2); + for (i = max(playerx - 1, 1); i <= xh; i++) /* vaporize rock */ + for (j = max(playery - 1, 1); j <= yh; j++) { + kn = &know[i][j]; + pm = &mitem[i][j]; + switch (*(p = &item[i][j])) { + case OWALL: + if (level < MAXLEVEL + MAXVLEVEL - 1) + *p = *kn = 0; + break; - case 20: xh = min(playerx+1,MAXX-2); yh = min(playery+1,MAXY-2); - for (i=max(playerx-1,1); i<=xh; i++) /* vaporize rock */ - for (j=max(playery-1,1); j<=yh; j++) - { - kn = &know[i][j]; pm = &mitem[i][j]; - switch(*(p= &item[i][j])) - { - case OWALL: if (level < MAXLEVEL+MAXVLEVEL-1) - *p = *kn = 0; - break; + case OSTATUE: + if (c[HARDGAME] < 3) { + *p = OBOOK; + iarg[i][j] = level; + *kn = 0; + } + break; - case OSTATUE: if (c[HARDGAME]<3) - { - *p=OBOOK; iarg[i][j]=level; *kn=0; - } - break; - - case OTHRONE: *pm=GNOMEKING; *kn=0; *p= OTHRONE2; - hitp[i][j]=monster[GNOMEKING].hitpoints; break; + case OTHRONE: + *pm = GNOMEKING; + *kn = 0; + *p = OTHRONE2; + hitp[i][j] = monster[GNOMEKING].hitpoints; + break; - case OALTAR: *pm=DEMONPRINCE; *kn=0; - hitp[i][j]=monster[DEMONPRINCE].hitpoints; break; - }; - switch(*pm) - { - case XORN: ifblind(i,j); hitm(i,j,200); break; /* Xorn takes damage from vpr */ - } - } - return; + case OALTAR: + *pm = DEMONPRINCE; + *kn = 0; + hitp[i][j] = monster[DEMONPRINCE].hitpoints; + break; + }; + switch (*pm) { + case XORN: + ifblind(i, j); + hitm(i, j, 200); + break; /* Xorn takes damage from vpr */ + } + } + return; -/* ----- LEVEL 4 SPELLS ----- */ + /* ----- LEVEL 4 SPELLS ----- */ - case 21: direct(x,100+clev," The %s shrivels up",0); /* dehydration */ - return; + case 21: + direct(x, 100 + clev, " The %s shrivels up", 0); /* dehydration */ + return; - case 22: godirect(x,rnd(25)+20+(clev<<1)," A lightning bolt hits the %s",1,'~'); /* lightning */ - return; + case 22: + godirect(x, rnd(25) + 20 + (clev << 1), " A lightning bolt hits the %s", 1, '~'); /* lightning */ + return; - case 23: i=min(c[HP]-1,c[HPMAX]/2); /* drain life */ - direct(x,i+i,"",0); c[HP] -= i; return; + case 23: + i = min(c[HP] - 1, c[HPMAX] / 2); /* drain life */ + direct(x, i + i, "", 0); + c[HP] -= i; + return; - case 24: if (c[GLOBE]==0) c[MOREDEFENSES] += 10; - c[GLOBE] += 200; loseint(); /* globe of invulnerability */ - return; + case 24: + if (c[GLOBE] == 0) + c[MOREDEFENSES] += 10; + c[GLOBE] += 200; + loseint(); /* globe of invulnerability */ + return; - case 25: omnidirect(x,32+clev," The %s struggles for air in your flood!"); /* flood */ - return; + case 25: + omnidirect(x, 32 + clev, " The %s struggles for air in your flood!"); /* flood */ + return; - case 26: if (rnd(151)==63) { beep(); lprcat("\nYour heart stopped!\n"); nap(4000); died(270); return; } - if (c[WISDOM]>rnd(10)+10) direct(x,2000," The %s's heart stopped",0); /* finger of death */ - else lprcat(" It didn't work"); return; + case 26: + if (rnd(151) == 63) { + beep(); + lprcat("\nYour heart stopped!\n"); + nap(4000); + died(270); + return; + } + if (c[WISDOM] > rnd(10) + 10) + direct(x, 2000, " The %s's heart stopped", 0); /* finger of death */ + else + lprcat(" It didn't work"); + return; -/* ----- LEVEL 5 SPELLS ----- */ + /* ----- LEVEL 5 SPELLS ----- */ - case 27: c[SCAREMONST] += rnd(10)+clev; return; /* scare monster */ + case 27: + c[SCAREMONST] += rnd(10) + clev; + return; /* scare monster */ - case 28: c[HOLDMONST] += rnd(10)+clev; return; /* hold monster */ + case 28: + c[HOLDMONST] += rnd(10) + clev; + return; /* hold monster */ - case 29: c[TIMESTOP] += rnd(20)+(clev<<1); return; /* time stop */ + case 29: + c[TIMESTOP] += rnd(20) + (clev << 1); + return; /* time stop */ - case 30: tdirect(x); return; /* teleport away */ + case 30: + tdirect(x); + return; /* teleport away */ - case 31: omnidirect(x,35+rnd(10)+clev," The %s cringes from the flame"); /* magic fire */ - return; + case 31: + omnidirect(x, 35 + rnd(10) + clev, " The %s cringes from the flame"); /* magic fire */ + return; -/* ----- LEVEL 6 SPELLS ----- */ + /* ----- LEVEL 6 SPELLS ----- */ - case 32: if ((rnd(23)==5) && (wizard==0)) /* sphere of annihilation */ - { - beep(); lprcat("\nYou have been enveloped by the zone of nothingness!\n"); - nap(4000); died(258); return; - } - xl=playerx; yl=playery; - loseint(); - i=dirsub(&xl,&yl); /* get direction of sphere */ - newsphere(xl,yl,i,rnd(20)+11); /* make a sphere */ - return; - - case 33: genmonst(); spelknow[33]=0; /* genocide */ - loseint(); - return; - - case 34: /* summon demon */ - if (rnd(100) > 30) { direct(x,150," The demon strikes at the %s",0); return; } - if (rnd(100) > 15) { lprcat(" Nothing seems to have happened"); return; } - lprcat(" The demon turned on you and vanished!"); beep(); - i=rnd(40)+30; lastnum=277; - losehp(i); /* must say killed by a demon */ return; - - case 35: /* walk through walls */ - c[WTW] += rnd(10)+5; return; - - case 36: /* alter reality */ - { - struct isave *save; /* pointer to item save structure */ - int sc; sc=0; /* # items saved */ - save = (struct isave *)malloc(sizeof(struct isave)*MAXX*MAXY*2); - for (j=0; j<MAXY; j++) - for (i=0; i<MAXX; i++) /* save all items and monsters */ - { - xl = item[i][j]; - if (xl && xl!=OWALL && xl!=OANNIHILATION) - { - save[sc].type=0; save[sc].id=item[i][j]; - save[sc++].arg=iarg[i][j]; - } - if (mitem[i][j]) - { - save[sc].type=1; save[sc].id=mitem[i][j]; - save[sc++].arg=hitp[i][j]; - } - item[i][j]=OWALL; mitem[i][j]=0; - if (wizard) know[i][j]=1; else know[i][j]=0; - } - eat(1,1); if (level==1) item[33][MAXY-1]=0; - for (j=rnd(MAXY-2), i=1; i<MAXX-1; i++) item[i][j]=0; - while (sc>0) /* put objects back in level */ - { - --sc; - if (save[sc].type == 0) - { - int trys; - for (trys=100, i=j=1; --trys>0 && item[i][j]; i=rnd(MAXX-1), j=rnd(MAXY-1)); - if (trys) { item[i][j]=save[sc].id; iarg[i][j]=save[sc].arg; } - } - else - { /* put monsters back in */ - int trys; - for (trys=100, i=j=1; --trys>0 && (item[i][j]==OWALL || mitem[i][j]); i=rnd(MAXX-1), j=rnd(MAXY-1)); - if (trys) { mitem[i][j]=save[sc].id; hitp[i][j]=save[sc].arg; } - } - } - loseint(); - draws(0,MAXX,0,MAXY); if (wizard==0) spelknow[36]=0; - free((char*)save); positionplayer(); return; + case 32: + if ((rnd(23) == 5) && (wizard == 0)) { /* sphere of + * annihilation */ + beep(); + lprcat("\nYou have been enveloped by the zone of nothingness!\n"); + nap(4000); + died(258); + return; + } + xl = playerx; + yl = playery; + loseint(); + i = dirsub(&xl, &yl); /* get direction of sphere */ + newsphere(xl, yl, i, rnd(20) + 11); /* make a sphere */ + return; + + case 33: + genmonst(); + spelknow[33] = 0; /* genocide */ + loseint(); + return; + + case 34: /* summon demon */ + if (rnd(100) > 30) { + direct(x, 150, " The demon strikes at the %s", 0); + return; + } + if (rnd(100) > 15) { + lprcat(" Nothing seems to have happened"); + return; + } + lprcat(" The demon turned on you and vanished!"); + beep(); + i = rnd(40) + 30; + lastnum = 277; + losehp(i); /* must say killed by a demon */ + return; + + case 35: /* walk through walls */ + c[WTW] += rnd(10) + 5; + return; + + case 36: /* alter reality */ + { + struct isave *save; /* pointer to item save + * structure */ + int sc; + sc = 0; /* # items saved */ + save = (struct isave *) malloc(sizeof(struct isave) * MAXX * MAXY * 2); + for (j = 0; j < MAXY; j++) + for (i = 0; i < MAXX; i++) { /* save all items and + * monsters */ + xl = item[i][j]; + if (xl && xl != OWALL && xl != OANNIHILATION) { + save[sc].type = 0; + save[sc].id = item[i][j]; + save[sc++].arg = iarg[i][j]; + } + if (mitem[i][j]) { + save[sc].type = 1; + save[sc].id = mitem[i][j]; + save[sc++].arg = hitp[i][j]; + } + item[i][j] = OWALL; + mitem[i][j] = 0; + if (wizard) + know[i][j] = 1; + else + know[i][j] = 0; + } + eat(1, 1); + if (level == 1) + item[33][MAXY - 1] = 0; + for (j = rnd(MAXY - 2), i = 1; i < MAXX - 1; i++) + item[i][j] = 0; + while (sc > 0) { /* put objects back in level */ + --sc; + if (save[sc].type == 0) { + int trys; + for (trys = 100, i = j = 1; --trys > 0 && item[i][j]; i = rnd(MAXX - 1), j = rnd(MAXY - 1)); + if (trys) { + item[i][j] = save[sc].id; + iarg[i][j] = save[sc].arg; + } + } else { /* put monsters back in */ + int trys; + for (trys = 100, i = j = 1; --trys > 0 && (item[i][j] == OWALL || mitem[i][j]); i = rnd(MAXX - 1), j = rnd(MAXY - 1)); + if (trys) { + mitem[i][j] = save[sc].id; + hitp[i][j] = save[sc].arg; } + } + } + loseint(); + draws(0, MAXX, 0, MAXY); + if (wizard == 0) + spelknow[36] = 0; + free((char *) save); + positionplayer(); + return; + } - case 37: /* permanence */ adjtime(-99999L); spelknow[37]=0; /* forget */ - loseint(); - return; + case 37: /* permanence */ + adjusttime(-99999L); + spelknow[37] = 0; /* forget */ + loseint(); + return; - default: lprintf(" spell %d not available!",(long)x); beep(); return; - }; - } + default: + lprintf(" spell %d not available!", (long) x); + beep(); + return; + }; +} /* - * loseint() Routine to subtract 1 from your int (intelligence) if > 3 + * loseint() Routine to subtract 1 from your int (intelligence) if > 3 * - * No arguments and no return value + * No arguments and no return value */ +void loseint() - { - if (--c[INTELLIGENCE]<3) c[INTELLIGENCE]=3; - } +{ + if (--c[INTELLIGENCE] < 3) + c[INTELLIGENCE] = 3; +} /* - * isconfuse() Routine to check to see if player is confused + * isconfuse() Routine to check to see if player is confused * - * This routine prints out a message saying "You can't aim your magic!" - * returns 0 if not confused, non-zero (time remaining confused) if confused + * This routine prints out a message saying "You can't aim your magic!" + * returns 0 if not confused, non-zero (time remaining confused) if confused */ +int isconfuse() - { - if (c[CONFUSE]) { lprcat(" You can't aim your magic!"); beep(); } - return(c[CONFUSE]); +{ + if (c[CONFUSE]) { + lprcat(" You can't aim your magic!"); + beep(); } + return (c[CONFUSE]); +} /* - * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster - * int x,monst; + * nospell(x,monst) Routine to return 1 if a spell doesn't affect a monster + * int x,monst; * - * Subroutine to return 1 if the spell can't affect the monster - * otherwise returns 0 - * Enter with the spell number in x, and the monster number in monst. + * Subroutine to return 1 if the spell can't affect the monster + * otherwise returns 0 + * Enter with the spell number in x, and the monster number in monst. */ -nospell(x,monst) - int x,monst; - { - register int tmp; - if (x>=SPNUM || monst>=MAXMONST+8 || monst<0 || x<0) return(0); /* bad spell or monst */ - if ((tmp=spelweird[monst-1][x])==0) return(0); - cursors(); lprc('\n'); lprintf(spelmes[tmp],monster[monst].name); return(1); - } +int +nospell(x, monst) + int x, monst; +{ + int tmp; + if (x >= SPNUM || monst >= MAXMONST + 8 || monst < 0 || x < 0) + return (0); /* bad spell or monst */ + if ((tmp = spelweird[monst - 1][x]) == 0) + return (0); + cursors(); + lprc('\n'); + lprintf(spelmes[tmp], monster[monst].name); + return (1); +} /* - * fullhit(xx) Function to return full damage against a monster (aka web) - * int xx; + * fullhit(xx) Function to return full damage against a monster (aka web) + * int xx; * - * Function to return hp damage to monster due to a number of full hits - * Enter with the number of full hits being done + * Function to return hp damage to monster due to a number of full hits + * Enter with the number of full hits being done */ +int fullhit(xx) - int xx; - { - register int i; - if (xx<0 || xx>20) return(0); /* fullhits are out of range */ - if (c[LANCEDEATH]) return(10000); /* lance of death */ - i = xx * ((c[WCLASS]>>1)+c[STRENGTH]+c[STREXTRA]-c[HARDGAME]-12+c[MOREDAM]); - return( (i>=1) ? i : xx ); - } + int xx; +{ + int i; + if (xx < 0 || xx > 20) + return (0); /* fullhits are out of range */ + if (c[LANCEDEATH]) + return (10000); /* lance of death */ + i = xx * ((c[WCLASS] >> 1) + c[STRENGTH] + c[STREXTRA] - c[HARDGAME] - 12 + c[MOREDAM]); + return ((i >= 1) ? i : xx); +} /* - * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir - * int spnum,dam,arg; - * char *str; - * - * Routine to ask for a direction to a spell and then hit the monster - * Enter with the spell number in spnum, the damage to be done in dam, - * lprintf format string in str, and lprintf's argument in arg. - * Returns no value. + * direct(spnum,dam,str,arg) Routine to direct spell damage 1 square in 1 dir + * int spnum,dam,arg; + * char *str; + * + * Routine to ask for a direction to a spell and then hit the monster + * Enter with the spell number in spnum, the damage to be done in dam, + * lprintf format string in str, and lprintf's argument in arg. + * Returns no value. */ -direct(spnum,dam,str,arg) - int spnum,dam,arg; - char *str; - { - int x,y; - register int m; - if (spnum<0 || spnum>=SPNUM || str==0) return; /* bad arguments */ - if (isconfuse()) return; - dirsub(&x,&y); +void +direct(spnum, dam, str, arg) + int spnum, dam, arg; + char *str; +{ + int x, y; + int m; + if (spnum < 0 || spnum >= SPNUM || str == 0) + return; /* bad arguments */ + if (isconfuse()) + return; + dirsub(&x, &y); m = mitem[x][y]; - if (item[x][y]==OMIRROR) - { - if (spnum==3) /* sleep */ - { - lprcat("You fall asleep! "); beep(); - fool: + if (item[x][y] == OMIRROR) { + if (spnum == 3) { /* sleep */ + lprcat("You fall asleep! "); + beep(); + fool: arg += 2; - while (arg-- > 0) { parse2(); nap(1000); } - return; + while (arg-- > 0) { + parse2(); + nap(1000); } - else if (spnum==6) /* web */ - { - lprcat("You get stuck in your own web! "); beep(); + return; + } else if (spnum == 6) { /* web */ + lprcat("You get stuck in your own web! "); + beep(); goto fool; - } - else - { - lastnum=278; - lprintf(str,"spell caster (thats you)",(long)arg); - beep(); losehp(dam); return; - } + } else { + lastnum = 278; + lprintf(str, "spell caster (thats you)", (long) arg); + beep(); + losehp(dam); + return; } - if (m==0) - { lprcat(" There wasn't anything there!"); return; } - ifblind(x,y); - if (nospell(spnum,m)) { lasthx=x; lasthy=y; return; } - lprintf(str,lastmonst,(long)arg); hitm(x,y,dam); } + if (m == 0) { + lprcat(" There wasn't anything there!"); + return; + } + ifblind(x, y); + if (nospell(spnum, m)) { + lasthx = x; + lasthy = y; + return; + } + lprintf(str, lastmonst, (long) arg); + hitm(x, y, dam); +} /* - * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks - * int spnum,dam,delay; - * char *str,cshow; - * - * Function to hit in a direction from a missile weapon and have it keep - * on going in that direction until its power is exhausted - * Enter with the spell number in spnum, the power of the weapon in hp, - * lprintf format string in str, the # of milliseconds to delay between - * locations in delay, and the character to represent the weapon in cshow. - * Returns no value. + * godirect(spnum,dam,str,delay,cshow) Function to perform missile attacks + * int spnum,dam,delay; + * char *str,cshow; + * + * Function to hit in a direction from a missile weapon and have it keep + * on going in that direction until its power is exhausted + * Enter with the spell number in spnum, the power of the weapon in hp, + * lprintf format string in str, the # of milliseconds to delay between + * locations in delay, and the character to represent the weapon in cshow. + * Returns no value. */ -godirect(spnum,dam,str,delay,cshow) - int spnum,dam,delay; - char *str,cshow; - { - register char *p; - register int x,y,m; - int dx,dy; - if (spnum<0 || spnum>=SPNUM || str==0 || delay<0) return; /* bad args */ - if (isconfuse()) return; - dirsub(&dx,&dy); x=dx; y=dy; - dx = x-playerx; dy = y-playery; x = playerx; y = playery; - while (dam>0) - { - x += dx; y += dy; - if ((x > MAXX-1) || (y > MAXY-1) || (x < 0) || (y < 0)) - { - dam=0; break; /* out of bounds */ - } - if ((x==playerx) && (y==playery)) /* if energy hits player */ - { - cursors(); lprcat("\nYou are hit my your own magic!"); beep(); - lastnum=278; losehp(dam); return; - } - if (c[BLINDCOUNT]==0) /* if not blind show effect */ - { - cursor(x+1,y+1); lprc(cshow); nap(delay); show1cell(x,y); - } - if ((m=mitem[x][y])) /* is there a monster there? */ - { - ifblind(x,y); - if (nospell(spnum,m)) { lasthx=x; lasthy=y; return; } - cursors(); lprc('\n'); - lprintf(str,lastmonst); dam -= hitm(x,y,dam); - show1cell(x,y); nap(1000); x -= dx; y -= dy; +void +godirect(spnum, dam, str, delay, cshow) + int spnum, dam, delay; + char *str, cshow; +{ + char *p; + int x, y, m; + int dx, dy; + if (spnum < 0 || spnum >= SPNUM || str == 0 || delay < 0) + return; /* bad args */ + if (isconfuse()) + return; + dirsub(&dx, &dy); + x = dx; + y = dy; + dx = x - playerx; + dy = y - playery; + x = playerx; + y = playery; + while (dam > 0) { + x += dx; + y += dy; + if ((x > MAXX - 1) || (y > MAXY - 1) || (x < 0) || (y < 0)) { + dam = 0; + break; /* out of bounds */ + } + if ((x == playerx) && (y == playery)) { /* if energy hits player */ + cursors(); + lprcat("\nYou are hit my your own magic!"); + beep(); + lastnum = 278; + losehp(dam); + return; + } + if (c[BLINDCOUNT] == 0) { /* if not blind show effect */ + cursor(x + 1, y + 1); + lprc(cshow); + nap(delay); + show1cell(x, y); + } + if ((m = mitem[x][y])) { /* is there a monster there? */ + ifblind(x, y); + if (nospell(spnum, m)) { + lasthx = x; + lasthy = y; + return; } - else switch (*(p= &item[x][y])) - { - case OWALL: cursors(); lprc('\n'); lprintf(str,"wall"); - if (dam>=50+c[HARDGAME]) /* enough damage? */ - if (level<MAXLEVEL+MAXVLEVEL-1) /* not on V3 */ - if ((x<MAXX-1) && (y<MAXY-1) && (x) && (y)) - { + cursors(); + lprc('\n'); + lprintf(str, lastmonst); + dam -= hitm(x, y, dam); + show1cell(x, y); + nap(1000); + x -= dx; + y -= dy; + } else + switch (*(p = &item[x][y])) { + case OWALL: + cursors(); + lprc('\n'); + lprintf(str, "wall"); + if (dam >= 50 + c[HARDGAME]) /* enough damage? */ + if (level < MAXLEVEL + MAXVLEVEL - 1) /* not on V3 */ + if ((x < MAXX - 1) && (y < MAXY - 1) && (x) && (y)) { lprcat(" The wall crumbles"); - god3: *p=0; - god: know[x][y]=0; - show1cell(x,y); - } - god2: dam = 0; break; - - case OCLOSEDDOOR: cursors(); lprc('\n'); lprintf(str,"door"); - if (dam>=40) - { - lprcat(" The door is blasted apart"); - goto god3; - } - goto god2; - - case OSTATUE: cursors(); lprc('\n'); lprintf(str,"statue"); - if (c[HARDGAME]<3) - if (dam>44) - { - lprcat(" The statue crumbles"); - *p=OBOOK; iarg[x][y]=level; - goto god; - } - goto god2; - - case OTHRONE: cursors(); lprc('\n'); lprintf(str,"throne"); - if (dam>39) - { - mitem[x][y]=GNOMEKING; hitp[x][y]=monster[GNOMEKING].hitpoints; - *p = OTHRONE2; - goto god; + god3: *p = 0; + god: know[x][y] = 0; + show1cell(x, y); } - goto god2; + god2: dam = 0; + break; - case OMIRROR: dx *= -1; dy *= -1; break; + case OCLOSEDDOOR: + cursors(); + lprc('\n'); + lprintf(str, "door"); + if (dam >= 40) { + lprcat(" The door is blasted apart"); + goto god3; + } + goto god2; + + case OSTATUE: + cursors(); + lprc('\n'); + lprintf(str, "statue"); + if (c[HARDGAME] < 3) + if (dam > 44) { + lprcat(" The statue crumbles"); + *p = OBOOK; + iarg[x][y] = level; + goto god; + } + goto god2; + + case OTHRONE: + cursors(); + lprc('\n'); + lprintf(str, "throne"); + if (dam > 39) { + mitem[x][y] = GNOMEKING; + hitp[x][y] = monster[GNOMEKING].hitpoints; + *p = OTHRONE2; + goto god; + } + goto god2; + + case OMIRROR: + dx *= -1; + dy *= -1; + break; }; - dam -= 3 + (c[HARDGAME]>>1); - } + dam -= 3 + (c[HARDGAME] >> 1); } +} /* - * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt - * int x,y; + * ifblind(x,y) Routine to put "monster" or the monster name into lastmosnt + * int x,y; * - * Subroutine to copy the word "monster" into lastmonst if the player is blind - * Enter with the coordinates (x,y) of the monster - * Returns no value. + * Subroutine to copy the word "monster" into lastmonst if the player is blind + * Enter with the coordinates (x,y) of the monster + * Returns no value. */ -ifblind(x,y) - int x,y; - { - char *p; - vxy(&x,&y); /* verify correct x,y coordinates */ - if (c[BLINDCOUNT]) { lastnum=279; p="monster"; } - else { lastnum=mitem[x][y]; p=monster[lastnum].name; } - strcpy(lastmonst,p); +void +ifblind(x, y) + int x, y; +{ + char *p; + vxy(&x, &y); /* verify correct x,y coordinates */ + if (c[BLINDCOUNT]) { + lastnum = 279; + p = "monster"; + } else { + lastnum = mitem[x][y]; + p = monster[lastnum].name; } + strcpy(lastmonst, p); +} /* - * tdirect(spnum) Routine to teleport away a monster - * int spnum; + * tdirect(spnum) Routine to teleport away a monster + * int spnum; * - * Routine to ask for a direction to a spell and then teleport away monster - * Enter with the spell number that wants to teleport away - * Returns no value. + * Routine to ask for a direction to a spell and then teleport away monster + * Enter with the spell number that wants to teleport away + * Returns no value. */ +void tdirect(spnum) - int spnum; - { - int x,y; - register int m; - if (spnum<0 || spnum>=SPNUM) return; /* bad args */ - if (isconfuse()) return; - dirsub(&x,&y); - if ((m=mitem[x][y])==0) - { lprcat(" There wasn't anything there!"); return; } - ifblind(x,y); - if (nospell(spnum,m)) { lasthx=x; lasthy=y; return; } - fillmonst(m); mitem[x][y]=know[x][y]=0; + int spnum; +{ + int x, y; + int m; + if (spnum < 0 || spnum >= SPNUM) + return; /* bad args */ + if (isconfuse()) + return; + dirsub(&x, &y); + if ((m = mitem[x][y]) == 0) { + lprcat(" There wasn't anything there!"); + return; + } + ifblind(x, y); + if (nospell(spnum, m)) { + lasthx = x; + lasthy = y; + return; } + fillmonst(m); + mitem[x][y] = know[x][y] = 0; +} /* - * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player - * int sp,dam; - * char *str; - * - * Routine to cast a spell and then hit the monster in all directions - * Enter with the spell number in sp, the damage done to wach square in dam, - * and the lprintf string to identify the spell in str. - * Returns no value. + * omnidirect(sp,dam,str) Routine to damage all monsters 1 square from player + * int sp,dam; + * char *str; + * + * Routine to cast a spell and then hit the monster in all directions + * Enter with the spell number in sp, the damage done to wach square in dam, + * and the lprintf string to identify the spell in str. + * Returns no value. */ -omnidirect(spnum,dam,str) - int spnum,dam; - char *str; - { - register int x,y,m; - if (spnum<0 || spnum>=SPNUM || str==0) return; /* bad args */ - for (x=playerx-1; x<playerx+2; x++) - for (y=playery-1; y<playery+2; y++) - { - if (m=mitem[x][y]) - if (nospell(spnum,m) == 0) - { - ifblind(x,y); - cursors(); lprc('\n'); lprintf(str,lastmonst); - hitm(x,y,dam); nap(800); - } - else { lasthx=x; lasthy=y; } - } - } +void +omnidirect(spnum, dam, str) + int spnum, dam; + char *str; +{ + int x, y, m; + if (spnum < 0 || spnum >= SPNUM || str == 0) + return; /* bad args */ + for (x = playerx - 1; x < playerx + 2; x++) + for (y = playery - 1; y < playery + 2; y++) { + if ((m = mitem[x][y]) != 0) + if (nospell(spnum, m) == 0) { + ifblind(x, y); + cursors(); + lprc('\n'); + lprintf(str, lastmonst); + hitm(x, y, dam); + nap(800); + } else { + lasthx = x; + lasthy = y; + } + } +} /* - * static dirsub(x,y) Routine to ask for direction, then modify x,y for it - * int *x,*y; + * static dirsub(x,y) Routine to ask for direction, then modify x,y for it + * int *x,*y; * - * Function to ask for a direction and modify an x,y for that direction - * Enter with the origination coordinates in (x,y). - * Returns index into diroffx[] (0-8). + * Function to ask for a direction and modify an x,y for that direction + * Enter with the origination coordinates in (x,y). + * Returns index into diroffx[] (0-8). */ static int -dirsub(x,y) - int *x,*y; - { - register int i; +dirsub(x, y) + int *x, *y; +{ + int i; lprcat("\nIn What Direction? "); - for (i=0; ; ) - switch(getchar()) - { - case 'b': i++; - case 'n': i++; - case 'y': i++; - case 'u': i++; - case 'h': i++; - case 'k': i++; - case 'l': i++; - case 'j': i++; goto out; - }; + for (i = 0;;) + switch (getchar()) { + case 'b': + i++; + case 'n': + i++; + case 'y': + i++; + case 'u': + i++; + case 'h': + i++; + case 'k': + i++; + case 'l': + i++; + case 'j': + i++; + goto out; + }; out: - *x = playerx+diroffx[i]; *y = playery+diroffy[i]; - vxy(x,y); return(i); - } + *x = playerx + diroffx[i]; + *y = playery + diroffy[i]; + vxy(x, y); + return (i); +} /* - * vxy(x,y) Routine to verify/fix coordinates for being within bounds - * int *x,*y; - * - * Function to verify x & y are within the bounds for a level - * If *x or *y is not within the absolute bounds for a level, fix them so that - * they are on the level. - * Returns TRUE if it was out of bounds, and the *x & *y in the calling - * routine are affected. + * vxy(x,y) Routine to verify/fix coordinates for being within bounds + * int *x,*y; + * + * Function to verify x & y are within the bounds for a level + * If *x or *y is not within the absolute bounds for a level, fix them so that + * they are on the level. + * Returns TRUE if it was out of bounds, and the *x & *y in the calling + * routine are affected. */ -vxy(x,y) - int *x,*y; - { - int flag=0; - if (*x<0) { *x=0; flag++; } - if (*y<0) { *y=0; flag++; } - if (*x>=MAXX) { *x=MAXX-1; flag++; } - if (*y>=MAXY) { *y=MAXY-1; flag++; } - return(flag); +int +vxy(x, y) + int *x, *y; +{ + int flag = 0; + if (*x < 0) { + *x = 0; + flag++; + } + if (*y < 0) { + *y = 0; + flag++; + } + if (*x >= MAXX) { + *x = MAXX - 1; + flag++; + } + if (*y >= MAXY) { + *y = MAXY - 1; + flag++; } + return (flag); +} /* - * dirpoly(spnum) Routine to ask for a direction and polymorph a monst - * int spnum; + * dirpoly(spnum) Routine to ask for a direction and polymorph a monst + * int spnum; * - * Subroutine to polymorph a monster and ask for the direction its in - * Enter with the spell number in spmun. - * Returns no value. + * Subroutine to polymorph a monster and ask for the direction its in + * Enter with the spell number in spmun. + * Returns no value. */ +void dirpoly(spnum) - int spnum; - { - int x,y,m; - if (spnum<0 || spnum>=SPNUM) return; /* bad args */ - if (isconfuse()) return; /* if he is confused, he can't aim his magic */ - dirsub(&x,&y); - if (mitem[x][y]==0) - { lprcat(" There wasn't anything there!"); return; } - ifblind(x,y); - if (nospell(spnum,mitem[x][y])) { lasthx=x; lasthy=y; return; } - while ( monster[m = mitem[x][y] = rnd(MAXMONST+7)].genocided ); - hitp[x][y] = monster[m].hitpoints; - show1cell(x,y); /* show the new monster */ + int spnum; +{ + int x, y, m; + if (spnum < 0 || spnum >= SPNUM) + return; /* bad args */ + if (isconfuse()) + return; /* if he is confused, he can't aim his magic */ + dirsub(&x, &y); + if (mitem[x][y] == 0) { + lprcat(" There wasn't anything there!"); + return; + } + ifblind(x, y); + if (nospell(spnum, mitem[x][y])) { + lasthx = x; + lasthy = y; + return; } + while (monster[m = mitem[x][y] = rnd(MAXMONST + 7)].genocided); + hitp[x][y] = monster[m].hitpoints; + show1cell(x, y); /* show the new monster */ +} /* - * hitmonster(x,y) Function to hit a monster at the designated coordinates - * int x,y; + * hitmonster(x,y) Function to hit a monster at the designated coordinates + * int x,y; * - * This routine is used for a bash & slash type attack on a monster - * Enter with the coordinates of the monster in (x,y). - * Returns no value. + * This routine is used for a bash & slash type attack on a monster + * Enter with the coordinates of the monster in (x,y). + * Returns no value. */ -hitmonster(x,y) - int x,y; - { - register int tmp,monst,damag,flag; - if (c[TIMESTOP]) return; /* not if time stopped */ - vxy(&x,&y); /* verify coordinates are within range */ - if ((monst = mitem[x][y]) == 0) return; - hit3flag=1; ifblind(x,y); - tmp = monster[monst].armorclass + c[LEVEL] + c[DEXTERITY] + c[WCLASS]/4 - 12; +void +hitmonster(x, y) + int x, y; +{ + int tmp, monst, damag = 0, flag; + if (c[TIMESTOP]) + return; /* not if time stopped */ + vxy(&x, &y); /* verify coordinates are within range */ + if ((monst = mitem[x][y]) == 0) + return; + hit3flag = 1; + ifblind(x, y); + tmp = monster[monst].armorclass + c[LEVEL] + c[DEXTERITY] + + c[WCLASS] / 4 - 12; cursors(); - if ((rnd(20) < tmp-c[HARDGAME]) || (rnd(71) < 5)) /* need at least random chance to hit */ - { - lprcat("\nYou hit"); flag=1; - damag = fullhit(1); - if (damag<9999) damag=rnd(damag)+1; - } - else - { - lprcat("\nYou missed"); flag=0; - } - lprcat(" the "); lprcat(lastmonst); - if (flag) /* if the monster was hit */ - if ((monst==RUSTMONSTER) || (monst==DISENCHANTRESS) || (monst==CUBE)) - if (c[WIELD]>0) - if (ivenarg[c[WIELD]] > -10) - { - lprintf("\nYour weapon is dulled by the %s",lastmonst); beep(); - --ivenarg[c[WIELD]]; - } - if (flag) hitm(x,y,damag); - if (monst == VAMPIRE) if (hitp[x][y]<25) { mitem[x][y]=BAT; know[x][y]=0; } + /* need at least random chance to hit */ + if ((rnd(20) < tmp - c[HARDGAME]) || (rnd(71) < 5)) { + lprcat("\nYou hit"); + flag = 1; + damag = fullhit(1); + if (damag < 9999) + damag = rnd(damag) + 1; + } else { + lprcat("\nYou missed"); + flag = 0; } + lprcat(" the "); + lprcat(lastmonst); + if (flag) /* if the monster was hit */ + if ((monst == RUSTMONSTER) || (monst == DISENCHANTRESS) || (monst == CUBE)) + if (c[WIELD] > 0) + if (ivenarg[c[WIELD]] > -10) { + lprintf("\nYour weapon is dulled by the %s", lastmonst); + beep(); + --ivenarg[c[WIELD]]; + } + if (flag) + hitm(x, y, damag); + if (monst == VAMPIRE) + if (hitp[x][y] < 25) { + mitem[x][y] = BAT; + know[x][y] = 0; + } +} /* - * hitm(x,y,amt) Function to just hit a monster at a given coordinates - * int x,y,amt; + * hitm(x,y,amt) Function to just hit a monster at a given coordinates + * int x,y,amt; * - * Returns the number of hitpoints the monster absorbed - * This routine is used to specifically damage a monster at a location (x,y) - * Called by hitmonster(x,y) + * Returns the number of hitpoints the monster absorbed + * This routine is used to specifically damage a monster at a location (x,y) + * Called by hitmonster(x,y) */ -hitm(x,y,amt) - int x,y; - register amt; - { - register int monst; - int hpoints,amt2; - vxy(&x,&y); /* verify coordinates are within range */ +int +hitm(x, y, amt) + int x, y; + int amt; +{ + int monst; + int hpoints, amt2; + vxy(&x, &y); /* verify coordinates are within range */ amt2 = amt; /* save initial damage so we can return it */ monst = mitem[x][y]; - if (c[HALFDAM]) amt >>= 1; /* if half damage curse adjust damage points */ - if (amt<=0) amt2 = amt = 1; - lasthx=x; lasthy=y; - stealth[x][y]=1; /* make sure hitting monst breaks stealth condition */ - c[HOLDMONST]=0; /* hit a monster breaks hold monster spell */ - switch(monst) /* if a dragon and orb(s) of dragon slaying */ - { - case WHITEDRAGON: case REDDRAGON: case GREENDRAGON: - case BRONZEDRAGON: case PLATINUMDRAGON: case SILVERDRAGON: - amt *= 1+(c[SLAYING]<<1); break; - } -/* invincible monster fix is here */ + if (c[HALFDAM]) + amt >>= 1; /* if half damage curse adjust damage points */ + if (amt <= 0) + amt2 = amt = 1; + lasthx = x; + lasthy = y; + stealth[x][y] = 1; /* make sure hitting monst breaks stealth + * condition */ + c[HOLDMONST] = 0; /* hit a monster breaks hold monster spell */ + switch (monst) { /* if a dragon and orb(s) of dragon slaying */ + case WHITEDRAGON: + case REDDRAGON: + case GREENDRAGON: + case BRONZEDRAGON: + case PLATINUMDRAGON: + case SILVERDRAGON: + amt *= 1 + (c[SLAYING] << 1); + break; + } + /* invincible monster fix is here */ if (hitp[x][y] > monster[monst].hitpoints) hitp[x][y] = monster[monst].hitpoints; - if ((hpoints = hitp[x][y]) <= amt) - { + if ((hpoints = hitp[x][y]) <= amt) { #ifdef EXTRA c[MONSTKILLED]++; #endif - lprintf("\nThe %s died!",lastmonst); - raiseexperience((long)monster[monst].experience); - amt = monster[monst].gold; if (amt>0) dropgold(rnd(amt)+amt); - dropsomething(monst); disappear(x,y); bottomline(); - return(hpoints); - } - hitp[x][y] = hpoints-amt; return(amt2); + lprintf("\nThe %s died!", lastmonst); + raiseexperience((long) monster[monst].experience); + amt = monster[monst].gold; + if (amt > 0) + dropgold(rnd(amt) + amt); + dropsomething(monst); + disappear(x, y); + bottomline(); + return (hpoints); } + hitp[x][y] = hpoints - amt; + return (amt2); +} /* - * hitplayer(x,y) Function for the monster to hit the player from (x,y) - * int x,y; + * hitplayer(x,y) Function for the monster to hit the player from (x,y) + * int x,y; * - * Function for the monster to hit the player with monster at location x,y - * Returns nothing of value. + * Function for the monster to hit the player with monster at location x,y + * Returns nothing of value. */ -hitplayer(x,y) - int x,y; - { - register int dam,tmp,mster,bias; - vxy(&x,&y); /* verify coordinates are within range */ +void +hitplayer(x, y) + int x, y; +{ + int dam, tmp, mster, bias; + vxy(&x, &y); /* verify coordinates are within range */ lastnum = mster = mitem[x][y]; -/* spirit naga's and poltergeist's do nothing if scarab of negate spirit */ - if (c[NEGATESPIRIT] || c[SPIRITPRO]) if ((mster ==POLTERGEIST) || (mster ==SPIRITNAGA)) return; -/* if undead and cube of undead control */ - if (c[CUBEofUNDEAD] || c[UNDEADPRO]) if ((mster ==VAMPIRE) || (mster ==WRAITH) || (mster ==ZOMBIE)) return; - if ((know[x][y]&1) == 0) - { - know[x][y]=1; show1cell(x,y); - } + /* + * spirit naga's and poltergeist's do nothing if scarab of negate + * spirit + */ + if (c[NEGATESPIRIT] || c[SPIRITPRO]) + if ((mster == POLTERGEIST) || (mster == SPIRITNAGA)) + return; + /* if undead and cube of undead control */ + if (c[CUBEofUNDEAD] || c[UNDEADPRO]) + if ((mster == VAMPIRE) || (mster == WRAITH) || (mster == ZOMBIE)) + return; + if ((know[x][y] & 1) == 0) { + know[x][y] = 1; + show1cell(x, y); + } bias = (c[HARDGAME]) + 1; hitflag = hit2flag = hit3flag = 1; - yrepcount=0; - cursors(); ifblind(x,y); - if (c[INVISIBILITY]) if (rnd(33)<20) - { - lprintf("\nThe %s misses wildly",lastmonst); return; + yrepcount = 0; + cursors(); + ifblind(x, y); + if (c[INVISIBILITY]) + if (rnd(33) < 20) { + lprintf("\nThe %s misses wildly", lastmonst); + return; } - if (c[CHARMCOUNT]) if (rnd(30)+5*monster[mster].level-c[CHARISMA]<30) - { - lprintf("\nThe %s is awestruck at your magnificence!",lastmonst); - return; + if (c[CHARMCOUNT]) + if (rnd(30) + 5 * monster[mster].level - c[CHARISMA] < 30) { + lprintf("\nThe %s is awestruck at your magnificence!", lastmonst); + return; } - if (mster==BAT) dam=1; - else - { + if (mster == BAT) + dam = 1; + else { dam = monster[mster].damage; - dam += rnd((int)((dam<1)?1:dam)) + monster[mster].level; - } + dam += rnd((int) ((dam < 1) ? 1 : dam)) + monster[mster].level; + } tmp = 0; - if (monster[mster].attack>0) - if (((dam + bias + 8) > c[AC]) || (rnd((int)((c[AC]>0)?c[AC]:1))==1)) - { if (spattack(monster[mster].attack,x,y)) { flushall(); return; } - tmp = 1; bias -= 2; cursors(); } - if (((dam + bias) > c[AC]) || (rnd((int)((c[AC]>0)?c[AC]:1))==1)) - { - lprintf("\n The %s hit you ",lastmonst); tmp = 1; - if ((dam -= c[AC]) < 0) dam=0; - if (dam > 0) { losehp(dam); bottomhp(); flushall(); } + if (monster[mster].attack > 0) + if (((dam + bias + 8) > c[AC]) || (rnd((int) ((c[AC] > 0) ? c[AC] : 1)) == 1)) { + if (spattack(monster[mster].attack, x, y)) { + flushall(); + return; + } + tmp = 1; + bias -= 2; + cursors(); + } + if (((dam + bias) > c[AC]) || (rnd((int) ((c[AC] > 0) ? c[AC] : 1)) == 1)) { + lprintf("\n The %s hit you ", lastmonst); + tmp = 1; + if ((dam -= c[AC]) < 0) + dam = 0; + if (dam > 0) { + losehp(dam); + bottomhp(); + flushall(); } - if (tmp == 0) lprintf("\n The %s missed ",lastmonst); } + if (tmp == 0) + lprintf("\n The %s missed ", lastmonst); +} /* - * dropsomething(monst) Function to create an object when a monster dies - * int monst; + * dropsomething(monst) Function to create an object when a monster dies + * int monst; * - * Function to create an object near the player when certain monsters are killed - * Enter with the monster number - * Returns nothing of value. + * Function to create an object near the player when certain monsters are killed + * Enter with the monster number + * Returns nothing of value. */ +void dropsomething(monst) - int monst; - { - switch(monst) - { - case ORC: case NYMPH: case ELF: case TROGLODYTE: - case TROLL: case ROTHE: case VIOLETFUNGI: - case PLATINUMDRAGON: case GNOMEKING: case REDDRAGON: - something(level); return; + int monst; +{ + switch (monst) { + case ORC: + case NYMPH: + case ELF: + case TROGLODYTE: + case TROLL: + case ROTHE: + case VIOLETFUNGI: + case PLATINUMDRAGON: + case GNOMEKING: + case REDDRAGON: + something(level); + return; - case LEPRECHAUN: if (rnd(101)>=75) creategem(); - if (rnd(5)==1) dropsomething(LEPRECHAUN); return; - } + case LEPRECHAUN: + if (rnd(101) >= 75) + creategem(); + if (rnd(5) == 1) + dropsomething(LEPRECHAUN); + return; } +} /* - * dropgold(amount) Function to drop some gold around player - * int amount; + * dropgold(amount) Function to drop some gold around player + * int amount; * - * Enter with the number of gold pieces to drop - * Returns nothing of value. + * Enter with the number of gold pieces to drop + * Returns nothing of value. */ +void dropgold(amount) - register int amount; - { - if (amount > 250) createitem(OMAXGOLD,amount/100); else createitem(OGOLDPILE,amount); - } + int amount; +{ + if (amount > 250) + createitem(OMAXGOLD, amount / 100); + else + createitem(OGOLDPILE, amount); +} /* - * something(level) Function to create a random item around player - * int level; + * something(level) Function to create a random item around player + * int level; * - * Function to create an item from a designed probability around player - * Enter with the cave level on which something is to be dropped - * Returns nothing of value. + * Function to create an item from a designed probability around player + * Enter with the cave level on which something is to be dropped + * Returns nothing of value. */ +void something(level) - int level; - { - register int j; - int i; - if (level<0 || level>MAXLEVEL+MAXVLEVEL) return; /* correct level? */ - if (rnd(101)<8) something(level); /* possibly more than one item */ - j = newobject(level,&i); createitem(j,i); - } + int level; +{ + int j; + int i; + if (level < 0 || level > MAXLEVEL + MAXVLEVEL) + return; /* correct level? */ + if (rnd(101) < 8) + something(level); /* possibly more than one item */ + j = newobject(level, &i); + createitem(j, i); +} /* - * newobject(lev,i) Routine to return a randomly selected new object - * int lev,*i; + * newobject(lev,i) Routine to return a randomly selected new object + * int lev,*i; * - * Routine to return a randomly selected object to be created - * Returns the object number created, and sets *i for its argument - * Enter with the cave level and a pointer to the items arg + * Routine to return a randomly selected object to be created + * Returns the object number created, and sets *i for its argument + * Enter with the cave level and a pointer to the items arg */ -static char nobjtab[] = { 0, OSCROLL, OSCROLL, OSCROLL, OSCROLL, OPOTION, - OPOTION, OPOTION, OPOTION, OGOLDPILE, OGOLDPILE, OGOLDPILE, OGOLDPILE, - OBOOK, OBOOK, OBOOK, OBOOK, ODAGGER, ODAGGER, ODAGGER, OLEATHER, OLEATHER, - OLEATHER, OREGENRING, OPROTRING, OENERGYRING, ODEXRING, OSTRRING, OSPEAR, - OBELT, ORING, OSTUDLEATHER, OSHIELD, OFLAIL, OCHAIN, O2SWORD, OPLATE, - OLONGSWORD }; - -newobject(lev,i) - register int lev,*i; - { - register int tmp=32,j; - if (level<0 || level>MAXLEVEL+MAXVLEVEL) return(0); /* correct level? */ - if (lev>6) tmp=37; else if (lev>4) tmp=35; - j = nobjtab[tmp=rnd(tmp)]; /* the object type */ - switch(tmp) - { - case 1: case 2: case 3: case 4: *i=newscroll(); break; - case 5: case 6: case 7: case 8: *i=newpotion(); break; - case 9: case 10: case 11: case 12: *i=rnd((lev+1)*10)+lev*10+10; break; - case 13: case 14: case 15: case 16: *i=lev; break; - case 17: case 18: case 19: if (!(*i=newdagger())) return(0); break; - case 20: case 21: case 22: if (!(*i=newleather())) return(0); break; - case 23: case 32: case 35: *i=rund(lev/3+1); break; - case 24: case 26: *i=rnd(lev/4+1); break; - case 25: *i=rund(lev/4+1); break; - case 27: *i=rnd(lev/2+1); break; - case 30: case 33: *i=rund(lev/2+1); break; - case 28: *i=rund(lev/3+1); if (*i==0) return(0); break; - case 29: case 31: *i=rund(lev/2+1); if (*i==0) return(0); break; - case 34: *i=newchain(); break; - case 36: *i=newplate(); break; - case 37: *i=newsword(); break; - } - return(j); +static char nobjtab[] = { + 0, OSCROLL, OSCROLL, OSCROLL, OSCROLL, OPOTION, OPOTION, + OPOTION, OPOTION, OGOLDPILE, OGOLDPILE, OGOLDPILE, OGOLDPILE, + OBOOK, OBOOK, OBOOK, OBOOK, ODAGGER, ODAGGER, ODAGGER, + OLEATHER, OLEATHER, OLEATHER, OREGENRING, OPROTRING, + OENERGYRING, ODEXRING, OSTRRING, OSPEAR, OBELT, ORING, + OSTUDLEATHER, OSHIELD, OFLAIL, OCHAIN, O2SWORD, OPLATE, + OLONGSWORD}; + +int +newobject(lev, i) + int lev, *i; +{ + int tmp = 32, j; + if (level < 0 || level > MAXLEVEL + MAXVLEVEL) + return (0); /* correct level? */ + if (lev > 6) + tmp = 37; + else if (lev > 4) + tmp = 35; + j = nobjtab[tmp = rnd(tmp)]; /* the object type */ + switch (tmp) { + case 1: + case 2: + case 3: + case 4: + *i = newscroll(); + break; + case 5: + case 6: + case 7: + case 8: + *i = newpotion(); + break; + case 9: + case 10: + case 11: + case 12: + *i = rnd((lev + 1) * 10) + lev * 10 + 10; + break; + case 13: + case 14: + case 15: + case 16: + *i = lev; + break; + case 17: + case 18: + case 19: + if (!(*i = newdagger())) + return (0); + break; + case 20: + case 21: + case 22: + if (!(*i = newleather())) + return (0); + break; + case 23: + case 32: + case 35: + *i = rund(lev / 3 + 1); + break; + case 24: + case 26: + *i = rnd(lev / 4 + 1); + break; + case 25: + *i = rund(lev / 4 + 1); + break; + case 27: + *i = rnd(lev / 2 + 1); + break; + case 30: + case 33: + *i = rund(lev / 2 + 1); + break; + case 28: + *i = rund(lev / 3 + 1); + if (*i == 0) + return (0); + break; + case 29: + case 31: + *i = rund(lev / 2 + 1); + if (*i == 0) + return (0); + break; + case 34: + *i = newchain(); + break; + case 36: + *i = newplate(); + break; + case 37: + *i = newsword(); + break; } + return (j); +} /* - * spattack(atckno,xx,yy) Function to process special attacks from monsters + * spattack(atckno,xx,yy) Function to process special attacks from monsters * int atckno,xx,yy; * - * Enter with the special attack number, and the coordinates (xx,yy) - * of the monster that is special attacking - * Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise + * Enter with the special attack number, and the coordinates (xx,yy) + * of the monster that is special attacking + * Returns 1 if must do a show1cell(xx,yy) upon return, 0 otherwise * * atckno monster effect * --------------------------------------------------- - * 0 none - * 1 rust monster eat armor - * 2 hell hound breathe light fire - * 3 dragon breathe fire - * 4 giant centipede weakening sing - * 5 white dragon cold breath - * 6 wraith drain level - * 7 waterlord water gusher - * 8 leprechaun steal gold - * 9 disenchantress disenchant weapon or armor - * 10 ice lizard hits with barbed tail - * 11 umber hulk confusion - * 12 spirit naga cast spells taken from special attacks - * 13 platinum dragon psionics - * 14 nymph steal objects - * 15 bugbear bite - * 16 osequip bite - * - * char rustarm[ARMORTYPES][2]; - * special array for maximum rust damage to armor from rustmonster - * format is: { armor type , minimum attribute + * 0 none + * 1 rust monster eat armor + * 2 hell hound breathe light fire + * 3 dragon breathe fire + * 4 giant centipede weakening sing + * 5 white dragon cold breath + * 6 wraith drain level + * 7 waterlord water gusher + * 8 leprechaun steal gold + * 9 disenchantress disenchant weapon or armor + * 10 ice lizard hits with barbed tail + * 11 umber hulk confusion + * 12 spirit naga cast spells taken from special attacks + * 13 platinum dragon psionics + * 14 nymph steal objects + * 15 bugbear bite + * 16 osequip bite + * + * char rustarm[ARMORTYPES][2]; + * special array for maximum rust damage to armor from rustmonster + * format is: { armor type , minimum attribute */ #define ARMORTYPES 6 -static char rustarm[ARMORTYPES][2] = { OSTUDLEATHER,-2, ORING,-4, OCHAIN,-5, - OSPLINT,-6, OPLATE,-8, OPLATEARMOR,-9 }; -static char spsel[] = { 1, 2, 3, 5, 6, 8, 9, 11, 13, 14 }; -spattack(x,xx,yy) - int x,xx,yy; - { - register int i,j=0,k,m; - register char *p=0; - if (c[CANCELLATION]) return(0); - vxy(&xx,&yy); /* verify x & y coordinates */ - switch(x) - { - case 1: /* rust your armor, j=1 when rusting has occurred */ - m = k = c[WEAR]; - if ((i=c[SHIELD]) != -1) - if (--ivenarg[i] < -1) ivenarg[i]= -1; else j=1; - if ((j==0) && (k != -1)) - { - m = iven[k]; - for (i=0; i<ARMORTYPES; i++) - if (m == rustarm[i][0]) /* find his armor in table */ - { - if (--ivenarg[k]< rustarm[i][1]) - ivenarg[k]= rustarm[i][1]; else j=1; - break; - } - } - if (j==0) /* if rusting did not occur */ - switch(m) - { - case OLEATHER: p = "\nThe %s hit you -- Your lucky you have leather on"; - break; - case OSSPLATE: p = "\nThe %s hit you -- Your fortunate to have stainless steel armor!"; - break; - } - else { beep(); p = "\nThe %s hit you -- your armor feels weaker"; } - break; - - case 2: i = rnd(15)+8-c[AC]; - spout: p="\nThe %s breathes fire at you!"; - if (c[FIRERESISTANCE]) - p="\nThe %s's flame doesn't phase you!"; +static char rustarm[ARMORTYPES][2] = { + { OSTUDLEATHER, -2 }, + { ORING, -4 }, + { OCHAIN, -5 }, + { OSPLINT, -6 }, + { OPLATE, -8 }, + { OPLATEARMOR, -9} +}; +static char spsel[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14}; +int +spattack(x, xx, yy) + int x, xx, yy; +{ + int i, j = 0, k, m; + char *p = 0; + if (c[CANCELLATION]) + return (0); + vxy(&xx, &yy); /* verify x & y coordinates */ + switch (x) { + case 1: /* rust your armor, j=1 when rusting has occurred */ + m = k = c[WEAR]; + if ((i = c[SHIELD]) != -1) + if (--ivenarg[i] < -1) + ivenarg[i] = -1; + else + j = 1; + if ((j == 0) && (k != -1)) { + m = iven[k]; + for (i = 0; i < ARMORTYPES; i++) + /* find his armor in table */ + if (m == rustarm[i][0]) { + if (--ivenarg[k] < rustarm[i][1]) + ivenarg[k] = rustarm[i][1]; else - spout2: if (p) { lprintf(p,lastmonst); beep(); } - checkloss(i); - return(0); - - case 3: i = rnd(20)+25-c[AC]; goto spout; - - case 4: if (c[STRENGTH]>3) - { - p="\nThe %s stung you! You feel weaker"; beep(); - --c[STRENGTH]; - } - else p="\nThe %s stung you!"; - break; - - case 5: p="\nThe %s blasts you with his cold breath"; - i = rnd(15)+18-c[AC]; goto spout2; - - case 6: lprintf("\nThe %s drains you of your life energy!",lastmonst); - loselevel(); beep(); return(0); - - case 7: p="\nThe %s got you with a gusher!"; - i = rnd(15)+25-c[AC]; goto spout2; - - case 8: if (c[NOTHEFT]) return(0); /* he has a device of no theft */ - if (c[GOLD]) - { - p="\nThe %s hit you -- Your purse feels lighter"; - if (c[GOLD]>32767) c[GOLD]>>=1; - else c[GOLD] -= rnd((int)(1+(c[GOLD]>>1))); - if (c[GOLD] < 0) c[GOLD]=0; - } - else p="\nThe %s couldn't find any gold to steal"; - lprintf(p,lastmonst); disappear(xx,yy); beep(); - bottomgold(); return(1); - - case 9: for(j=50; ; ) /* disenchant */ - { - i=rund(26); m=iven[i]; /* randomly select item */ - if (m>0 && ivenarg[i]>0 && m!=OSCROLL && m!=OPOTION) - { - if ((ivenarg[i] -= 3)<0) ivenarg[i]=0; - lprintf("\nThe %s hits you -- you feel a sense of loss",lastmonst); - srcount=0; beep(); show3(i); bottomline(); return(0); - } - if (--j<=0) - { - p="\nThe %s nearly misses"; break; - } + j = 1; break; - } + } + } + if (j == 0) /* if rusting did not occur */ + switch (m) { + case OLEATHER: + p = "\nThe %s hit you -- Your lucky you have leather on"; break; + case OSSPLATE: + p = "\nThe %s hit you -- Your fortunate to have stainless steel armor!"; + break; + } + else { + beep(); + p = "\nThe %s hit you -- your armor feels weaker"; + } + break; - case 10: p="\nThe %s hit you with his barbed tail"; - i = rnd(25)-c[AC]; goto spout2; - - case 11: p="\nThe %s has confused you"; beep(); - c[CONFUSE]+= 10+rnd(10); break; - - case 12: /* performs any number of other special attacks */ - return(spattack(spsel[rund(10)],xx,yy)); - - case 13: p="\nThe %s flattens you with his psionics!"; - i = rnd(15)+30-c[AC]; goto spout2; - - case 14: if (c[NOTHEFT]) return(0); /* he has device of no theft */ - if (emptyhanded()==1) - { - p="\nThe %s couldn't find anything to steal"; - break; - } - lprintf("\nThe %s picks your pocket and takes:",lastmonst); - beep(); - if (stealsomething()==0) lprcat(" nothing"); disappear(xx,yy); - bottomline(); return(1); - - case 15: i= rnd(10)+ 5-c[AC]; - spout3: p="\nThe %s bit you!"; - goto spout2; - - case 16: i= rnd(15)+10-c[AC]; goto spout3; - }; - if (p) { lprintf(p,lastmonst); bottomline(); } - return(0); + case 2: + i = rnd(15) + 8 - c[AC]; +spout: p = "\nThe %s breathes fire at you!"; + if (c[FIRERESISTANCE]) + p = "\nThe %s's flame doesn't phase you!"; + else +spout2: if (p) { + lprintf(p, lastmonst); + beep(); + } + checkloss(i); + return (0); + + case 3: + i = rnd(20) + 25 - c[AC]; + goto spout; + + case 4: + if (c[STRENGTH] > 3) { + p = "\nThe %s stung you! You feel weaker"; + beep(); + --c[STRENGTH]; + } else + p = "\nThe %s stung you!"; + break; + + case 5: + p = "\nThe %s blasts you with his cold breath"; + i = rnd(15) + 18 - c[AC]; + goto spout2; + + case 6: + lprintf("\nThe %s drains you of your life energy!", lastmonst); + loselevel(); + beep(); + return (0); + + case 7: + p = "\nThe %s got you with a gusher!"; + i = rnd(15) + 25 - c[AC]; + goto spout2; + + case 8: + if (c[NOTHEFT]) + return (0); /* he has a device of no theft */ + if (c[GOLD]) { + p = "\nThe %s hit you -- Your purse feels lighter"; + if (c[GOLD] > 32767) + c[GOLD] >>= 1; + else + c[GOLD] -= rnd((int) (1 + (c[GOLD] >> 1))); + if (c[GOLD] < 0) + c[GOLD] = 0; + } else + p = "\nThe %s couldn't find any gold to steal"; + lprintf(p, lastmonst); + disappear(xx, yy); + beep(); + bottomgold(); + return (1); + + case 9: + for (j = 50;;) {/* disenchant */ + i = rund(26); + m = iven[i]; /* randomly select item */ + if (m > 0 && ivenarg[i] > 0 && m != OSCROLL && m != OPOTION) { + if ((ivenarg[i] -= 3) < 0) + ivenarg[i] = 0; + lprintf("\nThe %s hits you -- you feel a sense of loss", lastmonst); + srcount = 0; + beep(); + show3(i); + bottomline(); + return (0); + } + if (--j <= 0) { + p = "\nThe %s nearly misses"; + break; + } + break; + } + break; + + case 10: + p = "\nThe %s hit you with his barbed tail"; + i = rnd(25) - c[AC]; + goto spout2; + + case 11: + p = "\nThe %s has confused you"; + beep(); + c[CONFUSE] += 10 + rnd(10); + break; + + case 12: /* performs any number of other special + * attacks */ + return (spattack(spsel[rund(10)], xx, yy)); + + case 13: + p = "\nThe %s flattens you with his psionics!"; + i = rnd(15) + 30 - c[AC]; + goto spout2; + + case 14: + if (c[NOTHEFT]) + return (0); /* he has device of no theft */ + if (emptyhanded() == 1) { + p = "\nThe %s couldn't find anything to steal"; + break; + } + lprintf("\nThe %s picks your pocket and takes:", lastmonst); + beep(); + if (stealsomething() == 0) + lprcat(" nothing"); + disappear(xx, yy); + bottomline(); + return (1); + + case 15: + i = rnd(10) + 5 - c[AC]; +spout3: p = "\nThe %s bit you!"; + goto spout2; + + case 16: + i = rnd(15) + 10 - c[AC]; + goto spout3; + }; + if (p) { + lprintf(p, lastmonst); + bottomline(); } + return (0); +} /* - * checkloss(x) Routine to subtract hp from user and flag bottomline display - * int x; + * checkloss(x) Routine to subtract hp from user and flag bottomline display + * int x; * - * Routine to subtract hitpoints from the user and flag the bottomline display - * Enter with the number of hit points to lose - * Note: if x > c[HP] this routine could kill the player! + * Routine to subtract hitpoints from the user and flag the bottomline display + * Enter with the number of hit points to lose + * Note: if x > c[HP] this routine could kill the player! */ +void checkloss(x) - int x; - { - if (x>0) { losehp(x); bottomhp(); } + int x; +{ + if (x > 0) { + losehp(x); + bottomhp(); } +} /* - * annihilate() Routine to annihilate all monsters around player (playerx,playery) + * annihilate() Routine to annihilate all monsters around player (playerx,playery) * - * Gives player experience, but no dropped objects - * Returns the experience gained from all monsters killed + * Gives player experience, but no dropped objects + * Returns the experience gained from all monsters killed */ +int annihilate() - { - int i,j; - register long k; - register char *p; - for (k=0, i=playerx-1; i<=playerx+1; i++) - for (j=playery-1; j<=playery+1; j++) - if (!vxy(&i,&j)) /* if not out of bounds */ - if (*(p= &mitem[i][j])) /* if a monster there */ - if (*p<DEMONLORD+2) - { - k += monster[*p].experience; *p=know[i][j]=0; +{ + int i, j; + long k; + u_char *p; + for (k = 0, i = playerx - 1; i <= playerx + 1; i++) + for (j = playery - 1; j <= playery + 1; j++) + if (!vxy(&i, &j)) /* if not out of bounds */ + if (*(p = &mitem[i][j])) /* if a monster there */ + if (*p < DEMONLORD + 2) { + k += monster[*p].experience; + *p = know[i][j] = 0; + } else { + lprintf("\nThe %s barely escapes being annihilated!", monster[*p].name); + hitp[i][j] = (hitp[i][j] >> 1) + 1; /* lose half hit points */ } - else - { - lprintf("\nThe %s barely escapes being annihilated!",monster[*p].name); - hitp[i][j] = (hitp[i][j]>>1) + 1; /* lose half hit points*/ - } - if (k>0) - { - lprcat("\nYou hear loud screams of agony!"); raiseexperience((long)k); - } - return(k); + if (k > 0) { + lprcat("\nYou hear loud screams of agony!"); + raiseexperience((long) k); } + return (k); +} /* - * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation - * int x,y,dir,lifetime; + * newsphere(x,y,dir,lifetime) Function to create a new sphere of annihilation + * int x,y,dir,lifetime; * - * Enter with the coordinates of the sphere in x,y - * the direction (0-8 diroffx format) in dir, and the lifespan of the - * sphere in lifetime (in turns) - * Returns the number of spheres currently in existence + * Enter with the coordinates of the sphere in x,y + * the direction (0-8 diroffx format) in dir, and the lifespan of the + * sphere in lifetime (in turns) + * Returns the number of spheres currently in existence */ -newsphere(x,y,dir,life) - int x,y,dir,life; - { - int m; - struct sphere *sp; - if (((sp=(struct sphere *)malloc(sizeof(struct sphere)))) == 0) - return(c[SPHCAST]); /* can't malloc, therefore failure */ - if (dir>=9) dir=0; /* no movement if direction not found */ - if (level==0) vxy(&x,&y); /* don't go out of bounds */ - else - { - if (x<1) x=1; if (x>=MAXX-1) x=MAXX-2; - if (y<1) y=1; if (y>=MAXY-1) y=MAXY-2; - } - if ((m=mitem[x][y]) >= DEMONLORD+4) /* demons dispel spheres */ - { - know[x][y]=1; show1cell(x,y); /* show the demon (ha ha) */ - cursors(); lprintf("\nThe %s dispels the sphere!",monster[m].name); - beep(); rmsphere(x,y); /* remove any spheres that are here */ - return(c[SPHCAST]); - } - if (m==DISENCHANTRESS) /* disenchantress cancels spheres */ - { - cursors(); lprintf("\nThe %s causes cancellation of the sphere!",monster[m].name); beep(); -boom: sphboom(x,y); /* blow up stuff around sphere */ - rmsphere(x,y); /* remove any spheres that are here */ - return(c[SPHCAST]); - } - if (c[CANCELLATION]) /* cancellation cancels spheres */ - { - cursors(); lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!"); beep(); +int +newsphere(x, y, dir, life) + int x, y, dir, life; +{ + int m; + struct sphere *sp; + if (((sp = (struct sphere *) malloc(sizeof(struct sphere)))) == 0) + return (c[SPHCAST]); /* can't malloc, therefore failure */ + if (dir >= 9) + dir = 0; /* no movement if direction not found */ + if (level == 0) + vxy(&x, &y); /* don't go out of bounds */ + else { + if (x < 1) + x = 1; + if (x >= MAXX - 1) + x = MAXX - 2; + if (y < 1) + y = 1; + if (y >= MAXY - 1) + y = MAXY - 2; + } + if ((m = mitem[x][y]) >= DEMONLORD + 4) { /* demons dispel spheres */ + know[x][y] = 1; + show1cell(x, y);/* show the demon (ha ha) */ + cursors(); + lprintf("\nThe %s dispels the sphere!", monster[m].name); + beep(); + rmsphere(x, y); /* remove any spheres that are here */ + return (c[SPHCAST]); + } + if (m == DISENCHANTRESS) { /* disenchantress cancels spheres */ + cursors(); + lprintf("\nThe %s causes cancellation of the sphere!", monster[m].name); + beep(); +boom: sphboom(x, y); /* blow up stuff around sphere */ + rmsphere(x, y); /* remove any spheres that are here */ + return (c[SPHCAST]); + } + if (c[CANCELLATION]) { /* cancellation cancels spheres */ + cursors(); + lprcat("\nAs the cancellation takes effect, you hear a great earth shaking blast!"); + beep(); goto boom; - } - if (item[x][y]==OANNIHILATION) /* collision of spheres detonates spheres */ - { - cursors(); lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!"); beep(); - rmsphere(x,y); + } + if (item[x][y] == OANNIHILATION) { /* collision of spheres + * detonates spheres */ + cursors(); + lprcat("\nTwo spheres of annihilation collide! You hear a great earth shaking blast!"); + beep(); + rmsphere(x, y); goto boom; - } - if (playerx==x && playery==y) /* collision of sphere and player! */ - { + } + if (playerx == x && playery == y) { /* collision of sphere and + * player! */ cursors(); lprcat("\nYou have been enveloped by the zone of nothingness!\n"); - beep(); rmsphere(x,y); /* remove any spheres that are here */ - nap(4000); died(258); - } - item[x][y]=OANNIHILATION; mitem[x][y]=0; know[x][y]=1; - show1cell(x,y); /* show the new sphere */ - sp->x=x; sp->y=y; sp->lev=level; sp->dir=dir; sp->lifetime=life; sp->p=0; - if (spheres==0) spheres=sp; /* if first node in the sphere list */ - else /* add sphere to beginning of linked list */ - { - sp->p = spheres; spheres = sp; - } - return(++c[SPHCAST]); /* one more sphere in the world */ + beep(); + rmsphere(x, y); /* remove any spheres that are here */ + nap(4000); + died(258); } + item[x][y] = OANNIHILATION; + mitem[x][y] = 0; + know[x][y] = 1; + show1cell(x, y); /* show the new sphere */ + sp->x = x; + sp->y = y; + sp->lev = level; + sp->dir = dir; + sp->lifetime = life; + sp->p = 0; + if (spheres == 0) + spheres = sp; /* if first node in the sphere list */ + else { /* add sphere to beginning of linked list */ + sp->p = spheres; + spheres = sp; + } + return (++c[SPHCAST]); /* one more sphere in the world */ +} /* - * rmsphere(x,y) Function to delete a sphere of annihilation from list - * int x,y; + * rmsphere(x,y) Function to delete a sphere of annihilation from list + * int x,y; * - * Enter with the coordinates of the sphere (on current level) - * Returns the number of spheres currently in existence + * Enter with the coordinates of the sphere (on current level) + * Returns the number of spheres currently in existence */ -rmsphere(x,y) - int x,y; - { - register struct sphere *sp,*sp2=0; - for (sp=spheres; sp; sp2=sp,sp=sp->p) - if (level==sp->lev) /* is sphere on this level? */ - if ((x==sp->x) && (y==sp->y)) /* locate sphere at this location */ - { - item[x][y]=mitem[x][y]=0; know[x][y]=1; - show1cell(x,y); /* show the now missing sphere */ - --c[SPHCAST]; - if (sp==spheres) { sp2=sp; spheres=sp->p; free((char*)sp2); } - else - { sp2->p = sp->p; free((char*)sp); } - break; +int +rmsphere(x, y) + int x, y; +{ + struct sphere *sp, *sp2 = 0; + for (sp = spheres; sp; sp2 = sp, sp = sp->p) + if (level == sp->lev) /* is sphere on this level? */ + if ((x == sp->x) && (y == sp->y)) { /* locate sphere at this + * location */ + item[x][y] = mitem[x][y] = 0; + know[x][y] = 1; + show1cell(x, y); /* show the now missing + * sphere */ + --c[SPHCAST]; + if (sp == spheres) { + sp2 = sp; + spheres = sp->p; + free((char *) sp2); + } else { + sp2->p = sp->p; + free((char *) sp); + } + break; } - return(c[SPHCAST]); /* return number of spheres in the world */ - } + return (c[SPHCAST]); /* return number of spheres in the world */ +} /* - * sphboom(x,y) Function to perform the effects of a sphere detonation - * int x,y; + * sphboom(x,y) Function to perform the effects of a sphere detonation + * int x,y; * - * Enter with the coordinates of the blast, Returns no value + * Enter with the coordinates of the blast, Returns no value */ -sphboom(x,y) - int x,y; - { - register int i,j; - if (c[HOLDMONST]) c[HOLDMONST]=1; - if (c[CANCELLATION]) c[CANCELLATION]=1; - for (j=max(1,x-2); j<min(x+3,MAXX-1); j++) - for (i=max(1,y-2); i<min(y+3,MAXY-1); i++) - { - item[j][i]=mitem[j][i]=0; - show1cell(j,i); - if (playerx==j && playery==i) - { - cursors(); beep(); - lprcat("\nYou were too close to the sphere!"); - nap(3000); - died(283); /* player killed in explosion */ +void +sphboom(x, y) + int x, y; +{ + int i, j; + if (c[HOLDMONST]) + c[HOLDMONST] = 1; + if (c[CANCELLATION]) + c[CANCELLATION] = 1; + for (j = max(1, x - 2); j < min(x + 3, MAXX - 1); j++) + for (i = max(1, y - 2); i < min(y + 3, MAXY - 1); i++) { + item[j][i] = mitem[j][i] = 0; + show1cell(j, i); + if (playerx == j && playery == i) { + cursors(); + beep(); + lprcat("\nYou were too close to the sphere!"); + nap(3000); + died(283); /* player killed in explosion */ } } - } +} /* - * genmonst() Function to ask for monster and genocide from game + * genmonst() Function to ask for monster and genocide from game * - * This is done by setting a flag in the monster[] structure + * This is done by setting a flag in the monster[] structure */ +void genmonst() - { - register int i,j; - cursors(); lprcat("\nGenocide what monster? "); - for (i=0; (!isalpha(i)) && (i!=' '); i=getchar()); +{ + int i, j; + cursors(); + lprcat("\nGenocide what monster? "); + for (i = 0; (!isalpha(i)) && (i != ' '); i = getchar()); lprc(i); - for (j=0; j<MAXMONST; j++) /* search for the monster type */ - if (monstnamelist[j]==i) /* have we found it? */ - { - monster[j].genocided=1; /* genocided from game */ - lprintf(" There will be no more %s's",monster[j].name); + for (j = 0; j < MAXMONST; j++) /* search for the monster type */ + if (monstnamelist[j] == i) { /* have we found it? */ + monster[j].genocided = 1; /* genocided from game */ + lprintf(" There will be no more %s's", monster[j].name); /* now wipe out monsters on this level */ - newcavelevel(level); draws(0,MAXX,0,MAXY); bot_linex(); + newcavelevel(level); + draws(0, MAXX, 0, MAXY); + bot_linex(); return; - } + } lprcat(" You sense failure!"); - } - +} diff --git a/larn/moreobj.c b/larn/moreobj.c index 737154f2..7c6766f7 100644 --- a/larn/moreobj.c +++ b/larn/moreobj.c @@ -1,19 +1,24 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: moreobj.c,v 1.3 1995/03/23 08:33:54 cgd Exp $"; -#endif /* not lint */ +/* $NetBSD: moreobj.c,v 1.4 1997/10/18 20:03:32 christos Exp $ */ -/* moreobj.c Larn is copyrighted 1986 by Noah Morgan. - * - * Routines in this file: - * - * oaltar() - * othrone() - * ochest() - * ofountain() +/* + * moreobj.c Larn is copyrighted 1986 by Noah Morgan. + * + * Routines in this file: + * + * oaltar() othrone() ochest() ofountain() */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: moreobj.c,v 1.4 1997/10/18 20:03:32 christos Exp $"); +#endif /* not lint */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> #include "header.h" +#include "extern.h" -static void ohear(); +static void ohear __P((void)); +static void fch __P((int, long *)); /* * ****** @@ -22,96 +27,115 @@ static void ohear(); * * subroutine to process an altar object */ +void oaltar() - { - unsigned long k; +{ + unsigned long k; - lprcat("\nDo you (p) pray (d) desecrate"); iopts(); - while (1) - { - while (1) switch(getchar()) - { - case 'p': lprcat(" pray\nDo you (m) give money or (j) just pray? "); - while (1) switch(getchar()) - { - case 'j': if (rnd(100)<75) - lprcat("\nnothing happens"); - else if (rnd(13)<4) ohear(); - else if (rnd(43) == 10) - { - if (c[WEAR]) lprcat("\nYou feel your armor vibrate for a moment"); - enchantarmor(); return; - } - else if (rnd(43) == 10) - { - if (c[WIELD]) lprcat("\nYou feel your weapon vibrate for a moment"); - enchweapon(); return; - } - else createmonster(makemonst(level+1)); - return; - - case 'm': lprcat("\n\n"); cursor(1,24); cltoeoln(); - cursor(1,23); cltoeoln(); - lprcat("how much do you donate? "); - k = readnum((long)c[GOLD]); - if (c[GOLD]<k) - { - lprcat("\nYou don't have that much!"); - return; - } - c[GOLD] -= k; - if (k < c[GOLD]/10 || k<rnd(50)) - { createmonster(makemonst(level+1)); c[AGGRAVATE] += 200; } - else if (rnd(101) > 50) { ohear(); return; } - else if (rnd(43) == 5) - { - if (c[WEAR]) lprcat("\nYou feel your armor vibrate for a moment"); - enchantarmor(); return; - } - else if (rnd(43) == 8) - { - if (c[WIELD]) lprcat("\nYou feel your weapon vibrate for a moment"); - enchweapon(); return; - } - else lprcat("\nThank You."); - bottomline(); return; - - case '\33': return; - }; - - case 'd': lprcat(" desecrate"); - if (rnd(100)<60) - { createmonster(makemonst(level+2)+8); c[AGGRAVATE] += 2500; } - else - if (rnd(101)<30) - { - lprcat("\nThe altar crumbles into a pile of dust before your eyes"); - forget(); /* remember to destroy the altar */ + lprcat("\nDo you (p) pray (d) desecrate"); + iopts(); + while (1) { + while (1) + switch (getchar()) { + case 'p': + lprcat(" pray\nDo you (m) give money or (j) just pray? "); + while (1) + switch (getchar()) { + case 'j': + if (rnd(100) < 75) + lprcat("\nnothing happens"); + else if (rnd(13) < 4) + ohear(); + else if (rnd(43) == 10) { + if (c[WEAR]) + lprcat("\nYou feel your armor vibrate for a moment"); + enchantarmor(); + return; + } else if (rnd(43) == 10) { + if (c[WIELD]) + lprcat("\nYou feel your weapon vibrate for a moment"); + enchweapon(); + return; + } else + createmonster(makemonst(level + 1)); + return; + + case 'm': + lprcat("\n\n"); + cursor(1, 24); + cltoeoln(); + cursor(1, 23); + cltoeoln(); + lprcat("how much do you donate? "); + k = readnum((long) c[GOLD]); + if (c[GOLD] < k) { + lprcat("\nYou don't have that much!"); + return; } - else - lprcat("\nnothing happens"); - return; + c[GOLD] -= k; + if (k < c[GOLD] / 10 || k < rnd(50)) { + createmonster(makemonst(level + 1)); + c[AGGRAVATE] += 200; + } else if (rnd(101) > 50) { + ohear(); + return; + } else if (rnd(43) == 5) { + if (c[WEAR]) + lprcat("\nYou feel your armor vibrate for a moment"); + enchantarmor(); + return; + } else if (rnd(43) == 8) { + if (c[WIELD]) + lprcat("\nYou feel your weapon vibrate for a moment"); + enchweapon(); + return; + } else + lprcat("\nThank You."); + bottomline(); + return; - case 'i': - case '\33': ignore(); - if (rnd(100)<30) { createmonster(makemonst(level+1)); c[AGGRAVATE] += rnd(450); } - else lprcat("\nnothing happens"); - return; - }; - } + case '\33': + return; + }; + + case 'd': + lprcat(" desecrate"); + if (rnd(100) < 60) { + createmonster(makemonst(level + 2) + 8); + c[AGGRAVATE] += 2500; + } else if (rnd(101) < 30) { + lprcat("\nThe altar crumbles into a pile of dust before your eyes"); + forget(); /* remember to destroy + * the altar */ + } else + lprcat("\nnothing happens"); + return; + + case 'i': + case '\33': + ignore(); + if (rnd(100) < 30) { + createmonster(makemonst(level + 1)); + c[AGGRAVATE] += rnd(450); + } else + lprcat("\nnothing happens"); + return; + }; } +} /* function to cast a +3 protection on the player */ static void ohear() - { +{ lprcat("\nYou have been heard!"); - if (c[ALTPRO]==0) c[MOREDEFENSES]+=3; + if (c[ALTPRO] == 0) + c[MOREDEFENSES] += 3; c[ALTPRO] += 500; /* protection field */ bottomline(); - } +} /* ******* @@ -120,68 +144,85 @@ ohear() subroutine to process a throne object */ +void othrone(arg) - int arg; - { - register int i,k; + int arg; +{ + int i, k; - lprcat("\nDo you (p) pry off jewels, (s) sit down"); iopts(); - while (1) - { - while (1) switch(getchar()) - { - case 'p': lprcat(" pry off"); k=rnd(101); - if (k<25) - { - for (i=0; i<rnd(4); i++) creategem(); /* gems pop off the throne */ - item[playerx][playery]=ODEADTHRONE; - know[playerx][playery]=0; - } - else if (k<40 && arg==0) - { - createmonster(GNOMEKING); - item[playerx][playery]=OTHRONE2; - know[playerx][playery]=0; - } - else lprcat("\nnothing happens"); - return; - - case 's': lprcat(" sit down"); k=rnd(101); - if (k<30 && arg==0) - { - createmonster(GNOMEKING); - item[playerx][playery]=OTHRONE2; - know[playerx][playery]=0; - } - else if (k<35) { lprcat("\nZaaaappp! You've been teleported!\n"); beep(); oteleport(0); } - else lprcat("\nnothing happens"); - return; + lprcat("\nDo you (p) pry off jewels, (s) sit down"); + iopts(); + while (1) { + while (1) + switch (getchar()) { + case 'p': + lprcat(" pry off"); + k = rnd(101); + if (k < 25) { + for (i = 0; i < rnd(4); i++) + creategem(); /* gems pop off the + * throne */ + item[playerx][playery] = ODEADTHRONE; + know[playerx][playery] = 0; + } else if (k < 40 && arg == 0) { + createmonster(GNOMEKING); + item[playerx][playery] = OTHRONE2; + know[playerx][playery] = 0; + } else + lprcat("\nnothing happens"); + return; - case 'i': - case '\33': ignore(); return; - }; - } + case 's': + lprcat(" sit down"); + k = rnd(101); + if (k < 30 && arg == 0) { + createmonster(GNOMEKING); + item[playerx][playery] = OTHRONE2; + know[playerx][playery] = 0; + } else if (k < 35) { + lprcat("\nZaaaappp! You've been teleported!\n"); + beep(); + oteleport(0); + } else + lprcat("\nnothing happens"); + return; + + case 'i': + case '\33': + ignore(); + return; + }; } +} +void odeadthrone() - { - register int k; +{ + int k; - lprcat("\nDo you (s) sit down"); iopts(); - while (1) - { - while (1) switch(getchar()) - { - case 's': lprcat(" sit down"); k=rnd(101); - if (k<35) { lprcat("\nZaaaappp! You've been teleported!\n"); beep(); oteleport(0); } - else lprcat("\nnothing happens"); - return; + lprcat("\nDo you (s) sit down"); + iopts(); + while (1) { + while (1) + switch (getchar()) { + case 's': + lprcat(" sit down"); + k = rnd(101); + if (k < 35) { + lprcat("\nZaaaappp! You've been teleported!\n"); + beep(); + oteleport(0); + } else + lprcat("\nnothing happens"); + return; - case 'i': - case '\33': ignore(); return; - }; - } + case 'i': + case '\33': + ignore(); + return; + }; } +} /* ****** @@ -190,55 +231,68 @@ odeadthrone() subroutine to process a throne object */ +void ochest() - { - register int i,k; - lprcat("\nDo you (t) take it, (o) try to open it"); iopts(); - while (1) - { - while (1) switch(getchar()) - { - case 'o': lprcat(" open it"); k=rnd(101); - if (k<40) - { - lprcat("\nThe chest explodes as you open it"); beep(); - i = rnd(10); lastnum=281; /* in case he dies */ - lprintf("\nYou suffer %d hit points damage!",(long)i); - checkloss(i); - switch(rnd(10)) /* see if he gets a curse */ - { - case 1: c[ITCHING]+= rnd(1000)+100; - lprcat("\nYou feel an irritation spread over your skin!"); - beep(); - break; - - case 2: c[CLUMSINESS]+= rnd(1600)+200; - lprcat("\nYou begin to lose hand to eye coordination!"); - beep(); - break; - - case 3: c[HALFDAM]+= rnd(1600)+200; - beep(); - lprcat("\nA sickness engulfs you!"); break; - }; - item[playerx][playery]=know[playerx][playery]=0; - if (rnd(100)<69) creategem(); /* gems from the chest */ - dropgold(rnd(110*iarg[playerx][playery]+200)); - for (i=0; i<rnd(4); i++) something(iarg[playerx][playery]+2); - } - else lprcat("\nnothing happens"); - return; +{ + int i, k; + lprcat("\nDo you (t) take it, (o) try to open it"); + iopts(); + while (1) { + while (1) + switch (getchar()) { + case 'o': + lprcat(" open it"); + k = rnd(101); + if (k < 40) { + lprcat("\nThe chest explodes as you open it"); + beep(); + i = rnd(10); + lastnum = 281; /* in case he dies */ + lprintf("\nYou suffer %d hit points damage!", (long) i); + checkloss(i); + switch (rnd(10)) { /* see if he gets a + * curse */ + case 1: + c[ITCHING] += rnd(1000) + 100; + lprcat("\nYou feel an irritation spread over your skin!"); + beep(); + break; - case 't': lprcat(" take"); - if (take(OCHEST,iarg[playerx][playery])==0) - item[playerx][playery]=know[playerx][playery]=0; - return; + case 2: + c[CLUMSINESS] += rnd(1600) + 200; + lprcat("\nYou begin to lose hand to eye coordination!"); + beep(); + break; - case 'i': - case '\33': ignore(); return; - }; - } + case 3: + c[HALFDAM] += rnd(1600) + 200; + beep(); + lprcat("\nA sickness engulfs you!"); + break; + }; + item[playerx][playery] = know[playerx][playery] = 0; + if (rnd(100) < 69) + creategem(); /* gems from the chest */ + dropgold(rnd(110 * iarg[playerx][playery] + 200)); + for (i = 0; i < rnd(4); i++) + something(iarg[playerx][playery] + 2); + } else + lprcat("\nnothing happens"); + return; + + case 't': + lprcat(" take"); + if (take(OCHEST, iarg[playerx][playery]) == 0) + item[playerx][playery] = know[playerx][playery] = 0; + return; + + case 'i': + case '\33': + ignore(); + return; + }; } +} /* ********* @@ -246,64 +300,70 @@ ochest() ********* */ +void ofountain() - { - register int x; +{ + int x; cursors(); - lprcat("\nDo you (d) drink, (w) wash yourself"); iopts(); - while (1) switch(getchar()) - { - case 'd': lprcat("drink"); - if (rnd(1501)<2) - { - lprcat("\nOops! You seem to have caught the dreadful sleep!"); - beep(); lflush(); sleep(3); died(280); return; - } - x = rnd(100); - if (x<7) - { - c[HALFDAM] += 200+rnd(200); - lprcat("\nYou feel a sickness coming on"); - } - else if (x<13) quaffpotion(23); /* see invisible */ - else if (x < 45) - lprcat("\nnothing seems to have happened"); - else if (rnd(3) != 2) - fntchange(1); /* change char levels upward */ - else - fntchange(-1); /* change char levels downward */ - if (rnd(12)<3) - { - lprcat("\nThe fountains bubbling slowly quiets"); - item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */ - know[playerx][playery]=0; - } - return; + lprcat("\nDo you (d) drink, (w) wash yourself"); + iopts(); + while (1) + switch (getchar()) { + case 'd': + lprcat("drink"); + if (rnd(1501) < 2) { + lprcat("\nOops! You seem to have caught the dreadful sleep!"); + beep(); + lflush(); + sleep(3); + died(280); + return; + } + x = rnd(100); + if (x < 7) { + c[HALFDAM] += 200 + rnd(200); + lprcat("\nYou feel a sickness coming on"); + } else if (x < 13) + quaffpotion(23); /* see invisible */ + else if (x < 45) + lprcat("\nnothing seems to have happened"); + else if (rnd(3) != 2) + fntchange(1); /* change char levels upward */ + else + fntchange(-1); /* change char levels + * downward */ + if (rnd(12) < 3) { + lprcat("\nThe fountains bubbling slowly quiets"); + item[playerx][playery] = ODEADFOUNTAIN; /* dead fountain */ + know[playerx][playery] = 0; + } + return; case '\33': - case 'i': ignore(); return; - - case 'w': lprcat("wash yourself"); - if (rnd(100) < 11) - { - x=rnd((level<<2)+2); - lprintf("\nOh no! The water was foul! You suffer %d hit points!",(long)x); - lastnum=273; losehp(x); bottomline(); cursors(); - } - else - if (rnd(100) < 29) - lprcat("\nYou got the dirt off!"); - else - if (rnd(100) < 31) - lprcat("\nThis water seems to be hard water! The dirt didn't come off!"); - else - if (rnd(100) < 34) - createmonster(WATERLORD); /* make water lord */ - else - lprcat("\nnothing seems to have happened"); - return; + case 'i': + ignore(); + return; + + case 'w': + lprcat("wash yourself"); + if (rnd(100) < 11) { + x = rnd((level << 2) + 2); + lprintf("\nOh no! The water was foul! You suffer %d hit points!", (long) x); + lastnum = 273; + losehp(x); + bottomline(); + cursors(); + } else if (rnd(100) < 29) + lprcat("\nYou got the dirt off!"); + else if (rnd(100) < 31) + lprcat("\nThis water seems to be hard water! The dirt didn't come off!"); + else if (rnd(100) < 34) + createmonster(WATERLORD); /* make water lord */ + else + lprcat("\nnothing seems to have happened"); + return; } - } +} /* *** @@ -313,64 +373,113 @@ ofountain() subroutine to process an up/down of a character attribute for ofountain */ static void -fch(how,x) - int how; - long *x; - { - if (how < 0) { lprcat(" went down by one!"); --(*x); } - else { lprcat(" went up by one!"); (*x)++; } - bottomline(); +fch(how, x) + int how; + long *x; +{ + if (how < 0) { + lprcat(" went down by one!"); + --(*x); + } else { + lprcat(" went up by one!"); + (*x)++; } + bottomline(); +} /* a subroutine to raise or lower character levels if x > 0 they are raised if x < 0 they are lowered */ +void fntchange(how) - int how; - { - register long j; + int how; +{ + long j; lprc('\n'); - switch(rnd(9)) - { - case 1: lprcat("Your strength"); fch(how,&c[0]); break; - case 2: lprcat("Your intelligence"); fch(how,&c[1]); break; - case 3: lprcat("Your wisdom"); fch(how,&c[2]); break; - case 4: lprcat("Your constitution"); fch(how,&c[3]); break; - case 5: lprcat("Your dexterity"); fch(how,&c[4]); break; - case 6: lprcat("Your charm"); fch(how,&c[5]); break; - case 7: j=rnd(level+1); - if (how < 0) - { lprintf("You lose %d hit point",(long)j); if (j>1) lprcat("s!"); else lprc('!'); losemhp((int)j); } - else - { lprintf("You gain %d hit point",(long)j); if (j>1) lprcat("s!"); else lprc('!'); raisemhp((int)j); } - bottomline(); break; - - case 8: j=rnd(level+1); - if (how > 0) - { - lprintf("You just gained %d spell",(long)j); raisemspells((int)j); - if (j>1) lprcat("s!"); else lprc('!'); - } - else - { - lprintf("You just lost %d spell",(long)j); losemspells((int)j); - if (j>1) lprcat("s!"); else lprc('!'); - } - bottomline(); break; - - case 9: j = 5*rnd((level+1)*(level+1)); - if (how < 0) - { - lprintf("You just lost %d experience point",(long)j); - if (j>1) lprcat("s!"); else lprc('!'); loseexperience((long)j); - } - else - { - lprintf("You just gained %d experience point",(long)j); - if (j>1) lprcat("s!"); else lprc('!'); raiseexperience((long)j); - } - break; + switch (rnd(9)) { + case 1: + lprcat("Your strength"); + fch(how, &c[0]); + break; + case 2: + lprcat("Your intelligence"); + fch(how, &c[1]); + break; + case 3: + lprcat("Your wisdom"); + fch(how, &c[2]); + break; + case 4: + lprcat("Your constitution"); + fch(how, &c[3]); + break; + case 5: + lprcat("Your dexterity"); + fch(how, &c[4]); + break; + case 6: + lprcat("Your charm"); + fch(how, &c[5]); + break; + case 7: + j = rnd(level + 1); + if (how < 0) { + lprintf("You lose %d hit point", (long) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + losemhp((int) j); + } else { + lprintf("You gain %d hit point", (long) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + raisemhp((int) j); } - cursors(); + bottomline(); + break; + + case 8: + j = rnd(level + 1); + if (how > 0) { + lprintf("You just gained %d spell", (long) j); + raisemspells((int) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + } else { + lprintf("You just lost %d spell", (long) j); + losemspells((int) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + } + bottomline(); + break; + + case 9: + j = 5 * rnd((level + 1) * (level + 1)); + if (how < 0) { + lprintf("You just lost %d experience point", (long) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + loseexperience((long) j); + } else { + lprintf("You just gained %d experience point", (long) j); + if (j > 1) + lprcat("s!"); + else + lprc('!'); + raiseexperience((long) j); + } + break; } + cursors(); +} diff --git a/larn/movem.c b/larn/movem.c index 6f88ea9b..55a3d27b 100644 --- a/larn/movem.c +++ b/larn/movem.c @@ -1,316 +1,446 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: movem.c,v 1.4 1997/07/13 20:21:37 christos Exp $"; -#endif /* not lint */ +/* $NetBSD: movem.c,v 1.5 1997/10/18 20:03:34 christos Exp $ */ /* - * movem.c (move monster) Larn is copyrighted 1986 by Noah Morgan. + * movem.c (move monster) Larn is copyrighted 1986 by Noah Morgan. * - * Here are the functions in this file: + * Here are the functions in this file: * - * movemonst() Routine to move the monsters toward the player - * movemt(x,y) Function to move a monster at (x,y) -- must determine where - * mmove(x,y,xd,yd) Function to actually perform the monster movement - * movsphere() Function to look for and move spheres of annihilation + * movemonst() Routine to move the monsters toward the player + * movemt(x,y) Function to move a monster at (x,y) -- must determine where + * mmove(x,y,xd,yd) Function to actually perform the monster movement + * movsphere() Function to look for and move spheres of annihilation */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: movem.c,v 1.5 1997/10/18 20:03:34 christos Exp $"); +#endif /* not lint */ + #include "header.h" +#include "extern.h" /* - * movemonst() Routine to move the monsters toward the player + * movemonst() Routine to move the monsters toward the player * - * This routine has the responsibility to determine which monsters are to - * move, and call movemt() to do the move. - * Returns no value. + * This routine has the responsibility to determine which monsters are to + * move, and call movemt() to do the move. + * Returns no value. */ -static short w1[9],w1x[9],w1y[9]; -static int tmp1,tmp2,tmp3,tmp4,distance; +static short w1[9], w1x[9], w1y[9]; +static int tmp1, tmp2, tmp3, tmp4, distance; +void movemonst() - { - register int i,j; - if (c[TIMESTOP]) return; /* no action if time is stopped */ - if (c[HASTESELF]) if ((c[HASTESELF]&1)==0) return; - if (spheres) movsphere(); /* move the spheres of annihilation if any */ - if (c[HOLDMONST]) return; /* no action if monsters are held */ +{ + int i, j; + if (c[TIMESTOP]) + return; /* no action if time is stopped */ + if (c[HASTESELF]) + if ((c[HASTESELF] & 1) == 0) + return; + if (spheres) + movsphere(); /* move the spheres of annihilation if any */ + if (c[HOLDMONST]) + return; /* no action if monsters are held */ - if (c[AGGRAVATE]) /* determine window of monsters to move */ - { - tmp1=playery-5; tmp2=playery+6; tmp3=playerx-10; tmp4=playerx+11; - distance=40; /* depth of intelligent monster movement */ - } - else - { - tmp1=playery-3; tmp2=playery+4; tmp3=playerx-5; tmp4=playerx+6; - distance=17; /* depth of intelligent monster movement */ - } + if (c[AGGRAVATE]) { /* determine window of monsters to move */ + tmp1 = playery - 5; + tmp2 = playery + 6; + tmp3 = playerx - 10; + tmp4 = playerx + 11; + distance = 40; /* depth of intelligent monster movement */ + } else { + tmp1 = playery - 3; + tmp2 = playery + 4; + tmp3 = playerx - 5; + tmp4 = playerx + 6; + distance = 17; /* depth of intelligent monster movement */ + } - if (level == 0) /* if on outside level monsters can move in perimeter */ - { - if (tmp1 < 0) tmp1=0; if (tmp2 > MAXY) tmp2=MAXY; - if (tmp3 < 0) tmp3=0; if (tmp4 > MAXX) tmp4=MAXX; - } - else /* if in a dungeon monsters can't be on the perimeter (wall there) */ - { - if (tmp1 < 1) tmp1=1; if (tmp2 > MAXY-1) tmp2=MAXY-1; - if (tmp3 < 1) tmp3=1; if (tmp4 > MAXX-1) tmp4=MAXX-1; - } + if (level == 0) { /* if on outside level monsters can move in + * perimeter */ + if (tmp1 < 0) + tmp1 = 0; + if (tmp2 > MAXY) + tmp2 = MAXY; + if (tmp3 < 0) + tmp3 = 0; + if (tmp4 > MAXX) + tmp4 = MAXX; + } else { /* if in a dungeon monsters can't be on the + * perimeter (wall there) */ + if (tmp1 < 1) + tmp1 = 1; + if (tmp2 > MAXY - 1) + tmp2 = MAXY - 1; + if (tmp3 < 1) + tmp3 = 1; + if (tmp4 > MAXX - 1) + tmp4 = MAXX - 1; + } - for (j=tmp1; j<tmp2; j++) /* now reset monster moved flags */ - for (i=tmp3; i<tmp4; i++) + for (j = tmp1; j < tmp2; j++) /* now reset monster moved flags */ + for (i = tmp3; i < tmp4; i++) moved[i][j] = 0; - moved[lasthx][lasthy]=0; + moved[lasthx][lasthy] = 0; - if (c[AGGRAVATE] || !c[STEALTH]) /* who gets moved? split for efficiency */ - { - for (j=tmp1; j<tmp2; j++) /* look thru all locations in window */ - for (i=tmp3; i<tmp4; i++) - if (mitem[i][j]) /* if there is a monster to move */ - if (moved[i][j]==0) /* if it has not already been moved */ - movemt(i,j); /* go and move the monster */ - } - else /* not aggravated and not stealth */ - { - for (j=tmp1; j<tmp2; j++) /* look thru all locations in window */ - for (i=tmp3; i<tmp4; i++) - if (mitem[i][j]) /* if there is a monster to move */ - if (moved[i][j]==0) /* if it has not already been moved */ - if (stealth[i][j]) /* if it is asleep due to stealth */ - movemt(i,j); /* go and move the monster */ - } + if (c[AGGRAVATE] || !c[STEALTH]) { /* who gets moved? split for + * efficiency */ + for (j = tmp1; j < tmp2; j++) /* look thru all locations in + * window */ + for (i = tmp3; i < tmp4; i++) + if (mitem[i][j]) /* if there is a monster + * to move */ + if (moved[i][j] == 0) /* if it has not already + * been moved */ + movemt(i, j); /* go and move the + * monster */ + } else { /* not aggravated and not stealth */ + for (j = tmp1; j < tmp2; j++) /* look thru all locations in + * window */ + for (i = tmp3; i < tmp4; i++) + if (mitem[i][j]) /* if there is a monster + * to move */ + if (moved[i][j] == 0) /* if it has not already + * been moved */ + if (stealth[i][j]) /* if it is asleep due + * to stealth */ + movemt(i, j); /* go and move the + * monster */ + } - if (mitem[lasthx][lasthy]) /* now move monster last hit by player if not already moved */ - { - if (moved[lasthx][lasthy]==0) /* if it has not already been moved */ - { - movemt(lasthx,lasthy); - lasthx = w1x[0]; lasthy = w1y[0]; - } + if (mitem[lasthx][lasthy]) { /* now move monster last hit by + * player if not already moved */ + if (moved[lasthx][lasthy] == 0) { /* if it has not already + * been moved */ + movemt(lasthx, lasthy); + lasthx = w1x[0]; + lasthy = w1y[0]; } } +} /* - * movemt(x,y) Function to move a monster at (x,y) -- must determine where - * int x,y; + * movemt(x,y) Function to move a monster at (x,y) -- must determine where + * int x,y; * - * This routine is responsible for determining where one monster at (x,y) will - * move to. Enter with the monsters coordinates in (x,y). - * Returns no value. + * This routine is responsible for determining where one monster at (x,y) will + * move to. Enter with the monsters coordinates in (x,y). + * Returns no value. */ -static int tmpitem,xl,xh,yl,yh; -movemt(i,j) - int i,j; - { - register int k,m,z,tmp,xtmp,ytmp,monst; - switch(monst=mitem[i][j]) /* for half speed monsters */ - { - case TROGLODYTE: case HOBGOBLIN: case METAMORPH: case XVART: - case INVISIBLESTALKER: case ICELIZARD: if ((gltime & 1) == 1) return; - }; +static int tmpitem, xl, xh, yl, yh; +void +movemt(i, j) + int i, j; +{ + int k, m, z, tmp, xtmp, ytmp, monst; + switch (monst = mitem[i][j]) { /* for half speed monsters */ + case TROGLODYTE: + case HOBGOBLIN: + case METAMORPH: + case XVART: + case INVISIBLESTALKER: + case ICELIZARD: + if ((gltime & 1) == 1) + return; + }; - if (c[SCAREMONST]) /* choose destination randomly if scared */ - { - if ((xl = i+rnd(3)-2) < 0) xl=0; if (xl >= MAXX) xl=MAXX-1; - if ((yl = j+rnd(3)-2) < 0) yl=0; if (yl >= MAXY) yl=MAXY-1; - if ((tmp=item[xl][yl]) != OWALL) - if (mitem[xl][yl] == 0) - if ((mitem[i][j] != VAMPIRE) || (tmpitem != OMIRROR)) - if (tmp != OCLOSEDDOOR) mmove(i,j,xl,yl); + if (c[SCAREMONST]) { /* choose destination randomly if scared */ + if ((xl = i + rnd(3) - 2) < 0) + xl = 0; + if (xl >= MAXX) + xl = MAXX - 1; + if ((yl = j + rnd(3) - 2) < 0) + yl = 0; + if (yl >= MAXY) + yl = MAXY - 1; + if ((tmp = item[xl][yl]) != OWALL) + if (mitem[xl][yl] == 0) + if ((mitem[i][j] != VAMPIRE) || (tmpitem != OMIRROR)) + if (tmp != OCLOSEDDOOR) + mmove(i, j, xl, yl); return; - } - - if (monster[monst].intelligence > 10-c[HARDGAME]) /* if smart monster */ -/* intelligent movement here -- first setup screen array */ - { - xl=tmp3-2; yl=tmp1-2; xh=tmp4+2; yh=tmp2+2; - vxy(&xl,&yl); vxy(&xh,&yh); - for (k=yl; k<yh; k++) - for (m=xl; m<xh; m++) - { - switch(item[m][k]) - { - case OWALL: case OPIT: case OTRAPARROW: case ODARTRAP: - case OCLOSEDDOOR: case OTRAPDOOR: case OTELEPORTER: - smm: screen[m][k]=127; break; - case OMIRROR: if (mitem[m][k]==VAMPIRE) goto smm; - default: screen[m][k]= 0; break; - }; - } - screen[playerx][playery]=1; - -/* now perform proximity ripple from playerx,playery to monster */ - xl=tmp3-1; yl=tmp1-1; xh=tmp4+1; yh=tmp2+1; - vxy(&xl,&yl); vxy(&xh,&yh); - for (tmp=1; tmp<distance; tmp++) /* only up to 20 squares away */ - for (k=yl; k<yh; k++) - for (m=xl; m<xh; m++) - if (screen[m][k]==tmp) /* if find proximity n advance it */ - for (z=1; z<9; z++) /* go around in a circle */ - { - if (screen[xtmp=m+diroffx[z]][ytmp=k+diroffy[z]]==0) - screen[xtmp][ytmp]=tmp+1; - if (xtmp==i && ytmp==j) goto out; - } + } + if (monster[monst].intelligence > 10 - c[HARDGAME]) { /* if smart monster */ + /* intelligent movement here -- first setup screen array */ + xl = tmp3 - 2; + yl = tmp1 - 2; + xh = tmp4 + 2; + yh = tmp2 + 2; + vxy(&xl, &yl); + vxy(&xh, &yh); + for (k = yl; k < yh; k++) + for (m = xl; m < xh; m++) { + switch (item[m][k]) { + case OWALL: + case OPIT: + case OTRAPARROW: + case ODARTRAP: + case OCLOSEDDOOR: + case OTRAPDOOR: + case OTELEPORTER: + smm: screen[m][k] = 127; + break; + case OMIRROR: + if (mitem[m][k] == VAMPIRE) + goto smm; + default: + screen[m][k] = 0; + break; + }; + } + screen[playerx][playery] = 1; -out: if (tmp<distance) /* did find connectivity */ - /* now select lowest value around playerx,playery */ - for (z=1; z<9; z++) /* go around in a circle */ - if (screen[xl=i+diroffx[z]][yl=j+diroffy[z]]==tmp) - if (!mitem[xl][yl]) { mmove(i,j,w1x[0]=xl,w1y[0]=yl); return; } - } + /* + * now perform proximity ripple from playerx,playery to + * monster + */ + xl = tmp3 - 1; + yl = tmp1 - 1; + xh = tmp4 + 1; + yh = tmp2 + 1; + vxy(&xl, &yl); + vxy(&xh, &yh); + for (tmp = 1; tmp < distance; tmp++) /* only up to 20 squares + * away */ + for (k = yl; k < yh; k++) + for (m = xl; m < xh; m++) + if (screen[m][k] == tmp) /* if find proximity n + * advance it */ + for (z = 1; z < 9; z++) { /* go around in a circle */ + if (screen[xtmp = m + diroffx[z]][ytmp = k + diroffy[z]] == 0) + screen[xtmp][ytmp] = tmp + 1; + if (xtmp == i && ytmp == j) + goto out; + } +out: if (tmp < distance) /* did find connectivity */ + /* now select lowest value around playerx,playery */ + for (z = 1; z < 9; z++) /* go around in a circle */ + if (screen[xl = i + diroffx[z]][yl = j + diroffy[z]] == tmp) + if (!mitem[xl][yl]) { + mmove(i, j, w1x[0] = xl, w1y[0] = yl); + return; + } + } /* dumb monsters move here */ - xl=i-1; yl=j-1; xh=i+2; yh=j+2; - if (i<playerx) xl++; else if (i>playerx) --xh; - if (j<playery) yl++; else if (j>playery) --yh; - for (k=0; k<9; k++) w1[k] = 10000; + xl = i - 1; + yl = j - 1; + xh = i + 2; + yh = j + 2; + if (i < playerx) + xl++; + else if (i > playerx) + --xh; + if (j < playery) + yl++; + else if (j > playery) + --yh; + for (k = 0; k < 9; k++) + w1[k] = 10000; - for (k=xl; k<xh; k++) - for (m=yl; m<yh; m++) /* for each square compute distance to player */ - { - tmp = k-i+4+3*(m-j); + for (k = xl; k < xh; k++) + for (m = yl; m < yh; m++) { /* for each square compute + * distance to player */ + tmp = k - i + 4 + 3 * (m - j); tmpitem = item[k][m]; - if (tmpitem!=OWALL || (k==playerx && m==playery)) - if (mitem[k][m]==0) - if ((mitem[i][j] != VAMPIRE) || (tmpitem != OMIRROR)) - if (tmpitem!=OCLOSEDDOOR) - { - w1[tmp] = (playerx-k)*(playerx-k)+(playery-m)*(playery-m); - w1x[tmp] = k; w1y[tmp] = m; - } - } + if (tmpitem != OWALL || (k == playerx && m == playery)) + if (mitem[k][m] == 0) + if ((mitem[i][j] != VAMPIRE) || (tmpitem != OMIRROR)) + if (tmpitem != OCLOSEDDOOR) { + w1[tmp] = (playerx - k) * (playerx - k) + (playery - m) * (playery - m); + w1x[tmp] = k; + w1y[tmp] = m; + } + } tmp = 0; - for (k=1; k<9; k++) if (w1[tmp] > w1[k]) tmp=k; + for (k = 1; k < 9; k++) + if (w1[tmp] > w1[k]) + tmp = k; if (w1[tmp] < 10000) - if ((i!=w1x[tmp]) || (j!=w1y[tmp])) - mmove(i,j,w1x[tmp],w1y[tmp]); - } + if ((i != w1x[tmp]) || (j != w1y[tmp])) + mmove(i, j, w1x[tmp], w1y[tmp]); +} /* - * mmove(x,y,xd,yd) Function to actually perform the monster movement - * int x,y,xd,yd; + * mmove(x,y,xd,yd) Function to actually perform the monster movement + * int x,y,xd,yd; * - * Enter with the from coordinates in (x,y) and the destination coordinates - * in (xd,yd). + * Enter with the from coordinates in (x,y) and the destination coordinates + * in (xd,yd). */ -mmove(aa,bb,cc,dd) - int aa,bb,cc,dd; - { - register int tmp,i,flag; - char *who,*p; - flag=0; /* set to 1 if monster hit by arrow trap */ - if ((cc==playerx) && (dd==playery)) - { - hitplayer(aa,bb); moved[aa][bb] = 1; return; - } - i=item[cc][dd]; - if ((i==OPIT) || (i==OTRAPDOOR)) - switch(mitem[aa][bb]) - { - case SPIRITNAGA: case PLATINUMDRAGON: case WRAITH: - case VAMPIRE: case SILVERDRAGON: case POLTERGEIST: - case DEMONLORD: case DEMONLORD+1: case DEMONLORD+2: - case DEMONLORD+3: case DEMONLORD+4: case DEMONLORD+5: - case DEMONLORD+6: case DEMONPRINCE: break; +void +mmove(aa, bb, cc, dd) + int aa, bb, cc, dd; +{ + int tmp, i, flag; + char *who = NULL, *p; + flag = 0; /* set to 1 if monster hit by arrow trap */ + if ((cc == playerx) && (dd == playery)) { + hitplayer(aa, bb); + moved[aa][bb] = 1; + return; + } + i = item[cc][dd]; + if ((i == OPIT) || (i == OTRAPDOOR)) + switch (mitem[aa][bb]) { + case SPIRITNAGA: + case PLATINUMDRAGON: + case WRAITH: + case VAMPIRE: + case SILVERDRAGON: + case POLTERGEIST: + case DEMONLORD: + case DEMONLORD + 1: + case DEMONLORD + 2: + case DEMONLORD + 3: + case DEMONLORD + 4: + case DEMONLORD + 5: + case DEMONLORD + 6: + case DEMONPRINCE: + break; - default: mitem[aa][bb]=0; /* fell in a pit or trapdoor */ + default: + mitem[aa][bb] = 0; /* fell in a pit or trapdoor */ }; tmp = mitem[cc][dd] = mitem[aa][bb]; - if (i==OANNIHILATION) - { - if (tmp>=DEMONLORD+3) /* demons dispel spheres */ - { + if (i == OANNIHILATION) { + if (tmp >= DEMONLORD + 3) { /* demons dispel spheres */ cursors(); - lprintf("\nThe %s dispels the sphere!",monster[tmp].name); - rmsphere(cc,dd); /* delete the sphere */ - } - else i=tmp=mitem[cc][dd]=0; - } - stealth[cc][dd]=1; - if ((hitp[cc][dd] = hitp[aa][bb]) < 0) hitp[cc][dd]=1; - mitem[aa][bb] = 0; moved[cc][dd] = 1; + lprintf("\nThe %s dispels the sphere!", monster[tmp].name); + rmsphere(cc, dd); /* delete the sphere */ + } else + i = tmp = mitem[cc][dd] = 0; + } + stealth[cc][dd] = 1; + if ((hitp[cc][dd] = hitp[aa][bb]) < 0) + hitp[cc][dd] = 1; + mitem[aa][bb] = 0; + moved[cc][dd] = 1; if (tmp == LEPRECHAUN) - switch(i) - { - case OGOLDPILE: case OMAXGOLD: case OKGOLD: case ODGOLD: - case ODIAMOND: case ORUBY: case OEMERALD: case OSAPPHIRE: - item[cc][dd] = 0; /* leprechaun takes gold */ - }; + switch (i) { + case OGOLDPILE: + case OMAXGOLD: + case OKGOLD: + case ODGOLD: + case ODIAMOND: + case ORUBY: + case OEMERALD: + case OSAPPHIRE: + item[cc][dd] = 0; /* leprechaun takes gold */ + }; - if (tmp == TROLL) /* if a troll regenerate him */ + if (tmp == TROLL) /* if a troll regenerate him */ if ((gltime & 1) == 0) - if (monster[tmp].hitpoints > hitp[cc][dd]) hitp[cc][dd]++; + if (monster[tmp].hitpoints > hitp[cc][dd]) + hitp[cc][dd]++; - if (i==OTRAPARROW) /* arrow hits monster */ - { who = "An arrow"; if ((hitp[cc][dd] -= rnd(10)+level) <= 0) - { mitem[cc][dd]=0; flag=2; } else flag=1; } - if (i==ODARTRAP) /* dart hits monster */ - { who = "A dart"; if ((hitp[cc][dd] -= rnd(6)) <= 0) - { mitem[cc][dd]=0; flag=2; } else flag=1; } - if (i==OTELEPORTER) /* monster hits teleport trap */ - { flag=3; fillmonst(mitem[cc][dd]); mitem[cc][dd]=0; } - if (c[BLINDCOUNT]) return; /* if blind don't show where monsters are */ - if (know[cc][dd] & 1) - { - p=0; - if (flag) cursors(); - switch(flag) - { - case 1: p="\n%s hits the %s"; break; - case 2: p="\n%s hits and kills the %s"; break; - case 3: p="\nThe %s%s gets teleported"; who=""; break; - }; - if (p) { lprintf(p,who,monster[tmp].name); beep(); } + if (i == OTRAPARROW) { /* arrow hits monster */ + who = "An arrow"; + if ((hitp[cc][dd] -= rnd(10) + level) <= 0) { + mitem[cc][dd] = 0; + flag = 2; + } else + flag = 1; + } + if (i == ODARTRAP) { /* dart hits monster */ + who = "A dart"; + if ((hitp[cc][dd] -= rnd(6)) <= 0) { + mitem[cc][dd] = 0; + flag = 2; + } else + flag = 1; + } + if (i == OTELEPORTER) { /* monster hits teleport trap */ + flag = 3; + fillmonst(mitem[cc][dd]); + mitem[cc][dd] = 0; + } + if (c[BLINDCOUNT]) + return; /* if blind don't show where monsters are */ + if (know[cc][dd] & 1) { + p = 0; + if (flag) + cursors(); + switch (flag) { + case 1: + p = "\n%s hits the %s"; + break; + case 2: + p = "\n%s hits and kills the %s"; + break; + case 3: + p = "\nThe %s%s gets teleported"; + who = ""; + break; + }; + if (p) { + lprintf(p, who, monster[tmp].name); + beep(); } -/* if (yrepcount>1) { know[aa][bb] &= 2; know[cc][dd] &= 2; return; } */ - if (know[aa][bb] & 1) show1cell(aa,bb); - if (know[cc][dd] & 1) show1cell(cc,dd); } + /* + * if (yrepcount>1) { know[aa][bb] &= 2; know[cc][dd] &= 2; return; + * } + */ + if (know[aa][bb] & 1) + show1cell(aa, bb); + if (know[cc][dd] & 1) + show1cell(cc, dd); +} /* - * movsphere() Function to look for and move spheres of annihilation + * movsphere() Function to look for and move spheres of annihilation * - * This function works on the sphere linked list, first duplicating the list - * (the act of moving changes the list), then processing each sphere in order - * to move it. They eat anything in their way, including stairs, volcanic - * shafts, potions, etc, except for upper level demons, who can dispel - * spheres. - * No value is returned. + * This function works on the sphere linked list, first duplicating the list + * (the act of moving changes the list), then processing each sphere in order + * to move it. They eat anything in their way, including stairs, volcanic + * shafts, potions, etc, except for upper level demons, who can dispel + * spheres. + * No value is returned. */ -#define SPHMAX 20 /* maximum number of spheres movsphere can handle */ +#define SPHMAX 20 /* maximum number of spheres movsphere can + * handle */ +void movsphere() - { - register int x,y,dir,len; - register struct sphere *sp,*sp2; - struct sphere sph[SPHMAX]; +{ + int x, y, dir, len; + struct sphere *sp, *sp2; + struct sphere sph[SPHMAX]; /* first duplicate sphere list */ - for (sp=0,x=0,sp2=spheres; sp2; sp2=sp2->p) /* look through sphere list */ - if (sp2->lev == level) /* only if this level */ - { - sph[x] = *sp2; sph[x++].p = 0; /* copy the struct */ - if (x>1) sph[x-2].p = &sph[x-1]; /* link pointers */ + for (sp = 0, x = 0, sp2 = spheres; sp2; sp2 = sp2->p) /* look through sphere + * list */ + if (sp2->lev == level) { /* only if this level */ + sph[x] = *sp2; + sph[x++].p = 0; /* copy the struct */ + if (x > 1) + sph[x - 2].p = &sph[x - 1]; /* link pointers */ } - if (x) sp= sph; /* if any spheres, point to them */ - else return; /* no spheres */ + if (x) + sp = sph; /* if any spheres, point to them */ + else + return; /* no spheres */ - for (sp=sph; sp; sp=sp->p) /* look through sphere list */ - { - x = sp->x; y = sp->y; - if (item[x][y]!=OANNIHILATION) continue; /* not really there */ - if (--(sp->lifetime) < 0) /* has sphere run out of gas? */ - { - rmsphere(x,y); /* delete sphere */ + for (sp = sph; sp; sp = sp->p) { /* look through sphere list */ + x = sp->x; + y = sp->y; + if (item[x][y] != OANNIHILATION) + continue; /* not really there */ + if (--(sp->lifetime) < 0) { /* has sphere run out of gas? */ + rmsphere(x, y); /* delete sphere */ continue; - } - switch(rnd((int)max(7,c[INTELLIGENCE]>>1))) /* time to move the sphere */ - { - case 1: - case 2: /* change direction to a random one */ - sp->dir = rnd(8); - default: /* move in normal direction */ - dir = sp->dir; len = sp->lifetime; - rmsphere(x,y); - newsphere(x+diroffx[dir],y+diroffy[dir],dir,len); - }; } + switch (rnd((int) max(7, c[INTELLIGENCE] >> 1))) { /* time to move the + * sphere */ + case 1: + case 2: /* change direction to a random one */ + sp->dir = rnd(8); + default: /* move in normal direction */ + dir = sp->dir; + len = sp->lifetime; + rmsphere(x, y); + newsphere(x + diroffx[dir], y + diroffy[dir], dir, len); + }; } +} @@ -1,18 +1,24 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: nap.c,v 1.4 1995/04/27 22:15:28 mycroft Exp $"; -#endif /* not lint */ +/* $NetBSD: nap.c,v 1.5 1997/10/18 20:03:36 christos Exp $ */ /* nap.c Larn is copyrighted 1986 by Noah Morgan. */ -#include <signal.h> -#include <sys/types.h> +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: nap.c,v 1.5 1997/10/18 20:03:36 christos Exp $"); +#endif /* not lint */ + +#include <unistd.h> +#include "header.h" +#include "extern.h" /* * routine to take a nap for n milliseconds */ +void nap(x) - register int x; - { - if (x<=0) return; /* eliminate chance for infinite loop */ + int x; +{ + if (x <= 0) + return; /* eliminate chance for infinite loop */ lflush(); - usleep(x*1000); - } + usleep(x * 1000); +} diff --git a/larn/object.c b/larn/object.c index 7ee92633..60950a44 100644 --- a/larn/object.c +++ b/larn/object.c @@ -1,9 +1,13 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: object.c,v 1.7 1997/07/13 20:21:38 christos Exp $"; -#endif /* not lint */ +/* $NetBSD: object.c,v 1.8 1997/10/18 20:03:38 christos Exp $ */ + +/* object.c Larn is copyrighted 1986 by Noah Morgan. */ -/* object.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: object.c,v 1.8 1997/10/18 20:03:38 christos Exp $"); +#endif /* not lint */ #include "header.h" +#include "extern.h" /* *************** @@ -13,275 +17,526 @@ static char rcsid[] = "$NetBSD: object.c,v 1.7 1997/07/13 20:21:38 christos Exp subroutine to look for an object and give the player his options if an object was found. */ +void lookforobject() { -register int i,j; -if (c[TIMESTOP]) return; /* can't find objects is time is stopped */ -i=item[playerx][playery]; if (i==0) return; -showcell(playerx,playery); cursors(); yrepcount=0; -switch(i) - { - case OGOLDPILE: case OMAXGOLD: - case OKGOLD: case ODGOLD: lprcat("\n\nYou have found some gold!"); ogold(i); break; - - case OPOTION: lprcat("\n\nYou have found a magic potion"); - i = iarg[playerx][playery]; - if (potionname[i][0]!=0) lprintf(" of%s", potionname[i]); - opotion(i); break; - - case OSCROLL: lprcat("\n\nYou have found a magic scroll"); - i = iarg[playerx][playery]; - if (scrollname[i][0]!=0) lprintf(" of%s", scrollname[i]); - oscroll(i); break; - - case OALTAR: if (nearbymonst()) return; - lprcat("\n\nThere is a Holy Altar here!"); oaltar(); break; - - case OBOOK: lprcat("\n\nYou have found a book."); obook(); break; - - case OCOOKIE: lprcat("\n\nYou have found a fortune cookie."); ocookie(); break; - - case OTHRONE: if (nearbymonst()) return; - lprintf("\n\nThere is %s here!",objectname[i]); othrone(0); break; - - case OTHRONE2: if (nearbymonst()) return; - lprintf("\n\nThere is %s here!",objectname[i]); othrone(1); break; - - case ODEADTHRONE: lprintf("\n\nThere is %s here!",objectname[i]); odeadthrone(); break; - - case OORB: lprcat("\n\nYou have found the Orb!!!!!"); oorb(); break; - - case OPIT: lprcat("\n\nYou're standing at the top of a pit."); opit(); break; - - case OSTAIRSUP: lprcat("\n\nThere is a circular staircase here"); ostairs(1); /* up */ break; - - case OELEVATORUP: lprcat("\n\nYou feel heavy for a moment, but the feeling disappears"); - oelevator(1); /* up */ break; - - case OFOUNTAIN: if (nearbymonst()) return; - lprcat("\n\nThere is a fountain here"); ofountain(); break; - - case OSTATUE: if (nearbymonst()) return; - lprcat("\n\nYou are standing in front of a statue"); ostatue(); break; - - case OCHEST: lprcat("\n\nThere is a chest here"); ochest(); break; - - case OIVTELETRAP: if (rnd(11)<6) return; - item[playerx][playery] = OTELEPORTER; - know[playerx][playery] = 1; - - case OTELEPORTER: lprcat("\nZaaaappp! You've been teleported!\n"); - beep(); nap(3000); oteleport(0); - break; - - case OSCHOOL: if (nearbymonst()) return; - lprcat("\n\nYou have found the College of Larn."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') { oschool(); /* the college of larn */ } - else lprcat(" stay here"); - break; - - case OMIRROR: if (nearbymonst()) return; - lprcat("\n\nThere is a mirror here"); omirror(); break; + int i, j; + if (c[TIMESTOP]) + return; /* can't find objects is time is stopped */ + i = item[playerx][playery]; + if (i == 0) + return; + showcell(playerx, playery); + cursors(); + yrepcount = 0; + switch (i) { + case OGOLDPILE: + case OMAXGOLD: + case OKGOLD: + case ODGOLD: + lprcat("\n\nYou have found some gold!"); + ogold(i); + break; + + case OPOTION: + lprcat("\n\nYou have found a magic potion"); + i = iarg[playerx][playery]; + if (potionname[i][0] != 0) + lprintf(" of%s", potionname[i]); + opotion(i); + break; + + case OSCROLL: + lprcat("\n\nYou have found a magic scroll"); + i = iarg[playerx][playery]; + if (scrollname[i][0] != 0) + lprintf(" of%s", scrollname[i]); + oscroll(i); + break; + + case OALTAR: + if (nearbymonst()) + return; + lprcat("\n\nThere is a Holy Altar here!"); + oaltar(); + break; + + case OBOOK: + lprcat("\n\nYou have found a book."); + obook(); + break; + + case OCOOKIE: + lprcat("\n\nYou have found a fortune cookie."); + ocookie(); + break; + + case OTHRONE: + if (nearbymonst()) + return; + lprintf("\n\nThere is %s here!", objectname[i]); + othrone(0); + break; + + case OTHRONE2: + if (nearbymonst()) + return; + lprintf("\n\nThere is %s here!", objectname[i]); + othrone(1); + break; + + case ODEADTHRONE: + lprintf("\n\nThere is %s here!", objectname[i]); + odeadthrone(); + break; + + case OORB: + lprcat("\n\nYou have found the Orb!!!!!"); + oorb(); + break; + + case OPIT: + lprcat("\n\nYou're standing at the top of a pit."); + opit(); + break; + + case OSTAIRSUP: + lprcat("\n\nThere is a circular staircase here"); + ostairs(1); /* up */ + break; + + case OELEVATORUP: + lprcat("\n\nYou feel heavy for a moment, but the feeling disappears"); + oelevator(1); /* up */ + break; + + case OFOUNTAIN: + if (nearbymonst()) + return; + lprcat("\n\nThere is a fountain here"); + ofountain(); + break; + + case OSTATUE: + if (nearbymonst()) + return; + lprcat("\n\nYou are standing in front of a statue"); + ostatue(); + break; + + case OCHEST: + lprcat("\n\nThere is a chest here"); + ochest(); + break; + + case OIVTELETRAP: + if (rnd(11) < 6) + return; + item[playerx][playery] = OTELEPORTER; + know[playerx][playery] = 1; + + case OTELEPORTER: + lprcat("\nZaaaappp! You've been teleported!\n"); + beep(); + nap(3000); + oteleport(0); + break; + + case OSCHOOL: + if (nearbymonst()) + return; + lprcat("\n\nYou have found the College of Larn."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') { + oschool(); /* the college of larn */ + } else + lprcat(" stay here"); + break; + + case OMIRROR: + if (nearbymonst()) + return; + lprcat("\n\nThere is a mirror here"); + omirror(); + break; case OBANK2: - case OBANK: if (nearbymonst()) return; - if (i==OBANK) lprcat("\n\nYou have found the bank of Larn."); - else lprcat("\n\nYou have found a branch office of the bank of Larn."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - j=0; while ((j!='g') && (j!='i') && (j!='\33')) j=getchar(); - if (j == 'g') { if (i==OBANK) obank(); else obank2(); /* the bank of larn */ } - else lprcat(" stay here"); - break; - - case ODEADFOUNTAIN: if (nearbymonst()) return; - lprcat("\n\nThere is a dead fountain here"); break; - - case ODNDSTORE: if (nearbymonst()) return; - lprcat("\n\nThere is a DND store here."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') - dndstore(); /* the dnd adventurers store */ - else lprcat(" stay here"); + case OBANK: + if (nearbymonst()) + return; + if (i == OBANK) + lprcat("\n\nYou have found the bank of Larn."); + else + lprcat("\n\nYou have found a branch office of the bank of Larn."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + j = 0; + while ((j != 'g') && (j != 'i') && (j != '\33')) + j = getchar(); + if (j == 'g') { + if (i == OBANK) + obank(); + else + obank2(); /* the bank of larn */ + } else + lprcat(" stay here"); + break; + + case ODEADFOUNTAIN: + if (nearbymonst()) + return; + lprcat("\n\nThere is a dead fountain here"); + break; + + case ODNDSTORE: + if (nearbymonst()) + return; + lprcat("\n\nThere is a DND store here."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') + dndstore(); /* the dnd adventurers store */ + else + lprcat(" stay here"); + break; + + case OSTAIRSDOWN: + lprcat("\n\nThere is a circular staircase here"); + ostairs(-1); /* down */ + break; + + case OELEVATORDOWN: + lprcat("\n\nYou feel light for a moment, but the feeling disappears"); + oelevator(-1); /* down */ + break; + + case OOPENDOOR: + lprintf("\n\nYou have found %s", objectname[i]); + lprcat("\nDo you (c) close it"); + iopts(); + i = 0; + while ((i != 'c') && (i != 'i') && (i != '\33')) + i = getchar(); + if ((i == '\33') || (i == 'i')) { + ignore(); + break; + } + lprcat("close"); + forget(); + item[playerx][playery] = OCLOSEDDOOR; + iarg[playerx][playery] = 0; + playerx = lastpx; + playery = lastpy; + break; + + case OCLOSEDDOOR: + lprintf("\n\nYou have found %s", objectname[i]); + lprcat("\nDo you (o) try to open it"); + iopts(); + i = 0; + while ((i != 'o') && (i != 'i') && (i != '\33')) + i = getchar(); + if ((i == '\33') || (i == 'i')) { + ignore(); + playerx = lastpx; + playery = lastpy; + break; + } else { + lprcat("open"); + if (rnd(11) < 7) { + switch (iarg[playerx][playery]) { + case 6: + c[AGGRAVATE] += rnd(400); break; - case OSTAIRSDOWN: lprcat("\n\nThere is a circular staircase here"); ostairs(-1); /* down */ break; - - case OELEVATORDOWN: lprcat("\n\nYou feel light for a moment, but the feeling disappears"); - oelevator(-1); /* down */ - break; - - case OOPENDOOR: lprintf("\n\nYou have found %s",objectname[i]); - lprcat("\nDo you (c) close it"); iopts(); - i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar(); - if ((i=='\33') || (i=='i')) { ignore(); break; } - lprcat("close"); forget(); - item[playerx][playery]=OCLOSEDDOOR; - iarg[playerx][playery]=0; - playerx = lastpx; playery = lastpy; - break; - - case OCLOSEDDOOR: lprintf("\n\nYou have found %s",objectname[i]); - lprcat("\nDo you (o) try to open it"); iopts(); - i=0; while ((i!='o') && (i!='i') && (i!='\33')) i=getchar(); - if ((i=='\33') || (i=='i')) - { ignore(); playerx = lastpx; - playery = lastpy; break; } - else - { - lprcat("open"); - if (rnd(11)<7) - { - switch(iarg[playerx][playery]) - { - case 6: c[AGGRAVATE] += rnd(400); break; - - case 7: lprcat("\nYou are jolted by an electric shock "); - lastnum=274; losehp(rnd(20)); bottomline(); break; - - case 8: loselevel(); break; - - case 9: lprcat("\nYou suddenly feel weaker "); - if (c[STRENGTH]>3) c[STRENGTH]--; - bottomline(); break; - - default: break; - } - playerx = lastpx; playery = lastpy; - } - else - { - forget(); item[playerx][playery]=OOPENDOOR; - } - } - break; - - case OENTRANCE: lprcat("\nYou have found "); lprcat(objectname[OENTRANCE]); - lprcat("\nDo you (g) go inside"); iopts(); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') - { - newcavelevel(1); playerx=33; playery=MAXY-2; - item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1]=0; - draws(0,MAXX,0,MAXY); bot_linex(); return; - } - else ignore(); + case 7: + lprcat("\nYou are jolted by an electric shock "); + lastnum = 274; + losehp(rnd(20)); + bottomline(); break; - case OVOLDOWN: lprcat("\nYou have found "); lprcat(objectname[OVOLDOWN]); - lprcat("\nDo you (c) climb down"); iopts(); - i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar(); - if ((i=='\33') || (i=='i')) { ignore(); break; } - if (level!=0) { lprcat("\nThe shaft only extends 5 feet downward!"); return; } - if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep(); - lastnum=275; losehp(30+rnd(20)); bottomhp(); } - - else lprcat("climb down"); nap(3000); newcavelevel(MAXLEVEL); - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) /* put player near volcano shaft */ - if (item[j][i]==OVOLUP) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); } - draws(0,MAXX,0,MAXY); bot_linex(); return; - - case OVOLUP: lprcat("\nYou have found "); lprcat(objectname[OVOLUP]); - lprcat("\nDo you (c) climb up"); iopts(); - i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar(); - if ((i=='\33') || (i=='i')) { ignore(); break; } - if (level!=11) { lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); return; } - if (packweight() > 45+5*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep(); - lastnum=275; losehp(15+rnd(20)); bottomhp(); return; } - lprcat("climb up"); lflush(); nap(3000); newcavelevel(0); - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) /* put player near volcano shaft */ - if (item[j][i]==OVOLDOWN) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); } - draws(0,MAXX,0,MAXY); bot_linex(); return; - - case OTRAPARROWIV: if (rnd(17)<13) return; /* for an arrow trap */ - item[playerx][playery] = OTRAPARROW; - know[playerx][playery] = 0; - - case OTRAPARROW: lprcat("\nYou are hit by an arrow"); beep(); /* for an arrow trap */ - lastnum=259; losehp(rnd(10)+level); - bottomhp(); return; - - case OIVDARTRAP: if (rnd(17)<13) return; /* for a dart trap */ - item[playerx][playery] = ODARTRAP; - know[playerx][playery] = 0; - - case ODARTRAP: lprcat("\nYou are hit by a dart"); beep(); /* for a dart trap */ - lastnum=260; losehp(rnd(5)); - if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3; - bottomline(); return; - - case OIVTRAPDOOR: if (rnd(17)<13) return; /* for a trap door */ - item[playerx][playery] = OTRAPDOOR; - know[playerx][playery] = 1; - - case OTRAPDOOR: lastnum = 272; /* a trap door */ - if ((level==MAXLEVEL-1) || (level==MAXLEVEL+MAXVLEVEL-1)) - { lprcat("\nYou fell through a bottomless trap door!"); beep(); nap(3000); died(271); } - lprcat("\nYou fall through a trap door!"); beep(); /* for a trap door */ - losehp(rnd(5+level)); - nap(2000); newcavelevel(level+1); draws(0,MAXX,0,MAXY); bot_linex(); - return; - - - case OTRADEPOST: if (nearbymonst()) return; - lprcat("\nYou have found the Larn trading Post."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') otradepost(); else lprcat("stay here"); - return; - - case OHOME: if (nearbymonst()) return; - lprcat("\nYou have found your way home."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') ohome(); else lprcat("stay here"); - return; - - case OWALL: break; + case 8: + loselevel(); + break; - case OANNIHILATION: died(283); return; /* annihilated by sphere of annihilation */ + case 9: + lprcat("\nYou suddenly feel weaker "); + if (c[STRENGTH] > 3) + c[STRENGTH]--; + bottomline(); + break; - case OLRS: if (nearbymonst()) return; - lprcat("\n\nThere is an LRS office here."); - lprcat("\nDo you (g) go inside, or (i) stay here? "); - i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); - if (i == 'g') - olrs(); /* the larn revenue service */ - else lprcat(" stay here"); - break; + default: + break; + } + playerx = lastpx; + playery = lastpy; + } else { + forget(); + item[playerx][playery] = OOPENDOOR; + } + } + break; + + case OENTRANCE: + lprcat("\nYou have found "); + lprcat(objectname[OENTRANCE]); + lprcat("\nDo you (g) go inside"); + iopts(); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') { + newcavelevel(1); + playerx = 33; + playery = MAXY - 2; + item[33][MAXY - 1] = know[33][MAXY - 1] = mitem[33][MAXY - 1] = 0; + draws(0, MAXX, 0, MAXY); + bot_linex(); + return; + } else + ignore(); + break; + + case OVOLDOWN: + lprcat("\nYou have found "); + lprcat(objectname[OVOLDOWN]); + lprcat("\nDo you (c) climb down"); + iopts(); + i = 0; + while ((i != 'c') && (i != 'i') && (i != '\33')) + i = getchar(); + if ((i == '\33') || (i == 'i')) { + ignore(); + break; + } + if (level != 0) { + lprcat("\nThe shaft only extends 5 feet downward!"); + return; + } + if (packweight() > 45 + 3 * (c[STRENGTH] + c[STREXTRA])) { + lprcat("\nYou slip and fall down the shaft"); + beep(); + lastnum = 275; + losehp(30 + rnd(20)); + bottomhp(); + } else + lprcat("climb down"); + nap(3000); + newcavelevel(MAXLEVEL); + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) /* put player near + * volcano shaft */ + if (item[j][i] == OVOLUP) { + playerx = j; + playery = i; + j = MAXX; + i = MAXY; + positionplayer(); + } + draws(0, MAXX, 0, MAXY); + bot_linex(); + return; + + case OVOLUP: + lprcat("\nYou have found "); + lprcat(objectname[OVOLUP]); + lprcat("\nDo you (c) climb up"); + iopts(); + i = 0; + while ((i != 'c') && (i != 'i') && (i != '\33')) + i = getchar(); + if ((i == '\33') || (i == 'i')) { + ignore(); + break; + } + if (level != 11) { + lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); + return; + } + if (packweight() > 45 + 5 * (c[STRENGTH] + c[STREXTRA])) { + lprcat("\nYou slip and fall down the shaft"); + beep(); + lastnum = 275; + losehp(15 + rnd(20)); + bottomhp(); + return; + } + lprcat("climb up"); + lflush(); + nap(3000); + newcavelevel(0); + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) /* put player near + * volcano shaft */ + if (item[j][i] == OVOLDOWN) { + playerx = j; + playery = i; + j = MAXX; + i = MAXY; + positionplayer(); + } + draws(0, MAXX, 0, MAXY); + bot_linex(); + return; + + case OTRAPARROWIV: + if (rnd(17) < 13) + return; /* for an arrow trap */ + item[playerx][playery] = OTRAPARROW; + know[playerx][playery] = 0; + + case OTRAPARROW: + lprcat("\nYou are hit by an arrow"); + beep(); /* for an arrow trap */ + lastnum = 259; + losehp(rnd(10) + level); + bottomhp(); + return; + + case OIVDARTRAP: + if (rnd(17) < 13) + return; /* for a dart trap */ + item[playerx][playery] = ODARTRAP; + know[playerx][playery] = 0; + + case ODARTRAP: + lprcat("\nYou are hit by a dart"); + beep(); /* for a dart trap */ + lastnum = 260; + losehp(rnd(5)); + if ((--c[STRENGTH]) < 3) + c[STRENGTH] = 3; + bottomline(); + return; + + case OIVTRAPDOOR: + if (rnd(17) < 13) + return; /* for a trap door */ + item[playerx][playery] = OTRAPDOOR; + know[playerx][playery] = 1; + + case OTRAPDOOR: + lastnum = 272; /* a trap door */ + if ((level == MAXLEVEL - 1) || (level == MAXLEVEL + MAXVLEVEL - 1)) { + lprcat("\nYou fell through a bottomless trap door!"); + beep(); + nap(3000); + died(271); + } + lprcat("\nYou fall through a trap door!"); + beep(); /* for a trap door */ + losehp(rnd(5 + level)); + nap(2000); + newcavelevel(level + 1); + draws(0, MAXX, 0, MAXY); + bot_linex(); + return; + + + case OTRADEPOST: + if (nearbymonst()) + return; + lprcat("\nYou have found the Larn trading Post."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') + otradepost(); + else + lprcat("stay here"); + return; + + case OHOME: + if (nearbymonst()) + return; + lprcat("\nYou have found your way home."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') + ohome(); + else + lprcat("stay here"); + return; + + case OWALL: + break; + + case OANNIHILATION: + died(283); + return; /* annihilated by sphere of annihilation */ + + case OLRS: + if (nearbymonst()) + return; + lprcat("\n\nThere is an LRS office here."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i = 0; + while ((i != 'g') && (i != 'i') && (i != '\33')) + i = getchar(); + if (i == 'g') + olrs(); /* the larn revenue service */ + else + lprcat(" stay here"); + break; - default: finditem(i); break; + default: + finditem(i); + break; }; } /* function to say what object we found and ask if player wants to take it */ +void finditem(itm) - int itm; - { - int tmp,i; - lprintf("\n\nYou have found %s ",objectname[itm]); - tmp=iarg[playerx][playery]; - switch(itm) - { - case ODIAMOND: case ORUBY: case OEMERALD: - case OSAPPHIRE: case OSPIRITSCARAB: case OORBOFDRAGON: - case OCUBEofUNDEAD: case ONOTHEFT: break; - - default: - if (tmp>0) lprintf("+ %d",(long)tmp); else if (tmp<0) lprintf(" %d",(long)tmp); - } - lprcat("\nDo you want to (t) take it"); iopts(); - i=0; while (i!='t' && i!='i' && i!='\33') i=getchar(); - if (i == 't') - { lprcat("take"); if (take(itm,tmp)==0) forget(); return; } - ignore(); + int itm; +{ + int tmp, i; + lprintf("\n\nYou have found %s ", objectname[itm]); + tmp = iarg[playerx][playery]; + switch (itm) { + case ODIAMOND: + case ORUBY: + case OEMERALD: + case OSAPPHIRE: + case OSPIRITSCARAB: + case OORBOFDRAGON: + case OCUBEofUNDEAD: + case ONOTHEFT: + break; + + default: + if (tmp > 0) + lprintf("+ %d", (long) tmp); + else if (tmp < 0) + lprintf(" %d", (long) tmp); + } + lprcat("\nDo you want to (t) take it"); + iopts(); + i = 0; + while (i != 't' && i != 'i' && i != '\33') + i = getchar(); + if (i == 't') { + lprcat("take"); + if (take(itm, tmp) == 0) + forget(); + return; } + ignore(); +} + + - /* ******* OSTAIRS @@ -290,55 +545,69 @@ finditem(itm) subroutine to process the stair cases if dir > 0 the up else down */ +void ostairs(dir) - int dir; - { - register int k; + int dir; +{ + int k; lprcat("\nDo you (s) stay here "); - if (dir > 0) lprcat("(u) go up "); else lprcat("(d) go down "); + if (dir > 0) + lprcat("(u) go up "); + else + lprcat("(d) go down "); lprcat("or (f) kick stairs? "); - while (1) switch(getchar()) - { + while (1) + switch (getchar()) { case '\33': - case 's': case 'i': lprcat("stay here"); return; - - case 'f': lprcat("kick stairs"); - if (rnd(2) == 1) - lprcat("\nI hope you feel better. Showing anger rids you of frustration."); - else - { - k=rnd((level+1)<<1); - lprintf("\nYou hurt your foot dumb dumb! You suffer %d hit points",(long)k); - lastnum=276; losehp(k); bottomline(); - } - return; - - case 'u': lprcat("go up"); - if (dir < 0) lprcat("\nThe stairs don't go up!"); - else - if (level>=2 && level!=11) - { - k = level; newcavelevel(level-1); - draws(0,MAXX,0,MAXY); bot_linex(); - } - else lprcat("\nThe stairs lead to a dead end!"); - return; - - case 'd': lprcat("go down"); - if (dir > 0) lprcat("\nThe stairs don't go down!"); - else - if (level!=0 && level!=10 && level!=13) - { - k = level; newcavelevel(level+1); - draws(0,MAXX,0,MAXY); bot_linex(); - } - else lprcat("\nThe stairs lead to a dead end!"); - return; + case 's': + case 'i': + lprcat("stay here"); + return; + + case 'f': + lprcat("kick stairs"); + if (rnd(2) == 1) + lprcat("\nI hope you feel better. Showing anger rids you of frustration."); + else { + k = rnd((level + 1) << 1); + lprintf("\nYou hurt your foot dumb dumb! You suffer %d hit points", (long) k); + lastnum = 276; + losehp(k); + bottomline(); + } + return; + + case 'u': + lprcat("go up"); + if (dir < 0) + lprcat("\nThe stairs don't go up!"); + else if (level >= 2 && level != 11) { + k = level; + newcavelevel(level - 1); + draws(0, MAXX, 0, MAXY); + bot_linex(); + } else + lprcat("\nThe stairs lead to a dead end!"); + return; + + case 'd': + lprcat("go down"); + if (dir > 0) + lprcat("\nThe stairs don't go down!"); + else if (level != 0 && level != 10 && level != 13) { + k = level; + newcavelevel(level + 1); + draws(0, MAXX, 0, MAXY); + bot_linex(); + } else + lprcat("\nThe stairs lead to a dead end!"); + return; }; - } +} + + - /* ********* OTELEPORTER @@ -346,24 +615,40 @@ ostairs(dir) subroutine to handle a teleport trap +/- 1 level maximum */ +void oteleport(err) - int err; - { - register int tmp; - if (err) if (rnd(151)<3) died(264); /* stuck in a rock */ - c[TELEFLAG]=1; /* show ?? on bottomline if been teleported */ - if (level==0) tmp=0; - else if (level < MAXLEVEL) - { tmp=rnd(5)+level-3; if (tmp>=MAXLEVEL) tmp=MAXLEVEL-1; - if (tmp<1) tmp=1; } - else - { tmp=rnd(3)+level-2; if (tmp>=MAXLEVEL+MAXVLEVEL) tmp=MAXLEVEL+MAXVLEVEL-1; - if (tmp<MAXLEVEL) tmp=MAXLEVEL; } - playerx = rnd(MAXX-2); playery = rnd(MAXY-2); - if (level != tmp) newcavelevel(tmp); positionplayer(); - draws(0,MAXX,0,MAXY); bot_linex(); + int err; +{ + int tmp; + if (err) + if (rnd(151) < 3) + died(264); /* stuck in a rock */ + c[TELEFLAG] = 1; /* show ?? on bottomline if been teleported */ + if (level == 0) + tmp = 0; + else if (level < MAXLEVEL) { + tmp = rnd(5) + level - 3; + if (tmp >= MAXLEVEL) + tmp = MAXLEVEL - 1; + if (tmp < 1) + tmp = 1; + } else { + tmp = rnd(3) + level - 2; + if (tmp >= MAXLEVEL + MAXVLEVEL) + tmp = MAXLEVEL + MAXVLEVEL - 1; + if (tmp < MAXLEVEL) + tmp = MAXLEVEL; } - + playerx = rnd(MAXX - 2); + playery = rnd(MAXY - 2); + if (level != tmp) + newcavelevel(tmp); + positionplayer(); + draws(0, MAXX, 0, MAXY); + bot_linex(); +} + + /* ******* OPOTION @@ -371,129 +656,212 @@ oteleport(err) function to process a potion */ +void opotion(pot) - int pot; - { - lprcat("\nDo you (d) drink it, (t) take it"); iopts(); - while (1) switch(getchar()) - { + int pot; +{ + lprcat("\nDo you (d) drink it, (t) take it"); + iopts(); + while (1) + switch (getchar()) { case '\33': - case 'i': ignore(); return; - - case 'd': lprcat("drink\n"); forget(); /* destroy potion */ - quaffpotion(pot); return; - - case 't': lprcat("take\n"); if (take(OPOTION,pot)==0) forget(); - return; + case 'i': + ignore(); + return; + + case 'd': + lprcat("drink\n"); + forget(); /* destroy potion */ + quaffpotion(pot); + return; + + case 't': + lprcat("take\n"); + if (take(OPOTION, pot) == 0) + forget(); + return; }; - } - +} + /* function to drink a potion */ +void quaffpotion(pot) - int pot; - { - register int i,j,k; - if (pot<0 || pot>=MAXPOTION) return; /* check for within bounds */ + int pot; +{ + int i, j, k; + if (pot < 0 || pot >= MAXPOTION) + return; /* check for within bounds */ potionname[pot] = potionhide[pot]; - switch(pot) - { - case 9: lprcat("\nYou feel greedy . . ."); nap(2000); - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) - if ((item[j][i]==OGOLDPILE) || (item[j][i]==OMAXGOLD)) - { - know[j][i]=1; show1cell(j,i); - } - showplayer(); return; - - case 19: lprcat("\nYou feel greedy . . ."); nap(2000); - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) - { - k=item[j][i]; - if ((k==ODIAMOND) || (k==ORUBY) || (k==OEMERALD) || (k==OMAXGOLD) - || (k==OSAPPHIRE) || (k==OLARNEYE) || (k==OGOLDPILE)) - { - know[j][i]=1; show1cell(j,i); - } - } - showplayer(); return; - - case 20: c[HP] = c[HPMAX]; break; /* instant healing */ - - case 1: lprcat("\nYou feel better"); - if (c[HP] == c[HPMAX]) raisemhp(1); - else if ((c[HP] += rnd(20)+20+c[LEVEL]) > c[HPMAX]) c[HP]=c[HPMAX]; break; - - case 2: lprcat("\nSuddenly, you feel much more skillful!"); - raiselevel(); raisemhp(1); return; - - case 3: lprcat("\nYou feel strange for a moment"); - c[rund(6)]++; break; - - case 4: lprcat("\nYou feel more self confident!"); - c[WISDOM] += rnd(2); break; - - case 5: lprcat("\nWow! You feel great!"); - if (c[STRENGTH]<12) c[STRENGTH]=12; else c[STRENGTH]++; break; - - case 6: lprcat("\nYour charm went up by one!"); c[CHARISMA]++; break; - - case 8: lprcat("\nYour intelligence went up by one!"); - c[INTELLIGENCE]++; break; - - case 10: for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) - if (mitem[j][i]) - { - know[j][i]=1; show1cell(j,i); - } - /* monster detection */ return; - - case 12: lprcat("\nThis potion has no taste to it"); return; - - case 15: lprcat("\nWOW!!! You feel Super-fantastic!!!"); - if (c[HERO]==0) for (i=0; i<6; i++) c[i] += 11; - c[HERO] += 250; break; - - case 16: lprcat("\nYou have a greater intestinal constitude!"); - c[CONSTITUTION]++; break; - - case 17: lprcat("\nYou now have incredibly bulging muscles!!!"); - if (c[GIANTSTR]==0) c[STREXTRA] += 21; - c[GIANTSTR] += 700; break; - - case 18: lprcat("\nYou feel a chill run up your spine!"); - c[FIRERESISTANCE] += 1000; break; - - case 0: lprcat("\nYou fall asleep. . ."); - i=rnd(11)-(c[CONSTITUTION]>>2)+2; while(--i>0) { parse2(); nap(1000); } - cursors(); lprcat("\nYou woke up!"); return; - - case 7: lprcat("\nYou become dizzy!"); - if (--c[STRENGTH] < 3) c[STRENGTH]=3; break; - - case 11: lprcat("\nYou stagger for a moment . ."); - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) - know[j][i]=0; - nap(2000); draws(0,MAXX,0,MAXY); /* potion of forgetfulness */ return; - - case 13: lprcat("\nYou can't see anything!"); /* blindness */ - c[BLINDCOUNT]+=500; return; - - case 14: lprcat("\nYou feel confused"); c[CONFUSE]+= 20+rnd(9); return; - - case 21: lprcat("\nYou don't seem to be affected"); return; /* cure dianthroritis */ + switch (pot) { + case 9: + lprcat("\nYou feel greedy . . ."); + nap(2000); + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + if ((item[j][i] == OGOLDPILE) || (item[j][i] == OMAXGOLD)) { + know[j][i] = 1; + show1cell(j, i); + } + showplayer(); + return; + + case 19: + lprcat("\nYou feel greedy . . ."); + nap(2000); + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) { + k = item[j][i]; + if ((k == ODIAMOND) || (k == ORUBY) || (k == OEMERALD) || (k == OMAXGOLD) + || (k == OSAPPHIRE) || (k == OLARNEYE) || (k == OGOLDPILE)) { + know[j][i] = 1; + show1cell(j, i); + } + } + showplayer(); + return; + + case 20: + c[HP] = c[HPMAX]; + break; /* instant healing */ + + case 1: + lprcat("\nYou feel better"); + if (c[HP] == c[HPMAX]) + raisemhp(1); + else if ((c[HP] += rnd(20) + 20 + c[LEVEL]) > c[HPMAX]) + c[HP] = c[HPMAX]; + break; + + case 2: + lprcat("\nSuddenly, you feel much more skillful!"); + raiselevel(); + raisemhp(1); + return; + + case 3: + lprcat("\nYou feel strange for a moment"); + c[rund(6)]++; + break; + + case 4: + lprcat("\nYou feel more self confident!"); + c[WISDOM] += rnd(2); + break; + + case 5: + lprcat("\nWow! You feel great!"); + if (c[STRENGTH] < 12) + c[STRENGTH] = 12; + else + c[STRENGTH]++; + break; + + case 6: + lprcat("\nYour charm went up by one!"); + c[CHARISMA]++; + break; + + case 8: + lprcat("\nYour intelligence went up by one!"); + c[INTELLIGENCE]++; + break; + + case 10: + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + if (mitem[j][i]) { + know[j][i] = 1; + show1cell(j, i); + } + /* monster detection */ return; + + case 12: + lprcat("\nThis potion has no taste to it"); + return; + + case 15: + lprcat("\nWOW!!! You feel Super-fantastic!!!"); + if (c[HERO] == 0) + for (i = 0; i < 6; i++) + c[i] += 11; + c[HERO] += 250; + break; + + case 16: + lprcat("\nYou have a greater intestinal constitude!"); + c[CONSTITUTION]++; + break; + + case 17: + lprcat("\nYou now have incredibly bulging muscles!!!"); + if (c[GIANTSTR] == 0) + c[STREXTRA] += 21; + c[GIANTSTR] += 700; + break; + + case 18: + lprcat("\nYou feel a chill run up your spine!"); + c[FIRERESISTANCE] += 1000; + break; + + case 0: + lprcat("\nYou fall asleep. . ."); + i = rnd(11) - (c[CONSTITUTION] >> 2) + 2; + while (--i > 0) { + parse2(); + nap(1000); + } + cursors(); + lprcat("\nYou woke up!"); + return; + + case 7: + lprcat("\nYou become dizzy!"); + if (--c[STRENGTH] < 3) + c[STRENGTH] = 3; + break; + + case 11: + lprcat("\nYou stagger for a moment . ."); + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + know[j][i] = 0; + nap(2000); + draws(0, MAXX, 0, MAXY); /* potion of forgetfulness */ + return; + + case 13: + lprcat("\nYou can't see anything!"); /* blindness */ + c[BLINDCOUNT] += 500; + return; + + case 14: + lprcat("\nYou feel confused"); + c[CONFUSE] += 20 + rnd(9); + return; + + case 21: + lprcat("\nYou don't seem to be affected"); + return; /* cure dianthroritis */ + + case 22: + lprcat("\nYou feel a sickness engulf you"); /* poison */ + c[HALFDAM] += 200 + rnd(200); + return; + + case 23: + lprcat("\nYou feel your vision sharpen"); /* see invisible */ + c[SEEINVISIBLE] += rnd(1000) + 400; + monstnamelist[INVISIBLESTALKER] = 'I'; + return; + }; + bottomline(); /* show new stats */ + return; +} - case 22: lprcat("\nYou feel a sickness engulf you"); /* poison */ - c[HALFDAM] += 200 + rnd(200); return; - case 23: lprcat("\nYou feel your vision sharpen"); /* see invisible */ - c[SEEINVISIBLE] += rnd(1000)+400; - monstnamelist[INVISIBLESTALKER] = 'I'; return; - }; - bottomline(); /* show new stats */ return; - } - /* ******* OSCROLL @@ -501,312 +869,478 @@ quaffpotion(pot) function to process a magic scroll */ +void oscroll(typ) - int typ; - { + int typ; +{ lprcat("\nDo you "); - if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); lprcat("(t) take it"); iopts(); - while (1) switch(getchar()) - { + if (c[BLINDCOUNT] == 0) + lprcat("(r) read it, "); + lprcat("(t) take it"); + iopts(); + while (1) + switch (getchar()) { case '\33': - case 'i': ignore(); return; - - case 'r': if (c[BLINDCOUNT]) break; - lprcat("read"); forget(); - if (typ==2 || typ==15) { show1cell(playerx,playery); cursors(); } - /* destroy it */ read_scroll(typ); return; + case 'i': + ignore(); + return; - case 't': lprcat("take"); if (take(OSCROLL,typ)==0) forget(); /* destroy it */ - return; + case 'r': + if (c[BLINDCOUNT]) + break; + lprcat("read"); + forget(); + if (typ == 2 || typ == 15) { + show1cell(playerx, playery); + cursors(); + } + /* destroy it */ read_scroll(typ); + return; + + case 't': + lprcat("take"); + if (take(OSCROLL, typ) == 0) + forget(); /* destroy it */ + return; }; - } +} /* data for the function to read a scroll */ -static int xh,yh,yl,xl; -static char curse[] = { BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING, - LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, HALFDAM }; -static char exten[] = { PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT, - INVISIBILITY, CANCELLATION, HASTESELF, GLOBE, SCAREMONST, HOLDMONST, TIMESTOP }; -char time_change[] = { HASTESELF,HERO,ALTPRO,PROTECTIONTIME,DEXCOUNT, - STRCOUNT,GIANTSTR,CHARMCOUNT,INVISIBILITY,CANCELLATION, - HASTESELF,AGGRAVATE,SCAREMONST,STEALTH,AWARENESS,HOLDMONST,HASTEMONST, - FIRERESISTANCE,GLOBE,SPIRITPRO,UNDEADPRO,HALFDAM,SEEINVISIBLE, - ITCHING,CLUMSINESS, WTW }; +static int xh, yh, yl, xl; +static u_char curse[] = { + BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING, + LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, HALFDAM +}; + +static u_char exten[] = { + PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT, INVISIBILITY, + CANCELLATION, HASTESELF, GLOBE, SCAREMONST, HOLDMONST, TIMESTOP +}; + +u_char time_change[] = { + HASTESELF, HERO, ALTPRO, PROTECTIONTIME, DEXCOUNT, STRCOUNT, + GIANTSTR, CHARMCOUNT, INVISIBILITY, CANCELLATION, HASTESELF, + AGGRAVATE, SCAREMONST, STEALTH, AWARENESS, HOLDMONST, + HASTEMONST, FIRERESISTANCE, GLOBE, SPIRITPRO, UNDEADPRO, + HALFDAM, SEEINVISIBLE, ITCHING, CLUMSINESS, WTW +}; + /* * function to adjust time when time warping and taking courses in school */ -adjtime(tim) - register long tim; - { - register int j; - for (j=0; j<26; j++) /* adjust time related parameters */ +void +adjusttime(tim) + long tim; +{ + int j; + for (j = 0; j < 26; j++)/* adjust time related parameters */ if (c[time_change[j]]) - if ((c[time_change[j]] -= tim) < 1) c[time_change[j]]=1; + if ((c[time_change[j]] -= tim) < 1) + c[time_change[j]] = 1; regen(); - } +} /* function to read a scroll */ +void read_scroll(typ) - int typ; - { - register int i,j; - if (typ<0 || typ>=MAXSCROLL) return; /* be sure we are within bounds */ + int typ; +{ + int i, j; + if (typ < 0 || typ >= MAXSCROLL) + return; /* be sure we are within bounds */ scrollname[typ] = scrollhide[typ]; - switch(typ) - { - case 0: lprcat("\nYour armor glows for a moment"); enchantarmor(); return; - - case 1: lprcat("\nYour weapon glows for a moment"); enchweapon(); return; /* enchant weapon */ - - case 2: lprcat("\nYou have been granted enlightenment!"); - yh = min(playery+7,MAXY); xh = min(playerx+25,MAXX); - yl = max(playery-7,0); xl = max(playerx-25,0); - for (i=yl; i<yh; i++) for (j=xl; j<xh; j++) know[j][i]=1; - nap(2000); draws(xl,xh,yl,yh); return; - - case 3: lprcat("\nThis scroll seems to be blank"); return; - - case 4: createmonster(makemonst(level+1)); return; /* this one creates a monster */ - - case 5: something(level); /* create artifact */ return; - - case 6: c[AGGRAVATE]+=800; return; /* aggravate monsters */ - - case 7: gltime += (i = rnd(1000) - 850); /* time warp */ - if (i>=0) lprintf("\nYou went forward in time by %d mobuls",(long)((i+99)/100)); - else lprintf("\nYou went backward in time by %d mobuls",(long)(-(i+99)/100)); - adjtime((long)i); /* adjust time for time warping */ - return; - - case 8: oteleport(0); return; /* teleportation */ - - case 9: c[AWARENESS] += 1800; return; /* expanded awareness */ - - case 10: c[HASTEMONST] += rnd(55)+12; return; /* haste monster */ - - case 11: for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) - if (mitem[j][i]) - hitp[j][i] = monster[mitem[j][i]].hitpoints; - return; /* monster healing */ - case 12: c[SPIRITPRO] += 300 + rnd(200); bottomline(); return; /* spirit protection */ - - case 13: c[UNDEADPRO] += 300 + rnd(200); bottomline(); return; /* undead protection */ - - case 14: c[STEALTH] += 250 + rnd(250); bottomline(); return; /* stealth */ - - case 15: lprcat("\nYou have been granted enlightenment!"); /* magic mapping */ - for (i=0; i<MAXY; i++) for (j=0; j<MAXX; j++) know[j][i]=1; - nap(2000); draws(0,MAXX,0,MAXY); return; - - case 16: c[HOLDMONST] += 30; bottomline(); return; /* hold monster */ - - case 17: for (i=0; i<26; i++) /* gem perfection */ - switch(iven[i]) - { - case ODIAMOND: case ORUBY: - case OEMERALD: case OSAPPHIRE: - j = ivenarg[i]; j &= 255; j <<= 1; - if (j > 255) j=255; /* double value */ - ivenarg[i] = j; break; - } - break; - - case 18: for (i=0; i<11; i++) c[exten[i]] <<= 1; /* spell extension */ - break; - - case 19: for (i=0; i<26; i++) /* identify */ - { - if (iven[i]==OPOTION) potionname[ivenarg[i]] = potionhide[ivenarg[i]]; - if (iven[i]==OSCROLL) scrollname[ivenarg[i]] = scrollhide[ivenarg[i]]; - } - break; - - case 20: for (i=0; i<10; i++) /* remove curse */ - if (c[curse[i]]) c[curse[i]] = 1; + switch (typ) { + case 0: + lprcat("\nYour armor glows for a moment"); + enchantarmor(); + return; + + case 1: + lprcat("\nYour weapon glows for a moment"); + enchweapon(); + return; /* enchant weapon */ + + case 2: + lprcat("\nYou have been granted enlightenment!"); + yh = min(playery + 7, MAXY); + xh = min(playerx + 25, MAXX); + yl = max(playery - 7, 0); + xl = max(playerx - 25, 0); + for (i = yl; i < yh; i++) + for (j = xl; j < xh; j++) + know[j][i] = 1; + nap(2000); + draws(xl, xh, yl, yh); + return; + + case 3: + lprcat("\nThis scroll seems to be blank"); + return; + + case 4: + createmonster(makemonst(level + 1)); + return; /* this one creates a monster */ + + case 5: + something(level); /* create artifact */ + return; + + case 6: + c[AGGRAVATE] += 800; + return; /* aggravate monsters */ + + case 7: + gltime += (i = rnd(1000) - 850); /* time warp */ + if (i >= 0) + lprintf("\nYou went forward in time by %d mobuls", (long) ((i + 99) / 100)); + else + lprintf("\nYou went backward in time by %d mobuls", (long) (-(i + 99) / 100)); + adjusttime((long) i); /* adjust time for time warping */ + return; + + case 8: + oteleport(0); + return; /* teleportation */ + + case 9: + c[AWARENESS] += 1800; + return; /* expanded awareness */ + + case 10: + c[HASTEMONST] += rnd(55) + 12; + return; /* haste monster */ + + case 11: + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + if (mitem[j][i]) + hitp[j][i] = monster[mitem[j][i]].hitpoints; + return; /* monster healing */ + case 12: + c[SPIRITPRO] += 300 + rnd(200); + bottomline(); + return; /* spirit protection */ + + case 13: + c[UNDEADPRO] += 300 + rnd(200); + bottomline(); + return; /* undead protection */ + + case 14: + c[STEALTH] += 250 + rnd(250); + bottomline(); + return; /* stealth */ + + case 15: + lprcat("\nYou have been granted enlightenment!"); /* magic mapping */ + for (i = 0; i < MAXY; i++) + for (j = 0; j < MAXX; j++) + know[j][i] = 1; + nap(2000); + draws(0, MAXX, 0, MAXY); + return; + + case 16: + c[HOLDMONST] += 30; + bottomline(); + return; /* hold monster */ + + case 17: + for (i = 0; i < 26; i++) /* gem perfection */ + switch (iven[i]) { + case ODIAMOND: + case ORUBY: + case OEMERALD: + case OSAPPHIRE: + j = ivenarg[i]; + j &= 255; + j <<= 1; + if (j > 255) + j = 255; /* double value */ + ivenarg[i] = j; break; + } + break; + + case 18: + for (i = 0; i < 11; i++) + c[exten[i]] <<= 1; /* spell extension */ + break; + + case 19: + for (i = 0; i < 26; i++) { /* identify */ + if (iven[i] == OPOTION) + potionname[ivenarg[i]] = potionhide[ivenarg[i]]; + if (iven[i] == OSCROLL) + scrollname[ivenarg[i]] = scrollhide[ivenarg[i]]; + } + break; + + case 20: + for (i = 0; i < 10; i++) /* remove curse */ + if (c[curse[i]]) + c[curse[i]] = 1; + break; + + case 21: + annihilate(); + break; /* scroll of annihilation */ + + case 22: + godirect(22, 150, "The ray hits the %s", 0, ' '); /* pulverization */ + break; + case 23: + c[LIFEPROT]++; + break; /* life protection */ + }; +} - case 21: annihilate(); break; /* scroll of annihilation */ - case 22: godirect(22,150,"The ray hits the %s",0,' '); /* pulverization */ - break; - case 23: c[LIFEPROT]++; break; /* life protection */ - }; - } - +void oorb() - { - } +{ +} +void opit() - { - register int i; - if (rnd(101)<81) - if (rnd(70) > 9*c[DEXTERITY]-packweight() || rnd(101)<5) - if (level==MAXLEVEL-1) obottomless(); else - if (level==MAXLEVEL+MAXVLEVEL-1) obottomless(); else - { - if (rnd(101)<20) - { - i=0; lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n"); - } - else - { - i = rnd(level*3+3); - lprintf("\nYou fell into a pit! You suffer %d hit points damage",(long)i); - lastnum=261; /* if he dies scoreboard will say so */ +{ + int i; + if (rnd(101) < 81) + if (rnd(70) > 9 * c[DEXTERITY] - packweight() || rnd(101) < 5) + if (level == MAXLEVEL - 1) + obottomless(); + else if (level == MAXLEVEL + MAXVLEVEL - 1) + obottomless(); + else { + if (rnd(101) < 20) { + i = 0; + lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n"); + } else { + i = rnd(level * 3 + 3); + lprintf("\nYou fell into a pit! You suffer %d hit points damage", (long) i); + lastnum = 261; /* if he dies scoreboard + * will say so */ } - losehp(i); nap(2000); newcavelevel(level+1); draws(0,MAXX,0,MAXY); + losehp(i); + nap(2000); + newcavelevel(level + 1); + draws(0, MAXX, 0, MAXY); } - } +} +void obottomless() - { - lprcat("\nYou fell into a bottomless pit!"); beep(); nap(3000); died(262); - } +{ + lprcat("\nYou fell into a bottomless pit!"); + beep(); + nap(3000); + died(262); +} +void oelevator(dir) - int dir; - { + int dir; +{ #ifdef lint - int x; - x=dir; - dir=x; -#endif lint - } + int x; + x = dir; + dir = x; +#endif /* lint */ +} +void ostatue() - { - } +{ +} +void omirror() - { - } +{ +} +void obook() - { +{ lprcat("\nDo you "); - if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); lprcat("(t) take it"); iopts(); - while (1) switch(getchar()) - { + if (c[BLINDCOUNT] == 0) + lprcat("(r) read it, "); + lprcat("(t) take it"); + iopts(); + while (1) + switch (getchar()) { case '\33': - case 'i': ignore(); return; - - case 'r': if (c[BLINDCOUNT]) break; - lprcat("read"); - /* no more book */ readbook(iarg[playerx][playery]); forget(); return; + case 'i': + ignore(); + return; - case 't': lprcat("take"); if (take(OBOOK,iarg[playerx][playery])==0) forget(); /* no more book */ - return; + case 'r': + if (c[BLINDCOUNT]) + break; + lprcat("read"); + /* no more book */ readbook(iarg[playerx][playery]); + forget(); + return; + + case 't': + lprcat("take"); + if (take(OBOOK, iarg[playerx][playery]) == 0) + forget(); /* no more book */ + return; }; - } +} /* function to read a book */ +void readbook(lev) - register int lev; - { - register int i,tmp; - if (lev<=3) i = rund((tmp=splev[lev])?tmp:1); else - i = rnd((tmp=splev[lev]-9)?tmp:1) + 9; - spelknow[i]=1; - lprintf("\nSpell \"%s\": %s\n%s",spelcode[i],spelname[i],speldescript[i]); - if (rnd(10)==4) - { lprcat("\nYour int went up by one!"); c[INTELLIGENCE]++; bottomline(); } + int lev; +{ + int i, tmp; + if (lev <= 3) + i = rund((tmp = splev[lev]) ? tmp : 1); + else + i = rnd((tmp = splev[lev] - 9) ? tmp : 1) + 9; + spelknow[i] = 1; + lprintf("\nSpell \"%s\": %s\n%s", spelcode[i], spelname[i], speldescript[i]); + if (rnd(10) == 4) { + lprcat("\nYour int went up by one!"); + c[INTELLIGENCE]++; + bottomline(); } +} +void ocookie() - { - char *p; - lprcat("\nDo you (e) eat it, (t) take it"); iopts(); - while (1) switch(getchar()) - { +{ + char *p; + lprcat("\nDo you (e) eat it, (t) take it"); + iopts(); + while (1) + switch (getchar()) { case '\33': - case 'i': ignore(); return; - - case 'e': lprcat("eat\nThe cookie tasted good."); - forget(); /* no more cookie */ - if (c[BLINDCOUNT]) return; - if (!(p=fortune())) return; - lprcat(" A message inside the cookie reads:\n"); lprcat(p); - return; - - case 't': lprcat("take"); if (take(OCOOKIE,0)==0) forget(); /* no more book */ - return; + case 'i': + ignore(); + return; + + case 'e': + lprcat("eat\nThe cookie tasted good."); + forget(); /* no more cookie */ + if (c[BLINDCOUNT]) + return; + if (!(p = fortune())) + return; + lprcat(" A message inside the cookie reads:\n"); + lprcat(p); + return; + + case 't': + lprcat("take"); + if (take(OCOOKIE, 0) == 0) + forget(); /* no more book */ + return; }; - } +} -/* routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth 100* the argument */ +/* + * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth + * 100* the argument + */ +void ogold(arg) - int arg; - { - register long i; + int arg; +{ + long i; i = iarg[playerx][playery]; - if (arg==OMAXGOLD) i *= 100; - else if (arg==OKGOLD) i *= 1000; - else if (arg==ODGOLD) i *= 10; - lprintf("\nIt is worth %d!",(long)i); c[GOLD] += i; bottomgold(); - item[playerx][playery] = know[playerx][playery] = 0; /* destroy gold */ - } + if (arg == OMAXGOLD) + i *= 100; + else if (arg == OKGOLD) + i *= 1000; + else if (arg == ODGOLD) + i *= 10; + lprintf("\nIt is worth %d!", (long) i); + c[GOLD] += i; + bottomgold(); + item[playerx][playery] = know[playerx][playery] = 0; /* destroy gold */ +} +void ohome() - { - register int i; - nosignal = 1; /* disable signals */ - for (i=0; i<26; i++) if (iven[i]==OPOTION) if (ivenarg[i]==21) - { - iven[i]=0; /* remove the potion of cure dianthroritis from inventory */ - clear(); lprcat("Congratulations. You found a potion of cure dianthroritis.\n"); - lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n"); - if (gltime>TIMELIMIT) - { - lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n"); - lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n"); - nap(5000); died(269); - } - else - { - lprcat("\nThe doctor is now administering the potion, and in a few moments\n"); - lprcat("Your daughter should be well on her way to recovery.\n"); - nap(6000); - lprcat("\nThe potion is"); nap(3000); lprcat(" working! The doctor thinks that\n"); - lprcat("your daughter will recover in a few days. Congratulations!\n"); - beep(); nap(5000); died(263); +{ + int i; + nosignal = 1; /* disable signals */ + for (i = 0; i < 26; i++) + if (iven[i] == OPOTION) + if (ivenarg[i] == 21) { + iven[i] = 0; /* remove the potion of cure + * dianthroritis from + * inventory */ + clear(); + lprcat("Congratulations. You found a potion of cure dianthroritis.\n"); + lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n"); + if (gltime > TIMELIMIT) { + lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n"); + lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n"); + nap(5000); + died(269); + } else { + lprcat("\nThe doctor is now administering the potion, and in a few moments\n"); + lprcat("Your daughter should be well on her way to recovery.\n"); + nap(6000); + lprcat("\nThe potion is"); + nap(3000); + lprcat(" working! The doctor thinks that\n"); + lprcat("your daughter will recover in a few days. Congratulations!\n"); + beep(); + nap(5000); + died(263); + } } - } - - while (1) - { - clear(); lprintf("Welcome home %s. Latest word from the doctor is not good.\n",logname); + while (1) { + clear(); + lprintf("Welcome home %s. Latest word from the doctor is not good.\n", logname); - if (gltime>TIMELIMIT) - { + if (gltime > TIMELIMIT) { lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n"); lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n"); - nap(5000); died(269); - } - + nap(5000); + died(269); + } lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n"); - lprintf("your daughter has only %d mobuls left in this world. It's up to you,\n",(long)((TIMELIMIT-gltime+99)/100)); - lprintf("%s, to find the only hope for your daughter, the very rare\n",logname); + lprintf("your daughter has only %d mobuls left in this world. It's up to you,\n", (long) ((TIMELIMIT - gltime + 99) / 100)); + lprintf("%s, to find the only hope for your daughter, the very rare\n", logname); lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n"); lprcat("depths of the caves can this potion be found.\n\n\n"); - lprcat("\n ----- press "); standout("return"); - lprcat(" to continue, "); standout("escape"); + lprcat("\n ----- press "); + standout("return"); + lprcat(" to continue, "); + standout("escape"); lprcat(" to leave ----- "); - i=getchar(); while (i!='\33' && i!='\n') i=getchar(); - if (i=='\33') { drawscreen(); nosignal = 0; /* enable signals */ return; } + i = getchar(); + while (i != '\33' && i != '\n') + i = getchar(); + if (i == '\33') { + drawscreen(); + nosignal = 0; /* enable signals */ + return; } } +} -/* routine to save program space */ +/* routine to save program space */ +void iopts() - { lprcat(", or (i) ignore it? "); } -ignore() - { lprcat("ignore\n"); } +{ + lprcat(", or (i) ignore it? "); +} +void +ignore() +{ + lprcat("ignore\n"); +} diff --git a/larn/pathnames.h b/larn/pathnames.h index 4c34d6fb..fe4d8f52 100644 --- a/larn/pathnames.h +++ b/larn/pathnames.h @@ -1,4 +1,4 @@ -/* $NetBSD: pathnames.h,v 1.6 1997/01/07 12:12:22 tls Exp $ */ +/* $NetBSD: pathnames.h,v 1.7 1997/10/18 20:03:41 christos Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. diff --git a/larn/regen.c b/larn/regen.c index 1bfe7b6b..efeefca5 100644 --- a/larn/regen.c +++ b/larn/regen.c @@ -1,9 +1,13 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: regen.c,v 1.4 1997/07/13 20:21:39 christos Exp $"; -#endif /* not lint */ +/* $NetBSD: regen.c,v 1.5 1997/10/18 20:03:43 christos Exp $ */ /* regen.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: regen.c,v 1.5 1997/10/18 20:03:43 christos Exp $"); +#endif /* not lint */ + #include "header.h" +#include "extern.h" /* ******* REGEN() @@ -12,85 +16,172 @@ static char rcsid[] = "$NetBSD: regen.c,v 1.4 1997/07/13 20:21:39 christos Exp $ subroutine to regenerate player hp and spells */ +void regen() - { - register int i,flag; - register long *d; +{ + int i, flag; + long *d; d = c; #ifdef EXTRA d[MOVESMADE]++; #endif - if (d[TIMESTOP]) { if(--d[TIMESTOP]<=0) bottomline(); return; } /* for stop time spell */ - flag=0; + if (d[TIMESTOP]) { + if (--d[TIMESTOP] <= 0) + bottomline(); + return; + } /* for stop time spell */ + flag = 0; - if (d[STRENGTH]<3) { d[STRENGTH]=3; flag=1; } - if ((d[HASTESELF]==0) || ((d[HASTESELF] & 1) == 0)) + if (d[STRENGTH] < 3) { + d[STRENGTH] = 3; + flag = 1; + } + if ((d[HASTESELF] == 0) || ((d[HASTESELF] & 1) == 0)) gltime++; if (d[HP] != d[HPMAX]) - if (d[REGENCOUNTER]-- <= 0) /* regenerate hit points */ - { - d[REGENCOUNTER] = 22 + (d[HARDGAME]<<1) - d[LEVEL]; - if ((d[HP] += d[REGEN]) > d[HPMAX]) d[HP] = d[HPMAX]; + if (d[REGENCOUNTER]-- <= 0) { /* regenerate hit points */ + d[REGENCOUNTER] = 22 + (d[HARDGAME] << 1) - d[LEVEL]; + if ((d[HP] += d[REGEN]) > d[HPMAX]) + d[HP] = d[HPMAX]; bottomhp(); - } - - if (d[SPELLS] < d[SPELLMAX]) /* regenerate spells */ - if (d[ECOUNTER]-- <= 0) - { - d[ECOUNTER] = 100+4*(d[HARDGAME]-d[LEVEL]-d[ENERGY]); - d[SPELLS]++; bottomspell(); - } - - if (d[HERO]) if (--d[HERO]<=0) { for (i=0; i<6; i++) d[i] -= 10; flag=1; } - if (d[ALTPRO]) if (--d[ALTPRO]<=0) { d[MOREDEFENSES]-=3; flag=1; } - if (d[PROTECTIONTIME]) if (--d[PROTECTIONTIME]<=0) { d[MOREDEFENSES]-=2; flag=1; } - if (d[DEXCOUNT]) if (--d[DEXCOUNT]<=0) { d[DEXTERITY]-=3; flag=1; } - if (d[STRCOUNT]) if (--d[STRCOUNT]<=0) { d[STREXTRA]-=3; flag=1; } - if (d[BLINDCOUNT]) if (--d[BLINDCOUNT]<=0) { cursors(); lprcat("\nThe blindness lifts "); beep(); } - if (d[CONFUSE]) if (--d[CONFUSE]<=0) { cursors(); lprcat("\nYou regain your senses"); beep(); } - if (d[GIANTSTR]) if (--d[GIANTSTR]<=0) { d[STREXTRA] -= 20; flag=1; } - if (d[CHARMCOUNT]) if ((--d[CHARMCOUNT]) <= 0) flag=1; - if (d[INVISIBILITY]) if ((--d[INVISIBILITY]) <= 0) flag=1; - if (d[CANCELLATION]) if ((--d[CANCELLATION]) <= 0) flag=1; - if (d[WTW]) if ((--d[WTW]) <= 0) flag=1; - if (d[HASTESELF]) if ((--d[HASTESELF]) <= 0) flag=1; - if (d[AGGRAVATE]) --d[AGGRAVATE]; - if (d[SCAREMONST]) if ((--d[SCAREMONST]) <= 0) flag=1; - if (d[STEALTH]) if ((--d[STEALTH]) <= 0) flag=1; - if (d[AWARENESS]) --d[AWARENESS]; - if (d[HOLDMONST]) if ((--d[HOLDMONST]) <= 0) flag=1; - if (d[HASTEMONST]) --d[HASTEMONST]; - if (d[FIRERESISTANCE]) if ((--d[FIRERESISTANCE]) <= 0) flag=1; - if (d[GLOBE]) if (--d[GLOBE]<=0) { d[MOREDEFENSES]-=10; flag=1; } - if (d[SPIRITPRO]) if (--d[SPIRITPRO] <= 0) flag=1; - if (d[UNDEADPRO]) if (--d[UNDEADPRO] <= 0) flag=1; - if (d[HALFDAM]) if (--d[HALFDAM]<=0) { cursors(); lprcat("\nYou now feel better "); beep(); } + } + if (d[SPELLS] < d[SPELLMAX]) /* regenerate spells */ + if (d[ECOUNTER]-- <= 0) { + d[ECOUNTER] = 100 + 4 * (d[HARDGAME] - d[LEVEL] - d[ENERGY]); + d[SPELLS]++; + bottomspell(); + } + if (d[HERO]) + if (--d[HERO] <= 0) { + for (i = 0; i < 6; i++) + d[i] -= 10; + flag = 1; + } + if (d[ALTPRO]) + if (--d[ALTPRO] <= 0) { + d[MOREDEFENSES] -= 3; + flag = 1; + } + if (d[PROTECTIONTIME]) + if (--d[PROTECTIONTIME] <= 0) { + d[MOREDEFENSES] -= 2; + flag = 1; + } + if (d[DEXCOUNT]) + if (--d[DEXCOUNT] <= 0) { + d[DEXTERITY] -= 3; + flag = 1; + } + if (d[STRCOUNT]) + if (--d[STRCOUNT] <= 0) { + d[STREXTRA] -= 3; + flag = 1; + } + if (d[BLINDCOUNT]) + if (--d[BLINDCOUNT] <= 0) { + cursors(); + lprcat("\nThe blindness lifts "); + beep(); + } + if (d[CONFUSE]) + if (--d[CONFUSE] <= 0) { + cursors(); + lprcat("\nYou regain your senses"); + beep(); + } + if (d[GIANTSTR]) + if (--d[GIANTSTR] <= 0) { + d[STREXTRA] -= 20; + flag = 1; + } + if (d[CHARMCOUNT]) + if ((--d[CHARMCOUNT]) <= 0) + flag = 1; + if (d[INVISIBILITY]) + if ((--d[INVISIBILITY]) <= 0) + flag = 1; + if (d[CANCELLATION]) + if ((--d[CANCELLATION]) <= 0) + flag = 1; + if (d[WTW]) + if ((--d[WTW]) <= 0) + flag = 1; + if (d[HASTESELF]) + if ((--d[HASTESELF]) <= 0) + flag = 1; + if (d[AGGRAVATE]) + --d[AGGRAVATE]; + if (d[SCAREMONST]) + if ((--d[SCAREMONST]) <= 0) + flag = 1; + if (d[STEALTH]) + if ((--d[STEALTH]) <= 0) + flag = 1; + if (d[AWARENESS]) + --d[AWARENESS]; + if (d[HOLDMONST]) + if ((--d[HOLDMONST]) <= 0) + flag = 1; + if (d[HASTEMONST]) + --d[HASTEMONST]; + if (d[FIRERESISTANCE]) + if ((--d[FIRERESISTANCE]) <= 0) + flag = 1; + if (d[GLOBE]) + if (--d[GLOBE] <= 0) { + d[MOREDEFENSES] -= 10; + flag = 1; + } + if (d[SPIRITPRO]) + if (--d[SPIRITPRO] <= 0) + flag = 1; + if (d[UNDEADPRO]) + if (--d[UNDEADPRO] <= 0) + flag = 1; + if (d[HALFDAM]) + if (--d[HALFDAM] <= 0) { + cursors(); + lprcat("\nYou now feel better "); + beep(); + } if (d[SEEINVISIBLE]) - if (--d[SEEINVISIBLE]<=0) - { monstnamelist[INVISIBLESTALKER] = ' '; - cursors(); lprcat("\nYou feel your vision return to normal"); beep(); } - if (d[ITCHING]) - { - if (d[ITCHING]>1) - if ((d[WEAR]!= -1) || (d[SHIELD]!= -1)) - if (rnd(100)<50) - { - d[WEAR]=d[SHIELD]= -1; cursors(); - lprcat("\nThe hysteria of itching forces you to remove your armor!"); - beep(); recalc(); bottomline(); - } - if (--d[ITCHING]<=0) { cursors(); lprcat("\nYou now feel the irritation subside!"); beep(); } + if (--d[SEEINVISIBLE] <= 0) { + monstnamelist[INVISIBLESTALKER] = ' '; + cursors(); + lprcat("\nYou feel your vision return to normal"); + beep(); + } + if (d[ITCHING]) { + if (d[ITCHING] > 1) + if ((d[WEAR] != -1) || (d[SHIELD] != -1)) + if (rnd(100) < 50) { + d[WEAR] = d[SHIELD] = -1; + cursors(); + lprcat("\nThe hysteria of itching forces you to remove your armor!"); + beep(); + recalc(); + bottomline(); + } + if (--d[ITCHING] <= 0) { + cursors(); + lprcat("\nYou now feel the irritation subside!"); + beep(); } - if (d[CLUMSINESS]) - { + } + if (d[CLUMSINESS]) { if (d[WIELD] != -1) - if (d[CLUMSINESS]>1) - if (item[playerx][playery]==0) /* only if nothing there */ - if (rnd(100)<33) /* drop your weapon due to clumsiness */ - drop_object((int)d[WIELD]); - if (--d[CLUMSINESS]<=0) { cursors(); lprcat("\nYou now feel less awkward!"); beep(); } + if (d[CLUMSINESS] > 1) + if (item[playerx][playery] == 0) /* only if nothing there */ + if (rnd(100) < 33) /* drop your weapon due + * to clumsiness */ + drop_object((int) d[WIELD]); + if (--d[CLUMSINESS] <= 0) { + cursors(); + lprcat("\nYou now feel less awkward!"); + beep(); } - if (flag) bottomline(); } - + if (flag) + bottomline(); +} diff --git a/larn/savelev.c b/larn/savelev.c index 4761233c..88c4849f 100644 --- a/larn/savelev.c +++ b/larn/savelev.c @@ -1,51 +1,65 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: savelev.c,v 1.3 1995/03/23 08:34:13 cgd Exp $"; -#endif /* not lint */ +/* $NetBSD: savelev.c,v 1.4 1997/10/18 20:03:45 christos Exp $ */ /* savelev.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: savelev.c,v 1.4 1997/10/18 20:03:45 christos Exp $"); +#endif /* not lint */ #include "header.h" -extern struct cel *cell; +#include "extern.h" /* * routine to save the present level into storage */ +void savelevel() - { - register struct cel *pcel; - register char *pitem,*pknow,*pmitem; - register short *phitp,*piarg; - register struct cel *pecel; - pcel = &cell[level*MAXX*MAXY]; /* pointer to this level's cells */ - pecel = pcel + MAXX*MAXY; /* pointer to past end of this level's cells */ - pitem=item[0]; piarg=iarg[0]; pknow=know[0]; pmitem=mitem[0]; phitp=hitp[0]; - while (pcel < pecel) - { - pcel->mitem = *pmitem++; - pcel->hitp = *phitp++; - pcel->item = *pitem++; - pcel->know = *pknow++; +{ + struct cel *pcel; + char *pitem, *pknow, *pmitem; + short *phitp, *piarg; + struct cel *pecel; + pcel = &cell[level * MAXX * MAXY]; /* pointer to this level's + * cells */ + pecel = pcel + MAXX * MAXY; /* pointer to past end of this + * level's cells */ + pitem = item[0]; + piarg = iarg[0]; + pknow = know[0]; + pmitem = mitem[0]; + phitp = hitp[0]; + while (pcel < pecel) { + pcel->mitem = *pmitem++; + pcel->hitp = *phitp++; + pcel->item = *pitem++; + pcel->know = *pknow++; pcel++->iarg = *piarg++; - } } +} /* * routine to restore a level from storage */ +void getlevel() - { - register struct cel *pcel; - register char *pitem,*pknow,*pmitem; - register short *phitp,*piarg; - register struct cel *pecel; - pcel = &cell[level*MAXX*MAXY]; /* pointer to this level's cells */ - pecel = pcel + MAXX*MAXY; /* pointer to past end of this level's cells */ - pitem=item[0]; piarg=iarg[0]; pknow=know[0]; pmitem=mitem[0]; phitp=hitp[0]; - while (pcel < pecel) - { +{ + struct cel *pcel; + char *pitem, *pknow, *pmitem; + short *phitp, *piarg; + struct cel *pecel; + pcel = &cell[level * MAXX * MAXY]; /* pointer to this level's + * cells */ + pecel = pcel + MAXX * MAXY; /* pointer to past end of this + * level's cells */ + pitem = item[0]; + piarg = iarg[0]; + pknow = know[0]; + pmitem = mitem[0]; + phitp = hitp[0]; + while (pcel < pecel) { *pmitem++ = pcel->mitem; *phitp++ = pcel->hitp; *pitem++ = pcel->item; *pknow++ = pcel->know; *piarg++ = pcel++->iarg; - } } +} diff --git a/larn/scores.c b/larn/scores.c index 6c5724e8..2fbe635e 100644 --- a/larn/scores.c +++ b/larn/scores.c @@ -1,674 +1,832 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: scores.c,v 1.9 1997/07/13 20:21:39 christos Exp $"; -#endif /* not lint */ +/* $NetBSD: scores.c,v 1.10 1997/10/18 20:03:48 christos Exp $ */ -/* scores.c Larn is copyrighted 1986 by Noah Morgan. - * - * Functions in this file are: - * - * readboard() Function to read in the scoreboard into a static buffer - * writeboard() Function to write the scoreboard from readboard()'s buffer - * makeboard() Function to create a new scoreboard (wipe out old one) - * hashewon() Function to return 1 if player has won a game before, else 0 - * long paytaxes(x) Function to pay taxes if any are due - * winshou() Subroutine to print out the winning scoreboard - * shou(x) Subroutine to print out the non-winners scoreboard - * showscores() Function to show the scoreboard on the terminal - * showallscores() Function to show scores and the iven lists that go with them - * sortboard() Function to sort the scoreboard - * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard - * new1sub(score,i,whoo,taxes) Subroutine to put player into a - * new2sub(score,i,whoo,whyded) Subroutine to put player into a - * died(x) Subroutine to record who played larn, and what the score was - * diedsub(x) Subroutine to print out a line showing player when he is killed - * diedlog() Subroutine to read a log file and print it out in ascii format - * getplid(name) Function to get players id # from id file - * +/* + * scores.c Larn is copyrighted 1986 by Noah Morgan. + * + * Functions in this file are: + * + * readboard() Function to read in the scoreboard into a static buffer + * writeboard() Function to write the scoreboard from readboard()'s buffer + * makeboard() Function to create a new scoreboard (wipe out old one) + * hashewon() Function to return 1 if player has won a game before, else 0 + * long paytaxes(x) Function to pay taxes if any are due winshou() + * ubroutine to print out the winning scoreboard shou(x) + * ubroutine to print out the non-winners scoreboard showscores() + * unction to show the scoreboard on the terminal showallscores() + * Function to show scores and the iven lists that go with them sortboard() + * unction to sort the scoreboard newscore(score, whoo, whyded, winner) + * Function to add entry to scoreboard new1sub(score,i,whoo,taxes) + * Subroutine to put player into a new2sub(score,i,whoo,whyded) + * Subroutine to put player into a died(x) Subroutine to record who + * played larn, and what the score was diedsub(x) Subroutine to print out a + * line showing player when he is killed diedlog() Subroutine to read a + * log file and print it out in ascii format getplid(name) + * on to get players id # from id file + * */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: scores.c,v 1.10 1997/10/18 20:03:48 christos Exp $"); +#endif /* not lint */ #include <sys/types.h> #include <sys/times.h> #include <sys/stat.h> -#include "header.h" +#include <stdio.h> #include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include "header.h" +#include "extern.h" -struct scofmt /* This is the structure for the scoreboard */ - { - long score; /* the score of the player */ - long suid; /* the user id number of the player */ - short what; /* the number of the monster that killed player */ - short level; /* the level player was on when he died */ - short hardlev; /* the level of difficulty player played at */ - short order; /* the relative ordering place of this entry */ - char who[40]; /* the name of the character */ - char sciv[26][2]; /* this is the inventory list of the character */ - }; -struct wscofmt /* This is the structure for the winning scoreboard */ - { - long score; /* the score of the player */ - long timeused; /* the time used in mobuls to win the game */ - long taxes; /* taxes he owes to LRS */ - long suid; /* the user id number of the player */ - short hardlev; /* the level of difficulty player played at */ - short order; /* the relative ordering place of this entry */ - char who[40]; /* the name of the character */ - }; +struct scofmt { /* This is the structure for the scoreboard */ + long score; /* the score of the player */ + long suid; /* the user id number of the player */ + short what; /* the number of the monster that killed + * player */ + short level; /* the level player was on when he died */ + short hardlev;/* the level of difficulty player played at */ + short order; /* the relative ordering place of this entry */ + char who[40];/* the name of the character */ + char sciv[26][2]; /* this is the inventory list of the + * character */ +}; +struct wscofmt { /* This is the structure for the winning + * scoreboard */ + long score; /* the score of the player */ + long timeused; /* the time used in mobuls to win the + * game */ + long taxes; /* taxes he owes to LRS */ + long suid; /* the user id number of the player */ + short hardlev;/* the level of difficulty player played at */ + short order; /* the relative ordering place of this entry */ + char who[40];/* the name of the character */ +}; -struct log_fmt /* 102 bytes struct for the log file */ - { - long score; /* the players score */ - time_t diedtime; /* time when game was over */ - short cavelev; /* level in caves */ - short diff; /* difficulty player played at */ +struct log_fmt { /* 102 bytes struct for the log file */ + long score; /* the players score */ + time_t diedtime; /* time when game was over */ + short cavelev;/* level in caves */ + short diff; /* difficulty player played at */ #ifdef EXTRA - long elapsedtime; /* real time of game in seconds */ - long bytout; /* bytes input and output */ - long bytin; - long moves; /* number of moves made by player */ - short ac; /* armor class of player */ - short hp,hpmax; /* players hitpoints */ - short cputime; /* cpu time needed in seconds */ - short killed,spused;/* monsters killed and spells cast */ - short usage; /* usage of the cpu in % */ - short lev; /* player level */ + long elapsedtime; /* real time of game in seconds */ + long bytout; /* bytes input and output */ + long bytin; + long moves; /* number of moves made by player */ + short ac; /* armor class of player */ + short hp, hpmax; /* players hitpoints */ + short cputime;/* cpu time needed in seconds */ + short killed, spused; /* monsters killed and spells cast */ + short usage; /* usage of the cpu in % */ + short lev; /* player level */ #endif - char who[12]; /* player name */ - char what[46]; /* what happened to player */ - }; + char who[12];/* player name */ + char what[46]; /* what happened to player */ +}; static struct scofmt sco[SCORESIZE]; /* the structure for the scoreboard */ static struct wscofmt winr[SCORESIZE]; /* struct for the winning scoreboard */ -static struct log_fmt logg; /* structure for the log file */ -static char *whydead[] = { +static struct log_fmt logg; /* structure for the log file */ +static char *whydead[] = { "quit", "suspended", "self - annihilated", "shot by an arrow", "hit by a dart", "fell into a pit", "fell into a bottomless pit", "a winner", "trapped in solid rock", "killed by a missing save file", "killed by an old save file", "caught by the greedy cheater checker trap", - "killed by a protected save file","killed his family and committed suicide", + "killed by a protected save file", "killed his family and committed suicide", "erased by a wayward finger", "fell through a bottomless trap door", "fell through a trap door", "drank some poisonous water", "fried by an electric shock", "slipped on a volcano shaft", "killed by a stupid act of frustration", "attacked by a revolting demon", "hit by his own magic", "demolished by an unseen attacker", "fell into the dreadful sleep", "killed by an exploding chest", -/*26*/ "killed by a missing maze data file", "annihilated in a sphere", - "died a post mortem death","wasted by a malloc() failure" - }; + /* 26 */ "killed by a missing maze data file", "annihilated in a sphere", + "died a post mortem death", "wasted by a malloc() failure" +}; /* - * readboard() Function to read in the scoreboard into a static buffer + * readboard() Function to read in the scoreboard into a static buffer * - * returns -1 if unable to read in the scoreboard, returns 0 if all is OK + * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ +int readboard() - { - int i; +{ + int i; seteuid(euid); i = lopen(scorefile); seteuid(uid); - if (i<0) - { lprcat("Can't read scoreboard\n"); lflush(); return(-1); } - lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr)); - lrclose(); lcreat((char*)0); return(0); + if (i < 0) { + lprcat("Can't read scoreboard\n"); + lflush(); + return (-1); } + lrfill((char *) sco, sizeof(sco)); + lrfill((char *) winr, sizeof(winr)); + lrclose(); + lcreat((char *) 0); + return (0); +} /* - * writeboard() Function to write the scoreboard from readboard()'s buffer + * writeboard() Function to write the scoreboard from readboard()'s buffer * - * returns -1 if unable to write the scoreboard, returns 0 if all is OK + * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ +int writeboard() - { - int i; +{ + int i; set_score_output(); seteuid(euid); i = lcreat(scorefile); seteuid(uid); - if (i<0) - { lprcat("Can't write scoreboard\n"); lflush(); return(-1); } - lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr)); - lwclose(); lcreat((char*)0); return(0); + if (i < 0) { + lprcat("Can't write scoreboard\n"); + lflush(); + return (-1); } + lwrite((char *) sco, sizeof(sco)); + lwrite((char *) winr, sizeof(winr)); + lwclose(); + lcreat((char *) 0); + return (0); +} /* - * makeboard() Function to create a new scoreboard (wipe out old one) + * makeboard() Function to create a new scoreboard (wipe out old one) * - * returns -1 if unable to write the scoreboard, returns 0 if all is OK + * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ +int makeboard() - { - register int i; - for (i=0; i<SCORESIZE; i++) - { +{ + int i; + for (i = 0; i < SCORESIZE; i++) { winr[i].taxes = winr[i].score = sco[i].score = 0; winr[i].order = sco[i].order = i; - } - if (writeboard()) return(-1); + } + if (writeboard()) + return (-1); seteuid(euid); - chmod(scorefile,0660); + chmod(scorefile, 0660); seteuid(uid); - return(0); - } + return (0); +} /* - * hashewon() Function to return 1 if player has won a game before, else 0 + * hashewon() Function to return 1 if player has won a game before, else 0 * - * This function also sets c[HARDGAME] to appropriate value -- 0 if not a - * winner, otherwise the next level of difficulty listed in the winners - * scoreboard. This function also sets outstanding_taxes to the value in - * the winners scoreboard. + * This function also sets c[HARDGAME] to appropriate value -- 0 if not a + * winner, otherwise the next level of difficulty listed in the winners + * scoreboard. This function also sets outstanding_taxes to the value in + * the winners scoreboard. */ +int hashewon() - { - register int i; +{ + int i; c[HARDGAME] = 0; - if (readboard() < 0) return(0); /* can't find scoreboard */ - for (i=0; i<SCORESIZE; i++) /* search through winners scoreboard */ - if (winr[i].suid == userid) - if (winr[i].score > 0) - { - c[HARDGAME]=winr[i].hardlev+1; outstanding_taxes=winr[i].taxes; - return(1); + if (readboard() < 0) + return (0); /* can't find scoreboard */ + for (i = 0; i < SCORESIZE; i++) /* search through winners scoreboard */ + if (winr[i].suid == userid) + if (winr[i].score > 0) { + c[HARDGAME] = winr[i].hardlev + 1; + outstanding_taxes = winr[i].taxes; + return (1); } - return(0); - } + return (0); +} /* - * long paytaxes(x) Function to pay taxes if any are due + * long paytaxes(x) Function to pay taxes if any are due * - * Enter with the amount (in gp) to pay on the taxes. - * Returns amount actually paid. + * Enter with the amount (in gp) to pay on the taxes. + * Returns amount actually paid. */ -long paytaxes(x) - long x; - { - register int i; - register long amt; - if (x<0) return(0L); - if (readboard()<0) return(0L); - for (i=0; i<SCORESIZE; i++) - if (winr[i].suid == userid) /* look for players winning entry */ - if (winr[i].score>0) /* search for a winning entry for the player */ - { +long +paytaxes(x) + long x; +{ + int i; + long amt; + if (x < 0) + return (0L); + if (readboard() < 0) + return (0L); + for (i = 0; i < SCORESIZE; i++) + if (winr[i].suid == userid) /* look for players winning + * entry */ + if (winr[i].score > 0) { /* search for a winning + * entry for the player */ amt = winr[i].taxes; - if (x < amt) amt=x; /* don't overpay taxes (Ughhhhh) */ + if (x < amt) + amt = x; /* don't overpay taxes + * (Ughhhhh) */ winr[i].taxes -= amt; outstanding_taxes -= amt; - if (writeboard()<0) return(0); - return(amt); - } - return(0L); /* couldn't find user on winning scoreboard */ - } + if (writeboard() < 0) + return (0); + return (amt); + } + return (0L); /* couldn't find user on winning scoreboard */ +} /* - * winshou() Subroutine to print out the winning scoreboard + * winshou() Subroutine to print out the winning scoreboard * - * Returns the number of players on scoreboard that were shown + * Returns the number of players on scoreboard that were shown */ +int winshou() - { - register struct wscofmt *p; - register int i,j,count; - for (count=j=i=0; i<SCORESIZE; i++) /* is there anyone on the scoreboard? */ - if (winr[i].score != 0) - { j++; break; } - if (j) - { +{ + struct wscofmt *p; + int i, j, count; + for (count = j = i = 0; i < SCORESIZE; i++) /* is there anyone on + * the scoreboard? */ + if (winr[i].score != 0) { + j++; + break; + } + if (j) { lprcat("\n Score Difficulty Time Needed Larn Winners List\n"); - for (i=0; i<SCORESIZE; i++) /* this loop is needed to print out the */ - for (j=0; j<SCORESIZE; j++) /* winners in order */ - { - p = &winr[j]; /* pointer to the scoreboard entry */ - if (p->order == i) - { - if (p->score) - { - count++; - lprintf("%10d %2d %5d Mobuls %s \n", - (long)p->score,(long)p->hardlev,(long)p->timeused,p->who); + for (i = 0; i < SCORESIZE; i++) /* this loop is needed to + * print out the */ + for (j = 0; j < SCORESIZE; j++) { /* winners in order */ + p = &winr[j]; /* pointer to the scoreboard + * entry */ + if (p->order == i) { + if (p->score) { + count++; + lprintf("%10d %2d %5d Mobuls %s \n", + (long) p->score, (long) p->hardlev, (long) p->timeused, p->who); } - break; + break; } } - } - return(count); /* return number of people on scoreboard */ } + return (count); /* return number of people on scoreboard */ +} /* - * shou(x) Subroutine to print out the non-winners scoreboard - * int x; + * shou(x) Subroutine to print out the non-winners scoreboard + * int x; * - * Enter with 0 to list the scores, enter with 1 to list inventories too - * Returns the number of players on scoreboard that were shown + * Enter with 0 to list the scores, enter with 1 to list inventories too + * Returns the number of players on scoreboard that were shown */ +int shou(x) - int x; - { - register int i,j,n,k; - int count; - for (count=j=i=0; i<SCORESIZE; i++) /* is the scoreboard empty? */ - if (sco[i].score!= 0) - { j++; break; } - if (j) - { + int x; +{ + int i, j, n, k; + int count; + for (count = j = i = 0; i < SCORESIZE; i++) /* is the scoreboard + * empty? */ + if (sco[i].score != 0) { + j++; + break; + } + if (j) { lprcat("\n Score Difficulty Larn Visitor Log\n"); - for (i=0; i<SCORESIZE; i++) /* be sure to print them out in order */ - for (j=0; j<SCORESIZE; j++) - if (sco[j].order == i) - { - if (sco[j].score) - { - count++; - lprintf("%10d %2d %s ", - (long)sco[j].score,(long)sco[j].hardlev,sco[j].who); - if (sco[j].what < 256) lprintf("killed by a %s",monster[sco[j].what].name); - else lprintf("%s",whydead[sco[j].what - 256]); - if (x != 263) lprintf(" on %s",levelname[sco[j].level]); - if (x) - { - for (n=0; n<26; n++) { iven[n]=sco[j].sciv[n][0]; ivenarg[n]=sco[j].sciv[n][1]; } - for (k=1; k<99; k++) - for (n=0; n<26; n++) - if (k==iven[n]) { srcount=0; show3(n); } - lprcat("\n\n"); - } - else lprc('\n'); + for (i = 0; i < SCORESIZE; i++) /* be sure to print them out + * in order */ + for (j = 0; j < SCORESIZE; j++) + if (sco[j].order == i) { + if (sco[j].score) { + count++; + lprintf("%10d %2d %s ", + (long) sco[j].score, (long) sco[j].hardlev, sco[j].who); + if (sco[j].what < 256) + lprintf("killed by a %s", monster[sco[j].what].name); + else + lprintf("%s", whydead[sco[j].what - 256]); + if (x != 263) + lprintf(" on %s", levelname[sco[j].level]); + if (x) { + for (n = 0; n < 26; n++) { + iven[n] = sco[j].sciv[n][0]; + ivenarg[n] = sco[j].sciv[n][1]; + } + for (k = 1; k < 99; k++) + for (n = 0; n < 26; n++) + if (k == iven[n]) { + srcount = 0; + show3(n); + } + lprcat("\n\n"); + } else + lprc('\n'); } - j=SCORESIZE; + j = SCORESIZE; } - } - return(count); /* return the number of players just shown */ } + return (count); /* return the number of players just shown */ +} /* - * showscores() Function to show the scoreboard on the terminal + * showscores() Function to show the scoreboard on the terminal * - * Returns nothing of value + * Returns nothing of value */ -static char esb[] = "The scoreboard is empty.\n"; +static char esb[] = "The scoreboard is empty.\n"; +void showscores() - { - register int i,j; - lflush(); lcreat((char*)0); if (readboard()<0) return; - i=winshou(); j=shou(0); - if (i+j == 0) lprcat(esb); else lprc('\n'); +{ + int i, j; lflush(); - } + lcreat((char *) 0); + if (readboard() < 0) + return; + i = winshou(); + j = shou(0); + if (i + j == 0) + lprcat(esb); + else + lprc('\n'); + lflush(); +} /* - * showallscores() Function to show scores and the iven lists that go with them + * showallscores() Function to show scores and the iven lists that go with them * - * Returns nothing of value + * Returns nothing of value */ +void showallscores() - { - register int i,j; - lflush(); lcreat((char*)0); if (readboard()<0) return; - c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing anything */ - for (i=0; i<MAXPOTION; i++) potionname[i]=potionhide[i]; - for (i=0; i<MAXSCROLL; i++) scrollname[i]=scrollhide[i]; - i=winshou(); j=shou(1); - if (i+j==0) lprcat(esb); else lprc('\n'); +{ + int i, j; lflush(); - } + lcreat((char *) 0); + if (readboard() < 0) + return; + c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing + * anything */ + for (i = 0; i < MAXPOTION; i++) + potionname[i] = potionhide[i]; + for (i = 0; i < MAXSCROLL; i++) + scrollname[i] = scrollhide[i]; + i = winshou(); + j = shou(1); + if (i + j == 0) + lprcat(esb); + else + lprc('\n'); + lflush(); +} /* - * sortboard() Function to sort the scoreboard + * sortboard() Function to sort the scoreboard * - * Returns 0 if no sorting done, else returns 1 + * Returns 0 if no sorting done, else returns 1 */ +int sortboard() - { - register int i,j,pos; - long jdat; - for (i=0; i<SCORESIZE; i++) sco[i].order = winr[i].order = -1; - pos=0; while (pos < SCORESIZE) - { - jdat=0; - for (i=0; i<SCORESIZE; i++) - if ((sco[i].order < 0) && (sco[i].score >= jdat)) - { j=i; jdat=sco[i].score; } +{ + int i, j = 0, pos; + long jdat; + for (i = 0; i < SCORESIZE; i++) + sco[i].order = winr[i].order = -1; + pos = 0; + while (pos < SCORESIZE) { + jdat = 0; + for (i = 0; i < SCORESIZE; i++) + if ((sco[i].order < 0) && (sco[i].score >= jdat)) { + j = i; + jdat = sco[i].score; + } sco[j].order = pos++; - } - pos=0; while (pos < SCORESIZE) - { - jdat=0; - for (i=0; i<SCORESIZE; i++) - if ((winr[i].order < 0) && (winr[i].score >= jdat)) - { j=i; jdat=winr[i].score; } + } + pos = 0; + while (pos < SCORESIZE) { + jdat = 0; + for (i = 0; i < SCORESIZE; i++) + if ((winr[i].order < 0) && (winr[i].score >= jdat)) { + j = i; + jdat = winr[i].score; + } winr[j].order = pos++; - } - return(1); } + return (1); +} /* - * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard - * int score, winner, whyded; - * char *whoo; + * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard + * int score, winner, whyded; + * char *whoo; * - * Enter with the total score in gp in score, players name in whoo, - * died() reason # in whyded, and TRUE/FALSE in winner if a winner - * ex. newscore(1000, "player 1", 32, 0); + * Enter with the total score in gp in score, players name in whoo, + * died() reason # in whyded, and TRUE/FALSE in winner if a winner + * ex. newscore(1000, "player 1", 32, 0); */ +void newscore(score, whoo, whyded, winner) - long score; - int winner, whyded; - char *whoo; - { - register int i; - long taxes; - if (readboard() < 0) return; /* do the scoreboard */ + long score; + int winner, whyded; + char *whoo; +{ + int i; + long taxes; + if (readboard() < 0) + return; /* do the scoreboard */ /* if a winner then delete all non-winning scores */ - if (cheat) winner=0; /* if he cheated, don't let him win */ - if (winner) - { - for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) sco[i].score=0; - taxes = score*TAXRATE; - score += 100000*c[HARDGAME]; /* bonus for winning */ - /* if he has a slot on the winning scoreboard update it if greater score */ - for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid) - { new1sub(score,i,whoo,taxes); return; } - /* he had no entry. look for last entry and see if he has a greater score */ - for (i=0; i<SCORESIZE; i++) if (winr[i].order == SCORESIZE-1) - { new1sub(score,i,whoo,taxes); return; } - } - else if (!cheat) /* for not winning scoreboard */ - { - /* if he has a slot on the scoreboard update it if greater score */ - for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) - { new2sub(score,i,whoo,whyded); return; } - /* he had no entry. look for last entry and see if he has a greater score */ - for (i=0; i<SCORESIZE; i++) if (sco[i].order == SCORESIZE-1) - { new2sub(score,i,whoo,whyded); return; } - } + if (cheat) + winner = 0; /* if he cheated, don't let him win */ + if (winner) { + for (i = 0; i < SCORESIZE; i++) + if (sco[i].suid == userid) + sco[i].score = 0; + taxes = score * TAXRATE; + score += 100000 * c[HARDGAME]; /* bonus for winning */ + /* + * if he has a slot on the winning scoreboard update it if + * greater score + */ + for (i = 0; i < SCORESIZE; i++) + if (winr[i].suid == userid) { + new1sub(score, i, whoo, taxes); + return; + } + /* + * he had no entry. look for last entry and see if he has a + * greater score + */ + for (i = 0; i < SCORESIZE; i++) + if (winr[i].order == SCORESIZE - 1) { + new1sub(score, i, whoo, taxes); + return; + } + } else if (!cheat) { /* for not winning scoreboard */ + /* + * if he has a slot on the scoreboard update it if greater + * score + */ + for (i = 0; i < SCORESIZE; i++) + if (sco[i].suid == userid) { + new2sub(score, i, whoo, whyded); + return; + } + /* + * he had no entry. look for last entry and see if he has a + * greater score + */ + for (i = 0; i < SCORESIZE; i++) + if (sco[i].order == SCORESIZE - 1) { + new2sub(score, i, whoo, whyded); + return; + } } +} /* - * new1sub(score,i,whoo,taxes) Subroutine to put player into a - * int score,i,whyded,taxes; winning scoreboard entry if his score - * char *whoo; is high enough + * new1sub(score,i,whoo,taxes) Subroutine to put player into a + * int score,i,whyded,taxes; winning scoreboard entry if his score + * char *whoo; is high enough * - * Enter with the total score in gp in score, players name in whoo, - * died() reason # in whyded, and TRUE/FALSE in winner if a winner - * slot in scoreboard in i, and the tax bill in taxes. - * Returns nothing of value + * Enter with the total score in gp in score, players name in whoo, + * died() reason # in whyded, and TRUE/FALSE in winner if a winner + * slot in scoreboard in i, and the tax bill in taxes. + * Returns nothing of value */ -new1sub(score,i,whoo,taxes) - long score,taxes; - int i; - char *whoo; - { - register struct wscofmt *p; +void +new1sub(score, i, whoo, taxes) + long score, taxes; + int i; + char *whoo; +{ + struct wscofmt *p; p = &winr[i]; p->taxes += taxes; - if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) - { - strcpy(p->who,whoo); p->score=score; - p->hardlev=c[HARDGAME]; p->suid=userid; - p->timeused=gltime/100; - } + if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) { + strcpy(p->who, whoo); + p->score = score; + p->hardlev = c[HARDGAME]; + p->suid = userid; + p->timeused = gltime / 100; } +} /* - * new2sub(score,i,whoo,whyded) Subroutine to put player into a - * int score,i,whyded,taxes; non-winning scoreboard entry if his - * char *whoo; score is high enough + * new2sub(score,i,whoo,whyded) Subroutine to put player into a + * int score,i,whyded,taxes; non-winning scoreboard entry if his + * char *whoo; score is high enough * - * Enter with the total score in gp in score, players name in whoo, - * died() reason # in whyded, and slot in scoreboard in i. - * Returns nothing of value + * Enter with the total score in gp in score, players name in whoo, + * died() reason # in whyded, and slot in scoreboard in i. + * Returns nothing of value */ -new2sub(score,i,whoo,whyded) - long score; - int i,whyded; - char *whoo; - { - register int j; - register struct scofmt *p; +void +new2sub(score, i, whoo, whyded) + long score; + int i, whyded; + char *whoo; +{ + int j; + struct scofmt *p; p = &sco[i]; - if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) - { - strcpy(p->who,whoo); p->score=score; - p->what=whyded; p->hardlev=c[HARDGAME]; - p->suid=userid; p->level=level; - for (j=0; j<26; j++) - { p->sciv[j][0]=iven[j]; p->sciv[j][1]=ivenarg[j]; } + if ((score >= p->score) || (c[HARDGAME] > p->hardlev)) { + strcpy(p->who, whoo); + p->score = score; + p->what = whyded; + p->hardlev = c[HARDGAME]; + p->suid = userid; + p->level = level; + for (j = 0; j < 26; j++) { + p->sciv[j][0] = iven[j]; + p->sciv[j][1] = ivenarg[j]; } } +} /* - * died(x) Subroutine to record who played larn, and what the score was - * int x; + * died(x) Subroutine to record who played larn, and what the score was + * int x; * - * if x < 0 then don't show scores - * died() never returns! (unless c[LIFEPROT] and a reincarnatable death!) + * if x < 0 then don't show scores + * died() never returns! (unless c[LIFEPROT] and a reincarnatable death!) * - * < 256 killed by the monster number - * 256 quit - * 257 suspended - * 258 self - annihilated - * 259 shot by an arrow - * 260 hit by a dart - * 261 fell into a pit - * 262 fell into a bottomless pit - * 263 a winner - * 264 trapped in solid rock - * 265 killed by a missing save file - * 266 killed by an old save file - * 267 caught by the greedy cheater checker trap - * 268 killed by a protected save file - * 269 killed his family and killed himself - * 270 erased by a wayward finger - * 271 fell through a bottomless trap door - * 272 fell through a trap door - * 273 drank some poisonous water - * 274 fried by an electric shock - * 275 slipped on a volcano shaft - * 276 killed by a stupid act of frustration - * 277 attacked by a revolting demon - * 278 hit by his own magic - * 279 demolished by an unseen attacker - * 280 fell into the dreadful sleep - * 281 killed by an exploding chest - * 282 killed by a missing maze data file - * 283 killed by a sphere of annihilation - * 284 died a post mortem death - * 285 malloc() failure - * 300 quick quit -- don't put on scoreboard + * < 256 killed by the monster number + * 256 quit + * 257 suspended + * 258 self - annihilated + * 259 shot by an arrow + * 260 hit by a dart + * 261 fell into a pit + * 262 fell into a bottomless pit + * 263 a winner + * 264 trapped in solid rock + * 265 killed by a missing save file + * 266 killed by an old save file + * 267 caught by the greedy cheater checker trap + * 268 killed by a protected save file + * 269 killed his family and killed himself + * 270 erased by a wayward finger + * 271 fell through a bottomless trap door + * 272 fell through a trap door + * 273 drank some poisonous water + * 274 fried by an electric shock + * 275 slipped on a volcano shaft + * 276 killed by a stupid act of frustration + * 277 attacked by a revolting demon + * 278 hit by his own magic + * 279 demolished by an unseen attacker + * 280 fell into the dreadful sleep + * 281 killed by an exploding chest + * 282 killed by a missing maze data file + * 283 killed by a sphere of annihilation + * 284 died a post mortem death + * 285 malloc() failure + * 300 quick quit -- don't put on scoreboard */ -static int scorerror; +static int scorerror; +void died(x) - int x; - { - register int f,win; - char ch,*mod; - time_t zzz; - long i; - struct tms cputime; - if (c[LIFEPROT]>0) /* if life protection */ - { - switch((x>0) ? x : -x) - { - case 256: case 257: case 262: case 263: case 265: case 266: - case 267: case 268: case 269: case 271: case 282: case 284: - case 285: case 300: goto invalid; /* can't be saved */ - }; - --c[LIFEPROT]; c[HP]=1; --c[CONSTITUTION]; - cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); beep(); - lflush(); sleep(4); - return; /* only case where died() returns */ - } + int x; +{ + int f, win; + char ch, *mod; + time_t zzz; + if (c[LIFEPROT] > 0) { /* if life protection */ + switch ((x > 0) ? x : -x) { + case 256: + case 257: + case 262: + case 263: + case 265: + case 266: + case 267: + case 268: + case 269: + case 271: + case 282: + case 284: + case 285: + case 300: + goto invalid; /* can't be saved */ + }; + --c[LIFEPROT]; + c[HP] = 1; + --c[CONSTITUTION]; + cursors(); + lprcat("\nYou feel wiiieeeeerrrrrd all over! "); + beep(); + lflush(); + sleep(4); + return; /* only case where died() returns */ + } invalid: - clearvt100(); lflush(); f=0; - if (ckpflag) unlink(ckpfile); /* remove checkpoint file if used */ - if (x<0) { f++; x = -x; } /* if we are not to display the scores */ - if ((x == 300) || (x == 257)) exit(); /* for quick exit or saved game */ - if (x == 263) win = 1; else win = 0; - c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0; - /* now enter the player at the end of the scoreboard */ + clearvt100(); + lflush(); + f = 0; + if (ckpflag) + unlink(ckpfile);/* remove checkpoint file if used */ + if (x < 0) { + f++; + x = -x; + } /* if we are not to display the scores */ + if ((x == 300) || (x == 257)) + exit(0); /* for quick exit or saved game */ + if (x == 263) + win = 1; + else + win = 0; + c[GOLD] += c[BANKACCOUNT]; + c[BANKACCOUNT] = 0; + /* now enter the player at the end of the scoreboard */ newscore(c[GOLD], logname, x, win); - diedsub(x); /* print out the score line */ lflush(); + diedsub(x); /* print out the score line */ + lflush(); set_score_output(); - if ((wizard == 0) && (c[GOLD] > 0)) /* wizards can't score */ - { + if ((wizard == 0) && (c[GOLD] > 0)) { /* wizards can't score */ #ifndef NOLOG seteuid(euid); - if (lappend(logfile)<0) /* append to file */ - { - if (lcreat(logfile)<0) /* and can't create new log file */ - { - lcreat((char*)0); + if (lappend(logfile) < 0) { /* append to file */ + if (lcreat(logfile) < 0) { /* and can't create new + * log file */ + lcreat((char *) 0); lprcat("\nCan't open record file: I can't post your score.\n"); - sncbr(); resetscroll(); lflush(); exit(); - } + sncbr(); + resetscroll(); + lflush(); + exit(0); + } seteuid(euid); - chmod(logfile,0660); + chmod(logfile, 0660); seteuid(uid); - } + } seteuid(uid); - strcpy(logg.who,loginname); - logg.score = c[GOLD]; logg.diff = c[HARDGAME]; - if (x < 256) - { + strcpy(logg.who, loginname); + logg.score = c[GOLD]; + logg.diff = c[HARDGAME]; + if (x < 256) { ch = *monster[x].name; - if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') - mod="an"; else mod="a"; - sprintf(logg.what,"killed by %s %s",mod,monster[x].name); - } - else sprintf(logg.what,"%s",whydead[x - 256]); - logg.cavelev=level; - time(&zzz); /* get cpu time -- write out score info */ - logg.diedtime=zzz; + if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') + mod = "an"; + else + mod = "a"; + sprintf(logg.what, "killed by %s %s", mod, monster[x].name); + } else + sprintf(logg.what, "%s", whydead[x - 256]); + logg.cavelev = level; + time(&zzz); /* get cpu time -- write out score info */ + logg.diedtime = zzz; #ifdef EXTRA - times(&cputime); /* get cpu time -- write out score info */ - logg.cputime = i = (cputime.tms_utime + cputime.tms_stime)/60 + c[CPUTIME]; - logg.lev=c[LEVEL]; logg.ac=c[AC]; - logg.hpmax=c[HPMAX]; logg.hp=c[HP]; - logg.elapsedtime=(zzz-initialtime+59)/60; - logg.usage=(10000*i)/(zzz-initialtime); - logg.bytin=c[BYTESIN]; logg.bytout=c[BYTESOUT]; - logg.moves=c[MOVESMADE]; logg.spused=c[SPELLSCAST]; - logg.killed=c[MONSTKILLED]; + times(&cputime);/* get cpu time -- write out score info */ + logg.cputime = i = (cputime.tms_utime + cputime.tms_stime) / 60 + c[CPUTIME]; + logg.lev = c[LEVEL]; + logg.ac = c[AC]; + logg.hpmax = c[HPMAX]; + logg.hp = c[HP]; + logg.elapsedtime = (zzz - initialtime + 59) / 60; + logg.usage = (10000 * i) / (zzz - initialtime); + logg.bytin = c[BYTESIN]; + logg.bytout = c[BYTESOUT]; + logg.moves = c[MOVESMADE]; + logg.spused = c[SPELLSCAST]; + logg.killed = c[MONSTKILLED]; #endif - lwrite((char*)&logg,sizeof(struct log_fmt)); lwclose(); -#endif NOLOG + lwrite((char *) &logg, sizeof(struct log_fmt)); + lwclose(); +#endif /* NOLOG */ -/* now for the scoreboard maintenance -- not for a suspended game */ - if (x != 257) - { - if (sortboard()) scorerror = writeboard(); - } + /* + * now for the scoreboard maintenance -- not for a suspended + * game + */ + if (x != 257) { + if (sortboard()) + scorerror = writeboard(); } - if ((x==256) || (x==257) || (f != 0)) exit(); - if (scorerror == 0) showscores(); /* if we updated the scoreboard */ - if (x == 263) mailbill(); exit(); } + if ((x == 256) || (x == 257) || (f != 0)) + exit(0); + if (scorerror == 0) + showscores(); /* if we updated the scoreboard */ + if (x == 263) + mailbill(); + exit(0); +} /* - * diedsub(x) Subroutine to print out the line showing the player when he is killed - * int x; + * diedsub(x) Subroutine to print out the line showing the player when he is killed + * int x; */ +void diedsub(x) -int x; - { - register char ch,*mod; - lprintf("Score: %d, Diff: %d, %s ",(long)c[GOLD],(long)c[HARDGAME],logname); - if (x < 256) - { + int x; +{ + char ch, *mod; + lprintf("Score: %d, Diff: %d, %s ", (long) c[GOLD], (long) c[HARDGAME], logname); + if (x < 256) { ch = *monster[x].name; - if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') - mod="an"; else mod="a"; - lprintf("killed by %s %s",mod,monster[x].name); - } - else lprintf("%s",whydead[x - 256]); - if (x != 263) lprintf(" on %s\n",levelname[level]); else lprc('\n'); - } + if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') + mod = "an"; + else + mod = "a"; + lprintf("killed by %s %s", mod, monster[x].name); + } else + lprintf("%s", whydead[x - 256]); + if (x != 263) + lprintf(" on %s\n", levelname[level]); + else + lprc('\n'); +} /* - * diedlog() Subroutine to read a log file and print it out in ascii format + * diedlog() Subroutine to read a log file and print it out in ascii format */ +void diedlog() - { - register int n; - register char *p; - struct stat stbuf; - lcreat((char*)0); - if (lopen(logfile)<0) - { - lprintf("Can't locate log file <%s>\n",logfile); +{ + int n; + char *p; + struct stat stbuf; + lcreat((char *) 0); + if (lopen(logfile) < 0) { + lprintf("Can't locate log file <%s>\n", logfile); return; - } - if (fstat(fd,&stbuf) < 0) - { - lprintf("Can't stat log file <%s>\n",logfile); + } + if (fstat(fd, &stbuf) < 0) { + lprintf("Can't stat log file <%s>\n", logfile); return; - } - for (n=stbuf.st_size/sizeof(struct log_fmt); n>0; --n) - { - lrfill((char*)&logg,sizeof(struct log_fmt)); - p = ctime(&logg.diedtime); p[16]='\n'; p[17]=0; - lprintf("Score: %d, Diff: %d, %s %s on %d at %s",(long)(logg.score),(long)(logg.diff),logg.who,logg.what,(long)(logg.cavelev),p+4); + } + for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) { + lrfill((char *) &logg, sizeof(struct log_fmt)); + p = ctime(&logg.diedtime); + p[16] = '\n'; + p[17] = 0; + lprintf("Score: %d, Diff: %d, %s %s on %d at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4); #ifdef EXTRA - if (logg.moves<=0) logg.moves=1; - lprintf(" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n",(long)(logg.lev),(long)(logg.ac),(long)(logg.hp),(long)(logg.hpmax),(long)(logg.elapsedtime)); - lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n",(long)(logg.cputime),(long)(logg.usage/100),(long)(logg.usage%100)); - lprintf(" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n",(long)(logg.bytin),(long)(logg.bytout),(long)(logg.moves),(long)(logg.killed),(long)(logg.spused)); - lprintf(" out bytes per move: %d, time per move: %d ms\n",(long)(logg.bytout/logg.moves),(long)((logg.cputime*1000)/logg.moves)); + if (logg.moves <= 0) + logg.moves = 1; + lprintf(" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime)); + lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100)); + lprintf(" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused)); + lprintf(" out bytes per move: %d, time per move: %d ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves)); #endif - } - lflush(); lrclose(); return; } + lflush(); + lrclose(); + return; +} #ifndef UIDSCORE /* - * getplid(name) Function to get players id # from id file + * getplid(name) Function to get players id # from id file * - * Enter with the name of the players character in name. - * Returns the id # of the players character, or -1 if failure. - * This routine will try to find the name in the id file, if its not there, - * it will try to make a new entry in the file. Only returns -1 if can't - * find him in the file, and can't make a new entry in the file. - * Format of playerids file: - * Id # in ascii \n character name \n + * Enter with the name of the players character in name. + * Returns the id # of the players character, or -1 if failure. + * This routine will try to find the name in the id file, if its not there, + * it will try to make a new entry in the file. Only returns -1 if can't + * find him in the file, and can't make a new entry in the file. + * Format of playerids file: + * Id # in ascii \n character name \n */ -static int havepid= -1; /* playerid # if previously done */ +static int havepid = -1; /* playerid # if previously done */ +int getplid(nam) - char *nam; - { - int fd7,high=999,no; - register char *p,*p2; - char name[80]; - if (havepid != -1) return(havepid); /* already did it */ - lflush(); /* flush any pending I/O */ - sprintf(name,"%s\n",nam); /* append a \n to name */ - if (lopen(playerids) < 0) /* no file, make it */ - { - if ((fd7=creat(playerids,0666)) < 0) return(-1); /* can't make it */ - close(fd7); goto addone; /* now append new playerid record to file */ - } - for (;;) /* now search for the name in the player id file */ - { - p = lgetl(); if (p==NULL) break; /* EOF? */ + char *nam; +{ + int fd7, high = 999, no; + char *p, *p2; + char name[80]; + if (havepid != -1) + return (havepid); /* already did it */ + lflush(); /* flush any pending I/O */ + sprintf(name, "%s\n", nam); /* append a \n to name */ + if (lopen(playerids) < 0) { /* no file, make it */ + if ((fd7 = creat(playerids, 0666)) < 0) + return (-1); /* can't make it */ + close(fd7); + goto addone; /* now append new playerid record to file */ + } + for (;;) { /* now search for the name in the player id + * file */ + p = lgetl(); + if (p == NULL) + break; /* EOF? */ no = atoi(p); /* the id # */ - p2= lgetl(); if (p2==NULL) break; /* EOF? */ - if (no>high) high=no; /* accumulate highest id # */ - if (strcmp(p2,name)==0) /* we found him */ - { - return(no); /* his id number */ - } + p2 = lgetl(); + if (p2 == NULL) + break; /* EOF? */ + if (no > high) + high = no; /* accumulate highest id # */ + if (strcmp(p2, name) == 0) { /* we found him */ + return (no); /* his id number */ } + } lrclose(); /* if we get here, we didn't find him in the file -- put him there */ addone: - if (lappend(playerids) < 0) return(-1); /* can't open file for append */ - lprintf("%d\n%s",(long)++high,name); /* new id # and name */ + if (lappend(playerids) < 0) + return (-1); /* can't open file for append */ + lprintf("%d\n%s", (long) ++high, name); /* new id # and name */ lwclose(); - lcreat((char*)0); /* re-open terminal channel */ - return(high); - } -#endif UIDSCORE - + lcreat((char *) 0); /* re-open terminal channel */ + return (high); +} +#endif /* UIDSCORE */ diff --git a/larn/signal.c b/larn/signal.c index 3b4e2f39..e16ff8ee 100644 --- a/larn/signal.c +++ b/larn/signal.c @@ -1,86 +1,140 @@ +/* $NetBSD: signal.c,v 1.6 1997/10/18 20:03:50 christos Exp $ */ + +/* "Larn is copyrighted 1986 by Noah Morgan.\n" */ + +#include <sys/cdefs.h> #ifndef lint -static char rcsid[] = "$NetBSD: signal.c,v 1.5 1995/12/21 11:27:51 mycroft Exp $"; -#endif /* not lint */ +__RCSID("$NetBSD: signal.c,v 1.6 1997/10/18 20:03:50 christos Exp $"); +#endif /* not lint */ +#include <stdio.h> #include <signal.h> -#include "header.h" /* "Larn is copyrighted 1986 by Noah Morgan.\n" */ #include <string.h> +#include <unistd.h> +#include "header.h" +#include "extern.h" + +static void s2choose __P((void)); +static void cntlc __P((int)); +static void sgam __P((int)); +static void tstop __P((int)); +static void sigpanic __P((int)); #define BIT(a) (1<<((a)-1)) -extern char savefilename[],wizard,predostuff,nosignal; -static s2choose() /* text to be displayed if ^C during intro screen */ - { - cursor(1,24); lprcat("Press "); setbold(); lprcat("return"); resetbold(); - lprcat(" to continue: "); lflush(); - } static void -cntlc() /* what to do for a ^C */ - { - if (nosignal) return; /* don't do anything if inhibited */ - signal(SIGQUIT,SIG_IGN); signal(SIGINT,SIG_IGN); - quit(); if (predostuff==1) s2choose(); else showplayer(); +s2choose() +{ /* text to be displayed if ^C during intro + * screen */ + cursor(1, 24); + lprcat("Press "); + setbold(); + lprcat("return"); + resetbold(); + lprcat(" to continue: "); + lflush(); +} + +static void +cntlc(n) + int n; +{ /* what to do for a ^C */ + if (nosignal) + return; /* don't do anything if inhibited */ + signal(SIGQUIT, SIG_IGN); + signal(SIGINT, SIG_IGN); + quit(); + if (predostuff == 1) + s2choose(); + else + showplayer(); lflush(); - signal(SIGQUIT,cntlc); signal(SIGINT,cntlc); - } + signal(SIGQUIT, cntlc); + signal(SIGINT, cntlc); +} /* * subroutine to save the game if a hangup signal */ static void -sgam() - { - savegame(savefilename); wizard=1; died(-257); /* hangup signal */ - } +sgam(n) + int n; +{ + savegame(savefilename); + wizard = 1; + died(-257); /* hangup signal */ +} #ifdef SIGTSTP static void -tstop() /* control Y */ - { - if (nosignal) return; /* nothing if inhibited */ - lcreat((char*)0); clearvt100(); lflush(); signal(SIGTSTP,SIG_DFL); +tstop(n) + int n; +{ /* control Y */ + if (nosignal) + return; /* nothing if inhibited */ + lcreat((char *) 0); + clearvt100(); + lflush(); + signal(SIGTSTP, SIG_DFL); #ifdef SIGVTALRM - /* looks like BSD4.2 or higher - must clr mask for signal to take effect*/ - sigsetmask(sigblock(0)& ~BIT(SIGTSTP)); + /* + * looks like BSD4.2 or higher - must clr mask for signal to take + * effect + */ + sigsetmask(sigblock(0) & ~BIT(SIGTSTP)); #endif - kill(getpid(),SIGTSTP); + kill(getpid(), SIGTSTP); - setupvt100(); signal(SIGTSTP,tstop); - if (predostuff==1) s2choose(); else drawscreen(); - showplayer(); lflush(); - } -#endif SIGTSTP + setupvt100(); + signal(SIGTSTP, tstop); + if (predostuff == 1) + s2choose(); + else + drawscreen(); + showplayer(); + lflush(); +} +#endif /* SIGTSTP */ /* * subroutine to issue the needed signal traps called from main() */ -static void sigpanic(); +void sigsetup() - { - signal(SIGQUIT, cntlc); signal(SIGINT, cntlc); - signal(SIGKILL, SIG_IGN); signal(SIGHUP, sgam); - signal(SIGILL, sigpanic); signal(SIGTRAP, sigpanic); - signal(SIGIOT, sigpanic); signal(SIGEMT, sigpanic); - signal(SIGFPE, sigpanic); signal(SIGBUS, sigpanic); - signal(SIGSEGV, sigpanic); signal(SIGSYS, sigpanic); - signal(SIGPIPE, sigpanic); signal(SIGTERM, sigpanic); +{ + signal(SIGQUIT, cntlc); + signal(SIGINT, cntlc); + signal(SIGKILL, SIG_IGN); + signal(SIGHUP, sgam); + signal(SIGILL, sigpanic); + signal(SIGTRAP, sigpanic); + signal(SIGIOT, sigpanic); + signal(SIGEMT, sigpanic); + signal(SIGFPE, sigpanic); + signal(SIGBUS, sigpanic); + signal(SIGSEGV, sigpanic); + signal(SIGSYS, sigpanic); + signal(SIGPIPE, sigpanic); + signal(SIGTERM, sigpanic); #ifdef SIGTSTP - signal(SIGTSTP,tstop); signal(SIGSTOP,tstop); -#endif SIGTSTP - } + signal(SIGTSTP, tstop); + signal(SIGSTOP, tstop); +#endif /* SIGTSTP */ +} /* * routine to process a fatal error signal */ static void sigpanic(sig) - int sig; - { - char buf[128]; - signal(sig,SIG_DFL); - sprintf(buf,"\nLarn - Panic! Signal %d received [SIG%s]",sig,sys_signame[sig]); - write(2,buf,strlen(buf)); sleep(2); + int sig; +{ + char buf[128]; + signal(sig, SIG_DFL); + sprintf(buf, "\nLarn - Panic! Signal %d received [SIG%s]", sig, sys_signame[sig]); + write(2, buf, strlen(buf)); + sleep(2); sncbr(); - savegame(savefilename); - kill(getpid(),sig); /* this will terminate us */ - } + savegame(savefilename); + kill(getpid(), sig); /* this will terminate us */ +} diff --git a/larn/store.c b/larn/store.c index 24226e09..01a3b483 100644 --- a/larn/store.c +++ b/larn/store.c @@ -1,4 +1,4 @@ -/* $NetBSD: store.c,v 1.5 1997/07/13 20:21:41 christos Exp $ */ +/* $NetBSD: store.c,v 1.6 1997/10/18 20:03:52 christos Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -33,155 +33,181 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 -static char sccsid[] = "@(#)store.c 5.4 (Berkeley) 5/13/91"; +static char sccsid[] = "@(#)store.c 5.4 (Berkeley) 5/13/91"; #else -static char rcsid[] = "$NetBSD: store.c,v 1.5 1997/07/13 20:21:41 christos Exp $"; +__RCSID("$NetBSD: store.c,v 1.6 1997/10/18 20:03:52 christos Exp $"); #endif -#endif /* not lint */ +#endif /* not lint */ -/* store.c Larn is copyrighted 1986 by Noah Morgan. */ +/* store.c Larn is copyrighted 1986 by Noah Morgan. */ #include "header.h" -static int dndcount=0,dnditm=0; - -/* this is the data for the stuff in the dnd store */ -int maxitm=83; /* number of items in the dnd inventory table */ -struct _itm itm[90] = { -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 2, OLEATHER, 0, 3 }, -{ 10, OSTUDLEATHER, 0, 2 }, -{ 40, ORING, 0, 2 }, -{ 85, OCHAIN, 0, 2 }, -{ 220, OSPLINT, 0, 1 }, -{ 400, OPLATE, 0, 1 }, -{ 900, OPLATEARMOR, 0, 1 }, -{ 2600, OSSPLATE, 0, 1 }, -{ 150, OSHIELD, 0, 1 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 2, ODAGGER, 0, 3 }, -{ 20, OSPEAR, 0, 3 }, -{ 80, OFLAIL, 0, 2 }, -{ 150, OBATTLEAXE, 0, 2 }, -{ 450, OLONGSWORD, 0, 2 }, -{ 1000, O2SWORD, 0, 2 }, -{ 5000, OSWORD, 0, 1 }, -{ 16500, OLANCE, 0, 1 }, -{ 6000, OSWORDofSLASHING, 0, 0 }, -{ 10000, OHAMMER, 0, 0 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 150, OPROTRING, 1, 1 }, -{ 85, OSTRRING, 1, 1 }, -{ 120, ODEXRING, 1, 1 }, -{ 120, OCLEVERRING, 1, 1 }, -{ 180, OENERGYRING, 0, 1 }, -{ 125, ODAMRING, 0, 1 }, -{ 220, OREGENRING, 0, 1 }, -{ 1000, ORINGOFEXTRA, 0, 1 }, - -{ 280, OBELT, 0, 1 }, - -{ 400, OAMULET, 0, 1 }, - -{ 6500, OORBOFDRAGON, 0, 0 }, -{ 5500, OSPIRITSCARAB, 0, 0 }, -{ 5000, OCUBEofUNDEAD, 0, 0 }, -{ 6000, ONOTHEFT, 0, 0 }, - -{ 590, OCHEST, 6, 1 }, -{ 200, OBOOK, 8, 1 }, -{ 10, OCOOKIE, 0, 3 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 20, OPOTION, 0, 6 }, -{ 90, OPOTION, 1, 5 }, -{ 520, OPOTION, 2, 1 }, -{ 100, OPOTION, 3, 2 }, -{ 50, OPOTION, 4, 2 }, -{ 150, OPOTION, 5, 2 }, -{ 70, OPOTION, 6, 1 }, -{ 30, OPOTION, 7, 7 }, -{ 200, OPOTION, 8, 1 }, -{ 50, OPOTION, 9, 1 }, -{ 80, OPOTION, 10, 1 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 30, OPOTION, 11, 3 }, -{ 20, OPOTION, 12, 5 }, -{ 40, OPOTION, 13, 3 }, -{ 35, OPOTION, 14, 2 }, -{ 520, OPOTION, 15, 1 }, -{ 90, OPOTION, 16, 2 }, -{ 200, OPOTION, 17, 2 }, -{ 220, OPOTION, 18, 4 }, -{ 80, OPOTION, 19, 6 }, -{ 370, OPOTION, 20, 3 }, -{ 50, OPOTION, 22, 1 }, -{ 150, OPOTION, 23, 3 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 100, OSCROLL, 0, 2 }, -{ 125, OSCROLL, 1, 2 }, -{ 60, OSCROLL, 2, 4 }, -{ 10, OSCROLL, 3, 4 }, -{ 100, OSCROLL, 4, 3 }, -{ 200, OSCROLL, 5, 2 }, -{ 110, OSCROLL, 6, 1 }, -{ 500, OSCROLL, 7, 2 }, -{ 200, OSCROLL, 8, 2 }, -{ 250, OSCROLL, 9, 4 }, -{ 20, OSCROLL, 10, 5 }, -{ 30, OSCROLL, 11, 3 }, - -/*cost iven name iven arg how - gp iven[] ivenarg[] many */ - -{ 340, OSCROLL, 12, 1 }, -{ 340, OSCROLL, 13, 1 }, -{ 300, OSCROLL, 14, 2 }, -{ 400, OSCROLL, 15, 2 }, -{ 500, OSCROLL, 16, 2 }, -{ 1000, OSCROLL, 17, 1 }, -{ 500, OSCROLL, 18, 1 }, -{ 340, OSCROLL, 19, 2 }, -{ 220, OSCROLL, 20, 3 }, -{ 3900, OSCROLL, 21, 0 }, -{ 610, OSCROLL, 22, 1 }, -{ 3000, OSCROLL, 23, 0 } - }; +#include "extern.h" + +static void handsfull __P((void)); +static void outofstock __P((void)); +static void nogold __P((void)); +static void dnditem __P((int)); +static void banktitle __P((char *)); +static void otradhead __P((void)); + +static int dndcount = 0, dnditm = 0; + +/* this is the data for the stuff in the dnd store */ +int maxitm = 83; /* number of items in the dnd inventory table */ +struct _itm itm[90] = { + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {2, OLEATHER, 0, 3}, + {10, OSTUDLEATHER, 0, 2}, + {40, ORING, 0, 2}, + {85, OCHAIN, 0, 2}, + {220, OSPLINT, 0, 1}, + {400, OPLATE, 0, 1}, + {900, OPLATEARMOR, 0, 1}, + {2600, OSSPLATE, 0, 1}, + {150, OSHIELD, 0, 1}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {2, ODAGGER, 0, 3}, + {20, OSPEAR, 0, 3}, + {80, OFLAIL, 0, 2}, + {150, OBATTLEAXE, 0, 2}, + {450, OLONGSWORD, 0, 2}, + {1000, O2SWORD, 0, 2}, + {5000, OSWORD, 0, 1}, + {16500, OLANCE, 0, 1}, + {6000, OSWORDofSLASHING, 0, 0}, + {10000, OHAMMER, 0, 0}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {150, OPROTRING, 1, 1}, + {85, OSTRRING, 1, 1}, + {120, ODEXRING, 1, 1}, + {120, OCLEVERRING, 1, 1}, + {180, OENERGYRING, 0, 1}, + {125, ODAMRING, 0, 1}, + {220, OREGENRING, 0, 1}, + {1000, ORINGOFEXTRA, 0, 1}, + + {280, OBELT, 0, 1}, + + {400, OAMULET, 0, 1}, + + {6500, OORBOFDRAGON, 0, 0}, + {5500, OSPIRITSCARAB, 0, 0}, + {5000, OCUBEofUNDEAD, 0, 0}, + {6000, ONOTHEFT, 0, 0}, + + {590, OCHEST, 6, 1}, + {200, OBOOK, 8, 1}, + {10, OCOOKIE, 0, 3}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {20, OPOTION, 0, 6}, + {90, OPOTION, 1, 5}, + {520, OPOTION, 2, 1}, + {100, OPOTION, 3, 2}, + {50, OPOTION, 4, 2}, + {150, OPOTION, 5, 2}, + {70, OPOTION, 6, 1}, + {30, OPOTION, 7, 7}, + {200, OPOTION, 8, 1}, + {50, OPOTION, 9, 1}, + {80, OPOTION, 10, 1}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {30, OPOTION, 11, 3}, + {20, OPOTION, 12, 5}, + {40, OPOTION, 13, 3}, + {35, OPOTION, 14, 2}, + {520, OPOTION, 15, 1}, + {90, OPOTION, 16, 2}, + {200, OPOTION, 17, 2}, + {220, OPOTION, 18, 4}, + {80, OPOTION, 19, 6}, + {370, OPOTION, 20, 3}, + {50, OPOTION, 22, 1}, + {150, OPOTION, 23, 3}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {100, OSCROLL, 0, 2}, + {125, OSCROLL, 1, 2}, + {60, OSCROLL, 2, 4}, + {10, OSCROLL, 3, 4}, + {100, OSCROLL, 4, 3}, + {200, OSCROLL, 5, 2}, + {110, OSCROLL, 6, 1}, + {500, OSCROLL, 7, 2}, + {200, OSCROLL, 8, 2}, + {250, OSCROLL, 9, 4}, + {20, OSCROLL, 10, 5}, + {30, OSCROLL, 11, 3}, + + /* + * cost iven name iven arg how gp + * iven[] ivenarg[] many + */ + + {340, OSCROLL, 12, 1}, + {340, OSCROLL, 13, 1}, + {300, OSCROLL, 14, 2}, + {400, OSCROLL, 15, 2}, + {500, OSCROLL, 16, 2}, + {1000, OSCROLL, 17, 1}, + {500, OSCROLL, 18, 1}, + {340, OSCROLL, 19, 2}, + {220, OSCROLL, 20, 3}, + {3900, OSCROLL, 21, 0}, + {610, OSCROLL, 22, 1}, + {3000, OSCROLL, 23, 0} +}; /* function for the dnd store */ +void dnd_2hed() - { +{ lprcat("Welcome to the Larn Thrift Shoppe. We stock many items explorers find useful\n"); lprcat(" in their adventures. Feel free to browse to your hearts content.\n"); lprcat("Also be advised, if you break 'em, you pay for 'em."); - } - -static void dnditem(); +} +void dnd_hed() - { - register int i; - for (i=dnditm; i<26+dnditm; i++) dnditem(i); - cursor(50,18); lprcat("You have "); - } +{ + int i; + for (i = dnditm; i < 26 + dnditm; i++) + dnditem(i); + cursor(50, 18); + lprcat("You have "); +} static void handsfull() @@ -199,70 +225,94 @@ outofstock() nap(2200); } -static void nogold() +static void +nogold() { lprcat("\nYou don't have enough gold to pay for that!"); lflush(); nap(2200); } +void dndstore() - { - register int i; - dnditm = 0; - nosignal = 1; /* disable signals */ - clear(); dnd_2hed(); - if (outstanding_taxes>0) - { - lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); beep(); - lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n",(long)outstanding_taxes); - lprcat("comply with the law, we cannot serve you at this time. Soo Sorry.\n"); - cursors(); - lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush(); - i=0; - while (i!='\33') i=getchar(); - drawscreen(); nosignal = 0; /* enable signals */ return; +{ + int i; + dnditm = 0; + nosignal = 1; /* disable signals */ + clear(); + dnd_2hed(); + if (outstanding_taxes > 0) { + lprcat("\n\nThe Larn Revenue Service has ordered us to not do business with tax evaders.\n"); + beep(); + lprintf("They have also told us that you owe %d gp in back taxes, and as we must\n", (long) outstanding_taxes); + lprcat("comply with the law, we cannot serve you at this time. Soo Sorry.\n"); + cursors(); + lprcat("\nPress "); + standout("escape"); + lprcat(" to leave: "); + lflush(); + i = 0; + while (i != '\33') + i = getchar(); + drawscreen(); + nosignal = 0; /* enable signals */ + return; } - - dnd_hed(); - while (1) - { - cursor(59,18); lprintf("%d gold pieces",(long)c[GOLD]); - cltoeoln(); cl_dn(1,20); /* erase to eod */ - lprcat("\nEnter your transaction ["); standout("space"); - lprcat(" for more, "); standout("escape"); - lprcat(" to leave]? "); - i=0; - while ((i<'a' || i>'z') && (i!=' ') && (i!='\33') && (i!=12)) i=getchar(); - if (i==12) { clear(); dnd_2hed(); dnd_hed(); } - else if (i=='\33') - { drawscreen(); nosignal = 0; /* enable signals */ return; } - else if (i==' ') - { - cl_dn(1,4); - if ((dnditm += 26) >= maxitm) dnditm=0; dnd_hed(); - } - else - { /* buy something */ - lprc(i); /* echo the byte */ - i += dnditm - 'a'; - if (i>=maxitm) outofstock(); else - if (itm[i].qty <= 0) outofstock(); else - if (pocketfull()) handsfull(); else - if (c[GOLD] < itm[i].price*10) nogold(); else - { - if (itm[i].obj == OPOTION) - { potionname[itm[i].arg] = potionhide[itm[i].arg]; } - else if (itm[i].obj == OSCROLL) - { scrollname[itm[i].arg] = scrollhide[itm[i].arg]; } - c[GOLD] -= itm[i].price*10; - itm[i].qty--; take(itm[i].obj,itm[i].arg); - if (itm[i].qty==0) dnditem(i); nap(1001); + dnd_hed(); + while (1) { + cursor(59, 18); + lprintf("%d gold pieces", (long) c[GOLD]); + cltoeoln(); + cl_dn(1, 20); /* erase to eod */ + lprcat("\nEnter your transaction ["); + standout("space"); + lprcat(" for more, "); + standout("escape"); + lprcat(" to leave]? "); + i = 0; + while ((i < 'a' || i > 'z') && (i != ' ') && (i != '\33') && (i != 12)) + i = getchar(); + if (i == 12) { + clear(); + dnd_2hed(); + dnd_hed(); + } else if (i == '\33') { + drawscreen(); + nosignal = 0; /* enable signals */ + return; + } else if (i == ' ') { + cl_dn(1, 4); + if ((dnditm += 26) >= maxitm) + dnditm = 0; + dnd_hed(); + } else { /* buy something */ + lprc(i);/* echo the byte */ + i += dnditm - 'a'; + if (i >= maxitm) + outofstock(); + else if (itm[i].qty <= 0) + outofstock(); + else if (pocketfull()) + handsfull(); + else if (c[GOLD] < itm[i].price * 10) + nogold(); + else { + if (itm[i].obj == OPOTION) { + potionname[itm[i].arg] = potionhide[itm[i].arg]; + } else if (itm[i].obj == OSCROLL) { + scrollname[itm[i].arg] = scrollhide[itm[i].arg]; + } + c[GOLD] -= itm[i].price * 10; + itm[i].qty--; + take(itm[i].obj, itm[i].arg); + if (itm[i].qty == 0) + dnditem(i); + nap(1001); } } } - } +} /* dnditem(index) @@ -271,430 +321,588 @@ dndstore() */ static void dnditem(i) - register int i; - { - register int j,k; - if (i >= maxitm) return; - cursor( (j=(i&1)*40+1) , (k=((i%26)>>1)+5) ); - if (itm[i].qty == 0) { lprintf("%39s",""); return; } - lprintf("%c) ",(i%26)+'a'); - if (itm[i].obj == OPOTION) - { lprintf("potion of%s", potionhide[itm[i].arg]); } - else if (itm[i].obj == OSCROLL) - { lprintf("scroll of%s", scrollhide[itm[i].arg]); } - else lprintf("%s",objectname[itm[i].obj]); - cursor( j+31,k ); lprintf("%6d",(long)(itm[i].price*10)); + int i; +{ + int j, k; + if (i >= maxitm) + return; + cursor((j = (i & 1) * 40 + 1), (k = ((i % 26) >> 1) + 5)); + if (itm[i].qty == 0) { + lprintf("%39s", ""); + return; } + lprintf("%c) ", (i % 26) + 'a'); + if (itm[i].obj == OPOTION) { + lprintf("potion of%s", potionhide[itm[i].arg]); + } else if (itm[i].obj == OSCROLL) { + lprintf("scroll of%s", scrollhide[itm[i].arg]); + } else + lprintf("%s", objectname[itm[i].obj]); + cursor(j + 31, k); + lprintf("%6d", (long) (itm[i].price * 10)); +} + + - /* for the college of larn */ -char course[26]={0}; /* the list of courses taken */ -char coursetime[] = { 10, 15, 10, 20, 10, 10, 10, 5 }; +u_char course[26] = {0}; /* the list of courses taken */ +char coursetime[] = {10, 15, 10, 20, 10, 10, 10, 5}; /* function to display the header info for the school */ +void sch_hed() - { +{ clear(); lprcat("The College of Larn offers the exciting opportunity of higher education to\n"); lprcat("all inhabitants of the caves. Here is a list of the class schedule:\n\n\n"); lprcat("\t\t Course Name \t Time Needed\n\n"); - if (course[0]==0) lprcat("\t\ta) Fighters Training I 10 mobuls"); /*line 7 of crt*/ + if (course[0] == 0) + lprcat("\t\ta) Fighters Training I 10 mobuls"); /* line 7 of crt */ lprc('\n'); - if (course[1]==0) lprcat("\t\tb) Fighters Training II 15 mobuls"); + if (course[1] == 0) + lprcat("\t\tb) Fighters Training II 15 mobuls"); lprc('\n'); - if (course[2]==0) lprcat("\t\tc) Introduction to Wizardry 10 mobuls"); + if (course[2] == 0) + lprcat("\t\tc) Introduction to Wizardry 10 mobuls"); lprc('\n'); - if (course[3]==0) lprcat("\t\td) Applied Wizardry 20 mobuls"); + if (course[3] == 0) + lprcat("\t\td) Applied Wizardry 20 mobuls"); lprc('\n'); - if (course[4]==0) lprcat("\t\te) Behavioral Psychology 10 mobuls"); + if (course[4] == 0) + lprcat("\t\te) Behavioral Psychology 10 mobuls"); lprc('\n'); - if (course[5]==0) lprcat("\t\tf) Faith for Today 10 mobuls"); + if (course[5] == 0) + lprcat("\t\tf) Faith for Today 10 mobuls"); lprc('\n'); - if (course[6]==0) lprcat("\t\tg) Contemporary Dance 10 mobuls"); + if (course[6] == 0) + lprcat("\t\tg) Contemporary Dance 10 mobuls"); lprc('\n'); - if (course[7]==0) lprcat("\t\th) History of Larn 5 mobuls"); + if (course[7] == 0) + lprcat("\t\th) History of Larn 5 mobuls"); lprcat("\n\n\t\tAll courses cost 250 gold pieces."); - cursor(30,18); + cursor(30, 18); lprcat("You are presently carrying "); - } +} +void oschool() - { - register int i; - long time_used; - nosignal = 1; /* disable signals */ +{ + int i; + long time_used; + nosignal = 1; /* disable signals */ sch_hed(); - while (1) - { - cursor(57,18); lprintf("%d gold pieces. ",(long)c[GOLD]); cursors(); - lprcat("\nWhat is your choice ["); standout("escape"); - lprcat(" to leave] ? "); yrepcount=0; - i=0; while ((i<'a' || i>'h') && (i!='\33') && (i!=12)) i=getchar(); - if (i==12) { sch_hed(); continue; } - else if (i=='\33') - { nosignal = 0; drawscreen(); /* enable signals */ return; } + while (1) { + cursor(57, 18); + lprintf("%d gold pieces. ", (long) c[GOLD]); + cursors(); + lprcat("\nWhat is your choice ["); + standout("escape"); + lprcat(" to leave] ? "); + yrepcount = 0; + i = 0; + while ((i < 'a' || i > 'h') && (i != '\33') && (i != 12)) + i = getchar(); + if (i == 12) { + sch_hed(); + continue; + } else if (i == '\33') { + nosignal = 0; + drawscreen(); /* enable signals */ + return; + } lprc(i); - if (c[GOLD] < 250) nogold(); else - if (course[i-'a']) - { lprcat("\nSorry, but that class is filled."); nap(1000); } - else - if (i <= 'h') - { - c[GOLD] -= 250; time_used=0; - switch(i) - { - case 'a': c[STRENGTH] += 2; c[CONSTITUTION]++; - lprcat("\nYou feel stronger!"); - cl_line(16,7); - break; - - case 'b': if (course[0]==0) - { - lprcat("\nSorry, but this class has a prerequisite of Fighters Training I"); - c[GOLD]+=250; time_used= -10000; break; - } - lprcat("\nYou feel much stronger!"); - cl_line(16,8); - c[STRENGTH] += 2; c[CONSTITUTION] += 2; break; - - case 'c': c[INTELLIGENCE] += 2; - lprcat("\nThe task before you now seems more attainable!"); - cl_line(16,9); break; - - case 'd': if (course[2]==0) - { - lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry"); - c[GOLD]+=250; time_used= -10000; break; - } - lprcat("\nThe task before you now seems very attainable!"); - cl_line(16,10); - c[INTELLIGENCE] += 2; break; - - case 'e': c[CHARISMA] += 3; - lprcat("\nYou now feel like a born leader!"); - cl_line(16,11); break; - - case 'f': c[WISDOM] += 2; - lprcat("\nYou now feel more confident that you can find the potion in time!"); - cl_line(16,12); break; - - case 'g': c[DEXTERITY] += 3; - lprcat("\nYou feel like dancing!"); - cl_line(16,13); break; - - case 'h': c[INTELLIGENCE]++; - lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n"); - lprcat("by a platinum dragon who possesses psionic abilities. "); - cl_line(16,14); break; - } - time_used += coursetime[i-'a']*100; - if (time_used > 0) - { - gltime += time_used; - course[i-'a']++; /* remember that he has taken that course */ - c[HP] = c[HPMAX]; c[SPELLS] = c[SPELLMAX]; /* he regenerated */ - - if (c[BLINDCOUNT]) c[BLINDCOUNT]=1; /* cure blindness too! */ - if (c[CONFUSE]) c[CONFUSE]=1; /* end confusion */ - adjtime((long)time_used); /* adjust parameters for time change */ - } + if (c[GOLD] < 250) + nogold(); + else if (course[i - 'a']) { + lprcat("\nSorry, but that class is filled."); nap(1000); + } else if (i <= 'h') { + c[GOLD] -= 250; + time_used = 0; + switch (i) { + case 'a': + c[STRENGTH] += 2; + c[CONSTITUTION]++; + lprcat("\nYou feel stronger!"); + cl_line(16, 7); + break; + + case 'b': + if (course[0] == 0) { + lprcat("\nSorry, but this class has a prerequisite of Fighters Training I"); + c[GOLD] += 250; + time_used = -10000; + break; + } + lprcat("\nYou feel much stronger!"); + cl_line(16, 8); + c[STRENGTH] += 2; + c[CONSTITUTION] += 2; + break; + + case 'c': + c[INTELLIGENCE] += 2; + lprcat("\nThe task before you now seems more attainable!"); + cl_line(16, 9); + break; + + case 'd': + if (course[2] == 0) { + lprcat("\nSorry, but this class has a prerequisite of Introduction to Wizardry"); + c[GOLD] += 250; + time_used = -10000; + break; + } + lprcat("\nThe task before you now seems very attainable!"); + cl_line(16, 10); + c[INTELLIGENCE] += 2; + break; + + case 'e': + c[CHARISMA] += 3; + lprcat("\nYou now feel like a born leader!"); + cl_line(16, 11); + break; + + case 'f': + c[WISDOM] += 2; + lprcat("\nYou now feel more confident that you can find the potion in time!"); + cl_line(16, 12); + break; + + case 'g': + c[DEXTERITY] += 3; + lprcat("\nYou feel like dancing!"); + cl_line(16, 13); + break; + + case 'h': + c[INTELLIGENCE]++; + lprcat("\nYour instructor told you that the Eye of Larn is rumored to be guarded\n"); + lprcat("by a platinum dragon who possesses psionic abilities. "); + cl_line(16, 14); + break; + } + time_used += coursetime[i - 'a'] * 100; + if (time_used > 0) { + gltime += time_used; + course[i - 'a']++; /* remember that he has + * taken that course */ + c[HP] = c[HPMAX]; + c[SPELLS] = c[SPELLMAX]; /* he regenerated */ + + if (c[BLINDCOUNT]) + c[BLINDCOUNT] = 1; /* cure blindness too! */ + if (c[CONFUSE]) + c[CONFUSE] = 1; /* end confusion */ + adjusttime((long) time_used); /* adjust parameters for + * time change */ } + nap(1000); } } - +} + + /* * for the first national bank of Larn */ -int lasttime=0; /* last time he was in bank */ -static void banktitle(); +int lasttime = 0; /* last time he was in bank */ +void obank() - { +{ banktitle(" Welcome to the First National Bank of Larn."); - } +} +void obank2() - { +{ banktitle("Welcome to the 5th level branch office of the First National Bank of Larn."); - } +} static void banktitle(str) - char *str; - { - nosignal = 1; /* disable signals */ - clear(); lprcat(str); - if (outstanding_taxes>0) - { - register int i; - lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n"); beep(); - lprintf("levied taxes have been paid. They have also told us that you owe %d gp in\n",(long)outstanding_taxes); + char *str; +{ + nosignal = 1; /* disable signals */ + clear(); + lprcat(str); + if (outstanding_taxes > 0) { + int i; + lprcat("\n\nThe Larn Revenue Service has ordered that your account be frozen until all\n"); + beep(); + lprintf("levied taxes have been paid. They have also told us that you owe %d gp in\n", (long) outstanding_taxes); lprcat("taxes, and we must comply with them. We cannot serve you at this time. Sorry.\n"); lprcat("We suggest you go to the LRS office and pay your taxes.\n"); - cursors(); - lprcat("\nPress "); standout("escape"); lprcat(" to leave: "); lflush(); - i=0; - while (i!='\33') i=getchar(); - drawscreen(); nosignal = 0; /* enable signals */ return; - } + cursors(); + lprcat("\nPress "); + standout("escape"); + lprcat(" to leave: "); + lflush(); + i = 0; + while (i != '\33') + i = getchar(); + drawscreen(); + nosignal = 0; /* enable signals */ + return; + } lprcat("\n\n\tGemstone\t Appraisal\t\tGemstone\t Appraisal"); - obanksub(); nosignal = 0; /* enable signals */ + obanksub(); + nosignal = 0; /* enable signals */ drawscreen(); - } +} /* * function to put interest on your bank account */ +void ointerest() - { - register int i; - if (c[BANKACCOUNT]<0) c[BANKACCOUNT] = 0; - else if ((c[BANKACCOUNT]>0) && (c[BANKACCOUNT]<500000)) - { - i = (gltime-lasttime)/100; /* # mobuls elapsed */ - while ((i-- > 0) && (c[BANKACCOUNT]<500000)) - c[BANKACCOUNT] += c[BANKACCOUNT]/250; - if (c[BANKACCOUNT]>500000) c[BANKACCOUNT]=500000; /* interest limit */ - } - lasttime = (gltime/100)*100; +{ + int i; + if (c[BANKACCOUNT] < 0) + c[BANKACCOUNT] = 0; + else if ((c[BANKACCOUNT] > 0) && (c[BANKACCOUNT] < 500000)) { + i = (gltime - lasttime) / 100; /* # mobuls elapsed */ + while ((i-- > 0) && (c[BANKACCOUNT] < 500000)) + c[BANKACCOUNT] += c[BANKACCOUNT] / 250; + if (c[BANKACCOUNT] > 500000) + c[BANKACCOUNT] = 500000; /* interest limit */ } + lasttime = (gltime / 100) * 100; +} -static short gemorder[26]={0}; /* the reference to screen location for each */ -static long gemvalue[26]={0}; /* the appraisal of the gems */ +static short gemorder[26] = {0}; /* the reference to screen location + * for each */ +static long gemvalue[26] = {0}; /* the appraisal of the gems */ +void obanksub() - { - unsigned long amt; - register int i,k; - ointerest(); /* credit any needed interest */ - - for (k=i=0; i<26; i++) - switch(iven[i]) - { - case OLARNEYE: case ODIAMOND: case OEMERALD: - case ORUBY: case OSAPPHIRE: - - if (iven[i]==OLARNEYE) - { - gemvalue[i]=250000-((gltime*7)/100)*100; - if (gemvalue[i]<50000) gemvalue[i]=50000; - } - else gemvalue[i] = (255&ivenarg[i])*100; - gemorder[i]=k; - cursor( (k%2)*40+1 , (k>>1)+4 ); - lprintf("%c) %s",i+'a',objectname[iven[i]]); - cursor( (k%2)*40+33 , (k>>1)+4 ); - lprintf("%5d",(long)gemvalue[i]); k++; - }; - cursor(31,17); lprintf("You have %8d gold pieces in the bank.",(long)c[BANKACCOUNT]); - cursor(40,18); lprintf("You have %8d gold pieces",(long)c[GOLD]); - if (c[BANKACCOUNT]+c[GOLD] >= 500000) +{ + unsigned long amt; + int i, k; + ointerest(); /* credit any needed interest */ + + for (k = i = 0; i < 26; i++) + switch (iven[i]) { + case OLARNEYE: + case ODIAMOND: + case OEMERALD: + case ORUBY: + case OSAPPHIRE: + + if (iven[i] == OLARNEYE) { + gemvalue[i] = 250000 - ((gltime * 7) / 100) * 100; + if (gemvalue[i] < 50000) + gemvalue[i] = 50000; + } else + gemvalue[i] = (255 & ivenarg[i]) * 100; + gemorder[i] = k; + cursor((k % 2) * 40 + 1, (k >> 1) + 4); + lprintf("%c) %s", i + 'a', objectname[iven[i]]); + cursor((k % 2) * 40 + 33, (k >> 1) + 4); + lprintf("%5d", (long) gemvalue[i]); + k++; + }; + cursor(31, 17); + lprintf("You have %8d gold pieces in the bank.", (long) c[BANKACCOUNT]); + cursor(40, 18); + lprintf("You have %8d gold pieces", (long) c[GOLD]); + if (c[BANKACCOUNT] + c[GOLD] >= 500000) lprcat("\nNote: Larndom law states that only deposits under 500,000gp can earn interest."); - while (1) - { - cl_dn(1,20); - lprcat("\nYour wish? [("); standout("d"); lprcat(") deposit, ("); - standout("w"); lprcat(") withdraw, ("); standout("s"); - lprcat(") sell a stone, or "); standout("escape"); lprcat("] "); - yrepcount=0; - i=0; while (i!='d' && i!='w' && i!='s' && i!='\33') i=getchar(); - switch(i) - { - case 'd': lprcat("deposit\nHow much? "); amt = readnum((long)c[GOLD]); - if (amt<0) { lprcat("\nSorry, but we can't take negative gold!"); nap(2000); amt=0; } else - if (amt>c[GOLD]) - { lprcat(" You don't have that much."); nap(2000); } - else { c[GOLD] -= amt; c[BANKACCOUNT] += amt; } - break; - - case 'w': lprcat("withdraw\nHow much? "); amt = readnum((long)c[BANKACCOUNT]); - if (amt<0) { lprcat("\nSorry, but we don't have any negative gold!"); nap(2000); amt=0; } - else if (amt > c[BANKACCOUNT]) - { lprcat("\nYou don't have that much in the bank!"); nap(2000); } - else { c[GOLD] += amt; c[BANKACCOUNT] -= amt; } - break; - - case 's': lprcat("\nWhich stone would you like to sell? "); - i=0; while ((i<'a' || i>'z') && i!='*') i=getchar(); - if (i=='*') - for (i=0; i<26; i++) - { - if (gemvalue[i]) - { - c[GOLD]+=gemvalue[i]; iven[i]=0; - gemvalue[i]=0; k = gemorder[i]; - cursor( (k%2)*40+1 , (k>>1)+4 ); - lprintf("%39s",""); - } - } - else - { - if (gemvalue[i=i-'a']==0) - { - lprintf("\nItem %c is not a gemstone!",i+'a'); - nap(2000); break; - } - c[GOLD]+=gemvalue[i]; iven[i]=0; - gemvalue[i]=0; k = gemorder[i]; - cursor( (k%2)*40+1 , (k>>1)+4 ); lprintf("%39s",""); - } - break; - - case '\33': return; - }; - cursor(40,17); lprintf("%8d",(long)c[BANKACCOUNT]); - cursor(49,18); lprintf("%8d",(long)c[GOLD]); - } + while (1) { + cl_dn(1, 20); + lprcat("\nYour wish? [("); + standout("d"); + lprcat(") deposit, ("); + standout("w"); + lprcat(") withdraw, ("); + standout("s"); + lprcat(") sell a stone, or "); + standout("escape"); + lprcat("] "); + yrepcount = 0; + i = 0; + while (i != 'd' && i != 'w' && i != 's' && i != '\33') + i = getchar(); + switch (i) { + case 'd': + lprcat("deposit\nHow much? "); + amt = readnum((long) c[GOLD]); + if (amt < 0) { + lprcat("\nSorry, but we can't take negative gold!"); + nap(2000); + amt = 0; + } else if (amt > c[GOLD]) { + lprcat(" You don't have that much."); + nap(2000); + } else { + c[GOLD] -= amt; + c[BANKACCOUNT] += amt; + } + break; + + case 'w': + lprcat("withdraw\nHow much? "); + amt = readnum((long) c[BANKACCOUNT]); + if (amt < 0) { + lprcat("\nSorry, but we don't have any negative gold!"); + nap(2000); + amt = 0; + } else if (amt > c[BANKACCOUNT]) { + lprcat("\nYou don't have that much in the bank!"); + nap(2000); + } else { + c[GOLD] += amt; + c[BANKACCOUNT] -= amt; + } + break; + + case 's': + lprcat("\nWhich stone would you like to sell? "); + i = 0; + while ((i < 'a' || i > 'z') && i != '*') + i = getchar(); + if (i == '*') + for (i = 0; i < 26; i++) { + if (gemvalue[i]) { + c[GOLD] += gemvalue[i]; + iven[i] = 0; + gemvalue[i] = 0; + k = gemorder[i]; + cursor((k % 2) * 40 + 1, (k >> 1) + 4); + lprintf("%39s", ""); + } + } + else { + if (gemvalue[i = i - 'a'] == 0) { + lprintf("\nItem %c is not a gemstone!", i + 'a'); + nap(2000); + break; + } + c[GOLD] += gemvalue[i]; + iven[i] = 0; + gemvalue[i] = 0; + k = gemorder[i]; + cursor((k % 2) * 40 + 1, (k >> 1) + 4); + lprintf("%39s", ""); + } + break; + + case '\33': + return; + }; + cursor(40, 17); + lprintf("%8d", (long) c[BANKACCOUNT]); + cursor(49, 18); + lprintf("%8d", (long) c[GOLD]); } +} /* subroutine to appraise any stone for the bank */ +void appraise(gemstone) - register int gemstone; - { - register int j,amt; - for (j=0; j<26; j++) - if (iven[j]==gemstone) - { - lprintf("\nI see you have %s",objectname[gemstone]); - if (gemstone==OLARNEYE) lprcat(" I must commend you. I didn't think\nyou could get it."); - lprcat(" Shall I appraise it for you? "); yrepcount=0; - if (getyn()=='y') - { - lprcat("yes.\n Just one moment please \n"); nap(1000); - if (gemstone==OLARNEYE) - { - amt = 250000-((gltime*7)/100)*100; - if (amt<50000) amt=50000; - } - else amt = (255 & ivenarg[j]) * 100; - lprintf("\nI can see this is an excellent stone, It is worth %d",(long)amt); - lprcat("\nWould you like to sell it to us? "); yrepcount=0; - if (getyn()=='y') { lprcat("yes\n"); c[GOLD]+=amt; iven[j]=0; } - else lprcat("no thank you.\n"); - if (gemstone==OLARNEYE) lprcat("It is, of course, your privilege to keep the stone\n"); - } - else lprcat("no\nO. K.\n"); + int gemstone; +{ + int j, amt; + for (j = 0; j < 26; j++) + if (iven[j] == gemstone) { + lprintf("\nI see you have %s", objectname[gemstone]); + if (gemstone == OLARNEYE) + lprcat(" I must commend you. I didn't think\nyou could get it."); + lprcat(" Shall I appraise it for you? "); + yrepcount = 0; + if (getyn() == 'y') { + lprcat("yes.\n Just one moment please \n"); + nap(1000); + if (gemstone == OLARNEYE) { + amt = 250000 - ((gltime * 7) / 100) * 100; + if (amt < 50000) + amt = 50000; + } else + amt = (255 & ivenarg[j]) * 100; + lprintf("\nI can see this is an excellent stone, It is worth %d", (long) amt); + lprcat("\nWould you like to sell it to us? "); + yrepcount = 0; + if (getyn() == 'y') { + lprcat("yes\n"); + c[GOLD] += amt; + iven[j] = 0; + } else + lprcat("no thank you.\n"); + if (gemstone == OLARNEYE) + lprcat("It is, of course, your privilege to keep the stone\n"); + } else + lprcat("no\nO. K.\n"); } - } +} /* function for the trading post */ -static otradhead() - { - clear(); +static void +otradhead() +{ + clear(); lprcat("Welcome to the Larn Trading Post. We buy items that explorers no longer find\n"); - lprcat("useful. Since the condition of the items you bring in is not certain,\n"); - lprcat("and we incur great expense in reconditioning the items, we usually pay\n"); - lprcat("only 20% of their value were they to be new. If the items are badly\n"); + lprcat("useful. Since the condition of the items you bring in is not certain,\n"); + lprcat("and we incur great expense in reconditioning the items, we usually pay\n"); + lprcat("only 20% of their value were they to be new. If the items are badly\n"); lprcat("damaged, we will pay only 10% of their new value.\n\n"); - } +} +void otradepost() - { - register int i,j,value,isub,izarg; - dnditm = dndcount = 0; - nosignal = 1; /* disable signals */ - resetscroll(); otradhead(); - while (1) - { - lprcat("\nWhat item do you want to sell to us ["); standout("*"); - lprcat(" for list, or "); standout("escape"); lprcat("] ? "); - i=0; while (i>'z' || (i<'a' && i!='*' && i!='\33' && i!='.')) i=getchar(); - if (i == '\33') - { setscroll(); recalc(); drawscreen(); nosignal=0; /* enable signals */ return; } - isub = i - 'a'; j=0; - if (iven[isub]==OSCROLL) if (scrollname[ivenarg[isub]][0]==0) - { j=1; cnsitm(); } /* can't sell unidentified item */ - if (iven[isub]==OPOTION) if (potionname[ivenarg[isub]][0]==0) - { j=1; cnsitm(); } /* can't sell unidentified item */ - if (!j) - if (i=='*') { clear(); qshowstr(); otradhead(); } - else if (iven[isub]==0) lprintf("\nYou don't have item %c!",isub+'a'); - else - { - for (j=0; j<maxitm; j++) - if ((itm[j].obj == iven[isub]) || (iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE)) - { - srcount=0; show3(isub); /* show what the item was */ - if ((iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) - || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE)) - value = 20*ivenarg[isub]; - else - if ((itm[j].obj == OSCROLL) || (itm[j].obj == OPOTION)) value = 2*itm[j+ivenarg[isub]].price; - else - { - izarg=ivenarg[isub]; value = itm[j].price; /* appreciate if a +n object */ - if (izarg >= 0) value *= 2; - while ((izarg-- > 0) && ((value=14*(67+value)/10) < 500000)); - } - lprintf("\nItem (%c) is worth %d gold pieces to us. Do you want to sell it? ",i,(long)value); - yrepcount=0; - if (getyn()=='y') - { - lprcat("yes\n"); c[GOLD]+=value; - if (c[WEAR] == isub) c[WEAR] = -1; - if (c[WIELD] == isub) c[WIELD] = -1; - if (c[SHIELD] == isub) c[SHIELD] = -1; - adjustcvalues(iven[isub],ivenarg[isub]); - iven[isub]=0; - } - else lprcat("no thanks.\n"); - j = maxitm+100; /* get out of the inner loop */ - } - if (j <= maxitm+2) lprcat("\nSo sorry, but we are not authorized to accept that item."); +{ + int i, j, value, isub, izarg; + dnditm = dndcount = 0; + nosignal = 1; /* disable signals */ + resetscroll(); + otradhead(); + while (1) { + lprcat("\nWhat item do you want to sell to us ["); + standout("*"); + lprcat(" for list, or "); + standout("escape"); + lprcat("] ? "); + i = 0; + while (i > 'z' || (i < 'a' && i != '*' && i != '\33' && i != '.')) + i = getchar(); + if (i == '\33') { + setscroll(); + recalc(); + drawscreen(); + nosignal = 0; /* enable signals */ + return; } + isub = i - 'a'; + j = 0; + if (iven[isub] == OSCROLL) + if (scrollname[ivenarg[isub]][0] == 0) { + j = 1; + cnsitm(); + } /* can't sell unidentified item */ + if (iven[isub] == OPOTION) + if (potionname[ivenarg[isub]][0] == 0) { + j = 1; + cnsitm(); + } /* can't sell unidentified item */ + if (!j) + if (i == '*') { + clear(); + qshowstr(); + otradhead(); + } else if (iven[isub] == 0) + lprintf("\nYou don't have item %c!", isub + 'a'); + else { + for (j = 0; j < maxitm; j++) + if ((itm[j].obj == iven[isub]) || (iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE)) { + srcount = 0; + show3(isub); /* show what the item + * was */ + if ((iven[isub] == ODIAMOND) || (iven[isub] == ORUBY) + || (iven[isub] == OEMERALD) || (iven[isub] == OSAPPHIRE)) + value = 20 * ivenarg[isub]; + else if ((itm[j].obj == OSCROLL) || (itm[j].obj == OPOTION)) + value = 2 * itm[j + ivenarg[isub]].price; + else { + izarg = ivenarg[isub]; + value = itm[j].price; /* appreciate if a +n + * object */ + if (izarg >= 0) + value *= 2; + while ((izarg-- > 0) && ((value = 14 * (67 + value) / 10) < 500000)); + } + lprintf("\nItem (%c) is worth %d gold pieces to us. Do you want to sell it? ", i, (long) value); + yrepcount = 0; + if (getyn() == 'y') { + lprcat("yes\n"); + c[GOLD] += value; + if (c[WEAR] == isub) + c[WEAR] = -1; + if (c[WIELD] == isub) + c[WIELD] = -1; + if (c[SHIELD] == isub) + c[SHIELD] = -1; + adjustcvalues(iven[isub], ivenarg[isub]); + iven[isub] = 0; + } else + lprcat("no thanks.\n"); + j = maxitm + 100; /* get out of the inner + * loop */ + } + if (j <= maxitm + 2) + lprcat("\nSo sorry, but we are not authorized to accept that item."); + } } - } +} +void cnsitm() - { lprcat("\nSorry, we can't accept unidentified objects."); } +{ + lprcat("\nSorry, we can't accept unidentified objects."); +} /* * for the Larn Revenue Service */ +void olrs() - { - register int i,first; - unsigned long amt; - first = nosignal = 1; /* disable signals */ - clear(); resetscroll(); cursor(1,4); +{ + int i, first; + unsigned long amt; + first = nosignal = 1; /* disable signals */ + clear(); + resetscroll(); + cursor(1, 4); lprcat("Welcome to the Larn Revenue Service district office. How can we help you?"); - while (1) - { - if (first) { first=0; goto nxt; } + while (1) { + if (first) { + first = 0; + goto nxt; + } cursors(); lprcat("\n\nYour wish? [("); standout("p"); lprcat(") pay taxes, or "); standout("escape"); - lprcat("] "); yrepcount=0; - i=0; while (i!='p' && i!='\33') i=getchar(); - switch(i) - { - case 'p': lprcat("pay taxes\nHow much? "); amt = readnum((long)c[GOLD]); - if (amt<0) { lprcat("\nSorry, but we can't take negative gold\n"); amt=0; } else - if (amt>c[GOLD]) lprcat(" You don't have that much.\n"); - else c[GOLD] -= paytaxes((long)amt); - break; - - case '\33': nosignal = 0; /* enable signals */ - setscroll(); drawscreen(); return; - }; - -nxt: cursor(1,6); - if (outstanding_taxes>0) - lprintf("You presently owe %d gp in taxes. ",(long)outstanding_taxes); + lprcat("] "); + yrepcount = 0; + i = 0; + while (i != 'p' && i != '\33') + i = getchar(); + switch (i) { + case 'p': + lprcat("pay taxes\nHow much? "); + amt = readnum((long) c[GOLD]); + if (amt < 0) { + lprcat("\nSorry, but we can't take negative gold\n"); + amt = 0; + } else if (amt > c[GOLD]) + lprcat(" You don't have that much.\n"); + else + c[GOLD] -= paytaxes((long) amt); + break; + + case '\33': + nosignal = 0; /* enable signals */ + setscroll(); + drawscreen(); + return; + }; + +nxt: cursor(1, 6); + if (outstanding_taxes > 0) + lprintf("You presently owe %d gp in taxes. ", (long) outstanding_taxes); else lprcat("You do not owe us any taxes. "); - cursor(1,8); - if (c[GOLD]>0) - lprintf("You have %6d gp. ",(long)c[GOLD]); + cursor(1, 8); + if (c[GOLD] > 0) + lprintf("You have %6d gp. ", (long) c[GOLD]); else lprcat("You have no gold pieces. "); - } } +} @@ -1,223 +1,274 @@ -#ifndef lint -static char rcsid[] = "$NetBSD: tok.c,v 1.4 1995/04/24 12:24:14 cgd Exp $"; -#endif /* not lint */ +/* $NetBSD: tok.c,v 1.5 1997/10/18 20:03:54 christos Exp $ */ /* tok.c Larn is copyrighted 1986 by Noah Morgan. */ +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: tok.c,v 1.5 1997/10/18 20:03:54 christos Exp $"); +#endif /* not lint */ + #include <sys/types.h> -#ifdef SYSV -#include <fcntl.h> -#include <termio.h> -#else SYSV +#include <string.h> #include <sys/ioctl.h> -#endif SYSV +#include <stdlib.h> +#include <unistd.h> +#include <sys/wait.h> #include "header.h" -#include <string.h> +#include "extern.h" -static char lastok=0; -int yrepcount=0,dayplay=0; +static char lastok = 0; +int yrepcount = 0, dayplay = 0; #ifndef FLUSHNO #define FLUSHNO 5 -#endif FLUSHNO -static int flushno=FLUSHNO; /* input queue flushing threshold */ -#define MAXUM 52 /* maximum number of user re-named monsters */ -#define MAXMNAME 40 /* max length of a monster re-name */ -static char usermonster[MAXUM][MAXMNAME]; /* the user named monster name goes here */ -static char usermpoint=0; /* the user monster pointer */ +#endif /* FLUSHNO */ +static int flushno = FLUSHNO; /* input queue flushing threshold */ +#define MAXUM 52 /* maximum number of user re-named monsters */ +#define MAXMNAME 40 /* max length of a monster re-name */ +static char usermonster[MAXUM][MAXMNAME]; /* the user named monster + * name goes here */ +static u_char usermpoint = 0; /* the user monster pointer */ /* lexical analyzer for larn */ +int yylex() - { - char cc; - int ic; - if (hit2flag) { hit2flag=0; yrepcount=0; return(' '); } - if (yrepcount>0) { --yrepcount; return(lastok); } else yrepcount=0; - if (yrepcount==0) { bottomdo(); showplayer(); } /* show where the player is */ - lflush(); - while (1) - { +{ + char cc; + int ic; + if (hit2flag) { + hit2flag = 0; + yrepcount = 0; + return (' '); + } + if (yrepcount > 0) { + --yrepcount; + return (lastok); + } else + yrepcount = 0; + if (yrepcount == 0) { + bottomdo(); + showplayer(); + } /* show where the player is */ + lflush(); + while (1) { c[BYTESIN]++; if (ckpflag) - if ((c[BYTESIN] % 400) == 0) /* check for periodic checkpointing */ - { + if ((c[BYTESIN] % 400) == 0) { /* check for periodic + * checkpointing */ #ifndef DOCHECKPOINTS - savegame(ckpfile); + savegame(ckpfile); #else - wait(0); /* wait for other forks to finish */ - if (fork() == 0) { savegame(ckpfile); exit(); } + wait(0); /* wait for other forks to + * finish */ + if (fork() == 0) { + savegame(ckpfile); + exit(); + } #endif #ifdef TIMECHECK - if (dayplay==0) - if (playable()) - { - cursor(1,19); - lprcat("\nSorry, but it is now time for work. Your game has been saved.\n"); beep(); - lflush(); savegame(savefilename); wizard=nomove=1; sleep(4); - died(-257); - } -#endif TIMECHECK - - } + if (dayplay == 0) + if (playable()) { + cursor(1, 19); + lprcat("\nSorry, but it is now time for work. Your game has been saved.\n"); + beep(); + lflush(); + savegame(savefilename); + wizard = nomove = 1; + sleep(4); + died(-257); + } +#endif /* TIMECHECK */ - do /* if keyboard input buffer is too big, flush some of it */ - { - ioctl(0,FIONREAD,&ic); - if (ic>flushno) read(0,&cc,1); } - while (ic>flushno); + do { /* if keyboard input buffer is too big, flush + * some of it */ + ioctl(0, FIONREAD, &ic); + if (ic > flushno) + read(0, &cc, 1); + } + while (ic > flushno); - if (read(0,&cc,1) != 1) return(lastok = -1); + if (read(0, &cc, 1) != 1) + return (lastok = -1); - if (cc == 'Y'-64) /* control Y -- shell escape */ - { - resetscroll(); clear(); /* scrolling region, home, clear, no attributes */ - if ((ic=fork())==0) /* child */ - { - execl("/bin/csh",0); exit(); - } + if (cc == 'Y' - 64) { /* control Y -- shell escape */ + resetscroll(); + clear();/* scrolling region, home, clear, no + * attributes */ + if ((ic = fork()) == 0) { /* child */ + execl("/bin/csh", 0); + exit(1); + } wait(0); - if (ic<0) /* error */ - { - write(2,"Can't fork off a shell!\n",25); sleep(2); - } - - setscroll(); - return(lastok = 'L'-64); /* redisplay screen */ + if (ic < 0) { /* error */ + write(2, "Can't fork off a shell!\n", 25); + sleep(2); } - - if ((cc <= '9') && (cc >= '0')) - { yrepcount = yrepcount*10 + cc - '0'; } - else { if (yrepcount>0) --yrepcount; return(lastok = cc); } + setscroll(); + return (lastok = 'L' - 64); /* redisplay screen */ + } + if ((cc <= '9') && (cc >= '0')) { + yrepcount = yrepcount * 10 + cc - '0'; + } else { + if (yrepcount > 0) + --yrepcount; + return (lastok = cc); } } +} /* * flushall() Function to flush all type-ahead in the input buffer */ +void flushall() - { - char cc; - int ic; - for (;;) /* if keyboard input buffer is too big, flush some of it */ - { - ioctl(0,FIONREAD,&ic); - if (ic<=0) return; - while (ic>0) { read(0,&cc,1); --ic; } /* gobble up the byte */ - } +{ + char cc; + int ic; + for (;;) { /* if keyboard input buffer is too big, flush + * some of it */ + ioctl(0, FIONREAD, &ic); + if (ic <= 0) + return; + while (ic > 0) { + read(0, &cc, 1); + --ic; + } /* gobble up the byte */ } +} /* - function to set the desired hardness + function to set the desired hardness enter with hard= -1 for default hardness, else any desired hardness */ +void sethard(hard) - int hard; - { - register int j,k,i; - j=c[HARDGAME]; hashewon(); - if (restorflag==0) /* don't set c[HARDGAME] if restoring game */ - { - if (hard >= 0) c[HARDGAME]= hard; + int hard; +{ + int j, k, i; + j = c[HARDGAME]; + hashewon(); + if (restorflag == 0) { /* don't set c[HARDGAME] if restoring game */ + if (hard >= 0) + c[HARDGAME] = hard; + } else + c[HARDGAME] = j;/* set c[HARDGAME] to proper value if + * restoring game */ + + if ((k = c[HARDGAME]) != 0) + for (j = 0; j <= MAXMONST + 8; j++) { + i = ((6 + k) * monster[j].hitpoints + 1) / 6; + monster[j].hitpoints = (i < 0) ? 32767 : i; + i = ((6 + k) * monster[j].damage + 1) / 5; + monster[j].damage = (i > 127) ? 127 : i; + i = (10 * monster[j].gold) / (10 + k); + monster[j].gold = (i > 32767) ? 32767 : i; + i = monster[j].armorclass - k; + monster[j].armorclass = (i < -127) ? -127 : i; + i = (7 * monster[j].experience) / (7 + k) + 1; + monster[j].experience = (i <= 0) ? 1 : i; } - else c[HARDGAME]=j; /* set c[HARDGAME] to proper value if restoring game */ - - if (k=c[HARDGAME]) - for (j=0; j<=MAXMONST+8; j++) - { - i = ((6+k)*monster[j].hitpoints+1)/6; - monster[j].hitpoints = (i<0) ? 32767 : i; - i = ((6+k)*monster[j].damage+1)/5; - monster[j].damage = (i>127) ? 127 : i; - i = (10*monster[j].gold)/(10+k); - monster[j].gold = (i>32767) ? 32767 : i; - i = monster[j].armorclass - k; - monster[j].armorclass = (i< -127) ? -127 : i; - i = (7*monster[j].experience)/(7+k) + 1; - monster[j].experience = (i<=0) ? 1 : i; - } - } +} /* function to read and process the larn options file */ +void readopts() - { - register char *i; - register int j,k; - int flag; - flag=1; /* set to 0 if he specifies a name for his character */ - if (lopen(optsfile) < 0) - { - strcpy(logname,loginname); return; /* user name if no character name */ - } +{ + char *i; + int j, k; + int flag; + flag = 1; /* set to 0 if he specifies a name for his + * character */ + if (lopen(optsfile) < 0) { + strcpy(logname, loginname); + return; /* user name if no character name */ + } i = " "; - while (*i) - { - if ((i=(char *)lgetw()) == 0) break; /* check for EOF */ - while ((*i==' ') || (*i=='\t')) i++; /* eat leading whitespace */ - switch(*i) - { - case 'b': if (strcmp(i,"bold-objects") == 0) boldon=1; - break; + while (*i) { + if ((i = (char *) lgetw()) == 0) + break; /* check for EOF */ + while ((*i == ' ') || (*i == '\t')) + i++; /* eat leading whitespace */ + switch (*i) { + case 'b': + if (strcmp(i, "bold-objects") == 0) + boldon = 1; + break; - case 'e': if (strcmp(i,"enable-checkpointing") == 0) ckpflag=1; - break; + case 'e': + if (strcmp(i, "enable-checkpointing") == 0) + ckpflag = 1; + break; - case 'i': if (strcmp(i,"inverse-objects") == 0) boldon=0; - break; + case 'i': + if (strcmp(i, "inverse-objects") == 0) + boldon = 0; + break; - case 'f': if (strcmp(i,"female") == 0) sex=0; /* male or female */ - break; + case 'f': + if (strcmp(i, "female") == 0) + sex = 0; /* male or female */ + break; - case 'm': if (strcmp(i,"monster:")== 0) /* name favorite monster */ - { - if ((i=lgetw())==0) break; - if (strlen(i)>=MAXMNAME) i[MAXMNAME-1]=0; - strcpy(usermonster[usermpoint],i); - if (usermpoint >= MAXUM) break; /* defined all of em */ - if (isalpha(j=usermonster[usermpoint][0])) - { - for (k=1; k<MAXMONST+8; k++) /* find monster */ - if (monstnamelist[k] == j) - { - monster[k].name = &usermonster[usermpoint++][0]; - break; - } - } - } - else if (strcmp(i,"male") == 0) sex=1; + case 'm': + if (strcmp(i, "monster:") == 0) { /* name favorite monster */ + if ((i = lgetw()) == 0) break; - - case 'n': if (strcmp(i,"name:") == 0) /* defining players name */ - { - if ((i=lgetw())==0) break; - if (strlen(i)>=LOGNAMESIZE) i[LOGNAMESIZE-1]=0; - strcpy(logname,i); flag=0; + if (strlen(i) >= MAXMNAME) + i[MAXMNAME - 1] = 0; + strcpy(usermonster[usermpoint], i); + if (usermpoint >= MAXUM) + break; /* defined all of em */ + if (isalpha(j = usermonster[usermpoint][0])) { + for (k = 1; k < MAXMONST + 8; k++) /* find monster */ + if (monstnamelist[k] == j) { + monster[k].name = &usermonster[usermpoint++][0]; + break; } - else if (strcmp(i,"no-introduction") == 0) nowelcome=1; - else if (strcmp(i,"no-beep") == 0) nobeep=1; + } + } else if (strcmp(i, "male") == 0) + sex = 1; + break; + + case 'n': + if (strcmp(i, "name:") == 0) { /* defining players name */ + if ((i = lgetw()) == 0) break; + if (strlen(i) >= LOGNAMESIZE) + i[LOGNAMESIZE - 1] = 0; + strcpy(logname, i); + flag = 0; + } else if (strcmp(i, "no-introduction") == 0) + nowelcome = 1; + else if (strcmp(i, "no-beep") == 0) + nobeep = 1; + break; - case 'p': if (strcmp(i,"process-name:")== 0) - { - if ((i=lgetw())==0) break; - if (strlen(i)>=PSNAMESIZE) i[PSNAMESIZE-1]=0; - strcpy(psname,i); - } - else if (strcmp(i,"play-day-play") == 0) dayplay=1; + case 'p': + if (strcmp(i, "process-name:") == 0) { + if ((i = lgetw()) == 0) break; + if (strlen(i) >= PSNAMESIZE) + i[PSNAMESIZE - 1] = 0; + strcpy(psname, i); + } else if (strcmp(i, "play-day-play") == 0) + dayplay = 1; + break; - case 's': if (strcmp(i,"savefile:") == 0) /* defining savefilename */ - { - if ((i=lgetw())==0) break; - strcpy(savefilename,i); flag=0; - } + case 's': + if (strcmp(i, "savefile:") == 0) { /* defining savefilename */ + if ((i = lgetw()) == 0) break; + strcpy(savefilename, i); + flag = 0; + } + break; }; - } - if (flag) strcpy(logname,loginname); } - + if (flag) + strcpy(logname, loginname); +} |