diff --git a/games/adventure/crc.c b/games/adventure/crc.c index 19b0f90aacf5..952d102343e0 100644 --- a/games/adventure/crc.c +++ b/games/adventure/crc.c @@ -1,136 +1,136 @@ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * James W. Williams of the University of Maryland. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)crc.c 8.1 (Berkeley) 5/31/93"; static char ORIGINAL_sccsid[] = "@(#)crc.c 5.2 (Berkeley) 4/4/91"; #endif /* not lint */ #include const u_long crctab[] = { 0x7fffffff, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; /* * crc -- * Compute a POSIX.2 checksum. This routine modified by Jim Gillogly * to work on sequential data rather than on a file. Initial call to * crc_start initializes the sum, and subsequent calls to crc update * it. */ u_long crcval; u_int step; crc_start() { crcval = step = 0; } u_long crc(ptr, nr) /* Process nr bytes at a time; ptr points to them */ const char *ptr; int nr; { - register int i; - register const char *p; + int i; + const char *p; while (nr > 0) for (p = ptr; nr--; ++p) { if (!(i = crcval >> 24 ^ *p)) { i = step++; if (step >= sizeof(crctab)/sizeof(crctab[0])) step = 0; } crcval = (crcval << 8) ^ crctab[i]; } return crcval & 0xffffffff; /* Mask to 32 bits. */ } diff --git a/games/adventure/done.c b/games/adventure/done.c index 79b91c3d7328..9cb25bf87eb1 100644 --- a/games/adventure/done.c +++ b/games/adventure/done.c @@ -1,141 +1,141 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)done.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* Re-coding of advent in C: termination routines */ #include #include "hdr.h" score() /* sort of like 20000 */ -{ register int scor,i; +{ int scor,i; mxscor=scor=0; for (i=50; i<=maxtrs; i++) { if (ptext[i].txtlen==0) continue; k=12; if (i==chest) k=14; if (i>chest) k=16; if (prop[i]>=0) scor += 2; if (place[i]==3&&prop[i]==0) scor += k-2; mxscor += k; } scor += (maxdie-numdie)*10; mxscor += maxdie*10; if (!(scorng||gaveup)) scor += 4; mxscor += 4; if (dflag!=0) scor += 25; mxscor += 25; if (closng) scor += 25; mxscor += 25; if (closed) { if (bonus==0) scor += 10; if (bonus==135) scor += 25; if (bonus==134) scor += 30; if (bonus==133) scor += 45; } mxscor += 45; if (place[magzin]==108) scor++; mxscor++; scor += 2; mxscor += 2; for (i=1; i<=hntmax; i++) if (hinted[i]) scor -= hints[i][2]; return(scor); } done(entry) /* entry=1 means goto 13000 */ /* game is over */ int entry; /* entry=2 means goto 20000 */ /* 3=19000 */ -{ register int i,sc; +{ int i,sc; if (entry==1) mspeak(1); if (entry==3) rspeak(136); printf("\n\n\nYou scored %d out of a ",(sc=score())); printf("possible %d using %d turns.\n",mxscor,turns); for (i=1; i<=clsses; i++) if (cval[i]>=sc) { speak(&ctext[i]); if (i==clsses-1) { printf("To achieve the next higher rating"); printf(" would be a neat trick!\n\n"); printf("Congratulations!!\n"); exit(0); } k=cval[i]+1-sc; printf("To achieve the next higher rating, you need"); printf(" %d more point",k); if (k==1) printf(".\n"); else printf("s.\n"); exit(0); } printf("You just went off my scale!!!\n"); exit(0); } void die(entry) /* label 90 */ int entry; -{ register int i; +{ int i; if (entry != 99) { rspeak(23); oldlc2=loc; } if (closng) /* 99 */ { rspeak(131); numdie++; done(2); } yea=yes(81+numdie*2,82+numdie*2,54); numdie++; if (numdie==maxdie || !yea) done(2); place[water]=0; place[oil]=0; if (toting(lamp)) prop[lamp]=0; for (i=100; i>=1; i--) { if (!toting(i)) continue; k=oldlc2; if (i==lamp) k=1; drop(i,k); } loc=3; oldloc=loc; } diff --git a/games/adventure/init.c b/games/adventure/init.c index f1a790de6764..893e3039413e 100644 --- a/games/adventure/init.c +++ b/games/adventure/init.c @@ -1,216 +1,216 @@ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/2/93"; #endif /* not lint */ /* Re-coding of advent in C: data initialization */ #include #include #include #include #include "hdr.h" int blklin = TRUE; int setbit[16] = {1,2,4,010,020,040,0100,0200,0400,01000,02000,04000, 010000,020000,040000,0100000}; init() /* everything for 1st time run */ { rdata(); /* read data from orig. file */ linkdata(); poof(); } char *decr(a,b,c,d,e) char a,b,c,d,e; { static char buf[6]; buf[0] = a-'+'; buf[1] = b-'-'; buf[2] = c-'#'; buf[3] = d-'&'; buf[4] = e-'%'; buf[5] = 0; return buf; } linkdata() /* secondary data manipulation */ -{ register int i,j; +{ int i,j; /* array linkages */ for (i=1; i<=LOCSIZ; i++) if (ltext[i].seekadr!=0 && travel[i] != 0) if ((travel[i]->tverb)==1) cond[i]=2; for (j=100; j>0; j--) if (fixd[j]>0) { drop(j+100,fixd[j]); drop(j,plac[j]); } for (j=100; j>0; j--) { fixed[j]=fixd[j]; if (plac[j]!=0 && fixd[j]<=0) drop(j,plac[j]); } maxtrs=79; tally=0; tally2=0; for (i=50; i<=maxtrs; i++) { if (ptext[i].seekadr!=0) prop[i] = -1; tally -= prop[i]; } /* define mnemonics */ keys = vocab(DECR(k,e,y,s,\0), 1); lamp = vocab(DECR(l,a,m,p,\0), 1); grate = vocab(DECR(g,r,a,t,e), 1); cage = vocab(DECR(c,a,g,e,\0),1); rod = vocab(DECR(r,o,d,\0,\0),1); rod2=rod+1; steps=vocab(DECR(s,t,e,p,s),1); bird = vocab(DECR(b,i,r,d,\0),1); door = vocab(DECR(d,o,o,r,\0),1); pillow= vocab(DECR(p,i,l,l,o), 1); snake = vocab(DECR(s,n,a,k,e), 1); fissur= vocab(DECR(f,i,s,s,u), 1); tablet= vocab(DECR(t,a,b,l,e), 1); clam = vocab(DECR(c,l,a,m,\0),1); oyster= vocab(DECR(o,y,s,t,e), 1); magzin= vocab(DECR(m,a,g,a,z), 1); dwarf = vocab(DECR(d,w,a,r,f), 1); knife = vocab(DECR(k,n,i,f,e), 1); food = vocab(DECR(f,o,o,d,\0),1); bottle= vocab(DECR(b,o,t,t,l), 1); water = vocab(DECR(w,a,t,e,r), 1); oil = vocab(DECR(o,i,l,\0,\0),1); plant = vocab(DECR(p,l,a,n,t), 1); plant2=plant+1; axe = vocab(DECR(a,x,e,\0,\0),1); mirror= vocab(DECR(m,i,r,r,o), 1); dragon= vocab(DECR(d,r,a,g,o), 1); chasm = vocab(DECR(c,h,a,s,m), 1); troll = vocab(DECR(t,r,o,l,l), 1); troll2=troll+1; bear = vocab(DECR(b,e,a,r,\0),1); messag= vocab(DECR(m,e,s,s,a), 1); vend = vocab(DECR(v,e,n,d,i), 1); batter= vocab(DECR(b,a,t,t,e), 1); nugget= vocab(DECR(g,o,l,d,\0),1); coins = vocab(DECR(c,o,i,n,s), 1); chest = vocab(DECR(c,h,e,s,t), 1); eggs = vocab(DECR(e,g,g,s,\0),1); tridnt= vocab(DECR(t,r,i,d,e), 1); vase = vocab(DECR(v,a,s,e,\0),1); emrald= vocab(DECR(e,m,e,r,a), 1); pyram = vocab(DECR(p,y,r,a,m), 1); pearl = vocab(DECR(p,e,a,r,l), 1); rug = vocab(DECR(r,u,g,\0,\0),1); chain = vocab(DECR(c,h,a,i,n), 1); back = vocab(DECR(b,a,c,k,\0),0); look = vocab(DECR(l,o,o,k,\0),0); cave = vocab(DECR(c,a,v,e,\0),0); null = vocab(DECR(n,u,l,l,\0),0); entrnc= vocab(DECR(e,n,t,r,a), 0); dprssn= vocab(DECR(d,e,p,r,e), 0); enter = vocab(DECR(e,n,t,e,r), 0); pour = vocab(DECR(p,o,u,r,\0), 2); say = vocab(DECR(s,a,y,\0,\0),2); lock = vocab(DECR(l,o,c,k,\0),2); throw = vocab(DECR(t,h,r,o,w), 2); find = vocab(DECR(f,i,n,d,\0),2); invent= vocab(DECR(i,n,v,e,n), 2); /* initialize dwarves */ chloc=114; chloc2=140; for (i=1; i<=6; i++) dseen[i]=FALSE; dflag=0; dloc[1]=19; dloc[2]=27; dloc[3]=33; dloc[4]=44; dloc[5]=64; dloc[6]=chloc; daltlc=18; /* random flags & ctrs */ turns=0; lmwarn=FALSE; iwest=0; knfloc=0; detail=0; abbnum=5; for (i=0; i<=4; i++) if (rtext[2*i+81].seekadr!=0) maxdie=i+1; numdie=holdng=dkill=foobar=bonus=0; clock1=30; clock2=50; saved=0; closng=panic=closed=scorng=FALSE; } trapdel() /* come here if he hits a del */ { delhit = 1; /* main checks, treats as QUIT */ signal(2,trapdel); /* catch subsequent DELs */ } startup() { demo=Start(); srandomdev(); hinted[3]=yes(65,1,0); newloc=1; delhit = 0; limit=330; if (hinted[3]) limit=1000; /* better batteries if instrucs */ } diff --git a/games/adventure/io.c b/games/adventure/io.c index 4b5365972078..7b929f674515 100644 --- a/games/adventure/io.c +++ b/games/adventure/io.c @@ -1,522 +1,522 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* Re-coding of advent in C: file i/o and user i/o */ #include "hdr.h" #include #include #include #include getin(wrd1,wrd2) /* get command from user */ char **wrd1,**wrd2; /* no prompt, usually */ -{ register char *s; +{ char *s; static char wd1buf[MAXSTR],wd2buf[MAXSTR]; int first, numch; *wrd1=wd1buf; /* return ptr to internal string*/ *wrd2=wd2buf; wd2buf[0]=0; /* in case it isn't set here */ for (s=wd1buf, first=1, numch=0;;) { if ((*s=getchar())>='A' && *s <='Z') *s = *s - ('A' -'a'); /* convert to upper case */ switch(*s) /* start reading from user */ { case '\n': *s=0; return; case ' ': if (s==wd1buf||s==wd2buf) /* initial blank */ continue; *s=0; if (first) /* finished 1st wd; start 2nd */ { first=numch=0; s=wd2buf; break; } else /* finished 2nd word */ { FLUSHLINE; *s=0; return; } case EOF: printf("user closed input stream, quitting...\n"); exit(0); default: if (++numch>=MAXSTR) /* string too long */ { printf("Give me a break!!\n"); wd1buf[0]=wd2buf[0]=0; FLUSHLINE; return; } s++; } } } yes(x,y,z) /* confirm with rspeak */ int x,y,z; -{ register int result; +{ int result; int ch; for (;;) { rspeak(x); /* tell him what we want*/ if ((ch=getchar())=='y') result=TRUE; else if (ch=='n') result=FALSE; else if (ch == EOF) { printf("user closed input stream, quitting...\n"); exit(0); } FLUSHLINE; if (ch=='y'|| ch=='n') break; printf("Please answer the question.\n"); } if (result==TRUE) rspeak(y); if (result==FALSE) rspeak(z); return(result); } yesm(x,y,z) /* confirm with mspeak */ int x,y,z; -{ register int result; +{ int result; int ch; for (;;) { mspeak(x); /* tell him what we want*/ if ((ch=getchar())=='y') result=TRUE; else if (ch=='n') result=FALSE; else if (ch == EOF) { printf("user closed input stream, quitting...\n"); exit(0); } FLUSHLINE; if (ch=='y'|| ch=='n') break; printf("Please answer the question.\n"); } if (result==TRUE) mspeak(y); if (result==FALSE) mspeak(z); return(result); } /* FILE *inbuf,*outbuf; */ char *inptr; /* Pointer into virtual disk */ int outsw = 0; /* putting stuff to data file? */ const char iotape[] = "Ax3F'\003tt$8h\315qer*h\017nGKrX\207:!l"; const char *tape = iotape; /* pointer to encryption tape */ next() /* next virtual char, bump adr */ { int ch; ch=(*inptr ^ random()) & 0xFF; /* Decrypt input data */ if (outsw) /* putting data in tmp file */ { if (*tape==0) tape=iotape; /* rewind encryption tape */ *inptr = ch ^ *tape++; /* re-encrypt and replace value */ } inptr++; return(ch); } char breakch; /* tell which char ended rnum */ rdata() /* "read" data from virtual file*/ -{ register int sect; - register char ch; +{ int sect; + char ch; inptr = data_file; /* Pointer to virtual data file */ srandom(SEED); /* which is lightly encrypted. */ clsses=1; for (;;) /* read data sections */ { sect=next()-'0'; /* 1st digit of section number */ #ifdef VERBOSE printf("Section %c",sect+'0'); #endif if ((ch=next())!=LF) /* is there a second digit? */ { FLUSHLF; #ifdef VERBOSE putchar(ch); #endif sect=10*sect+ch-'0'; } #ifdef VERBOSE putchar('\n'); #endif switch(sect) { case 0: /* finished reading database */ return; case 1: /* long form descriptions */ rdesc(1); break; case 2: /* short form descriptions */ rdesc(2); break; case 3: /* travel table */ rtrav(); break; case 4: /* vocabulary */ rvoc(); break; case 5: /* object descriptions */ rdesc(5); break; case 6: /* arbitrary messages */ rdesc(6); break; case 7: /* object locations */ rlocs(); break; case 8: /* action defaults */ rdflt(); break; case 9: /* liquid assets */ rliq(); break; case 10: /* class messages */ rdesc(10); break; case 11: /* hints */ rhints(); break; case 12: /* magic messages */ rdesc(12); break; default: printf("Invalid data section number: %d\n",sect); for (;;) putchar(next()); } if (breakch!=LF) /* routines return after "-1" */ FLUSHLF; } } char nbf[12]; rnum() /* read initial location num */ -{ register char *s; +{ char *s; tape = iotape; /* restart encryption tape */ for (s=nbf,*s=0;; s++) if ((*s=next())==TAB || *s=='\n' || *s==LF) break; breakch= *s; /* save char for rtrav() */ *s=0; /* got the number as ascii */ if (nbf[0]=='-') return(-1); /* end of data */ return(atoi(nbf)); /* convert it to integer */ } char *seekhere; rdesc(sect) /* read description-format msgs */ int sect; -{ register char *s,*t; - register int locc; +{ char *s,*t; + int locc; char *seekstart, *maystart, *adrstart; char *entry; seekhere = inptr; /* Where are we in virtual file?*/ outsw=1; /* these msgs go into tmp file */ for (oldloc= -1, seekstart=seekhere;;) { maystart=inptr; /* maybe starting new entry */ if ((locc=rnum())!=oldloc && oldloc>=0 /* finished msg */ && ! (sect==5 && (locc==0 || locc>=100)))/* unless sect 5*/ { switch(sect) /* now put it into right table */ { case 1: /* long descriptions */ ltext[oldloc].seekadr=seekhere; ltext[oldloc].txtlen=maystart-seekstart; break; case 2: /* short descriptions */ stext[oldloc].seekadr=seekhere; stext[oldloc].txtlen=maystart-seekstart; break; case 5: /* object descriptions */ ptext[oldloc].seekadr=seekhere; ptext[oldloc].txtlen=maystart-seekstart; break; case 6: /* random messages */ if (oldloc>RTXSIZ) { errx(1, "Too many random msgs"); } rtext[oldloc].seekadr=seekhere; rtext[oldloc].txtlen=maystart-seekstart; break; case 10: /* class messages */ ctext[clsses].seekadr=seekhere; ctext[clsses].txtlen=maystart-seekstart; cval[clsses++]=oldloc; break; case 12: /* magic messages */ if (oldloc>MAGSIZ) { errx(1, "Too many magic msgs"); } mtext[oldloc].seekadr=seekhere; mtext[oldloc].txtlen=maystart-seekstart; break; default: errx(1, "rdesc called with bad section"); } seekhere += maystart-seekstart; } if (locc<0) { outsw=0; /* turn off output */ seekhere += 3; /* -1 */ return; } if (sect!=5 || (locc>0 && locc<100)) { if (oldloc!=locc)/* starting a new message */ seekstart=maystart; oldloc=locc; } FLUSHLF; /* scan the line */ } } rtrav() /* read travel table */ -{ register int locc; - register struct travlist *t; - register char *s; +{ int locc; + struct travlist *t; + char *s; char buf[12]; int len,m,n,entries; for (oldloc= -1;;) /* get another line */ { if ((locc=rnum())!=oldloc && oldloc>=0) /* end of entry */ { t->next = 0; /* terminate the old entry */ /* printf("%d:%d entries\n",oldloc,entries); */ /* twrite(oldloc); */ } if (locc== -1) return; if (locc!=oldloc) /* getting a new entry */ { t=travel[locc]=(struct travlist *) malloc(sizeof (struct travlist)); /* printf("New travel list for %d\n",locc); */ if (t == NULL) errx(1, "Out of memory!"); entries=0; oldloc=locc; } for (s=buf;; *s++) /* get the newloc number /ASCII */ if ((*s=next())==TAB || *s==LF) break; *s=0; len=strlen(buf); /* quad long number handling */ /* printf("Newloc: %s (%d chars)\n",buf,len); */ if (len<4) /* no "m" conditions */ { m=0; n=atoi(buf); /* newloc mod 1000 = newloc */ } else /* a long integer */ { n=atoi(buf+len-3); buf[len-3]=0; /* terminate newloc/1000 */ m=atoi(buf); } while (breakch!=LF) /* only do one line at a time */ { if (entries++) { t=t->next=(struct travlist *) malloc(sizeof (struct travlist)); if (t == NULL) errx(1, "Out of memory!"); } t->tverb=rnum();/* get verb from the file */ t->tloc=n; /* table entry mod 1000 */ t->conditions=m;/* table entry / 1000 */ /* printf("entry %d for %d\n",entries,locc); */ } } } #ifdef DEBUG twrite(loq) /* travel options from this loc */ int loq; -{ register struct travlist *t; +{ struct travlist *t; printf("If"); speak(<ext[loq]); printf("then\n"); for (t=travel[loq]; t!=0; t=t->next) { printf("verb %d takes you to ",t->tverb); if (t->tloc<=300) speak(<ext[t->tloc]); else if (t->tloc<=500) printf("special code %d\n",t->tloc-300); else rspeak(t->tloc-500); printf("under conditions %d\n",t->conditions); } } #endif DEBUG rvoc() -{ register char *s; /* read the vocabulary */ - register int index; +{ char *s; /* read the vocabulary */ + int index; char buf[6]; for (;;) { index=rnum(); if (index<0) break; for (s=buf,*s=0;; s++) /* get the word */ if ((*s=next())==TAB || *s=='\n' || *s==LF || *s==' ') break; /* terminate word with newline, LF, tab, blank */ if (*s!='\n' && *s!=LF) FLUSHLF; /* can be comments */ *s=0; /* printf("\"%s\"=%d\n",buf,index);*/ vocab(buf,-2,index); } /* prht(); */ } rlocs() /* initial object locations */ { for (;;) { if ((obj=rnum())<0) break; plac[obj]=rnum(); /* initial loc for this obj */ if (breakch==TAB) /* there's another entry */ fixd[obj]=rnum(); else fixd[obj]=0; } } rdflt() /* default verb messages */ { for (;;) { if ((verb=rnum())<0) break; actspk[verb]=rnum(); } } rliq() /* liquid assets &c: cond bits */ -{ register int bitnum; +{ int bitnum; for (;;) /* read new bit list */ { if ((bitnum=rnum())<0) break; for (;;) /* read locs for bits */ { cond[rnum()] |= setbit[bitnum]; if (breakch==LF) break; } } } rhints() -{ register int hintnum,i; +{ int hintnum,i; hntmax=0; for (;;) { if ((hintnum=rnum())<0) break; for (i=1; i<5; i++) hints[hintnum][i]=rnum(); if (hintnum>hntmax) hntmax=hintnum; } } rspeak(msg) int msg; { if (msg!=0) speak(&rtext[msg]); } mspeak(msg) int msg; { if (msg!=0) speak(&mtext[msg]); } speak(msg) /* read, decrypt, and print a message (not ptext) */ const struct text *msg;/* msg is a pointer to seek address and length of mess */ { - register char *s, nonfirst; + char *s, nonfirst; s = msg->seekadr; nonfirst=0; while (s - msg->seekadr < msg->txtlen) /* read a line at a time */ { tape=iotape; /* restart decryption tape */ while ((*s++ ^ *tape++) != TAB); /* read past loc num */ /* assume tape is longer than location number */ /* plus the lookahead put together */ if ((*s ^ *tape) == '>' && (*(s+1) ^ *(tape+1)) == '$' && (*(s+2) ^ *(tape+2)) == '<') break; if (blklin && !nonfirst++) putchar('\n'); do { if (*tape == 0) tape = iotape;/* rewind decryp tape */ putchar(*s ^ *tape); } while ((*s++ ^ *tape++) != LF); /* better end with LF */ } } pspeak(m,skip) /* read, decrypt an print a ptext message */ int m; /* msg is the number of all the p msgs for this place */ int skip; /* assumes object 1 doesn't have prop 1, obj 2 no prop 2 &c*/ { - register char *s,nonfirst; + char *s,nonfirst; char *numst, save; struct text *msg; char *tbuf; msg = &ptext[m]; if ((tbuf=(char *) malloc(msg->txtlen + 1)) == 0) errx(1, "Out of memory!"); memcpy(tbuf, msg->seekadr, msg->txtlen + 1); /* Room to null */ s = tbuf; nonfirst=0; while (s - tbuf < msg->txtlen) /* read line at a time */ { tape=iotape; /* restart decryption tape */ for (numst=s; (*s^= *tape++)!=TAB; s++); /* get number */ save = *s; /* Temporarily trash the string (cringe) */ *s++ = 0; /* decrypting number within the string */ if (atoi(numst) != 100 * skip && skip >= 0) { while ((*s++^*tape++)!=LF) /* flush the line */ if (*tape==0) tape=iotape; continue; } if ((*s^*tape)=='>' && (*(s+1)^*(tape+1))=='$' && (*(s+2)^*(tape+2))=='<') break; if (blklin && ! nonfirst++) putchar('\n'); do { if (*tape==0) tape=iotape; putchar(*s^*tape); } while ((*s++^*tape++)!=LF); /* better end with LF */ if (skip<0) break; } free(tbuf); } diff --git a/games/adventure/main.c b/games/adventure/main.c index 6bd549ea24ba..39a90c436da0 100644 --- a/games/adventure/main.c +++ b/games/adventure/main.c @@ -1,584 +1,584 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/2/93"; #endif /* not lint */ /* Re-coding of advent in C: main program */ #include #include #include #include #include "hdr.h" main(argc,argv) int argc; char **argv; { extern int errno; - register int i; + int i; int rval,ll; struct text *kk; extern trapdel(); /* revoke */ setgid(getgid()); init(); /* Initialize everything */ signal(SIGINT,trapdel); if (argc > 1) /* Restore file specified */ { /* Restart is label 8305 (Fortran) */ i = restore(argv[1]); /* See what we've got */ switch(i) { case 0: /* The restore worked fine */ yea=Start(); k=null; unlink(argv[1]);/* Don't re-use the save */ goto l8; /* Get where we're going */ case 1: /* Couldn't open it */ exit(1); /* So give up */ case 2: /* Oops -- file was altered */ rspeak(202); /* You dissolve */ exit(1); /* File could be non-adventure */ } /* So don't unlink it. */ } startup(); /* prepare for a user */ for (;;) /* main command loop (label 2) */ { if (newloc<9 && newloc!=0 && closng) { rspeak(130); /* if closing leave only by */ newloc=loc; /* main office */ if (!panic) clock2=15; panic=TRUE; } rval=fdwarf(); /* dwarf stuff */ if (rval==99) die(99); l2000: if (loc==0) die(99); /* label 2000 */ kk = &stext[loc]; if ((abb[loc]%abbnum)==0 || kk->seekadr==0) kk = <ext[loc]; if (!forced(loc) && dark()) { if (wzdark && pct(35)) { die(90); goto l2000; } kk = &rtext[16]; } l2001: if (toting(bear)) rspeak(141); /* 2001 */ speak(kk); k=1; if (forced(loc)) goto l8; if (loc==33 && pct(25)&&!closng) rspeak(8); if (!dark()) { abb[loc]++; for (i=atloc[loc]; i!=0; i=linkx[i]) /*2004 */ { obj=i; if (obj>100) obj -= 100; if (obj==steps && toting(nugget)) continue; if (prop[obj]<0) { if (closed) continue; prop[obj]=0; if (obj==rug||obj==chain) prop[obj]=1; tally--; if (tally==tally2 && tally != 0) if (limit>35) limit=35; } ll = prop[obj]; /* 2006 */ if (obj==steps && loc==fixed[steps]) ll = 1; pspeak(obj, ll); } /* 2008 */ goto l2012; l2009: k=54; /* 2009 */ l2010: spk=k; l2011: rspeak(spk); } l2012: verb=0; /* 2012 */ obj=0; l2600: checkhints(); /* to 2600-2602 */ if (closed) { if (prop[oyster]<0 && toting(oyster)) pspeak(oyster,1); for (i=1; i<100; i++) if (toting(i)&&prop[i]<0) /*2604 */ prop[i] = -1-prop[i]; } wzdark=dark(); /* 2605 */ if (knfloc>0 && knfloc!=loc) knfloc=1; getin(&wd1,&wd2); if (delhit) /* user typed a DEL */ { delhit=0; /* reset counter */ strcpy(wd1,"quit"); /* pretend he's quitting*/ *wd2=0; } l2608: if ((foobar = -foobar)>0) foobar=0; /* 2608 */ /* should check here for "magic mode" */ turns++; if (demo && turns>=SHORT) done(1); /* to 13000 */ if (verb==say && *wd2!=0) verb=0; if (verb==say) goto l4090; if (tally==0 && loc>=15 && loc!=33) clock1--; if (clock1==0) { closing(); /* to 10000 */ goto l19999; } if (clock1<0) clock2--; if (clock2==0) { caveclose(); /* to 11000 */ continue; /* back to 2 */ } if (prop[lamp]==1) limit--; if (limit<=30 && here(batter) && prop[batter]==0 && here(lamp)) { rspeak(188); /* 12000 */ prop[batter]=1; if (toting(batter)) drop(batter,loc); limit=limit+2500; lmwarn=FALSE; goto l19999; } if (limit==0) { limit = -1; /* 12400 */ prop[lamp]=0; rspeak(184); goto l19999; } if (limit<0&&loc<=8) { rspeak(185); /* 12600 */ gaveup=TRUE; done(2); /* to 20000 */ } if (limit<=30) { if (lmwarn|| !here(lamp)) goto l19999; /*12200*/ lmwarn=TRUE; spk=187; if (place[batter]==0) spk=183; if (prop[batter]==1) spk=189; rspeak(spk); } l19999: k=43; if (liqloc(loc)==water) k=70; if (!strncmp(wd1,"enter",5) && (!strncmp(wd2,"strea",5)||!strncmp(wd2,"water",5))) goto l2010; if (!strncmp(wd1,"enter",5) && *wd2!=0) goto l2800; if ((strncmp(wd1,"water",5)&&strncmp(wd1,"oil",3)) || (strncmp(wd2,"plant",5)&&strncmp(wd2,"door",4))) goto l2610; if (at(vocab(wd2,1))) strcpy(wd2,"pour"); l2610: if (!strncmp(wd1,"west",4)) if (++iwest==10) rspeak(17); l2630: i=vocab(wd1,-1); if (i== -1) { spk=60; /* 3000 */ if (pct(20)) spk=61; if (pct(20)) spk=13; rspeak(spk); goto l2600; } k=i%1000; kq=i/1000+1; switch(kq) { case 1: goto l8; case 2: goto l5000; case 3: goto l4000; case 4: goto l2010; default: bug(22); } l8: switch(march()) { case 2: continue; /* i.e. goto l2 */ case 99: die(99); goto l2000; default: bug(110); } l2800: strcpy(wd1,wd2); *wd2=0; goto l2610; l4000: verb=k; spk=actspk[verb]; if (*wd2!=0 && verb!=say) goto l2800; if (verb==say) obj= *wd2; if (obj!=0) goto l4090; l4080: switch(verb) { case 1: /* take = 8010 */ if (atloc[loc]==0||linkx[atloc[loc]]!=0) goto l8000; for (i=1; i<=5; i++) if (dloc[i]==loc&&dflag>=2) goto l8000; obj=atloc[loc]; goto l9010; case 2: case 3: case 9: /* 8000 : drop,say,wave */ case 10: case 16: case 17: /* calm,rub,toss */ case 19: case 21: case 28: /* find,feed,break */ case 29: /* wake */ l8000: printf("%s what?\n",wd1); obj=0; goto l2600; case 4: case 6: /* 8040 open,lock */ spk=28; if (here(clam)) obj=clam; if (here(oyster)) obj=oyster; if (at(door)) obj=door; if (at(grate)) obj=grate; if (obj!=0 && here(chain)) goto l8000; if (here(chain)) obj=chain; if (obj==0) goto l2011; goto l9040; case 5: goto l2009; /* nothing */ case 7: goto l9070; /* on */ case 8: goto l9080; /* off */ case 11: goto l8000; /* walk */ case 12: goto l9120; /* kill */ case 13: goto l9130; /* pour */ case 14: /* eat: 8140 */ if (!here(food)) goto l8000; l8142: dstroy(food); spk=72; goto l2011; case 15: goto l9150; /* drink */ case 18: /* quit: 8180 */ gaveup=yes(22,54,54); if (gaveup) done(2); /* 8185 */ goto l2012; case 20: /* invent=8200 */ spk=98; for (i=1; i<=100; i++) { if (i!=bear && toting(i)) { if (spk==98) rspeak(99); blklin=FALSE; pspeak(i,-1); blklin=TRUE; spk=0; } } if (toting(bear)) spk=141; goto l2011; case 22: goto l9220; /* fill */ case 23: goto l9230; /* blast */ case 24: /* score: 8240 */ scorng=TRUE; printf("If you were to quit now, you would score"); printf(" %d out of a possible ",score()); printf("%d.",mxscor); scorng=FALSE; gaveup=yes(143,54,54); if (gaveup) done(2); goto l2012; case 25: /* foo: 8250 */ k=vocab(wd1,3); spk=42; if (foobar==1-k) goto l8252; if (foobar!=0) spk=151; goto l2011; l8252: foobar=k; if (k!=4) goto l2009; foobar=0; if (place[eggs]==plac[eggs] ||(toting(eggs)&&loc==plac[eggs])) goto l2011; if (place[eggs]==0&&place[troll]==0&&prop[troll]==0) prop[troll]=1; k=2; if (here(eggs)) k=1; if (loc==plac[eggs]) k=0; move(eggs,plac[eggs]); pspeak(eggs,k); goto l2012; case 26: /* brief=8260 */ spk=156; abbnum=10000; detail=3; goto l2011; case 27: /* read=8270 */ if (here(magzin)) obj=magzin; if (here(tablet)) obj=obj*100+tablet; if (here(messag)) obj=obj*100+messag; if (closed&&toting(oyster)) obj=oyster; if (obj>100||obj==0||dark()) goto l8000; goto l9270; case 30: /* suspend=8300 */ spk=201; if (demo) goto l2011; printf("I can suspend your adventure for you so"); printf(" you can resume later, but\n"); printf("you will have to wait at least"); printf(" %d minutes before continuing.",latncy); if (!yes(200,54,54)) goto l2012; datime(&saved,&savet); ciao(); /* Do we quit? */ continue; /* Maybe not */ case 31: /* hours=8310 */ printf("Colossal cave is closed 9am-5pm Mon "); printf("through Fri except holidays.\n"); goto l2012; default: bug(23); } l4090: switch(verb) { case 1: /* take = 9010 */ l9010: switch(trtake()) { case 2011: goto l2011; case 9220: goto l9220; case 2009: goto l2009; case 2012: goto l2012; default: bug(102); } l9020: case 2: /* drop = 9020 */ switch(trdrop()) { case 2011: goto l2011; case 19000: done(3); case 2012: goto l2012; default: bug(105); } l9030: case 3: switch(trsay()) { case 2012: goto l2012; case 2630: goto l2630; default: bug(107); } l9040: case 4: case 6: /* open, close */ switch(tropen()) { case 2011: goto l2011; case 2010: goto l2010; default: bug(106); } case 5: goto l2009; /* nothing */ case 7: /* on 9070 */ l9070: if (!here(lamp)) goto l2011; spk=184; if (limit<0) goto l2011; prop[lamp]=1; rspeak(39); if (wzdark) goto l2000; goto l2012; case 8: /* off */ l9080: if (!here(lamp)) goto l2011; prop[lamp]=0; rspeak(40); if (dark()) rspeak(16); goto l2012; case 9: /* wave */ if ((!toting(obj))&&(obj!=rod||!toting(rod2))) spk=29; if (obj!=rod||!at(fissur)||!toting(obj)||closng) goto l2011; prop[fissur]=1-prop[fissur]; pspeak(fissur,2-prop[fissur]); goto l2012; case 10: case 11: case 18: /* calm, walk, quit */ case 24: case 25: case 26: /* score, foo, brief */ case 30: case 31: /* suspend, hours */ goto l2011; l9120: case 12: /* kill */ switch(trkill()) { case 8000: goto l8000; case 8: goto l8; case 2011: goto l2011; case 2608: goto l2608; case 19000: done(3); default: bug(112); } l9130: case 13: /* pour */ if (obj==bottle||obj==0) obj=liq(); if (obj==0) goto l8000; if (!toting(obj)) goto l2011; spk=78; if (obj!=oil&&obj!=water) goto l2011; prop[bottle]=1; place[obj]=0; spk=77; if (!(at(plant)||at(door))) goto l2011; if (at(door)) { prop[door]=0; /* 9132 */ if (obj==oil) prop[door]=1; spk=113+prop[door]; goto l2011; } spk=112; if (obj!=water) goto l2011; pspeak(plant,prop[plant]+1); prop[plant]=(prop[plant]+2)% 6; prop[plant2]=prop[plant]/2; k=null; goto l8; case 14: /* 9140 - eat */ if (obj==food) goto l8142; if (obj==bird||obj==snake||obj==clam||obj==oyster ||obj==dwarf||obj==dragon||obj==troll ||obj==bear) spk=71; goto l2011; l9150: case 15: /* 9150 - drink */ if (obj==0&&liqloc(loc)!=water&&(liq()!=water ||!here(bottle))) goto l8000; if (obj!=0&&obj!=water) spk=110; if (spk==110||liq()!=water||!here(bottle)) goto l2011; prop[bottle]=1; place[water]=0; spk=74; goto l2011; case 16: /* 9160: rub */ if (obj!=lamp) spk=76; goto l2011; case 17: /* 9170: throw */ switch(trtoss()) { case 2011: goto l2011; case 9020: goto l9020; case 9120: goto l9120; case 8: goto l8; case 9210: goto l9210; default: bug(113); } case 19: case 20: /* 9190: find, invent */ if (at(obj)||(liq()==obj&&at(bottle)) ||k==liqloc(loc)) spk=94; for (i=1; i<=5; i++) if (dloc[i]==loc&&dflag>=2&&obj==dwarf) spk=94; if (closed) spk=138; if (toting(obj)) spk=24; goto l2011; l9210: case 21: /* feed */ switch(trfeed()) { case 2011: goto l2011; default: bug(114); } l9220: case 22: /* fill */ switch(trfill()) { case 2011: goto l2011; case 8000: goto l8000; case 9020: goto l9020; default: bug(115); } l9230: case 23: /* blast */ if (prop[rod2]<0||!closed) goto l2011; bonus=133; if (loc==115) bonus=134; if (here(rod2)) bonus=135; rspeak(bonus); done(2); l9270: case 27: /* read */ if (dark()) goto l5190; if (obj==magzin) spk=190; if (obj==tablet) spk=196; if (obj==messag) spk=191; if (obj==oyster&&hinted[2]&&toting(oyster)) spk=194; if (obj!=oyster||hinted[2]||!toting(oyster) ||!closed) goto l2011; hinted[2]=yes(192,193,54); goto l2012; l9280: case 28: /* break */ if (obj==mirror) spk=148; if (obj==vase&&prop[vase]==0) { spk=198; if (toting(vase)) drop(vase,loc); prop[vase]=2; fixed[vase]= -1; goto l2011; } if (obj!=mirror||!closed) goto l2011; rspeak(197); done(3); l9290: case 29: /* wake */ if (obj!=dwarf||!closed) goto l2011; rspeak(199); done(3); default: bug(24); } l5000: obj=k; if (fixed[k]!=loc && !here(k)) goto l5100; l5010: if (*wd2!=0) goto l2800; if (verb!=0) goto l4090; printf("What do you want to do with the %s?\n",wd1); goto l2600; l5100: if (k!=grate) goto l5110; if (loc==1||loc==4||loc==7) k=dprssn; if (loc>9&&loc<15) k=entrnc; if (k!=grate) goto l8; l5110: if (k!=dwarf) goto l5120; for (i=1; i<=5; i++) if (dloc[i]==loc&&dflag>=2) goto l5010; l5120: if ((liq()==k&&here(bottle))||k==liqloc(loc)) goto l5010; if (obj!=plant||!at(plant2)||prop[plant2]==0) goto l5130; obj=plant2; goto l5010; l5130: if (obj!=knife||knfloc!=loc) goto l5140; knfloc = -1; spk=116; goto l2011; l5140: if (obj!=rod||!here(rod2)) goto l5190; obj=rod2; goto l5010; l5190: if ((verb==find||verb==invent)&&*wd2==0) goto l5010; printf("I see no %s here\n",wd1); goto l2012; } } diff --git a/games/adventure/subr.c b/games/adventure/subr.c index 24c4352214dd..ffac61a1b547 100644 --- a/games/adventure/subr.c +++ b/games/adventure/subr.c @@ -1,834 +1,834 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* Re-coding of advent in C: subroutines from main */ #include #include # include "hdr.h" /* Statement functions */ toting(objj) int objj; { if (place[objj] == -1) return(TRUE); else return(FALSE); } here(objj) int objj; { if (place[objj]==loc || toting(objj)) return(TRUE); else return(FALSE); } at(objj) int objj; { if (place[objj]==loc || fixed[objj]==loc) return(TRUE); else return (FALSE); } liq2(pbotl) int pbotl; { return((1-pbotl)*water+(pbotl/2)*(water+oil)); } liq() -{ register int i; +{ int i; i=prop[bottle]; if (i>-1-i) return(liq2(i)); else return(liq2(-1-i)); } liqloc(locc) /* may want to clean this one up a bit */ int locc; -{ register int i,j,l; +{ int i,j,l; i=cond[locc]/2; j=((i*2)%8)-5; l=cond[locc]/4; l=l%2; return(liq2(j*l+1)); } bitset(l,n) int l,n; { if (cond[l] & setbit[n]) return(TRUE); return(FALSE); } forced(locc) int locc; { if (cond[locc]==2) return(TRUE); return(FALSE); } dark() { if ((cond[loc]%2)==0 && (prop[lamp]==0 || !here(lamp))) return(TRUE); return(FALSE); } pct(n) int n; { if (ran(100)=15) dflag=1; return(2000); } if (dflag==1) /* 6000 */ { if (loc<15||pct(95)) return(2000); dflag=2; for (i=1; i<=2; i++) { j=1+ran(5); if (pct(50)&&saved== -1) dloc[j]=0; /* 6001 */ } for (i=1; i<=5; i++) { if (dloc[i]==loc) dloc[i]=daltlc; odloc[i]=dloc[i]; /* 6002 */ } rspeak(3); drop(axe,loc); return(2000); } dtotal=attack=stick=0; /* 6010 */ for (i=1; i<=6; i++) /* loop to 6030 */ { if (dloc[i]==0) continue; j=1; for (kk=travel[dloc[i]]; kk!=0; kk=kk->next) { newloc=kk->tloc; if (newloc>300||newloc<15||newloc==odloc[i] ||(j>1&&newloc==tk[j-1])||j>=20 ||newloc==dloc[i]||forced(newloc) ||(i==6&&bitset(newloc,3)) ||kk->conditions==100) continue; tk[j++]=newloc; } tk[j]=odloc[i]; /* 6016 */ if (j>=2) j--; j=1+ran(j); odloc[i]=dloc[i]; dloc[i]=tk[j]; dseen[i]=(dseen[i]&&loc>=15)||(dloc[i]==loc||odloc[i]==loc); if (!dseen[i]) continue; /* i.e. goto 6030 */ dloc[i]=loc; if (i==6) /* pirate's spotted him */ { if (loc==chloc||prop[chest]>=0) continue; k=0; for (j=50; j<=maxtrs; j++) /* loop to 6020 */ { if (j==pyram&&(loc==plac[pyram] || loc==plac[emrald])) goto l6020; if (toting(j)) goto l6022; l6020: if (here(j)) k=1; } /* 6020 */ if (tally==tally2+1 && k==0 && place[chest]==0 &&here(lamp) && prop[lamp]==1) goto l6025; if (odloc[6]!=dloc[6]&&pct(20)) rspeak(127); continue; /* to 6030 */ l6022: rspeak(128); if (place[messag]==0) move(chest,chloc); move(messag,chloc2); for (j=50; j<=maxtrs; j++) /* loop to 6023 */ { if (j==pyram && (loc==plac[pyram] || loc==plac[emrald])) continue; if (at(j)&&fixed[j]==0) carry(j,loc); if (toting(j)) drop(j,chloc); } l6024: dloc[6]=odloc[6]=chloc; dseen[6]=FALSE; continue; l6025: rspeak(186); move(chest,chloc); move(messag,chloc2); goto l6024; } dtotal++; /* 6027 */ if (odloc[i]!=dloc[i]) continue; attack++; if (knfloc>=0) knfloc=loc; if (ran(1000)<95*(dflag-2)) stick++; } /* 6030 */ if (dtotal==0) return(2000); if (dtotal!=1) { printf("There are %d threatening little dwarves ",dtotal); printf("in the room with you.\n"); } else rspeak(4); if (attack==0) return(2000); if (dflag==2) dflag=3; if (saved!= -1) dflag=20; if (attack!=1) { printf("%d of them throw knives at you!\n",attack); k=6; l82: if (stick<=1) /* 82 */ { rspeak(k+stick); if (stick==0) return(2000); } else printf("%d of them get you!\n",stick); /* 83 */ oldlc2=loc; return(99); } rspeak(5); k=52; goto l82; } march() /* label 8 */ -{ register int ll1,ll2; +{ int ll1,ll2; if ((tkk=travel[newloc=loc])==0) bug(26); if (k==null) return(2); if (k==cave) /* 40 */ { if (loc<8) rspeak(57); if (loc>=8) rspeak(58); return(2); } if (k==look) /* 30 */ { if (detail++<3) rspeak(15); wzdark=FALSE; abb[loc]=0; return(2); } if (k==back) /* 20 */ { switch(mback()) { case 2: return(2); case 9: goto l9; default: bug(100); } } oldlc2=oldloc; oldloc=loc; l9: for (; tkk!=0; tkk=tkk->next) if (tkk->tverb==1 || tkk->tverb==k) break; if (tkk==0) { badmove(); return(2); } l11: ll1=tkk->conditions; /* 11 */ ll2=tkk->tloc; newloc=ll1; /* newloc=conditions */ k=newloc%100; /* k used for prob */ if (newloc<=300) { if (newloc<=100) /* 13 */ { if (newloc!=0&&!pct(newloc)) goto l12; /* 14 */ l16: newloc=ll2; /* newloc=location */ if (newloc<=300) return(2); if (newloc<=500) switch(specials())/* to 30000 */ { case 2: return(2); case 12: goto l12; case 99: return(99); default: bug(101); } rspeak(newloc-500); newloc=loc; return(2); } if (toting(k)||(newloc>200&&at(k))) goto l16; goto l12; } if (prop[k]!=(newloc/100)-3) goto l16; /* newloc still conditions*/ l12: /* alternative to probability move */ for (; tkk!=0; tkk=tkk->next) if (tkk->tloc!=ll2 || tkk->conditions!=ll1) break; if (tkk==0) bug(25); goto l11; } mback() /* 20 */ -{ register struct travlist *tk2,*j; - register int ll; +{ struct travlist *tk2,*j; + int ll; if (forced(k=oldloc)) k=oldlc2; /* k=location */ oldlc2=oldloc; oldloc=loc; tk2=0; if (k==loc) { rspeak(91); return(2); } for (; tkk!=0; tkk=tkk->next) /* 21 */ { ll=tkk->tloc; if (ll==k) { k=tkk->tverb; /* k back to verb */ tkk=travel[loc]; return(9); } if (ll<=300) { j=travel[loc]; if (forced(ll) && k==j->tloc) tk2=tkk; } } tkk=tk2; /* 23 */ if (tkk!=0) { k=tkk->tverb; tkk=travel[loc]; return(9); } rspeak(140); return(2); } specials() /* 30000 */ { switch(newloc -= 300) { case 1: /* 30100 */ newloc = 99+100-loc; if (holdng==0||(holdng==1&&toting(emrald))) return(2); newloc=loc; rspeak(117); return(2); case 2: /* 30200 */ drop(emrald,loc); return(12); case 3: /* to 30300 */ return(trbridge()); default: bug(29); } } trbridge() /* 30300 */ { if (prop[troll]==1) { pspeak(troll,1); prop[troll]=0; move(troll2,0); move(troll2+100,0); move(troll,plac[troll]); move(troll+100,fixd[troll]); juggle(chasm); newloc=loc; return(2); } newloc=plac[troll]+fixd[troll]-loc; /* 30310 */ if (prop[troll]==0) prop[troll]=1; if (!toting(bear)) return(2); rspeak(162); prop[chasm]=1; prop[troll]=2; drop(bear,newloc); fixed[bear] = -1; prop[bear]=3; if (prop[spices]<0) tally2++; oldlc2=newloc; return(99); } int badmove() /* 20 */ { spk=12; if (k>=43 && k<=50) spk=9; if (k==29||k==30) spk=9; if (k==7||k==36||k==37) spk=10; if (k==11||k==19) spk=11; if (verb==find||verb==invent) spk=59; if (k==62||k==65) spk=42; if (k==17) spk=80; rspeak(spk); } int bug(n) int n; { printf("Please tell jim@rand.org that fatal bug %d happened.\n",n); exit(1); } void checkhints() /* 2600 &c */ -{ register int hint; +{ int hint; for (hint=4; hint<=hntmax; hint++) { if (hinted[hint]) continue; if (!bitset(loc,hint)) hintlc[hint]= -1; hintlc[hint]++; if (hintlc[hint]1) goto l40010; goto l40020; case 8: /* 40800 */ if (prop[emrald]!= -1&&prop[pyram]== -1) goto l40010; goto l40020; case 9: goto l40010; /* 40900 */ default: bug(27); } l40010: hintlc[hint]=0; if (!yes(hints[hint][3],0,54)) continue; printf("I am prepared to give you a hint, but it will "); printf("cost you %d points.\n",hints[hint][2]); hinted[hint]=yes(175,hints[hint][4],54); l40020: hintlc[hint]=0; } } trsay() /* 9030 */ -{ register int i; +{ int i; if (*wd2!=0) strcpy(wd1,wd2); i=vocab(wd1,-1); if (i==62||i==65||i==71||i==2025) { *wd2=0; obj=0; return(2630); } printf("\nOkay, \"%s\".\n",wd2); return(2012); } trtake() /* 9010 */ -{ register int i; +{ int i; if (toting(obj)) return(2011); /* 9010 */ spk=25; if (obj==plant&&prop[plant]<=0) spk=115; if (obj==bear&&prop[bear]==1) spk=169; if (obj==chain&&prop[bear]!=0) spk=170; if (fixed[obj]!=0) return(2011); if (obj==water||obj==oil) { if (here(bottle)&&liq()==obj) { obj=bottle; goto l9017; } obj=bottle; if (toting(bottle)&&prop[bottle]==1) return(9220); if (prop[bottle]!=1) spk=105; if (!toting(bottle)) spk=104; return(2011); } l9017: if (holdng>=7) { rspeak(92); return(2012); } if (obj==bird) { if (prop[bird]!=0) goto l9014; if (toting(rod)) { rspeak(26); return(2012); } if (!toting(cage)) /* 9013 */ { rspeak(27); return(2012); } prop[bird]=1; /* 9015 */ } l9014: if ((obj==bird||obj==cage)&&prop[bird]!=0) carry(bird+cage-obj,loc); carry(obj,loc); k=liq(); if (obj==bottle && k!=0) place[k] = -1; return(2009); } dropper() /* 9021 */ { k=liq(); if (k==obj) obj=bottle; if (obj==bottle&&k!=0) place[k]=0; if (obj==cage&&prop[bird]!=0) drop(bird,loc); if (obj==bird) prop[bird]=0; drop(obj,loc); return(2012); } trdrop() /* 9020 */ { if (toting(rod2)&&obj==rod&&!toting(rod)) obj=rod2; if (!toting(obj)) return(2011); if (obj==bird&&here(snake)) { rspeak(30); if (closed) return(19000); dstroy(snake); prop[snake]=1; return(dropper()); } if (obj==coins&&here(vend)) /* 9024 */ { dstroy(coins); drop(batter,loc); pspeak(batter,0); return(2012); } if (obj==bird&&at(dragon)&&prop[dragon]==0) /* 9025 */ { rspeak(154); dstroy(bird); prop[bird]=0; if (place[snake]==plac[snake]) tally2--; return(2012); } if (obj==bear&&at(troll)) /* 9026 */ { rspeak(163); move(troll,0); move(troll+100,0); move(troll2,plac[troll]); move(troll2+100,fixd[troll]); juggle(chasm); prop[troll]=2; return(dropper()); } if (obj!=vase||loc==plac[pillow]) /* 9027 */ { rspeak(54); return(dropper()); } prop[vase]=2; /* 9028 */ if (at(pillow)) prop[vase]=0; pspeak(vase,prop[vase]+1); if (prop[vase]!=0) fixed[vase] = -1; return(dropper()); } tropen() /* 9040 */ { if (obj==clam||obj==oyster) { k=0; /* 9046 */ if (obj==oyster) k=1; spk=124+k; if (toting(obj)) spk=120+k; if (!toting(tridnt)) spk=122+k; if (verb==lock) spk=61; if (spk!=124) return(2011); dstroy(clam); drop(oyster,loc); drop(pearl,105); return(2011); } if (obj==door) spk=111; if (obj==door&&prop[door]==1) spk=54; if (obj==cage) spk=32; if (obj==keys) spk=55; if (obj==grate||obj==chain) spk=31; if (spk!=31||!here(keys)) return(2011); if (obj==chain) { if (verb==lock) { spk=172; /* 9049: lock */ if (prop[chain]!=0) spk=34; if (loc!=plac[chain]) spk=173; if (spk!=172) return(2011); prop[chain]=2; if (toting(chain)) drop(chain,loc); fixed[chain]= -1; return(2011); } spk=171; if (prop[bear]==0) spk=41; if (prop[chain]==0) spk=37; if (spk!=171) return(2011); prop[chain]=0; fixed[chain]=0; if (prop[bear]!=3) prop[bear]=2; fixed[bear]=2-prop[bear]; return(2011); } if (closng) { k=130; if (!panic) clock2=15; panic=TRUE; return(2010); } k=34+prop[grate]; /* 9043 */ prop[grate]=1; if (verb==lock) prop[grate]=0; k=k+2*prop[grate]; return(2010); } trkill() /* 9120 */ -{ register int i; +{ int i; for (i=1; i<=5; i++) if (dloc[i]==loc&&dflag>=2) break; if (i==6) i=0; if (obj==0) /* 9122 */ { if (i!=0) obj=dwarf; if (here(snake)) obj=obj*100+snake; if (at(dragon)&&prop[dragon]==0) obj=obj*100+dragon; if (at(troll)) obj=obj*100+troll; if (here(bear)&&prop[bear]==0) obj=obj*100+bear; if (obj>100) return(8000); if (obj==0) { if (here(bird)&&verb!=throw) obj=bird; if (here(clam)||here(oyster)) obj=100*obj+clam; if (obj>100) return(8000); } } if (obj==bird) /* 9124 */ { spk=137; if (closed) return(2011); dstroy(bird); prop[bird]=0; if (place[snake]==plac[snake]) tally2++; spk=45; } if (obj==0) spk=44; /* 9125 */ if (obj==clam||obj==oyster) spk=150; if (obj==snake) spk=46; if (obj==dwarf) spk=49; if (obj==dwarf&&closed) return(19000); if (obj==dragon) spk=147; if (obj==troll) spk=157; if (obj==bear) spk=165+(prop[bear]+1)/2; if (obj!=dragon||prop[dragon]!=0) return(2011); rspeak(49); verb=0; obj=0; getin(&wd1,&wd2); if (strncmp(wd1,"y",1)&&strncmp(wd1,"yes",3)) return(2608); pspeak(dragon,1); prop[dragon]=2; prop[rug]=0; k=(plac[dragon]+fixd[dragon])/2; move(dragon+100,-1); move(rug+100,0); move(dragon,k); move(rug,k); for (obj=1; obj<=100; obj++) if (place[obj]==plac[dragon]||place[obj]==fixd[dragon]) move(obj,k); loc=k; k=null; return(8); } trtoss() /* 9170: throw */ -{ register int i; +{ int i; if (toting(rod2)&&obj==rod&&!toting(rod)) obj=rod2; if (!toting(obj)) return(2011); if (obj>=50&&obj<=maxtrs&&at(troll)) { spk=159; /* 9178 */ drop(obj,0); move(troll,0); move(troll+100,0); drop(troll2,plac[troll]); drop(troll2+100,fixd[troll]); juggle(chasm); return(2011); } if (obj==food&&here(bear)) { obj=bear; /* 9177 */ return(9210); } if (obj!=axe) return(9020); for (i=1; i<=5; i++) { if (dloc[i]==loc) { spk=48; /* 9172 */ if (ran(3)==0||saved!= -1) l9175: { rspeak(spk); drop(axe,loc); k=null; return(8); } dseen[i]=FALSE; dloc[i]=0; spk=47; dkill++; if (dkill==1) spk=149; goto l9175; } } spk=152; if (at(dragon)&&prop[dragon]==0) goto l9175; spk=158; if (at(troll)) goto l9175; if (here(bear)&&prop[bear]==0) { spk=164; drop(axe,loc); fixed[axe]= -1; prop[axe]=1; juggle(bear); return(2011); } obj=0; return(9120); } trfeed() /* 9210 */ { if (obj==bird) { spk=100; return(2011); } if (obj==snake||obj==dragon||obj==troll) { spk=102; if (obj==dragon&&prop[dragon]!=0) spk=110; if (obj==troll) spk=182; if (obj!=snake||closed||!here(bird)) return(2011); spk=101; dstroy(bird); prop[bird]=0; tally2++; return(2011); } if (obj==dwarf) { if (!here(food)) return(2011); spk=103; dflag++; return(2011); } if (obj==bear) { if (prop[bear]==0) spk=102; if (prop[bear]==3) spk=110; if (!here(food)) return(2011); dstroy(food); prop[bear]=1; fixed[axe]=0; prop[axe]=0; spk=168; return(2011); } spk=14; return(2011); } trfill() /* 9220 */ { if (obj==vase) { spk=29; if (liqloc(loc)==0) spk=144; if (liqloc(loc)==0||!toting(vase)) return(2011); rspeak(145); prop[vase]=2; fixed[vase]= -1; return(9020); /* advent/10 goes to 9024 */ } if (obj!=0&&obj!=bottle) return(2011); if (obj==0&&!here(bottle)) return(8000); spk=107; if (liqloc(loc)==0) spk=106; if (liq()!=0) spk=105; if (spk!=107) return(2011); prop[bottle]=((cond[loc]%4)/2)*2; k=liq(); if (toting(bottle)) place[k]= -1; if (k==oil) spk=108; return(2011); } void closing() /* 10000 */ -{ register int i; +{ int i; prop[grate]=prop[fissur]=0; for (i=1; i<=6; i++) { dseen[i]=FALSE; dloc[i]=0; } move(troll,0); move(troll+100,0); move(troll2,plac[troll]); move(troll2+100,fixd[troll]); juggle(chasm); if(prop[bear]!=3) dstroy(bear); prop[chain]=0; fixed[chain]=0; prop[axe]=0; fixed[axe]=0; rspeak(129); clock1 = -1; closng=TRUE; } void caveclose() /* 11000 */ -{ register int i; +{ int i; prop[bottle]=put(bottle,115,1); prop[plant]=put(plant,115,0); prop[oyster]=put(oyster,115,0); prop[lamp]=put(lamp,115,0); prop[rod]=put(rod,115,0); prop[dwarf]=put(dwarf,115,0); loc=115; oldloc=115; newloc=115; put(grate,116,0); prop[snake]=put(snake,116,1); prop[bird]=put(bird,116,1); prop[cage]=put(cage,116,0); prop[rod2]=put(rod2,116,0); prop[pillow]=put(pillow,116,0); prop[mirror]=put(mirror,115,0); fixed[mirror]=116; for (i=1; i<=100; i++) if (toting(i)) dstroy(i); rspeak(132); closed=TRUE; } diff --git a/games/adventure/vocab.c b/games/adventure/vocab.c index 70eefa40fe58..84d558b45e0b 100644 --- a/games/adventure/vocab.c +++ b/games/adventure/vocab.c @@ -1,197 +1,197 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* Re-coding of advent in C: data structure routines */ #include #include #include #include "hdr.h" dstroy(object) int object; { move(object,0); } juggle(object) int object; -{ register int i,j; +{ int i,j; i=place[object]; j=fixed[object]; move(object,i); move(object+100,j); } move(object,where) int object,where; -{ register int from; +{ int from; if (object<=100) from=place[object]; else from=fixed[object-100]; if (from>0 && from<=300) carry(object,from); drop(object,where); } put(object,where,pval) int object,where,pval; { move(object,where); return(-1-pval); } carry(object,where) int object,where; -{ register int temp; +{ int temp; if (object<=100) { if (place[object]== -1) return; place[object] = -1; holdng++; } if (atloc[where]==object) { atloc[where]=linkx[object]; return; } for (temp=atloc[where]; linkx[temp]!=object; temp=linkx[temp]); linkx[temp]=linkx[object]; } drop(object,where) int object,where; { if (object>100) fixed[object-100]=where; else { if (place[object]== -1) holdng--; place[object]=where; } if (where<=0) return; linkx[object]=atloc[where]; atloc[where]=object; } vocab(word,type,value) /* look up or store a word */ const char *word; int type; /* -2 for store, -1 for user word, >=0 for canned lookup*/ int value; /* used for storing only */ -{ register int adr; +{ int adr; const char *s; - register char *t; + char *t; int hash, i; struct hashtab *h; for (hash=0,s=word,i=0; i<5 &&*s; i++) /* some kind of hash */ hash += *s++; /* add all chars in the word */ hash = (hash*3719)&077777; /* pulled that one out of a hat */ hash %= HTSIZE; /* put it into range of table */ for(adr=hash;; adr++) /* look for entry in table */ { if (adr==HTSIZE) adr=0; /* wrap around */ h = &voc[adr]; /* point at the entry */ switch(type) { case -2: /* fill in entry */ if (h->val) /* already got an entry? */ goto exitloop2; h->val=value; h->atab=malloc(strlen(word)+1); if (h->atab == NULL) errx(1, "Out of memory!"); for (s=word,t=h->atab; *s;) *t++ = *s++ ^ '='; *t=0^'='; /* encrypt slightly to thwart core reader */ /* printf("Stored \"%s\" (%d ch) as entry %d\n", */ /* word, strlen(word)+1, adr); */ return(0); /* entry unused */ case -1: /* looking up user word */ if (h->val==0) return(-1); /* not found */ for (s=word, t=h->atab;*t ^ '=';) if ((*s++ ^ '=') != *t++) goto exitloop2; if ((*s ^ '=') != *t && s-word<5) goto exitloop2; /* the word matched o.k. */ return(h->val); default: /* looking up known word */ if (h->val==0) { errx(1, "Unable to find %s in vocab", word); } for (s=word, t=h->atab;*t ^ '=';) if ((*s++ ^ '=') != *t++) goto exitloop2; /* the word matched o.k. */ if (h->val/1000 != type) continue; return(h->val%1000); } exitloop2: /* hashed entry does not match */ if (adr+1==hash || (adr==HTSIZE && hash==0)) { errx(1, "Hash table overflow"); } } } prht() /* print hash table */ -{ register int i,j,l; +{ int i,j,l; char *c; struct hashtab *h; for (i=0; i=HTSIZE) break; h= &voc[i*10+j]; putchar(' '); if (h->val==0) { printf("-----"); continue; } for (l=0, c=h->atab; l<5; l++) if ((*c ^ '=')) putchar(*c++ ^ '='); else putchar(' '); } putchar('\n'); } } diff --git a/games/adventure/wizard.c b/games/adventure/wizard.c index eff6d5f18396..b02c9004bc31 100644 --- a/games/adventure/wizard.c +++ b/games/adventure/wizard.c @@ -1,149 +1,149 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * The game adventure was originally written in Fortran by Will Crowther * and Don Woods. It was later translated to C and enhanced by Jim * Gillogly. This code is derived from software contributed to Berkeley * by Jim Gillogly at The Rand Corporation. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 6/2/93"; #endif /* not lint */ /* Re-coding of advent in C: privileged operations */ #include #include #include #include #include # include "hdr.h" datime(d,t) int *d,*t; { struct tm *tptr; time_t tvec; time(&tvec); tptr=localtime(&tvec); /* day since 1977 */ *d = (tptr->tm_yday + 365 * (tptr->tm_year - 77) + (tptr->tm_year - 77) / 4 - (tptr->tm_year - 1) / 100 + (tptr->tm_year + 299) / 400); /* bug: this will overflow in the year 2066 AD (with 16 bit int) */ /* it will be attributed to Wm the C's millenial celebration */ /* and minutes since midnite */ *t=tptr->tm_hour*60+tptr->tm_min; } char magic[6]; poof() { strcpy(magic, DECR(d,w,a,r,f)); latncy = 45; } Start() { int d,t,delay; datime(&d,&t); delay=(d-saved)*1440+(t-savet); /* good for about a month */ if (delay >= latncy) { saved = -1; return(FALSE); } printf("This adventure was suspended a mere %d minute%s ago.", delay, delay == 1? "" : "s"); if (delay <= latncy/3) { mspeak(2); exit(0); } mspeak(8); if (!wizard()) { mspeak(9); exit(0); } saved = -1; return(FALSE); } wizard() /* not as complex as advent/10 (for now) */ -{ register int wiz; +{ int wiz; char *word,*x; if (!yesm(16,0,7)) return(FALSE); mspeak(17); getin(&word,&x); if (strncmp(word,magic,5)) { mspeak(20); return(FALSE); } mspeak(19); return(TRUE); } ciao() -{ register char *c; - register int outfd, size; +{ char *c; + int outfd, size; char fname[80], buf[512]; extern unsigned filesize; printf("What would you like to call the saved version?\n"); /* XXX - should use fgetln to avoid arbitrary limit */ for (c = fname; c < fname + sizeof fname - 1; c++) { int ch; ch = getchar(); if (ch == '\n' || ch == EOF) break; *c = ch; } *c=0; if (save(fname) != 0) return; /* Save failed */ printf("To resume, say \"adventure %s\".\n", fname); printf("\"With these rooms I might now have been familiarly acquainted.\"\n"); exit(0); } ran(range) int range; { int i; i = random() % range; return(i); } diff --git a/games/arithmetic/arithmetic.c b/games/arithmetic/arithmetic.c index d7d8b95c11b1..4e8efef9d566 100644 --- a/games/arithmetic/arithmetic.c +++ b/games/arithmetic/arithmetic.c @@ -1,379 +1,379 @@ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Eamonn McManus of Trinity College Dublin. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)arithmetic.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* * By Eamonn McManus, Trinity College Dublin . * * The operation of this program mimics that of the standard Unix game * `arithmetic'. I've made it as close as I could manage without examining * the source code. The principal differences are: * * The method of biasing towards numbers that had wrong answers in the past * is different; original `arithmetic' seems to retain the bias forever, * whereas this program lets the bias gradually decay as it is used. * * Original `arithmetic' delays for some period (3 seconds?) after printing * the score. I saw no reason for this delay, so I scrapped it. * * There is no longer a limitation on the maximum range that can be supplied * to the program. The original program required it to be less than 100. * Anomalous results may occur with this program if ranges big enough to * allow overflow are given. * * I have obviously not attempted to duplicate bugs in the original. It * would go into an infinite loop if invoked as `arithmetic / 0'. It also * did not recognise an EOF in its input, and would continue trying to read * after it. It did not check that the input was a valid number, treating any * garbage as 0. Finally, it did not flush stdout after printing its prompt, * so in the unlikely event that stdout was not a terminal, it would not work * properly. */ #include #include #include #include #include #include const char keylist[] = "+-x/"; const char defaultkeys[] = "+-"; const char *keys = defaultkeys; int nkeys = sizeof(defaultkeys) - 1; int rangemax = 10; int nright, nwrong; time_t qtime; #define NQUESTS 20 /* * Select keys from +-x/ to be asked addition, subtraction, multiplication, * and division problems. More than one key may be given. The default is * +-. Specify a range to confine the operands to 0 - range. Default upper * bound is 10. After every NQUESTS questions, statistics on the performance * so far are printed. */ int main(argc, argv) int argc; char **argv; { extern char *optarg; extern int optind; int ch, cnt; void intr(); /* Revoke setgid privileges */ setgid(getgid()); while ((ch = getopt(argc, argv, "r:o:")) != -1) switch(ch) { case 'o': { - register const char *p; + const char *p; for (p = keys = optarg; *p; ++p) if (!index(keylist, *p)) { (void)fprintf(stderr, "arithmetic: unknown key.\n"); exit(1); } nkeys = p - optarg; break; } case 'r': if ((rangemax = atoi(optarg)) <= 0) { (void)fprintf(stderr, "arithmetic: invalid range.\n"); exit(1); } break; case '?': default: usage(); } if (argc -= optind) usage(); /* Seed the random-number generator. */ srandomdev(); (void)signal(SIGINT, intr); /* Now ask the questions. */ for (;;) { for (cnt = NQUESTS; cnt--;) if (problem() == EOF) exit(0); showstats(); } /* NOTREACHED */ } /* Handle interrupt character. Print score and exit. */ void intr() { showstats(); exit(0); } /* Print score. Original `arithmetic' had a delay after printing it. */ showstats() { if (nright + nwrong > 0) { (void)printf("\n\nRights %d; Wrongs %d; Score %d%%", nright, nwrong, (int)(100L * nright / (nright + nwrong))); if (nright > 0) (void)printf("\nTotal time %ld seconds; %.1f seconds per problem\n\n", (long)qtime, (float)qtime / nright); } (void)printf("\n"); } /* * Pick a problem and ask it. Keeps asking the same problem until supplied * with the correct answer, or until EOF or interrupt is typed. Problems are * selected such that the right operand and either the left operand (for +, x) * or the correct result (for -, /) are in the range 0 to rangemax. Each wrong * answer causes the numbers in the problem to be penalised, so that they are * more likely to appear in subsequent problems. */ problem() { - register char *p; + char *p; time_t start, finish; int left, op, right, result; char line[80]; op = keys[random() % nkeys]; if (op != '/') right = getrandom(rangemax + 1, op, 1); retry: /* Get the operands. */ switch (op) { case '+': left = getrandom(rangemax + 1, op, 0); result = left + right; break; case '-': result = getrandom(rangemax + 1, op, 0); left = right + result; break; case 'x': left = getrandom(rangemax + 1, op, 0); result = left * right; break; case '/': right = getrandom(rangemax, op, 1) + 1; result = getrandom(rangemax + 1, op, 0); left = right * result + random() % right; break; } /* * A very big maxrange could cause negative values to pop * up, owing to overflow. */ if (result < 0 || left < 0) goto retry; (void)printf("%d %c %d = ", left, op, right); (void)fflush(stdout); (void)time(&start); /* * Keep looping until the correct answer is given, or until EOF or * interrupt is typed. */ for (;;) { if (!fgets(line, sizeof(line), stdin)) { (void)printf("\n"); return(EOF); } for (p = line; *p && isspace(*p); ++p); if (!isdigit(*p)) { (void)printf("Please type a number.\n"); continue; } if (atoi(p) == result) { (void)printf("Right!\n"); ++nright; break; } /* Wrong answer; penalise and ask again. */ (void)printf("What?\n"); ++nwrong; penalise(right, op, 1); if (op == 'x' || op == '+') penalise(left, op, 0); else penalise(result, op, 0); } /* * Accumulate the time taken. Obviously rounding errors happen here; * however they should cancel out, because some of the time you are * charged for a partially elapsed second at the start, and some of * the time you are not charged for a partially elapsed second at the * end. */ (void)time(&finish); qtime += finish - start; return(0); } /* * Here is the code for accumulating penalties against the numbers for which * a wrong answer was given. The right operand and either the left operand * (for +, x) or the result (for -, /) are stored in a list for the particular * operation, and each becomes more likely to appear again in that operation. * Initially, each number is charged a penalty of WRONGPENALTY, giving it that * many extra chances of appearing. Each time it is selected because of this, * its penalty is decreased by one; it is removed when it reaches 0. * * The penalty[] array gives the sum of all penalties in the list for * each operation and each operand. The penlist[] array has the lists of * penalties themselves. */ int penalty[sizeof(keylist) - 1][2]; struct penalty { int value, penalty; /* Penalised value and its penalty. */ struct penalty *next; } *penlist[sizeof(keylist) - 1][2]; #define WRONGPENALTY 5 /* Perhaps this should depend on maxrange. */ /* * Add a penalty for the number `value' to the list for operation `op', * operand number `operand' (0 or 1). If we run out of memory, we just * forget about the penalty (how likely is this, anyway?). */ penalise(value, op, operand) int value, op, operand; { struct penalty *p; op = opnum(op); if ((p = (struct penalty *)malloc((u_int)sizeof(*p))) == NULL) return; p->next = penlist[op][operand]; penlist[op][operand] = p; penalty[op][operand] += p->penalty = WRONGPENALTY; p->value = value; } /* * Select a random value from 0 to maxval - 1 for operand `operand' (0 or 1) * of operation `op'. The random number we generate is either used directly * as a value, or represents a position in the penalty list. If the latter, * we find the corresponding value and return that, decreasing its penalty. */ getrandom(maxval, op, operand) int maxval, op, operand; { int value; - register struct penalty **pp, *p; + struct penalty **pp, *p; op = opnum(op); value = random() % (maxval + penalty[op][operand]); /* * 0 to maxval - 1 is a number to be used directly; bigger values * are positions to be located in the penalty list. */ if (value < maxval) return(value); value -= maxval; /* * Find the penalty at position `value'; decrement its penalty and * delete it if it reaches 0; return the corresponding value. */ for (pp = &penlist[op][operand]; (p = *pp) != NULL; pp = &p->next) { if (p->penalty > value) { value = p->value; penalty[op][operand]--; if (--(p->penalty) <= 0) { p = p->next; (void)free((char *)*pp); *pp = p; } return(value); } value -= p->penalty; } /* * We can only get here if the value from the penalty[] array doesn't * correspond to the actual sum of penalties in the list. Provide an * obscure message. */ (void)fprintf(stderr, "arithmetic: bug: inconsistent penalties\n"); exit(1); /* NOTREACHED */ } /* Return an index for the character op, which is one of [+-x/]. */ opnum(op) int op; { char *p; if (op == 0 || (p = index(keylist, op)) == NULL) { (void)fprintf(stderr, "arithmetic: bug: op %c not in keylist %s\n", op, keylist); exit(1); } return(p - keylist); } /* Print usage message and quit. */ usage() { (void)fprintf(stderr, "usage: arithmetic [-o +-x/] [-r range]\n"); exit(1); } diff --git a/games/atc/graphics.c b/games/atc/graphics.c index 36ee49f96f05..91aa975bec3f 100644 --- a/games/atc/graphics.c +++ b/games/atc/graphics.c @@ -1,423 +1,423 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ed James. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ /* * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. * * Copy permission is hereby granted provided that this notice is * retained on all partial or complete copies. * * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ #ifndef lint static char sccsid[] = "@(#)graphics.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include "include.h" #ifdef SYSV #include #endif #define C_TOPBOTTOM '-' #define C_LEFTRIGHT '|' #define C_AIRPORT '=' #define C_LINE '+' #define C_BACKROUND '.' #define C_BEACON '*' #define C_CREDIT '*' WINDOW *radar, *cleanradar, *credit, *input, *planes; getAChar() { #ifdef BSD return (getchar()); #endif #ifdef SYSV int c; while ((c = getchar()) == -1 && errno == EINTR) ; return(c); #endif } erase_all() { PLANE *pp; for (pp = air.head; pp != NULL; pp = pp->next) { wmove(cleanradar, pp->ypos, pp->xpos * 2); wmove(radar, pp->ypos, pp->xpos * 2); waddch(radar, winch(cleanradar)); wmove(cleanradar, pp->ypos, pp->xpos * 2 + 1); wmove(radar, pp->ypos, pp->xpos * 2 + 1); waddch(radar, winch(cleanradar)); } } draw_all() { PLANE *pp; for (pp = air.head; pp != NULL; pp = pp->next) { if (pp->status == S_MARKED) wstandout(radar); wmove(radar, pp->ypos, pp->xpos * 2); waddch(radar, name(pp)); waddch(radar, '0' + pp->altitude); if (pp->status == S_MARKED) wstandend(radar); } wrefresh(radar); planewin(); wrefresh(input); /* return cursor */ fflush(stdout); } init_gr() { static char buffer[BUFSIZ]; initscr(); setbuf(stdout, buffer); input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0); credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES, COLS - PLANE_COLS); planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS); } setup_screen(scp) const C_SCREEN *scp; { - register int i, j; + int i, j; char str[3]; const char *airstr; str[2] = '\0'; if (radar != NULL) delwin(radar); radar = newwin(scp->height, scp->width * 2, 0, 0); if (cleanradar != NULL) delwin(cleanradar); cleanradar = newwin(scp->height, scp->width * 2, 0, 0); /* minus one here to prevent a scroll */ for (i = 0; i < PLANE_COLS - 1; i++) { wmove(credit, 0, i); waddch(credit, C_CREDIT); wmove(credit, INPUT_LINES - 1, i); waddch(credit, C_CREDIT); } wmove(credit, INPUT_LINES / 2, 1); waddstr(credit, AUTHOR_STR); for (i = 1; i < scp->height - 1; i++) { for (j = 1; j < scp->width - 1; j++) { wmove(radar, i, j * 2); waddch(radar, C_BACKROUND); } } /* * Draw the lines first, since people like to draw lines * through beacons and exit points. */ str[0] = C_LINE; for (i = 0; i < scp->num_lines; i++) { str[1] = ' '; draw_line(radar, scp->line[i].p1.x, scp->line[i].p1.y, scp->line[i].p2.x, scp->line[i].p2.y, str); } str[0] = C_TOPBOTTOM; str[1] = C_TOPBOTTOM; wmove(radar, 0, 0); for (i = 0; i < scp->width - 1; i++) waddstr(radar, str); waddch(radar, C_TOPBOTTOM); str[0] = C_TOPBOTTOM; str[1] = C_TOPBOTTOM; wmove(radar, scp->height - 1, 0); for (i = 0; i < scp->width - 1; i++) waddstr(radar, str); waddch(radar, C_TOPBOTTOM); for (i = 1; i < scp->height - 1; i++) { wmove(radar, i, 0); waddch(radar, C_LEFTRIGHT); wmove(radar, i, (scp->width - 1) * 2); waddch(radar, C_LEFTRIGHT); } str[0] = C_BEACON; for (i = 0; i < scp->num_beacons; i++) { str[1] = '0' + i; wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2); waddstr(radar, str); } for (i = 0; i < scp->num_exits; i++) { wmove(radar, scp->exit[i].y, scp->exit[i].x * 2); waddch(radar, '0' + i); } airstr = "^?>?v?num_airports; i++) { str[0] = airstr[scp->airport[i].dir]; str[1] = '0' + i; wmove(radar, scp->airport[i].y, scp->airport[i].x * 2); waddstr(radar, str); } overwrite(radar, cleanradar); wrefresh(radar); wrefresh(credit); fflush(stdout); } draw_line(w, x, y, lx, ly, s) WINDOW *w; int x, y, lx, ly; const char *s; { int dx, dy; dx = SGN(lx - x); dy = SGN(ly - y); for (;;) { wmove(w, y, x * 2); waddstr(w, s); if (x == lx && y == ly) break; x += dx; y += dy; } } ioclrtoeol(pos) { wmove(input, 0, pos); wclrtoeol(input); wrefresh(input); fflush(stdout); } iomove(pos) { wmove(input, 0, pos); wrefresh(input); fflush(stdout); } ioaddstr(pos, str) const char *str; { wmove(input, 0, pos); waddstr(input, str); wrefresh(input); fflush(stdout); } ioclrtobot() { wclrtobot(input); wrefresh(input); fflush(stdout); } ioerror(pos, len, str) const char *str; { int i; wmove(input, 1, pos); for (i = 0; i < len; i++) waddch(input, '^'); wmove(input, 2, 0); waddstr(input, str); wrefresh(input); fflush(stdout); } quit() { int c, y, x; #ifdef BSD struct itimerval itv; #endif getyx(input, y, x); wmove(input, 2, 0); waddstr(input, "Really quit? (y/n) "); wclrtobot(input); wrefresh(input); fflush(stdout); c = getchar(); if (c == EOF || c == 'y') { /* disable timer */ #ifdef BSD itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itv, NULL); #endif #ifdef SYSV alarm(0); #endif fflush(stdout); clear(); refresh(); endwin(); log_score(0); exit(0); } wmove(input, 2, 0); wclrtobot(input); wmove(input, y, x); wrefresh(input); fflush(stdout); return; } planewin() { PLANE *pp; char *command(); int warning = 0; #ifdef BSD wclear(planes); #endif wmove(planes, 0,0); #ifdef SYSV wclrtobot(planes); #endif wprintw(planes, "Time: %-4d Safe: %d", clck, safe_planes); wmove(planes, 2, 0); waddstr(planes, "pl dt comm"); for (pp = air.head; pp != NULL; pp = pp->next) { if (waddch(planes, '\n') == ERR) { warning++; break; } waddstr(planes, command(pp)); } waddch(planes, '\n'); for (pp = ground.head; pp != NULL; pp = pp->next) { if (waddch(planes, '\n') == ERR) { warning++; break; } waddstr(planes, command(pp)); } if (warning) { wmove(planes, LINES - INPUT_LINES - 1, 0); waddstr(planes, "---- more ----"); wclrtoeol(planes); } wrefresh(planes); fflush(stdout); } loser(p, s) const PLANE *p; const char *s; { int c; #ifdef BSD struct itimerval itv; #endif /* disable timer */ #ifdef BSD itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itv, NULL); #endif #ifdef SYSV alarm(0); #endif wmove(input, 0, 0); wclrtobot(input); wprintw(input, "Plane '%c' %s\n\nHit space for top players list...", name(p), s); wrefresh(input); fflush(stdout); while ((c = getchar()) != EOF && c != ' ') ; clear(); /* move to top of screen */ refresh(); endwin(); log_score(0); exit(0); } redraw() { clear(); refresh(); touchwin(radar); wrefresh(radar); touchwin(planes); wrefresh(planes); touchwin(credit); wrefresh(credit); /* refresh input last to get cursor in right place */ touchwin(input); wrefresh(input); fflush(stdout); } done_screen() { clear(); refresh(); endwin(); /* clean up curses */ } diff --git a/games/backgammon/backgammon/extra.c b/games/backgammon/backgammon/extra.c index acefad55d7a2..86170eec79a0 100644 --- a/games/backgammon/backgammon/extra.c +++ b/games/backgammon/backgammon/extra.c @@ -1,255 +1,255 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)extra.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" #ifdef DEBUG #include FILE *trace; #endif /* * dble() * Have the current player double and ask opponent to accept. */ dble () { - register int resp; /* response to y/n */ + int resp; /* response to y/n */ for (;;) { writel (" doubles."); /* indicate double */ if (cturn == -pnum) { /* see if computer accepts */ if (dblgood()) { /* guess not */ writel (" Declined.\n"); nexturn(); cturn *= -2; /* indicate loss */ return; } else { /* computer accepts */ writel (" Accepted.\n"); gvalue *= 2; /* double game value */ dlast = cturn; if (tflag) gwrite(); return; } } /* ask if player accepts */ writel (" Does "); writel (cturn == 1? color[2]: color[3]); writel (" accept?"); /* get response from yorn, * a "2" means he said "p" * for print board. */ if ((resp = yorn ('R')) == 2) { writel (" Reprint.\n"); buflush(); wrboard(); writel (*Colorptr); continue; } /* check response */ if (resp) { /* accepted */ gvalue *= 2; dlast = cturn; if (tflag) gwrite(); return; } nexturn (); /* declined */ cturn *= -2; return; } } /* * dblgood () * Returns 1 if the computer would double in this position. This * is not an exact science. The computer will decline a double that he * would have made. Accumulated judgments are kept in the variable n, * which is in "pips", i.e., the position of each man summed over all * men, with opponent's totals negative. Thus, n should have a positive * value of 7 for each move ahead, or a negative value of 7 for each one * behind. */ dblgood () { - register int n; /* accumulated judgment */ - register int OFFC = *offptr; /* no. of computer's men off */ - register int OFFO = *offopp; /* no. of player's men off */ + int n; /* accumulated judgment */ + int OFFC = *offptr; /* no. of computer's men off */ + int OFFO = *offopp; /* no. of player's men off */ #ifdef DEBUG - register int i; + int i; if (trace == NULL) trace = fopen ("bgtrace","w"); #endif /* get real pip value */ n = eval()*cturn; #ifdef DEBUG fputs ("\nDoubles:\nBoard: ",trace); for (i = 0; i < 26; i++) fprintf (trace," %d",board[i]); fprintf (trace,"\n\tpip = %d, ",n); #endif /* below adjusts pip value * according to position * judgments */ /* check men moving off * board */ if (OFFC > -15 || OFFO > -15) { if (OFFC < 0 && OFFO < 0) { OFFC += 15; OFFO += 15; n +=((OFFC-OFFO)*7)/2; } else if (OFFC < 0) { OFFC += 15; n -= OFFO*7/2; } else if (OFFO < 0) { OFFO += 15; n += OFFC*7/2; } if (OFFC < 8 && OFFO > 8) n -= 7; if (OFFC < 10 && OFFO > 10) n -= 7; if (OFFC < 12 && OFFO > 12) n -= 7; if (OFFO < 8 && OFFC > 8) n += 7; if (OFFO < 10 && OFFC > 10) n += 7; if (OFFO < 12 && OFFC > 12) n += 7; n += ((OFFC-OFFO)*7)/2; } #ifdef DEBUG fprintf (trace,"off = %d, ",n); #endif /* see if men are trapped */ n -= freemen(bar); n += freemen(home); n += trapped(home,-cturn); n -= trapped(bar,cturn); #ifdef DEBUG fprintf (trace,"free = %d\n",n); fprintf (trace,"\tOFFC = %d, OFFO = %d\n",OFFC,OFFO); fflush (trace); #endif /* double if 2-3 moves ahead */ if (n > 10+rnum(7)) return(1); return (0); } freemen (b) int b; { - register int i, inc, lim; + int i, inc, lim; odds(0,0,0); if (board[b] == 0) return (0); inc = (b == 0? 1: -1); lim = (b == 0? 7: 18); for (i = b+inc; i != lim; i += inc) if (board[i]*inc < -1) odds(abs(b-i),0,abs(board[b])); if (abs(board[b]) == 1) return ((36-count())/5); return (count()/5); } trapped (n,inc) int n, inc; { - register int i, j, k; + int i, j, k; int c, l, ct; ct = 0; l = n+7*inc; for (i = n+inc; i != l; i += inc) { odds (0,0,0); c = abs(i-l); if (board[i]*inc > 0) { for (j = c; j < 13; j++) if (board[i+inc*j]*inc < -1) { if (j < 7) odds (j,0,1); for (k = 1; k < 7 && k < j; k++) if (j-k < 7) odds (k,j-k,1); } ct += abs(board[i])*(36-count()); } } return (ct/5); } eval () { - register int i, j; + int i, j; for (j = i = 0; i < 26; i++) j += (board[i] >= 0 ? i*board[i] : (25-i)*board[i]); if (off[1] >= 0) j += 25*off[1]; else j += 25*(off[1]+15); if (off[0] >= 0) j -= 25*off[0]; else j -= 25*(off[0]+15); return (j); } diff --git a/games/backgammon/backgammon/main.c b/games/backgammon/backgammon/main.c index 972f0ee59120..c6abfab0edda 100644 --- a/games/backgammon/backgammon/main.c +++ b/games/backgammon/backgammon/main.c @@ -1,569 +1,569 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include #include "back.h" #define MVPAUSE 5 /* time to sleep when stuck */ #define MAXUSERS 35 /* maximum number of users */ extern const char *const instr[]; /* text of instructions */ extern const char *const message[]; /* update message */ char ospeed; /* tty output speed */ const char *helpm[] = { /* help message */ "Enter a space or newline to roll, or", " R to reprint the board\tD to double", " S to save the game\tQ to quit", 0 }; const char *contin[] = { /* pause message */ "(Type a newline to continue.)", "", 0 }; static const char rules[] = "\nDo you want the rules of the game?"; static const char noteach[] = "Teachgammon not available!\n\007"; static const char need[] = "Do you need instructions for this program?"; static const char askcol[] = "Enter 'r' to play red, 'w' to play white, 'b' to play both:"; static const char rollr[] = "Red rolls a "; static const char rollw[] = ". White rolls a "; static const char rstart[] = ". Red starts.\n"; static const char wstart[] = ". White starts.\n"; static const char toobad1[] = "Too bad, "; static const char unable[] = " is unable to use that roll.\n"; static const char toobad2[] = ". Too bad, "; static const char cantmv[] = " can't move.\n"; static const char bgammon[] = "Backgammon! "; static const char gammon[] = "Gammon! "; static const char again[] = ".\nWould you like to play again?"; static const char svpromt[] = "Would you like to save this game?"; static const char password[] = "losfurng"; static char pbuf[10]; main (argc,argv) int argc; char **argv; { - register int i; /* non-descript index */ - register int l; /* non-descript index */ - register char c; /* non-descript character storage */ + int i; /* non-descript index */ + int l; /* non-descript index */ + char c; /* non-descript character storage */ /* revoke privs */ setgid(getgid()); /* initialization */ bflag = 2; /* default no board */ acnt = 1; /* Nuber of args */ signal (SIGINT,getout); /* trap interrupts */ if (gtty (0,&tty) == -1) /* get old tty mode */ errexit ("backgammon(gtty)"); old = tty.sg_flags; #ifdef V7 raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */ #else raw = ((noech = old & ~ECHO) | RAW); /* set up modes */ #endif ospeed = tty.sg_ospeed; /* for termlib */ /* get terminal * capabilities, and * decide if it can * cursor address */ tflag = getcaps (getenv ("TERM")); /* use whole screen * for text */ if (tflag) begscr = 0; srandomdev(); getarg (argc, argv); args[acnt] = NULL; if (tflag) { /* clear screen */ noech &= ~(CRMOD|XTABS); raw &= ~(CRMOD|XTABS); clear(); } fixtty (raw); /* go into raw mode */ /* check if restored * game and save flag * for later */ if (rfl = rflag) { text (message); /* print message */ text (contin); wrboard(); /* print board */ /* if new game, pretend * to be a non-restored * game */ if (cturn == 0) rflag = 0; } else { rscore = wscore = 0; /* zero score */ text (message); /* update message * without pausing */ if (aflag) { /* print rules */ writel (rules); if (yorn(0)) { fixtty (old); /* restore tty */ args[0] = strdup ("teachgammon"); execv (TEACH,args); tflag = 0; /* error! */ writel (noteach); exit(1); } else { /* if not rules, then * instructions */ writel (need); if (yorn(0)) { /* print instructions */ clear(); text (instr); } } } for (i = 0; i < acnt; i++) free (args[i]); init(); /* initialize board */ if (pnum == 2) { /* ask for color(s) */ writec ('\n'); writel (askcol); while (pnum == 2) { c = readc(); switch (c) { case 'R': /* red */ pnum = -1; break; case 'W': /* white */ pnum = 1; break; case 'B': /* both */ pnum = 0; break; case 'P': if (iroll) break; if (tflag) curmove (curr,0); else writec ('\n'); writel ("Password:"); signal (SIGALRM,getout); cflag = 1; alarm (10); for (i = 0; i < 10; i++) { pbuf[i] = readc(); if (pbuf[i] == '\n') break; } if (i == 10) while (readc() != '\n'); alarm (0); cflag = 0; if (i < 10) pbuf[i] = '\0'; for (i = 0; i < 9; i++) if (pbuf[i] != password[i]) getout(); iroll = 1; if (tflag) curmove (curr,0); else writec ('\n'); writel (askcol); break; default: /* error */ writec ('\007'); } } } else if (!aflag) /* pause to read * message */ text (contin); wrboard(); /* print board */ if (tflag) curmove (18,0); else writec ('\n'); } /* limit text to bottom * of screen */ if (tflag) begscr = 17; for (;;) { /* begin game! */ /* initial roll if * needed */ if ((! rflag) || raflag) roll(); /* perform ritual of * first roll */ if (! rflag) { if (tflag) curmove (17,0); while (D0 == D1) /* no doubles */ roll(); /* print rolls */ writel (rollr); writec (D0+'0'); writel (rollw); writec (D1+'0'); /* winner goes first */ if (D0 > D1) { writel (rstart); cturn = 1; } else { writel (wstart); cturn = -1; } } /* initalize variables * according to whose * turn it is */ if (cturn == 1) { /* red */ home = 25; bar = 0; inptr = &in[1]; inopp = &in[0]; offptr = &off[1]; offopp = &off[0]; Colorptr = &color[1]; colorptr = &color[3]; colen = 3; } else { /* white */ home = 0; bar = 25; inptr = &in[0]; inopp = &in[1]; offptr = &off[0]; offopp = &off[1]; Colorptr = &color[0]; colorptr = &color[2]; colen = 5; } /* do first move * (special case) */ if (! (rflag && raflag)) { if (cturn == pnum) /* computer's move */ move (0); else { /* player's move */ mvlim = movallow(); /* reprint roll */ if (tflag) curmove (cturn == -1? 18: 19,0); proll(); getmove(); /* get player's move */ } } if (tflag) { curmove (17,0); cline(); begscr = 18; } /* no longer any diff- * erence between normal * game and recovered * game. */ rflag = 0; /* move as long as it's * someone's turn */ while (cturn == 1 || cturn == -1) { /* board maintainence */ if (tflag) refresh(); /* fix board */ else /* redo board if -p */ if (cturn == bflag || bflag == 0) wrboard(); /* do computer's move */ if (cturn == pnum) { move (1); /* see if double * refused */ if (cturn == -2 || cturn == 2) break; /* check for winning * move */ if (*offopp == 15) { cturn *= -2; break; } continue; } /* (player's move) */ /* clean screen if * safe */ if (tflag && hflag) { curmove (20,0); clend (); hflag = 1; } /* if allowed, give him * a chance to double */ if (dlast != cturn && gvalue < 64) { if (tflag) curmove (cturn == -1? 18: 19,0); writel (*Colorptr); c = readc(); /* character cases */ switch (c) { /* reprint board */ case 'R': wrboard(); break; /* save game */ case 'S': raflag = 1; save (1); break; /* quit */ case 'Q': quit(); break; /* double */ case 'D': dble(); break; /* roll */ case ' ': case '\n': roll(); writel (" rolls "); writec (D0+'0'); writec (' '); writec (D1+'0'); writel (". "); /* see if he can move */ if ( (mvlim = movallow()) == 0) { /* can't move */ writel (toobad1); writel (*colorptr); writel (unable); if (tflag) { if (pnum) { buflush(); sleep (MVPAUSE); } } nexturn(); break; } /* get move */ getmove(); /* okay to clean * screen */ hflag = 1; break; /* invalid character */ default: /* print help message */ if (tflag) curmove (20,0); else writec ('\n'); text (helpm); if (tflag) curmove (cturn == -1? 18: 19,0); else writec ('\n'); /* don't erase */ hflag = 0; } } else { /* couldn't double */ /* print roll */ roll(); if (tflag) curmove (cturn == -1? 18: 19,0); proll (); /* can he move? */ if ((mvlim = movallow()) == 0) { /* he can't */ writel (toobad2); writel (*colorptr); writel (cantmv); buflush(); sleep (MVPAUSE); nexturn(); continue; } /* get move */ getmove(); } } /* don't worry about who * won if quit */ if (cturn == 0) break; /* fix cturn = winner */ cturn /= -2; /* final board pos. */ if (tflag) refresh(); /* backgammon? */ mflag = 0; l = bar+7*cturn; for (i = bar; i != l; i += cturn) if (board[i]*cturn) mflag++; /* compute game value */ if (tflag) curmove (20,0); if (*offopp == 15) { if (mflag) { writel (bgammon); gvalue *= 3; } else if (*offptr <= 0) { writel (gammon); gvalue *= 2; } } /* report situation */ if (cturn == -1) { writel ("Red wins "); rscore += gvalue; } else { writel ("White wins "); wscore += gvalue; } wrint (gvalue); writel (" point"); if (gvalue > 1) writec ('s'); writel (".\n"); /* write score */ wrscore(); /* see if he wants * another game */ writel (again); if ((i = yorn ('S')) == 0) break; init(); if (i == 2) { writel (" Save.\n"); cturn = 0; save (0); } /* yes, reset game */ wrboard(); } /* give him a chance to save if game was recovered */ if (rfl && cturn) { writel (svpromt); if (yorn (0)) { /* re-initialize for * recovery */ init(); cturn = 0; save(0); } } /* leave peacefully */ getout (); } diff --git a/games/backgammon/backgammon/move.c b/games/backgammon/backgammon/move.c index 8b3286f58976..bf8ab86fb320 100644 --- a/games/backgammon/backgammon/move.c +++ b/games/backgammon/backgammon/move.c @@ -1,554 +1,554 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include "back.h" #ifdef DEBUG #include FILE *trace; static char tests[20]; #endif struct BOARD { /* structure of game position */ int b_board[26]; /* board position */ int b_in[2]; /* men in */ int b_off[2]; /* men off */ int b_st[4], b_fn[4]; /* moves */ struct BOARD *b_next; /* forward queue pointer */ }; struct BOARD *freeq = 0; struct BOARD *checkq = 0; struct BOARD *bsave(); struct BOARD *nextfree(); /* these variables are values for the * candidate move */ static int ch; /* chance of being hit */ static int op; /* computer's open men */ static int pt; /* comp's protected points */ static int em; /* farthest man back */ static int frc; /* chance to free comp's men */ static int frp; /* chance to free pl's men */ /* these values are the values for the * move chosen (so far) */ static int chance; /* chance of being hit */ static int openmen; /* computer's open men */ static int points; /* comp's protected points */ static int endman; /* farthest man back */ static int barmen; /* men on bar */ static int menin; /* men in inner table */ static int menoff; /* men off board */ static int oldfrc; /* chance to free comp's men */ static int oldfrp; /* chance to free pl's men */ static int cp[5]; /* candidate start position */ static int cg[5]; /* candidate finish position */ static int race; /* game reduced to a race */ move (okay) int okay; /* zero if first move */ { - register int i; /* index */ - register int l; /* last man */ + int i; /* index */ + int l; /* last man */ if (okay) { /* see if comp should double */ if (gvalue < 64 && dlast != cturn && dblgood()) { writel (*Colorptr); dble(); /* double */ /* return if declined */ if (cturn != 1 && cturn != -1) return; } roll(); } race = 0; for (i = 0; i < 26; i++) { if (board[i] < 0) l = i; } for (i = 0; i < l; i++) { if (board[i] > 0) break; } if (i == l) race = 1; /* print roll */ if (tflag) curmove (cturn == -1? 18: 19,0); writel (*Colorptr); writel (" rolls "); writec (D0+'0'); writec (' '); writec (D1+'0'); /* make tty interruptable * while thinking */ if (tflag) cline(); fixtty (noech); /* find out how many moves */ mvlim = movallow(); if (mvlim == 0) { writel (" but cannot use it.\n"); nexturn(); fixtty (raw); return; } /* initialize */ for (i = 0; i < 4; i++) cp[i] = cg[i] = 0; /* strategize */ trymove (0,0); pickmove(); /* print move */ writel (" and moves "); for (i = 0; i < mvlim; i++) { if (i > 0) writec (','); wrint (p[i] = cp[i]); writec ('-'); wrint (g[i] = cg[i]); makmove (i); } writec ('.'); /* print blots hit */ if (tflag) curmove (20,0); else writec ('\n'); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); /* get ready for next move */ nexturn(); if (!okay) { buflush(); sleep (3); } fixtty (raw); /* no more tty interrupt */ } trymove (mvnum,swapped) -register int mvnum; /* number of move (rel zero) */ +int mvnum; /* number of move (rel zero) */ int swapped; /* see if swapped also tested */ { - register int pos; /* position on board */ - register int rval; /* value of roll */ + int pos; /* position on board */ + int rval; /* value of roll */ /* if recursed through all dice * values, compare move */ if (mvnum == mvlim) { binsert (bsave()); return; } /* make sure dice in always * same order */ if (d0 == swapped) swap; /* choose value for this move */ rval = dice[mvnum != 0]; /* find all legitimate moves */ for (pos = bar; pos != home; pos += cturn) { /* fix order of dice */ if (d0 == swapped) swap; /* break if stuck on bar */ if (board[bar] != 0 && pos != bar) break; /* on to next if not occupied */ if (board[pos]*cturn <= 0) continue; /* set up arrays for move */ p[mvnum] = pos; g[mvnum] = pos+rval*cturn; if (g[mvnum]*cturn >= home) { if (*offptr < 0) break; g[mvnum] = home; } /* try to move */ if (makmove (mvnum)) continue; else trymove (mvnum+1,2); /* undo move to try another */ backone (mvnum); } /* swap dice and try again */ if ((!swapped) && D0 != D1) trymove (0,1); } struct BOARD * bsave () { - register int i; /* index */ + int i; /* index */ struct BOARD *now; /* current position */ now = nextfree (); /* get free BOARD */ /* store position */ for (i = 0; i < 26; i++) now->b_board[i] = board[i]; now->b_in[0] = in[0]; now->b_in[1] = in[1]; now->b_off[0] = off[0]; now->b_off[1] = off[1]; for (i = 0; i < mvlim; i++) { now->b_st[i] = p[i]; now->b_fn[i] = g[i]; } return (now); } binsert (new) struct BOARD *new; /* item to insert */ { - register struct BOARD *p = checkq; /* queue pointer */ - register int result; /* comparison result */ + struct BOARD *p = checkq; /* queue pointer */ + int result; /* comparison result */ if (p == 0) { /* check if queue empty */ checkq = p = new; p->b_next = 0; return; } result = bcomp (new,p); /* compare to first element */ if (result < 0) { /* insert in front */ new->b_next = p; checkq = new; return; } if (result == 0) { /* duplicate entry */ mvcheck (p,new); makefree (new); return; } while (p->b_next != 0) { /* traverse queue */ result = bcomp (new,p->b_next); if (result < 0) { /* found place */ new->b_next = p->b_next; p->b_next = new; return; } if (result == 0) { /* duplicate entry */ mvcheck (p->b_next,new); makefree (new); return; } p = p->b_next; } /* place at end of queue */ p->b_next = new; new->b_next = 0; } bcomp (a,b) struct BOARD *a; struct BOARD *b; { - register int *aloc = a->b_board; /* pointer to board a */ - register int *bloc = b->b_board; /* pointer to board b */ - register int i; /* index */ + int *aloc = a->b_board; /* pointer to board a */ + int *bloc = b->b_board; /* pointer to board b */ + int i; /* index */ int result; /* comparison result */ for (i = 0; i < 26; i++) { /* compare boards */ result = cturn*(aloc[i]-bloc[i]); if (result) return (result); /* found inequality */ } return (0); /* same position */ } mvcheck (incumbent,candidate) -register struct BOARD *incumbent; -register struct BOARD *candidate; +struct BOARD *incumbent; +struct BOARD *candidate; { - register int i; - register int result; + int i; + int result; for (i = 0; i < mvlim; i++) { result = cturn*(candidate->b_st[i]-incumbent->b_st[i]); if (result > 0) return; if (result < 0) break; } if (i == mvlim) return; for (i = 0; i < mvlim; i++) { incumbent->b_st[i] = candidate->b_st[i]; incumbent->b_fn[i] = candidate->b_fn[i]; } } makefree (dead) struct BOARD *dead; /* dead position */ { dead->b_next = freeq; /* add to freeq */ freeq = dead; } struct BOARD * nextfree () { struct BOARD *new; if (freeq == 0) { new = (struct BOARD *)calloc (1,sizeof (struct BOARD)); if (new == 0) { writel ("\nOut of memory\n"); getout(); } new->b_next = 0; } else { new = freeq; freeq = freeq->b_next; } return (new); } pickmove () { /* current game position */ - register struct BOARD *now = bsave(); - register struct BOARD *next; /* next move */ + struct BOARD *now = bsave(); + struct BOARD *next; /* next move */ #ifdef DEBUG if (trace == NULL) trace = fopen ("bgtrace","w"); fprintf (trace,"\nRoll: %d %d%s\n",D0,D1,race? " (race)": ""); fflush (trace); #endif do { /* compare moves */ boardcopy (checkq); next = checkq->b_next; makefree (checkq); checkq = next; movcmp(); } while (checkq != 0); boardcopy (now); } boardcopy (s) -register struct BOARD *s; /* game situation */ +struct BOARD *s; /* game situation */ { - register int i; /* index */ + int i; /* index */ for (i = 0; i < 26; i++) board[i] = s->b_board[i]; for (i = 0; i < 2; i++) { in[i] = s->b_in[i]; off[i] = s->b_off[i]; } for (i = 0; i < mvlim; i++) { p[i] = s->b_st[i]; g[i] = s->b_fn[i]; } } movcmp () { - register int i; - register int c; + int i; + int c; #ifdef DEBUG if (trace == NULL) trace = fopen ("bgtrace","w"); #endif odds (0,0,0); if (!race) { ch = op = pt = 0; for (i = 1; i < 25; i++) { if (board[i] == cturn) ch = canhit (i,1); op += abs (bar-i); } for (i = bar+cturn; i != home; i += cturn) if (board[i]*cturn > 1) pt += abs(bar-i); frc = freemen (bar)+trapped (bar,cturn); frp = freemen (home)+trapped (home,-cturn); } for (em = bar; em != home; em += cturn) if (board[em]*cturn > 0) break; em = abs(home-em); #ifdef DEBUG fputs ("Board: ",trace); for (i = 0; i < 26; i++) fprintf (trace, " %d",board[i]); if (race) fprintf (trace,"\n\tem = %d\n",em); else fprintf (trace, "\n\tch = %d, pt = %d, em = %d, frc = %d, frp = %d\n", ch,pt,em,frc,frp); fputs ("\tMove: ",trace); for (i = 0; i < mvlim; i++) fprintf (trace," %d-%d",p[i],g[i]); fputs ("\n",trace); fflush (trace); strcpy (tests,""); #endif if ((cp[0] == 0 && cg[0] == 0) || movegood()) { #ifdef DEBUG fprintf (trace,"\t[%s] ... wins.\n",tests); fflush (trace); #endif for (i = 0; i < mvlim; i++) { cp[i] = p[i]; cg[i] = g[i]; } if (!race) { chance = ch; openmen = op; points = pt; endman = em; barmen = abs(board[home]); oldfrc = frc; oldfrp = frp; } menin = *inptr; menoff = *offptr; } #ifdef DEBUG else { fprintf (trace,"\t[%s] ... loses.\n",tests); fflush (trace); } #endif } movegood () { - register int n; + int n; if (*offptr == 15) return (1); if (menoff == 15) return (0); if (race) { #ifdef DEBUG strcat (tests,"o"); #endif if (*offptr-menoff) return (*offptr > menoff); #ifdef DEBUG strcat (tests,"e"); #endif if (endman-em) return (endman > em); #ifdef DEBUG strcat (tests,"i"); #endif if (menin == 15) return (0); if (*inptr == 15) return (1); #ifdef DEBUG strcat (tests,"i"); #endif if (*inptr-menin) return (*inptr > menin); return (rnum(2)); } else { n = barmen-abs(board[home]); #ifdef DEBUG strcat (tests,"c"); #endif if (abs(chance-ch)+25*n > rnum(150)) return (n? (n < 0): (ch < chance)); #ifdef DEBUG strcat (tests,"o"); #endif if (*offptr-menoff) return (*offptr > menoff); #ifdef DEBUG strcat (tests,"o"); #endif if (abs(openmen-op) > 7+rnum(12)) return (openmen > op); #ifdef DEBUG strcat (tests,"b"); #endif if (n) return (n < 0); #ifdef DEBUG strcat (tests,"e"); #endif if (abs(endman-em) > rnum(2)) return (endman > em); #ifdef DEBUG strcat (tests,"f"); #endif if (abs(frc-oldfrc) > rnum(2)) return (frc < oldfrc); #ifdef DEBUG strcat (tests,"p"); #endif if (abs(n = pt-points) > rnum(4)) return (n > 0); #ifdef DEBUG strcat (tests,"i"); #endif if (*inptr-menin) return (*inptr > menin); #ifdef DEBUG strcat (tests,"f"); #endif if (abs(frp-oldfrp) > rnum(2)) return (frp > oldfrp); return (rnum(2)); } } diff --git a/games/backgammon/backgammon/text.c b/games/backgammon/backgammon/text.c index 00a5946f9754..3ec45f1d4551 100644 --- a/games/backgammon/backgammon/text.c +++ b/games/backgammon/backgammon/text.c @@ -1,135 +1,135 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)text.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" const char *const instr[] = { " If you did not notice by now, this program reacts to things as", "soon as you type them, without waiting for a newline. This means that", "the special characters RUBOUT, ESC, and CONTROL-D, will not perform", "their special functions during most of this program. The program", "should usually stop when a RUBOUT is typed, but occasionally it will", "ignore RUBOUTs until it is waiting for input.\n", " These instructions are presented in small chunks designed not to", "roll off the top of your screen. When the characters '-->' are print-", "ed, no more data will be printed until a space or newline is typed.", "In this way, you can finish one section before continuing to another.", "Like this:", "", " The two sides are colored 'red' and 'white.' The computer may play", "one side, or if there are two players, the computer can merely act as", "a gamekeeper, letting the players make the moves. Once you tell the", "computer what color(s) you want to play, the decision remains in ef-", "fect until you quit the program, even if you play more than one game,", "since the program keeps a running score.\n", " The program will prompt for a move in one of two ways. If the", "player has the opportunity to double, then merely his color will be", "typed out. The player can now do one of several things. He can dou-", "ble by typing a 'd', he can roll by typing a space (' ') or newline,", "or if he is not sure, he can reprint the board by typing a 'r'.\n", " If the player cannot double, his roll will be thrust in front of", "him, followed by the request 'Move:', asking for a move but not giving", "him the chance to double. He can still ask for the board by typing", "'r'. In either of these two states, the player can quit by typing 'q'", "or save the game by typing 's'. In either case, the player will be", "asked to verify, in case there was some error. The program then ends", "immediately, after first saving the file if so requested.", "", " A player can move one of his men using two forms of input. The", "first form is -, where is the starting position, and is", "the finishing position of the player's man. For example, if white", "wanted to move a piece from position 13 to position 8, his move could", "be entered as 13-8. The second form is / where is the", "starting position, an is the roll actually made. Hence, white", "could have entered as 13/5 instead of 13-8.\n", " A player must move each roll of the dice separately. For example,", "if a player rolled 4 3, and wanted to move from 13 to 6, he could", "enter it as 13/4,9/3 or 13/3,10/4 or 13-10,10-6 or 13-9,9-6, but not", "13-6. The last two entries can be shortened to 13-10-6 and 13-9-6.", "If you want to move more than one piece from the same position, such", "as 13-10,13-9, you can abbreviate this using the / format as by", "entering more than one , or 13/34. A player can use both forms for", "the same roll, e.g. 13/3,13-9, and separates individual moves by ei-", "ther a comma or a space. The letter 'b' represents the bar, and the", "letter 'h' represents a player's home. You could also enter the", "number that would be in the position of the bar, 25 or 0 as appropri-", "ate. Use a newline at the end of your moves for a turn.", "", " As you type in your move, if a character does not make sense under", "the above constrictions, a bell will sound instead of the character,", "and it will be ignored. You may kill lines and erase characters as", "you would normally, but don't be surprised if they look different than", "usual. Also, if you have entered one or more of your rolls, and you", "wish to see what the move looks like so far, type a 'r' to see what it", "looks like. This cannot be done in the middle of a move (e.g., after", "a '-' or '/'). After the printing board, the program will go back to", "inputting your move and you can backspace or kill just as if you had", "just typed in your input.\n", " Now you should be ready to begin the game. Good luck!", "", 0}; int text (t) const char *const *t; { - register int i; + int i; const char *s, *a; fixtty (noech); while (*t != 0) { s = a = *t; for (i = 0; *a != '\0'; i--) a++; if (i) { writel (s); writec ('\n'); } else { writel ("-->"); fixtty (raw); while ((i = readc()) != ' ' && i != '\n'); fixtty (noech); clear(); } t++; } fixtty (raw); } diff --git a/games/backgammon/common_source/allow.c b/games/backgammon/common_source/allow.c index 620ce05b525c..d2848b1d5948 100644 --- a/games/backgammon/common_source/allow.c +++ b/games/backgammon/common_source/allow.c @@ -1,111 +1,111 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)allow.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" movallow () { - register int i, m, iold; + int i, m, iold; int r; if (d0) swap; m = (D0 == D1? 4: 2); for (i = 0; i < 4; i++) p[i] = bar; i = iold = 0; while (i < m) { if (*offptr == 15) break; h[i] = 0; if (board[bar]) { if (i == 1 || m == 4) g[i] = bar+cturn*D1; else g[i] = bar+cturn*D0; if (r = makmove(i)) { if (d0 || m == 4) break; swap; movback (i); if (i > iold) iold = i; for (i = 0; i < 4; i++) p[i] = bar; i = 0; } else i++; continue; } if ((p[i] += cturn) == home) { if (i > iold) iold = i; if (m == 2 && i) { movback(i); p[i--] = bar; if (p[i] != bar) continue; else break; } if (d0 || m == 4) break; swap; movback (i); for (i = 0; i < 4; i++) p[i] = bar; i = 0; continue; } if (i == 1 || m == 4) g[i] = p[i]+cturn*D1; else g[i] = p[i]+cturn*D0; if (g[i]*cturn > home) { if (*offptr >= 0) g[i] = home; else continue; } if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0) i++; } movback (i); return (iold > i? iold: i); } diff --git a/games/backgammon/common_source/board.c b/games/backgammon/common_source/board.c index 1446248ebe71..b7c365c90a64 100644 --- a/games/backgammon/common_source/board.c +++ b/games/backgammon/common_source/board.c @@ -1,179 +1,179 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include "back.h" static int i, j, k; static char ln[60]; wrboard () { - register int l; + int l; static const char bl[] = "| | | |\n"; static const char sv[] = "| | | | \n"; fixtty (noech); clear(); if (tflag) { fboard(); goto lastline; } writel ("_____________________________________________________\n"); writel (bl); strcpy (ln,bl); for (j = 1; j < 50; j += 4) { k = j/4+(j > 24? 12: 13); ln[j+1] = k%10+'0'; ln[j] = k/10+'0'; if (j == 21) j += 4; } writel (ln); for (i = 0; i < 5; i++) { strcpy (ln,sv); for (j = 1; j < 50; j += 4) { k = j/4+(j > 24? 12: 13); wrbsub (); if (j == 21) j += 4; } if (-board[25] > i) ln[26] = 'w'; if (-board[25] > i+5) ln[25] = 'w'; if (-board[25] > i+10) ln[27] = 'w'; l = 53; if (off[1] > i || (off[1] < 0 && off[1]+15 > i)) { ln[54] = 'r'; l = 55; } if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5)) { ln[55] = 'r'; l = 56; } if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10)) { ln[56] = 'r'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; writel (ln); } strcpy (ln,bl); ln[25] = 'B'; ln[26] = 'A'; ln[27] = 'R'; writel (ln); strcpy (ln,sv); for (i = 4; i > -1; i--) { for (j = 1; j < 50; j += 4) { k = ((j > 24? 53: 49)-j)/4; wrbsub(); if (j == 21) j += 4; } if (board[0] > i) ln[26] = 'r'; if (board[0] > i+5) ln[25] = 'r'; if (board[0] > i+10) ln[27] = 'r'; l = 53; if (off[0] > i || (off[0] < 0 && off[0]+15 > i)) { ln[54] = 'w'; l = 55; } if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5)) { ln[55] = 'w'; l = 56; } if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10)) { ln[56] = 'w'; l = 57; } ln[l++] = '\n'; ln[l] = '\0'; writel (ln); } strcpy (ln,bl); for (j = 1; j < 50; j += 4) { k = ((j > 24? 53: 49)-j)/4; ln[j+1] = k%10+'0'; if (k > 9) ln[j] = k/10+'0'; if (j == 21) j += 4; } writel (ln); writel ("|_______________________|___|_______________________|\n"); lastline: gwrite (); if (tflag) curmove (18,0); else { writec ('\n'); writec ('\n'); } fixtty(raw); } wrbsub () { - register int m; - register char d; + int m; + char d; if (board[k] > 0) { m = board[k]; d = 'r'; } else { m = -board[k]; d = 'w'; } if (m>i) ln[j+1] = d; if (m>i+5) ln[j] = d; if (m>i+10) ln[j+2] = d; } diff --git a/games/backgammon/common_source/check.c b/games/backgammon/common_source/check.c index c545e3901e47..78433b79fb01 100644 --- a/games/backgammon/common_source/check.c +++ b/games/backgammon/common_source/check.c @@ -1,160 +1,160 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)check.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" getmove () { - register int i, c; + int i, c; c = 0; for (;;) { i = checkmove(c); switch (i) { case -1: if (movokay(mvlim)) { if (tflag) curmove (20,0); else writec ('\n'); for (i = 0; i < mvlim; i++) if (h[i]) wrhit(g[i]); nexturn(); if (*offopp == 15) cturn *= -2; if (tflag && pnum) bflag = pnum; return; } case -4: case 0: if (tflag) refresh(); if (i != 0 && i != -4) break; if (tflag) curmove (20,0); else writec ('\n'); writel (*Colorptr); if (i == -4) writel (" must make "); else writel (" can only make "); writec (mvlim+'0'); writel (" move"); if (mvlim > 1) writec ('s'); writec ('.'); writec ('\n'); break; case -3: if (quit()) return; } if (! tflag) proll (); else { curmove (cturn == -1? 18: 19,39); cline (); c = -1; } } } movokay (mv) -register int mv; +int mv; { - register int i, m; + int i, m; if (d0) swap; for (i = 0; i < mv; i++) { if (p[i] == g[i]) { moverr (i); curmove (20,0); writel ("Attempt to move to same location.\n"); return (0); } if (cturn*(g[i]-p[i]) < 0) { moverr (i); curmove (20,0); writel ("Backwards move.\n"); return (0); } if (abs(board[bar]) && p[i] != bar) { moverr (i); curmove (20,0); writel ("Men still on bar.\n"); return (0); } if ( (m = makmove(i)) ) { moverr (i); switch (m) { case 1: writel ("Move not rolled.\n"); break; case 2: writel ("Bad starting position.\n"); break; case 3: writel ("Destination occupied.\n"); break; case 4: writel ("Can't remove men yet.\n"); } return (0); } } return (1); } diff --git a/games/backgammon/common_source/fancy.c b/games/backgammon/common_source/fancy.c index 8a4ddc4b3913..6ddb464a4ff4 100644 --- a/games/backgammon/common_source/fancy.c +++ b/games/backgammon/common_source/fancy.c @@ -1,751 +1,750 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)fancy.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include "back.h" char PC; /* padding character */ char *BC; /* backspace sequence */ char *CD; /* clear to end of screen sequence */ char *CE; /* clear to end of line sequence */ char *CL; /* clear screen sequence */ char *CM; /* cursor movement instructions */ char *HO; /* home cursor sequence */ char *MC; /* column cursor movement map */ char *ML; /* row cursor movement map */ char *ND; /* forward cursor sequence */ char *UP; /* up cursor sequence */ int lHO; /* length of HO */ int lBC; /* length of BC */ int lND; /* length of ND */ int lUP; /* length of UP */ int CO; /* number of columns */ int LI; /* number of lines */ int *linect; /* array of lengths of lines on screen (the actual screen is not stored) */ /* two letter codes */ char tcap[] = "bccdceclcmhomcmlndup"; /* corresponding strings */ char **tstr[] = { &BC, &CD, &CE, &CL, &CM, &HO, &MC, &ML, &ND, &UP }; int buffnum; /* pointer to output buffer */ char tbuf[1024]; /* buffer for decoded termcap entries */ int oldb[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int oldr; int oldw; /* "real" cursor positions, so * it knows when to reposition. * These are -1 if curr and curc * are accurate */ int realr; int realc; int addbuf __P((int)); fboard () { - register int i, j, l; + int i, j, l; curmove (0,0); /* do top line */ for (i = 0; i < 53; i++) fancyc ('_'); curmove (15,0); /* do botttom line */ for (i = 0; i < 53; i++) fancyc ('_'); l = 1; /* do vertical lines */ for (i = 52; i > -1; i -= 28) { curmove ( (l == 1? 1: 15) ,i); fancyc ('|'); for (j = 0; j < 14; j++) { curmove (curr+l,curc-1); fancyc ('|'); } if (i == 24) i += 32; l = -l; /* alternate directions */ } curmove (2,1); /* label positions 13-18 */ for (i = 13; i < 18; i++) { fancyc ('1'); fancyc ((i % 10)+'0'); curmove (curr,curc+2); } fancyc ('1'); fancyc ('8'); curmove (2,29); /* label positions 19-24 */ fancyc ('1'); fancyc ('9'); for (i = 20; i < 25; i++) { curmove (curr,curc+2); fancyc ('2'); fancyc ((i % 10)+'0'); } curmove (14,1); /* label positions 12-7 */ fancyc ('1'); fancyc ('2'); for (i = 11; i > 6; i--) { curmove (curr,curc+2); fancyc (i > 9? '1': ' '); fancyc ((i % 10)+'0'); } curmove (14,30); /* label positions 6-1 */ fancyc ('6'); for (i = 5; i > 0; i--) { curmove (curr,curc+3); fancyc (i+'0'); } for (i = 12; i > 6; i--) /* print positions 12-7 */ if (board[i]) bsect (board[i],13,1+4*(12-i),-1); if (board[0]) /* print red men on bar */ bsect (board[0],13,25,-1); for (i = 6; i > 0; i--) /* print positions 6-1 */ if (board[i]) bsect (board[i],13,29+4*(6-i),-1); l = (off[1] < 0? off[1]+15: off[1]); /* print white's home */ bsect (l,3,54,1); curmove (8,25); /* print the word BAR */ fancyc ('B'); fancyc ('A'); fancyc ('R'); for (i = 13; i < 19; i++) /* print positions 13-18 */ if (board[i]) bsect (board[i],3,1+4*(i-13),1); if (board[25]) /* print white's men on bar */ bsect (board[25],3,25,1); for (i = 19; i < 25; i++) /* print positions 19-24 */ if (board[i]) bsect (board[i],3,29+4*(i-19),1); l = (off[0] < 0? off[0]+15: off[0]); /* print red's home */ bsect (-l,13,54,-1); for (i = 0; i < 26; i++) /* save board position * for refresh later */ oldb[i] = board[i]; oldr = (off[1] < 0? off[1]+15: off[1]); oldw = -(off[0] < 0? off[0]+15: off[0]); } /* * bsect (b,rpos,cpos,cnext) * Print the contents of a board position. "b" has the value of the * position, "rpos" is the row to start printing, "cpos" is the column to * start printing, and "cnext" is positive if the position starts at the top * and negative if it starts at the bottom. The value of "cpos" is checked * to see if the position is a player's home, since those are printed * differently. */ bsect (b,rpos,cpos,cnext) int b; /* contents of position */ int rpos; /* row of position */ int cpos; /* column of position */ int cnext; /* direction of position */ { - register int j; /* index */ - register int n; /* number of men on position */ - register int bct; /* counter */ + int j; /* index */ + int n; /* number of men on position */ + int bct; /* counter */ int k; /* index */ char pc; /* color of men on position */ n = abs(b); /* initialize n and pc */ pc = (b > 0? 'r': 'w'); if (n < 6 && cpos < 54) /* position cursor at start */ curmove (rpos,cpos+1); else curmove (rpos,cpos); for (j = 0; j < 5; j++) { /* print position row by row */ for (k = 0; k < 15; k += 5) /* print men */ if (n > j+k) fancyc (pc); if (j < 4) { /* figure how far to * back up for next * row */ if (n < 6) { /* stop if none left */ if (j+1 == n) break; bct = 1; /* single column */ } else { if (n < 11) { /* two columns */ if (cpos == 54) { /* home pos */ if (j+5 >= n) bct = 1; else bct = 2; } if (cpos < 54) { /* not home */ if (j+6 >= n) bct = 1; else bct = 2; } } else { /* three columns */ if (j+10 >= n) bct = 2; else bct = 3; } } curmove (curr+cnext,curc-bct); /* reposition cursor */ } } } refresh() { - register int i, r, c; + int i, r, c; r = curr; /* save current position */ c = curc; for (i = 12; i > 6; i--) /* fix positions 12-7 */ if (board[i] != oldb[i]) { fixpos (oldb[i],board[i],13,1+(12-i)*4,-1); oldb[i] = board[i]; } if (board[0] != oldb[0]) { /* fix red men on bar */ fixpos (oldb[0],board[0],13,25,-1); oldb[0] = board[0]; } for (i = 6; i > 0; i--) /* fix positions 6-1 */ if (board[i] != oldb[i]) { fixpos (oldb[i],board[i],13,29+(6-i)*4,-1); oldb[i] = board[i]; } i = -(off[0] < 0? off[0]+15: off[0]); /* fix white's home */ if (oldw != i) { fixpos (oldw,i,13,54,-1); oldw = i; } for (i = 13; i < 19; i++) /* fix positions 13-18 */ if (board[i] != oldb[i]) { fixpos (oldb[i],board[i],3,1+(i-13)*4,1); oldb[i] = board[i]; } if (board[25] != oldb[25]) { /* fix white men on bar */ fixpos (oldb[25],board[25],3,25,1); oldb[25] = board[25]; } for (i = 19; i < 25; i++) /* fix positions 19-24 */ if (board[i] != oldb[i]) { fixpos (oldb[i],board[i],3,29+(i-19)*4,1); oldb[i] = board[i]; } i = (off[1] < 0? off[1]+15: off[1]); /* fix red's home */ if (oldr != i) { fixpos (oldr,i,3,54,1); oldr = i; } curmove (r,c); /* return to saved position */ newpos(); buflush(); } fixpos (old,new,r,c,inc) int old, new, r, c, inc; { - register int o, n, nv; + int o, n, nv; int ov, nc; char col; if (old*new >= 0) { ov = abs(old); nv = abs(new); col = (old+new > 0? 'r': 'w'); o = (ov-1)/5; n = (nv-1)/5; if (o == n) { if (o == 2) nc = c+2; if (o == 1) nc = c < 54? c: c+1; if (o == 0) nc = c < 54? c+1: c; if (ov > nv) fixcol (r+inc*(nv-n*5),nc,abs(ov-nv),' ',inc); else fixcol (r+inc*(ov-o*5),nc,abs(ov-nv),col,inc); return; } else { if (c < 54) { if (o+n == 1) { if (n) { fixcol (r,c,abs(nv-5),col,inc); if (ov != 5) fixcol (r+inc*ov,c+1,abs(ov-5),col,inc); } else { fixcol (r,c,abs(ov-5),' ',inc); if (nv != 5) fixcol (r+inc*nv,c+1,abs(nv-5),' ',inc); } return; } if (n == 2) { if (ov != 10) fixcol (r+inc*(ov-5),c,abs(ov-10),col,inc); fixcol (r,c+2,abs(nv-10),col,inc); } else { if (nv != 10) fixcol (r+inc*(nv-5),c,abs(nv-10),' ',inc); fixcol (r,c+2,abs(ov-10),' ',inc); } return; } if (n > o) { fixcol (r+inc*(ov%5),c+o,abs(5*n-ov),col,inc); if (nv != 5*n) fixcol (r,c+n,abs(5*n-nv),col,inc); } else { fixcol (r+inc*(nv%5),c+n,abs(5*n-nv),' ',inc); if (ov != 5*o) fixcol (r,c+o,abs(5*o-ov),' ',inc); } return; } } nv = abs(new); fixcol (r,c+1,nv,new > 0? 'r': 'w',inc); if (abs(old) <= abs(new)) return; fixcol (r+inc*new,c+1,abs(old+new),' ',inc); } fixcol (r,c,l,ch,inc) -register int l, ch; -int r, c, inc; +int l, ch, r, c, inc; { - register int i; + int i; curmove (r,c); fancyc (ch); for (i = 1; i < l; i++) { curmove (curr+inc,curc-1); fancyc (ch); } } curmove (r,c) -register int r, c; +int r, c; { if (curr == r && curc == c) return; if (realr == -1) { realr = curr; realc = curc; } curr = r; curc = c; } newpos () { - register int r; /* destination row */ - register int c; /* destination column */ - register int mode = -1; /* mode of movement */ + int r; /* destination row */ + int c; /* destination column */ + int mode = -1; /* mode of movement */ int count = 1000; /* character count */ int i; /* index */ int j; /* index */ int n; /* temporary variable */ char *m; /* string containing CM movement */ if (realr == -1) /* see if already there */ return; r = curr; /* set current and dest. positions */ c = curc; curr = realr; curc = realc; /* double check position */ if (curr == r && curc == c) { realr = realc = -1; return; } if (CM) { /* try CM to get there */ mode = 0; m = (char *)tgoto (CM,c,r); count = strlen (m); } /* try HO and local movement */ if (HO && (n = r+c*lND+lHO) < count) { mode = 1; count = n; } /* try various LF combinations */ if (r >= curr) { /* CR, LF, and ND */ if ((n = (r-curr)+c*lND+1) < count) { mode = 2; count = n; } /* LF, ND */ if (c >= curc && (n = (r-curr)+(c-curc)*lND) < count) { mode = 3; count = n; } /* LF, BS */ if (c < curc && (n = (r-curr)+(curc-c)*lBC) < count) { mode = 4; count = n; } } /* try corresponding UP combinations */ if (r < curr) { /* CR, UP, and ND */ if ((n = (curr-r)*lUP+c*lND+1) < count) { mode = 5; count = n; } /* UP and ND */ if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < count) { mode = 6; count = n; } /* UP and BS */ if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < count) { mode = 7; count = n; } } /* space over */ if (curr == r && c > curc && linect[r] < curc && c-curc < count) mode = 8; switch (mode) { case -1: /* error! */ write (2,"\r\nInternal cursor error.\r\n",26); getout(); /* direct cursor motion */ case 0: tputs (m,abs(curr-r),addbuf); break; /* relative to "home" */ case 1: tputs (HO,r,addbuf); for (i = 0; i < r; i++) addbuf ('\012'); for (i = 0; i < c; i++) tputs (ND,1,addbuf); break; /* CR and down and over */ case 2: addbuf ('\015'); for (i = 0; i < r-curr; i++) addbuf ('\012'); for (i = 0; i < c; i++) tputs (ND,1,addbuf); break; /* down and over */ case 3: for (i = 0; i < r-curr; i++) addbuf ('\012'); for (i = 0; i < c-curc; i++) tputs (ND,1,addbuf); break; /* down and back */ case 4: for (i = 0; i < r-curr; i++) addbuf ('\012'); for (i = 0; i < curc-c; i++) addbuf ('\010'); break; /* CR and up and over */ case 5: addbuf ('\015'); for (i = 0; i < curr-r; i++) tputs (UP,1,addbuf); for (i = 0; i < c; i++) tputs (ND,1,addbuf); break; /* up and over */ case 6: for (i = 0; i < curr-r; i++) tputs (UP,1,addbuf); for (i = 0; i < c-curc; i++) tputs (ND,1,addbuf); break; /* up and back */ case 7: for (i = 0; i < curr-r; i++) tputs (UP,1,addbuf); for (i = 0; i < curc-c; i++) { if (BC) tputs (BC,1,addbuf); else addbuf ('\010'); } break; /* safe space */ case 8: for (i = 0; i < c-curc; i++) addbuf (' '); } /* fix positions */ curr = r; curc = c; realr = -1; realc = -1; } clear () { - register int i; + int i; /* double space if can't clear */ if (CL == 0) { writel ("\n\n"); return; } curr = curc = 0; /* fix position markers */ realr = realc = -1; for (i = 0; i < 24; i++) /* clear line counts */ linect[i] = -1; buffnum = -1; /* ignore leftover buffer contents */ tputs (CL,CO,addbuf); /* put CL in buffer */ } fancyc (c) -register char c; /* character to output */ +char c; /* character to output */ { - register int sp; /* counts spaces in a tab */ + int sp; /* counts spaces in a tab */ if (c == '\007') { /* bells go in blindly */ addbuf (c); return; } /* process tabs, use spaces if the * the tab should be erasing things, * otherwise use cursor movement * routines. Note this does not use * hardware tabs at all. */ if (c == '\t') { sp = (curc+8) & (~ 7); /* compute spaces */ /* check line length */ if (linect[curr] >= curc || sp < 4) { for (; sp > curc; sp--) addbuf (' '); curc = sp; /* fix curc */ } else curmove (curr,sp); return; } /* do newline be calling newline */ if (c == '\n') { newline(); return; } /* ignore any other control chars */ if (c < ' ') return; /* if an erasing space or non-space, * just add it to buffer. Otherwise * use cursor movement routine, so that * multiple spaces will be grouped * together */ if (c > ' ' || linect[curr] >= curc) { newpos (); /* make sure position correct */ addbuf (c); /* add character to buffer */ /* fix line length */ if (c == ' ' && linect[curr] == curc) linect[curr]--; else if (linect[curr] < curc) linect[curr] = curc; curc++; /* fix curc */ } else /* use cursor movement routine */ curmove (curr,curc+1); } clend() { - register int i; - register char *s; + int i; + char *s; if (CD) { tputs (CD,CO-curr,addbuf); for (i = curr; i < LI; i++) linect[i] = -1; return; } curmove (i = curr,0); cline(); while (curr < LI-1) { curmove (curr+1,0); if (linect[curr] > -1) cline (); } curmove (i,0); } cline () { - register int i; - register int c; - register char *s; + int i; + int c; + char *s; if (curc > linect[curr]) return; newpos (); if (CE) { tputs (CE,1,addbuf); linect[curr] = curc-1; } else { c = curc-1; while (linect[curr] > c) { addbuf (' '); curc++; linect[curr]--; } curmove (curr,c+1); } } newline () { cline(); if (curr == LI-1) curmove (begscr,0); else curmove (curr+1,0); } int getcaps (s) const char *s; { - register char *code; /* two letter code */ - register char ***cap; /* pointer to cap string */ + char *code; /* two letter code */ + char ***cap; /* pointer to cap string */ char *bufp; /* pointer to cap buffer */ char tentry[1024]; /* temporary uncoded caps buffer */ tgetent (tentry, (char *)s); /* get uncoded termcap entry */ LI = tgetnum ("li"); /* get number of lines */ if (LI == -1) LI = 12; CO = tgetnum ("co"); /* get number of columns */ if (CO == -1) CO = 65; bufp = tbuf; /* get padding character */ tgetstr ("pc",&bufp); if (bufp != tbuf) PC = *tbuf; else PC = 0; bufp = tbuf; /* get string entries */ cap = tstr; for (code = tcap; *code; code += 2) **cap++ = (char *)tgetstr (code,&bufp); /* get pertinent lengths */ if (HO) lHO = strlen (HO); if (BC) lBC = strlen (BC); else lBC = 1; if (UP) lUP = strlen (UP); if (ND) lND = strlen (ND); if (LI < 24 || CO < 72 || !(CL && UP && ND)) return (0); linect = (int *)calloc (LI+1,sizeof(int)); return (1); } diff --git a/games/backgammon/common_source/odds.c b/games/backgammon/common_source/odds.c index a989d65565df..d3e21e42442e 100644 --- a/games/backgammon/common_source/odds.c +++ b/games/backgammon/common_source/odds.c @@ -1,115 +1,115 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)odds.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" odds (r1,r2,val) -register int r1; +int r1; int r2, val; { - register int i, j; + int i, j; if (r1 == 0) { for (i = 0; i < 6; i++) for (j = 0; j < 6; j++) table[i][j] = 0; return; } else { r1--; if (r2-- == 0) for (i = 0; i < 6; i++) { table[i][r1] += val; table[r1][i] += val; } else { table[r2][r1] += val; table[r1][r2] += val; } } } count () { - register int i; - register int j; - register int total; + int i; + int j; + int total; total = 0; for (i = 0; i < 6; i++) for (j = 0; j < 6; j++) total += table[i][j]; return (total); } canhit (i,c) int i, c; { - register int j, k, b; + int j, k, b; int a, d, diff, place, addon, menstuck; if (c == 0) odds (0,0,0); if (board[i] > 0) { a = -1; b = 25; } else { a = 1; b = 0; } place = abs (25-b-i); menstuck = abs (board[b]); for (j = b; j != i; j += a) { if (board[j]*a > 0) { diff = abs(j-i); addon = place+((board[j]*a > 2 || j == b)? 5: 0); if ((j == b && menstuck == 1) && (j != b && menstuck == 0)) for (k = 1; k < diff; k++) if (k < 7 && diff-k < 7 && (board[i+a*k]*a >= 0 || board[i+a*(diff-k)] >= 0)) odds (k,diff-k,addon); if ((j == b || menstuck < 2) && diff < 7) odds (diff,0,addon); } if (j == b && menstuck > 1) break; } return (count()); } diff --git a/games/backgammon/common_source/one.c b/games/backgammon/common_source/one.c index a8dda644c190..e62a59fdf184 100644 --- a/games/backgammon/common_source/one.c +++ b/games/backgammon/common_source/one.c @@ -1,171 +1,171 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)one.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" makmove (i) -register int i; +int i; { - register int n, d; + int n, d; int max; d = d0; n = abs(g[i]-p[i]); max = (*offptr < 0? 7: last()); if (board[p[i]]*cturn <= 0) return (checkd(d)+2); if (g[i] != home && board[g[i]]*cturn < -1) return (checkd(d)+3); if (i || D0 == D1) { if (n == max? D1 < n: D1 != n) return (checkd(d)+1); } else { if (n == max? D0 < n && D1 < n: D0 != n && D1 != n) return (checkd(d)+1); if (n == max? D0 < n: D0 != n) { if (d0) return (checkd(d)+1); swap; } } if (g[i] == home && *offptr < 0) return (checkd(d)+4); h[i] = 0; board[p[i]] -= cturn; if (g[i] != home) { if (board[g[i]] == -cturn) { board[home] -= cturn; board[g[i]] = 0; h[i] = 1; if (abs(bar-g[i]) < 7) { (*inopp)--; if (*offopp >= 0) *offopp -= 15; } } board[g[i]] += cturn; if (abs(home-g[i]) < 7 && abs(home-p[i]) > 6) { (*inptr)++; if (*inptr+*offptr == 0) *offptr += 15; } } else { (*offptr)++; (*inptr)--; } return (0); } moverr (i) -register int i; +int i; { - register int j; + int j; if (tflag) curmove (20,0); else writec ('\n'); writel ("Error: "); for (j = 0; j <= i; j++) { wrint (p[j]); writec ('-'); wrint (g[j]); if (j < i) writec (','); } writel ("... "); movback (i); } checkd (d) -register int d; +int d; { if (d0 != d) swap; return (0); } last () { - register int i; + int i; for (i = home-6*cturn; i != home; i += cturn) if (board[i]*cturn > 0) return (abs(home-i)); } movback (i) -register int i; +int i; { - register int j; + int j; for (j = i-1; j >= 0; j--) backone(j); } backone (i) -register int i; +int i; { board[p[i]] += cturn; if (g[i] != home) { board[g[i]] -= cturn; if (abs(g[i]-home) < 7 && abs(p[i]-home) > 6) { (*inptr)--; if (*inptr+*offptr < 15 && *offptr >= 0) *offptr -= 15; } } else { (*offptr)--; (*inptr)++; } if (h[i]) { board[home] += cturn; board[g[i]] = -cturn; if (abs(bar-g[i]) < 7) { (*inopp)++; if (*inopp+*offopp == 0) *offopp += 15; } } } diff --git a/games/backgammon/common_source/save.c b/games/backgammon/common_source/save.c index a82939b74600..674c1926758f 100644 --- a/games/backgammon/common_source/save.c +++ b/games/backgammon/common_source/save.c @@ -1,184 +1,184 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include "back.h" static const char confirm[] = "Are you sure you want to leave now?"; static const char prompt[] = "Enter a file name: "; static const char exist1[] = "The file '"; static const char exist2[] = "' already exists.\nAre you sure you want to use this file?"; static const char cantuse[] = "\nCan't use "; static const char saved[] = "This game has been saved on the file '"; static const char type[] = "'.\nType \"backgammon "; static const char rec[] = "\" to recover your game.\n\n"; static const char cantrec[] = "Can't recover file: "; save (n) -register int n; +int n; { - register int fdesc; - register char *fs; + int fdesc; + char *fs; char fname[50]; if (n) { if (tflag) { curmove (20,0); clend(); } else writec ('\n'); writel (confirm); if (! yorn(0)) return; } cflag = 1; for (;;) { writel (prompt); fs = fname; while ((*fs = readc()) != '\n') { if (*fs == tty.sg_erase) { if (fs > fname) { fs--; if (tflag) curmove (curr,curc-1); else writec (*fs); } else writec ('\007'); continue; } writec (*fs++); } *fs = '\0'; if ((fdesc = open(fname,O_RDWR)) == -1 && errno == ENOENT) { if ((fdesc = creat (fname,0600)) != -1) break; } if (fdesc != -1) { if (tflag) { curmove (18,0); clend(); } else writec ('\n'); writel (exist1); writel (fname); writel (exist2); cflag = 0; close (fdesc); if (yorn (0)) { unlink (fname); fdesc = creat (fname,0700); break; } else { cflag = 1; continue; } } writel (cantuse); writel (fname); writel (".\n"); close (fdesc); cflag = 1; } write (fdesc,board,sizeof board); write (fdesc,off,sizeof off); write (fdesc,in,sizeof in); write (fdesc,dice,sizeof dice); write (fdesc,&cturn,sizeof cturn); write (fdesc,&dlast,sizeof dlast); write (fdesc,&pnum,sizeof pnum); write (fdesc,&rscore,sizeof rscore); write (fdesc,&wscore,sizeof wscore); write (fdesc,&gvalue,sizeof gvalue); write (fdesc,&raflag,sizeof raflag); close (fdesc); if (tflag) curmove (18,0); writel (saved); writel (fname); writel (type); writel (fname); writel (rec); if (tflag) clend(); getout (); } int recover (s) const char *s; { - register int i; + int i; int fdesc; if ((fdesc = open (s,O_RDONLY)) == -1) norec (s); read (fdesc,board,sizeof board); read (fdesc,off,sizeof off); read (fdesc,in,sizeof in); read (fdesc,dice,sizeof dice); read (fdesc,&cturn,sizeof cturn); read (fdesc,&dlast,sizeof dlast); read (fdesc,&pnum,sizeof pnum); read (fdesc,&rscore,sizeof rscore); read (fdesc,&wscore,sizeof wscore); read (fdesc,&gvalue,sizeof gvalue); read (fdesc,&raflag,sizeof raflag); close (fdesc); rflag = 1; } int norec (s) const char *s; { const char *c; tflag = 0; writel (cantrec); c = s; while (*c != '\0') writec (*c++); getout (); } diff --git a/games/backgammon/common_source/subs.c b/games/backgammon/common_source/subs.c index a54ee4bb9dd2..d60bf4a129f7 100644 --- a/games/backgammon/common_source/subs.c +++ b/games/backgammon/common_source/subs.c @@ -1,481 +1,481 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)subs.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include "back.h" int buffnum; char outbuff[BUFSIZ]; static const char plred[] = "Player is red, computer is white."; static const char plwhite[] = "Player is white, computer is red."; static const char nocomp[] = "(No computer play.)"; const char *const descr[] = { "Usage: backgammon [-h n r w b pr pw pb tterm sfile]\n", "\t-h\tgets this list\n\t-n\tdon't ask for rules or instructions", "\t-r\tplayer is red (implies -n)\n\t-w\tplayer is white (implies -n)", "\t-b\ttwo players, red and white (implies -n)", "\t-pr\tprint the board before red's turn", "\t-pw\tprint the board before white's turn", "\t-pb\tprint the board before both player's turn", "\t-tterm\tterminal is a term", "\t-sfile\trecover saved game from file", 0 }; errexit (s) -register char *s; +char *s; { write (2,"\n",1); perror (s); getout(); } int addbuf (c) -register int c; +int c; { buffnum++; if (buffnum == BUFSIZ) { if (write(1,outbuff,BUFSIZ) != BUFSIZ) errexit ("addbuf (write):"); buffnum = 0; } outbuff[buffnum] = c; return (0); } buflush () { if (buffnum < 0) return; buffnum++; if (write (1,outbuff,buffnum) != buffnum) errexit ("buflush (write):"); buffnum = -1; } readc () { char c; if (tflag) { cline(); newpos(); } buflush(); if (read(0,&c,1) != 1) errexit ("readc"); #ifdef WHY_IS_THIS_HARDWIRED_IN_HERE if (c == '\177') getout(); #endif if (c == '\033' || c == '\015') return ('\n'); if (cflag) return (c); if (c == '\014') return ('R'); if (c >= 'a' && c <= 'z') return (c & 0137); return (c); } writec (c) char c; { if (tflag) fancyc (c); else addbuf (c); } void writel (l) const char *l; { #ifdef DEBUG const char *s; if (trace == NULL) trace = fopen ("bgtrace","w"); fprintf (trace,"writel: \""); for (s = l; *s; s++) { if (*s < ' ' || *s == '\177') fprintf (trace,"^%c",(*s)^0100); else putc (*s,trace); } fprintf (trace,"\"\n"); fflush (trace); #endif while (*l) writec (*l++); } proll () { if (d0) swap; if (cturn == 1) writel ("Red's roll: "); else writel ("White's roll: "); writec (D0+'0'); writec ('\040'); writec (D1+'0'); if (tflag) cline(); } wrint (n) int n; { - register int i, j, t; + int i, j, t; for (i = 4; i > 0; i--) { t = 1; for (j = 0; j t-1) writec ((n/t)%10+'0'); } writec (n%10+'0'); } gwrite() { - register int r, c; + int r, c; if (tflag) { r = curr; c = curc; curmove (16,0); } if (gvalue > 1) { writel ("Game value: "); wrint (gvalue); writel (". "); if (dlast == -1) writel (color[0]); else writel (color[1]); writel (" doubled last."); } else { switch (pnum) { case -1: /* player is red */ writel (plred); break; case 0: /* player is both colors */ writel (nocomp); break; case 1: /* player is white */ writel (plwhite); } } if (rscore || wscore) { writel (" "); wrscore(); } if (tflag) { cline(); curmove (r,c); } } quit () { - register int i; + int i; if (tflag) { curmove (20,0); clend(); } else writec ('\n'); writel ("Are you sure you want to quit?"); if (yorn (0)) { if (rfl) { writel ("Would you like to save this game?"); if (yorn(0)) save(0); } cturn = 0; return (1); } return (0); } yorn (special) -register char special; /* special response */ +char special; /* special response */ { - register char c; - register int i; + char c; + int i; i = 1; while ( (c = readc()) != 'Y' && c != 'N') { if (special && c == special) return (2); if (i) { if (special) { writel (" (Y, N, or "); writec (special); writec (')'); } else writel (" (Y or N)"); i = 0; } else writec ('\007'); } if (c == 'Y') writel (" Yes.\n"); else writel (" No.\n"); if (tflag) buflush(); return (c == 'Y'); } wrhit (i) -register int i; +int i; { writel ("Blot hit on "); wrint (i); writec ('.'); writec ('\n'); } nexturn () { - register int c; + int c; cturn = -cturn; c = cturn/abs(cturn); home = bar; bar = 25-bar; offptr += c; offopp -= c; inptr += c; inopp -= c; Colorptr += c; colorptr += c; } getarg (argc, argv) -register int argc; -register char **argv; +int argc; +char **argv; { - register char ch; + char ch; extern int optind; extern char *optarg; int i; /* process arguments here. dashes are ignored, nbrw are ignored if the game is being recovered */ while ((ch = getopt (argc, argv, "nbrwp:t:s:h")) != -1) { switch (ch) { /* don't ask if rules or instructions needed */ case 'n': if (rflag) break; aflag = 0; args[acnt++] = strdup ("-n"); break; /* player is both red and white */ case 'b': if (rflag) break; pnum = 0; aflag = 0; args[acnt++] = strdup ("-b"); break; /* player is red */ case 'r': if (rflag) break; pnum = -1; aflag = 0; args[acnt++] = strdup ("-r"); break; /* player is white */ case 'w': if (rflag) break; pnum = 1; aflag = 0; args[acnt++] = strdup ("-w"); break; /* print board after move according to following character */ case 'p': if (optarg[0] != 'r' && optarg[0] != 'w' && optarg[0] != 'b') break; args[acnt] = strdup ("-p "); args[acnt++][2] = optarg[0]; if (optarg[0] == 'r') bflag = 1; if (optarg[0] == 'w') bflag = -1; if (optarg[0] == 'b') bflag = 0; break; case 't': tflag = getcaps (optarg); break; case 's': /* recover file */ recover (optarg); break; case 'h': for (i = 0; descr[i] != 0; i++) puts (descr[i]); getout(); } } argc -= optind; argv += optind; if ( argc && argv[0][0] != '\0' ) recover(argv[0]); } init () { - register int i; + int i; for (i = 0; i < 26;) board[i++] = 0; board[1] = 2; board[6] = board[13] = -5; board[8] = -3; board[12] = board[19] = 5; board[17] = 3; board[24] = -2; off[0] = off[1] = -15; in[0] = in[1] = 5; gvalue = 1; dlast = 0; } wrscore () { writel ("Score: "); writel (color[1]); writec (' '); wrint (rscore); writel (", "); writel (color[0]); writec (' '); wrint (wscore); } fixtty (mode) int mode; { if (tflag) newpos(); buflush(); tty.sg_flags = mode; if (stty (0,&tty) < 0) errexit("fixtty"); } void getout () { /* go to bottom of screen */ if (tflag) { curmove (23,0); cline(); } else writec ('\n'); /* fix terminal status */ fixtty (old); exit(0); } roll () { - register char c; - register int row; - register int col; + char c; + int row; + int col; if (iroll) { if (tflag) { row = curr; col = curc; curmove (17,0); } else writec ('\n'); writel ("ROLL: "); c = readc(); if (c != '\n') { while (c < '1' || c > '6') c = readc(); D0 = c-'0'; writec (' '); writec (c); c = readc(); while (c < '1' || c > '6') c = readc(); D1 = c-'0'; writec (' '); writec (c); if (tflag) { curmove (17,0); cline(); curmove (row,col); } else writec ('\n'); return; } if (tflag) { curmove (17,0); cline(); curmove (row,col); } else writec ('\n'); } D0 = rnum(6)+1; D1 = rnum(6)+1; d0 = 0; } diff --git a/games/backgammon/common_source/table.c b/games/backgammon/common_source/table.c index d8f074dc1022..b64f09b5e088 100644 --- a/games/backgammon/common_source/table.c +++ b/games/backgammon/common_source/table.c @@ -1,310 +1,310 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" const char *const help2[] = { " Enter moves as - or / where is the starting", "position, is the finishing position, and is the roll.", "Remember, each die roll must be moved separately.", 0 }; struct state { char ch; int fcode; int newst; }; static const struct state atmata[] = { 'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25, '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19, '1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25, '0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0, '/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1, '6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28, '2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61, '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53, '1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61, '0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39, '\n', 0, -1, '.', 0, 0 }; checkmove (ist) int ist; { - register int j, n; - register char c; + int j, n; + char c; char a; domove: if (ist == 0) { if (tflag) curmove (curr,32); else writel ("\t\t"); writel ("Move: "); } ist = mvl = ncin = 0; for (j = 0; j < 5; j++) p[j] = g[j] = -1; dochar: c = readc(); if (c == 'S') { raflag = 0; save (1); if (tflag) { curmove (cturn == -1? 18: 19,39); ist = -1; goto domove; } else { proll (); ist = 0; goto domove; } } if (c == tty.sg_erase && ncin > 0) { if (tflag) curmove (curr,curc-1); else { if (tty.sg_erase == '\010') writel ("\010 \010"); else writec (cin[ncin-1]); } ncin--; n = rsetbrd(); if (n == 0) { n = -1; if (tflag) refresh(); } if ((ist = n) > 0) goto dochar; goto domove; } if (c == tty.sg_kill && ncin > 0) { if (tflag) { refresh(); curmove (curr,39); ist = -1; goto domove; } else if (tty.sg_erase == '\010') { for (j = 0; j < ncin; j++) writel ("\010 \010"); ist = -1; goto domove; } else { writec ('\\'); writec ('\n'); proll (); ist = 0; goto domove; } } n = dotable(c,ist); if (n >= 0) { cin[ncin++] = c; if (n > 2) if ((! tflag) || c != '\n') writec (c); ist = n; if (n) goto dochar; else goto domove; } if (n == -1 && mvl >= mvlim) return(0); if (n == -1 && mvl < mvlim-1) return(-4); if (n == -6) { if (! tflag) { if (movokay(mvl+1)) { wrboard(); movback (mvl+1); } proll (); writel ("\t\tMove: "); for (j = 0; j < ncin;) writec (cin[j++]); } else { if (movokay(mvl+1)) { refresh(); movback (mvl+1); } else curmove (cturn == -1? 18:19,ncin+39); } ist = n = rsetbrd(); goto dochar; } if (n != -5) return(n); writec ('\007'); goto dochar; } dotable (c,i) char c; -register int i; +int i; { - register int a, j; + int a, j; int test; test = (c == 'R'); while ( (a = atmata[i].ch) != '.') { if (a == c || (test && a == '\n')) { switch (atmata[i].fcode) { case 1: wrboard(); if (tflag) { curmove (cturn == -1? 18: 19,0); proll (); writel ("\t\t"); } else proll (); break; case 2: if (p[mvl] == -1) p[mvl] = c-'0'; else p[mvl] = p[mvl]*10+c-'0'; break; case 3: if (g[mvl] != -1) { if (mvl < mvlim) mvl++; p[mvl] = p[mvl-1]; } g[mvl] = p[mvl]+cturn*(c-'0'); if (g[mvl] < 0) g[mvl] = 0; if (g[mvl] > 25) g[mvl] = 25; break; case 4: if (g[mvl] == -1) g[mvl] = c-'0'; else g[mvl] = g[mvl]*10+c-'0'; break; case 5: if (mvl < mvlim) mvl++; p[mvl] = g[mvl-1]; break; case 6: if (mvl < mvlim) mvl++; break; case 7: if (tflag) curmove (20,0); else writec ('\n'); text (help2); if (tflag) { curmove (cturn == -1? 18: 19,39); } else { writec ('\n'); proll(); writel ("\t\tMove: "); } break; case 8: p[mvl] = bar; break; case 9: g[mvl] = home; } if (! test || a != '\n') return (atmata[i].newst); else return (-6); } i++; } return (-5); } rsetbrd () { - register int i, j, n; + int i, j, n; n = 0; mvl = 0; for (i = 0; i < 4; i++) p[i] = g[i] = -1; for (j = 0; j < ncin; j++) n = dotable (cin[j],n); return (n); } diff --git a/games/backgammon/teachgammon/teach.c b/games/backgammon/teachgammon/teach.c index 2aa1409e0e6b..64e7aa76af56 100644 --- a/games/backgammon/teachgammon/teach.c +++ b/games/backgammon/teachgammon/teach.c @@ -1,177 +1,177 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include "back.h" extern char *hello[]; extern char *list[]; extern char *intro1[]; extern char *intro2[]; extern char *moves[]; extern char *remove[]; extern char *hits[]; extern char *endgame[]; extern char *doubl[]; extern char *stragy[]; extern char *prog[]; extern char *lastch[]; extern char ospeed; /* tty output speed for termlib */ const char *const helpm[] = { "\nEnter a space or newline to roll, or", " b to display the board", " d to double", " q to quit\n", 0 }; const char *const contin[] = { "", 0 }; main (argc,argv) int argc; char **argv; { - register int i; + int i; /* revoke privs */ setgid(getgid()); acnt = 1; signal (SIGINT,getout); if (gtty (0,&tty) == -1) /* get old tty mode */ errexit ("teachgammon(gtty)"); old = tty.sg_flags; #ifdef V7 raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */ #else raw = ((noech = old & ~ECHO) | RAW); /* set up modes */ #endif ospeed = tty.sg_ospeed; /* for termlib */ tflag = getcaps (getenv ("TERM")); getarg (argc, argv); if (tflag) { noech &= ~(CRMOD|XTABS); raw &= ~(CRMOD|XTABS); clear(); } text (hello); text (list); i = text (contin); if (i == 0) i = 2; init(); while (i) switch (i) { case 1: leave(); case 2: if (i = text(intro1)) break; wrboard(); if (i = text(intro2)) break; case 3: if (i = text(moves)) break; case 4: if (i = text(remove)) break; case 5: if (i = text(hits)) break; case 6: if (i = text(endgame)) break; case 7: if (i = text(doubl)) break; case 8: if (i = text(stragy)) break; case 9: if (i = text(prog)) break; case 10: if (i = text(lastch)) break; } tutor(); } leave() { - register int i; + int i; if (tflag) clear(); else writec ('\n'); fixtty(old); args[0] = strdup("backgammon"); args[acnt++] = strdup("-n"); args[acnt] = 0; execv (EXEC,args); for (i = 0; i < acnt; i++) free (args[i]); writel ("Help! Backgammon program is missing\007!!\n"); exit (-1); } diff --git a/games/backgammon/teachgammon/tutor.c b/games/backgammon/teachgammon/tutor.c index 4409ba9d0961..4b3370b37168 100644 --- a/games/backgammon/teachgammon/tutor.c +++ b/games/backgammon/teachgammon/tutor.c @@ -1,159 +1,159 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "back.h" #include "tutor.h" extern int maxmoves; extern const char *const finis[]; extern const struct situatn test[]; static const char better[] = "That is a legal move, but there is a better one.\n"; void tutor () { - register int i, j; + int i, j; i = 0; begscr = 18; cturn = -1; home = 0; bar = 25; inptr = &in[0]; inopp = &in[1]; offptr = &off[0]; offopp = &off[1]; Colorptr = &color[0]; colorptr = &color[2]; colen = 5; wrboard(); while (1) { if (! brdeq(test[i].brd,board)) { if (tflag && curr == 23) curmove (18,0); writel (better); nexturn(); movback (mvlim); if (tflag) { refresh(); clrest (); } if ((! tflag) || curr == 19) { proll(); writec ('\t'); } else curmove (curr > 19? curr-2: curr+4,25); getmove(); if (cturn == 0) leave(); continue; } if (tflag) curmove (18,0); text (*test[i].com); if (! tflag) writec ('\n'); if (i == maxmoves) break; D0 = test[i].roll1; D1 = test[i].roll2; d0 = 0; mvlim = 0; for (j = 0; j < 4; j++) { if (test[i].mp[j] == test[i].mg[j]) break; p[j] = test[i].mp[j]; g[j] = test[i].mg[j]; mvlim++; } if (mvlim) for (j = 0; j < mvlim; j++) if (makmove(j)) writel ("AARGH!!!\n"); if (tflag) refresh(); nexturn(); D0 = test[i].new1; D1 = test[i].new2; d0 = 0; i++; mvlim = movallow(); if (mvlim) { if (tflag) clrest(); proll(); writec('\t'); getmove(); if (tflag) refresh(); if (cturn == 0) leave(); } } leave(); } clrest () { - register int r, c, j; + int r, c, j; r = curr; c = curc; for (j = r+1; j < 24; j++) { curmove (j,0); cline(); } curmove (r,c); } int brdeq (b1,b2) const int *b1, *b2; { const int *e; e = b1+26; while (b1 < e) if (*b1++ != *b2++) return(0); return(1); } diff --git a/games/battlestar/com1.c b/games/battlestar/com1.c index 643f037234f7..6dd600ae2e05 100644 --- a/games/battlestar/com1.c +++ b/games/battlestar/com1.c @@ -1,252 +1,252 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)com1.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" move(thataway, token) int thataway, token; { wordnumber++; if ((!notes[CANTMOVE] && !notes[LAUNCHED]) || testbit(location[position].objects, LAND) || fuel > 0 && notes[LAUNCHED]) if (thataway) { position = thataway; newway(token); gtime++; } else { puts("You can't go this way."); newway(token); whichway(location[position]); return(0); } else if (notes[CANTMOVE] && !notes[LAUNCHED]) puts("You aren't able to move; you better drop something."); else puts("You are out of fuel; now you will rot in space forever!"); return(1); } convert(tothis) /* Converts day to night and vice versa. */ int tothis; /* Day objects are permanent. Night objects are added*/ { /* at dusk, and subtracted at dawn. */ const struct objs *p; - register i, j; + int i, j; if (tothis == TONIGHT) { for (i = 1; i <= NUMOFROOMS; i++) for (j = 0; j < NUMOFWORDS; j++) nightfile[i].objects[j] = dayfile[i].objects[j]; for (p = nightobjs; p->room != 0; p++) setbit(nightfile[p->room].objects, p->obj); location = nightfile; } else { for (i = 1; i <= NUMOFROOMS; i++) for (j = 0; j < NUMOFWORDS; j++) dayfile[i].objects[j] = nightfile[i].objects[j]; for (p = nightobjs; p->room != 0; p++) clearbit(dayfile[p->room].objects, p->obj); location = dayfile; } } news() { - register int n; + int n; int hurt; if (gtime > 30 && position < 32){ puts("An explosion of shuddering magnitude splinters bulkheads and"); puts("ruptures the battlestar's hull. You are sucked out into the"); puts("frozen void of space and killed."); die(); } if (gtime > 20 && position < 32) puts("Explosions rock the battlestar."); if (gtime > snooze){ puts("You drop from exhaustion..."); zzz(); } if (gtime > snooze - 5) puts("You're getting tired."); if (gtime > (rythmn + CYCLE)) { if (location == nightfile) { convert(TODAY); if (OUTSIDE && gtime - rythmn - CYCLE < 10) { puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn."); puts("You awake from a misty dream-world into stark reality."); puts("It is day."); } } else { convert(TONIGHT); clearbit(location[POOLS].objects, BATHGOD); if (OUTSIDE && gtime - rythmn - CYCLE < 10) { puts("The dying sun sinks into the ocean, leaving a blood stained sunset."); puts("The sky slowly fades from orange to violet to black. A few stars"); puts("flicker on, and it is night."); puts("The world seems completly different at night."); } } rythmn = gtime - gtime % CYCLE; } if (!wiz && !tempwiz) if ((testbit(inven,TALISMAN) || testbit(wear,TALISMAN)) && (testbit(inven,MEDALION) || testbit(wear,MEDALION)) && (testbit(inven,AMULET) || testbit(wear,AMULET))){ tempwiz = 1; puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard."); } if (testbit(location[position].objects,ELF)){ printf("%s\n",objdes[ELF]); fight(ELF,rnd(30)); } if (testbit(location[position].objects,DARK)){ printf("%s\n",objdes[DARK]); fight(DARK,100); } if (testbit(location[position].objects,WOODSMAN)){ printf("%s\n",objdes[WOODSMAN]); fight(WOODSMAN,50); } switch(position){ case 267: case 257: /* entering a cave */ case 274: case 246: notes[CANTSEE] = 1; break; case 160: case 216: /* leaving a cave */ case 230: case 231: case 232: notes[CANTSEE] = 0; break; } if (testbit(location[position].objects, GIRL)) meetgirl = 1; if (meetgirl && CYCLE * 1.5 - gtime < 10){ setbit(location[GARDEN].objects,GIRLTALK); setbit(location[GARDEN].objects,LAMPON); setbit(location[GARDEN].objects,ROPE); } if (position == DOCK && (beenthere[position] || gtime > CYCLE)){ clearbit(location[DOCK].objects, GIRL); clearbit(location[DOCK].objects,MAN); } if (meetgirl && gtime - CYCLE * 1.5 > 10){ clearbit(location[GARDEN].objects,GIRLTALK); clearbit(location[GARDEN].objects,LAMPON); clearbit(location[GARDEN].objects,ROPE); meetgirl = 0; } if (testbit(location[position].objects,CYLON)){ puts("Oh my God, you're being shot at by an alien spacecraft!"); printf("The targeting computer says we have %d seconds to attack!\n",gclock); fflush(stdout); sleep(1); if (!visual()){ hurt = rnd(NUMOFINJURIES); injuries[hurt] = 1; puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll."); puts("The viper shudders under a terrible explosion."); printf("I'm afraid you have suffered %s.\n", ouch[hurt]); } else clearbit(location[position].objects,CYLON); } if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]){ puts("I'm afraid you have suffered fatal injuries."); die(); } for (n=0; n < NUMOFINJURIES; n++) if (injuries[n] == 1){ injuries[n] = 2; if (WEIGHT > 5) WEIGHT -= 5; else WEIGHT = 0; } if (injuries[ARM] == 2){ CUMBER -= 5; injuries[ARM]++; } if (injuries[RIBS] == 2){ CUMBER -= 2; injuries[RIBS]++; } if (injuries[SPINE] == 2){ WEIGHT = 0; injuries[SPINE]++; } if (carrying > WEIGHT || encumber > CUMBER) notes[CANTMOVE] = 1; else notes[CANTMOVE] = 0; } crash() { int hurt1,hurt2; fuel--; if (!location[position].flyhere || (testbit(location[position].objects,LAND) && fuel <= 0)){ if (!location[position].flyhere) puts("You're flying too low. We're going to crash!"); else{ puts("You're out of fuel. We'll have to crash land!"); if (!location[position].down){ puts("Your viper strikes the ground and explodes into firey fragments."); puts("Thick black smoke billows up from the wreckage."); die(); } position = location[position].down; } notes[LAUNCHED] = 0; setbit(location[position].objects,CRASH); gtime += rnd(CYCLE/4); puts("The viper explodes into the ground and you lose consciousness..."); zzz(); hurt1 = rnd(NUMOFINJURIES - 2) + 2; hurt2 = rnd(NUMOFINJURIES - 2) + 2; injuries[hurt1] = 1; injuries[hurt2] = 1; injuries[0] = 1; /* abrasions */ injuries[1] = 1; /* lacerations */ printf("I'm afraid you have suffered %s and %s.\n",ouch[hurt1],ouch[hurt2]); } } diff --git a/games/battlestar/com2.c b/games/battlestar/com2.c index 45a91318426e..4f2dc1d5d0f6 100644 --- a/games/battlestar/com2.c +++ b/games/battlestar/com2.c @@ -1,299 +1,299 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)com2.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" wearit() /* synonyms = {sheathe, sheath} */ { - register int n; + int n; int firstnumber, value; firstnumber = wordnumber; while(wordtype[++wordnumber] == ADJS); while(wordnumber <= wordcount){ value = wordvalue[wordnumber]; for (n=0; objsht[value][n]; n++); switch(value){ case -1: puts("Wear what?"); return(firstnumber); default: printf("You can't wear%s%s!\n",(objsht[value][n-1] == 's' ? " " : " a "),objsht[value]); return(firstnumber); case KNIFE: /* case SHIRT: */ case ROBE: case LEVIS: /* wearable things */ case SWORD: case MAIL: case HELM: case SHOES: case PAJAMAS: case COMPASS: case LASER: case AMULET: case TALISMAN: case MEDALION: case ROPE: case RING: case BRACELET: case GRENADE: if (testbit(inven,value)){ clearbit(inven,value); setbit(wear,value); carrying -= objwt[value]; encumber -= objcumber[value]; gtime++; printf("You are now wearing %s %s.\n",(objsht[value][n-1] == 's' ? "the" : "a"), objsht[value]); } else if (testbit(wear,value)) printf("You are already wearing the %s.\n", objsht[value]); else printf("You aren't holding the %s.\n", objsht[value]); if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(firstnumber); } /* end switch */ } /* end while */ puts("Don't be ridiculous."); return(firstnumber); } put() /* synonyms = {buckle, strap, tie} */ { if (wordvalue[wordnumber + 1] == ON){ wordvalue[++wordnumber] = PUTON; return(cypher()); } if (wordvalue[wordnumber + 1] == DOWN){ wordvalue[++wordnumber] = DROP; return(cypher()); } puts("I don't understand what you want to put."); return(-1); } draw() /* synonyms = {pull, carry} */ { return(take(wear)); } use() { while (wordtype[++wordnumber] == ADJS && wordnumber < wordcount); if (wordvalue[wordnumber] == AMULET && testbit(inven,AMULET) && position != FINAL){ puts("The amulet begins to glow."); if (testbit(inven,MEDALION)){ puts("The medallion comes to life too."); if (position == 114){ location[position].down = 160; whichway(location[position]); puts("The waves subside and it is possible to descend to the sea cave now."); gtime++; return(-1); } } puts("A light mist falls over your eyes and the sound of purling water trickles in"); puts("your ears. When the mist lifts you are standing beside a cool stream."); if (position == 229) position = 224; else position = 229; gtime++; notes[CANTSEE] = 0; return(0); } else if (position == FINAL) puts("The amulet won't work in here."); else if (wordvalue[wordnumber] == COMPASS && testbit(inven,COMPASS)) printf("Your compass points %s.\n",truedirec(NORTH,'-')); else if (wordvalue[wordnumber] == COMPASS) puts("You aren't holding the compass."); else if (wordvalue[wordnumber] == AMULET) puts("You aren't holding the amulet."); else puts("There is no apparent use."); return(-1); } murder() { - register int n; + int n; for (n=0; !((n == SWORD || n == KNIFE || n == TWO_HANDED || n == MACE || n == CLEAVER || n == BROAD || n == CHAIN || n == SHOVEL || n == HALBERD) && testbit(inven,n)) && n < NUMOFOBJECTS; n++); if (n == NUMOFOBJECTS) puts("You don't have suitable weapons to kill."); else { printf("Your %s should do the trick.\n",objsht[n]); while (wordtype[++wordnumber] == ADJS); switch(wordvalue[wordnumber]){ case NORMGOD: if (testbit(location[position].objects,BATHGOD)){ puts("The goddess's head slices off. Her corpse floats in the water."); clearbit(location[position].objects,BATHGOD); setbit(location[position].objects,DEADGOD); power += 5; notes[JINXED]++; } else if (testbit(location[position].objects,NORMGOD)){ puts("The goddess pleads but you strike her mercilessly. Her broken body lies in a\npool of blood."); clearbit(location[position].objects,NORMGOD); setbit(location[position].objects,DEADGOD); power += 5; notes[JINXED]++; if (wintime) live(); } else puts("I dont see her anywhere."); break; case TIMER: if (testbit(location[position].objects,TIMER)){ puts("The old man offers no resistance."); clearbit(location[position].objects,TIMER); setbit(location[position].objects,DEADTIME); power++; notes[JINXED]++; } else puts("Who?"); break; case NATIVE: if (testbit(location[position].objects,NATIVE)){ puts("The girl screams as you cut her body to shreds. She is dead."); clearbit(location[position].objects,NATIVE); setbit(location[position].objects,DEADNATIVE); power += 5; notes[JINXED]++; } else puts("What girl?"); break; case MAN: if (testbit(location[position].objects,MAN)){ puts("You strike him to the ground, and he coughs up blood."); puts("Your fantasy is over."); die(); } case -1: puts("Kill what?"); break; default: if (wordtype[wordnumber] != NOUNS) puts("Kill what?"); else printf("You can't kill the %s!\n",objsht[wordvalue[wordnumber]]); } } } ravage() { while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ gtime++; switch(wordvalue[wordnumber]){ case NORMGOD: puts("You attack the goddess, and she screams as you beat her. She falls down"); puts("crying and tries to hold her torn and bloodied dress around her."); power += 5; pleasure += 8; ego -= 10; wordnumber--; godready = -30000; murder(); win = -30000; break; case NATIVE: puts("The girl tries to run, but you catch her and throw her down. Her face is"); puts("bleeding, and she screams as you tear off her clothes."); power += 3; pleasure += 5; ego -= 10; wordnumber--; murder(); if (rnd(100) < 50){ puts("Her screams have attracted attention. I think we are surrounded."); setbit(location[ahead].objects,WOODSMAN); setbit(location[ahead].objects,DEADWOOD); setbit(location[ahead].objects,MALLET); setbit(location[back].objects,WOODSMAN); setbit(location[back].objects,DEADWOOD); setbit(location[back].objects,MALLET); setbit(location[left].objects,WOODSMAN); setbit(location[left].objects,DEADWOOD); setbit(location[left].objects,MALLET); setbit(location[right].objects,WOODSMAN); setbit(location[right].objects,DEADWOOD); setbit(location[right].objects,MALLET); } break; default: puts("You are perverted."); } } else puts("Who?"); } follow() { if (followfight == gtime){ puts("The Dark Lord leaps away and runs down secret tunnels and corridors."); puts("You chase him through the darkness and splash in pools of water."); puts("You have cornered him. His laser sword extends as he steps forward."); position = FINAL; fight(DARK,75); setbit(location[position].objects,TALISMAN); setbit(location[position].objects,AMULET); return(0); } else if (followgod == gtime){ puts("The goddess leads you down a steamy tunnel and into a high, wide chamber."); puts("She sits down on a throne."); position = 268; setbit(location[position].objects,NORMGOD); notes[CANTSEE] = 1; return(0); } else puts("There is no one to follow."); return(-1); } diff --git a/games/battlestar/com3.c b/games/battlestar/com3.c index bd9dd7463840..e0184d2fa610 100644 --- a/games/battlestar/com3.c +++ b/games/battlestar/com3.c @@ -1,314 +1,314 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)com3.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" dig() { if (testbit(inven,SHOVEL)){ puts("OK"); gtime++; switch(position){ case 144: /* copse near beach */ if (!notes[DUG]){ setbit(location[position].objects,DEADWOOD); setbit(location[position].objects,COMPASS); setbit(location[position].objects,KNIFE); setbit(location[position].objects,MACE); notes[DUG] = 1; } break; default: puts("Nothing happens."); } } else puts("You don't have a shovel."); } jump() { - register int n; + int n; switch(position){ default: puts("Nothing happens."); return(-1); case 242: position = 133; break; case 214: case 215: case 162: case 159: position = 145; break; case 232: position = 275; break; case 3: position = 1; break; case 172: position = 201; } puts("Ahhhhhhh..."); injuries[12] = injuries[8] = injuries[7] = injuries[6] = 1; for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n)){ clearbit(inven,n); setbit(location[position].objects,n); } carrying = 0; encumber = 0; return(0); } bury() { int value; if (testbit(inven,SHOVEL)){ while(wordtype[++wordnumber] != OBJECT && wordtype[wordnumber] != NOUNS && wordnumber < wordcount); value = wordvalue[wordnumber]; if (wordtype[wordnumber] == NOUNS && (testbit(location[position].objects,value) || value == BODY)) switch(value){ case BODY: wordtype[wordnumber] = OBJECT; if (testbit(inven,MAID) || testbit(location[position].objects,MAID)) value = MAID; if (testbit(inven,DEADWOOD) || testbit(location[position].objects,DEADWOOD)) value = DEADWOOD; if (testbit(inven,DEADGOD) || testbit(location[position].objects,DEADGOD)) value = DEADGOD; if (testbit(inven,DEADTIME) || testbit(location[position].objects,DEADTIME)) value = DEADTIME; if (testbit(inven,DEADNATIVE) || testbit(location[position].objects,DEADNATIVE)) value = DEADNATIVE; break; case NATIVE: case NORMGOD: puts("She screams as you wrestle her into the hole."); case TIMER: power += 7; ego -= 10; case AMULET: case MEDALION: case TALISMAN: wordtype[wordnumber] = OBJECT; break; default: puts("Wha..?"); } if (wordtype[wordnumber] == OBJECT && position > 88 && (testbit(inven,value) || testbit(location[position].objects,value))){ puts("Buried."); if (testbit(inven,value)){ clearbit(inven,value); carrying -= objwt[value]; encumber -= objcumber[value]; } clearbit(location[position].objects,value); switch(value){ case MAID: case DEADWOOD: case DEADNATIVE: case DEADTIME: case DEADGOD: ego += 2; printf("The %s should rest easier now.\n",objsht[value]); } } else puts("It doesn't seem to work."); } else puts("You aren't holding a shovel."); } drink() { - register int n; + int n; if (testbit(inven,POTION)){ puts("The cool liquid runs down your throat but turns to fire and you choke."); puts("The heat reaches your limbs and tingles your spirit. You feel like falling"); puts("asleep."); clearbit(inven, POTION); WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; for (n=0; n < NUMOFINJURIES; n++) injuries[n] = 0; gtime++; zzz(); } else puts("I'm not thirsty."); } shoot() { int firstnumber, value; - register int n; + int n; firstnumber = wordnumber; if (!testbit(inven,LASER)) puts("You aren't holding a blaster."); else { while(wordtype[++wordnumber] == ADJS); while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){ value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); for (n=0; objsht[value][n]; n++); if (testbit(location[position].objects,value)){ clearbit(location[position].objects,value); gtime++; printf("The %s explode%s\n",objsht[value],(objsht[value][n-1]=='s' ? (objsht[value][n-2]=='s' ? "s." : ".") : "s.")); if (value == BOMB) die(); } else printf("I dont see any %s around here.\n", objsht[value]); if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(firstnumber); } /* special cases with their own return()'s */ if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS){ gtime++; switch(wordvalue[wordnumber]){ case DOOR: switch(position){ case 189: case 231: puts("The door is unhinged."); location[189].north = 231; location[231].south = 189; whichway(location[position]); break; case 30: puts("The wooden door splinters."); location[30].west = 25; whichway(location[position]); break; case 31: puts("The laser blast has no effect on the door."); break; case 20: puts("The blast hits the door and it explodes into flame. The magnesium burns"); puts("so rapidly that we have no chance to escape."); die(); default: puts("Nothing happens."); } break; case NORMGOD: if (testbit(location[position].objects,BATHGOD)){ puts("The goddess is hit in the chest and splashes back against the rocks."); puts("Dark blood oozes from the charred blast hole. Her naked body floats in the"); puts("pools and then off downstream."); clearbit(location[position].objects,BATHGOD); setbit(location[180].objects,DEADGOD); power += 5; ego -= 10; notes[JINXED]++; } else if (testbit(location[position].objects,NORMGOD)){ puts("The blast catches the goddess in the stomach, knocking her to the ground."); puts("She writhes in the dirt as the agony of death taunts her."); puts("She has stopped moving."); clearbit(location[position].objects,NORMGOD); setbit(location[position].objects,DEADGOD); power += 5; ego -= 10; notes[JINXED]++; if (wintime) live(); break; } else puts("I don't see any goddess around here."); break; case TIMER: if (testbit(location[position].objects,TIMER)){ puts("The old man slumps over the bar."); power++; ego -= 2; notes[JINXED]++; clearbit(location[position].objects,TIMER); setbit(location[position].objects,DEADTIME); } else puts("What old timer?"); break; case MAN: if (testbit(location[position].objects,MAN)){ puts("The man falls to the ground with blood pouring all over his white suit."); puts("Your fantasy is over."); die(); } else puts("What man?"); break; case NATIVE: if (testbit(location[position].objects,NATIVE)){ puts("The girl is blown backwards several feet and lies in a pool of blood."); clearbit(location[position].objects,NATIVE); setbit(location[position].objects,DEADNATIVE); power += 5; ego -= 2; notes[JINXED]++; } else puts("There is no girl here."); break; case -1: puts("Shoot what?"); break; default: printf("You can't shoot the %s.\n",objsht[wordvalue[wordnumber]]); } } else puts("You must be a looney."); } return(firstnumber); } diff --git a/games/battlestar/com4.c b/games/battlestar/com4.c index 9af086b2fb26..ab610fd56e2c 100644 --- a/games/battlestar/com4.c +++ b/games/battlestar/com4.c @@ -1,382 +1,382 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)com4.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include "externs.h" take(from) unsigned int from[]; { int firstnumber, heavy, bulky, value; - register int n; + int n; firstnumber = wordnumber; if (wordnumber < wordcount && wordvalue[wordnumber+1] == OFF){ wordnumber++; wordvalue[wordnumber] = TAKEOFF; return(cypher()); } else { while(wordtype[++wordnumber] == ADJS); while(wordnumber<=wordcount && wordtype[wordnumber] == OBJECT){ value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); for (n=0; objsht[value][n]; n++); heavy = (carrying + objwt[value]) <= WEIGHT; bulky = (encumber + objcumber[value]) <= CUMBER; if ((testbit(from,value) || wiz || tempwiz) && heavy && bulky && !testbit(inven,value)){ setbit(inven,value); carrying += objwt[value]; encumber += objcumber[value]; gtime++; if (testbit(from,value)) printf("Taken.\n"); else printf("Zap! Taken from thin air.\n"); clearbit(from,value); if (value == MEDALION) win--; } else if (testbit(inven,value)) printf("You're already holding%s%s.\n", (objsht[value][n-1] == 's' ? " " : " a "),objsht[value]); else if (!heavy) printf("The %s %s too heavy.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); else if (!bulky) printf("The %s %s too cumbersome to hold.\n", objsht[value],(objsht[value][n-1] == 's' ? "are" : "is")); else printf("I dont see any %s around here.\n", objsht[value]); if (wordnumber < wordcount -1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(firstnumber); } } /* special cases with their own return()'s */ if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) switch(wordvalue[wordnumber]){ case SWORD: if (testbit(from, SWORD)){ wordtype[wordnumber--] = OBJECT; return(take(from)); } if (testbit(from, TWO_HANDED)){ wordvalue[wordnumber] = TWO_HANDED; wordtype[wordnumber--] = OBJECT; return(take(from)); } wordvalue[wordnumber] = BROAD; wordtype[wordnumber--] = OBJECT; return(take(from)); case BODY: if (testbit(from,MAID)){ wordvalue[wordnumber] = MAID; wordtype[wordnumber--] = OBJECT; return(take(from)); } else if (testbit(from,DEADWOOD)){ wordvalue[wordnumber] = DEADWOOD; wordtype[wordnumber--] = OBJECT; return(take(from)); } else if (testbit(from,DEADNATIVE)){ wordvalue[wordnumber] = DEADNATIVE; wordtype[wordnumber--] = OBJECT; return(take(from)); } else if (testbit(from,DEADGOD)){ wordvalue[wordnumber] = DEADGOD; wordtype[wordnumber--] = OBJECT; return(take(from)); } else { wordvalue[wordnumber] = DEADTIME; wordtype[wordnumber--] = OBJECT; return(take(from)); } break; case AMULET: if (testbit(location[position].objects,AMULET)){ puts("The amulet is warm to the touch, and its beauty catches your breath."); puts("A mist falls over your eyes, but then it is gone. Sounds seem clearer"); puts("and sharper but far away as if in a dream. The sound of purling water reaches"); puts("you from afar. The mist falls again, and your heart leaps in horror. The gold"); puts("freezes your hands and fathomless darkness engulfs your soul."); } wordtype[wordnumber--] = OBJECT; return(take(from)); case MEDALION: if (testbit(location[position].objects, MEDALION)){ puts("The medallion is warm, and it rekindles your spirit with the warmth of life."); puts("Your amulet begins to glow as the medallion is brought near to it, and together\nthey radiate."); } wordtype[wordnumber--] = OBJECT; return(take(from)); case TALISMAN: if (testbit(location[position].objects,TALISMAN)){ puts("The talisman is cold to the touch, and it sends a chill down your spine."); } wordtype[wordnumber--] = OBJECT; return(take(from)); case NORMGOD: if (testbit(location[position].objects,BATHGOD) && (testbit(wear,AMULET) || testbit(inven,AMULET))){ puts("She offers a delicate hand, and you help her out of the sparkling springs."); puts("Water droplets like liquid silver bedew her golden skin, but when they part"); puts("from her, they fall as teardrops. She wraps a single cloth around her and"); puts("ties it at the waist. Around her neck hangs a golden amulet."); puts("She bids you to follow her."); pleasure++; followgod = gtime; clearbit(location[position].objects,BATHGOD); } else if (!testbit(location[position].objects,BATHGOD)) puts("You're in no position to take her."); else puts("She moves away from you."); break; default: puts("It doesn't seem to work."); } else puts("You've got to be kidding."); return(firstnumber); } throw(name) const char *name; { int n; int deposit = 0; int first, value; first = wordnumber; if (drop(name) != -1){ switch(wordvalue[wordnumber]){ case AHEAD: deposit = ahead; break; case BACK: deposit = back; break; case LEFT: deposit = left; break; case RIGHT: deposit = right; break; case UP: deposit = location[position].up * (location[position].access || position == FINAL); break; case DOWN: deposit = location[position].down; break; } wordnumber = first; while (wordtype[++wordnumber] == ADJS); while (wordnumber <= wordcount){ value = wordvalue[wordnumber]; if (deposit && testbit(location[position].objects,value)){ clearbit(location[position].objects,value); if (value != GRENADE) setbit(location[deposit].objects,value); else{ puts("A thundering explosion nearby sends up a cloud of smoke and shrapnel."); for (n = 0; n < NUMOFWORDS; n ++) location[deposit].objects[n] = 0; setbit(location[deposit].objects,CHAR); } if (value == ROPE && position == FINAL) location[position].access = 1; switch(deposit){ case 189: case 231: puts("The stone door is unhinged."); location[189].north = 231; location[231].south = 189; break; case 30: puts("The wooden door is blown open."); location[30].west = 25; break; case 31: puts("The door is not damaged."); } } else if (value == GRENADE && testbit(location[position].objects,value)){ puts("You are blown into shreds when your grenade explodes."); die(); } if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(first); } return(first); } return(first); } drop(name) const char *name; { int firstnumber, value; firstnumber = wordnumber; while (wordtype[++wordnumber] == ADJS) ; while (wordnumber<=wordcount && (wordtype[wordnumber] == OBJECT || wordtype[wordnumber] == NOUNS)) { value = wordvalue[wordnumber]; printf("%s:\n", objsht[value]); if (testbit(inven,value)){ clearbit(inven,value); carrying -= objwt[value]; encumber -= objcumber[value]; if (value == BOMB){ puts("The bomb explodes. A blinding white light and immense concussion obliterate us."); die(); } if (value != AMULET && value != MEDALION && value != TALISMAN) setbit(location[position].objects,value); else tempwiz = 0; gtime++; if (*name == 'K') puts("Drop kicked."); else printf("%s.\n", name); } else { if (*name != 'K') { printf("You aren't holding the %s.\n", objsht[value]); if (testbit(location[position].objects,value)) { if (*name == 'T') puts("Kicked instead."); else if (*name == 'G') puts("Given anyway."); } } else puts("Kicked."); } if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(firstnumber); } puts("Do what?"); return(-1); } takeoff() { wordnumber = take(wear); return(drop("Dropped")); } puton() { wordnumber = take(location[position].objects); return(wearit()); } eat() { int firstnumber, value; firstnumber = wordnumber; while(wordtype[++wordnumber] == ADJS); while(wordnumber <= wordcount){ value = wordvalue[wordnumber]; switch(value){ case -1: puts("Eat what?"); return(firstnumber); default: printf("You can't eat%s%s!\n", wordtype[wordnumber] == OBJECT && objsht[value] [strlen(objsht[value]) - 1] == 's' ? " " : " a ", words[wordnumber]); return(firstnumber); case PAPAYAS: case PINEAPPLE: case KIWI: case COCONUTS: /* eatable things */ case MANGO: printf("%s:\n",objsht[value]); if (testbit(inven,value) && gtime > ate - CYCLE && testbit(inven,KNIFE)){ clearbit(inven,value); carrying -= objwt[value]; encumber -= objcumber[value]; ate = max(gtime,ate) + CYCLE/3; snooze += CYCLE/10; gtime++; puts("Eaten. You can explore a little longer now."); } else if (gtime < ate - CYCLE) puts("You're stuffed."); else if (!testbit(inven,KNIFE)) puts("You need a knife."); else printf("You aren't holding the %s.\n", objsht[value]); if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND) wordnumber++; else return(firstnumber); } /* end switch */ } /* end while */ return(firstnumber); } diff --git a/games/battlestar/com5.c b/games/battlestar/com5.c index d3b18fb3f63e..f3cb6a8ba234 100644 --- a/games/battlestar/com5.c +++ b/games/battlestar/com5.c @@ -1,341 +1,341 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)com5.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" kiss() { while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ pleasure++; printf("Kissed.\n"); switch (wordvalue[wordnumber]){ case NORMGOD: switch(godready++){ case 0: puts("She squirms and avoids your advances."); break; case 1: puts("She is coming around; she didn't fight it as much."); break; case 2: puts("She's begining to like it."); break; default: puts("She's gone limp."); } break; case NATIVE: puts("The lips are warm and her body robust. She pulls you down to the ground."); break; case TIMER: puts("The old man blushes."); break; case MAN: puts("The dwarf punches you in the kneecap."); break; default: pleasure--; } } else puts("I'd prefer not to."); } love() { - register int n; + int n; while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount); if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){ if (wordvalue[wordnumber] == NORMGOD && !loved) { if (godready >= 2){ puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet. The lovely goddess, Purl, was she. The Empire\ncaptured her just after the Darkness came. My other sister, Vert, was killed\nby the Dark Lord himself. He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill. I will leave you my amulet."); puts("which you may use as you wish. As for me, I am the last goddess of the\nwaters. My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed."); power++; pleasure += 15; ego++; if (card(injuries, NUMOFINJURIES)){ puts("Her kisses revive you; your wounds are healed.\n"); for (n=0; n < NUMOFINJURIES; n++) injuries[n] = 0; WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; } printf("Goddess:\n"); if (!loved) setbit(location[position].objects,MEDALION); loved = 1; gtime += 10; zzz(); } else { puts("You wish!"); return; } } if (wordvalue[wordnumber] == NATIVE){ puts("The girl is easy prey. She peels off her sarong and indulges you."); power++; pleasure += 5; printf("Girl:\n"); gtime += 10; zzz(); } printf("Loved.\n"); } else puts("I't doesn't seem to work."); } zzz() { int oldtime; - register int n; + int n; oldtime = gtime; if ((snooze - gtime) < (0.75 * CYCLE)){ gtime += 0.75 * CYCLE - (snooze - gtime); printf(""); for (n = 0; n < gtime - oldtime; n++) printf("."); printf("\n"); snooze += 3 * (gtime - oldtime); if (notes[LAUNCHED]){ fuel -= (gtime - oldtime); if (location[position].down){ position = location[position].down; crash(); } else notes[LAUNCHED] = 0; } if (OUTSIDE && rnd(100) < 50){ puts("You are awakened abruptly by the sound of someone nearby."); switch(rnd(4)){ case 0: if (ucard(inven)){ n = rnd(NUMOFOBJECTS); while(!testbit(inven,n)) n = rnd(NUMOFOBJECTS); clearbit(inven,n); if (n != AMULET && n != MEDALION && n != TALISMAN) setbit(location[position].objects,n); carrying -= objwt[n]; encumber -= objcumber[n]; } puts("A fiendish little Elf is stealing your treasures!"); fight(ELF,10); break; case 1: setbit(location[position].objects,DEADWOOD); break; case 2: setbit(location[position].objects,HALBERD); break; default: break; } } } else return(0); return(1); } chime() { if ((gtime / CYCLE + 1) % 2 && OUTSIDE) switch((gtime % CYCLE)/(CYCLE / 7)){ case 0: puts("It is just after sunrise."); break; case 1: puts("It is early morning."); break; case 2: puts("It is late morning."); break; case 3: puts("It is near noon."); break; case 4: puts("It is early afternoon."); break; case 5: puts("It is late afternoon."); break; case 6: puts("It is near sunset."); break; } else if (OUTSIDE) switch((gtime % CYCLE)/(CYCLE / 7)){ case 0: puts("It is just after sunset."); break; case 1: puts("It is early evening."); break; case 2: puts("The evening is getting old."); break; case 3: puts("It is near midnight."); break; case 4: puts("These are the wee hours of the morning."); break; case 5: puts("The night is waning."); break; case 6: puts("It is almost morning."); break; } else puts("I can't tell the time in here."); } give() { int obj = -1, result = -1, person = 0, firstnumber, last1, last2; firstnumber = wordnumber; while (wordtype[++wordnumber] != OBJECT && wordvalue[wordnumber] != AMULET && wordvalue[wordnumber] != MEDALION && wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount); if (wordnumber <= wordcount){ obj = wordvalue[wordnumber]; if (obj == EVERYTHING) wordtype[wordnumber] = -1; last1 = wordnumber; } wordnumber = firstnumber; while ((wordtype[++wordnumber] != NOUNS || wordvalue[wordnumber] == obj) && wordnumber <= wordcount); if (wordtype[wordnumber] == NOUNS){ person = wordvalue[wordnumber]; last2 = wordnumber; } /* Setting wordnumber to last1 - 1 looks wrong if last1 is 0, e.g., * plain `give'. However, detecting this case is liable to detect * `give foo' as well, which would give a confusing error. We * need to make sure the -1 value can cause no problems if it arises. * If in the below we get to the drop("Given") then drop will look * at word 0 for an object to give, and fail, which is OK; then * result will be -1 and we get to the end, where wordnumber gets * set to something more sensible. If we get to "I don't think * that is possible" then again wordnumber is set to something * sensible. The wordnumber we leave with still isn't right if * you include words the game doesn't know in your command, but * that's no worse than what other commands than give do in * the same place. */ wordnumber = last1 - 1; if (person && testbit(location[position].objects,person)) if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET)) puts("The goddess won't look at you."); else result = drop("Given"); else { puts("I don't think that is possible."); wordnumber = max(last1, last2) + 1; return(0); } if (result != -1 && (testbit(location[position].objects,obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)){ clearbit(location[position].objects,obj); gtime++; ego++; switch(person){ case NATIVE: puts("She accepts it shyly."); ego += 2; break; case NORMGOD: if (obj == RING || obj == BRACELET){ puts("She takes the charm and puts it on. A little kiss on the cheek is"); puts("your reward."); ego += 5; godready += 3; } if (obj == AMULET || obj == MEDALION || obj == TALISMAN){ win++; ego += 5; power -= 5; if (win >= 3){ puts("The powers of the earth are now legitimate. You have destroyed the Darkness"); puts("and restored the goddess to her thrown. The entire island celebrates with"); puts("dancing and spring feasts. As a measure of her gratitude, the goddess weds you"); puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus."); puts("\nBut, as the year wears on and autumn comes along, you become restless and"); puts("yearn for adventure. The goddess, too, realizes that the marriage can't last."); puts("She becomes bored and takes several more natives as husbands. One evening,"); puts("after having been out drinking with the girls, she kicks the throne particularly"); puts("hard and wakes you up. (If you want to win this game, you're going to have to\nshoot her!)"); clearbit(location[position].objects,MEDALION); wintime = gtime; } } break; case TIMER: if (obj == COINS){ puts("He fingers the coins for a moment and then looks up agape. `Kind you are and"); puts("I mean to repay you as best I can.' Grabbing a pencil and cocktail napkin...\n"); printf( "+-----------------------------------------------------------------------------+\n"); printf( "| xxxxxxxx\\ |\n"); printf( "| xxxxx\\ CLIFFS |\n"); printf( "| FOREST xxx\\ |\n"); printf( "| \\\\ x\\ OCEAN |\n"); printf( "| || x\\ |\n"); printf( "| || ROAD x\\ |\n"); printf( "| || x\\ |\n"); printf( "| SECRET || ......... |\n"); printf( "| - + - || ........ |\n"); printf( "| ENTRANCE || ... BEACH |\n"); printf( "| || ... E |\n"); printf( "| || ... | |\n"); printf( "| // ... N <-- + --- S |\n"); printf( "| PALM GROVE // ... | |\n"); printf( "| // ... W |\n"); printf( "+-----------------------------------------------------------------------------+\n"); puts("\n`This map shows a secret entrance to the catacombs."); puts("You will know when you arrive because I left an old pair of shoes there.'"); } break; } } wordnumber = max(last1,last2) + 1; return(firstnumber); } diff --git a/games/battlestar/cypher.c b/games/battlestar/cypher.c index af65af4e4d76..f15d81643b6b 100644 --- a/games/battlestar/cypher.c +++ b/games/battlestar/cypher.c @@ -1,432 +1,432 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)cypher.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" cypher() { - register int n; + int n; int junk; int lflag = -1; char buffer[10]; while (wordtype[wordnumber] == ADJS) wordnumber++; while (wordnumber <= wordcount) { switch(wordvalue[wordnumber]) { case UP: if (location[position].access || wiz || tempwiz) { if (!location[position].access) puts("Zap! A gust of wind lifts you up."); if (!move(location[position].up, AHEAD)) return(-1); } else { puts("There is no way up"); return(-1); } lflag = 0; break; case DOWN: if (!move(location[position].down, AHEAD)) return(-1); lflag = 0; break; case LEFT: if (!move(left, LEFT)) return(-1); lflag = 0; break; case RIGHT: if (!move(right, RIGHT)) return(-1); lflag = 0; break; case AHEAD: if (!move(ahead, AHEAD)) return(-1); lflag = 0; break; case BACK: if (!move(back, BACK)) return(-1); lflag = 0; break; case SHOOT: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects,n) && objsht[n]){ wordvalue[wordnumber+1] = n; wordnumber = shoot(); } wordnumber++; wordnumber++; } else shoot(); break; case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects,n) && objsht[n]){ wordvalue[wordnumber+1] = n; wordnumber = take(location[position].objects); } wordnumber++; wordnumber++; } else take(location[position].objects); break; case DROP: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n)){ wordvalue[wordnumber+1] = n; wordnumber = drop("Dropped"); } wordnumber++; wordnumber++; } else drop("Dropped"); break; case KICK: case THROW: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n) || testbit(location[position].objects, n) && objsht[n]){ wordvalue[wordnumber+1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } wordnumber += 2; } else throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); break; case TAKEOFF: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(wear,n)){ wordvalue[wordnumber+1] = n; wordnumber = takeoff(); } wordnumber += 2; } else takeoff(); break; case DRAW: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(wear,n)){ wordvalue[wordnumber+1] = n; wordnumber = draw(); } wordnumber += 2; } else draw(); break; case PUTON: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects,n) && objsht[n]){ wordvalue[wordnumber+1] = n; wordnumber = puton(); } wordnumber += 2; } else puton(); break; case WEARIT: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n)){ wordvalue[wordnumber+1] = n; wordnumber = wearit(); } wordnumber += 2; } else wearit(); break; case EAT: if (wordnumber < wordcount && wordvalue[wordnumber+1] == EVERYTHING){ for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n)){ wordvalue[wordnumber+1] = n; wordnumber = eat(); } wordnumber += 2; } else eat(); break; case PUT: put(); break; case INVEN: if (ucard(inven)){ puts("You are holding:\n"); for (n=0; n < NUMOFOBJECTS; n++) if (testbit(inven,n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."),(WEIGHT ? carrying*100/WEIGHT : -1)); printf("Your arms are %d%% full.\n",encumber*100/CUMBER); } else puts("You aren't carrying anything."); if (ucard(wear)){ puts("\nYou are wearing:\n"); for (n=0; n < NUMOFOBJECTS; n++) if (testbit(wear,n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); if (card(injuries,NUMOFINJURIES)){ puts("\nYou have suffered:\n"); for (n=0; n < NUMOFINJURIES; n++) if (injuries[n]) printf("\t%s\n",ouch[n]); printf("\nYou can still carry up to %d kilogram%s\n",WEIGHT,(WEIGHT == 1 ? "." : "s.")); } else puts("\nYou are in perfect health."); break; case USE: lflag = use(); break; case LOOK: if (!notes[CANTSEE] || testbit(inven,LAMPON) || testbit(location[position].objects,LAMPON) || matchlight){ beenthere[position] = 2; writedes(); printobjs(); if (matchlight){ puts("\nYour match splutters out."); matchlight = 0; } } else puts("I can't see anything."); return(-1); break; case SU: if (wiz || tempwiz){ printf("\nRoom (was %d) = ", position); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d", &position); printf("Time (was %d) = ",gtime); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d", >ime); printf("Fuel (was %d) = ",fuel); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d", &fuel); printf("Torps (was %d) = ",torps); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d", &torps); printf("CUMBER (was %d) = ",CUMBER); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d", &CUMBER); printf("WEIGHT (was %d) = ",WEIGHT); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d",&WEIGHT); printf("Clock (was %d) = ",gclock); fgets(buffer,10,stdin); if (*buffer != '\n') sscanf(buffer,"%d",&gclock); printf("Wizard (was %d, %d) = ",wiz, tempwiz); fgets(buffer,10,stdin); if (*buffer != '\n'){ sscanf(buffer,"%d",&junk); if (!junk) tempwiz = wiz = 0; } printf("\nDONE.\n"); return(0); } else puts("You aren't a wizard."); break; case SCORE: printf("\tPLEASURE\tPOWER\t\tEGO\n"); printf("\t%3d\t\t%3d\t\t%3d\n\n",pleasure,power,ego); printf("This gives you the rating of %s in %d turns.\n",rate(),gtime); printf("You have visited %d out of %d rooms this run (%d%%).\n",card(beenthere,NUMOFROOMS),NUMOFROOMS,card(beenthere,NUMOFROOMS)*100/NUMOFROOMS); break; case KNIFE: case KILL: murder(); break; case UNDRESS: case RAVAGE: ravage(); break; case SAVE: save(); break; case FOLLOW: lflag = follow(); break; case GIVE: give(); break; case KISS: kiss(); break; case LOVE: love(); break; case RIDE: lflag = ride(); break; case DRIVE: lflag = drive(); break; case LIGHT: light(); break; case LAUNCH: if (!launch()) return(-1); else lflag = 0; break; case LANDIT: if (!land()) return(-1); else lflag = 0; break; case TIME: chime(); break; case SLEEP: zzz(); break; case DIG: dig(); break; case JUMP: lflag = jump(); break; case BURY: bury(); break; case SWIM: puts("Surf's up!"); break; case DRINK: drink(); break; case QUIT: die(); default: puts("How's that?"); return(-1); break; } if (wordnumber < wordcount && *words[wordnumber++] == ',') continue; else return(lflag); } return(lflag); } diff --git a/games/battlestar/fly.c b/games/battlestar/fly.c index 9d229be277c1..80f23b7c1f84 100644 --- a/games/battlestar/fly.c +++ b/games/battlestar/fly.c @@ -1,286 +1,286 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)fly.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" #undef UP #include #include #define abs(a) ((a) < 0 ? -(a) : (a)) #define MIDR (LINES/2 - 1) #define MIDC (COLS/2 - 1) int row, column; int dr = 0, dc = 0; char destroyed; int gclock = 120; /* gtime for all the flights in the game */ char cross = 0; sig_t oldsig; void succumb() { if (oldsig == SIG_DFL) { endfly(); exit(1); } if (oldsig != SIG_IGN) { endfly(); (*oldsig)(SIGINT); } } visual() { void moveenemy(); destroyed = 0; if(initscr() == ERR){ puts("Whoops! No more memory..."); return(0); } oldsig = signal(SIGINT, succumb); crmode(); noecho(); screen(); row = rnd(LINES-3) + 1; column = rnd(COLS-2) + 1; moveenemy(); for (;;) { switch(getchar()){ case 'h': case 'r': dc = -1; fuel--; break; case 'H': case 'R': dc = -5; fuel -= 10; break; case 'l': dc = 1; fuel--; break; case 'L': dc = 5; fuel -= 10; break; case 'j': case 'u': dr = 1; fuel--; break; case 'J': case 'U': dr = 5; fuel -= 10; break; case 'k': case 'd': dr = -1; fuel--; break; case 'K': case 'D': dr = -5; fuel -= 10; break; case '+': if (cross){ cross = 0; notarget(); } else cross = 1; break; case ' ': case 'f': if (torps){ torps -= 2; blast(); if (row == MIDR && column - MIDC < 2 && MIDC - column < 2){ destroyed = 1; alarm(0); } } else mvaddstr(0,0,"*** Out of torpedoes. ***"); break; case 'q': endfly(); return(0); default: mvaddstr(0,26,"Commands = r,R,l,L,u,U,d,D,f,+,q"); continue; case EOF: break; } if (destroyed){ endfly(); return(1); } if (gclock <= 0){ endfly(); die(); } } } screen() { - register int r,c,n; + int r,c,n; int i; clear(); i = rnd(100); for (n=0; n < i; n++){ r = rnd(LINES-3) + 1; c = rnd(COLS); mvaddch(r, c, '.'); } mvaddstr(LINES-1-1,21,"TORPEDOES FUEL TIME"); refresh(); } target() { - register int n; + int n; move(MIDR,MIDC-10); addstr("------- + -------"); for (n = MIDR-4; n < MIDR-1; n++){ mvaddch(n,MIDC,'|'); mvaddch(n+6,MIDC,'|'); } } notarget() { - register int n; + int n; move(MIDR,MIDC-10); addstr(" "); for (n = MIDR-4; n < MIDR-1; n++){ mvaddch(n,MIDC,' '); mvaddch(n+6,MIDC,' '); } } blast() { - register int n; + int n; alarm(0); move(LINES-1, 24); printw("%3d", torps); for(n = LINES-1-2; n >= MIDR + 1; n--){ mvaddch(n, MIDC+MIDR-n, '/'); mvaddch(n, MIDC-MIDR+n, '\\'); refresh(); } mvaddch(MIDR,MIDC,'*'); for(n = LINES-1-2; n >= MIDR + 1; n--){ mvaddch(n, MIDC+MIDR-n, ' '); mvaddch(n, MIDC-MIDR+n, ' '); refresh(); } alarm(1); } void moveenemy() { double d; int oldr, oldc; oldr = row; oldc = column; if (fuel > 0){ if (row + dr <= LINES-3 && row + dr > 0) row += dr; if (column + dc < COLS-1 && column + dc > 0) column += dc; } else if (fuel < 0){ fuel = 0; mvaddstr(0,60,"*** Out of fuel ***"); } d = (double) ((row - MIDR)*(row - MIDR) + (column - MIDC)*(column - MIDC)); if (d < 16){ row += (rnd(9) - 4) % (4 - abs(row - MIDR)); column += (rnd(9) - 4) % (4 - abs(column - MIDC)); } gclock--; mvaddstr(oldr, oldc - 1, " "); if (cross) target(); mvaddstr(row, column - 1, "/-\\"); move(LINES-1, 24); printw("%3d", torps); move(LINES-1, 42); printw("%3d", fuel); move(LINES-1, 57); printw("%3d", gclock); refresh(); signal(SIGALRM, moveenemy); alarm(1); } endfly() { alarm(0); signal(SIGALRM, SIG_DFL); mvcur(0,COLS-1,LINES-1,0); endwin(); signal(SIGTSTP, SIG_DFL); signal(SIGINT, oldsig); } diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c index 7d3a37e5af76..f2772bfe1a05 100644 --- a/games/battlestar/getcom.c +++ b/games/battlestar/getcom.c @@ -1,101 +1,101 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)getcom.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include char * getcom(buf, size, prompt, error) char *buf; int size; const char *prompt, *error; { for (;;) { fputs(prompt, stdout); if (fgets(buf, size, stdin) == 0) { clearerr(stdin); continue; } while (isspace(*buf)) buf++; if (*buf) break; if (error) puts(error); } return (buf); } /* * shifts to UPPERCASE if flag > 0, lowercase if flag < 0, * and leaves it unchanged if flag = 0 */ char * getword(buf1, buf2, flag) - register char *buf1, *buf2; - register flag; + char *buf1, *buf2; + int flag; { while (isspace(*buf1)) buf1++; if (*buf1 != ',') { if (!*buf1) { *buf2 = 0; return (0); } while (*buf1 && !isspace(*buf1) && *buf1 != ',') if (flag < 0) if (isupper(*buf1)) *buf2++ = tolower(*buf1++); else *buf2++ = *buf1++; else if (flag > 0) if (islower(*buf1)) *buf2++ = toupper(*buf1++); else *buf2++ = *buf1++; else *buf2++ = *buf1++; } else *buf2++ = *buf1++; *buf2 = 0; while (isspace(*buf1)) buf1++; return (*buf1 ? buf1 : 0); } diff --git a/games/battlestar/misc.c b/games/battlestar/misc.c index 158167167ec5..45e9ec27805f 100644 --- a/games/battlestar/misc.c +++ b/games/battlestar/misc.c @@ -1,66 +1,66 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" int card(array, size) /* for beenthere, injuries */ const char *array; int size; { const char *end = array + size; - register int i = 0; + int i = 0; while (array < end) if (*array++) i++; return (i); } int ucard(array) const unsigned int *array; { - register int j = 0, n; + int j = 0, n; for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(array, n)) j++; return (j); } diff --git a/games/battlestar/parse.c b/games/battlestar/parse.c index 7eb72ee1c28b..abab858cd9c0 100644 --- a/games/battlestar/parse.c +++ b/games/battlestar/parse.c @@ -1,104 +1,104 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" wordinit() { - register struct wlist *w; + struct wlist *w; for (w = wlist; w->string; w++) install(w); } int hash(s) const char *s; { - register hashval = 0; + int hashval = 0; while (*s) { hashval += *s++; hashval *= HASHMUL; hashval &= HASHMASK; } return hashval; } struct wlist * lookup(s) const char *s; { - register struct wlist *wp; + struct wlist *wp; for (wp = hashtab[hash(s)]; wp != NULL; wp = wp->next) if (*s == *wp->string && strcmp(s, wp->string) == 0) return wp; return NULL; } install(wp) - register struct wlist *wp; + struct wlist *wp; { int hashval; if (lookup(wp->string) == NULL) { hashval = hash(wp->string); wp->next = hashtab[hashval]; hashtab[hashval] = wp; } else printf("Multiply defined %s.\n", wp->string); } parse() { - register struct wlist *wp; - register n; + struct wlist *wp; + int n; wordnumber = 0; /* for cypher */ for (n = 0; n <= wordcount; n++) { if ((wp = lookup(words[n])) == NULL) { wordvalue[n] = -1; wordtype[n] = -1; } else { wordvalue[n] = wp -> value; wordtype[n] = wp -> article; } } } diff --git a/games/battlestar/room.c b/games/battlestar/room.c index 899291957006..d78cc00bb095 100644 --- a/games/battlestar/room.c +++ b/games/battlestar/room.c @@ -1,228 +1,228 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)room.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include "externs.h" writedes() { int compass; const char *p; - register c; + int c; printf("\n\t%s\n", location[position].name); if (beenthere[position] < 3) { compass = NORTH; for (p = location[position].desc; c = *p++;) if (c != '-' && c != '*' && c != '+') putchar(c); else { if (c != '*') printf(truedirec(compass, c)); compass++; } } } printobjs() { - register int *p = location[position].objects; - register n; + int *p = location[position].objects; + int n; printf("\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(p, n) && objdes[n]) puts(objdes[n]); } whichway(here) struct room here; { switch(direction) { case NORTH: left = here.west; right = here.east; ahead = here.north; back = here.south; break; case SOUTH: left = here.east; right = here.west; ahead = here.south; back = here.north; break; case EAST: left = here.north; right = here.south; ahead = here.east; back = here.west; break; case WEST: left = here.south; right = here.north; ahead = here.west; back = here.east; break; } } const char * truedirec(way, option) int way; char option; { switch(way) { case NORTH: switch(direction) { case NORTH: return("ahead"); case SOUTH: return(option == '+' ? "behind you" : "back"); case EAST: return("left"); case WEST: return("right"); } case SOUTH: switch(direction) { case NORTH: return(option == '+' ? "behind you" : "back"); case SOUTH: return("ahead"); case EAST: return("right"); case WEST: return("left"); } case EAST: switch(direction) { case NORTH: return("right"); case SOUTH: return("left"); case EAST: return("ahead"); case WEST: return(option == '+' ? "behind you" : "back"); } case WEST: switch(direction) { case NORTH: return("left"); case SOUTH: return("right"); case EAST: return(option == '+' ? "behind you" : "back"); case WEST: return("ahead"); } default: printf("Error: room %d. More than four directions wanted.", position); return("!!"); } } newway(thisway) int thisway; { switch(direction){ case NORTH: switch(thisway){ case LEFT: direction = WEST; break; case RIGHT: direction = EAST; break; case BACK: direction = SOUTH; break; } break; case SOUTH: switch(thisway){ case LEFT: direction = EAST; break; case RIGHT: direction = WEST; break; case BACK: direction = NORTH; break; } break; case EAST: switch(thisway){ case LEFT: direction = NORTH; break; case RIGHT: direction = SOUTH; break; case BACK: direction = WEST; break; } break; case WEST: switch(thisway){ case LEFT: direction = SOUTH; break; case RIGHT: direction = NORTH; break; case BACK: direction = EAST; break; } break; } } diff --git a/games/battlestar/save.c b/games/battlestar/save.c index c91070a0a39c..627f82197357 100644 --- a/games/battlestar/save.c +++ b/games/battlestar/save.c @@ -1,181 +1,181 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include /* MAXPATHLEN */ #include #include #include #include "externs.h" void restore() { char *home; char home1[MAXPATHLEN]; - register int n; + int n; int tmp; - register FILE *fp; + FILE *fp; if ( (home = getenv("HOME")) != NULL) sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); else return; if ((fp = fopen(home1, "r")) == 0) { perror(home1); return; } fread(&WEIGHT, sizeof WEIGHT, 1, fp); fread(&CUMBER, sizeof CUMBER, 1, fp); fread(&gclock, sizeof gclock, 1, fp); fread(&tmp, sizeof tmp, 1, fp); location = tmp ? dayfile : nightfile; for (n = 1; n <= NUMOFROOMS; n++) { fread(location[n].link, sizeof location[n].link, 1, fp); fread(location[n].objects, sizeof location[n].objects, 1, fp); } fread(inven, sizeof inven, 1, fp); fread(wear, sizeof wear, 1, fp); fread(injuries, sizeof injuries, 1, fp); fread(notes, sizeof notes, 1, fp); fread(&direction, sizeof direction, 1, fp); fread(&position, sizeof position, 1, fp); fread(>ime, sizeof gtime, 1, fp); fread(&fuel, sizeof fuel, 1, fp); fread(&torps, sizeof torps, 1, fp); fread(&carrying, sizeof carrying, 1, fp); fread(&encumber, sizeof encumber, 1, fp); fread(&rythmn, sizeof rythmn, 1, fp); fread(&followfight, sizeof followfight, 1, fp); fread(&ate, sizeof ate, 1, fp); fread(&snooze, sizeof snooze, 1, fp); fread(&meetgirl, sizeof meetgirl, 1, fp); fread(&followgod, sizeof followgod, 1, fp); fread(&godready, sizeof godready, 1, fp); fread(&win, sizeof win, 1, fp); fread(&wintime, sizeof wintime, 1, fp); fread(&matchlight, sizeof matchlight, 1, fp); fread(&matchcount, sizeof matchcount, 1, fp); fread(&loved, sizeof loved, 1, fp); fread(&pleasure, sizeof pleasure, 1, fp); fread(&power, sizeof power, 1, fp); /* We must check the last read, to catch truncated save files. */ if (fread(&ego, sizeof ego, 1, fp) < 1) errx(1, "save file %s too short", home1); fclose(fp); } void save() { struct stat sbuf; char *home; char home1[MAXPATHLEN]; - register int n; + int n; int tmp, fd; FILE *fp; home = getenv("HOME"); if (home == 0) return; sprintf(home1, "%.*s/Bstar", MAXPATHLEN - 7, home); /* Try to open the file safely. */ if (stat(home1, &sbuf) < 0) { fd = open(home1, O_WRONLY|O_CREAT|O_EXCL, 0600); if (fd < 0) { fprintf(stderr, "Can't create %s\n", home1); return; } } else { if ((sbuf.st_mode & S_IFLNK) == S_IFLNK) { fprintf(stderr, "No symlinks!\n"); return; } fd = open(home1, O_WRONLY|O_EXCL); if (fd < 0) { fprintf(stderr, "Can't open %s for writing\n", home1); return; } } if ((fp = fdopen(fd, "w")) == 0) { perror(home1); return; } printf("Saved in %s.\n", home1); fwrite(&WEIGHT, sizeof WEIGHT, 1, fp); fwrite(&CUMBER, sizeof CUMBER, 1, fp); fwrite(&gclock, sizeof gclock, 1, fp); tmp = location == dayfile; fwrite(&tmp, sizeof tmp, 1, fp); for (n = 1; n <= NUMOFROOMS; n++) { fwrite(location[n].link, sizeof location[n].link, 1, fp); fwrite(location[n].objects, sizeof location[n].objects, 1, fp); } fwrite(inven, sizeof inven, 1, fp); fwrite(wear, sizeof wear, 1, fp); fwrite(injuries, sizeof injuries, 1, fp); fwrite(notes, sizeof notes, 1, fp); fwrite(&direction, sizeof direction, 1, fp); fwrite(&position, sizeof position, 1, fp); fwrite(>ime, sizeof gtime, 1, fp); fwrite(&fuel, sizeof fuel, 1, fp); fwrite(&torps, sizeof torps, 1, fp); fwrite(&carrying, sizeof carrying, 1, fp); fwrite(&encumber, sizeof encumber, 1, fp); fwrite(&rythmn, sizeof rythmn, 1, fp); fwrite(&followfight, sizeof followfight, 1, fp); fwrite(&ate, sizeof ate, 1, fp); fwrite(&snooze, sizeof snooze, 1, fp); fwrite(&meetgirl, sizeof meetgirl, 1, fp); fwrite(&followgod, sizeof followgod, 1, fp); fwrite(&godready, sizeof godready, 1, fp); fwrite(&win, sizeof win, 1, fp); fwrite(&wintime, sizeof wintime, 1, fp); fwrite(&matchlight, sizeof matchlight, 1, fp); fwrite(&matchcount, sizeof matchcount, 1, fp); fwrite(&loved, sizeof loved, 1, fp); fwrite(&pleasure, sizeof pleasure, 1, fp); fwrite(&power, sizeof power, 1, fp); fwrite(&ego, sizeof ego, 1, fp); } diff --git a/games/bcd/bcd.c b/games/bcd/bcd.c index f3542b65ac57..3e0595376fd1 100644 --- a/games/bcd/bcd.c +++ b/games/bcd/bcd.c @@ -1,219 +1,219 @@ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Steve Hayman of the Indiana University Computer Science Dept. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)bcd.c 8.2 (Berkeley) 3/20/94"; #endif /* not lint */ /* * bcd -- * * Read one line of standard input and produce something that looks like a * punch card. An attempt to reimplement /usr/games/bcd. All I looked at * was the man page. * * I couldn't find a BCD table handy so I wrote a shell script to deduce what * the patterns were that the old bcd was using for each possible 8-bit * character. These are the results -- the low order 12 bits represent the * holes. (A 1 bit is a hole.) These may be wrong, but they match the old * program! * * Steve Hayman * sahayman@iuvax.cs.indiana.edu * 1989 11 30 * * * I found an error in the table. The same error is found in the SunOS 4.1.1 * version of bcd. It has apparently been around a long time. The error caused * 'Q' and 'R' to have the same punch code. I only noticed the error due to * someone pointing it out to me when the program was used to print a cover * for an APA! The table was wrong in 4 places. The other error was masked * by the fact that the input is converted to upper case before lookup. * * Dyane Bruce * db@diana.ocunix.on.ca * Nov 5, 1993 */ #include #include #include #include u_short holes[256] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x206, 0x20a, 0x042, 0x442, 0x222, 0x800, 0x406, 0x812, 0x412, 0x422, 0xa00, 0x242, 0x400, 0x842, 0x300, 0x200, 0x100, 0x080, 0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001, 0x012, 0x40a, 0x80a, 0x212, 0x00a, 0x006, 0x022, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x822, 0x600, 0x282, 0x30f, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x206, 0x20a, 0x042, 0x442, 0x222, 0x800, 0x406, 0x812, 0x412, 0x422, 0xa00, 0x242, 0x400, 0x842, 0x300, 0x200, 0x100, 0x080, 0x040, 0x020, 0x010, 0x008, 0x004, 0x002, 0x001, 0x012, 0x40a, 0x80a, 0x212, 0x00a, 0x006, 0x022, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x30f, 0x900, 0x880, 0x840, 0x820, 0x810, 0x808, 0x804, 0x802, 0x801, 0x500, 0x480, 0x440, 0x420, 0x410, 0x408, 0x404, 0x402, 0x401, 0x280, 0x240, 0x220, 0x210, 0x208, 0x204, 0x202, 0x201, 0x082, 0x806, 0x822, 0x600, 0x282, 0x0 }; /* * i'th bit of w. */ #define bit(w,i) ((w)&(1<<(i))) int main(argc, argv) int argc; char **argv; { char cardline[80]; /* revoke setgid privileges */ setgid(getgid()); /* * The original bcd prompts with a "%" when reading from stdin, * but this seems kind of silly. So this one doesn't. */ if (argc > 1) { while (--argc) printcard(*++argv); } else while (fgets(cardline, sizeof(cardline), stdin)) printcard(cardline); exit(0); } #define COLUMNS 48 printcard(str) - register char *str; + char *str; { static char rowchars[] = " 123456789"; - register int i, row; - register char *p; + int i, row; + char *p; char *index(); /* ruthlessly remove newlines and truncate at 48 characters. */ if ((p = index(str, '\n'))) *p = '\0'; if (strlen(str) > COLUMNS) str[COLUMNS] = '\0'; /* make string upper case. */ for (p = str; *p; ++p) if (isascii(*p) && islower(*p)) *p = toupper(*p); /* top of card */ putchar(' '); for (i = 1; i <= COLUMNS; ++i) putchar('_'); putchar('\n'); /* * line of text. Leave a blank if the character doesn't have * a hole pattern. */ p = str; putchar('/'); for (i = 1; *p; i++, p++) if (holes[*p]) putchar(*p); else putchar(' '); while (i++ <= COLUMNS) putchar(' '); putchar('|'); putchar('\n'); /* * 12 rows of potential holes; output a ']', which looks kind of * like a hole, if the appropriate bit is set in the holes[] table. * The original bcd output a '[', a backspace, five control A's, * and then a ']'. This seems a little excessive. */ for (row = 0; row <= 11; ++row) { putchar('|'); for (i = 0, p = str; *p; i++, p++) { if (bit(holes[*p], 11 - row)) putchar(']'); else putchar(rowchars[row]); } while (i++ < COLUMNS) putchar(rowchars[row]); putchar('|'); putchar('\n'); } /* bottom of card */ putchar('|'); for (i = 1; i <= COLUMNS; i++) putchar('_'); putchar('|'); putchar('\n'); } diff --git a/games/bs/bs.c b/games/bs/bs.c index 216bc0cc6e29..76133066357f 100644 --- a/games/bs/bs.c +++ b/games/bs/bs.c @@ -1,1242 +1,1242 @@ /* * bs.c - original author: Bruce Holloway * salvo option by: Chuck A DeGaul * with improved user interface, autoconfiguration and code cleanup * by Eric S. Raymond * v1.2 with color support and minor portability fixes, November 1990 * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #ifndef A_UNDERLINE /* BSD curses */ #define beep() write(1,"\007",1); #define cbreak crmode #define saveterm savetty #define resetterm resetty #define nocbreak nocrmode #define strchr index #endif /* !A_UNDERLINE */ static bool checkplace(); /* * Constants for tuning the random-fire algorithm. It prefers moves that * diagonal-stripe the board with a stripe separation of srchstep. If * no such preferred moves are found, srchstep is decremented. */ #define BEGINSTEP 3 /* initial value of srchstep */ /* miscellaneous constants */ #define SHIPTYPES 5 #define OTHER (1-turn) #define PLAYER 0 #define COMPUTER 1 #define MARK_HIT 'H' #define MARK_MISS 'o' #define CTRLC '\003' /* used as terminate command */ #define FF '\014' /* used as redraw command */ /* coordinate handling */ #define BWIDTH 10 #define BDEPTH 10 /* display symbols */ #define SHOWHIT '*' #define SHOWSPLASH ' ' #define IS_SHIP(c) isupper(c) /* how to position us on player board */ #define PYBASE 3 #define PXBASE 3 #define PY(y) (PYBASE + (y)) #define PX(x) (PXBASE + (x)*3) #define pgoto(y, x) (void)move(PY(y), PX(x)) /* how to position us on cpu board */ #define CYBASE 3 #define CXBASE 48 #define CY(y) (CYBASE + (y)) #define CX(x) (CXBASE + (x)*3) #define cgoto(y, x) (void)move(CY(y), CX(x)) #define ONBOARD(x, y) (x >= 0 && x < BWIDTH && y >= 0 && y < BDEPTH) /* other board locations */ #define COLWIDTH 80 #define PROMPTLINE 21 /* prompt line */ #define SYBASE CYBASE + BDEPTH + 3 /* move key diagram */ #define SXBASE 63 #define MYBASE SYBASE - 1 /* diagram caption */ #define MXBASE 64 #define HYBASE SYBASE - 1 /* help area */ #define HXBASE 0 /* this will need to be changed if BWIDTH changes */ static char numbers[] = " 0 1 2 3 4 5 6 7 8 9"; static char carrier[] = "Aircraft Carrier"; static char battle[] = "Battleship"; static char sub[] = "Submarine"; static char destroy[] = "Destroyer"; static char ptboat[] = "PT Boat"; static char name[40]; static char dftname[] = "stranger"; /* direction constants */ #define E 0 #define SE 1 #define S 2 #define SW 3 #define W 4 #define NW 5 #define N 6 #define NE 7 static int xincr[8] = {1, 1, 0, -1, -1, -1, 0, 1}; static int yincr[8] = {0, 1, 1, 1, 0, -1, -1, -1}; /* current ship position and direction */ static int curx = (BWIDTH / 2); static int cury = (BDEPTH / 2); typedef struct { char *name; /* name of the ship type */ unsigned hits; /* how many times has this ship been hit? */ char symbol; /* symbol for game purposes */ char length; /* length of ship */ char x, y; /* coordinates of ship start point */ char dir; /* direction of `bow' */ bool placed; /* has it been placed on the board? */ } ship_t; ship_t plyship[SHIPTYPES] = { { carrier, 0, 'A', 5}, { battle, 0, 'B', 4}, { destroy, 0, 'D', 3}, { sub, 0, 'S', 3}, { ptboat, 0, 'P', 2}, }; ship_t cpuship[SHIPTYPES] = { { carrier, 0, 'A', 5}, { battle, 0, 'B', 4}, { destroy, 0, 'D', 3}, { sub, 0, 'S', 3}, { ptboat, 0, 'P', 2}, }; /* "Hits" board, and main board. */ static char hits[2][BWIDTH][BDEPTH], board[2][BWIDTH][BDEPTH]; static int turn; /* 0=player, 1=computer */ static int plywon=0, cpuwon=0; /* How many games has each won? */ static int salvo, blitz, closepack; #define PR (void)addstr static void uninitgame(sig) /* end the game, either normally or due to signal */ int sig; { clear(); (void)refresh(); (void)resetterm(); (void)echo(); (void)endwin(); exit(0); } static void announceopts() /* announce which game options are enabled */ { if (salvo || blitz || closepack) { (void) printw("Playing optional game ("); if (salvo) (void) printw("salvo, "); else (void) printw("nosalvo, "); if (blitz) (void) printw("blitz "); else (void) printw("noblitz, "); if (closepack) (void) printw("closepack)"); else (void) printw("noclosepack)"); } else (void) printw( "Playing standard game (noblitz, nosalvo, noclosepack)"); } static void intro() { extern char *getlogin(); char *tmpname; srandomdev(); (void) signal(SIGINT,uninitgame); (void) signal(SIGINT,uninitgame); (void) signal(SIGIOT,uninitgame); /* for assert(3) */ if(signal(SIGQUIT,SIG_IGN) != SIG_IGN) (void)signal(SIGQUIT,uninitgame); if(tmpname = getlogin()) { (void)strcpy(name,tmpname); name[0] = toupper(name[0]); } else (void)strcpy(name,dftname); (void)initscr(); #ifdef KEY_MIN keypad(stdscr, TRUE); #endif /* KEY_MIN */ (void)saveterm(); (void)nonl(); (void)cbreak(); (void)noecho(); #ifdef PENGUIN (void)clear(); (void)mvaddstr(4,29,"Welcome to Battleship!"); (void)move(8,0); PR(" \\\n"); PR(" \\ \\ \\\n"); PR(" \\ \\ \\ \\ \\_____________\n"); PR(" \\ \\ \\_____________ \\ \\/ |\n"); PR(" \\ \\/ \\ \\/ |\n"); PR(" \\/ \\_____/ |__\n"); PR(" ________________/ |\n"); PR(" \\ S.S. Penguin |\n"); PR(" \\ /\n"); PR(" \\___________________________________________________/\n"); (void) mvaddstr(22,27,"Hit any key to continue..."); (void)refresh(); (void) getch(); #endif /* PENGUIN */ #ifdef A_COLOR start_color(); init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); #endif /* A_COLOR */ } /* VARARGS1 */ static void prompt(n, f, s) /* print a message at the prompt line */ int n; char *f, *s; { (void) move(PROMPTLINE + n, 0); (void) clrtoeol(); (void) printw(f, s); (void) refresh(); } static void error(s) char *s; { (void) move(PROMPTLINE + 2, 0); (void) clrtoeol(); if (s) { (void) addstr(s); (void) beep(); } } static void placeship(b, ss, vis) int b; ship_t *ss; int vis; { int l; for(l = 0; l < ss->length; ++l) { int newx = ss->x + l * xincr[ss->dir]; int newy = ss->y + l * yincr[ss->dir]; board[b][newx][newy] = ss->symbol; if (vis) { pgoto(newy, newx); (void) addch((chtype)ss->symbol); } } ss->hits = 0; } static int rnd(n) int n; { return(random() % n); } static void randomplace(b, ss) /* generate a valid random ship placement into px,py */ int b; ship_t *ss; { - register int bwidth = BWIDTH - ss->length; - register int bdepth = BDEPTH - ss->length; + int bwidth = BWIDTH - ss->length; + int bdepth = BDEPTH - ss->length; do { ss->y = rnd(bdepth); ss->x = rnd(bwidth); ss->dir = rnd(2) ? E : S; } while (!checkplace(b, ss, FALSE)); } static void initgame() { int i, j, unplaced; ship_t *ss; (void) clear(); (void) mvaddstr(0,35,"BATTLESHIPS"); (void) move(PROMPTLINE + 2, 0); announceopts(); bzero(board, sizeof(char) * BWIDTH * BDEPTH * 2); bzero(hits, sizeof(char) * BWIDTH * BDEPTH * 2); for (i = 0; i < SHIPTYPES; i++) { ss = cpuship + i; ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; ss = plyship + i; ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0; } /* draw empty boards */ (void) mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board"); (void) mvaddstr(PYBASE - 1, PXBASE - 3,numbers); for(i=0; i < BDEPTH; ++i) { (void) mvaddch(PYBASE + i, PXBASE - 3, i + 'A'); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_BLUE)); #endif /* A_COLOR */ (void) addch(' '); for (j = 0; j < BWIDTH; j++) (void) addstr(" . "); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ (void) addch(' '); (void) addch(i + 'A'); } (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers); (void) mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board"); (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers); for(i=0; i < BDEPTH; ++i) { (void) mvaddch(CYBASE + i, CXBASE - 3, i + 'A'); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_BLUE)); #endif /* A_COLOR */ (void) addch(' '); for (j = 0; j < BWIDTH; j++) (void) addstr(" . "); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ (void) addch(' '); (void) addch(i + 'A'); } (void) mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers); (void) mvprintw(HYBASE, HXBASE, "To position your ships: move the cursor to a spot, then"); (void) mvprintw(HYBASE+1,HXBASE, "type the first letter of a ship type to select it, then"); (void) mvprintw(HYBASE+2,HXBASE, "type a direction ([hjkl] or [4862]), indicating how the"); (void) mvprintw(HYBASE+3,HXBASE, "ship should be pointed. You may also type a ship letter"); (void) mvprintw(HYBASE+4,HXBASE, "followed by `r' to position it randomly, or type `R' to"); (void) mvprintw(HYBASE+5,HXBASE, "place all remaining ships randomly."); (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:"); (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9"); (void) mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ "); (void) mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6"); (void) mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ "); (void) mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3"); /* have the computer place ships */ for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++) { randomplace(COMPUTER, ss); placeship(COMPUTER, ss, FALSE); } ss = (ship_t *)NULL; do { extern char *strchr(); static char getcoord(); char c, docked[SHIPTYPES + 2], *cp = docked; /* figure which ships still wait to be placed */ *cp++ = 'R'; for (i = 0; i < SHIPTYPES; i++) if (!plyship[i].placed) *cp++ = plyship[i].symbol; *cp = '\0'; /* get a command letter */ prompt(1, "Type one of [%s] to pick a ship.", docked+1); do { c = getcoord(PLAYER); } while (!strchr(docked, c)); if (c == 'R') (void) ungetch('R'); else { /* map that into the corresponding symbol */ for (ss = plyship; ss < plyship + SHIPTYPES; ss++) if (ss->symbol == c) break; prompt(1, "Type one of [hjklrR] to place your %s.", ss->name); pgoto(cury, curx); } do { c = getch(); } while (!strchr("hjklrR", c) || c == FF); if (c == FF) { (void)clearok(stdscr, TRUE); (void)refresh(); } else if (c == 'r') { prompt(1, "Random-placing your %s", ss->name); randomplace(PLAYER, ss); placeship(PLAYER, ss, TRUE); error((char *)NULL); ss->placed = TRUE; } else if (c == 'R') { prompt(1, "Placing the rest of your fleet at random..."); for (ss = plyship; ss < plyship + SHIPTYPES; ss++) if (!ss->placed) { randomplace(PLAYER, ss); placeship(PLAYER, ss, TRUE); ss->placed = TRUE; } error((char *)NULL); } else if (strchr("hjkl8462", c)) { ss->x = curx; ss->y = cury; switch(c) { case 'k': case '8': ss->dir = N; break; case 'j': case '2': ss->dir = S; break; case 'h': case '4': ss->dir = W; break; case 'l': case '6': ss->dir = E; break; } if (checkplace(PLAYER, ss, TRUE)) { placeship(PLAYER, ss, TRUE); error((char *)NULL); ss->placed = TRUE; } } for (unplaced = i = 0; i < SHIPTYPES; i++) unplaced += !plyship[i].placed; } while (unplaced); turn = rnd(2); (void) mvprintw(HYBASE, HXBASE, "To fire, move the cursor to your chosen aiming point "); (void) mvprintw(HYBASE+1, HXBASE, "and strike any key other than a motion key. "); (void) mvprintw(HYBASE+2, HXBASE, " "); (void) mvprintw(HYBASE+3, HXBASE, " "); (void) mvprintw(HYBASE+4, HXBASE, " "); (void) mvprintw(HYBASE+5, HXBASE, " "); (void) prompt(0, "Press any key to start..."); (void) getch(); } static int getcoord(atcpu) int atcpu; { int ny, nx, c; if (atcpu) cgoto(cury,curx); else pgoto(cury, curx); (void)refresh(); for (;;) { if (atcpu) { (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury); cgoto(cury, curx); } else { (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury); pgoto(cury, curx); } switch(c = getch()) { case 'k': case '8': #ifdef KEY_MIN case KEY_UP: #endif /* KEY_MIN */ ny = cury+BDEPTH-1; nx = curx; break; case 'j': case '2': #ifdef KEY_MIN case KEY_DOWN: #endif /* KEY_MIN */ ny = cury+1; nx = curx; break; case 'h': case '4': #ifdef KEY_MIN case KEY_LEFT: #endif /* KEY_MIN */ ny = cury; nx = curx+BWIDTH-1; break; case 'l': case '6': #ifdef KEY_MIN case KEY_RIGHT: #endif /* KEY_MIN */ ny = cury; nx = curx+1; break; case 'y': case '7': #ifdef KEY_MIN case KEY_A1: #endif /* KEY_MIN */ ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; break; case 'b': case '1': #ifdef KEY_MIN case KEY_C1: #endif /* KEY_MIN */ ny = cury+1; nx = curx+BWIDTH-1; break; case 'u': case '9': #ifdef KEY_MIN case KEY_A3: #endif /* KEY_MIN */ ny = cury+BDEPTH-1; nx = curx+1; break; case 'n': case '3': #ifdef KEY_MIN case KEY_C3: #endif /* KEY_MIN */ ny = cury+1; nx = curx+1; break; case FF: nx = curx; ny = cury; (void)clearok(stdscr, TRUE); (void)refresh(); break; default: if (atcpu) (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " "); else (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " "); return(c); } curx = nx % BWIDTH; cury = ny % BDEPTH; } } static int collidecheck(b, y, x) /* is this location on the selected zboard adjacent to a ship? */ int b; int y, x; { int collide; /* anything on the square */ if (collide = IS_SHIP(board[b][x][y])) return(collide); /* anything on the neighbors */ if (!closepack) { int i; for (i = 0; i < 8; i++) { int xend, yend; yend = y + yincr[i]; xend = x + xincr[i]; if (ONBOARD(xend, yend)) collide += IS_SHIP(board[b][xend][yend]); } } return(collide); } static bool checkplace(b, ss, vis) int b; ship_t *ss; int vis; { int l, xend, yend; /* first, check for board edges */ xend = ss->x + ss->length * xincr[ss->dir]; yend = ss->y + ss->length * yincr[ss->dir]; if (!ONBOARD(xend, yend)) { if (vis) switch(rnd(3)) { case 0: error("Ship is hanging from the edge of the world"); break; case 1: error("Try fitting it on the board"); break; case 2: error("Figure I won't find it if you put it there?"); break; } return(0); } for(l = 0; l < ss->length; ++l) { if(collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir])) { if (vis) switch(rnd(3)) { case 0: error("There's already a ship there"); break; case 1: error("Collision alert! Aaaaaagh!"); break; case 2: error("Er, Admiral, what about the other ship?"); break; } return(FALSE); } } return(TRUE); } static int awinna() { int i, j; ship_t *ss; for(i=0; i<2; ++i) { ss = (i) ? cpuship : plyship; for(j=0; j < SHIPTYPES; ++j, ++ss) if(ss->length > ss->hits) break; if (j == SHIPTYPES) return(OTHER); } return(-1); } static ship_t *hitship(x, y) -/* register a hit on the targeted ship */ +/* a hit on the targeted ship */ int x, y; { ship_t *sb, *ss; char sym; int oldx, oldy; getyx(stdscr, oldy, oldx); sb = (turn) ? plyship : cpuship; if(!(sym = board[OTHER][x][y])) return((ship_t *)NULL); for(ss = sb; ss < sb + SHIPTYPES; ++ss) if(ss->symbol == sym) { if (++ss->hits < ss->length) /* still afloat? */ return((ship_t *)NULL); else /* sunk! */ { int i, j; if (!closepack) for (j = -1; j <= 1; j++) { int bx = ss->x + j * xincr[(ss->dir + 2) % 8]; int by = ss->y + j * yincr[(ss->dir + 2) % 8]; for (i = -1; i <= ss->length; ++i) { int x, y; x = bx + i * xincr[ss->dir]; y = by + i * yincr[ss->dir]; if (ONBOARD(x, y)) { hits[turn][x][y] = MARK_MISS; if (turn % 2 == PLAYER) { cgoto(y, x); #ifdef A_COLOR if (has_colors()) attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ (void)addch(MARK_MISS); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ } } } } for (i = 0; i < ss->length; ++i) { int x = ss->x + i * xincr[ss->dir]; int y = ss->y + i * yincr[ss->dir]; hits[turn][x][y] = ss->symbol; if (turn % 2 == PLAYER) { cgoto(y, x); (void) addch(ss->symbol); } } (void) move(oldy, oldx); return(ss); } } (void) move(oldy, oldx); return((ship_t *)NULL); } static int plyturn() { ship_t *ss; bool hit; char *m; prompt(1, "Where do you want to shoot? "); for (;;) { (void) getcoord(COMPUTER); if (hits[PLAYER][curx][cury]) { prompt(1, "You shelled this spot already! Try again."); beep(); } else break; } hit = IS_SHIP(board[COMPUTER][curx][cury]); hits[PLAYER][curx][cury] = hit ? MARK_HIT : MARK_MISS; cgoto(cury, curx); #ifdef A_COLOR if (has_colors()) if (hit) attron(COLOR_PAIR(COLOR_RED)); else attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ (void) addch((chtype)hits[PLAYER][curx][cury]); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ prompt(1, "You %s.", hit ? "scored a hit" : "missed"); if(hit && (ss = hitship(curx, cury))) { switch(rnd(5)) { case 0: m = " You sank my %s!"; break; case 1: m = " I have this sinking feeling about my %s...."; break; case 2: m = " My %s has gone to Davy Jones's locker!"; break; case 3: m = " Glub, glub -- my %s is headed for the bottom!"; break; case 4: m = " You'll pick up survivors from my my %s, I hope...!"; break; } (void)printw(m, ss->name); (void)beep(); return(awinna() == -1); } return(hit); } static int sgetc(s) char *s; { char *s1; int ch; (void)refresh(); for(;;) { ch = getch(); if (islower(ch)) ch = toupper(ch); if (ch == CTRLC) uninitgame(); for (s1=s; *s1 && ch != *s1; ++s1) continue; if (*s1) { (void) addch((chtype)ch); (void)refresh(); return(ch); } } } static void randomfire(px, py) /* random-fire routine -- implements simple diagonal-striping strategy */ int *px, *py; { static int turncount = 0; static int srchstep = BEGINSTEP; static int huntoffs; /* Offset on search strategy */ int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs; int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref; int x, y, i; if (turncount++ == 0) huntoffs = rnd(srchstep); /* first, list all possible moves */ nposs = npref = 0; for (x = 0; x < BWIDTH; x++) for (y = 0; y < BDEPTH; y++) if (!hits[COMPUTER][x][y]) { xpossible[nposs] = x; ypossible[nposs] = y; nposs++; if (((x+huntoffs) % srchstep) != (y % srchstep)) { xpreferred[npref] = x; ypreferred[npref] = y; npref++; } } if (npref) { i = rnd(npref); *px = xpreferred[i]; *py = ypreferred[i]; } else if (nposs) { i = rnd(nposs); *px = xpossible[i]; *py = ypossible[i]; if (srchstep > 1) --srchstep; } else { error("No moves possible?? Help!"); exit(1); /*NOTREACHED*/ } } #define S_MISS 0 #define S_HIT 1 #define S_SUNK -1 static bool cpufire(x, y) /* fire away at given location */ int x, y; { bool hit, sunk; ship_t *ss; hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS; (void) mvprintw(PROMPTLINE, 0, "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss"); if (sunk = (hit && (ss = hitship(x, y)))) (void) printw(" I've sunk your %s", ss->name); (void)clrtoeol(); pgoto(y, x); #ifdef A_COLOR if (has_colors()) if (hit) attron(COLOR_PAIR(COLOR_RED)); else attron(COLOR_PAIR(COLOR_GREEN)); #endif /* A_COLOR */ (void)addch((chtype)(hit ? SHOWHIT : SHOWSPLASH)); #ifdef A_COLOR attrset(0); #endif /* A_COLOR */ return(hit ? (sunk ? S_SUNK : S_HIT) : S_MISS); } /* * This code implements a fairly irregular FSM, so please forgive the rampant * unstructuredness below. The five labels are states which need to be held * between computer turns. */ static bool cputurn() { #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y]) #define RANDOM_FIRE 0 #define RANDOM_HIT 1 #define HUNT_DIRECT 2 #define FIRST_PASS 3 #define REVERSE_JUMP 4 #define SECOND_PASS 5 static int next = RANDOM_FIRE; static bool used[4]; static ship_t ts; int navail, x, y, d, n, hit = S_MISS; switch(next) { case RANDOM_FIRE: /* last shot was random and missed */ refire: randomfire(&x, &y); if (!(hit = cpufire(x, y))) next = RANDOM_FIRE; else { ts.x = x; ts.y = y; ts.hits = 1; next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT; } break; case RANDOM_HIT: /* last shot was random and hit */ used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE; /* FALLTHROUGH */ case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */ for (d = navail = 0; d < 4; d++) { x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2]; if (!used[d] && POSSIBLE(x, y)) navail++; else used[d] = TRUE; } if (navail == 0) /* no valid places for shots adjacent... */ goto refire; /* ...so we must random-fire */ else { for (d = 0, n = rnd(navail) + 1; n; n--) while (used[d]) d++; assert(d <= 4); used[d] = FALSE; x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2]; assert(POSSIBLE(x, y)); if (!(hit = cpufire(x, y))) next = HUNT_DIRECT; else { ts.x = x; ts.y = y; ts.dir = d*2; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS; } } break; case FIRST_PASS: /* we have a start and a direction now */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { ts.x = x; ts.y = y; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS; } else next = REVERSE_JUMP; break; case REVERSE_JUMP: /* nail down the ship's other end */ d = ts.dir + 4; x = ts.x + ts.hits * xincr[d]; y = ts.y + ts.hits * yincr[d]; if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { ts.x = x; ts.y = y; ts.dir = d; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS; } else next = RANDOM_FIRE; break; case SECOND_PASS: /* kill squares not caught on first pass */ x = ts.x + xincr[ts.dir]; y = ts.y + yincr[ts.dir]; if (POSSIBLE(x, y) && (hit = cpufire(x, y))) { ts.x = x; ts.y = y; ts.hits++; next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS; break; } else next = RANDOM_FIRE; break; } /* check for continuation and/or winner */ if (salvo) { (void)refresh(); (void)sleep(1); } if (awinna() != -1) return(FALSE); #ifdef DEBUG (void) mvprintw(PROMPTLINE + 2, 0, "New state %d, x=%d, y=%d, d=%d", next, x, y, d); #endif /* DEBUG */ return(hit); } playagain() { int j; ship_t *ss; for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) for(j = 0; j < ss->length; j++) { cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]); (void)addch((chtype)ss->symbol); } if(awinna()) ++cpuwon; else ++plywon; j = 18 + strlen(name); if(plywon >= 10) ++j; if(cpuwon >= 10) ++j; (void) mvprintw(1,(COLWIDTH-j)/2, "%s: %d Computer: %d",name,plywon,cpuwon); prompt(2, (awinna()) ? "Want to be humiliated again, %s [yn]? " : "Going to give me a chance for revenge, %s [yn]? ",name); return(sgetc("YN") == 'Y'); } static void do_options(c,op) int c; char *op[]; { - register int i; + int i; if (c > 1) { for (i=1; ihits >= sp->length) continue; /* dead ship */ else shots++; } return(shots); } main(argc, argv) int argc; char *argv[]; { /* revoke */ setgid(getgid()); do_options(argc, argv); intro(); do { initgame(); while(awinna() == -1) { if (!blitz) { if (!salvo) { if(turn) (void) cputurn(); else (void) plyturn(); } else { - register int i; + int i; i = scount(turn); while (i--) { if (turn) { if (cputurn() && awinna() != -1) i = 0; } else { if (plyturn() && awinna() != -1) i = 0; } } } } else while(turn ? cputurn() : plyturn()) continue; turn = OTHER; } } while (playagain()); uninitgame(); /*NOTREACHED*/ } /* bs.c ends here */ diff --git a/games/caesar/caesar.c b/games/caesar/caesar.c index e04fc6208267..bc3af27d6702 100644 --- a/games/caesar/caesar.c +++ b/games/caesar/caesar.c @@ -1,171 +1,171 @@ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Rick Adams. * * Authors: * Stan King, John Eldridge, based on algorithm suggested by * Bob Morris * 29-Sep-82 * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static const char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93"; #else static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ #include #include #include #include #include #include #include #define LINELENGTH 2048 #define ROTATE(ch, perm) \ isascii(ch) ? ( \ isupper(ch) ? ('A' + (ch - 'A' + perm) % 26) : \ islower(ch) ? ('a' + (ch - 'a' + perm) % 26) : ch) : ch /* * letter frequencies (taken from some unix(tm) documentation) * (unix is a trademark of Bell Laboratories) */ double stdf[26] = { 7.97, 1.35, 3.61, 4.78, 12.37, 2.01, 1.46, 4.49, 6.39, 0.04, 0.42, 3.81, 2.69, 5.92, 6.96, 2.91, 0.08, 6.63, 8.77, 9.68, 2.62, 0.81, 1.88, 0.23, 2.07, 0.06, }; void printit(); int main(argc, argv) int argc; char **argv; { - register int ch, dot, i, nread, winnerdot = 0; - register char *inbuf; + int ch, dot, i, nread, winnerdot = 0; + char *inbuf; int obs[26], try, winner; /* revoke setgid privileges */ setgid(getgid()); if (argc > 1) printit(argv[1]); if (!(inbuf = malloc(LINELENGTH))) { (void)fprintf(stderr, "caesar: out of memory.\n"); exit(1); } /* adjust frequency table to weight low probs REAL low */ for (i = 0; i < 26; ++i) stdf[i] = log(stdf[i]) + log(26.0 / 100.0); /* zero out observation table */ bzero(obs, 26 * sizeof(int)); if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) { (void)fprintf(stderr, "caesar: %s\n", strerror(errno)); exit(1); } for (i = nread; i--;) { ch = (unsigned char) inbuf[i]; if (isascii(ch)) { if (islower(ch)) ++obs[ch - 'a']; else if (isupper(ch)) ++obs[ch - 'A']; } } /* * now "dot" the freqs with the observed letter freqs * and keep track of best fit */ for (try = winner = 0; try < 26; ++try) { /* += 13) { */ dot = 0; for (i = 0; i < 26; i++) dot += obs[i] * stdf[(i + try) % 26]; /* initialize winning score */ if (try == 0) winnerdot = dot; if (dot > winnerdot) { /* got a new winner! */ winner = try; winnerdot = dot; } } for (;;) { for (i = 0; i < nread; ++i) { ch = (unsigned char) inbuf[i]; putchar(ROTATE(ch, winner)); } if (nread < LINELENGTH) break; if ((nread = read(STDIN_FILENO, inbuf, LINELENGTH)) < 0) { (void)fprintf(stderr, "caesar: %s\n", strerror(errno)); exit(1); } } exit(0); } void printit(arg) char *arg; { - register int ch, rot; + int ch, rot; if ((rot = atoi(arg)) < 0) { (void)fprintf(stderr, "caesar: bad rotation value.\n"); exit(1); } while ((ch = getchar()) != EOF) putchar(ROTATE(ch, rot)); exit(0); } diff --git a/games/canfield/canfield/canfield.c b/games/canfield/canfield/canfield.c index 8a95e5f473aa..b8a938e713d6 100644 --- a/games/canfield/canfield/canfield.c +++ b/games/canfield/canfield/canfield.c @@ -1,1716 +1,1716 @@ /* * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)canfield.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ /* * The canfield program * * Authors: * Originally written: Steve Levine * Converted to use curses and debugged: Steve Feldman * Card counting: Kirk McKusick and Mikey Olson * User interface cleanups: Eric Allman and Kirk McKusick * Betting by Kirk McKusick */ #include #include #include #include #include #include #include #include #include #include "pathnames.h" #define decksize 52 #define originrow 0 #define origincol 0 #define basecol 1 #define boxcol 42 #define tboxrow 2 #define bboxrow 17 #define movecol 43 #define moverow 16 #define msgcol 43 #define msgrow 15 #define titlecol 30 #define titlerow 0 #define sidecol 1 #define ottlrow 6 #define foundcol 11 #define foundrow 3 #define stockcol 2 #define stockrow 8 #define fttlcol 10 #define fttlrow 1 #define taloncol 2 #define talonrow 13 #define tabrow 8 #define ctoprow 21 #define cbotrow 23 #define cinitcol 14 #define cheightcol 1 #define cwidthcol 4 #define handstatrow 21 #define handstatcol 7 #define talonstatrow 22 #define talonstatcol 7 #define stockstatrow 23 #define stockstatcol 7 #define Ace 1 #define Jack 11 #define Queen 12 #define King 13 #define atabcol 11 #define btabcol 18 #define ctabcol 25 #define dtabcol 32 #define spades 's' #define clubs 'c' #define hearts 'h' #define diamonds 'd' #define black 'b' #define red 'r' #define stk 1 #define tal 2 #define tab 3 #define INCRHAND(row, col) {\ row -= cheightcol;\ if (row < ctoprow) {\ row = cbotrow;\ col += cwidthcol;\ }\ } #define DECRHAND(row, col) {\ row += cheightcol;\ if (row > cbotrow) {\ row = ctoprow;\ col -= cwidthcol;\ }\ } struct cardtype { char suit; char color; bool visible; bool paid; int rank; struct cardtype *next; }; #define NIL ((struct cardtype *) -1) struct cardtype *deck[decksize]; struct cardtype cards[decksize]; struct cardtype *bottom[4], *found[4], *tableau[4]; struct cardtype *talon, *hand, *stock, *basecard; int length[4]; int cardsoff, base, cinhand, taloncnt, stockcnt, timesthru; char suitmap[4] = {spades, clubs, hearts, diamonds}; char colormap[4] = {black, black, red, red}; char pilemap[4] = {atabcol, btabcol, ctabcol, dtabcol}; char srcpile, destpile; int mtforigin, tempbase; int coldcol, cnewcol, coldrow, cnewrow; bool errmsg, done; bool mtfdone, Cflag = FALSE; #define INSTRUCTIONBOX 1 #define BETTINGBOX 2 #define NOBOX 3 int status = INSTRUCTIONBOX; int uid; /* * Basic betting costs */ #define costofhand 13 #define costofinspection 13 #define costofgame 26 #define costofrunthroughhand 5 #define costofinformation 1 #define secondsperdollar 60 #define maxtimecharge 3 #define valuepercardup 5 /* * Variables associated with betting */ struct betinfo { long hand; /* cost of dealing hand */ long inspection; /* cost of inspecting hand */ long game; /* cost of buying game */ long runs; /* cost of running through hands */ long information; /* cost of information */ long thinktime; /* cost of thinking time */ long wins; /* total winnings */ long worth; /* net worth after costs */ }; struct betinfo this, game, total; bool startedgame = FALSE, infullgame = FALSE; time_t acctstart; int dbfd = -1; /* * The following procedures print the board onto the screen using the * addressible cursor. The end of these procedures will also be * separated from the rest of the program. * * procedure to set the move command box */ movebox() { switch (status) { case BETTINGBOX: printtopbettingbox(); break; case NOBOX: clearabovemovebox(); break; case INSTRUCTIONBOX: printtopinstructions(); break; } move(moverow, boxcol); printw("| |"); move(msgrow, boxcol); printw("| |"); switch (status) { case BETTINGBOX: printbottombettingbox(); break; case NOBOX: clearbelowmovebox(); break; case INSTRUCTIONBOX: printbottominstructions(); break; } refresh(); } /* * print directions above move box */ printtopinstructions() { move(tboxrow, boxcol); printw("*----------------------------------*"); move(tboxrow + 1, boxcol); printw("| MOVES |"); move(tboxrow + 2, boxcol); printw("|s# = stock to tableau |"); move(tboxrow + 3, boxcol); printw("|sf = stock to foundation |"); move(tboxrow + 4, boxcol); printw("|t# = talon to tableau |"); move(tboxrow + 5, boxcol); printw("|tf = talon to foundation |"); move(tboxrow + 6, boxcol); printw("|## = tableau to tableau |"); move(tboxrow + 7, boxcol); printw("|#f = tableau to foundation |"); move(tboxrow + 8, boxcol); printw("|ht = hand to talon |"); move(tboxrow + 9, boxcol); printw("|c = toggle card counting |"); move(tboxrow + 10, boxcol); printw("|b = present betting information |"); move(tboxrow + 11, boxcol); printw("|q = quit to end the game |"); move(tboxrow + 12, boxcol); printw("|==================================|"); } /* * Print the betting box. */ printtopbettingbox() { move(tboxrow, boxcol); printw("*----------------------------------*"); move(tboxrow + 1, boxcol); printw("|Costs Hand Game Total |"); move(tboxrow + 2, boxcol); printw("| Hands |"); move(tboxrow + 3, boxcol); printw("| Inspections |"); move(tboxrow + 4, boxcol); printw("| Games |"); move(tboxrow + 5, boxcol); printw("| Runs |"); move(tboxrow + 6, boxcol); printw("| Information |"); move(tboxrow + 7, boxcol); printw("| Think time |"); move(tboxrow + 8, boxcol); printw("|Total Costs |"); move(tboxrow + 9, boxcol); printw("|Winnings |"); move(tboxrow + 10, boxcol); printw("|Net Worth |"); move(tboxrow + 11, boxcol); printw("|Return |"); move(tboxrow + 12, boxcol); printw("|==================================|"); } /* * clear info above move box */ clearabovemovebox() { int i; for (i = 0; i <= 11; i++) { move(tboxrow + i, boxcol); printw(" "); } move(tboxrow + 12, boxcol); printw("*----------------------------------*"); } /* * print instructions below move box */ printbottominstructions() { move(bboxrow, boxcol); printw("|Replace # with the number of the |"); move(bboxrow + 1, boxcol); printw("|tableau you want. |"); move(bboxrow + 2, boxcol); printw("*----------------------------------*"); } /* * print betting information below move box */ printbottombettingbox() { move(bboxrow, boxcol); printw("|x = toggle information box |"); move(bboxrow + 1, boxcol); printw("|i = list playing instructions |"); move(bboxrow + 2, boxcol); printw("*----------------------------------*"); } /* * clear info below move box */ clearbelowmovebox() { int i; move(bboxrow, boxcol); printw("*----------------------------------*"); for (i = 1; i <= 2; i++) { move(bboxrow + i, boxcol); printw(" "); } } /* * procedure to put the board on the screen using addressable cursor */ makeboard() { clear(); refresh(); move(titlerow, titlecol); printw("=-> CANFIELD <-="); move(fttlrow, fttlcol); printw("foundation"); move(foundrow - 1, fttlcol); printw("=---= =---= =---= =---="); move(foundrow, fttlcol); printw("| | | | | | | |"); move(foundrow + 1, fttlcol); printw("=---= =---= =---= =---="); move(ottlrow, sidecol); printw("stock tableau"); move(stockrow - 1, sidecol); printw("=---="); move(stockrow, sidecol); printw("| |"); move(stockrow + 1, sidecol); printw("=---="); move(talonrow - 2, sidecol); printw("talon"); move(talonrow - 1, sidecol); printw("=---="); move(talonrow, sidecol); printw("| |"); move(talonrow + 1, sidecol); printw("=---="); move(tabrow - 1, atabcol); printw("-1- -2- -3- -4-"); movebox(); } /* * clean up the board for another game */ cleanupboard() { int cnt, row, col; struct cardtype *ptr; if (Cflag) { clearstat(); for(ptr = stock, row = stockrow; ptr != NIL; ptr = ptr->next, row++) { move(row, sidecol); printw(" "); } move(row, sidecol); printw(" "); move(stockrow + 1, sidecol); printw("=---="); move(talonrow - 2, sidecol); printw("talon"); move(talonrow - 1, sidecol); printw("=---="); move(talonrow + 1, sidecol); printw("=---="); } move(stockrow, sidecol); printw("| |"); move(talonrow, sidecol); printw("| |"); move(foundrow, fttlcol); printw("| | | | | | | |"); for (cnt = 0; cnt < 4; cnt++) { switch(cnt) { case 0: col = atabcol; break; case 1: col = btabcol; break; case 2: col = ctabcol; break; case 3: col = dtabcol; break; } for(ptr = tableau[cnt], row = tabrow; ptr != NIL; ptr = ptr->next, row++) removecard(col, row); } } /* * procedure to create a deck of cards */ initdeck(deck) struct cardtype *deck[]; { int i; int scnt; char s; int r; i = 0; for (scnt=0; scnt<4; scnt++) { s = suitmap[scnt]; for (r=Ace; r<=King; r++) { deck[i] = &cards[i]; cards[i].rank = r; cards[i].suit = s; cards[i].color = colormap[scnt]; cards[i].next = NIL; i++; } } } /* * procedure to shuffle the deck */ shuffle(deck) struct cardtype *deck[]; { int i,j; struct cardtype *temp; for (i=0; ivisible = FALSE; deck[i]->paid = FALSE; } for (i = decksize-1; i>=0; i--) { j = random() % decksize; if (i != j) { temp = deck[i]; deck[i] = deck[j]; deck[j] = temp; } } } /* * procedure to remove the card from the board */ removecard(a, b) { move(b, a); printw(" "); } /* * procedure to print the cards on the board */ printrank(a, b, cp, inverse) struct cardtype *cp; bool inverse; { move(b, a); if (cp->rank != 10) addch(' '); if (inverse) standout(); switch (cp->rank) { case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: printw("%d", cp->rank); break; case Ace: addch('A'); break; case Jack: addch('J'); break; case Queen: addch('Q'); break; case King: addch('K'); } if (inverse) standend(); } /* * procedure to print out a card */ printcard(a, b, cp) int a,b; struct cardtype *cp; { if (cp == NIL) removecard(a, b); else if (cp->visible == FALSE) { move(b, a); printw(" ? "); } else { bool inverse = (cp->suit == 'd' || cp->suit == 'h'); printrank(a, b, cp, inverse); if (inverse) standout(); addch(cp->suit); if (inverse) standend(); } } /* * procedure to move the top card from one location to the top * of another location. The pointers always point to the top * of the piles. */ transit(source, dest) struct cardtype **source, **dest; { struct cardtype *temp; temp = *source; *source = (*source)->next; temp->next = *dest; *dest = temp; } /* * Procedure to set the cards on the foundation base when available. * Note that it is only called on a foundation pile at the beginning of * the game, so the pile will have exactly one card in it. */ fndbase(cp, column, row) struct cardtype **cp; { bool nomore; if (*cp != NIL) do { if ((*cp)->rank == basecard->rank) { base++; printcard(pilemap[base], foundrow, *cp); if (*cp == tableau[0]) length[0] = length[0] - 1; if (*cp == tableau[1]) length[1] = length[1] - 1; if (*cp == tableau[2]) length[2] = length[2] - 1; if (*cp == tableau[3]) length[3] = length[3] - 1; transit(cp, &found[base]); if (cp == &talon) usedtalon(); if (cp == &stock) usedstock(); if (*cp != NIL) { printcard(column, row, *cp); nomore = FALSE; } else { removecard(column, row); nomore = TRUE; } cardsoff++; if (infullgame) { this.wins += valuepercardup; game.wins += valuepercardup; total.wins += valuepercardup; } } else nomore = TRUE; } while (nomore == FALSE); } /* * procedure to initialize the things necessary for the game */ initgame() { - register i; + int i; for (i=0; i<18; i++) { deck[i]->visible = TRUE; deck[i]->paid = TRUE; } stockcnt = 13; stock = deck[12]; for (i=12; i>=1; i--) deck[i]->next = deck[i - 1]; deck[0]->next = NIL; found[0] = deck[13]; deck[13]->next = NIL; for (i=1; i<4; i++) found[i] = NIL; basecard = found[0]; for (i=14; i<18; i++) { tableau[i - 14] = deck[i]; deck[i]->next = NIL; } for (i=0; i<4; i++) { bottom[i] = tableau[i]; length[i] = tabrow; } hand = deck[18]; for (i=18; inext = deck[i + 1]; deck[decksize-1]->next = NIL; talon = NIL; base = 0; cinhand = 34; taloncnt = 0; timesthru = 0; cardsoff = 1; coldrow = ctoprow; coldcol = cinitcol; cnewrow = ctoprow; cnewcol = cinitcol + cwidthcol; } /* * procedure to print the beginning cards and to start each game */ startgame() { - register int j; + int j; shuffle(deck); initgame(); this.hand = costofhand; game.hand += costofhand; total.hand += costofhand; this.inspection = 0; this.game = 0; this.runs = 0; this.information = 0; this.wins = 0; this.thinktime = 0; infullgame = FALSE; startedgame = FALSE; printcard(foundcol, foundrow, found[0]); printcard(stockcol, stockrow, stock); printcard(atabcol, tabrow, tableau[0]); printcard(btabcol, tabrow, tableau[1]); printcard(ctabcol, tabrow, tableau[2]); printcard(dtabcol, tabrow, tableau[3]); printcard(taloncol, talonrow, talon); move(foundrow - 2, basecol); printw("Base"); move(foundrow - 1, basecol); printw("Rank"); printrank(basecol, foundrow, found[0], 0); for (j=0; j<=3; j++) fndbase(&tableau[j], pilemap[j], tabrow); fndbase(&stock, stockcol, stockrow); showstat(); /* show card counting info to cheaters */ movetotalon(); updatebettinginfo(); } /* * procedure to clear the message printed from an error */ clearmsg() { int i; if (errmsg == TRUE) { errmsg = FALSE; move(msgrow, msgcol); for (i=0; i<25; i++) addch(' '); refresh(); } } /* * procedure to print an error message if the move is not listed */ dumberror() { errmsg = TRUE; move(msgrow, msgcol); printw("Not a proper move "); } /* * procedure to print an error message if the move is not possible */ destinerror() { errmsg = TRUE; move(msgrow, msgcol); printw("Error: Can't move there"); } /* * function to see if the source has cards in it */ bool notempty(cp) struct cardtype *cp; { if (cp == NIL) { errmsg = TRUE; move(msgrow, msgcol); printw("Error: no cards to move"); return (FALSE); } else return (TRUE); } /* * function to see if the rank of one card is less than another */ bool ranklower(cp1, cp2) struct cardtype *cp1, *cp2; { if (cp2->rank == Ace) if (cp1->rank == King) return (TRUE); else return (FALSE); else if (cp1->rank + 1 == cp2->rank) return (TRUE); else return (FALSE); } /* * function to check the cardcolor for moving to a tableau */ bool diffcolor(cp1, cp2) struct cardtype *cp1, *cp2; { if (cp1->color == cp2->color) return (FALSE); else return (TRUE); } /* * function to see if the card can move to the tableau */ bool tabok(cp, des) struct cardtype *cp; { if ((cp == stock) && (tableau[des] == NIL)) return (TRUE); else if (tableau[des] == NIL) if (stock == NIL && cp != bottom[0] && cp != bottom[1] && cp != bottom[2] && cp != bottom[3]) return (TRUE); else return (FALSE); else if (ranklower(cp, tableau[des]) && diffcolor(cp, tableau[des])) return (TRUE); else return (FALSE); } /* * procedure to turn the cards onto the talon from the deck */ movetotalon() { int i, fin; if (cinhand <= 3 && cinhand > 0) { move(msgrow, msgcol); printw("Hand is now empty "); } if (cinhand >= 3) fin = 3; else if (cinhand > 0) fin = cinhand; else if (talon != NIL) { timesthru++; errmsg = TRUE; move(msgrow, msgcol); if (timesthru != 4) { printw("Talon is now the new hand"); this.runs += costofrunthroughhand; game.runs += costofrunthroughhand; total.runs += costofrunthroughhand; while (talon != NIL) { transit(&talon, &hand); cinhand++; } if (cinhand >= 3) fin = 3; else fin = cinhand; taloncnt = 0; coldrow = ctoprow; coldcol = cinitcol; cnewrow = ctoprow; cnewcol = cinitcol + cwidthcol; clearstat(); showstat(); } else { fin = 0; done = TRUE; printw("I believe you have lost"); refresh(); sleep(5); } } else { errmsg = TRUE; move(msgrow, msgcol); printw("Talon and hand are empty"); fin = 0; } for (i=0; ivisible = TRUE; if (Cflag) { if (talon->paid == FALSE && talon->visible == TRUE) { this.information += costofinformation; game.information += costofinformation; total.information += costofinformation; talon->paid = TRUE; } printcard(coldcol, coldrow, talon); } } if (fin != 0) { printcard(taloncol, talonrow, talon); cinhand -= fin; taloncnt += fin; if (Cflag) { move(handstatrow, handstatcol); printw("%3d", cinhand); move(talonstatrow, talonstatcol); printw("%3d", taloncnt); } fndbase(&talon, taloncol, talonrow); } } /* * procedure to print card counting info on screen */ showstat() { int row, col; - register struct cardtype *ptr; + struct cardtype *ptr; if (!Cflag) return; move(talonstatrow, talonstatcol - 7); printw("Talon: %3d", taloncnt); move(handstatrow, handstatcol - 7); printw("Hand: %3d", cinhand); move(stockstatrow, stockstatcol - 7); printw("Stock: %3d", stockcnt); for ( row = coldrow, col = coldcol, ptr = talon; ptr != NIL; ptr = ptr->next ) { if (ptr->paid == FALSE && ptr->visible == TRUE) { ptr->paid = TRUE; this.information += costofinformation; game.information += costofinformation; total.information += costofinformation; } printcard(col, row, ptr); DECRHAND(row, col); } for ( row = cnewrow, col = cnewcol, ptr = hand; ptr != NIL; ptr = ptr->next ) { if (ptr->paid == FALSE && ptr->visible == TRUE) { ptr->paid = TRUE; this.information += costofinformation; game.information += costofinformation; total.information += costofinformation; } INCRHAND(row, col); printcard(col, row, ptr); } } /* * procedure to clear card counting info from screen */ clearstat() { int row; move(talonstatrow, talonstatcol - 7); printw(" "); move(handstatrow, handstatcol - 7); printw(" "); move(stockstatrow, stockstatcol - 7); printw(" "); for ( row = ctoprow ; row <= cbotrow ; row++ ) { move(row, cinitcol); printw("%56s", " "); } } /* * procedure to update card counting base */ usedtalon() { removecard(coldcol, coldrow); DECRHAND(coldrow, coldcol); if (talon != NIL && (talon->visible == FALSE)) { talon->visible = TRUE; if (Cflag) { this.information += costofinformation; game.information += costofinformation; total.information += costofinformation; talon->paid = TRUE; printcard(coldcol, coldrow, talon); } } taloncnt--; if (Cflag) { move(talonstatrow, talonstatcol); printw("%3d", taloncnt); } } /* * procedure to update stock card counting base */ usedstock() { stockcnt--; if (Cflag) { move(stockstatrow, stockstatcol); printw("%3d", stockcnt); } } /* * let 'em know how they lost! */ showcards() { - register struct cardtype *ptr; + struct cardtype *ptr; int row; if (!Cflag || cardsoff == 52) return; for (ptr = talon; ptr != NIL; ptr = ptr->next) { ptr->visible = TRUE; ptr->paid = TRUE; } for (ptr = hand; ptr != NIL; ptr = ptr->next) { ptr->visible = TRUE; ptr->paid = TRUE; } showstat(); move(stockrow + 1, sidecol); printw(" "); move(talonrow - 2, sidecol); printw(" "); move(talonrow - 1, sidecol); printw(" "); move(talonrow, sidecol); printw(" "); move(talonrow + 1, sidecol); printw(" "); for (ptr = stock, row = stockrow; ptr != NIL; ptr = ptr->next, row++) { move(row, stockcol - 1); printw("| |"); printcard(stockcol, row, ptr); } if (stock == NIL) { move(row, stockcol - 1); printw("| |"); row++; } move(handstatrow, handstatcol - 7); printw(" "); move(row, stockcol - 1); printw("=---="); if ( cardsoff == 52 ) getcmd(moverow, movecol, "Hit return to exit"); } /* * procedure to update the betting values */ updatebettinginfo() { long thiscosts, gamecosts, totalcosts; double thisreturn, gamereturn, totalreturn; time_t now; - register long dollars; + long dollars; time(&now); dollars = (now - acctstart) / secondsperdollar; if (dollars > 0) { acctstart += dollars * secondsperdollar; if (dollars > maxtimecharge) dollars = maxtimecharge; this.thinktime += dollars; game.thinktime += dollars; total.thinktime += dollars; } thiscosts = this.hand + this.inspection + this.game + this.runs + this.information + this.thinktime; gamecosts = game.hand + game.inspection + game.game + game.runs + game.information + game.thinktime; totalcosts = total.hand + total.inspection + total.game + total.runs + total.information + total.thinktime; this.worth = this.wins - thiscosts; game.worth = game.wins - gamecosts; total.worth = total.wins - totalcosts; thisreturn = ((double)this.wins / (double)thiscosts - 1.0) * 100.0; gamereturn = ((double)game.wins / (double)gamecosts - 1.0) * 100.0; totalreturn = ((double)total.wins / (double)totalcosts - 1.0) * 100.0; if (status != BETTINGBOX) return; move(tboxrow + 2, boxcol + 13); printw("%4d%8d%9d", this.hand, game.hand, total.hand); move(tboxrow + 3, boxcol + 13); printw("%4d%8d%9d", this.inspection, game.inspection, total.inspection); move(tboxrow + 4, boxcol + 13); printw("%4d%8d%9d", this.game, game.game, total.game); move(tboxrow + 5, boxcol + 13); printw("%4d%8d%9d", this.runs, game.runs, total.runs); move(tboxrow + 6, boxcol + 13); printw("%4d%8d%9d", this.information, game.information, total.information); move(tboxrow + 7, boxcol + 13); printw("%4d%8d%9d", this.thinktime, game.thinktime, total.thinktime); move(tboxrow + 8, boxcol + 13); printw("%4d%8d%9d", thiscosts, gamecosts, totalcosts); move(tboxrow + 9, boxcol + 13); printw("%4d%8d%9d", this.wins, game.wins, total.wins); move(tboxrow + 10, boxcol + 13); printw("%4d%8d%9d", this.worth, game.worth, total.worth); move(tboxrow + 11, boxcol + 13); printw("%4.0f%%%7.1f%%%8.1f%%", thisreturn, gamereturn, totalreturn); } /* * procedure to move a card from the stock or talon to the tableau */ simpletableau(cp, des) struct cardtype **cp; { int origin; if (notempty(*cp)) { if (tabok(*cp, des)) { if (*cp == stock) origin = stk; else origin = tal; if (tableau[des] == NIL) bottom[des] = *cp; transit(cp, &tableau[des]); length[des]++; printcard(pilemap[des], length[des], tableau[des]); timesthru = 0; if (origin == stk) { usedstock(); printcard(stockcol, stockrow, stock); } else { usedtalon(); printcard(taloncol, talonrow, talon); } } else destinerror(); } } /* * print the tableau */ tabprint(sour, des) { int dlength, slength, i; struct cardtype *tempcard; for (i=tabrow; i<=length[sour]; i++) removecard(pilemap[sour], i); dlength = length[des] + 1; slength = length[sour]; if (slength == tabrow) printcard(pilemap[des], dlength, tableau[sour]); else while (slength != tabrow - 1) { tempcard = tableau[sour]; for (i=1; i<=slength-tabrow; i++) tempcard = tempcard->next; printcard(pilemap[des], dlength, tempcard); slength--; dlength++; } } /* * procedure to move from the tableau to the tableau */ tabtotab(sour, des) - register int sour, des; + int sour, des; { struct cardtype *temp; if (notempty(tableau[sour])) { if (tabok(bottom[sour], des)) { tabprint(sour, des); temp = bottom[sour]; bottom[sour] = NIL; if (bottom[des] == NIL) bottom[des] = temp; temp->next = tableau[des]; tableau[des] = tableau[sour]; tableau[sour] = NIL; length[des] = length[des] + (length[sour] - (tabrow - 1)); length[sour] = tabrow - 1; timesthru = 0; } else destinerror(); } } /* * functions to see if the card can go onto the foundation */ bool rankhigher(cp, let) struct cardtype *cp; { if (found[let]->rank == King) if (cp->rank == Ace) return(TRUE); else return(FALSE); else if (cp->rank - 1 == found[let]->rank) return(TRUE); else return(FALSE); } /* * function to determine if two cards are the same suit */ samesuit(cp, let) struct cardtype *cp; { if (cp->suit == found[let]->suit) return (TRUE); else return (FALSE); } /* * procedure to move a card to the correct foundation pile */ movetofound(cp, source) struct cardtype **cp; { tempbase = 0; mtfdone = FALSE; if (notempty(*cp)) { do { if (found[tempbase] != NIL) if (rankhigher(*cp, tempbase) && samesuit(*cp, tempbase)) { if (*cp == stock) mtforigin = stk; else if (*cp == talon) mtforigin = tal; else mtforigin = tab; transit(cp, &found[tempbase]); printcard(pilemap[tempbase], foundrow, found[tempbase]); timesthru = 0; if (mtforigin == stk) { usedstock(); printcard(stockcol, stockrow, stock); } else if (mtforigin == tal) { usedtalon(); printcard(taloncol, talonrow, talon); } else { removecard(pilemap[source], length[source]); length[source]--; } cardsoff++; if (infullgame) { this.wins += valuepercardup; game.wins += valuepercardup; total.wins += valuepercardup; } mtfdone = TRUE; } else tempbase++; else tempbase++; } while ((tempbase != 4) && !mtfdone); if (!mtfdone) destinerror(); } } /* * procedure to get a command */ getcmd(row, col, cp) int row, col; char *cp; { char cmd[2], ch; int i; i = 0; move(row, col); printw("%-24s", cp); col += 1 + strlen(cp); move(row, col); refresh(); do { ch = getch() & 0177; if (ch >= 'A' && ch <= 'Z') ch += ('a' - 'A'); if (ch == '\f') { wrefresh(curscr); refresh(); } else if (i >= 2 && ch != erasechar() && ch != killchar()) { if (ch != '\n' && ch != '\r' && ch != ' ') write(1, "\007", 1); } else if (ch == erasechar() && i > 0) { printw("\b \b"); refresh(); i--; } else if (ch == killchar() && i > 0) { while (i > 0) { printw("\b \b"); i--; } refresh(); } else if (ch == '\032') { /* Control-Z */ suspend(); move(row, col + i); refresh(); } else if (isprint(ch)) { cmd[i++] = ch; addch(ch); refresh(); } } while (ch != '\n' && ch != '\r' && ch != ' '); srcpile = cmd[0]; destpile = cmd[1]; } /* * Suspend the game (shell escape if no process control on system) */ suspend() { #ifndef SIGTSTP char *sh; #endif updatebettinginfo(); move(21, 0); refresh(); if (dbfd != -1) { lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET); write(dbfd, (char *)&total, sizeof(total)); } kill(getpid(), SIGTSTP); raw(); noecho(); } /* * procedure to evaluate and make the specific moves */ movecard() { int source, dest; char osrcpile, odestpile; done = FALSE; errmsg = FALSE; do { if (talon == NIL && hand != NIL) movetotalon(); if (cardsoff == 52) { refresh(); srcpile = 'q'; } else if (!startedgame) { move(msgrow, msgcol); errmsg = TRUE; switch (34 - taloncnt - cinhand) { default: errmsg = FALSE; break; case 1: printw("One card used from talon "); break; case 2: printw("Two cards used from talon "); break; case 3: printw(">3< cards used from talon "); break; } getcmd(moverow, movecol, "Move:"); } else getcmd(moverow, movecol, "Move:"); clearmsg(); if (srcpile >= '1' && srcpile <= '4') source = (int) (srcpile - '1'); if (destpile >= '1' && destpile <= '4') dest = (int) (destpile - '1'); if (!startedgame && (srcpile == 't' || srcpile == 's' || srcpile == 'h' || srcpile == '1' || srcpile == '2' || srcpile == '3' || srcpile == '4')) { startedgame = TRUE; osrcpile = srcpile; odestpile = destpile; if (status != BETTINGBOX) srcpile = 'y'; else do { getcmd(moverow, movecol, "Inspect game?"); } while (srcpile != 'y' && srcpile != 'n'); if (srcpile == 'n') { srcpile = 'q'; } else { this.inspection += costofinspection; game.inspection += costofinspection; total.inspection += costofinspection; srcpile = osrcpile; destpile = odestpile; } } switch (srcpile) { case 't': if (destpile == 'f' || destpile == 'F') movetofound(&talon, source); else if (destpile >= '1' && destpile <= '4') simpletableau(&talon, dest); else dumberror(); break; case 's': if (destpile == 'f' || destpile == 'F') movetofound(&stock, source); else if (destpile >= '1' && destpile <= '4') simpletableau(&stock, dest); else dumberror(); break; case 'h': if (destpile != 't' && destpile != 'T') { dumberror(); break; } if (infullgame) { movetotalon(); break; } if (status == BETTINGBOX) { do { getcmd(moverow, movecol, "Buy game?"); } while (srcpile != 'y' && srcpile != 'n'); if (srcpile == 'n') { showcards(); done = TRUE; break; } } infullgame = TRUE; this.wins += valuepercardup * cardsoff; game.wins += valuepercardup * cardsoff; total.wins += valuepercardup * cardsoff; this.game += costofgame; game.game += costofgame; total.game += costofgame; movetotalon(); break; case 'q': showcards(); done = TRUE; break; case 'b': printtopbettingbox(); printbottombettingbox(); status = BETTINGBOX; break; case 'x': clearabovemovebox(); clearbelowmovebox(); status = NOBOX; break; case 'i': printtopinstructions(); printbottominstructions(); status = INSTRUCTIONBOX; break; case 'c': Cflag = !Cflag; if (Cflag) showstat(); else clearstat(); break; case '1': case '2': case '3': case '4': if (destpile == 'f' || destpile == 'F') movetofound(&tableau[source], source); else if (destpile >= '1' && destpile <= '4') tabtotab(source, dest); else dumberror(); break; default: dumberror(); } fndbase(&stock, stockcol, stockrow); fndbase(&talon, taloncol, talonrow); updatebettinginfo(); } while (!done); } char *basicinstructions[] = { "Here are brief instuctions to the game of Canfield:\n\n", " If you have never played solitaire before, it is recom-\n", "mended that you consult a solitaire instruction book. In\n", "Canfield, tableau cards may be built on each other downward\n", "in alternate colors. An entire pile must be moved as a unit\n", "in building. Top cards of the piles are available to be able\n", "to be played on foundations, but never into empty spaces.\n\n", " Spaces must be filled from the stock. The top card of\n", "the stock also is available to be played on foundations or\n", "built on tableau piles. After the stock is exhausted, ta-\n", "bleau spaces may be filled from the talon and the player may\n", "keep them open until he wishes to use them.\n\n", " Cards are dealt from the hand to the talon by threes\n", "and this repeats until there are no more cards in the hand\n", "or the player quits. To have cards dealt onto the talon the\n", "player types 'ht' for his move. Foundation base cards are\n", "also automatically moved to the foundation when they become\n", "available.\n\n", "push any key when you are finished: ", 0 }; char *bettinginstructions[] = { " The rules for betting are somewhat less strict than\n", "those used in the official version of the game. The initial\n", "deal costs $13. You may quit at this point or inspect the\n", "game. Inspection costs $13 and allows you to make as many\n", "moves as is possible without moving any cards from your hand\n", "to the talon. (the initial deal places three cards on the\n", "talon; if all these cards are used, three more are made\n", "available) Finally, if the game seems interesting, you must\n", "pay the final installment of $26. At this point you are\n", "credited at the rate of $5 for each card on the foundation;\n", "as the game progresses you are credited with $5 for each\n", "card that is moved to the foundation. Each run through the\n", "hand after the first costs $5. The card counting feature\n", "costs $1 for each unknown card that is identified. If the\n", "information is toggled on, you are only charged for cards\n", "that became visible since it was last turned on. Thus the\n", "maximum cost of information is $34. Playing time is charged\n", "at a rate of $1 per minute.\n\n", "push any key when you are finished: ", 0 }; /* * procedure to printout instructions */ instruct() { - register char **cp; + char **cp; move(originrow, origincol); printw("This is the game of solitaire called Canfield. Do\n"); printw("you want instructions for the game?"); do { getcmd(originrow + 3, origincol, "y or n?"); } while (srcpile != 'y' && srcpile != 'n'); if (srcpile == 'n') return; clear(); for (cp = basicinstructions; *cp != 0; cp++) printw(*cp); refresh(); getch(); clear(); move(originrow, origincol); printw("Do you want instructions for betting?"); do { getcmd(originrow + 2, origincol, "y or n?"); } while (srcpile != 'y' && srcpile != 'n'); if (srcpile == 'n') return; clear(); for (cp = bettinginstructions; *cp != 0; cp++) printw(*cp); refresh(); getch(); } /* * procedure to initialize the game */ initall() { int i; if (dbfd < 0) return; srandomdev(); time(&acctstart); initdeck(deck); uid = getuid(); i = lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET); if (i < 0) { close(dbfd); dbfd = -1; return; } i = read(dbfd, (char *)&total, sizeof(total)); if (i < 0) { close(dbfd); dbfd = -1; return; } } /* * procedure to end the game */ bool finish() { int row, col; if (cardsoff == 52) { getcmd(moverow, movecol, "Hit return to exit"); clear(); refresh(); move(originrow, origincol); printw("CONGRATULATIONS!\n"); printw("You won the game. That is a feat to be proud of.\n"); row = originrow + 5; col = origincol; } else { move(msgrow, msgcol); printw("You got %d card", cardsoff); if (cardsoff > 1) printw("s"); printw(" off "); move(msgrow, msgcol); row = moverow; col = movecol; } do { getcmd(row, col, "Play again (y or n)?"); } while (srcpile != 'y' && srcpile != 'n'); errmsg = TRUE; clearmsg(); if (srcpile == 'y') return (FALSE); else return (TRUE); } /* * procedure to clean up and exit */ void cleanup() { total.thinktime += 1; status = NOBOX; updatebettinginfo(); if (dbfd != -1) { lseek(dbfd, uid * sizeof(struct betinfo), SEEK_SET); write(dbfd, (char *)&total, sizeof(total)); close(dbfd); } clear(); move(22,0); refresh(); endwin(); exit(0); /* NOTREACHED */ } /* * Field an interrupt. */ void askquit() { move(msgrow, msgcol); printw("Really wish to quit? "); do { getcmd(moverow, movecol, "y or n?"); } while (srcpile != 'y' && srcpile != 'n'); clearmsg(); if (srcpile == 'y') cleanup(); signal(SIGINT, askquit); } /* * Can you tell that this used to be a Pascal program? */ main() { dbfd = open(_PATH_SCORE, O_RDWR); /* revoke */ setgid(getgid()); #ifdef MAXLOAD double vec[3]; loadav(vec); if (vec[2] >= MAXLOAD) { puts("The system load is too high. Try again later."); exit(0); } #endif signal(SIGINT, askquit); signal(SIGHUP, cleanup); signal(SIGTERM, cleanup); initscr(); raw(); noecho(); initall(); instruct(); makeboard(); for (;;) { startgame(); movecard(); if (finish()) break; if (cardsoff == 52) makeboard(); else cleanupboard(); } cleanup(); /* NOTREACHED */ } diff --git a/games/canfield/cfscores/cfscores.c b/games/canfield/cfscores/cfscores.c index cc2d44b51bc8..1883696b61df 100644 --- a/games/canfield/cfscores/cfscores.c +++ b/games/canfield/cfscores/cfscores.c @@ -1,153 +1,153 @@ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1983, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)cfscores.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include "pathnames.h" struct betinfo { long hand; /* cost of dealing hand */ long inspection; /* cost of inspecting hand */ long game; /* cost of buying game */ long runs; /* cost of running through hands */ long information; /* cost of information */ long thinktime; /* cost of thinking time */ long wins; /* total winnings */ long worth; /* net worth after costs */ }; int dbfd; main(argc, argv) int argc; char *argv[]; { - register struct passwd *pw; + struct passwd *pw; int uid; if (argc > 2) { printf("Usage: cfscores [user]\n"); exit(1); } dbfd = open(_PATH_SCORE, O_RDONLY); if (dbfd < 0) { perror(_PATH_SCORE); exit(2); } setpwent(); if (argc == 1) { uid = getuid(); pw = getpwuid(uid); if (pw == 0) { printf("You are not listed in the password file?!?\n"); exit(2); } printuser(pw, 1); exit(0); } if (strcmp(argv[1], "-a") == 0) { while ((pw = getpwent()) != 0) printuser(pw, 0); exit(0); } pw = getpwnam(argv[1]); if (pw == 0) { printf("User %s unknown\n", argv[1]); exit(3); } printuser(pw, 1); exit(0); } /* * print out info for specified password entry */ printuser(pw, printfail) - register struct passwd *pw; + struct passwd *pw; int printfail; { struct betinfo total; int i; if (pw->pw_uid < 0) { printf("Bad uid %d\n", pw->pw_uid); return; } i = lseek(dbfd, pw->pw_uid * sizeof(struct betinfo), SEEK_SET); if (i < 0) { perror("lseek"); return; } i = read(dbfd, (char *)&total, sizeof(total)); if (i < 0) { perror("read"); return; } if (i == 0 || total.hand == 0) { if (printfail) printf("%s has never played canfield.\n", pw->pw_name); return; } printf("*----------------------*\n"); if (total.worth >= 0) printf("* Winnings for %-8s*\n", pw->pw_name); else printf("* Losses for %-10s*\n", pw->pw_name); printf("*======================*\n"); printf("|Costs Total |\n"); printf("| Hands %8ld |\n", total.hand); printf("| Inspections %8ld |\n", total.inspection); printf("| Games %8ld |\n", total.game); printf("| Runs %8ld |\n", total.runs); printf("| Information %8ld |\n", total.information); printf("| Think time %8ld |\n", total.thinktime); printf("|Total Costs %8ld |\n", total.wins - total.worth); printf("|Winnings %8ld |\n", total.wins); printf("|Net Worth %8ld |\n", total.worth); printf("*----------------------*\n\n"); } diff --git a/games/cribbage/cards.c b/games/cribbage/cards.c index 93c5ebf3d29f..9b678d43e800 100644 --- a/games/cribbage/cards.c +++ b/games/cribbage/cards.c @@ -1,149 +1,149 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include "deck.h" #include "cribbage.h" /* * Initialize a deck of cards to contain one of each type. */ void makedeck(d) CARD d[]; { - register int i, j, k; + int i, j, k; srandomdev(); k = 0; for (i = 0; i < RANKS; i++) for (j = 0; j < SUITS; j++) { d[k].suit = j; d[k++].rank = i; } } /* * Given a deck of cards, shuffle it -- i.e. randomize it * see Knuth, vol. 2, page 125. */ void shuffle(d) CARD d[]; { - register int j, k; + int j, k; CARD c; for (j = CARDS; j > 0; --j) { k = random() % j; /* random 0 <= k < j */ c = d[j - 1]; /* exchange (j - 1) and k */ d[j - 1] = d[k]; d[k] = c; } } /* * return true if the two cards are equal... */ int eq(a, b) CARD a, b; { return ((a.rank == b.rank) && (a.suit == b.suit)); } /* * isone returns TRUE if a is in the set of cards b */ int isone(a, b, n) CARD a, b[]; int n; { - register int i; + int i; for (i = 0; i < n; i++) if (eq(a, b[i])) return (TRUE); return (FALSE); } /* * remove the card a from the deck d of n cards */ void cremove(a, d, n) CARD a, d[]; int n; { - register int i, j; + int i, j; for (i = j = 0; i < n; i++) if (!eq(a, d[i])) d[j++] = d[i]; if (j < n) d[j].suit = d[j].rank = EMPTY; } /* * sorthand: * Sort a hand of n cards */ void sorthand(h, n) - register CARD h[]; + CARD h[]; int n; { - register CARD *cp, *endp; + CARD *cp, *endp; CARD c; for (endp = &h[n]; h < endp - 1; h++) for (cp = h + 1; cp < endp; cp++) if ((cp->rank < h->rank) || (cp->rank == h->rank && cp->suit < h->suit)) { c = *h; *h = *cp; *cp = c; } } diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c index df8e2bec8466..620651015c78 100644 --- a/games/cribbage/crib.c +++ b/games/cribbage/crib.c @@ -1,631 +1,631 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1980, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include #include #include "deck.h" #include "cribbage.h" #include "cribcur.h" #include "pathnames.h" int main(argc, argv) int argc; char *argv[]; { BOOLEAN playing; FILE *f; int ch; f = fopen(_PATH_LOG, "a"); /* revoke */ setgid(getgid()); while ((ch = getopt(argc, argv, "eqr")) != -1) switch (ch) { case 'e': explain = TRUE; break; case 'q': quiet = TRUE; break; case 'r': rflag = TRUE; break; case '?': default: (void) fprintf(stderr, "usage: cribbage [-eqr]\n"); exit(1); } initscr(); (void)signal(SIGINT, rint); crmode(); noecho(); Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0); Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X); Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X); Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1); leaveok(Playwin, TRUE); leaveok(Tablewin, TRUE); leaveok(Compwin, TRUE); clearok(stdscr, FALSE); if (!quiet) { msg("Do you need instructions for cribbage? "); if (getuchar() == 'Y') { endwin(); clear(); mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); instructions(); crmode(); noecho(); clear(); refresh(); msg("For cribbage rules, use \"man cribbage\""); } } playing = TRUE; do { wclrtobot(Msgwin); msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? "); if (glimit == SGAME) glimit = (getuchar() == 'L' ? LGAME : SGAME); else glimit = (getuchar() == 'S' ? SGAME : LGAME); game(); msg("Another game? "); playing = (getuchar() == 'Y'); } while (playing); if (f != NULL) { (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n", getlogin(), cgames, pgames); (void) fclose(f); } bye(); if (!f) { (void) fprintf(stderr, "\ncribbage: can't open %s.\n", _PATH_LOG); exit(1); } exit(0); } /* * makeboard: * Print out the initial board on the screen */ void makeboard() { mvaddstr(SCORE_Y + 0, SCORE_X, "+---------------------------------------+"); mvaddstr(SCORE_Y + 1, SCORE_X, "| Score: 0 YOU |"); mvaddstr(SCORE_Y + 2, SCORE_X, "| *.....:.....:.....:.....:.....:..... |"); mvaddstr(SCORE_Y + 3, SCORE_X, "| *.....:.....:.....:.....:.....:..... |"); mvaddstr(SCORE_Y + 4, SCORE_X, "| |"); mvaddstr(SCORE_Y + 5, SCORE_X, "| *.....:.....:.....:.....:.....:..... |"); mvaddstr(SCORE_Y + 6, SCORE_X, "| *.....:.....:.....:.....:.....:..... |"); mvaddstr(SCORE_Y + 7, SCORE_X, "| Score: 0 ME |"); mvaddstr(SCORE_Y + 8, SCORE_X, "+---------------------------------------+"); gamescore(); } /* * gamescore: * Print out the current game score */ void gamescore() { extern int Lastscore[]; if (pgames || cgames) { mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames); mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames); } Lastscore[0] = -1; Lastscore[1] = -1; } /* * game: * Play one game up to glimit points. Actually, we only ASK the * player what card to turn. We do a random one, anyway. */ void game() { - register int i, j; + int i, j; BOOLEAN flag; BOOLEAN compcrib; makedeck(deck); shuffle(deck); if (gamecount == 0) { flag = TRUE; do { if (!rflag) { /* player cuts deck */ msg(quiet ? "Cut for crib? " : "Cut to see whose crib it is -- low card wins? "); getline(); } i = random() % CARDS; /* random cut */ do { /* comp cuts deck */ j = random() % CARDS; } while (j == i); addmsg(quiet ? "You cut " : "You cut the "); msgcard(deck[i], FALSE); endmsg(); addmsg(quiet ? "I cut " : "I cut the "); msgcard(deck[j], FALSE); endmsg(); flag = (deck[i].rank == deck[j].rank); if (flag) { msg(quiet ? "We tied..." : "We tied and have to try again..."); shuffle(deck); continue; } else compcrib = (deck[i].rank > deck[j].rank); } while (flag); clear(); makeboard(); refresh(); } else { werase(Tablewin); wrefresh(Tablewin); werase(Compwin); wrefresh(Compwin); msg("Loser (%s) gets first crib", (iwon ? "you" : "me")); compcrib = !iwon; } pscore = cscore = 0; flag = TRUE; do { shuffle(deck); flag = !playhand(compcrib); compcrib = !compcrib; } while (flag); ++gamecount; if (cscore < pscore) { if (glimit - cscore > 60) { msg("YOU DOUBLE SKUNKED ME!"); pgames += 4; } else if (glimit - cscore > 30) { msg("YOU SKUNKED ME!"); pgames += 2; } else { msg("YOU WON!"); ++pgames; } iwon = FALSE; } else { if (glimit - pscore > 60) { msg("I DOUBLE SKUNKED YOU!"); cgames += 4; } else if (glimit - pscore > 30) { msg("I SKUNKED YOU!"); cgames += 2; } else { msg("I WON!"); ++cgames; } iwon = TRUE; } gamescore(); } /* * playhand: * Do up one hand of the game */ int playhand(mycrib) BOOLEAN mycrib; { - register int deckpos; + int deckpos; werase(Compwin); knownum = 0; deckpos = deal(mycrib); sorthand(chand, FULLHAND); sorthand(phand, FULLHAND); makeknown(chand, FULLHAND); prhand(phand, FULLHAND, Playwin, FALSE); discard(mycrib); if (cut(mycrib, deckpos)) return TRUE; if (peg(mycrib)) return TRUE; werase(Tablewin); wrefresh(Tablewin); if (score(mycrib)) return TRUE; return FALSE; } /* * deal cards to both players from deck */ int deal(mycrib) BOOLEAN mycrib; { - register int i, j; + int i, j; for (i = j = 0; i < FULLHAND; i++) { if (mycrib) { phand[i] = deck[j++]; chand[i] = deck[j++]; } else { chand[i] = deck[j++]; phand[i] = deck[j++]; } } return (j); } /* * discard: * Handle players discarding into the crib... * Note: we call cdiscard() after prining first message so player doesn't wait */ void discard(mycrib) BOOLEAN mycrib; { - register char *prompt; + char *prompt; CARD crd; prcrib(mycrib, TRUE); prompt = (quiet ? "Discard --> " : "Discard a card --> "); cdiscard(mycrib); /* puts best discard at end */ crd = phand[infrom(phand, FULLHAND, prompt)]; cremove(crd, phand, FULLHAND); prhand(phand, FULLHAND, Playwin, FALSE); crib[0] = crd; /* Next four lines same as last four except for cdiscard(). */ crd = phand[infrom(phand, FULLHAND - 1, prompt)]; cremove(crd, phand, FULLHAND - 1); prhand(phand, FULLHAND, Playwin, FALSE); crib[1] = crd; crib[2] = chand[4]; crib[3] = chand[5]; chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY; } /* * cut: * Cut the deck and set turnover. Actually, we only ASK the * player what card to turn. We do a random one, anyway. */ int cut(mycrib, pos) BOOLEAN mycrib; int pos; { - register int i; + int i; BOOLEAN win; win = FALSE; if (mycrib) { if (!rflag) { /* random cut */ msg(quiet ? "Cut the deck? " : "How many cards down do you wish to cut the deck? "); getline(); } i = random() % (CARDS - pos); turnover = deck[i + pos]; addmsg(quiet ? "You cut " : "You cut the "); msgcard(turnover, FALSE); endmsg(); if (turnover.rank == JACK) { msg("I get two for his heels"); win = chkscr(&cscore, 2); } } else { i = random() % (CARDS - pos) + pos; turnover = deck[i]; addmsg(quiet ? "I cut " : "I cut the "); msgcard(turnover, FALSE); endmsg(); if (turnover.rank == JACK) { msg("You get two for his heels"); win = chkscr(&pscore, 2); } } makeknown(&turnover, 1); prcrib(mycrib, FALSE); return (win); } /* * prcrib: * Print out the turnover card with crib indicator */ void prcrib(mycrib, blank) BOOLEAN mycrib, blank; { - register int y, cardx; + int y, cardx; if (mycrib) cardx = CRIB_X; else cardx = 0; mvaddstr(CRIB_Y, cardx + 1, "CRIB"); prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank); if (mycrib) cardx = 0; else cardx = CRIB_X; for (y = CRIB_Y; y <= CRIB_Y + 5; y++) mvaddstr(y, cardx, " "); } /* * peg: * Handle all the pegging... */ static CARD Table[14]; static int Tcnt; int peg(mycrib) BOOLEAN mycrib; { static CARD ch[CINHAND], ph[CINHAND]; - register int i, j, k; - register int l; - register int cnum, pnum, sum; - register BOOLEAN myturn, mego, ugo, last, played; + int i, j, k; + int l; + int cnum, pnum, sum; + BOOLEAN myturn, mego, ugo, last, played; CARD crd; cnum = pnum = CINHAND; for (i = 0; i < CINHAND; i++) { /* make copies of hands */ ch[i] = chand[i]; ph[i] = phand[i]; } Tcnt = 0; /* index to table of cards played */ sum = 0; /* sum of cards played */ mego = ugo = FALSE; myturn = !mycrib; for (;;) { last = TRUE; /* enable last flag */ prhand(ph, pnum, Playwin, FALSE); prhand(ch, cnum, Compwin, TRUE); prtable(sum); if (myturn) { /* my tyrn to play */ if (!anymove(ch, cnum, sum)) { /* if no card to play */ if (!mego && cnum) { /* go for comp? */ msg("GO"); mego = TRUE; } /* can player move? */ if (anymove(ph, pnum, sum)) myturn = !myturn; else { /* give him his point */ msg(quiet ? "You get one" : "You get one point"); if (chkscr(&pscore, 1)) return TRUE; sum = 0; mego = ugo = FALSE; Tcnt = 0; } } else { played = TRUE; j = -1; k = 0; /* maximize score */ for (i = 0; i < cnum; i++) { l = pegscore(ch[i], Table, Tcnt, sum); if (l > k) { k = l; j = i; } } if (j < 0) /* if nothing scores */ j = cchose(ch, cnum, sum); crd = ch[j]; cremove(crd, ch, cnum--); sum += VAL(crd.rank); Table[Tcnt++] = crd; if (k > 0) { addmsg(quiet ? "I get %d playing " : "I get %d points playing ", k); msgcard(crd, FALSE); endmsg(); if (chkscr(&cscore, k)) return TRUE; } myturn = !myturn; } } else { if (!anymove(ph, pnum, sum)) { /* can player move? */ if (!ugo && pnum) { /* go for player */ msg("You have a GO"); ugo = TRUE; } /* can computer play? */ if (anymove(ch, cnum, sum)) myturn = !myturn; else { msg(quiet ? "I get one" : "I get one point"); do_wait(); if (chkscr(&cscore, 1)) return TRUE; sum = 0; mego = ugo = FALSE; Tcnt = 0; } } else { /* player plays */ played = FALSE; if (pnum == 1) { crd = ph[0]; msg("You play your last card"); } else for (;;) { prhand(ph, pnum, Playwin, FALSE); crd = ph[infrom(ph, pnum, "Your play: ")]; if (sum + VAL(crd.rank) <= 31) break; else msg("Total > 31 -- try again"); } makeknown(&crd, 1); cremove(crd, ph, pnum--); i = pegscore(crd, Table, Tcnt, sum); sum += VAL(crd.rank); Table[Tcnt++] = crd; if (i > 0) { msg(quiet ? "You got %d" : "You got %d points", i); if (chkscr(&pscore, i)) return TRUE; } myturn = !myturn; } } if (sum >= 31) { if (!myturn) do_wait(); sum = 0; mego = ugo = FALSE; Tcnt = 0; last = FALSE; /* disable last flag */ } if (!pnum && !cnum) break; /* both done */ } prhand(ph, pnum, Playwin, FALSE); prhand(ch, cnum, Compwin, TRUE); prtable(sum); if (last) { if (played) { msg(quiet ? "I get one for last" : "I get one point for last"); do_wait(); if (chkscr(&cscore, 1)) return TRUE; } else { msg(quiet ? "You get one for last" : "You get one point for last"); if (chkscr(&pscore, 1)) return TRUE; } } return (FALSE); } /* * prtable: * Print out the table with the current score */ void prtable(score) int score; { prhand(Table, Tcnt, Tablewin, FALSE); mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score); wrefresh(Tablewin); } /* * score: * Handle the scoring of the hands */ int score(mycrib) BOOLEAN mycrib; { sorthand(crib, CINHAND); if (mycrib) { if (plyrhand(phand, "hand")) return (TRUE); if (comphand(chand, "hand")) return (TRUE); do_wait(); if (comphand(crib, "crib")) return (TRUE); } else { if (comphand(chand, "hand")) return (TRUE); if (plyrhand(phand, "hand")) return (TRUE); if (plyrhand(crib, "crib")) return (TRUE); } return (FALSE); } diff --git a/games/cribbage/io.c b/games/cribbage/io.c index 32a2436fe6f4..96b92dbb89fe 100644 --- a/games/cribbage/io.c +++ b/games/cribbage/io.c @@ -1,626 +1,626 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include #include #include #if __STDC__ #include #else #include #endif #include "deck.h" #include "cribbage.h" #include "cribcur.h" #define LINESIZE 128 #ifdef CTRL #undef CTRL #endif #define CTRL(X) (X - 'A' + 1) char linebuf[LINESIZE]; char *rankname[RANKS] = { "ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING" }; char *rankchar[RANKS] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" }; char *suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"}; char *suitchar[SUITS] = {"S", "H", "D", "C"}; /* * msgcard: * Call msgcrd in one of two forms */ int msgcard(c, brief) CARD c; BOOLEAN brief; { if (brief) return (msgcrd(c, TRUE, NULL, TRUE)); else return (msgcrd(c, FALSE, " of ", FALSE)); } /* * msgcrd: * Print the value of a card in ascii */ int msgcrd(c, brfrank, mid, brfsuit) CARD c; BOOLEAN brfrank, brfsuit; char *mid; { if (c.rank == EMPTY || c.suit == EMPTY) return (FALSE); if (brfrank) addmsg("%1.1s", rankchar[c.rank]); else addmsg(rankname[c.rank]); if (mid != NULL) addmsg(mid); if (brfsuit) addmsg("%1.1s", suitchar[c.suit]); else addmsg(suitname[c.suit]); return (TRUE); } /* * printcard: * Print out a card. */ void printcard(win, cardno, c, blank) WINDOW *win; int cardno; CARD c; BOOLEAN blank; { prcard(win, cardno * 2, cardno, c, blank); } /* * prcard: * Print out a card on the window at the specified location */ void prcard(win, y, x, c, blank) WINDOW *win; int y, x; CARD c; BOOLEAN blank; { if (c.rank == EMPTY) return; mvwaddstr(win, y + 0, x, "+-----+"); mvwaddstr(win, y + 1, x, "| |"); mvwaddstr(win, y + 2, x, "| |"); mvwaddstr(win, y + 3, x, "| |"); mvwaddstr(win, y + 4, x, "+-----+"); if (!blank) { mvwaddch(win, y + 1, x + 1, rankchar[c.rank][0]); waddch(win, suitchar[c.suit][0]); mvwaddch(win, y + 3, x + 4, rankchar[c.rank][0]); waddch(win, suitchar[c.suit][0]); } } /* * prhand: * Print a hand of n cards */ void prhand(h, n, win, blank) CARD h[]; int n; WINDOW *win; BOOLEAN blank; { - register int i; + int i; werase(win); for (i = 0; i < n; i++) printcard(win, i, *h++, blank); wrefresh(win); } /* * infrom: * reads a card, supposedly in hand, accepting unambigous brief * input, returns the index of the card found... */ int infrom(hand, n, prompt) CARD hand[]; int n; char *prompt; { - register int i, j; + int i, j; CARD crd; if (n < 1) { printf("\nINFROM: %d = n < 1!!\n", n); exit(74); } for (;;) { msg(prompt); if (incard(&crd)) { /* if card is full card */ if (!isone(crd, hand, n)) msg("That's not in your hand"); else { for (i = 0; i < n; i++) if (hand[i].rank == crd.rank && hand[i].suit == crd.suit) break; if (i >= n) { printf("\nINFROM: isone or something messed up\n"); exit(77); } return (i); } } else /* if not full card... */ if (crd.rank != EMPTY) { for (i = 0; i < n; i++) if (hand[i].rank == crd.rank) break; if (i >= n) msg("No such rank in your hand"); else { for (j = i + 1; j < n; j++) if (hand[j].rank == crd.rank) break; if (j < n) msg("Ambiguous rank"); else return (i); } } else msg("Sorry, I missed that"); } /* NOTREACHED */ } /* * incard: * Inputs a card in any format. It reads a line ending with a CR * and then parses it. */ int incard(crd) CARD *crd; { - register int i; + int i; int rnk, sut; char *line, *p, *p1; BOOLEAN retval; retval = FALSE; rnk = sut = EMPTY; if (!(line = getline())) goto gotit; p = p1 = line; while (*p1 != ' ' && *p1 != '\0') ++p1; *p1++ = '\0'; if (*p == '\0') goto gotit; /* IMPORTANT: no real card has 2 char first name */ if (strlen(p) == 2) { /* check for short form */ rnk = EMPTY; for (i = 0; i < RANKS; i++) { if (*p == *rankchar[i]) { rnk = i; break; } } if (rnk == EMPTY) goto gotit; /* it's nothing... */ ++p; /* advance to next char */ sut = EMPTY; for (i = 0; i < SUITS; i++) { if (*p == *suitchar[i]) { sut = i; break; } } if (sut != EMPTY) retval = TRUE; goto gotit; } rnk = EMPTY; for (i = 0; i < RANKS; i++) { if (!strcmp(p, rankname[i]) || !strcmp(p, rankchar[i])) { rnk = i; break; } } if (rnk == EMPTY) goto gotit; p = p1; while (*p1 != ' ' && *p1 != '\0') ++p1; *p1++ = '\0'; if (*p == '\0') goto gotit; if (!strcmp("OF", p)) { p = p1; while (*p1 != ' ' && *p1 != '\0') ++p1; *p1++ = '\0'; if (*p == '\0') goto gotit; } sut = EMPTY; for (i = 0; i < SUITS; i++) { if (!strcmp(p, suitname[i]) || !strcmp(p, suitchar[i])) { sut = i; break; } } if (sut != EMPTY) retval = TRUE; gotit: (*crd).rank = rnk; (*crd).suit = sut; return (retval); } /* * getuchar: * Reads and converts to upper case */ int getuchar() { - register int c; + int c; c = readchar(); if (islower(c)) c = toupper(c); waddch(Msgwin, c); return (c); } /* * number: * Reads in a decimal number and makes sure it is between "lo" and * "hi" inclusive. */ int number(lo, hi, prompt) int lo, hi; char *prompt; { - register char *p; - register int sum; + char *p; + int sum; for (sum = 0;;) { msg(prompt); if (!(p = getline()) || *p == '\0') { msg(quiet ? "Not a number" : "That doesn't look like a number"); continue; } sum = 0; if (!isdigit(*p)) sum = lo - 1; else while (isdigit(*p)) { sum = 10 * sum + (*p - '0'); ++p; } if (*p != ' ' && *p != '\t' && *p != '\0') sum = lo - 1; if (sum >= lo && sum <= hi) break; if (sum == lo - 1) msg("that doesn't look like a number, try again --> "); else msg("%d is not between %d and %d inclusive, try again --> ", sum, lo, hi); } return (sum); } /* * msg: * Display a message at the top of the screen. */ char Msgbuf[BUFSIZ] = {'\0'}; int Mpos = 0; static int Newpos = 0; void #if __STDC__ msg(const char *fmt, ...) #else msg(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void)vsprintf(&Msgbuf[Newpos], fmt, ap); va_end(ap); endmsg(); } /* * addmsg: * Add things to the current message */ void #if __STDC__ addmsg(const char *fmt, ...) #else addmsg(fmt, va_alist) char *fmt; va_dcl #endif { va_list ap; #if __STDC__ va_start(ap, fmt); #else va_start(ap); #endif (void)vsprintf(&Msgbuf[Newpos], fmt, ap); va_end(ap); } /* * endmsg: * Display a new msg. */ int Lineno = 0; void endmsg() { static int lastline = 0; - register int len; - register char *mp, *omp; + int len; + char *mp, *omp; /* All messages should start with uppercase */ mvaddch(lastline + Y_MSG_START, SCORE_X, ' '); if (islower(Msgbuf[0]) && Msgbuf[1] != ')') Msgbuf[0] = toupper(Msgbuf[0]); mp = Msgbuf; len = strlen(mp); if (len / MSG_X + Lineno >= MSG_Y) { while (Lineno < MSG_Y) { wmove(Msgwin, Lineno++, 0); wclrtoeol(Msgwin); } Lineno = 0; } mvaddch(Lineno + Y_MSG_START, SCORE_X, '*'); lastline = Lineno; do { mvwaddstr(Msgwin, Lineno, 0, mp); if ((len = strlen(mp)) > MSG_X) { omp = mp; for (mp = &mp[MSG_X - 1]; *mp != ' '; mp--) continue; while (*mp == ' ') mp--; mp++; wmove(Msgwin, Lineno, mp - omp); wclrtoeol(Msgwin); } if (++Lineno >= MSG_Y) Lineno = 0; } while (len > MSG_X); wclrtoeol(Msgwin); Mpos = len; Newpos = 0; wrefresh(Msgwin); refresh(); wrefresh(Msgwin); } /* * do_wait: * Wait for the user to type ' ' before doing anything else */ void do_wait() { static char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'}; if (Mpos + sizeof prompt < MSG_X) wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos); else { mvwaddch(Msgwin, Lineno, 0, ' '); wclrtoeol(Msgwin); if (++Lineno >= MSG_Y) Lineno = 0; } waddstr(Msgwin, prompt); wrefresh(Msgwin); wait_for(' '); } /* * wait_for * Sit around until the guy types the right key */ void wait_for(ch) - register int ch; + int ch; { - register char c; + char c; if (ch == '\n') while ((c = readchar()) != '\n') continue; else while (readchar() != ch) continue; } /* * readchar: * Reads and returns a character, checking for gross input errors */ int readchar() { - register int cnt; + int cnt; char c; over: cnt = 0; while (read(STDIN_FILENO, &c, sizeof(char)) <= 0) if (cnt++ > 100) { /* if we are getting infinite EOFs */ bye(); /* quit the game */ exit(1); } if (c == CTRL('L')) { wrefresh(curscr); goto over; } if (c == '\r') return ('\n'); else return (c); } /* * getline: * Reads the next line up to '\n' or EOF. Multiple spaces are * compressed to one space; a space is inserted before a ',' */ char * getline() { - register char *sp; - register int c, oy, ox; - register WINDOW *oscr; + char *sp; + int c, oy, ox; + WINDOW *oscr; oscr = stdscr; stdscr = Msgwin; getyx(stdscr, oy, ox); refresh(); /* loop reading in the string, and put it in a temporary buffer */ for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) { if (c == -1) continue; else if (c == erasechar()) { /* process erase character */ if (sp > linebuf) { - register int i; + int i; sp--; for (i = strlen(unctrl(*sp)); i; i--) addch('\b'); } continue; } else if (c == killchar()) { /* process kill * character */ sp = linebuf; move(oy, ox); continue; } else if (sp == linebuf && c == ' ') continue; if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' ')) putchar(CTRL('G')); else { if (islower(c)) c = toupper(c); *sp++ = c; addstr(unctrl(c)); Mpos++; } } *sp = '\0'; stdscr = oscr; return (linebuf); } void rint(signo) int signo; { bye(); exit(1); } /* * bye: * Leave the program, cleaning things up as we go. */ void bye() { signal(SIGINT, SIG_IGN); mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); endwin(); putchar('\n'); } diff --git a/games/cribbage/score.c b/games/cribbage/score.c index 7a5d1aa20025..d81ebcea6aa8 100644 --- a/games/cribbage/score.c +++ b/games/cribbage/score.c @@ -1,371 +1,371 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include "deck.h" #include "cribbage.h" /* * the following arrays give the sum of the scores of the (50 2)*48 = 58800 * hands obtainable for the crib given the two cards whose ranks index the * array. the two arrays are for the case where the suits are equal and * not equal respectively */ long crbescr[169] = { -10000, 271827, 278883, 332319, 347769, 261129, 250653, 253203, 248259, 243435, 256275, 237435, 231051, -10000, -10000, 412815, 295707, 349497, 267519, 262521, 259695, 254019, 250047, 262887, 244047, 237663, -10000, -10000, -10000, 333987, 388629, 262017, 266787, 262971, 252729, 254475, 267315, 248475, 242091, -10000, -10000, -10000, -10000, 422097, 302787, 256437, 263751, 257883, 254271, 267111, 248271, 241887, -10000, -10000, -10000, -10000, -10000, 427677, 387837, 349173, 347985, 423861, 436701, 417861, 411477, -10000, -10000, -10000, -10000, -10000, -10000, 336387, 298851, 338667, 236487, 249327, 230487, 224103, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 408483, 266691, 229803, 246195, 227355, 220971, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 300675, 263787, 241695, 226407, 220023, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 295635, 273543, 219771, 216939, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 306519, 252747, 211431, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 304287, 262971, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 244131, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000 }; long crbnescr[169] = { 325272, 260772, 267828, 321264, 336714, 250074, 239598, 242148, 237204, 232380, 246348, 226380, 219996, -10000, 342528, 401760, 284652, 338442, 256464, 251466, 248640, 242964, 238992, 252960, 232992, 226608, -10000, -10000, 362280, 322932, 377574, 250962, 255732, 251916, 241674, 243420, 257388, 237420, 231036, -10000, -10000, -10000, 360768, 411042, 291732, 245382, 252696, 246828, 243216, 257184, 237216, 230832, -10000, -10000, -10000, -10000, 528768, 416622, 376782, 338118, 336930, 412806, 426774, 406806, 400422, -10000, -10000, -10000, -10000, -10000, 369864, 325332, 287796, 327612, 225432, 239400, 219432, 213048, -10000, -10000, -10000, -10000, -10000, -10000, 359160, 397428, 255636, 218748, 236268, 216300, 209916, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 331320, 289620, 252732, 231768, 215352, 208968, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 325152, 284580, 263616, 208716, 205884, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 321240, 296592, 241692, 200376, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 348600, 294360, 253044, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 308664, 233076, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, 295896 }; static int ichoose2[5] = { 0, 0, 2, 6, 12 }; static int pairpoints, runpoints; /* Globals from pairuns. */ /* * scorehand: * Score the given hand of n cards and the starter card. * n must be <= 4 */ int scorehand(hand, starter, n, crb, do_explain) - register CARD hand[]; + CARD hand[]; CARD starter; int n; BOOLEAN crb; /* true if scoring crib */ BOOLEAN do_explain; /* true if must explain this hand */ { - register int i, k; - register int score; - register BOOLEAN flag; + int i, k; + int score; + BOOLEAN flag; CARD h[(CINHAND + 1)]; char buf[32]; expl[0] = '\0'; /* initialize explanation */ score = 0; flag = TRUE; k = hand[0].suit; for (i = 0; i < n; i++) { /* check for flush */ flag = (flag && (hand[i].suit == k)); if (hand[i].rank == JACK) /* check for his nibs */ if (hand[i].suit == starter.suit) { score++; if (do_explain) strcat(expl, "His Nobs"); } h[i] = hand[i]; } if (flag && n >= CINHAND) { if (do_explain && expl[0] != '\0') strcat(expl, ", "); if (starter.suit == k) { score += 5; if (do_explain) strcat(expl, "Five-flush"); } else if (!crb) { score += 4; if (do_explain && expl[0] != '\0') strcat(expl, ", Four-flush"); else strcpy(expl, "Four-flush"); } } if (do_explain && expl[0] != '\0') strcat(expl, ", "); h[n] = starter; sorthand(h, n + 1); /* sort by rank */ i = 2 * fifteens(h, n + 1); score += i; if (do_explain) { if (i > 0) { (void) sprintf(buf, "%d points in fifteens", i); strcat(expl, buf); } else strcat(expl, "No fifteens"); } i = pairuns(h, n + 1); score += i; if (do_explain) { if (i > 0) { (void) sprintf(buf, ", %d points in pairs, %d in runs", pairpoints, runpoints); strcat(expl, buf); } else strcat(expl, ", No pairs/runs"); } return (score); } /* * fifteens: * Return number of fifteens in hand of n cards */ int fifteens(hand, n) - register CARD hand[]; + CARD hand[]; int n; { - register int *sp, *np; - register int i; - register CARD *endp; + int *sp, *np; + int i; + CARD *endp; static int sums[15], nsums[15]; np = nsums; sp = sums; i = 16; while (--i) { *np++ = 0; *sp++ = 0; } for (endp = &hand[n]; hand < endp; hand++) { i = hand->rank + 1; if (i > 10) i = 10; np = &nsums[i]; np[-1]++; /* one way to make this */ sp = sums; while (i < 15) { *np++ += *sp++; i++; } sp = sums; np = nsums; i = 16; while (--i) *sp++ = *np++; } return sums[14]; } /* * pairuns returns the number of points in the n card sorted hand * due to pairs and runs * this routine only works if n is strictly less than 6 * sets the globals pairpoints and runpoints appropriately */ int pairuns(h, n) CARD h[]; int n; { - register int i; + int i; int runlength, runmult, lastmult, curmult; int mult1, mult2, pair1, pair2; BOOLEAN run; run = TRUE; runlength = 1; mult1 = 1; pair1 = -1; mult2 = 1; pair2 = -1; curmult = runmult = 1; for (i = 1; i < n; i++) { lastmult = curmult; if (h[i].rank == h[i - 1].rank) { if (pair1 < 0) { pair1 = h[i].rank; mult1 = curmult = 2; } else { if (h[i].rank == pair1) { curmult = ++mult1; } else { if (pair2 < 0) { pair2 = h[i].rank; mult2 = curmult = 2; } else { curmult = ++mult2; } } } if (i == (n - 1) && run) { runmult *= curmult; } } else { curmult = 1; if (h[i].rank == h[i - 1].rank + 1) { if (run) { ++runlength; } else { /* only if old short */ if (runlength < 3) { run = TRUE; runlength = 2; runmult = 1; } } runmult *= lastmult; } else { /* if just ended */ if (run) runmult *= lastmult; run = FALSE; } } } pairpoints = ichoose2[mult1] + ichoose2[mult2]; runpoints = (runlength >= 3 ? runlength * runmult : 0); return (pairpoints + runpoints); } /* * pegscore tells how many points crd would get if played after * the n cards in tbl during pegging */ int pegscore(crd, tbl, n, sum) CARD crd, tbl[]; int n, sum; { BOOLEAN got[RANKS]; - register int i, j, scr; + int i, j, scr; int k, lo, hi; sum += VAL(crd.rank); if (sum > 31) return (-1); if (sum == 31 || sum == 15) scr = 2; else scr = 0; if (!n) return (scr); j = 1; while ((crd.rank == tbl[n - j].rank) && (n - j >= 0)) ++j; if (j > 1) return (scr + ichoose2[j]); if (n < 2) return (scr); lo = hi = crd.rank; for (i = 0; i < RANKS; i++) got[i] = FALSE; got[crd.rank] = TRUE; k = -1; for (i = n - 1; i >= 0; --i) { if (got[tbl[i].rank]) break; got[tbl[i].rank] = TRUE; if (tbl[i].rank < lo) lo = tbl[i].rank; if (tbl[i].rank > hi) hi = tbl[i].rank; for (j = lo; j <= hi; j++) if (!got[j]) break; if (j > hi) k = hi - lo + 1; } if (k >= 3) return (scr + k); else return (scr); } /* * adjust takes a two card hand that will be put in the crib * and returns an adjusted normalized score for the number of * points such a crib will get. */ int adjust(cb, tnv) CARD cb[], tnv; { long scr; int i, c0, c1; c0 = cb[0].rank; c1 = cb[1].rank; if (c0 > c1) { i = c0; c0 = c1; c1 = i; } if (cb[0].suit != cb[1].suit) scr = crbnescr[RANKS * c0 + c1]; else scr = crbescr[RANKS * c0 + c1]; if (scr <= 0) { printf("\nADJUST: internal error %d %d\n", c0, c1); exit(93); } return ((scr + 29400) / 58800); } diff --git a/games/cribbage/support.c b/games/cribbage/support.c index f4ee2a98a695..60d9f5bc3280 100644 --- a/games/cribbage/support.c +++ b/games/cribbage/support.c @@ -1,360 +1,360 @@ /*- * Copyright (c) 1980, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char sccsid[] = "@(#)support.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include "deck.h" #include "cribbage.h" #include "cribcur.h" #define NTV 10 /* number scores to test */ /* score to test reachability of, and order to test them in */ int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; /* * computer chooses what to play in pegging... * only called if no playable card will score points */ int cchose(h, n, s) CARD h[]; int n, s; { - register int i, j, l; + int i, j, l; if (n <= 1) return (0); if (s < 4) { /* try for good value */ if ((j = anysumto(h, n, s, 4)) >= 0) return (j); if ((j = anysumto(h, n, s, 3)) >= 0 && s == 0) return (j); } if (s > 0 && s < 20) { /* try for retaliation to 31 */ for (i = 1; i <= 10; i++) { if ((j = anysumto(h, n, s, 21 - i)) >= 0) { if ((l = numofval(h, n, i)) > 0) { if (l > 1 || VAL(h[j].rank) != i) return (j); } } } } if (s < 15) { /* for retaliation after 15 */ for (i = 0; i < NTV; i++) { if ((j = anysumto(h, n, s, tv[i])) >= 0) { if ((l = numofval(h, n, 15 - tv[i])) > 0) { if (l > 1 || VAL(h[j].rank) != 15 - tv[i]) return (j); } } } } j = -1; /* remember: h is sorted */ for (i = n - 1; i >= 0; --i) { l = s + VAL(h[i].rank); if (l > 31) continue; if (l != 5 && l != 10 && l != 21) { j = i; break; } } if (j >= 0) return (j); for (i = n - 1; i >= 0; --i) { l = s + VAL(h[i].rank); if (l > 31) continue; if (j < 0) j = i; if (l != 5 && l != 21) { j = i; break; } } return (j); } /* * plyrhand: * Evaluate and score a player hand or crib */ int plyrhand(hand, s) CARD hand[]; char *s; { static char prompt[BUFSIZ]; - register int i, j; - register BOOLEAN win; + int i, j; + BOOLEAN win; prhand(hand, CINHAND, Playwin, FALSE); (void) sprintf(prompt, "Your %s scores ", s); i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain); if ((j = number(0, 29, prompt)) == 19) j = 0; if (i != j) { if (i < j) { win = chkscr(&pscore, i); msg("It's really only %d points; I get %d", i, 2); if (!win) win = chkscr(&cscore, 2); } else { win = chkscr(&pscore, j); msg("You should have taken %d, not %d!", i, j); } if (explain) msg("Explanation: %s", expl); do_wait(); } else win = chkscr(&pscore, i); return (win); } /* * comphand: * Handle scoring and displaying the computers hand */ int comphand(h, s) CARD h[]; char *s; { - register int j; + int j; j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, FALSE); prhand(h, CINHAND, Compwin, FALSE); msg("My %s scores %d", s, (j == 0 ? 19 : j)); return (chkscr(&cscore, j)); } /* * chkscr: * Add inc to scr and test for > glimit, printing on the scoring * board while we're at it. */ int Lastscore[2] = {-1, -1}; int chkscr(scr, inc) int *scr, inc; { BOOLEAN myturn; myturn = (scr == &cscore); if (inc != 0) { prpeg(Lastscore[myturn], '.', myturn); Lastscore[myturn] = *scr; *scr += inc; prpeg(*scr, PEG, myturn); refresh(); } return (*scr >= glimit); } /* * prpeg: * Put out the peg character on the score board and put the * score up on the board. */ void prpeg(score, peg, myturn) - register int score; + int score; int peg; BOOLEAN myturn; { - register int y, x; + int y, x; if (!myturn) y = SCORE_Y + 2; else y = SCORE_Y + 5; if (score <= 0 || score >= glimit) { if (peg == '.') peg = ' '; if (score == 0) x = SCORE_X + 2; else { x = SCORE_X + 2; y++; } } else { x = (score - 1) % 30; if (score > 90 || (score > 30 && score <= 60)) { y++; x = 29 - x; } x += x / 5; x += SCORE_X + 3; } mvaddch(y, x, peg); mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", score); } /* * cdiscard -- the computer figures out what is the best discard for * the crib and puts the best two cards at the end */ void cdiscard(mycrib) BOOLEAN mycrib; { CARD d[CARDS], h[FULLHAND], cb[2]; - register int i, j, k; + int i, j, k; int nc, ns; long sums[15]; static int undo1[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4}; static int undo2[15] = {1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 5, 4, 5, 5}; makedeck(d); nc = CARDS; for (i = 0; i < knownum; i++) { /* get all other cards */ cremove(known[i], d, nc--); } for (i = 0; i < 15; i++) sums[i] = 0L; ns = 0; for (i = 0; i < (FULLHAND - 1); i++) { cb[0] = chand[i]; for (j = i + 1; j < FULLHAND; j++) { cb[1] = chand[j]; for (k = 0; k < FULLHAND; k++) h[k] = chand[k]; cremove(chand[i], h, FULLHAND); cremove(chand[j], h, FULLHAND - 1); for (k = 0; k < nc; k++) { sums[ns] += scorehand(h, d[k], CINHAND, TRUE, FALSE); if (mycrib) sums[ns] += adjust(cb, d[k]); else sums[ns] -= adjust(cb, d[k]); } ++ns; } } j = 0; for (i = 1; i < 15; i++) if (sums[i] > sums[j]) j = i; for (k = 0; k < FULLHAND; k++) h[k] = chand[k]; cremove(h[undo1[j]], chand, FULLHAND); cremove(h[undo2[j]], chand, FULLHAND - 1); chand[4] = h[undo1[j]]; chand[5] = h[undo2[j]]; } /* * returns true if some card in hand can be played without exceeding 31 */ int anymove(hand, n, sum) CARD hand[]; int n, sum; { - register int i, j; + int i, j; if (n < 1) return (FALSE); j = hand[0].rank; for (i = 1; i < n; i++) { if (hand[i].rank < j) j = hand[i].rank; } return (sum + VAL(j) <= 31); } /* * anysumto returns the index (0 <= i < n) of the card in hand that brings * the s up to t, or -1 if there is none */ int anysumto(hand, n, s, t) CARD hand[]; int n, s, t; { - register int i; + int i; for (i = 0; i < n; i++) { if (s + VAL(hand[i].rank) == t) return (i); } return (-1); } /* * return the number of cards in h having the given rank value */ int numofval(h, n, v) CARD h[]; int n, v; { - register int i, j; + int i, j; j = 0; for (i = 0; i < n; i++) { if (VAL(h[i].rank) == v) ++j; } return (j); } /* * makeknown remembers all n cards in h for future recall */ void makeknown(h, n) CARD h[]; int n; { - register int i; + int i; for (i = 0; i < n; i++) known[knownum++] = h[i]; } diff --git a/games/dm/dm.c b/games/dm/dm.c index 0e63a733db32..d20de608d99d 100644 --- a/games/dm/dm.c +++ b/games/dm/dm.c @@ -1,337 +1,337 @@ /* * Copyright (c) 1987, 1993 * The Regents of the University of California. 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1987, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pathnames.h" extern int errno; static time_t now; /* current time value */ static int priority = 0; /* priority game runs at */ static char *game, /* requested game */ *gametty; /* from tty? */ int main(argc, argv) int argc; char *argv[]; { char *cp; nogamefile(); game = (cp = strrchr(*argv, '/')) ? ++cp : *argv; if (!strcmp(game, "dm")) exit(0); gametty = ttyname(0); unsetenv("TZ"); (void)time(&now); read_config(); #ifdef LOG logfile(); #endif play(argv); /*NOTREACHED*/ } /* * play -- * play the game */ play(args) char **args; { char pbuf[MAXPATHLEN]; if (sizeof(_PATH_HIDE) + strlen(game) > sizeof(pbuf)) { (void)fprintf(stderr, "dm: %s/%s: %s\n", _PATH_HIDE, game, strerror(ENAMETOOLONG)); exit(1); } (void)strcpy(pbuf, _PATH_HIDE); (void)strcpy(pbuf + sizeof(_PATH_HIDE) - 1, game); if (priority > 0) /* < 0 requires root */ (void)setpriority(PRIO_PROCESS, 0, priority); execv(pbuf, args); (void)fprintf(stderr, "dm: %s: %s\n", pbuf, strerror(errno)); exit(1); } /* * read_config -- * read through config file, looking for key words. */ read_config() { FILE *cfp; char lbuf[BUFSIZ], f1[40], f2[40], f3[40], f4[40], f5[40]; if (!(cfp = fopen(_PATH_CONFIG, "r"))) return; while (fgets(lbuf, sizeof(lbuf), cfp)) switch(*lbuf) { case 'b': /* badtty */ if (sscanf(lbuf, "%s%s", f1, f2) != 2 || strcasecmp(f1, "badtty")) break; c_tty(f2); break; case 'g': /* game */ if (sscanf(lbuf, "%s%s%s%s%s", f1, f2, f3, f4, f5) != 5 || strcasecmp(f1, "game")) break; c_game(f2, f3, f4, f5); break; case 't': /* time */ if (sscanf(lbuf, "%s%s%s%s", f1, f2, f3, f4) != 4 || strcasecmp(f1, "time")) break; c_day(f2, f3, f4); } (void)fclose(cfp); } /* * c_day -- * if day is today, see if okay to play */ c_day(s_day, s_start, s_stop) char *s_day, *s_start, *s_stop; { static char *days[] = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", }; static struct tm *ct; int start, stop; if (!ct) ct = localtime(&now); if (strcasecmp(s_day, days[ct->tm_wday])) return; if (!isdigit(*s_start) || !isdigit(*s_stop)) return; start = atoi(s_start); stop = atoi(s_stop); if (ct->tm_hour >= start && ct->tm_hour < stop) { (void)fputs("dm: Sorry, games are not available from ", stderr); hour(start); (void)fputs(" to ", stderr); hour(stop); (void)fputs(" today.\n", stderr); exit(0); } } /* * c_tty -- * decide if this tty can be used for games. */ c_tty(tty) char *tty; { static int first = 1; static char *p_tty; if (first) { p_tty = strrchr(gametty, '/'); first = 0; } if (!strcmp(gametty, tty) || p_tty && !strcmp(p_tty, tty)) { (void)fprintf(stderr, "dm: Sorry, you may not play games on %s.\n", gametty); exit(0); } } /* * c_game -- * see if game can be played now. */ c_game(s_game, s_load, s_users, s_priority) char *s_game, *s_load, *s_users, *s_priority; { static int found; double load(); if (found) return; if (strcmp(game, s_game) && strcasecmp("default", s_game)) return; ++found; if (isdigit(*s_load) && atoi(s_load) < load()) { (void)fputs("dm: Sorry, the load average is too high right now.\n", stderr); exit(0); } if (isdigit(*s_users) && atoi(s_users) <= users()) { (void)fputs("dm: Sorry, there are too many users logged on right now.\n", stderr); exit(0); } if (isdigit(*s_priority)) priority = atoi(s_priority); } /* * load -- * return 15 minute load average */ double load() { double avenrun[3]; if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0) { (void)fputs("dm: getloadavg() failed.\n", stderr); exit(1); } return(avenrun[2]); } /* * users -- * return current number of users * todo: check idle time; if idle more than X minutes, don't * count them. */ users() { - register int nusers, utmp; + int nusers, utmp; struct utmp buf; if ((utmp = open(_PATH_UTMP, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "dm: %s: %s\n", _PATH_UTMP, strerror(errno)); exit(1); } for (nusers = 0; read(utmp, (char *)&buf, sizeof(struct utmp)) > 0;) if (buf.ut_name[0] != '\0') ++nusers; return(nusers); } nogamefile() { - register int fd, n; + int fd, n; char buf[BUFSIZ]; if ((fd = open(_PATH_NOGAMES, O_RDONLY, 0)) >= 0) { #define MESG "Sorry, no games right now.\n\n" (void)write(2, MESG, sizeof(MESG) - 1); while ((n = read(fd, buf, sizeof(buf))) > 0) (void)write(2, buf, n); exit(1); } } /* * hour -- * print out the hour in human form */ hour(h) int h; { switch(h) { case 0: (void)fputs("midnight", stderr); break; case 12: (void)fputs("noon", stderr); break; default: if (h > 12) (void)fprintf(stderr, "%dpm", h - 12); else (void)fprintf(stderr, "%dam", h); } } #ifdef LOG /* * logfile -- * log play of game */ logfile() { struct passwd *pw; FILE *lp; uid_t uid; int lock_cnt; if (lp = fopen(_PATH_LOG, "a")) { for (lock_cnt = 0;; ++lock_cnt) { if (!flock(fileno(lp), LOCK_EX)) break; if (lock_cnt == 4) { perror("dm: log lock"); (void)fclose(lp); return; } sleep((u_int)1); } if (pw = getpwuid(uid = getuid())) fputs(pw->pw_name, lp); else fprintf(lp, "%u", uid); fprintf(lp, "\t%s\t%s\t%s", game, gametty, ctime(&now)); (void)fclose(lp); (void)flock(fileno(lp), LOCK_UN); } } #endif /* LOG */ diff --git a/games/fish/fish.c b/games/fish/fish.c index 2cea11299e34..a447c0f18e13 100644 --- a/games/fish/fish.c +++ b/games/fish/fish.c @@ -1,431 +1,431 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Muffy Barkocy. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static char copyright[] = "@(#) Copyright (c) 1990, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ #include #include #include #include #include #include #include "pathnames.h" #define RANKS 13 #define HANDSIZE 7 #define CARDS 4 #define USER 1 #define COMPUTER 0 #define OTHER(a) (1 - (a)) char *cards[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", NULL, }; #define PRC(card) (void)printf(" %s", cards[card]) int promode; int asked[RANKS], comphand[RANKS], deck[RANKS]; int userasked[RANKS], userhand[RANKS]; main(argc, argv) int argc; char **argv; { int ch, move; while ((ch = getopt(argc, argv, "p")) != -1) switch(ch) { case 'p': promode = 1; break; case '?': default: (void)fprintf(stderr, "usage: fish [-p]\n"); exit(1); } srandomdev(); instructions(); init(); if (nrandom(2) == 1) { printplayer(COMPUTER); (void)printf("get to start.\n"); goto istart; } printplayer(USER); (void)printf("get to start.\n"); for (;;) { move = usermove(); if (!comphand[move]) { if (gofish(move, USER, userhand)) continue; } else { goodmove(USER, move, userhand, comphand); continue; } istart: for (;;) { move = compmove(); if (!userhand[move]) { if (!gofish(move, COMPUTER, comphand)) break; } else goodmove(COMPUTER, move, comphand, userhand); } } /* NOTREACHED */ } usermove() { - register int n; - register char **p; + int n; + char **p; char buf[256]; (void)printf("\nYour hand is:"); printhand(userhand); for (;;) { (void)printf("You ask me for: "); (void)fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) exit(0); if (buf[0] == '\0') continue; if (buf[0] == '\n') { (void)printf("%d cards in my hand, %d in the pool.\n", countcards(comphand), countcards(deck)); (void)printf("My books:"); (void)countbooks(comphand); continue; } buf[strlen(buf) - 1] = '\0'; if (!strcasecmp(buf, "p") && !promode) { promode = 1; (void)printf("Entering pro mode.\n"); continue; } if (!strcasecmp(buf, "quit")) exit(0); for (p = cards; *p; ++p) if (!strcasecmp(*p, buf)) break; if (!*p) { (void)printf("I don't understand!\n"); continue; } n = p - cards; if (userhand[n]) { userasked[n] = 1; return(n); } if (nrandom(3) == 1) (void)printf("You don't have any of those!\n"); else (void)printf("You don't have any %s's!\n", cards[n]); if (nrandom(4) == 1) (void)printf("No cheating!\n"); (void)printf("Guess again.\n"); } /* NOTREACHED */ } compmove() { static int lmove; if (promode) lmove = promove(); else { do { lmove = (lmove + 1) % RANKS; } while (!comphand[lmove] || comphand[lmove] == CARDS); } asked[lmove] = 1; (void)printf("I ask you for: %s.\n", cards[lmove]); return(lmove); } promove() { - register int i, max; + int i, max; for (i = 0; i < RANKS; ++i) if (userasked[i] && comphand[i] > 0 && comphand[i] < CARDS) { userasked[i] = 0; return(i); } if (nrandom(3) == 1) { for (i = 0;; ++i) if (comphand[i] && comphand[i] != CARDS) { max = i; break; } while (++i < RANKS) if (comphand[i] != CARDS && comphand[i] > comphand[max]) max = i; return(max); } if (nrandom(1024) == 0723) { for (i = 0; i < RANKS; ++i) if (userhand[i] && comphand[i]) return(i); } for (;;) { for (i = 0; i < RANKS; ++i) if (comphand[i] && comphand[i] != CARDS && !asked[i]) return(i); for (i = 0; i < RANKS; ++i) asked[i] = 0; } /* NOTREACHED */ } drawcard(player, hand) int player; int *hand; { int card; while (deck[card = nrandom(RANKS)] == 0); ++hand[card]; --deck[card]; if (player == USER || hand[card] == CARDS) { printplayer(player); (void)printf("drew %s", cards[card]); if (hand[card] == CARDS) { (void)printf(" and made a book of %s's!\n", cards[card]); chkwinner(player, hand); } else (void)printf(".\n"); } return(card); } gofish(askedfor, player, hand) int askedfor, player; int *hand; { printplayer(OTHER(player)); (void)printf("say \"GO FISH!\"\n"); if (askedfor == drawcard(player, hand)) { printplayer(player); (void)printf("drew the guess!\n"); printplayer(player); (void)printf("get to ask again!\n"); return(1); } return(0); } goodmove(player, move, hand, opphand) int player, move; int *hand, *opphand; { printplayer(OTHER(player)); (void)printf("have %d %s%s.\n", opphand[move], cards[move], opphand[move] == 1 ? "": "'s"); hand[move] += opphand[move]; opphand[move] = 0; if (hand[move] == CARDS) { printplayer(player); (void)printf("made a book of %s's!\n", cards[move]); chkwinner(player, hand); } chkwinner(OTHER(player), opphand); printplayer(player); (void)printf("get another guess!\n"); } chkwinner(player, hand) int player; - register int *hand; + int *hand; { - register int cb, i, ub; + int cb, i, ub; for (i = 0; i < RANKS; ++i) if (hand[i] > 0 && hand[i] < CARDS) return; printplayer(player); (void)printf("don't have any more cards!\n"); (void)printf("My books:"); cb = countbooks(comphand); (void)printf("Your books:"); ub = countbooks(userhand); (void)printf("\nI have %d, you have %d.\n", cb, ub); if (ub > cb) { (void)printf("\nYou win!!!\n"); if (nrandom(1024) == 0723) (void)printf("Cheater, cheater, pumpkin eater!\n"); } else if (cb > ub) { (void)printf("\nI win!!!\n"); if (nrandom(1024) == 0723) (void)printf("Hah! Stupid peasant!\n"); } else (void)printf("\nTie!\n"); exit(0); } printplayer(player) int player; { switch (player) { case COMPUTER: (void)printf("I "); break; case USER: (void)printf("You "); break; } } printhand(hand) int *hand; { - register int book, i, j; + int book, i, j; for (book = i = 0; i < RANKS; i++) if (hand[i] < CARDS) for (j = hand[i]; --j >= 0;) PRC(i); else ++book; if (book) { (void)printf(" + Book%s of", book > 1 ? "s" : ""); for (i = 0; i < RANKS; i++) if (hand[i] == CARDS) PRC(i); } (void)putchar('\n'); } countcards(hand) - register int *hand; + int *hand; { - register int i, count; + int i, count; for (count = i = 0; i < RANKS; i++) count += *hand++; return(count); } countbooks(hand) int *hand; { int i, count; for (count = i = 0; i < RANKS; i++) if (hand[i] == CARDS) { ++count; PRC(i); } if (!count) (void)printf(" none"); (void)putchar('\n'); return(count); } init() { - register int i, rank; + int i, rank; for (i = 0; i < RANKS; ++i) deck[i] = CARDS; for (i = 0; i < HANDSIZE; ++i) { while (!deck[rank = nrandom(RANKS)]); ++userhand[rank]; --deck[rank]; } for (i = 0; i < HANDSIZE; ++i) { while (!deck[rank = nrandom(RANKS)]); ++comphand[rank]; --deck[rank]; } } nrandom(n) int n; { long random(); return((int)random() % n); } instructions() { int input; char buf[1024]; (void)printf("Would you like instructions (y or n)? "); input = getchar(); while (getchar() != '\n'); if (input != 'y') return; (void)sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR); (void)system(buf); (void)printf("Hit return to continue...\n"); while ((input = getchar()) != EOF && input != '\n'); } usage() { (void)fprintf(stderr, "usage: fish [-p]\n"); exit(1); } diff --git a/games/fortune/fortune/fortune.c b/games/fortune/fortune/fortune.c index dae1d279bca6..ea10c03c8b9d 100644 --- a/games/fortune/fortune/fortune.c +++ b/games/fortune/fortune/fortune.c @@ -1,1409 +1,1409 @@ /*- * Copyright (c) 1986, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. */ /* $FreeBSD$ */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1986, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static const char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93"; #endif /* not lint */ # include # include # include # include # include # include # include # include # include # include # include # include # include "strfile.h" # include "pathnames.h" # define TRUE 1 # define FALSE 0 # define bool short # define MINW 6 /* minimum wait if desired */ # define CPERS 20 /* # of chars for each sec */ # define SLEN 160 /* # of chars in short fortune */ # define POS_UNKNOWN ((long) -1) /* pos for file unknown */ # define NO_PROB (-1) /* no prob specified for file */ # ifdef DEBUG # define DPRINTF(l,x) { if (Debug >= l) fprintf x; } # undef NDEBUG # else # define DPRINTF(l,x) # define NDEBUG 1 # endif typedef struct fd { int percent; int fd, datfd; long pos; FILE *inf; char *name; char *path; char *datfile, *posfile; bool read_tbl; bool was_pos_file; STRFILE tbl; int num_children; struct fd *child, *parent; struct fd *next, *prev; } FILEDESC; bool Found_one; /* did we find a match? */ bool Find_files = FALSE; /* just find a list of proper fortune files */ bool Fortunes_only = FALSE; /* check only "fortunes" files */ bool Wait = FALSE; /* wait desired after fortune */ bool Short_only = FALSE; /* short fortune desired */ bool Long_only = FALSE; /* long fortune desired */ bool Offend = FALSE; /* offensive fortunes only */ bool All_forts = FALSE; /* any fortune allowed */ bool Equal_probs = FALSE; /* scatter un-allocted prob equally */ #ifndef NO_REGEX bool Match = FALSE; /* dump fortunes matching a pattern */ #endif #ifdef DEBUG bool Debug = FALSE; /* print debug messages */ #endif char *Fortbuf = NULL; /* fortune buffer for -m */ int Fort_len = 0; long Seekpts[2]; /* seek pointers to fortunes */ FILEDESC *File_list = NULL, /* Head of file list */ *File_tail = NULL; /* Tail of file list */ FILEDESC *Fortfile; /* Fortune file to use */ STRFILE Noprob_tbl; /* sum of data for all no prob files */ int add_dir __P((FILEDESC *)); int add_file __P((int, char *, char *, FILEDESC **, FILEDESC **, FILEDESC *)); void all_forts __P((FILEDESC *, char *)); char *copy __P((char *, u_int)); void display __P((FILEDESC *)); void do_free __P((void *)); void *do_malloc __P((u_int)); int form_file_list __P((char **, int)); int fortlen __P((void)); void get_fort __P((void)); void get_pos __P((FILEDESC *)); void get_tbl __P((FILEDESC *)); void getargs __P((int, char *[])); void init_prob __P((void)); int is_dir __P((char *)); int is_fortfile __P((char *, char **, char **, int)); int is_off_name __P((char *)); int max __P((int, int)); FILEDESC * new_fp __P((void)); char *off_name __P((char *)); void open_dat __P((FILEDESC *)); void open_fp __P((FILEDESC *)); FILEDESC * pick_child __P((FILEDESC *)); void print_file_list __P((void)); void print_list __P((FILEDESC *, int)); void sum_noprobs __P((FILEDESC *)); void sum_tbl __P((STRFILE *, STRFILE *)); void usage __P((void)); void zero_tbl __P((STRFILE *)); #ifndef NO_REGEX char *conv_pat __P((char *)); int find_matches __P((void)); void matches_in_list __P((FILEDESC *)); int maxlen_in_list __P((FILEDESC *)); #endif #ifndef NO_REGEX #ifdef REGCMP # define RE_COMP(p) (Re_pat = regcmp(p, NULL)) # define BAD_COMP(f) ((f) == NULL) # define RE_EXEC(p) regex(Re_pat, (p)) char *Re_pat; char *regcmp(), *regex(); #else # define RE_COMP(p) (p = re_comp(p)) # define BAD_COMP(f) ((f) != NULL) # define RE_EXEC(p) re_exec(p) #endif #endif int main(ac, av) int ac; char *av[]; { #ifdef OK_TO_WRITE_DISK int fd; #endif /* OK_TO_WRITE_DISK */ (void) setlocale(LC_ALL, ""); getargs(ac, av); #ifndef NO_REGEX if (Match) exit(find_matches() != 0); #endif init_prob(); srandomdev(); do { get_fort(); } while ((Short_only && fortlen() > SLEN) || (Long_only && fortlen() <= SLEN)); display(Fortfile); #ifdef OK_TO_WRITE_DISK if ((fd = creat(Fortfile->posfile, 0666)) < 0) { perror(Fortfile->posfile); exit(1); } #ifdef LOCK_EX /* * if we can, we exclusive lock, but since it isn't very * important, we just punt if we don't have easy locking * available. */ (void) flock(fd, LOCK_EX); #endif /* LOCK_EX */ write(fd, (char *) &Fortfile->pos, sizeof Fortfile->pos); if (!Fortfile->was_pos_file) (void) chmod(Fortfile->path, 0666); #ifdef LOCK_EX (void) flock(fd, LOCK_UN); #endif /* LOCK_EX */ #endif /* OK_TO_WRITE_DISK */ if (Wait) { if (Fort_len == 0) (void) fortlen(); sleep((unsigned int) max(Fort_len / CPERS, MINW)); } exit(0); /* NOTREACHED */ } void display(fp) FILEDESC *fp; { - register char *p; - register unsigned char ch; + char *p; + unsigned char ch; char line[BUFSIZ]; open_fp(fp); (void) fseek(fp->inf, Seekpts[0], 0); for (Fort_len = 0; fgets(line, sizeof line, fp->inf) != NULL && !STR_ENDSTRING(line, fp->tbl); Fort_len++) { if (fp->tbl.str_flags & STR_ROTATED) for (p = line; (ch = *p) != '\0'; ++p) { if (isascii(ch)) { if (isupper(ch)) *p = 'A' + (ch - 'A' + 13) % 26; else if (islower(ch)) *p = 'a' + (ch - 'a' + 13) % 26; } } if (fp->tbl.str_flags & STR_COMMENTS && line[0] == fp->tbl.str_delim && line[1] == fp->tbl.str_delim) continue; fputs(line, stdout); } (void) fflush(stdout); } /* * fortlen: * Return the length of the fortune. */ int fortlen() { - register int nchar; + int nchar; char line[BUFSIZ]; if (!(Fortfile->tbl.str_flags & (STR_RANDOM | STR_ORDERED))) nchar = (Seekpts[1] - Seekpts[0] <= SLEN); else { open_fp(Fortfile); (void) fseek(Fortfile->inf, Seekpts[0], 0); nchar = 0; while (fgets(line, sizeof line, Fortfile->inf) != NULL && !STR_ENDSTRING(line, Fortfile->tbl)) nchar += strlen(line); } Fort_len = nchar; return nchar; } /* * This routine evaluates the arguments on the command line */ void getargs(argc, argv) -register int argc; -register char **argv; +int argc; +char **argv; { - register int ignore_case; + int ignore_case; # ifndef NO_REGEX - register char *pat; + char *pat; # endif /* NO_REGEX */ extern char *optarg; extern int optind; int ch; ignore_case = FALSE; # ifndef NO_REGEX pat = NULL; # endif /* NO_REGEX */ # ifdef DEBUG while ((ch = getopt(argc, argv, "aDefilm:osw")) != -1) #else while ((ch = getopt(argc, argv, "aefilm:osw")) != -1) #endif /* DEBUG */ switch(ch) { case 'a': /* any fortune */ All_forts++; break; # ifdef DEBUG case 'D': Debug++; break; # endif /* DEBUG */ case 'e': Equal_probs++; /* scatter un-allocted prob equally */ break; case 'f': /* find fortune files */ Find_files++; break; case 'l': /* long ones only */ Long_only++; Short_only = FALSE; break; case 'o': /* offensive ones only */ Offend++; break; case 's': /* short ones only */ Short_only++; Long_only = FALSE; break; case 'w': /* give time to read */ Wait++; break; # ifdef NO_REGEX case 'i': /* case-insensitive match */ case 'm': /* dump out the fortunes */ (void) fprintf(stderr, "fortune: can't match fortunes on this system (Sorry)\n"); exit(0); # else /* NO_REGEX */ case 'm': /* dump out the fortunes */ Match++; pat = optarg; break; case 'i': /* case-insensitive match */ ignore_case++; break; # endif /* NO_REGEX */ case '?': default: usage(); } argc -= optind; argv += optind; if (!form_file_list(argv, argc)) exit(1); /* errors printed through form_file_list() */ if (Find_files) { print_file_list(); exit(0); } #ifdef DEBUG else if (Debug >= 1) print_file_list(); #endif /* DEBUG */ # ifndef NO_REGEX if (pat != NULL) { if (ignore_case) pat = conv_pat(pat); if (BAD_COMP(RE_COMP(pat))) { #ifndef REGCMP fprintf(stderr, "%s\n", pat); #else /* REGCMP */ fprintf(stderr, "bad pattern: %s\n", pat); #endif /* REGCMP */ } } # endif /* NO_REGEX */ } /* * form_file_list: * Form the file list from the file specifications. */ int form_file_list(files, file_cnt) -register char **files; -register int file_cnt; +char **files; +int file_cnt; { - register int i, percent; - register char *sp; + int i, percent; + char *sp; if (file_cnt == 0) { if (Find_files) { Fortunes_only = TRUE; i = add_file(NO_PROB, FORTDIR, NULL, &File_list, &File_tail, NULL); Fortunes_only = FALSE; return i; } else return add_file(NO_PROB, "fortunes", FORTDIR, &File_list, &File_tail, NULL); } for (i = 0; i < file_cnt; i++) { percent = NO_PROB; if (!isdigit((unsigned char)files[i][0])) sp = files[i]; else { percent = 0; for (sp = files[i]; isdigit((unsigned char)*sp); sp++) percent = percent * 10 + *sp - '0'; if (percent > 100) { fprintf(stderr, "percentages must be <= 100\n"); return FALSE; } if (*sp == '.') { fprintf(stderr, "percentages must be integers\n"); return FALSE; } /* * If the number isn't followed by a '%', then * it was not a percentage, just the first part * of a file name which starts with digits. */ if (*sp != '%') { percent = NO_PROB; sp = files[i]; } else if (*++sp == '\0') { if (++i >= file_cnt) { fprintf(stderr, "percentages must precede files\n"); return FALSE; } sp = files[i]; } } if (strcmp(sp, "all") == 0) sp = FORTDIR; if (!add_file(percent, sp, NULL, &File_list, &File_tail, NULL)) return FALSE; } return TRUE; } /* * add_file: * Add a file to the file list. */ int add_file(percent, file, dir, head, tail, parent) int percent; -register char *file; +char *file; char *dir; FILEDESC **head, **tail; FILEDESC *parent; { - register FILEDESC *fp; - register int fd; - register char *path, *offensive; - register bool was_malloc; - register bool isdir; + FILEDESC *fp; + int fd; + char *path, *offensive; + bool was_malloc; + bool isdir; if (dir == NULL) { path = file; was_malloc = FALSE; } else { path = do_malloc((unsigned int) (strlen(dir) + strlen(file) + 2)); (void) strcat(strcat(strcpy(path, dir), "/"), file); was_malloc = TRUE; } if ((isdir = is_dir(path)) && parent != NULL) { if (was_malloc) free(path); return FALSE; /* don't recurse */ } offensive = NULL; if (!isdir && parent == NULL && (All_forts || Offend) && !is_off_name(path)) { offensive = off_name(path); if (Offend) { if (was_malloc) free(path); path = offensive; offensive = NULL; was_malloc = TRUE; DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); file = off_name(file); } } DPRINTF(1, (stderr, "adding file \"%s\"\n", path)); over: if ((fd = open(path, 0)) < 0) { /* * This is a sneak. If the user said -a, and if the * file we're given isn't a file, we check to see if * there is a -o version. If there is, we treat it as * if *that* were the file given. We only do this for * individual files -- if we're scanning a directory, * we'll pick up the -o file anyway. */ if (All_forts && offensive != NULL) { if (was_malloc) free(path); path = offensive; offensive = NULL; was_malloc = TRUE; DPRINTF(1, (stderr, "\ttrying \"%s\"\n", path)); file = off_name(file); goto over; } if (dir == NULL && file[0] != '/') return add_file(percent, file, FORTDIR, head, tail, parent); if (parent == NULL) perror(path); if (was_malloc) free(path); return FALSE; } DPRINTF(2, (stderr, "path = \"%s\"\n", path)); fp = new_fp(); fp->fd = fd; fp->percent = percent; fp->name = file; fp->path = path; fp->parent = parent; if ((isdir && !add_dir(fp)) || (!isdir && !is_fortfile(path, &fp->datfile, &fp->posfile, (parent != NULL)))) { if (parent == NULL) fprintf(stderr, "fortune:%s not a fortune file or directory\n", path); if (was_malloc) free(path); do_free(fp->datfile); do_free(fp->posfile); free((char *) fp); do_free(offensive); return FALSE; } /* * If the user said -a, we need to make this node a pointer to * both files, if there are two. We don't need to do this if * we are scanning a directory, since the scan will pick up the * -o file anyway. */ if (All_forts && parent == NULL && !is_off_name(path)) all_forts(fp, offensive); if (*head == NULL) *head = *tail = fp; else if (fp->percent == NO_PROB) { (*tail)->next = fp; fp->prev = *tail; *tail = fp; } else { (*head)->prev = fp; fp->next = *head; *head = fp; } #ifdef OK_TO_WRITE_DISK fp->was_pos_file = (access(fp->posfile, W_OK) >= 0); #endif /* OK_TO_WRITE_DISK */ return TRUE; } /* * new_fp: * Return a pointer to an initialized new FILEDESC. */ FILEDESC * new_fp() { - register FILEDESC *fp; + FILEDESC *fp; fp = (FILEDESC *) do_malloc(sizeof *fp); fp->datfd = -1; fp->pos = POS_UNKNOWN; fp->inf = NULL; fp->fd = -1; fp->percent = NO_PROB; fp->read_tbl = FALSE; fp->next = NULL; fp->prev = NULL; fp->child = NULL; fp->parent = NULL; fp->datfile = NULL; fp->posfile = NULL; return fp; } /* * off_name: * Return a pointer to the offensive version of a file of this name. */ char * off_name(file) char *file; { char *new; new = copy(file, (unsigned int) (strlen(file) + 2)); return strcat(new, "-o"); } /* * is_off_name: * Is the file an offensive-style name? */ int is_off_name(file) char *file; { int len; len = strlen(file); return (len >= 3 && file[len - 2] == '-' && file[len - 1] == 'o'); } /* * all_forts: * Modify a FILEDESC element to be the parent of two children if * there are two children to be a parent of. */ void all_forts(fp, offensive) -register FILEDESC *fp; +FILEDESC *fp; char *offensive; { - register char *sp; - register FILEDESC *scene, *obscene; - register int fd; + char *sp; + FILEDESC *scene, *obscene; + int fd; auto char *datfile, *posfile; if (fp->child != NULL) /* this is a directory, not a file */ return; if (!is_fortfile(offensive, &datfile, &posfile, FALSE)) return; if ((fd = open(offensive, 0)) < 0) return; DPRINTF(1, (stderr, "adding \"%s\" because of -a\n", offensive)); scene = new_fp(); obscene = new_fp(); *scene = *fp; fp->num_children = 2; fp->child = scene; scene->next = obscene; obscene->next = NULL; scene->child = obscene->child = NULL; scene->parent = obscene->parent = fp; fp->fd = -1; scene->percent = obscene->percent = NO_PROB; obscene->fd = fd; obscene->inf = NULL; obscene->path = offensive; if ((sp = rindex(offensive, '/')) == NULL) obscene->name = offensive; else obscene->name = ++sp; obscene->datfile = datfile; obscene->posfile = posfile; obscene->read_tbl = FALSE; #ifdef OK_TO_WRITE_DISK obscene->was_pos_file = (access(obscene->posfile, W_OK) >= 0); #endif /* OK_TO_WRITE_DISK */ } /* * add_dir: * Add the contents of an entire directory. */ int add_dir(fp) -register FILEDESC *fp; +FILEDESC *fp; { - register DIR *dir; - register struct dirent *dirent; + DIR *dir; + struct dirent *dirent; auto FILEDESC *tailp; auto char *name; (void) close(fp->fd); fp->fd = -1; if ((dir = opendir(fp->path)) == NULL) { perror(fp->path); return FALSE; } tailp = NULL; DPRINTF(1, (stderr, "adding dir \"%s\"\n", fp->path)); fp->num_children = 0; while ((dirent = readdir(dir)) != NULL) { if (dirent->d_namlen == 0) continue; name = copy(dirent->d_name, dirent->d_namlen); if (add_file(NO_PROB, name, fp->path, &fp->child, &tailp, fp)) fp->num_children++; else free(name); } if (fp->num_children == 0) { (void) fprintf(stderr, "fortune: %s: No fortune files in directory.\n", fp->path); return FALSE; } return TRUE; } /* * is_dir: * Return TRUE if the file is a directory, FALSE otherwise. */ int is_dir(file) char *file; { auto struct stat sbuf; if (stat(file, &sbuf) < 0) return FALSE; return (sbuf.st_mode & S_IFDIR); } /* * is_fortfile: * Return TRUE if the file is a fortune database file. We try and * exclude files without reading them if possible to avoid * overhead. Files which start with ".", or which have "illegal" * suffixes, as contained in suflist[], are ruled out. */ /* ARGSUSED */ int is_fortfile(file, datp, posp, check_for_offend) char *file, **datp, **posp; int check_for_offend; { - register int i; - register char *sp; - register char *datfile; + int i; + char *sp; + char *datfile; static char *suflist[] = { /* list of "illegal" suffixes" */ "dat", "pos", "c", "h", "p", "i", "f", "pas", "ftn", "ins.c", "ins,pas", "ins.ftn", "sml", NULL }; DPRINTF(2, (stderr, "is_fortfile(%s) returns ", file)); /* * Preclude any -o files for offendable people, and any non -o * files for completely offensive people. */ if (check_for_offend && !All_forts) { i = strlen(file); if (Offend ^ (file[i - 2] == '-' && file[i - 1] == 'o')) { DPRINTF(2, (stderr, "FALSE (offending file)\n")); return FALSE; } } if ((sp = rindex(file, '/')) == NULL) sp = file; else sp++; if (*sp == '.') { DPRINTF(2, (stderr, "FALSE (file starts with '.')\n")); return FALSE; } if (Fortunes_only && strncmp(sp, "fortunes", 8) != 0) { DPRINTF(2, (stderr, "FALSE (check fortunes only)\n")); return FALSE; } if ((sp = rindex(sp, '.')) != NULL) { sp++; for (i = 0; suflist[i] != NULL; i++) if (strcmp(sp, suflist[i]) == 0) { DPRINTF(2, (stderr, "FALSE (file has suffix \".%s\")\n", sp)); return FALSE; } } datfile = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ strcat(datfile, ".dat"); if (access(datfile, R_OK) < 0) { DPRINTF(2, (stderr, "FALSE (no readable \".dat\" file)\n")); #ifdef DEBUG if (Debug < 2) DPRINTF(0, (stderr, "Warning: file \"%s\" unreadable\n", datfile)); #endif free(datfile); return FALSE; } if (datp != NULL) *datp = datfile; else free(datfile); if (posp != NULL) { #ifdef OK_TO_WRITE_DISK *posp = copy(file, (unsigned int) (strlen(file) + 4)); /* +4 for ".dat" */ (void) strcat(*posp, ".pos"); #else *posp = NULL; #endif /* OK_TO_WRITE_DISK */ } DPRINTF(2, (stderr, "TRUE\n")); return TRUE; } /* * copy: * Return a malloc()'ed copy of the string */ char * copy(str, len) char *str; unsigned int len; { char *new, *sp; new = do_malloc(len + 1); sp = new; do { *sp++ = *str; } while (*str++); return new; } /* * do_malloc: * Do a malloc, checking for NULL return. */ void * do_malloc(size) unsigned int size; { void *new; if ((new = malloc(size)) == NULL) { (void) fprintf(stderr, "fortune: out of memory.\n"); exit(1); } return new; } /* * do_free: * Free malloc'ed space, if any. */ void do_free(ptr) void *ptr; { if (ptr != NULL) free(ptr); } /* * init_prob: * Initialize the fortune probabilities. */ void init_prob() { - register FILEDESC *fp, *last = NULL; - register int percent, num_noprob, frac; + FILEDESC *fp, *last = NULL; + int percent, num_noprob, frac; /* * Distribute the residual probability (if any) across all * files with unspecified probability (i.e., probability of 0) * (if any). */ percent = 0; num_noprob = 0; for (fp = File_tail; fp != NULL; fp = fp->prev) if (fp->percent == NO_PROB) { num_noprob++; if (Equal_probs) last = fp; } else percent += fp->percent; DPRINTF(1, (stderr, "summing probabilities:%d%% with %d NO_PROB's", percent, num_noprob)); if (percent > 100) { (void) fprintf(stderr, "fortune: probabilities sum to %d%% > 100%%!\n", percent); exit(1); } else if (percent < 100 && num_noprob == 0) { (void) fprintf(stderr, "fortune: no place to put residual probability (%d%% < 100%%)\n", percent); exit(1); } else if (percent == 100 && num_noprob != 0) { (void) fprintf(stderr, "fortune: no probability left to put in residual files (100%%)\n"); exit(1); } percent = 100 - percent; if (Equal_probs) { if (num_noprob != 0) { if (num_noprob > 1) { frac = percent / num_noprob; DPRINTF(1, (stderr, ", frac = %d%%", frac)); for (fp = File_list; fp != last; fp = fp->next) if (fp->percent == NO_PROB) { fp->percent = frac; percent -= frac; } } last->percent = percent; DPRINTF(1, (stderr, ", residual = %d%%", percent)); } else DPRINTF(1, (stderr, ", %d%% distributed over remaining fortunes\n", percent)); } DPRINTF(1, (stderr, "\n")); #ifdef DEBUG if (Debug >= 1) print_file_list(); #endif } /* * get_fort: * Get the fortune data file's seek pointer for the next fortune. */ void get_fort() { - register FILEDESC *fp; - register int choice; + FILEDESC *fp; + int choice; if (File_list->next == NULL || File_list->percent == NO_PROB) fp = File_list; else { choice = random() % 100; DPRINTF(1, (stderr, "choice = %d\n", choice)); for (fp = File_list; fp->percent != NO_PROB; fp = fp->next) if (choice < fp->percent) break; else { choice -= fp->percent; DPRINTF(1, (stderr, " skip \"%s\", %d%% (choice = %d)\n", fp->name, fp->percent, choice)); } DPRINTF(1, (stderr, "using \"%s\", %d%% (choice = %d)\n", fp->name, fp->percent, choice)); } if (fp->percent != NO_PROB) get_tbl(fp); else { if (fp->next != NULL) { sum_noprobs(fp); choice = random() % Noprob_tbl.str_numstr; DPRINTF(1, (stderr, "choice = %d (of %ld) \n", choice, Noprob_tbl.str_numstr)); while (choice >= fp->tbl.str_numstr) { choice -= fp->tbl.str_numstr; fp = fp->next; DPRINTF(1, (stderr, " skip \"%s\", %ld (choice = %d)\n", fp->name, fp->tbl.str_numstr, choice)); } DPRINTF(1, (stderr, "using \"%s\", %ld\n", fp->name, fp->tbl.str_numstr)); } get_tbl(fp); } if (fp->child != NULL) { DPRINTF(1, (stderr, "picking child\n")); fp = pick_child(fp); } Fortfile = fp; get_pos(fp); open_dat(fp); (void) lseek(fp->datfd, (off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), 0); read(fp->datfd, Seekpts, sizeof Seekpts); Seekpts[0] = ntohl(Seekpts[0]); Seekpts[1] = ntohl(Seekpts[1]); } /* * pick_child * Pick a child from a chosen parent. */ FILEDESC * pick_child(parent) FILEDESC *parent; { - register FILEDESC *fp; - register int choice; + FILEDESC *fp; + int choice; if (Equal_probs) { choice = random() % parent->num_children; DPRINTF(1, (stderr, " choice = %d (of %d)\n", choice, parent->num_children)); for (fp = parent->child; choice--; fp = fp->next) continue; DPRINTF(1, (stderr, " using %s\n", fp->name)); return fp; } else { get_tbl(parent); choice = random() % parent->tbl.str_numstr; DPRINTF(1, (stderr, " choice = %d (of %ld)\n", choice, parent->tbl.str_numstr)); for (fp = parent->child; choice >= fp->tbl.str_numstr; fp = fp->next) { choice -= fp->tbl.str_numstr; DPRINTF(1, (stderr, "\tskip %s, %ld (choice = %d)\n", fp->name, fp->tbl.str_numstr, choice)); } DPRINTF(1, (stderr, " using %s, %ld\n", fp->name, fp->tbl.str_numstr)); return fp; } } /* * sum_noprobs: * Sum up all the noprob probabilities, starting with fp. */ void sum_noprobs(fp) -register FILEDESC *fp; +FILEDESC *fp; { static bool did_noprobs = FALSE; if (did_noprobs) return; zero_tbl(&Noprob_tbl); while (fp != NULL) { get_tbl(fp); sum_tbl(&Noprob_tbl, &fp->tbl); fp = fp->next; } did_noprobs = TRUE; } int max(i, j) -register int i, j; +int i, j; { return (i >= j ? i : j); } /* * open_fp: * Assocatiate a FILE * with the given FILEDESC. */ void open_fp(fp) FILEDESC *fp; { if (fp->inf == NULL && (fp->inf = fdopen(fp->fd, "r")) == NULL) { perror(fp->path); exit(1); } } /* * open_dat: * Open up the dat file if we need to. */ void open_dat(fp) FILEDESC *fp; { if (fp->datfd < 0 && (fp->datfd = open(fp->datfile, 0)) < 0) { perror(fp->datfile); exit(1); } } /* * get_pos: * Get the position from the pos file, if there is one. If not, * return a random number. */ void get_pos(fp) FILEDESC *fp; { #ifdef OK_TO_WRITE_DISK int fd; #endif /* OK_TO_WRITE_DISK */ assert(fp->read_tbl); if (fp->pos == POS_UNKNOWN) { #ifdef OK_TO_WRITE_DISK if ((fd = open(fp->posfile, 0)) < 0 || read(fd, &fp->pos, sizeof fp->pos) != sizeof fp->pos) fp->pos = random() % fp->tbl.str_numstr; else if (fp->pos >= fp->tbl.str_numstr) fp->pos %= fp->tbl.str_numstr; if (fd >= 0) (void) close(fd); #else fp->pos = random() % fp->tbl.str_numstr; #endif /* OK_TO_WRITE_DISK */ } if (++(fp->pos) >= fp->tbl.str_numstr) fp->pos -= fp->tbl.str_numstr; DPRINTF(1, (stderr, "pos for %s is %ld\n", fp->name, fp->pos)); } /* * get_tbl: * Get the tbl data file the datfile. */ void get_tbl(fp) FILEDESC *fp; { auto int fd; - register FILEDESC *child; + FILEDESC *child; if (fp->read_tbl) return; if (fp->child == NULL) { if ((fd = open(fp->datfile, 0)) < 0) { perror(fp->datfile); exit(1); } if (read(fd, (char *) &fp->tbl, sizeof fp->tbl) != sizeof fp->tbl) { (void)fprintf(stderr, "fortune: %s corrupted\n", fp->path); exit(1); } /* fp->tbl.str_version = ntohl(fp->tbl.str_version); */ fp->tbl.str_numstr = ntohl(fp->tbl.str_numstr); fp->tbl.str_longlen = ntohl(fp->tbl.str_longlen); fp->tbl.str_shortlen = ntohl(fp->tbl.str_shortlen); fp->tbl.str_flags = ntohl(fp->tbl.str_flags); (void) close(fd); } else { zero_tbl(&fp->tbl); for (child = fp->child; child != NULL; child = child->next) { get_tbl(child); sum_tbl(&fp->tbl, &child->tbl); } } fp->read_tbl = TRUE; } /* * zero_tbl: * Zero out the fields we care about in a tbl structure. */ void zero_tbl(tp) -register STRFILE *tp; +STRFILE *tp; { tp->str_numstr = 0; tp->str_longlen = 0; tp->str_shortlen = ~((unsigned long)0); } /* * sum_tbl: * Merge the tbl data of t2 into t1. */ void sum_tbl(t1, t2) -register STRFILE *t1, *t2; +STRFILE *t1, *t2; { t1->str_numstr += t2->str_numstr; if (t1->str_longlen < t2->str_longlen) t1->str_longlen = t2->str_longlen; if (t1->str_shortlen > t2->str_shortlen) t1->str_shortlen = t2->str_shortlen; } #define STR(str) ((str) == NULL ? "NULL" : (str)) /* * print_file_list: * Print out the file list */ void print_file_list() { print_list(File_list, 0); } /* * print_list: * Print out the actual list, recursively. */ void print_list(list, lev) -register FILEDESC *list; +FILEDESC *list; int lev; { while (list != NULL) { fprintf(stderr, "%*s", lev * 4, ""); if (list->percent == NO_PROB) fprintf(stderr, "___%%"); else fprintf(stderr, "%3d%%", list->percent); fprintf(stderr, " %s", STR(list->name)); DPRINTF(1, (stderr, " (%s, %s, %s)", STR(list->path), STR(list->datfile), STR(list->posfile))); fprintf(stderr, "\n"); if (list->child != NULL) print_list(list->child, lev + 1); list = list->next; } } #ifndef NO_REGEX /* * conv_pat: * Convert the pattern to an ignore-case equivalent. */ char * conv_pat(orig) -register char *orig; +char *orig; { - register char *sp; - register unsigned int cnt; - register char *new; + char *sp; + unsigned int cnt; + char *new; cnt = 1; /* allow for '\0' */ for (sp = orig; *sp != '\0'; sp++) if (isalpha((unsigned char)*sp)) cnt += 4; else cnt++; if ((new = malloc(cnt)) == NULL) { fprintf(stderr, "pattern too long for ignoring case\n"); exit(1); } for (sp = new; *orig != '\0'; orig++) { if (islower((unsigned char)*orig)) { *sp++ = '['; *sp++ = *orig; *sp++ = toupper((unsigned char)*orig); *sp++ = ']'; } else if (isupper((unsigned char)*orig)) { *sp++ = '['; *sp++ = *orig; *sp++ = tolower((unsigned char)*orig); *sp++ = ']'; } else *sp++ = *orig; } *sp = '\0'; return new; } /* * find_matches: * Find all the fortunes which match the pattern we've been given. */ int find_matches() { Fort_len = maxlen_in_list(File_list); DPRINTF(2, (stderr, "Maximum length is %d\n", Fort_len)); /* extra length, "%\n" is appended */ Fortbuf = do_malloc((unsigned int) Fort_len + 10); Found_one = FALSE; matches_in_list(File_list); return Found_one; /* NOTREACHED */ } /* * maxlen_in_list * Return the maximum fortune len in the file list. */ int maxlen_in_list(list) FILEDESC *list; { - register FILEDESC *fp; - register int len, maxlen; + FILEDESC *fp; + int len, maxlen; maxlen = 0; for (fp = list; fp != NULL; fp = fp->next) { if (fp->child != NULL) { if ((len = maxlen_in_list(fp->child)) > maxlen) maxlen = len; } else { get_tbl(fp); if (fp->tbl.str_longlen > maxlen) maxlen = fp->tbl.str_longlen; } } return maxlen; } /* * matches_in_list * Print out the matches from the files in the list. */ void matches_in_list(list) FILEDESC *list; { - register char *sp, *p; - register FILEDESC *fp; + char *sp, *p; + FILEDESC *fp; int in_file; unsigned char ch; for (fp = list; fp != NULL; fp = fp->next) { if (fp->child != NULL) { matches_in_list(fp->child); continue; } DPRINTF(1, (stderr, "searching in %s\n", fp->path)); open_fp(fp); sp = Fortbuf; in_file = FALSE; while (fgets(sp, Fort_len, fp->inf) != NULL) if (fp->tbl.str_flags & STR_COMMENTS && sp[0] == fp->tbl.str_delim && sp[1] == fp->tbl.str_delim) continue; else if (!STR_ENDSTRING(sp, fp->tbl)) sp += strlen(sp); else { *sp = '\0'; if (fp->tbl.str_flags & STR_ROTATED) for (p = Fortbuf; (ch = *p) != '\0'; ++p) { if (isascii(ch)) { if (isupper(ch)) *p = 'A' + (ch - 'A' + 13) % 26; else if (islower(ch)) *p = 'a' + (ch - 'a' + 13) % 26; } } if (RE_EXEC(Fortbuf)) { printf("%c%c", fp->tbl.str_delim, fp->tbl.str_delim); if (!in_file) { printf(" (%s)", fp->name); Found_one = TRUE; in_file = TRUE; } putchar('\n'); (void) fwrite(Fortbuf, 1, (sp - Fortbuf), stdout); } sp = Fortbuf; } } } # endif /* NO_REGEX */ void usage() { (void) fprintf(stderr, "fortune [-a"); #ifdef DEBUG (void) fprintf(stderr, "D"); #endif /* DEBUG */ (void) fprintf(stderr, "f"); #ifndef NO_REGEX (void) fprintf(stderr, "i"); #endif /* NO_REGEX */ (void) fprintf(stderr, "losw]"); #ifndef NO_REGEX (void) fprintf(stderr, " [-m pattern]"); #endif /* NO_REGEX */ (void) fprintf(stderr, "[ [#%%] file/directory/all]\n"); exit(1); } diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c index cf1babd1c5ee..28a0e2552d77 100644 --- a/games/fortune/strfile/strfile.c +++ b/games/fortune/strfile/strfile.c @@ -1,463 +1,463 @@ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static const char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; #else static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ # include # include # include # include # include # include # include # include # include "strfile.h" /* * This program takes a file composed of strings seperated by * lines starting with two consecutive delimiting character (default * character is '%') and creates another file which consists of a table * describing the file (structure from "strfile.h"), a table of seek * pointers to the start of the strings, and the strings, each terminated * by a null byte. Usage: * * % strfile [-iorsx] [ -cC ] sourcefile [ datafile ] * * C - Allow comments marked by a double delimiter at line's beginning * c - Change delimiting character from '%' to 'C' * s - Silent. Give no summary of data processed at the end of * the run. * o - order the strings in alphabetic order * i - if ordering, ignore case * r - randomize the order of the strings * x - set rotated bit * * Ken Arnold Sept. 7, 1978 -- * * Added ordering options. */ # define TRUE 1 # define FALSE 0 # define STORING_PTRS (Oflag || Rflag) # define CHUNKSIZE 512 # define ALLOC(ptr,sz) { \ if (ptr == NULL) \ ptr = malloc((unsigned int) (CHUNKSIZE * sizeof *ptr)); \ else if (((sz) + 1) % CHUNKSIZE == 0) \ ptr = realloc((void *) ptr, ((unsigned int) ((sz) + CHUNKSIZE) * sizeof *ptr)); \ if (ptr == NULL) { \ fprintf(stderr, "out of space\n"); \ exit(1); \ } \ } #ifdef NO_VOID # define void char #endif typedef struct { char first; long pos; } STR; char *Infile = NULL, /* input file name */ Outfile[MAXPATHLEN] = "", /* output file name */ Delimch = '%'; /* delimiting character */ int Cflag = FALSE; /* embedded comments */ int Sflag = FALSE; /* silent run flag */ int Oflag = FALSE; /* ordering flag */ int Iflag = FALSE; /* ignore case flag */ int Rflag = FALSE; /* randomize order flag */ int Xflag = FALSE; /* set rotated bit */ long Num_pts = 0; /* number of pointers/strings */ long *Seekpts; FILE *Sort_1, *Sort_2; /* pointers for sorting */ STRFILE Tbl; /* statistics table */ STR *Firstch; /* first chars of each string */ void getargs(), add_offset(), do_order(), randomize(), usage(); int cmp_str(); /* * main: * Drive the sucker. There are two main modes -- either we store * the seek pointers, if the table is to be sorted or randomized, * or we write the pointer directly to the file, if we are to stay * in file order. If the former, we allocate and re-allocate in * CHUNKSIZE blocks; if the latter, we just write each pointer, * and then seek back to the beginning to write in the table. */ int main(ac, av) int ac; char **av; { - register char *sp, dc; - register FILE *inf, *outf; - register long last_off, length, pos, *p; - register int first, cnt; - register char *nsp; - register STR *fp; + char *sp, dc; + FILE *inf, *outf; + long last_off, length, pos, *p; + int first, cnt; + char *nsp; + STR *fp; static char string[257]; (void) setlocale(LC_ALL, ""); getargs(ac, av); /* evalute arguments */ dc = Delimch; if ((inf = fopen(Infile, "r")) == NULL) { perror(Infile); exit(1); } if ((outf = fopen(Outfile, "w")) == NULL) { perror(Outfile); exit(1); } if (!STORING_PTRS) (void) fseek(outf, (long) sizeof Tbl, 0); /* * Write the strings onto the file */ Tbl.str_longlen = 0; Tbl.str_shortlen = ~((unsigned long) 0); Tbl.str_delim = dc; Tbl.str_version = VERSION; first = Oflag; add_offset(outf, ftell(inf)); last_off = 0; do { sp = fgets(string, 256, inf); if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) { pos = ftell(inf); length = pos - last_off - (sp ? strlen(sp) : 0); last_off = pos; if (!length) continue; add_offset(outf, pos); if (Tbl.str_longlen < length) Tbl.str_longlen = length; if (Tbl.str_shortlen > length) Tbl.str_shortlen = length; first = Oflag; } else if (first) { for (nsp = sp; !isalnum((unsigned char)*nsp); nsp++) continue; ALLOC(Firstch, Num_pts); fp = &Firstch[Num_pts - 1]; if (Iflag && isupper((unsigned char)*nsp)) fp->first = tolower((unsigned char)*nsp); else fp->first = *nsp; fp->pos = Seekpts[Num_pts - 1]; first = FALSE; } } while (sp != NULL); /* * write the tables in */ (void) fclose(inf); Tbl.str_numstr = Num_pts - 1; if (Cflag) Tbl.str_flags |= STR_COMMENTS; if (Oflag) do_order(); else if (Rflag) randomize(); if (Xflag) Tbl.str_flags |= STR_ROTATED; if (!Sflag) { printf("\"%s\" created\n", Outfile); if (Num_pts == 2) puts("There was 1 string"); else printf("There were %ld strings\n", Num_pts - 1); printf("Longest string: %lu byte%s\n", Tbl.str_longlen, Tbl.str_longlen == 1 ? "" : "s"); printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen, Tbl.str_shortlen == 1 ? "" : "s"); } rewind(outf); Tbl.str_version = htonl(Tbl.str_version); Tbl.str_numstr = htonl(Tbl.str_numstr); Tbl.str_longlen = htonl(Tbl.str_longlen); Tbl.str_shortlen = htonl(Tbl.str_shortlen); Tbl.str_flags = htonl(Tbl.str_flags); (void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf); if (STORING_PTRS) { for (p = Seekpts, cnt = Num_pts; cnt--; ++p) *p = htonl(*p); (void) fwrite((char *) Seekpts, sizeof *Seekpts, (int) Num_pts, outf); } (void) fclose(outf); exit(0); } /* * This routine evaluates arguments from the command line */ void getargs(argc, argv) int argc; char **argv; { extern char *optarg; extern int optind; int ch; while ((ch = getopt(argc, argv, "Cc:iorsx")) != EOF) switch(ch) { case 'C': /* embedded comments */ Cflag++; break; case 'c': /* new delimiting char */ Delimch = *optarg; if (!isascii(Delimch)) { printf("bad delimiting character: '\\%o\n'", (unsigned char)Delimch); } break; case 'i': /* ignore case in ordering */ Iflag++; break; case 'o': /* order strings */ Oflag++; break; case 'r': /* randomize pointers */ Rflag++; break; case 's': /* silent */ Sflag++; break; case 'x': /* set the rotated bit */ Xflag++; break; case '?': default: usage(); } argv += optind; if (*argv) { Infile = *argv; if (*++argv) (void) strcpy(Outfile, *argv); } if (!Infile) { puts("No input file name"); usage(); } if (*Outfile == '\0') { (void) strcpy(Outfile, Infile); (void) strcat(Outfile, ".dat"); } } void usage() { (void) fprintf(stderr, "strfile [-Ciorsx] [-c char] sourcefile [datafile]\n"); exit(1); } /* * add_offset: * Add an offset to the list, or write it out, as appropriate. */ void add_offset(fp, off) FILE *fp; long off; { long net; if (!STORING_PTRS) { net = htonl(off); fwrite(&net, 1, sizeof net, fp); } else { ALLOC(Seekpts, Num_pts + 1); Seekpts[Num_pts] = off; } Num_pts++; } /* * do_order: * Order the strings alphabetically (possibly ignoring case). */ void do_order() { - register int i; - register long *lp; - register STR *fp; + int i; + long *lp; + STR *fp; Sort_1 = fopen(Infile, "r"); Sort_2 = fopen(Infile, "r"); qsort((char *) Firstch, (int) Tbl.str_numstr, sizeof *Firstch, cmp_str); i = Tbl.str_numstr; lp = Seekpts; fp = Firstch; while (i--) *lp++ = fp++->pos; (void) fclose(Sort_1); (void) fclose(Sort_2); Tbl.str_flags |= STR_ORDERED; } static int collate_range_cmp (c1, c2) int c1, c2; { static char s1[2], s2[2]; int ret; c1 &= UCHAR_MAX; c2 &= UCHAR_MAX; if (c1 == c2) return (0); s1[0] = c1; s2[0] = c2; if ((ret = strcoll(s1, s2)) != 0) return (ret); return (c1 - c2); } /* * cmp_str: * Compare two strings in the file */ int cmp_str(p1, p2) STR *p1, *p2; { - register int c1, c2; - register int n1, n2; + int c1, c2; + int n1, n2; int r; # define SET_N(nf,ch) (nf = (ch == '\n')) # define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf)) c1 = (unsigned char) p1->first; c2 = (unsigned char) p2->first; if ((r = collate_range_cmp(c1, c2)) != 0) return r; (void) fseek(Sort_1, p1->pos, 0); (void) fseek(Sort_2, p2->pos, 0); n1 = FALSE; n2 = FALSE; while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF) SET_N(n1, c1); while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF) SET_N(n2, c2); while (!IS_END(c1, n1) && !IS_END(c2, n2)) { if (Iflag) { if (isupper(c1)) c1 = tolower(c1); if (isupper(c2)) c2 = tolower(c2); } if ((r = collate_range_cmp(c1, c2)) != 0) return r; SET_N(n1, c1); SET_N(n2, c2); c1 = getc(Sort_1); c2 = getc(Sort_2); } if (IS_END(c1, n1)) c1 = 0; if (IS_END(c2, n2)) c2 = 0; return collate_range_cmp(c1, c2); } /* * randomize: * Randomize the order of the string table. We must be careful * not to randomize across delimiter boundaries. All * randomization is done within each block. */ void randomize() { - register int cnt, i; - register long tmp; - register long *sp; + int cnt, i; + long tmp; + long *sp; srandomdev(); Tbl.str_flags |= STR_RANDOM; cnt = Tbl.str_numstr; /* * move things around randomly */ for (sp = Seekpts; cnt > 0; cnt--, sp++) { i = random() % cnt; tmp = sp[0]; sp[0] = sp[i]; sp[i] = tmp; } } diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c index 3cca1a0a100e..9bd2298140cb 100644 --- a/games/fortune/unstr/unstr.c +++ b/games/fortune/unstr/unstr.c @@ -1,147 +1,147 @@ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ken Arnold. * * 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 the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. * * $FreeBSD$ */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1991, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static const char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93"; #else static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ /* * This program un-does what "strfile" makes, thereby obtaining the * original file again. This can be invoked with the name of the output * file, the input file, or both. If invoked with only a single argument * ending in ".dat", it is pressumed to be the input file and the output * file will be the same stripped of the ".dat". If the single argument * doesn't end in ".dat", then it is presumed to be the output file, and * the input file is that name prepended by a ".dat". If both are given * they are treated literally as the input and output files. * * Ken Arnold Aug 13, 1978 */ # include # include # include # include # include "strfile.h" char *Infile, /* name of input file */ Datafile[MAXPATHLEN], /* name of data file */ Delimch; /* delimiter character */ FILE *Inf, *Dataf; void getargs(), order_unstr(); /* ARGSUSED */ int main(ac, av) int ac; char **av; { static STRFILE tbl; /* description table */ getargs(av); if ((Inf = fopen(Infile, "r")) == NULL) { perror(Infile); exit(1); } if ((Dataf = fopen(Datafile, "r")) == NULL) { perror(Datafile); exit(1); } (void) fread((char *) &tbl, sizeof tbl, 1, Dataf); tbl.str_version = ntohl(tbl.str_version); tbl.str_numstr = ntohl(tbl.str_numstr); tbl.str_longlen = ntohl(tbl.str_longlen); tbl.str_shortlen = ntohl(tbl.str_shortlen); tbl.str_flags = ntohl(tbl.str_flags); if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) { fprintf(stderr, "nothing to do -- table in file order\n"); exit(1); } Delimch = tbl.str_delim; order_unstr(&tbl); (void) fclose(Inf); (void) fclose(Dataf); exit(0); } void getargs(av) -register char *av[]; +char *av[]; { if (!*++av) { (void) fprintf(stderr, "usage: unstr datafile\n"); exit(1); } Infile = *av; (void) strcpy(Datafile, Infile); (void) strcat(Datafile, ".dat"); } void order_unstr(tbl) -register STRFILE *tbl; +STRFILE *tbl; { - register int i; - register char *sp; + int i; + char *sp; long pos; char buf[BUFSIZ]; for (i = 0; i < tbl->str_numstr; i++) { (void) fread((char *) &pos, 1, sizeof pos, Dataf); (void) fseek(Inf, ntohl(pos), 0); if (i != 0) (void) printf("%c\n", Delimch); for (;;) { sp = fgets(buf, sizeof buf, Inf); if (sp == NULL || STR_ENDSTRING(sp, *tbl)) break; else fputs(sp, stdout); } } } diff --git a/games/hack/alloc.c b/games/hack/alloc.c index 30a6a96f2ef9..94512653e8cd 100644 --- a/games/hack/alloc.c +++ b/games/hack/alloc.c @@ -1,48 +1,48 @@ /* alloc.c - version 1.0.2 */ /* $FreeBSD$ */ #include #ifdef LINT /* a ridiculous definition, suppressing "possible pointer alignment problem" for (long *) malloc() "enlarg defined but never used" "ftell defined (in ) but never used" from lint */ #include long * alloc(n) unsigned n; { long dummy = ftell(stderr); if(n) dummy = 0; /* make sure arg is used */ return(&dummy); } #else long * alloc(lth) -register unsigned lth; +unsigned lth; { - register char *ptr; + char *ptr; if(!(ptr = malloc(lth))) panic("Cannot get %d bytes", lth); return((long *) ptr); } long * enlarge(ptr,lth) -register char *ptr; -register unsigned lth; +char *ptr; +unsigned lth; { - register char *nptr; + char *nptr; if(!(nptr = realloc(ptr,lth))) panic("Cannot reallocate %d bytes", lth); return((long *) nptr); } #endif LINT diff --git a/games/hack/hack.apply.c b/games/hack/hack.apply.c index 2a29e7990024..12fb470ebde0 100644 --- a/games/hack/hack.apply.c +++ b/games/hack/hack.apply.c @@ -1,438 +1,438 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.apply.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include "def.edog.h" #include "def.mkroom.h" static struct monst *bchit(); extern struct obj *addinv(); extern struct trap *maketrap(); extern int (*occupation)(); extern char *occtxt; extern char quitchars[]; extern char pl_character[]; static void use_camera(), use_ice_box(), use_whistle(), use_magic_whistle(); static int use_pick_axe(); doapply() { - register struct obj *obj; - register int res = 1; + struct obj *obj; + int res = 1; obj = getobj("(", "use or apply"); if(!obj) return(0); switch(obj->otyp){ case EXPENSIVE_CAMERA: use_camera(obj); break; case ICE_BOX: use_ice_box(obj); break; case PICK_AXE: res = use_pick_axe(obj); break; case MAGIC_WHISTLE: if(pl_character[0] == 'W' || u.ulevel > 9) { use_magic_whistle(obj); break; } /* fall into next case */ case WHISTLE: use_whistle(obj); break; case CAN_OPENER: if(!carrying(TIN)) { pline("You have no can to open."); goto xit; } pline("You cannot open a tin without eating its contents."); pline("In order to eat, use the 'e' command."); if(obj != uwep) pline("Opening the tin will be much easier if you wield the can-opener."); goto xit; default: pline("Sorry, I don't know how to use that."); xit: nomul(0); return(0); } nomul(0); return(res); } /* ARGSUSED */ static void -use_camera(obj) /* register */ struct obj *obj; { -register struct monst *mtmp; +use_camera(obj) /* */ struct obj *obj; { +struct monst *mtmp; if(!getdir(1)){ /* ask: in what direction? */ flags.move = multi = 0; return; } if(u.uswallow) { pline("You take a picture of %s's stomach.", monnam(u.ustuck)); return; } if(u.dz) { pline("You take a picture of the %s.", (u.dz > 0) ? "floor" : "ceiling"); return; } if(mtmp = bchit(u.dx, u.dy, COLNO, '!')) { if(mtmp->msleep){ mtmp->msleep = 0; pline("The flash awakens %s.", monnam(mtmp)); /* a3 */ } else if(mtmp->data->mlet != 'y') if(mtmp->mcansee || mtmp->mblinded){ - register int tmp = dist(mtmp->mx,mtmp->my); - register int tmp2; + int tmp = dist(mtmp->mx,mtmp->my); + int tmp2; if(cansee(mtmp->mx,mtmp->my)) pline("%s is blinded by the flash!", Monnam(mtmp)); setmangry(mtmp); if(tmp < 9 && !mtmp->isshk && rn2(4)) { mtmp->mflee = 1; if(rn2(4)) mtmp->mfleetim = rnd(100); } if(tmp < 3) mtmp->mcansee = mtmp->mblinded = 0; else { tmp2 = mtmp->mblinded; tmp2 += rnd(1 + 50/tmp); if(tmp2 > 127) tmp2 = 127; mtmp->mblinded = tmp2; mtmp->mcansee = 0; } } } } static struct obj *current_ice_box; /* a local variable of use_ice_box, to be used by its local procedures in/ck_ice_box */ static -in_ice_box(obj) register struct obj *obj; { +in_ice_box(obj) struct obj *obj; { if(obj == current_ice_box || (Punished && (obj == uball || obj == uchain))){ pline("You must be kidding."); return(0); } if(obj->owornmask & (W_ARMOR | W_RING)) { pline("You cannot refrigerate something you are wearing."); return(0); } if(obj->owt + current_ice_box->owt > 70) { pline("It won't fit."); return(1); /* be careful! */ } if(obj == uwep) { if(uwep->cursed) { pline("Your weapon is welded to your hand!"); return(0); } setuwep((struct obj *) 0); } current_ice_box->owt += obj->owt; freeinv(obj); obj->o_cnt_id = current_ice_box->o_id; obj->nobj = fcobj; fcobj = obj; obj->age = moves - obj->age; /* actual age */ return(1); } static -ck_ice_box(obj) register struct obj *obj; { +ck_ice_box(obj) struct obj *obj; { return(obj->o_cnt_id == current_ice_box->o_id); } static -out_ice_box(obj) register struct obj *obj; { -register struct obj *otmp; +out_ice_box(obj) struct obj *obj; { +struct obj *otmp; if(obj == fcobj) fcobj = fcobj->nobj; else { for(otmp = fcobj; otmp->nobj != obj; otmp = otmp->nobj) if(!otmp->nobj) panic("out_ice_box"); otmp->nobj = obj->nobj; } current_ice_box->owt -= obj->owt; obj->age = moves - obj->age; /* simulated point of time */ (void) addinv(obj); } static void -use_ice_box(obj) register struct obj *obj; { -register int cnt = 0; -register struct obj *otmp; +use_ice_box(obj) struct obj *obj; { +int cnt = 0; +struct obj *otmp; current_ice_box = obj; /* for use by in/out_ice_box */ for(otmp = fcobj; otmp; otmp = otmp->nobj) if(otmp->o_cnt_id == obj->o_id) cnt++; if(!cnt) pline("Your ice-box is empty."); else { pline("Do you want to take something out of the ice-box? [yn] "); if(readchar() == 'y') if(askchain(fcobj, (char *) 0, 0, out_ice_box, ck_ice_box, 0)) return; pline("That was all. Do you wish to put something in? [yn] "); if(readchar() != 'y') return; } /* call getobj: 0: allow cnt; #: allow all types; %: expect food */ otmp = getobj("0#%", "put in"); if(!otmp || !in_ice_box(otmp)) flags.move = multi = 0; } static struct monst * -bchit(ddx,ddy,range,sym) register int ddx,ddy,range; char sym; { - register struct monst *mtmp = (struct monst *) 0; - register int bchx = u.ux, bchy = u.uy; +bchit(ddx,ddy,range,sym) int ddx,ddy,range; char sym; { + struct monst *mtmp = (struct monst *) 0; + int bchx = u.ux, bchy = u.uy; if(sym) Tmp_at(-1, sym); /* open call */ while(range--) { bchx += ddx; bchy += ddy; if(mtmp = m_at(bchx,bchy)) break; if(!ZAP_POS(levl[bchx][bchy].typ)) { bchx -= ddx; bchy -= ddy; break; } if(sym) Tmp_at(bchx, bchy); } if(sym) Tmp_at(-1, -1); return(mtmp); } /* ARGSUSED */ static void use_whistle(obj) struct obj *obj; { -register struct monst *mtmp = fmon; +struct monst *mtmp = fmon; pline("You produce a high whistling sound."); while(mtmp) { if(dist(mtmp->mx,mtmp->my) < u.ulevel*20) { if(mtmp->msleep) mtmp->msleep = 0; if(mtmp->mtame) EDOG(mtmp)->whistletime = moves; } mtmp = mtmp->nmon; } } /* ARGSUSED */ static void use_magic_whistle(obj) struct obj *obj; { -register struct monst *mtmp = fmon; +struct monst *mtmp = fmon; pline("You produce a strange whistling sound."); while(mtmp) { if(mtmp->mtame) mnexto(mtmp); mtmp = mtmp->nmon; } } static int dig_effort; /* effort expended on current pos */ static uchar dig_level; static coord dig_pos; static boolean dig_down; static dig() { - register struct rm *lev; - register dpx = dig_pos.x, dpy = dig_pos.y; + struct rm *lev; + dpx = dig_pos.x, dpy = dig_pos.y; /* perhaps a nymph stole his pick-axe while he was busy digging */ /* or perhaps he teleported away */ if(u.uswallow || !uwep || uwep->otyp != PICK_AXE || dig_level != dlevel || ((dig_down && (dpx != u.ux || dpy != u.uy)) || (!dig_down && dist(dpx,dpy) > 2))) return(0); dig_effort += 10 + abon() + uwep->spe + rn2(5); if(dig_down) { if(!xdnstair) { pline("The floor here seems too hard to dig in."); return(0); } if(dig_effort > 250) { dighole(); return(0); /* done with digging */ } if(dig_effort > 50) { - register struct trap *ttmp = t_at(dpx,dpy); + struct trap *ttmp = t_at(dpx,dpy); if(!ttmp) { ttmp = maketrap(dpx,dpy,PIT); ttmp->tseen = 1; pline("You have dug a pit."); u.utrap = rn1(4,2); u.utraptype = TT_PIT; return(0); } } } else if(dig_effort > 100) { - register char *digtxt; - register struct obj *obj; + char *digtxt; + struct obj *obj; lev = &levl[dpx][dpy]; if(obj = sobj_at(ENORMOUS_ROCK, dpx, dpy)) { fracture_rock(obj); digtxt = "The rock falls apart."; } else if(!lev->typ || lev->typ == SCORR) { lev->typ = CORR; digtxt = "You succeeded in cutting away some rock."; } else if(lev->typ == HWALL || lev->typ == VWALL || lev->typ == SDOOR) { lev->typ = xdnstair ? DOOR : ROOM; digtxt = "You just made an opening in the wall."; } else digtxt = "Now what exactly was it that you were digging in?"; mnewsym(dpx, dpy); prl(dpx, dpy); pline(digtxt); /* after mnewsym & prl */ return(0); } else { if(IS_WALL(levl[dpx][dpy].typ)) { - register int rno = inroom(dpx,dpy); + int rno = inroom(dpx,dpy); if(rno >= 0 && rooms[rno].rtype >= 8) { pline("This wall seems too hard to dig into."); return(0); } } pline("You hit the rock with all your might."); } return(1); } /* When will hole be finished? Very rough indication used by shopkeeper. */ holetime() { return( (occupation == dig) ? (250 - dig_effort)/20 : -1); } dighole() { - register struct trap *ttmp = t_at(u.ux, u.uy); + struct trap *ttmp = t_at(u.ux, u.uy); if(!xdnstair) { pline("The floor here seems too hard to dig in."); } else { if(ttmp) ttmp->ttyp = TRAPDOOR; else ttmp = maketrap(u.ux, u.uy, TRAPDOOR); ttmp->tseen = 1; pline("You've made a hole in the floor."); if(!u.ustuck) { if(inshop()) shopdig(1); pline("You fall through ..."); if(u.utraptype == TT_PIT) { u.utrap = 0; u.utraptype = 0; } goto_level(dlevel+1, FALSE); } } } static use_pick_axe(obj) struct obj *obj; { char dirsyms[12]; extern char sdir[]; - register char *dsp = dirsyms, *sdp = sdir; - register struct monst *mtmp; - register struct rm *lev; - register int rx, ry, res = 0; + char *dsp = dirsyms, *sdp = sdir; + struct monst *mtmp; + struct rm *lev; + int rx, ry, res = 0; if(obj != uwep) { if(uwep && uwep->cursed) { /* Andreas Bormann - ihnp4!decvax!mcvax!unido!ab */ pline("Since your weapon is welded to your hand,"); pline("you cannot use that pick-axe."); return(0); } pline("You now wield %s.", doname(obj)); setuwep(obj); res = 1; } while(*sdp) { (void) movecmd(*sdp); /* sets u.dx and u.dy and u.dz */ rx = u.ux + u.dx; ry = u.uy + u.dy; if(u.dz > 0 || (u.dz == 0 && isok(rx, ry) && (IS_ROCK(levl[rx][ry].typ) || sobj_at(ENORMOUS_ROCK, rx, ry)))) *dsp++ = *sdp; sdp++; } *dsp = 0; pline("In what direction do you want to dig? [%s] ", dirsyms); if(!getdir(0)) /* no txt */ return(res); if(u.uswallow && attack(u.ustuck)) /* return(1) */; else if(u.dz < 0) pline("You cannot reach the ceiling."); else if(u.dz == 0) { if(Confusion) confdir(); rx = u.ux + u.dx; ry = u.uy + u.dy; if((mtmp = m_at(rx, ry)) && attack(mtmp)) return(1); if(!isok(rx, ry)) { pline("Clash!"); return(1); } lev = &levl[rx][ry]; if(lev->typ == DOOR) pline("Your %s against the door.", aobjnam(obj, "clang")); else if(!IS_ROCK(lev->typ) && !sobj_at(ENORMOUS_ROCK, rx, ry)) { /* ACCESSIBLE or POOL */ pline("You swing your %s through thin air.", aobjnam(obj, (char *) 0)); } else { if(dig_pos.x != rx || dig_pos.y != ry || dig_level != dlevel || dig_down) { dig_down = FALSE; dig_pos.x = rx; dig_pos.y = ry; dig_level = dlevel; dig_effort = 0; pline("You start digging."); } else pline("You continue digging."); occupation = dig; occtxt = "digging"; } } else if(Levitation) { pline("You cannot reach the floor."); } else { if(dig_pos.x != u.ux || dig_pos.y != u.uy || dig_level != dlevel || !dig_down) { dig_down = TRUE; dig_pos.x = u.ux; dig_pos.y = u.uy; dig_level = dlevel; dig_effort = 0; pline("You start digging in the floor."); if(inshop()) shopdig(0); } else pline("You continue digging in the floor."); occupation = dig; occtxt = "digging"; } return(1); } diff --git a/games/hack/hack.bones.c b/games/hack/hack.bones.c index 69eb2a86a02e..960e44b364dc 100644 --- a/games/hack/hack.bones.c +++ b/games/hack/hack.bones.c @@ -1,96 +1,96 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.bones.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" extern char plname[PL_NSIZ]; extern long somegold(); extern struct monst *makemon(); extern struct permonst pm_ghost; char bones[] = "bones_xx"; /* save bones and possessions of a deceased adventurer */ savebones(){ -register fd; -register struct obj *otmp; -register struct trap *ttmp; -register struct monst *mtmp; +fd; +struct obj *otmp; +struct trap *ttmp; +struct monst *mtmp; if(dlevel <= 0 || dlevel > MAXLEVEL) return; if(!rn2(1 + dlevel/2)) return; /* not so many ghosts on low levels */ bones[6] = '0' + (dlevel/10); bones[7] = '0' + (dlevel%10); if((fd = open(bones,0)) >= 0){ (void) close(fd); return; } /* drop everything; the corpse's possessions are usually cursed */ otmp = invent; while(otmp){ otmp->ox = u.ux; otmp->oy = u.uy; otmp->age = 0; /* very long ago */ otmp->owornmask = 0; if(rn2(5)) otmp->cursed = 1; if(!otmp->nobj){ otmp->nobj = fobj; fobj = invent; invent = 0; /* superfluous */ break; } otmp = otmp->nobj; } if(!(mtmp = makemon(PM_GHOST, u.ux, u.uy))) return; mtmp->mx = u.ux; mtmp->my = u.uy; mtmp->msleep = 1; (void) strcpy((char *) mtmp->mextra, plname); mkgold(somegold() + d(dlevel,30), u.ux, u.uy); for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ mtmp->m_id = 0; if(mtmp->mtame) { mtmp->mtame = 0; mtmp->mpeaceful = 0; } mtmp->mlstmv = 0; if(mtmp->mdispl) unpmon(mtmp); } for(ttmp = ftrap; ttmp; ttmp = ttmp->ntrap) ttmp->tseen = 0; for(otmp = fobj; otmp; otmp = otmp->nobj) { otmp->o_id = 0; /* otmp->o_cnt_id = 0; - superfluous */ otmp->onamelth = 0; otmp->known = 0; otmp->invlet = 0; if(otmp->olet == AMULET_SYM && !otmp->spe) { otmp->spe = -1; /* no longer the actual amulet */ otmp->cursed = 1; /* flag as gotten from a ghost */ } } if((fd = creat(bones, FMASK)) < 0) return; savelev(fd,dlevel); (void) close(fd); } getbones(){ -register fd,x,y,ok; +fd,x,y,ok; if(rn2(3)) return(0); /* only once in three times do we find bones */ bones[6] = '0' + dlevel/10; bones[7] = '0' + dlevel%10; if((fd = open(bones, 0)) < 0) return(0); if((ok = uptodate(fd)) != 0){ getlev(fd, 0, dlevel); for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) levl[x][y].seen = levl[x][y].new = 0; } (void) close(fd); #ifdef WIZARD if(!wizard) /* duvel!frans: don't remove bones while debugging */ #endif WiZARD if(unlink(bones) < 0){ pline("Cannot unlink %s .", bones); return(0); } return(ok); } diff --git a/games/hack/hack.c b/games/hack/hack.c index 6863b6096019..8cb99bdb6bee 100644 --- a/games/hack/hack.c +++ b/games/hack/hack.c @@ -1,799 +1,799 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include extern char news0(); extern char *nomovemsg; extern char *exclam(); extern struct obj *addinv(); extern boolean hmon(); /* called on movement: 1. when throwing ball+chain far away 2. when teleporting 3. when walking out of a lit room */ unsee() { - register x,y; - register struct rm *lev; + x,y; + struct rm *lev; /* if(u.udispl){ u.udispl = 0; newsym(u.udisx, u.udisy); } */ #ifndef QUEST if(seehx){ seehx = 0; } else #endif QUEST for(x = u.ux-1; x < u.ux+2; x++) for(y = u.uy-1; y < u.uy+2; y++) { if(!isok(x, y)) continue; lev = &levl[x][y]; if(!lev->lit && lev->scrsym == '.') { lev->scrsym =' '; lev->new = 1; on_scr(x,y); } } } /* called: in hack.eat.c: seeoff(0) - blind after eating rotten food in hack.mon.c: seeoff(0) - blinded by a yellow light in hack.mon.c: seeoff(1) - swallowed in hack.do.c: seeoff(0) - blind after drinking potion in hack.do.c: seeoff(1) - go up or down the stairs in hack.trap.c:seeoff(1) - fall through trapdoor */ seeoff(mode) /* 1 to redo @, 0 to leave them */ { /* 1 means misc movement, 0 means blindness */ - register x,y; - register struct rm *lev; + x,y; + struct rm *lev; if(u.udispl && mode){ u.udispl = 0; levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy); } #ifndef QUEST if(seehx) { seehx = 0; } else #endif QUEST if(!mode) { for(x = u.ux-1; x < u.ux+2; x++) for(y = u.uy-1; y < u.uy+2; y++) { if(!isok(x, y)) continue; lev = &levl[x][y]; if(!lev->lit && lev->scrsym == '.') lev->seen = 0; } } } domove() { xchar oldx,oldy; - register struct monst *mtmp; - register struct rm *tmpr,*ust; + struct monst *mtmp; + struct rm *tmpr,*ust; struct trap *trap; - register struct obj *otmp; + struct obj *otmp; u_wipe_engr(rnd(5)); if(inv_weight() > 0){ pline("You collapse under your load."); nomul(0); return; } if(u.uswallow) { u.dx = u.dy = 0; u.ux = u.ustuck->mx; u.uy = u.ustuck->my; } else { if(Confusion) { do { confdir(); } while(!isok(u.ux+u.dx, u.uy+u.dy) || IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ)); } if(!isok(u.ux+u.dx, u.uy+u.dy)){ nomul(0); return; } } ust = &levl[u.ux][u.uy]; oldx = u.ux; oldy = u.uy; if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen) nomul(0); if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx || u.uy+u.dy != u.ustuck->my)) { if(dist(u.ustuck->mx, u.ustuck->my) > 2){ /* perhaps it fled (or was teleported or ... ) */ u.ustuck = 0; } else { if(Blind) pline("You cannot escape from it!"); else pline("You cannot escape from %s!", monnam(u.ustuck)); nomul(0); return; } } if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) { /* attack monster */ nomul(0); gethungry(); if(multi < 0) return; /* we just fainted */ /* try to attack; note that it might evade */ if(attack(u.uswallow ? u.ustuck : mtmp)) return; } /* not attacking an animal, so we try to move */ if(u.utrap) { if(u.utraptype == TT_PIT) { pline("You are still in a pit."); u.utrap--; } else { pline("You are caught in a beartrap."); if((u.dx && u.dy) || !rn2(5)) u.utrap--; } return; } tmpr = &levl[u.ux+u.dx][u.uy+u.dy]; if(IS_ROCK(tmpr->typ) || (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){ flags.move = 0; nomul(0); return; } while(otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy)) { - register xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy; - register struct trap *ttmp; + xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy; + struct trap *ttmp; nomul(0); if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) && (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) && !sobj_at(ENORMOUS_ROCK, rx, ry)) { if(m_at(rx,ry)) { pline("You hear a monster behind the rock."); pline("Perhaps that's why you cannot move it."); goto cannot_push; } if(ttmp = t_at(rx,ry)) switch(ttmp->ttyp) { case PIT: pline("You push the rock into a pit!"); deltrap(ttmp); delobj(otmp); pline("It completely fills the pit!"); continue; case TELEP_TRAP: pline("You push the rock and suddenly it disappears!"); delobj(otmp); continue; } if(levl[rx][ry].typ == POOL) { levl[rx][ry].typ = ROOM; mnewsym(rx,ry); prl(rx,ry); pline("You push the rock into the water."); pline("Now you can cross the water!"); delobj(otmp); continue; } otmp->ox = rx; otmp->oy = ry; /* pobj(otmp); */ if(cansee(rx,ry)) atl(rx,ry,otmp->olet); if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy); { static long lastmovetime; /* note: this var contains garbage initially and after a restore */ if(moves > lastmovetime+2 || moves < lastmovetime) pline("With great effort you move the enormous rock."); lastmovetime = moves; } } else { pline("You try to move the enormous rock, but in vain."); cannot_push: if((!invent || inv_weight()+90 <= 0) && (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ) && IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){ pline("However, you can squeeze yourself into a small opening."); break; } else return; } } if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) && IS_ROCK(levl[u.ux+u.dx][u.uy].typ) && invent && inv_weight()+40 > 0) { pline("You are carrying too much to get through."); nomul(0); return; } if(Punished && DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){ if(carried(uball)) { movobj(uchain, u.ux, u.uy); goto nodrag; } if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){ /* leave ball, move chain under/over ball */ movobj(uchain, uball->ox, uball->oy); goto nodrag; } if(inv_weight() + (int) uball->owt/2 > 0) { pline("You cannot %sdrag the heavy iron ball.", invent ? "carry all that and also " : ""); nomul(0); return; } movobj(uball, uchain->ox, uchain->oy); unpobj(uball); /* BAH %% */ uchain->ox = u.ux; uchain->oy = u.uy; nomul(-2); nomovemsg = ""; nodrag: ; } u.ux += u.dx; u.uy += u.dy; if(flags.run) { if(tmpr->typ == DOOR || (xupstair == u.ux && yupstair == u.uy) || (xdnstair == u.ux && ydnstair == u.uy)) nomul(0); } if(tmpr->typ == POOL && !Levitation) drown(); /* not necessarily fatal */ /* if(u.udispl) { u.udispl = 0; newsym(oldx,oldy); } */ if(!Blind) { #ifdef QUEST setsee(); #else if(ust->lit) { if(tmpr->lit) { if(tmpr->typ == DOOR) prl1(u.ux+u.dx,u.uy+u.dy); else if(ust->typ == DOOR) nose1(oldx-u.dx,oldy-u.dy); } else { unsee(); prl1(u.ux+u.dx,u.uy+u.dy); } } else { if(tmpr->lit) setsee(); else { prl1(u.ux+u.dx,u.uy+u.dy); if(tmpr->typ == DOOR) { if(u.dy) { prl(u.ux-1,u.uy); prl(u.ux+1,u.uy); } else { prl(u.ux,u.uy-1); prl(u.ux,u.uy+1); } } } nose1(oldx-u.dx,oldy-u.dy); } #endif QUEST } else { pru(); } if(!flags.nopick) pickup(1); if(trap) dotrap(trap); /* fall into pit, arrow trap, etc. */ (void) inshop(); if(!Blind) read_engr_at(u.ux,u.uy); } movobj(obj, ox, oy) -register struct obj *obj; -register int ox, oy; +struct obj *obj; +int ox, oy; { /* Some dirty programming to get display right */ freeobj(obj); unpobj(obj); obj->nobj = fobj; fobj = obj; obj->ox = ox; obj->oy = oy; } dopickup(){ if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) { pline("There is nothing here to pick up."); return(0); } if(Levitation) { pline("You cannot reach the floor."); return(1); } pickup(0); return(1); } pickup(all) { - register struct gold *gold; - register struct obj *obj, *obj2; - register int wt; + struct gold *gold; + struct obj *obj, *obj2; + int wt; if(Levitation) return; while(gold = g_at(u.ux,u.uy)) { pline("%ld gold piece%s.", gold->amount, plur(gold->amount)); u.ugold += gold->amount; flags.botl = 1; freegold(gold); if(flags.run) nomul(0); if(Invisible) newsym(u.ux,u.uy); } /* check for more than one object */ if(!all) { - register int ct = 0; + int ct = 0; for(obj = fobj; obj; obj = obj->nobj) if(obj->ox == u.ux && obj->oy == u.uy) if(!Punished || obj != uchain) ct++; if(ct < 2) all++; else pline("There are several objects here."); } for(obj = fobj; obj; obj = obj2) { obj2 = obj->nobj; /* perhaps obj will be picked up */ if(obj->ox == u.ux && obj->oy == u.uy) { if(flags.run) nomul(0); /* do not pick up uchain */ if(Punished && obj == uchain) continue; if(!all) { char c; pline("Pick up %s ? [ynaq]", doname(obj)); while(!index("ynaq ", (c = readchar()))) bell(); if(c == 'q') return; if(c == 'n') continue; if(c == 'a') all = 1; } if(obj->otyp == DEAD_COCKATRICE && !uarmg){ pline("Touching the dead cockatrice is a fatal mistake."); pline("You turn to stone."); killer = "cockatrice cadaver"; done("died"); } if(obj->otyp == SCR_SCARE_MONSTER){ if(!obj->spe) obj->spe = 1; else { /* Note: perhaps the 1st pickup failed: you cannot carry anymore, and so we never dropped it - let's assume that treading on it twice also destroys the scroll */ pline("The scroll turns to dust as you pick it up."); delobj(obj); continue; } } wt = inv_weight() + obj->owt; if(wt > 0) { if(obj->quan > 1) { /* see how many we can lift */ extern struct obj *splitobj(); int savequan = obj->quan; int iw = inv_weight(); int qq; for(qq = 1; qq < savequan; qq++){ obj->quan = qq; if(iw + weight(obj) > 0) break; } obj->quan = savequan; qq--; /* we can carry qq of them */ if(!qq) goto too_heavy; pline("You can only carry %s of the %s lying here.", (qq == 1) ? "one" : "some", doname(obj)); (void) splitobj(obj, qq); /* note: obj2 is set already, so we'll never * encounter the other half; if it should be * otherwise then write * obj2 = splitobj(obj,qq); */ goto lift_some; } too_heavy: pline("There %s %s here, but %s.", (obj->quan == 1) ? "is" : "are", doname(obj), !invent ? "it is too heavy for you to lift" : "you cannot carry anymore"); break; } lift_some: if(inv_cnt() >= 52) { pline("Your knapsack cannot accomodate anymore items."); break; } if(wt > -5) pline("You have a little trouble lifting"); freeobj(obj); if(Invisible) newsym(u.ux,u.uy); addtobill(obj); /* sets obj->unpaid if necessary */ { int pickquan = obj->quan; int mergquan; if(!Blind) obj->dknown = 1; /* this is done by prinv(), but addinv() needs it already for merging */ obj = addinv(obj); /* might merge it with other objects */ mergquan = obj->quan; obj->quan = pickquan; /* to fool prinv() */ prinv(obj); obj->quan = mergquan; } } } } /* stop running if we see something interesting */ /* turn around a corner if that is the only way we can proceed */ /* do not turn left or right twice */ lookaround(){ -register x,y,i,x0,y0,m0,i0 = 9; -register int corrct = 0, noturn = 0; -register struct monst *mtmp; +x,y,i,x0,y0,m0,i0 = 9; +int corrct = 0, noturn = 0; +struct monst *mtmp; #ifdef lint /* suppress "used before set" message */ x0 = y0 = 0; #endif lint if(Blind || flags.run == 0) return; if(flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) return; #ifdef QUEST if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop; #endif QUEST for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ if(x == u.ux && y == u.uy) continue; if(!levl[x][y].typ) continue; if((mtmp = m_at(x,y)) && !mtmp->mimic && (!mtmp->minvis || See_invisible)){ if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy)) goto stop; } else mtmp = 0; /* invisible M cannot influence us */ if(x == u.ux-u.dx && y == u.uy-u.dy) continue; switch(levl[x][y].scrsym){ case '|': case '-': case '.': case ' ': break; case '+': if(x != u.ux && y != u.uy) break; if(flags.run != 1) goto stop; /* fall into next case */ case CORR_SYM: corr: if(flags.run == 1 || flags.run == 3) { i = DIST(x,y,u.ux+u.dx,u.uy+u.dy); if(i > 2) break; if(corrct == 1 && DIST(x,y,x0,y0) != 1) noturn = 1; if(i < i0) { i0 = i; x0 = x; y0 = y; m0 = mtmp ? 1 : 0; } } corrct++; break; case '^': if(flags.run == 1) goto corr; /* if you must */ if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop; break; default: /* e.g. objects or trap or stairs */ if(flags.run == 1) goto corr; if(mtmp) break; /* d */ stop: nomul(0); return; } } #ifdef QUEST if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop; #endif QUEST if(corrct > 1 && flags.run == 2) goto stop; if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 && (corrct == 1 || (corrct == 2 && i0 == 1))) { /* make sure that we do not turn too far */ if(i0 == 2) { if(u.dx == y0-u.uy && u.dy == u.ux-x0) i = 2; /* straight turn right */ else i = -2; /* straight turn left */ } else if(u.dx && u.dy) { if((u.dx == u.dy && y0 == u.uy) || (u.dx != u.dy && y0 != u.uy)) i = -1; /* half turn left */ else i = 1; /* half turn right */ } else { if((x0-u.ux == y0-u.uy && !u.dy) || (x0-u.ux != y0-u.uy && u.dy)) i = 1; /* half turn right */ else i = -1; /* half turn left */ } i += u.last_str_turn; if(i <= 2 && i >= -2) { u.last_str_turn = i; u.dx = x0-u.ux, u.dy = y0-u.uy; } } } /* something like lookaround, but we are not running */ /* react only to monsters that might hit us */ monster_nearby() { -register int x,y; -register struct monst *mtmp; +int x,y; +struct monst *mtmp; if(!Blind) for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){ if(x == u.ux && y == u.uy) continue; if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame && !mtmp->mpeaceful && !index("Ea", mtmp->data->mlet) && !mtmp->mfroz && !mtmp->msleep && /* aplvax!jcn */ (!mtmp->minvis || See_invisible)) return(1); } return(0); } #ifdef QUEST cansee(x,y) xchar x,y; { -register int dx,dy,adx,ady,sdx,sdy,dmax,d; +int dx,dy,adx,ady,sdx,sdy,dmax,d; if(Blind) return(0); if(!isok(x,y)) return(0); d = dist(x,y); if(d < 3) return(1); if(d > u.uhorizon*u.uhorizon) return(0); if(!levl[x][y].lit) return(0); dx = x - u.ux; adx = abs(dx); sdx = sgn(dx); dy = y - u.uy; ady = abs(dy); sdy = sgn(dy); if(dx == 0 || dy == 0 || adx == ady){ dmax = (dx == 0) ? ady : adx; for(d = 1; d <= dmax; d++) if(!rroom(sdx*d,sdy*d)) return(0); return(1); } else if(ady > adx){ for(d = 1; d <= ady; d++){ if(!rroom(sdx*( (d*adx)/ady ), sdy*d) || !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d)) return(0); } return(1); } else { for(d = 1; d <= adx; d++){ if(!rroom(sdx*d, sdy*( (d*ady)/adx )) || !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 ))) return(0); } return(1); } } -rroom(x,y) register int x,y; { +rroom(x,y) int x,y; { return(IS_ROOM(levl[u.ux+x][u.uy+y].typ)); } #else cansee(x,y) xchar x,y; { if(Blind || u.uswallow) return(0); if(dist(x,y) < 3) return(1); if(levl[x][y].lit && seelx <= x && x <= seehx && seely <= y && y <= seehy) return(1); return(0); } #endif QUEST -sgn(a) register int a; { +sgn(a) int a; { return((a > 0) ? 1 : (a == 0) ? 0 : -1); } #ifdef QUEST setsee() { - register x,y; + x,y; if(Blind) { pru(); return; } for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++) for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) { if(cansee(x,y)) prl(x,y); } } #else setsee() { - register x,y; + x,y; if(Blind) { pru(); return; } if(!levl[u.ux][u.uy].lit) { seelx = u.ux-1; seehx = u.ux+1; seely = u.uy-1; seehy = u.uy+1; } else { for(seelx = u.ux; levl[seelx-1][u.uy].lit; seelx--); for(seehx = u.ux; levl[seehx+1][u.uy].lit; seehx++); for(seely = u.uy; levl[u.ux][seely-1].lit; seely--); for(seehy = u.uy; levl[u.ux][seehy+1].lit; seehy++); } for(y = seely; y <= seehy; y++) for(x = seelx; x <= seehx; x++) { prl(x,y); } if(!levl[u.ux][u.uy].lit) seehx = 0; /* seems necessary elsewhere */ else { if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1); if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1); if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y); if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y); } } #endif QUEST nomul(nval) -register nval; +nval; { if(multi < 0) return; multi = nval; flags.mv = flags.run = 0; } abon() { if(u.ustr == 3) return(-3); else if(u.ustr < 6) return(-2); else if(u.ustr < 8) return(-1); else if(u.ustr < 17) return(0); else if(u.ustr < 69) return(1); /* up to 18/50 */ else if(u.ustr < 118) return(2); else return(3); } dbon() { if(u.ustr < 6) return(-1); else if(u.ustr < 16) return(0); else if(u.ustr < 18) return(1); else if(u.ustr == 18) return(2); /* up to 18 */ else if(u.ustr < 94) return(3); /* up to 18/75 */ else if(u.ustr < 109) return(4); /* up to 18/90 */ else if(u.ustr < 118) return(5); /* up to 18/99 */ else return(6); } losestr(num) /* may kill you; cause may be poison or monster like 'A' */ -register num; +num; { u.ustr -= num; while(u.ustr < 3) { u.ustr++; u.uhp -= 6; u.uhpmax -= 6; } flags.botl = 1; } losehp(n,knam) -register n; -register char *knam; +n; +char *knam; { u.uhp -= n; if(u.uhp > u.uhpmax) u.uhpmax = u.uhp; /* perhaps n was negative */ flags.botl = 1; if(u.uhp < 1) { killer = knam; /* the thing that killed you */ done("died"); } } losehp_m(n,mtmp) -register n; -register struct monst *mtmp; +n; +struct monst *mtmp; { u.uhp -= n; flags.botl = 1; if(u.uhp < 1) done_in_by(mtmp); } losexp() /* hit by V or W */ { - register num; + num; extern long newuexp(); if(u.ulevel > 1) pline("Goodbye level %u.", u.ulevel--); else u.uhp = -1; num = rnd(10); u.uhp -= num; u.uhpmax -= num; u.uexp = newuexp(); flags.botl = 1; } inv_weight(){ -register struct obj *otmp = invent; -register int wt = (u.ugold + 500)/1000; -register int carrcap; +struct obj *otmp = invent; +int wt = (u.ugold + 500)/1000; +int carrcap; if(Levitation) /* pugh@cornell */ carrcap = MAX_CARR_CAP; else { carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel); if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP; if(Wounded_legs & LEFT_SIDE) carrcap -= 10; if(Wounded_legs & RIGHT_SIDE) carrcap -= 10; } while(otmp){ wt += otmp->owt; otmp = otmp->nobj; } return(wt - carrcap); } inv_cnt(){ -register struct obj *otmp = invent; -register int ct = 0; +struct obj *otmp = invent; +int ct = 0; while(otmp){ ct++; otmp = otmp->nobj; } return(ct); } long newuexp() { return(10*(1L << (u.ulevel-1))); } diff --git a/games/hack/hack.cmd.c b/games/hack/hack.cmd.c index 5eedbf591996..ba2f428f2eda 100644 --- a/games/hack/hack.cmd.c +++ b/games/hack/hack.cmd.c @@ -1,303 +1,303 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.cmd.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include "def.func_tab.h" int doredraw(),doredotopl(),dodrop(),dodrink(),doread(),dosearch(),dopickup(), doversion(),doweararm(),dowearring(),doremarm(),doremring(),dopay(),doapply(), dosave(),dowield(),ddoinv(),dozap(),ddocall(),dowhatis(),doengrave(),dotele(), dohelp(),doeat(),doddrop(),do_mname(),doidtrap(),doprwep(),doprarm(), doprring(),doprgold(),dodiscovered(),dotypeinv(),dolook(),doset(), doup(), dodown(), done1(), donull(), dothrow(), doextcmd(), dodip(), dopray(); #ifdef SHELL int dosh(); #endif SHELL #ifdef SUSPEND int dosuspend(); #endif SUSPEND struct func_tab cmdlist[]={ '\020', doredotopl, '\022', doredraw, '\024', dotele, #ifdef SUSPEND '\032', dosuspend, #endif SUSPEND 'a', doapply, /* 'A' : UNUSED */ /* 'b', 'B' : go sw */ 'c', ddocall, 'C', do_mname, 'd', dodrop, 'D', doddrop, 'e', doeat, 'E', doengrave, /* 'f', 'F' : multiple go (might become 'fight') */ /* 'g', 'G' : UNUSED */ /* 'h', 'H' : go west */ 'I', dotypeinv, /* Robert Viduya */ 'i', ddoinv, /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' : move commands */ /* 'o', doopen, */ 'O', doset, 'p', dopay, 'P', dowearring, 'q', dodrink, 'Q', done1, 'r', doread, 'R', doremring, 's', dosearch, 'S', dosave, 't', dothrow, 'T', doremarm, /* 'u', 'U' : go ne */ 'v', doversion, /* 'V' : UNUSED */ 'w', dowield, 'W', doweararm, /* 'x', 'X' : UNUSED */ /* 'y', 'Y' : go nw */ 'z', dozap, /* 'Z' : UNUSED */ '<', doup, '>', dodown, '/', dowhatis, '?', dohelp, #ifdef SHELL '!', dosh, #endif SHELL '.', donull, ' ', donull, ',', dopickup, ':', dolook, '^', doidtrap, '\\', dodiscovered, /* Robert Viduya */ WEAPON_SYM, doprwep, ARMOR_SYM, doprarm, RING_SYM, doprring, '$', doprgold, '#', doextcmd, 0,0,0 }; struct ext_func_tab extcmdlist[] = { "dip", dodip, "pray", dopray, (char *) 0, donull }; extern char *parse(), lowc(), unctrl(), quitchars[]; rhack(cmd) -register char *cmd; +char *cmd; { - register struct func_tab *tlist = cmdlist; + struct func_tab *tlist = cmdlist; boolean firsttime = FALSE; - register res; + res; if(!cmd) { firsttime = TRUE; flags.nopick = 0; cmd = parse(); } if(!*cmd || (*cmd & 0377) == 0377 || (flags.no_rest_on_space && *cmd == ' ')){ bell(); flags.move = 0; return; /* probably we just had an interrupt */ } if(movecmd(*cmd)) { walk: if(multi) flags.mv = 1; domove(); return; } if(movecmd(lowc(*cmd))) { flags.run = 1; rush: if(firsttime){ if(!multi) multi = COLNO; u.last_str_turn = 0; } flags.mv = 1; #ifdef QUEST if(flags.run >= 4) finddir(); if(firsttime){ u.ux0 = u.ux + u.dx; u.uy0 = u.uy + u.dy; } #endif QUEST domove(); return; } if((*cmd == 'f' && movecmd(cmd[1])) || movecmd(unctrl(*cmd))) { flags.run = 2; goto rush; } if(*cmd == 'F' && movecmd(lowc(cmd[1]))) { flags.run = 3; goto rush; } if(*cmd == 'm' && movecmd(cmd[1])) { flags.run = 0; flags.nopick = 1; goto walk; } if(*cmd == 'M' && movecmd(lowc(cmd[1]))) { flags.run = 1; flags.nopick = 1; goto rush; } #ifdef QUEST if(*cmd == cmd[1] && (*cmd == 'f' || *cmd == 'F')) { flags.run = 4; if(*cmd == 'F') flags.run += 2; if(cmd[2] == '-') flags.run += 1; goto rush; } #endif QUEST while(tlist->f_char) { if(*cmd == tlist->f_char){ res = (*(tlist->f_funct))(); if(!res) { flags.move = 0; multi = 0; } return; } tlist++; } { char expcmd[10]; - register char *cp = expcmd; + char *cp = expcmd; while(*cmd && cp-expcmd < sizeof(expcmd)-2) { if(*cmd >= 040 && *cmd < 0177) *cp++ = *cmd++; else { *cp++ = '^'; *cp++ = *cmd++ ^ 0100; } } *cp++ = 0; pline("Unknown command '%s'.", expcmd); } multi = flags.move = 0; } doextcmd() /* here after # - now read a full-word command */ { char buf[BUFSZ]; - register struct ext_func_tab *efp = extcmdlist; + struct ext_func_tab *efp = extcmdlist; pline("# "); getlin(buf); clrlin(); if(buf[0] == '\033') return(0); while(efp->ef_txt) { if(!strcmp(efp->ef_txt, buf)) return((*(efp->ef_funct))()); efp++; } pline("%s: unknown command.", buf); return(0); } char lowc(sym) char sym; { return( (sym >= 'A' && sym <= 'Z') ? sym+'a'-'A' : sym ); } char unctrl(sym) char sym; { return( (sym >= ('A' & 037) && sym <= ('Z' & 037)) ? sym + 0140 : sym ); } /* 'rogue'-like direction commands */ char sdir[] = "hykulnjb><"; schar xdir[10] = { -1,-1, 0, 1, 1, 1, 0,-1, 0, 0 }; schar ydir[10] = { 0,-1,-1,-1, 0, 1, 1, 1, 0, 0 }; schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1,-1 }; movecmd(sym) /* also sets u.dz, but returns false for <> */ char sym; { - register char *dp; + char *dp; u.dz = 0; if(!(dp = index(sdir, sym))) return(0); u.dx = xdir[dp-sdir]; u.dy = ydir[dp-sdir]; u.dz = zdir[dp-sdir]; return(!u.dz); } getdir(s) boolean s; { char dirsym; if(s) pline("In what direction?"); dirsym = readchar(); if(!movecmd(dirsym) && !u.dz) { if(!index(quitchars, dirsym)) pline("What a strange direction!"); return(0); } if(Confusion && !u.dz) confdir(); return(1); } confdir() { - register x = rn2(8); + x = rn2(8); u.dx = xdir[x]; u.dy = ydir[x]; } #ifdef QUEST finddir(){ -register int i, ui = u.di; +int i, ui = u.di; for(i = 0; i <= 8; i++){ if(flags.run & 1) ui++; else ui += 7; ui %= 8; if(i == 8){ pline("Not near a wall."); flags.move = multi = 0; return(0); } if(!isroom(u.ux+xdir[ui], u.uy+ydir[ui])) break; } for(i = 0; i <= 8; i++){ if(flags.run & 1) ui += 7; else ui++; ui %= 8; if(i == 8){ pline("Not near a room."); flags.move = multi = 0; return(0); } if(isroom(u.ux+xdir[ui], u.uy+ydir[ui])) break; } u.di = ui; u.dx = xdir[ui]; u.dy = ydir[ui]; } -isroom(x,y) register x,y; { /* what about POOL? */ +isroom(x,y) x,y; { /* what about POOL? */ return(isok(x,y) && (levl[x][y].typ == ROOM || (levl[x][y].typ >= LDOOR && flags.run >= 6))); } #endif QUEST -isok(x,y) register x,y; { +isok(x,y) x,y; { /* x corresponds to curx, so x==1 is the first column. Ach. %% */ return(x >= 1 && x <= COLNO-1 && y >= 0 && y <= ROWNO-1); } diff --git a/games/hack/hack.do.c b/games/hack/hack.do.c index b8dd66ffafba..8e7a52f0bc12 100644 --- a/games/hack/hack.do.c +++ b/games/hack/hack.do.c @@ -1,489 +1,489 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.do.c - version 1.0.3 */ /* $FreeBSD$ */ /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */ #include "hack.h" extern struct obj *splitobj(), *addinv(); extern boolean hmon(); extern boolean level_exists[]; extern struct monst youmonst; extern char *Doname(); extern char *nomovemsg; static int drop(); dodrop() { return(drop(getobj("0$#", "drop"))); } static int -drop(obj) register struct obj *obj; { +drop(obj) struct obj *obj; { if(!obj) return(0); if(obj->olet == '$') { /* pseudo object */ - register long amount = OGOLD(obj); + long amount = OGOLD(obj); if(amount == 0) pline("You didn't drop any gold pieces."); else { mkgold(amount, u.ux, u.uy); pline("You dropped %ld gold piece%s.", amount, plur(amount)); if(Invisible) newsym(u.ux, u.uy); } free((char *) obj); return(1); } if(obj->owornmask & (W_ARMOR | W_RING)){ pline("You cannot drop something you are wearing."); return(0); } if(obj == uwep) { if(uwep->cursed) { pline("Your weapon is welded to your hand!"); return(0); } setuwep((struct obj *) 0); } pline("You dropped %s.", doname(obj)); dropx(obj); return(1); } /* Called in several places - should not produce texts */ dropx(obj) -register struct obj *obj; +struct obj *obj; { freeinv(obj); dropy(obj); } dropy(obj) -register struct obj *obj; +struct obj *obj; { if(obj->otyp == CRYSKNIFE) obj->otyp = WORM_TOOTH; obj->ox = u.ux; obj->oy = u.uy; obj->nobj = fobj; fobj = obj; if(Invisible) newsym(u.ux,u.uy); subfrombill(obj); stackobj(obj); } /* drop several things */ doddrop() { return(ggetobj("drop", drop, 0)); } dodown() { if(u.ux != xdnstair || u.uy != ydnstair) { pline("You can't go down here."); return(0); } if(u.ustuck) { pline("You are being held, and cannot go down."); return(1); } if(Levitation) { pline("You're floating high above the stairs."); return(0); } goto_level(dlevel+1, TRUE); return(1); } doup() { if(u.ux != xupstair || u.uy != yupstair) { pline("You can't go up here."); return(0); } if(u.ustuck) { pline("You are being held, and cannot go up."); return(1); } if(!Levitation && inv_weight() + 5 > 0) { pline("Your load is too heavy to climb the stairs."); return(1); } goto_level(dlevel-1, TRUE); return(1); } goto_level(newlevel, at_stairs) -register int newlevel; -register boolean at_stairs; +int newlevel; +boolean at_stairs; { - register fd; - register boolean up = (newlevel < dlevel); + fd; + boolean up = (newlevel < dlevel); if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */ if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */ if(newlevel == dlevel) return; /* this can happen */ glo(dlevel); fd = creat(lock, FMASK); if(fd < 0) { /* * This is not quite impossible: e.g., we may have * exceeded our quota. If that is the case then we * cannot leave this level, and cannot save either. * Another possibility is that the directory was not * writable. */ pline("A mysterious force prevents you from going %s.", up ? "up" : "down"); return; } if(Punished) unplacebc(); u.utrap = 0; /* needed in level_tele */ u.ustuck = 0; /* idem */ keepdogs(); seeoff(1); if(u.uswallow) /* idem */ u.uswldtim = u.uswallow = 0; flags.nscrinh = 1; u.ux = FAR; /* hack */ (void) inshop(); /* probably was a trapdoor */ savelev(fd,dlevel); (void) close(fd); dlevel = newlevel; if(maxdlevel < dlevel) maxdlevel = dlevel; glo(dlevel); if(!level_exists[dlevel]) mklev(); else { extern int hackpid; if((fd = open(lock,0)) < 0) { pline("Cannot open %s .", lock); pline("Probably someone removed it."); done("tricked"); } getlev(fd, hackpid, dlevel); (void) close(fd); } if(at_stairs) { if(up) { u.ux = xdnstair; u.uy = ydnstair; if(!u.ux) { /* entering a maze from below? */ u.ux = xupstair; /* this will confuse the player! */ u.uy = yupstair; } if(Punished && !Levitation){ pline("With great effort you climb the stairs."); placebc(1); } } else { u.ux = xupstair; u.uy = yupstair; if(inv_weight() + 5 > 0 || Punished){ pline("You fall down the stairs."); /* %% */ losehp(rnd(3), "fall"); if(Punished) { if(uwep != uball && rn2(3)){ pline("... and are hit by the iron ball."); losehp(rnd(20), "iron ball"); } placebc(1); } selftouch("Falling, you"); } } - { register struct monst *mtmp = m_at(u.ux, u.uy); + { struct monst *mtmp = m_at(u.ux, u.uy); if(mtmp) mnexto(mtmp); } } else { /* trapdoor or level_tele */ do { u.ux = rnd(COLNO-1); u.uy = rn2(ROWNO); } while(levl[u.ux][u.uy].typ != ROOM || m_at(u.ux,u.uy)); if(Punished){ if(uwep != uball && !up /* %% */ && rn2(5)){ pline("The iron ball falls on your head."); losehp(rnd(25), "iron ball"); } placebc(1); } selftouch("Falling, you"); } (void) inshop(); initrack(); losedogs(); - { register struct monst *mtmp; + { struct monst *mtmp; if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */ } flags.nscrinh = 0; setsee(); seeobjs(); /* make old cadavers disappear - riv05!a3 */ docrt(); pickup(1); read_engr_at(u.ux,u.uy); } donull() { return(1); /* Do nothing, but let other things happen */ } dopray() { nomovemsg = "You finished your prayer."; nomul(-3); return(1); } struct monst *bhit(), *boomhit(); dothrow() { - register struct obj *obj; - register struct monst *mon; - register tmp; + struct obj *obj; + struct monst *mon; + tmp; obj = getobj("#)", "throw"); /* it is also possible to throw food */ /* (or jewels, or iron balls ... ) */ if(!obj || !getdir(1)) /* ask "in what direction?" */ return(0); if(obj->owornmask & (W_ARMOR | W_RING)){ pline("You can't throw something you are wearing."); return(0); } u_wipe_engr(2); if(obj == uwep){ if(obj->cursed){ pline("Your weapon is welded to your hand."); return(1); } if(obj->quan > 1) setuwep(splitobj(obj, 1)); else setuwep((struct obj *) 0); } else if(obj->quan > 1) (void) splitobj(obj, 1); freeinv(obj); if(u.uswallow) { mon = u.ustuck; bhitpos.x = mon->mx; bhitpos.y = mon->my; } else if(u.dz) { if(u.dz < 0) { pline("%s hits the ceiling, then falls back on top of your head.", Doname(obj)); /* note: obj->quan == 1 */ if(obj->olet == POTION_SYM) potionhit(&youmonst, obj); else { if(uarmh) pline("Fortunately, you are wearing a helmet!"); losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object"); dropy(obj); } } else { pline("%s hits the floor.", Doname(obj)); if(obj->otyp == EXPENSIVE_CAMERA) { pline("It is shattered in a thousand pieces!"); obfree(obj, Null(obj)); } else if(obj->otyp == EGG) { pline("\"Splash!\""); obfree(obj, Null(obj)); } else if(obj->olet == POTION_SYM) { pline("The flask breaks, and you smell a peculiar odor ..."); potionbreathe(obj); obfree(obj, Null(obj)); } else { dropy(obj); } } return(1); } else if(obj->otyp == BOOMERANG) { mon = boomhit(u.dx, u.dy); if(mon == &youmonst) { /* the thing was caught */ (void) addinv(obj); return(1); } } else { if(obj->otyp == PICK_AXE && shkcatch(obj)) return(1); mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 : (!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1, obj->olet, (int (*)()) 0, (int (*)()) 0, obj); } if(mon) { /* awake monster if sleeping */ wakeup(mon); if(obj->olet == WEAPON_SYM) { tmp = -1+u.ulevel+mon->data->ac+abon(); if(obj->otyp < ROCK) { if(!uwep || uwep->otyp != obj->otyp+(BOW-ARROW)) tmp -= 4; else { tmp += uwep->spe; } } else if(obj->otyp == BOOMERANG) tmp += 4; tmp += obj->spe; if(u.uswallow || tmp >= rnd(20)) { if(hmon(mon,obj,1) == TRUE){ /* mon still alive */ #ifndef NOWORM cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp); #endif NOWORM } else mon = 0; /* weapons thrown disappear sometimes */ if(obj->otyp < BOOMERANG && rn2(3)) { /* check bill; free */ obfree(obj, (struct obj *) 0); return(1); } } else miss(objects[obj->otyp].oc_name, mon); } else if(obj->otyp == HEAVY_IRON_BALL) { tmp = -1+u.ulevel+mon->data->ac+abon(); if(!Punished || obj != uball) tmp += 2; if(u.utrap) tmp -= 2; if(u.uswallow || tmp >= rnd(20)) { if(hmon(mon,obj,1) == FALSE) mon = 0; /* he died */ } else miss("iron ball", mon); } else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) { potionhit(mon, obj); return(1); } else { if(cansee(bhitpos.x,bhitpos.y)) pline("You miss %s.",monnam(mon)); else pline("You miss it."); if(obj->olet == FOOD_SYM && mon->data->mlet == 'd') if(tamedog(mon,obj)) return(1); if(obj->olet == GEM_SYM && mon->data->mlet == 'u' && !mon->mtame){ if(obj->dknown && objects[obj->otyp].oc_name_known){ if(objects[obj->otyp].g_val > 0){ u.uluck += 5; goto valuable; } else { pline("%s is not interested in your junk.", Monnam(mon)); } } else { /* value unknown to @ */ u.uluck++; valuable: if(u.uluck > LUCKMAX) /* dan@ut-ngp */ u.uluck = LUCKMAX; pline("%s graciously accepts your gift.", Monnam(mon)); mpickobj(mon, obj); rloc(mon); return(1); } } } } /* the code following might become part of dropy() */ if(obj->otyp == CRYSKNIFE) obj->otyp = WORM_TOOTH; obj->ox = bhitpos.x; obj->oy = bhitpos.y; obj->nobj = fobj; fobj = obj; /* prevent him from throwing articles to the exit and escaping */ /* subfrombill(obj); */ stackobj(obj); if(Punished && obj == uball && (bhitpos.x != u.ux || bhitpos.y != u.uy)){ freeobj(uchain); unpobj(uchain); if(u.utrap){ if(u.utraptype == TT_PIT) pline("The ball pulls you out of the pit!"); else { - register long side = + long side = rn2(3) ? LEFT_SIDE : RIGHT_SIDE; pline("The ball pulls you out of the bear trap."); pline("Your %s leg is severely damaged.", (side == LEFT_SIDE) ? "left" : "right"); set_wounded_legs(side, 500+rn2(1000)); losehp(2, "thrown ball"); } u.utrap = 0; } unsee(); uchain->nobj = fobj; fobj = uchain; u.ux = uchain->ox = bhitpos.x - u.dx; u.uy = uchain->oy = bhitpos.y - u.dy; setsee(); (void) inshop(); } if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y); return(1); } /* split obj so that it gets size num */ /* remainder is put in the object structure delivered by this call */ struct obj * -splitobj(obj, num) register struct obj *obj; register int num; { -register struct obj *otmp; +splitobj(obj, num) struct obj *obj; int num; { +struct obj *otmp; otmp = newobj(0); *otmp = *obj; /* copies whole structure */ otmp->o_id = flags.ident++; otmp->onamelth = 0; obj->quan = num; obj->owt = weight(obj); otmp->quan -= num; otmp->owt = weight(otmp); /* -= obj->owt ? */ obj->nobj = otmp; if(obj->unpaid) splitbill(obj,otmp); return(otmp); } more_experienced(exp,rexp) -register int exp, rexp; +int exp, rexp; { extern char pl_character[]; u.uexp += exp; u.urexp += 4*exp + rexp; if(exp) flags.botl = 1; if(u.urexp >= ((pl_character[0] == 'W') ? 1000 : 2000)) flags.beginner = 0; } set_wounded_legs(side, timex) -register long side; -register int timex; +long side; +int timex; { if(!Wounded_legs || (Wounded_legs & TIMEOUT)) Wounded_legs |= side + timex; else Wounded_legs |= side; } heal_legs() { if(Wounded_legs) { if((Wounded_legs & BOTH_SIDES) == BOTH_SIDES) pline("Your legs feel somewhat better."); else pline("Your leg feels somewhat better."); Wounded_legs = 0; } } diff --git a/games/hack/hack.do_name.c b/games/hack/hack.do_name.c index 538bd7fb3234..ab33c4281b44 100644 --- a/games/hack/hack.do_name.c +++ b/games/hack/hack.do_name.c @@ -1,290 +1,290 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.do_name.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include extern char plname[]; coord getpos(force,goal) int force; char *goal; { -register cx,cy,i,c; +cx,cy,i,c; extern char sdir[]; /* defined in hack.c */ extern schar xdir[], ydir[]; /* idem */ extern char *visctrl(); /* see below */ coord cc; pline("(For instructions type a ?)"); cx = u.ux; cy = u.uy; curs(cx,cy+2); while((c = readchar()) != '.'){ for(i=0; i<8; i++) if(sdir[i] == c){ if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO) cx += xdir[i]; if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1) cy += ydir[i]; goto nxtc; } if(c == '?'){ pline("Use [hjkl] to move the cursor to %s.", goal); pline("Type a . when you are at the right place."); } else { pline("Unknown direction: '%s' (%s).", visctrl(c), force ? "use hjkl or ." : "aborted"); if(force) goto nxtc; cc.x = -1; cc.y = 0; return(cc); } nxtc: ; curs(cx,cy+2); } cc.x = cx; cc.y = cy; return(cc); } do_mname(){ char buf[BUFSZ]; coord cc; -register int cx,cy,lth,i; -register struct monst *mtmp, *mtmp2; +int cx,cy,lth,i; +struct monst *mtmp, *mtmp2; extern char *lmonnam(); cc = getpos(0, "the monster you want to name"); cx = cc.x; cy = cc.y; if(cx < 0) return(0); mtmp = m_at(cx,cy); if(!mtmp){ if(cx == u.ux && cy == u.uy) pline("This ugly monster is called %s and cannot be renamed.", plname); else pline("There is no monster there."); return(1); } if(mtmp->mimic){ pline("I see no monster there."); return(1); } if(!cansee(cx,cy)) { pline("I cannot see a monster there."); return(1); } pline("What do you want to call %s? ", lmonnam(mtmp)); getlin(buf); clrlin(); if(!*buf || *buf == '\033') return(1); lth = strlen(buf)+1; if(lth > 63){ buf[62] = 0; lth = 63; } mtmp2 = newmonst(mtmp->mxlth + lth); *mtmp2 = *mtmp; for(i=0; imxlth; i++) ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i]; mtmp2->mnamelth = lth; (void) strcpy(NAME(mtmp2), buf); replmon(mtmp,mtmp2); return(1); } /* * This routine changes the address of obj . Be careful not to call it * when there might be pointers around in unknown places. For now: only * when obj is in the inventory. */ -do_oname(obj) register struct obj *obj; { -register struct obj *otmp, *otmp2; -register lth; +do_oname(obj) struct obj *obj; { +struct obj *otmp, *otmp2; +lth; char buf[BUFSZ]; pline("What do you want to name %s? ", doname(obj)); getlin(buf); clrlin(); if(!*buf || *buf == '\033') return; lth = strlen(buf)+1; if(lth > 63){ buf[62] = 0; lth = 63; } otmp2 = newobj(lth); *otmp2 = *obj; otmp2->onamelth = lth; (void) strcpy(ONAME(otmp2), buf); setworn((struct obj *) 0, obj->owornmask); setworn(otmp2, otmp2->owornmask); /* do freeinv(obj); etc. by hand in order to preserve the position of this object in the inventory */ if(obj == invent) invent = otmp2; else for(otmp = invent; ; otmp = otmp->nobj){ if(!otmp) panic("Do_oname: cannot find obj."); if(otmp->nobj == obj){ otmp->nobj = otmp2; break; } } /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */ free((char *) obj); /* let us hope nobody else saved a pointer */ } ddocall() { - register struct obj *obj; + struct obj *obj; pline("Do you want to name an individual object? [ny] "); switch(readchar()) { case '\033': break; case 'y': obj = getobj("#", "name"); if(obj) do_oname(obj); break; default: obj = getobj("?!=/", "call"); if(obj) docall(obj); } return(0); } docall(obj) -register struct obj *obj; +struct obj *obj; { char buf[BUFSZ]; struct obj otemp; - register char **str1; + char **str1; extern char *xname(); - register char *str; + char *str; otemp = *obj; otemp.quan = 1; otemp.onamelth = 0; str = xname(&otemp); pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str); getlin(buf); clrlin(); if(!*buf || *buf == '\033') return; str = newstring(strlen(buf)+1); (void) strcpy(str,buf); str1 = &(objects[obj->otyp].oc_uname); if(*str1) free(*str1); *str1 = str; } char *ghostnames[] = { /* these names should have length < PL_NSIZ */ "adri", "andries", "andreas", "bert", "david", "dirk", "emile", "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay", "kenny", "maud", "michiel", "mike", "peter", "robert", "ron", "tom", "wilmar" }; char * -xmonnam(mtmp, vb) register struct monst *mtmp; int vb; { +xmonnam(mtmp, vb) struct monst *mtmp; int vb; { static char buf[BUFSZ]; /* %% */ extern char *shkname(); if(mtmp->mnamelth && !vb) { (void) strcpy(buf, NAME(mtmp)); return(buf); } switch(mtmp->data->mlet) { case ' ': - { register char *gn = (char *) mtmp->mextra; + { char *gn = (char *) mtmp->mextra; if(!*gn) { /* might also look in scorefile */ gn = ghostnames[rn2(SIZE(ghostnames))]; if(!rn2(2)) (void) strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn); } (void) sprintf(buf, "%s's ghost", gn); } break; case '@': if(mtmp->isshk) { (void) strcpy(buf, shkname(mtmp)); break; } /* fall into next case */ default: (void) sprintf(buf, "the %s%s", mtmp->minvis ? "invisible " : "", mtmp->data->mname); } if(vb && mtmp->mnamelth) { (void) strcat(buf, " called "); (void) strcat(buf, NAME(mtmp)); } return(buf); } char * -lmonnam(mtmp) register struct monst *mtmp; { +lmonnam(mtmp) struct monst *mtmp; { return(xmonnam(mtmp, 1)); } char * -monnam(mtmp) register struct monst *mtmp; { +monnam(mtmp) struct monst *mtmp; { return(xmonnam(mtmp, 0)); } char * -Monnam(mtmp) register struct monst *mtmp; { -register char *bp = monnam(mtmp); +Monnam(mtmp) struct monst *mtmp; { +char *bp = monnam(mtmp); if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a'); return(bp); } char * amonnam(mtmp,adj) -register struct monst *mtmp; -register char *adj; +struct monst *mtmp; +char *adj; { - register char *bp = monnam(mtmp); + char *bp = monnam(mtmp); static char buf[BUFSZ]; /* %% */ if(!strncmp(bp, "the ", 4)) bp += 4; (void) sprintf(buf, "the %s %s", adj, bp); return(buf); } char * Amonnam(mtmp, adj) -register struct monst *mtmp; -register char *adj; +struct monst *mtmp; +char *adj; { - register char *bp = amonnam(mtmp,adj); + char *bp = amonnam(mtmp,adj); *bp = 'T'; return(bp); } char * -Xmonnam(mtmp) register struct monst *mtmp; { -register char *bp = Monnam(mtmp); +Xmonnam(mtmp) struct monst *mtmp; { +char *bp = Monnam(mtmp); if(!strncmp(bp, "The ", 4)) { bp += 2; *bp = 'A'; } return(bp); } char * visctrl(c) char c; { static char ccc[3]; if(c < 040) { ccc[0] = '^'; ccc[1] = c + 0100; ccc[2] = 0; } else { ccc[0] = c; ccc[1] = 0; } return(ccc); } diff --git a/games/hack/hack.do_wear.c b/games/hack/hack.do_wear.c index 14f74e429fae..46e701372aa6 100644 --- a/games/hack/hack.do_wear.c +++ b/games/hack/hack.do_wear.c @@ -1,337 +1,337 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.do_wear.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include extern char *nomovemsg; extern char quitchars[]; extern char *Doname(); -off_msg(otmp) register struct obj *otmp; { +off_msg(otmp) struct obj *otmp; { pline("You were wearing %s.", doname(otmp)); } doremarm() { - register struct obj *otmp; + struct obj *otmp; if(!uarm && !uarmh && !uarms && !uarmg) { pline("Not wearing any armor."); return(0); } otmp = (!uarmh && !uarms && !uarmg) ? uarm : (!uarms && !uarm && !uarmg) ? uarmh : (!uarmh && !uarm && !uarmg) ? uarms : (!uarmh && !uarm && !uarms) ? uarmg : getobj("[", "take off"); if(!otmp) return(0); if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) { pline("You can't take that off."); return(0); } if( otmp == uarmg && uwep && uwep->cursed ) { /* myers@uwmacc */ pline("You seem not able to take off the gloves while holding your weapon."); return(0); } (void) armoroff(otmp); return(1); } doremring() { if(!uleft && !uright){ pline("Not wearing any ring."); return(0); } if(!uleft) return(dorr(uright)); if(!uright) return(dorr(uleft)); if(uleft && uright) while(1) { char answer; pline("What ring, Right or Left? [ rl?]"); if(index(quitchars, (answer = readchar()))) return(0); switch(answer) { case 'l': case 'L': return(dorr(uleft)); case 'r': case 'R': return(dorr(uright)); case '?': (void) doprring(); /* might look at morc here %% */ } } /* NOTREACHED */ #ifdef lint return(0); #endif lint } -dorr(otmp) register struct obj *otmp; { +dorr(otmp) struct obj *otmp; { if(cursed(otmp)) return(0); ringoff(otmp); off_msg(otmp); return(1); } -cursed(otmp) register struct obj *otmp; { +cursed(otmp) struct obj *otmp; { if(otmp->cursed){ pline("You can't. It appears to be cursed."); return(1); } return(0); } -armoroff(otmp) register struct obj *otmp; { -register int delay = -objects[otmp->otyp].oc_delay; +armoroff(otmp) struct obj *otmp; { +int delay = -objects[otmp->otyp].oc_delay; if(cursed(otmp)) return(0); setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); if(delay) { nomul(delay); switch(otmp->otyp) { case HELMET: nomovemsg = "You finished taking off your helmet."; break; case PAIR_OF_GLOVES: nomovemsg = "You finished taking off your gloves"; break; default: nomovemsg = "You finished taking off your suit."; } } else { off_msg(otmp); } return(1); } doweararm() { - register struct obj *otmp; - register int delay; - register int err = 0; + struct obj *otmp; + int delay; + int err = 0; long mask = 0; otmp = getobj("[", "wear"); if(!otmp) return(0); if(otmp->owornmask & W_ARMOR) { pline("You are already wearing that!"); return(0); } if(otmp->otyp == HELMET){ if(uarmh) { pline("You are already wearing a helmet."); err++; } else mask = W_ARMH; } else if(otmp->otyp == SHIELD){ if(uarms) pline("You are already wearing a shield."), err++; if(uwep && uwep->otyp == TWO_HANDED_SWORD) pline("You cannot wear a shield and wield a two-handed sword."), err++; if(!err) mask = W_ARMS; } else if(otmp->otyp == PAIR_OF_GLOVES) { if(uarmg) { pline("You are already wearing gloves."); err++; } else if(uwep && uwep->cursed) { pline("You cannot wear gloves over your weapon."); err++; } else mask = W_ARMG; } else { if(uarm) { if(otmp->otyp != ELVEN_CLOAK || uarm2) { pline("You are already wearing some armor."); err++; } } if(!err) mask = W_ARM; } if(otmp == uwep && uwep->cursed) { if(!err++) pline("%s is welded to your hand.", Doname(uwep)); } if(err) return(0); setworn(otmp, mask); if(otmp == uwep) setuwep((struct obj *) 0); delay = -objects[otmp->otyp].oc_delay; if(delay){ nomul(delay); nomovemsg = "You finished your dressing manoeuvre."; } otmp->known = 1; return(1); } dowearring() { - register struct obj *otmp; + struct obj *otmp; long mask = 0; long oldprop; if(uleft && uright){ pline("There are no more ring-fingers to fill."); return(0); } otmp = getobj("=", "wear"); if(!otmp) return(0); if(otmp->owornmask & W_RING) { pline("You are already wearing that!"); return(0); } if(otmp == uleft || otmp == uright) { pline("You are already wearing that."); return(0); } if(otmp == uwep && uwep->cursed) { pline("%s is welded to your hand.", Doname(uwep)); return(0); } if(uleft) mask = RIGHT_RING; else if(uright) mask = LEFT_RING; else do { char answer; pline("What ring-finger, Right or Left? "); if(index(quitchars, (answer = readchar()))) return(0); switch(answer){ case 'l': case 'L': mask = LEFT_RING; break; case 'r': case 'R': mask = RIGHT_RING; break; } } while(!mask); setworn(otmp, mask); if(otmp == uwep) setuwep((struct obj *) 0); oldprop = u.uprops[PROP(otmp->otyp)].p_flgs; u.uprops[PROP(otmp->otyp)].p_flgs |= mask; switch(otmp->otyp){ case RIN_LEVITATION: if(!oldprop) float_up(); break; case RIN_PROTECTION_FROM_SHAPE_CHANGERS: rescham(); break; case RIN_GAIN_STRENGTH: u.ustr += otmp->spe; u.ustrmax += otmp->spe; if(u.ustr > 118) u.ustr = 118; if(u.ustrmax > 118) u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: u.udaminc += otmp->spe; break; } prinv(otmp); return(1); } ringoff(obj) -register struct obj *obj; +struct obj *obj; { -register long mask; +long mask; mask = obj->owornmask & W_RING; setworn((struct obj *) 0, obj->owornmask); if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) impossible("Strange... I didnt know you had that ring."); u.uprops[PROP(obj->otyp)].p_flgs &= ~mask; switch(obj->otyp) { case RIN_FIRE_RESISTANCE: /* Bad luck if the player is in hell... --jgm */ if (!Fire_resistance && dlevel >= 30) { pline("The flames of Hell burn you to a crisp."); killer = "stupidity in hell"; done("burned"); } break; case RIN_LEVITATION: if(!Levitation) { /* no longer floating */ float_down(); } break; case RIN_GAIN_STRENGTH: u.ustr -= obj->spe; u.ustrmax -= obj->spe; if(u.ustr > 118) u.ustr = 118; if(u.ustrmax > 118) u.ustrmax = 118; flags.botl = 1; break; case RIN_INCREASE_DAMAGE: u.udaminc -= obj->spe; break; } } find_ac(){ -register int uac = 10; +int uac = 10; if(uarm) uac -= ARM_BONUS(uarm); if(uarm2) uac -= ARM_BONUS(uarm2); if(uarmh) uac -= ARM_BONUS(uarmh); if(uarms) uac -= ARM_BONUS(uarms); if(uarmg) uac -= ARM_BONUS(uarmg); if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe; if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe; if(uac != u.uac){ u.uac = uac; flags.botl = 1; } } glibr(){ -register struct obj *otmp; +struct obj *otmp; int xfl = 0; if(!uarmg) if(uleft || uright) { /* Note: at present also cursed rings fall off */ pline("Your %s off your fingers.", (uleft && uright) ? "rings slip" : "ring slips"); xfl++; if((otmp = uleft) != Null(obj)){ ringoff(uleft); dropx(otmp); } if((otmp = uright) != Null(obj)){ ringoff(uright); dropx(otmp); } } if((otmp = uwep) != Null(obj)){ /* Note: at present also cursed weapons fall */ setuwep((struct obj *) 0); dropx(otmp); pline("Your weapon %sslips from your hands.", xfl ? "also " : ""); } } struct obj * some_armor(){ -register struct obj *otmph = uarm; +struct obj *otmph = uarm; if(uarmh && (!otmph || !rn2(4))) otmph = uarmh; if(uarmg && (!otmph || !rn2(4))) otmph = uarmg; if(uarms && (!otmph || !rn2(4))) otmph = uarms; return(otmph); } corrode_armor(){ -register struct obj *otmph = some_armor(); +struct obj *otmph = some_armor(); if(otmph){ if(otmph->rustfree || otmph->otyp == ELVEN_CLOAK || otmph->otyp == LEATHER_ARMOR || otmph->otyp == STUDDED_LEATHER_ARMOR) { pline("Your %s not affected!", aobjnam(otmph, "are")); return; } pline("Your %s!", aobjnam(otmph, "corrode")); otmph->spe--; } } diff --git a/games/hack/hack.dog.c b/games/hack/hack.dog.c index c47a3531a604..9e518e1b3275 100644 --- a/games/hack/hack.dog.c +++ b/games/hack/hack.dog.c @@ -1,414 +1,414 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.dog.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include "hack.mfndpos.h" extern struct monst *makemon(); #include "def.edog.h" #include "def.mkroom.h" struct permonst li_dog = { "little dog", 'd',2,18,6,1,6,sizeof(struct edog) }; struct permonst dog = { "dog", 'd',4,16,5,1,6,sizeof(struct edog) }; struct permonst la_dog = { "large dog", 'd',6,15,4,2,4,sizeof(struct edog) }; makedog(){ -register struct monst *mtmp = makemon(&li_dog,u.ux,u.uy); +struct monst *mtmp = makemon(&li_dog,u.ux,u.uy); if(!mtmp) return; /* dogs were genocided */ initedog(mtmp); } -initedog(mtmp) register struct monst *mtmp; { +initedog(mtmp) struct monst *mtmp; { mtmp->mtame = mtmp->mpeaceful = 1; EDOG(mtmp)->hungrytime = 1000 + moves; EDOG(mtmp)->eattime = 0; EDOG(mtmp)->droptime = 0; EDOG(mtmp)->dropdist = 10000; EDOG(mtmp)->apport = 10; EDOG(mtmp)->whistletime = 0; } /* attach the monsters that went down (or up) together with @ */ struct monst *mydogs = 0; struct monst *fallen_down = 0; /* monsters that fell through a trapdoor */ /* they will appear on the next level @ goes to, even if he goes up! */ losedogs(){ -register struct monst *mtmp; +struct monst *mtmp; while(mtmp = mydogs){ mydogs = mtmp->nmon; mtmp->nmon = fmon; fmon = mtmp; mnexto(mtmp); } while(mtmp = fallen_down){ fallen_down = mtmp->nmon; mtmp->nmon = fmon; fmon = mtmp; rloc(mtmp); } } keepdogs(){ -register struct monst *mtmp; +struct monst *mtmp; for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(dist(mtmp->mx,mtmp->my) < 3 && follower(mtmp) && !mtmp->msleep && !mtmp->mfroz) { relmon(mtmp); mtmp->nmon = mydogs; mydogs = mtmp; unpmon(mtmp); keepdogs(); /* we destroyed the link, so use recursion */ return; /* (admittedly somewhat primitive) */ } } -fall_down(mtmp) register struct monst *mtmp; { +fall_down(mtmp) struct monst *mtmp; { relmon(mtmp); mtmp->nmon = fallen_down; fallen_down = mtmp; unpmon(mtmp); mtmp->mtame = 0; } /* return quality of food; the lower the better */ #define DOGFOOD 0 #define CADAVER 1 #define ACCFOOD 2 #define MANFOOD 3 #define APPORT 4 #define POISON 5 #define UNDEF 6 -dogfood(obj) register struct obj *obj; { +dogfood(obj) struct obj *obj; { switch(obj->olet) { case FOOD_SYM: return( (obj->otyp == TRIPE_RATION) ? DOGFOOD : (obj->otyp < CARROT) ? ACCFOOD : (obj->otyp < CORPSE) ? MANFOOD : (poisonous(obj) || obj->age + 50 <= moves || obj->otyp == DEAD_COCKATRICE) ? POISON : CADAVER ); default: if(!obj->cursed) return(APPORT); /* fall into next case */ case BALL_SYM: case CHAIN_SYM: case ROCK_SYM: return(UNDEF); } } /* return 0 (no move), 1 (move) or 2 (dead) */ -dog_move(mtmp, after) register struct monst *mtmp; { -register int nx,ny,omx,omy,appr,nearer,j; +dog_move(mtmp, after) struct monst *mtmp; { +int nx,ny,omx,omy,appr,nearer,j; int udist,chi,i,whappr; -register struct monst *mtmp2; -register struct permonst *mdat = mtmp->data; -register struct edog *edog = EDOG(mtmp); +struct monst *mtmp2; +struct permonst *mdat = mtmp->data; +struct edog *edog = EDOG(mtmp); struct obj *obj; struct trap *trap; xchar cnt,chcnt,nix,niy; schar dogroom,uroom; xchar gx,gy,gtyp,otyp; /* current goal */ coord poss[9]; int info[9]; #define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy)) #define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy)) if(moves <= edog->eattime) return(0); /* dog is still eating */ omx = mtmp->mx; omy = mtmp->my; whappr = (moves - EDOG(mtmp)->whistletime < 5); if(moves > edog->hungrytime + 500 && !mtmp->mconf){ mtmp->mconf = 1; mtmp->mhpmax /= 3; if(mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; if(cansee(omx,omy)) pline("%s is confused from hunger.", Monnam(mtmp)); else pline("You feel worried about %s.", monnam(mtmp)); } else if(moves > edog->hungrytime + 750 || mtmp->mhp < 1){ if(cansee(omx,omy)) pline("%s dies from hunger.", Monnam(mtmp)); else pline("You have a sad feeling for a moment, then it passes."); mondied(mtmp); return(2); } dogroom = inroom(omx,omy); uroom = inroom(u.ux,u.uy); udist = dist(omx,omy); /* maybe we tamed him while being swallowed --jgm */ if(!udist) return(0); /* if we are carrying sth then we drop it (perhaps near @) */ /* Note: if apport == 1 then our behaviour is independent of udist */ if(mtmp->minvent){ if(!rn2(udist) || !rn2((int) edog->apport)) if(rn2(10) < edog->apport){ relobj(mtmp, (int) mtmp->minvis); if(edog->apport > 1) edog->apport--; edog->dropdist = udist; /* hpscdi!jon */ edog->droptime = moves; } } else { if(obj = o_at(omx,omy)) if(!index("0_", obj->olet)){ if((otyp = dogfood(obj)) <= CADAVER){ nix = omx; niy = omy; goto eatobj; } if(obj->owt < 10*mtmp->data->mlevel) if(rn2(20) < edog->apport+3) if(rn2(udist) || !rn2((int) edog->apport)){ freeobj(obj); unpobj(obj); /* if(levl[omx][omy].scrsym == obj->olet) newsym(omx,omy); */ mpickobj(mtmp,obj); } } } /* first we look for food */ gtyp = UNDEF; /* no goal as yet */ #ifdef LINT gx = gy = 0; /* suppress 'used before set' message */ #endif LINT for(obj = fobj; obj; obj = obj->nobj) { otyp = dogfood(obj); if(otyp > gtyp || otyp == UNDEF) continue; if(inroom(obj->ox,obj->oy) != dogroom) continue; if(otyp < MANFOOD && (dogroom >= 0 || DDIST(obj->ox,obj->oy) < 10)) { if(otyp < gtyp || (otyp == gtyp && DDIST(obj->ox,obj->oy) < DDIST(gx,gy))){ gx = obj->ox; gy = obj->oy; gtyp = otyp; } } else if(gtyp == UNDEF && dogroom >= 0 && uroom == dogroom && !mtmp->minvent && edog->apport > rn2(8)){ gx = obj->ox; gy = obj->oy; gtyp = APPORT; } } if(gtyp == UNDEF || (gtyp != DOGFOOD && gtyp != APPORT && moves < edog->hungrytime)){ if(dogroom < 0 || dogroom == uroom){ gx = u.ux; gy = u.uy; #ifndef QUEST } else { int tmp = rooms[dogroom].fdoor; cnt = rooms[dogroom].doorct; gx = gy = FAR; /* random, far away */ while(cnt--){ if(dist(gx,gy) > dist(doors[tmp].x, doors[tmp].y)){ gx = doors[tmp].x; gy = doors[tmp].y; } tmp++; } /* here gx == FAR e.g. when dog is in a vault */ if(gx == FAR || (gx == omx && gy == omy)){ gx = u.ux; gy = u.uy; } #endif QUEST } appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; if(after && udist <= 4 && gx == u.ux && gy == u.uy) return(0); if(udist > 1){ if(!IS_ROOM(levl[u.ux][u.uy].typ) || !rn2(4) || whappr || (mtmp->minvent && rn2((int) edog->apport))) appr = 1; } /* if you have dog food he'll follow you more closely */ if(appr == 0){ obj = invent; while(obj){ if(obj->otyp == TRIPE_RATION){ appr = 1; break; } obj = obj->nobj; } } } else appr = 1; /* gtyp != UNDEF */ if(mtmp->mconf) appr = 0; if(gx == u.ux && gy == u.uy && (dogroom != uroom || dogroom < 0)){ extern coord *gettrack(); - register coord *cp; + coord *cp; cp = gettrack(omx,omy); if(cp){ gx = cp->x; gy = cp->y; } } nix = omx; niy = omy; cnt = mfndpos(mtmp,poss,info,ALLOW_M | ALLOW_TRAPS); chcnt = 0; chi = -1; for(i=0; idata->mlevel >= mdat->mlevel+2 || mtmp2->data->mlet == 'c') continue; if(after) return(0); /* hit only once each move */ if(hitmm(mtmp, mtmp2) == 1 && rn2(4) && mtmp2->mlstmv != moves && hitmm(mtmp2,mtmp) == 2) return(2); return(0); } /* dog avoids traps */ /* but perhaps we have to pass a trap in order to follow @ */ if((info[i] & ALLOW_TRAPS) && (trap = t_at(nx,ny))){ if(!trap->tseen && rn2(40)) continue; if(rn2(10)) continue; } /* dog eschewes cursed objects */ /* but likes dog food */ obj = fobj; while(obj){ if(obj->ox != nx || obj->oy != ny) goto nextobj; if(obj->cursed) goto nxti; if(obj->olet == FOOD_SYM && (otyp = dogfood(obj)) < MANFOOD && (otyp < ACCFOOD || edog->hungrytime <= moves)){ /* Note: our dog likes the food so much that he might eat it even when it conceals a cursed object */ nix = nx; niy = ny; chi = i; eatobj: edog->eattime = moves + obj->quan * objects[obj->otyp].oc_delay; if(edog->hungrytime < moves) edog->hungrytime = moves; edog->hungrytime += 5*obj->quan * objects[obj->otyp].nutrition; mtmp->mconf = 0; if(cansee(nix,niy)) pline("%s ate %s.", Monnam(mtmp), doname(obj)); /* perhaps this was a reward */ if(otyp != CADAVER) edog->apport += 200/(edog->dropdist+moves-edog->droptime); delobj(obj); goto newdogpos; } nextobj: obj = obj->nobj; } for(j=0; jmtrack[j].x && ny == mtmp->mtrack[j].y) if(rn2(4*(cnt-j))) goto nxti; /* Some stupid C compilers cannot compute the whole expression at once. */ nearer = GDIST(nx,ny); nearer -= GDIST(nix,niy); nearer *= appr; if((nearer == 0 && !rn2(++chcnt)) || nearer<0 || (nearer > 0 && !whappr && ((omx == nix && omy == niy && !rn2(3)) || !rn2(12)) )){ nix = nx; niy = ny; if(nearer < 0) chcnt = 0; chi = i; } nxti: ; } newdogpos: if(nix != omx || niy != omy){ if(info[chi] & ALLOW_U){ (void) hitu(mtmp, d(mdat->damn, mdat->damd)+1); return(0); } mtmp->mx = nix; mtmp->my = niy; for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; } if(mintrap(mtmp) == 2) /* he died */ return(2); pmon(mtmp); return(1); } /* return roomnumber or -1 */ inroom(x,y) xchar x,y; { #ifndef QUEST - register struct mkroom *croom = &rooms[0]; + struct mkroom *croom = &rooms[0]; while(croom->hx >= 0){ if(croom->hx >= x-1 && croom->lx <= x+1 && croom->hy >= y-1 && croom->ly <= y+1) return(croom - rooms); croom++; } #endif QUEST return(-1); /* not in room or on door */ } tamedog(mtmp, obj) -register struct monst *mtmp; -register struct obj *obj; +struct monst *mtmp; +struct obj *obj; { - register struct monst *mtmp2; + struct monst *mtmp2; if(flags.moonphase == FULL_MOON && night() && rn2(6)) return(0); /* If we cannot tame him, at least he's no longer afraid. */ mtmp->mflee = 0; mtmp->mfleetim = 0; if(mtmp->mtame || mtmp->mfroz || #ifndef NOWORM mtmp->wormno || #endif NOWORM mtmp->isshk || mtmp->isgd || index(" &@12", mtmp->data->mlet)) return(0); /* no tame long worms? */ if(obj) { if(dogfood(obj) >= MANFOOD) return(0); if(cansee(mtmp->mx,mtmp->my)){ pline("%s devours the %s.", Monnam(mtmp), objects[obj->otyp].oc_name); } obfree(obj, (struct obj *) 0); } mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth); *mtmp2 = *mtmp; mtmp2->mxlth = sizeof(struct edog); if(mtmp->mnamelth) (void) strcpy(NAME(mtmp2), NAME(mtmp)); initedog(mtmp2); replmon(mtmp,mtmp2); return(1); } diff --git a/games/hack/hack.eat.c b/games/hack/hack.eat.c index 9c0a64cf0636..a490be8475ac 100644 --- a/games/hack/hack.eat.c +++ b/games/hack/hack.eat.c @@ -1,460 +1,460 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.eat.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" char POISONOUS[] = "ADKSVabhks"; extern char *nomovemsg; extern int (*afternmv)(); extern int (*occupation)(); extern char *occtxt; extern struct obj *splitobj(), *addinv(); /* hunger texts used on bottom line (each 8 chars long) */ #define SATIATED 0 #define NOT_HUNGRY 1 #define HUNGRY 2 #define WEAK 3 #define FAINTING 4 #define FAINTED 5 #define STARVED 6 char *hu_stat[] = { "Satiated", " ", "Hungry ", "Weak ", "Fainting", "Fainted ", "Starved " }; init_uhunger(){ u.uhunger = 900; u.uhs = NOT_HUNGRY; } #define TTSZ SIZE(tintxts) struct { char *txt; int nut; } tintxts[] = { "It contains first quality peaches - what a surprise!", 40, "It contains salmon - not bad!", 60, "It contains apple juice - perhaps not what you hoped for.", 20, "It contains some nondescript substance, tasting awfully.", 500, "It contains rotten meat. You vomit.", -50, "It turns out to be empty.", 0 }; static struct { struct obj *tin; int usedtime, reqtime; } tin; opentin(){ - register int r; + int r; if(!carried(tin.tin)) /* perhaps it was stolen? */ return(0); /* %% probably we should use tinoid */ if(tin.usedtime++ >= 50) { pline("You give up your attempt to open the tin."); return(0); } if(tin.usedtime < tin.reqtime) return(1); /* still busy */ pline("You succeed in opening the tin."); useup(tin.tin); r = rn2(2*TTSZ); if(r < TTSZ){ pline(tintxts[r].txt); lesshungry(tintxts[r].nut); if(r == 1) /* SALMON */ { Glib = rnd(15); pline("Eating salmon made your fingers very slippery."); } } else { pline("It contains spinach - this makes you feel like Popeye!"); lesshungry(600); if(u.ustr < 118) u.ustr += rnd( ((u.ustr < 17) ? 19 : 118) - u.ustr); if(u.ustr > u.ustrmax) u.ustrmax = u.ustr; flags.botl = 1; } return(0); } Meatdone(){ u.usym = '@'; prme(); } doeat(){ - register struct obj *otmp; - register struct objclass *ftmp; - register tmp; + struct obj *otmp; + struct objclass *ftmp; + tmp; /* Is there some food (probably a heavy corpse) here on the ground? */ if(!Levitation) for(otmp = fobj; otmp; otmp = otmp->nobj) { if(otmp->ox == u.ux && otmp->oy == u.uy && otmp->olet == FOOD_SYM) { pline("There %s %s here; eat %s? [ny] ", (otmp->quan == 1) ? "is" : "are", doname(otmp), (otmp->quan == 1) ? "it" : "one"); if(readchar() == 'y') { if(otmp->quan != 1) (void) splitobj(otmp, 1); freeobj(otmp); otmp = addinv(otmp); addtobill(otmp); goto gotit; } } } otmp = getobj("%", "eat"); if(!otmp) return(0); gotit: if(otmp->otyp == TIN){ if(uwep) { switch(uwep->otyp) { case CAN_OPENER: tmp = 1; break; case DAGGER: case CRYSKNIFE: tmp = 3; break; case PICK_AXE: case AXE: tmp = 6; break; default: goto no_opener; } pline("Using your %s you try to open the tin.", aobjnam(uwep, (char *) 0)); } else { no_opener: pline("It is not so easy to open this tin."); if(Glib) { pline("The tin slips out of your hands."); if(otmp->quan > 1) { - register struct obj *obj; + struct obj *obj; extern struct obj *splitobj(); obj = splitobj(otmp, 1); if(otmp == uwep) setuwep(obj); } dropx(otmp); return(1); } tmp = 10 + rn2(1 + 500/((int)(u.ulevel + u.ustr))); } tin.reqtime = tmp; tin.usedtime = 0; tin.tin = otmp; occupation = opentin; occtxt = "opening the tin"; return(1); } ftmp = &objects[otmp->otyp]; multi = -ftmp->oc_delay; if(otmp->otyp >= CORPSE && eatcorpse(otmp)) goto eatx; if(!rn2(7) && otmp->otyp != FORTUNE_COOKIE) { pline("Blecch! Rotten food!"); if(!rn2(4)) { pline("You feel rather light headed."); Confusion += d(2,4); } else if(!rn2(4)&& !Blind) { pline("Everything suddenly goes dark."); Blind = d(2,10); seeoff(0); } else if(!rn2(3)) { if(Blind) pline("The world spins and you slap against the floor."); else pline("The world spins and goes dark."); nomul(-rnd(10)); nomovemsg = "You are conscious again."; } lesshungry(ftmp->nutrition / 4); } else { if(u.uhunger >= 1500) { pline("You choke over your food."); pline("You die..."); killer = ftmp->oc_name; done("choked"); } switch(otmp->otyp){ case FOOD_RATION: if(u.uhunger <= 200) pline("That food really hit the spot!"); else if(u.uhunger <= 700) pline("That satiated your stomach!"); else { pline("You're having a hard time getting all that food down."); multi -= 2; } lesshungry(ftmp->nutrition); if(multi < 0) nomovemsg = "You finished your meal."; break; case TRIPE_RATION: pline("Yak - dog food!"); more_experienced(1,0); flags.botl = 1; if(rn2(2)){ pline("You vomit."); morehungry(20); if(Sick) { Sick = 0; /* David Neves */ pline("What a relief!"); } } else lesshungry(ftmp->nutrition); break; default: if(otmp->otyp >= CORPSE) pline("That %s tasted terrible!",ftmp->oc_name); else pline("That %s was delicious!",ftmp->oc_name); lesshungry(ftmp->nutrition); if(otmp->otyp == DEAD_LIZARD && (Confusion > 2)) Confusion = 2; else #ifdef QUEST if(otmp->otyp == CARROT && !Blind){ u.uhorizon++; setsee(); pline("Your vision improves."); } else #endif QUEST if(otmp->otyp == FORTUNE_COOKIE) { if(Blind) { pline("This cookie has a scrap of paper inside!"); pline("What a pity, that you cannot read it!"); } else outrumor(); } else if(otmp->otyp == LUMP_OF_ROYAL_JELLY) { /* This stuff seems to be VERY healthy! */ if(u.ustrmax < 118) u.ustrmax++; if(u.ustr < u.ustrmax) u.ustr++; u.uhp += rnd(20); if(u.uhp > u.uhpmax) { if(!rn2(17)) u.uhpmax++; u.uhp = u.uhpmax; } heal_legs(); } break; } } eatx: if(multi<0 && !nomovemsg){ static char msgbuf[BUFSZ]; (void) sprintf(msgbuf, "You finished eating the %s.", ftmp->oc_name); nomovemsg = msgbuf; } useup(otmp); return(1); } /* called in hack.main.c */ gethungry(){ --u.uhunger; if(moves % 2) { if(Regeneration) u.uhunger--; if(Hunger) u.uhunger--; /* a3: if(Hunger & LEFT_RING) u.uhunger--; if(Hunger & RIGHT_RING) u.uhunger--; etc. */ } if(moves % 20 == 0) { /* jimt@asgb */ if(uleft) u.uhunger--; if(uright) u.uhunger--; } newuhs(TRUE); } /* called after vomiting and after performing feats of magic */ -morehungry(num) register num; { +morehungry(num) num; { u.uhunger -= num; newuhs(TRUE); } /* called after eating something (and after drinking fruit juice) */ -lesshungry(num) register num; { +lesshungry(num) num; { u.uhunger += num; newuhs(FALSE); } unfaint(){ u.uhs = FAINTING; flags.botl = 1; } newuhs(incr) boolean incr; { - register int newhs, h = u.uhunger; + int newhs, h = u.uhunger; newhs = (h > 1000) ? SATIATED : (h > 150) ? NOT_HUNGRY : (h > 50) ? HUNGRY : (h > 0) ? WEAK : FAINTING; if(newhs == FAINTING) { if(u.uhs == FAINTED) newhs = FAINTED; if(u.uhs <= WEAK || rn2(20-u.uhunger/10) >= 19) { if(u.uhs != FAINTED && multi >= 0 /* %% */) { pline("You faint from lack of food."); nomul(-10+(u.uhunger/10)); nomovemsg = "You regain consciousness."; afternmv = unfaint; newhs = FAINTED; } } else if(u.uhunger < -(int)(200 + 25*u.ulevel)) { u.uhs = STARVED; flags.botl = 1; bot(); pline("You die from starvation."); done("starved"); } } if(newhs != u.uhs) { if(newhs >= WEAK && u.uhs < WEAK) losestr(1); /* this may kill you -- see below */ else if(newhs < WEAK && u.uhs >= WEAK && u.ustr < u.ustrmax) losestr(-1); switch(newhs){ case HUNGRY: pline((!incr) ? "You only feel hungry now." : (u.uhunger < 145) ? "You feel hungry." : "You are beginning to feel hungry."); break; case WEAK: pline((!incr) ? "You feel weak now." : (u.uhunger < 45) ? "You feel weak." : "You are beginning to feel weak."); break; } u.uhs = newhs; flags.botl = 1; if(u.uhp < 1) { pline("You die from hunger and exhaustion."); killer = "exhaustion"; done("starved"); } } } #define CORPSE_I_TO_C(otyp) (char) ((otyp >= DEAD_ACID_BLOB)\ ? 'a' + (otyp - DEAD_ACID_BLOB)\ : '@' + (otyp - DEAD_HUMAN)) poisonous(otmp) -register struct obj *otmp; +struct obj *otmp; { return(index(POISONOUS, CORPSE_I_TO_C(otmp->otyp)) != 0); } /* returns 1 if some text was printed */ -eatcorpse(otmp) register struct obj *otmp; { -register char let = CORPSE_I_TO_C(otmp->otyp); -register tp = 0; +eatcorpse(otmp) struct obj *otmp; { +char let = CORPSE_I_TO_C(otmp->otyp); +tp = 0; if(let != 'a' && moves > otmp->age + 50 + rn2(100)) { tp++; pline("Ulch -- that meat was tainted!"); pline("You get very sick."); Sick = 10 + rn2(10); u.usick_cause = objects[otmp->otyp].oc_name; } else if(index(POISONOUS, let) && rn2(5)){ tp++; pline("Ecch -- that must have been poisonous!"); if(!Poison_resistance){ losestr(rnd(4)); losehp(rnd(15), "poisonous corpse"); } else pline("You don't seem affected by the poison."); } else if(index("ELNOPQRUuxz", let) && rn2(5)){ tp++; pline("You feel sick."); losehp(rnd(8), "cadaver"); } switch(let) { case 'L': case 'N': case 't': Teleportation |= INTRINSIC; break; case 'W': pluslvl(); break; case 'n': u.uhp = u.uhpmax; flags.botl = 1; /* fall into next case */ case '@': pline("You cannibal! You will be sorry for this!"); /* not tp++; */ /* fall into next case */ case 'd': Aggravate_monster |= INTRINSIC; break; case 'I': if(!Invis) { Invis = 50+rn2(100); if(!See_invisible) newsym(u.ux, u.uy); } else { Invis |= INTRINSIC; See_invisible |= INTRINSIC; } /* fall into next case */ case 'y': #ifdef QUEST u.uhorizon++; #endif QUEST /* fall into next case */ case 'B': Confusion = 50; break; case 'D': Fire_resistance |= INTRINSIC; break; case 'E': Telepat |= INTRINSIC; break; case 'F': case 'Y': Cold_resistance |= INTRINSIC; break; case 'k': case 's': Poison_resistance |= INTRINSIC; break; case 'c': pline("You turn to stone."); killer = "dead cockatrice"; done("died"); /* NOTREACHED */ case 'a': if(Stoned) { pline("What a pity - you just destroyed a future piece of art!"); tp++; Stoned = 0; } break; case 'M': pline("You cannot resist the temptation to mimic a treasure chest."); tp++; nomul(-30); afternmv = Meatdone; nomovemsg = "You now again prefer mimicking a human."; u.usym = '$'; prme(); break; } return(tp); } diff --git a/games/hack/hack.end.c b/games/hack/hack.end.c index c089b446cc81..a49d75871a18 100644 --- a/games/hack/hack.end.c +++ b/games/hack/hack.end.c @@ -1,643 +1,643 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.end.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include #include #define Sprintf (void) sprintf extern char plname[], pl_character[]; extern char *itoa(), *ordin(), *eos(); xchar maxdlevel = 1; void done1() { (void) signal(SIGINT,SIG_IGN); pline("Really quit?"); if(readchar() != 'y') { (void) signal(SIGINT,done1); clrlin(); (void) fflush(stdout); if(multi > 0) nomul(0); return; } done("quit"); /* NOTREACHED */ } int done_stopprint; int done_hup; void done_intr(){ done_stopprint++; (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); } void done_hangup(){ done_hup++; (void) signal(SIGHUP, SIG_IGN); done_intr(); } -done_in_by(mtmp) register struct monst *mtmp; { +done_in_by(mtmp) struct monst *mtmp; { static char buf[BUFSZ]; pline("You die ..."); if(mtmp->data->mlet == ' '){ Sprintf(buf, "the ghost of %s", (char *) mtmp->mextra); killer = buf; } else if(mtmp->mnamelth) { Sprintf(buf, "%s called %s", mtmp->data->mname, NAME(mtmp)); killer = buf; } else if(mtmp->minvis) { Sprintf(buf, "invisible %s", mtmp->data->mname); killer = buf; } else killer = mtmp->data->mname; done("died"); } /* called with arg "died", "drowned", "escaped", "quit", "choked", "panicked", "burned", "starved" or "tricked" */ /* Be careful not to call panic from here! */ done(st1) -register char *st1; +char *st1; { #ifdef WIZARD if(wizard && *st1 == 'd'){ u.uswldtim = 0; if(u.uhpmax < 0) u.uhpmax = 100; /* arbitrary */ u.uhp = u.uhpmax; pline("For some reason you are still alive."); flags.move = 0; if(multi > 0) multi = 0; else multi = -1; flags.botl = 1; return; } #endif WIZARD (void) signal(SIGINT, done_intr); (void) signal(SIGQUIT, done_intr); (void) signal(SIGHUP, done_hangup); if(*st1 == 'q' && u.uhp < 1){ st1 = "died"; killer = "quit while already on Charon's boat"; } if(*st1 == 's') killer = "starvation"; else if(*st1 == 'd' && st1[1] == 'r') killer = "drowning"; else if(*st1 == 'p') killer = "panic"; else if(*st1 == 't') killer = "trickery"; else if(!index("bcd", *st1)) killer = st1; paybill(); clearlocks(); if(flags.toplin == 1) more(); if(index("bcds", *st1)){ #ifdef WIZARD if(!wizard) #endif WIZARD savebones(); if(!flags.notombstone) outrip(); } if(*st1 == 'c') killer = st1; /* after outrip() */ settty((char *) 0); /* does a clear_screen() */ if(!done_stopprint) printf("Goodbye %s %s...\n\n", pl_character, plname); { long int tmp; tmp = u.ugold - u.ugold0; if(tmp < 0) tmp = 0; if(*st1 == 'd' || *st1 == 'b') tmp -= tmp/10; u.urexp += tmp; u.urexp += 50 * maxdlevel; if(maxdlevel > 20) u.urexp += 1000*((maxdlevel > 30) ? 10 : maxdlevel - 20); } if(*st1 == 'e') { extern struct monst *mydogs; - register struct monst *mtmp; - register struct obj *otmp; - register int i; - register unsigned worthlessct = 0; + struct monst *mtmp; + struct obj *otmp; + int i; + unsigned worthlessct = 0; boolean has_amulet = FALSE; killer = st1; keepdogs(); mtmp = mydogs; if(mtmp) { if(!done_stopprint) printf("You"); while(mtmp) { if(!done_stopprint) printf(" and %s", monnam(mtmp)); if(mtmp->mtame) u.urexp += mtmp->mhp; mtmp = mtmp->nmon; } if(!done_stopprint) printf("\nescaped from the dungeon with %ld points,\n", u.urexp); } else if(!done_stopprint) printf("You escaped from the dungeon with %ld points,\n", u.urexp); for(otmp = invent; otmp; otmp = otmp->nobj) { if(otmp->olet == GEM_SYM){ objects[otmp->otyp].oc_name_known = 1; i = otmp->quan*objects[otmp->otyp].g_val; if(i == 0) { worthlessct += otmp->quan; continue; } u.urexp += i; if(!done_stopprint) printf("\t%s (worth %d Zorkmids),\n", doname(otmp), i); } else if(otmp->olet == AMULET_SYM) { otmp->known = 1; i = (otmp->spe < 0) ? 2 : 5000; u.urexp += i; if(!done_stopprint) printf("\t%s (worth %d Zorkmids),\n", doname(otmp), i); if(otmp->spe >= 0) { has_amulet = TRUE; killer = "escaped (with amulet)"; } } } if(worthlessct) if(!done_stopprint) printf("\t%u worthless piece%s of coloured glass,\n", worthlessct, plur(worthlessct)); if(has_amulet) u.urexp *= 2; } else if(!done_stopprint) printf("You %s on dungeon level %d with %ld points,\n", st1, dlevel, u.urexp); if(!done_stopprint) printf("and %ld piece%s of gold, after %ld move%s.\n", u.ugold, plur(u.ugold), moves, plur(moves)); if(!done_stopprint) printf("You were level %u with a maximum of %d hit points when you %s.\n", u.ulevel, u.uhpmax, st1); if(*st1 == 'e' && !done_stopprint){ getret(); /* all those pieces of coloured glass ... */ cls(); } #ifdef WIZARD if(!wizard) #endif WIZARD topten(); if(done_stopprint) printf("\n\n"); exit(0); } #define newttentry() (struct toptenentry *) alloc(sizeof(struct toptenentry)) #define NAMSZ 8 #define DTHSZ 40 #define PERSMAX 1 #define POINTSMIN 1 /* must be > 0 */ #define ENTRYMAX 100 /* must be >= 10 */ #define PERS_IS_UID /* delete for PERSMAX per name; now per uid */ struct toptenentry { struct toptenentry *tt_next; long int points; int level,maxlvl,hp,maxhp; int uid; char plchar; char sex; char name[NAMSZ+1]; char death[DTHSZ+1]; char date[7]; /* yymmdd */ } *tt_head; topten(){ int uid = getuid(); int rank, rank0 = -1, rank1 = 0; int occ_cnt = PERSMAX; - register struct toptenentry *t0, *t1, *tprev; + struct toptenentry *t0, *t1, *tprev; char *recfile = RECORD; char *reclock = "record_lock"; int sleepct = 300; FILE *rfile; - register flg = 0; + flg = 0; extern char *getdate(); #define HUP if(!done_hup) while(link(recfile, reclock) == -1) { HUP perror(reclock); if(!sleepct--) { HUP puts("I give up. Sorry."); HUP puts("Perhaps there is an old record_lock around?"); return; } HUP printf("Waiting for access to record file. (%d)\n", sleepct); HUP (void) fflush(stdout); sleep(1); } if(!(rfile = fopen(recfile,"r"))){ HUP puts("Cannot open record file!"); goto unlock; } HUP (void) putchar('\n'); /* create a new 'topten' entry */ t0 = newttentry(); t0->level = dlevel; t0->maxlvl = maxdlevel; t0->hp = u.uhp; t0->maxhp = u.uhpmax; t0->points = u.urexp; t0->plchar = pl_character[0]; t0->sex = (flags.female ? 'F' : 'M'); t0->uid = uid; (void) strncpy(t0->name, plname, NAMSZ); (t0->name)[NAMSZ] = 0; (void) strncpy(t0->death, killer, DTHSZ); (t0->death)[DTHSZ] = 0; (void) strcpy(t0->date, getdate()); /* assure minimum number of points */ if(t0->points < POINTSMIN) t0->points = 0; t1 = tt_head = newttentry(); tprev = 0; /* rank0: -1 undefined, 0 not_on_list, n n_th on list */ for(rank = 1; ; ) { if(fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", t1->date, &t1->uid, &t1->level, &t1->maxlvl, &t1->hp, &t1->maxhp, &t1->points, &t1->plchar, &t1->sex, t1->name, t1->death) != 11 || t1->points < POINTSMIN) t1->points = 0; if(rank0 < 0 && t1->points < t0->points) { rank0 = rank++; if(tprev == 0) tt_head = t0; else tprev->tt_next = t0; t0->tt_next = t1; occ_cnt--; flg++; /* ask for a rewrite */ } else tprev = t1; if(t1->points == 0) break; if( #ifdef PERS_IS_UID t1->uid == t0->uid && #else strncmp(t1->name, t0->name, NAMSZ) == 0 && #endif PERS_IS_UID t1->plchar == t0->plchar && --occ_cnt <= 0){ if(rank0 < 0){ rank0 = 0; rank1 = rank; HUP printf("You didn't beat your previous score of %ld points.\n\n", t1->points); } if(occ_cnt < 0){ flg++; continue; } } if(rank <= ENTRYMAX){ t1 = t1->tt_next = newttentry(); rank++; } if(rank > ENTRYMAX){ t1->points = 0; break; } } if(flg) { /* rewrite record file */ (void) fclose(rfile); if(!(rfile = fopen(recfile,"w"))){ HUP puts("Cannot write record file\n"); goto unlock; } if(!done_stopprint) if(rank0 > 0){ if(rank0 <= 10) puts("You made the top ten list!\n"); else printf("You reached the %d%s place on the top %d list.\n\n", rank0, ordin(rank0), ENTRYMAX); } } if(rank0 == 0) rank0 = rank1; if(rank0 <= 0) rank0 = rank; if(!done_stopprint) outheader(); t1 = tt_head; for(rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { if(flg) fprintf(rfile,"%6s %d %d %d %d %d %ld %c%c %s,%s\n", t1->date, t1->uid, t1->level, t1->maxlvl, t1->hp, t1->maxhp, t1->points, t1->plchar, t1->sex, t1->name, t1->death); if(done_stopprint) continue; if(rank > flags.end_top && (rank < rank0-flags.end_around || rank > rank0+flags.end_around) && (!flags.end_own || #ifdef PERS_IS_UID t1->uid != t0->uid )) #else strncmp(t1->name, t0->name, NAMSZ))) #endif PERS_IS_UID continue; if(rank == rank0-flags.end_around && rank0 > flags.end_top+flags.end_around+1 && !flags.end_own) (void) putchar('\n'); if(rank != rank0) (void) outentry(rank, t1, 0); else if(!rank1) (void) outentry(rank, t1, 1); else { int t0lth = outentry(0, t0, -1); int t1lth = outentry(rank, t1, t0lth); if(t1lth > t0lth) t0lth = t1lth; (void) outentry(0, t0, t0lth); } } if(rank0 >= rank) if(!done_stopprint) (void) outentry(0, t0, 1); (void) fclose(rfile); unlock: (void) unlink(reclock); } outheader() { char linebuf[BUFSZ]; -register char *bp; +char *bp; (void) strcpy(linebuf, "Number Points Name"); bp = eos(linebuf); while(bp < linebuf + COLNO - 9) *bp++ = ' '; (void) strcpy(bp, "Hp [max]"); puts(linebuf); } /* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */ int -outentry(rank,t1,so) register struct toptenentry *t1; { +outentry(rank,t1,so) struct toptenentry *t1; { boolean quit = FALSE, killed = FALSE, starv = FALSE; char linebuf[BUFSZ]; linebuf[0] = 0; if(rank) Sprintf(eos(linebuf), "%3d", rank); else Sprintf(eos(linebuf), " "); Sprintf(eos(linebuf), " %6ld %8s", t1->points, t1->name); if(t1->plchar == 'X') Sprintf(eos(linebuf), " "); else Sprintf(eos(linebuf), "-%c ", t1->plchar); if(!strncmp("escaped", t1->death, 7)) { if(!strcmp(" (with amulet)", t1->death+7)) Sprintf(eos(linebuf), "escaped the dungeon with amulet"); else Sprintf(eos(linebuf), "escaped the dungeon [max level %d]", t1->maxlvl); } else { if(!strncmp(t1->death,"quit",4)) { quit = TRUE; if(t1->maxhp < 3*t1->hp && t1->maxlvl < 4) Sprintf(eos(linebuf), "cravenly gave up"); else Sprintf(eos(linebuf), "quit"); } else if(!strcmp(t1->death,"choked")) Sprintf(eos(linebuf), "choked on %s food", (t1->sex == 'F') ? "her" : "his"); else if(!strncmp(t1->death,"starv",5)) Sprintf(eos(linebuf), "starved to death"), starv = TRUE; else Sprintf(eos(linebuf), "was killed"), killed = TRUE; Sprintf(eos(linebuf), " on%s level %d", (killed || starv) ? "" : " dungeon", t1->level); if(t1->maxlvl != t1->level) Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); if(quit && t1->death[4]) Sprintf(eos(linebuf), t1->death + 4); } if(killed) Sprintf(eos(linebuf), " by %s%s", (!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4)) ? "" : index(vowels,*t1->death) ? "an " : "a ", t1->death); Sprintf(eos(linebuf), "."); if(t1->maxhp) { - register char *bp = eos(linebuf); + char *bp = eos(linebuf); char hpbuf[10]; int hppos; Sprintf(hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-"); hppos = COLNO - 7 - strlen(hpbuf); if(bp <= linebuf + hppos) { while(bp < linebuf + hppos) *bp++ = ' '; (void) strcpy(bp, hpbuf); Sprintf(eos(bp), " [%d]", t1->maxhp); } } if(so == 0) puts(linebuf); else if(so > 0) { - register char *bp = eos(linebuf); + char *bp = eos(linebuf); if(so >= COLNO) so = COLNO-1; while(bp < linebuf + so) *bp++ = ' '; *bp = 0; standoutbeg(); fputs(linebuf,stdout); standoutend(); (void) putchar('\n'); } return(strlen(linebuf)); } char * itoa(a) int a; { static char buf[12]; Sprintf(buf,"%d",a); return(buf); } char * ordin(n) int n; { -register int d = n%10; +int d = n%10; return((d==0 || d>3 || n/10==1) ? "th" : (d==1) ? "st" : (d==2) ? "nd" : "rd"); } clearlocks(){ -register x; +x; (void) signal(SIGHUP,SIG_IGN); for(x = maxdlevel; x >= 0; x--) { glo(x); (void) unlink(lock); /* not all levels need be present */ } } #ifdef NOSAVEONHANGUP hangup() { (void) signal(SIGINT, SIG_IGN); clearlocks(); exit(1); } #endif NOSAVEONHANGUP char * eos(s) -register char *s; +char *s; { while(*s) s++; return(s); } /* it is the callers responsibility to check that there is room for c */ -charcat(s,c) register char *s, c; { +charcat(s,c) char *s, c; { while(*s) s++; *s++ = c; *s = 0; } /* * Called with args from main if argc >= 0. In this case, list scores as * requested. Otherwise, find scores for the current player (and list them * if argc == -1). */ prscore(argc,argv) int argc; char **argv; { extern char *hname; char **players; int playerct; int rank; - register struct toptenentry *t1, *t2; + struct toptenentry *t1, *t2; char *recfile = RECORD; FILE *rfile; - register flg = 0; - register int i; + flg = 0; + int i; #ifdef nonsense long total_score = 0L; char totchars[10]; int totcharct = 0; #endif nonsense int outflg = (argc >= -1); #ifdef PERS_IS_UID int uid = -1; #else char *player0; #endif PERS_IS_UID if(!(rfile = fopen(recfile,"r"))){ puts("Cannot open record file!"); return; } if(argc > 1 && !strncmp(argv[1], "-s", 2)){ if(!argv[1][2]){ argc--; argv++; } else if(!argv[1][3] && index("CFKSTWX", argv[1][2])) { argv[1]++; argv[1][0] = '-'; } else argv[1] += 2; } if(argc <= 1){ #ifdef PERS_IS_UID uid = getuid(); playerct = 0; #else player0 = plname; if(!*player0) player0 = "hackplayer"; playerct = 1; players = &player0; #endif PERS_IS_UID } else { playerct = --argc; players = ++argv; } if(outflg) putchar('\n'); t1 = tt_head = newttentry(); for(rank = 1; ; rank++) { if(fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", t1->date, &t1->uid, &t1->level, &t1->maxlvl, &t1->hp, &t1->maxhp, &t1->points, &t1->plchar, &t1->sex, t1->name, t1->death) != 11) t1->points = 0; if(t1->points == 0) break; #ifdef PERS_IS_UID if(!playerct && t1->uid == uid) flg++; else #endif PERS_IS_UID for(i = 0; i < playerct; i++){ if(strcmp(players[i], "all") == 0 || strncmp(t1->name, players[i], NAMSZ) == 0 || (players[i][0] == '-' && players[i][1] == t1->plchar && players[i][2] == 0) || (digit(players[i][0]) && rank <= atoi(players[i]))) flg++; } t1 = t1->tt_next = newttentry(); } (void) fclose(rfile); if(!flg) { if(outflg) { printf("Cannot find any entries for "); if(playerct < 1) printf("you.\n"); else { if(playerct > 1) printf("any of "); for(i=0; ipoints != 0; rank++, t1 = t2) { t2 = t1->tt_next; #ifdef PERS_IS_UID if(!playerct && t1->uid == uid) goto outwithit; else #endif PERS_IS_UID for(i = 0; i < playerct; i++){ if(strcmp(players[i], "all") == 0 || strncmp(t1->name, players[i], NAMSZ) == 0 || (players[i][0] == '-' && players[i][1] == t1->plchar && players[i][2] == 0) || (digit(players[i][0]) && rank <= atoi(players[i]))){ outwithit: if(outflg) (void) outentry(rank, t1, 0); #ifdef nonsense total_score += t1->points; if(totcharct < sizeof(totchars)-1) totchars[totcharct++] = t1->plchar; #endif nonsense break; } } free((char *) t1); } #ifdef nonsense totchars[totcharct] = 0; /* We would like to determine whether he is experienced. However, the information collected here only tells about the scores/roles that got into the topten (top 100?). We should maintain a .hacklog or something in his home directory. */ flags.beginner = (total_score < 6000); for(i=0; i<6; i++) if(!index(totchars, "CFKSTWX"[i])) { flags.beginner = 1; if(!pl_character[0]) pl_character[0] = "CFKSTWX"[i]; break; } #endif nonsense } diff --git a/games/hack/hack.engrave.c b/games/hack/hack.engrave.c index d3bf27f6cbc0..bc9ed849dae9 100644 --- a/games/hack/hack.engrave.c +++ b/games/hack/hack.engrave.c @@ -1,307 +1,307 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.engrave.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" extern char *nomovemsg; extern char nul[]; extern struct obj zeroobj; struct engr { struct engr *nxt_engr; char *engr_txt; xchar engr_x, engr_y; unsigned engr_lth; /* for save & restore; not length of text */ long engr_time; /* moment engraving was (will be) finished */ xchar engr_type; #define DUST 1 #define ENGRAVE 2 #define BURN 3 } *head_engr; struct engr * -engr_at(x,y) register xchar x,y; { -register struct engr *ep = head_engr; +engr_at(x,y) xchar x,y; { +struct engr *ep = head_engr; while(ep) { if(x == ep->engr_x && y == ep->engr_y) return(ep); ep = ep->nxt_engr; } return((struct engr *) 0); } -sengr_at(s,x,y) register char *s; register xchar x,y; { -register struct engr *ep = engr_at(x,y); -register char *t; -register int n; +sengr_at(s,x,y) char *s; xchar x,y; { +struct engr *ep = engr_at(x,y); +char *t; +int n; if(ep && ep->engr_time <= moves) { t = ep->engr_txt; /* if(!strcmp(s,t)) return(1); */ n = strlen(s); while(*t) { if(!strncmp(s,t,n)) return(1); t++; } } return(0); } u_wipe_engr(cnt) -register int cnt; +int cnt; { if(!u.uswallow && !Levitation) wipe_engr_at(u.ux, u.uy, cnt); } -wipe_engr_at(x,y,cnt) register xchar x,y,cnt; { -register struct engr *ep = engr_at(x,y); -register int lth,pos; +wipe_engr_at(x,y,cnt) xchar x,y,cnt; { +struct engr *ep = engr_at(x,y); +int lth,pos; char ch; if(ep){ if((ep->engr_type != DUST) || Levitation) { cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1; } lth = strlen(ep->engr_txt); if(lth && cnt > 0 ) { while(cnt--) { pos = rn2(lth); if((ch = ep->engr_txt[pos]) == ' ') continue; ep->engr_txt[pos] = (ch != '?') ? '?' : ' '; } } while(lth && ep->engr_txt[lth-1] == ' ') ep->engr_txt[--lth] = 0; while(ep->engr_txt[0] == ' ') ep->engr_txt++; if(!ep->engr_txt[0]) del_engr(ep); } } -read_engr_at(x,y) register int x,y; { -register struct engr *ep = engr_at(x,y); +read_engr_at(x,y) int x,y; { +struct engr *ep = engr_at(x,y); if(ep && ep->engr_txt[0]) { switch(ep->engr_type) { case DUST: pline("Something is written here in the dust."); break; case ENGRAVE: pline("Something is engraved here on the floor."); break; case BURN: pline("Some text has been burned here in the floor."); break; default: impossible("Something is written in a very strange way."); } pline("You read: \"%s\".", ep->engr_txt); } } make_engr_at(x,y,s) -register int x,y; -register char *s; +int x,y; +char *s; { - register struct engr *ep; + struct engr *ep; if(ep = engr_at(x,y)) del_engr(ep); ep = (struct engr *) alloc((unsigned)(sizeof(struct engr) + strlen(s) + 1)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = x; ep->engr_y = y; ep->engr_txt = (char *)(ep + 1); (void) strcpy(ep->engr_txt, s); ep->engr_time = 0; ep->engr_type = DUST; ep->engr_lth = strlen(s) + 1; } doengrave(){ -register int len; -register char *sp; -register struct engr *ep, *oep = engr_at(u.ux,u.uy); +int len; +char *sp; +struct engr *ep, *oep = engr_at(u.ux,u.uy); char buf[BUFSZ]; xchar type; int spct; /* number of leading spaces */ -register struct obj *otmp; +struct obj *otmp; multi = 0; if(u.uswallow) { pline("You're joking. Hahaha!"); /* riv05!a3 */ return(0); } /* one may write with finger, weapon or wand */ otmp = getobj("#-)/", "write with"); if(!otmp) return(0); if(otmp == &zeroobj) otmp = 0; if(otmp && otmp->otyp == WAN_FIRE && otmp->spe) { type = BURN; otmp->spe--; } else { /* first wield otmp */ if(otmp != uwep) { if(uwep && uwep->cursed) { /* Andreas Bormann */ pline("Since your weapon is welded to your hand,"); pline("you use the %s.", aobjnam(uwep, (char *) 0)); otmp = uwep; } else { if(!otmp) pline("You are now empty-handed."); else if(otmp->cursed) pline("The %s %s to your hand!", aobjnam(otmp, "weld"), (otmp->quan == 1) ? "itself" : "themselves"); else pline("You now wield %s.", doname(otmp)); setuwep(otmp); } } if(!otmp) type = DUST; else if(otmp->otyp == DAGGER || otmp->otyp == TWO_HANDED_SWORD || otmp->otyp == CRYSKNIFE || otmp->otyp == LONG_SWORD || otmp->otyp == AXE) { type = ENGRAVE; if((int)otmp->spe <= -3) { type = DUST; pline("Your %s too dull for engraving.", aobjnam(otmp, "are")); if(oep && oep->engr_type != DUST) return(1); } } else type = DUST; } if(Levitation && type != BURN){ /* riv05!a3 */ pline("You can't reach the floor!"); return(1); } if(oep && oep->engr_type == DUST){ pline("You wipe out the message that was written here."); del_engr(oep); oep = 0; } if(type == DUST && oep){ pline("You cannot wipe out the message that is %s in the rock.", (oep->engr_type == BURN) ? "burned" : "engraved"); return(1); } pline("What do you want to %s on the floor here? ", (type == ENGRAVE) ? "engrave" : (type == BURN) ? "burn" : "write"); getlin(buf); clrlin(); spct = 0; sp = buf; while(*sp == ' ') spct++, sp++; len = strlen(sp); if(!len || *buf == '\033') { if(type == BURN) otmp->spe++; return(0); } switch(type) { case DUST: case BURN: if(len > 15) { multi = -(len/10); nomovemsg = "You finished writing."; } break; case ENGRAVE: /* here otmp != 0 */ { int len2 = (otmp->spe + 3) * 2 + 1; pline("Your %s dull.", aobjnam(otmp, "get")); if(len2 < len) { len = len2; sp[len] = 0; otmp->spe = -3; nomovemsg = "You cannot engrave more."; } else { otmp->spe -= len/2; nomovemsg = "You finished engraving."; } multi = -len; } break; } if(oep) len += strlen(oep->engr_txt) + spct; ep = (struct engr *) alloc((unsigned)(sizeof(struct engr) + len + 1)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = u.ux; ep->engr_y = u.uy; sp = (char *)(ep + 1); /* (char *)ep + sizeof(struct engr) */ ep->engr_txt = sp; if(oep) { (void) strcpy(sp, oep->engr_txt); (void) strcat(sp, buf); del_engr(oep); } else (void) strcpy(sp, buf); ep->engr_lth = len+1; ep->engr_type = type; ep->engr_time = moves-multi; /* kludge to protect pline against excessively long texts */ if(len > BUFSZ-20) sp[BUFSZ-20] = 0; return(1); } save_engravings(fd) int fd; { -register struct engr *ep = head_engr; +struct engr *ep = head_engr; while(ep) { if(!ep->engr_lth || !ep->engr_txt[0]){ ep = ep->nxt_engr; continue; } bwrite(fd, (char *) & (ep->engr_lth), sizeof(ep->engr_lth)); bwrite(fd, (char *) ep, sizeof(struct engr) + ep->engr_lth); ep = ep->nxt_engr; } bwrite(fd, (char *) nul, sizeof(unsigned)); head_engr = 0; } rest_engravings(fd) int fd; { -register struct engr *ep; +struct engr *ep; unsigned lth; head_engr = 0; while(1) { mread(fd, (char *) <h, sizeof(unsigned)); if(lth == 0) return; ep = (struct engr *) alloc(sizeof(struct engr) + lth); mread(fd, (char *) ep, sizeof(struct engr) + lth); ep->nxt_engr = head_engr; ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */ head_engr = ep; } } -del_engr(ep) register struct engr *ep; { -register struct engr *ept; +del_engr(ep) struct engr *ep; { +struct engr *ept; if(ep == head_engr) head_engr = ep->nxt_engr; else { for(ept = head_engr; ept; ept = ept->nxt_engr) { if(ept->nxt_engr == ep) { ept->nxt_engr = ep->nxt_engr; goto fnd; } } impossible("Error in del_engr?"); return; fnd: ; } free((char *) ep); } diff --git a/games/hack/hack.fight.c b/games/hack/hack.fight.c index f8e2ea98e786..2a3947447a4a 100644 --- a/games/hack/hack.fight.c +++ b/games/hack/hack.fight.c @@ -1,359 +1,359 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.fight.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" extern struct permonst li_dog, dog, la_dog; extern char *exclam(), *xname(); extern struct obj *mkobj_at(); static boolean far_noise; static long noisetime; /* hitmm returns 0 (miss), 1 (hit), or 2 (kill) */ -hitmm(magr,mdef) register struct monst *magr,*mdef; { -register struct permonst *pa = magr->data, *pd = mdef->data; +hitmm(magr,mdef) struct monst *magr,*mdef; { +struct permonst *pa = magr->data, *pd = mdef->data; int hit; schar tmp; boolean vis; if(index("Eauy", pa->mlet)) return(0); if(magr->mfroz) return(0); /* riv05!a3 */ tmp = pd->ac + pa->mlevel; if(mdef->mconf || mdef->mfroz || mdef->msleep){ tmp += 4; if(mdef->msleep) mdef->msleep = 0; } hit = (tmp > rnd(20)); if(hit) mdef->msleep = 0; vis = (cansee(magr->mx,magr->my) && cansee(mdef->mx,mdef->my)); if(vis){ char buf[BUFSZ]; if(mdef->mimic) seemimic(mdef); if(magr->mimic) seemimic(magr); (void) sprintf(buf,"%s %s", Monnam(magr), hit ? "hits" : "misses"); pline("%s %s.", buf, monnam(mdef)); } else { boolean far = (dist(magr->mx, magr->my) > 15); if(far != far_noise || moves-noisetime > 10) { far_noise = far; noisetime = moves; pline("You hear some noises%s.", far ? " in the distance" : ""); } } if(hit){ if(magr->data->mlet == 'c' && !magr->cham) { magr->mhpmax += 3; if(vis) pline("%s is turned to stone!", Monnam(mdef)); else if(mdef->mtame) pline("You have a peculiarly sad feeling for a moment, then it passes."); monstone(mdef); hit = 2; } else if((mdef->mhp -= d(pa->damn,pa->damd)) < 1) { magr->mhpmax += 1 + rn2(pd->mlevel+1); if(magr->mtame && magr->mhpmax > 8*pa->mlevel){ if(pa == &li_dog) magr->data = pa = &dog; else if(pa == &dog) magr->data = pa = &la_dog; } if(vis) pline("%s is killed!", Monnam(mdef)); else if(mdef->mtame) pline("You have a sad feeling for a moment, then it passes."); mondied(mdef); hit = 2; } } return(hit); } /* drop (perhaps) a cadaver and remove monster */ -mondied(mdef) register struct monst *mdef; { -register struct permonst *pd = mdef->data; +mondied(mdef) struct monst *mdef; { +struct permonst *pd = mdef->data; if(letter(pd->mlet) && rn2(3)){ (void) mkobj_at(pd->mlet,mdef->mx,mdef->my); if(cansee(mdef->mx,mdef->my)){ unpmon(mdef); atl(mdef->mx,mdef->my,fobj->olet); } stackobj(fobj); } mondead(mdef); } /* drop a rock and remove monster */ -monstone(mdef) register struct monst *mdef; { +monstone(mdef) struct monst *mdef; { extern char mlarge[]; if(index(mlarge, mdef->data->mlet)) mksobj_at(ENORMOUS_ROCK, mdef->mx, mdef->my); else mksobj_at(ROCK, mdef->mx, mdef->my); if(cansee(mdef->mx, mdef->my)){ unpmon(mdef); atl(mdef->mx,mdef->my,fobj->olet); } mondead(mdef); } -fightm(mtmp) register struct monst *mtmp; { -register struct monst *mon; +fightm(mtmp) struct monst *mtmp; { +struct monst *mon; for(mon = fmon; mon; mon = mon->nmon) if(mon != mtmp) { if(DIST(mon->mx,mon->my,mtmp->mx,mtmp->my) < 3) if(rn2(4)) return(hitmm(mtmp,mon)); } return(-1); } /* u is hit by sth, but not a monster */ thitu(tlev,dam,name) -register tlev,dam; -register char *name; +tlev,dam; +char *name; { char buf[BUFSZ]; setan(name,buf); if(u.uac + tlev <= rnd(20)) { if(Blind) pline("It misses."); else pline("You are almost hit by %s!", buf); return(0); } else { if(Blind) pline("You are hit!"); else pline("You are hit by %s!", buf); losehp(dam,name); return(1); } } char mlarge[] = "bCDdegIlmnoPSsTUwY',&"; boolean hmon(mon,obj,thrown) /* return TRUE if mon still alive */ -register struct monst *mon; -register struct obj *obj; -register thrown; +struct monst *mon; +struct obj *obj; +thrown; { - register tmp; + tmp; boolean hittxt = FALSE; if(!obj){ tmp = rnd(2); /* attack with bare hands */ if(mon->data->mlet == 'c' && !uarmg){ pline("You hit the cockatrice with your bare hands."); pline("You turn to stone ..."); done_in_by(mon); } } else if(obj->olet == WEAPON_SYM || obj->otyp == PICK_AXE) { if(obj == uwep && (obj->otyp > SPEAR || obj->otyp < BOOMERANG)) tmp = rnd(2); else { if(index(mlarge, mon->data->mlet)) { tmp = rnd(objects[obj->otyp].wldam); if(obj->otyp == TWO_HANDED_SWORD) tmp += d(2,6); else if(obj->otyp == FLAIL) tmp += rnd(4); } else { tmp = rnd(objects[obj->otyp].wsdam); } tmp += obj->spe; if(!thrown && obj == uwep && obj->otyp == BOOMERANG && !rn2(3)){ pline("As you hit %s, the boomerang breaks into splinters.", monnam(mon)); freeinv(obj); setworn((struct obj *) 0, obj->owornmask); obfree(obj, (struct obj *) 0); tmp++; } } if(mon->data->mlet == 'O' && obj->otyp == TWO_HANDED_SWORD && !strcmp(ONAME(obj), "Orcrist")) tmp += rnd(10); } else switch(obj->otyp) { case HEAVY_IRON_BALL: tmp = rnd(25); break; case EXPENSIVE_CAMERA: pline("You succeed in destroying your camera. Congratulations!"); freeinv(obj); if(obj->owornmask) setworn((struct obj *) 0, obj->owornmask); obfree(obj, (struct obj *) 0); return(TRUE); case DEAD_COCKATRICE: pline("You hit %s with the cockatrice corpse.", monnam(mon)); if(mon->data->mlet == 'c') { tmp = 1; hittxt = TRUE; break; } pline("%s is turned to stone!", Monnam(mon)); killed(mon); return(FALSE); case CLOVE_OF_GARLIC: /* no effect against demons */ if(index(UNDEAD, mon->data->mlet)) mon->mflee = 1; tmp = 1; break; default: /* non-weapons can damage because of their weight */ /* (but not too much) */ tmp = obj->owt/10; if(tmp < 1) tmp = 1; else tmp = rnd(tmp); if(tmp > 6) tmp = 6; } /****** NOTE: perhaps obj is undefined!! (if !thrown && BOOMERANG) */ tmp += u.udaminc + dbon(); if(u.uswallow) { if((tmp -= u.uswldtim) <= 0) { pline("Your arms are no longer able to hit."); return(TRUE); } } if(tmp < 1) tmp = 1; mon->mhp -= tmp; if(mon->mhp < 1) { killed(mon); return(FALSE); } if(mon->mtame && (!mon->mflee || mon->mfleetim)) { mon->mflee = 1; /* Rick Richardson */ mon->mfleetim += 10*rnd(tmp); } if(!hittxt) { if(thrown) /* this assumes that we cannot throw plural things */ hit( xname(obj) /* or: objects[obj->otyp].oc_name */, mon, exclam(tmp) ); else if(Blind) pline("You hit it."); else pline("You hit %s%s", monnam(mon), exclam(tmp)); } if(u.umconf && !thrown) { if(!Blind) { pline("Your hands stop glowing blue."); if(!mon->mfroz && !mon->msleep) pline("%s appears confused.",Monnam(mon)); } mon->mconf = 1; u.umconf = 0; } return(TRUE); /* mon still alive */ } /* try to attack; return FALSE if monster evaded */ /* u.dx and u.dy must be set */ attack(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { schar tmp; boolean malive = TRUE; - register struct permonst *mdat; + struct permonst *mdat; mdat = mtmp->data; u_wipe_engr(3); /* andrew@orca: prevent unlimited pick-axe attacks */ if(mdat->mlet == 'L' && !mtmp->mfroz && !mtmp->msleep && !mtmp->mconf && mtmp->mcansee && !rn2(7) && (m_move(mtmp, 0) == 2 /* he died */ || /* he moved: */ mtmp->mx != u.ux+u.dx || mtmp->my != u.uy+u.dy)) return(FALSE); if(mtmp->mimic){ if(!u.ustuck && !mtmp->mflee) u.ustuck = mtmp; switch(levl[u.ux+u.dx][u.uy+u.dy].scrsym){ case '+': pline("The door actually was a Mimic."); break; case '$': pline("The chest was a Mimic!"); break; default: pline("Wait! That's a Mimic!"); } wakeup(mtmp); /* clears mtmp->mimic */ return(TRUE); } wakeup(mtmp); if(mtmp->mhide && mtmp->mundetected){ - register struct obj *obj; + struct obj *obj; mtmp->mundetected = 0; if((obj = o_at(mtmp->mx,mtmp->my)) && !Blind) pline("Wait! There's a %s hiding under %s!", mdat->mname, doname(obj)); return(TRUE); } tmp = u.uluck + u.ulevel + mdat->ac + abon(); if(uwep) { if(uwep->olet == WEAPON_SYM || uwep->otyp == PICK_AXE) tmp += uwep->spe; if(uwep->otyp == TWO_HANDED_SWORD) tmp -= 1; else if(uwep->otyp == DAGGER) tmp += 2; else if(uwep->otyp == CRYSKNIFE) tmp += 3; else if(uwep->otyp == SPEAR && index("XDne", mdat->mlet)) tmp += 2; } if(mtmp->msleep) { mtmp->msleep = 0; tmp += 2; } if(mtmp->mfroz) { tmp += 4; if(!rn2(10)) mtmp->mfroz = 0; } if(mtmp->mflee) tmp += 2; if(u.utrap) tmp -= 3; /* with a lot of luggage, your agility diminishes */ tmp -= (inv_weight() + 40)/20; if(tmp <= rnd(20) && !u.uswallow){ if(Blind) pline("You miss it."); else pline("You miss %s.",monnam(mtmp)); } else { /* we hit the monster; be careful: it might die! */ if((malive = hmon(mtmp,uwep,0)) == TRUE) { /* monster still alive */ if(!rn2(25) && mtmp->mhp < mtmp->mhpmax/2) { mtmp->mflee = 1; if(!rn2(3)) mtmp->mfleetim = rnd(100); if(u.ustuck == mtmp && !u.uswallow) u.ustuck = 0; } #ifndef NOWORM if(mtmp->wormno) cutworm(mtmp, u.ux+u.dx, u.uy+u.dy, uwep ? uwep->otyp : 0); #endif NOWORM } if(mdat->mlet == 'a') { if(rn2(2)) { pline("You are splashed by the blob's acid!"); losehp_m(rnd(6), mtmp); if(!rn2(30)) corrode_armor(); } if(!rn2(6)) corrode_weapon(); } } if(malive && mdat->mlet == 'E' && canseemon(mtmp) && !mtmp->mcan && rn2(3)) { if(mtmp->mcansee) { pline("You are frozen by the floating eye's gaze!"); nomul((u.ulevel > 6 || rn2(4)) ? rn1(20,-21) : -200); } else { pline("The blinded floating eye cannot defend itself."); if(!rn2(500)) if((int)u.uluck > LUCKMIN) u.uluck--; } } return(TRUE); } diff --git a/games/hack/hack.invent.c b/games/hack/hack.invent.c index d5af8430b727..819bcff0cb65 100644 --- a/games/hack/hack.invent.c +++ b/games/hack/hack.invent.c @@ -1,864 +1,864 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.invent.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include extern struct obj *splitobj(); extern struct obj zeroobj; extern char morc; extern char quitchars[]; static char *xprname(); #ifndef NOWORM #include "def.wseg.h" extern struct wseg *wsegs[32]; #endif NOWORM #define NOINVSYM '#' static int lastinvnr = 51; /* 0 ... 51 */ static assigninvlet(otmp) -register struct obj *otmp; +struct obj *otmp; { boolean inuse[52]; - register int i; - register struct obj *obj; + int i; + struct obj *obj; for(i = 0; i < 52; i++) inuse[i] = FALSE; for(obj = invent; obj; obj = obj->nobj) if(obj != otmp) { i = obj->invlet; if('a' <= i && i <= 'z') inuse[i - 'a'] = TRUE; else if('A' <= i && i <= 'Z') inuse[i - 'A' + 26] = TRUE; if(i == otmp->invlet) otmp->invlet = 0; } if((i = otmp->invlet) && (('a' <= i && i <= 'z') || ('A' <= i && i <= 'Z'))) return; for(i = lastinvnr+1; i != lastinvnr; i++) { if(i == 52) { i = -1; continue; } if(!inuse[i]) break; } otmp->invlet = (inuse[i] ? NOINVSYM : (i < 26) ? ('a'+i) : ('A'+i-26)); lastinvnr = i; } struct obj * addinv(obj) -register struct obj *obj; +struct obj *obj; { - register struct obj *otmp; + struct obj *otmp; /* merge or attach to end of chain */ if(!invent) { invent = obj; otmp = 0; } else for(otmp = invent; /* otmp */; otmp = otmp->nobj) { if(merged(otmp, obj, 0)) return(otmp); if(!otmp->nobj) { otmp->nobj = obj; break; } } obj->nobj = 0; if(flags.invlet_constant) { assigninvlet(obj); /* * The ordering of the chain is nowhere significant * so in case you prefer some other order than the * historical one, change the code below. */ if(otmp) { /* find proper place in chain */ otmp->nobj = 0; if((invent->invlet ^ 040) > (obj->invlet ^ 040)) { obj->nobj = invent; invent = obj; } else for(otmp = invent; ; otmp = otmp->nobj) { if(!otmp->nobj || (otmp->nobj->invlet ^ 040) > (obj->invlet ^ 040)){ obj->nobj = otmp->nobj; otmp->nobj = obj; break; } } } } return(obj); } useup(obj) -register struct obj *obj; +struct obj *obj; { if(obj->quan > 1){ obj->quan--; obj->owt = weight(obj); } else { setnotworn(obj); freeinv(obj); obfree(obj, (struct obj *) 0); } } freeinv(obj) -register struct obj *obj; +struct obj *obj; { - register struct obj *otmp; + struct obj *otmp; if(obj == invent) invent = invent->nobj; else { for(otmp = invent; otmp->nobj != obj; otmp = otmp->nobj) if(!otmp->nobj) panic("freeinv"); otmp->nobj = obj->nobj; } } /* destroy object in fobj chain (if unpaid, it remains on the bill) */ -delobj(obj) register struct obj *obj; { +delobj(obj) struct obj *obj; { freeobj(obj); unpobj(obj); obfree(obj, (struct obj *) 0); } /* unlink obj from chain starting with fobj */ -freeobj(obj) register struct obj *obj; { - register struct obj *otmp; +freeobj(obj) struct obj *obj; { + struct obj *otmp; if(obj == fobj) fobj = fobj->nobj; else { for(otmp = fobj; otmp->nobj != obj; otmp = otmp->nobj) if(!otmp) panic("error in freeobj"); otmp->nobj = obj->nobj; } } /* Note: freegold throws away its argument! */ -freegold(gold) register struct gold *gold; { - register struct gold *gtmp; +freegold(gold) struct gold *gold; { + struct gold *gtmp; if(gold == fgold) fgold = gold->ngold; else { for(gtmp = fgold; gtmp->ngold != gold; gtmp = gtmp->ngold) if(!gtmp) panic("error in freegold"); gtmp->ngold = gold->ngold; } free((char *) gold); } deltrap(trap) -register struct trap *trap; +struct trap *trap; { - register struct trap *ttmp; + struct trap *ttmp; if(trap == ftrap) ftrap = ftrap->ntrap; else { for(ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) ; ttmp->ntrap = trap->ntrap; } free((char *) trap); } struct wseg *m_atseg; struct monst * m_at(x,y) -register x,y; +x,y; { - register struct monst *mtmp; + struct monst *mtmp; #ifndef NOWORM - register struct wseg *wtmp; + struct wseg *wtmp; #endif NOWORM m_atseg = 0; for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ if(mtmp->mx == x && mtmp->my == y) return(mtmp); #ifndef NOWORM if(mtmp->wormno){ for(wtmp = wsegs[mtmp->wormno]; wtmp; wtmp = wtmp->nseg) if(wtmp->wx == x && wtmp->wy == y){ m_atseg = wtmp; return(mtmp); } } #endif NOWORM } return(0); } struct obj * o_at(x,y) -register x,y; +x,y; { - register struct obj *otmp; + struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp->ox == x && otmp->oy == y) return(otmp); return(0); } struct obj * sobj_at(n,x,y) -register n,x,y; +n,x,y; { - register struct obj *otmp; + struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp->ox == x && otmp->oy == y && otmp->otyp == n) return(otmp); return(0); } -carried(obj) register struct obj *obj; { -register struct obj *otmp; +carried(obj) struct obj *obj; { +struct obj *otmp; for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp == obj) return(1); return(0); } carrying(type) -register int type; +int type; { - register struct obj *otmp; + struct obj *otmp; for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp->otyp == type) return(TRUE); return(FALSE); } struct obj * -o_on(id, objchn) unsigned int id; register struct obj *objchn; { +o_on(id, objchn) unsigned int id; struct obj *objchn; { while(objchn) { if(objchn->o_id == id) return(objchn); objchn = objchn->nobj; } return((struct obj *) 0); } struct trap * t_at(x,y) -register x,y; +x,y; { - register struct trap *trap = ftrap; + struct trap *trap = ftrap; while(trap) { if(trap->tx == x && trap->ty == y) return(trap); trap = trap->ntrap; } return(0); } struct gold * g_at(x,y) -register x,y; +x,y; { - register struct gold *gold = fgold; + struct gold *gold = fgold; while(gold) { if(gold->gx == x && gold->gy == y) return(gold); gold = gold->ngold; } return(0); } /* make dummy object structure containing gold - for temporary use only */ struct obj * mkgoldobj(q) -register long q; +long q; { - register struct obj *otmp; + struct obj *otmp; otmp = newobj(0); /* should set o_id etc. but otmp will be freed soon */ otmp->olet = '$'; u.ugold -= q; OGOLD(otmp) = q; flags.botl = 1; return(otmp); } /* * getobj returns: * struct obj *xxx: object to do something with. * (struct obj *) 0 error return: no object. * &zeroobj explicitly no object (as in w-). */ struct obj * getobj(let,word) -register char *let,*word; +char *let,*word; { - register struct obj *otmp; - register char ilet,ilet1,ilet2; + struct obj *otmp; + char ilet,ilet1,ilet2; char buf[BUFSZ]; char lets[BUFSZ]; - register int foo = 0, foo2; - register char *bp = buf; + int foo = 0, foo2; + char *bp = buf; xchar allowcnt = 0; /* 0, 1 or 2 */ boolean allowgold = FALSE; boolean allowall = FALSE; boolean allownone = FALSE; xchar foox = 0; long cnt; if(*let == '0') let++, allowcnt = 1; if(*let == '$') let++, allowgold = TRUE; if(*let == '#') let++, allowall = TRUE; if(*let == '-') let++, allownone = TRUE; if(allownone) *bp++ = '-'; if(allowgold) *bp++ = '$'; if(bp > buf && bp[-1] == '-') *bp++ = ' '; ilet = 'a'; for(otmp = invent; otmp; otmp = otmp->nobj){ if(!*let || index(let, otmp->olet)) { bp[foo++] = flags.invlet_constant ? otmp->invlet : ilet; /* ugly check: remove inappropriate things */ if((!strcmp(word, "take off") && !(otmp->owornmask & (W_ARMOR - W_ARM2))) || (!strcmp(word, "wear") && (otmp->owornmask & (W_ARMOR | W_RING))) || (!strcmp(word, "wield") && (otmp->owornmask & W_WEP))) { foo--; foox++; } } if(ilet == 'z') ilet = 'A'; else ilet++; } bp[foo] = 0; if(foo == 0 && bp > buf && bp[-1] == ' ') *--bp = 0; (void) strcpy(lets, bp); /* necessary since we destroy buf */ if(foo > 5) { /* compactify string */ foo = foo2 = 1; ilet2 = bp[0]; ilet1 = bp[1]; while(ilet = bp[++foo2] = bp[++foo]){ if(ilet == ilet1+1){ if(ilet1 == ilet2+1) bp[foo2 - 1] = ilet1 = '-'; else if(ilet2 == '-') { bp[--foo2] = ++ilet1; continue; } } ilet2 = ilet1; ilet1 = ilet; } } if(!foo && !allowall && !allowgold && !allownone) { pline("You don't have anything %sto %s.", foox ? "else " : "", word); return(0); } for(;;) { if(!buf[0]) pline("What do you want to %s [*]? ", word); else pline("What do you want to %s [%s or ?*]? ", word, buf); cnt = 0; ilet = readchar(); while(digit(ilet) && allowcnt) { if (cnt < 100000000) cnt = 10*cnt + (ilet - '0'); else cnt = 999999999; allowcnt = 2; /* signal presence of cnt */ ilet = readchar(); } if(digit(ilet)) { pline("No count allowed with this command."); continue; } if(index(quitchars,ilet)) return((struct obj *)0); if(ilet == '-') { return(allownone ? &zeroobj : (struct obj *) 0); } if(ilet == '$') { if(!allowgold){ pline("You cannot %s gold.", word); continue; } if(!(allowcnt == 2 && cnt < u.ugold)) cnt = u.ugold; return(mkgoldobj(cnt)); } if(ilet == '?') { doinv(lets); if(!(ilet = morc)) continue; /* he typed a letter (not a space) to more() */ } else if(ilet == '*') { doinv((char *) 0); if(!(ilet = morc)) continue; /* ... */ } if(flags.invlet_constant) { for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp->invlet == ilet) break; } else { if(ilet >= 'A' && ilet <= 'Z') ilet += 'z'-'A'+1; ilet -= 'a'; for(otmp = invent; otmp && ilet; ilet--, otmp = otmp->nobj) ; } if(!otmp) { pline("You don't have that object."); continue; } if(cnt < 0 || otmp->quan < cnt) { pline("You don't have that many! [You have %u]" , otmp->quan); continue; } break; } if(!allowall && let && !index(let,otmp->olet)) { pline("That is a silly thing to %s.",word); return(0); } if(allowcnt == 2) { /* cnt given */ if(cnt == 0) return(0); if(cnt != otmp->quan) { - register struct obj *obj; + struct obj *obj; obj = splitobj(otmp, (int) cnt); if(otmp == uwep) setuwep(obj); } } return(otmp); } -ckunpaid(otmp) register struct obj *otmp; { +ckunpaid(otmp) struct obj *otmp; { return( otmp->unpaid ); } /* interactive version of getobj - used for Drop and Identify */ /* return the number of times fn was called successfully */ ggetobj(word, fn, max) char *word; int (*fn)(), max; { char buf[BUFSZ]; -register char *ip; -register char sym; -register int oletct = 0, iletct = 0; -register boolean allflag = FALSE; +char *ip; +char sym; +int oletct = 0, iletct = 0; +boolean allflag = FALSE; char olets[20], ilets[20]; int (*ckfn)() = (int (*)()) 0; xchar allowgold = (u.ugold && !strcmp(word, "drop")) ? 1 : 0; /* BAH */ if(!invent && !allowgold){ pline("You have nothing to %s.", word); return(0); } else { - register struct obj *otmp = invent; - register int uflg = 0; + struct obj *otmp = invent; + int uflg = 0; if(allowgold) ilets[iletct++] = '$'; ilets[iletct] = 0; while(otmp) { if(!index(ilets, otmp->olet)){ ilets[iletct++] = otmp->olet; ilets[iletct] = 0; } if(otmp->unpaid) uflg = 1; otmp = otmp->nobj; } ilets[iletct++] = ' '; if(uflg) ilets[iletct++] = 'u'; if(invent) ilets[iletct++] = 'a'; ilets[iletct] = 0; } pline("What kinds of thing do you want to %s? [%s] ", word, ilets); getlin(buf); if(buf[0] == '\033') { clrlin(); return(0); } ip = buf; olets[0] = 0; while(sym = *ip++){ if(sym == ' ') continue; if(sym == '$') { if(allowgold == 1) (*fn)(mkgoldobj(u.ugold)); else if(!u.ugold) pline("You have no gold."); allowgold = 2; } else if(sym == 'a' || sym == 'A') allflag = TRUE; else if(sym == 'u' || sym == 'U') ckfn = ckunpaid; else if(index("!%?[()=*/\"0", sym)){ if(!index(olets, sym)){ olets[oletct++] = sym; olets[oletct] = 0; } } else pline("You don't have any %c's.", sym); } if(allowgold == 2 && !oletct) return(1); /* he dropped gold (or at least tried to) */ else return(askchain(invent, olets, allflag, fn, ckfn, max)); } /* * Walk through the chain starting at objchn and ask for all objects * with olet in olets (if nonNULL) and satisfying ckfn (if nonNULL) * whether the action in question (i.e., fn) has to be performed. * If allflag then no questions are asked. Max gives the max nr of * objects to be treated. Return the number of objects treated. */ askchain(objchn, olets, allflag, fn, ckfn, max) struct obj *objchn; -register char *olets; +char *olets; int allflag; int (*fn)(), (*ckfn)(); int max; { -register struct obj *otmp, *otmp2; -register char sym, ilet; -register int cnt = 0; +struct obj *otmp, *otmp2; +char sym, ilet; +int cnt = 0; ilet = 'a'-1; for(otmp = objchn; otmp; otmp = otmp2){ if(ilet == 'z') ilet = 'A'; else ilet++; otmp2 = otmp->nobj; if(olets && *olets && !index(olets, otmp->olet)) continue; if(ckfn && !(*ckfn)(otmp)) continue; if(!allflag) { pline(xprname(otmp, ilet)); addtopl(" [nyaq]? "); sym = readchar(); } else sym = 'y'; switch(sym){ case 'a': allflag = 1; case 'y': cnt += (*fn)(otmp); if(--max == 0) goto ret; case 'n': default: break; case 'q': goto ret; } } pline(cnt ? "That was all." : "No applicable objects."); ret: return(cnt); } obj_to_let(obj) /* should of course only be called for things in invent */ -register struct obj *obj; +struct obj *obj; { - register struct obj *otmp; - register char ilet; + struct obj *otmp; + char ilet; if(flags.invlet_constant) return(obj->invlet); ilet = 'a'; for(otmp = invent; otmp && otmp != obj; otmp = otmp->nobj) if(++ilet > 'z') ilet = 'A'; return(otmp ? ilet : NOINVSYM); } prinv(obj) -register struct obj *obj; +struct obj *obj; { pline(xprname(obj, obj_to_let(obj))); } static char * xprname(obj,let) -register struct obj *obj; -register char let; +struct obj *obj; +char let; { static char li[BUFSZ]; (void) sprintf(li, "%c - %s.", flags.invlet_constant ? obj->invlet : let, doname(obj)); return(li); } ddoinv() { doinv((char *) 0); return(0); } /* called with 0 or "": all objects in inventory */ /* otherwise: all objects with (serial) letter in lets */ doinv(lets) -register char *lets; +char *lets; { - register struct obj *otmp; - register char ilet; + struct obj *otmp; + char ilet; int ct = 0; char any[BUFSZ]; morc = 0; /* just to be sure */ if(!invent){ pline("Not carrying anything."); return; } cornline(0, (char *) 0); ilet = 'a'; for(otmp = invent; otmp; otmp = otmp->nobj) { if(flags.invlet_constant) ilet = otmp->invlet; if(!lets || !*lets || index(lets, ilet)) { cornline(1, xprname(otmp, ilet)); any[ct++] = ilet; } if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; } any[ct] = 0; cornline(2, any); } dotypeinv () /* free after Robert Viduya */ /* Changed to one type only, so he doesnt have to type cr */ { char c, ilet; char stuff[BUFSZ]; - register int stct; - register struct obj *otmp; + int stct; + struct obj *otmp; boolean billx = inshop() && doinvbill(0); boolean unpd = FALSE; if (!invent && !u.ugold && !billx) { pline ("You aren't carrying anything."); return(0); } stct = 0; if(u.ugold) stuff[stct++] = '$'; stuff[stct] = 0; for(otmp = invent; otmp; otmp = otmp->nobj) { if (!index (stuff, otmp->olet)) { stuff[stct++] = otmp->olet; stuff[stct] = 0; } if(otmp->unpaid) unpd = TRUE; } if(unpd) stuff[stct++] = 'u'; if(billx) stuff[stct++] = 'x'; stuff[stct] = 0; if(stct > 1) { pline ("What type of object [%s] do you want an inventory of? ", stuff); c = readchar(); if(index(quitchars,c)) return(0); } else c = stuff[0]; if(c == '$') return(doprgold()); if(c == 'x' || c == 'X') { if(billx) (void) doinvbill(1); else pline("No used-up objects on the shopping bill."); return(0); } if((c == 'u' || c == 'U') && !unpd) { pline("You are not carrying any unpaid objects."); return(0); } stct = 0; ilet = 'a'; for (otmp = invent; otmp; otmp = otmp -> nobj) { if(flags.invlet_constant) ilet = otmp->invlet; if (c == otmp -> olet || (c == 'u' && otmp -> unpaid)) stuff[stct++] = ilet; if(!flags.invlet_constant) if(++ilet > 'z') ilet = 'A'; } stuff[stct] = '\0'; if(stct == 0) pline("You have no such objects."); else doinv (stuff); return(0); } /* look at what is here */ dolook() { - register struct obj *otmp, *otmp0; - register struct gold *gold; + struct obj *otmp, *otmp0; + struct gold *gold; char *verb = Blind ? "feel" : "see"; int ct = 0; if(!u.uswallow) { if(Blind) { pline("You try to feel what is lying here on the floor."); if(Levitation) { /* ab@unido */ pline("You cannot reach the floor!"); return(1); } } otmp0 = o_at(u.ux, u.uy); gold = g_at(u.ux, u.uy); } if(u.uswallow || (!otmp0 && !gold)) { pline("You %s no objects here.", verb); return(!!Blind); } cornline(0, "Things that are here:"); for(otmp = otmp0; otmp; otmp = otmp->nobj) { if(otmp->ox == u.ux && otmp->oy == u.uy) { ct++; cornline(1, doname(otmp)); if(Blind && otmp->otyp == DEAD_COCKATRICE && !uarmg) { pline("Touching the dead cockatrice is a fatal mistake ..."); pline("You die ..."); killer = "dead cockatrice"; done("died"); } } } if(gold) { char gbuf[30]; (void) sprintf(gbuf, "%ld gold piece%s", gold->amount, plur(gold->amount)); if(!ct++) pline("You %s here %s.", verb, gbuf); else cornline(1, gbuf); } if(ct == 1 && !gold) { pline("You %s here %s.", verb, doname(otmp0)); cornline(3, (char *) 0); } if(ct > 1) cornline(2, (char *) 0); return(!!Blind); } -stackobj(obj) register struct obj *obj; { -register struct obj *otmp = fobj; +stackobj(obj) struct obj *obj; { +struct obj *otmp = fobj; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp != obj) if(otmp->ox == obj->ox && otmp->oy == obj->oy && merged(obj,otmp,1)) return; } /* merge obj with otmp and delete obj if types agree */ -merged(otmp,obj,lose) register struct obj *otmp, *obj; { +merged(otmp,obj,lose) struct obj *otmp, *obj; { if(obj->otyp == otmp->otyp && obj->unpaid == otmp->unpaid && obj->spe == otmp->spe && obj->dknown == otmp->dknown && obj->cursed == otmp->cursed && (index("%*?!", obj->olet) || (obj->known == otmp->known && (obj->olet == WEAPON_SYM && obj->otyp < BOOMERANG)))) { otmp->quan += obj->quan; otmp->owt += obj->owt; if(lose) freeobj(obj); obfree(obj,otmp); /* free(obj), bill->otmp */ return(1); } else return(0); } /* * Gold is no longer displayed; in fact, when you have a lot of money, * it may take a while before you have counted it all. * [Bug: d$ and pickup still tell you how much it was.] */ extern int (*occupation)(); extern char *occtxt; static long goldcounted; countgold(){ if((goldcounted += 100*(u.ulevel + 1)) >= u.ugold) { long eps = 0; if(!rn2(2)) eps = rnd((int) (u.ugold/100 + 1)); pline("You probably have about %ld gold pieces.", u.ugold + eps); return(0); /* done */ } return(1); /* continue */ } doprgold(){ if(!u.ugold) pline("You do not carry any gold."); else if(u.ugold <= 500) pline("You are carrying %ld gold pieces.", u.ugold); else { pline("You sit down in order to count your gold pieces."); goldcounted = 500; occupation = countgold; occtxt = "counting your gold"; } return(1); } /* --- end of gold counting section --- */ doprwep(){ if(!uwep) pline("You are empty handed."); else prinv(uwep); return(0); } doprarm(){ if(!uarm && !uarmg && !uarms && !uarmh) pline("You are not wearing any armor."); else { char lets[6]; - register int ct = 0; + int ct = 0; if(uarm) lets[ct++] = obj_to_let(uarm); if(uarm2) lets[ct++] = obj_to_let(uarm2); if(uarmh) lets[ct++] = obj_to_let(uarmh); if(uarms) lets[ct++] = obj_to_let(uarms); if(uarmg) lets[ct++] = obj_to_let(uarmg); lets[ct] = 0; doinv(lets); } return(0); } doprring(){ if(!uleft && !uright) pline("You are not wearing any rings."); else { char lets[3]; - register int ct = 0; + int ct = 0; if(uleft) lets[ct++] = obj_to_let(uleft); if(uright) lets[ct++] = obj_to_let(uright); lets[ct] = 0; doinv(lets); } return(0); } digit(c) char c; { return(c >= '0' && c <= '9'); } diff --git a/games/hack/hack.lev.c b/games/hack/hack.lev.c index 82afd61b7064..4047e456ba5d 100644 --- a/games/hack/hack.lev.c +++ b/games/hack/hack.lev.c @@ -1,286 +1,286 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.lev.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include "def.mkroom.h" #include extern struct monst *restmonchn(); extern struct obj *restobjchn(); extern struct obj *billobjs; extern char *itoa(); extern char SAVEF[]; extern int hackpid; extern xchar dlevel; extern char nul[]; #ifndef NOWORM #include "def.wseg.h" extern struct wseg *wsegs[32], *wheads[32]; extern long wgrowtime[32]; #endif NOWORM boolean level_exists[MAXLEVEL+1]; savelev(fd,lev) int fd; xchar lev; { #ifndef NOWORM - register struct wseg *wtmp, *wtmp2; - register tmp; + struct wseg *wtmp, *wtmp2; + tmp; #endif NOWORM if(fd < 0) panic("Save on bad file!"); /* impossible */ if(lev >= 0 && lev <= MAXLEVEL) level_exists[lev] = TRUE; bwrite(fd,(char *) &hackpid,sizeof(hackpid)); bwrite(fd,(char *) &lev,sizeof(lev)); bwrite(fd,(char *) levl,sizeof(levl)); bwrite(fd,(char *) &moves,sizeof(long)); bwrite(fd,(char *) &xupstair,sizeof(xupstair)); bwrite(fd,(char *) &yupstair,sizeof(yupstair)); bwrite(fd,(char *) &xdnstair,sizeof(xdnstair)); bwrite(fd,(char *) &ydnstair,sizeof(ydnstair)); savemonchn(fd, fmon); savegoldchn(fd, fgold); savetrapchn(fd, ftrap); saveobjchn(fd, fobj); saveobjchn(fd, billobjs); billobjs = 0; save_engravings(fd); #ifndef QUEST bwrite(fd,(char *) rooms,sizeof(rooms)); bwrite(fd,(char *) doors,sizeof(doors)); #endif QUEST fgold = 0; ftrap = 0; fmon = 0; fobj = 0; #ifndef NOWORM bwrite(fd,(char *) wsegs,sizeof(wsegs)); for(tmp=1; tmp<32; tmp++){ for(wtmp = wsegs[tmp]; wtmp; wtmp = wtmp2){ wtmp2 = wtmp->nseg; bwrite(fd,(char *) wtmp,sizeof(struct wseg)); } wsegs[tmp] = 0; } bwrite(fd,(char *) wgrowtime,sizeof(wgrowtime)); #endif NOWORM } bwrite(fd,loc,num) -register fd; -register char *loc; -register unsigned num; +fd; +char *loc; +unsigned num; { /* lint wants the 3rd arg of write to be an int; lint -p an unsigned */ if(write(fd, loc, (int) num) != num) panic("cannot write %u bytes to file #%d", num, fd); } saveobjchn(fd,otmp) -register fd; -register struct obj *otmp; +fd; +struct obj *otmp; { - register struct obj *otmp2; + struct obj *otmp2; unsigned xl; int minusone = -1; while(otmp) { otmp2 = otmp->nobj; xl = otmp->onamelth; bwrite(fd, (char *) &xl, sizeof(int)); bwrite(fd, (char *) otmp, xl + sizeof(struct obj)); free((char *) otmp); otmp = otmp2; } bwrite(fd, (char *) &minusone, sizeof(int)); } savemonchn(fd,mtmp) -register fd; -register struct monst *mtmp; +fd; +struct monst *mtmp; { - register struct monst *mtmp2; + struct monst *mtmp2; unsigned xl; int minusone = -1; struct permonst *monbegin = &mons[0]; bwrite(fd, (char *) &monbegin, sizeof(monbegin)); while(mtmp) { mtmp2 = mtmp->nmon; xl = mtmp->mxlth + mtmp->mnamelth; bwrite(fd, (char *) &xl, sizeof(int)); bwrite(fd, (char *) mtmp, xl + sizeof(struct monst)); if(mtmp->minvent) saveobjchn(fd,mtmp->minvent); free((char *) mtmp); mtmp = mtmp2; } bwrite(fd, (char *) &minusone, sizeof(int)); } savegoldchn(fd,gold) -register fd; -register struct gold *gold; +fd; +struct gold *gold; { - register struct gold *gold2; + struct gold *gold2; while(gold) { gold2 = gold->ngold; bwrite(fd, (char *) gold, sizeof(struct gold)); free((char *) gold); gold = gold2; } bwrite(fd, nul, sizeof(struct gold)); } savetrapchn(fd,trap) -register fd; -register struct trap *trap; +fd; +struct trap *trap; { - register struct trap *trap2; + struct trap *trap2; while(trap) { trap2 = trap->ntrap; bwrite(fd, (char *) trap, sizeof(struct trap)); free((char *) trap); trap = trap2; } bwrite(fd, nul, sizeof(struct trap)); } getlev(fd,pid,lev) int fd,pid; xchar lev; { - register struct gold *gold; - register struct trap *trap; + struct gold *gold; + struct trap *trap; #ifndef NOWORM - register struct wseg *wtmp; + struct wseg *wtmp; #endif NOWORM - register tmp; + tmp; long omoves; int hpid; xchar dlvl; /* First some sanity checks */ mread(fd, (char *) &hpid, sizeof(hpid)); mread(fd, (char *) &dlvl, sizeof(dlvl)); if((pid && pid != hpid) || (lev && dlvl != lev)) { pline("Strange, this map is not as I remember it."); pline("Somebody is trying some trickery here ..."); pline("This game is void ..."); done("tricked"); } fgold = 0; ftrap = 0; mread(fd, (char *) levl, sizeof(levl)); mread(fd, (char *)&omoves, sizeof(omoves)); mread(fd, (char *)&xupstair, sizeof(xupstair)); mread(fd, (char *)&yupstair, sizeof(yupstair)); mread(fd, (char *)&xdnstair, sizeof(xdnstair)); mread(fd, (char *)&ydnstair, sizeof(ydnstair)); fmon = restmonchn(fd); /* regenerate animals while on another level */ { long tmoves = (moves > omoves) ? moves-omoves : 0; - register struct monst *mtmp, *mtmp2; + struct monst *mtmp, *mtmp2; extern char genocided[]; for(mtmp = fmon; mtmp; mtmp = mtmp2) { long newhp; /* tmoves may be very large */ mtmp2 = mtmp->nmon; if(index(genocided, mtmp->data->mlet)) { mondead(mtmp); continue; } if(mtmp->mtame && tmoves > 250) { mtmp->mtame = 0; mtmp->mpeaceful = 0; } newhp = mtmp->mhp + (index(MREGEN, mtmp->data->mlet) ? tmoves : tmoves/20); if(newhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; else mtmp->mhp = newhp; } } setgd(); gold = newgold(); mread(fd, (char *)gold, sizeof(struct gold)); while(gold->gx) { gold->ngold = fgold; fgold = gold; gold = newgold(); mread(fd, (char *)gold, sizeof(struct gold)); } free((char *) gold); trap = newtrap(); mread(fd, (char *)trap, sizeof(struct trap)); while(trap->tx) { trap->ntrap = ftrap; ftrap = trap; trap = newtrap(); mread(fd, (char *)trap, sizeof(struct trap)); } free((char *) trap); fobj = restobjchn(fd); billobjs = restobjchn(fd); rest_engravings(fd); #ifndef QUEST mread(fd, (char *)rooms, sizeof(rooms)); mread(fd, (char *)doors, sizeof(doors)); #endif QUEST #ifndef NOWORM mread(fd, (char *)wsegs, sizeof(wsegs)); for(tmp = 1; tmp < 32; tmp++) if(wsegs[tmp]){ wheads[tmp] = wsegs[tmp] = wtmp = newseg(); while(1) { mread(fd, (char *)wtmp, sizeof(struct wseg)); if(!wtmp->nseg) break; wheads[tmp]->nseg = wtmp = newseg(); wheads[tmp] = wtmp; } } mread(fd, (char *)wgrowtime, sizeof(wgrowtime)); #endif NOWORM } mread(fd, buf, len) -register fd; -register char *buf; -register unsigned len; +fd; +char *buf; +unsigned len; { - register int rlen; + int rlen; extern boolean restoring; rlen = read(fd, buf, (int) len); if(rlen != len){ pline("Read %d instead of %u bytes.\n", rlen, len); if(restoring) { (void) unlink(SAVEF); error("Error restoring old game."); } panic("Error reading level file."); } } mklev() { extern boolean in_mklev; if(getbones()) return; in_mklev = TRUE; makelevel(); in_mklev = FALSE; } diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c index af3080f1c7ba..0d07c6eda54b 100644 --- a/games/hack/hack.main.c +++ b/games/hack/hack.main.c @@ -1,502 +1,502 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.main.c - version 1.0.3 */ /* $FreeBSD$ */ #include #include #include #include #include "hack.h" #ifdef QUEST #define gamename "quest" #else #define gamename "hack" #endif extern char plname[PL_NSIZ], pl_character[PL_CSIZ]; extern struct permonst mons[CMNUM+2]; extern char genocided[60], fut_geno[]; int (*afternmv)(); int (*occupation)(); char *occtxt; /* defined when occupation != NULL */ void done1(); void hangup(); int hackpid; /* current pid */ int locknum; /* max num of players */ #ifdef DEF_PAGER char *catmore; /* default pager */ #endif char SAVEF[PL_NSIZ + 11] = "save/"; /* save/99999player */ char *hname; /* name of the game (argv[0] of call) */ char obuf[BUFSIZ]; /* BUFSIZ is defined in stdio.h */ extern char *nomovemsg; extern long wailmsg; #ifdef CHDIR static void chdirx(); #endif main(argc,argv) int argc; char *argv[]; { - register int fd; + int fd; #ifdef CHDIR - register char *dir; + char *dir; #endif hname = argv[0]; hackpid = getpid(); #ifdef CHDIR /* otherwise no chdir() */ /* * See if we must change directory to the playground. * (Perhaps hack runs suid and playground is inaccessible * for the player.) * The environment variable HACKDIR is overridden by a * -d command line option (must be the first option given) */ dir = getenv("HACKDIR"); if(argc > 1 && !strncmp(argv[1], "-d", 2)) { argc--; argv++; dir = argv[0]+2; if(*dir == '=' || *dir == ':') dir++; if(!*dir && argc > 1) { argc--; argv++; dir = argv[0]; } if(!*dir) error("Flag -d must be followed by a directory name."); } #endif /* * Who am i? Algorithm: 1. Use name as specified in HACKOPTIONS * 2. Use $USER or $LOGNAME (if 1. fails) * 3. Use getlogin() (if 2. fails) * The resulting name is overridden by command line options. * If everything fails, or if the resulting name is some generic * account like "games", "play", "player", "hack" then eventually * we'll ask him. * Note that we trust him here; it is possible to play under * somebody else's name. */ - { register char *s; + { char *s; initoptions(); if(!*plname && (s = getenv("USER"))) (void) strncpy(plname, s, sizeof(plname)-1); if(!*plname && (s = getenv("LOGNAME"))) (void) strncpy(plname, s, sizeof(plname)-1); if(!*plname && (s = getlogin())) (void) strncpy(plname, s, sizeof(plname)-1); } /* * Now we know the directory containing 'record' and * may do a prscore(). */ if(argc > 1 && !strncmp(argv[1], "-s", 2)) { #ifdef CHDIR chdirx(dir,0); #endif prscore(argc, argv); exit(0); } /* * It seems he really wants to play. * Remember tty modes, to be restored on exit. */ gettty(); setbuf(stdout,obuf); umask(007); setrandom(); startup(); cls(); u.uhp = 1; /* prevent RIP on early quits */ u.ux = FAR; /* prevent nscr() */ (void) signal(SIGHUP, hangup); /* * Find the creation date of this game, * so as to avoid restoring outdated savefiles. */ gethdate(hname); /* * We cannot do chdir earlier, otherwise gethdate will fail. */ #ifdef CHDIR chdirx(dir,1); #endif /* * Process options. */ while(argc > 1 && argv[1][0] == '-'){ argv++; argc--; switch(argv[0][1]){ #ifdef WIZARD case 'D': /* if(!strcmp(getlogin(), WIZARD)) */ wizard = TRUE; /* else printf("Sorry.\n"); */ break; #endif #ifdef NEWS case 'n': flags.nonews = TRUE; break; #endif case 'u': if(argv[0][2]) (void) strncpy(plname, argv[0]+2, sizeof(plname)-1); else if(argc > 1) { argc--; argv++; (void) strncpy(plname, argv[0], sizeof(plname)-1); } else printf("Player name expected after -u\n"); break; default: /* allow -T for Tourist, etc. */ (void) strncpy(pl_character, argv[0]+1, sizeof(pl_character)-1); /* printf("Unknown option: %s\n", *argv); */ } } if(argc > 1) locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS if(!locknum || locknum > MAX_NR_OF_PLAYERS) locknum = MAX_NR_OF_PLAYERS; #endif #ifdef DEF_PAGER if(!(catmore = getenv("HACKPAGER")) && !(catmore = getenv("PAGER"))) catmore = DEF_PAGER; #endif #ifdef MAIL getmailstatus(); #endif #ifdef WIZARD if(wizard) (void) strcpy(plname, "wizard"); else #endif if(!*plname || !strncmp(plname, "player", 4) || !strncmp(plname, "games", 4)) askname(); plnamesuffix(); /* strip suffix from name; calls askname() */ /* again if suffix was whole name */ /* accepts any suffix */ #ifdef WIZARD if(!wizard) { #endif /* * check for multiple games under the same name * (if !locknum) or check max nr of players (otherwise) */ (void) signal(SIGQUIT,SIG_IGN); (void) signal(SIGINT,SIG_IGN); if(!locknum) (void) strcpy(lock,plname); getlock(); /* sets lock if locknum != 0 */ #ifdef WIZARD } else { - register char *sfoo; + char *sfoo; (void) strcpy(lock,plname); if(sfoo = getenv("MAGIC")) while(*sfoo) { switch(*sfoo++) { case 'n': (void) srandom(*sfoo++); break; } } if(sfoo = getenv("GENOCIDED")){ if(*sfoo == '!'){ - register struct permonst *pm = mons; - register char *gp = genocided; + struct permonst *pm = mons; + char *gp = genocided; while(pm < mons+CMNUM+2){ if(!index(sfoo, pm->mlet)) *gp++ = pm->mlet; pm++; } *gp = 0; } else (void) strncpy(genocided, sfoo, sizeof(genocided)-1); (void) strcpy(fut_geno, genocided); } } #endif setftty(); (void) sprintf(SAVEF, "save/%d%s", getuid(), plname); regularize(SAVEF+5); /* avoid . or / in name */ if((fd = open(SAVEF,0)) >= 0 && (uptodate(fd) || unlink(SAVEF) == 666)) { (void) signal(SIGINT,done1); pline("Restoring old save file..."); (void) fflush(stdout); if(!dorecover(fd)) goto not_recovered; pline("Hello %s, welcome to %s!", plname, gamename); flags.move = 0; } else { not_recovered: fobj = fcobj = invent = 0; fmon = fallen_down = 0; ftrap = 0; fgold = 0; flags.ident = 1; init_objects(); u_init(); (void) signal(SIGINT,done1); mklev(); u.ux = xupstair; u.uy = yupstair; (void) inshop(); setsee(); flags.botlx = 1; makedog(); - { register struct monst *mtmp; + { struct monst *mtmp; if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */ } seemons(); #ifdef NEWS if(flags.nonews || !readnews()) /* after reading news we did docrt() already */ #endif docrt(); /* give welcome message before pickup messages */ pline("Hello %s, welcome to %s!", plname, gamename); pickup(1); read_engr_at(u.ux,u.uy); flags.move = 1; } flags.moonphase = phase_of_the_moon(); if(flags.moonphase == FULL_MOON) { pline("You are lucky! Full moon tonight."); u.uluck++; } else if(flags.moonphase == NEW_MOON) { pline("Be careful! New moon tonight."); } initrack(); for(;;) { if(flags.move) { /* actual time passed */ settrack(); if(moves%2 == 0 || (!(Fast & ~INTRINSIC) && (!Fast || rn2(3)))) { extern struct monst *makemon(); movemon(); if(!rn2(70)) (void) makemon((struct permonst *)0, 0, 0); } if(Glib) glibr(); timeout(); ++moves; if(flags.time) flags.botl = 1; if(u.uhp < 1) { pline("You die..."); done("died"); } if(u.uhp*10 < u.uhpmax && moves-wailmsg > 50){ wailmsg = moves; if(u.uhp == 1) pline("You hear the wailing of the Banshee..."); else pline("You hear the howling of the CwnAnnwn..."); } if(u.uhp < u.uhpmax) { if(u.ulevel > 9) { if(Regeneration || !(moves%3)) { flags.botl = 1; u.uhp += rnd((int) u.ulevel-9); if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; } } else if(Regeneration || (!(moves%(22-u.ulevel*2)))) { flags.botl = 1; u.uhp++; } } if(Teleportation && !rn2(85)) tele(); if(Searching && multi >= 0) (void) dosearch(); gethungry(); invault(); amulet(); } if(multi < 0) { if(!++multi){ pline(nomovemsg ? nomovemsg : "You can move again."); nomovemsg = 0; if(afternmv) (*afternmv)(); afternmv = 0; } } find_ac(); #ifndef QUEST if(!flags.mv || Blind) #endif { seeobjs(); seemons(); nscr(); } if(flags.botl || flags.botlx) bot(); flags.move = 1; if(multi >= 0 && occupation) { if(monster_nearby()) stop_occupation(); else if ((*occupation)() == 0) occupation = 0; continue; } if(multi > 0) { #ifdef QUEST if(flags.run >= 4) finddir(); #endif lookaround(); if(!multi) { /* lookaround may clear multi */ flags.move = 0; continue; } if(flags.mv) { if(multi < COLNO && !--multi) flags.mv = flags.run = 0; domove(); } else { --multi; rhack(save_cm); } } else if(multi == 0) { #ifdef MAIL ckmailstatus(); #endif rhack((char *) 0); } if(multi && multi%7 == 0) (void) fflush(stdout); } } glo(foo) -register foo; +foo; { /* construct the string xlock.n */ - register char *tf; + char *tf; tf = lock; while(*tf && *tf != '.') tf++; (void) sprintf(tf, ".%d", foo); } /* * plname is filled either by an option (-u Player or -uPlayer) or * explicitly (-w implies wizard) or by askname. * It may still contain a suffix denoting pl_character. */ askname(){ -register int c,ct; +int c,ct; printf("\nWho are you? "); (void) fflush(stdout); ct = 0; while((c = getchar()) != '\n'){ if(c == EOF) error("End of input\n"); /* some people get confused when their erase char is not ^H */ if(c == '\010') { if(ct) ct--; continue; } if(c != '-') if(c < 'A' || (c > 'Z' && c < 'a') || c > 'z') c = '_'; if(ct < sizeof(plname)-1) plname[ct++] = c; } plname[ct] = 0; if(ct == 0) askname(); } /*VARARGS1*/ impossible(s,x1,x2) -register char *s; +char *s; { pline(s,x1,x2); pline("Program in disorder - perhaps you'd better Quit."); } #ifdef CHDIR static void chdirx(dir, wr) char *dir; boolean wr; { #ifdef SECURE if(dir /* User specified directory? */ #ifdef HACKDIR && strcmp(dir, HACKDIR) /* and not the default? */ #endif ) { /* revoke */ setgid(getgid()); } #endif #ifdef HACKDIR if(dir == NULL) dir = HACKDIR; #endif if(dir && chdir(dir) < 0) { perror(dir); error("Cannot chdir to %s.", dir); } /* warn the player if he cannot write the record file */ /* perhaps we should also test whether . is writable */ /* unfortunately the access systemcall is worthless */ if(wr) { - register fd; + fd; if(dir == NULL) dir = "."; if((fd = open(RECORD, 2)) < 0) { printf("Warning: cannot write %s/%s", dir, RECORD); getret(); } else (void) close(fd); } } #endif stop_occupation() { if(occupation) { pline("You stop %s.", occtxt); occupation = 0; } } diff --git a/games/hack/hack.makemon.c b/games/hack/hack.makemon.c index 7ad6385f732a..cce2183a04d9 100644 --- a/games/hack/hack.makemon.c +++ b/games/hack/hack.makemon.c @@ -1,199 +1,199 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.makemon.c - version 1.0.2 */ /* $FreeBSD$ */ #include "hack.h" extern char fut_geno[]; extern char *index(); extern struct obj *mkobj_at(); struct monst zeromonst; /* * called with [x,y] = coordinates; * [0,0] means anyplace * [u.ux,u.uy] means: call mnexto (if !in_mklev) * * In case we make an Orc or killer bee, we make an entire horde (swarm); * note that in this case we return only one of them (the one at [x,y]). */ struct monst * makemon(ptr,x,y) -register struct permonst *ptr; +struct permonst *ptr; { - register struct monst *mtmp; - register tmp, ct; + struct monst *mtmp; + tmp, ct; boolean anything = (!ptr); extern boolean in_mklev; if(x != 0 || y != 0) if(m_at(x,y)) return((struct monst *) 0); if(ptr){ if(index(fut_geno, ptr->mlet)) return((struct monst *) 0); } else { ct = CMNUM - strlen(fut_geno); if(index(fut_geno, 'm')) ct++; /* make only 1 minotaur */ if(index(fut_geno, '@')) ct++; if(ct <= 0) return(0); /* no more monsters! */ tmp = rn2(ct*dlevel/24 + 7); if(tmp < dlevel - 4) tmp = rn2(ct*dlevel/24 + 12); if(tmp >= ct) tmp = rn1(ct - ct/2, ct/2); for(ct = 0; ct < CMNUM; ct++){ ptr = &mons[ct]; if(index(fut_geno, ptr->mlet)) continue; if(!tmp--) goto gotmon; } panic("makemon?"); } gotmon: mtmp = newmonst(ptr->pxlth); *mtmp = zeromonst; /* clear all entries in structure */ for(ct = 0; ct < ptr->pxlth; ct++) ((char *) &(mtmp->mextra[0]))[ct] = 0; mtmp->nmon = fmon; fmon = mtmp; mtmp->m_id = flags.ident++; mtmp->data = ptr; mtmp->mxlth = ptr->pxlth; if(ptr->mlet == 'D') mtmp->mhpmax = mtmp->mhp = 80; else if(!ptr->mlevel) mtmp->mhpmax = mtmp->mhp = rnd(4); else mtmp->mhpmax = mtmp->mhp = d(ptr->mlevel, 8); mtmp->mx = x; mtmp->my = y; mtmp->mcansee = 1; if(ptr->mlet == 'M'){ mtmp->mimic = 1; mtmp->mappearance = ']'; } if(!in_mklev) { if(x == u.ux && y == u.uy && ptr->mlet != ' ') mnexto(mtmp); if(x == 0 && y == 0) rloc(mtmp); } if(ptr->mlet == 's' || ptr->mlet == 'S') { mtmp->mhide = mtmp->mundetected = 1; if(in_mklev) if(mtmp->mx && mtmp->my) (void) mkobj_at(0, mtmp->mx, mtmp->my); } if(ptr->mlet == ':') { mtmp->cham = 1; (void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); } if(ptr->mlet == 'I' || ptr->mlet == ';') mtmp->minvis = 1; if(ptr->mlet == 'L' || ptr->mlet == 'N' || (in_mklev && index("&w;", ptr->mlet) && rn2(5)) ) mtmp->msleep = 1; #ifndef NOWORM if(ptr->mlet == 'w' && getwn(mtmp)) initworm(mtmp); #endif NOWORM if(anything) if(ptr->mlet == 'O' || ptr->mlet == 'k') { coord enexto(); coord mm; - register int cnt = rnd(10); + int cnt = rnd(10); mm.x = x; mm.y = y; while(cnt--) { mm = enexto(mm.x, mm.y); (void) makemon(ptr, mm.x, mm.y); } } return(mtmp); } coord enexto(xx,yy) -register xchar xx,yy; +xchar xx,yy; { - register xchar x,y; + xchar x,y; coord foo[15], *tfoo; int range; tfoo = foo; range = 1; do { /* full kludge action. */ for(x = xx-range; x <= xx+range; x++) if(goodpos(x, yy-range)) { tfoo->x = x; tfoo++->y = yy-range; if(tfoo == &foo[15]) goto foofull; } for(x = xx-range; x <= xx+range; x++) if(goodpos(x,yy+range)) { tfoo->x = x; tfoo++->y = yy+range; if(tfoo == &foo[15]) goto foofull; } for(y = yy+1-range; y < yy+range; y++) if(goodpos(xx-range,y)) { tfoo->x = xx-range; tfoo++->y = y; if(tfoo == &foo[15]) goto foofull; } for(y = yy+1-range; y < yy+range; y++) if(goodpos(xx+range,y)) { tfoo->x = xx+range; tfoo++->y = y; if(tfoo == &foo[15]) goto foofull; } range++; } while(tfoo == foo); foofull: return( foo[rn2(tfoo-foo)] ); } goodpos(x,y) /* used only in mnexto and rloc */ { return( ! (x < 1 || x > COLNO-2 || y < 1 || y > ROWNO-2 || m_at(x,y) || !ACCESSIBLE(levl[x][y].typ) || (x == u.ux && y == u.uy) || sobj_at(ENORMOUS_ROCK, x, y) )); } rloc(mtmp) struct monst *mtmp; { - register tx,ty; - register char ch = mtmp->data->mlet; + tx,ty; + char ch = mtmp->data->mlet; #ifndef NOWORM if(ch == 'w' && mtmp->mx) return; /* do not relocate worms */ #endif NOWORM do { tx = rn1(COLNO-3,2); ty = rn2(ROWNO); } while(!goodpos(tx,ty)); mtmp->mx = tx; mtmp->my = ty; if(u.ustuck == mtmp){ if(u.uswallow) { u.ux = tx; u.uy = ty; docrt(); } else u.ustuck = 0; } pmon(mtmp); } struct monst * mkmon_at(let,x,y) char let; -register int x,y; +int x,y; { - register int ct; - register struct permonst *ptr; + int ct; + struct permonst *ptr; for(ct = 0; ct < CMNUM; ct++) { ptr = &mons[ct]; if(ptr->mlet == let) return(makemon(ptr,x,y)); } return(0); } diff --git a/games/hack/hack.mhitu.c b/games/hack/hack.mhitu.c index f41e00e12d5b..4d7122957311 100644 --- a/games/hack/hack.mhitu.c +++ b/games/hack/hack.mhitu.c @@ -1,364 +1,364 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mhitu.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" extern struct monst *makemon(); /* * mhitu: monster hits you * returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise */ mhitu(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { - register struct permonst *mdat = mtmp->data; - register int tmp, ctmp; + struct permonst *mdat = mtmp->data; + int tmp, ctmp; nomul(0); /* If swallowed, can only be affected by hissers and by u.ustuck */ if(u.uswallow) { if(mtmp != u.ustuck) { if(mdat->mlet == 'c' && !rn2(13)) { pline("Outside, you hear %s's hissing!", monnam(mtmp)); pline("%s gets turned to stone!", Monnam(u.ustuck)); pline("And the same fate befalls you."); done_in_by(mtmp); /* "notreached": not return(1); */ } return(0); } switch(mdat->mlet) { /* now mtmp == u.ustuck */ case ',': youswld(mtmp, (u.uac > 0) ? u.uac+4 : 4, 5, "The trapper"); break; case '\'': youswld(mtmp,rnd(6),7,"The lurker above"); break; case 'P': youswld(mtmp,d(2,4),12,"The purple worm"); break; default: /* This is not impossible! */ pline("The mysterious monster totally digests you."); u.uhp = 0; } if(u.uhp < 1) done_in_by(mtmp); return(0); } if(mdat->mlet == 'c' && Stoned) return(0); /* make eels visible the moment they hit/miss us */ if(mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx,mtmp->my)){ mtmp->minvis = 0; pmon(mtmp); } if(!index("1&DuxynNF",mdat->mlet)) tmp = hitu(mtmp,d(mdat->damn,mdat->damd)); else tmp = 0; if(index(UNDEAD, mdat->mlet) && midnight()) tmp += hitu(mtmp,d(mdat->damn,mdat->damd)); ctmp = tmp && !mtmp->mcan && (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50)); switch(mdat->mlet) { case '1': if(wiz_hit(mtmp)) return(1); /* he disappeared */ break; case '&': if(!mtmp->cham && !mtmp->mcan && !rn2(13)) { (void) makemon(PM_DEMON,u.ux,u.uy); } else { (void) hitu(mtmp,d(2,6)); (void) hitu(mtmp,d(2,6)); (void) hitu(mtmp,rnd(3)); (void) hitu(mtmp,rnd(3)); (void) hitu(mtmp,rn1(4,2)); } break; case ',': if(tmp) justswld(mtmp,"The trapper"); break; case '\'': if(tmp) justswld(mtmp, "The lurker above"); break; case ';': if(ctmp) { if(!u.ustuck && !rn2(10)) { pline("%s swings itself around you!", Monnam(mtmp)); u.ustuck = mtmp; } else if(u.ustuck == mtmp && levl[mtmp->mx][mtmp->my].typ == POOL) { pline("%s drowns you ...", Monnam(mtmp)); done("drowned"); } } break; case 'A': if(ctmp && rn2(2)) { if(Poison_resistance) pline("The sting doesn't seem to affect you."); else { pline("You feel weaker!"); losestr(1); } } break; case 'C': (void) hitu(mtmp,rnd(6)); break; case 'c': if(!rn2(5)) { pline("You hear %s's hissing!", monnam(mtmp)); if(ctmp || !rn2(20) || (flags.moonphase == NEW_MOON && !carrying(DEAD_LIZARD))) { Stoned = 5; /* pline("You get turned to stone!"); */ /* done_in_by(mtmp); */ } } break; case 'D': if(rn2(6) || mtmp->mcan) { (void) hitu(mtmp,d(3,10)); (void) hitu(mtmp,rnd(8)); (void) hitu(mtmp,rnd(8)); break; } kludge("%s breathes fire!","The dragon"); buzz(-1,mtmp->mx,mtmp->my,u.ux-mtmp->mx,u.uy-mtmp->my); break; case 'd': (void) hitu(mtmp,d(2, (flags.moonphase == FULL_MOON) ? 3 : 4)); break; case 'e': (void) hitu(mtmp,d(3,6)); break; case 'F': if(mtmp->mcan) break; kludge("%s explodes!","The freezing sphere"); if(Cold_resistance) pline("You don't seem affected by it."); else { xchar dn; if(17-(u.ulevel/2) > rnd(20)) { pline("You get blasted!"); dn = 6; } else { pline("You duck the blast..."); dn = 3; } losehp_m(d(dn,6), mtmp); } mondead(mtmp); return(1); case 'g': if(ctmp && multi >= 0 && !rn2(3)) { kludge("You are frozen by %ss juices","the cube'"); nomul(-rnd(10)); } break; case 'h': if(ctmp && multi >= 0 && !rn2(5)) { nomul(-rnd(10)); kludge("You are put to sleep by %ss bite!", "the homunculus'"); } break; case 'j': tmp = hitu(mtmp,rnd(3)); tmp &= hitu(mtmp,rnd(3)); if(tmp){ (void) hitu(mtmp,rnd(4)); (void) hitu(mtmp,rnd(4)); } break; case 'k': if((hitu(mtmp,rnd(4)) || !rn2(3)) && ctmp){ poisoned("bee's sting",mdat->mname); } break; case 'L': if(tmp) stealgold(mtmp); break; case 'N': if(mtmp->mcan && !Blind) { pline("%s tries to seduce you, but you seem not interested.", Amonnam(mtmp, "plain")); if(rn2(3)) rloc(mtmp); } else if(steal(mtmp)) { rloc(mtmp); mtmp->mflee = 1; } break; case 'n': if(!uwep && !uarm && !uarmh && !uarms && !uarmg) { pline("%s hits! (I hope you don't mind)", Monnam(mtmp)); u.uhp += rnd(7); if(!rn2(7)) u.uhpmax++; if(u.uhp > u.uhpmax) u.uhp = u.uhpmax; flags.botl = 1; if(!rn2(50)) rloc(mtmp); } else { (void) hitu(mtmp,d(2,6)); (void) hitu(mtmp,d(2,6)); } break; case 'o': tmp = hitu(mtmp,rnd(6)); if(hitu(mtmp,rnd(6)) && tmp && /* hits with both paws */ !u.ustuck && rn2(2)) { u.ustuck = mtmp; kludge("%s has grabbed you!","The owlbear"); u.uhp -= d(2,8); } else if(u.ustuck == mtmp) { u.uhp -= d(2,8); pline("You are being crushed."); } break; case 'P': if(ctmp && !rn2(4)) justswld(mtmp,"The purple worm"); else (void) hitu(mtmp,d(2,4)); break; case 'Q': (void) hitu(mtmp,rnd(2)); (void) hitu(mtmp,rnd(2)); break; case 'R': if(tmp && uarmh && !uarmh->rustfree && (int) uarmh->spe >= -1) { pline("Your helmet rusts!"); uarmh->spe--; } else if(ctmp && uarm && !uarm->rustfree && /* Mike Newton */ uarm->otyp < STUDDED_LEATHER_ARMOR && (int) uarm->spe >= -1) { pline("Your armor rusts!"); uarm->spe--; } break; case 'S': if(ctmp && !rn2(8)) { poisoned("snake's bite",mdat->mname); } break; case 's': if(tmp && !rn2(8)) { poisoned("scorpion's sting",mdat->mname); } (void) hitu(mtmp,rnd(8)); (void) hitu(mtmp,rnd(8)); break; case 'T': (void) hitu(mtmp,rnd(6)); (void) hitu(mtmp,rnd(6)); break; case 't': if(!rn2(5)) rloc(mtmp); break; case 'u': mtmp->mflee = 1; break; case 'U': (void) hitu(mtmp,d(3,4)); (void) hitu(mtmp,d(3,4)); break; case 'v': if(ctmp && !u.ustuck) u.ustuck = mtmp; break; case 'V': if(tmp) u.uhp -= 4; if(ctmp) losexp(); break; case 'W': if(ctmp) losexp(); break; #ifndef NOWORM case 'w': if(tmp) wormhit(mtmp); #endif NOWORM break; case 'X': (void) hitu(mtmp,rnd(5)); (void) hitu(mtmp,rnd(5)); (void) hitu(mtmp,rnd(5)); break; case 'x': - { register long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; + { long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; pline("%s pricks in your %s leg!", Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left"); set_wounded_legs(side, rnd(50)); losehp_m(2, mtmp); break; } case 'y': if(mtmp->mcan) break; mondead(mtmp); if(!Blind) { pline("You are blinded by a blast of light!"); Blind = d(4,12); seeoff(0); } return(1); case 'Y': (void) hitu(mtmp,rnd(6)); break; } if(u.uhp < 1) done_in_by(mtmp); return(0); } hitu(mtmp,dam) -register struct monst *mtmp; -register dam; +struct monst *mtmp; +dam; { - register tmp, res; + tmp, res; nomul(0); if(u.uswallow) return(0); if(mtmp->mhide && mtmp->mundetected) { mtmp->mundetected = 0; if(!Blind) { - register struct obj *obj; + struct obj *obj; extern char * Xmonnam(); if(obj = o_at(mtmp->mx,mtmp->my)) pline("%s was hidden under %s!", Xmonnam(mtmp), doname(obj)); } } tmp = u.uac; /* give people with Ac = -10 at least some vulnerability */ if(tmp < 0) { dam += tmp; /* decrease damage */ if(dam <= 0) dam = 1; tmp = -rn2(-tmp); } tmp += mtmp->data->mlevel; if(multi < 0) tmp += 4; if((Invis && mtmp->data->mlet != 'I') || !mtmp->mcansee) tmp -= 2; if(mtmp->mtrapped) tmp -= 2; if(tmp <= rnd(20)) { if(Blind) pline("It misses."); else pline("%s misses.",Monnam(mtmp)); res = 0; } else { if(Blind) pline("It hits!"); else pline("%s hits!",Monnam(mtmp)); losehp_m(dam, mtmp); res = 1; } stop_occupation(); return(res); } diff --git a/games/hack/hack.mklev.c b/games/hack/hack.mklev.c index cad724f81bf5..760c4016e8ca 100644 --- a/games/hack/hack.mklev.c +++ b/games/hack/hack.mklev.c @@ -1,744 +1,744 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mklev.c - version 1.0.3 */ /* $FreeBSD$ */ #include #include #include "hack.h" extern struct monst *makemon(); extern struct obj *mkobj_at(); extern struct trap *maketrap(); #define somex() ((random()%(croom->hx-croom->lx+1))+croom->lx) #define somey() ((random()%(croom->hy-croom->ly+1))+croom->ly) #include "def.mkroom.h" #define XLIM 4 /* define minimum required space around a room */ #define YLIM 3 boolean secret; /* TRUE while making a vault: increase [XY]LIM */ struct mkroom rooms[MAXNROFROOMS+1]; int smeq[MAXNROFROOMS+1]; coord doors[DOORMAX]; int doorindex; struct rm zerorm; int comp(); schar nxcor; boolean goldseen; int nroom; xchar xdnstair,xupstair,ydnstair,yupstair; /* Definitions used by makerooms() and addrs() */ #define MAXRS 50 /* max lth of temp rectangle table - arbitrary */ struct rectangle { xchar rlx,rly,rhx,rhy; } rs[MAXRS+1]; int rscnt,rsmax; /* 0..rscnt-1: currently under consideration */ /* rscnt..rsmax: discarded */ makelevel() { - register struct mkroom *croom, *troom; - register unsigned tryct; - register x,y; + struct mkroom *croom, *troom; + unsigned tryct; + x,y; nroom = 0; doorindex = 0; rooms[0].hx = -1; /* in case we are in a maze */ for(x=0; x= rn1(3, 26)) { /* there might be several mazes */ makemaz(); return; } /* construct the rooms */ nroom = 0; secret = FALSE; (void) makerooms(); /* construct stairs (up and down in different rooms if possible) */ croom = &rooms[rn2(nroom)]; xdnstair = somex(); ydnstair = somey(); levl[xdnstair][ydnstair].scrsym ='>'; levl[xdnstair][ydnstair].typ = STAIRS; if(nroom > 1) { troom = croom; croom = &rooms[rn2(nroom-1)]; if(croom >= troom) croom++; } xupstair = somex(); /* %% < and > might be in the same place */ yupstair = somey(); levl[xupstair][yupstair].scrsym ='<'; levl[xupstair][yupstair].typ = STAIRS; /* for each room: put things inside */ for(croom = rooms; croom->hx > 0; croom++) { /* put a sleeping monster inside */ /* Note: monster may be on the stairs. This cannot be avoided: maybe the player fell through a trapdoor while a monster was on the stairs. Conclusion: we have to check for monsters on the stairs anyway. */ if(!rn2(3)) (void) makemon((struct permonst *) 0, somex(), somey()); /* put traps and mimics inside */ goldseen = FALSE; while(!rn2(8-(dlevel/6))) mktrap(0,0,croom); if(!goldseen && !rn2(3)) mkgold(0L,somex(),somey()); if(!rn2(3)) { (void) mkobj_at(0, somex(), somey()); tryct = 0; while(!rn2(5)) { if(++tryct > 100){ printf("tryct overflow4\n"); break; } (void) mkobj_at(0, somex(), somey()); } } } qsort((char *) rooms, nroom, sizeof(struct mkroom), comp); makecorridors(); make_niches(); /* make a secret treasure vault, not connected to the rest */ if(nroom <= (2*MAXNROFROOMS/3)) if(rn2(3)) { troom = &rooms[nroom]; secret = TRUE; if(makerooms()) { troom->rtype = VAULT; /* treasure vault */ for(x = troom->lx; x <= troom->hx; x++) for(y = troom->ly; y <= troom->hy; y++) mkgold((long)(rnd(dlevel*100) + 50), x, y); if(!rn2(3)) makevtele(); } } #ifndef QUEST #ifdef WIZARD if(wizard && getenv("SHOPTYPE")) mkshop(); else #endif WIZARD if(dlevel > 1 && dlevel < 20 && rn2(dlevel) < 3) mkshop(); else if(dlevel > 6 && !rn2(7)) mkzoo(ZOO); else if(dlevel > 9 && !rn2(5)) mkzoo(BEEHIVE); else if(dlevel > 11 && !rn2(6)) mkzoo(MORGUE); else if(dlevel > 18 && !rn2(6)) mkswamp(); #endif QUEST } makerooms() { -register struct rectangle *rsp; -register int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy; +struct rectangle *rsp; +int lx, ly, hx, hy, lowx, lowy, hix, hiy, dx, dy; int tryct = 0, xlim, ylim; /* init */ xlim = XLIM + secret; ylim = YLIM + secret; if(nroom == 0) { rsp = rs; rsp->rlx = rsp->rly = 0; rsp->rhx = COLNO-1; rsp->rhy = ROWNO-1; rsmax = 1; } rscnt = rsmax; /* make rooms until satisfied */ while(rscnt > 0 && nroom < MAXNROFROOMS-1) { if(!secret && nroom > (MAXNROFROOMS/3) && !rn2((MAXNROFROOMS-nroom)*(MAXNROFROOMS-nroom))) return(0); /* pick a rectangle */ rsp = &rs[rn2(rscnt)]; hx = rsp->rhx; hy = rsp->rhy; lx = rsp->rlx; ly = rsp->rly; /* find size of room */ if(secret) dx = dy = 1; else { dx = 2 + rn2((hx-lx-8 > 20) ? 12 : 8); dy = 2 + rn2(4); if(dx*dy > 50) dy = 50/dx; } /* look whether our room will fit */ if(hx-lx < dx + dx/2 + 2*xlim || hy-ly < dy + dy/3 + 2*ylim) { /* no, too small */ /* maybe we throw this area out */ if(secret || !rn2(MAXNROFROOMS+1-nroom-tryct)) { rscnt--; rs[rsmax] = *rsp; *rsp = rs[rscnt]; rs[rscnt] = rs[rsmax]; tryct = 0; } else tryct++; continue; } lowx = lx + xlim + rn2(hx - lx - dx - 2*xlim + 1); lowy = ly + ylim + rn2(hy - ly - dy - 2*ylim + 1); hix = lowx + dx; hiy = lowy + dy; if(maker(lowx, dx, lowy, dy)) { if(secret) return(1); addrs(lowx-1, lowy-1, hix+1, hiy+1); tryct = 0; } else if(tryct++ > 100) break; } return(0); /* failed to make vault - very strange */ } addrs(lowx,lowy,hix,hiy) -register int lowx,lowy,hix,hiy; +int lowx,lowy,hix,hiy; { - register struct rectangle *rsp; - register int lx,ly,hx,hy,xlim,ylim; + struct rectangle *rsp; + int lx,ly,hx,hy,xlim,ylim; boolean discarded; xlim = XLIM + secret; ylim = YLIM + secret; /* walk down since rscnt and rsmax change */ for(rsp = &rs[rsmax-1]; rsp >= rs; rsp--) { if((lx = rsp->rlx) > hix || (ly = rsp->rly) > hiy || (hx = rsp->rhx) < lowx || (hy = rsp->rhy) < lowy) continue; if((discarded = (rsp >= &rs[rscnt]))) { *rsp = rs[--rsmax]; } else { rsmax--; rscnt--; *rsp = rs[rscnt]; if(rscnt != rsmax) rs[rscnt] = rs[rsmax]; } if(lowy - ly > 2*ylim + 4) addrsx(lx,ly,hx,lowy-2,discarded); if(lowx - lx > 2*xlim + 4) addrsx(lx,ly,lowx-2,hy,discarded); if(hy - hiy > 2*ylim + 4) addrsx(lx,hiy+2,hx,hy,discarded); if(hx - hix > 2*xlim + 4) addrsx(hix+2,ly,hx,hy,discarded); } } addrsx(lx,ly,hx,hy,discarded) -register int lx,ly,hx,hy; +int lx,ly,hx,hy; boolean discarded; /* piece of a discarded area */ { - register struct rectangle *rsp; + struct rectangle *rsp; /* check inclusions */ for(rsp = rs; rsp < &rs[rsmax]; rsp++) { if(lx >= rsp->rlx && hx <= rsp->rhx && ly >= rsp->rly && hy <= rsp->rhy) return; } /* make a new entry */ if(rsmax >= MAXRS) { #ifdef WIZARD if(wizard) pline("MAXRS may be too small."); #endif WIZARD return; } rsmax++; if(!discarded) { *rsp = rs[rscnt]; rsp = &rs[rscnt]; rscnt++; } rsp->rlx = lx; rsp->rly = ly; rsp->rhx = hx; rsp->rhy = hy; } comp(x,y) -register struct mkroom *x,*y; +struct mkroom *x,*y; { if(x->lx < y->lx) return(-1); return(x->lx > y->lx); } coord finddpos(xl,yl,xh,yh) { coord ff; - register x,y; + x,y; x = (xl == xh) ? xl : (xl + rn2(xh-xl+1)); y = (yl == yh) ? yl : (yl + rn2(yh-yl+1)); if(okdoor(x, y)) goto gotit; for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) if(okdoor(x, y)) goto gotit; for(x = xl; x <= xh; x++) for(y = yl; y <= yh; y++) if(levl[x][y].typ == DOOR || levl[x][y].typ == SDOOR) goto gotit; /* cannot find something reasonable -- strange */ x = xl; y = yh; gotit: ff.x = x; ff.y = y; return(ff); } /* see whether it is allowable to create a door at [x,y] */ okdoor(x,y) -register x,y; +x,y; { if(levl[x-1][y].typ == DOOR || levl[x+1][y].typ == DOOR || levl[x][y+1].typ == DOOR || levl[x][y-1].typ == DOOR || levl[x-1][y].typ == SDOOR || levl[x+1][y].typ == SDOOR || levl[x][y-1].typ == SDOOR || levl[x][y+1].typ == SDOOR || (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) || doorindex >= DOORMAX) return(0); return(1); } dodoor(x,y,aroom) -register x,y; -register struct mkroom *aroom; +x,y; +struct mkroom *aroom; { if(doorindex >= DOORMAX) { impossible("DOORMAX exceeded?"); return; } if(!okdoor(x,y) && nxcor) return; dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR); } dosdoor(x,y,aroom,type) -register x,y; -register struct mkroom *aroom; -register type; +x,y; +struct mkroom *aroom; +type; { - register struct mkroom *broom; - register tmp; + struct mkroom *broom; + tmp; if(!IS_WALL(levl[x][y].typ)) /* avoid SDOORs with '+' as scrsym */ type = DOOR; levl[x][y].typ = type; if(type == DOOR) levl[x][y].scrsym = '+'; aroom->doorct++; broom = aroom+1; if(broom->hx < 0) tmp = doorindex; else for(tmp = doorindex; tmp > broom->fdoor; tmp--) doors[tmp] = doors[tmp-1]; doorindex++; doors[tmp].x = x; doors[tmp].y = y; for( ; broom->hx >= 0; broom++) broom->fdoor++; } /* Only called from makerooms() */ maker(lowx,ddx,lowy,ddy) schar lowx,ddx,lowy,ddy; { - register struct mkroom *croom; - register x, y, hix = lowx+ddx, hiy = lowy+ddy; - register xlim = XLIM + secret, ylim = YLIM + secret; + struct mkroom *croom; + x, y, hix = lowx+ddx, hiy = lowy+ddy; + xlim = XLIM + secret, ylim = YLIM + secret; if(nroom >= MAXNROFROOMS) return(0); if(lowx < XLIM) lowx = XLIM; if(lowy < YLIM) lowy = YLIM; if(hix > COLNO-XLIM-1) hix = COLNO-XLIM-1; if(hiy > ROWNO-YLIM-1) hiy = ROWNO-YLIM-1; chk: if(hix <= lowx || hiy <= lowy) return(0); /* check area around room (and make room smaller if necessary) */ for(x = lowx - xlim; x <= hix + xlim; x++) { for(y = lowy - ylim; y <= hiy + ylim; y++) { if(levl[x][y].typ) { #ifdef WIZARD if(wizard && !secret) pline("Strange area [%d,%d] in maker().",x,y); #endif WIZARD if(!rn2(3)) return(0); if(x < lowx) lowx = x+xlim+1; else hix = x-xlim-1; if(y < lowy) lowy = y+ylim+1; else hiy = y-ylim-1; goto chk; } } } croom = &rooms[nroom]; /* on low levels the room is lit (usually) */ /* secret vaults are always lit */ if((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1)) { for(x = lowx-1; x <= hix+1; x++) for(y = lowy-1; y <= hiy+1; y++) levl[x][y].lit = 1; croom->rlit = 1; } else croom->rlit = 0; croom->lx = lowx; croom->hx = hix; croom->ly = lowy; croom->hy = hiy; croom->rtype = croom->doorct = croom->fdoor = 0; for(x = lowx-1; x <= hix+1; x++) for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) { levl[x][y].scrsym = '-'; levl[x][y].typ = HWALL; } for(x = lowx-1; x <= hix+1; x += (hix-lowx+2)) for(y = lowy; y <= hiy; y++) { levl[x][y].scrsym = '|'; levl[x][y].typ = VWALL; } for(x = lowx; x <= hix; x++) for(y = lowy; y <= hiy; y++) { levl[x][y].scrsym = '.'; levl[x][y].typ = ROOM; } smeq[nroom] = nroom; croom++; croom->hx = -1; nroom++; return(1); } makecorridors() { - register a,b; + a,b; nxcor = 0; for(a = 0; a < nroom-1; a++) join(a, a+1); for(a = 0; a < nroom-2; a++) if(smeq[a] != smeq[a+2]) join(a, a+2); for(a = 0; a < nroom; a++) for(b = 0; b < nroom; b++) if(smeq[a] != smeq[b]) join(a, b); if(nroom > 2) for(nxcor = rn2(nroom) + 4; nxcor; nxcor--) { a = rn2(nroom); b = rn2(nroom-2); if(b >= a) b += 2; join(a, b); } } join(a,b) -register a,b; +a,b; { coord cc,tt; - register tx, ty, xx, yy; - register struct rm *crm; - register struct mkroom *croom, *troom; - register dx, dy, dix, diy, cct; + tx, ty, xx, yy; + struct rm *crm; + struct mkroom *croom, *troom; + dx, dy, dix, diy, cct; croom = &rooms[a]; troom = &rooms[b]; /* find positions cc and tt for doors in croom and troom and direction for a corridor between them */ if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return; if(troom->lx > croom->hx) { dx = 1; dy = 0; xx = croom->hx+1; tx = troom->lx-1; cc = finddpos(xx,croom->ly,xx,croom->hy); tt = finddpos(tx,troom->ly,tx,troom->hy); } else if(troom->hy < croom->ly) { dy = -1; dx = 0; yy = croom->ly-1; cc = finddpos(croom->lx,yy,croom->hx,yy); ty = troom->hy+1; tt = finddpos(troom->lx,ty,troom->hx,ty); } else if(troom->hx < croom->lx) { dx = -1; dy = 0; xx = croom->lx-1; tx = troom->hx+1; cc = finddpos(xx,croom->ly,xx,croom->hy); tt = finddpos(tx,troom->ly,tx,troom->hy); } else { dy = 1; dx = 0; yy = croom->hy+1; ty = troom->ly-1; cc = finddpos(croom->lx,yy,croom->hx,yy); tt = finddpos(troom->lx,ty,troom->hx,ty); } xx = cc.x; yy = cc.y; tx = tt.x - dx; ty = tt.y - dy; if(nxcor && levl[xx+dx][yy+dy].typ) return; dodoor(xx,yy,croom); cct = 0; while(xx != tx || yy != ty) { xx += dx; yy += dy; /* loop: dig corridor at [xx,yy] and find new [xx,yy] */ if(cct++ > 500 || (nxcor && !rn2(35))) return; if(xx == COLNO-1 || xx == 0 || yy == 0 || yy == ROWNO-1) return; /* impossible */ crm = &levl[xx][yy]; if(!(crm->typ)) { if(rn2(100)) { crm->typ = CORR; crm->scrsym = CORR_SYM; if(nxcor && !rn2(50)) (void) mkobj_at(ROCK_SYM, xx, yy); } else { crm->typ = SCORR; crm->scrsym = ' '; } } else if(crm->typ != CORR && crm->typ != SCORR) { /* strange ... */ return; } /* find next corridor position */ dix = abs(xx-tx); diy = abs(yy-ty); /* do we have to change direction ? */ if(dy && dix > diy) { - register ddx = (xx > tx) ? -1 : 1; + ddx = (xx > tx) ? -1 : 1; crm = &levl[xx+ddx][yy]; if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) { dx = ddx; dy = 0; continue; } } else if(dx && diy > dix) { - register ddy = (yy > ty) ? -1 : 1; + ddy = (yy > ty) ? -1 : 1; crm = &levl[xx][yy+ddy]; if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) { dy = ddy; dx = 0; continue; } } /* continue straight on? */ crm = &levl[xx+dx][yy+dy]; if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) continue; /* no, what must we do now?? */ if(dx) { dx = 0; dy = (ty < yy) ? -1 : 1; crm = &levl[xx+dx][yy+dy]; if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) continue; dy = -dy; continue; } else { dy = 0; dx = (tx < xx) ? -1 : 1; crm = &levl[xx+dx][yy+dy]; if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) continue; dx = -dx; continue; } } /* we succeeded in digging the corridor */ dodoor(tt.x, tt.y, troom); if(smeq[a] < smeq[b]) smeq[b] = smeq[a]; else smeq[a] = smeq[b]; } make_niches() { - register int ct = rnd(nroom/2 + 1); + int ct = rnd(nroom/2 + 1); while(ct--) makeniche(FALSE); } makevtele() { makeniche(TRUE); } makeniche(with_trap) boolean with_trap; { - register struct mkroom *aroom; - register struct rm *rm; - register int vct = 8; + struct mkroom *aroom; + struct rm *rm; + int vct = 8; coord dd; - register dy,xx,yy; - register struct trap *ttmp; + dy,xx,yy; + struct trap *ttmp; if(doorindex < DOORMAX) while(vct--) { aroom = &rooms[rn2(nroom-1)]; if(aroom->rtype != 0) continue; /* not an ordinary room */ if(aroom->doorct == 1 && rn2(5)) continue; if(rn2(2)) { dy = 1; dd = finddpos(aroom->lx,aroom->hy+1,aroom->hx,aroom->hy+1); } else { dy = -1; dd = finddpos(aroom->lx,aroom->ly-1,aroom->hx,aroom->ly-1); } xx = dd.x; yy = dd.y; if((rm = &levl[xx][yy+dy])->typ) continue; if(with_trap || !rn2(4)) { rm->typ = SCORR; rm->scrsym = ' '; if(with_trap) { ttmp = maketrap(xx, yy+dy, TELEP_TRAP); ttmp->once = 1; make_engr_at(xx, yy-dy, "ad ae?ar um"); } dosdoor(xx, yy, aroom, SDOOR); } else { rm->typ = CORR; rm->scrsym = CORR_SYM; if(rn2(7)) dosdoor(xx, yy, aroom, rn2(5) ? SDOOR : DOOR); else { mksobj_at(SCR_TELEPORTATION, xx, yy+dy); if(!rn2(3)) (void) mkobj_at(0, xx, yy+dy); } } return; } } /* make a trap somewhere (in croom if mazeflag = 0) */ mktrap(num,mazeflag,croom) -register num,mazeflag; -register struct mkroom *croom; +num,mazeflag; +struct mkroom *croom; { - register struct trap *ttmp; - register int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0; - register xchar mx,my; + struct trap *ttmp; + int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0; + xchar mx,my; extern char fut_geno[]; if(!num || num >= TRAPNUM) { nopierc = (dlevel < 4) ? 1 : 0; nomimic = (dlevel < 9 || goldseen ) ? 1 : 0; if(index(fut_geno, 'M')) nomimic = 1; kind = rn2(TRAPNUM - nopierc - nomimic); /* note: PIERC = 7, MIMIC = 8, TRAPNUM = 9 */ } else kind = num; if(kind == MIMIC) { - register struct monst *mtmp; + struct monst *mtmp; fakedoor = (!rn2(3) && !mazeflag); fakegold = (!fakedoor && !rn2(2)); if(fakegold) goldseen = TRUE; do { if(++tryct > 200) return; if(fakedoor) { /* note: fakedoor maybe on actual door */ if(rn2(2)){ if(rn2(2)) mx = croom->hx+1; else mx = croom->lx-1; my = somey(); } else { if(rn2(2)) my = croom->hy+1; else my = croom->ly-1; mx = somex(); } } else if(mazeflag) { extern coord mazexy(); coord mm; mm = mazexy(); mx = mm.x; my = mm.y; } else { mx = somex(); my = somey(); } } while(m_at(mx,my) || levl[mx][my].typ == STAIRS); if(mtmp = makemon(PM_MIMIC,mx,my)) { mtmp->mimic = 1; mtmp->mappearance = fakegold ? '$' : fakedoor ? '+' : (mazeflag && rn2(2)) ? AMULET_SYM : "=/)%?![<>" [ rn2(9) ]; } return; } do { if(++tryct > 200) return; if(mazeflag){ extern coord mazexy(); coord mm; mm = mazexy(); mx = mm.x; my = mm.y; } else { mx = somex(); my = somey(); } } while(t_at(mx, my) || levl[mx][my].typ == STAIRS); ttmp = maketrap(mx, my, kind); if(mazeflag && !rn2(10) && ttmp->ttyp < PIERC) ttmp->tseen = 1; } diff --git a/games/hack/hack.mkmaze.c b/games/hack/hack.mkmaze.c index 66cf634588a0..620d83ba4369 100644 --- a/games/hack/hack.mkmaze.c +++ b/games/hack/hack.mkmaze.c @@ -1,137 +1,137 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mkmaze.c - version 1.0.2 */ /* $FreeBSD$ */ #include "hack.h" #include "def.mkroom.h" /* not really used */ extern struct monst *makemon(); extern struct permonst pm_wizard; extern struct obj *mkobj_at(); extern coord mazexy(); struct permonst hell_hound = { "hell hound", 'd', 12, 14, 2, 3, 6, 0 }; makemaz() { int x,y; - register zx,zy; + zx,zy; coord mm; boolean al = (dlevel >= 30 && !flags.made_amulet); for(x = 2; x < COLNO-1; x++) for(y = 2; y < ROWNO-1; y++) levl[x][y].typ = (x%2 && y%2) ? 0 : HWALL; if(al) { - register struct monst *mtmp; + struct monst *mtmp; zx = 2*(COLNO/4) - 1; zy = 2*(ROWNO/4) - 1; for(x = zx-2; x < zx+4; x++) for(y = zy-2; y <= zy+2; y++) { levl[x][y].typ = (y == zy-2 || y == zy+2 || x == zx-2 || x == zx+3) ? POOL : (y == zy-1 || y == zy+1 || x == zx-1 || x == zx+2) ? HWALL: ROOM; } (void) mkobj_at(AMULET_SYM, zx, zy); flags.made_amulet = 1; walkfrom(zx+4, zy); if(mtmp = makemon(&hell_hound, zx, zy)) mtmp->msleep = 1; if(mtmp = makemon(PM_WIZARD, zx+1, zy)) { mtmp->msleep = 1; flags.no_of_wizards = 1; } } else { mm = mazexy(); zx = mm.x; zy = mm.y; walkfrom(zx,zy); (void) mksobj_at(WAN_WISHING, zx, zy); (void) mkobj_at(ROCK_SYM, zx, zy); /* put a rock on top of it */ } for(x = 2; x < COLNO-1; x++) for(y = 2; y < ROWNO-1; y++) { switch(levl[x][y].typ) { case HWALL: levl[x][y].scrsym = '-'; break; case ROOM: levl[x][y].scrsym = '.'; break; } } for(x = rn1(8,11); x; x--) { mm = mazexy(); (void) mkobj_at(rn2(2) ? GEM_SYM : 0, mm.x, mm.y); } for(x = rn1(10,2); x; x--) { mm = mazexy(); (void) mkobj_at(ROCK_SYM, mm.x, mm.y); } mm = mazexy(); (void) makemon(PM_MINOTAUR, mm.x, mm.y); for(x = rn1(5,7); x; x--) { mm = mazexy(); (void) makemon((struct permonst *) 0, mm.x, mm.y); } for(x = rn1(6,7); x; x--) { mm = mazexy(); mkgold(0L,mm.x,mm.y); } for(x = rn1(6,7); x; x--) mktrap(0,1,(struct mkroom *) 0); mm = mazexy(); levl[(xupstair = mm.x)][(yupstair = mm.y)].scrsym = '<'; levl[xupstair][yupstair].typ = STAIRS; xdnstair = ydnstair = 0; } walkfrom(x,y) int x,y; { -register int q,a,dir; +int q,a,dir; int dirs[4]; levl[x][y].typ = ROOM; while(1) { q = 0; for(a = 0; a < 4; a++) if(okay(x,y,a)) dirs[q++]= a; if(!q) return; dir = dirs[rn2(q)]; move(&x,&y,dir); levl[x][y].typ = ROOM; move(&x,&y,dir); walkfrom(x,y); } } move(x,y,dir) -register int *x, *y; -register int dir; +int *x, *y; +int dir; { switch(dir){ case 0: --(*y); break; case 1: (*x)++; break; case 2: (*y)++; break; case 3: --(*x); break; } } okay(x,y,dir) int x,y; -register int dir; +int dir; { move(&x,&y,dir); move(&x,&y,dir); if(x<3 || y<3 || x>COLNO-3 || y>ROWNO-3 || levl[x][y].typ != 0) return(0); else return(1); } coord mazexy(){ coord mm; mm.x = 3 + 2*rn2(COLNO/2 - 2); mm.y = 3 + 2*rn2(ROWNO/2 - 2); return mm; } diff --git a/games/hack/hack.mkobj.c b/games/hack/hack.mkobj.c index d377e2177d39..61b4235c9d14 100644 --- a/games/hack/hack.mkobj.c +++ b/games/hack/hack.mkobj.c @@ -1,149 +1,149 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mkobj.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%"; struct obj *mkobj(), *mksobj(); struct obj * mkobj_at(let,x,y) -register let,x,y; +let,x,y; { - register struct obj *otmp = mkobj(let); + struct obj *otmp = mkobj(let); otmp->ox = x; otmp->oy = y; otmp->nobj = fobj; fobj = otmp; return(otmp); } mksobj_at(otyp,x,y) -register otyp,x,y; +otyp,x,y; { - register struct obj *otmp = mksobj(otyp); + struct obj *otmp = mksobj(otyp); otmp->ox = x; otmp->oy = y; otmp->nobj = fobj; fobj = otmp; } struct obj * mkobj(let) { if(!let) let = mkobjstr[rn2(sizeof(mkobjstr) - 1)]; return( mksobj( letter(let) ? CORPSE + ((let > 'Z') ? (let-'a'+'Z'-'@'+1) : (let-'@')) : probtype(let) ) ); } struct obj zeroobj; struct obj * mksobj(otyp) -register otyp; +otyp; { - register struct obj *otmp; + struct obj *otmp; char let = objects[otyp].oc_olet; otmp = newobj(0); *otmp = zeroobj; otmp->age = moves; otmp->o_id = flags.ident++; otmp->quan = 1; otmp->olet = let; otmp->otyp = otyp; otmp->dknown = index("/=!?*", let) ? 0 : 1; switch(let) { case WEAPON_SYM: otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1; if(!rn2(11)) otmp->spe = rnd(3); else if(!rn2(10)) { otmp->cursed = 1; otmp->spe = -rnd(3); } break; case FOOD_SYM: if(otmp->otyp >= CORPSE) break; #ifdef NOT_YET_IMPLEMENTED /* if tins are to be identified, need to adapt doname() etc */ if(otmp->otyp == TIN) otmp->spe = rnd(...); #endif NOT_YET_IMPLEMENTED /* fall into next case */ case GEM_SYM: otmp->quan = rn2(6) ? 1 : 2; case TOOL_SYM: case CHAIN_SYM: case BALL_SYM: case ROCK_SYM: case POTION_SYM: case SCROLL_SYM: case AMULET_SYM: break; case ARMOR_SYM: if(!rn2(8)) otmp->cursed = 1; if(!rn2(10)) otmp->spe = rnd(3); else if(!rn2(9)) { otmp->spe = -rnd(3); otmp->cursed = 1; } break; case WAND_SYM: if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else otmp->spe = rn1(5, (objects[otmp->otyp].bits & NODIR) ? 11 : 4); break; case RING_SYM: if(objects[otmp->otyp].bits & SPEC) { if(!rn2(3)) { otmp->cursed = 1; otmp->spe = -rnd(2); } else otmp->spe = rnd(2); } else if(otmp->otyp == RIN_TELEPORTATION || otmp->otyp == RIN_AGGRAVATE_MONSTER || otmp->otyp == RIN_HUNGER || !rn2(9)) otmp->cursed = 1; break; default: panic("impossible mkobj"); } otmp->owt = weight(otmp); return(otmp); } letter(c) { return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); } weight(obj) -register struct obj *obj; +struct obj *obj; { -register int wt = objects[obj->otyp].oc_weight; +int wt = objects[obj->otyp].oc_weight; return(wt ? wt*obj->quan : (obj->quan + 1)/2); } mkgold(num,x,y) -register long num; +long num; { - register struct gold *gold; - register long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30))); + struct gold *gold; + long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30))); if(gold = g_at(x,y)) gold->amount += amount; else { gold = newgold(); gold->ngold = fgold; gold->gx = x; gold->gy = y; gold->amount = amount; fgold = gold; /* do sth with display? */ } } diff --git a/games/hack/hack.mkshop.c b/games/hack/hack.mkshop.c index 2ed2d4160f22..289368caf47d 100644 --- a/games/hack/hack.mkshop.c +++ b/games/hack/hack.mkshop.c @@ -1,275 +1,275 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mkshop.c - version 1.0.3 */ /* $FreeBSD$ */ #ifndef QUEST #include "hack.h" #include "def.mkroom.h" #include "def.eshk.h" #include #define ESHK ((struct eshk *)(&(shk->mextra[0]))) extern struct monst *makemon(); extern struct obj *mkobj_at(); extern int nroom; extern char shtypes[]; /* = "=/)%?!["; 8 types: 7 specialized, 1 mixed */ schar shprobs[] = { 3,3,5,5,10,10,14,50 }; /* their probabilities */ mkshop(){ -register struct mkroom *sroom; -register int sh,sx,sy,i = -1; -register char let; +struct mkroom *sroom; +int sh,sx,sy,i = -1; +char let; int roomno; -register struct monst *shk; +struct monst *shk; #ifdef WIZARD /* first determine shoptype */ if(wizard){ - register char *ep = getenv("SHOPTYPE"); + char *ep = getenv("SHOPTYPE"); if(ep){ if(*ep == 'z' || *ep == 'Z'){ mkzoo(ZOO); return; } if(*ep == 'm' || *ep == 'M'){ mkzoo(MORGUE); return; } if(*ep == 'b' || *ep == 'B'){ mkzoo(BEEHIVE); return; } if(*ep == 's' || *ep == 'S'){ mkswamp(); return; } for(i=0; shtypes[i]; i++) if(*ep == shtypes[i]) break; goto gottype; } } gottype: #endif WIZARD for(sroom = &rooms[0], roomno = 0; ; sroom++, roomno++){ if(sroom->hx < 0) return; if(sroom - rooms >= nroom) { pline("rooms not closed by -1?"); return; } if(sroom->rtype) continue; if(!sroom->rlit || has_dnstairs(sroom) || has_upstairs(sroom)) continue; if( #ifdef WIZARD (wizard && getenv("SHOPTYPE") && sroom->doorct != 0) || #endif WIZARD sroom->doorct <= 2 && sroom->doorct > 0) break; } if(i < 0) { /* shoptype not yet determined */ - register int j; + int j; for(j = rn2(100), i = 0; (j -= shprobs[i])>= 0; i++) if(!shtypes[i]) break; /* superfluous */ if(isbig(sroom) && i + SHOPBASE == WANDSHOP) i = GENERAL-SHOPBASE; } sroom->rtype = i + SHOPBASE; let = shtypes[i]; sh = sroom->fdoor; sx = doors[sh].x; sy = doors[sh].y; if(sx == sroom->lx-1) sx++; else if(sx == sroom->hx+1) sx--; else if(sy == sroom->ly-1) sy++; else if(sy == sroom->hy+1) sy--; else { #ifdef WIZARD /* This is said to happen sometimes, but I've never seen it. */ if(wizard) { - register int j = sroom->doorct; + int j = sroom->doorct; extern int doorindex; pline("Where is shopdoor?"); pline("Room at (%d,%d),(%d,%d).", sroom->lx, sroom->ly, sroom->hx, sroom->hy); pline("doormax=%d doorct=%d fdoor=%d", doorindex, sroom->doorct, sh); while(j--) { pline("door [%d,%d]", doors[sh].x, doors[sh].y); sh++; } more(); } #endif WIZARD return; } if(!(shk = makemon(PM_SHK,sx,sy))) return; shk->isshk = shk->mpeaceful = 1; shk->msleep = 0; shk->mtrapseen = ~0; /* we know all the traps already */ ESHK->shoproom = roomno; ESHK->shoplevel = dlevel; ESHK->shd = doors[sh]; ESHK->shk.x = sx; ESHK->shk.y = sy; ESHK->robbed = 0; ESHK->visitct = 0; ESHK->following = 0; shk->mgold = 1000 + 30*rnd(100); /* initial capital */ ESHK->billct = 0; findname(ESHK->shknam, let); for(sx = sroom->lx; sx <= sroom->hx; sx++) for(sy = sroom->ly; sy <= sroom->hy; sy++){ - register struct monst *mtmp; + struct monst *mtmp; if((sx == sroom->lx && doors[sh].x == sx-1) || (sx == sroom->hx && doors[sh].x == sx+1) || (sy == sroom->ly && doors[sh].y == sy-1) || (sy == sroom->hy && doors[sh].y == sy+1)) continue; if(rn2(100) < dlevel && !m_at(sx,sy) && (mtmp = makemon(PM_MIMIC, sx, sy))){ mtmp->mimic = 1; mtmp->mappearance = (let && rn2(10) < dlevel) ? let : ']'; continue; } (void) mkobj_at(let, sx, sy); } } mkzoo(type) int type; { - register struct mkroom *sroom; - register struct monst *mon; - register int sh,sx,sy,i; + struct mkroom *sroom; + struct monst *mon; + int sh,sx,sy,i; int goldlim = 500 * dlevel; int moct = 0; struct permonst *morguemon(); i = nroom; for(sroom = &rooms[rn2(nroom)]; ; sroom++) { if(sroom == &rooms[nroom]) sroom = &rooms[0]; if(!i-- || sroom->hx < 0) return; if(sroom->rtype) continue; if(type == MORGUE && sroom->rlit) continue; if(has_upstairs(sroom) || (has_dnstairs(sroom) && rn2(3))) continue; if(sroom->doorct == 1 || !rn2(5)) break; } sroom->rtype = type; sh = sroom->fdoor; for(sx = sroom->lx; sx <= sroom->hx; sx++) for(sy = sroom->ly; sy <= sroom->hy; sy++){ if((sx == sroom->lx && doors[sh].x == sx-1) || (sx == sroom->hx && doors[sh].x == sx+1) || (sy == sroom->ly && doors[sh].y == sy-1) || (sy == sroom->hy && doors[sh].y == sy+1)) continue; mon = makemon( (type == MORGUE) ? morguemon() : (type == BEEHIVE) ? PM_KILLER_BEE : (struct permonst *) 0, sx, sy); if(mon) mon->msleep = 1; switch(type) { case ZOO: i = sq(dist2(sx,sy,doors[sh].x,doors[sh].y)); if(i >= goldlim) i = 5*dlevel; goldlim -= i; mkgold((long)(10 + rn2(i)), sx, sy); break; case MORGUE: /* Usually there is one dead body in the morgue */ if(!moct && rn2(3)) { mksobj_at(CORPSE, sx, sy); moct++; } break; case BEEHIVE: if(!rn2(3)) mksobj_at(LUMP_OF_ROYAL_JELLY, sx, sy); break; } } } struct permonst * morguemon() { extern struct permonst pm_ghost; - register int i = rn2(100), hd = rn2(dlevel); + int i = rn2(100), hd = rn2(dlevel); if(hd > 10 && i < 10) return(PM_DEMON); if(hd > 8 && i > 85) return(PM_VAMPIRE); return((i < 40) ? PM_GHOST : (i < 60) ? PM_WRAITH : PM_ZOMBIE); } mkswamp() /* Michiel Huisjes & Fred de Wilde */ { - register struct mkroom *sroom; - register int sx,sy,i,eelct = 0; + struct mkroom *sroom; + int sx,sy,i,eelct = 0; extern struct permonst pm_eel; for(i=0; i<5; i++) { /* 5 tries */ sroom = &rooms[rn2(nroom)]; if(sroom->hx < 0 || sroom->rtype || has_upstairs(sroom) || has_dnstairs(sroom)) continue; /* satisfied; make a swamp */ sroom->rtype = SWAMP; for(sx = sroom->lx; sx <= sroom->hx; sx++) for(sy = sroom->ly; sy <= sroom->hy; sy++) if((sx+sy)%2 && !o_at(sx,sy) && !t_at(sx,sy) && !m_at(sx,sy) && !nexttodoor(sx,sy)){ levl[sx][sy].typ = POOL; levl[sx][sy].scrsym = POOL_SYM; if(!eelct || !rn2(4)) { (void) makemon(PM_EEL, sx, sy); eelct++; } } } } nexttodoor(sx,sy) -register sx,sy; +sx,sy; { - register dx,dy; - register struct rm *lev; + dx,dy; + struct rm *lev; for(dx = -1; dx <= 1; dx++) for(dy = -1; dy <= 1; dy++) if((lev = &levl[sx+dx][sy+dy])->typ == DOOR || lev->typ == SDOOR || lev->typ == LDOOR) return(1); return(0); } has_dnstairs(sroom) -register struct mkroom *sroom; +struct mkroom *sroom; { return(sroom->lx <= xdnstair && xdnstair <= sroom->hx && sroom->ly <= ydnstair && ydnstair <= sroom->hy); } has_upstairs(sroom) -register struct mkroom *sroom; +struct mkroom *sroom; { return(sroom->lx <= xupstair && xupstair <= sroom->hx && sroom->ly <= yupstair && yupstair <= sroom->hy); } isbig(sroom) -register struct mkroom *sroom; +struct mkroom *sroom; { - register int area = (sroom->hx - sroom->lx) * (sroom->hy - sroom->ly); + int area = (sroom->hx - sroom->lx) * (sroom->hy - sroom->ly); return( area > 20 ); } dist2(x0,y0,x1,y1){ return((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1)); } sq(a) int a; { return(a*a); } #endif QUEST diff --git a/games/hack/hack.mon.c b/games/hack/hack.mon.c index 237fada71f69..90511b1af350 100644 --- a/games/hack/hack.mon.c +++ b/games/hack/hack.mon.c @@ -1,854 +1,854 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.mon.c - version 1.0.3 */ /* $FreeBSD$ */ #include "hack.h" #include "hack.mfndpos.h" #ifndef NULL #define NULL (char *) 0 #endif extern struct monst *makemon(); extern struct obj *mkobj_at(); int warnlevel; /* used by movemon and dochugw */ long lastwarntime; int lastwarnlev; char *warnings[] = { "white", "pink", "red", "ruby", "purple", "black" }; movemon() { - register struct monst *mtmp; - register int fr; + struct monst *mtmp; + int fr; warnlevel = 0; while(1) { /* find a monster that we haven't treated yet */ /* note that mtmp or mtmp->nmon might get killed while mtmp moves, so we cannot just walk down the chain (even new monsters might get created!) */ for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(mtmp->mlstmv < moves) goto next_mon; /* treated all monsters */ break; next_mon: mtmp->mlstmv = moves; /* most monsters drown in pools */ { boolean inpool, iseel; inpool = (levl[mtmp->mx][mtmp->my].typ == POOL); iseel = (mtmp->data->mlet == ';'); if(inpool && !iseel) { if(cansee(mtmp->mx,mtmp->my)) pline("%s drowns.", Monnam(mtmp)); mondead(mtmp); continue; } /* but eels have a difficult time outside */ if(iseel && !inpool) { if(mtmp->mhp > 1) mtmp->mhp--; mtmp->mflee = 1; mtmp->mfleetim += 2; } } if(mtmp->mblinded && !--mtmp->mblinded) mtmp->mcansee = 1; if(mtmp->mfleetim && !--mtmp->mfleetim) mtmp->mflee = 0; if(mtmp->mimic) continue; if(mtmp->mspeed != MSLOW || !(moves%2)){ /* continue if the monster died fighting */ fr = -1; if(Conflict && cansee(mtmp->mx,mtmp->my) && (fr = fightm(mtmp)) == 2) continue; if(fr<0 && dochugw(mtmp)) continue; } if(mtmp->mspeed == MFAST && dochugw(mtmp)) continue; } warnlevel -= u.ulevel; if(warnlevel >= SIZE(warnings)) warnlevel = SIZE(warnings)-1; if(warnlevel >= 0) if(warnlevel > lastwarnlev || moves > lastwarntime + 5){ - register char *rr; + char *rr; switch(Warning & (LEFT_RING | RIGHT_RING)){ case LEFT_RING: rr = "Your left ring glows"; break; case RIGHT_RING: rr = "Your right ring glows"; break; case LEFT_RING | RIGHT_RING: rr = "Both your rings glow"; break; default: rr = "Your fingertips glow"; break; } pline("%s %s!", rr, warnings[warnlevel]); lastwarntime = moves; lastwarnlev = warnlevel; } dmonsfree(); /* remove all dead monsters */ } justswld(mtmp,name) -register struct monst *mtmp; +struct monst *mtmp; char *name; { mtmp->mx = u.ux; mtmp->my = u.uy; u.ustuck = mtmp; pmon(mtmp); kludge("%s swallows you!",name); more(); seeoff(1); u.uswallow = 1; u.uswldtim = 0; swallowed(); } youswld(mtmp,dam,die,name) -register struct monst *mtmp; -register dam,die; +struct monst *mtmp; +dam,die; char *name; { if(mtmp != u.ustuck) return; kludge("%s digests you!",name); u.uhp -= dam; if(u.uswldtim++ >= die){ /* a3 */ pline("It totally digests you!"); u.uhp = -1; } if(u.uhp < 1) done_in_by(mtmp); /* flags.botlx = 1; */ /* should we show status line ? */ } -dochugw(mtmp) register struct monst *mtmp; { -register x = mtmp->mx; -register y = mtmp->my; -register d = dochug(mtmp); -register dd; +dochugw(mtmp) struct monst *mtmp; { +x = mtmp->mx; +y = mtmp->my; +d = dochug(mtmp); +dd; if(!d) /* monster still alive */ if(Warning) if(!mtmp->mpeaceful) if(mtmp->data->mlevel > warnlevel) if((dd = dist(mtmp->mx,mtmp->my)) < dist(x,y)) if(dd < 100) if(!canseemon(mtmp)) warnlevel = mtmp->data->mlevel; return(d); } /* returns 1 if monster died moving, 0 otherwise */ dochug(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { - register struct permonst *mdat; - register tmp, nearby, scared; + struct permonst *mdat; + tmp, nearby, scared; if(mtmp->cham && !rn2(6)) (void) newcham(mtmp, &mons[dlevel+14+rn2(CMNUM-14-dlevel)]); mdat = mtmp->data; if(mdat->mlevel < 0) panic("bad monster %c (%d)",mdat->mlet,mdat->mlevel); /* regenerate monsters */ if((!(moves%20) || index(MREGEN, mdat->mlet)) && mtmp->mhp < mtmp->mhpmax) mtmp->mhp++; if(mtmp->mfroz) return(0); /* frozen monsters don't do anything */ if(mtmp->msleep) { /* wake up, or get out of here. */ /* ettins are hard to surprise */ /* Nymphs and Leprechauns do not easily wake up */ if(cansee(mtmp->mx,mtmp->my) && (!Stealth || (mdat->mlet == 'e' && rn2(10))) && (!index("NL",mdat->mlet) || !rn2(50)) && (Aggravate_monster || index("d1", mdat->mlet) || (!rn2(7) && !mtmp->mimic))) mtmp->msleep = 0; else return(0); } /* not frozen or sleeping: wipe out texts written in the dust */ wipe_engr_at(mtmp->mx, mtmp->my, 1); /* confused monsters get unconfused with small probability */ if(mtmp->mconf && !rn2(50)) mtmp->mconf = 0; /* some monsters teleport */ if(mtmp->mflee && index("tNL", mdat->mlet) && !rn2(40)){ rloc(mtmp); return(0); } if(mdat->mmove < rnd(6)) return(0); /* fleeing monsters might regain courage */ if(mtmp->mflee && !mtmp->mfleetim && mtmp->mhp == mtmp->mhpmax && !rn2(25)) mtmp->mflee = 0; nearby = (dist(mtmp->mx, mtmp->my) < 3); scared = (nearby && (sengr_at("Elbereth", u.ux, u.uy) || sobj_at(SCR_SCARE_MONSTER, u.ux, u.uy))); if(scared && !mtmp->mflee) { mtmp->mflee = 1; mtmp->mfleetim = (rn2(7) ? rnd(10) : rnd(100)); } if(!nearby || mtmp->mflee || mtmp->mconf || (mtmp->minvis && !rn2(3)) || (index("BIuy", mdat->mlet) && !rn2(4)) || (mdat->mlet == 'L' && !u.ugold && (mtmp->mgold || rn2(2))) || (!mtmp->mcansee && !rn2(4)) || mtmp->mpeaceful ) { tmp = m_move(mtmp,0); /* 2: monster died moving */ if(tmp == 2 || (tmp && mdat->mmove <= 12)) return(tmp == 2); } if(!index("Ea", mdat->mlet) && nearby && !mtmp->mpeaceful && u.uhp > 0 && !scared) { if(mhitu(mtmp)) return(1); /* monster died (e.g. 'y' or 'F') */ } /* extra movement for fast monsters */ if(mdat->mmove-12 > rnd(12)) tmp = m_move(mtmp,1); return(tmp == 2); } m_move(mtmp,after) -register struct monst *mtmp; +struct monst *mtmp; { - register struct monst *mtmp2; - register nx,ny,omx,omy,appr,nearer,cnt,i,j; + struct monst *mtmp2; + nx,ny,omx,omy,appr,nearer,cnt,i,j; xchar gx,gy,nix,niy,chcnt; schar chi; boolean likegold, likegems, likeobjs; char msym = mtmp->data->mlet; schar mmoved = 0; /* not strictly nec.: chi >= 0 will do */ coord poss[9]; int info[9]; if(mtmp->mfroz || mtmp->msleep) return(0); if(mtmp->mtrapped) { i = mintrap(mtmp); if(i == 2) return(2); /* he died */ if(i == 1) return(0); /* still in trap, so didnt move */ } if(mtmp->mhide && o_at(mtmp->mx,mtmp->my) && rn2(10)) return(0); /* do not leave hiding place */ #ifndef NOWORM if(mtmp->wormno) goto not_special; #endif NOWORM /* my dog gets a special treatment */ if(mtmp->mtame) { return( dog_move(mtmp, after) ); } /* likewise for shopkeeper */ if(mtmp->isshk) { mmoved = shk_move(mtmp); if(mmoved >= 0) goto postmov; mmoved = 0; /* follow player outside shop */ } /* and for the guard */ if(mtmp->isgd) { mmoved = gd_move(); goto postmov; } /* teleport if that lies in our nature ('t') or when badly wounded ('1') */ if((msym == 't' && !rn2(5)) || (msym == '1' && (mtmp->mhp < 7 || (!xdnstair && !rn2(5)) || levl[u.ux][u.uy].typ == STAIRS))) { if(mtmp->mhp < 7 || (msym == 't' && rn2(2))) rloc(mtmp); else mnexto(mtmp); mmoved = 1; goto postmov; } /* spit fire ('D') or use a wand ('1') when appropriate */ if(index("D1", msym)) inrange(mtmp); if(msym == 'U' && !mtmp->mcan && canseemon(mtmp) && mtmp->mcansee && rn2(5)) { if(!Confusion) pline("%s's gaze has confused you!", Monnam(mtmp)); else pline("You are getting more and more confused."); if(rn2(3)) mtmp->mcan = 1; Confusion += d(3,4); /* timeout */ } not_special: if(!mtmp->mflee && u.uswallow && u.ustuck != mtmp) return(1); appr = 1; if(mtmp->mflee) appr = -1; if(mtmp->mconf || Invis || !mtmp->mcansee || (index("BIy", msym) && !rn2(3))) appr = 0; omx = mtmp->mx; omy = mtmp->my; gx = u.ux; gy = u.uy; if(msym == 'L' && appr == 1 && mtmp->mgold > u.ugold) appr = -1; /* random criterion for 'smell' or track finding ability should use mtmp->msmell or sth */ if(msym == '@' || ('a' <= msym && msym <= 'z')) { extern coord *gettrack(); - register coord *cp; + coord *cp; schar mroom; mroom = inroom(omx,omy); if(mroom < 0 || mroom != inroom(u.ux,u.uy)){ cp = gettrack(omx,omy); if(cp){ gx = cp->x; gy = cp->y; } } } /* look for gold or jewels nearby */ likegold = (index("LOD", msym) != NULL); likegems = (index("ODu", msym) != NULL); likeobjs = mtmp->mhide; #define SRCHRADIUS 25 { xchar mind = SRCHRADIUS; /* not too far away */ - register int dd; + int dd; if(likegold){ - register struct gold *gold; + struct gold *gold; for(gold = fgold; gold; gold = gold->ngold) if((dd = DIST(omx,omy,gold->gx,gold->gy)) < mind){ mind = dd; gx = gold->gx; gy = gold->gy; } } if(likegems || likeobjs){ - register struct obj *otmp; + struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(likeobjs || otmp->olet == GEM_SYM) if(msym != 'u' || objects[otmp->otyp].g_val != 0) if((dd = DIST(omx,omy,otmp->ox,otmp->oy)) < mind){ mind = dd; gx = otmp->ox; gy = otmp->oy; } } if(mind < SRCHRADIUS && appr == -1) { if(dist(omx,omy) < 10) { gx = u.ux; gy = u.uy; } else appr = 1; } } nix = omx; niy = omy; cnt = mfndpos(mtmp,poss,info, msym == 'u' ? NOTONL : (msym == '@' || msym == '1') ? (ALLOW_SSM | ALLOW_TRAPS) : index(UNDEAD, msym) ? NOGARLIC : ALLOW_TRAPS); /* ALLOW_ROCK for some monsters ? */ chcnt = 0; chi = -1; for(i=0; imtrack[j].x && ny == mtmp->mtrack[j].y) if(rn2(4*(cnt-j))) goto nxti; #ifdef STUPID /* some stupid compilers think that this is too complicated */ { int d1 = DIST(nx,ny,gx,gy); int d2 = DIST(nix,niy,gx,gy); nearer = (d1 < d2); } #else nearer = (DIST(nx,ny,gx,gy) < DIST(nix,niy,gx,gy)); #endif STUPID if((appr == 1 && nearer) || (appr == -1 && !nearer) || !mmoved || (!appr && !rn2(++chcnt))){ nix = nx; niy = ny; chi = i; mmoved = 1; } nxti: ; } if(mmoved){ if(info[chi] & ALLOW_M){ mtmp2 = m_at(nix,niy); if(hitmm(mtmp,mtmp2) == 1 && rn2(4) && hitmm(mtmp2,mtmp) == 2) return(2); return(0); } if(info[chi] & ALLOW_U){ (void) hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd)+1); return(0); } mtmp->mx = nix; mtmp->my = niy; for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; #ifndef NOWORM if(mtmp->wormno) worm_move(mtmp); #endif NOWORM } else { if(msym == 'u' && rn2(2)){ rloc(mtmp); return(0); } #ifndef NOWORM if(mtmp->wormno) worm_nomove(mtmp); #endif NOWORM } postmov: if(mmoved == 1) { if(mintrap(mtmp) == 2) /* he died */ return(2); if(likegold) mpickgold(mtmp); if(likegems) mpickgems(mtmp); if(mtmp->mhide) mtmp->mundetected = 1; } pmon(mtmp); return(mmoved); } -mpickgold(mtmp) register struct monst *mtmp; { -register struct gold *gold; +mpickgold(mtmp) struct monst *mtmp; { +struct gold *gold; while(gold = g_at(mtmp->mx, mtmp->my)){ mtmp->mgold += gold->amount; freegold(gold); if(levl[mtmp->mx][mtmp->my].scrsym == '$') newsym(mtmp->mx, mtmp->my); } } -mpickgems(mtmp) register struct monst *mtmp; { -register struct obj *otmp; +mpickgems(mtmp) struct monst *mtmp; { +struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp->olet == GEM_SYM) if(otmp->ox == mtmp->mx && otmp->oy == mtmp->my) if(mtmp->data->mlet != 'u' || objects[otmp->otyp].g_val != 0){ freeobj(otmp); mpickobj(mtmp, otmp); if(levl[mtmp->mx][mtmp->my].scrsym == GEM_SYM) newsym(mtmp->mx, mtmp->my); /* %% */ return; /* pick only one object */ } } /* return number of acceptable neighbour positions */ mfndpos(mon,poss,info,flag) -register struct monst *mon; +struct monst *mon; coord poss[9]; int info[9], flag; { - register int x,y,nx,ny,cnt = 0,ntyp; - register struct monst *mtmp; + int x,y,nx,ny,cnt = 0,ntyp; + struct monst *mtmp; int nowtyp; boolean pool; x = mon->mx; y = mon->my; nowtyp = levl[x][y].typ; pool = (mon->data->mlet == ';'); nexttry: /* eels prefer the water, but if there is no water nearby, they will crawl over land */ if(mon->mconf) { flag |= ALLOW_ALL; flag &= ~NOTONL; } for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) if(nx != x || ny != y) if(isok(nx,ny)) if(!IS_ROCK(ntyp = levl[nx][ny].typ)) if(!(nx != x && ny != y && (nowtyp == DOOR || ntyp == DOOR))) if((ntyp == POOL) == pool) { info[cnt] = 0; if(nx == u.ux && ny == u.uy){ if(!(flag & ALLOW_U)) continue; info[cnt] = ALLOW_U; } else if(mtmp = m_at(nx,ny)){ if(!(flag & ALLOW_M)) continue; info[cnt] = ALLOW_M; if(mtmp->mtame){ if(!(flag & ALLOW_TM)) continue; info[cnt] |= ALLOW_TM; } } if(sobj_at(CLOVE_OF_GARLIC, nx, ny)) { if(flag & NOGARLIC) continue; info[cnt] |= NOGARLIC; } if(sobj_at(SCR_SCARE_MONSTER, nx, ny) || (!mon->mpeaceful && sengr_at("Elbereth", nx, ny))) { if(!(flag & ALLOW_SSM)) continue; info[cnt] |= ALLOW_SSM; } if(sobj_at(ENORMOUS_ROCK, nx, ny)) { if(!(flag & ALLOW_ROCK)) continue; info[cnt] |= ALLOW_ROCK; } if(!Invis && online(nx,ny)){ if(flag & NOTONL) continue; info[cnt] |= NOTONL; } /* we cannot avoid traps of an unknown kind */ - { register struct trap *ttmp = t_at(nx, ny); - register int tt; + { struct trap *ttmp = t_at(nx, ny); + int tt; if(ttmp) { tt = 1 << ttmp->ttyp; if(mon->mtrapseen & tt){ if(!(flag & tt)) continue; info[cnt] |= tt; } } } poss[cnt].x = nx; poss[cnt].y = ny; cnt++; } if(!cnt && pool && nowtyp != POOL) { pool = FALSE; goto nexttry; } return(cnt); } dist(x,y) int x,y; { return((x-u.ux)*(x-u.ux) + (y-u.uy)*(y-u.uy)); } poisoned(string, pname) -register char *string, *pname; +char *string, *pname; { - register int i; + int i; if(Blind) pline("It was poisoned."); else pline("The %s was poisoned!",string); if(Poison_resistance) { pline("The poison doesn't seem to affect you."); return; } i = rn2(10); if(i == 0) { u.uhp = -1; pline("I am afraid the poison was deadly ..."); } else if(i <= 5) { losestr(rn1(3,3)); } else { losehp(rn1(10,6), pname); } if(u.uhp < 1) { killer = pname; done("died"); } } mondead(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { relobj(mtmp,1); unpmon(mtmp); relmon(mtmp); unstuck(mtmp); if(mtmp->isshk) shkdead(mtmp); if(mtmp->isgd) gddead(); #ifndef NOWORM if(mtmp->wormno) wormdead(mtmp); #endif NOWORM monfree(mtmp); } /* called when monster is moved to larger structure */ replmon(mtmp,mtmp2) -register struct monst *mtmp, *mtmp2; +struct monst *mtmp, *mtmp2; { relmon(mtmp); monfree(mtmp); mtmp2->nmon = fmon; fmon = mtmp2; if(u.ustuck == mtmp) u.ustuck = mtmp2; if(mtmp2->isshk) replshk(mtmp,mtmp2); if(mtmp2->isgd) replgd(mtmp,mtmp2); } relmon(mon) -register struct monst *mon; +struct monst *mon; { - register struct monst *mtmp; + struct monst *mtmp; if(mon == fmon) fmon = fmon->nmon; else { for(mtmp = fmon; mtmp->nmon != mon; mtmp = mtmp->nmon) ; mtmp->nmon = mon->nmon; } } /* we do not free monsters immediately, in order to have their name available shortly after their demise */ struct monst *fdmon; /* chain of dead monsters, need not to be saved */ -monfree(mtmp) register struct monst *mtmp; { +monfree(mtmp) struct monst *mtmp; { mtmp->nmon = fdmon; fdmon = mtmp; } dmonsfree(){ -register struct monst *mtmp; +struct monst *mtmp; while(mtmp = fdmon){ fdmon = mtmp->nmon; free((char *) mtmp); } } unstuck(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { if(u.ustuck == mtmp) { if(u.uswallow){ u.ux = mtmp->mx; u.uy = mtmp->my; u.uswallow = 0; setsee(); docrt(); } u.ustuck = 0; } } killed(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { #ifdef lint #define NEW_SCORING #endif lint - register int tmp,tmp2,nk,x,y; - register struct permonst *mdat; + int tmp,tmp2,nk,x,y; + struct permonst *mdat; extern long newuexp(); if(mtmp->cham) mtmp->data = PM_CHAMELEON; mdat = mtmp->data; if(Blind) pline("You destroy it!"); else { pline("You destroy %s!", mtmp->mtame ? amonnam(mtmp, "poor") : monnam(mtmp)); } if(u.umconf) { if(!Blind) pline("Your hands stop glowing blue."); u.umconf = 0; } /* count killed monsters */ #define MAXMONNO 100 nk = 1; /* in case we cannot find it in mons */ tmp = mdat - mons; /* index in mons array (if not 'd', '@', ...) */ if(tmp >= 0 && tmp < CMNUM+2) { extern char fut_geno[]; u.nr_killed[tmp]++; if((nk = u.nr_killed[tmp]) > MAXMONNO && !index(fut_geno, mdat->mlet)) charcat(fut_geno, mdat->mlet); } /* punish bad behaviour */ if(mdat->mlet == '@') Telepat = 0, u.uluck -= 2; if(mtmp->mpeaceful || mtmp->mtame) u.uluck--; if(mdat->mlet == 'u') u.uluck -= 5; if((int)u.uluck < LUCKMIN) u.uluck = LUCKMIN; /* give experience points */ tmp = 1 + mdat->mlevel * mdat->mlevel; if(mdat->ac < 3) tmp += 2*(7 - mdat->ac); if(index("AcsSDXaeRTVWU&In:P", mdat->mlet)) tmp += 2*mdat->mlevel; if(index("DeV&P",mdat->mlet)) tmp += (7*mdat->mlevel); if(mdat->mlevel > 6) tmp += 50; if(mdat->mlet == ';') tmp += 1000; #ifdef NEW_SCORING /* ------- recent addition: make nr of points decrease when this is not the first of this kind */ { int ul = u.ulevel; int ml = mdat->mlevel; if(ul < 14) /* points are given based on present and future level */ for(tmp2 = 0; !tmp2 || ul + tmp2 <= ml; tmp2++) if(u.uexp + 1 + (tmp + ((tmp2 <= 0) ? 0 : 4<<(tmp2-1)))/nk >= 10*pow((unsigned)(ul-1))) if(++ul == 14) break; tmp2 = ml - ul -1; tmp = (tmp + ((tmp2 < 0) ? 0 : 4<= newuexp()){ pline("Welcome to experience level %u.", ++u.ulevel); tmp = rnd(10); if(tmp < 3) tmp = rnd(10); u.uhpmax += tmp; u.uhp += tmp; flags.botl = 1; } /* dispose of monster and make cadaver */ x = mtmp->mx; y = mtmp->my; mondead(mtmp); tmp = mdat->mlet; if(tmp == 'm') { /* he killed a minotaur, give him a wand of digging */ /* note: the dead minotaur will be on top of it! */ mksobj_at(WAN_DIGGING, x, y); /* if(cansee(x,y)) atl(x,y,fobj->olet); */ stackobj(fobj); } else #ifndef NOWORM if(tmp == 'w') { mksobj_at(WORM_TOOTH, x, y); stackobj(fobj); } else #endif NOWORM if(!letter(tmp) || (!index("mw", tmp) && !rn2(3))) tmp = 0; if(ACCESSIBLE(levl[x][y].typ)) /* might be mimic in wall or dead eel*/ if(x != u.ux || y != u.uy) /* might be here after swallowed */ if(index("NTVm&",mdat->mlet) || rn2(5)) { - register struct obj *obj2 = mkobj_at(tmp,x,y); + struct obj *obj2 = mkobj_at(tmp,x,y); if(cansee(x,y)) atl(x,y,obj2->olet); stackobj(obj2); } } kludge(str,arg) -register char *str,*arg; +char *str,*arg; { if(Blind) { if(*str == '%') pline(str,"It"); else pline(str,"it"); } else pline(str,arg); } rescham() /* force all chameleons to become normal */ { - register struct monst *mtmp; + struct monst *mtmp; for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) if(mtmp->cham) { mtmp->cham = 0; (void) newcham(mtmp, PM_CHAMELEON); } } newcham(mtmp,mdat) /* make a chameleon look like a new monster */ /* returns 1 if the monster actually changed */ -register struct monst *mtmp; -register struct permonst *mdat; +struct monst *mtmp; +struct permonst *mdat; { - register mhp, hpn, hpd; + mhp, hpn, hpd; if(mdat == mtmp->data) return(0); /* still the same monster */ #ifndef NOWORM if(mtmp->wormno) wormdead(mtmp); /* throw tail away */ #endif NOWORM if (u.ustuck == mtmp) { if (u.uswallow) { u.uswallow = 0; u.uswldtim = 0; mnexto (mtmp); docrt (); prme (); } u.ustuck = 0; } hpn = mtmp->mhp; hpd = (mtmp->data->mlevel)*8; if(!hpd) hpd = 4; mtmp->data = mdat; mhp = (mdat->mlevel)*8; /* new hp: same fraction of max as before */ mtmp->mhp = 2 + (hpn*mhp)/hpd; hpn = mtmp->mhpmax; mtmp->mhpmax = 2 + (hpn*mhp)/hpd; mtmp->minvis = (mdat->mlet == 'I') ? 1 : 0; #ifndef NOWORM if(mdat->mlet == 'w' && getwn(mtmp)) initworm(mtmp); /* perhaps we should clear mtmp->mtame here? */ #endif NOWORM unpmon(mtmp); /* necessary for 'I' and to force pmon */ pmon(mtmp); return(1); } mnexto(mtmp) /* Make monster mtmp next to you (if possible) */ struct monst *mtmp; { extern coord enexto(); coord mm; mm = enexto(u.ux, u.uy); mtmp->mx = mm.x; mtmp->my = mm.y; pmon(mtmp); } -ishuman(mtmp) register struct monst *mtmp; { +ishuman(mtmp) struct monst *mtmp; { return(mtmp->data->mlet == '@'); } -setmangry(mtmp) register struct monst *mtmp; { +setmangry(mtmp) struct monst *mtmp; { if(!mtmp->mpeaceful) return; if(mtmp->mtame) return; mtmp->mpeaceful = 0; if(ishuman(mtmp)) pline("%s gets angry!", Monnam(mtmp)); } /* not one hundred procent correct: now a snake may hide under an invisible object */ canseemon(mtmp) -register struct monst *mtmp; +struct monst *mtmp; { return((!mtmp->minvis || See_invisible) && (!mtmp->mhide || !o_at(mtmp->mx,mtmp->my)) && cansee(mtmp->mx, mtmp->my)); } diff --git a/games/hack/hack.o_init.c b/games/hack/hack.o_init.c index f55d96c948d5..6cac5dd72140 100644 --- a/games/hack/hack.o_init.c +++ b/games/hack/hack.o_init.c @@ -1,162 +1,162 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.o_init.c - version 1.0.3 */ /* $FreeBSD$ */ #include #include "config.h" /* for typedefs */ #include "def.objects.h" #include "hack.onames.h" /* for LAST_GEM */ extern char *index(); int -letindex(let) register char let; { -register int i = 0; -register char ch; +letindex(let) char let; { +int i = 0; +char ch; while((ch = obj_symbols[i++]) != 0) if(ch == let) return(i); return(0); } init_objects(){ -register int i, j, first, last, sum, end; -register char let, *tmp; +int i, j, first, last, sum, end; +char let, *tmp; /* init base; if probs given check that they add up to 100, otherwise compute probs; shuffle descriptions */ end = SIZE(objects); first = 0; while( first < end ) { let = objects[first].oc_olet; last = first+1; while(last < end && objects[last].oc_olet == let && objects[last].oc_name != NULL) last++; i = letindex(let); if((!i && let != ILLOBJ_SYM) || bases[i] != 0) error("initialization error"); bases[i] = first; if(let == GEM_SYM) setgemprobs(); check: sum = 0; for(j = first; j < last; j++) sum += objects[j].oc_prob; if(sum == 0) { for(j = first; j < last; j++) objects[j].oc_prob = (100+j-first)/(last-first); goto check; } if(sum != 100) error("init-prob error for %c", let); if(objects[first].oc_descr != NULL && let != TOOL_SYM){ /* shuffle, also some additional descriptions */ while(last < end && objects[last].oc_olet == let) last++; j = last; while(--j > first) { i = first + rn2(j+1-first); tmp = objects[j].oc_descr; objects[j].oc_descr = objects[i].oc_descr; objects[i].oc_descr = tmp; } } first = last; } } -probtype(let) register char let; { -register int i = bases[letindex(let)]; -register int prob = rn2(100); +probtype(let) char let; { +int i = bases[letindex(let)]; +int prob = rn2(100); while((prob -= objects[i].oc_prob) >= 0) i++; if(objects[i].oc_olet != let || !objects[i].oc_name) panic("probtype(%c) error, i=%d", let, i); return(i); } setgemprobs() { - register int j,first; + int j,first; extern xchar dlevel; first = bases[letindex(GEM_SYM)]; for(j = 0; j < 9-dlevel/3; j++) objects[first+j].oc_prob = 0; first += j; if(first >= LAST_GEM || first >= SIZE(objects) || objects[first].oc_olet != GEM_SYM || objects[first].oc_name == NULL) printf("Not enough gems? - first=%d j=%d LAST_GEM=%d\n", first, j, LAST_GEM); for(j = first; j < LAST_GEM; j++) objects[j].oc_prob = (20+j-first)/(LAST_GEM-first); } oinit() /* level dependent initialization */ { setgemprobs(); } extern long *alloc(); -savenames(fd) register fd; { -register int i; +savenames(fd) fd; { +int i; unsigned len; bwrite(fd, (char *) bases, sizeof bases); bwrite(fd, (char *) objects, sizeof objects); /* as long as we use only one version of Hack/Quest we need not save oc_name and oc_descr, but we must save oc_uname for all objects */ for(i=0; i < SIZE(objects); i++) { if(objects[i].oc_uname) { len = strlen(objects[i].oc_uname)+1; bwrite(fd, (char *) &len, sizeof len); bwrite(fd, objects[i].oc_uname, len); } } } -restnames(fd) register fd; { -register int i; +restnames(fd) fd; { +int i; unsigned len; mread(fd, (char *) bases, sizeof bases); mread(fd, (char *) objects, sizeof objects); for(i=0; i < SIZE(objects); i++) if(objects[i].oc_uname) { mread(fd, (char *) &len, sizeof len); objects[i].oc_uname = (char *) alloc(len); mread(fd, objects[i].oc_uname, len); } } dodiscovered() /* free after Robert Viduya */ { extern char *typename(); - register int i, end; + int i, end; int ct = 0; cornline(0, "Discoveries"); end = SIZE(objects); for (i = 0; i < end; i++) { if (interesting_to_discover (i)) { ct++; cornline(1, typename(i)); } } if (ct == 0) { pline ("You haven't discovered anything yet..."); cornline(3, (char *) 0); } else cornline(2, (char *) 0); return(0); } interesting_to_discover(i) -register int i; +int i; { return( objects[i].oc_uname != NULL || (objects[i].oc_name_known && objects[i].oc_descr != NULL) ); } diff --git a/games/hack/hack.objnam.c b/games/hack/hack.objnam.c index ad47e7e77115..eebc05230b22 100644 --- a/games/hack/hack.objnam.c +++ b/games/hack/hack.objnam.c @@ -1,548 +1,548 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.objnam.c - version 1.0.2 */ /* $FreeBSD$ */ #include "hack.h" #define Sprintf (void) sprintf #define Strcat (void) strcat #define Strcpy (void) strcpy #define PREFIX 15 extern char *eos(); extern int bases[]; char * -strprepend(s,pref) register char *s, *pref; { -register int i = strlen(pref); +strprepend(s,pref) char *s, *pref; { +int i = strlen(pref); if(i > PREFIX) { pline("WARNING: prefix too short."); return(s); } s -= i; (void) strncpy(s, pref, i); /* do not copy trailing 0 */ return(s); } char * sitoa(a) int a; { static char buf[13]; Sprintf(buf, (a < 0) ? "%d" : "+%d", a); return(buf); } char * typename(otyp) -register int otyp; +int otyp; { static char buf[BUFSZ]; -register struct objclass *ocl = &objects[otyp]; -register char *an = ocl->oc_name; -register char *dn = ocl->oc_descr; -register char *un = ocl->oc_uname; -register int nn = ocl->oc_name_known; +struct objclass *ocl = &objects[otyp]; +char *an = ocl->oc_name; +char *dn = ocl->oc_descr; +char *un = ocl->oc_uname; +int nn = ocl->oc_name_known; switch(ocl->oc_olet) { case POTION_SYM: Strcpy(buf, "potion"); break; case SCROLL_SYM: Strcpy(buf, "scroll"); break; case WAND_SYM: Strcpy(buf, "wand"); break; case RING_SYM: Strcpy(buf, "ring"); break; default: if(nn) { Strcpy(buf, an); if(otyp >= TURQUOISE && otyp <= JADE) Strcat(buf, " stone"); if(un) Sprintf(eos(buf), " called %s", un); if(dn) Sprintf(eos(buf), " (%s)", dn); } else { Strcpy(buf, dn ? dn : an); if(ocl->oc_olet == GEM_SYM) Strcat(buf, " gem"); if(un) Sprintf(eos(buf), " called %s", un); } return(buf); } /* here for ring/scroll/potion/wand */ if(nn) Sprintf(eos(buf), " of %s", an); if(un) Sprintf(eos(buf), " called %s", un); if(dn) Sprintf(eos(buf), " (%s)", dn); return(buf); } char * xname(obj) -register struct obj *obj; +struct obj *obj; { static char bufr[BUFSZ]; -register char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */ -register int nn = objects[obj->otyp].oc_name_known; -register char *an = objects[obj->otyp].oc_name; -register char *dn = objects[obj->otyp].oc_descr; -register char *un = objects[obj->otyp].oc_uname; -register int pl = (obj->quan != 1); +char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */ +int nn = objects[obj->otyp].oc_name_known; +char *an = objects[obj->otyp].oc_name; +char *dn = objects[obj->otyp].oc_descr; +char *un = objects[obj->otyp].oc_uname; +int pl = (obj->quan != 1); if(!obj->dknown && !Blind) obj->dknown = 1; /* %% doesnt belong here */ switch(obj->olet) { case AMULET_SYM: Strcpy(buf, (obj->spe < 0 && obj->known) ? "cheap plastic imitation of the " : ""); Strcat(buf,"Amulet of Yendor"); break; case TOOL_SYM: if(!nn) { Strcpy(buf, dn); break; } Strcpy(buf,an); break; case FOOD_SYM: if(obj->otyp == DEAD_HOMUNCULUS && pl) { pl = 0; Strcpy(buf, "dead homunculi"); break; } /* fungis ? */ /* fall into next case */ case WEAPON_SYM: if(obj->otyp == WORM_TOOTH && pl) { pl = 0; Strcpy(buf, "worm teeth"); break; } if(obj->otyp == CRYSKNIFE && pl) { pl = 0; Strcpy(buf, "crysknives"); break; } /* fall into next case */ case ARMOR_SYM: case CHAIN_SYM: case ROCK_SYM: Strcpy(buf,an); break; case BALL_SYM: Sprintf(buf, "%sheavy iron ball", (obj->owt > objects[obj->otyp].oc_weight) ? "very " : ""); break; case POTION_SYM: if(nn || un || !obj->dknown) { Strcpy(buf, "potion"); if(pl) { pl = 0; Strcat(buf, "s"); } if(!obj->dknown) break; if(un) { Strcat(buf, " called "); Strcat(buf, un); } else { Strcat(buf, " of "); Strcat(buf, an); } } else { Strcpy(buf, dn); Strcat(buf, " potion"); } break; case SCROLL_SYM: Strcpy(buf, "scroll"); if(pl) { pl = 0; Strcat(buf, "s"); } if(!obj->dknown) break; if(nn) { Strcat(buf, " of "); Strcat(buf, an); } else if(un) { Strcat(buf, " called "); Strcat(buf, un); } else { Strcat(buf, " labeled "); Strcat(buf, dn); } break; case WAND_SYM: if(!obj->dknown) Sprintf(buf, "wand"); else if(nn) Sprintf(buf, "wand of %s", an); else if(un) Sprintf(buf, "wand called %s", un); else Sprintf(buf, "%s wand", dn); break; case RING_SYM: if(!obj->dknown) Sprintf(buf, "ring"); else if(nn) Sprintf(buf, "ring of %s", an); else if(un) Sprintf(buf, "ring called %s", un); else Sprintf(buf, "%s ring", dn); break; case GEM_SYM: if(!obj->dknown) { Strcpy(buf, "gem"); break; } if(!nn) { Sprintf(buf, "%s gem", dn); break; } Strcpy(buf, an); if(obj->otyp >= TURQUOISE && obj->otyp <= JADE) Strcat(buf, " stone"); break; default: Sprintf(buf,"glorkum %c (0%o) %u %d", obj->olet,obj->olet,obj->otyp,obj->spe); } if(pl) { - register char *p; + char *p; for(p = buf; *p; p++) { if(!strncmp(" of ", p, 4)) { /* pieces of, cloves of, lumps of */ - register int c1, c2 = 's'; + int c1, c2 = 's'; do { c1 = c2; c2 = *p; *p++ = c1; } while(c1); goto nopl; } } p = eos(buf)-1; if(*p == 's' || *p == 'z' || *p == 'x' || (*p == 'h' && p[-1] == 's')) Strcat(buf, "es"); /* boxes */ else if(*p == 'y' && !index(vowels, p[-1])) Strcpy(p, "ies"); /* rubies, zruties */ else Strcat(buf, "s"); } nopl: if(obj->onamelth) { Strcat(buf, " named "); Strcat(buf, ONAME(obj)); } return(buf); } char * doname(obj) -register struct obj *obj; +struct obj *obj; { char prefix[PREFIX]; -register char *bp = xname(obj); +char *bp = xname(obj); if(obj->quan != 1) Sprintf(prefix, "%u ", obj->quan); else Strcpy(prefix, "a "); switch(obj->olet) { case AMULET_SYM: if(strncmp(bp, "cheap ", 6)) Strcpy(prefix, "the "); break; case ARMOR_SYM: if(obj->owornmask & W_ARMOR) Strcat(bp, " (being worn)"); /* fall into next case */ case WEAPON_SYM: if(obj->known) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } break; case WAND_SYM: if(obj->known) Sprintf(eos(bp), " (%d)", obj->spe); break; case RING_SYM: if(obj->owornmask & W_RINGR) Strcat(bp, " (on right hand)"); if(obj->owornmask & W_RINGL) Strcat(bp, " (on left hand)"); if(obj->known && (objects[obj->otyp].bits & SPEC)) { Strcat(prefix, sitoa(obj->spe)); Strcat(prefix, " "); } break; } if(obj->owornmask & W_WEP) Strcat(bp, " (weapon in hand)"); if(obj->unpaid) Strcat(bp, " (unpaid)"); if(!strcmp(prefix, "a ") && index(vowels, *bp)) Strcpy(prefix, "an "); bp = strprepend(bp, prefix); return(bp); } /* used only in hack.fight.c (thitu) */ setan(str,buf) -register char *str,*buf; +char *str,*buf; { if(index(vowels,*str)) Sprintf(buf, "an %s", str); else Sprintf(buf, "a %s", str); } char * -aobjnam(otmp,verb) register struct obj *otmp; register char *verb; { -register char *bp = xname(otmp); +aobjnam(otmp,verb) struct obj *otmp; char *verb; { +char *bp = xname(otmp); char prefix[PREFIX]; if(otmp->quan != 1) { Sprintf(prefix, "%u ", otmp->quan); bp = strprepend(bp, prefix); } if(verb) { /* verb is given in plural (i.e., without trailing s) */ Strcat(bp, " "); if(otmp->quan != 1) Strcat(bp, verb); else if(!strcmp(verb, "are")) Strcat(bp, "is"); else { Strcat(bp, verb); Strcat(bp, "s"); } } return(bp); } char * Doname(obj) -register struct obj *obj; +struct obj *obj; { - register char *s = doname(obj); + char *s = doname(obj); if('a' <= *s && *s <= 'z') *s -= ('a' - 'A'); return(s); } char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" }; char wrpsym[] = { WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM }; struct obj * -readobjnam(bp) register char *bp; { -register char *p; -register int i; +readobjnam(bp) char *bp; { +char *p; +int i; int cnt, spe, spesgn, typ, heavy; char let; char *un, *dn, *an; /* int the = 0; char *oname = 0; */ cnt = spe = spesgn = typ = heavy = 0; let = 0; an = dn = un = 0; for(p = bp; *p; p++) if('A' <= *p && *p <= 'Z') *p += 'a'-'A'; if(!strncmp(bp, "the ", 4)){ /* the = 1; */ bp += 4; } else if(!strncmp(bp, "an ", 3)){ cnt = 1; bp += 3; } else if(!strncmp(bp, "a ", 2)){ cnt = 1; bp += 2; } if(!cnt && digit(*bp)){ cnt = atoi(bp); while(digit(*bp)) bp++; while(*bp == ' ') bp++; } if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */ if(*bp == '+' || *bp == '-'){ spesgn = (*bp++ == '+') ? 1 : -1; spe = atoi(bp); while(digit(*bp)) bp++; while(*bp == ' ') bp++; } else { p = rindex(bp, '('); if(p) { if(p > bp && p[-1] == ' ') p[-1] = 0; else *p = 0; p++; spe = atoi(p); while(digit(*p)) p++; if(strcmp(p, ")")) spe = 0; else spesgn = 1; } } /* now we have the actual name, as delivered by xname, say green potions called whisky scrolls labeled "QWERTY" egg dead zruties fortune cookies very heavy iron ball named hoei wand of wishing elven cloak */ for(p = bp; *p; p++) if(!strncmp(p, " named ", 7)) { *p = 0; /* oname = p+7; */ } for(p = bp; *p; p++) if(!strncmp(p, " called ", 8)) { *p = 0; un = p+8; } for(p = bp; *p; p++) if(!strncmp(p, " labeled ", 9)) { *p = 0; dn = p+9; } /* first change to singular if necessary */ if(cnt != 1) { /* find "cloves of garlic", "worthless pieces of blue glass" */ for(p = bp; *p; p++) if(!strncmp(p, "s of ", 5)){ while(*p = p[1]) p++; goto sing; } /* remove -s or -es (boxes) or -ies (rubies, zruties) */ p = eos(bp); if(p[-1] == 's') { if(p[-2] == 'e') { if(p[-3] == 'i') { if(!strcmp(p-7, "cookies")) goto mins; Strcpy(p-3, "y"); goto sing; } /* note: cloves / knives from clove / knife */ if(!strcmp(p-6, "knives")) { Strcpy(p-3, "fe"); goto sing; } /* note: nurses, axes but boxes */ if(!strcmp(p-5, "boxes")) { p[-2] = 0; goto sing; } } mins: p[-1] = 0; } else { if(!strcmp(p-9, "homunculi")) { Strcpy(p-1, "us"); /* !! makes string longer */ goto sing; } if(!strcmp(p-5, "teeth")) { Strcpy(p-5, "tooth"); goto sing; } /* here we cannot find the plural suffix */ } } sing: if(!strcmp(bp, "amulet of yendor")) { typ = AMULET_OF_YENDOR; goto typfnd; } p = eos(bp); if(!strcmp(p-5, " mail")){ /* Note: ring mail is not a ring ! */ let = ARMOR_SYM; an = bp; goto srch; } for(i = 0; i < sizeof(wrpsym); i++) { - register int j = strlen(wrp[i]); + int j = strlen(wrp[i]); if(!strncmp(bp, wrp[i], j)){ let = wrpsym[i]; bp += j; if(!strncmp(bp, " of ", 4)) an = bp+4; /* else if(*bp) ?? */ goto srch; } if(!strcmp(p-j, wrp[i])){ let = wrpsym[i]; p -= j; *p = 0; if(p[-1] == ' ') p[-1] = 0; dn = bp; goto srch; } } if(!strcmp(p-6, " stone")){ p[-6] = 0; let = GEM_SYM; an = bp; goto srch; } if(!strcmp(bp, "very heavy iron ball")){ heavy = 1; typ = HEAVY_IRON_BALL; goto typfnd; } an = bp; srch: if(!an && !dn && !un) goto any; i = 1; if(let) i = bases[letindex(let)]; while(i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)){ - register char *zn = objects[i].oc_name; + char *zn = objects[i].oc_name; if(!zn) goto nxti; if(an && strcmp(an, zn)) goto nxti; if(dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn))) goto nxti; if(un && (!(zn = objects[i].oc_uname) || strcmp(un, zn))) goto nxti; typ = i; goto typfnd; nxti: i++; } any: if(!let) let = wrpsym[rn2(sizeof(wrpsym))]; typ = probtype(let); typfnd: - { register struct obj *otmp; + { struct obj *otmp; extern struct obj *mksobj(); let = objects[typ].oc_olet; otmp = mksobj(typ); if(heavy) otmp->owt += 15; if(cnt > 0 && index("%?!*)", let) && (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20))) otmp->quan = cnt; if(spe > 3 && spe > otmp->spe) spe = 0; else if(let == WAND_SYM) spe = otmp->spe; if(spe == 3 && u.uluck < 0) spesgn = -1; if(let != WAND_SYM && spesgn == -1) spe = -spe; if(let == BALL_SYM) spe = 0; else if(let == AMULET_SYM) spe = -1; else if(typ == WAN_WISHING && rn2(10)) spe = (rn2(10) ? -1 : 0); otmp->spe = spe; if(spesgn == -1) otmp->cursed = 1; return(otmp); } } diff --git a/games/hack/hack.options.c b/games/hack/hack.options.c index 1c3a4a51c442..7bd1baa197d4 100644 --- a/games/hack/hack.options.c +++ b/games/hack/hack.options.c @@ -1,204 +1,204 @@ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* hack.options.c - version 1.0.3 */ /* $FreeBSD$ */ #include #include "config.h" #include "hack.h" extern char *eos(); initoptions() { - register char *opts; + char *opts; flags.time = flags.nonews = flags.notombstone = flags.end_own = flags.standout = flags.nonull = FALSE; flags.no_rest_on_space = TRUE; flags.invlet_constant = TRUE; flags.end_top = 5; flags.end_around = 4; flags.female = FALSE; /* players are usually male */ if(opts = getenv("HACKOPTIONS")) parseoptions(opts,TRUE); } parseoptions(opts, from_env) -register char *opts; +char *opts; boolean from_env; { - register char *op,*op2; + char *op,*op2; unsigned num; boolean negated; if(op = index(opts, ',')) { *op++ = 0; parseoptions(op, from_env); } if(op = index(opts, ' ')) { op2 = op; while(*op++) if(*op != ' ') *op2++ = *op; } if(!*opts) return; negated = FALSE; while((*opts == '!') || !strncmp(opts, "no", 2)) { if(*opts == '!') opts++; else opts += 2; negated = !negated; } if(!strncmp(opts,"standout",8)) { flags.standout = !negated; return; } if(!strncmp(opts,"null",3)) { flags.nonull = negated; return; } if(!strncmp(opts,"tombstone",4)) { flags.notombstone = negated; return; } if(!strncmp(opts,"news",4)) { flags.nonews = negated; return; } if(!strncmp(opts,"time",4)) { flags.time = !negated; flags.botl = 1; return; } if(!strncmp(opts,"restonspace",4)) { flags.no_rest_on_space = negated; return; } if(!strncmp(opts,"fixinv",4)) { if(from_env) flags.invlet_constant = !negated; else pline("The fixinvlet option must be in HACKOPTIONS."); return; } if(!strncmp(opts,"male",4)) { flags.female = negated; return; } if(!strncmp(opts,"female",6)) { flags.female = !negated; return; } /* name:string */ if(!strncmp(opts,"name",4)) { extern char plname[PL_NSIZ]; if(!from_env) { pline("The playername can be set only from HACKOPTIONS."); return; } op = index(opts,':'); if(!op) goto bad; (void) strncpy(plname, op+1, sizeof(plname)-1); return; } /* endgame:5t[op] 5a[round] o[wn] */ if(!strncmp(opts,"endgame",3)) { op = index(opts,':'); if(!op) goto bad; op++; while(*op) { num = 1; if(digit(*op)) { num = atoi(op); while(digit(*op)) op++; } else if(*op == '!') { negated = !negated; op++; } switch(*op) { case 't': flags.end_top = num; break; case 'a': flags.end_around = num; break; case 'o': flags.end_own = !negated; break; default: goto bad; } while(letter(*++op)) ; if(*op == '/') op++; } return; } bad: if(!from_env) { if(!strncmp(opts, "help", 4)) { pline("%s%s%s", "To set options use `HACKOPTIONS=\"\"' in your environment, or ", "give the command 'o' followed by the line `' while playing. ", "Here is a list of